#include <bits/stdc++.h>   using namespace std;   struct node {     int l, r, mx, pre, suf;   };   vector<node> T;   vector<pair<int, int> > ht;   int n, m, a[100055], root[100055], first, second, z;   int init(int l, int r) {     int ind = T.size();     if (l == r) {       T.push_back({-1, -1, 1, 1, 1});       return ind;     }     int mid = (l + r) >> 1;     T.push_back({-1, -1, r - l + 1, r - l + 1, r - l + 1});     T[ind].l = init(l, mid);     T[ind].r = init(mid + 1, r);     return ind;   }   int update(int k, int l, int r, int tar) {     int ind = T.size();     if (l == r) {       T.push_back({-1, -1, 0, 0, 0});       return ind;     }     int mid = (l + r) >> 1, left, right;     T.push_back({-1, -1, 0, 0, 0});     if (tar <= mid) {       left = update(T[k].l, l, mid, tar);       right = T[k].r;     } else if (tar > mid) {       left = T[k].l;       right = update(T[k].r, mid + 1, r, tar);     }     T[ind] = {left, right,               max(max(T[left].mx, T[right].mx), T[left].suf + T[right].pre),               T[left].pre, T[right].suf};     if (T[left].pre == mid - l + 1) T[ind].pre = T[left].pre + T[right].pre;     if (T[right].suf == r - mid) T[ind].suf = T[right].suf + T[left].suf;     return ind;   }   node longest(int k, int l, int r, int tl, int tr) {     if (tl <= l && r <= tr) {       return T[k];     }     int mid = (l + r) >> 1;     if (mid < tl) return longest(T[k].r, mid + 1, r, tl, tr);     if (tr <= mid) return longest(T[k].l, l, mid, tl, tr);     node rans = longest(T[k].r, mid + 1, r, mid + 1, tr);     node lans = longest(T[k].l, l, mid, tl, mid);     node ret = (node){0, 0, 0, 0, 0};     ret.mx = max(max(rans.mx, lans.mx), lans.suf + rans.pre);     ret.pre = lans.pre;     if (lans.pre == mid - tl + 1) ret.pre = lans.pre + rans.pre;     ret.suf = rans.suf;     if (rans.suf == tr - mid) ret.suf = rans.suf + lans.suf;     return ret;   }   void DEBUG(int k, int l, int r) {     if (l == r) return;     int mid = (l + r) >> 1;     DEBUG(T[k].l, l, mid);     DEBUG(T[k].r, mid + 1, r);   }   int main() {     T.reserve(1000000);     scanf( %d , &n);     ht.push_back({0, 0});     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       ht.push_back({a[i], i});     }     sort(ht.begin(), ht.end());     root[1] = init(1, n);     for (int i = 2; i <= n; i++)       root[i] = update(root[i - 1], 1, n, ht[i - 1].second);     for (int i = 1; i <= n; i++) {     }     scanf( %d , &m);     while (m--) {       scanf( %d%d%d , &first, &second, &z);       int l = 1, r = n + 1;       while (l < r - 1) {         int mid = (l + r) >> 1;         node res = longest(root[mid], 1, n, first, second);         if (res.mx >= z)           l = mid;         else           r = mid;       }       printf( %d n , ht[l]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q, x, y, xx, yy;   long long read() {     long long x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = getchar();     }     return x;   }   struct BIT {     long long c[1005][1005];     long long ask(int x, int y) {       long long ans = 0;       for (; x; x -= x & -x)         for (int i = y; i; i -= i & -i) ans ^= c[x][i];       return ans;     }     void modify(int x, int y, long long v) {       for (; x <= (n + 1); x += x & -x)         for (int i = y; i <= (n + 1); i += i & -i) c[x][i] ^= v;     }   } t[2][2];   long long v;   int main() {     n = read();     q = read();     while (q--) {       int op = read();       x = read();       y = read();       xx = read();       yy = read();       if (op == 2) {         v = read();         t[x & 1][y & 1].modify((x + 1) >> 1, (y + 1) >> 1, v);         t[x & 1][(yy + 1) & 1].modify((x + 1) >> 1, (yy + 2) >> 1, v);         t[(xx + 1) & 1][y & 1].modify((xx + 2) >> 1, (y + 1) >> 1, v);         t[(xx + 1) & 1][(yy + 1) & 1].modify((xx + 2) >> 1, (yy + 2) >> 1, v);       } else {         long long v1 = t[(x - 1) & 1][(y - 1) & 1].ask(x >> 1, y >> 1);         long long v2 = t[(x - 1) & 1][yy & 1].ask(x >> 1, (yy + 1) >> 1);         long long v3 = t[xx & 1][(y - 1) & 1].ask((xx + 1) >> 1, y >> 1);         long long v4 = t[xx & 1][yy & 1].ask((xx + 1) >> 1, (yy + 1) >> 1);         printf( %lld n , v1 ^ v2 ^ v3 ^ v4);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int t;     cin >> t;     for (int i = 0; i < t; i++) {       long long a, b;       long long uns = 0;       cin >> a >> b;       uns = abs(a - b) / 5;       if (abs(a - b) % 5 == 1) uns++;       if (abs(a - b) % 5 == 2) uns += 1;       if (abs(a - b) % 5 == 3) uns += 2;       if (abs(a - b) % 5 == 4) uns += 2;       cout << uns << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int v[1000005];   long long int l[1000005];   long long int r[1000005];   int main(void) {     int n, m;     int sum;     scanf(  %d %d , &n, &m);     for (int i = 0; i < n; i++) {       scanf(  %d , &v[i]);     }     l[0] = 0;     sum = 0;     for (int i = 1; i < n; i++) {       sum++;       int trip = (sum + m - 1) / m;       l[i] = l[i - 1] + 1LL * trip * (v[i] - v[i - 1]);     }     r[n - 1] = 0;     sum = 0;     for (int i = n - 2; i >= 0; i--) {       sum++;       int trip = (sum + m - 1) / m;       r[i] = r[i + 1] + 1LL * trip * (v[i + 1] - v[i]);     }     long long int res = l[0] + r[0];     for (int i = 0; i < n; i++) {       res = min(res, l[i] + r[i]);     }     printf( %lld n , 2 * res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long g[222222][2];   int f[222222], p[222222][2], n, i;   long long dfs(int x, int k, int z) {     if (x < 1 || x > n) return 0;     if (g[x][z] == -1 || p[x][z] == k) return -1;     if (p[x][z]) return g[x][z];     long long ans = 0;     p[x][z] = k;     if (z)       ans = dfs(x + f[x], k, z ^ 1);     else       ans = dfs(x - f[x], k, z ^ 1);     if (ans == -1)       return g[x][z] = -1;     else       return g[x][z] = ans + f[x];   }   int main() {     scanf( %d , &n);     for (i = 2; i <= n; i++) scanf( %d , f + i);     for (i = 1; i < n; i++) {       f[1] = i;       p[1][1] = 0;       g[1][1] = 0;       printf( %I64d n , dfs(1, i, 1));     }     return 0;   }


#include <bits/stdc++.h>   int a[100001], p[100001], N, Q;   int T[2100001], ls[2100001], rs[2100001], n, root[100001];   int end[100001], steps[100001];   int build(int l, int r) {     int p = ++n;     T[p] = r - l + 1;     if (l < r) {       int m = l + r >> 1;       ls[p] = build(l, m);       rs[p] = build(m + 1, r);     }     return p;   }   int get_kth(int p, int x) {     int l = 1, r = N;     while (l < r) {       int m = l + r >> 1;       if (x <= T[ls[p]])         p = ls[p], r = m;       else         x -= T[ls[p]], p = rs[p], l = m + 1;     }     return l;   }   int P(int p, int x, int w) {     int l = 1, r = N, root;     T[root = ++n] = T[p] + w;     while (l < r) {       int m = l + r >> 1;       if (x <= m)         ls[n] = n + 1, rs[n] = rs[p], p = ls[p], r = m;       else         rs[n] = n + 1, ls[n] = ls[p], p = rs[p], l = m + 1;       T[++n] = T[p] + w;     }     return root;   }   int G(int p, int x) {     int l = 1, r = N, ans = 0;     while (l < r) {       int m = l + r >> 1;       if (x <= m)         p = ls[p], r = m;       else         ans += T[ls[p]], p = rs[p], l = m + 1;     }     return ans + T[p];   }   int main() {     scanf( %d%d , &N, &Q);     for (int i = 1; i <= N; i++) scanf( %d , a + i);     end[0] = a[1] - 1;     steps[0] = 0;     for (int i = 1; i < N; i++) {       int add = (a[i + 1] - end[i - 1] - 1) / i;       end[i] = end[i - 1] + i * add;       steps[i] = steps[i - 1] + add;     }     for (int i = 2; i <= N; i++) p[i] = (p[i - 1] + a[i] - a[i - 1]) % (i - 1);     root[N] = build(1, N);     for (int i = N; i; i--) {       p[i] = get_kth(root[i], p[i] + 1);       root[i - 1] = P(root[i], p[i], -1);     }     while (Q--) {       int x, k;       scanf( %d%d , &x, &k);       if (x < a[1]) {         printf( %d n , x);         continue;       }       int belong = std::lower_bound(end + 1, end + N, x) - end;       k += steps[belong - 1] + (x - end[belong - 1] - 1) / belong + 1;       int ord = (x - end[belong - 1] - 1) % belong + 1;       ord = get_kth(root[belong], ord);       belong = std::lower_bound(steps + 1, steps + N, k) - steps;       printf( %lld n , end[belong - 1] +                            (long long)(k - steps[belong - 1] - 1) * belong +                            G(root[belong], ord));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, x, y, x1, y1;     cin >> a >> b >> c >> d;     x = (3 * a) / 10;     x1 = (a - (a / 250) * c);     int m = max(x, x1);     y = (3 * b) / 10;     y1 = (b - (b / 250) * d);     int m1 = max(y, y1);     if (m < m1)       cout <<  Vasya  << endl;     else if (m1 < m)       cout <<  Misha  << endl;     else       cout <<  Tie  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 50;   const int MOD = 1e9 + 9;   int n, k, a, b, c, d, m, L, R, tot = 1;   pair<int, int> cities[MAXN];   struct TreeNode {     int x, l, r, lson, rson;     pair<int, int> v;   } tree[MAXN];   int newNode(int &x) { return x = ++tot; }   pair<int, int> calc(pair<int, int> l, pair<int, int> r) {     return {l.second + r.second, max(l.first + r.second, l.second + r.first) + 1};   }   void build(int o, int l, int r) {     int max_y = -1, max_id = l;     for (int i = l; i <= r; i++) {       if (cities[i].second > max_y) {         max_y = cities[i].second;         max_id = i;       }     }     tree[o].l = cities[l].first;     tree[o].r = cities[r].first;     tree[o].x = cities[max_id].first;     if (l < max_id) build(newNode(tree[o].lson), l, max_id - 1);     if (max_id < r) build(newNode(tree[o].rson), max_id + 1, r);     tree[o].v = calc(tree[tree[o].lson].v, tree[tree[o].rson].v);   }   pair<int, int> query(int o, int l, int r) {     if (o == 0 || l > tree[o].r || r < tree[o].l) return {-1, 0};     if (l <= tree[o].l && tree[o].r <= r) return tree[o].v;     if (r < tree[o].x) return query(tree[o].lson, l, r);     if (l > tree[o].x) return query(tree[o].rson, l, r);     return calc(query(tree[o].lson, l, r), query(tree[o].rson, l, r));   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < k; i++) {       scanf( %d%d , &cities[i].first, &cities[i].second);     }     scanf( %d%d%d%d , &a, &b, &c, &d);     for (int i = k; i < n; i++) {       cities[i].first = (1LL * a * cities[i - 1].first + b) % MOD;       cities[i].second = (1LL * c * cities[i - 1].second + d) % MOD;     }     sort(cities, cities + n);     tree[0].v = {-1, 0};     build(1, 0, n - 1);     scanf( %d , &m);     while (m--) {       scanf( %d%d , &L, &R);       printf( %d n , query(1, L, R).second);     }   }


