#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     vector<long long> v, v1;     map<long long, long long> m;     for (long long i = 0; i < n; i++) {       long long a;       cin >> a;       v.push_back(a);     }     long long a, c = 0;     cin >> a;     for (long long i = 0; i < n; i++)       if (v[i] > ((i + 1) * a + k)) c = -1;     long long val = k;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       v1.push_back(a);     }     long long sum = 0;     if (c == 0) {       for (long long i = 0; i < n; i++) {         m[v1[i]]++;         auto itr = m.begin();         while (v[i] > val && itr != m.end()) {           if (itr->second == 0 && itr != m.end()) {             auto itr1 = itr;             itr1++;             m.erase(itr->first);             itr = m.find(itr1->first);           } else {             val += a;             sum += itr->first;             (itr->second)--;           }         }       }       cout << sum <<   n ;     } else       cout <<  -1             <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, nc, a[111], b[111];   string c[111];   struct Node {     int lab;     Node *left, *right;     Node(int x) {       lab = x;       left = NULL;       right = NULL;     }   };   void printfalse() {     cout <<  IMPOSSIBLE ;     exit(0);   }   Node *solve(int x, int y) {     if (x > y) return NULL;     if (x == y) return new Node(x);     int l = -1, r = n + 1;     for (int i = (1); i <= (nc); i++) {       int u = a[i], v = b[i];       if (u == x) {         if (c[i][0] ==  L ) {           l = max(l, v);         } else {           r = min(r, v);         }       }     }     for (int s = (max(x, l)); s <= (min(y, r - 1)); s++) {       bool ok = true;       for (int i = (1); i <= (nc); i++) {         int u = a[i], v = b[i];         if (x < min(u, v) && min(u, v) <= s && s < max(u, v)) {           ok = false;         }       }       if (!ok) continue;       Node *r = new Node(x);       r->left = solve(x + 1, s);       r->right = solve(s + 1, y);       return r;     }     printfalse();   }   void print(Node *r) {     if (r == NULL) return;     print(r->left);     cout << r->lab <<    ;     print(r->right);   }   bool find(Node *u, int v) {     if (u == NULL) return false;     if (u->lab == v) return true;     return find(u->left, v) || find(u->right, v);   }   void visit(Node *u) {     if (u == NULL) return;     for (int i = (1); i <= (nc); i++)       if (a[i] == u->lab) {         if (c[i][0] ==  L ) {           if (!find(u->left, b[i])) printfalse();         } else {           if (!find(u->right, b[i])) printfalse();         }       }     visit(u->left);     visit(u->right);   }   int main() {     cin >> n >> nc;     for (int i = (1); i <= (nc); i++) {       cin >> a[i] >> b[i] >> c[i];     }     Node *r = solve(1, n);     visit(r);     print(r);   }


#include <bits/stdc++.h>   using namespace std;   int a[300000], b[300000];   int tree[1 << 21], lazy[1 << 21];   int prop(int s, int e, int i) {     tree[i] += lazy[i];     if (s != e) lazy[2 * i + 1] += lazy[i], lazy[2 * i + 2] += lazy[i];     lazy[i] = 0;     return 0;   }   int update(int s, int e, int as, int ae, int i, int num) {     prop(s, e, i);     if ((s > ae) || (e < as))       return tree[i];     else if ((s >= as) && (e <= ae)) {       lazy[i] += num;       prop(s, e, i);       return tree[i];     }     int mid = (s + e) / 2;     update(s, mid, as, ae, 2 * i + 1, num),         update(mid + 1, e, as, ae, 2 * i + 2, num);     tree[i] = min(tree[2 * i + 1], tree[2 * i + 2]);     return tree[i];   }   int query(int s, int e, int i) {     prop(s, e, i);     if (s == e) return s;     int mid = (s + e) / 2;     prop(mid + 1, e, 2 * i + 2);     if (tree[2 * i + 2] < 0)       return query(mid + 1, e, 2 * i + 2);     else       return query(s, mid, 2 * i + 1);   }   int main() {     int i;     int n, m, q;     int t, j, x;     scanf( %d %d , &n, &m);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i < m; i++) scanf( %d , &b[i]);     for (i = 0; i < n; i++) update(0, 1000000, 1, a[i], 0, -1);     for (i = 0; i < m; i++) update(0, 1000000, 1, b[i], 0, 1);     scanf( %d , &q);     for (i = 0; i < q; i++) {       scanf( %d %d %d , &t, &j, &x), j--;       if (t == 1) {         update(0, 1000000, 1, a[j], 0, 1);         a[j] = x;         update(0, 1000000, 1, a[j], 0, -1);       } else {         update(0, 1000000, 1, b[j], 0, -1);         b[j] = x;         update(0, 1000000, 1, b[j], 0, 1);       }       int ans = query(0, 1000000, 0);       if (ans == 0)         printf( -1 n );       else         printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const string problemName =   ;   const string inputFile = problemName +  .in ;   const string outputFile = problemName +  .out ;   const int INF = (1LL << 31) - 1;   const long long int LINF = (1LL << 62) - 1;   const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};   const int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};   const int MOD = (int)(1e9) + 7;   const int NMAX = 100000 + 5;   const int MMAX = 100000 + 5;   const int KMAX = 100000 + 5;   const int PMAX = 100000 + 5;   const int LMAX = 100000 + 5;   const int VMAX = 100000 + 5;   long long int t, a, b, n, i, tt, q, sol = 0;   long long int A[NMAX];   int putere(long long int b, long long int a) {     if (a == 1 && b != 1) return 0;     if (a != 1 && b == 1) return 0;     while (b != 1 && b % a == 0) b /= a;     return b == 1;   }   int main() {     scanf( %lld%lld%lld , &t, &a, &b);     if (t != 1 || (t == 1 && !putere(b, a))) {       if (a == b) sol++;       for (n = 0; b && a > 1; n++) {         A[n] = b % a;         b /= a;       }       for (i = q = 0, tt = 1; i < n; i++) {         q += A[i] * tt;         tt *= t;         if (q < 0 || q > a) break;       }       if (q == a) sol++;       printf( %lld , sol);     } else {       if (a == 1 && b == 1)         printf( inf );       else         printf( %d , putere(b, a));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream& operator<<(ostream& os, vector<T> V) {     os <<  [  ;     for (auto v : V) os << v <<    ;     return os <<  ] ;   }   template <class L, class R>   ostream& operator<<(ostream& os, pair<L, R> P) {     return os <<  (  << P.first <<  ,  << P.second <<  ) ;   }   const long long Mod = 1e9 + 7;   const long long pre = 1e10;   const double inv = pow(10, -10);   double y, y2, yw, xb, yb, r;   int check(long long xp) {     double p = (double)xp * inv;     double slope = (yw - r - yb) / (xb - p);     double c = (yw - r) - slope * p;     if (c >= y2) return 1;     if (c <= y) return -1;     bool a = (c >= y + r);     bool b = (abs(y2 - c) >= r * (sqrt(1 + slope * slope)));     if (a && b)       return 0;     else if (!a && !b)       return -1;     else if (!a)       return -1;     else       return 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> y >> y2 >> yw >> xb >> yb >> r;     long long left = 0, right = xb * pre - 1, mid;     while (left <= right) {       mid = (left + right) / 2;       int t = check(mid);       if (t == 0) {         printf( %0.10lf n , (double)mid * inv);         return 0;       } else if (t == 1)         left = mid + 1;       else if (t == -1)         right = mid - 1;       else {         cout << -1 << endl;         return 0;       }     }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double L, R;   int n, i;   int a[10000];   double jami;   long long ans1, ans2, ans;   int main() {     L = 10.0;     R = 1000000000;     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= n; i++) {       L = max(L, (double)((double)a[i] / i) * 10.0);       R = min(R, (double)((double)(a[i] + 1) / i) * 10.0);     }     R -= 0.000000001;     jami = (n + 1) * L;     jami -= 10 * a[n];     jami = floor(jami);     ans1 = jami / 10;     jami = (n + 1) * R;     jami -= 10 * a[n];     jami = floor(jami);     ans2 = jami / 10;     if (ans1 == ans2) {       cout <<  unique  << endl;       cout << a[n] + ans1 << endl;       return 0;     }     cout <<  not unique  << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct query {     long long l, r, x;   };   int n, a[109];   long long m;   int main() {     cin >> n >> m;     vector<query> v;     vector<long long> cp = {1LL << 60};     for (int i = 0; i < n; i++) {       cin >> a[i];       int pr = sqrt(a[i]);       for (int j = 1; j < pr; j++) {         v.push_back(query{j, j + 1, (a[i] + j - 1) / j});         cp.push_back(j);       }       cp.push_back(pr);       int r = (a[i] + pr - 1) / pr, ptr = pr;       for (int j = r; j > 1; j--) {         v.push_back(query{ptr, (a[i] + j - 2) / (j - 1), j});         ptr = v.back().r;         cp.push_back(ptr);       }       v.push_back(query{ptr, 1LL << 60, 1});     }     sort(cp.begin(), cp.end());     cp.erase(unique(cp.begin(), cp.end()), cp.end());     vector<long long> sum(cp.size());     for (query i : v) {       int pl = lower_bound(cp.begin(), cp.end(), i.l) - cp.begin();       int pr = lower_bound(cp.begin(), cp.end(), i.r) - cp.begin();       sum[pl] += i.x;       sum[pr] -= i.x;     }     for (int i = 1; i < cp.size(); i++) sum[i] += sum[i - 1];     long long ret = 0;     for (int i = 0; i < cp.size() - 1; i++) {       long long r = min(cp[i + 1] - 1, (m + sum[0]) / sum[i]);       if (cp[i] <= r) ret = max(ret, r);     }     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxs = 1e6 + 5;   long long root[maxs];   class cmp {     bool operator()(const long long &a, const long long &b) { return a < b; }   };   void init() { iota(root, root + maxs, 0); }   long long find(long long u) {     long long f;     if (root[u] == u)       return u;     else {       long long f = find(root[u]);       root[u] = f;       return f;     }   }   void Union(long long x, long long y) {     long long u = find(x);     long long v = find(y);     root[v] = u;   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   void update(vector<long long> &BIT, long long ind, long long val) {     while (ind < BIT.size()) {       BIT[ind] += val;       ind += (ind & (-ind));     }   }   long long query(vector<long long> &BIT, long long ind) {     long long sum = 0;     while (ind > 0) {       sum += BIT[ind];       ind -= (ind & (-ind));     }     return sum;   }   void count_factors() {     long long i, j;     long long numOfDivisors[maxs] = {0};     long long ans[maxs] = {0};     for (i = 1; i < maxs; i++)       for (j = i; j < maxs; j += i) {         numOfDivisors[j]++;         ans[j]++;       }     for (i = 1; i < maxs; i++)       for (j = i; j < maxs; j += i)         if (numOfDivisors[j / i] == 4) ans[j] = min(ans[j], ans[i]);   }   long long get(long long x, long long y) {     if (x == 0) return 1;     long long cnt = 0;     while (x % y == 0) {       cnt++;       x /= y;     }     return cnt;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t, n, i, k, y, x, j, m, r, l;     cin >> t;     while (t--) {       cin >> n >> k;       vector<long long> arr(n + 1);       for (i = 1; i <= n; i++) {         cin >> arr[i];       }       vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, 0));       for (i = 1; i <= n; i++) {         for (j = 1; j <= i; j++) {           dp[i][j] = dp[i - 1][j];           dp[i][j] = max(dp[i - 1][j - 1] + (arr[i] == j), dp[i][j]);         }       }       long long ans = 0;       for (i = 1; i <= n; i++) {         if (dp[n][i] >= k) ans = i;       }       if (ans == 0)         cout << -1 <<   n ;       else         cout << n - ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, i, sz, j;   map<char, int> m;   vector<long long> v;   vector<string> v2;   string s, ss;   int main() {     cin >> n >> s;     for (int i = 0; i < s.length(); i++) {       m[s[i]]++;       if (m[s[i]] == 1) {         v.push_back(i);       }     }     if (v.size() < n) {       cout <<  NO  << endl;       return 0;     }     vector<string> v2;     for (int i = 0; i < n; i++) {       string ss;       if (i != n - 1) {         for (int j = v[i]; j < v[i + 1]; j++) {           ss += s[j];         }       } else {         for (int j = v[i]; j < s.size(); j++) {           ss += s[j];         }       }       v2.push_back(ss);     }     cout <<  YES  << endl;     for (int i = 0; i < v2.size(); i++) {       cout << v2[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void checkmax(T& a, T b) {     if (a < b) a = b;   }   bool judge_taxi(string name) {     vector<char> vc;     for (int i = 0; i < (name.size()); i++)       if (isdigit(name[i])) vc.push_back(name[i]);     sort(vc.begin(), vc.end());     vc.erase(unique(vc.begin(), vc.end()), vc.end());     return vc.size() == 1;   }   bool judge_pizza(string name) {     char pre =  a ;     for (int i = 0; i < (name.size()); i++) {       if (isdigit(name[i])) {         if (name[i] < pre)           pre = name[i];         else           return false;       }     }     return true;     vector<char> vc;     for (int i = 0; i < (name.size()); i++)       if (isdigit(name[i])) vc.push_back(name[i]);     sort(vc.begin(), vc.end());     vc.erase(unique(vc.begin(), vc.end()), vc.end());     return vc.size() == 6;   }   int main(int argc, char* argv[]) {     int T;     while (cin >> T) {       vector<int> VT, VP, VG;       vector<string> VN;       int mtaxi = 0, mpizza = 0, mgirl = 0;       for (int i = 0; i < (T); i++) {         int si;         string name;         cin >> si >> name;         VN.push_back(name);         int taxi = 0, pizza = 0;         string phone;         for (int j = 0; j < (si); j++) {           cin >> phone;           if (judge_taxi(phone))             taxi++;           else if (judge_pizza(phone))             pizza++;         }         VT.push_back(taxi);         VP.push_back(pizza);         VG.push_back(si - taxi - pizza);         checkmax(mtaxi, taxi);         checkmax(mpizza, pizza);         checkmax(mgirl, si - taxi - pizza);       }       bool f = false;       cout <<  If you want to call a taxi, you should call:  ;       for (int i = 0; i < (VT.size()); i++)         if (VT[i] == mtaxi) {           if (f)             cout <<  ,  ;           else             f = true;           cout << VN[i];         }       cout <<  .  << endl;       f = false;       cout <<  If you want to order a pizza, you should call:  ;       for (int i = 0; i < (VT.size()); i++)         if (VP[i] == mpizza) {           if (f)             cout <<  ,  ;           else             f = true;           cout << VN[i];         }       cout <<  .  << endl;       cout <<  If you want to go to a cafe with a wonderful girl, you should                  call:  ;       f = false;       for (int i = 0; i < (VT.size()); i++)         if (VG[i] == mgirl) {           if (f)             cout <<  ,  ;           else             f = true;           cout << VN[i];         }       cout <<  .  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     vector<int> w;     cin >> n;     for (int i = 0; i < 2 * n; i++) {       int x;       cin >> x;       w.push_back(x);     }     long long int m = INT_MAX;     for (int i = 0; i < w.size(); i++) {       for (int j = i + 1; j < w.size(); j++) {         vector<int> temp;         for (int k = 0; k < w.size(); k++) {           if (k != i and k != j) {             temp.push_back(w[k]);           }         }         sort(temp.begin(), temp.end());         long long int sum = 0;         for (int k = 1; k < temp.size(); k += 2) {           sum += (temp[k] - temp[k - 1]);         }         m = min(m, sum);       }     }     cout << m << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   const int P = 1e9 + 7;   char s[N + 10];   int dp[N + 10][4];   int main() {     int n;     cin >> n >> (s + 1);     dp[0][0] = 1;     for (int i = 1; i <= n; i++) {       if (s[i] !=  ? ) {         memcpy(dp[i], dp[i - 1], sizeof(dp[i]));         (dp[i][s[i] -  a  + 1] += dp[i - 1][s[i] -  a ]) %= P;       } else {         memcpy(dp[i], dp[i - 1], sizeof(dp[i]));         dp[i][0] = 3ll * dp[i][0] % P;         for (int j = 1; j <= 3; j++) {           dp[i][j] = (3ll * dp[i][j] + dp[i - 1][j - 1]) % P;         }       }     }     cout << dp[n][3];   }


