#include <bits/stdc++.h>   using namespace std;   unsigned long long pow_of_two[10000];   int create() {     unsigned long long i = 0;     unsigned long long num = 1;     while (num <= INT_MAX and num >= 0) {       num = pow(2, i);       pow_of_two[i] = num;       i++;     }   }   int main() {     int n;     cin >> n;     string str;     cin >> str;     int len = str.length();     int swapi = 0;     for (int i = len - 1; i >= 0; i--) {       if (str[i] ==  1 ) {         for (int j = i - 1; j >= 0; j--) {           if (str[j] ==  1 ) {             int left = j;             int right = i;             while (left + 1 < right) {               swap(str[right], str[right - 1]);               right--;               swapi++;             }             if (str[right] ==  1  && str[right - 1] ==  1 ) {               str[right] =  4 ;             }             break;           }         }       }     }     for (int i = 0; i < str.length(); i++) {       if (str[i] !=  4 ) cout << str[i];     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     cin >> n >> s;     sort(s.begin(), s.end());     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a =   , b =   ;     int n, m;     cin >> n >> m;     for (int i = 0; i < 2220; i++) {       if (i % 2 == 0) {         a +=  5 ;         b +=  4 ;       } else {         a +=  4 ;         b +=  5 ;       }     }     a +=  5 ;     b +=  5 ;     cout << a << endl;     cout << b << endl;   }


#include <bits/stdc++.h>   using namespace std;   ifstream Cin( input.txt );   ofstream Cout( output.txt );   int main() {     long long n, x, i, num = 0, m[100001], m1[100001];     m[0] = m1[0] = 0;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> m[i];       m1[i] = m[i];     }     sort(m, m + n + 1);     for (i = 1; i <= n; i++) {       if (m[i] != m1[i]) {         num++;       }     }     cout << (num <= 2 ?  YES  :  NO );   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, unsigned long long int y) {     long long int res = 1;     while (y > 0) {       if (y & 1) {         res = res * x;       }       y = y >> 1;       x = x * x;     }     return res;   }   long long int powermod(long long int x, unsigned long long int y,                          long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) {         res = (res * x) % p;       }       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int32_t main() {     long long int n, m;     cin >> n >> m;     vector<long long int> v, suf(m + 1);     for (long long int i = (long long int)(0); i < (long long int)(m); i++) {       long long int t;       cin >> t;       v.push_back(t);     }     long long int ok = 1;     for (long long int i = (long long int)(m - 1); i >= (long long int)(0); i--) {       suf[i] = suf[i + 1] + v[i];       if (v[i] + i > n) ok = 0;     }     if (!ok or suf[0] < n) {       cout << -1 <<   n ;       return 0;     }     for (long long int i = (long long int)(0); i < (long long int)(m); i++) {       cout << max(i + 1, n - suf[i] + 1) <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005 * 2;   struct SegmentTree {     int l, r;     int sum, lmx, rmn, ansl, ansr, ans, Ans;   } t[N << 2];   int s[N];   char ss[N];   void merge(int p) {     t[p].sum = t[p * 2].sum + t[p * 2 + 1].sum;     t[p].lmx = max(t[p * 2].lmx, t[p * 2].sum + t[p * 2 + 1].lmx);     t[p].rmn = min(t[p * 2 + 1].rmn, t[p * 2 + 1].sum + t[p * 2].rmn);     t[p].ansl = max(max(t[p * 2].ansl, t[p * 2 + 1].ansl - t[p * 2].sum),                     t[p * 2].ans + t[p * 2 + 1].lmx);     t[p].ansr = max(max(t[p * 2 + 1].ansr, t[p * 2].ansr + t[p * 2 + 1].sum),                     t[p * 2 + 1].ans - t[p * 2].rmn);     t[p].ans =         max(t[p * 2].ans + t[p * 2 + 1].sum, t[p * 2 + 1].ans - t[p * 2].sum);     t[p].Ans = max(max(max(t[p * 2].Ans, t[p * 2 + 1].Ans),                        t[p * 2 + 1].ansl - t[p * 2].rmn),                    t[p * 2].ansr + t[p * 2 + 1].lmx);   }   void build(int p, int l, int r) {     t[p].l = l, t[p].r = r;     if (l == r) {       t[p].sum = s[l];       t[p].lmx = max(s[l], 0);       t[p].rmn = min(s[l], 0);       t[p].ansl = t[p].ansr = t[p].ans = t[p].Ans = 1;       return;     }     int mid = (l + r) / 2;     build(p * 2, l, mid);     build(p * 2 + 1, mid + 1, r);     merge(p);   }   void change(int p, int x, int d) {     if (t[p].l == t[p].r) {       t[p].sum = d;       t[p].lmx = max(d, 0);       t[p].rmn = min(d, 0);       t[p].ansl = t[p].ansr = t[p].ans = t[p].Ans = 1;       return;     }     int mid = (t[p].l + t[p].r) / 2;     if (x <= mid)       change(p * 2, x, d);     else       change(p * 2 + 1, x, d);     merge(p);   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     scanf( %s , ss + 1);     for (int i = 1; i <= 2 * (n - 1); i++) s[i] = (ss[i] ==  (  ? 1 : -1);     build(1, 1, 2 * (n - 1));     printf( %d n , t[1].Ans);     for (int i = 1; i <= m; i++) {       int l, r;       scanf( %d%d , &l, &r);       if (s[l] == s[r]) {         printf( %d n , t[1].Ans);         continue;       }       change(1, l, s[r]);       change(1, r, s[l]);       swap(s[l], s[r]);       printf( %d n , t[1].Ans);     }   }


#include <bits/stdc++.h>   using namespace std;   long long a[300005];   long long s[300005];   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     int n, p, k;     cin >> n >> p >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       a[i] %= p;     }     map<long long, long long> cnt;     for (int i = 1; i <= n; i++) {       s[i] = a[i] * a[i] % p;       s[i] = s[i] * a[i] % p;       s[i] -= k;       s[i] = (s[i] % p + p) % p;       s[i] = s[i] * a[i] % p;       cnt[s[i]]++;     }     long long res = 0;     for (auto i : cnt) {       long long val = i.second * (i.second - 1) / 2;       res += val;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     string s;     cin >> s;     vector<string> splitted;     stringstream ss(s);     string item;     while (getline(ss, item,  , )) {       splitted.push_back(item);     }     int MAX = 1001;     vector<bool> a(MAX + 1);     for (const string& page : splitted) {       a[stoi(page)] = true;     }     vector<pair<int, int>> ret;     int p = 0;     while (p <= MAX) {       if (a[p]) {         int from = p;         int to = from;         while (a[to]) {           ++to;         }         ret.emplace_back(from, to - 1);         p = to;       } else {         ++p;       }     }     for (int i = 0; i < ret.size(); ++i) {       int from = ret[i].first;       int to = ret[i].second;       cout << from;       if (to != from) {         cout <<  -  << to;       }       if (i != ret.size() - 1) {         cout <<  , ;       }     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using ul = std::uint32_t;   using li = std::int32_t;   using ll = std::int64_t;   using ull = std::uint64_t;   using vul = std::vector<ul>;   using vvul = std::vector<vul>;   using pulul = std::pair<ul, ul>;   using lf = long double;   ul n, m;   const lf pi = std::acos(lf(-1));   const lf eps = 1e-7;   class point {    public:     lf x = 0;     lf y = 0;     lf rho = 0;     lf theta = 0;   };   class segment {    public:     lf s = 0;     lf t = 0;     ul id = 0;   };   point data[100000];   segment segs[300000];   std::vector<segment> segv;   ul f[300000];   ul g[300000];   lf inner(const point& a, const point& b) { return a.x * b.x + a.y * b.y; }   lf norm2(const point& a) { return inner(a, a); }   lf mysqrt(lf x) { return std::sqrt(std::max(x, lf(0))); }   lf norm(const point& a) { return mysqrt(norm2(a)); }   lf myasin(lf x) { return std::asin(std::max(lf(-1), std::min(lf(1), x))); }   lf myacos(lf x) { return std::acos(std::max(lf(-1), std::min(lf(1), x))); }   lf theta(const point& a) {     lf rho = norm(a);     lf x = a.x;     lf y = a.y;     if (x < 0) {       if (y < 0) {         return pi + myacos(-x / rho);       } else {         return pi - myacos(-x / rho);       }     } else {       if (y < 0) {         return pi + pi - myacos(x / rho);       } else {         return myacos(x / rho);       }     }   }   int main() {     std::scanf( %u%u , &n, &m);     lf mx = 1.5e5;     for (ul i = 0; i != n; ++i) {       double tx, ty;       std::scanf( %lf%lf , &tx, &ty);       data[i].x = tx;       data[i].y = ty;       data[i].rho = norm(data[i]);       data[i].theta = theta(data[i]);       mx = std::min(mx, data[i].rho);       if (data[i].x == 0 && data[i].y == 0) {         std::printf( %.20lf n , lf(0));         return 0;       }     }     lf mn = 0;     while (mx - mn > eps) {       lf mid = (mx + mn) * lf(0.5);       for (ul i = 0; i != n; ++i) {         lf temp = myacos(mid / data[i].rho);         segs[i].s = data[i].theta - temp;         segs[i].t = data[i].theta + temp;         segs[i + n].s = segs[i].s + pi + pi;         segs[i + n].t = segs[i].t + pi + pi;         segs[i + n + n].s = segs[i + n].s + pi + pi;         segs[i + n + n].t = segs[i + n].t + pi + pi;       }       std::sort(segs, segs + n + n + n,                 [](const segment& a, const segment& b) { return a.t < b.t; });       segv.resize(0);       for (ul i = 0; i != n + n + n; ++i) {         segs[i].id = i;         segv.push_back(segs[i]);       }       ul key = 4e5;       ul keyid = 0;       for (ul i = 0, j = 0; i != segv.size(); ++i) {         for (; j != segv.size() && segv[j].s <= segv[i].t; ++j) {           g[j] = i - 1;           if (j >= n && j < n + n) {             if (key > j - i) {               key = j - i;               keyid = j;             }           }         }         f[i] = j;       }       if (ull(key) * ull(m) >= ull(n)) {         mn = mid;         continue;       }       bool flag = false;       for (ul i = keyid; i != g[keyid]; --i) {         ul j;         ul cnt;         for (j = i, cnt = 0;              cnt != m && j != segv.size() && segv[j].id < segv[i].id + n;              j = f[j], ++cnt)           ;         if (j == segv.size() || segv[j].id >= segv[i].id + n) {           flag = true;           break;         }       }       if (flag) {         mn = mid;       } else {         mx = mid;       }     }     std::printf( %.20lf n , double(mn));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int l, r;   } ar[300000];   bool compare(node a, node b) {     if (a.r != b.r)       return a.r < b.r;     else       return a.l < b.l;   }   vector<pair<int, int> > vectl, vectn, temp;   int main() {     int n, i, m, flag = 0;     scanf( %d%d , &n, &m);     for (i = 0; i < m; i++) {       scanf( %d%d , &ar[i].l, &ar[i].r);     }     sort(ar, ar + m, compare);     int col = -1;     for (int j = 0; j < m; j++) {       if (ar[j].r != col) {         ar[i].l = n + 1;         ar[i].r = ar[j].r;         col = ar[j].r;         i++;       }     }     m = i;     sort(ar, ar + m, compare);     int row = ar[0].l, lastrow = 1, lastcol = ar[0].r;     i = 0;     col = ar[i].r;     while (ar[i].r == col) {       if (ar[i].l > lastrow) vectl.push_back(make_pair(lastrow, ar[i].l - 1));       lastrow = ar[i].l + 1;       i++;       if (col == 1) {         while (ar[i].r == 1) i++;         break;       }     }     col = ar[i].r;     while (i < m) {       if (ar[i].r > lastcol + 1) {         int st = vectl[0].first;         lastrow = 1;         while (ar[i].r == col) {           if (ar[i].l > lastrow && ar[i].l > st) {             vectn.push_back(make_pair(lastrow, ar[i].l - 1));           }           lastrow = ar[i].l + 1;           i++;           if (i >= m) break;         }       } else {         int j = 0;         lastrow = 1;         while (ar[i].r == col) {           while (j < vectl.size() && vectl[j].second < lastrow) j++;           if (j == vectl.size()) {             while (i < m && ar[i].r == col) i++;             break;           }           lastrow = max(vectl[j].first, lastrow);           if (ar[i].l > lastrow) {             vectn.push_back(make_pair(lastrow, ar[i].l - 1));           }           lastrow = ar[i].l + 1;           i++;           if (i >= m) break;         }       }       if (i >= m) {         vectl = vectn;         lastcol = ar[i - 1].r;         if (vectl.size() == 0) {           flag = 1;         }         break;       }       lastcol = col;       col = ar[i].r;       vectl = vectn;       vectn.clear();       if (vectl.size() == 0) {         flag = 1;         break;       }     }     if (flag == 1)       printf( -1 n );     else if (lastcol != n)       printf( %d n , n + n - 2);     else if (vectl[vectl.size() - 1].second == n)       printf( %d n , n + n - 2);     else       printf( -1 n );   }


