#include <bits/stdc++.h>   using namespace std;   unordered_set<int> si;   int fff = 0;   int fj = 2;   void mmin(int &t) {     for (int j = fj; 1;) {       int fflag = 0;       vector<int> pr;       for (int i = 2; i < sqrt(j) + 1; i++) {         if (j % i == 0) {           if (si.find(i) == si.end() && si.find(j / i) == si.end()) {             pr.push_back(i);             pr.push_back(j / i);           } else {             fflag = 2;             break;           }         }       }       if (fflag == 0 && si.find(j) == si.end()) {         for (auto tt : pr) si.insert(tt);         si.insert(j);         t = j;         fj = j + 1;         fff = 1;         break;       }       if (j % 2 == 0)         j++;       else         j += 2;     }   }   void check(int &t) {     vector<int> prime;     int flag = 0;     for (int i = 2; i < sqrt(t) + 1; i++) {       if (t % i == 0) {         if (si.find(i) == si.end())           prime.push_back(i);         else {           flag = 1;           break;         }         if (si.find(t / i) == si.end())           prime.push_back(t / i);         else {           flag = 1;           break;         }       }     }     if (si.find(t) == si.end())       prime.push_back(t);     else {       flag = 1;     }     if (flag) {       for (int j = t + 1; 1; j++) {         int fflag = 0;         for (int i = 2; i < sqrt(j) + 1; i++) {           if (j % i == 0) {             if (si.find(i) == si.end() && si.find(j / i) == si.end())               ;             else {               fflag = 2;               break;             }           }         }         if (fflag == 0 && si.find(j) == si.end()) {           for (int i = 2; i < max((int)sqrt(j) + 1, j); i++)             if (j % i == 0) {               si.insert(i);               si.insert(j / i);             }           si.insert(j);           t = j;           fff = 1;           break;         }       }     } else {       for (auto tt : prime) si.insert(tt);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<int> ans;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       if (t == 1) {         ans.push_back(t);         continue;       }       if (fff == 1)         mmin(t);       else         check(t);       ans.push_back(t);     }     for (auto t : ans) cout << t <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 2000005;   const int INF = 0x3f3f3f3f;   struct Num {     int a, b;     Num() {}     Num(int x, int y) : a(x), b(y) {}     bool operator<(const Num &y) const { return a == y.a ? b < y.b : a < y.a; }     bool operator>(const Num &y) const { return a == y.a ? b > y.b : a > y.a; }     bool operator==(const Num &y) const { return a == y.a && b == y.b; }     Num operator+(const Num &y) const { return Num(a + y.a, b + y.b); }   };   struct State {     Num n;     int base;     long long route;     bool operator<(const State &b) const { return n < b.n; }     bool operator==(const State &b) const { return n == b.n; }   };   bool cmp(const State &a, const State &b) {     return a.n == b.n ? a.base > b.base : a.n < b.n;   }   State sta[MaxN];   int cou;   int N;   Num rem[30][3];   int rnum[30];   int bbb;   long long lll;   void dfs1(int d, Num tn, int b, long long l) {     if (d > ((N + 1) >> 1)) {       sta[cou].n = tn;       sta[cou].base = b;       sta[cou++].route = l;       return;     }     for (int i = 0; i < 3; ++i)       dfs1(d + 1, tn + rem[d][i], b + (i ? rnum[d] : 0), (l << 2) | i);   }   void dfs2(int d, Num tn, int b, long long l) {     if (d > N) {       State ts;       ts.n.a = -tn.a;       ts.n.b = -tn.b;       int p = lower_bound(sta, sta + cou, ts) - sta;       if (p < cou && sta[p] == ts && sta[p].base + b > bbb) {         bbb = sta[p].base + b;         lll = (sta[p].route << (2 * (N / 2))) | l;       }       return;     }     for (int i = 0; i < 3; ++i)       dfs2(d + 1, tn + rem[d][i], b + (i ? rnum[d] : 0), (l << 2) | i);   }   void show() {     int rrr[30];     for (int i = 0; i < N; ++i) {       rrr[i] = lll & 3;       lll >>= 2;     }     for (int i = N - 1; i >= 0; --i)       if (rrr[i] == 0)         puts( MW );       else if (rrr[i] == 1)         puts( LW );       else         puts( LM );   }   int main() {     int a, b, c;     scanf( %d , &N);     for (int i = 1; i <= N; ++i) {       scanf( %d %d %d , &a, &b, &c);       rnum[i] = a;       rem[i][0] = Num(b, c);       rem[i][1] = Num(-a, c - a);       rem[i][2] = Num(b - a, -a);     }     cou = 0;     bbb = -INF;     dfs1(1, Num(0, 0), 0, 0);     sort(sta, sta + cou, cmp);     cou = unique(sta, sta + cou) - sta;     dfs2((N + 1) / 2 + 1, Num(0, 0), 0, 0);     if (bbb == -INF)       puts( Impossible );     else       show();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 2;   long long gcd(long long a, long long b) {     if (b > a) {       return gcd(b, a);     }     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   long long expo(long long a, long long b, long long mod) {     long long res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b = b >> 1;     }     return res;   }   long long mminvprime(long long a, long long b) { return expo(a, b - 2, b); }   vector<long long> sieve(int n) {     int* arr = new int[n + 1]();     vector<long long> vect;     for (int i = 2; i <= n; i++)       if (arr[i] == 0) {         vect.push_back(i);         for (int j = 2 * i; j <= n; j += i) arr[j] = 1;       }     return vect;   }   long long mod_add(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a + b) % m) + m) % m;   }   long long mod_mul(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a * b) % m) + m) % m;   }   long long mod_sub(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (((a - b) % m) + m) % m;   }   long long mod_div(long long a, long long b, long long m) {     a = a % m;     b = b % m;     return (mod_mul(a, mminvprime(b, m), m) + m) % m;   }   int fact[N];   void precalc() {     fact[0] = 1;     for (int i = 1; i < N; i++) {       fact[i] = mod_mul(fact[i - 1], i, 1000000007);     }   }   long long mod(long long x) {     return ((x % 1000000007 + 1000000007) % 1000000007);   }   long long inv(long long x) { return expo(x, 1000000007 - 2, 1000000007); }   long long divide(long long a, long long b) {     return mod_mul(a, inv(b), 1000000007);   }   long long nCr(long long n, long long r) {     return divide(fact[n], mod_mul(fact[r], fact[n - r], 1000000007));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       string s;       cin >> s;       map<char, long long> m;       long long cnt = 0;       for (int i = 0; i < s.length(); i++) {         m[s[i]]++;       }       for (auto x : m) {         if (x.second <= 2)           cnt += x.second;         else           cnt += 2;       }       if (cnt % 2 != 0) cnt--;       cout << cnt / 2 << (  n );     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000000000 )   using namespace std;   const long long int INF = 2e18;   char mode[5002 / 2][5002];   short int cup[4][5002 / 2][5002];   short int up[4][5002 / 2][5002];   int best = 0, cnt = 0;   inline int geti(int type, int x, int y) {     if (up[type][x][y] == -1 || (type >= 2 && up[type][x][y] == x) ||         (type < 2 && up[type][x][y] == y))       return up[type][x][y];     int nex = up[type][x][y];     if (type >= 2) return up[type][x][y] = geti(type, nex, y);     return up[type][x][y] = geti(type, x, nex);   }   inline void upd(int x, int y) {     for (int i = 0; i < 2; i++) {       int plus = (!i ? -1 : 1);       up[i][x][y] = y + plus;     }     for (int i = 0; i < 2; i++) {       int plus = (!i ? -1 : 1);       up[i + 2][x][y] = x + plus;     }   }   int n, m;   int dfs(int i, int j) {     char c = mode[i][j];     upd(i, j);     int out = 1;     if (c ==  L ) {       int nex = geti(0, i, j);       if (nex != -1 && nex < m) out = dfs(i, nex) + 1;     }     if (c ==  R ) {       int nex = geti(1, i, j);       if (nex != -1 && nex < m) out = dfs(i, nex) + 1;     }     if (c ==  U ) {       int nex = geti(2, i, j);       if (nex != -1 && nex < n) out = dfs(nex, j) + 1;     }     if (c ==  D ) {       int nex = geti(3, i, j);       if (nex != -1 && nex < n) out = dfs(nex, j) + 1;     }     if (out > best) {       best = out;       cnt = 0;     }     if (out == best) cnt++;     return out;   }   int main() {     cin >> n >> m;     char c;     scanf(  n );     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         scanf( %c , &c);         if (n < m)           mode[i][j] = c;         else {           if (c ==  U )             c =  R ;           else if (c ==  R )             c =  D ;           else if (c ==  D )             c =  L ;           else if (c !=  . )             c =  U ;           mode[j][n - 1 - i] = c;         }         if (c ==  . ) continue;       }       scanf(  n );     }     if (n >= m) swap(n, m);     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= m; j++) {         cup[1][i][j] = m;         cup[3][i][j] = n;       }     }     vector<int> pre(m, -1);     for (int i = 0; i < n; i++) {       int pp = -1;       for (int j = 0; j < m; j++) {         if (mode[i][j] !=  . ) {           pre[j] = i;           pp = j;         }         cup[0][i][j] = pp;         cup[2][i][j] = pre[j];       }     }     pre.assign(m, n);     for (int i = n - 1; i >= 0; i--) {       int pp = m;       for (int j = m - 1; j >= 0; j--) {         if (mode[i][j] !=  . ) {           pre[j] = i;           pp = j;         }         cup[1][i][j] = pp;         cup[3][i][j] = pre[j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         for (int k = 0; k < 4; k++) {           for (int i2 = 0; i2 <= n; i2++) {             for (int j2 = 0; j2 <= m; j2++) {               up[k][i2][j2] = cup[k][i2][j2];             }           }         }         if (mode[i][j] !=  . ) dfs(i, j);       }     }     cout << best <<     << cnt;   }