#include <bits/stdc++.h>   int main() {     int i, n;     scanf( %d , &n);     for (i = 0; i < n; i++) {       long long int x;       long long int k, y;       scanf( %I64d %I64d , &k, &x);       y = x + 9 * (k - 1);       printf( %I64d , y);       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     for (int i = 0; i < q; ++i) {       int n;       cin >> n;       set<int> st;       for (int j = 0; j < n; ++j) {         int x;         cin >> x;         st.insert(x);       }       int ans = 0;       int mx = *st.rbegin();       if (mx % 2 == 0 && mx % 3 == 0 && mx % 5 == 0) {         if (st.count(mx / 2) && st.count(mx / 3) && st.count(mx / 5)) {           ans = max(ans, mx / 2 + mx / 3 + mx / 5);         }       }       vector<int> res;       while (!st.empty() && int(res.size()) < 3) {         int x = *st.rbegin();         st.erase(prev(st.end()));         bool ok = true;         for (auto it : res) ok &= (it % x != 0);         if (ok) res.push_back(x);       }       ans = max(ans, accumulate(res.begin(), res.end(), 0));       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a, b, w, start = 0, k;   long long int MAX = 1e18;   vector<vector<int> > wait(100005);   vector<vector<pair<int, int> > > adj(100005);   void binarySearch(int v, long long int& d) {     if (v == n - 1 or wait[v].size() == 0) {       return;     }     int low = 0, high = wait[v].size() - 1, mid;     while (low <= high) {       mid = (low + high) >> 1;       if (wait[v][mid] == d) {         ++d;         ++mid;         while (mid <= wait[v].size() - 1 and                wait[v][mid] == wait[v][mid - 1] + 1) {           ++d;           ++mid;         }         return;       } else if (wait[v][mid] > d) {         high = mid - 1;       } else {         low = mid + 1;       }     }     return;   }   int main(void) {     ios ::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i <= m - 1; ++i) {       cin >> a >> b >> w;       --a;       --b;       adj[a].push_back({b, w});       adj[b].push_back({a, w});     }     for (int i = 0; i <= n - 1; ++i) {       cin >> k;       for (int j = 1; j <= k; ++j) {         cin >> w;         wait[i].emplace_back(w);       }     }     set<pair<long long int, int> > s;     vector<long long int> dist(n, MAX);     vector<int> present(n, 1);     dist[start] = 0;     s.insert({dist[start], start});     while (!s.empty()) {       auto c = *(s.begin());       s.erase(c);       int v = c.second;       present[v] = 0;       binarySearch(v, dist[v]);       for (auto e : adj[v]) {         int u = e.first;         w = e.second;         if (present[u] and dist[u] > dist[v] + 1LL * w) {           s.erase({dist[u], u});           dist[u] = dist[v] + 1LL * w;           s.insert({dist[u], u});         }       }     }     if (dist[n - 1] == MAX) {       cout << -1 << endl;     } else {       cout << dist[n - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool *Seive(long long n, bool *p) {     memset(p, 1, sizeof(p));     long long i, j;     for (i = 2; i <= n; i++) {       if (p[i] == 1)         for (j = i * i; j <= n; j += i) {           p[j] = 0;         }     }     p[1] = 0;     return p;   }   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long modexp(long long x, long long y) {     if (y == 0)       return 1;     else if (y % 2 == 0) {       return modexp((x * x) % (long long)(1e9 + 7), y / 2);     } else {       return (x * modexp((x * x) % (long long)(1e9 + 7), (y - 1) / 2)) %              (long long)(1e9 + 7);     }   }   long long fact(long long n) {     long long f = 1;     for (long long i = 2; i <= n; i++) {       f = (i % (long long)(1e9 + 7) * f % (long long)(1e9 + 7)) %           (long long)(1e9 + 7);     }     return f;   }   long long nCr(long long n, long long r) {     return (fact(n) * modexp((fact(n - r) * fact(r)) % (long long)(1e9 + 7),                              (long long)(1e9 + 7) - 2)) %            (long long)(1e9 + 7);   }   void showlist(list<int> g) {     list<int>::iterator it;     for (it = g.begin(); it != g.end(); ++it) cout << *it <<    ;     cout <<   n ;   }   bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {     return (a.first > b.first);   }   struct Point {     int x, y;   };   long long overlappingArea(long long x3, long long x4, long long x5,                             long long x6, long long y3, long long y4,                             long long y5, long long y6) {     long long area1 = abs(x3 - x4) * abs(y3 - y4);     long long area2 = abs(x5 - x6) * abs(y5 - y6);     long long areaI = (min(x4, x6) - max(x3, x5)) * (min(y4, y6) - max(y3, y5));     if (areaI <= 0) areaI = 0;     return (area1 + area2 - areaI);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long a, x1, x2, y1, y2, x3, x4, x5, x6, y3, y4, y5, y6;     cin >> x1 >> y1 >> x2 >> y2;     cin >> x3 >> y3 >> x4 >> y4;     if (x4 > x2) {       x4 = x2;     }     if (x3 < x1) {       x3 = x1;     }     if (y4 > y2) {       y4 = y2;     }     if (y3 < y1) {       y3 = y1;     }     cin >> x5 >> y5 >> x6 >> y6;     if (x6 > x2) {       x6 = x2;     }     if (x5 < x1) {       x5 = x1;     }     if (y6 > y2) {       y6 = y2;     }     if (y5 < y1) {       y5 = y1;     }     a = 0;     if ((x4 - x3 <= 0 || y4 - y3 <= 0) && (x6 - x5 <= 0 || y6 - y5 <= 0))       ;     else if (x4 - x3 <= 0 || y4 - y3 <= 0) {       a = (x6 - x5) * (y6 - y5);     } else if (x6 - x5 <= 0 || y6 - y5 <= 0) {       a = (x4 - x3) * (y4 - y3);     } else {       a = overlappingArea(x3, x4, x5, x6, y3, y4, y5, y6);     }     if (a == (x2 - x1) * (y2 - y1)) {       cout <<  NO  << endl;     } else {       cout <<  YES  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e+7;   const int N = 1e5 + 5;   long long pwr(long long x, long long y);   long long a[N];   vector<long long> v;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < m; i++) {       cin >> a[i];       v.push_back(a[i]);     }     long long ans = 0, l = k;     long long cur = 0, pre = 0;     while (pre < m) {       cur = (upper_bound(v.begin(), v.end(), l) - v.begin());       if (cur == pre) {         long long po = (v[cur] - l) / k;         l += (long long)(po + bool((v[cur] - l) % k)) * k;       } else {         l += (cur - pre);         ans++;       }       pre = cur;     }     cout << ans << endl;     return 0;   }   long long pwr(long long x, long long y) {     long long ans = 1;     x = x % mod;     while (y > 0) {       if (y & 1) ans = (x * (ans % mod)) % mod;       x = (x * x) % mod;       y = y / 2;     }     return ans % mod;   }


#include <bits/stdc++.h>   using namespace std;   long long b[60005], c[60005];   signed main() {     long long a;     scanf( %lld , &a);     long long MIN = LLONG_MAX / 3, MAX = 0;     for (long long d = 0; d < a; d++) {       scanf( %lld , &b[d]);       MIN = min(MIN, b[d]);       MAX = max(MAX, b[d]);     }     for (long long d = 0; d < a; d++) {       scanf( %lld , &c[d]);     }     double s = MIN, g = MAX;     for (long long i = 0; i < 10000; i++) {       double k = (s + g) / 2;       double n = -1;       bool t = false;       for (long long j = 0; j < a; j++) {         double m = abs(k - b[j]) / (double)c[j];         if (m > n) {           if (b[j] > k)             t = true;           else             t = false;           n = m;         }       }       if (i == 9999) {         printf( %.15lf n , n);       }       if (t)         s = k;       else         g = k;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[101], b[101], c[101], i;     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) cin >> b[i];     for (i = 0; i < n; i++)       if (a[i] <= b[i]) c[i] = 1;     int bs = 0, rc = 0, sett;     for (i = 0; i < n; i++)       if (a[i] > b[i])         rc++;       else if (a[i] < b[i])         bs++;     if (rc == 0)       cout <<  -1 ;     else       cout << bs / rc + 1;     cout << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long int a[n];     for (int i = 0; i < n; i++) {       scanf( %lld , &a[i]);     }     int m;     cin >> m;     long long int b[m];     for (int i = 0; i < m; i++) {       scanf( %lld , &b[i]);     }     int i = 0, j = 0, ans = 0;     while (i < n && j < m) {       if (a[i] == b[j]) {         i++;         j++;         ans++;       } else if (a[i] > b[j]) {         j++;         if (j < m) {           b[j] += b[j - 1];         }       } else {         i++;         if (i < n) {           a[i] += a[i - 1];         }       }     }     if (i != n || j != m) {       ans = -1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 1, LOGN = 20;   vector<pair<int, long long> > adj[N];   long long a[N], dis[N];   int lca[N][LOGN];   int upd[N];   void dfs1(int u, long long d = 0, int par = 0) {     dis[u] = d;     lca[u][0] = par;     for (int i = 1; i < LOGN; i++) lca[u][i] = lca[lca[u][i - 1]][i - 1];     long long del = dis[u] - a[u];     int v = u;     for (int i = LOGN - 1; i >= 0; i--) {       if (dis[lca[v][i]] >= del) v = lca[v][i];     }     if (v != 0) {       v = lca[v][0];       upd[v]--;     }     for (auto& ch : adj[u]) {       dfs1(ch.first, d + ch.second, u);       upd[u] += upd[ch.first];     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n - 1; i++) {       int p, w;       cin >> p >> w;       adj[p - 1].emplace_back(i + 1, w);     }     fill(upd, upd + n, 1);     dfs1(0);     for (int i = 0; i < n; i++) cout << upd[i] - 1 <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 7;   const int inf = INT_MAX;   const long long inff = 1e18;   const long long mod = 1e9 + 7;   int n, m, x, y;   int a[maxn], p[maxn];   int b[maxn];   int dp1[maxn], dp2[maxn];   vector<int> v;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> x >> y;       p[x]++;       p[y + 1]--;     }     for (int i = 1; i <= m; i++) a[i] = a[i - 1] + p[i], b[m - i + 1] = a[i];     for (int i = 1; i <= m; i++) {       auto now = upper_bound((v).begin(), (v).end(), a[i]);       if (now == v.end())         v.push_back(a[i]);       else         v[now - v.begin()] = a[i];       dp1[i] = ((int)(v).size());     }     v.clear();     for (int i = 1; i <= m; i++) {       auto now = upper_bound((v).begin(), (v).end(), b[i]);       if (now == v.end())         v.push_back(b[i]);       else         v[now - v.begin()] = b[i];       dp2[i] = ((int)(v).size());     }     int ans = 0;     for (int i = 0; i <= m; i++) ans = max(ans, dp1[i] + dp2[m - i]);     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e6 + 10;   const long long int md = 1e9 + 7;   long long int n, fac[MAXN], invf[MAXN];   inline long long int inv(long long int a, long long int b = 1e9 + 5ll) {     long long int k = 1ll;     while (b) {       if (b & 1) k = (k * a) % md;       a = (a * a) % md;       b /= 2ll;     }     return k;   }   inline long long int ch(long long int a, long long int b) {     return ((((invf[b] * invf[a - b]) % md) * fac[a]) % md);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     fac[0] = 1ll;     invf[0] = 1ll;     cin >> n;     for (long long int i = 1ll; i < MAXN; i++)       fac[i] = (fac[i - 1] * i) % md, invf[i] = inv(fac[i]);     long long int ans = inv(2ll, 2ll * n + 1ll);     ans--;     ans = (ans + md) % md;     long long int bad = 0ll;     for (long long int i = n + 1; i <= 2ll * n; i++) {       long long int tmp = (2ll * ch(i - 1ll, n)) % md;       tmp += ((2ll * bad) % md);       tmp %= md;       ans = (((ans - tmp) % md) + md) % md;       bad = tmp;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool seen[100005], x[100005];   vector<int> g[100005], ans;   inline void add(int u) { ans.push_back(u + 1), x[u] ^= 1; }   void dfs(int u, int p) {     seen[u] = true;     add(u);     for (auto v : g[u])       if (v != p && !seen[v]) dfs(v, u), add(u);     if (x[u]) {       if (p != -1)         add(p), add(u);       else         x[u] = 0, ans.pop_back();     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (auto i = (0); i < m; i++) {       int u, v;       scanf( %d%d , &u, &v);       u--, v--;       g[u].push_back(v), g[v].push_back(u);     }     for (auto i = (0); i < n; i++) scanf( %d , x + i);     for (auto i = (0); i < n; i++)       if (x[i]) {         dfs(i, -1);         break;       }     for (auto i = (0); i < n; i++)       if (x[i]) {         printf( -1 );         return 0;       }     printf( %d n , ans.size());     for (auto u : ans) printf( %d  , u);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool compare(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }   int main() {     int maxz, tempbuff, tempbuff2;     cin >> maxz;     vector<pair<int, int>> z;     for (int i = 0; i < maxz; i++) {       cin >> tempbuff >> tempbuff2;       z.push_back(make_pair(tempbuff, tempbuff2));     }     sort(z.begin(), z.end(), compare);     for (int i = 0; i < maxz - 1; i++) {       if (z[i].first > z[i + 1].first) {         cout <<  Happy Alex ;         return 0;       }     }     cout <<  Poor Alex ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   template <typename T>   T sqr(T a) {     return a * a;   }   template <typename T>   int sign(T a) {     if (a == 0) return 0;     return (a > 0 ? 1 : -1);   }   template <typename T1, typename T2>   T2 sum_mod(T1 x, T2 MOD) {     if (x < 0) x += MOD;     if (x >= MOD) x -= MOD;     return x;   }   template <typename T1, typename T2>   T2 mul_mod(T1 x, T2 MOD) {     if (x < 0) return (abs(x) % MOD == 0 ? 0 : MOD - abs(x) % MOD);     return x % MOD;   }   template <typename T>   bool uax(T& a, const T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <typename T>   bool uin(T& a, const T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& p) {     in >> p.first >> p.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2>& p) {     out << p.first <<     << p.second;     return out;   }   const int LOG = 18;   const int N = (int)1e5 + 7;   const int MAXN = (int)2e3 + 7;   const int MOD = (int)998244353;   const int INF = (int)1e9 + 7;   const int CONST = 300;   const long long LINF = (int64_t)2e15;   const long double PI = 3.1415926535897932384626433832795;   const long double EPS = 1;   string a[3];   vector<int> zfunc(const string& a, const string& b) {     string s = a +  #  + b;     int n = (int)s.size();     vector<int> z(n);     int l = 0, r = 0;     for (int i = 1; i < n; i++) {       if (i <= r) z[i] = min(z[i - l], r - i + 1);       while (i + z[i] < n && s[z[i]] == s[i + z[i]]) z[i]++;       if (i + z[i] > r) l = i, r = i + z[i] - 1;     }     return z;   }   string unite(const string& a, const string& b) {     auto v = zfunc(b, a);     string res = a;     for (int i = (int)b.size() + 1; i <= (int)a.size() + (int)b.size(); i++) {       if (v[i] >= (int)b.size()) return res;       if (v[i] + i == (int)a.size() + (int)b.size() + 1) {         res += b.substr(v[i], (int)b.size() - v[i]);         return res;       }     }     return a + b;   }   int get(const string& a, const string& b, const string& c) {     string s = unite(a, b);     s = unite(s, c);     return (int)s.size();   }   int main() {     double start = clock();     cout << fixed << setprecision(20);     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> a[0] >> a[1] >> a[2];     vector<int> perm = {0, 1, 2};     int ans = INF;     do {       uin(ans, get(a[perm[0]], a[perm[1]], a[perm[2]]));     } while (next_permutation(perm.begin(), perm.end()));     cout << ans;   }