#include <bits/stdc++.h>   using namespace std;   int n, v[100002], nr;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> v[i];     }     sort(v + 1, v + n + 1);     for (int i = 1; i <= n - 2; i++) {       if (v[i] + v[i + 1] > v[i + 2]) nr++;     }     if (nr == 0)       cout <<  NO n ;     else       cout <<  YES n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M, T;   char str[1005];   int main() {     int i, j, k;     scanf( %d , &N);     scanf( %s , str);     for (i = 0; i < N; i++)       if (str[i] ==  H ) M++;     int Mc = 1005;     k = 0;     for (i = 0; i < M; i++)       if (str[i] !=  H ) k++;     int st = 0;     if (k < Mc) Mc = k;     for (i = M; i < N; i++) {       if (str[st] !=  H ) k--;       st++;       if (str[i] !=  H ) k++;       if (k < Mc) Mc = k;     }     M = 0;     for (i = 0; i < N; i++)       if (str[i] ==  T ) M++;     k = 0;     for (i = 0; i < M; i++)       if (str[i] ==  H ) k++;     st = 0;     if (k < Mc) Mc = k;     for (i = M; i < N; i++) {       if (str[st] ==  H ) k--;       st++;       if (str[i] ==  H ) k++;       if (k < Mc) Mc = k;     }     printf( %d n , Mc);     scanf(   );   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     long long store[100005] = {};     for (long long i = 1; i <= n; i++) {       long long x, y;       cin >> x >> y;       y = i - y;       long long ct = 0;       for (long long j = 1; j * j <= x; j++) {         if (x % j == 0) {           if (store[j] < y) ct++;           if (j != x / j && store[x / j] < y) ct++;           store[j] = i;           store[x / j] = i;         }       }       cout << ct <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T in() {     char ch;     T n = 0;     bool ng = false;     while (1) {       ch = getchar();       if (ch ==  - ) {         ng = true;         ch = getchar();         break;       }       if (ch >=  0  && ch <=  9 ) break;     }     while (1) {       n = n * 10 + (ch -  0 );       ch = getchar();       if (ch <  0  || ch >  9 ) break;     }     return (ng ? -n : n);   }   template <typename T>   inline T POW(T B, T P) {     if (P == 0) return 1;     if (P & 1)       return B * POW(B, P - 1);     else       return (POW(B, P / 2) * POW(B, P / 2));   }   template <typename T>   inline T Gcd(T a, T b) {     if (a < 0) return Gcd(-a, b);     if (b < 0) return Gcd(a, -b);     return (b == 0) ? a : Gcd(b, a % b);   }   template <typename T>   inline T Lcm(T a, T b) {     if (a < 0) return Lcm(-a, b);     if (b < 0) return Lcm(a, -b);     return a * (b / Gcd(a, b));   }   long long Bigmod(long long base, long long power, long long MOD) {     long long ret = 1;     while (power) {       if (power & 1) ret = (ret * base) % MOD;       base = (base * base) % MOD;       power >>= 1;     }     return ret;   }   bool isVowel(char ch) {     ch = toupper(ch);     if (ch ==  A  || ch ==  U  || ch ==  I  || ch ==  O  || ch ==  E )       return true;     return false;   }   template <typename T>   long long int isLeft(T a, T b, T c) {     return (a.x - b.x) * (b.y - c.y) - (b.x - c.x) * (a.y - b.y);   }   long long ModInverse(long long number, long long MOD) {     return Bigmod(number, MOD - 2, MOD);   }   bool isConst(char ch) {     if (isalpha(ch) && !isVowel(ch)) return true;     return false;   }   int toInt(string s) {     int sm;     stringstream second(s);     second >> sm;     return sm;   }   long long int a[200007];   int main() {     int n;     n = in<int>();     for (int i = 1; i < n + 1; i++) a[i] = in<long long int>();     int m;     m = in<int>();     long long int last = 0;     while (m--) {       int w, h;       w = in<int>(), h = in<int>();       long long int ans = max(last, a[w]);       printf( %lld n , ans);       last = ans + h;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, A;   int level[10], loyal[10];   double maxP;   void backtrack(int p, int k) {     if (p == n || k == 0) {       double x = 0;       for (int mask = 0; mask < (1 << n); mask++) {         int cnt = 0, B = 0;         double prob = 1.0;         for (int i = 0; i < n; i++) {           if (mask & (1 << i)) {             prob *= loyal[i] / 100.0;             cnt++;           } else {             prob *= (100 - loyal[i]) / 100.0;             B += level[i];           }         }         if (2 * cnt > n)           x += prob;         else           x += prob * A / (A + B);       }       maxP = max(maxP, x);     } else {       backtrack(p + 1, k);       if (loyal[p] < 100) {         loyal[p] += 10;         backtrack(p, k - 1);         loyal[p] -= 10;       }     }   }   int main() {     int k;     while (cin >> n >> k >> A) {       for (int i = 0; i < n; i++) cin >> level[i] >> loyal[i];       maxP = 0;       backtrack(0, k);       printf( %.10lf n , maxP);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class U>   void Max(T &a, U b) {     if (a < b) a = b;   }   template <class T, class U>   void Min(T &a, U b) {     if (a > b) a = b;   }   template <class T, class U>   void add(T &a, U b) {     a += b;     if (a >= 1000000007) a -= 1000000007;   }   template <class T, class U>   int min(T a, U b) {     return a >= b ? b : a;   }   int ans, first[50010], second[50010], a[50010], b[50010], res[50010], g[10240];   void out(int i, int j) {     cout <<  ?   << i <<     << j <<   n ;     cin >> ans;     fflush(stdout);   }   int main() {     int i, j, k, ca = 0, n, T, m = 0, K;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       out(i, i);       b[i] = ans;       out(i, 0);       a[i] = ans;     }     ans = 0;     int M = 4096 * 2;     for (int i = 0; i < n; i++) {       first[i] = 0;       for (int j = 0; j < n; j++) g[j] = -1;       int ok = 1;       for (int j = 0; j < n; j++) {         k = a[i] ^ a[j];         if (k >= n) {           ok = 0;           break;         }         g[k] = j;       }       if (!ok) continue;       for (int j = 0; j < n; j++) {         if (g[j] == -1) {           ok = 0;           break;         }         k = g[j];         first[k] = j;       }       if (!ok) continue;       for (int j = 0; j < n; j++) second[first[j]] = j;       for (int j = 0; j < n; j++) {         if ((first[j] ^ second[j]) != b[j]) {           ok = 0;           break;         }       }       if (!ok) continue;       for (int j = 0; j < n; j++) {         if ((first[j] ^ second[0]) != a[j]) {           ok = 0;           break;         }       }       if (!ok) continue;       ans++;       for (int j = 0; j < n; j++) res[j] = first[j];     }     printf( ! n%d n , ans);     for (int i = 0; i < n; i++) printf( %d  , res[i]);     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   int n, A[5001], B[5001], S[5001], ma, man;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> A[i];     for (int i = 1; i <= n; i++) {       for (int j = i; j <= n; j++) {         S[A[j]]++;         if (S[A[j]] > ma || (S[A[j]] == ma && A[j] < man)) {           ma = S[A[j]];           man = A[j];         }         B[man]++;       }       ma = 0;       for (int j = 1; j <= n; j++) S[j] = 0;     }     for (int i = 1; i <= n; i++) cout << B[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 132222;   const long long mod = 1000000007;   char s[maxn];   int main() {     int n;     cin >> n;     cin >> s + 1;     int len = strlen(s + 1);     int l = -1, r = -1;     for (int i = (1); i < (len + 1); i++) {       if (s[i] ==  L  && l == -1) l = i;       if (s[i] ==  R  && r == -1) r = i;     }     if (l != -1 && r == -1) {       int x;       for (int i = len; i >= 1; i--) {         if (s[i] ==  L ) {           x = i;           break;         }       }       cout << x <<     << l - 1 << endl;       return 0;     }     if (l == -1 && r != -1) {       int x;       for (int i = len; i >= 1; i--) {         if (s[i] ==  R ) {           x = i;           break;         }       }       cout << r <<     << x + 1 << endl;       return 0;     }     if (l != -1 && r != -1) {       cout << r <<     << l - 1 << endl;       return 0;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 5e2 + 10;   const int P = 239017;   const int INF = 1e9;   const int MOD = 1e9 + 7;   int dp[MaxN][MaxN][2], n, m, q;   char s[MaxN][MaxN];   int get(int xl, int yl, int xr, int yr, int c) {     if (c == 0 && xl > xr) {       return 0;     }     if (c == 1 && yl > yr) {       return 0;     }     return dp[xr][yr][c] + dp[xl - 1][yl - 1][c] - dp[xr][yl - 1][c] -            dp[xl - 1][yr][c];   }   int main() {     scanf( %d%d n , &n, &m);     for (int i = 1; i <= n; ++i) {       gets(s[i] + 1);     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         dp[i][j][0] = dp[i - 1][j][0] + dp[i][j - 1][0] - dp[i - 1][j - 1][0] +                       (s[i - 1][j] == s[i][j] && s[i][j] ==  . );         dp[i][j][1] = dp[i - 1][j][1] + dp[i][j - 1][1] - dp[i - 1][j - 1][1] +                       (s[i][j - 1] == s[i][j] && s[i][j] ==  . );       }     }     scanf( %d , &q);     while (q-- > 0) {       int xl, yl, xr, yr;       scanf( %d%d%d%d , &xl, &yl, &xr, &yr);       printf( %d n , get(xl + 1, yl, xr, yr, 0) + get(xl, yl + 1, xr, yr, 1));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool uin(T &a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   bool uax(T &a, T b) {     return a < b ? (a = b, true) : false;   }   const int maxn = 210000;   vector<int> e[maxn];   int h[maxn];   void dfsh(int v, int p) {     h[v] = 0;     for (int u : e[v]) {       if (u == p) continue;       dfsh(u, v);       uax(h[v], h[u] + 1);     }     sort((e[v]).begin(), (e[v]).end(), [&](int u, int w) { return h[u] > h[w]; });   }   vector<int> ord;   void dfsord(int v, int p, int l) {     bool anyc = false;     for (int u : e[v]) {       if (u == p) continue;       if (!anyc)         dfsord(u, v, l + 1), anyc = true;       else         dfsord(u, v, 1);     }     int r = !anyc ? l : 0;     ord.push_back(r);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(10);     cout << fixed;     int n, k;     cin >> n >> k;     for (int i = 0; i < (int)(n - 1); ++i) {       int u, v;       cin >> u >> v;       --u;       --v;       e[u].push_back(v);       e[v].push_back(u);     }     dfsh(0, -1);     dfsord(0, -1, 1);     sort((ord).rbegin(), (ord).rend());     long long W = n;     long long ans = -1LL * (n / 2) * (n - n / 2);     for (int i = 0; i < (int)(k); ++i) {       W -= ord[i];       long long b = n / 2, r = i + 1;       long long res = 1e18;       if (b <= W) uin(res, (n - r - b) * (r - b));       if (b + 1 <= W) uin(res, (n - r - b - 1) * (r - b - 1));       uin(res, (n - r - W) * (r - W));       uax(ans, res);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 510;   const int MOD = 1e9 + 7;   long long dp[2][maxn][maxn];   int N, M;   char s[maxn][maxn];   void add(long long &x, long long y) {     x += y;     if (x >= MOD) x -= MOD;   }   int main() {     scanf( %d%d , &N, &M);     for (int i = 1; i <= N; i++) scanf( %s , s[i] + 1);     dp[0][1][N] = (s[1][1] == s[N][M]);     int cur = 0;     for (int step = 1; step <= (M + N - 2) / 2; step++) {       cur ^= 1;       for (int i = 0; i <= N; i++)         for (int j = 1; j <= N; j++) dp[cur][i][j] = 0;       for (int x1 = 1; x1 <= N && x1 - 1 <= step; x1++) {         for (int x2 = N; x2 >= 1 && N - x2 <= step; x2--) {           int y1 = 1 + step - (x1 - 1);           int y2 = M - (step - (N - x2));           if (s[x1][y1] != s[x2][y2]) continue;           add(dp[cur][x1][x2], dp[cur ^ 1][x1][x2]);           add(dp[cur][x1][x2], dp[cur ^ 1][x1][x2 + 1]);           add(dp[cur][x1][x2], dp[cur ^ 1][x1 - 1][x2]);           add(dp[cur][x1][x2], dp[cur ^ 1][x1 - 1][x2 + 1]);         }       }     }     long long ans = 0;     for (int i = 1; i <= N; i++) {       add(ans, dp[cur][i][i]);     }     if ((N + M) % 2) {       for (int i = 1; i < N; i++) add(ans, dp[cur][i][i + 1]);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v1[3010], v2[3010];   int dista[3010][3010], distb[3010][3010];   pair<int, int> besta[3010][3], bestb[3010][3];   int n, m;   void dijkstra(int x) {     for (int i = 1; i <= n; i++) dista[x][i] = 1000000009;     dista[x][x] = 0;     priority_queue<pair<int, int> > q;     q.push(make_pair(0, x));     while (!q.empty()) {       pair<int, int> t = q.top();       q.pop();       int u = t.second;       for (int i = 0; i < v1[u].size(); i++) {         if (dista[x][v1[u][i]] > dista[x][u] + 1) {           dista[x][v1[u][i]] = dista[x][u] + 1;           q.push(make_pair(-dista[x][v1[u][i]], v1[u][i]));         }       }     }     for (int i = 1; i <= n; i++) {       if (dista[x][i] != 1000000009 && dista[x][i] > besta[x][0].first)         besta[x][2] = besta[x][1], besta[x][1] = besta[x][0],         besta[x][0] = make_pair(dista[x][i], i);       else if (dista[x][i] != 1000000009 && dista[x][i] > besta[x][1].first)         besta[x][2] = besta[x][1], besta[x][1] = make_pair(dista[x][i], i);       else if (dista[x][i] != 1000000009 && dista[x][i] > besta[x][2].first)         besta[x][2] = make_pair(dista[x][i], i);     }   }   void dijkstra2(int x) {     for (int i = 1; i <= n; i++) distb[x][i] = 1000000009;     distb[x][x] = 0;     priority_queue<pair<int, int> > q;     q.push(make_pair(0, x));     while (!q.empty()) {       pair<int, int> t = q.top();       q.pop();       int u = t.second;       for (int i = 0; i < v2[u].size(); i++) {         if (distb[x][v2[u][i]] > distb[x][u] + 1) {           distb[x][v2[u][i]] = distb[x][u] + 1;           q.push(make_pair(-distb[x][v2[u][i]], v2[u][i]));         }       }     }     for (int i = 1; i <= n; i++) {       if (distb[x][i] != 1000000009 && distb[x][i] > bestb[x][0].first)         bestb[x][2] = bestb[x][1], bestb[x][1] = bestb[x][0],         bestb[x][0] = make_pair(distb[x][i], i);       else if (distb[x][i] != 1000000009 && distb[x][i] > bestb[x][1].first)         bestb[x][2] = bestb[x][1], bestb[x][1] = make_pair(distb[x][i], i);       else if (distb[x][i] != 1000000009 && distb[x][i] > bestb[x][2].first)         bestb[x][2] = make_pair(distb[x][i], i);     }   }   int main() {     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       v1[x].push_back(y);       v2[y].push_back(x);     }     int ans = -1, ansa, ansb, ansc, ansd;     for (int i = 1; i <= n; i++) dijkstra(i);     for (int i = 1; i <= n; i++) dijkstra2(i);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         for (int a = 0; a < 3; a++) {           for (int d = 0; d < 3; d++) {             int aa = bestb[i][a].second, dd = besta[j][d].second;             if (aa == 0 || dd == 0) continue;             if (i == j || i == aa || i == dd || j == aa || j == dd || aa == dd)               continue;             if (bestb[i][a].first == 1000000009 ||                 besta[j][d].first == 1000000009 || dista[i][j] == 1000000009)               continue;             int val = bestb[i][a].first + besta[j][d].first + dista[i][j];             if (val > ans) {               ans = val;               ansa = aa;               ansb = i;               ansc = j;               ansd = dd;             }           }         }       }     }     cout << ansa <<     << ansb <<     << ansc <<     << ansd << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10, mod = 1e9 + 7;   const long long infl = LLONG_MAX / 2;   int n, ans, h[N];   vector<int> g[N], L;   void dfs(int u = 0, int p = -1) {     bool leaf = 1;     for (int x : g[u])       if (x - p) {         h[x] = h[u] + 1;         dfs(x, u);         leaf = 0;       }     if (leaf) L.push_back(h[u]);     if (h[u] == 1) {       sort(L.begin(), L.end());       int now = 0;       for (int i = 0; i < L.size(); ++i) {         now = max(now + 1, L[i]);       }       ans = max(ans, now - 1);       L.clear();     }   }   int main() {     cin >> n;     for (int i = 0; i < n - 1; ++i) {       int u, v;       scanf( %d %d , &u, &v);       --u;       --v;       g[u].push_back(v);       g[v].push_back(u);     }     dfs();     cout << ans + 1;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string x, y, z;     int a = 0, c = 0;     cin >> x;     cin >> y;     cin >> z;     for (int i = 0; i < x.length(); i++) {       for (int j = 0; j < z.length(); j++) {         if (x[i] == z[j]) {           c += 1;           z[j] =  1 ;           break;         }       }     }     for (int i = 0; i < y.length(); i++) {       for (int j = 0; j < z.length(); j++) {         if (y[i] == z[j]) {           a += 1;           z[j] =  1 ;           break;         }       }     }     if (c + a == z.length() && a == y.length() && c == x.length())       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math )   long long comb(long long n, long long r) {     if (r < 0 || r > n) return 0;     if ((n - r) < r) r = n - r;     long long vec = 1;     for (long long i = n; i > n - r; --i) {       vec = vec * i;     }     for (long long i = 1; i < r + 1; ++i) {       vec = vec / i;     }     return vec;   }   template <typename T>   void press(T &v) {     v.erase(unique(v.begin(), v.end()), v.end());   }   long long small(vector<long long> &vec, long long first) {     return lower_bound(vec.begin(), vec.end(), first) - vec.begin();   }   long long osmall(vector<long long> &vec, long long first) {     return upper_bound(vec.begin(), vec.end(), first) - vec.begin();   }   long long big(vector<long long> &vec, long long first) {     return vec.size() - osmall(vec, first);   }   long long obig(vector<long long> &vec, long long first) {     return vec.size() - small(vec, first);   }   long long freq(vector<long long> &vec, long long first) {     return upper_bound(vec.begin(), vec.end(), first) -            lower_bound(vec.begin(), vec.end(), first);   }   long long maxa(vector<long long> &vec) {     return max_element(vec.begin(), vec.end()) - vec.begin();   }   long long mina(vector<long long> &vec) {     return min_element(vec.begin(), vec.end()) - vec.begin();   }   long long Set(long long qq, long long pos) { return (qq | (1 << pos)); }   long long chk(long long qq, long long pos) { return (qq & (1 << pos)); }   long long bits(long long qq) { return __builtin_popcount(qq); }   long long p2[32];   long long modpow(long long first, long long n, long long m) {     if (n == 0) return 1 % m;     long long u = modpow(first, n / 2, m);     u = (u * u) % m;     if (n % 2 == 1) u = (u * first) % m;     return u;   }   long long _pow(long long vec, long long b) {     if (!b) return 1;     long long temp = _pow(vec, b / 2);     temp = (temp * temp);     if (b % 2) return (vec * temp);     return temp;   }   long long cl(long long vec, long long b) {     if (vec % b) return 1 + vec / b;     return vec / b;   }   long long dx[] = {0, 0, -1, 1};   long long dy[] = {1, -1, 0, 0};   const long long MOD = 1e9 + 7;   const long long inf = 1e18;   const long long N = 1e4 + 5;   const long long K = 1e3 + 10;   void solve() {     vector<long long> v;     long long n, ans = 0;     cin >> n;     if (n == 1) {       cin >> n;       cout << 0 << endl;       return;     }     for (long long i = 0; i < n; i++) {       long long val;       long long s = v.size();       cin >> val;       while (s > 1 && v[s - 1] <= val && v[s - 1] <= v[s - 2]) {         ans += min(val, v[s - 2]);         v.pop_back();         s--;       }       v.push_back(val);     }     sort(v.begin(), v.end());     for (long long i = 0; i < v.size() - 2; i++) ans += v[i];     cout << ans << endl;   }   signed main() {     for (long long i = 0; i < 32; i++) p2[i] = (1 << i);     cout << fixed << setprecision(12);     long long t;     t = 1;     for (long long i = 1; i <= t; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   bool a[20][2][1 << 17];   int ans = 1234, ami, apl;   void solve(int ind, int mx, int mi, int pl, int res) {     if (ind > 18) {       return;     }     if (mx == 0) {       if (res < ans) {         ans = res;         ami = mi;         apl = pl;       }       return;     }     for (int j = 0; j < (int)(2); ++j)       for (int i = 0; i < (int)(mx + 1); ++i) {         a[ind + 1][j][i] = false;       }     bool ok = true;     for (int j = 0; j < (int)(2); ++j)       for (int i = 1; i <= mx; i += 2)         if (a[ind][j][i]) {           ok = false;         }     int nmx = 0;     if (ok) {       for (int j = 0; j < (int)(2); ++j)         for (int i = 0; i < (int)(mx + 1); ++i)           if (a[ind][j][i]) {             int ni = i >> 1;             if (ni != 0) {               a[ind + 1][j][ni] = true;               nmx = max(nmx, ni);             }           }       solve(ind + 1, nmx, mi, pl, res);     } else {       for (int i = 0; i < (int)(mx + 1); ++i)         if (a[ind][0][i]) {           int ni = i >> 1;           if (ni != 0) {             a[ind + 1][0][ni] = true;             nmx = max(nmx, ni);           }         }       for (int i = 0; i < (int)(mx + 1); ++i)         if (a[ind][1][i]) {           int ni = i;           if (ni & 1) {             ++ni;           }           ni >>= 1;           if (ni != 0) {             a[ind + 1][1][ni] = true;             nmx = max(nmx, ni);           }         }       solve(ind + 1, nmx, mi, pl | (1 << ind), res + 1);       nmx = 0;       for (int j = 0; j < (int)(2); ++j)         for (int i = 0; i < (int)(mx + 1); ++i) {           a[ind + 1][j][i] = false;         }       for (int i = 0; i < (int)(mx + 1); ++i)         if (a[ind][1][i]) {           int ni = i >> 1;           if (ni != 0) {             a[ind + 1][1][ni] = true;             nmx = max(nmx, ni);           }         }       for (int i = 0; i < (int)(mx + 1); ++i)         if (a[ind][0][i]) {           int ni = i;           if (ni & 1) {             ++ni;           }           ni >>= 1;           if (ni != 0) {             a[ind + 1][0][ni] = true;             nmx = max(nmx, ni);           }         }       solve(ind + 1, nmx, mi | (1 << ind), pl, res + 1);     }   }   int main() {     scanf( %d , &n);     int mx = 0;     for (int i = 0; i < (int)(n); ++i) {       int x;       scanf( %d , &x);       if (x > 0) {         a[0][0][x] = true;         mx = max(mx, x);       }       if (x < 0) {         a[0][1][-x] = true;         mx = max(mx, -x);       }     }     solve(0, mx, 0, 0, 0);     printf( %d n , ans);     for (int i = 0; i < (int)(20); ++i)       if (apl & (1 << i)) {         printf( %d  , 1 << i);       } else if (ami & (1 << i)) {         printf( %d  , -(1 << i));       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   const int cipher = -1e9;   template <typename T>   void chkmax(T &x, T y) {     x = max(x, y);   }   template <typename T>   void chkmin(T &x, T y) {     x = min(x, y);   }   template <typename T>   void read(T &x) {     x = 0;     int f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     x *= f;   }   template <typename T>   void write(T x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   template <typename T>   void writeln(T x) {     write(x);     puts(  );   }   struct SegmentTree {     struct Node {       int lc, rc;       int tag, Max, depth;     } a[MAXN * 2];     int root, size, n, depth[MAXN];     void update(int root) {       a[root].Max = max(a[a[root].lc].Max, a[a[root].rc].Max);       a[root].depth = max(a[a[root].lc].depth, a[a[root].rc].depth);     }     void build(int &root, int l, int r) {       root = ++size;       a[root].Max = -2e9;       a[root].tag = cipher;       if (l == r) {         a[root].depth = depth[l];         return;       }       int mid = (l + r) / 2;       build(a[root].lc, l, mid);       build(a[root].rc, mid + 1, r);       update(root);     }     void init(int x, int *y) {       n = x, size = 0;       for (int i = 1; i <= n; i++) depth[i] = 2 * y[i];       build(root, 1, n);     }     void pushdown(int root) {       if (a[root].tag != cipher && a[root].lc) {         a[a[root].lc].Max = a[root].tag + a[a[root].lc].depth;         a[a[root].lc].tag = a[root].tag;         a[a[root].rc].Max = a[root].tag + a[a[root].rc].depth;         a[a[root].rc].tag = a[root].tag;         a[root].tag = cipher;       }     }     void modify(int root, int l, int r, int ql, int qr, int x) {       if (l == ql && r == qr) {         a[root].Max = x + a[root].depth;         a[root].tag = x;         return;       }       pushdown(root);       int mid = (l + r) / 2;       if (mid >= ql) modify(a[root].lc, l, mid, ql, min(mid, qr), x);       if (mid + 1 <= qr) modify(a[root].rc, mid + 1, r, max(mid + 1, ql), qr, x);       update(root);     }     void modify(int l, int r, int x) { modify(root, 1, n, l, r, x); }     int query(int root, int l, int r, int ql, int qr, int x) {       pushdown(root);       int mid = (l + r) / 2;       if (l == ql && r == qr) {         if (l == r) {           if (a[root].Max > x)             return l;           else             return l - 1;         }         if (a[a[root].rc].Max > x)           return query(a[root].rc, mid + 1, r, mid + 1, r, x);         else           return query(a[root].lc, l, mid, l, mid, x);       }       if (mid >= qr) return query(a[root].lc, l, mid, ql, qr, x);       if (mid + 1 <= ql) return query(a[root].rc, mid + 1, r, ql, qr, x);       int tans = query(a[root].rc, mid + 1, r, mid + 1, qr, x);       if (tans == mid)         return query(a[root].lc, l, mid, ql, mid, x);       else         return tans;     }     int query(int l, int r, int x) { return query(root, 1, n, l, r, x); }   } ST;   vector<int> a[MAXN], points[MAXN];   int y[MAXN], t[MAXN], p[MAXN], ans[MAXN], val[MAXN];   int n, m, depth[MAXN], size[MAXN], son[MAXN];   int timer, father[MAXN], dfn[MAXN], up[MAXN];   void dfs(int pos, int fa) {     depth[pos] = depth[fa] + 1;     size[pos] = 1, son[pos] = 0;     for (auto x : a[pos])       if (x != fa) {         dfs(x, pos);         size[pos] += size[x];         if (size[x] > size[son[pos]]) son[pos] = x;       }   }   void efs(int pos, int fa, int from) {     up[pos] = from;     father[pos] = fa;     dfn[pos] = ++timer;     points[from].push_back(pos);     if (son[pos]) efs(son[pos], pos, from);     for (auto x : a[pos])       if (x != son[pos] && x != fa) efs(x, pos, x);   }   bool cmp(int a, int b) {     if (t[a] + depth[y[a]] == t[b] + depth[y[b]])       return y[a] < y[b];     else       return t[a] + depth[y[a]] < t[b] + depth[y[b]];   }   int main() {     read(n), read(m);     for (int i = 2; i <= n + 1; i++) {       int x;       read(x), x++;       a[x].push_back(i);     }     dfs(1, 0);     efs(1, 0, 1);     for (int i = 1; i <= m; i++) {       read(y[i]), y[i]++;       read(t[i]), p[i] = i;     }     sort(p + 1, p + m + 1, cmp);     static int tmp[MAXN];     for (int i = 1; i <= n + 1; i++) tmp[dfn[i]] = depth[i];     ST.init(n + 1, tmp);     ST.modify(1, 1, 2e9);     for (int i = 1; i <= m; i++) {       int pos = y[p[i]], x = pos, res = 0;       while (true) {         int f = up[x];         int tmp = ST.query(dfn[f], dfn[x], depth[pos] + t[p[i]]);         if (tmp == dfn[f] - 1)           res += dfn[x] - dfn[f] + 1;         else {           res += dfn[x] - tmp;           break;         }         x = father[f];       }       x = pos;       ans[p[i]] = t[p[i]] + 2 * res;       int tres = res;       while (tres) {         int f = up[x];         if (tres <= dfn[x] - dfn[f] + 1) {           ST.modify(dfn[x] - tres + 1, dfn[x], t[p[i]] + 2 * res - depth[pos]);           break;         } else {           tres -= dfn[x] - dfn[f] + 1;           ST.modify(dfn[f], dfn[x], t[p[i]] + 2 * res - depth[pos]);         }         x = father[f];       }     }     for (int i = 1; i <= m; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T sqr(T x) {     return x * x;   }   template <class T>   T gcd(T a, T b) {     return (b != 0 ? gcd<T>(b, a % b) : a);   }   template <class T>   T lcm(T a, T b) {     return (a / gcd<T>(a, b) * b);   }   template <class T>   inline T bigmod(T p, T e, T M) {     if (e == 0) return 1;     if (e % 2 == 0) {       long long int t = bigmod(p, e / 2, M);       return (T)((t * t) % M);     }     return (T)((long long int)bigmod(p, e - 1, M) * (long long int)p) % M;   }   template <class T>   inline T bigexp(T p, T e) {     if (e == 0) return 1;     if (e % 2 == 0) {       long long int t = bigexp(p, e / 2);       return (T)((t * t));     }     return (T)((long long int)bigexp(p, e - 1) * (long long int)p);   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   int dx4[] = {1, 0, -1, 0};   int dy4[] = {0, 1, 0, -1};   int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};   int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};   int nx8[] = {1, 1, -1, -1, 2, 2, -2, -2};   int ny8[] = {2, -2, 2, -2, 1, -1, 1, -1};   int month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int n, a[100005], b[100005], c, com;   vector<int> v[100005];   map<int, int> m;   bool bl[100005];   void dfs(int p) {     if (bl[p]) return;     bl[p] = true;     v[com].push_back(p);     dfs(b[p]);   }   int main() {     scanf( %d , &n);     for (__typeof(n) i = (1); i <= (n); i++) scanf( %d , &a[i]);     for (__typeof(n) i = (1); i <= (n); i++) b[i] = a[i];     sort(b + 1, b + n + 1);     for (__typeof(n) i = (1); i <= (n); i++) m[b[i]] = ++c;     for (__typeof(n) i = (1); i <= (n); i++) b[i] = m[a[i]];     for (int i = 1; i <= n; i++) {       if (bl[i] == false) {         ++com;         dfs(i);       }     }     cout << com, printf(  n );     for (__typeof(com) i = (1); i <= (com); i++) {       printf( %d , (int)v[i].size());       for (int j = 0; j < (int)v[i].size(); j++) printf(  %d , v[i][j]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int t;   int n;   string a, b;   int op[N];   int opb[N];   int bp = 0;   int ans = 0;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> t;     while (t--) {       cin >> n;       ans = 0;       cin >> a;       cin >> b;       if (a == b) {         cout << 0 << endl;         continue;       }       char st = a[0];       for (int i = 1; i < n; i++) {         if (a[i] != st) {           op[++ans] = i;           st = a[i];         }       }       if (a[n - 1] ==  0 ) op[++ans] = n;       st = b[0];       bp = 0;       for (int i = 1; i < n; i++) {         if (b[i] != st) {           opb[++bp] = i;           st = b[i];         }       }       if (b[n - 1] ==  0 ) opb[++bp] = n;       cout << ans + bp;       for (int i = 1; i <= ans; i++) cout <<     << op[i];       for (int i = bp; i >= 1; i--) cout <<     << opb[i];       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     if (n > 5 * m) {       cout <<  YES ;       return 0;     }     bool dp[n][m + 1];     for (int i = 0; i <= m; i++) dp[0][i] = false;     for (int i = 0; i < n; i++) dp[i][0] = true;     if (arr[0] % m == 0)       dp[0][m] = true;     else       dp[0][arr[0] % m] = true;     for (int i = 1; i < n; i++) {       for (int j = 1; j <= m; j++)         dp[i][j] = dp[i - 1][j] || dp[i - 1][(j - (arr[i] % m) + m) % m];     }     if (dp[n - 1][m])       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   long long __gcd(long long a, long long b) {     while (a != 0) {       long long __t = b % a;       b = a;       a = __t;     }     return b;   }   bool isSimple(unsigned x) {     for (unsigned i = 2; i < x; i++)       if (x % i == 0) return false;     return true;   }   int main() {     cin.tie(0);     cout.tie(0);     cerr.tie(0);     ios_base::sync_with_stdio(false);     long long x;     cin >> x;     cout << x - x / 2 - x / 3 - x / 5 - x / 7 + x / 6 + x / 10 + x / 14 + x / 15 +                 x / 21 + x / 35 - x / 30 - x / 42 - x / 70 - x / 105 + x / 210;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, b;     while (~scanf( %d%d , &n, &b)) {       int a[2050];       int m = -999;       for (int i = 0; i < n; i++) scanf( %d , a + i);       for (int i = 0; i < n - 1; i++) {         int z = b / a[i];         for (int j = i + 1; j < n; j++) {           m = max(m, (a[j] - a[i]) * z + b);         }       }       if (m > b)         printf( %d n , m);       else         printf( %d n , b);     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   char s[200001];   long long a[26];   long long cnt = 0;   int main() {     long long i, j, k, l, m, n, t;     cin >> t;     cin >> s;     l = strlen(s);     for (i = 0; i < 26; i++) a[i] = 0;     for (i = 1; i < l; i = i + 2) {       if ((s[i - 1] - 97) != (s[i] - 65)) {         if (a[s[i] - 65] > 0) {           a[s[i] - 65]--;           a[s[i - 1] - 97]++;         } else {           cnt++;           a[s[i - 1] - 97]++;         }       }     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( -O3 )   using namespace std;   const long long mod = 998244353;   struct edge {     int u, v, cap;     edge() {}     edge(int _u, int _v, int _cap) : u(_u), v(_v), cap(_cap) {}     int get(int t) { return t ^ u ^ v; }   };   const int inf = 1e9;   struct edkarp {     vector<edge> edges;     vector<vector<int>> adj;     int n;     void init(int _n) {       n = _n;       adj.assign(n, vector<int>(0));     }     inline int comp(int i) { return i ^ 1; }     inline int par(int i, int ed) { return edges[ed].get(i); }     void add(int u, int v, int c) {       adj[u].emplace_back(edges.size());       edges.emplace_back(u, v, c);       adj[v].emplace_back(edges.size());       edges.emplace_back(u, v, 0);     }     int bfs(int st, int tar, vector<int> &p) {       p.assign(n, -1);       p[st] = -2;       queue<pair<int, int>> q;       q.push(make_pair(st, inf));       while (!q.empty()) {         int i = q.front().first, flow = q.front().second;         q.pop();         for (auto &x : adj[i]) {           if (p[par(i, x)] == -1 && edges[x].cap) {             p[par(i, x)] = x;             int nf = min(flow, edges[x].cap);             if (par(i, x) == tar) {               return nf;             }             q.push(make_pair(par(i, x), nf));           }         }       }       return 0;     }     int maxflow(int st, int tar) {       vector<int> p(n);       int flow = 0;       int nf;       while (nf = bfs(st, tar, p)) {         flow += nf;         int cr = tar;         while (cr != st) {           edges[p[cr]].cap -= nf;           edges[comp(p[cr])].cap += nf;           cr = par(cr, p[cr]);         }       }       return flow;     }   };   struct edgeg {     int u, v, c, lo;     bool in_loop = false;     edgeg() {}     edgeg(int _u, int _v, int _c) : u(_u), v(_v), c(_c), lo(-1) {}     int get(int t) { return t ^ u ^ v; }   };   const int N = 1e4 + 5;   int n, m, u, v, c, vis[N], p[N], vis1[N];   vector<int> adj[N];   vector<bool> avai;   vector<vector<int>> loops;   vector<edgeg> edges;   edkarp fo;   inline int geta(int x, int edge_num) { return edges[edge_num].get(x); }   void dfs(int i, int par) {     vis[i] = 1;     vis1[i] = 1;     for (int x : adj[i]) {       int u = geta(i, x);       if (u == par) continue;       if (vis[u]) {         if (!vis1[u]) continue;         edges[x].in_loop = true;         vector<int> clrs;         clrs.push_back(edges[x].c);         u = i;         while (u != geta(i, x)) {           edges[p[u]].in_loop = true;           clrs.push_back(edges[p[u]].c);           u = geta(u, p[u]);         }         sort(clrs.begin(), clrs.end());         auto it = unique(clrs.begin(), clrs.end());         if (it != clrs.end()) {           for (auto it1 = clrs.begin(); it1 != it; it1++) {             avai[*it1] = 1;           }         } else {           loops.push_back(clrs);         }       } else {         p[u] = x;         dfs(u, i);       }     }     vis1[i] = 0;   }   void solve() {     cin >> n >> m;     avai.assign(m, 0);     for (int i = 0; i < m; i++) {       cin >> u >> v >> c;       u--, v--, c--;       adj[u].push_back(edges.size());       adj[v].push_back(edges.size());       edges.emplace_back(u, v, c);     }     fill(vis, vis + n, 0);     fill(vis1, vis1 + n, 0);     dfs(0, -1);     int cr = 0;     for (int i = 0; i < (int)edges.size(); i++) {       if (!edges[i].in_loop) {         avai[edges[i].c] = 1;       }     }     fo.init((int)loops.size() + m + 2);     for (int i = 0; i < (int)loops.size(); i++) {       fo.add(0, i + 1, (int)loops[i].size() - 1);       for (int c : loops[i]) {         if (avai[c]) continue;         fo.add(i + 1, (int)loops.size() + 1 + c, 1);       }     }     int flow = 0;     for (int i = 0; i < m; i++) {       flow += avai[i];     }     for (int i = (int)loops.size() + 1; i <= (int)loops.size() + m; i++) {       fo.add(i, (int)loops.size() + m + 1, 1);     }     flow += fo.maxflow(0, (int)loops.size() + m + 1);     cout << flow <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int n, ans[1010][1010];   pair<int, int> a[1010];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i].first), a[i].second = i;     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) {       int j = i;       while (a[i].first--) ans[j][a[i].second] = 1, j = (j + n) % (n + 1);     }     printf( %d n , n + 1);     for (int i = 0; i <= n; i++, puts(  ))       for (int j = 1; j <= n; j++) printf( %d , ans[i][j]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b;     cin >> n >> a >> b;     string arr;     cin >> arr;     if (arr[a - 1] == arr[b - 1])       cout << 0 <<   n ;     else       cout << 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char str[510];     int n, i;     bool rec[27];     while (cin >> str) {       int flag = 0, faill = 0;       memset(rec, 0, sizeof(rec));       int t = strlen(str);       if (str[0] !=  a ) faill = 1;       rec[1] = 1;       rec[0] = 1;       int sum = 1;       for (i = 0; i < t; i++) {         if (rec[str[i] -  a  + 1] == 0) {           rec[str[i] -  a  + 1] = 1;           for (int j = i - 1; j >= 1; j--) {             if (str[j] > str[i]) {               faill = 1;               break;             }           }         }       }       for (int i = 26; i >= 1; i--) {         if (flag == 1 && rec[i] == 0) {           faill = 1;           break;         }         if (rec[i]) flag = 1;       }       if (faill)         cout <<  NO  << endl;       else         cout <<  YES  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 0x3fffffff;   double a, b, c, d;   int main() {     while (cin >> a >> b >> c >> d) {       double l = 0, r = 2000000000.0;       double a1, a2, b1, b2, c1, c2, d1, d2;       double m1, m2, min1, min2;       for (int i = 0; i < 10000; i++) {         double mid = (l + r) / 2;         a1 = a + mid, a2 = a - mid;         b1 = b + mid, b2 = b - mid;         c1 = c + mid, c2 = c - mid;         d1 = d + mid, d2 = d - mid;         min1 = min(min(a1 * d1, a1 * d2), min(a2 * d1, a2 * d2));         min2 = min(min(b1 * c1, b1 * c2), min(b2 * c1, b2 * c2));         m1 = max(max(a1 * d1, a1 * d2), max(a2 * d1, a2 * d2));         m2 = max(max(b1 * c1, b1 * c2), max(b2 * c1, b2 * c2));         if (min1 <= m2 && min2 <= m1)           r = mid;         else           l = mid;       }       printf( %.10lf n , l);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int min(int a, int b) {     if (a > b) {       return b;     } else {       return a;     }   }   int max(int a, int b) {     if (a > b) {       return a;     } else {       return b;     }   }   int main() {     int n, x0;     int a, b;     int d, f;     cin >> n >> x0 >> a >> b;     if (a > b) {       d = b;       f = a;     } else {       d = a;       f = b;     }     int temp1;     int temp2;     for (int i = 1; i != n; i++) {       cin >> a >> b;       if (a > b) {         temp1 = a;         a = b;         b = temp1;       }       if (a > d) {         if (a > f) {           cout << -1;           return 0;         }         d = a;       }       if (b < f) {         if (b < d) {           cout << -1;           return 0;         }         f = b;       }     }     if (x0 >= d && x0 <= f) {       cout << 0;     } else {       if (x0 < d) {         cout << d - x0;       } else {         cout << x0 - f;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, leaf, po;   vector<int> v[100005];   int main() {     scanf( %d , &n);     for (int i = (2); i <= (n); i++) {       int a, b;       scanf( %d %d , &a, &b);       v[a].push_back(b);       v[b].push_back(a);     }     for (int i = (1); i <= (n); i++)       if (v[i].size() == 1) leaf++;     po = 1;     for (int i = (1); i <= (n - leaf); i++) po = (po + po) % 1000000007;     printf( %d n , (1LL * po * (n - leaf) + 2LL * po * leaf) % 1000000007);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, x, y;     int ar = 0;     int al = 0;     int br = 0;     int bl = 0;     cin >> n;     for (int i = 0; n > i; i++) {       cin >> t;       cin >> x;       cin >> y;       if (t == 1) {         ar += x;         al += y;       } else {         br += x;         bl += y;       }     }     if (ar >= al) {       cout <<  LIVE  << endl;     } else {       cout <<  DEAD  << endl;     }     if (br >= bl) {       cout <<  LIVE  << endl;     } else {       cout <<  DEAD  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[2 * 2005], pos[2 * 2005], dp[2 * 2005][2 * 2005];   int call(int p, int len) {     if (p > 2 * n) return len == n;     if (len < n) return 0;     int &ret = dp[p][len];     if (~ret) return ret;     ret = call(p + pos[p], len);     ret += call(p + pos[p], len - pos[p]);     return ret;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int tc;     cin >> tc;     while (tc--) {       cin >> n;       for (int i = 1; i <= 2 * n; i++) {         cin >> a[i];       }       for (int i = 1; i <= 2 * n; i++) {         int cnt = 1;         for (int j = i + 1; j <= 2 * n; j++) {           if (a[i] > a[j])             cnt++;           else             break;         }         pos[i] = cnt;       }       for (int i = 1; i <= 2 * n; i++)         for (int j = 1; j <= 2 * n; j++) dp[i][j] = -1;       if (call(1, 2 * n))         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   const long long INF = 4 * (long long)1e18 + 7;   const long double eps = 1e-9;   signed main() {     if (false) {       freopen( output.txt ,  w , stdout);       freopen( input.txt ,  r , stdin);     }     ios_base::sync_with_stdio(false);     int n;     cin >> n;     vector<int> arr(n);     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     vector<vector<int>> dp(5, vector<int>(n, -1));     for (int i = 0; i < 5; i++) {       dp[i][0] = -2;     }     for (int i = 0; i < n - 1; i++) {       for (int j = 0; j < 5; j++) {         if (dp[j][i] != -1) {           if (arr[i + 1] > arr[i]) {             for (int m = j + 1; m < 5; m++) {               dp[m][i + 1] = j;             }           } else if (arr[i + 1] < arr[i]) {             for (int m = 0; m < j; m++) {               dp[m][i + 1] = j;             }           } else {             for (int m = 0; m < 5; m++) {               if (m == j) continue;               dp[m][i + 1] = j;             }           }         }       }     }     vector<int> ans;     for (int j = 0; j < 5; j++) {       if (dp[j][n - 1] != -1) {         int type = j;         for (int i = n - 1; i >= 0; i--) {           ans.push_back(type + 1);           type = dp[type][i];         }         break;       }     }     if (ans.size() == 0) {       cout << -1 << endl;     } else {       for (int i = n - 1; i >= 0; i--) {         cout << ans[i] <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     string s;     cin >> s;     map<char, vector<int>> ma;     for (int i = 0; i < n; i++) {       ma[s[i]].push_back(i + 1);     }     int m;     cin >> m;     vector<int> ans;     while (m--) {       string s1;       cin >> s1;       map<char, int> m1;       for (int i = 0; i < s1.size(); i++) {         m1[s1[i]]++;       }       int a = -1;       for (auto &i : ma) {         if (m1.find(i.first) != m1.end()) {           int b = m1[i.first];           a = max(a, i.second[b - 1]);         }       }       ans.push_back(a);     }     for (int i = 0; i < ans.size(); i++) {       cout << ans[i] <<   n ;     }   }   int main() {     ios::sync_with_stdio(0);     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> t[4 * 200009];   long long a[200009], lazy[4 * 200009], ans[200009];   void build(long long v, long long tl, long long tr) {     if (tl == tr) {       t[v] = {a[tl], tl};     } else {       long long tm = (tl + tr) / 2;       build(v * 2, tl, tm);       build(v * 2 + 1, tm + 1, tr);       if (t[v * 2].first < t[v * 2 + 1].first ||           (t[v * 2].first == t[v * 2 + 1].first &&            t[v * 2].second > t[v * 2 + 1].second))         t[v] = t[v * 2];       else         t[v] = t[v * 2 + 1];     }   }   void push(long long v) {     t[v * 2].first += lazy[v];     lazy[v * 2] += lazy[v];     t[v * 2 + 1].first += lazy[v];     lazy[v * 2 + 1] += lazy[v];     lazy[v] = 0;   }   void update(long long v, long long tl, long long tr, long long l, long long r,               long long addend) {     if (l > r) return;     if (l == tl && tr == r) {       t[v].first += addend;       lazy[v] += addend;     } else {       push(v);       long long tm = (tl + tr) / 2;       update(v * 2, tl, tm, l, min(r, tm), addend);       update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, addend);       if (t[v * 2].first < t[v * 2 + 1].first ||           (t[v * 2].first == t[v * 2 + 1].first &&            t[v * 2].second > t[v * 2 + 1].second))         t[v] = t[v * 2];       else         t[v] = t[v * 2 + 1];     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     long long i = 1;     while (i <= n) cin >> a[i++];     build(1, 1, n);     i = 1;     long long x;     while (i <= n) {       x = t[1].second;       ans[x] = i;       update(1, 1, n, x + 1, n, -i);       update(1, 1, n, x, x, 1e13);       i++;     }     i = 1;     while (i <= n) {       cout << ans[i] <<    ;       i++;     }   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     x = 0;     int f = 1;     char ch = getchar();     while (ch != 45 && (ch >  9  || ch <  0 )) ch = getchar();     if (ch == 45) {       f = -1, ch = getchar();     }     while (ch <=  9  && ch >=  0 ) {       x = x * 10 + ch - 48;       ch = getchar();     }     x *= f;   }   int i, j, k, n, s, t, m, flag = 1, ans;   const int N = 2e5 + 10, mod = 1e9 + 7;   int fa[N], e[N][3], col[N], p[N], type[N];   int find(int x) {     if (x == fa[x]) return x;     return fa[x] = find(fa[x]);   }   void merge(int u, int v) {     u = find(u), v = find(v);     if (v > u) swap(u, v);     if (u == v) return;     fa[u] = v;   }   signed main() {     memset(type, -1, sizeof(type));     read(n), read(m);     for (i = 1; i <= n; i++) fa[i] = i, fa[i + n] = i + n;     for (i = 1; i <= m; i++) {       read(e[i][1]), read(e[i][2]), read(col[i]);       if (e[i][1] > e[i][2]) swap(e[i][1], e[i][2]);       if (e[i][1] == 1) {         type[e[i][2]] = col[i];         continue;       }       if (col[i] == 1)         merge(e[i][1], e[i][2]), merge(e[i][1] + n, e[i][2] + n);       else         merge(e[i][1], e[i][2] + n), merge(e[i][1] + n, e[i][2]);     }     for (i = 1; i <= n; i++) {       if (type[i] == -1) continue;       if (type[find(i + n)] == -1) type[find(i + n)] = type[i] ^ 1;       if (type[find(i + n)] == type[i]) flag = 0;       if (type[find(i)] == -1) type[find(i)] = type[i];       if (type[find(i)] != type[i]) flag = 0;     }     for (i = 1; i <= n; i++) {       if (find(i) == find(i + n)) flag = 0;     }     for (i = 2; i <= n; i++) {       if (find(i) != i) continue;       ans++;       if (type[find(i + n)] != -1 || type[i] != -1) ans--;       type[i] = 1;     }     if (flag == 0) {       printf( 0 n );       return 0;     }     int now = 1;     for (i = 1; i <= ans; i++) now = now * 2 % mod;     cout << now << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool lambs[101];   int main() {     int n, m;     cin >> n >> m;     while (n--) {       int x;       cin >> x;       while (x--) {         int y;         cin >> y;         lambs[y] = true;       }     }     for (int i = 1; i < m + 1; i++)       if (lambs[i] == false) {         cout <<  NO ;         return 0;       }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   const long long seed = 131;   const int N = 1000010;   char ac[N], bc[N];   int main() {     int n;     scanf( %d%s%s , &n, ac, bc), n--;     for (int i = 0; i < n; i++) {       if (bc[i] ==  N )         bc[i] =  S ;       else if (bc[i] ==  S )         bc[i] =  N ;       else if (bc[i] ==  E )         bc[i] =  W ;       else         bc[i] =  E ;     }     unsigned long long ha = 0, hb = 0, pow = 1;     for (int l = 1; l <= n; l++) {       ha += ac[n - l] * pow;       hb *= 131, hb += bc[n - l];       pow *= 131;       if (ha == hb) {         printf( NO n );         return 0;       }     }     printf( YES n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 702, M = 4900005;   int main() {     int n, m, a[55], b, i, j, ans, cnt;     while (scanf( %d , &n) == 1) {       for (i = 1; i <= n; i++) scanf( %d , a + i);       scanf( %d , &m);       for (i = 1, ans = 0; i <= m; i++) {         scanf( %d , &b);         for (j = 1; j <= n; j++)           if (b % a[j] == 0) {             if (b / a[j] > ans) {               ans = b / a[j];               cnt = 1;             } else if (b / a[j] == ans)               cnt++;           }       }       printf( %d n , cnt);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = (int)1e5 + 55;   const int INF = (int)1e9 + 77;   const int MOD = (int)1e9 + 7;   const double PI = 2 * acos(0.0);   const double EPS = 1e-7;   const int N = (int)1e5 + 5;   vector<vector<int>> adj;   pair<int, int> cost[N];   int mn;   bool vis[N];   long long ans;   void dfs(int u) {     if (vis[u]) return;     vis[u] = 1;     mn = min(mn, cost[u].first);     for (int v : adj[u]) dfs(v);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     adj.resize(n + 1);     for (int i = 1; i <= n; ++i) {       int x;       cin >> x;       cost[i] = {x, i};     }     for (int i = 0; i < m; ++i) {       int x, y;       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     for (int i = 1; i <= n; ++i) {       int cur = cost[i].second;       if (vis[cur]) continue;       mn = INF;       dfs(cur);       ans += mn;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int a, b, c, ty;   } a[100010];   struct Tnode {     int x, f, tag, ls, rs;   } t[3000000];   int n, m, k, K, ans, rt, tot;   bool cmp(node x, node y) { return x.a < y.a; }   int getfull(int l, int r) {     int s = 0;     l--;     for (int j = 1; j <= k; j <<= 1)       s |= (((r / j - l / j) - (j * 2 <= k ? (r / j / 2 - l / j / 2) : 0)) & 1) *            j;     return s;   }   void update(int n) {     if (t[n].tag)       t[n].x = t[n].f;     else       t[n].x = t[t[n].ls].x ^ t[t[n].rs].x;   }   void modify(int &n, int l, int r, int L, int R, int k) {     if (!n) n = ++tot, t[n].f = getfull(l, r);     if ((L <= l) && (r <= R))       t[n].tag += k;     else {       int mid = (l + r) >> 1;       if (L <= mid) modify(t[n].ls, l, mid, L, R, k);       if (mid < R) modify(t[n].rs, mid + 1, r, L, R, k);     }     update(n);   }   void work() {     scanf( %d %d %d , &n, &m, &k);     for (K = 1; K * 2 <= k; K <<= 1)       ;     for (int i = 1, A, B, C, D; i <= m; i++) {       scanf( %d %d %d %d , &A, &B, &C, &D);       a[i] = (node){A, B, D, 1}, a[i + m] = (node){C + 1, B, D, -1};     }     sort(a + 1, a + 2 * m + 1, cmp);     for (int i = 1; i <= 2 * m; i++) {       if (a[i - 1].a != a[i].a) {         int x = getfull(a[i - 1].a, a[i].a - 1), y = t[rt].x, sx = 0, sy = 0, s;         for (int j = K; j; j >>= 1) {           s = -sx * sy, sx += (x & j) > 0, sy += (y & j) > 0, s += sx * sy;           if (s & 1) ans ^= j;         }       }       modify(rt, 1, n, a[i].b, a[i].c, a[i].ty);     }     puts(ans ?  Hamed  :  Malek );   }   int main() {     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 * 4;   inline int get() {     int x;     cin >> x;     return x;   }   inline long long getlong() {     long long x;     cin >> x;     return x;   }   inline string getString() {     string s;     cin >> s;     return s;   }   template <typename T>   inline vector<T> getvector(int len) {     vector<T> a(len);     for (auto &it : a) cin >> it;     return a;   }   inline vector<int> getvector(int len) {     vector<int> a(len);     for (auto &it : a) cin >> it;     return a;   }   inline vector<pair<int, int>> getvector_andPairCnt(int len) {     vector<pair<int, int>> a(len);     int i = 1;     for (auto &it : a) {       it.second = i;       i++;       cin >> it.first;     }     return a;   }   double power_log(double power, double val) { return log(val) / log(power); }   template <typename T>   int sqr(T x) {     return x * x;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (auto it : v) os << it <<    ;     os <<   n ;     return os;   }   template <typename T, typename H>   inline vector<pair<T, H>> getvector_andBiPair(int len) {     vector<pair<T, H>> a(len);     int i = 1;     for (auto &it : a) {       cin >> it.first >> it.second;     }     return a;   }   template <typename T>   inline set<T> vector_to_set(const vector<T> &vec) {     set<T> s;     for (auto &it : vec) s.insert(it);     return s;   }   int main() {     int n = get(), k = get();     vector<pair<int, int>> arr(n);     for (auto &it : arr) cin >> it.first;     for (auto &it : arr) cin >> it.second;     sort(arr.begin(), arr.end(), [](pair<int, int> l, pair<int, int> r) {       return l.first - l.second < r.first - r.second;     });     int ans = 0;     bool can = true;     for (int i = 1; i <= n; i++) {       if (i > k && arr[i - 1].first > arr[i - 1].second) {         can = false;       }       if (can)         ans += arr[i - 1].first;       else         ans += arr[i - 1].second;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1000, INDEX = 1;   int n, type[MAX_N + INDEX];   string team[MAX_N + INDEX], city[MAX_N + INDEX];   bool isUsed[MAX_N + INDEX];   void get(int ind) {     isUsed[ind] = true;     for (int i = 1; i <= n; i++) {       if (i != ind) {         if (team[i][0] == team[ind][0] && team[i][1] == team[ind][1] &&             team[i][2] == city[ind][0]) {           type[i] = 1;           if (!isUsed[i]) {             get(i);           }         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     cout.tie();     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> team[i] >> city[i];     }     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         if (team[i][0] == team[j][0] && team[i][1] == team[j][1] &&             team[i][2] == team[j][2]) {           type[i] = 1, type[j] = 1;         }       }     }     for (int i = 1; i <= n; i++) {       if (type[i] == 1 && !isUsed[i]) {         get(i);       }     }     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         if (team[i][0] == team[j][0] && team[i][1] == team[j][1]) {           if (team[i][2] == team[j][2] && type[i] == 0 && type[j] == 0) {             cout <<  NO  << endl;             return 0;           }           if (team[i][2] == city[j][0] && type[i] == 0 && type[j] == 1) {             cout <<  NO  << endl;             return 0;           }           if (city[i][0] == team[j][2] && type[i] == 1 && type[j] == 0) {             cout <<  NO  << endl;             return 0;           }           if (city[i][0] == city[j][0] && type[i] == 1 && type[j] == 1) {             cout <<  NO  << endl;             return 0;           }         }       }     }     cout <<  YES  << endl;     for (int i = 1; i <= n; i++) {       if (type[i] == 0) {         cout << team[i][0] << team[i][1] << team[i][2] <<   n ;       }       if (type[i] == 1) {         cout << team[i][0] << team[i][1] << city[i][0] <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   bool check(int k) {     int p = (int)ceil(sqrt(k));     for (int i = 2; i <= p; ++i)       if (k % i == 0) return 1;     return 0;   }   int main() {     cin >> N;     int x = 200, y = x + N;     for (;; ++x, ++y)       if (check(x) && check(y)) return printf( %d %d n , y, x), 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int R[101];   double dp[100100], sum[100100];   int main() {     scanf( %d%d , &n, &m);     if (m == 1) {       puts( 1 );       return 0;     }     int score = 0;     dp[0] = 1;     double f = 1. / (m - 1);     for (int i = 0; i < n; ++i) {       scanf( %d , R + i);       score += R[i];     }     for (int i = 0; i < n; ++i) {       int r = R[i];       sum[0] = dp[0];       for (int j = 1; j <= min(score - 1, (i + 1) * m); ++j) {         sum[j] = sum[j - 1] + dp[j];       }       for (int j = min(score - 1, (i + 1) * m); j > 0; --j) {         dp[j] = sum[j - 1];         if (j - m - 1 >= 0) dp[j] -= sum[j - m - 1];         if (j - r >= 0) dp[j] -= dp[j - r];         dp[j] *= f;       }       dp[0] = 0;     }     double res = 1;     for (int i = 0; i < score; ++i) {       res += dp[i] * (m - 1);     }     printf( %.15lf n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int MOD = 1e9 + 7;   const int di[4] = {1, 0, -1, 0};   const int dj[4] = {0, 1, 0, -1};   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       long long a, b, x, y, n;       cin >> a >> b >> x >> y >> n;       long long a2, b2, x2, y2, n2;       a2 = a, b2 = b, x2 = x, y2 = y, n2 = n;       long long cnt_to_a = a - x;       long long cnt_to_a2 = cnt_to_a;       long long cnt_to_b = b - y;       long long cnt_to_b2 = cnt_to_b;       if (cnt_to_a < n) {         a = x;         n -= cnt_to_a;       } else {         a -= n;         n = 0;       }       if (cnt_to_b < n) {         b = y;         n -= cnt_to_b;       } else {         b -= n;         n = 0;       }       if (cnt_to_b2 < n2) {         b2 = y2;         n2 -= cnt_to_b2;       } else {         b2 -= n2;         n2 = 0;       }       if (cnt_to_a2 < n2) {         a2 = x2;         n2 -= cnt_to_a2;       } else {         a2 -= n2;         n2 = 0;       }       cout << min(a * b, a2 * b2) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   bool secdes(const pair<long long, long long>& a,               const pair<long long, long long>& b) {     if (a.second == b.second) {       return a.first > b.first;     } else {       return a.second > b.second;     }   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s;     cin >> s;     long long ind = -1;     long long l = s.length(), f = 0;     for (long long i = l - 1; i >= 0; i--) {       long long k = s[i] - 48;       if (k % 2 == 0) {         f += 1;         if (f == 1) {           ind = i;         }         if (s[l - 1] - 48 > k) {           ind = i;         }       }     }     if (f == 0)       cout << -1;     else {       swap(s[ind], s[l - 1]);       cout << s;     }   }