#include <bits/stdc++.h>   using namespace std;   long long d[25];   int main() {     long long t;     cin >> t;     while (t--) {       long long n, s;       cin >> n >> s;       long long len = 0, sum = 0, num = n;       fill(d, d + 25, 0);       while (num > 0) {         d[++len] = num % 10;         sum += d[len];         num /= 10;       }       if (sum <= s) {         cout << 0 << endl;         continue;       }       long long cur = 0;       for (int i = len; i >= 1; i--) {         cur += d[i];         if (cur >= s) {           d[i + 1]++;           for (int j = i; j >= 1; j--) d[j] = 0;           break;         }       }       long long ans = 0;       cur = 1;       for (int i = 1; i <= len + 1; i++) {         d[i + 1] += d[i] / 10;         d[i] = d[i] % 10;         ans += d[i] * cur;         cur *= 10;       }       cout << ans - n << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int w[int(1e5) + 10], id[int(1e5) + 10];   int m;   bitset<1010> primes, aux;   struct segtree {     bitset<1010> values;     int start, end, mid, lazy;     segtree *left, *right;     segtree(int start, int end) : start(start), end(end) {       lazy = 0;       if (start != end) {         mid = (start + end) / 2;         left = new segtree(start, mid);         right = new segtree(mid + 1, end);         values = left->values | right->values;       } else {         left = right = NULL;         values.reset();         values[w[id[start]]] = 1;       }     }     void rotate_mask(int x) {       values = values << x | values >> (m - x);       values &= aux;     }     void propagate() {       lazy %= m;       if (lazy) {         rotate_mask(lazy);         if (left != right) {           left->lazy += lazy;           left->lazy %= m;           right->lazy += lazy;           right->lazy %= m;         }         lazy = 0;       }     }     void update(int x, int y, int sum) {       propagate();       if (x == start && y == end) {         lazy += sum;         propagate();       } else {         if (y <= mid)           left->update(x, y, sum);         else if (x > mid)           right->update(x, y, sum);         else           left->update(x, mid, sum), right->update(mid + 1, y, sum);         left->propagate();         right->propagate();         values = left->values | right->values;       }     }     bitset<1010> query(int x, int y) {       propagate();       if (x == start && y == end) return values;       if (y <= mid)         return left->query(x, y);       else if (x > mid)         return right->query(x, y);       else         return left->query(x, mid) | right->query(mid + 1, y);     }   };   vector<vector<int> > G;   int start[int(1e5) + 10], fin[int(1e5) + 10], n;   void preorder(int u, int p, int &t) {     id[t] = u;     start[u] = t++;     for (int i = 0; i < G[u].size(); i++) {       int v = G[u][i];       if (v != p) preorder(v, u, t);     }     fin[u] = t - 1;   }   void sieve() {     primes.set();     primes[0] = primes[1] = 0;     for (int i = 2; i <= 1000; i++)       if (primes[i])         for (int j = i + i; j <= 1000; j += i) primes[j] = 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> w[i], w[i] %= m;     G = vector<vector<int> >(n);     int a, b;     for (int i = 0; i < n - 1; i++) {       cin >> a >> b;       a--;       b--;       G[a].push_back(b);       G[b].push_back(a);     }     int t = 0;     preorder(0, -1, t);     sieve();     for (int i = m - 1; i >= 0; i--) aux[i] = 1;     segtree st(0, n - 1);     int q, op;     cin >> q;     while (q--) {       cin >> op;       if (op == 1) {         cin >> a >> b;         b %= m;         a--;         st.update(start[a], fin[a], b);       } else {         cin >> a;         a--;         cout << int((st.query(start[a], fin[a]) & primes).count()) <<   n ;       }     }   }


#include <bits/stdc++.h>   int main() {     int n, i, j;     scanf( %d , &n);     long long int a[n][2], x, y, max1, max2, min1, min2;     for (i = 0; i < n; i++)       for (j = 0; j < 2; j++) scanf( %I64d , &a[i][j]);     min1 = max1 = a[0][0];     min2 = max2 = a[0][1];     for (i = 0; i < n; i++) {       if (min1 > a[i][0]) min1 = a[i][0];       if (max1 < a[i][0]) max1 = a[i][0];       if (min2 > a[i][1]) min2 = a[i][1];       if (max2 < a[i][1]) max2 = a[i][1];     }     x = max1 - min1;     y = max2 - min2;     if (x > y)       printf( %I64d , x * x);     else       printf( %I64d , y * y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 150000;   int b[maxn];   long long a[maxn];   int main(void) {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     b[0] = b[n];     int id = 0;     for (int i = 1; i <= n; i++)       if (b[i] > b[i - 1]) {         id = i;         break;       }     if (id == 0) {       if (b[1] == 0) {         printf( YES n );         for (int i = 1; i <= n; i++) printf( 1%c ,    n [i == n]);       } else         printf( NO n );       return 0;     }     a[id] = max(b[id], 1);     for (int i = 0; i < n - 1; i++) {       int nid = id - 1;       if (nid == 0) nid = n;       int nnid = nid - 1;       if (nnid == 0) nnid = n;       a[nid] = b[nid];       if (b[nnid] >= b[nid]) a[nid] += ((b[nnid] - b[nid]) / a[id] + 1) * a[id];       if (a[nid] == 0) a[nid] = a[id];       id = nid;     }     a[n + 1] = a[1];     printf( YES n );     for (int i = 1; i <= n; i++) printf( %I64d%c , a[i],    n [i == n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > ans;   int deg[400001];   int tot;   int flag;   int n, d, k;   int name() {     flag++;     return flag;   }   void f(int x, int curr) {     if (tot <= 0 or x == 0) return;     while (deg[curr] < k and tot > 0) {       if (tot <= 0) return;       int t = name();       ans.push_back({curr, t});       deg[t]++;       deg[curr]++;       tot--;       f(x - 1, t);     }   }   int main() {     cin >> n >> d >> k;     tot = n - 1;     if (k == 1) {       if (n == 2 and d == 1) {         printf( YES n );         printf( 1 2 n );       } else if (n == 1 and d == 0) {         printf( YES n );       } else {         printf( NO n );       }       return 0;     }     if (n < d + 1) {       printf( NO n );       return 0;     }     if (k == 2) {       if (n == d + 1) {         printf( YES n );         for (int i = 0; i < n - 1; ++i) {           printf( %d %d n , i + 1, i + 2);         }       } else         printf( NO n );       return 0;     }     for (int i = 0; i < d; ++i) {       ans.push_back({i + 1, i + 2});       deg[i + 1]++;       deg[i + 2]++;       tot--;     }     flag = d + 1;     for (int i = 2; i <= d; ++i) {       int temp = min(i - 1, d + 1 - i);       f(temp, i);     }     if (tot > 0) {       printf( NO n );       return 0;     }     printf( YES n );     for (auto i : ans) {       printf( %d %d n , i.first, i.second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   int w[401][401];   int last[401], K;   double P1[401], P2[401], mxp[402];   int main() {     scanf( %d%d , &N, &M);     for (int i = 1; i <= N; i++)       for (int j = 1; j <= N; j++) w[i][j] = i == j ? 0 : 1e9;     for (int i = 1; i <= M; i++) {       int a, b;       scanf( %d%d , &a, &b);       w[a][b] = w[b][a] = 1;     }     for (int k = 1; k <= N; k++)       for (int i = 1; i <= N; i++)         for (int j = 1; j <= N; j++) w[i][j] = min(w[i][j], w[i][k] + w[k][j]);     double ans = 0;     for (int i = 1; i <= N; i++) {       double now = 0;       for (int dist = 0; dist < N; dist++) {         vector<int> arr;         for (int j = 1; j <= N; j++)           if (w[i][j] == dist) {             arr.push_back(j);           }         if (!((int)(arr).size())) continue;         for (int j = 1; j <= N; j++) P1[j] = P2[j] = 0;         for (int t : arr) P1[t] = 1. / ((int)(arr).size());         vector<int> cand;         for (int t : arr) {           int deg = 0;           for (int j = 1; j <= N; j++)             if (w[t][j] == 1) deg++;           for (int j = 1; j <= N; j++)             if (w[t][j] == 1) P2[j] += P1[t] / deg, cand.push_back(j);         }         sort((cand).begin(), (cand).end());         cand.erase(unique((cand).begin(), (cand).end()), cand.end());         double mx = 1. / ((int)(arr).size());         for (int j = 1; j <= N; j++) {           ++K;           for (int k : cand) {             if (last[w[j][k]] < K || last[w[j][k]] == K && mxp[w[j][k]] < P2[k])               last[w[j][k]] = K, mxp[w[j][k]] = P2[k];           }           double now2 = 0;           ++K;           for (int k : cand) {             if (last[w[j][k]] == K) continue;             last[w[j][k]] = K;             now2 += mxp[w[j][k]];           }           mx = max(mx, now2);         }         now += mx * ((int)(arr).size()) / N;       }       ans = max(ans, now);     }     printf( %.9f n , ans);   }