#include <bits/stdc++.h>      /*   ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);   int t;   cin >> t;   while(t--) solve();   */   using namespace std;      typedef long long ll;   typedef long double ld;      int magic(vector<int> &a, int del){       auto it = lower_bound(a.begin(), a.end(), del);       if(it == a.end()) return -1;       return *it;   }      void solve(){       int n;       cin >> n;       vector<int> a(n);       map<int, int> mp;       for(int i = 0;i < n;i++){           cin >> a[i];           mp[a[i]] = i + 1;       }       //sort(a.begin(), a.end());       int ans = 0;       for(int i = 2;i <= 2 * n;i++){           for(int j = 2;j * j <= i;j++){               if(i % j == 0){                   int v1 = j, v2 = i / j;                   if(mp[v1] == 0 || mp[v2] == 0 || (mp[v1] == mp[v2])) continue;                   if(mp[v1] + mp[v2] == i) ans++;                   //cout << v1 <<     << v2 <<   n                }           }              if(mp[i] != 0 && mp[1] != 0){               if(mp[i] + mp[1] == i) ans++;           }       }          cout << ans <<   n ;   }      int main(){       ios_base::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);       int t;       cin >> t;       while(t--) solve();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int i, j, n, m, k;     cin >> n;     long long int a[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     cin >> m;     long long int b[m];     for (i = 0; i < m; i++) {       cin >> b[i];     }     sort(a, a + n);     sort(b, b + m);     long long int c = 0;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if (abs(a[i] - b[j]) <= 1) {           b[j] = 1005;           c++;           break;         }       }     }     cout << c << endl;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int tst, t = 1;     for (tst = 1; tst <= t; tst++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<long long> a(n);     for (long long& v : a) cin >> v;     vector<long long> p(n);     for (long long& v : p) cin >> v;     int m;     cin >> m;     vector<long long> b(m);     for (long long& v : b) cin >> v;     vector<long long> cost(m + 1);     for (int i = 0; i < n; i++) {       int j = lower_bound(b.begin(), b.end(), a[i]) - b.begin();       if (j == m)         cost[m] += p[i];       else if (p[i] < 0) {         cost[j] += p[i];       }     }     vector<long long> dp(m + 1, 1e18);     dp[0] = 0;     for (int i = 0; i < n; i++) {       int j = lower_bound(b.begin(), b.end(), a[i]) - b.begin();       if (j == m) continue;       if (b[j] == a[i]) {         long long take_cost = 0;         if (p[i] < 0) take_cost = -p[i];         dp[j + 1] = min(dp[j + 1], dp[j] + cost[j] + take_cost);       }       if (p[i] > 0) {         cost[j] += p[i];       }     }     if (dp[m] > 1e17) {       cout <<  NO  << endl;       return 0;     }     cout <<  YES  << endl;     cout << dp[m] + cost[m] << endl;   }