#include <bits/stdc++.h>   using namespace std;   int f[10000050], pre[10000050], used[10000050], edge[105];   vector<int> vec;   int main() {     int n, m, i, j, x, y, maxi, size, news;     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) {       scanf( %d%d , &x, &y);       edge[x] |= 1 << y;       edge[y] |= 1 << x;     }     memset(f, 127, sizeof(f));     for (i = 1; i <= n; i++) f[1 << i] = 0;     maxi = 0;     for (i = 1; i <= n; i++) maxi |= 1 << i;     for (i = 0; i <= maxi; i++)       if (f[i] < 999999999) {         for (j = 1; j <= n; j++)           if ((1 << j) & i) {             news = i | edge[j];             if (f[i] + 1 < f[news]) {               f[news] = f[i] + 1;               used[news] = j;               pre[news] = i;             }           } else if ((i & edge[j]) == i) {             news = i | (1 << j);             if (f[i] < f[news]) {               f[news] = f[i];               used[news] = 0;               pre[news] = i;             }           }       }     vec.clear();     for (i = maxi; (i & -i) != i; i = pre[i])       if (used[i]) vec.push_back(used[i]);     size = vec.size();     printf( %d n , size);     for (i = size - 1; i >= 0; i--) printf( %d  , vec[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   const int maxn = 50;   using namespace std;   long long n, k, M;   int a[maxn + 5], b[maxn * maxn];   void ok() {     long long ans = 0, cot = 0, tot = 0, cnt = 0, sum = 0;     sort(a + 1, a + k + 1);     for (int i = 1; i <= k; i++) cot += a[i];     for (int i = 0; i <= n; i++) {       tot = cot * i;       if (tot > M) break;       sum = tot, cnt = (k + 1) * i;       for (int j = 1; j <= k; j++) {         for (int r = i + 1; r <= n; r++) {           sum += a[j];           cnt++;           if (sum > M) {             cnt--, j = k + 1;             break;           }         }       }       ans = max(ans, cnt);     }     printf( %I64d n , ans);   }   int main() {     while (~scanf( %I64d %I64d %I64d , &n, &k, &M)) {       for (int i = 1; i <= k; i++) scanf( %d , &a[i]);       ok();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 10;   int mx = 0;   vector<int> g[N];   int n;   int col[N];   int cnt[N][N];   void gen(int v) {     if (v == n) {       for (int i = 0; i < n; i++)         for (int u : g[i]) {           int t = col[i];           int z = col[u];           cnt[min(t, z)][max(t, z)] = 1;         }       int cur = 0;       for (int i = 0; i < 6; i++)         for (int j = 0; j < 6; j++) {           cur += cnt[i][j];           cnt[i][j] = 0;         }       mx = max(mx, cur);       return;     }     for (int i = 0; i < 6; i++) {       col[v] = i;       gen(v + 1);     }   }   int solve() {     if (!(cin >> n)) return 1;     int m;     cin >> m;     for (int i = 0; i < n; i++) g[i].clear();     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       g[x].push_back(y);       g[y].push_back(x);     }     mx = 0;     gen(0);     cout << mx << endl;     return 0;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int TET = 1e9;     for (int i = 1; i <= TET; i++) {       if (solve()) break;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   inline long long rd() {     long long x = 0;     bool f = 0;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = 1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + (c ^ 48);       c = getchar();     }     return f ? -x : x;   }   long long n, m, l[1000010 << 1], f[1000010 << 1], hd[1000010];   int main() {     n = rd();     m = rd();     for (register long long i = 1; i <= n; ++i) l[i] = l[n + i] = rd();     for (register long long i = 1; i <= (n << 1); ++i) l[i] += l[i - 1];     while (m--) {       long long ptr = 0, len = rd();       for (register long long i = n + 1; i <= (n << 1); ++i) {         while (l[i] - l[ptr] > len) ++ptr;         f[i] = f[ptr] + 1;         hd[i - n] = (i == ptr ? i : (ptr <= n ? ptr : hd[ptr - n]));         if (i - hd[i - n] >= n) {           printf( %I64d n , f[i]);           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > v, par;   long long QN, cmd, nums = 0;   map<long long, long long> ans;   long long solve(long long l, long long r, long long x) {     long long st = l, en = r;     while (st <= en) {       long long mid = (st + en) / 2;       if (x < v[mid].first) {         en = mid - 1;         continue;       }       if (x > v[mid].second) {         st = mid + 1;         continue;       }       if (v[mid].first == v[mid].second && par[mid].first == -1)         return ans[v[mid].first];       x = x - v[mid].first + 1;       x %= par[mid].first;       if (x == 0) x = par[mid].first;       return solve(l, mid, x);     }   }   long long x, l, r;   int main() {     cin >> QN;     while (QN--) {       cin >> cmd;       if (cmd == 1) {         cin >> x;         ans[++nums] = x;         v.push_back(make_pair(nums, nums));         par.push_back(make_pair(-1, -1));       } else {         cin >> l >> r;         nums++;         v.push_back(make_pair(nums, nums + l * r - 1));         nums = nums + l * r - 1;         par.push_back(make_pair(l, -1));       }     }     cin >> QN;     while (QN--) {       cin >> x;       cout << solve(0, v.size() - 1, x) <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   void imp() {     cout << -1;     exit(0);   }   double mn = 0, mx = 2e9;   void solve(int x, int vx, int x1, int x2) {     if (vx == 0) {       if (x1 < x && x < x2) return;       imp();     }     if (vx < 0) {       mn = std::max(mn, (x2 - x) / (double)vx);       mx = std::min(mx, (x1 - x) / (double)vx);     } else {       mn = std::max(mn, (x1 - x) / (double)vx);       mx = std::min(mx, (x2 - x) / (double)vx);     }     if (mn >= mx) imp();   }   int main() {     int n, x1, x2, y1, y2;     cin >> n >> x1 >> y1 >> x2 >> y2;     for (int i = 0; i < n; ++i) {       int x, y, vx, vy;       cin >> x >> y >> vx >> vy;       solve(x, vx, x1, x2);       solve(y, vy, y1, y2);     }     cout << setprecision(17) << mn;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     vector<long long> arr(n + 1);     for (long long i = 0; i < n; i++) cin >> arr[i];     long long minute;     long long mn = 100000000000;     long long ans = 0;     long long x;     for (long long i = 0; i < n; i++) {       x = arr[i];       if ((x - i) <= 0)         minute = i;       else {         minute = n * ceil((x - i) / (long double)n);         minute += i;       }       if (minute < mn) {         mn = minute;         ans = i;       }     }     cout << ans + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k1, k2, k3, count[6], min_elt = INT_MAX;     memset(count, 0, sizeof(count));     scanf( %d%d%d , &k1, &k2, &k3);     count[k1 >= 5 ? 5 : k1]++;     count[k2 >= 5 ? 5 : k2]++;     count[k3 >= 5 ? 5 : k3]++;     min_elt = min(k3, min(k1, k2));     if (min_elt >= 4)       printf( NO n );     else if (min_elt == 1)       printf( YES n );     else if (min_elt == 2) {       if (count[2] >= 2)         printf( YES n );       else if (count[4] == 2)         printf( YES n );       else         printf( NO n );     } else if (count[3] == 3)       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long a, b, c, r, d, t, x1 = 0, x2 = 0;     cin >> t;     while (t--) {       cin >> a >> b >> c >> r;       d = 0;       if (a > b) {         swap(a, b);       }       x1 = c - r;       x2 = c + r;       if (x2 < a || x1 > b) {         d = b - a;       } else if (x1 <= a && x2 >= b) {         d = 0;       } else {         if (a <= x1) {           d += x1 - a;         }         if (b >= x2) {           d += b - x2;         }       }       cout << d << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005, M = 50 * N + 5;   int n, m, k, ans, X[N], Y[N];   int cnt = 0, hed[M], to[M], nxt[M];   bool vis[M];   char s[55];   int f[M];   int dfn[M], low[M], bl[M], lb = 0, sum[M];   int sta[M], top = 0, idx = 0;   inline int g(int u, int d) { return u + d * n; }   inline int Min(int x, int y) { return x < y ? x : y; }   inline int Max(int x, int y) { return x > y ? x : y; }   inline void add(int x, int y) {     to[++cnt] = y, nxt[cnt] = hed[x], hed[x] = cnt;   }   void tarjan(int u) {     dfn[u] = low[u] = ++idx, sta[++top] = u;     for (int i = hed[u]; i; i = nxt[i]) {       int v = to[i];       if (!dfn[v])         tarjan(v), low[u] = Min(low[u], low[v]);       else if (!bl[v])         low[u] = Min(low[u], dfn[v]);     }     if (dfn[u] == low[u]) {       for (bl[u] = ++lb, sum[lb] += vis[u]; sta[top] != u; --top)         bl[sta[top]] = lb, sum[lb] += vis[sta[top]];       --top;     }   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = (1), ied = (m); i <= ied; i++) {       scanf( %d%d , &X[i], &Y[i]);       for (int j = (0), jed = (k - 2); j <= jed; j++)         add(g(X[i], j), g(Y[i], j + 1));       add(g(X[i], k - 1), g(Y[i], 0));     }     for (int i = (1), ied = (n); i <= ied; i++) {       scanf( %s , s);       for (int j = (0), jed = (k - 1); j <= jed; j++) vis[g(i, j)] = s[j] -  0 ;     }     for (int i = (1), ied = (n * k); i <= ied; i++)       if (!dfn[i]) tarjan(i);     for (int i = (1), ied = (n); i <= ied; i++)       for (int j = (0), jed = (k - 1); j <= jed; j++) {         if (!vis[g(i, j)]) continue;         for (int h = (j + 1), hed = (k - 1); h <= hed; h++)           if (vis[g(i, h)] && bl[g(i, h)] == bl[g(i, j)])             vis[g(i, h)] = 0, --sum[bl[g(i, j)]];       }     memset(hed, 0, sizeof(hed)), cnt = 0;     for (int i = (1), ied = (m); i <= ied; i++) {       for (int j = (0), jed = (k - 2); j <= jed; j++)         if (bl[g(X[i], j)] != bl[g(Y[i], j + 1)])           add(bl[g(X[i], j)], bl[g(Y[i], j + 1)]);       if (bl[g(X[i], k - 1)] != bl[g(Y[i], 0)])         add(bl[g(X[i], k - 1)], bl[g(Y[i], 0)]);     }     memset(f, -0x3f3f3f3f, sizeof(f)), f[bl[g(1, 0)]] = 0;     for (int i = (lb), ied = (1); i >= ied; i--) {       f[i] += sum[i];       ans = Max(ans, f[i]);       for (int j = hed[i]; j; j = nxt[j]) f[to[j]] = Max(f[to[j]], f[i]);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 100000 + 5, inf = 2005120699;   const long long INF = 9200512069999999999ll;   int reads() {     int ans = 0;     bool fu = 0;     char ch = getchar();     while ((ch >  9  || ch <  0 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) fu = 1, ch = getchar();     while (ch <=  9  && ch >=  0 )       ans = (ans << 3) + (ans << 1) + (ch ^ 48), ch = getchar();     if (fu) ans *= -1;     return ans;   }   long long a[maxN];   inline long long abss(long long x) { return x < 0 ? -x : x; }   int main() {     int n, c;     long long ans = INF, tem, o;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %lld , &a[i]);     }     sort(a + 1, a + 1 + n);     c = (int)pow((((1ll << 62) - 1) << 1) + 1, 1.0 / n);     for (long long i = 0ll; i <= c; ++i) {       tem = 0;       o = 1ll;       for (int j = 1; j <= n; ++j) {         tem += abss(a[j] - o);         o *= i;         if (o > (1ll << 50)) {           tem = INF;           break;         }       }       ans = min(ans, tem);     }     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   int n;   int a[105];   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     int mx = 0;     for (int i = 1; i <= n; i++) {       int tmp = 0;       for (int j = i; j <= n; j++) {         tmp ^= a[j];         mx = max(mx, tmp);       }     }     cout << mx << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     Node *ch[26];     Node() {       for (int i = 0; i < 26; i++) ch[i] = NULL;     }   } * Root;   struct Trie {     void init() { Root = new Node(); }     void ins(Node *t, string s) {       for (int i = 0; i < s.size(); i++) {         int id = s[i] -  a ;         if (t->ch[id] == NULL) {           Node *p = new Node();           t->ch[id] = p;         }         t = t->ch[id];       }     }     void del(Node *t) {       for (int i = 0; i < 26; i++)         if (t->ch[i] != NULL) del(t->ch[i]);       free(t);     }     bool win(Node *t) {       for (int i = 0; i < 26; i++)         if (t->ch[i] != NULL)           if (!win(t->ch[i])) return true;       return false;     }     bool lose(Node *t) {       bool flag = 0;       for (int i = 0; i < 26; i++)         if (t->ch[i] != NULL) {           flag = true;           if (!lose(t->ch[i])) return true;         }       return false || !flag;     }   };   const int Maxn = 1e5 + 8;   char s[Maxn];   int main() {     Trie T;     T.init();     int n, k;     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %s , s);       T.ins(Root, s);     }     bool win = T.win(Root), lose = T.lose(Root);     if (win && lose)       puts( First );     else {       if (win) {         if (k & 1)           puts( First );         else           puts( Second );       } else         puts( Second );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 5555, Inf = 1e9;   int n, m;   vector<int> G[Maxn];   vector<pair<int, int> > V1[Maxn], V2[Maxn];   int d[Maxn][Maxn];   void bfs(int idx) {     for (int i = 1; i <= n; i++) d[idx][i] = i == idx ? 0 : Inf;     queue<int> q;     q.push(idx);     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 0; i < G[u].size(); i++) {         int v = G[u][i];         if (d[idx][v] == Inf) {           d[idx][v] = d[idx][u] + 1;           q.push(v);         }       }     }     for (int i = 1; i <= n; i++) {       if (i != idx && d[idx][i] != Inf)         V1[idx].push_back(pair<int, int>(d[idx][i], i)),             V2[i].push_back(pair<int, int>(d[idx][i], idx));     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d%d , &u, &v);       G[u].push_back(v);     }     for (int i = 1; i <= n; i++) {       bfs(i);     }     for (int i = 1; i <= n; i++) {       sort(V1[i].begin(), V1[i].end(), greater<pair<int, int> >());       sort(V2[i].begin(), V2[i].end(), greater<pair<int, int> >());     }     int ans = -1;     vector<int> rep(4, 0);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == j || d[i][j] == Inf) continue;         for (int k1 = 0; k1 < 3 && k1 < V2[i].size(); k1++) {           for (int k2 = 0; k2 < 3 && k2 < V1[j].size(); k2++) {             if (V2[i][k1].second != j && V1[j][k2].second != i &&                 V2[i][k1].second != V1[j][k2].second) {               int tmp = V2[i][k1].first + V1[j][k2].first + d[i][j];               if (ans < tmp) {                 ans = tmp;                 rep[0] = V2[i][k1].second, rep[1] = i;                 rep[2] = j, rep[3] = V1[j][k2].second;               }             }           }         }       }     }     for (int i = 0; i < 4; i++) printf( %d  , rep[i]);   }