#include <bits/stdc++.h>   using namespace std;   long long totalSum;   long long check(long long a, long long b, long long c, long long r) {     if (b + c > a) {       return 0;     }     long long d = min(r, a - b - c);     return (d + 2) * (d + 1) / 2;   }   int main() {     long long a, b, c, l, total;     cin >> a >> b >> c >> l;     totalSum = a + b + c + l;     total = (l + 3) * (l + 2) * (l + 1) / 6;     for (long long i = 0; i <= l; i++) {       total -= check(a + i, b, c, l - i);       total -= check(b + i, a, c, l - i);       total -= check(c + i, b, a, l - i);     }     cout << total <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const double alpha = 0.9;   struct Node {     int size, key, nodeCount;     bool isExist;     Node *lc, *rc;     unordered_map<int, int> mp;     bool isBad() {       return lc->nodeCount > alpha * nodeCount + 5 ||              rc->nodeCount > alpha * nodeCount + 5;     }     void merge() {       size = isExist;       size += lc->size;       size += rc->size;       nodeCount = 1;       nodeCount += lc->nodeCount;       nodeCount += rc->nodeCount;       mp.clear();       for (auto e : lc->mp) {         mp[e.first] += e.second;       }       for (auto e : rc->mp) {         mp[e.first] += e.second;       }       if (isExist) mp[key]++;     }   } pool[N * 2], *C = pool + 1, *root, *null;   Node *newNode(int key) {     C->size = 1;     C->key = key;     C->mp.clear();     C->mp[key] = 1;     C->isExist = 1;     C->lc = C->rc = null;     return C++;   }   int n, q;   Node *buildTree(int *a, int l, int r) {     if (l >= r) return null;     int mid = (l + r) / 2;     Node *p = newNode(a[mid]);     p->lc = buildTree(a, l, mid);     p->rc = buildTree(a, mid + 1, r);     p->merge();     return p;   }   void dfs(Node *p, vector<Node *> &v) {     if (p == null) return;     dfs(p->lc, v);     v.push_back(p);     dfs(p->rc, v);   }   Node *divide(vector<Node *> &v, int l, int r) {     if (l >= r) return null;     int mid = (l + r) / 2;     Node *p = v[mid];     p->lc = divide(v, l, mid);     p->rc = divide(v, mid + 1, r);     p->merge();     return p;   }   void rebuild(Node *&p) {     vector<Node *> v;     dfs(p, v);     p = divide(v, 0, v.size());   }   int erase(Node *p, int idx) {     if (p->isExist && idx == p->lc->size + 1) {       p->isExist = 0;       p->mp[p->key]--;       p->size--;       return p->key;     }     int res;     p->size--;     res = idx <= p->lc->size ? erase(p->lc, idx)                              : erase(p->rc, idx - p->lc->size - p->isExist);     p->mp[res]--;     return res;   }   Node **insert(Node *&p, int idx, int val) {     if (p == null) {       p = newNode(val);       return &null;     } else {       p->nodeCount++;       p->size++;       p->mp[val]++;       Node **res = idx <= p->lc->size + 1                        ? insert(p->lc, idx, val)                        : insert(p->rc, idx - p->lc->size - p->isExist, val);       if (p->isBad()) res = &p;       return res;     }   }   int getNumber(Node *p, int l, int r, int w) {     if (p == null) return 0;     if (l <= 1 && p->size <= r) {       return p->mp.count(w) ? p->mp[w] : 0;     } else {       int res = 0;       if (l <= p->lc->size) res += getNumber(p->lc, l, r, w);       if (r > p->lc->size + p->isExist)         res += getNumber(p->rc, l - p->lc->size - p->isExist,                          r - p->lc->size - p->isExist, w);       if (p->isExist && l <= p->lc->size + 1 && p->lc->size + 1 <= r &&           p->key == w) {         res++;       }       return res;     }   }   int main() {     null = pool;     null->size = 0;     null->nodeCount = 0;     null->key = 0;     null->mp.clear();     null->isExist = 0;     null->lc = null->rc = null;     static int a[N];     int lastans = 0;     scanf( %d , &n);     for (int i = 0; i < (int)(n); i++) {       scanf( %d , &a[i]);     }     root = buildTree(a, 0, n);     scanf( %d , &q);     for (int i = 0; i < (int)(q); i++) {       int op, l, r, w;       scanf( %d%d%d , &op, &l, &r);       l = (l + lastans - 1 + n) % n + 1;       r = (r + lastans - 1 + n) % n + 1;       if (l > r) swap(l, r);       if (op == 1) {         int value = erase(root, r);         Node **p = insert(root, l, value);         if (*p != null) rebuild(*p);       } else if (op == 2) {         scanf( %d , &w);         w = (w + lastans - 1 + n) % n + 1;         lastans = getNumber(root, l, r, w);         printf( %d n , lastans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> A[55];   double pos[55][55];   bool comp(pair<long long, long long> a, pair<long long, long long> b) {     if (a.first > b.first)       return 1;     else if (a.first < b.first)       return 0;     else {       return a.second <= b.second;     }   }   bool vis[55][55];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) cin >> A[i].first;     for (int i = 1; i <= n; ++i) cin >> A[i].second;     sort(A + 1, A + n + 1, comp);     long long low = 0;     long long high = 10000000000000;     int count = 10000;     while (--count) {       long long mid = low + high;       mid /= 2.0;       for (int i = 0; i <= n; ++i) {         for (int j = 0; j <= n; ++j) {           vis[i][j] = 0;         }       }       pos[0][0] = 0;       vis[0][0] = 1;       for (int i = 1; i <= n; ++i) {         long long st = A[i].first;         int u = i - 1;         while (i <= n && A[i].first == st) ++i;         --i;         int coun = i - u;         long long sum[55];         for (int j = u + 1; j <= i; ++j) sum[j - u] = 0;         sum[0] = 0;         for (int j = u + 1; j <= i; ++j)           sum[j - u] = sum[j - u - 1] + A[j].second;         long long sum2[55];         for (int j = u + 1; j <= i; ++j) sum2[j - u] = 0;         sum2[0] = 0;         for (int j = u + 1; j <= i; ++j)           sum2[j - u] = sum2[j - u - 1] + A[j].first;         for (int j = 0; j <= u; ++j) {           for (int l = 0; l <= min(coun, j); ++l) {             if (vis[u][j] == 0) continue;             int rem = j - l + coun - l;             if (vis[i][rem] == 0) {               vis[i][rem] = 1;               pos[i][rem] = pos[u][j] - (sum[coun] - sum[l]) * mid / 1000.0 +                             (sum2[coun] - sum2[l]);             } else               pos[i][rem] = min(pos[i][rem],                                 pos[u][j] - (sum[coun] - sum[l]) * mid / 1000.0 +                                     (sum2[coun] - sum2[l]));           }         }       }       bool flag = 0;       for (int j = 0; j <= n; ++j) {         if (pos[n][j] <= 0 && vis[n][j]) {           flag = 1;         }       }       if (flag) {         high = mid;       } else {         low = mid + 1;       }     }     cout << high << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n, m, i, j, mn, mx;     scanf( %ld %ld , &n, &m);     long a[n][m];     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         scanf( %ld , &a[i][j]);       }     }     mx = 0;     for (i = 0; i < n; i++) {       mn = LONG_MAX;       for (j = 0; j < m; j++) {         mn = min(a[i][j], mn);       }       mx = max(mn, mx);     }     printf( %ld , mx);   }


#include <bits/stdc++.h>   using namespace std;   long long pwr(long long a, long long b, long long mod) {     a %= mod;     if (a < 0) a += mod;     long long ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % mod;       a = (a * a) % mod;       b /= 2;     }     return ans;   }   long long pwr(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans *= a;       a *= a;       b /= 2;     }     return ans;   }   long long gcd(long long a, long long b) {     while (b) {       long long temp = a;       a = b;       b = temp % b;     }     return a;   }   long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }   long long modularInverse(long long a, long long m) {     assert(false);     return pwr(a, m - 2, m);   }   int main(int argc, char const *argv[]) {     std::ios::sync_with_stdio(false);     int n, m, num1, num2;     cin >> n >> m;     if (n > m) {       num1 = n;       num2 = m;     } else {       num1 = m;       num2 = n;     }     long long sum = 0;     while (num2 != 0 && num1 >= 2) {       sum++;       num2--;       num1 = num1 - 2;       if (num1 < num2) {         swap(num1, num2);       }     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using lpair = pair<ll, ll>;   const ll MOD = 1e9 + 7;   const ll INF = 8e18;   void print() {}   template <class H, class... T>   void print(H&& h, T&&... t) {     cout << h <<    n [sizeof...(t) == 0];     print(forward<T>(t)...);   }   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     ll t;     cin >> t;     while (t--) {       ll nr, ng, nb;       cin >> nr >> ng >> nb;       vector<ll> r(nr), g(ng), b(nb);       for (ll i = (0); i < (nr); i++) cin >> r[i];       for (ll i = (0); i < (ng); i++) cin >> g[i];       for (ll i = (0); i < (nb); i++) cin >> b[i];       sort(r.begin(), r.end());       sort(g.begin(), g.end());       sort(b.begin(), b.end());       ll ans = INF;       vector<lpair> lp;       for (ll i = (0); i < (nr); i++) {         lp.push_back({r[i], 0});       }       for (ll i = (0); i < (ng); i++) {         lp.push_back({g[i], 1});       }       for (ll i = (0); i < (nb); i++) {         lp.push_back({b[i], 2});       }       sort(lp.begin(), lp.end());       vector<ll> pr, pg, pb;       for (ll i = (0); i < (nr + ng + nb); i++) {         if (lp[i].second == 0) {           pr.push_back(i);         } else if (lp[i].second == 1) {           pg.push_back(i);         } else {           pb.push_back(i);         }       }       for (ll i = (1); i < (nr + ng + nb - 1); i++) {         if (lp[i].second == 0) {           ll val_g = -1, val_b = -1;           ll pos = lower_bound(pg.begin(), pg.end(), i) - pg.begin();           if (pos != 0) {             val_g = g[pos - 1];           }           pos = lower_bound(pb.begin(), pb.end(), i) - pb.begin();           if (pos != nb) {             val_b = b[pos];           }           if (val_g != -1 && val_b != -1) {             ll val_r = lp[i].first;             ll res = (val_r - val_g) * (val_r - val_g) +                      (val_r - val_b) * (val_r - val_b) +                      (val_b - val_g) * (val_b - val_g);             ans = min(ans, res);           }           val_b = -1, val_g = -1;           pos = lower_bound(pb.begin(), pb.end(), i) - pb.begin();           if (pos != 0) {             val_b = b[pos - 1];           }           pos = lower_bound(pg.begin(), pg.end(), i) - pg.begin();           if (pos != ng) {             val_g = g[pos];           }           if (val_g != -1 && val_b != -1) {             ll val_r = lp[i].first;             ll res = (val_r - val_g) * (val_r - val_g) +                      (val_r - val_b) * (val_r - val_b) +                      (val_b - val_g) * (val_b - val_g);             ans = min(ans, res);           }         } else if (lp[i].second == 1) {           ll val_r = -1, val_b = -1;           ll pos = lower_bound(pr.begin(), pr.end(), i) - pr.begin();           if (pos != 0) {             val_r = r[pos - 1];           }           pos = lower_bound(pb.begin(), pb.end(), i) - pb.begin();           if (pos != nb) {             val_b = b[pos];           }           if (val_r != -1 && val_b != -1) {             ll val_g = lp[i].first;             ll res = (val_r - val_g) * (val_r - val_g) +                      (val_r - val_b) * (val_r - val_b) +                      (val_b - val_g) * (val_b - val_g);             ans = min(ans, res);           }           val_r = -1, val_b = -1;           pos = lower_bound(pb.begin(), pb.end(), i) - pb.begin();           if (pos != 0) {             val_b = b[pos - 1];           }           pos = lower_bound(pr.begin(), pr.end(), i) - pr.begin();           if (pos != nr) {             val_r = r[pos];           }           if (val_r != -1 && val_b != -1) {             ll val_g = lp[i].first;             ll res = (val_r - val_g) * (val_r - val_g) +                      (val_r - val_b) * (val_r - val_b) +                      (val_b - val_g) * (val_b - val_g);             ans = min(ans, res);           }         } else {           ll val_r = -1, val_g = -1;           ll pos = lower_bound(pr.begin(), pr.end(), i) - pr.begin();           if (pos != 0) {             val_r = r[pos - 1];           }           pos = lower_bound(pg.begin(), pg.end(), i) - pg.begin();           if (pos != ng) {             val_g = g[pos];           }           if (val_r != -1 && val_g != -1) {             ll val_b = lp[i].first;             ll res = (val_r - val_g) * (val_r - val_g) +                      (val_r - val_b) * (val_r - val_b) +                      (val_b - val_g) * (val_b - val_g);             ans = min(ans, res);           }           val_g = -1, val_r = -1;           pos = lower_bound(pg.begin(), pg.end(), i) - pg.begin();           if (pos != 0) {             val_g = g[pos - 1];           }           pos = lower_bound(pr.begin(), pr.end(), i) - pr.begin();           if (pos != nr) {             val_r = r[pos];           }           if (val_r != -1 && val_g != -1) {             ll val_b = lp[i].first;             ll res = (val_r - val_g) * (val_r - val_g) +                      (val_r - val_b) * (val_r - val_b) +                      (val_b - val_g) * (val_b - val_g);             ans = min(ans, res);           }         }       }       print(ans);     }   }