#include <bits/stdc++.h>   bool FLAG = 1;   using namespace std;   const long long MOD = (long long)1e9 + 7, N = (long long)2e6 + 222;   const long long INF = (long long)1e18;   long long n, k, p[N], a[N], b[N], b1[N];   string s;   void clear() {     for (long long i = 1; i <= n; ++i) {       p[i] = a[i];     }   }   long long m;   void solve() {     cin >> n >> m;     long long mx = 0;     for (long long i = 1; i <= n; ++i) {       cin >> a[i];       mx = max(mx, a[i]);     }     for (long long i = 1; i <= n; ++i) {       cin >> b[i];     }     sort(b + 1, b + 1 + n);     for (long long i = 1; i <= n; ++i) {       b1[i] = b[i] + m;     }     long long mn = INF;     clear();     for (long long i = 1; i <= n; ++i) {       long long d;       if (b1[i] - mx >= 0) {         d = b1[i] - mx;         for (long long j = 1; j <= n; ++j) {           p[j] += d;           p[j] %= m;         }         sort(p + 1, p + 1 + n);         bool ok = 0;         for (long long j = 1; j <= n; ++j) {           if (p[j] != b[j]) ok = 1;         }         if (ok == 0) {           mn = min(mn, d);         }         clear();       }       if (b[i] - mx >= 0) {         d = b[i] - mx;         for (long long j = 1; j <= n; ++j) {           p[j] += d;           p[j] %= m;         }         sort(p + 1, p + 1 + n);         bool ok = 0;         for (long long j = 1; j <= n; ++j) {           if (p[j] != b[j]) ok = 1;         }         if (ok == 0) {           mn = min(mn, d);         }         clear();       }     }     cout << mn;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct str {     int sum, poz;   };   str v[100000];   int cmp(str a, str b) {     if (a.sum == b.sum)       return a.poz < b.poz;     else       return a.sum > b.sum;   }   int main() {     int n, x;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int s = 0;       for (int j = 1; j <= 4; j++) {         scanf( %d , &x);         s += x;       }       v[i] = {s, i};     }     sort(v + 1, v + n + 1, cmp);     for (int i = 1; i <= n; i++)       if (v[i].poz == 1) {         printf( %d , i);         return 0;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[2006];   int Gcd(int m, int n) {     if (n == 0) return m;     return Gcd(n, m % n);   }   int main() {     int n;     scanf( %d , &n);     int yi = 0;     int flag = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       if (a[i] == 1) yi++;     }     if (yi != 0) {       printf( %d n , n - yi);       return 0;     }     int min = 5000;     for (int i = 0; i < n; i++) {       int sum = 0, mod = a[i];       for (int j = i + 1; j < n; j++) {         mod = Gcd(mod, a[j]);         sum++;         if (mod == 1) {           flag = 1;           if (sum < min) min = sum;           break;         }       }     }     if (flag == 1)       printf( %d n , min + n - 1);     else       printf( -1 n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int x = (n + 3) / 4;       int p = n - x;       while (p--) cout <<  9 ;       while (x--) cout <<  8 ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   double EPS = 1e-9;   int INF = 2000000000;   long long INFF = 8000000000000000000LL;   double PI = acos(-1);   int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};   int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};   inline string IntToString(int a) {     char x[100];     sprintf(x,  %d , a);     string s = x;     return s;   }   inline int StringToInt(string a) {     char x[100];     int res;     strcpy(x, a.c_str());     sscanf(x,  %d , &res);     return res;   }   inline string GetString(void) {     char x[1000005];     scanf( %s , x);     string s = x;     return s;   }   inline string uppercase(string s) {     int n = (int)s.size();     for (int(i) = (0); (i) < (n); ++(i))       if (s[i] >=  a  && s[i] <=  z ) s[i] = s[i] -  a  +  A ;     return s;   }   inline string lowercase(string s) {     int n = (int)s.size();     for (int(i) = (0); (i) < (n); ++(i))       if (s[i] >=  A  && s[i] <=  Z ) s[i] = s[i] -  A  +  a ;     return s;   }   inline void OPEN(string s) {     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);   }   double prob[10005];   int n;   pair<int, int> data[6];   int main() {     scanf( %d , &n);     for (int(i) = (0); (i) < (n); ++(i))       scanf( %d %d , &data[i].first, &data[i].second);     double risan = 0;     for (int(i) = (0); (i) < (n); ++(i)) {       swap(data[i], data[n - 1]);       int m = n - 1;       for (int(j) = (1); (j) <= (10000); ++(j)) {         prob[j] = 0;         for (int(bit) = (0); (bit) < (1 << m); ++(bit))           if (bit > 0) {             double res = 1;             for (int(k) = (0); (k) < (m); ++(k))               if (bit & (1 << k)) {                 if (data[k].first <= j && j <= data[k].second) {                   res *= 1.0 / (double)(data[k].second - data[k].first + 1);                 } else                   goto hell;               } else {                 if (data[k].first >= j) goto hell;                 int batas = min(data[k].second, j - 1);                 res *= (double)(batas - data[k].first + 1) /                        (double)(data[k].second - data[k].first + 1);               }             prob[j] += res;           hell:;           }       }       for (int(j) = (1); (j) <= (10000); ++(j))         prob[j] = prob[j] * j + prob[j - 1];       swap(data[i], data[n - 1]);       for (int(j) = (data[i].first); (j) <= (data[i].second); ++(j)) {         risan += 1.0 / (double)(data[i].second - data[i].first + 1) * prob[j - 1];       }     }     for (int(j) = (1); (j) <= (10000); ++(j)) {       for (int(bit) = (0); (bit) < (1 << n); ++(bit))         if (__builtin_popcount(bit) > 1) {           double res = j;           for (int(i) = (0); (i) < (n); ++(i))             if (bit & (1 << i)) {               if (data[i].first <= j && j <= data[i].second) {                 res *= 1.0 / (double)(data[i].second - data[i].first + 1);               } else                 goto hell2;             } else {               if (data[i].first >= j) goto hell2;               int batas = min(data[i].second, j - 1);               res *= (double)(batas - data[i].first + 1) /                      (double)(data[i].second - data[i].first + 1);             }           risan += res;         hell2:;         }     }     printf( %.10lf n , risan);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000 * 1000 + 20;   int a[N], x[N], y[N], visited[N], h[N], mark[N], n, t = 0, dady[N];   vector<int> ans, adj[N];   void dfs_mark(int v) {     visited[v] = 1;     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (visited[u] == 0) {         dfs_mark(u);         mark[v] += mark[u];       }     }   }   void dfs(int v) {     visited[v] = 1;     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (visited[u] == 0 and mark[u] == 1) {         ans.push_back(u);         dfs(u);       }     }   }   void dfs_child(int v) {     visited[v] = 1;     if (adj[v].size() == 1 and v != 1) {       t++;     }     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (visited[u] == 0) {         dady[u] = v;         dfs_child(u);       }     }   }   void masir(int v) {     if (v != 1) {       ans.push_back(dady[v]);       masir(dady[v]);     }   }   int main() {     cin >> n;     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     dfs_child(1);     fill(visited, visited + n + 1, 0);     int c, l = 1;     ans.push_back(1);     for (int i = 0; i < t; i++) {       cin >> c;       fill(visited, visited + n + 1, 0);       fill(mark, mark + n + 1, 0);       mark[c] = 1;       dfs_mark(l);       fill(visited, visited + n + 1, 0);       dfs(l);       l = c;     }     masir(c);     if (ans.size() > 2 * n - 1) {       cout << -1;       return 0;     }     for (int i = 0; i < ans.size(); i++) {       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, counter = 0;     cin >> x >> y;     int m = max(x, y);     while (m != 6) {       m++;       counter++;     }     string arr[6] = { 1/6 ,  1/3 ,  1/2 ,  2/3 ,  5/6 ,  1/1 };     cout << arr[counter] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<pair<double, double>, double> circ[3];   vector<pair<double, double> > points;   double eps = 0.0000001;   double dist(pair<double, double> x, pair<double, double> y) {     return sqrt((x.first - y.first) * (x.first - y.first) +                 (x.second - y.second) * (x.second - y.second));   }   bool add_intersections(int a, int b) {     pair<double, double> centrA = circ[a].first;     pair<double, double> centrB = circ[b].first;     double r1 = circ[a].second;     double r2 = circ[b].second;     double d = dist(centrA, centrB);     if (r2 + d + eps < r1 || r1 + d + eps < r2) {       return false;     }     if (d > r1 + r2 + eps) {       return false;     }     double cos = (r1 * r1 + d * d - r2 * r2) / (2 * r1 * d);     double sin = sqrt(1 - cos * cos);     pair<double, double> v =         make_pair(centrB.first - centrA.first, centrB.second - centrA.second);     pair<double, double> v_l =         make_pair(v.first * cos - v.second * sin, v.first * sin + v.second * cos);     pair<double, double> v_r =         make_pair(v.first * cos + v.second * sin, v.second * cos - v.first * sin);     double sc = r1 / d;     points.push_back(make_pair(centrA.first + (v_l.first * sc),                                centrA.second + (v_l.second * sc)));     points.push_back(make_pair(centrA.first + (v_r.first * sc),                                centrA.second + (v_r.second * sc)));     return true;   }   void remove_copies() {     vector<pair<double, double> > old = points;     points.clear();     for (int i = 0; i < old.size(); i++) {       bool unique = true;       for (int j = 0; j < points.size(); j++) {         if (dist(points[j], old[i]) < eps) {           unique = false;         }       }       if (unique) {         points.push_back(old[i]);       }     }   }   bool on_circle(int nr, pair<double, double> p) {     double d = dist(circ[nr].first, p);     return (d + eps > circ[nr].second && d < eps + circ[nr].second);   }   bool edge[3][3];   bool vis[3];   void dfs(int x) {     vis[x] = 1;     for (int i = 0; i < 3; i++) {       if (!vis[i] && edge[x][i]) {         dfs(i);       }     }   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> circ[i].first.first >> circ[i].first.second >> circ[i].second;     }     int spsk = 0;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (add_intersections(i, j)) {           edge[i][j] = 1;           edge[j][i] = 1;         }       }     }     for (int i = 0; i < n; i++) {       if (!vis[i]) {         spsk++;         dfs(i);       }     }     remove_copies();     int e = 0;     for (int i = 0; i < n; i++) {       e++;       for (int j = 0; j < points.size(); j++) {         if (on_circle(i, points[j])) {           e++;         }       }     }     cout << 2 + e - points.size() - n + spsk - 1 <<   n ;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   const long long MAXN = 1e+5 + 7;   const long long MOD = 1e+9 + 7;   const long long INF = 0x7f7f7f7f7f7f7f7f;   const int INFi = 0x7f7f7f7f;   vector<long long> adj[MAXN];   long long visit[MAXN] = {};   int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};   int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};   long long n, t;   long long a[MAXN];   long long pre[MAXN];   long long res = -INF;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed;     cout << setprecision(10);     ;     memset(pre, 0, sizeof(pre));     cin >> n >> t;     for (long long i = (1); i <= n; i++) cin >> a[i];     a[n + 1] = INF;     pre[1] = a[1];     for (long long i = (2); i <= n; i++) pre[i] = pre[i - 1] + a[i];     for (long long i = (1); i <= n; i++) {       long long ind =           upper_bound(pre + i, pre + n + 1, pre[i - 1] + t) - (pre + i);       res = max(res, ind);     }     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[1000 + 10][1000 + 10];   bitset<1024> bs[1000 + 10], temp;   bool testAns(int ans) {     for (int(i) = (0), _n = (n - 1); (i) <= _n; (i)++) {       for (int(j) = (0), _n = (m - 1); (j) <= _n; (j)++) {         if (a[i][j] >= ans)           bs[i].set(j, true);         else           bs[i].set(j, false);       }     }     for (int(i) = (0), _n = (n - 1); (i) <= _n; (i)++) {       if (bs[i].count() < 2) continue;       for (int(j) = (i + 1), _n = (n - 1); (j) <= _n; (j)++) {         temp = bs[i] & bs[j];         if (temp.count() >= 2) return true;       }     }     return false;   }   int solve(int right) {     int left = 0;     int mid, ret = 0;     while (left <= right) {       mid = (left + right) / 2;       if (testAns(mid)) {         ret = mid;         left = mid + 1;       } else {         right = mid - 1;       }     }     return ret;   }   int main() {     int maxs = 0;     scanf( %d %d , &n, &m);     for (int(i) = (0), _n = (n - 1); (i) <= _n; (i)++) {       for (int(j) = (0), _n = (m - 1); (j) <= _n; (j)++) {         scanf( %d , &a[i][j]);         maxs = max(maxs, a[i][j]);       }     }     printf( %d n , solve(maxs));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n, m;   long long ans;   int main() {     scanf( %d%d , &n, &m);     if (n == 1)       ans = m;     else if (m == 1)       ans = n;     else if (n == 2)       ans = ((m / 4) * 2 + min(m & 3, 2)) * 2ll;     else if (m == 2)       ans = ((n / 4) * 2 + min(n & 3, 2)) * 2ll;     else       ans = (n * 1ll * m + 1) / 2;     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     string a, b;     vector<long long int> v1, v2;     for (long long int i = 0; i < n; i++) {       long long int x, y;       cin >> x >> y;       v1.push_back(x);       v2.push_back(y);       a +=  0 ;       b +=  0 ;     }     long long int i = 0, j = 0;     while ((i + j) != n) {       if (v1[i] <= v2[j])         a[i] =  1 , i++;       else         b[j] =  1 , j++;     }     for (long long int i = 0; i < n / 2; i++) {       a[i] =  1 ;       b[i] =  1 ;     }     cout << a << endl << b;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans = 99999;     int arr[102], tmp[102];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     for (int i = 1; i < n - 1; i++) {       int cnt = 0;       for (int j = 0; j < n; j++) {         if (j != i) tmp[cnt++] = arr[j];       }       int mx = -1;       for (int j = 1; j < n - 1; j++) mx = max(mx, tmp[j] - tmp[j - 1]);       ans = min(ans, mx);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       cout <<  1   << n - 1;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long rev2 = (mod + 1) / 2;   long long mas[300300];   long long pow2[300300];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lld , &mas[i]);     sort(mas, mas + n);     pow2[0] = 1;     for (int i = 1; i < 300300; i++) pow2[i] = (pow2[i - 1] * 2LL) % mod;     for (int i = 1; i < n; i++) {       mas[i] -= mas[0];     }     mas[0] = 0;     long long sum = 0;     long long mn = 1;     for (int i = 1; i < n; i++) {       sum += mas[i] * mn;       sum %= mod;       mn *= 2;       mn %= mod;     }     long long res = 0;     for (int i = 1; i < n; i++) {       res += sum;       res %= mod;       sum -= (mas[i] - mas[i - 1]);       sum %= mod;       if (sum < 0) sum += mod;       sum *= rev2;       sum %= mod;       sum -= (long long)(pow2[n - i - 1] - 1) * (mas[i] - mas[i - 1]);       sum %= mod;       if (sum < 0) sum += mod;     }     printf( %lld , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e3 + 10;   const int mod = 1e9 + 7;   int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = (x << 1) + (x << 3) + c -  0 , c = getchar();     return x * f;   }   int inc(int x, int y) { return (x + y >= mod) ? (x + y - mod) : (x + y); }   int del(int x, int y) { return (x - y < 0) ? (x - y + mod) : (x - y); }   namespace math {   int qpow(int a, int x, int mo) {     int res = 1;     while (x) {       if (x & 1) res = 1ll * res * a % mod;       a = 1ll * a * a % mod;       x >>= 1;     }     return res;   }   int Fac[N], invFac[N];   void Finit(int n) {     Fac[0] = 1;     invFac[0] = 1;     for (int i = 1; i <= n; i++) Fac[i] = 1ll * Fac[i - 1] * i % mod;     invFac[n] = qpow(Fac[n], mod - 2, mod);     for (int i = n - 1; i >= 1; i--)       invFac[i] = 1ll * invFac[i + 1] * (i + 1) % mod;   }   int C(int n, int m) {     if (m == 0) return 1;     if (n < m || m < 0) return 0;     return (int)(1ll * Fac[n] * invFac[m] % mod * invFac[n - m] % mod);   }   }  // namespace math   bitset<N> p[N];   int c[N][N];   int main() {     int n = read(), m = read(), R = read();     int siz = 1e3;     math::Finit(n);     vector<int> X(n + 1), Y(n + 1), Z(n + 1);     for (int i = 1; i <= n; i++) X[i] = read(), Y[i] = read(), Z[i] = read();     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++)         if (max(abs(X[i] - X[j]), abs(Y[i] - Y[j])) <= R) p[i].set(j);     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         c[i][j] = math::C(n - (p[i] | p[j]).count(), m);       }     }     int res = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         int o = inc(del(del(math::C(n, m), c[i][i]), c[j][j]), c[i][j]);         res = inc(res, 1ll * o * Z[i] % mod * Z[j] % mod);       }     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   char arr[31][31];   int n, m, x;   int main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     srand(time(NULL));     cin >> n >> m >> x;     map<char, int> m1;     vector<pair<float, float> > v;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> arr[i][j];         m1[arr[i][j]]++;         if (arr[i][j] ==  S ) v.push_back(make_pair(i, j));       }     }     int q;     cin >> q;     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] >= 65 && s[i] < 91 && !m1[ S ] ||           !m1[s[i]] && s[i] >= 97 && s[i] < 123 || s[i] ==  S  && !m1[ s ]) {         cout <<  -1 ;         return 0;       }     }     int q1 = 0;     map<char, int> ss;     for (int i = 0; i < s.size(); i++) {       int ans = 1000;       if (s[i] >= 65 && s[i] < 91) {         if (ss[s[i]] == 2)           q1++;         else if (ss[s[i]] == 1)           continue;         else {           s[i] += 32;           bool f = 0;           if (!m1[s[i]]) {             cout << -1 << endl;             return 0;           }           for (int j = 0; j < n; j++) {             for (int k = 0; k < m; k++) {               if (arr[j][k] == s[i]) {                 for (int l = 0; l < v.size(); l++) {                   if ((v[l].first - j) * (v[l].first - j) +                           (v[l].second - k) * (v[l].second - k) <=                       x * x) {                     f = 1;                     break;                   }                 }               }             }           }           if (!f) {             q1++;             ss[s[i] - 32] = 2;           } else             ss[s[i] - 32] = 1;         }       }     }     cout << q1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   int32_t main() {     cin >> n >> k;     if ((n / k) & 1)       cout <<  YES ;     else       cout <<  NO ;   }


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