#include<bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pint = pair<int, int>;   using pll = pair<ll, ll>;      int main(){       int t; cin >> t;       while(t--){           int k, n, m; cin >> k >> n >> m;           queue<int> a, b;           int size = k;           for(int i = 0; i < n; i++){               int x; cin >> x;               a.push(x);           }           for(int j = 0; j < m; j++){               int x; cin >> x;               b.push(x);           }           bool ok = true;           vector<int> ans;           while(!a.empty() && !b.empty()){               int op;               if(a.front() < b.front()){                   op = a.front();                   a.pop();               }               else{                   op = b.front();                   b.pop();               }               if(op == 0)size++;               else{                   if(op > size){                       ok = false;                       break;                   }               }               ans.push_back(op);           }           if(ok){               int op;               while(!a.empty()){                   op = a.front();                   a.pop();                   if(op == 0)size++;                   else{                       if(op > size){                           ok = false;                           break;                       }                   }                   ans.push_back(op);               }               while(!b.empty()){                   op = b.front();                   b.pop();                   if(op == 0)size++;                   else{                       if(op > size){                           ok = false;                           break;                       }                   }                   ans.push_back(op);               }           }           if(ok){               for(int i = 0; i < ans.size(); i++)cout << ans[i] <<    ;               cout << endl;           }           else{               cout << -1 << endl;           }       }   }