#include <bits/stdc++.h>   using namespace std;   const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};   const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};   const int INF = 1000000000;   const long long LINF = 1000000000000000000;   const long long MOD = 1000000007;   const double PI = acos(-1.0);   const double EPS = 1e-10;   template <class T>   inline bool chmax(T& a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <class T>   inline bool chmin(T& a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <class T>   inline void add(T& a, T b) {     a = ((a + b) % MOD + MOD) % MOD;   };   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     long long n, z;     cin >> n >> z;     vector<long long> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a.begin(), a.end());     int ans = 0;     int i = 0, j = n / 2;     while (i < n / 2 && j < n) {       if (a[j] - a[i] >= z) {         ans++;         i++;         j++;       } else         j++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline int setBit(int N, int pos) { return N = N | (1 << pos); }   inline int resetBit(int N, int pos) { return N = N & ~(1 << pos); }   inline bool checkBit(int N, int pos) { return (bool)(N & (1 << pos)); }   int main() {     long long n, k, x, sum = 0;     scanf( %lld %lld , &n, &k);     while (n--) {       scanf( %lld , &x);       sum += (x / k) + (bool)(x % k);     }     printf( %lld n , sum / 2 + (bool)(sum % 2));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long power(long long a, long long b, long long m = mod) {     long long x = 1;     while (b) {       if (b & 1) {         x = 1ll * x * a % m;       }       a = 1ll * a * a % m;       b /= 2;     }     return x;   }   const int N = 5e5 + 9;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tt;     cin >> tt;     while (tt--) {       int n;       cin >> n;       vector<vector<int>> g(n + 1);       map<pair<int, int>, vector<int>> gg;       vector<vector<int>> a(n + 1, vector<int>(3));       map<pair<int, int>, int> ed1;       for (int i = 1; i <= n - 2; i++) {         for (int j = 0; j < 3; j++) {           cin >> a[i][j];         }         for (int j = 0; j < 3; j++) {           int u = a[i][j];           int v = a[i][(j + 1) % 3];           if (u > v) swap(u, v);           g[u].push_back(v);           g[v].push_back(u);           gg[{u, v}].push_back(i);           ed1[{u, v}]++;         }       }       vector<vector<int>> gp(n + 1);       for (auto it : ed1) {         if (it.second == 1) {           int u = it.first.first, v = it.first.second;           gp[u].push_back(v);           gp[v].push_back(u);         }       }       vector<int> poly;       vector<int> vis(n + 1);       map<pair<int, int>, int> ed;       vis[1] = 1;       poly.push_back(1);       for (int i = 1;;) {         int pi = i;         for (int v : gp[i]) {           if (vis[v] == 0) {             vis[v] = 1;             i = v;             ed[{min(pi, i), max(pi, i)}]++;             break;           }         }         if (i == pi) {           ed[{1, pi}]++;           break;         }         poly.push_back(i);       }       vector<int> cnt(n + 2);       for (int i : poly) cout << i <<    ;       cout <<   n ;       if (n == 3) {         cout <<  1 n ;         continue;       }       function<pair<int, int>(int)> get_corner = [&](int i) {         int cc = 0, tu;         for (int j = 0; j < 3; j++) cnt[a[i][j]] = 0;         for (int j = 0; j < 3; j++) {           int u = a[i][j];           int v = a[i][(j + 1) % 3];           if (u > v) swap(u, v);           if (ed.count({u, v})) {             cc++;             cnt[u]++;             cnt[v]++;             if (cnt[u] > cnt[v])               tu = u;             else               tu = v;           }         }         return make_pair(tu, cc);       };       int cur = 1;       set<pair<int, int>> ss;       for (int i = 1; i <= n - 2; i++) {         auto r = get_corner(i);         if (r.second == 2) {           cur = i;           ss.insert({-r.second, i});         }       }       while ((int)ss.size() > 1) {         auto it = *ss.begin();         ss.erase(ss.begin());         cur = it.second;         auto r = get_corner(cur);         cout << cur <<    ;         int x = -1, y = -1;         for (int j = 0; j < 3; j++) {           int v = a[cur][j];           if (v != r.first) {             if (x == -1)               x = v;             else               y = v;           }         }         if (x > y) swap(x, y);         int ind = 0;         auto tmp = gg[{x, y}];         if (tmp.empty()) {           return 0;         }         if (tmp[ind] == cur) ind++;         ed[{x, y}]++;         cur = tmp[ind];         r = get_corner(cur);         ss.erase({-r.second + 1, cur});         ss.insert({-r.second, cur});       }       cout << ss.begin()->second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void in() {}   int main() {     in();     int n;     cin >> n;     int arr[n + 10], ps[n + 10];     for (int i = 0; i < n; ++i) {       scanf( %d , arr + i);       ps[arr[i]] = i + 1;     }     ps[0] = ps[n + 1] = -1;     int a = 0, pre = 1;     for (int i = 1; i <= n + 1; ++i) {       if (ps[i - 1] < ps[i]) continue;       a = max(a, i - pre);       pre = i;     }     cout << (n - a) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string a, b;       cin >> a >> b;       vector<int> ans;       int l = 0, r = n - 1, x = 0;       for (int i = n - 1; i >= 0; --i) {         int cur = (a[r] -  0 ) ^ x;         if (cur == (b[i] -  0 )) {           if (l < r)             --r;           else             ++r;           continue;         }         cur = (a[l] -  0 ) ^ x;         if (cur == (b[i] -  0 )) {           ans.push_back(1);         }         ans.push_back(i + 1);         x ^= 1;         swap(l, r);         if (l < r)           --r;         else           ++r;       }       cout << ans.size() <<    ;       for (auto i : ans) cout << i <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const int N = 3e5 + 100;   const double PI = acos(-1.0);   void fre() {     freopen( /Users/luras/Desktop/in.txt ,  r , stdin);     freopen( /Users/luras/Desktop/out.txt ,  w , stdout);   }   int n, m, i, j, ans, p;   char s[N], ch;   int main() {     while (~scanf( %d%d , &n, &m)) {       scanf( %s , s + 1);       ans = 0;       for (i = 2; i <= n; i++) {         if (s[i] ==  .  && s[i - 1] ==  . ) ans++;       }       for (i = 1; i <= m; i++) {         scanf( %d %c , &p, &ch);         if ((s[p] ==  .  && ch ==  . ) || (s[p] !=  .  && ch !=  . )) {           printf( %d n , ans);           continue;         }         if (s[p] ==  . ) {           if (p == 1) {             if (s[p + 1] ==  . ) {               ans--;             }           } else {             if (s[p + 1] ==  . ) ans--;             if (s[p - 1] ==  . ) ans--;           }         } else {           if (p == 1) {             if (s[p + 1] ==  . ) ans++;           } else {             if (s[p + 1] ==  . ) ans++;             if (s[p - 1] ==  . ) ans++;           }         }         s[p] = ch;         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 3 * 100002;   int a[N], pr[N];   ll cnt[N];   map<int, int> s[N];   int main() {     int q;     cin >> q;     while (q--) {       ll ans = 0;       int n;       cin >> n;       for (int i = 0; i <= n; i++) {         pr[i] = -1;         s[i].clear();       }       for (int i = 1; i <= n; i++) {         cnt[i] = 0;         cin >> a[i];         if (i != 1) {           if (pr[i - 1] != -1) {             swap(s[i], s[pr[i - 1]]);             s[i][a[pr[i - 1] - 1]] = pr[i - 1] - 1;           }           if (s[i][a[i]])             pr[i] = s[i][a[i]];           else             pr[i] = -1;           if (a[i] == a[i - 1]) pr[i] = i - 1;         }         if (pr[i] != -1) cnt[i] = cnt[pr[i] - 1] + 1;         ans += cnt[i];       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using   namespace  std ;   using LL  =  long long ;      short int mark[500005] ;      class cmp{   public:        bool operator () (const pair<int, int> &p1, const pair<int, int> &p2){           return ((p1.first < p2.first) || (p1.first == p2.first && p1.second > p2.second)) ;       }   } ;      int main(){          ios_base::sync_with_stdio(false);       cin.tie(0);              int q ;       cin >>  q ;          int id = 0 ;       queue<int> a ;       priority_queue<pair<int, int> , vector<pair<int, int> > , cmp > b ;          for(int i = 1 ; i <= q ; i++){           int x ;           cin >> x ;              if(x == 1){               int m ;               cin >> m ;               a.push(++id) ;               b.push(make_pair(m, id)) ;           }           else if(x == 2){               while(mark[a.front()])                   a.pop() ;               cout << a.front() <<     ;               mark[a.front()] = 1 ;               a.pop() ;           }           else if(x == 3) {               while(mark[b.top().second])                   b.pop() ;               cout << b.top().second <<     ;               mark[b.top().second] = 1 ;               b.pop() ;           }       }       cout << endl ;          return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     int k;     cin >> n >> k;     int ar[n];     for (int i = 0; i < n; i++) {       cin >> ar[i];     }     sort(ar, ar + n);     long long lista[n];     int cantidad[n];     int index = 0;     for (int i = 0; i < n; i++) {       if (i == 0) {         lista[i] = ar[i];         cantidad[index] = 1;       } else if (ar[i] == ar[i - 1]) {         cantidad[index]++;       } else {         index++;         cantidad[index] = 1;         lista[index] = ar[i];       }     }     int diferentes = index + 1;     long long L[diferentes];     long long R[diferentes];     int LeftAmount[diferentes];     int RightAmount[diferentes];     L[0] = 0;     LeftAmount[0] = 0;     R[diferentes - 1] = 0;     RightAmount[diferentes - 1] = 0;     for (int i = 1; i < diferentes; i++) {       LeftAmount[i] = LeftAmount[i - 1] + cantidad[i - 1];       L[i] = L[i - 1] + (lista[i] - 1 - lista[i - 1]) * cantidad[i - 1];       L[i] += (lista[i] - 1 - (lista[i - 1] - 1)) * LeftAmount[i - 1];     }     for (int i = diferentes - 2; i >= 0; i--) {       RightAmount[i] = RightAmount[i + 1] + cantidad[i + 1];       R[i] = R[i + 1] + (lista[i + 1] - (lista[i] + 1)) * cantidad[i + 1];       R[i] += (lista[i + 1] - lista[i]) * RightAmount[i + 1];     }     long long ans = 1000000000000000005;     for (int i = 0; i < diferentes; i++) {       if (cantidad[i] >= k) {         ans = 0;       } else {         int needed = k - cantidad[i];         if ((LeftAmount[i] >= needed) && (RightAmount[i] >= needed)) {           ans = min(min(L[i], R[i]) + needed, ans);         } else if (LeftAmount[i] >= needed) {           ans = min(L[i] + needed, ans);         } else if (RightAmount[i] >= needed) {           ans = min(R[i] + needed, ans);         } else {           ans = min(L[i] + R[i] + needed, ans);         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       vector<vector<long long>> a(n, vector<long long>(3));       vector<long long> b(k);       vector<int> make_pair(n + 1);       for (int i = 0; i < n; ++i) {         cin >> a[i][0];         make_pair[a[i][0]] = i;         a[i][1] = i - 1;         a[i][2] = i < n - 1 ? i + 1 : -1;       }       vector<int> st(n + 1, false);       for (auto &i : b) {         cin >> i;         st[i] = true;       }       long long ans = 1;       for (long long i = 0; i < k; ++i) {         int pos = make_pair[b[i]];         int cnt = 0;         if (a[pos][1] != -1) {           int nbr = a[pos][1];           if (!st[a[nbr][0]]) cnt++;         }         if (a[pos][2] != -1) {           int nbr = a[pos][2];           if (!st[a[nbr][0]]) cnt++;         }         st[b[i]] = false;         int l = a[pos][1];         int r = a[pos][2];         if (l != -1) a[l][2] = r;         if (r != -1) a[r][1] = l;         if (!cnt) {           ans = 0;           break;         }         ans = (ans * cnt) % ((long long)(998244353));       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void bfs(long long root, list<long long> adj[], vector<long long> &level) {     level[root] = 0;     queue<long long> qu;     qu.push(root);     while (!qu.empty()) {       long long cur = qu.front();       qu.pop();       for (auto it : adj[cur]) {         if (level[it] == -1) {           level[it] = level[cur] + 1;           qu.push(it);         }       }     }   }   void solve() {     long long V, E, a, b;     cin >> V >> E;     list<long long> adj[V + 1];     vector<long long> level(V + 1, -1);     for (long long i = 0; i < E; i++) {       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     bfs(1, adj, level);     map<long long, vector<long long> > mp;     for (int i = 1; i <= V; i++) {       mp[level[i]].push_back(i);     }     a = mp.size();     vector<long long> ans1, ans2;     for (int i = 0; i < a; i += 2) {       vector<long long> hold = mp[i];       for (auto it : hold) ans1.push_back(it);     }     for (int i = 1; i < a; i += 2) {       vector<long long> hold = mp[i];       for (auto it : hold) ans2.push_back(it);     }     if (ans1.size() < ans2.size()) {       cout << ans1.size() << endl;       for (auto it : ans1) cout << it <<    ;       cout << endl;     } else {       cout << ans2.size() << endl;       for (auto it : ans2) cout << it <<    ;       cout << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long q = 1;     cin >> q;     while (q--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fast() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     int n, c = 0;     char x;     vector<pair<int, int> > v;     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> x;         if (x ==  C ) {           v.push_back(make_pair(i, j));         }       }     }     sort(v.begin(), v.end());     for (int i = 0; i < v.size(); i++) {       for (int j = i + 1; j < v.size(); j++) {         if (v[i].first == v[j].first) c++;         if (v[i].second == v[j].second) c++;       }     }     cout << c;     return 0;   }