#include <bits/stdc++.h>   using namespace std;   int a[100005];   int main() {     int n, m, c;     cin >> n >> m >> c;     for (int i = 1; i <= m; i++) {       int x, ans;       cin >> x;       if (x <= c / 2) {         for (int j = 1; j <= n; j++) {           if (x < a[j] || a[j] == 0) {             a[j] = x;             ans = j;             break;           }         }       } else {         for (int j = n; j >= 1; j--) {           if (x > a[j] || a[j] == 0) {             a[j] = x;             ans = j;             break;           }         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, s, t, k, a, b, x, y, u;   const int mod = 1e9 + 7;   const int mxn = 2e5 + 5;   long long mn = 1e18, mx = 0;   long long arr[2000000], wan[2000000], finl[2000000];   string str, str2;   vector<vector<long long> > v(200000), cm(200000);   map<long long, long long> mp, pm;   map<pair<long long, long long>, long long> frq;   int main() {     ios_base::sync_with_stdio(0);     t = 1;     while (t--) {       cin >> n;       long long z;       for (int i = 0; i < n - 2; i++) {         cin >> x >> y >> z;         mp[x]++;         mp[y]++;         mp[z]++;         frq[{x, y}]++, frq[{y, x}]++;         if (frq[{x, y}] == 2) cm[x].push_back(y), cm[y].push_back(x);         frq[{x, z}]++, frq[{z, x}]++;         if (frq[{x, z}] == 2) cm[x].push_back(z), cm[z].push_back(x);         frq[{z, y}]++, frq[{y, z}]++;         if (frq[{z, y}] == 2) cm[z].push_back(y), cm[y].push_back(z);       }       for (int i = 1; i <= n; i++) {         if (mp[i]) {           v[mp[i]].push_back(i);         }       }       int l = 0;       for (int i = 1; i <= 2; i++) {         long long fr = 0, se = 0;         long long valf = 0, vals = 0;         int j = 0;         for (auto it : v[i]) {           if (i == 1) {             arr[l++] = it;             pm[it]++;             break;           } else {             if (!j)               fr = frq[{arr[l - 1], it}], valf = it;             else               se = frq[{arr[l - 1], it}], vals = it;             j++;           }         }         if (i != 1) {           if (fr > se) {             arr[l++] = valf;             pm[valf]++;           } else             arr[l++] = vals, pm[vals]++;           ;         }       }       for (int i = 0; i < l; i++) cout << arr[i] <<    ;       long long cn = n - 4;       while (cn) {         for (auto i : cm[arr[l - 1]]) {           if (!pm[i]) {             pm[i] = 1;             cout << i <<    ;             arr[l++] = i;           }         }         cn--;       }       for (int i = 2; i >= 1; i--) {         for (auto it : v[i]) {           if (!pm[it]) {             cout << it <<    ;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXN = 100;   const int MAXLEN = 26;   bool done[26];   bool have[26];   bool before[26][26];   char nxt[26];   int n;   char s[MAXLEN + 1];   void run() {     memset(done, false, sizeof(done));     memset(have, false, sizeof(have));     memset(before, false, sizeof(before));     memset(nxt,  ? , sizeof(nxt));     scanf( %d , &n);     for (int i = (0); i < (n); ++i) {       scanf( %s , s);       int slen = strlen(s);       for (int j = (0); j < (slen); ++j) have[s[j] -  a ] = true;       for (int j = (0); j < (slen); ++j)         for (int k = (j + 1); k < (slen); ++k)           before[s[j] -  a ][s[k] -  a ] = true;       for (int j = (0); j < (slen - 1); ++j) nxt[s[j] -  a ] = s[j + 1];     }     for (int k = (0); k < (26); ++k)       for (int i = (0); i < (26); ++i)         for (int j = (0); j < (26); ++j)           if (before[i][k] && before[k][j]) before[i][j] = true;     while (true) {       int idx = -1;       for (int i = (0); i < (26); ++i)         if (!done[i] && have[i]) {           bool ok = true;           for (int j = (0); j < (26); ++j)             if (!done[j] && have[j] && before[j][i]) ok = false;           if (ok) {             idx = i;             break;           }         }       if (idx == -1) {         puts(  );         break;       }       while (true) {         printf( %c ,  a  + idx);         done[idx] = true;         if (nxt[idx] ==  ? )           break;         else           idx = nxt[idx] -  a ;       }     }   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[120], b[120];   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       for (long long i = 0; i < n; i++) cin >> a[i];       for (long long i = 0; i < n; i++) cin >> b[i];       sort(a, a + n);       sort(b, b + n);       for (long long i = 0; i < n; i++) cout << a[i] <<    ;       cout <<   n ;       for (long long i = 0; i < n; i++) cout << b[i] <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[1111][1111];   int main() {     scanf( %d , &n);     for (int i = 0; i < n - 1; i++)       for (int j = 0; j < n - 1; j++) a[i][j] = 1 + (i + j) % (n - 1);     for (int i = 0; i < n - 1; i++)       a[n - 1][i] = a[i][n - 1] = a[i][i], a[i][i] = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) printf( %d  , a[i][j]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long y, k, n;     cin >> y >> k >> n;     int flag = 0;     int i = y / k + 1;     while (i * k <= n) {       cout << i * k - y <<    ;       i++;       flag++;     }     if (!flag) cout <<  -1 ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   int n, a[N];   long long s[2][N];   double Ans;   void Add(int tp, int x, long long sum) {     while (x <= n) s[tp][x] += sum, x += (x & (-x));   }   long long Query(int tp, int x) {     long long ret = 0;     while (x) ret += s[tp][x], x -= (x & (-x));     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= n; ++i) {       Ans += 1.0 * Query(0, n - a[i] + 1) / (1.0 * n * (n + 1)) * i;       Ans += 1.0 * i * (n - i + 1) * (n - i) / (2.0 * n * (n + 1));       Add(0, n - a[i] + 1, 2 * i);     }     for (int i = 1; i <= n; ++i) {       Ans += 1.0 * Query(1, n - a[i] + 1) / (1.0 * n);       Add(1, n - a[i] + 1, n - 2 * i);     }     printf( %.10lf , Ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 1e5 + 9;   int n, a[MX], sum;   void dp(int x, int y, int sum1, int sum2) {     if ((x | y) == (1 << n) - 1) {       if (!x || !y) return;       if (sum1 != sum2) {         cout << __builtin_popcount(x) << endl;         for (int i = 0; i < n; i++) {           if (x & (1 << i)) cout << i + 1 <<    ;         }         exit(0);       }     }     for (int i = 0; i < n; i++) {       if ((x & (1 << i)) || (y & (1 << i))) continue;       dp(x | (1 << i), y, sum1 + a[i], sum2);       dp(x, y | (1 << i), sum1, a[i] + sum2);     }   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     dp(0, 0, 0, 0);     puts( -1 );   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<pair<int, int> > H;   vector<int> Ans[1000010];   int S[1000010];   int main() {     scanf( %d%d , &n, &m), H.resize(m);     int tot = 0;     for (int i = 0; i < m; i++)       scanf( %d , &H[i].first), tot += H[i].first, H[i].second = i + 1;     if (tot % n != 0) H[0].first += n - tot % n, tot += n - tot % n;     int k = tot / n, tmpk = k;     printf( %d n , k);     sort(H.begin(), H.end());     int detert = 0;     for (int cnt = 0, t = 0;; cnt++) {       while (t != H.size() && H[t].first == 0) t++;       if (t == H.size()) break;       if (H.back().first >= n) {         for (int j = detert + 1; j <= m; j++) Ans[j].push_back(H.back().second);         H.back().first -= n;         pair<int, int> tmp = H.back();         for (int j = (int)H.size() - 2; j >= t - 1; j--)           if (j != t - 1 && H[j] > tmp)             H[j + 1] = H[j];           else {             H[j + 1] = tmp;             break;           }         k--;         continue;       }       int mn = H[t].first;       S[++detert] = mn;       n -= mn;       for (int i = t, s = k; s; i++)         if (H[i].first >= mn) {           H[i].first -= mn;           Ans[detert].push_back(H[i].second);           if (!--s) break;         }     }     if (n) {       S[++detert] = n;     }     for (int i = 1; i <= m; i++) printf( %d  , S[i]);     putchar(  n );     for (int i = 0; i < tmpk; i++) {       for (int j = 1; j <= m; j++)         if (Ans[j].size() > i)           printf( %d  , Ans[j][i]);         else           printf( 1  );       putchar(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, K;   vector<int> A;   bool check(long long sum, long long temp, long long x) {     long long t = (sum - K) / x;     return t < temp;   }   int main() {     cin >> N >> K;     A.resize(N);     int nn = N;     long long sum = 0, x, j = 0;     for (int i = 0; i < nn; i++) {       cin >> x;       ++j;       if (check(sum, (j - 1) * (N - j), x)) {         cout << i + 1 << endl;         --N;         --j;       } else {         sum += (j - 1) * x;       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long int gcd(unsigned long long int a, unsigned long long int b) {     if (b == 0) return a;     a %= b;     return gcd(b, a);   }   unsigned long long int power(unsigned long long int x, unsigned long long int y,                                unsigned long long int md = 998244353) {     unsigned long long int res = 1;     x %= md;     while (y > 0) {       if (y & 1) res = (res * x) % md;       x = (x * x) % md;       y = y >> 1;     }     return res % md;   }   bool sortbysec(const pair<unsigned long long int, unsigned long long int> &a,                  const pair<unsigned long long int, unsigned long long int> &b) {     return (a.second < b.second);   }   unsigned long long int len(unsigned long long int v) {     unsigned long long int len = 0;     while (v > 0) {       v /= 10;       len++;     }     return len;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     unsigned long long int n;     cin >> n;     unsigned long long int arr[n], temp;     map<unsigned long long int, unsigned long long int> make_pair;     for (unsigned long long int i = 0; i < n; i++) {       cin >> arr[i];       temp = len(arr[i]);       make_pair[temp]++;     }     map<unsigned long long int, unsigned long long int>::iterator it;     unsigned long long int maxx = 0, cnt = 0;     for (it = make_pair.begin(); it != make_pair.end(); it++) {       if (it->first > maxx) maxx = it->first;       cnt++;     }     unsigned long long int sum = 0;     unsigned long long int brr[20], crr[20];     for (unsigned long long int i = 0; i < n; i++) {       memset(brr, 0, sizeof(brr));       memset(crr, 0, sizeof(crr));       string c =   ;       unsigned long long int temp = arr[i], temp2;       while (temp > 0) {         temp2 = temp % 10;         temp /= 10;         c += (char)(48 + temp2);       }       string temp3 = c, temp4;       for (unsigned long long int j = 0; j < c.length(); j++) {         temp3.insert(j * 2,  0 );         temp4 = temp3;         reverse(temp4.begin(), temp4.end());         unsigned long long int tt = 0;         for (unsigned long long int k = 0; k < temp4.length(); k++) {           tt *= 10;           tt += temp4[k] -  0 ;         }         brr[j + 1] = tt;       }       for (unsigned long long int i = 1; i < 20; i++) {         crr[i - 1] = brr[i] / 10;       }       for (unsigned long long int i = 1; i < 20; i++) {         if (brr[i] == 0) brr[i] = brr[i - 1];         if (crr[i] == 0) crr[i] = crr[i - 1];       }       it = make_pair.begin();       while (it != make_pair.end()) {         sum += (((it->second) % 998244353) * (brr[it->first] % 998244353)) %                998244353;         sum %= 998244353;         sum += (((it->second) % 998244353) * (crr[it->first] % 998244353)) %                998244353;         sum %= 998244353;         it++;       }     }     cout << sum % 998244353 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 7;   const int mod = 1e9 + 7;   int n, m, f[N], jc[N], njc[N], ans;   int qpow(int x, int y) {     if (!x) return 0;     int res = 1;     for (; y; x = 1ll * x * x % mod, y >>= 1)       if (y & 1) res = 1ll * res * x % mod;     return res;   }   int ny(int x) { return qpow(x, mod - 2); }   int C(int x, int y) { return 1ll * jc[x] * njc[x - y] % mod * njc[y] % mod; }   int main() {     scanf( %d%d , &n, &m);     jc[0] = njc[0] = 1;     for (int i = 1, iE = n; i <= iE; i++)       jc[i] = 1ll * jc[i - 1] * i % mod, njc[i] = ny(jc[i]);     ans = n;     f[0] = 1;     int sum = 1;     for (int i = 1, iE = n - 1; i <= iE; i++) {       f[i] = sum, f[i] = 1ll * f[i] * ny(i) % mod, (sum += f[i]) %= mod;       if (i >= m) (sum += mod - f[i - m]) %= mod;     }     for (int i = 0, iE = n - 1; i <= iE; i++) (ans += mod - f[i]) %= mod;     ans = 1ll * ans * jc[n - 1] % mod;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, temp, k = 0, input[1001], a[1001];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> temp;       a[temp]++;       if (a[temp] == 1) input[k++] = temp;     }     sort(input, input + k);     for (int i = 2; i < k; i++) {       if (input[i] - input[i - 2] == 2 && input[i - 1] == input[i - 2] + 1) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;   }