#include <bits/stdc++.h>   double Pow(double x, int n) {     double ans = 1;     for (; n; n >>= 1) {       if (n & 1) ans *= x;       x *= x;     }     return ans;   }   int main() {     int n, m;     double ans = 0;     scanf( %d%d , &m, &n);     for (int i = 1; i < m; i++) ans += Pow((double)i / (double)m, n);     ans = (double)m - ans;     printf( %lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, m, n, c;     cin >> n >> c;     int ar[n];     for (i = 0; i < n; i++) {       cin >> ar[i];     }     long long int l = 1, h = n, mid;     long long int co = 0, res1 = 0, res2 = 0;     while (l <= h) {       co = 0;       mid = (l + h) / 2;       vector<long long int> v(n);       for (i = 0; i < n; i++) {         v[i] = ar[i] + mid * (i + 1);       }       sort(v.begin(), v.end());       for (i = 0; i < mid; i++) {         co = co + v[i];       }       if (co > c)         h = mid - 1;       else if (co <= c)         l = mid + 1, res1 = co, res2 = mid;     }     cout << res2 <<     << res1;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   const int N = 19;   int g[N];   unsigned long long dp[1 << N][N + 1];   unsigned long long ok[1 << N];   unsigned long long slen[N + 1][1 << N];   unsigned long long cur[N + 1][1 << N];   unsigned long long val[1 << N];   unsigned long long ans[1 << N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         char c;         cin >> c;         if (c ==  1 ) {           g[i] |= (1 << j);         }       }     }     for (int i = 0; i < n; i++) {       dp[1 << i][i] = 1;     }     for (int mask = 0; mask < (1 << n); mask++) {       for (int i = 0; i < n; i++) {         int cands = g[i] & (~mask);         for (int j = 0; j < n; j++) {           if ((cands >> j) & 1) {             dp[mask | (1 << j)][j] += dp[mask][i];           }         }         ok[mask] += dp[mask][i];       }     }     for (int len = 1; len <= n; len++) {       for (int mask = 0; mask < (1 << n); mask++) {         if (__builtin_popcount(mask) == len) {           slen[len][mask] += ok[mask];         }       }       for (int i = 0; i < n; i++) {         for (int mask = 0; mask < (1 << n); mask++) {           if ((mask >> i) & 1) {             slen[len][mask] += slen[len][mask ^ (1 << i)];           }         }       }     }     map<vector<int>, vector<int> > ok;     for (int mask = 0; mask < (1 << (n - 1)); mask++) {       int x = 0;       vector<int> t;       while (x < n) {         int len = 1;         while ((mask >> x) & 1) {           x++;           len++;         }         t.push_back(len);         x++;       }       sort(t.begin(), t.end());       ok[t].push_back(mask);     }     vector<int> a;     for (int mask = 0; mask < (1 << n); mask++) val[mask] = 1;     function<void(int, int)> f = [&](int s, int last) {       if (s == n) {         unsigned long long ret = 0;         int x = (1 << n) - 1;         for (int mask = 0; mask < (1 << n); mask++) {           if (__builtin_popcount(mask) % 2 == 0)             ret += val[x ^ mask];           else             ret -= val[x ^ mask];         }         for (auto c : ok[a]) {           ans[c] += ret;         }         return;       }       if (s + last > n) {         return;       }       for (int mask = 0; mask < (1 << n); mask++) {         cur[s][mask] = val[mask];       }       for (int i = last; s + i <= n; i++) {         if (s + i != n && s + i + i > n) continue;         a.push_back(i);         for (int mask = 0; mask < (1 << n); mask++) {           val[mask] *= slen[i][mask];         }         f(s + i, i);         for (int mask = 0; mask < (1 << n); mask++) {           val[mask] = cur[s][mask];         }         a.pop_back();       }     };     f(0, 1);     for (int i = 0; i < (n - 1); i++) {       for (int mask = 0; mask < (1 << (n - 1)); mask++) {         if (!((mask >> i) & 1)) {           ans[mask] -= ans[mask + (1 << i)];         }       }     }     for (int mask = 0; mask < (1 << (n - 1)); mask++) {       cout << ans[mask] <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-5;   struct line {     double x, y, vx, vy;     void read() {       double t1, t2;       cin >> t1 >> x >> y >> t2 >> vx >> vy;       vx = (vx - x) / (t2 - t1);       vy = (vy - y) / (t2 - t1);       x -= vx * t1;       y -= vy * t1;     }   } L[1005];   struct vec {     double x, y;   } b[1005];   double cross(const vec &a, const vec &b) { return a.x * b.y - a.y * b.x; }   double a[1005];   int tot;   bool cmp(const vec a, const vec b) {     if (fabs(cross(a, b)) < eps) {       if (fabs(a.x - b.x) < eps) return a.y < b.y;       return a.x < b.x;     }     return cross(a, b) < 0;   }   int main() {     ios::sync_with_stdio(0);     int N;     cin >> N;     int ans = 0;     double px, py, pvx, pvy, t;     for (int i = 1; i <= N; i++) L[i].read();     for (int i = 1; i <= N; i++) {       tot = 0;       for (int j = 1; j <= N; j++)         if (i != j) {           px = L[j].x - L[i].x;           py = L[j].y - L[i].y;           pvx = L[j].vx - L[i].vx;           pvy = L[j].vy - L[i].vy;           t = 0;           if (!((fabs(pvx) < eps)))             t = px / pvx;           else if (!(fabs(pvy) < eps))             t = py / pvy;           if (fabs(px - t * pvx) < eps && fabs(py - t * pvy) < eps) {             a[++tot] = t;             b[tot].x = pvx, b[tot].y = pvy;           }         }       sort(a + 1, a + tot + 1);       int cnt = 0;       for (int j = 1; j <= tot; j++) {         if (fabs(a[j] - a[j - 1]) < eps)           cnt++;         else           cnt = 1;         ans = max(ans, cnt);       }       sort(b + 1, b + tot + 1, cmp);       cnt = 0;       for (int j = 1; j <= tot; j++) {         if (fabs(cross(b[j], b[j - 1])) < eps) {           if (fabs(b[j].x - b[j - 1].x) > eps || fabs(b[j].y - b[j - 1].y) > eps)             cnt++;         } else           cnt = 1;         ans = max(ans, cnt);       }     }     cout << ans + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int A = 26;   const int maxn = 5e3 + 5;   const long long mod = 1e9 + 7;   char s[maxn];   int n;   int nxt[maxn][A];   long long fat[maxn], inv[maxn];   long long dp[maxn][maxn];   string t;   void fillNxtTable() {     t = s;     t =  $  + t;     int last[A];     fill(last, last + A, n + 1);     for (int i = n; i >= 0; i--) {       for (int j = 0; j < A; j++) nxt[i][j] = last[j];       if (i) last[t[i] -  a ] = i;     }   }   long long exp(long long a, long long b) {     long long result = 1;     while (b) {       if (b & 1) result = (result * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return result;   }   void preComputeBinomial() {     fat[0] = 1;     inv[0] = 1;     for (int i = 1; i < maxn; i++) {       fat[i] = (fat[i - 1] * i) % mod;       inv[i] = exp(fat[i], mod - 2);     }   }   long long C(int n, int k) {     if (k < 0) return 0;     return (((fat[n] * inv[n - k]) % mod) * inv[k]) % mod;   }   long long solve(int pos, int k) {     if (pos > n) return 0;     long long &ans = dp[pos][k];     if (ans != -1) return ans;     ans = C(n - 1, k - 1);     for (int i = 0; i < A; i++) {       if ((t[pos] -  a ) != i) {         ans = (ans + solve(nxt[pos][i], k + 1));       }     }     ans %= mod;     return ans;   }   int main() {     scanf( %d , &n);     scanf( %s , s);     fillNxtTable();     preComputeBinomial();     memset(dp, -1, sizeof(dp));     printf( %lld n , solve(0, 0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int nbElems, nbAuto;   bitset<2000> autos[2000];   bitset<2000> inverse[2000];   int main() {     scanf( %d%d , &nbElems, &nbAuto);     vector<pair<int, int> > paires;     for (int iPaire = 0; iPaire < nbAuto; iPaire++) {       int pos, elem;       scanf( %d%d , &pos, &elem);       autos[pos - 1][elem - 1] = true;       paires.push_back(make_pair(pos - 1, elem - 1));     }     for (int iElem = 0; iElem < nbElems; iElem++) {       inverse[iElem][iElem] = 1;     }     for (int iLigne = 0; iLigne < nbElems; iLigne++) {       if (!autos[iLigne][iLigne]) {         for (int iAutre = iLigne + 1; iAutre < nbElems; iAutre++) {           if (autos[iAutre][iLigne]) {             autos[iLigne] ^= autos[iAutre];             inverse[iLigne] ^= inverse[iAutre];             break;           }         }       }       for (int iAutre = 0; iAutre < nbElems; iAutre++) {         if (iAutre != iLigne && autos[iAutre][iLigne]) {           autos[iAutre] ^= autos[iLigne];           inverse[iAutre] ^= inverse[iLigne];         }       }     }     for (int iPaire = 0; iPaire < nbAuto; iPaire++) {       if (inverse[paires[iPaire].second][paires[iPaire].first]) {         printf( NO n );       } else {         printf( YES n );       }     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long n, mod, s, s1, s2;   inline long long get(long long id, long long rem, long long l, long long r,                        long long b, long long e, long long x) {     if (e < l || r < b) {       return 0;     }     if (b <= l && r <= e) {       if (x < rem) {         return 0;       }       s = (x - rem) / (1LL << id);       s1 = s;       s2 = s + 1;       if (s % 2 == 0) {         s1 /= 2;       } else {         s2 /= 2;       }       return (((s + 1) % mod) * (rem % mod) % mod +               ((1LL << id) % mod) * (s1 % mod) % mod * (s2 % mod) % mod) %              mod;     }     long long lrem = rem, rrem = rem + (1LL << id);     if (rem == 0) {       rrem = 0;       lrem = (1LL << id);     }     return (get(id + 1, lrem, l, (l + r) / 2, b, e, x) +             get(id + 1, rrem, (l + r) / 2 + 1, r, b, e, x)) %            mod;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long m, l, r, u, v;     cin >> n >> m >> mod;     while (m--) {       cin >> l >> r >> u >> v;       cout << (get(0, 0, 1, n, l, r, min(n, v)) -                get(0, 0, 1, n, l, r, min(n + 1, u) - 1) + mod) %                   mod            << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int p = 0;     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       x--;       if (x % 2) p++;       if (p % 2)         cout << 1 << endl;       else         cout << 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m;     cin >> m >> n;     map<int, vector<pair<int, int>>> matrix;     vector<int> cnt(n, m), mag(m, n);     int cnt2 = m;     for (int i = 0; i < m; ++i) {       for (int j = 0; j < n; ++j) {         int a;         cin >> a;         matrix[a].push_back(make_pair(j, i));       }     }     int ans = -1;     for (auto &elem : matrix) {       ans = elem.first;       bool ok = 1;       for (auto &pr : elem.second) {         int i = pr.first, j = pr.second;         --cnt[i];         --mag[j];         if (cnt[i] == 0) {           ok = 0;           break;         }         if (mag[j] == 1) --cnt2;       }       if (!ok || cnt2 == 0) break;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     srand(time(NULL));     int tt = 1;     cin >> tt;     while (tt--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int up_div(int a, int b) { return a / b + (a % b != 0); }   int down_div(int a, int b) { return a / b; }   int main() {     int a, b;     cin >> a >> b;     int res = 0;     for (int k = 1; k <= a + b; ++k) {       int d = (a + b) / k;       int min_k = k;       int max_k = (a + b) / d;       res += (up_div(a, d + 1) <= down_div(a, d) &&               up_div(b, d + 1) <= down_div(b, d)) *              (min(down_div(a, d) + down_div(b, d), max_k) -               max(up_div(a, d + 1) + up_div(b, d + 1), min_k) + 1);       k = max_k;     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long long inf = 10e17 + 9;   const long double p = acos(-1);   int n, x;   vector<int> v[200009];   int dis1[200009];   int dis2[200009];   void dfs1(int node, int p, int k) {     dis1[node] = k;     for (int i = 0; i < v[node].size(); i++) {       int u = v[node][i];       if (u != p) dfs1(u, node, k + 1);     }   }   void dfs2(int node, int p, int k) {     dis2[node] = k;     for (int i = 0; i < v[node].size(); i++) {       int u = v[node][i];       if (u != p) dfs2(u, node, k + 1);     }   }   int main() {     cin >> n >> x;     x--;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b, a--, b--;       v[a].push_back(b), v[b].push_back(a);     }     dfs1(0, 0, 0);     dfs2(x, x, 0);     int mx = 0;     for (int i = 0; i < n; i++) {       int x = 0;       if (dis2[i] < dis1[i]) x = dis1[i];       mx = max(mx, x);     }     cout << mx * 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   long long m, n, t, a1, b1, cnta, cntb, b[maxn];   struct point {     long long x, y;     point(long long x = 0, long long y = 0) : x(x), y(y) {}     bool operator<(const point& p) const {       return x < p.x || (x == p.x && y < p.y);     }   } a[maxn];   int main() {     cin >> m;     while (m--) {       cnta = cntb = 0;       cin >> n >> t >> a1 >> b1;       for (long long i = 1; i <= n; i++) {         cin >> b[i];         if (b[i])           cntb++;         else           cnta++;       }       for (long long i = 1; i <= n; i++) {         long long x;         cin >> x;         a[i] = point(x, b[i]);       }       a[n + 1] = point(t + 1, 0);       sort(a + 1, a + n + 2);       long long ans = 0, cnt1 = 0, cnt2 = 0;       for (int i = 1; i <= n + 1; i++) {         long long sum = cnt1 * a1 + cnt2 * b1, res = a[i].x - sum - 1;         if (res >= 0) {           long long ta = min(cnta - cnt1, res / a1);           res -= ta * a1;           long long tb = min(cntb - cnt2, res / b1);           ans = max(ans, cnt1 + cnt2 + ta + tb);         }         long long cnt = i;         while (cnt <= n + 1 && a[cnt].x == a[i].x) {           if (a[cnt].y)             cnt2++;           else             cnt1++;           cnt++;         }         i = cnt - 1;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   const int N = 1e3 + 10;   const double eps = 1e-5;   int n;   struct Tarr {     long long tarr[N][N];     Tarr() {       for (int i = 0; i < N; i++) {         for (int j = 0; j < N; j++) {           tarr[i][j] = 0;         }       }     }     static int lowbit(int x) { return x & -x; }     void add(int x, int y, long long val) {       while (x <= n) {         int p = y;         while (p <= n) {           tarr[x][p] ^= val;           p += lowbit(p);         }         x += lowbit(x);       }     }     long long query(int x, int y) {       long long res = 0;       while (x) {         int p = y;         while (p) {           res ^= tarr[x][p];           p -= lowbit(p);         }         x -= lowbit(x);       }       return res;     }   };   Tarr an, ai, aj, aij;   long long query(int x, int y) {     return (((x + 1) * (y + 1) % 2) * an.query(x, y)) ^            (((x + 1) % 2) * ai.query(x, y)) ^ (((y + 1) % 2) * aj.query(x, y)) ^            aij.query(x, y);   }   long long query(int x1, int y1, int x2, int y2) {     return query(x2, y2) ^ query(x1 - 1, y2) ^ query(x2, y1 - 1) ^            query(x1 - 1, y1 - 1);   }   void add(int x, int y, long long val) {     an.add(x, y, val);     ai.add(x, y, (y % 2) * val);     aj.add(x, y, (x % 2) * val);     aij.add(x, y, (x * y % 2) * val);   }   void add(int x1, int y1, int x2, int y2, long long val) {     add(x1, y1, val);     add(x1, y2 + 1, val);     add(x2 + 1, y1, val);     add(x2 + 1, y2 + 1, val);   }   int main() {     std::ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int op;       cin >> op;       if (op == 2) {         int x1, y1, x2, y2;         long long v;         cin >> x1 >> y1 >> x2 >> y2 >> v;         add(x1, y1, x2, y2, v);       } else {         int x1, y1, x2, y2;         cin >> x1 >> y1 >> x2 >> y2;         cout << query(x1, y1, x2, y2) <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, hd, el;   char s[1000];   struct E {     char tag;     int p[26];   } e[1000000];   void ins() {     int i, j, k, l;     for (i = 0, l = hd; s[i]; i++) {       if (!e[l].p[s[i] -  a ]) e[l].p[s[i] -  a ] = el++;       l = e[l].p[s[i] -  a ];     }   }   void dfs(int ei) {     int i, j, c[5] = {0, 0, 0, 0, 0};     for (i = j = 0; i < 26; i++) {       if (e[ei].p[i]) {         j = 1;         dfs(e[ei].p[i]);         c[e[e[ei].p[i]].tag]++;       }     }     if (!j)       e[ei].tag = 1;     else if (c[4] || (c[1] && c[2]))       e[ei].tag = 3;     else if (c[1])       e[ei].tag = 2;     else if (c[2])       e[ei].tag = 1;     else       e[ei].tag = 4;   }   void init() {     int i, j, k, l;     hd = el = 0;     el++;     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++) {       scanf( %s , s);       ins();     }     dfs(hd);   }   void solve() {     if (e[hd].tag == 1 || e[hd].tag == 4)       puts( Second );     else if (e[hd].tag == 3)       puts( First );     else if (m & 1)       puts( First );     else       puts( Second );   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int tree[10000][2];   int lights;   void mark(int node, int l) {     int p = node / 2;     if (p == 0) return;     tree[p][node % 2] = min(tree[p][node % 2], lights - l);     mark(p, l);   }   int cont[10000];   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     memset(tree, -1, sizeof(tree));     int n, a, p;     cin >> n;     int lim = (1 << (n + 1)) - 1;     for (int i = 2; i <= lim; ++i) {       cin >> a;       p = i / 2;       tree[p][i % 2] = a;     }     lights = 0;     queue<int> Q;     Q.push(1);     Q.push(0);     while (!Q.empty()) {       int u = Q.front();       Q.pop();       int l = Q.front();       Q.pop();       if (tree[u][0] == -1) {         lights = max(lights, l);         cont[u] = l;         continue;       }       Q.push(2 * u);       Q.push(tree[u][0] + l);       Q.push(2 * u + 1);       Q.push(tree[u][1] + l);       tree[u][0] = tree[u][1] = 0x3fffffff;     }     for (int i = 1 << n; i <= lim; ++i) mark(i, cont[i]);     int ans = 0;     Q.push(1);     Q.push(0);     while (!Q.empty()) {       int u = Q.front();       Q.pop();       int l = Q.front();       Q.pop();       if (tree[u][0] == -1) continue;       ans += tree[u][0] + tree[u][1] - 2 * l;       Q.push(2 * u);       Q.push(tree[u][0]);       Q.push(2 * u + 1);       Q.push(tree[u][1]);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n), ans;       for (int i = 0; i < n; i++) {         cin >> a[i];       }       auto cyc = [&](int idx) {         swap(a[idx + 2], a[idx]);         swap(a[idx + 1], a[idx + 2]);         ans.push_back(idx);       };       if (n == 3) {         if (!is_sorted(a.begin(), a.end())) cyc(0);         if (!is_sorted(a.begin(), a.end())) cyc(0);       }       for (int i = 0; i + 2 < n; i++) {         vector<pair<int, int>> b(n);         for (int j = 0; j < n; j++) {           b[j] = {a[j], j};         }         sort(b.begin(), b.end());         if (i < b[i].second) {           for (int k = b[i].second - 2; k >= i; k -= 2) {             cyc(k);           }           if ((b[i].second - i) & 1) {             cyc(i);             cyc(i);           }         }       }       if (a[n - 2] > a[n - 1]) {         int x = -1;         for (int i = 0; i + 2 < n; i++) {           if (a[i] == a[i + 1]) {             x = i;           }         }         if (x != -1) {           for (int i = x; i < n - 4; i++) {             cyc(i);           }           cyc(n - 3);           cyc(n - 4);           for (int i = n - 5; i >= x; i--) {             cyc(i);             cyc(i);           }         }       }       if (a[n - 2] > a[n - 1]) cyc(n - 3);       if (is_sorted(a.begin(), a.end()) && ans.size() <= n * n) {         cout << ans.size() <<   n ;         for (auto i : ans) cout << i + 1 <<    ;         cout <<   n ;       } else {         cout << -1 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 7;   vector<long long> v[N];   long long vis[N], prt[N], bip[N], cs, ce;   void dfs(long long ver, long long par) {     bip[ver] = (!bip[par]);     vis[ver] = 1;     prt[ver] = par;     for (auto it : v[ver]) {       if (vis[it] == 2 || it == par) continue;       if (vis[it] == 1) {         cs = it;         ce = ver;         break;       }       dfs(it, ver);     }     vis[ver] = 2;   }   int32_t main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long n, m, k;     cin >> n >> m >> k;     for (long long i = (long long)(1); i <= (long long)(m); i++) {       long long x, y;       cin >> x >> y;       if (x > k || y > k) continue;       v[x].push_back(y);       v[y].push_back(x);     }     for (long long i = (long long)(1); i <= (long long)(k); i++) {       if (vis[i]) continue;       dfs(i, 0);     }     if (cs) {       cout << 2 <<   n ;       vector<long long> ans;       while (cs != ce) {         ans.push_back(ce);         ce = prt[ce];       }       ans.push_back(ce);       cout << ans.size() <<   n ;       for (auto it : ans) cout << it <<    ;     } else {       cout << 1 <<   n ;       long long kk = k / 2 + k % 2;       long long tmp = count(bip + 1, bip + k + 1, 0);       if (tmp >= kk) {         for (long long i = (long long)(1); i <= (long long)(k); i++) {           if (kk > 0 && bip[i] == 0) {             cout << i <<    ;             kk--;           }         }       } else {         for (long long i = (long long)(1); i <= (long long)(k); i++) {           if (kk > 0 && bip[i]) {             cout << i <<    ;             kk--;           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, l;     cin >> n >> l;     double a[n];     for (int i = 0; i < n; i++) cin >> a[i];     sort(&a[0], &a[n]);     float x = a[0] - 0;     float y = l - a[n - 1];     for (int i = 0; i < n - 1; i++) a[i] = (a[i + 1] - a[i]) / 2;     if (x > y)       a[n - 1] = x;     else       a[n - 1] = y;     sort(&a[0], &a[n]);     cout << std::fixed << a[n - 1];   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 2;   const int mod = 100003;   const int INF = 0x3f3f3f;   int n, m, x, y;   int vis[N];   struct node {     int x, r, i, v;   } tar[N];   bool cmp1(node &x, node &y) { return x.x < y.x; }   bool cmp2(node &x, node &y) { return x.i < y.i; }   int find(int x) {     int l, mid, r;     l = 1, r = n;     while (r - l > 1) {       mid = (l + r) / 2;       if (tar[mid].x == x) return mid;       if (tar[mid].x < x) l = mid;       if (tar[mid].x > x) r = mid;     }     return l;   }   bool chk(int p, int x, int y) {     if ((tar[p].x - x) * (tar[p].x - x) + y * y <= tar[p].r * tar[p].r)       return true;     else       return false;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     memset(vis, 0, sizeof(vis));     ;     for (int i = 1; i <= n; i++) {       cin >> tar[i].x >> tar[i].r;       tar[i].v = -1;       tar[i].i = i;     }     sort(tar + 1, tar + 1 + n, cmp1);     cin >> m;     int pos;     int sum = 0;     for (int i = 1; i <= m; i++) {       cin >> x >> y;       pos = find(x);       if (tar[pos - 1].v == -1 && chk(pos - 1, x, y)) {         tar[pos - 1].v = i;         sum++;       }       if (tar[pos].v == -1 && chk(pos, x, y)) {         tar[pos].v = i;         sum++;       }       if (tar[pos + 1].v == -1 && chk(pos + 1, x, y)) {         tar[pos + 1].v = i;         sum++;       }     }     sort(tar + 1, tar + 1 + n, cmp2);     cout << sum << endl;     for (int i = 1; i <= n; i++) {       cout << tar[i].v <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     if (s[1] ==  1 ) {       if (s[0] ==  a  || s[0] ==  h ) {         cout <<  3  << endl;       } else {         cout <<  5  << endl;       }     } else if (s[1] ==  8 ) {       if (s[0] ==  a  || s[0] ==  h ) {         cout <<  3  << endl;       } else {         cout <<  5  << endl;       }     } else {       if (s[0] ==  a  || s[0] ==  h ) {         cout <<  5  << endl;       } else {         cout <<  8  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     double x, y;     Point() {}     Point(double a, double b) { x = a, y = b; }   };   const double eps = 1e-10;   Point operator+(Point A, Point B) { return Point(A.x + B.x, A.y + B.y); }   Point operator-(Point A, Point B) { return Point(A.x - B.x, A.y - B.y); }   Point operator*(Point A, double p) { return Point(A.x * p, A.y * p); }   Point operator/(Point A, double p) { return Point(A.x / p, A.y / p); }   bool operator<(const Point &a, const Point &b) {     return a.x < b.x || (a.x == b.x && a.y < b.y);   }   int dcmp(double x) {     if (fabs(x) < eps)       return 0;     else       return x < 0 ? -1 : 1;   }   bool operator==(const Point &a, const Point &b) {     return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;   }   double Dot(Point A, Point B) { return A.x * B.x + A.y * B.y; }   double Length(Point A) { return sqrt(Dot(A, A)); }   double Angle(Point A, Point B) {     return acos(Dot(A, B) / Length(A) / Length(B));   }   double Cross(Point A, Point B) { return A.x * B.y - A.y * B.x; }   double Area2(Point A, Point B, Point C) { return Cross(B - A, C - A); }   Point Rotate(Point A, double rad) {     return Point(A.x * cos(rad) - A.y * sin(rad),                  A.x * sin(rad) + A.y * cos(rad));   }   Point Jd(Point P, Point v, Point Q, Point w) {     Point u = P - Q;     double t = Cross(w, u) / Cross(v, w);     return P + v * t;   }   double Dtl(Point P, Point A, Point B) {     Point v1 = B - A, v2 = P - A;     return fabs(Cross(v1, v2)) / Length(v1);   }   double Dts(Point P, Point A, Point B) {     if (A == B) return Length(P - A);     Point v1 = B - A, v2 = P - A, v3 = P - B;     if (dcmp(Dot(v1, v2) < 0))       return Length(v2);     else if (dcmp(Dot(v1, v3)) > 0)       return Length(v3);     else       return fabs(Cross(v1, v2)) / Length(v1);   }   Point Gjp(Point P, Point A, Point B) {     Point v = B - A;     return A + v * (Dot(v, P - A)) / (Dot(v, v));   }   bool Spi(Point a1, Point a2, Point b1, Point b2) {     double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1),            c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - a1);     return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0;   }   bool Onseg(Point p, Point a1, Point a2) {     return dcmp(Cross(a1 - p, a2 - p)) == 0 && dcmp(Dot(a1 - p, a2 - p)) < 0;   }   double Parea(Point *p, int n) {     double area = 0;     for (int i = 1; i <= n; i++) area += Cross(p[i] - p[0], p[i + 1] - p[0]);     return area / 2;   }   bool cmp(Point a, Point b) {     if (fabs(a.x - b.x) > eps)       return a.x + eps < b.x;     else       return a.y + eps < b.y;   }   struct Circle {     Point o;     double r;     Circle() {}     Circle(Point _o, double _r) { o = _o, r = _r; }     friend vector<Point> operator&(const Circle &c1, const Circle &c2) {       double d = Length(c1.o - c2.o);       if (d > c1.r + c2.r + eps || d < fabs(c1.r - c2.r) - eps)         return vector<Point>();       double dt = (c1.r * c1.r - c2.r * c2.r) / d, d1 = (d + dt) / 2.0;       Point dir = (c2.o - c1.o) / d, pcrs = c1.o + dir * d1;       dt = sqrt(max(0.0, c1.r * c1.r - d1 * d1));       swap(dir.x, dir.y), dir.x = -dir.x;       return vector<Point>{pcrs + dir * dt, pcrs - dir * dt};     }   } p[10];   int f[10], rk[10], n;   int find(int x) {     if (f[x] != x)       return f[x] = find(f[x]);     else       return x;   }   void merge(int i, int j) {     int x = find(i), y = find(j);     if (rk[x] > rk[y])       f[y] = x;     else {       f[x] = y;       if (rk[x] == rk[y]) rk[y]++;     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) f[i] = i, rk[i] = 0;     for (int i = 1; i <= n; i++) cin >> p[i].o.x >> p[i].o.y >> p[i].r;     int e = 0, v = 0, c = 0;     vector<Point> all;     for (int i = 1; i <= n; i++) {       vector<Point> tmp1;       for (int j = 1; j <= n; j++) {         if (j == i) continue;         vector<Point> tmp2 = p[i] & p[j];         if (tmp2.size()) merge(i, j);         tmp1.insert(tmp1.end(), tmp2.begin(), tmp2.end());         all.insert(all.end(), tmp2.begin(), tmp2.end());       }       sort(tmp1.begin(), tmp1.end(), cmp);       e += unique(tmp1.begin(), tmp1.end()) - tmp1.begin();     }     sort(all.begin(), all.end(), cmp);     v += unique(all.begin(), all.end()) - all.begin();     set<int> st;     for (int i = 1; i <= n; i++) {       st.insert(find(i));     }     cout << e - v + st.size() + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int l, r, b, No;     bool operator<(const Node &t) const {       if (b != t.b) return b < t.b;       return r < t.r;     }   };   const int N = 200005;   const int M = 1000005;   int n, Q;   int seq[N];   Node q[N];   int cnt[M];   long long ans[N];   long long &cal(int x, int &l, int &r, long long &ret) {     int L = q[x].l, R = q[x].r;     while (l > L) {       --l;       int t = seq[l];       ret += 2LL * cnt[t] * t + t;       cnt[t]++;     }     while (r < R) {       ++r;       int t = seq[r];       ret += 2LL * cnt[t] * t + t;       cnt[t]++;     }     while (l < L) {       int t = seq[l];       ret += -2LL * cnt[t] * t + t;       ++l;       cnt[t]--;     }     while (r > R) {       int t = seq[r];       ret += -2LL * cnt[t] * t + t;       --r;       cnt[t]--;     }     return ret;   }   void solve() {     int B = (int)sqrt(1.0 * n);     memset(cnt, 0, sizeof(cnt));     for (int i = 1; i <= Q; ++i) {       scanf( %d %d , &q[i].l, &q[i].r);       q[i].b = q[i].l / B;       q[i].No = i;     }     sort(q + 1, q + 1 + Q);     int l = q[1].l, r = q[1].r;     long long ret = 0;     for (int i = l; i <= r; ++i) {       int t = seq[i];       ret += 2LL * cnt[t] * t + t;       cnt[t]++;     }     ans[q[1].No] = ret;     for (int i = 2; i <= Q; ++i) {       ans[q[i].No] = cal(i, l, r, ret);     }     for (int i = 1; i <= Q; ++i) {       printf( %I64d n , ans[i]);     }   }   int main() {     while (scanf( %d %d , &n, &Q) != EOF) {       for (int i = 1; i <= n; ++i) {         scanf( %d , &seq[i]);       }       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int l = s.length();       vector<int> v(26, 0);       for (int i = 0; i < l; i++) {         if (s[i] == s[i + 1]) {           i++;         } else {           v[s[i] -  a ] = 1;         }       }       for (int i = 0; i < 26; i++) {         if (v[i]) {           cout << (char)(i +  a );         }       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) {cerr << x;}   void __print(long x) {cerr << x;}   void __print(long long x) {cerr << x;}   void __print(unsigned x) {cerr << x;}   void __print(unsigned long x) {cerr << x;}   void __print(unsigned long long x) {cerr << x;}   void __print(float x) {cerr << x;}   void __print(double x) {cerr << x;}   void __print(long double x) {cerr << x;}   void __print(char x) {cerr <<      << x <<     ;}   void __print(const char *x) {cerr <<     << x <<    ;}   void __print(const string &x) {cerr <<     << x <<    ;}   void __print(bool x) {cerr << (x ?  true  :  false );}      template<typename T, typename V>   void __print(const pair<T, V> &x) {cerr <<  { ; __print(x.first); cerr <<  , ; __print(x.second); cerr <<  } ;}   template<typename T>   void __print(const T &x) {int f = 0; cerr <<  { ; for (auto &i: x) cerr << (f++ ?  ,  :   ), __print(i); cerr <<  } ;}   void _print() {cerr <<  ] n ;}   template <typename T, typename... V>   void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr <<  ,  ; _print(v...);}   #ifndef ONLINE_JUDGE   #define debug(x...) cerr <<  [  << #x <<  ] = [ ; _print(x)   #else   #define debug(x...)   #endif      #define ll long long int   const int mod = 1000000007;   int mpow(int b, int e);      void solve(){    int n; cin>>n;     vector<int> even, odd;     for(int i=0; i<n;i++){     int x; cin>>x;      if(x&1) odd.push_back(x);      else even.push_back(x);     }       for(auto i:odd) cout<<i<<   ;     for(auto i:even) cout<<i<<   ;     cout<<endl;      }      int main(){       ios_base::sync_with_stdio(false);       cin.tie(0);cout.tie(0);       int t=1;       cin>>t;       for(int tt=1; tt<=t; tt++){           //cout <<  Case # <<tt<< :  ;           solve();       }       return 0;   }      //modular exponentiation   int mpow(int base, int exp) {     base %= mod;     int result = 1;     while (exp > 0) {       if (exp & 1) result = ((ll)result * base) % mod;       base = ((ll)base * base) % mod;       exp >>= 1;     }     return result;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   long long calc(long long n, long long k) {     map<long long, long long> l, r;     l.clear();     r.clear();     long long cnt[2];     cnt[0] = cnt[1] = 0;     if (k == 1) return n / 2;     k--;     l[n / 2] = 1;     r[n / 2 + (n % 2)] = 1;     while (1) {       if ((*l.rbegin()).first / 2 >= (*r.rbegin()).first / 2) {         if ((*l.rbegin()).second >= k) return calc(n / 2, k + cnt[0]);         k -= (*l.rbegin()).second;         cnt[0] += (*l.rbegin()).second;         l[(*l.rbegin()).first / 2] += (*l.rbegin()).second;         l[(*l.rbegin()).first / 2 + ((*l.rbegin()).first % 2)] +=             (*l.rbegin()).second;         l.erase((*l.rbegin()).first);       } else {         if ((*r.rbegin()).second >= k)           return calc(n / 2 + (n % 2), k + cnt[1]) + n / 2;         k -= (*r.rbegin()).second;         cnt[1] += (*r.rbegin()).second;         r[(*r.rbegin()).first / 2] += (*r.rbegin()).second;         r[(*r.rbegin()).first / 2 + ((*r.rbegin()).first % 2)] +=             (*r.rbegin()).second;         r.erase((*r.rbegin()).first);       }     }   }   int main() {     cin >> n >> k;     if (k == 1) {       cout << 1;       return 0;     }     if (k == 2) {       cout << n;       return 0;     }     cout << 1 + calc(n - 1, k - 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 250000, B = 18;   vector<int> tr1[N + 1], tr2[N + 1];   int n, dp[N + 1], pa[N + 1][B], gr[N + 1];   int P(int v) { return gr[v] ? gr[v] = P(gr[v]) : v; }   void pl(int v = 1, int p = 0) {     dp[v] = dp[p] + 1;     pa[v][0] = p;     int k = 1, z;     while (k < B && (z = pa[v][k - 1])) pa[v][k] = pa[z][k - 1], ++k;     for (int u : tr1[v])       if (u != p) pl(u, v);   }   int lca(int a, int b) {     if (dp[a] < dp[b]) swap(a, b);     int d = dp[a] - dp[b], j = 0;     while (d) {       if (d & 1) a = pa[a][j];       ++j;       d >>= 1;     }     if (a == b) return a;     for (int i = B - 1; i >= 0; --i)       if (pa[a][i] != pa[b][i]) a = pa[a][i], b = pa[b][i];     return pa[a][0];   }   void J(int a, int b) {     printf( %d %d , a, b);     gr[a] = b;   }   void kl(int a, int b) {     a = P(a);     int c = lca(a, b);     if (c != a)       J(a, pa[a][0]);     else {       for (int i = B - 1; i >= 0; --i)         if (dp[pa[b][i]] > dp[c] && P(pa[b][i]) != a) b = pa[b][i];       J(b, pa[b][0]);     }   }   void go(int v = 1, int p = 0) {     for (int u : tr2[v])       if (u != p) go(u, v);     if (p) {       kl(v, p);       printf(  %d %d n , v, p);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < (int)(n); ++i) {       int a, b;       scanf( %d%d , &a, &b);       tr1[a].push_back(b);       tr1[b].push_back(a);     }     for (int i = 1; i < (int)(n); ++i) {       int a, b;       scanf( %d%d , &a, &b);       tr2[a].push_back(b);       tr2[b].push_back(a);     }     pl();     printf( %d n , n - 1);     go();   }