#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   template <typename A>   ostream &operator<<(ostream &cout, vector<A> const &v);   template <typename A, typename B>   ostream &operator<<(ostream &cout, pair<A, B> const &p) {     return cout <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename A>   ostream &operator<<(ostream &cout, vector<A> const &v) {     cout <<  [ ;     for (int i = 0; i < v.size(); i++) {       if (i) cout <<  ,  ;       cout << v[i];     }     return cout <<  ] ;   }   template <typename A, typename B>   istream &operator>>(istream &cin, pair<A, B> &p) {     cin >> p.first;     return cin >> p.second;   }   mt19937 rng(steady_clock::now().time_since_epoch().count());   void usaco(string filename) {     freopen((filename +  .in ).c_str(),  r , stdin);     freopen((filename +  .out ).c_str(),  w , stdout);   }   const long double pi = 3.14159265358979323846;   long long n, m, k, q, l, r, x, y, z;   long long a[1000005];   long long b[1000005];   long long c[1000005];   string second, t;   long long ans = 0;   long long solve2() {     long long r = 0, best = 0;     for (long long i = 0; i < (n - 1); ++i) {       r += b[i];       best = max(best, r);       if (r < 0) r = 0;     }     return best;   }   void solve(int tc) {     cin >> n;     for (int ele = 0; ele < n; ele++) cin >> a[ele];     ;     for (long long i = 0; i < (n - 1); ++i) {       b[i] = abs(a[i] - a[i + 1]);       if (i % 2) b[i] = -b[i];     }     ans = 0;     ans = max(ans, solve2());     for (long long i = 0; i < (n - 1); ++i) b[i] = -b[i];     ans = max(ans, solve2());     cout << ans <<   n ;   }   int main() {     { ios_base::sync_with_stdio(false); }     {       cin.tie(NULL);       cout.tie(NULL);     }     int tc = 1;     for (int t = 0; t < tc; t++) solve(t);   }