#include <bits/stdc++.h>   const int kM = 4e4 + 5;   const int kN = 55;   int M, n, m, k;   long long T[kM << 3], tag[kM << 3], a[kN][kM], pre[kM], s[kM], f[kN][kM];   void Update(int cur) { T[cur] = std::max(T[cur << 1], T[cur << 1 | 1]); }   void PushTag(int cur) {     T[cur << 1] += tag[cur];     T[cur << 1 | 1] += tag[cur];     tag[cur << 1] += tag[cur];     tag[cur << 1 | 1] += tag[cur];     tag[cur] = 0;   }   void Build(int cur, int l, int r) {     if (l < r) {       int mid = (l + r) >> 1;       Build(cur << 1, l, mid);       Build(cur << 1 | 1, mid + 1, r);       Update(cur);     } else       T[cur] = s[l];   }   void Modify(int cur, int l, int r, int ql, int qr, long long v) {     if (l > qr || r < ql) return;     if (ql <= l && r <= qr)       T[cur] += v, tag[cur] += v;     else {       int mid = (l + r) >> 1;       PushTag(cur);       if (ql <= mid) Modify(cur << 1, l, mid, ql, qr, v);       if (qr > mid) Modify(cur << 1 | 1, mid + 1, r, ql, qr, v);       Update(cur);     }   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) scanf( %d , &a[i][j]);     for (int i = 1; i <= m + k; ++i) pre[i] = pre[i - 1] + a[1][i];     for (int i = 1; i <= m; ++i) f[1][i] = pre[i + k - 1] - pre[i - 1];     for (int i = 2; i <= n; ++i) {       for (int j = 1; j <= m + k; ++j) pre[j] = pre[j - 1] + a[i][j];       for (int j = 1; j <= m; ++j)         s[j] = pre[j + k - 1] - pre[std::max(k, j - 1)] + f[i - 1][j];       memset(tag, 0, sizeof(tag));       Build(1, 1, m);       for (int j = 1; j <= m; ++j) {         f[i][j] = T[1] + pre[j + k - 1] - pre[j - 1];         Modify(1, 1, m, j - k + 1, j, a[i][j]);         Modify(1, 1, m, j + 1, j + k, -a[i][j + k]);       }     }     long long ans = 0;     for (int i = 1; i <= m; ++i) ans = std::max(ans, f[n][i]);     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7, mxn = 2e5 + 5;   int n;   int a[200005];   int mp1[200005], mp2[200005];   map<int, int> mp;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       mp[a[i]]++;     }     int ele, ma = 0;     for (auto ii : mp) {       if (ma < ii.second) {         ma = ii.second;         ele = ii.first;       }     }     int an = 0;     for (int i = 1; i <= 100; i++) {       if (ele == i) continue;       memset(mp1, -1, sizeof(mp1));       memset(mp2, -1, sizeof(mp2));       int su = 0;       mp1[0] = 0;       for (int j = 0; j < n; j++) {         if (a[j] == ele)           su++;         else if (a[j] == i)           su--;         if (su >= 0) {           if (mp1[su] != -1) {             int idx = mp1[su];             int tm = j + 1 - idx;             an = max(tm, an);           } else {             mp1[su] = j + 1;           }         } else {           if (mp2[-1 * su] != -1) {             int idx = mp2[-1 * su];             int tm = j + 1 - idx;             an = max(tm, an);           } else {             mp2[-1 * su] = j + 1;           }         }       }     }     cout << an;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     char c = getchar();     while (!isdigit(c)) c = getchar();     int num = 0;     while (isdigit(c)) num = num * 10 + c -  0 , c = getchar();     return num;   }   void write(int num) {     if (num >= 10) write(num / 10);     putchar(num % 10 +  0 );   }   int u[50001], v[50001], c[50001], t[50001];   vector<int> e[50001];   bool cmp(int a, int b) { return c[a] < c[b]; }   int head[500001], ver[2000001], nxt[2000001], sz;   void addedge(int u, int v) { ver[++sz] = v, nxt[sz] = head[u], head[u] = sz; }   int dfn[500001], low[500001];   int vis[500001], stk[500001];   int now, top, cnt, scc[500001];   void tarjan(int x) {     dfn[x] = low[x] = ++now;     stk[++top] = x, vis[x] = 1;     for (int i = head[x]; i; i = nxt[i])       if (!vis[ver[i]])         tarjan(ver[i]), low[x] = min(low[x], low[ver[i]]);       else if (vis[ver[i]] == 1)         low[x] = min(low[x], dfn[ver[i]]);     if (dfn[x] == low[x]) {       scc[x] = ++cnt, vis[x] = 2;       while (stk[top] != x) {         scc[stk[top]] = cnt;         vis[stk[top]] = 2;         --top;       }       --top;     }   }   bool _2sat(int n) {     now = cnt = 0;     for (int i = 1; i <= n * 2; i++) vis[i] = 0;     for (int i = 1; i <= n * 2; i++)       if (!vis[i]) tarjan(i);     for (int i = 1; i <= n; i++)       if (scc[i] == scc[i + n]) return 0;     return 1;   }   int main() {     int n, m;     n = read(), m = read();     for (int i = 1; i <= m; i++) {       u[i] = read(), v[i] = read(), c[i] = read(), t[i] = read();       e[u[i]].push_back(i), e[v[i]].push_back(i);     }     int tot = m;     for (int i = 1; i <= n; i++) {       int tmp = 0;       sort(e[i].begin(), e[i].end(), cmp);       for (int j = 1; j < e[i].size(); j++)         if (c[e[i][j]] == c[e[i][j - 1]]) {           if (tmp) {             puts( No );             return 0;           }           tmp = j;         }       if (tmp) {         addedge(e[i][tmp], m * 5 + e[i][tmp - 1]);         addedge(e[i][tmp - 1], m * 5 + e[i][tmp]);         addedge(m * 5 + e[i][tmp - 1], e[i][tmp]);         addedge(m * 5 + e[i][tmp], e[i][tmp - 1]);         for (int j = 0; j < e[i].size(); j++)           if (j != tmp && j != tmp - 1) addedge(e[i][j], m * 5 + e[i][j]);       } else {         for (int j = 1; j < e[i].size(); j++) {           addedge(j + tot, j + 1 + tot);           addedge(j + 1 + tot + e[i].size(), j + tot + e[i].size());           addedge(j + 1 + tot + m * 5, j + tot + m * 5);           addedge(j + tot + e[i].size() + m * 5,                   j + 1 + tot + e[i].size() + m * 5);         }         for (int j = 0; j < e[i].size(); j++) {           addedge(e[i][j], j + 1 + tot);           addedge(e[i][j], j + 1 + tot + e[i].size());           addedge(j + 1 + tot + m * 5, e[i][j] + m * 5);           addedge(j + 1 + tot + e[i].size() + m * 5, e[i][j] + m * 5);         }         for (int j = 1; j < e[i].size(); j++) {           addedge(e[i][j], j + tot + m * 5);           addedge(e[i][j - 1], j + 1 + tot + e[i].size() + m * 5);           addedge(j + tot, e[i][j] + m * 5);           addedge(j + 1 + tot + e[i].size(), e[i][j - 1] + m * 5);         }       }       tot += e[i].size() * 2;     }     int tmp = sz;     int l = 0, r = 1000000001;     while (l < r) {       int mid = (l + r) / 2;       for (int i = 1; i <= m * 10; i++)         while (head[i] > tmp) head[i] = nxt[head[i]];       sz = tmp;       for (int i = 1; i <= m; i++)         if (t[i] > mid) addedge(i, i + m * 5);       if (_2sat(m * 5))         r = mid;       else         l = mid + 1;     }     if (l == 1000000001) {       puts( No );       return 0;     }     puts( Yes );     write(l), putchar(   );     for (int i = 1; i <= m * 10; i++)       while (head[i] > tmp) head[i] = nxt[head[i]];     sz = tmp;     for (int i = 1; i <= m; i++)       if (t[i] > l) addedge(i, i + m * 5);     _2sat(m * 5);     int res = 0;     for (int i = 1; i <= m; i++)       if (scc[i] < scc[i + m * 5]) ++res;     write(res), putchar(  n );     for (int i = 1; i <= m; i++)       if (scc[i] < scc[i + m * 5]) write(i), putchar(   );     putchar(  n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, dist[110][110];     scanf( %d , &n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) scanf( %d , &dist[i][j]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         for (int k = 1; k <= n; k++)           dist[j][k] = dist[j][k] > dist[j][i] + dist[i][k]                            ? dist[j][i] + dist[i][k]                            : dist[j][k];     int max = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) max = max > dist[i][j] ? max : dist[i][j];     cout << max << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     cout << 2 * n - 1 <<     << 2 <<   n ;     cout << 1 <<     << 2 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, i, j, x, y, z, ans2, ans;   int ans1[101];   int main() {     cin >> n >> m;     for (i = 1; i <= m; i++) {       y = -1;       for (j = 1; j <= n; j++) {         cin >> x;         if (x > y) {           y = x;           z = j;         }       }       ans1[z]++;     }     for (i = 1; i <= 101; i++) {       if (ans1[i] > ans2) {         ans2 = ans1[i];         ans = i;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int u, v, w, id;   } e[500001];   int f[500001], last[500001];   int Left[500001];   struct que {     int x, y, next;   } q[1000001];   int head[500001];   int cnt;   void init() {     cnt = 0;     memset(head, -1, sizeof(head));   }   void add_edge(int w, int i, int id) {     q[cnt].x = i;     q[cnt].y = id;     q[cnt].next = head[w];     head[w] = cnt++;   }   int fa[500001];   int stid[500001 << 3], stfa[500001 << 3], top = 0;   bool cmp(edge a, edge b) {     if (a.w == b.w) return a.id < b.id;     return a.w < b.w;   }   int Find(int u) {     if (u == fa[u]) {       return u;     } else {       int v = Find(fa[u]);       ++top;       stid[top] = u, stfa[top] = fa[u];       fa[u] = v;       return v;     }   }   bool add(int id) {     int u = e[id].u, v = e[id].v;     u = Find(u), v = Find(v);     if (u == v) return false;     ++top;     stid[top] = u, stfa[top] = fa[u];     fa[u] = v;     return true;   }   void back(int ret) {     while (top > ret) {       fa[stid[top]] = stfa[top];       top--;     }   }   int main() {     init();     int n, m, Q;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &e[i].u, &e[i].v, &e[i].w);       e[i].id = i;     }     sort(e + 1, e + 1 + m, cmp);     for (int i = 1; i <= m; i++) f[e[i].id] = i;     scanf( %d , &Q);     for (int i = 1; i <= Q; i++) {       int qn;       scanf( %d , &qn);       for (int j = 1; j <= qn; j++) {         int id;         scanf( %d , &id);         id = f[id];         if (last[e[id].w] != i) {           last[e[id].w] = i;           Left[i]++;         }         add_edge(e[id].w, i, id);       }     }     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= m; i++) {       if (e[i].w != e[i - 1].w) {         int w = e[i].w;         int rec = top;         for (int j = head[w]; ~j; j = q[j].next) {           bool ok = true;           while (q[j].next != -1 && q[j].x == q[q[j].next].x) {             ok &= add(q[j].y);             j = q[j].next;           }           ok &= add(q[j].y);           if (ok) {             Left[q[j].x]--;           }           back(rec);         }       }       for (; e[i].w == e[i + 1].w; i++) {         add(i);       }       add(i);     }     for (int i = 1; i <= Q; i++) {       if (!Left[i])         printf( YES n );       else         printf( NO n );     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 55;   int read() {     int w = 0, f = 0;     char c = getchar();     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     if (c ==  - ) f = 1, c = getchar();     while (c >=  0  && c <=  9 ) w = w * 10 + c -  0 , c = getchar();     return f ? -w : w;   }   int n;   int a[N][N], b[N][N];   int ask(int x1, int y1, int x2, int y2) {     printf( ? %d %d %d %d n , x1, y1, x2, y2);     fflush(stdout);     int tmp;     scanf( %d , &tmp);     return tmp;   }   void Ans(int res) {     puts( ! );     if (res == 1) {       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= n; ++j) {           printf( %d , a[i][j]);           if (j == n) puts(  );         }     } else {       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= n; ++j) {           printf( %d , b[i][j]);           if (j == n) puts(  );         }       }     }   }   bool check(vector<int>& v) {     vector<int> tmp = v;     reverse(tmp.begin(), tmp.end());     for (size_t i = 0; i < v.size(); ++i)       if (v[i] != tmp[i]) return 0;     return 1;   }   int tx = -1, ty, sx, sy;   bool r1, r2;   vector<int> p1, p2;   void work(int t, int x, int y) {     if (!t) {       bool b1 = check(p1), b2 = check(p2);       if (b1 != b2) {         tx = x, ty = y;         r1 = b1, r2 = b2;       }       return;     }     if (tx != -1) return;     if (x + 1 <= n) {       p1.push_back(a[x + 1][y]);       p2.push_back(b[x + 1][y]);       work(t - 1, x + 1, y);       p1.pop_back();       p2.pop_back();       if (tx != -1) return;     }     if (y + 1 <= n) {       p1.push_back(a[x][y + 1]);       p2.push_back(b[x][y + 1]);       work(t - 1, x, y + 1);       p1.pop_back();       p2.pop_back();     }   }   int main() {     memset(a, -1, sizeof a);     memset(b, -1, sizeof b);     n = read();     for (int i = 1; i <= n; i += 2) {       for (int j = 1; j <= n; j += 2) {         if (i == 1 && j == 1)           a[i][j] = 1;         else {           if (j > 2)             a[i][j] = ask(i, j - 2, i, j) ^ a[i][j - 2] ^ 1;           else             a[i][j] = ask(i - 2, j, i, j) ^ a[i - 2][j] ^ 1;         }         b[i][j] = a[i][j];       }     }     for (int i = 2; i <= n; i += 2) {       for (int j = 2; j <= n; j += 2) {         if (i == 2 && j == 2)           a[2][2] = ask(1, 1, 2, 2);         else {           if (j > 2)             a[i][j] = ask(i, j - 2, i, j) ^ a[i][j - 2] ^ 1;           else             a[i][j] = ask(i - 2, j, i, j) ^ a[i - 2][j] ^ 1;         }         b[i][j] = a[i][j];       }     }     for (int i = 1; i <= n; i += 2) {       for (int j = 2; j <= n; j += 2) {         if (i == 1 && j == 2)           a[1][2] = 0;         else {           if (j > 2)             a[i][j] = ask(i, j - 2, i, j) ^ a[i][j - 2] ^ 1;           else             a[i][j] = ask(i - 2, j, i, j) ^ a[i - 2][j] ^ 1;         }         b[i][j] = a[i][j] ^ 1;       }     }     for (int i = 2; i <= n; i += 2) {       for (int j = 3; j <= n; j += 2) {         if (i == 2 && j == 3)           a[2][3] = ask(1, 2, 2, 3) ^ a[1][2] ^ 1;         else {           if (j > 3)             a[i][j] = ask(i, j - 2, i, j) ^ a[i][j - 2] ^ 1;           else             a[i][j] = ask(i - 2, j, i, j) ^ a[i - 2][j] ^ 1;         }         b[i][j] = a[i][j] ^ 1;       }     }     for (int i = 2; i <= n; i += 2) {       a[i][1] = ask(i, 1, i, 3) ^ a[i][3] ^ 1;       b[i][1] = a[i][1] ^ 1;     }     for (int t = 3; tx == -1; ++t) {       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= n; ++j) {           p1.clear(), p2.clear();           p1.push_back(a[i][j]), p2.push_back(b[i][j]);           work(t, i, j);           if (tx != -1) {             sx = i, sy = j;             break;           }         }         if (tx != -1) break;       }     }     int tmp = ask(sx, sy, tx, ty);     Ans(tmp == r1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5004;   const int MAXNN = MAXN * 2 + 10;   const int INF = 0x3f3f3f3f;   struct Edge {     int u, v, f, cap;     Edge() { f = 0; }     Edge(int uu, int vv, int cc) : u(uu), v(vv), f(0), cap(cc) {}     inline int other(int w) { return w == u ? v : u; }     inline int flow(int from) { return from == u ? cap - f : f; }     inline void augment(int from, int val) {       if (from == u)         f += val;       else         f -= val;     }   };   struct Dinic {     int N;     vector<int> par, L, pt, eIdx;     vector<Edge> E;     vector<vector<int>> a;     Dinic(int n) : N(n), par(n), L(n), pt(n), eIdx(n), a(n) {}     Dinic() : N(0) {}     void addEdge(int u, int v, int c) {       if (u != v) {         E.emplace_back(u, v, c);         a[u].push_back(E.size() - 1);         a[v].push_back(E.size() - 1);       }     }     void clearFlow() {       for (Edge &e : E) e.f = 0;     }     bool BFS(int source, int target) {       const int INF = 0x3f3f3f3f;       queue<int> Q;       fill(L.begin(), L.end(), INF);       L[source] = 0;       Q.push(source);       while (Q.size()) {         int u = Q.front();         Q.pop();         for (int ei : a[u]) {           Edge &e = E[ei];           int v = e.other(u);           if (L[v] > L[u] + 1 && e.flow(u)) {             L[v] = L[u] + 1;             if (v == target) return true;             Q.push(v);           }         }       }       return false;     }     int DFS(int source, int target) {       stack<int> S;       int ans = 0;       S.push(source);       while (S.size()) {         int u = S.top();         if (u == target) {           int f = 1e9, bottleneck = -1;           for (int cur = target; cur != source; cur = par[cur])             f = min(f, E[eIdx[cur]].flow(par[cur]));           for (int cur = target; cur != source; cur = par[cur]) {             Edge &e = E[eIdx[cur]];             e.augment(par[cur], f);             if (!e.flow(par[cur])) bottleneck = par[cur];           }           ans += f;           while (S.top() != bottleneck) S.pop();         } else {           if (pt[u]) {             int &i = pt[u];             while (--i >= 0) {               int ei = a[u][i];               Edge &e = E[ei];               int v = e.other(u);               if (pt[v] > 0 && L[u] + 1 == L[v] && e.flow(u)) {                 par[v] = u;                 eIdx[v] = ei;                 S.push(v);                 break;               }             }           }           if (S.top() == u) {             pt[u] = 0;             S.pop();           }         }       }       return ans;     }     int maxFlow(int source, int target) {       int mf = 0, f;       clearFlow();       while (BFS(source, target)) {         for (int i = 0; i < N; ++i) pt[i] = (int)a[i].size();         while (pt[source]) {           f = DFS(source, target);           if (!f) break;           mf += f;         }       }       return mf;     }   };   bool vis[MAXNN];   int n, m, S, T;   inline void init(Dinic &F, int val) {     for (int ei : F.a[T]) {       F.E[ei].cap = val;     }   }   void bs(Dinic &F) {     int hi = n, lo = 0, ans = 0, mid;     while (hi >= lo) {       mid = (hi + lo) >> 1;       init(F, mid);       if (F.maxFlow(S, T) == m) {         ans = mid;         hi = mid - 1;       } else {         lo = mid + 1;       }     }     init(F, ans);     F.maxFlow(S, T);     printf( %d n , ans);     for (int i = 1, from = -1, to = -1; i <= m; ++i) {       for (int ei : F.a[i]) {         Edge &e = F.E[ei];         if (e.other(i) == S) continue;         if (e.flow(i))           to = e.other(i);         else           from = e.other(i);       }       printf( %d %d n , from - m, to - m);     }   }   int main() {     scanf( %d%d , &n, &m);     S = 0;     T = n + m + 1;     Dinic F(T + 1);     for (int i = 1, x, y; i <= m; ++i) {       scanf( %d%d , &x, &y);       F.addEdge(i, m + x, 1);       F.addEdge(i, m + y, 1);       F.addEdge(S, i, 1);     }     for (int i = 1; i <= n; ++i) F.addEdge(m + i, T, MAXN);     bs(F);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double cp(const complex<double> &a, const complex<double> &b) {     return a.real() * b.imag() - b.real() * a.imag();   }   inline complex<double> line_inter(const complex<double> &a,                                     const complex<double> &b,                                     const complex<double> &c,                                     const complex<double> &d) {     return a + cp(c - a, d - c) / cp(b - a, d - c) * (b - a);   }   inline double lp_dist(const complex<double> &a, const complex<double> &b,                         const complex<double> &p) {     return cp(b - a, p - a) / abs(b - a);   }   int main() {     int y1, y2, yw, xb, yb, r;     cin >> y1 >> y2 >> yw >> xb >> yb >> r;     yw -= r;     y1 += r;     y2 -= r;     if (y1 == y2)       cout << -1 << endl;     else {       double cc = yw + (yw - (y1 + 0.00001));       complex<double> a(0, cc), b(xb, yb), c(0, yw), d(xb, yw);       complex<double> e(0, yw + yw - (y2 + r));       if (lp_dist(b, a, e) <= r)         cout << -1 << endl;       else {         complex<double> s = line_inter(a, b, c, d);         cout << fixed << setprecision(12) << s.real() << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline int read(T& x) {     x = 0;     char c = getchar(), f = 1;     while (c >  9  || c <  0 ) {       if (c ==  - ) f = -1;       if (c == -1) return -1;       c = getchar();     }     while (c <=  9  && c >=  0 )       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     x *= f;     return 1;   }   template <typename T, typename... Args>   inline int read(T& x, Args&... args) {     return read(x) + read(args...);   }   template <typename T>   inline int write(T x) {     if (x < 0) return putchar( - ) & write((~x) + 1);     if (x / 10) return write(x / 10) & putchar(x % 10 | 48);     return putchar(x | 48);   }   template <typename T>   inline int write(T x, char c) {     return write(x) + putchar(c);   }   int n, m;   struct edge {     int u, v, nxt;   } e[1000005 << 1];   int f[1000005], tot = 1;   inline void addEdge(int u, int v) {     tot++, e[tot].u = u, e[tot].v = v, e[tot].nxt = f[u], f[u] = tot;   }   int dfn[1000005], low[1000005], idx;   int bel[1000005], siz[1000005], scc;   bool ins[1000005];   int sta[1000005], tp;   inline void tarjan(int x, int fa) {     dfn[x] = low[x] = ++idx;     sta[++tp] = x;     ins[x] = 1;     for (int i = f[x]; i; i = e[i].nxt) {       int v = e[i].v;       if (!dfn[v]) {         tarjan(v, x);         low[x] = ((low[x]) < (low[v]) ? (low[x]) : (low[v]));       } else if (ins[v])         low[x] = ((low[x]) < (dfn[v]) ? (low[x]) : (dfn[v]));     }     if (dfn[x] == low[x]) {       int v;       scc++;       do {         v = sta[tp--];         bel[v] = scc;         siz[scc]++;         ins[v] = 0;       } while (v != x);     }   }   signed main() {     int t;     read(t);     while (t--) {       read(n, m);       tot = idx = scc = 0;       for (int i = 1; i <= n; i++) bel[i] = dfn[i] = low[i] = f[i] = siz[i] = 0;       for (int i = 1; i <= m; i++) {         int u, v;         read(u, v);         if (u != v) addEdge(u, v);       }       for (int i = 1; i <= n; i++)         if (!dfn[i]) tarjan(i, -1);       if (scc == 1) {         puts( No );         continue;       }       puts( Yes );       write(siz[1],    ), write(n - siz[1],   n );       for (int i = 1; i <= n; i++)         if (bel[i] == 1) write(i,    );       putchar(10);       for (int i = 1; i <= n; i++)         if (bel[i] != 1) write(i,    );       putchar(10);     }   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(pair<int, int> a, pair<int, int> b) {     return abs(a.first) + abs(a.second) < abs(b.first) + abs(b.second);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<pair<int, int>> q1;     vector<pair<int, int>> q2;     vector<pair<int, int>> q3;     vector<pair<int, int>> q4;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       if (x > 0 && y >= 0) {         q1.push_back(make_pair(x, y));       }       if (x <= 0 && y > 0) {         q2.push_back(make_pair(x, y));       }       if (x < 0 && y <= 0) {         q3.push_back(make_pair(x, y));       }       if (x >= 0 && y < 0) {         q4.push_back(make_pair(x, y));       }     }     sort(q1.begin(), q1.end(), cmp);     sort(q2.begin(), q2.end(), cmp);     sort(q3.begin(), q3.end(), cmp);     sort(q4.begin(), q4.end(), cmp);     int ans = 0;     for (int i = 0; i < q1.size(); i++) {       ans += 4;       if (q1[i].second != 0) {         ans += 2;       }     }     for (int i = 0; i < q2.size(); i++) {       ans += 4;       if (q2[i].first != 0) {         ans += 2;       }     }     for (int i = 0; i < q3.size(); i++) {       ans += 4;       if (q3[i].second != 0) {         ans += 2;       }     }     for (int i = 0; i < q4.size(); i++) {       ans += 4;       if (q4[i].first != 0) {         ans += 2;       }     }     cout << ans << endl;     for (int i = 0; i < q1.size(); i++) {       cout <<  1   << abs(q1[i].first) <<   R n ;       if (q1[i].second != 0) {         cout <<  1   << abs(q1[i].second) <<   U n ;       }       cout << 2 << endl;       if (q1[i].second != 0) {         cout <<  1   << abs(q1[i].second) <<   D n ;       }       cout <<  1   << abs(q1[i].first) <<   L n ;       cout << 3 << endl;     }     for (int i = 0; i < q2.size(); i++) {       cout <<  1   << abs(q2[i].second) <<   U n ;       if (q2[i].first != 0) {         cout <<  1   << abs(q2[i].first) <<   L n ;       }       cout << 2 << endl;       if (q2[i].first != 0) {         cout <<  1   << abs(q2[i].first) <<   R n ;       }       cout <<  1   << abs(q2[i].second) <<   D n ;       cout << 3 << endl;     }     for (int i = 0; i < q3.size(); i++) {       cout <<  1   << abs(q3[i].first) <<   L n ;       if (q3[i].second != 0) {         cout <<  1   << abs(q3[i].second) <<   D n ;       }       cout << 2 << endl;       if (q3[i].second != 0) {         cout <<  1   << abs(q3[i].second) <<   U n ;       }       cout <<  1   << abs(q3[i].first) <<   R n ;       cout << 3 << endl;     }     for (int i = 0; i < q4.size(); i++) {       cout <<  1   << abs(q4[i].second) <<   D n ;       if (q4[i].first != 0) {         cout <<  1   << abs(q4[i].first) <<   R n ;       }       cout << 2 << endl;       if (q4[i].first != 0) {         cout <<  1   << abs(q4[i].first) <<   L n ;       }       cout <<  1   << abs(q4[i].second) <<   U n ;       cout << 3 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2007;   set<pair<int, int> > E[N];   struct edge {     int x, y;   } e[N];   int n, rk[N], mxrk, mxid;   void adde(int x, int y, int i) {     E[x].insert(make_pair(y, i)), E[y].insert(make_pair(x, i));   }   void dele(int i) {     int x = e[i].x, y = e[i].y;     E[x].erase(make_pair(y, i)), E[y].erase(make_pair(x, i));     printf( ? %d %d n , x, y), fflush(stdout);   }   bool check(vector<pair<__int128, int> > &ve, __int128 x) {     priority_queue<pair<__int128, int> > q;     for (auto u : ve) q.push(u);     for (int i = n - 1; i >= 0; i--)       if (x >> i & 1) {         pair<__int128, int> v = q.top();         q.pop();         v.first -= __int128(1) << i, rk[v.second] = i;         q.push(v);       }     return q.top().first < 0;   }   __int128 produce(vector<pair<__int128, int> > &ve) {     if (!ve.size()) return 0;     __int128 z = (__int128(1) << n) - 1;     for (int i = n - 1; i >= 0; i--)       if (check(ve, z - (__int128(1) << i))) z -= __int128(1) << i;     check(ve, z);     return z;   }   __int128 dfs(int v, int fa) {     vector<pair<__int128, int> > ve;     for (auto x : E[v]) {       int u = x.first;       if (u == fa) continue;       ve.push_back(make_pair(dfs(u, v), x.second));     }     return produce(ve);   }   void find(int v, int fa) {     for (auto x : E[v]) {       int u = x.first, i = x.second;       if (u == fa) continue;       if (rk[i] > mxrk) mxrk = rk[i], mxid = i;       find(u, v);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       adde(x, y, i), adde(y, x, i);       e[i] = {x, y};     }     dfs(1, 0);     int rt = 1;     while (1) {       mxrk = -1, mxid = 0;       find(rt, 0);       if (mxrk == -1) break;       dele(mxid);       scanf( %d , &rt);     }     printf( ! %d n , rt), fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long bin_pow(long long a, long long b) {     if (b == 0) return 1;     if (b % 2 == 0) {       long long t = bin_pow(a, b / 2);       return t * t % 1000000007;     } else       return a * bin_pow(a, b - 1) % 1000000007;   }   vector<long long> a;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long t = 1, n, m, k = 0, x = 0, y = 0, z = 0, sum = 0, l = 0, r = 0,               ans = 0, mn = LLONG_MAX, mx = LLONG_MIN;     cin >> n;     a.resize(n);     vector<pair<long long, long long> > d;     stack<long long> s;     for (int i = 0; i < n; i++) cin >> a[i];     t = 0;     for (int i = 0; i < n; i++) {       if (a[i] < t) {         while (a[i] != t) {           x = s.top();           s.pop();           d.push_back({x, i});           t--;         }       } else {         while (a[i] != t) {           s.push(i + 1);           t++;         }       }     }     while (!s.empty()) {       x = s.top();       d.push_back({x, n});       s.pop();     }     cout << d.size() <<   n ;     for (auto u : d) cout << u.first <<     << u.second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> graph[5001];   bool subset[5001][5001];   set<pair<int, int>> ans_pairs;   vector<int> child_nodes(5001, -1);   int total_nodes;   void insert_into_answer(int network1, int network2) {     if (network1 != 0 && network2 != 0) {       ans_pairs.insert({network1, network2});       ans_pairs.insert({network2, network1});     }     return;   }   bool isSubsetSum(vector<int> &set, int n, int sum) {     for (int i = 0; i <= set.size(); i++) subset[i][0] = true;     for (int j = 1; j <= sum; j++) subset[0][j] = false;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= sum; j++) {         if (j < set[i - 1]) subset[i][j] = subset[i - 1][j];         if (j >= set[i - 1])           subset[i][j] = subset[i - 1][j] || subset[i - 1][j - set[i - 1]];       }     }     return subset[n][sum];   }   int dfs(int id, int parent) {     if (child_nodes[id] != -1) {       return child_nodes[id];     }     if (graph[id].size() == 0) {       return child_nodes[id] = 1;     }     int temp = 0;     for (long long i = 0; i < graph[id].size(); i++) {       if (graph[id][i] != parent) {         temp += dfs(graph[id][i], id);       }     }     return child_nodes[id] = temp + 1;   }   void solve(int id, int parent) {     insert_into_answer(child_nodes[id] - 1, total_nodes - child_nodes[id]);     vector<int> childs_to_adjacent;     for (long long i = 0; i < graph[id].size(); i++) {       if (graph[id][i] != parent) {         childs_to_adjacent.push_back(child_nodes[graph[id][i]]);       }     }     isSubsetSum(childs_to_adjacent, childs_to_adjacent.size(), child_nodes[id]);     int child_length = childs_to_adjacent.size();     for (long long i = 1; i < child_nodes[id]; i++) {       if (subset[child_length][i]) {         insert_into_answer(i, total_nodes - i - 1);       }     }     for (long long i = 0; i < graph[id].size(); i++) {       if (graph[id][i] != parent) {         solve(graph[id][i], id);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> total_nodes;     int x, y;     for (long long i = 1; i < total_nodes; i++) {       cin >> x >> y;       graph[x - 1].push_back(y - 1);       graph[y - 1].push_back(x - 1);     }     int a = dfs(0, -1);     solve(0, -1);     cout << ans_pairs.size() << endl;     for (auto it : ans_pairs) {       cout << it.first <<     << it.second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     cin >> a >> b >> c >> d;     int e = max(c, d);     if (e > 2 * c || e > 2 * d || e >= b) {       cout << -1;       return 0;     }     cout << 2 * a << endl << 2 * b << endl << e;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string str;       int n;       cin >> n;       cin.ignore();       getline(cin, str);       int l = 0, r = n - 1;       while (l < n && str[l] ==  0 ) {         l++;       }       while (r >= 0 && str[r] ==  1 ) {         r--;       }       if (l >= r) {         cout << str << endl;       } else {         cout << str.substr(0, l) <<  0  << str.substr(r + 1, n) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k, l;       cin >> n >> k;       vector<int> barrel;       for (int i = 0; i < n; i++) {         cin >> l;         barrel.push_back(l);       }       sort(barrel.begin(), barrel.end());       long long int resp = 0;       k++;       while (k--) {         resp += barrel.back();         barrel.pop_back();       }       cout << resp << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   char buf[100000];   vector<pair<int, string> > vp;   int b[maxn], n, m;   pair<int, string> me;   int getL() {     int tx = 0, ret = 1;     if (m == n) {       me.first -= b[0];       tx = 1;     }     for (int i = 0; i < (int)vp.size(); i++) {       if (vp[i] < me) {         ret++;         continue;       }       while (tx < m) {         pair<int, string> tmp = vp[i];         tmp.first -= b[tx];         tx++;         if (tmp < me) {           ret++;           break;         }       }     }     if (m == n) me.first += b[0];     return ret;   }   int getH() {     me.first -= b[m - 1];     int tx = m - 2, ret = 1;     vector<pair<int, string> > vp2;     for (int i = 0; i < (int)vp.size(); i++) {       if (vp[i] < me) {         if (tx >= 0) tx--;         ret++;       } else         vp2.push_back(vp[i]);     }     for (int i = (int)vp2.size() - 1; i >= 0; i--) {       while (tx >= 0) {         pair<int, string> tmp = vp2[i];         tmp.first -= b[tx];         tx--;         if (tmp < me) {           ret++;         } else           break;       }     }     while (tx >= 0) {       ret++;       tx--;     }     me.first += b[m - 1];     return ret;   }   int main() {     while (scanf( %d , &n) != EOF) {       vp.clear();       for (int i = 0; i < n; i++) {         int tmp;         scanf( %s%d , buf, &tmp);         vp.push_back(make_pair(-tmp, string(buf)));       }       scanf( %d , &m);       for (int i = 0; i < m; i++) {         scanf( %d , &b[i]);       }       sort(b, b + m);       scanf( %s , buf);       string s(buf);       for (int i = 0; i < (int)vp.size(); i++) {         if (vp[i].second == s) {           me = vp[i];           swap(vp[i], vp[vp.size() - 1]);           vp.pop_back();           break;         }       }       sort(vp.begin(), vp.end());       printf( %d %d n , getH(), getL());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > v;   int promena[3002];   long long d[3001], s[3002][3002], pom;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int j, n, i, x, p;     cin >> n;     for (i = 0; i < n; i++) {       cin >> x >> p;       v.push_back(make_pair(x, p));     }     sort(v.begin(), v.end());     d[n - 1] = v[n - 1].second;     for (i = 0; i < n - 1; i++)       for (j = i + 1; j < n; j++)         s[i][j] = s[i][j - 1] + (long long)v[j].first - v[i].first;     for (i = n - 2; i >= 0; i--) {       for (j = i; j < n; j++) {         pom = d[j + 1] + s[i][j] + (long long)v[i].second;         if (promena[i] == 0) {           d[i] = pom;           promena[i] = 1;         } else {           if (d[i] > pom) d[i] = pom;         }       }     }     cout << d[0];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int n;     cin >> n;     long long int a[n];     map<long long int, long long int> mp;     for (long long int i = 0; i < n; i++) {       cin >> a[i];       mp[a[i]] = i;     }     long long int prev = mp[1];     long long int mx = 1;     for (long long int i = 2; i <= n; i++) {       if (mp[i] > mp[i - 1]) {         long long int j = i;         long long int cnt = 1;         while (mp[j] > mp[j - 1]) {           cnt++;           j++;         }         mx = max(mx, cnt);         i = j - 1;       }     }     long long int ans = n - mx;     cout << ans <<   n ;     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;   }