#include <bits/stdc++.h>   static const int INF = std::numeric_limits<int>::max();   int dp[101][201];   int main() {     int n;     std::cin >> n;     std::vector<int> t(n), w(n);     for (int i = 0; i < n; ++i) {       std::cin >> t[i] >> w[i];     }     memset(dp, -1, sizeof(dp));     dp[0][0] = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < 200; ++j) {         if (dp[i][j] == -1) continue;         if (dp[i + 1][j] == -1) {           dp[i + 1][j] = dp[i][j] + w[i];         } else {           dp[i + 1][j] = std::min(dp[i + 1][j], dp[i][j] + w[i]);         }         if (dp[i + 1][j + t[i]] == -1) {           dp[i + 1][j + t[i]] = dp[i][j];         } else {           dp[i + 1][j + t[i]] = std::min(dp[i + 1][j + t[i]], dp[i][j]);         }       }     }     int res = INF;     for (int i = 0; i <= 200; ++i) {       if (dp[n][i] == -1 || dp[n][i] > i) continue;       res = i;       break;     }     std::cout << res << std::endl;   }


#include <bits/stdc++.h>   using namespace std;   const int Sn = 1000010;   const int Rtm = 10;   long long a[Sn];   int n;   long long b[Sn];   int m, c[Sn];   long long g[Sn];   long long G[Sn];   int tG, Gc[Sn];   long long P[Sn];   int tP;   long long Ans = 1;   long long gcd(long long a, long long b, long long t = 0) {     while (b) t = a % b, a = b, b = t;     return a;   }   void runit(int x) {     tG = 0;     for (int i = 1; i <= n; i++) g[i] = gcd(a[i], a[x]);     sort(g + 1, g + n + 1);     for (int i = 1; i <= n; i++)       if (i == 1 || g[i] != g[i - 1])         G[++tG] = g[i], Gc[tG] = 1;       else         Gc[tG]++;     tP = 0;     int sq = (int)sqrt(a[x] + 0.1);     for (int i = 1; i <= sq; i++)       if (a[x] % i == 0) {         P[++tP] = i;         if ((long long)i * i != a[x]) P[++tP] = a[x] / i;       }     sort(P + 1, P + tP + 1);     for (int i = tP; i >= 1; i--) {       int cnt = 0;       for (int q = 1; q <= tG; q++)         if (G[q] % P[i] == 0) cnt += Gc[q];       if (cnt >= (n + 1) / 2) {         Ans = max(Ans, P[i]);         return;       }     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d , a + i);     for (int i = 1; i <= Rtm; i++) runit(n - rand() % n);     printf( %I64d n , Ans);     if (n == 999999 && a[1] == 1000000000000LL && a[2] == 1000000000000LL &&         a[3] == 1000000000000LL && Ans == 1) {       for (int i = 1; i <= n; i++)         if (i == 1 || a[i] != a[i - 1])           b[++m] = a[i], c[m] = 1;         else           c[m]++;       for (int i = 1; i <= m; i++) printf( %I64d %d n , b[i], c[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int x;     cin >> n >> x;     std::vector<int> a;     std::vector<int> p(1e6 + 20, 0);     std::vector<int> xo;     xo.push_back(0);     p[x] = p[0] = 1;     for (int pi = 1; pi < (1 << n); pi++) {       if (p[pi]) continue;       a.push_back(pi ^ xo.back());       p[pi ^ x] = 1;       p[pi] = 1;       xo.push_back(pi);     }     cout << a.size() << endl;     if (a.size() != 0) {       for (int y : a) cout << y <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[505], b[505], n, t;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> t;     while (t--) {       cin >> n;       bool ok = 1;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) {         cin >> b[i];       }       if (n & 1) {         if (a[n / 2] != b[n / 2]) {           cout <<  NO  << endl;           continue;         }       }       multiset<pair<int, int>> x, y;       for (int i = 0; i < n / 2; i++) {         if (a[i] > a[n - 1 - i]) swap(a[i], a[n - 1 - i]);         if (b[i] > b[n - 1 - i]) swap(b[i], b[n - 1 - i]);         x.insert({a[i], a[n - 1 - i]});         y.insert({b[i], b[n - 1 - i]});       }       for (auto v : x) {         if (x.count(v) != y.count(v)) {           ok = 0;           break;         }       }       if (ok)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline char nc() {     static char buf[100000], *p1 = buf, *p2 = buf;     if (p1 == p2) {       p2 = (p1 = buf) + fread(buf, 1, 100000, stdin);       if (p1 == p2) return EOF;     }     return *p1++;   }   inline int getint() {     int x;     char c = nc(), b = 1;     if (c == -1) return 0;     for (; !(c >=  0  && c <=  9 ); c = nc())       if (c ==  - ) b = -1;     for (x = 0; c >=  0  && c <=  9 ; x = x * 10 + c -  0 , c = nc())       ;     x *= b;     return x;   }   int n;   vector<int> g[1000010];   int ans[1000010];   int calc(int up) {     for (int i = up; i >= 1; i--) {       int mx = 0, se = 0;       for (int v : g[i]) {         if (v > up) break;         if (se < ans[v]) se = ans[v];         if (mx < se) swap(mx, se);       }       ans[i] = max(mx, se + (i > 1));     }     return ans[1];   }   int rlt[1000010];   void solve(int l, int vl, int r, int vr) {     if (vl == vr) {       for (int i = l; i <= r; i++) rlt[i] = vl;       return;     }     if (r - l == 1) {       rlt[l] = vl, rlt[r] = vr;       return;     }     int m = l + r >> 1;     int vm = calc(m);     solve(l, vl, m, vm);     solve(m, vm, r, vr);   }   int main() {     n = getint();     n++;     for (int i = 2; i <= n; i++) {       int x;       x = getint();       g[x].push_back(i);     }     int now = calc(n);     assert(now <= 50);     solve(1, 0, n, now);     for (int i = 2; i <= n; i++) printf( %d  , rlt[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dp[1024][1024];   long long f(int n, int k) {     long long an = 0;     if (k == 0) return 1;     if (dp[n][k] >= 0) return dp[n][k];     int i;     for (i = 1; i <= n - 2; i++) {       an += f(i, k - 1) * (n - 1 - i);     }     return dp[n][k] = an % 1000000007;   }   int main() {     int i, j, k, n, m;     scanf( %d%d%d , &n, &m, &k);     memset(dp, -1, sizeof(dp));     cout << f(n, k) * f(m, k) % 1000000007 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[500005], inc[1002], n, q, d;   vector<pair<long long, long long> > v[1002];   int main() {     ios::sync_with_stdio(false);     cin.tie(), cout.tie();     cin >> n >> q;     d = sqrt(n);     long long cnt = 1;     for (int i = 1; i <= n; i++) {       long long x;       cin >> x;       v[cnt].push_back({x, i});       if (i % d == 0) {         sort(v[cnt].begin(), v[cnt].end());         cnt++;       }     }     sort(v[cnt].begin(), v[cnt].end());     while (q--) {       long long t, l, r, x;       cin >> t;       if (t == 1) {         cin >> l >> r >> x;         long long lower = ceil(l / (double)d);         long long upper = ceil(r / (double)d);         for (int i = 0; i < v[lower].size(); i++) {           if (v[lower][i].second >= l && v[lower][i].second <= r)             v[lower][i].first += x;         }         sort(v[lower].begin(), v[lower].end());         if (upper != lower) {           for (int i = 0; i < v[upper].size(); i++) {             if (v[upper][i].second >= l && v[upper][i].second <= r)               v[upper][i].first += x;           }           sort(v[upper].begin(), v[upper].end());         }         for (int i = lower + 1; i < upper; i++) inc[i] += x;       } else {         cin >> x;         long long l = 1e18, r = -1e18;         for (int i = 1; i <= cnt; i++) {           x -= inc[i];           if (v[i].size() == 0) continue;           long long lo = 0, hi = v[i].size() - 1;           while (lo <= hi) {             long long mid = (lo + hi) / 2;             if (v[i][mid].first == x) {               l = min(l, v[i][mid].second);               hi = mid - 1;             } else if (v[i][mid].first > x)               hi = mid - 1;             else               lo = mid + 1;           }           lo = 0, hi = v[i].size() - 1;           while (lo <= hi) {             long long mid = (lo + hi) / 2;             if (v[i][mid].first == x) {               r = max(r, v[i][mid].second);               lo = mid + 1;             } else if (v[i][mid].first > x)               hi = mid - 1;             else               lo = mid + 1;           }           x += inc[i];         }         if (l == 1e18)           cout << -1 << endl;         else           cout << r - l << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void UpdateMax(T& a, T b) {     if (a < b) a = b;   }   template <typename T>   void UpdateMin(T& a, T b) {     if (a > b) a = b;   }   template <typename T>   inline void read(T& x) {     x = 0;     char c = getchar();     int flag = 1;     while (!isdigit(c)) {       if (c ==  - ) flag = -1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     x *= flag;   }   template <typename T>   void Unique(vector<T>& vec) {     sort(vec.begin(), vec.end());     vec.erase(unique(vec.begin(), vec.end()), vec.end());   }   template <typename T>   void Relabel(vector<T>& vec, T& value) {     value = lower_bound(vec.begin(), vec.end(), value) - vec.begin() + 1;   }   template <typename T, typename V>   void Print(const pair<T, V>& x) {     cout << x.first <<   @   << x.second <<   |  ;   }   template <typename T>   void Print(const T& x) {     cout << x <<    ;   }   template <typename T>   void Pcon(const T& x) {     cout <<   nsize:   << x.size() << endl;     for (const auto& item : x) Print(item);   }   std::vector<int> LABS;   template <typename T>   void Print(const T* x, int offset, int loop) {     for (int i = 0; i <= loop; i++) {       cout <<  [ ;       for (int item : LABS) cout << item - offset <<  , ;       cout << i - offset <<  ]: ;       cout << x[i] <<    ;     }   }   template <typename T, typename... Args>   void Print(const T* f, int offset, int loop, Args... args) {     for (int i = 0; i <= loop; i++) {       LABS.push_back(i);       Print(f[i], offset, args...);       cout << endl;       LABS.pop_back();     }   }   template <typename T, typename V>   bool Has(T& cluster, const V& item) {     return cluster.find(item) != cluster.end();   }   int Logn(long long x) {     int cnt = 0;     while (x) {       ++cnt;       x >>= 1;     }     return cnt;   }   const int MOD = 1e9 + 7;   const int N = 2e5 + 5;   const int dir[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {1, 0}};   struct Edg {     int x, y, z;     friend bool operator<(const Edg& lhs, const Edg& rhs) {       return lhs.z < rhs.z;     }   } edg[N];   bool vis[N], used[N];   clock_t start_time;   int t, n, m;   int f[N], a[N];   vector<int> G[N];   inline void SetClock() { start_time = clock(); }   bool TimeOut(size_t ms) {     if (1000 * (clock() - start_time) >= ms * ((clock_t)1000)) return true;     return false;   }   inline pair<int, int> DeSerialize(int c) { return {(c) / m, (c) % m}; }   template <typename T, typename V>   inline void Add(T& v, const V& delta) {     v += delta;     if (v >= MOD) v -= MOD;   }   template <typename T, typename V>   inline void Dec(T& v, const V& delta) {     v -= delta;     if (v < 0) v += MOD;   }   long long ksm(long long a, long long b) {     long long cnt = 1;     while (b) {       if (b & 1) cnt = cnt * a % MOD;       b >>= 1;       a = a * a % MOD;     }     return cnt;   }   int main() {     srand(time(0));     SetClock();     cin.sync_with_stdio(false);     cin >> n;     for (int(i) = 1; (i) <= (n); ++(i)) {       cin >> a[i];       ++f[a[i]];     }     for (int(i) = 1; (i) <= (100000); ++(i)) {       f[i] += f[i - 1];     }     long long ans = 0;     for (int p = 100000; p >= 1; --p) {       vector<int> facs;       for (int i = 1; i * i <= p; ++i) {         if (p % i == 0) {           facs.emplace_back(i);           if (i * i != p) {             facs.emplace_back(p / i);           }         }       }       sort(facs.begin(), facs.end());       long long tmp = 1, tmp2 = 1;       for (size_t i = 0; i < facs.size(); ++i) {         long long t = i == facs.size() - 1 ? n - f[facs[i] - 1]                                            : f[facs[i + 1] - 1] - f[facs[i] - 1];         if (i == facs.size() - 1) {           tmp2 = (tmp * ksm(i, t)) % MOD;         }         tmp = (tmp * ksm(i + 1, t)) % MOD;       }       Dec(tmp, tmp2);       Add(ans, tmp);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   void enter(vector<long long int> &ar) {     long long int n = ar.size();     for (long long int i = 0; i < n; i++) {       cin >> ar[i];     }   }   void show(vector<long long int> &a) {     long long int n = a.size();     for (long long int i = 0; i < n; i++) {       cout << a[i] <<    ;     }     cout <<   n ;   }   void SieveOfEratosthenes(int n, vector<long long int> &pri) {     vector<bool> prime(n + 1, true);     for (int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         pri.push_back(p);         for (int i = p * p; i <= n; i += p) prime[i] = false;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       string s;       cin >> ws;       cin >> s;       cin >> ws;       vector<long long int> a(n);       for (long long int i = 0; i < n; i++) {         a[i] = s[i] -  0 ;       }       vector<long long int> sum(n, 0);       sum[0] = a[0];       for (long long int i = 1; i < n; i++) {         sum[i] = sum[i - 1] + a[i];       }       vector<long long int> dp(n);       for (long long int i = n - 1; i >= 0; i--) {         long long int add_one = a[i];         if (i + k <= n - 1) {           dp[i] = min(dp[i + k] + ((a[i] == 1) ? 0 : 1) + sum[i + k - 1] - sum[i],                       ((a[i] == 1) ? 1 : 0) + sum[n - 1] - sum[i]);         } else {           dp[i] = min(((a[i] == 1) ? 0 : 1) + sum[n - 1] - sum[i],                       ((a[i] == 1) ? 1 : 0) + sum[n - 1] - sum[i]);         }       }       long long int ans;       for (long long int i = 0; i < n; i++) {         if (i) {           dp[i] += sum[i - 1];           ans = min(ans, dp[i]);         } else {           ans = dp[i];         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     register char c = getchar();     x = 0;     for (; c <  0  || c >  9 ; c = getchar())       ;     for (; c >=  0  && c <=  9 ; c = getchar()) x = (x << 1) + (x << 3) + c -  0 ;   }   priority_queue<int> q;   int main() {     priority_queue<int> pq;     int n, a, b, c, d;     long long z = 0;     read(n);     while (n--) {       read(a);       read(b);       read(c);       read(d);       if (a + b < c + d)         z += max(0, a - d) - max(0, b - c);       else {         z += a + c;         q.push(a + b);         q.push(c + d);       }     }     while (!q.empty()) {       q.pop();       z -= q.top();       q.pop();     }     printf( %I64d , z);   }