#include <bits/stdc++.h>   using namespace std;   deque<int> enumeration;   deque<int> cutOrder;   struct Edge {     Edge(int from, int to, int ind) : from(from), to(to), ind(ind) {}     int from, to, ind;     shared_ptr<Edge> nxt = nullptr;     shared_ptr<Edge> rev = nullptr;     shared_ptr<Edge> flip = nullptr;   };   void search(shared_ptr<Edge> e, int end) {     if (e->flip == nullptr) {       enumeration.push_back(e->from);       if (e->to != end) {         search(e->nxt, end);       }     } else {       search(e->flip->rev->nxt, e->to);       if (e->to != end) {         search(e->nxt, end);       }     }     if (e->to == end) {       cutOrder.push_back(e->ind);     }   }   auto hashf = [](pair<int, int> p) { return p.first + (p.second << 15); };   unordered_map<pair<int, int>, shared_ptr<Edge>, decltype(hashf)> edgeSet(1000,                                                                            hashf);   shared_ptr<Edge> addFlip(shared_ptr<Edge> e) {     pair<int, int> p(e->from, e->to);     shared_ptr<Edge> flip = edgeSet[p];     if (flip == nullptr) {       edgeSet[p] = e;     } else {       assert(flip->flip == nullptr);       e->flip = flip;       flip->flip = e;     }     return e;   }   void addTriangle(int a, int b, int c, int i) {     shared_ptr<Edge> e1, e2, e3, e1r, e2r, e3r;     e1 = make_shared<Edge>(a, b, i);     e2 = make_shared<Edge>(b, c, i);     e3 = make_shared<Edge>(c, a, i);     e1->nxt = e2;     e2->nxt = e3;     e3->nxt = e1;     e1r = make_shared<Edge>(b, a, i);     e2r = make_shared<Edge>(c, b, i);     e3r = make_shared<Edge>(a, c, i);     e1r->nxt = e3r;     e2r->nxt = e1r;     e3r->nxt = e2r;     e1->rev = e1r;     e2->rev = e2r;     e3->rev = e3r;     e1r->rev = e1;     e2r->rev = e2;     e3r->rev = e3;     addFlip(e1);     addFlip(e2);     addFlip(e3);     addFlip(e1r);     addFlip(e2r);     addFlip(e3r);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int t, n;     cin >> t;     for (int caseNum = 0; caseNum < t; caseNum++) {       cin >> n;       enumeration.clear();       cutOrder.clear();       edgeSet.clear();       for (int i = 1; i <= n - 2; i++) {         int a, b, c;         cin >> a >> b >> c;         addTriangle(a, b, c, i);       }       shared_ptr<Edge> e1 = edgeSet.begin()->second;       search(e1, e1->from);       for (auto e : enumeration) {         cout << e <<    ;       }       cout <<   n ;       for (auto e : cutOrder) {         cout << e <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int slimes, values;     vector<int> vec;     cin >> slimes;     for (int i = 0; i < slimes; i++) {       vec.push_back(1);       while (vec.size() > 1 && vec[vec.size() - 1] == vec[vec.size() - 2]) {         vec.pop_back();         vec[vec.size() - 1] += 1;       }     }     for (int j = 0; j < vec.size(); j++) {       cout << vec[j] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, x;     cin >> n >> x;     long long a[n], b[n];     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) cin >> b[i];     sort(a, a + n, greater<int>());     sort(b, b + n);     long long ans = 0, f, id = 0;     for (int i = 0; i < n; ++i) {       f = 0;       while (id < n) {         if (a[i] + b[id] >= x) {           f = 1;           ++id;           break;         }         ++id;       }       if (f)         ++ans;       else         break;     }     cout <<  1   << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, r, s1, s2, d;     cin >> n;     r = ceil(double(sqrt(n)));     s1 = r * r;     s2 = (r - 1) * (r - 1);     d = s1 - s2;     d = d / 2;     d = s1 - d;     if (n < d) {       cout << (r * 2) - 1;     } else {       cout << r * 2;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   const int maxn = 1e5 + 5;   void Solution() {     int n;     cin >> n;     cout << (n / 2) + 1 <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) Solution();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n;   int a[2000010];   int main() {     while (~scanf( %d , &n)) {       for (int i = 1; i <= n; i++) a[i] = i;       for (int k = 2; k <= n; k++) {         int ed = n + k - 1, rp = n / k + (n % k != 0);         for (int t = k - 1 + (rp - 1) * k; t >= k - 1; t -= k) {           swap(a[ed], a[t]);           ed = t;         }       }       for (int i = n; i <= 2 * n - 1; i++) printf( %d  , a[i]);       puts(  );     }   }