#include <bits/stdc++.h>   long long s, x;   int sba[150], xba[150];   long long bab[150];   int main(int argc, char** argv) {     int i, j;     int num;     int n, m;     int flag;     long long tmp;     long long ans;     bab[0] = 1;     for (i = 1; i < 60; i++) bab[i] = bab[i - 1] * 2;     while (~scanf( %I64d%I64d , &s, &x)) {       if (s < x) {         printf( 0 n );         continue;       }       memset(sba, 0, sizeof(sba));       memset(xba, 0, sizeof(xba));       i = 0;       num = 0;       tmp = x;       while (tmp) {         if (tmp & 1) {           num++;           xba[i] = 1;         }         tmp >>= 1;         i++;       }       n = i;       ans = 0;       ans += bab[num];       tmp = s - x;       if (tmp & 1) {         printf( 0 n );         continue;       }       flag = 0;       i = 0;       while (tmp) {         if (tmp & 1) {           sba[i] = 1;         }         tmp >>= 1;         i++;       }       m = i;       for (i = 0; i < n; i++) {         if (xba[i] == 1 && sba[i + 1] == 1) {           flag = 1;           break;         }       }       if (flag) {         printf( 0 n );         continue;       } else {         if ((s ^ 0) == x) ans -= 2;         printf( %I64d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, i, mi, ma, x;       cin >> n;       int m[n + 1];       for (i = 1; i <= n; i++) {         cin >> x;         m[x] = i;       }       int a[n + 1];       a[1] = 1;       a[n] = 1;       mi = m[1];       ma = m[1];       for (i = 2; i < n; i++) {         mi = min(mi, m[i]);         ma = max(ma, m[i]);         if ((ma - mi) == i - 1) {           a[i] = 1;         } else {           a[i] = 0;         }       }       for (i = 1; i <= n; i++) {         cout << a[i];       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int x;     scanf( %d , &x);     if (x == 1)       puts( 1 );     else if (x == 3)       puts( 5 );     else if (x <= 5)       puts( 3 );     else if (x <= 13)       puts( 5 );     else if (x <= 25)       puts( 7 );     else if (x <= 41)       puts( 9 );     else if (x <= 61)       puts( 11 );     else if (x <= 85)       puts( 13 );     else       puts( 15 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     unordered_map<string, char> index;     int t;     cin >> t;     while (t--) {       cin >> str;       sort(str.begin(), str.end());       str = str.substr(0, unique(str.begin(), str.end()) - str.begin());       if (index.find(str) == index.end()) {         index.insert(unordered_map<string, char>::value_type(str,  c ));       }     }     cout << index.size() << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x = 1;     cin >> n;     string arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     for (int i = 0; i < n && x == 1; i++) {       string s = arr[i];       for (int j = 0; j < 5; j++) {         if (s[j] ==  O  && s[j + 1] ==  O ) {           cout <<  YES  << endl;           s[j] =  + ;           s[j + 1] =  + ;           arr[i] = s;           x = 0;           break;         }       }     }     if (x == 0) {       for (int m = 0; m < n; m++) {         cout << arr[m] << endl;       }     } else {       cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const int block_size = 360;   const int maxn = 100010;   const long long mod = 1e9 + 7;   const long double eps = 1e-9;   template <typename T>   int sign(const T& a) {     if (a < 0) {       return -1;     }     if (a > 0) {       return 1;     }     return 0;   }   long long cross_product(const complex<long long>& from, complex<long long> a,                           complex<long long> b) {     a -= from;     b -= from;     return a.imag() * b.real() - a.real() - b.imag();   }   string a =   , b =   ;   int main() {     int n;     scanf( %d , &n);     for (long long i = 0; i < n; i++) {       string c;       cin >> c;       if (c !=  0 ) {         a += c;       }     }     for (long long i = 0; i < n; i++) {       string c;       cin >> c;       if (c !=  0 ) {         b += c;       }     }     a = a + a;     if (strstr(a.c_str(), b.c_str())) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, cnt;   int ans[100005];   vector<int> e[100005];   map<int, int> mp[100005];   map<vector<int>, int> H;   set<int> st;   int dp(int x, int fa) {     if (mp[x][fa]) return mp[x][fa];     vector<int> cur;     for (int i = 0; i < e[x].size(); i++)       if (e[x][i] != fa) cur.push_back(dp(e[x][i], x));     sort(cur.begin(), cur.end());     if (!H[cur]) H[cur] = ++cnt;     return mp[x][fa] = H[cur];   }   int main() {     n = read();     for (int i = 1; i < n; i++) {       int u = read(), v = read();       e[u].push_back(v);       e[v].push_back(u);     }     for (int i = 1; i <= n; i++)       if (e[i].size() < 4) st.insert(dp(i, 0));     cout << st.size() << endl;     return 0;   }