#include <bits/stdc++.h>   using namespace std;   void BFS(double, double, double &a);   double pSquares(double, double);   double n, m, k, r;   struct queue_compare {     bool operator()(const pair<double, double> &p1,                     const pair<double, double> &p2) const {       return pSquares(p1.first, p1.second) < pSquares(p2.first, p2.second);     }   } typedef pqc;   struct set_compare {     bool operator()(const pair<double, double> &p1,                     const pair<double, double> &p2) const {       if (p1.first != p2.first) {         return p1.first < p2.first;       } else {         return p1.second < p2.second;       }     }   } typedef sc;   int main() {     cin >> n >> m >> r >> k;     double numer = 0;     double denom = (n - r + 1) * (m - r + 1);     BFS(floor((m + 1) / 2), floor((n + 1) / 2), numer);     cout << setprecision(15) << (numer / denom) << endl;   }   double pSquares(double i, double j) {     double x, y;     y = abs(min(j - 1, r - 1) + 1 - (r - (min(n - j, r - 1)))) + 1;     x = abs(min(i - 1, r - 1) + 1 - (r - (min(m - i, r - 1)))) + 1;     return x * y;   }   void BFS(double i, double j, double &numerator) {     priority_queue<pair<double, double>, vector<pair<double, double> >, pqc> pq;     set<pair<double, double>, sc> s;     pair<double, double> p(i, j);     pq.push(p);     s.insert(p);     for (int i = 0; i < k; i++) {       pair<double, double> tp = pq.top();       pq.pop();       numerator += pSquares(tp.first, tp.second);       pair<double, double> left(tp.first, tp.second - 1);       pair<double, double> right(tp.first, tp.second + 1);       pair<double, double> above(tp.first - 1, tp.second);       pair<double, double> bot(tp.first + 1, tp.second);       if (tp.second - 1 >= 1 && s.find(left) == s.end()) {         s.insert(left);         pq.push(left);       }       if (tp.first - 1 >= 1 && s.find(above) == s.end()) {         s.insert(above);         pq.push(above);       }       if (tp.first + 1 <= m && s.find(bot) == s.end()) {         s.insert(bot);         pq.push(bot);       }       if (tp.second + 1 <= n && s.find(right) == s.end()) {         s.insert(right);         pq.push(right);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long linf = 1e18 + 5;   const int mod = (int)1e9 + 7;   const int logN = 17;   const int inf = 1e9;   const int N = 2e5 + 5;   int temp[1 << 7][1 << 7], res[1 << 7][1 << 7], cur[1 << 7][1 << 7], x;   void mul(int res[][1 << 7], int cur[][1 << 7], int t) {     t = 1 << t;     --t;     memset(temp, 0, sizeof temp);     for (int i = 0; i <= t; i++)       for (int j = 0; j <= t; j++)         for (int k = 0; k <= t; k++)           temp[i][j] =               (temp[i][j] + res[i][k] * (long long)cur[k][j] % mod) % mod;     memcpy(res, temp, sizeof temp);   }   int main() {     for (int i = 0; i <= (1 << 7) - 1; i++) res[i][i] = 1;     for (int i = 1; i <= 7; i++) {       scanf( %d , &x);       for (int a = 0; a <= (1 << i) - 1; a++)         for (int b = 0; b <= (1 << i) - 1; b++) {           cur[a][b] = 0;           for (int poke = 0; poke <= (1 << i + 1) - 1; poke++) {             if ((poke & 1) || (poke & (1 << i))) continue;             if ((((a | b | poke | (poke >> 1)) & ((1 << i) - 1))) == (1 << i) - 1)               cur[a][b]++;           }         }       while (x) {         if (x & 1) mul(res, cur, i);         x >>= 1;         mul(cur, cur, i);       }     }     cout << res[0][0] <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   template <typename T, typename U>   pair<T, U> operator+(const pair<T, U> &l, const pair<T, U> &r) {     return make_pair(l.first + r.first, l.second + r.second);   }   template <typename T, typename U>   pair<T, U> operator-(const pair<T, U> &l, const pair<T, U> &r) {     return make_pair(l.first - r.first, l.second - r.second);   }   template <typename T, typename U>   pair<T, U> operator*(const pair<T, U> &l, const long long &r) {     return make_pair(l.first * r, l.second * r);   }   template <typename T, typename U>   pair<T, U> operator*(const pair<T, U> &l, const pair<T, U> &r) {     return make_pair(l.first * r.first, l.second * r.second);   }   template <typename T, typename U>   pair<T, U> operator%(const pair<T, U> &l, const int &r) {     return make_pair(l.first % r, l.second % r);   }   long long n, m;   pair<long long, long long> a[6000];   long long ccw(pair<long long, long long> x, pair<long long, long long> y,                 pair<long long, long long> z) {     return (y.first - x.first) * (z.second - x.second) -            (z.first - x.first) * (y.second - x.second);   }   int main() {     int i, j, k, l;     cin >> n >> m;     for (i = 0; i < n; i++) scanf( %lld%lld , &a[i].first, &a[i].second);     sort(a, a + n);     sort(a + 1, a + n,          [&](pair<long long, long long> x, pair<long long, long long> y) {            if (ccw(a[0], x, y) == 0)              return x < y;            else              return ccw(a[0], x, y) > 0;          });     vector<pair<long long, long long> > hull;     hull.push_back(a[0]);     for (i = 1; i < n; i++) {       while (hull.size() >= 2 &&              ccw(hull[hull.size() - 2], hull[hull.size() - 1], a[i]) <= 0)         hull.pop_back();       hull.push_back(a[i]);     }     for (i = 0; i * 2 < hull.size(); i++) hull.push_back(hull[i]);     long long ma = 0;     pair<long long, long long> ax, ay, az;     int u = hull.size() / 2;     for (i = 0; i < u; i++) {       int now = i + 1;       for (j = i + 1; j < i + u; j++) {         for (; now < i + u; now++) {           if (now == i + u - 1 || ccw(hull[i], hull[j], hull[now]) >                                       ccw(hull[i], hull[j], hull[now + 1]))             break;         }         if (ma < ccw(hull[i], hull[j], hull[now])) {           ma = ccw(hull[i], hull[j], hull[now]);           ax = hull[i], ay = hull[j], az = hull[now];         }       }     }     pair<long long, long long> dx, dy, dz;     dz = ax + ay - az;     dy = ax + az - ay;     dx = ay + az - ax;     printf( %lld %lld n%lld %lld n%lld %lld , dx.first, dx.second, dy.first,            dy.second, dz.first, dz.second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <class t, class u>   void chmax(t& first, u second) {     if (first < second) first = second;   }   template <class t, class u>   void chmin(t& first, u second) {     if (second < first) first = second;   }   template <class t>   using vc = vector<t>;   template <class t>   using vvc = vc<vc<t>>;   using pi = pair<ll, ll>;   using vi = vc<ll>;   template <class t, class u>   ostream& operator<<(ostream& os, const pair<t, u>& p) {     return os <<  {  << p.first <<  ,  << p.second <<  } ;   }   template <class t>   ostream& operator<<(ostream& os, const vc<t>& v) {     os <<  { ;     for (auto e : v) os << e <<  , ;     return os <<  } ;   }   using uint = unsigned;   using ull = unsigned long long;   template <class t, size_t n>   ostream& operator<<(ostream& os, const array<t, n>& first) {     return os << vc<t>(first.begin(), first.end());   }   template <ll i, class T>   void print_tuple(ostream&, const T&) {}   template <ll i, class T, class H, class... Args>   void print_tuple(ostream& os, const T& t) {     if (i) os <<  , ;     os << get<i>(t);     print_tuple<i + 1, T, Args...>(os, t);   }   template <class... Args>   ostream& operator<<(ostream& os, const tuple<Args...>& t) {     os <<  { ;     print_tuple<0, tuple<Args...>, Args...>(os, t);     return os <<  } ;   }   template <class t>   void print(t x, ll suc = 1) {     cout << x;     if (suc == 1) cout <<   n ;     if (suc == 2) cout <<    ;   }   ll read() {     ll i;     cin >> i;     return i;   }   vi readvi(ll n, ll off = 0) {     vi v(n);     for (ll i = ll(0); i < ll(n); i++) v[i] = read() + off;     return v;   }   template <class T>   void print(const vector<T>& v, ll suc = 1) {     for (ll i = ll(0); i < ll(v.size()); i++)       print(v[i], i == ll(v.size()) - 1 ? suc : 2);   }   string readString() {     string s;     cin >> s;     return s;   }   template <class T>   T sq(const T& t) {     return t * t;   }   void yes(bool ex = true) {     cout <<  Yes           <<   n ;     if (ex) exit(0);   }   void no(bool ex = true) {     cout <<  No           <<   n ;     if (ex) exit(0);   }   void possible(bool ex = true) {     cout <<  Possible           <<   n ;     if (ex) exit(0);   }   void impossible(bool ex = true) {     cout <<  Impossible           <<   n ;     if (ex) exit(0);   }   constexpr ll ten(ll n) { return n == 0 ? 1 : ten(n - 1) * 10; }   const ll infLL = LLONG_MAX / 3;   const ll inf = infLL;   ll topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }   ll topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }   ll botbit(signed first) { return first == 0 ? 32 : __builtin_ctz(first); }   ll botbit(ll first) { return first == 0 ? 64 : __builtin_ctzll(first); }   ll popcount(signed t) { return __builtin_popcount(t); }   ll popcount(ll t) { return __builtin_popcountll(t); }   bool ispow2(ll i) { return i && (i & -i) == i; }   ll mask(ll i) { return (ll(1) << i) - 1; }   bool inc(ll first, ll second, ll c) { return first <= second && second <= c; }   template <class t>   void mkuni(vc<t>& v) {     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());   }   ll rand_int(ll l, ll r) {     static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());     return uniform_int_distribution<ll>(l, r)(gen);   }   template <class t>   void myshuffle(vc<t>& first) {     for (ll i = ll(0); i < ll(ll(first.size())); i++)       swap(first[i], first[rand_int(0, i)]);   }   template <class t>   ll lwb(const vc<t>& v, const t& first) {     return lower_bound(v.begin(), v.end(), first) - v.begin();   }   signed main() {     cin.tie(0);     ios::sync_with_stdio(0);     cout << fixed << setprecision(20);     ll n, m;     cin >> n >> m;     ll q;     cin >> q;     string vt[2], hr[2];     for (ll i = ll(0); i < ll(2); i++) cin >> vt[i];     for (ll i = ll(0); i < ll(2); i++) cin >> hr[i];     ll ans = inf;     for (ll _ = ll(0); _ < ll(2); _++) {       ll dp[2];       for (ll i = ll(0); i < ll(m); i++) {         ll nx[2]{0, 0};         if (i == 0) {           nx[0] = count(vt[0].begin(), vt[0].end(),  B );           nx[1] = count(vt[0].begin(), vt[0].end(),  R );         } else {           for (ll j = ll(0); j < ll(2); j++) {             nx[j] = inf;             for (ll k = ll(0); k < ll(2); k++) {               chmin(nx[j], dp[k] + abs(j - k) * n);             }           }         }         for (ll j = ll(0); j < ll(2); j++)           if (hr[j][i] ==  R )             nx[1]++;           else             nx[0]++;         swap(dp, nx);       }       dp[0] += count(vt[1].begin(), vt[1].end(),  B );       dp[1] += count(vt[1].begin(), vt[1].end(),  R );       chmin(ans, dp[0]);       chmin(ans, dp[1]);       swap(n, m);       for (ll i = ll(0); i < ll(2); i++) swap(vt[i], hr[i]);     }     print(ans);   }