#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-8;   const long double INF = 1e12;   const long double PI = acos(-1);   struct L : array<complex<long double>, 2> {     L(const complex<long double>& a, const complex<long double>& b) {       at(0) = a;       at(1) = b;     }     L() {}   };   namespace std {   bool operator<(const complex<long double>& a, const complex<long double>& b) {     return !(abs((a.real()) - (b.real())) < EPS) ? a.real() < b.real()                                                  : a.imag() + EPS < b.imag();   }   bool operator==(const complex<long double>& a, const complex<long double>& b) {     return abs(a - b) < EPS;   }   }  // namespace std   long double dot(complex<long double> a, complex<long double> b) {     return (conj(a) * b).real();   }   long double cross(complex<long double> a, complex<long double> b) {     return (conj(a) * b).imag();   }   bool intersectLP(const L& l, const complex<long double>& p) {     return abs(cross(l[1] - p, l[0] - p)) < EPS;   }   bool strictItsLS(const L& l, const L& s) {     return cross(l[1] - l[0], s[0] - l[0]) * cross(l[1] - l[0], s[1] - l[0]) <            -EPS;   }   bool isParallel(const complex<long double>& a, const complex<long double>& b) {     return abs(cross(a, b)) < EPS;   }   bool isParallel(const L& a, const L& b) {     return isParallel(a[1] - a[0], b[1] - b[0]);   }   complex<long double> crosspointLL(const L& l, const L& m) {     long double A = cross(l[1] - l[0], m[1] - m[0]);     long double B = cross(l[1] - l[0], l[1] - m[0]);     return m[0] + B / A * (m[1] - m[0]);   }   long double getarea(const vector<complex<long double> >& poly) {     long double ret = 0;     for (int i = 0; i < (int)poly.size(); i++) {       ret += cross(poly[i], poly[(i + 1) % poly.size()]);     }     return ret * 0.5;   }   bool in_corner(const complex<long double>& p,                  const vector<complex<long double> >& v) {     bool s1 = cross(v[1] - v[0], p - v[0]) > -EPS;     bool s2 = cross(v[2] - v[1], p - v[1]) > -EPS;     return (cross(v[1] - v[0], v[2] - v[0]) > -EPS) ? s1 and s2 : s1 or s2;   }   long double solve(vector<complex<long double> >& v, L cut) {     int n = v.size();     complex<long double> cdir = cut[1] - cut[0];     vector<complex<long double> > cps;     for (int i = 0; i < n; i++) {       L edge(v[i], v[(i + 1) % n]);       if (strictItsLS(cut, edge) and !isParallel(cut, edge)) {         cps.push_back(crosspointLL(cut, edge));       }       if (intersectLP(cut, v[i])) {         vector<complex<long double> > p{v[(i - 1 + n) % n], v[i], v[(i + 1) % n]};         if (in_corner(p[1] + cdir, p) != in_corner(p[1] - cdir, p)) {           cps.push_back(v[i]);         }       }     }     sort(cps.begin(), cps.end());     long double res = 0;     for (int i = 0; i < (int)cps.size() - 1; i += 2) {       res += abs(cps[i + 1] - cps[i]);     }     return res;   }   int main() {     int n, m;     cin >> n >> m;     vector<complex<long double> > v(n);     for (int i = 0; i < n; i++) {       long double x, y;       cin >> x >> y;       v[i] = complex<long double>(x, y);     }     if (getarea(v) < 0) {       reverse(v.begin(), v.end());     }     cout << fixed << setprecision(10);     for (int i = 0; i < m; i++) {       long double xs, ys, xt, yt;       cin >> xs >> ys >> xt >> yt;       cout << solve(v,                     L(complex<long double>(xs, ys), complex<long double>(xt, yt)))            << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int MAXX = 2e6 + 10;   long long phi(long long n) {     long long ret = n;     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) {         while (n % i == 0) n /= i;         ret -= ret / i;       }     }     if (n > 1) ret -= ret / n;     return ret;   }   int main() {     long long n, k;     scanf( %lld %lld , &n, &k);     k = (k + 1) / 2;     long long ans = n;     while (k--) {       ans = phi(ans);       if (ans == 1) break;     }     printf( %lld , ans % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 7;   const long long inf = 0x3f3f3f3f;   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       double pi = 3.1415926535897932384626433832795028841971, n;       cin >> n;       long long sum = n / 2;       double x = 0.5 / tan(pi / (n * 2)), y = 0.5 / sin(pi / (n * 2));       printf( %.10lf n , x * 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(pair<long long, long long> a, pair<long long, long long> b) {     return a.first > b.first;   }   long long findBest(vector<pair<long long, long long> > &ps, long long x) {     long long res = 0;     for (long long i = 0; i < ps.size(); i++) {       long long num = ps[i].second;       long long diff = ps[i].first;       if (x - num >= 0) {         res += (num * diff);         x -= num;       } else {         res += (x * diff);         break;       }     }     return res;   }   int main() {     long long n, s;     cin >> n >> s;     vector<pair<long long, long long> > ps;     long long total = 0;     long long positives = 0;     long long pieces = 0;     for (long long i = 0; i < n; i++) {       long long num, a, b;       cin >> num >> a >> b;       ps.push_back(make_pair(a - b, num));       total += num * b;       pieces += num;       if (a - b > 0) {         positives += num;       }     }     sort(ps.begin(), ps.end(), comp);     long long pizzas = (pieces % s == 0) ? (pieces / s) : (pieces / s + 1);     long long extra = pizzas * s - pieces;     long long best = total;     if (positives > 0) {       best = max(best, findBest(ps, positives / s * s) + total);       if (positives % s != 0) {         long long x = max(positives, (positives / s + 1) * s - extra);         best = max(best, findBest(ps, x) + total);       }     }     cout << best << endl;     return 0;   }