#include <bits/stdc++.h>   using namespace std;   bool SR(int &_x) { return scanf( %d , &_x) == 1; }   bool SR(long long &_x) { return scanf( %lld , &_x) == 1; }   bool SR(double &_x) { return scanf( %lf , &_x) == 1; }   bool SR(char *_s) { return scanf( %s , _s) == 1; }   bool RI() { return true; }   template <typename I, typename... T>   bool RI(I &_x, T &..._tail) {     return SR(_x) && RI(_tail...);   }   void SP(const int _x) { printf( %d , _x); }   void SP(const long long _x) { printf( %lld , _x); }   void SP(const double _x) { printf( %.16lf , _x); }   void SP(const char *s) { printf( %s , s); }   void PL() { puts(  ); }   template <typename I, typename... T>   void PL(const I _x, const T... _tail) {     SP(_x);     if (sizeof...(_tail)) putchar(   );     PL(_tail...);   }   const int maxn = 55;   struct Solver {     int wid, hei;     char mp[maxn][maxn];     void rot(int x, int y) {       if (mp[x][y] ==  L ) {         for (int i : {x, x + 1})           for (int j : {y, y + 1}) mp[i][j] =  UD [i - x];       } else {         for (int i : {x, x + 1})           for (int j : {y, y + 1}) mp[i][j] =  LR [j - y];       }     }     vector<pair<int, int> > solve() {       assert(wid % 2 == 0);       vector<pair<int, int> > ret;       for (int i = 0; i < int(hei); i++)         for (int j = 0; j < wid; j += 2) {           vector<pair<int, int> > cur;           int x = i, y = j, f = 0;           while (1) {             if ((f == 0 && mp[x][y] ==  L ) || (f == 1 && mp[x][y] ==  U )) break;             cur.push_back({x, y});             if (f == 0)               y++;             else               x++;             f ^= 1;           }           reverse((cur).begin(), (cur).end());           for (auto p : cur) rot(p.first, p.second);           ret.insert(ret.end(), (cur).begin(), (cur).end());         }       return ret;     }   } sol0, sol1;   int n, m;   char f0[maxn][maxn], f1[maxn][maxn];   void read() {     RI(n, m);     for (int i = 0; i < int(n); i++) RI(f0[i]);     for (int i = 0; i < int(n); i++) RI(f1[i]);   }   bool flip;   void build() {     if (m % 2) {       flip = 1;       auto rev = [&](char c) {         if (c ==  L ) return  U ;         if (c ==  R ) return  D ;         if (c ==  U ) return  L ;         if (c ==  D ) return  R ;         assert(0);       };       {         sol0.hei = m;         sol0.wid = n;         for (int i = 0; i < int(n); i++)           for (int j = 0; j < int(m); j++) sol0.mp[j][i] = rev(f0[i][j]);         sol1.hei = m;         sol1.wid = n;         for (int i = 0; i < int(n); i++)           for (int j = 0; j < int(m); j++) sol1.mp[j][i] = rev(f1[i][j]);       }     } else {       sol0.hei = n;       sol0.wid = m;       for (int i = 0; i < int(n); i++)         for (int j = 0; j < int(m); j++) sol0.mp[i][j] = f0[i][j];       sol1.hei = n;       sol1.wid = m;       for (int i = 0; i < int(n); i++)         for (int j = 0; j < int(m); j++) sol1.mp[i][j] = f1[i][j];     }   }   void sol() {     auto res0 = sol0.solve(), res1 = sol1.solve();     reverse((res1).begin(), (res1).end());     res0.insert(res0.end(), (res1).begin(), (res1).end());     if (flip)       for (auto &p : res0) swap(p.first, p.second);     PL(((int)(res0).size()));     for (auto p : res0) PL(p.first + 1, p.second + 1);   }   int main() {     read();     build();     sol();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int setBit(int N, int pos) { return N = N | (1 << pos); }   inline int resetBit(int N, int pos) { return N = N & ~(1 << pos); }   inline bool checkBit(int N, int pos) { return (bool)(N & (1 << pos)); }   int A[400000 + 10];   vector<int> nxt[400000 + 10];   int idx[400000 + 10];   struct data {     int id, p;   };   bool operator<(data a, data b) { return a.p < b.p; }   priority_queue<data> Q;   int holding[400000 + 10];   void validate(int i) {     while (Q.size() && Q.top().p <= i) Q.pop();   }   int main() {     int n, k;     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &A[i]), nxt[A[i]].push_back(i);     for (int i = 1; i <= n; i++) nxt[i].push_back(n + 1), idx[i] = 1;     int ans = 0;     int have = 0;     for (int i = 1; i <= n; i++) {       if (holding[A[i]] == true) {         Q.push({A[i], nxt[A[i]][idx[A[i]]]});         idx[A[i]]++;       } else {         if (have < k) {           have++;           ans++;           Q.push({A[i], nxt[A[i]][idx[A[i]]]});           idx[A[i]]++;           holding[A[i]] = true;         } else {           validate(i);           ans++;           holding[Q.top().id] = false;           Q.pop();           Q.push({A[i], nxt[A[i]][idx[A[i]]]});           holding[A[i]] = true;           idx[A[i]]++;         }       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100 + 3;   int n, m, k, ns[MAX];   long long dp[MAX][MAX][MAX], cs[MAX][MAX];   long long solve(int cur = 0, int pre = 0, int rem = k) {     if (cur == n && rem == 0) return 0;     if (rem < 0 || (cur == n && rem != 0)) return 1e18;     long long &ret = dp[cur][pre][rem];     if (ret != -1) return ret;     if (ns[cur] == 0) {       ret = 1e18;       for (int i = 1; i <= m; i++)         ret = min(ret, solve(cur + 1, i, rem - (pre != i)) + cs[cur][i - 1]);     } else {       if (ns[cur] == pre)         ret = solve(cur + 1, pre, rem);       else         ret = solve(cur + 1, ns[cur], rem - 1);     }     return ret;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     memset(dp, -1, sizeof(dp));     for (int i = 0; i < n; i++) {       scanf( %d , &ns[i]);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         scanf( %d , &cs[i][j]);       }     }     long long ans = solve();     if (ans == 1e18)       printf( -1 );     else       printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, i, count = 0;     vector<long long int> v;     string s1, s2, s3, reverses1, reverses2, reverses3;     cin >> s1 >> s2 >> s3;     reverses1 = s1;     reverses2 = s2;     reverses3 = s3;     reverse(s1.begin(), s1.end());     reverse(s2.begin(), s2.end());     reverse(s3.begin(), s3.end());     if (reverses1 == s3 && reverses2 == s2 && reverses3 == s1)       cout <<  YES             <<   n ;     else       cout <<  NO             <<   n ;   }   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int main() {     fast();     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 3e18 + 100;   const int MOD = 1e9 + 7;   const int N = 100;   int32_t main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin.exceptions(cin.failbit);     int n;     cin >> n;     set<int> s, tot;     vector<int> a(n + 5, 0), cnt(n + 5, 0), last(n + 5);     vector<bool> ok(n + 4, true);     for (int i = 1; i <= n; ++i) {       s.insert(i);     }     for (int i = 1; i <= n; ++i) {       cin >> a[i];       cnt[a[i]]++;       tot.insert(a[i]);       if (s.find(a[i]) != s.end()) {         s.erase(a[i]);       }     }     cout << n - tot.size() << endl;     for (int i = 1; i <= n; ++i) {       if (cnt[a[i]] == 1) continue;       if (ok[a[i]] and *s.begin() > a[i]) {         ok[a[i]] = false;       } else {         cnt[a[i]]--;         a[i] = *s.begin();         s.erase(s.begin());       }     }     for (int i = 1; i <= n; ++i) {       cout << a[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, cnt;     string s;     map<int, pair<int, int> > mapp;     cin >> n;     cin >> s;     cnt = 0;     int maxm = 0;     for (i = 0; i < n; i++) {       if (s[i] ==  0 )         cnt--;       else         cnt++;       if (mapp.find(cnt) == mapp.end()) {         mapp[cnt].first = i;         mapp[cnt].second = i;       } else {         mapp[cnt].second = i;         int len = mapp[cnt].second - mapp[cnt].first;         if (len > maxm) maxm = len;       }     }     if (mapp.find(0) != mapp.end()) maxm = max(maxm, mapp[0].second + 1);     cout << maxm << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const vector<int> mods = {998244353, 1000000007, 1000000009};   const long long inf = 3e18;   const double pi = acos(-1.0);   const double eps = 0.0000001;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   template <class... K>   using umap = unordered_map<K...>;   template <class... K>   using uset = unordered_set<K...>;   const int N = 1000100;   int n, l[N];   vector<vector<int> > a, ord;   string s;   umap<int, long long> dp;   long long res;   void build(int x) {     vector<int> cur = {};     vector<int> bk;     auto ad = [&](vector<int>& to) {       while (((int)(cur).size())) {         to.push_back(cur.back());         cur.pop_back();       }     };     for (long long i = (0); i < (l[x] - 1); ++i) {       cur.push_back(i);       if (a[x][i] < a[x][i + 1]) ad(ord[x]);       if (a[x][i] > a[x][i + 1]) ad(bk);     }     cur.push_back(l[x] - 1);     ad(ord[x]);     for (int i = ((int)(bk).size()) - 1; i >= 0; i--) ord[x].push_back(bk[i]);   }   int p(int i, int si) { return i + (i >= si); }   bool gt(int i, int si, int j, int sj) {     int pp = 0;     while (p(pp, si) < l[i] && p(pp, sj) < l[j]) {       int ppi = p(pp, si), ppj = p(pp, sj);       if (a[i][ppi] < a[j][ppj]) return 0;       if (a[i][ppi] > a[j][ppj]) return 1;       pp++;     }     long long il = l[i] - (si != l[i] - 1);     long long jl = l[j] - (sj != l[j] - 1);     if (il > jl)       return 1;     else       return 0;   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cout.precision(13);     cin >> n;     a.resize(n + 1);     ord.resize(n + 1);     for (long long i = (0); i < (n); ++i) {       cin >> s;       l[i] = s.length() + 1;       for (long long j = (0); j < (l[i] - 1); ++j) a[i].push_back(s[j] -  a );       a[i].push_back(-1);     }     a[n] = {27, -1};     l[n] = 2;     for (long long i = (0); i < (n + 1); ++i) build(i);     dp[0] = 1;     dp[1] = 0;     for (int i = n; i >= 1; i--) {       umap<int, long long> nxdp;       int j = i - 1;       int pi = 0, pj = 0;       long long pre = 0;       while (pi < l[i] || pj < l[j]) {         if (pi >= l[i] || pj < l[j] && gt(j, ord[j][pj], i, ord[i][pi]))           nxdp[pj++] = pre;         else           pre = (pre + dp[pi++]) % mod;       }       dp = move(nxdp);     }     for (auto& d_ : dp) res = (res + d_.second) % mod;     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2200000;   int chk[N];   int main() {     ios_base::sync_with_stdio(0);     int cnt = 0, n, m;     cin >> n >> m;     for (int i = 0; i < n; i++)       if (!chk[i]) {         for (int j = i;              (j < n && chk[j] < 2) || (j >= n && chk[n + n - 2 - j] < 2);              j = (j + m + m - 2) % (n + n - 2)) {           if (j < n)             chk[j]++;           else             chk[n + n - 2 - j]++;         }         cnt++;       }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[55][55];   const int MAX = 1e3 + 5;   const int INF = 0x3f3f3f3f;   int color;   int A[MAX][MAX];   int A1[MAX][MAX], A2[MAX][MAX];   int N;   int DX[2] = {0, 1}, DY[2] = {1, 0};   int NOW1[4], NOW2[4];   int X1, Y1, X2, Y2;   bool FLAG = false;   bool VIS[MAX][MAX];   void dfs(int x, int y, int count) {     if (FLAG) return;     if (count == 4) {       if (NOW1[1] == NOW1[2] && NOW1[0] == NOW1[3]) {         if (NOW2[1] != NOW2[2] || NOW2[0] != NOW2[3]) {           FLAG = true;           X2 = x, Y2 = y;           color = 1;           return;         }       }       if (NOW2[1] == NOW2[2] && NOW2[0] == NOW2[3]) {         if (NOW1[1] != NOW1[2] || NOW1[0] != NOW1[3]) {           FLAG = true;           X2 = x, Y2 = y;           color = 2;           return;         }       }       return;     }     for (int i = 0; i < 2; ++i) {       int numX = x + DX[i];       int numY = y + DY[i];       if (numX >= 1 && numX <= N && numY >= 1 && numY <= N && !VIS[numX][numY]) {         NOW1[count] = A1[numX][numY];         NOW2[count] = A2[numX][numY];         VIS[numX][numY] = true;         dfs(numX, numY, count + 1);         VIS[numX][numY] = false;       }     }   }   void solve() {     for (int i = 1; i <= N; ++i) {       for (int j = 1; j <= N; ++j) {         A[i][j] = a[i][j];         if ((i + j) & 1) {           if (A[i][j] == 0)             A1[i][j] = 1, A2[i][j] = 0;           else             A1[i][j] = 0, A2[i][j] = 1;         } else           A1[i][j] = A2[i][j] = A[i][j];       }     }     for (int i = 1; i <= N; ++i) {       for (int j = 1; j <= N; ++j) {         NOW1[0] = A1[i][j];         NOW2[0] = A2[i][j];         VIS[i][j] = true;         dfs(i, j, 1);         VIS[i][j] = false;         if (FLAG) {           X1 = i, Y1 = j;           return;         }       }     }   }   int main() {     int n, t;     scanf( %d , &n);     N = n;     a[1][1] = 1;     a[1][2] = 0;     a[n][n] = 0;     printf( ? %d %d %d %d n , 1, 2, 2, 3);     fflush(stdout);     scanf( %d , &t);     if (t == 1)       a[2][3] = a[1][2];     else       a[2][3] = a[1][2] ^ 1;     printf( ? %d %d %d %d n , 2, 1, 2, 3);     fflush(stdout);     scanf( %d , &t);     if (t == 1)       a[2][1] = a[2][3];     else       a[2][1] = a[2][3] ^ 1;     for (int i = 3; i <= n; i++) {       printf( ? %d %d %d %d n , i - 2, 1, i, 1);       fflush(stdout);       scanf( %d , &t);       if (t == 1)         a[i][1] = a[i - 2][1];       else         a[i][1] = a[i - 2][1] ^ 1;       printf( ? %d %d %d %d n , 1, i - 2, 1, i);       fflush(stdout);       scanf( %d , &t);       if (t == 1)         a[1][i] = a[1][i - 2];       else         a[1][i] = a[1][i - 2] ^ 1;     }     for (int i = 2; i <= n; i++) {       for (int j = 2; j <= n; j++) {         if (i == j && j == n) continue;         if (i == 2 && j == 3) continue;         printf( ? %d %d %d %d n , i - 1, j - 1, i, j);         fflush(stdout);         scanf( %d , &t);         if (t == 1)           a[i][j] = a[i - 1][j - 1];         else           a[i][j] = a[i - 1][j - 1] ^ 1;       }     }     solve();     printf( ? %d %d %d %d n , X1, Y1, X2, Y2);     fflush(stdout);     scanf( %d , &t);     printf( ! n );     if (t == 1) {       if (color == 1) {         for (int i = 1; i <= n; i++) {           for (int j = 1; j <= n; j++) {             if ((i + j) % 2 == 1)               printf( %d , a[i][j] ^ 1);             else               printf( %d , a[i][j]);           }           printf(  n );         }       } else {         for (int i = 1; i <= n; i++) {           for (int j = 1; j <= n; j++) printf( %d , a[i][j]);           printf(  n );         }       }     } else {       if (color == 2) {         for (int i = 1; i <= n; i++) {           for (int j = 1; j <= n; j++) {             if ((i + j) % 2 == 1)               printf( %d , a[i][j] ^ 1);             else               printf( %d , a[i][j]);           }           printf(  n );         }       } else {         for (int i = 1; i <= n; i++) {           for (int j = 1; j <= n; j++) printf( %d , a[i][j]);           printf(  n );         }       }     }   }