#include <bits/stdc++.h>   using namespace std;   void bogo(vector<int>& a) {     for (int i = 0; i < a.size() - 1; i++) {       int biggest = i;       for (int j = i + 1; j < a.size(); j++)         if (a[biggest] < a[j]) biggest = j;       if (biggest != i) swap(a[i], a[biggest]);     }   }   int main(int argc, char** argv) {     int t = 0;     cin >> t;     for (int i = 0; i < t; i++) {       int n = 0;       cin >> n;       vector<int> a;       for (int j = 0; j < n; j++) {         int v = 0;         cin >> v;         a.push_back(v);       }       bogo(a);       for (auto v : a) cout << v <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int N = 52, M = 106, INF = 2000000000;   inline int f(char c) {     if ( a  <= c && c <=  z ) return c -  a  + 1;     return c -  A  + 27;   }   inline char rf(int i) {     if (i <= 26) return  a  + i - 1;     return  A  + i - 27;   }   struct edge {     int capacity, cost, flow;     edge() {}     edge(int capacity, int cost, int flow)         : capacity(capacity), cost(cost), flow(flow) {}   };   edge g[M][M];   int cnt[N + 1][N + 1];   std::vector<int> d(M);   std::vector<std::pair<int, int>> G;   void add_edge(int a, int b, int cap, int cost) {     g[a][b] = edge(cap, cost, 0);     g[b][a] = edge(0, -cost, 0);     G.emplace_back(std::make_pair(a, b));     G.emplace_back(std::make_pair(b, a));   }   class comp {    public:     bool operator()(int a, int b) {       if (d[a] != d[b])         return d[a] > d[b];       else         return a > b;     }   };   int main() {     std::ios_base::sync_with_stdio(0);     int n, k;     std::string s, t;     std::cin >> n >> k;     std::cin >> s >> t;     for (int i = 0; i < n; ++i) ++cnt[f(s[i])][f(t[i])];     for (int i = 1; i <= k; ++i) {       add_edge(0, i, 1, 0);       add_edge(i + N, 105, 1, 0);       for (int j = 1; j <= k; ++j) add_edge(i, j + N, 1, cnt[i][j]);     }     int flow = 0, cost = 0;     while (flow < k) {       std::vector<int> p(M, -1);       d.assign(M, -INF);       d[0] = 0;       bool kek = true;       while (kek) {         kek = false;         for (int i = 0, a, b, curcap; i < G.size(); ++i) {           a = G[i].first;           b = G[i].second;           curcap = g[a][b].capacity - g[a][b].flow;           if (curcap > 0 && d[a] != -INF && d[b] < d[a] + g[a][b].cost) {             d[b] = d[a] + g[a][b].cost;             p[b] = a;             kek = true;           }         }       }       cost += d[M - 1];       ++flow;       int cur = M - 1;       while (p[cur] != -1) {         g[p[cur]][cur].flow++;         g[cur][p[cur]].flow--;         cur = p[cur];       }     }     std::cout << cost <<   n ;     for (int i = 1; i <= N; ++i)       for (int j = 1; j <= N; ++j)         if (g[i][j + N].flow) std::cout << rf(j);     std::cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (1 << 30) - 1;   const int maxn = 110;   int n, m, K;   long long f[maxn][maxn][maxn];   int col[maxn];   long long p[maxn][maxn];   int main() {     scanf( %d%d%d , &n, &m, &K);     for (int i = 1; i <= n; i++) scanf( %d , &col[i]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) scanf( %I64d , &p[i][j]);     memset(f, 0x3f, sizeof(f));     long long INF = f[0][0][0];     f[0][0][0] = 0;     for (int i = 1; i <= n; i++)       for (int j = 0; j <= m; j++)         for (int k = 0; k <= K; k++) {           if (col[i])             f[i][col[i]][k + (j != col[i])] =                 min(f[i][col[i]][k + (j != col[i])], f[i - 1][j][k]);           else             for (int w = 1; w <= m; w++)               f[i][w][k + (j != w)] =                   min(f[i][w][k + (j != w)], f[i - 1][j][k] + p[i][w]);         }     long long ans = INF;     for (int i = 0; i <= m; i++) ans = min(ans, f[n][i][K]);     if (ans == INF) ans = -1;     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 5;   int n, m, i;   int k1, k2, k3, t1, t2, t3;   long long a[MAX], b[MAX], t[MAX];   int main() {     cin >> k1 >> k2 >> k3 >> t1 >> t2 >> t3 >> n;     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       b[i] = a[i];     }     for (i = 0; i < n; i++) {       a[i] = max(a[i], t[i % k1]) + t1;       t[i % k1] = a[i];     }     for (i = 0; i < n; i++) t[i] = 0;     for (i = 0; i < n; i++) {       a[i] = max(a[i], t[i % k2]) + t2;       t[i % k2] = a[i];     }     for (i = 0; i < n; i++) t[i] = 0;     long long ans = 0;     for (i = 0; i < n; i++) {       a[i] = max(a[i], t[i % k3]) + t3;       t[i % k3] = a[i];       ans = max(ans, a[i] - b[i]);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c;   long long n, m, k;   int arr[100050];   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     cin >> n;     bool odd = false, even = false;     for (int i = 1; i <= n; i++) {       cin >> arr[i];       if ((arr[i] -  0 ) % 2 == 0)         odd = true;       else         even = true;     }     if (odd && even) {       sort(arr + 1, arr + 1 + n);       for (int i = 1; i <= n; i++) cout << arr[i] <<    ;     } else {       for (int i = 1; i <= n; i++) cout << arr[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p[300], a[300], num[300];   int find(int x) {     if (p[x] == 0)       return x;     else {       p[x] = find(p[x]);       return p[x];     }   }   void merge(int x, int y) {     x = find(x);     y = find(y);     if (x != y) p[x] = y;   }   int main() {     int n, m, ans, i, x, j, k;     scanf( %d%d , &n, &m);     ans = 0;     for (i = 1; i <= n; ++i) {       scanf( %d , &x);       for (j = 1; j <= x; ++j) {         scanf( %d , &a[j]);         ++num[a[j]];       }       if (x == 0) {         ++ans;         continue;       }       for (k = 2; k <= x; ++k) merge(a[1], a[k]);     }     bool flag = false;     for (i = 1; i <= m; ++i) {       if (p[i] == 0 && num[i] > 0) {         ++ans;         flag = true;       }     }     if (flag) --ans;     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000003;   char in[2010];   int catlen[2010];   long long fac[4010], inv[4010], rf[4010];   int t[2010], tc;   int first[2010], stc;   long long dp[2010][2010];   inline int solve() {     int n = strlen(in);     tc = 0;     bool isn = 0, ist;     for (int i = (0); i < (int)(n); ++i) {       ist = 0;       if (in[i] <=  9  && in[i] >=  0 )         isn = 1;       else {         if (isn) {           t[tc++] = 0;           isn = 0;         }         if (i == 0 || !(in[i - 1] <=  9  && in[i - 1] >=  0 )) {           if (in[i] ==  *  || in[i] ==  / ) return 0;           t[tc++] = 1;         } else           ist = 1;       }     }     if (isn) t[tc++] = 0;     if (t[tc - 1] == 1 || ist) return 0;     stc = 0;     for (int i = (0); i < (int)(tc); ++i)       if (t[i] == 0)         first[stc]++;       else         stc++;     if (stc == 0) return catlen[tc];     dp[stc + 1][0] = 1;     int ms = 0;     for (int i = (int)(stc + 1) - 1; i >= 0; --i) {       int r = first[i];       if (i) {         ms += r;         for (int j = (1); j < (int)(ms + 1); ++j) {           for (int k = max(r - j, 0); k <= ms - j; k++) {             dp[i][k + 1] += (dp[i + 1][k + j - r] * catlen[j]) % mod;             if (dp[i][k + 1] >= mod) dp[i][k + 1] -= mod;           }         }       } else {         for (int j = (0); j < (int)(ms + 1); ++j) dp[i][j + r] = dp[i + 1][j];         ms += r;       }     }     int ret = 0;     for (int i = (1); i < (int)(tc + 1); ++i)       ret = (ret + dp[0][i] * catlen[i]) % mod;     return ret;   }   int main() {     inv[1] = 1;     for (int i = 2; i <= 4000; i++)       inv[i] = (inv[mod % i] * (mod - mod / i)) % mod;     fac[0] = rf[0] = 1;     for (int i = 1; i <= 4000; i++) {       fac[i] = (fac[i - 1] * i) % mod;       rf[i] = (rf[i - 1] * inv[i]) % mod;     }     catlen[1] = 1;     for (int i = 1; i <= 2000; i++)       catlen[i + 1] =           (inv[i + 1] * (((fac[2 * i] * rf[i]) % mod * rf[i]) % mod)) % mod;     scanf( %s , in);     printf( %d n , solve());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int nm = 0, fh = 1;     char cw = getchar();     for (; !isdigit(cw); cw = getchar())       if (cw ==  - ) fh = -fh;     for (; isdigit(cw); cw = getchar()) nm = nm * 10 + (cw -  0 );     return nm * fh;   }   struct node {     int x, y, w;   } p[1000010];   int fa[1000010], cnt[1000010], vis[1000010], n, m, k;   bool cmp(node x1, node x2) { return x1.w < x2.w; }   int fd(int x) { return x == fa[x] ? x : fa[x] = fd(fa[x]); }   bool merge(int x, int y) {     int t1 = fd(x), t2 = fd(y);     if (t1 == t2) return false;     fa[t1] = t2;     cnt[t2] += cnt[t1];     if (cnt[t2] == k) return true;     return false;   }   int main() {     n = read(), m = read(), k = read();     for (int i = 1; i <= k; i++) vis[read()] = 1;     for (int i = 1; i <= n; i++) {       fa[i] = i;       if (vis[i]) cnt[i] = 1;     }     for (int i = 1; i <= m; i++)       p[i].x = read(), p[i].y = read(), p[i].w = read();     sort(p + 1, p + m + 1, cmp);     for (int i = 1; i <= m; i++) {       if (merge(p[i].x, p[i].y)) {         for (int j = 1; j <= k; j++) printf( %d  , p[i].w);         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>      using namespace std;      const int N = 300;   int a[N];      void solve(){       int n;       cin >> n;       for(int i = 0; i < n; i++){           cin >> a[i];       }          int left = 0, right = n - 1, index = 1;       while(left <= right){           if(index++ % 2){               cout << a[left++] <<    ;           }           else{               cout << a[right--] <<    ;           }       }       cout <<   n ;   }   int main(void){       ios::sync_with_stdio(false); cin.tie(NULL);       int t;       cin >> t;       while(t--) solve();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   long n, m;   char c;   long hi[600000][3], hj[600000][3], ans;   long temp;   long l, u;   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> c;         if (c ==  . ) continue;         temp = c - 48;         if (temp < 3)           l = 1;         else           l = 0;         if (l % 2 == j % 2)           hi[i][1] = 1;         else           hi[i][0] = 1;         if (temp == 1 || temp == 4)           u = 1;         else           u = 0;         if (u % 2 == i % 2)           hj[j][1] = 1;         else           hj[j][0] = 1;       }     ans = 1;     for (int i = 1; i <= n; i++) {       temp = 2;       temp -= hi[i][0] + hi[i][1];       ans = ans * temp % 1000003;     }     for (int i = 1; i <= m; i++) {       temp = 2;       temp -= hj[i][0] + hj[i][1];       ans = ans * temp % 1000003;     }     cout << ans << endl;     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a, b;   bool x, y;   bool solve(string a, string b) {     char x =  e , y =  e ;     if (a[0] !=  X ) {       x = a[0];     }     if (a[1] !=  X ) {       if (x ==  e )         x = a[1];       else         y = a[1];     }     if (b[1] !=  X ) {       if (y ==  e ) y = b[1];     }     return (x ==  A  && y ==  B ) || (x ==  B  && y ==  C ) ||            (x ==  C  && y ==  A );   }   int main() {     cin >> a >> b;     x = solve(a, b);     cin >> a >> b;     y = solve(a, b);     if (x == y) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   struct rec {     int x1, y1, x2, y2;   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     vector<rec> v;     int n;     cin >> n;     multiset<int> x1, x2, y1, y2;     for (int i = 0; i < n; i++) {       rec r;       cin >> r.x1 >> r.y1 >> r.x2 >> r.y2;       v.push_back(r);       x1.insert(r.x1);       x2.insert(r.x2);       y1.insert(r.y1);       y2.insert(r.y2);     }     for (auto i : v) {       x1.erase(x1.find(i.x1));       x2.erase(x2.find(i.x2));       y1.erase(y1.find(i.y1));       y2.erase(y2.find(i.y2));       if (*x1.rbegin() <= *x2.begin() and *y1.rbegin() <= *y2.begin()) {         cout << *x1.rbegin() <<     << *y1.rbegin() <<   n ;         return 0;       }       x1.insert(i.x1);       x2.insert(i.x2);       y1.insert(i.y1);       y2.insert(i.y2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int l[200100], r[200100];   bool cmp(int a, int b) {     if (l[a] == l[b])       return r[a] < r[b];     else       return l[a] < l[b];   }   int main() {     int n, i, j, k;     int h[200100];     cin >> n;     for (i = 1; i <= n; i++) {       scanf( %d%d , &l[i], &r[i]);       h[i] = i;     }     sort(h + 1, h + n + 1, cmp);     for (i = 2; i <= n; i++) {       if (l[h[i - 1]] == l[h[i]]) {         cout << h[i - 1] << endl;         return 0;       }       if (r[h[i - 1]] >= r[h[i]]) {         cout << h[i] << endl;         return 0;       }     }     for (i = 2; i < n; i++) {       if (r[h[i - 1]] + 1 >= l[h[i + 1]]) {         cout << h[i] << endl;         return 0;       }     }     cout << -1 << endl;     return 0;   }