#include <bits/stdc++.h>   using ll = long long;   using namespace std;   int n, k, a[110];   int main() {     ios::sync_with_stdio(false);     cin >> n >> k;     for (int i = 0; i < k; ++i) cin >> a[i];     vector<int> s;     for (int i = 1; i <= n; ++i) s.push_back(i);     int curr_leader = 0;     for (int i = 0; i < k; ++i) {       int elim = (curr_leader + a[i]) % n;       cout << s[elim] <<    ;       s.erase(s.begin() + elim);       curr_leader = elim;       n--;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, k;     string s;     cin >> k;     vector<long long> cnt(10, 0);     for (long long i = 0; i < 4; i++) {       cin >> s;       for (long long j = 0; s[j]; j++) {         if (s[j] >=  0  && s[j] <=  9 ) cnt[s[j] -  0 ]++;       }     }     for (long long i = 0; i < 10; i++) {       if (cnt[i] > 2 * k) {         cout <<  NO ;         return;       }     }     cout <<  YES ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1, n, a, b, m;     while (t--) solve();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   const int INF = 0x3f3f3f3f;   int d, n, m;   struct Sta {     int x, p;     Sta() {}     Sta(int x, int p) : x(x), p(p) {}     void read() { scanf( %d%d , &x, &p); }     bool operator<(const Sta& c) const { return x < c.x; }   } p[N];   struct Node {     int Min, Minid;   } node[N << 2];   void pushup(int x) {     node[x].Min = min(node[(x << 1)].Min, node[(x << 1) | 1].Min);     if (node[x].Min == node[(x << 1) | 1].Min)       node[x].Minid = node[(x << 1) | 1].Minid;     if (node[x].Min == node[(x << 1)].Min) node[x].Minid = node[(x << 1)].Minid;   }   void build(int L = 1, int R = m, int x = 1) {     if (L == R) {       node[x].Min = p[L].p;       node[x].Minid = L;       return;     }     int mid = (L + R) >> 1;     build(L, mid, (x << 1));     build(mid + 1, R, (x << 1) | 1);     pushup(x);   }   int Min, Minid;   void getMin(int l, int r, int L = 1, int R = m, int x = 1) {     if (L >= l && R <= r) {       if (Min > node[x].Min) {         Min = node[x].Min;         Minid = node[x].Minid;       }       return;     }     int mid = (L + R) >> 1;     if (l <= mid) getMin(l, r, L, mid, (x << 1));     if (r > mid) getMin(l, r, mid + 1, R, (x << 1) | 1);   }   long long solve() {     int s = 0;     long long ans = 0;     int yu = 0;     while (s < m) {       int v = upper_bound(p + s + 1, p + m + 1, Sta(p[s].x + n, 0)) - p - 1;       if (v == s) return -1;       Min = INF;       getMin(s + 1, v);       if (Min > p[s].p) {         ans += 1LL * (n - yu) * p[s].p;         yu = n;         yu -= p[Minid].x - p[s].x;         s = Minid;       } else {         for (int j = s + 1; j <= Minid; j++) {           if (p[j].p <= p[s].p) {             int dis = p[j].x - p[s].x;             if (yu >= dis) {               yu -= dis;             } else {               ans += 1LL * (dis - yu) * p[s].p;               yu = 0;             }             s = j;             break;           }         }       }     }     return ans;   }   int main() {     scanf( %d%d%d , &d, &n, &m);     p[0] = Sta(0, 0);     for (int i = 1; i <= m; i++) p[i].read();     p[++m] = Sta(d, 0);     sort(p, p + m + 1);     build();     printf( %lld n , solve());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, ans = 0, odd = 0, ev = 0;     cin >> n;     int a[n + 1];     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] & 1)         odd++;       else         ev++;     }     if (n == 1) {       if (odd)         cout <<  Yes ;       else         cout <<  No ;       return 0;     }     if (a[0] % 2 == 0 || a[n - 1] % 2 == 0) {       cout <<  No ;     } else {       if (n & 1) {         if (odd >= 2)           cout <<  Yes ;         else           cout <<  No ;       } else {         cout <<  No ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long n, long long m) { return m == 0 ? n : gcd(m, n % m); }   long long lcm(long long n, long long m) { return (m * n) / gcd(n, m); }   long long dx[] = {1, 0};   long long dy[] = {0, 1};   const long long inf = 1e9 + 10;   const long long INF = 1e18;   long long const N = 2e5 + 10;   long long const M = 5100;   double const PI = acos(-1);   long long const MOD = 998244353;   long long Check(long long n, long long pos) { return n & (1 << pos); }   long long Set(long long n, long long pos) { return n |= (1 << pos); }   long long n, m;   vector<pair<long long, long long> > store;   vector<long long> k;   long long visit[N];   bool check(long long now) {     memset(visit, 0, sizeof(visit));     pair<long long, long long> pt = {now, n};     auto it = upper_bound((store.begin()), (store.end()), pt);     it--;     long long pos = it - store.begin();     vector<pair<long long, long long> > apes;     for (long long i = pos; i >= 0; i--) {       long long day = store[i].first;       long long type = store[i].second;       if (visit[type] == 0) {         apes.push_back({day, type});         visit[type] = 1;       }     }     reverse((apes.begin()), (apes.end()));     long long taka = 0;     long long extra = 0;     long long lastDay = 0;     for (long long i = 0; i < (long long)apes.size(); i++) {       long long day = apes[i].first;       lastDay = day;       long long type = apes[i].second;       if (i == 0)         taka += day;       else         taka += day - apes[i - 1].first;       if (k[type] <= taka)         taka -= k[type];       else {         extra += k[type] - taka;         taka = 0;       }     }     taka += now - lastDay;     for (long long i = 0; i < n; i++) {       if (visit[i] == 0) extra += k[i];     }     extra <<= 1;     if (taka >= extra)       return true;     else       return false;   }   int32_t main() {     cin >> n >> m;     k.resize(n);     for (long long i = 0; i < n; i++) {       cin >> k[i];     }     for (long long i = 0; i < m; i++) {       long long day, type;       cin >> day >> type;       type--;       store.push_back({day, type});     }     sort((store.begin()), (store.end()));     long long res = 1;     long long left = 1, right = 1e11;     while (left <= right) {       long long mid = (left + right) >> 1;       if (check(mid)) {         res = mid;         right = mid - 1;       } else {         left = mid + 1;       }     }     cout << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   bool dbg = 0;   clock_t start_time = clock();   void bad(string mes =  Impossible ) {     cout << mes;     exit(0);   }   void bad(int mes) {     cout << mes;     exit(0);   }   template <typename T>   string bin(T x, int st = 2) {     string ans =   ;     while (x > 0) {       ans += char( 0  + x % st);       x /= st;     }     reverse(ans.begin(), ans.end());     return ans.empty() ?  0  : ans;   }   template <typename T>   void amax(T& x, T y) {     x = max(x, y);   }   template <typename T>   void amin(T& x, T y) {     x = min(x, y);   }   template <typename T>   T input() {     T ans = 0, m = 1;     char c =    ;     while (!((c >=  0  && c <=  9 ) || c ==  - )) {       c = getchar();     }     if (c ==  - ) m = -1, c = getchar();     while (c >=  0  && c <=  9 ) {       ans = ans * 10 + (c -  0 ), c = getchar();     }     return ans * m;   }   template <typename T>   void read(T& a) {     a = input<T>();   }   template <typename T>   void read(T& a, T& b) {     read(a), read(b);   }   template <typename T>   void read(T& a, T& b, T& c) {     read(a, b), read(c);   }   template <typename T>   void read(T& a, T& b, T& c, T& d) {     read(a, b), read(c, d);   }   const int inf = 1e9 + 20;   const short short_inf = 3e4 + 20;   const long double eps = 1e-15;   const int maxn = (int)1e5 + 12, base = 1e9 + 7;   const long long llinf = 2e18 + 5;   template <typename T>   T binpow(T n, T second) {     if (second <= 0) return 1LL;     if (second % 2 == 0) {       T b = binpow(n, second / 2);       return (1LL * b * b) % base;     } else {       return (1LL * binpow(n, second - 1) * n) % base;     }   }   vector<int> g[maxn], gr[maxn];   bool used[maxn];   int u[maxn];   vector<int> cmp, order;   void dfs1(int v) {     used[v] = 1;     for (int to : g[v])       if (!used[to]) dfs1(to);     order.push_back(v);   }   void dfs2(int v) {     used[v] = 1;     cmp.push_back(v);     for (int to : gr[v])       if (!used[to]) dfs2(to);   }   int comp[maxn], sz[maxn];   int main() {     int n, m, h;     ios_base::sync_with_stdio(0);     cin.tie(0);     read(n, m, h);     for (int i = 0; i < n; i++) {       read(u[i]);     }     for (int i = 0; i < m; i++) {       int a, b;       read(a, b);       a--, b--;       if (u[a] + 1 == u[b] || (u[a] == h - 1 && u[b] == 0)) {         g[a].push_back(b);         gr[b].push_back(a);       }       swap(a, b);       if (u[a] + 1 == u[b] || (u[a] == h - 1 && u[b] == 0)) {         g[a].push_back(b);         gr[b].push_back(a);       }     }     memset(used, 0, sizeof(used));     for (int i = 0; i < n; i++)       if (!used[i]) dfs1(i);     memset(used, 0, sizeof(used));     for (int i = n - 1; i >= 0; i--) {       int v = order[i];       if (!used[v]) {         cmp.clear();         dfs2(v);         for (int j : cmp) {           comp[j] = v;           sz[v]++;         }       }     }     for (int i = 0; i < n; i++) {       for (int to : g[i])         if (comp[to] != comp[i]) {           sz[comp[i]] = 0;         }     }     int res = inf, ans;     for (int i = 0; i < n; i++) {       if (sz[i] > 0 && sz[i] < res) {         res = sz[i];         ans = i;       }     }     cout << res <<   n ;     for (int i = 0; i < n; i++)       if (comp[i] == ans) cout << i + 1 <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 100010;   int t[MX];   int main() {     int n;     cin >> n;     for (int i = (1); i <= (n); ++i) {       scanf( %d , &t[i]);     }     for (int i = (1); i <= (n); ++i) {       printf( %d  , t[i] + t[i + 1]);     }   }