#include <bits/stdc++.h>   int main() {     int n, i, b;     while (scanf( %d , &n) != EOF) {       int j = 0, str[10001] = {0}, total = 0;       for (i = 0; i < n; i++) {         scanf( %d , &b);         if (str[b] == 0) ++total;         ++str[b];         if (str[b] > j) j = str[b];       }       printf( %d %d n , j, total);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double eps = 1e-6;   double pi = acos(0.0) * 2;   double dinf = 1e250;   long long INF = static_cast<long long>(2e18);   long long inf = static_cast<long long>(1e9 + 7);   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   template <class T>   void OUT(T a) {     cout << a;     exit(0);   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long extgcd(long long a, long long b, long long& x, long long& y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long d = extgcd(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return d;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       long long x, y, k;       cin >> x >> y >> k;       if (x < 0) x = -x;       if (y < 0) y = -y;       if (x < y) swap(x, y);       if (x > k)         cout << -1 << endl;       else {         if ((x & 1) != (y & 1)) {           k -= 1;           x -= 1;         } else if ((x & 1) != (k & 1)) {           x -= 1;           y -= 1;           k -= 2;         }         cout << k << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, x, y, a, b, c, t, q;     string s;     while (cin >> n >> q) {       if ((n / q) % 2 == 0) {         cout <<  NO  << endl;       } else         cout <<  YES  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int a[100001], l = 1;     for (int i = 1; i <= n; i++) {       int c, t;       cin >> c >> t;       int x = c * t;       a[l] = c * t;       l++;     }     int d = 1, s = 0;     for (int i = 0; i < m; i++) {       int k;       cin >> k;       if (s + a[d] >= k) {         cout << d << endl;       } else {         while (1) {           s += a[d];           d++;           if (s + a[d] >= k) {             cout << d << endl;             break;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void OJ() {}   long long n, m, x, k, y;   long long a[200000 + 5], b[200000 + 5];   void imp() { cout << -1 <<   n , exit(0); }   long long remove(long long start, long long end) {     if (start > end) return 0;     long long sz = end - start + 1;     long long maxneb = max(a[start - 1], a[end + 1]);     long long m = *max_element(a + start, a + end + 1);     long long a1 = (sz / k) * x + (sz % k) * y;     if (maxneb > m) return min(a1, y * sz);     if (sz < k) imp();     return min(a1, (sz - k) * y + x);   }   void solve() {     cin >> n >> m >> x >> k >> y;     for (long long i = 1; i <= n; ++i) cin >> a[i];     for (long long i = 1; i <= m; ++i) cin >> b[i];     long long ans = 0;     long long j = 1;     for (long long i = 1; i <= m; ++i) {       long long start = j;       while (j <= n && a[j] != b[i]) j++;       if (j > n) imp();       ans += remove(start, j - 1);       j++;     }     ans += remove(j, n);     cout << ans <<   n ;   }   signed main() {     OJ();     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   const int N = 100005;   void solve() {     long long n;     cin >> n;     long long ans = 1;     for (long long i = 2; i <= n; i++) {       ans = ans + 4 * (i - 1);     }     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       solve();     }     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ton {     vector<pair<long long, long long> > v[1919810 + 3];     long long& operator()(long long a, int b, int c, int d) {       a = ((a * 4000ll + b) * 4000ll + c) * 3ll + (d == 1);       int k = a % 1919810;       for (auto u = v[k].begin(); u != v[k].end(); u++)         if (u->first == a) return u->second;       v[k].push_back(make_pair(a, -1e17));       return v[k].back().second;     }   } f;   long long s[100010];   long long F(int l, int r, int k, int p) {     if (r - l + 1 < k) return 0;     if (r - l + 1 == k) return p * (s[r] - s[l - 1]);     long long& u = f(l, r, k, p);     if (u != -1e17) return u;     if (p == -1)       u = min(F(l, r - k, k, 1) - (s[r] - s[r - k]),               F(l, r - k - 1, k + 1, 1) - (s[r] - s[r - k - 1]));     else       u = max(F(l + k, r, k, -1) + (s[l + k - 1] - s[l - 1]),               F(l + k + 1, r, k + 1, -1) + (s[l + k] - s[l - 1]));     return u;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lld , &s[i]), s[i] += s[i - 1];     printf( %lld n , F(1, n, 1, 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char dirs[100001];   int todo[4];   int main() {     int n, fx, fy, tx, ty;     string wind;     cin >> n >> fx >> fy >> tx >> ty >> wind;     memcpy(dirs, wind.c_str(), n);     memset(todo, 0, sizeof(todo));     if (fx < tx) todo[0] = tx - fx;     if (fy < ty) todo[3] = ty - fy;     if (fx > tx) todo[2] = fx - tx;     if (fy > ty) todo[1] = fy - ty;     for (int i = 0; i < n; i++) {       switch (dirs[i]) {         case  E :           if (todo[0]) todo[0]--;           break;         case  S :           if (todo[1]) todo[1]--;           break;         case  W :           if (todo[2]) todo[2]--;           break;         case  N :           if (todo[3]) todo[3]--;           break;       }       if (todo[0] == 0 && todo[1] == 0 && todo[2] == 0 && todo[3] == 0) {         cout << i + 1 << endl;         return 0;       }     }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, p;     cin >> t;     for (; t > 0; t--) {       cin >> n >> p;       int br = 0;       for (int r = 1; r <= n; r++) {         for (int i = 1; i <= n; i++) {           cout << i <<     << (i + r - 1) % n + 1 << endl;           br++;           if (br == 2 * n + p) goto st;         }       }     st:;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int div_floor(const long long int &a, const long long int &b) {     return a / b - (((a ^ b) < 0) and a % b);   }   long long int div_ceil(const long long int &a, const long long int &b) {     return a / b + (((a ^ b) >= 0) and a % b);   }   long long int diff(long long int a, long long int cnt) {     long long int rem = a % cnt;     return a * a - ((a / cnt + 1) * (a / cnt + 1) * rem +                     (a / cnt) * (a / cnt) * (cnt - rem));   }   void solve() {     long long int n, k;     cin >> n >> k;     long long int sum = 0;     multiset<pair<long long int, pair<long long int, long long int> > > mst;     vector<long long int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i] * a[i];       mst.insert({diff(a[i], 2), {a[i], 2}});     }     while (n++ < k) {       auto it = mst.end();       it--;       auto el = *it;       mst.erase(it);       sum -= el.first;       long long int x = el.second.first, ct = el.second.second;       mst.insert({diff(x, ct + 1) - diff(x, ct), {x, ct + 1}});     }     cout << sum <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[111];   int vv(int k) {     int i, j;     j = 0;     for (i = 1; i < k; i++)       if (a[i] == 0) j++;     for (i = k; i <= n; i++)       if (a[i] == 1) j++;     return j;   }   int main() {     cin >> n;     int i, j, k;     for (i = 1; i <= n; i++) cin >> a[i];     a[n + 1] = 1;     int d = 1;     for (i = 0; i <= n + 1; i++) {       d = max(vv(i), d);     }     cout << d;   }


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