#include <bits/stdc++.h>   template <typename T>   bool ckmax(T& a, const T& b) {     return b > a ? a = b, 1 : 0;   }   template <typename T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   const int MV = 1e5 + 10;   const int MM = 1e5 + 10;   const int MG = 450;   const int INF = 0x3f3f3f3f;   struct DSU {     int p[MM], t[MM];     char r[MM];     void init(int M) {       memset(p, -1, M * sizeof *p);       memset(r, 0, M * sizeof *r);       std::iota(t, t + M, 0);     }     int find(int v) { return ~p[v] ? p[v] = find(p[v]) : v; }     bool merge(int a, int b) {       a = find(a), b = find(b);       if (a == b) return 0;       t[a] = t[b];       if (r[a] < r[b]) std::swap(a, b);       r[a] += r[a] == r[b];       p[a] = b;     }   } dsu;   int M, v[MM], maxv[MM], dp[MM][2], ub[MV];   bool ok[MM];   int solve() {     scanf( %d , &M);     for (int i = 0; i < M; ++i) {       scanf( %d , v + i);       assert(v[i] > 0);     }     for (int i = 0, j = 0; i < MV; ++i) {       while (j < M && v[j] == i) ++j;       ub[i] = j;     }     memset(maxv, 0x3f, sizeof maxv);     std::fill(ok, ok + M, 1);     int f = 0;     bool c = 0;     for (int i = 0; f == i; ++i, c ^= 1) {       dsu.init(M + 1);       for (int j = M - 1; j >= 0; --j) {         if (ok[j] &= (maxv[j] > 0)) ckmax(f, i + 1);         dp[j][c] = v[j] * 2 - maxv[j];         ckmax(dp[j][c], 0);         ckmin(dp[j][c], v[j] - 1);         if (i) {           ckmax(dp[j][c], dp[j][!c]);           int x = ub[dp[j][!c]], y = ub[dp[j][c]];           for (int g = dsu.find(x), t; (t = dsu.t[g]) < y;) {             maxv[t] = v[j];             dsu.merge(g, t + 1);             g = dsu.find(g);           }         }       }       memset(maxv, 0, sizeof maxv);     }     return f;   }   int main() {     int N, f = 0;     scanf( %d , &N);     for (int i = 0; i < N; ++i) f ^= solve();     if (f)       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mx = 2e5 + 10;   long long int x[mx], y[mx];   int ord[mx];   int hs[mx], h = 0;   vector<int> g[mx];   int ans[mx];   int cross(int a, int o, int b) {     long long int l = (x[o] - x[a]) * (y[o] - y[b]) * y[a] * x[b];     long long int r = (y[o] - y[a]) * (x[o] - x[b]) * x[a] * y[b];     if (l == r) return 0;     if (l < r) return -1;     return 1;   }   bool cmp1(int i, int j) {     if (x[i] != x[j]) return x[i] < x[j];     if (y[i] != y[j]) return y[i] < y[j];     return i < j;   }   bool cmp(int i, int j) {     int c = cross(i, ord[0], j);     if (c == 0) {       if (x[j] != x[i]) return x[j] < x[i];       return i < j;     }     return c > 0;   }   inline bool ccw(int a, int o, int b) { return (-cross(a, o, b)) >= 0; }   int main() {     int n, xi, yi;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d , &xi, &yi);       x[i] = xi, y[i] = yi, ord[i] = i;     }     sort(ord, ord + n, cmp1);     int c = 0;     int il = 0, id = 0;     for (int i = 0; i < n;) {       int ii = ord[i];       int xi = x[ii], yi = y[ii];       while (i < n && x[ord[i]] == xi && y[ord[i]] == yi) {         g[ii].push_back(ord[i]);         i++;       }       int j = ord[il];       if (xi > x[j] || (xi == x[j] && yi > y[j])) il = c;       j = ord[id];       if (yi > y[j] || (yi == y[j] && xi > x[j])) id = c;       ord[c++] = ii;     }     int dwn = ord[id];     swap(ord[0], ord[il]);     sort(ord + 1, ord + c, cmp);     for (int i = 0; i < c; i++) {       while (h >= 2 && !ccw(hs[h - 2], hs[h - 1], ord[i])) h--;       hs[h++] = ord[i];       if (ord[i] == dwn) break;     }     c = 0;     for (int i = 0; i < h; i++) {       int u = hs[i];       for (int j = 0; j < int(g[u].size()); j++) {         ans[c++] = 1 + g[u][j];       }     }     sort(ans, ans + c);     printf( %d , ans[0]);     for (int i = 1; i < c; i++) printf(  %d , ans[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int mod = 1e9 + 7;     string S;     cin >> S;     bool flag = false;     long ans = 0;     long plus = 0;     for (int i = 0; i < S.size(); i++) {       if (S[i] ==  a ) {         if (flag) {           ans = (2 * ans + 1) % mod;         } else {           ans = ans + 1 + plus;           ans = ans % mod;         }         flag = false;       } else if (S[i] ==  b ) {         plus = ans;         flag = true;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int temp;     int a[6] = {0};     int i = 0;     while (n > 0) {       a[i] = n % 2;       n = n / 2;       i++;     }     temp = a[0];     a[0] = a[4];     a[4] = temp;     temp = a[2];     a[2] = a[3];     a[3] = temp;     int count = 1;     int sum = 0;     for (int i = 0; i < 6; i++) {       sum = sum + a[i] * count;       count = count * 2;     }     cout << sum;   }