#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     double a[20] = {0};     int i = 0;     for (i = 0; i < 16; i++) cin >> a[i];     double x1 = a[0], x2 = a[2], x3 = a[4], x4 = a[6];     double y1 = a[1], y2 = a[3], y3 = a[5], y4 = a[7];     double maxx = max(x1, (max(x2, max(x3, x4))));     double minx = min(x1, (min(x2, min(x3, x4))));     double maxy = max(y1, (max(y2, max(y3, y4))));     double miny = min(y1, (min(y2, min(y3, y4))));     double centre2x = (a[8] + a[12]) / 2.00;     double centre2y = (a[9] + a[13]) / 2.00;     if (minx <= centre2x && centre2x <= maxx && miny <= centre2y &&         centre2y <= maxy) {       cout <<  YES  <<   n ;       return 0;     }     if (minx <= a[8] && a[8] <= maxx && miny <= a[9] && a[9] <= maxy) {       cout <<  YES  <<   n ;       return 0;     }     if (minx <= a[10] && a[10] <= maxx && miny <= a[11] && a[11] <= maxy) {       cout <<  YES  <<   n ;       return 0;     }     if (minx <= a[12] && a[12] <= maxx && miny <= a[13] && a[13] <= maxy) {       cout <<  YES  <<   n ;       return 0;     }     if (minx <= a[14] && a[14] <= maxx && miny <= a[15] && a[15] <= maxy) {       cout <<  YES  <<   n ;       return 0;     }     for (i = 0; i < 16; i += 2) {       double x = (a[i] + a[i + 1]) / sqrt(2);       double y = (a[i] - a[i + 1]) / sqrt(2);       a[i] = x;       a[i + 1] = y;     }     x1 = a[0 + 8], x2 = a[2 + 8], x3 = a[4 + 8], x4 = a[6 + 8];     y1 = a[1 + 8], y2 = a[3 + 8], y3 = a[5 + 8], y4 = a[7 + 8];     maxx = max(x1, (max(x2, max(x3, x4))));     minx = min(x1, (min(x2, min(x3, x4))));     maxy = max(y1, (max(y2, max(y3, y4))));     miny = min(y1, (min(y2, min(y3, y4))));     centre2x = (a[8 - 8] + a[12 - 8]) / 2.00;     centre2y = (a[9 - 8] + a[13 - 8]) / 2.00;     if (minx <= centre2x && centre2x <= maxx && miny <= centre2y &&         centre2y <= maxy) {       cout <<  YES  <<   n ;       return 0;     }     if (minx <= a[8 - 8] && a[8 - 8] <= maxx && miny <= a[9 - 8] &&         a[9 - 8] <= maxy) {       cout <<  YES  <<   n ;       return 0;     }     if (minx <= a[10 - 8] && a[10 - 8] <= maxx && miny <= a[11 - 8] &&         a[11 - 8] <= maxy) {       cout <<  YES  <<   n ;       return 0;     }     if (minx <= a[12 - 8] && a[12 - 8] <= maxx && miny <= a[13 - 8] &&         a[13 - 8] <= maxy) {       cout <<  YES  <<   n ;       return 0;     }     if (minx <= a[14 - 8] && a[14 - 8] <= maxx && miny <= a[15 - 8] &&         a[15 - 8] <= maxy) {       cout <<  YES  <<   n ;       return 0;     }     cout <<  NO  <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int tam = 100010;   const int MOD = 1000000007;   const int MOD1 = 998244353;   const double EPS = 1e-9;   const double PI = acos(-1);   const int sq = 500;   int ar[tam];   int res[tam];   bool comp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {     if (a.first.first / sq == b.first.first / sq)       return a.first.second < b.first.second;     return a.first.first / sq < b.first.first / sq;   }   struct trie {     int maxo, mino, nam;     trie* ce;     trie* un;     trie() {       ce = un = NULL;       maxo = 0;       mino = MOD;     }   };   typedef trie* ptrie;   void del(ptrie t) {     if (t) {       del(t->ce);       del(t->un);       delete t;     }   }   void add(string& second, int ind, int num, ptrie t, int nam) {     if (ind < second.size()) {       ptrie go;       if (second[ind] ==  0 ) {         if (t->ce == NULL) t->ce = new trie();         go = t->ce;       } else {         if (t->un == NULL) t->un = new trie();         go = t->un;       }       add(second, ind + 1, num, go, nam);     } else       t->nam = nam;     t->maxo = max(max(t->ce ? t->ce->maxo : 0, t->un ? t->un->maxo : 0), num);     t->mino = min(min(t->ce ? t->ce->mino : MOD, t->un ? t->un->mino : MOD), num);   }   int ask1(string& second, int ind, int num, ptrie t) {     if (ind == second.size()) return t->nam;     ptrie go;     if (second[ind] ==  0 ) {       if (t->un != NULL && t->un->maxo > num)         go = t->un;       else if (t->ce != NULL && t->ce->maxo > num)         go = t->ce;       else         return -1;     } else {       if (t->ce != NULL && t->ce->maxo > num)         go = t->ce;       else if (t->un != NULL && t->un->maxo > num)         go = t->un;       else         return -1;     }     return ask1(second, ind + 1, num, go);   }   int ask2(string& second, int ind, int num, ptrie t) {     if (ind == second.size()) return t->nam;     ptrie go;     if (second[ind] ==  0 ) {       if (t->un != NULL && t->un->mino < num)         go = t->un;       else if (t->ce != NULL && t->ce->mino < num)         go = t->ce;       else         return -1;     } else {       if (t->ce != NULL && t->ce->mino < num)         go = t->ce;       else if (t->un != NULL && t->un->mino < num)         go = t->un;       else         return -1;     }     return ask2(second, ind + 1, num, go);   }   string tost(int n) {     string res =   ;     while (n > 0) {       res += (n % 2) +  0 ;       n /= 2;     }     while (res.size() < 22) res +=  0 ;     reverse((res).begin(), (res).end());     return res;   }   int xo[1000010];   int ros[tam];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     for (int i = 1; i < 1000010; i++) xo[i] = xo[i - 1] ^ i;     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> ar[i];     int a, b;     vector<pair<pair<int, int>, int>> que;     ptrie t1 = 0, t2 = 0;     int ras;     string s1, s2;     int x, y, x1, y1;     for (int i = 0; i < m; i++) {       cin >> a >> b;       a--;       b--;       if (b - a < sq) {         del(t1);         del(t2);         t1 = new trie();         t2 = new trie();         ras = 0;         for (int i = a; i < b + 1; i++) {           x = ar[i] - 1;           y = ar[i];           s1 = tost(xo[x]);           s2 = tost(xo[y]);           add(s1, 0, x, t2, xo[x]);           add(s2, 0, y, t1, xo[y]);           x1 = ask1(s1, 0, x, t1);           y1 = ask2(s2, 0, y, t2);           ras = max(ras,                     max(xo[x] ^ ask1(s1, 0, x, t1), xo[y] ^ ask2(s2, 0, y, t2)));         }         res[i] = ras;       } else         que.push_back({{a, b}, i});     }     sort((que).begin(), (que).end(), comp);     int level = 0;     int nu = sq;     while (nu <= n) {       for (int i = nu - 1; i > nu - sq - 1; i--) {         ros[i] = ros[i + 1];         for (int j = i; j < nu; j++)           ros[i] = max(ros[i], ar[i] > ar[j] ? xo[ar[i]] ^ xo[ar[j] - 1]                                              : xo[ar[i] - 1] ^ xo[ar[j]]);       }       nu += sq;     }     int divo = -1, lasto = -1, rus;     for (int i = 0; i < que.size(); i++) {       if (que[i].first.first / sq != divo) {         divo = que[i].first.first / sq;         lasto = que[i].first.first / sq * sq + sq;         del(t1);         del(t2);         t1 = new trie();         t2 = new trie();         ras = 0;       }       while (que[i].first.second >= lasto) {         x = ar[lasto] - 1;         y = ar[lasto];         s1 = tost(xo[x]);         s2 = tost(xo[y]);         add(s1, 0, x, t2, xo[x]);         add(s2, 0, y, t1, xo[y]);         ras =             max(ras, max(xo[x] ^ ask1(s1, 0, x, t1), xo[y] ^ ask2(s2, 0, y, t2)));         lasto++;       }       rus = ros[que[i].first.first];       for (int j = que[i].first.first; j < que[i].first.first / sq * sq + sq;            j++) {         x = ar[j] - 1;         y = ar[j];         s1 = tost(xo[x]);         s2 = tost(xo[y]);         rus =             max(rus, max(xo[x] ^ ask1(s1, 0, x, t1), xo[y] ^ ask2(s2, 0, y, t2)));       }       res[que[i].second] = max(rus, ras);     }     for (int i = 0; i < m; i++) cout << res[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[100010];   map<string, int> mp;   int tot, cnt[100010];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     char f[110];     string s;     for (int i = 1; i <= m; i++) {       scanf( %s , f);       s = f;       if (!mp[s]) mp[s] = ++tot;       ++cnt[mp[s]];     }     sort(cnt + 1, cnt + tot + 1);     int minans = 0, maxans = 0;     for (int i = tot, j = 1; i >= 1; i--, j++) {       minans += cnt[i] * a[j];       maxans += cnt[i] * a[n - j + 1];     }     printf( %d %d n , minans, maxans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   const int C = 26;   void add(int &x, int y) {     x += y;     while (x >= MOD) x -= MOD;     while (x < 0) x += MOD;   }   int fix(int x) {     while (x >= MOD) x -= MOD;     while (x < 0) x += MOD;     return x;   }   int pw(int a, int b) {     int ret = 1;     while (b) {       if (b & 1) ret = 1ll * ret * a % MOD;       b >>= 1;       a = 1ll * a * a % MOD;     }     return ret;   }   int inv(int a) { return pw(a, MOD - 2); }   int mul(int a, int b) { return (long long)a * b % MOD; }   const int MAXN = 2e5 + 10;   const int LOG = 20;   int n, q, p[MAXN];   int tab[MAXN][LOG];   int get(int l, int r) {     int ans = 1;     for (int i = LOG - 1; ~i; --i)       if (l + (1 << i) <= r) ans = mul(ans, tab[l][i]), l += 1 << i;     return ans;   }   int st[MAXN << 2], lz[MAXN << 2];   int pr[MAXN];   void plant(int v, int b, int e) {     if (e - b == 1) {       st[v] = pr[b];       return;     }     int m = (b + e) >> 1;     plant(v << 1, b, m);     plant(v << 1 ^ 1, m, e);     st[v] = fix(st[v << 1] + st[v << 1 ^ 1]);   }   void weed(int v) {     for (int u : {v << 1, v << 1 ^ 1}) {       st[u] = mul(st[u], lz[v]);       lz[u] = mul(lz[u], lz[v]);     }     lz[v] = 1;   }   void water(int v, int b, int e, int l, int r, int x) {     if (l >= r) return;     if (b == l && e == r) {       st[v] = mul(st[v], x);       lz[v] = mul(lz[v], x);       return;     }     weed(v);     int m = (b + e) >> 1;     water(v << 1, b, m, l, min(r, m), x);     water(v << 1 ^ 1, m, e, max(l, m), r, x);     st[v] = fix(st[v << 1] + st[v << 1 ^ 1]);   }   int smoke(int v, int b, int e, int l, int r) {     if (l >= r) return 0;     if (b == l && e == r) return st[v];     weed(v);     int m = (b + e) >> 1;     return fix(smoke(v << 1, b, m, l, min(r, m)) +                smoke(v << 1 ^ 1, m, e, max(l, m), r));   }   void solve() {     cin >> n >> q;     for (int i = 0; i < n; i++) cin >> p[i];     for (int i = 0; i < n; i++) p[i] = mul(p[i], inv(100));     for (int i = 0; i < n; i++) tab[i][0] = p[i];     for (int j = 1; j < LOG; j++)       for (int i = 0; i < n; i++)         if (i + (1 << j) <= n)           tab[i][j] = mul(tab[i][j - 1], tab[i + (1 << (j - 1))][j - 1]);         else           tab[i][j] = tab[i][j - 1];     fill(lz, lz + (MAXN << 2), 1);     pr[n - 1] = inv(p[n - 1]);     for (int i = n - 2; ~i; --i) pr[i] = mul(pr[i + 1], inv(p[i]));     plant(1, 0, n);     set<int> pts;     pts.insert(0);     pts.insert(n);     while (q--) {       int u;       cin >> u;       --u;       if (pts.count(u)) {         auto prv = --pts.lower_bound(u);         water(1, 0, n, *prv, u, smoke(1, 0, n, u, u + 1));         pts.erase(u);       } else {         auto prv = --pts.lower_bound(u);         water(1, 0, n, *prv, u, inv(smoke(1, 0, n, u, u + 1)));         pts.insert(u);       }       cout << st[1] <<   n ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int te = 1;     for (int w = 1; w <= te; w++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   void solve() {     int n, m, k, x, y;     cin >> n >> m >> k;     for (int i = 0; i < 2 * k; i++) cin >> x >> y;     string ans =   ;     ans += (string(n - 1,  U ) + string(m - 1,  L ));     for (int i = 0; i < n; i++) {       if (i & 1)         ans += string(m - 1,  L );       else         ans += string(m - 1,  R );       if (i != n - 1) ans +=  D ;     }     cout << ans.size() <<   n ;     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   int w[505];   int book[505];   int v[1005];   int used[505];   int main(void) {     int n, m;     int k;     int r = 0;     scanf(  %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       used[i] = 0;       scanf(  %d , &w[i]);     }     for (int i = 1; i <= m; i++) {       scanf(  %d , &v[i]);     }     k = 1;     for (int i = 1; i <= m; i++) {       if (!used[v[i]]) {         used[v[i]] = 1;         book[k++] = v[i];       }     }     for (int i = 1; i <= m; i++) {       for (int j = 1; j < k; j++) {         if (book[j] == v[i]) {           for (int p = j - 1; p >= 1; p--) {             r += w[book[p]];             book[p + 1] = book[p];           }           book[1] = v[i];           break;         }       }     }     printf( %d n , r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char b[1000050], a[1000050];   int n, m, p, P;   bool c[2050], ans[2050], Ans;   bool Calc(int x, int y, int z, int o, int u) {     for (; o >= z; o--) {       bool Flag = false;       while (y >= x) {         bool flag = true;         for (int j = y, k = o; j <= n && k <= m; j += p, k += u)           if (a[j] != b[k] || ((j + p > n) ^ (k + u > m))) {             flag = false;             break;           }         if (flag) {           c[y] = 1;           y--;           Flag = true;           break;         }         y--;       }       if (!Flag) return false;     }     return true;   }   void Put() {     for (int i = 1; i <= P; i++) putchar(ans[i] ?  1  :  0 );     puts(  );   }   void PUUUUUT() {     if (Ans)       for (int i = 1; i <= p; i++)         if (ans[i] && !c[i])           break;         else if (!ans[i] && c[i])           return;     for (int i = 1; i <= p; i++) ans[i] = c[i];     Ans = true;   }   void Solve() {     int k = n / p, l = n % p;     for (int i = 0; i <= l; i++)       if ((m - i) % k == 0 && (m - i) / k - i <= p - l) {         if (Calc(1, l, 1, i, (m - i) / k) &&             Calc(l + 1, p, i + 1, (m - i) / k, (m - i) / k))           PUUUUUT();         memset(c, 0, sizeof(c));       }     return;   }   int main() {     gets(a + 1);     gets(b + 1);     scanf( %d , &P);     n = strlen(a + 1);     m = strlen(b + 1);     p = min(P, n);     Solve();     if (!Ans)       puts( 0 );     else       Put();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, val = 0;     cin >> n;     int k;     cin >> k;     for (int i = 1; i <= n; i++) {       if (k % i == 0 && k / i <= n) val++;     }     cout << val;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int MAX_SIZE = 10;   int n;   unsigned long long adj[200010], k;   struct Matrix {     unsigned long long a[MAX_SIZE][MAX_SIZE];     Matrix() {       for (int i = 0; i < MAX_SIZE; i++)         for (int j = 0; j < MAX_SIZE; j++) a[i][j] = 0;     }     Matrix mul(Matrix m) {       Matrix res = Matrix();       for (int i = 0; i < MAX_SIZE; i++) {         for (int j = 0; j < MAX_SIZE; j++) {           for (int z = 0; z < MAX_SIZE; z++) {             if (a[i][z] != 0 && m.a[z][j] != 0 &&                 (a[i][z] >= k || m.a[z][j] >= k || (a[i][z] > k / m.a[z][j]) ||                  res.a[i][j] >= (k - a[i][z] * m.a[z][j])))               res.a[i][j] = k;             else               res.a[i][j] += a[i][z] * m.a[z][j];             res.a[i][j] = min(res.a[i][j], k);             if (res.a[i][j] == k) break;           }         }       }       return res;     }     void toIndentity() {       for (int i = 0; i < MAX_SIZE; i++)         for (int j = 0; j < MAX_SIZE; j++) a[i][j] = i == j ? 1 : 0;     }     void toRightMatrix() {       for (int i = 0; i < MAX_SIZE; i++)         for (int j = 0; j < MAX_SIZE; j++) a[i][j] = i <= j ? 1 : 0;     }   };   struct Vector {     unsigned long long a[MAX_SIZE];     int size;     Vector(int _size = MAX_SIZE) {       size = _size;       for (int i = 0; i < MAX_SIZE; i++) a[i] = 0;     }     Vector mul(Matrix m) {       Vector res = Vector(size);       for (int i = 0; i < size; i++) {         for (int j = 0; j < size; j++) {           if (m.a[j][i] != 0 && a[j] != 0 &&               (m.a[j][i] >= k || a[j] >= k || m.a[j][i] > k / a[j] ||                res.a[i] >= (k - m.a[j][i] * a[j])))             res.a[i] = k;           else             res.a[i] += m.a[j][i] * a[j];           res.a[i] = min(res.a[i], k);           if (res.a[i] == k) break;         }       }       return res;     }     bool hasSolution() {       int res = false;       for (int i = 0; i < size; i++)         if (a[i] >= k) {           res = true;           break;         }       return res;     }   };   Matrix pow(Matrix m, unsigned long long p) {     Matrix res = Matrix();     res.toIndentity();     while (p > 0) {       if (p % 2 == 0) {         m = m.mul(m);         p /= 2;       } else {         res = res.mul(m);         p--;       }     }     return res;   }   bool solve(Vector v, unsigned long long p) {     Matrix m = Matrix();     m.toRightMatrix();     m = pow(m, p);     return v.mul(m).hasSolution();   }   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> adj[i];     unsigned long long res = 0;     for (int i = 0; i < n; i++)       if (adj[i] >= k) {         cout << res;         return 0;       }     int j = 0;     for (int i = 0; i < n; i++)       if (adj[i] != 0) {         j = i;         break;       }     for (int i = 0; i < n - j; i++) adj[i] = adj[i + j];     n -= j;     if (n > MAX_SIZE) {       while (true) {         res++;         for (int i = 1; i < n; i++) {           adj[i] += adj[i - 1];           if (adj[i] >= k) {             cout << res;             return 0;           }         }       }     } else {       Vector v = Vector(n);       for (int i = 0; i < n; i++) v.a[i] = adj[i];       unsigned long long l = 1, r = k, m;       while (l + 1 < r) {         m = (l + r) / 2;         if (solve(v, m))           r = m;         else           l = m + 1;       }       res = (l < r && solve(v, l)) ? l : r;       cout << res;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const int INF = 0x3f3f3f3f;   inline void cmin(int &x, int y) {     if (y < x) x = y;   }   inline void cmax(int &x, int y) {     if (y > x) x = y;   }   bool isvowel(char a) {     if (a ==  a  || a ==  e  || a ==  i  || a ==  o  || a ==  u ) return true;     return false;   }   int main() {     string s, t;     cin >> s >> t;     if (s.size() != t.size()) return !printf( No );     for (int i = 0; i < s.size(); i++) {       if (isvowel(s[i]) == isvowel(t[i]))         continue;       else         return !printf( No );     }     printf( Yes );     return 0;   }


#include <bits/stdc++.h>   using namespace ::std;   const long long maxn = 1e5 + 500;   const long long mod = 1e9 + 7;   const long long inf = 1e9 + 500;   const long long rad = 330;   long long a[maxn];   long long t[maxn];   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     if (a.first / rad == b.first / rad) {       return (a.second < b.second);     }     return (a.first < b.first);   }   long long ml[maxn];   pair<long long, long long> sque[maxn];   map<pair<long long, long long>, long long> anss;   long long lastid[maxn];   long long nextid[maxn];   long long id[maxn];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     for (long long i = 1; i <= n; i++) {       cin >> t[i];     }     for (long long i = 1; i <= n; i++) {       cin >> a[i];       if (t[i] == 2) {         a[i] *= -1;       }     }     for (long long i = 1; i <= n; i++) {       a[i] += a[i - 1];     }     vector<long long> vec;     for (long long i = 0; i <= n; i++) {       vec.push_back(a[i]);     }     {       sort(vec.begin(), vec.end());       auto it = unique(vec.begin(), vec.end());       vec.resize(distance(vec.begin(), it));     }     vector<long long>::iterator it;     for (long long i = 0; i <= n; i++) {       id[i] = lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin();       it = lower_bound(vec.begin(), vec.end(), a[i] + k);       if (it != vec.end() && (*it) == a[i] + k) {         nextid[i] = it - vec.begin();       } else {         nextid[i] = maxn - 1;       }       it = lower_bound(vec.begin(), vec.end(), a[i] - k);       if (it != vec.end() && (*it) == a[i] - k) {         lastid[i] = it - vec.begin();       } else {         lastid[i] = maxn - 1;       }     }     long long q;     cin >> q;     vector<pair<long long, long long> > que;     for (long long i = 0; i < q; i++) {       long long l, r;       cin >> l >> r;       l--;       sque[i] = make_pair(l, r);       que.push_back(make_pair(l, r));     }     sort(que.begin(), que.end(), cmp);     long long res = 0;     long long l = 0;     long long r = 0;     for (auto b : que) {       long long L = b.first;       long long R = b.second;       while (r <= R) {         res += ml[lastid[r]];         ml[id[r]]++;         r++;       }       while (L < l) {         l--;         res += ml[nextid[l]];         ml[id[l]]++;       }       while (R + 1 < r) {         r--;         ml[id[r]]--;         res -= ml[lastid[r]];       }       while (l < L) {         ml[id[l]]--;         res -= ml[nextid[l]];         l++;       }       anss[make_pair(L, R)] = res;     }     for (long long i = 0; i < q; i++) {       cout << anss[sque[i]] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int N;   int Move[100005], cnt, P[100005];   vector<int> G[100005];   int TT[100005], Next[100005];   int DP[100005], Stack[100005], top;   void Read() {     scanf( %d , &N);     for (int i = 1; i < N; i++) {       int father;       scanf( %d , &father);       ++father;       G[father].push_back(i + 1);       TT[i + 1] = father;     }   }   void DFS(int node) {     for (int i = 0; i < G[node].size(); i++) {       int neighb = G[node][i];       DFS(neighb);       DP[node] = max(DP[node], DP[neighb] + 1);     }   }   void precalcPath() {     int node = 1;     while (G[node].size() != 0) {       Stack[++top] = node;       for (int i = 0; i < G[node].size(); i++) {         int neighb = G[node][i];         if (DP[neighb] == DP[node] - 1) {           swap(G[node][i], G[node][G[node].size() - 1]);           G[node].pop_back();           node = neighb;           break;         }       }     }     Stack[++top] = node;   }   void Solve(int node, int next) {     int last = next;     for (int i = 0; i < G[node].size(); i++) {       int neighb = G[node][i];       TT[last] = neighb;       Move[++cnt] = last;       last = neighb;     }     for (int i = G[node].size() - 1; i >= 1; i--)       Solve(G[node][i], G[node][i - 1]);     if (G[node].size() > 0) Solve(G[node][0], next);   }   void printSol() {     int node = 1;     for (int i = 1; i <= N; i++) Next[TT[i]] = i;     for (int i = 1; i <= N; i++) {       printf( %d  , node - 1);       node = Next[node];     }     printf(  n%d n , cnt);     for (int i = cnt; i >= 1; i--) printf( %d  , Move[i] - 1);     printf(  n );   }   int main() {     Read();     DFS(1);     precalcPath();     for (int i = 1; i < top; i++) Solve(Stack[i], Stack[i + 1]);     printSol();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   const int mod = 1e9 + 7;   struct point {     int x, y;     inline friend long long operator*(point a, point b) {       return 1ll * a.x * b.y - 1ll * a.y * b.x;     }   } p[N];   long long sx[N], sy[N], s[N], ans, sum, area;   int n;   inline long long getS(int l, int r) { return s[r] - s[l] + (p[r] * p[l]); }   inline int chk(int l, int r) {     long long L = getS(l, r), R = getS(r, l + n);     if (L < R) return 1;     if (L == R && r <= n) return 1;     return 0;   }   inline long long cro(int k, int l, int r) {     long long xy = (sx[r] - sx[l - 1]) * p[k].y;     long long yx = (sy[r] - sy[l - 1]) * p[k].x;     return (xy % mod - yx % mod + mod) % mod;   }   int main() {     scanf( %d , &n);     for (int i = (1); i <= (n); i++) scanf( %d%d , &p[i].x, &p[i].y);     for (int i = (1); i <= (n / 2); i++) swap(p[i], p[n + 1 - i]);     for (int i = (1); i <= (n); i++) p[i + n] = p[i];     p[0] = p[n];     for (int i = (0); i < (n); i++) area = (area + (p[i] * p[i + 1])) % mod;     sx[0] = p[0].x, sy[0] = p[0].y;     for (int i = (1); i <= (2 * n); i++) {       sx[i] = (sx[i - 1] + p[i].x) % mod;       sy[i] = (sy[i - 1] + p[i].y) % mod;       s[i] = s[i - 1] + (p[i - 1] * p[i]);     }     int r = 0;     for (int l = (1); l <= (n); l++) {       if (r <= l + 1) sum = 0, r = l + 1;       while (chk(l, r + 1)) sum = (sum + s[++r] - s[l] + mod) % mod;       ans = (ans + sum + cro(l, l + 2, r)) % mod;       sum = (sum - (p[l] * p[l + 1]) % mod * (r - l - 1) % mod -              (p[l + 1] * p[l + 2]) % mod + 2ll * mod) %             mod;     }     ans = (1ll * n * (n - 3) / 2) % mod * area - 2 * ans;     ans = (ans % mod + mod) % mod;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int r, p, s;       cin >> r >> p >> s;       string q;       cin >> q;       int lastn = ceil(n / 2.0);       int R = 0, P = 0, S = 0;       for (long long i = 0; i < q.size(); i++) {         if (q[i] ==  R ) {           R++;         } else if (q[i] ==  S ) {           S++;         } else {           P++;         }       }       int total = min(R, p) + min(P, s) + min(S, r);       if (total < lastn) {         cout <<  NO  << endl;         ;         continue;       } else {         char ans[q.size()];         memset(ans,  0 , sizeof(ans));         for (int i = 0; i < q.size(); i++) {           if (q[i] ==  S ) {             if (r > 0) {               ans[i] =  R ;               r--;             }           } else if (q[i] ==  R ) {             if (p > 0) {               ans[i] =  P ;               p--;             }           } else {             if (s > 0) {               ans[i] =  S ;               s--;             }           }         }         for (int i = 0; i < q.size(); i++) {           if (ans[i] ==  0 ) {             if (r > 0) {               ans[i] =  R ;               r--;             } else if (p > 0) {               ans[i] =  P ;               p--;             } else if (s > 0) {               ans[i] =  S ;               s--;             }           }         }         cout <<  YES  << endl;         ;         for (int i = 0; i < q.size(); i++) {           cout << ans[i];         }         cout << endl;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }


#include <bits/stdc++.h>   int main() {     char s[20];     bool jizz = false;     int value1[61] = {0}, value2[61] = {0}, k, max = 0;     int m, n, a, b;     scanf( %s , &s);     for (m = 0; m < strlen(s); m++) {       if (s[m] ==  : ) break;       for (a = 2; a < 61; a++) {         if (s[m] <=  Z  && s[m] >=  A )           k = s[m] -  A  + 10;         else           k = s[m] -  0 ;         if (k > max) max = k;         value1[a] = value1[a] * a + k;       }     }     for (n = m + 1; n < strlen(s); n++) {       for (a = 2; a < 61; a++) {         if (s[n] <=  Z  && s[n] >=  A )           k = s[n] -  A  + 10;         else           k = s[n] -  0 ;         if (k > max) max = k;         value2[a] = value2[a] * a + k;       }     }     if (value1[60] <= 23 && value2[60] <= 59)       printf( -1 n );     else {       for (a = max + 1; a < 60; a++) {         if (value1[a] <= 23 && value2[a] <= 59) {           jizz = true;           break;         }       }       if (jizz == false) printf( 0 n );       for (a = max + 1; a < 60; a++) {         if (value1[a] <= 23 && value2[a] <= 59) {           printf( %d  , a);         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   char s1[6], s2[6], ch;   int cnt = 0, ans, ok1, ok2;   bool func1(int sumA, int sumB, char s[]) {     int dif = sumB - sumA;     for (int i = 0; i < 3; i++) {       bool fl = 0;       ch = s[i];       while (ch <  9  && dif > 0) ch++, dif--, fl = 1;       if (fl) cnt++;     }     return dif == 0;   }   bool func2(int sumA, int sumB, char s[]) {     int dif = sumB - sumA;     for (int i = 2; i >= 0; i--) {       bool fl = 0;       ch = s[i];       while (ch >  0  && dif > 0) ch--, dif--, fl = 1;       if (fl) cnt++;     }     return dif == 0;   }   int main() {     while (scanf( %3s%3s , s1, s2) == 2) {       cerr << s1 <<     << s2 <<   n ;       int sum = 0, sum1 = 0, sum2 = 0, ans = 9;       for (int i = 0; i < 3; i++) sum1 += s1[i] -  0 ;       for (int i = 0; i < 3; i++) sum2 += s2[i] -  0 ;       sort(s1, s1 + 3), sort(s2, s2 + 3);       sum = max(sum1, sum2);       while (sum) {         cnt = ok1 = ok2 = 0;         if (sum1 <= sum)           ok1 = func1(sum1, sum, s1);         else           ok1 = func2(sum, sum1, s1);         if (sum2 <= sum)           ok2 = func1(sum2, sum, s2);         else           ok2 = func2(sum, sum2, s2);         if (ok1 && ok2) {           cerr <<  cnt=   << cnt <<     << sum <<   n ;           ans = min(ans, cnt);         }         sum--;       }       if (ans == 9) ans = 0;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   const int MAX_LEN = 1010;   using namespace std;   template <typename U, typename V>   string to_string(pair<U, V>);   string to_string(const string& e_) { return     + e_ +    ; }   string to_string(char e_) { return      + string(1, e_) +     ; }   string to_string(bool e_) { return e_ ?  true  :  false ; }   template <typename T>   string to_string(T e_) {     string s_ =  [  ;     for (const auto& x_ : e_) s_ += to_string(x_) +    ;     return s_ +  ] ;   }   template <typename U, typename V>   string to_string(pair<U, V> e_) {     return  (  + to_string(e_.first) +  ,   + to_string(e_.second) +  ) ;   }   void dbg_str() { ; }   template <typename U, typename... V>   void dbg_str(U u, V... v) {     ;     dbg_str(v...);   }   long long int n, m;   long long int ans, mn;   long long int lx, hx, wx;   struct rd {     long long int l;     long long int w;     long long int h;   };   vector<rd> rooms;   vector<rd> rolls;   int main() {     scanf( %lld , &n);     for (int i = 0; i < n; i++) {       scanf( %lld %lld %lld , &lx, &wx, &hx);       rooms.push_back({lx, wx, hx});     }     scanf( %lld , &m);     for (int i = 0; i < m; i++) {       scanf( %lld %lld %lld , &lx, &wx, &hx);       rolls.push_back({lx, wx, hx});     }     ans = 0;     for (int i = 0; i < n; i++) {       mn = 1e14;       for (int j = 0; j < m; j++) {         long long int totw = (rolls[j].l / rooms[i].h) * rolls[j].w;         if (!totw) continue;         long long int nr =             (long long int)ceil(((double)2 * (rooms[i].l + rooms[i].w)) / totw);         mn = min(mn, nr * rolls[j].h);       }       ans += mn;     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long int M = 998244353, q, n, p[300001], d[300001], fans, products[300001],                 invproducts[300001];   long long int power(long long int x, long long int n) {     if (n == 0)       return (long long)1;     else if (n % 2 == 0)       return power((x * x) % M, n / 2);     else       return (x * power((x * x) % M, (n - 1) / 2)) % M;   }   long long int cans(long long int p, long long int q) {     return ((p * power(q, M - 2)) % M + M) % M;   }   void build() {     products[0] = invproducts[0] = 1;     for (long long int i = 1; i <= n; i++) {       products[i] = (products[i - 1] * p[i]) % M;       invproducts[i] = cans(1, products[i]);     }     return;   }   long long int querry(long long int l, long long int r) {     return (products[r] * invproducts[l - 1]) % M;   }   long long int qvalue(long long int i, long long int j) {     long long int prod = querry(i, j);     long long int ans = (d[i - 1] * prod) % M;     ans = ((d[j] - ans) % M + M) % M;     return ans;   }   set<long long int> checkpoints;   void addcheckpoint(long long int id) {     checkpoints.insert(id);     auto it = checkpoints.find(id);     auto it1 = prev(it);     auto it2 = next(it);     fans = ((fans - qvalue(*it1, *it2 - 1)) % M + M) % M;     fans = (fans + qvalue(*it1, id - 1)) % M;     fans = (fans + qvalue(id, *it2 - 1)) % M;   }   void delcheckpoint(long long int id) {     auto it = checkpoints.find(id);     auto it1 = prev(it);     auto it2 = next(it);     fans = ((fans + qvalue(*it1, *it2 - 1)) % M + M) % M;     fans = ((fans - qvalue(*it1, id - 1)) % M + M) % M;     fans = ((fans - qvalue(id, *it2 - 1)) % M + M) % M;     checkpoints.erase(id);   }   int main() {     cin >> n >> q;     for (int i = 1; i <= n; i++) {       long long int pr;       cin >> pr;       p[i] = cans(100, pr);       d[i] = ((1 + d[i - 1]) * p[i]) % M;     }     build();     checkpoints.insert(1);     checkpoints.insert(n + 1);     fans = d[n];     while (q--) {       long long int quer;       cin >> quer;       if (checkpoints.find(quer) == checkpoints.end())         addcheckpoint(quer);       else         delcheckpoint(quer);       cout << fans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, one, two[2], tmp, num, a[N];   bool flag, f[N];   int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * f;   }   int main() {     n = read();     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= n; i++) {       if (f[i]) continue;       f[i] = true;       if (a[i] == i) {         one = i;         continue;       }       if (a[a[i]] == i) {         two[0] = i;         two[1] = a[i];         f[a[i]] = true;         continue;       }       tmp = a[i];       num = 1;       while (!f[tmp]) {         f[tmp] = true;         num++;         tmp = a[tmp];       }       if (num & 1) flag = true;     }     if (one) {       printf( YES n );       for (int i = 1; i <= n; i++)         if (i != one) printf( %d %d n , one, i);       return 0;     }     if (flag || !two[0]) {       printf( NO );       return 0;     }     printf( YES n%d %d n , two[0], two[1]);     memset(f, 0, sizeof(f));     for (int i = 1; i <= n; i++) {       if (f[i] || i == two[0] || i == two[1]) continue;       tmp = i;       num = 0;       while (!f[tmp]) {         printf( %d %d n , two[num & 1], a[tmp]);         num++;         f[tmp] = true;         tmp = a[tmp];       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void getre() {     int x = 0;     printf( %d n , 1 / x);   }   void gettle() {     int res = 1;     while (1) res <<= 1;     printf( %d n , res);   }   template <typename T, typename S>   inline bool upmin(T &a, const S &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T, typename S>   inline bool upmax(T &a, const S &b) {     return a < b ? a = b, 1 : 0;   }   template <typename N, typename PN>   inline N flo(N a, PN b) {     return a >= 0 ? a / b : -((-a - 1) / b) - 1;   }   template <typename N, typename PN>   inline N cei(N a, PN b) {     return a > 0 ? (a - 1) / b + 1 : -(-a / b);   }   template <typename N>   N gcd(N a, N b) {     return b ? gcd(b, a % b) : a;   }   template <typename N>   inline int sgn(N a) {     return a > 0 ? 1 : (a < 0 ? -1 : 0);   }   inline void gn(long long &x) {     int sg = 1;     char c;     while (((c = getchar()) <  0  || c >  9 ) && c !=  - )       ;     c ==  -  ? (sg = -1, x = 0) : (x = c -  0 );     while ((c = getchar()) >=  0  && c <=  9 ) x = x * 10 + c -  0 ;     x *= sg;   }   inline void gn(int &x) {     long long t;     gn(t);     x = t;   }   inline void gn(unsigned long long &x) {     long long t;     gn(t);     x = t;   }   inline void gn(double &x) {     double t;     scanf( %lf , &t);     x = t;   }   inline void gn(long double &x) {     double t;     scanf( %lf , &t);     x = t;   }   inline void gs(char *s) { scanf( %s , s); }   inline void gc(char &c) {     while ((c = getchar()) > 126 || c < 33)       ;   }   inline void pc(char c) { putchar(c); }   inline long long sqr(long long a) { return a * a; }   inline double sqrf(double a) { return a * a; }   const int inf = 0x3f3f3f3f;   const double pi = 3.14159265358979323846264338327950288L;   const double eps = 1e-6;   int n;   long long x[111111], y[111111], z[111111];   int out = 0;   bool check(long long d, int par) {     long long lz, rz;     lz = -7e18, rz = 7e18;     long long l10, r10, l20, r20;     long long l1, r1, l2, r2;     l1 = l2 = -7e18;     r1 = r2 = 7e18;     for (int i = (1), _ed = (n + 1); i < _ed; i++) {       upmax(l1, x[i] + y[i] + z[i] - d);       upmin(r1, x[i] + y[i] + z[i] + d);       upmax(l2, x[i] + y[i] - z[i] - d);       upmin(r2, x[i] + y[i] - z[i] + d);     }     if ((l1 & 1) != par) l1++;     if ((l2 & 1) != par) l2++;     if ((r1 & 1) != par) r1--;     if ((r2 & 1) != par) r2--;     if (l1 > r1 || l2 > r2) return 0;     upmin(rz, (r1 - l2) / 2ll);     upmax(lz, (l1 - r2) / 2ll);     l10 = l1;     r10 = r1;     l20 = l2;     r20 = r2;     l1 = l2 = -7e18;     r1 = r2 = 7e18;     for (int i = (1), _ed = (n + 1); i < _ed; i++) {       upmax(l1, x[i] - y[i] + z[i] - d);       upmin(r1, x[i] - y[i] + z[i] + d);       upmax(l2, x[i] - y[i] - z[i] - d);       upmin(r2, x[i] - y[i] - z[i] + d);     }     if ((l1 & 1) != par) l1++;     if ((l2 & 1) != par) l2++;     if ((r1 & 1) != par) r1--;     if ((r2 & 1) != par) r2--;     if (l1 > r1 || l2 > r2) return 0;     upmin(rz, (r1 - l2) / 2ll);     upmax(lz, (l1 - r2) / 2ll);     if (lz > rz) return 0;     long long z = lz;     long long lplu = max(l10 - z, l20 + z);     long long rplu = min(r10 - z, r20 + z);     long long lmin = max(l1 - z, l2 + z);     long long rmin = min(r1 - z, r2 + z);     long long x = (lplu + lmin) / 2, y = (lplu - lmin) / 2;     if (out) {       out = 0;       printf( %I64d %I64d %I64d n , x, y, z);     }     return 1;   }   int main() {     int te;     gn(te);     while (te--) {       gn(n);       for (int i = (1), _ed = (n + 1); i < _ed; i++) {         gn(x[i]);         gn(y[i]);         gn(z[i]);       }       long long l = 0, r = 3.1e18;       while (l <= r) {         long long mid = l + r >> 1;         if (check(mid, 0) || check(mid, 1))           r = mid - 1;         else           l = mid + 1;       }       out = 1;       check(l, 0);       check(l, 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > adjl(500000);   int s[500000] = {0};   long long int a[500000] = {0};   map<pair<int, int>, long long int> mp;   int vis[500000] = {0};   void dfs(int n, vector<pair<int, int> > &ans, int p, long long int sum,            long long int mini) {     if (sum - mini > a[n]) {       ans.push_back(make_pair(n, p));     }     for (int i = 0; i < adjl[n].size(); i++) {       int ch = adjl[n][i];       if (ch != p) {         dfs(ch, ans, n, sum + mp[make_pair(ch, n)],             min(mini, sum + mp[make_pair(ch, n)]));       }     }   }   void dfs1(int n, int p, int &count) {     vis[n] = 1;     count++;     for (int i = 0; i < adjl[n].size(); i++) {       int ch = adjl[n][i];       if (ch != p) {         dfs1(ch, n, count);       }     }   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i + 1];     }     for (int i = 0; i < (n - 1); i++) {       int a, c;       cin >> a >> c;       adjl[a].push_back(i + 2);       adjl[i + 2].push_back(a);       mp[make_pair(a, i + 2)] = c;       mp[make_pair(i + 2, a)] = c;     }     vector<pair<int, int> > ans;     dfs(1, ans, -1, 0, 0);     long long int ans1 = 0;     for (int i = 0; i < ans.size(); i++) {       if (!vis[ans[i].first]) {         int count = 0;         dfs1(ans[i].first, ans[i].second, count);         ans1 += count;       }     }     cout << ans1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) {     if (a > b) {       return a;     } else {       return b;     }   }   long long min(long long a, long long b) {     if (a < b) {       return a;     } else {       return b;     }   }   string int2str(int& i) {     string s;     stringstream ss(s);     ss << i;     return ss.str();   }   int cnt;   bool done[100000000];   void outputspec(int x) {     if (!done[x]) {       done[x] = 1;       string u = int2str(x);       while (u.length() < 8) {         u =  0  + u;       }       cout << u << endl;       cnt--;     }   }   struct node {     int dir;     node* next;   };   node *h[20001], *ba[20001];   void insert(int data, int tar) {     node* temp = new node;     temp->next = NULL;     temp->dir = data;     ba[tar]->next = temp;     ba[tar] = temp;   }   void trygen(int cur, int id, int act, int yes) {     if (id == 0) {       if ((cur <= 10000) && (cur >= -10000)) {         insert(act, cur + 10000);       }     } else {       for (long long i = 0; i <= 9; i++) {         int cur2 = cur + i, id2 = id / 10, act2 = act + id * i;         trygen(cur2, id2, act2, 0);         cur2 = cur - i;         id2 = id / 10;         act2 = act + id * i;         trygen(cur2, id2, act2, 0);         if (yes) {           cur2 = cur * 10 + i;           id2 = id / 10;           act2 = act + id * i;           trygen(cur2, id2, act2, 1);         }         if (id != 1000) {           cur2 = cur * i;           id2 = id / 10;           act2 = act + id * i;           trygen(cur2, id2, act2, 0);         }       }     }   }   int main() {     int k, m;     cin >> k >> m;     for (long long i = 0; i <= 99999999; i++) {       done[i] = 0;     }     if (k == 0) {       for (long long i = 1; i <= m; i++) {         outputspec(i);       }       return 0;     }     if (k != 0) {       for (long long i = 0; i <= 20000; i++) {         h[i] = new node;         h[i]->next = NULL;         ba[i] = h[i];       }       trygen(0, 1000, 0, 1);       cnt = m;       for (long long j = 1; j <= 9999; j++) {         node* a = h[j + 10000];         if (cnt == 0) {           return 0;         } else {           while (a->next != NULL) {             a = a->next;             node* b = h[k + 10000 - j];             while (b->next != NULL) {               b = b->next;               outputspec(a->dir * 10000 + b->dir);               if (cnt == 0) {                 return 0;               }             }             b = h[-1 * k + j + 10000];             while (b->next != NULL) {               b = b->next;               outputspec(a->dir * 10000 + b->dir);               if (cnt == 0) {                 return 0;               }             }           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 1e18;   const long double PI = acos((long double)-1);   const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   void setIO(string name =   ) {     ios_base::sync_with_stdio(0);     cin.tie(0);     if ((int)(name).size()) {       freopen((name +  .in ).c_str(),  r , stdin);       freopen((name +  .out ).c_str(),  w , stdout);     }   }   int main() {     setIO();     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       for (int i = (0); i < (n); i++) cin >> arr[i];       int last = 1;       int cnt = 0, prev = 1, c = 0;       for (int i = (1); i < (n - 1); i++) {         if (arr[i] > arr[i + 1]) {           cnt++;         }         c++;         if (cnt >= prev) {           last++;           prev = c;           c = 0;           cnt = 0;         }       }       cout << last <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int SQ = 350;   const int MAX_N = 100000;   deque<int> a[MAX_N / SQ + 10];   int num[MAX_N / SQ + 10][MAX_N + 10];   int N, Q, lastans = 0;   void print() {     for (int i = 0; i <= N / SQ; i++) {       for (int j = 0; j < a[i].size(); j++) {         cout << a[i][j] <<    ;       }     }     cout << endl;     return;   }   int main() {     scanf( %d , &N);     for (int i = 0; i < N; i++) {       int x = i / SQ, k;       scanf( %d , &k);       a[x].push_back(k);       num[x][k]++;     }     scanf( %d , &Q);     for (int i = 0; i < Q; i++) {       int type, l, r, k;       scanf( %d , &type);       if (type == 1) {         scanf( %d %d , &l, &r);         l = (l + lastans - 1) % N;         r = (r + lastans - 1) % N;         if (l > r) swap(l, r);         int lx = l / SQ, ly = l % SQ, rx = r / SQ, ry = r % SQ;         if (lx == rx) {           int f = a[rx][ry];           a[rx].erase(a[rx].begin() + ry);           a[rx].insert(a[rx].begin() + ly, f);         } else {           int f = a[rx][ry];           a[rx].erase(a[rx].begin() + ry);           num[rx][f]--;           for (int j = lx; j < rx; j++) {             int b = a[j].back();             a[j].pop_back();             a[j + 1].push_front(b);             num[j][b]--;             num[j + 1][b]++;           }           a[lx].insert(a[lx].begin() + ly, f);           num[lx][f]++;         }       } else {         scanf( %d %d %d , &l, &r, &k);         l = (l + lastans - 1) % N;         r = (r + lastans - 1) % N;         k = (k + lastans - 1) % N + 1;         if (l > r) swap(l, r);         int lx = l / SQ, ly = l % SQ, rx = r / SQ, ry = r % SQ;         int ans = 0;         if (lx == rx) {           for (int j = ly; j <= ry; j++)             if (a[lx][j] == k) ans++;         } else {           for (int j = ly; j < SQ; j++)             if (a[lx][j] == k) ans++;           for (int j = lx + 1; j < rx; j++) ans += num[j][k];           for (int j = 0; j <= ry; j++)             if (a[rx][j] == k) ans++;         }         lastans = ans;         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) {     return make_pair(a.first + b.first, a.second + b.second);   }   pair<int, int> operator-(const pair<int, int> &a, const pair<int, int> &b) {     return make_pair(a.first - b.first, a.second - b.second);   }   pair<int, int> &operator+=(pair<int, int> &a, const pair<int, int> &b) {     a.first += b.first;     a.second += b.second;     return a;   }   pair<int, int> &operator-=(pair<int, int> &a, const pair<int, int> &b) {     a.first -= b.first;     a.second -= b.second;     return a;   }   template <class T, class U>   bool cmp_second(const pair<T, U> &a, const pair<T, U> &b) {     return a.second < b.second;   }   template <class T>   T gcd(T a, T b) {     a = abs(a);     b = abs(b);     while (b) {       T t = b;       b = a % b;       a = t;     }     return a;   }   template <class T>   pair<T, T> ext_gcd(T a, T b) {     T a0 = 1, a1 = 0, b0 = 0, b1 = 1;     if (a < 0) {       a = -a;       a0 = -1;     }     if (b < 0) {       b = -b;       b1 = -1;     }     while (b) {       T t, q = a / b;       t = b;       b = a - b * q;       a = t;       t = b0;       b0 = a0 - b0 * q;       a0 = t;       t = b1;       b1 = a1 - b1 * q;       a1 = t;     }     return make_pair(a0, a1);   }   inline int sg(int x) { return x ? (x > 0 ? 1 : -1) : 0; }   int main(void) {     int len, skip;     scanf( %d %d , &(len), &(skip));     len++;     skip++;     long long sol = 0;     for (int a = skip; a <= len - a; a++) {       int b = len - a;       int ab3 = a * b * 3;       int cnt = 0;       for (int c = skip; c <= len - skip; c++) {         int dmax = (ab3 - 1) / (a + c) - b;         dmax = min(dmax, len - skip);         dmax = max(dmax, skip - 1);         if (dmax < skip) break;         cnt += dmax - (skip - 1);       }       sol += cnt + (a < len - a ? cnt : 0);     }     sol *= 3;     cout << sol << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2001111;   long long n, m, k;   long long md = 1000000007;   long long a[N];   set<long long> s;   long long len[N];   vector<long long> t[N];   vector<long long> pref[N];   void merge(vector<long long> &t, vector<long long> a, vector<long long> b,              long long x, long long y) {     long long i = 0;     long long j = 0;     while (i < a.size() && j < b.size()) {       if (a[i] + x <= b[j] + y) {         t.push_back(a[i] + x);         i++;       } else {         t.push_back(b[j] + y);         j++;       }     }     while (i < a.size()) {       t.push_back(a[i] + x);       i++;     }     while (j < b.size()) {       t.push_back(b[j] + y);       j++;     }   }   void build(long long x) {     if (x * 2 <= n) {       build(x * 2);     }     if (x * 2 + 1 <= n) {       build(x * 2 + 1);     }     t[x].push_back(0);     merge(t[x], t[x * 2], t[x * 2 + 1], len[x * 2], len[x * 2 + 1]);     pref[x].push_back(t[x][0]);     for (long long i = 1; i < t[x].size(); i++) {       pref[x].push_back(t[x][i] + pref[x][i - 1]);     }   }   signed main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (long long i = 2; i <= n; i++) {       cin >> len[i];     }     build(1);     long long ans = 0;     for (long long i = 1; i <= m; i++) {       long long x, h;       cin >> x >> h;       long long pos = upper_bound(t[x].begin(), t[x].end(), h) - t[x].begin() - 1;       ans = ans + (pos + 1) * h - pref[x][pos];       long long prev = x;       h -= len[x];       x /= 2;       while (x >= 1) {         if (h <= 0) {           break;         }         ans += h;         if (x * 2 != prev && x * 2 <= n) {           h -= len[x * 2];           pos = upper_bound(t[x * 2].begin(), t[x * 2].end(), h) -                 t[x * 2].begin() - 1;           if (pos >= 0) ans = ans + (pos + 1) * h - pref[2 * x][pos];           h += len[x * 2];         }         if (x * 2 + 1 != prev && x * 2 + 1 <= n) {           h -= len[x * 2 + 1];           pos = upper_bound(t[x * 2 + 1].begin(), t[x * 2 + 1].end(), h) -                 t[x * 2 + 1].begin() - 1;           if (pos >= 0) ans = ans + (pos + 1) * h - pref[2 * x + 1][pos];           h += len[x * 2 + 1];         }         h -= len[x];         prev = x;         x /= 2;       }       cout << ans <<   n ;       ans = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int x, y;   vector<int> v1[200086], v2[200086];   bool ins[200086];   bool vis[200086], vis1[200086], vis2[200086];   bool e[200086];   int ans;   void dfs(int i) {     vis[i] = ins[i] = true;     for (int j = 0; j < v1[i].size(); j++) {       int to = v1[i][j];       if (ins[to]) {         printf( -1 );         exit(0);       }       if (!vis[to]) dfs(to);     }     ins[i] = false;   }   void dfs1(int i) {     vis1[i] = true;     for (int j = 0; j < v1[i].size(); j++) {       int to = v1[i][j];       if (!vis1[to]) dfs1(to);     }   }   void dfs2(int i) {     vis2[i] = true;     for (int j = 0; j < v2[i].size(); j++) {       int to = v2[i][j];       if (!vis2[to]) dfs2(to);     }   }   int main() {     scanf( %d%d , &n, &m);     ans = n;     for (int i = 1; i <= m; i++)       scanf( %d%d , &x, &y), v1[x].push_back(y), v2[y].push_back(x);     for (int i = 1; i <= n; i++)       if (!vis[i]) dfs(i);     for (int i = 1; i <= n; i++) {       if (vis1[i])         e[i] = true;       else         dfs1(i);       if (vis2[i])         e[i] = true;       else         dfs2(i);       if (e[i]) ans--;     }     printf( %d n , ans);     for (int i = 1; i <= n; i++) printf( %c , e[i] ?  E  :  A );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<char> vec(100001);     vec[0] =  a ;     int i = 1;     while (i < 100001) {       if (vec[i - 1] ==  a )         vec[i] =  b ;       else if (vec[i - 1] ==  b )         vec[i] =  c ;       else if (vec[i - 1] ==  c )         vec[i] =  d ;       else if (vec[i - 1] ==  d )         vec[i] =  a ;       i++;     }     int n;     cin >> n;     for (int i = 0; i < n; i++) cout << vec[i];     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, int> cont;   int n;   int ans;   int main() {     while (~scanf( %d , &n)) {       int a;       long long num = 0;       for (int i = 1; i <= n; i++) {         scanf( %d , &a);         num += a;         ans = max(ans, ++cont[num]);       }       printf( %d n , n - ans);     }     cont.clear();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, d1[200005], d2[200005], ty, re1, re2, re3;   long long s, a[200005], b[200005], te;   vector<pair<long long, int> > v1, v2;   vector<long long> v3;   void bs(int lo, int up) {     int mid = (lo + up) / 2;     if (lo == up) {       v3.clear();       for (int i = 0; i < v2.size(); i++) v3.push_back(v2[i].first * b[mid]);       for (int i = 0; i < v1.size(); i++) {         if (v1[i].first * a[mid] > s) break;         int k1 = upper_bound(v3.begin(), v3.end(), s - v1[i].first * a[mid]) -                  v3.begin();         if (i + 1 + k1 >= k) {           re1 = i, re2 = k - i - 2, re3 = mid;           return;         }       }       if (v3.size() >= k && v3[k - 1] <= s) {         re1 = -1, re2 = k - 1;         re3 = mid;         return;       }     }     v3.clear();     for (int i = 0; i < v2.size(); i++) v3.push_back(v2[i].first * b[mid]);     for (int i = 0; i < v1.size(); i++) {       if (v1[i].first * a[mid] > s) break;       int k1 = upper_bound(v3.begin(), v3.end(), s - v1[i].first * a[mid]) -                v3.begin();       if (i + 1 + k1 >= k) {         re1 = i, re2 = k - i - 2, re3 = mid;         bs(lo, mid);         return;       }     }     if (v3.size() >= k && v3[k - 1] <= s) {       re1 = -1, re2 = k - 1;       re3 = mid;       bs(lo, mid);       return;     }     bs(mid + 1, up);   }   int main() {     cin >> n >> m >> k >> s;     a[0] = 1e9;     b[0] = 1e9;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] < a[i - 1])         d1[i] = i;       else         a[i] = a[i - 1], d1[i] = d1[i - 1];     }     v1.clear();     for (int i = 1; i <= n; i++) {       cin >> b[i];       if (b[i] < b[i - 1])         d2[i] = i;       else         b[i] = b[i - 1], d2[i] = d2[i - 1];     }     v2.clear();     for (int i = 1; i <= m; i++) {       cin >> ty;       if (ty == 1) {         cin >> te;         v1.push_back(pair<long long, int>(te, i));       } else {         cin >> te;         v2.push_back(pair<long long, int>(te, i));       }     }     sort(v1.begin(), v1.end());     sort(v2.begin(), v2.end());     for (int i = 1; i < v1.size(); i++) v1[i].first += v1[i - 1].first;     for (int i = 1; i < v2.size(); i++) v2[i].first += v2[i - 1].first;     re3 = 1e9;     v3.clear();     for (int i = 0; i < v2.size(); i++) v3.push_back(v2[i].first * b[n]);     for (int i = 0; i < v1.size(); i++) {       if (v1[i].first * a[n] > s) break;       int k1 =           upper_bound(v3.begin(), v3.end(), s - v1[i].first * a[n]) - v3.begin();       if (i + 1 + k1 >= k) {         re1 = i, re2 = k - i - 2, re3 = n;         break;       }     }     if (v3.size() >= k && v3[k - 1] <= s) {       re1 = -1, re2 = k - 1;       re3 = n;     }     if (re3 != 1e9) {       bs(1, n);       cout << re3 << endl;       for (int i = 0; i <= re1; i++)         cout << v1[i].second <<     << d1[re3] << endl;       for (int i = 0; i <= re2; i++)         cout << v2[i].second <<     << d2[re3] << endl;     } else       cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n;     cin >> m >> n;     cout << (n * m) / 2 <<   n ;   }


#include <bits/stdc++.h>   const int inf = (1ll << 30) - 1;   const int maxn = (int)1e5 + 10;   using namespace std;   int dp[150][(1 << 16) + 100];   int c[111];   int r[111];   int b[111];   char temp[111];   int cntR[(1 << 16) + 10];   int cntB[(1 << 16) + 10];   int n;   void solve() {     memset(dp, -1, sizeof dp);     queue<pair<pair<int, int>, int> > pq;     scanf( %d , &n);     int xx = 0;     for (int i = 0; i < n; i++) {       scanf( %s%d%d , temp, &r[i], &b[i]);       c[i] = temp[0] ==  R  ? 1 : 0;       xx += c[i];     }     for (int i = 0; i < (1 << n); i++) {       for (int j = 0; j < n; j++) {         if (i & (1 << j)) {           if (c[j])             cntR[i]++;           else             cntB[i]++;         }       }     }     dp[0][0] = 0;     pq.push(make_pair(make_pair(0, 0), 0));     while (pq.size() > 0) {       int x = pq.front().first.first;       int y = pq.front().first.second;       int mask = pq.front().second;       pq.pop();       if (dp[x][mask] < y) continue;       for (int i = 0; i < n; i++) {         if (mask & (1 << i)) continue;         int nmask = mask | (1 << i);         int X = x, Y = y;         if (r[i] >= cntR[mask]) {           X += cntR[mask];         } else           X += r[i];         if (b[i] >= cntB[mask]) {           Y += cntB[mask];         } else           Y += b[i];         if (dp[X][nmask] == -1 || dp[X][nmask] < Y) {           dp[X][nmask] = Y;           pq.push(make_pair(make_pair(X, Y), nmask));         }       }     }     int sumA = 0, sumB = 0;     for (int i = 0; i < n; i++) {       sumA += r[i];       sumB += b[i];     }     int ans = inf;     for (int i = 0; i < 144; i++) {       if (dp[i][(1 << n) - 1] == -1) continue;       ans = min(ans, max(sumA - i, sumB - dp[i][(1 << n) - 1]));     }     printf( %d n , ans + n);   }   int main() {     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[300005];   vector<int> vec;   int par[300005];   int vis1[300005];   int vis2[300005];   int vis3[300005];   int vis4[300005];   int dia[300005];   int root(int x) { return par[x] = ((par[x] == x) ? x : root(par[x])); }   void unite(int x, int y) { par[root(y)] = root(x); }   void dfs1(int x, int cnt, int &y, int &mx, int t) {     if (t)       vis1[x] = 1;     else       vis2[x] = 1;     int i;     for (i = 0; i < int(adj[x].size()); i++) {       if ((!vis1[adj[x][i]] && t) || (!vis2[adj[x][i]] && !t)) {         dfs1(adj[x][i], cnt + 1, y, mx, t);       }     }     if (cnt > mx) {       mx = cnt;       y = x;     }   }   bool dfs2(int x, int y) {     if (x == y) {       vec.push_back(y);       return true;     }     vis3[x] = 1;     int i;     for (i = 0; i < int(adj[x].size()); i++) {       if (!vis3[adj[x][i]]) {         if (dfs2(adj[x][i], y)) {           vec.push_back(adj[x][i]);           return true;         }       }     }     return false;   }   void dfs3(int x, int y) {     vis4[x] = 1;     unite(y, x);     int i;     for (i = 0; i < int(adj[x].size()); i++) {       if (!vis4[adj[x][i]]) {         dfs3(adj[x][i], y);       }     }   }   int main() {     int i, n, m, q, x, y, c;     scanf( %d %d %d , &n, &m, &q);     for (i = 0; i <= n; i++) par[i] = i;     for (i = 0; i < m; i++) {       scanf( %d %d , &x, &y);       adj[x].push_back(y);       adj[y].push_back(x);     }     int mx = 0;     for (i = 1; i <= n; i++) {       if (!vis1[i]) {         vec.clear();         mx = 0;         x = i;         y = i;         dfs1(i, 0, y, mx, 0);         mx = 0;         dfs1(y, 0, x, mx, 1);         dfs2(x, y);         int k = int(vec.size());         dfs3(x, vec[k / 2]);         dia[vec[k / 2]] = k - 1;       }     }     while (q--) {       scanf( %d %d , &c, &x);       if (c == 1) {         x = root(x);         printf( %d n , dia[x]);       } else {         scanf( %d , &y);         x = root(x);         y = root(y);         if (x == y) continue;         if (dia[x] >= dia[y]) {           unite(x, y);           dia[x] = max(dia[x], 1 + (dia[x] - dia[x] / 2) + (dia[y] - dia[y] / 2));         } else {           unite(y, x);           dia[y] = max(dia[y], 1 + (dia[x] - dia[x] / 2) + (dia[y] - dia[y] / 2));         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n = 0, s = 0;     cin >> n >> s;     if (s > n) {       if (s % n != 0) {         cout << ((s / n) + 1);       } else {         cout << (s / n);       }     } else {       cout << 1;     }   }


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


#include <bits/stdc++.h>   using namespace std;   long long int solve(long long int a, long long int b) {     long long int x = sqrt(8 * (a + b) + 1) - 1;     return x / 2;   }   int main() {     long long int a, b;     cin >> a >> b;     long long int x = solve(a, b);     vector<long long int> w1, w2;     for (long long int i = x; i > 0; i--) {       if (a >= i) {         a -= i;         w1.push_back(i);       } else {         b -= i;         w2.push_back(i);       }     }     cout << w1.size() << endl;     for (int i = 0; i < w1.size(); i++) cout << w1[i] <<    ;     cout << endl;     cout << w2.size() << endl;     for (int i = 0; i < w2.size(); i++) cout << w2[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100500];   int p[100500];   int q[100500];   vector<pair<int, int> > moves;   int n, h = -1;   bool asign(int x, int y) { return a[x] < a[y]; }   bool happy(int n) {     if (n == 0) return true;     if (n % 10 == 7 || n % 10 == 4) return happy(n / 10);     return false;   }   void move(int x, int y) {     if (x == y) return;     moves.push_back(make_pair(x + 1, y + 1));     swap(q[x], q[y]);     p[q[x]] = x;     p[q[y]] = y;     if (h == x)       h = y;     else if (h == y)       h = x;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       p[i] = i;       if (happy(a[i])) h = i;     }     sort(p, p + n, asign);     if (h == -1) {       for (int i = 0; i < n - 1; ++i)         if (a[i] > a[i + 1]) {           printf( -1 n );           return 0;         }       printf( 0 n );       return 0;     }     for (int i = 0; i < n; ++i) q[p[i]] = i;     for (int i = 0; i < n; ++i) {       if (p[i] == h) continue;       move(i, h);       move(h, p[i]);     }     printf( %d n , (int)moves.size());     for (int i = 0; i < moves.size(); ++i)       printf( %d %d n , moves[i].first, moves[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void wait(double seconds) {     double endtime = clock() + (seconds * CLOCKS_PER_SEC);     while (clock() < endtime) {       ;     }   }   inline int fastIn() {     register char c = 0;     register int a = 0;     while (c < 33) c = getchar();     while (c > 33) {       a = (a * 10) + (c -  0 );       c = getchar();     }     return a;   }   int tour_count;   int win_need;   int bag_cap;   const int mx = 210;   struct NODE {     double p;     double np;     int w;     NODE(int p = 0, int np = 0, int w = 0) : p(p), np(np), w(w) {}     bool operator<(const NODE &r) const { return this->w > r.w; }   };   NODE vi[mx];   inline void read() {     scanf( %d %d %d , &tour_count, &win_need, &bag_cap);     for (int i = 0, j1 = tour_count; i < j1; ++i) {       int tmp = fastIn();       vi[i].p = (double)tmp / (double)100;       vi[i].np = (double)1 - vi[i].p;     }     for (int i = 0, j1 = tour_count; i < j1; ++i) {       scanf( %d , &vi[i].w);     }   }   struct data {     bool f;     double v;     data(bool f = false, double v = 0) : f(f), v(v) { ; }   };   double dp[200][200][201];   bool vis[200][200][201];   double go(int at, int win, int cap) {     if (cap < 0) return (double)0;     if (at >= tour_count) {       return win >= win_need ? (double)1 : (double)0;     }     if (vis[at][win][cap]) return dp[at][win][cap];     vis[at][win][cap] = true;     double v1 = vi[at].p * go(at + 1, win + 1, min(cap + vi[at].w, 200));     double v2 = vi[at].np * go(at + 1, win, cap);     return dp[at][win][cap] = (v1 + v2);   }   inline void proc() {     memset(vis, false, sizeof(vis));     sort(vi, vi + tour_count);     double res = go(0, 0, bag_cap);     printf( %.9lf n , res);   }   int main() {     int kase = 1;     for (int i = 0, j1 = kase; i < j1; ++i) {       read();       proc();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[6];     for (int i = 0; i < 6; i++) {       cin >> a[i];     }     int ans = (a[0] + a[1] + a[2]) * (a[0] + a[1] + a[2]) - a[0] * a[0] -               a[2] * a[2] - a[4] * a[4];     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int x, int y) {     if (x == 0)       return y;     else       return gcd(y % x, x);   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   bool sortbysize(string &s1, string &s2) { return s1.size() < s2.size(); }   bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {     return (a.first > b.first);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n, k, a, b, i, x, cnt = 0;     cin >> n >> k;     vector<pair<int, int>> v;     map<int, int> mp;     while (n--) {       cin >> a >> b;       v.push_back(make_pair(a, b));       mp[a]++;     }     sort(v.begin(), v.end(), sortinrev);     for (i = 0; i < v.size();) {       if (mp[v[i].first] > 1) {         sort(v.begin() + i, v.begin() + i + mp[v[i].first], sortbysec);       }       i += mp[v[i].first];     }     for (i = 0; i < v.size(); i++) {       if (v[i].second == v[k - 1].second && v[i].first == v[k - 1].first) cnt++;     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const int inf = 1000000007;   const long long linf = 1LL << 62;   const unsigned long long ulinf = 1ULL << 63;   const double eps = 0.000001;   const double pi = 3.14159265358979323846;   template <class T>   T abs(T a) {     return a >= 0 ? a : -a;   }   template <class T>   T sqr(T a) {     return a * a;   }   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <class T>   T mod(T a, T b) {     return (a % b + b) % b;   }   long long powmod(long long a, long long b, long long c) {     if (b == 0LL) return 1LL;     long long ret = powmod(a, b >> 1, c);     ret = ret * ret % c;     if (b & 1LL) ret = ret * a % c;     return ret;   }   long long inv(long long a, long long b) { return powmod(a, b - 2LL, b); }   template <class T>   void maxe(T &a, T b) {     if (a < b) a = b;   }   template <class T>   void mine(T &a, T b) {     if (a > b) a = b;   }   int iszero(double a) { return abs(a) <= eps; }   template <class T>   void geti(T &a) {     a = 0;     T b = 1;     char c = getchar();     if (c ==  - )       b = -1;     else       a = c - 48;     while ((c = getchar()) !=     && c !=   n ) a = a * 10 + c - 48;     a *= b;   }   void fileio_in_out() {     freopen( .in ,  r , stdin);     freopen( .out ,  w , stdout);   }   void fileio_txt() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   const int N = 222222;   const int M = 1111111;   const int K = 20;   int test;   int n, m, k, ans;   char s[11];   int main() {     scanf( %d , &test);     while (test--) {       vector<pair<int, int> > v;       for (int i = 0; i < 8; i++) {         scanf( %s , s);         for (int j = 0; j < 8; j++)           if (s[j] ==  K ) v.push_back(make_pair(i, j));       }       ans = ((v[0].first - v[1].first) % 4 == 0) &&             ((v[0].second - v[1].second) % 4 == 0);       puts(ans ?  YES  :  NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k;     int n;     cin >> n;     long arr[n][2];     for (i = 0; i < n; i++) cin >> arr[i][0] >> arr[i][1];     long long minx, miny, maxx, maxy;     minx = arr[0][0];     miny = arr[0][1];     maxx = arr[0][0];     maxy = arr[0][1];     for (i = 0; i < n; i++) {       if (minx > arr[i][0]) minx = arr[i][0];       if (miny > arr[i][1]) miny = arr[i][1];       if (maxx < arr[i][0]) maxx = arr[i][0];       if (maxy < arr[i][1]) maxy = arr[i][1];     }     long long l1, l2;     l1 = (maxx - minx);     l2 = (maxy - miny);     if (l1 > l2)       cout << l1 * l1;     else       cout << l2 * l2;   }


#include <bits/stdc++.h>   using namespace std;   void __print(long long x) { cerr << x; }   void __print(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) {     long long 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...);   }   const long long N = 2e5 + 4;   const long long mod = 1e9 + 7;   void solve() {     long long n;     cin >> n;     string a, b;     cin >> a >> b;     long long ans = 0;     for (long long i = 0; i < n / 2; i++) {       if (a[i] == a[n - i - 1] and b[i] == b[n - i - 1]) continue;       if (a[i] == b[i] and a[n - i - 1] == b[n - i - 1]) continue;       if (a[i] == b[n - i - 1] and b[i] == a[n - i - 1]) continue;       bool f = 0, f2 = 0;       if (b[i] == b[n - i - 1]) {         ans++;         continue;       }       if (a[i] != b[i] and a[n - i - 1] != b[n - i - 1]) {         f = 1;       }       if (a[i] != b[n - i - 1] and b[i] != a[n - i - 1]) {         f2 = 1;       }       if (f and f2) {         ans += 2;       } else {         ans++;       }     }     if (a[n / 2] != b[n / 2] and n & 1) {       ans++;     }     cout << ans;   }   int32_t main() {     long long tt;     tt = 1;     for (long long t = 1; t <= tt; t++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const long long md = 1e9 + 7;   const long double eps = 1e-8;   struct frac {     long long x, y;     frac() {}     frac(long long x, long long y) : x(x), y(y) {}     bool operator==(const frac& ot) { return x * ot.y == y * ot.x; }     bool operator<(const frac& ot) { return x * ot.y < y * ot.x; }   };   vector<int> tr;   int sz = 1;   void add(int v, int val) {     v += sz - 1;     tr[v] += val;     while (v) {       v = (v - 1) >> 1;       tr[v] += val;     }     return;   }   int get(int v, int l, int r, int bg, int en) {     if (bg >= r || l >= en) {       return 0;     }     if (l >= bg && r <= en) {       return tr[v];     }     int m = (l + r) >> 1;     return get(2 * v + 1, l, m, bg, en) + get(2 * v + 2, m, r, bg, en);   }   int main() {     iostream::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int n;     long long w;     cin >> n >> w;     vector<long long> v(n), x(n);     for (int i = 0; i < n; i++) {       cin >> x[i] >> v[i];     }     vector<frac> f1(n), f2(n);     for (int i = 0; i < n; i++) {       f1[i] = {-x[i], v[i] + w};       if (f1[i].y < 0) {         f1[i].x = -f1[i].x;         f1[i].y = -f1[i].y;       }       f2[i] = {-x[i], v[i] - w};       if (f2[i].y < 0) {         f2[i].x = -f2[i].x;         f2[i].y = -f2[i].y;       }     }     vector<int> all(n);     for (int i = 0; i < n; i++) {       all[i] = i;     }     vector<int> F2(n);     sort(all.begin(), all.end(), [&](int a, int b) { return f2[a] < f2[b]; });     F2[all[0]] = 0;     for (int i = 1; i < n; i++) {       F2[all[i]] = F2[all[i - 1]] + !(f2[all[i]] == f2[all[i - 1]]);     }     sort(all.begin(), all.end(), [&](int a, int b) {       if (f1[a] < f1[b]) {         return true;       }       if (f1[b] < f1[a]) {         return false;       }       return F2[b] < F2[a];     });     while (sz < n) {       sz <<= 1;     }     tr.resize(2 * sz - 1, 0);     long long ans = 0;     for (int i : all) {       ans += get(0, 0, sz, F2[i], n);       add(F2[i], 1);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, c;     cin >> n >> m >> c;     vector<int> A(n), B(m);     for (auto &a : A) cin >> a;     for (auto &b : B) cin >> b;     int i = 0, x = 0;     for (int i = 0; i < n; ++i) {       if (i < m) x = (x + B[i]) % c;       if (i > n - m) x = (x - B[i - n + m - 1] + c) % c;       A[i] = (A[i] + x) % c;     }     for (auto a : A) cout << a <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 500010;   int n, m;   struct edge {     int a, b, c, t;   } e[N];   inline bool operator<(const edge &a, const edge &b) { return a.c < b.c; }   struct union_find {     int f[N], h[N], sz[N], cnt;     struct oper {       int x, fx, hx, szx, tc;     } op[N * 2];     int l;     void init() {       l = 0, cnt = n;       for (int i = 1; i <= n; i++) f[i] = i, h[i] = 0, sz[i] = 1;     }     int find(int x) { return f[x] == x ? x : find(f[x]); }     void rewind(int t) {       for (int i = l; i >= t + 1; i--) {         int x = op[i].x;         f[x] = op[i].fx, h[x] = op[i].hx;         sz[x] = op[i].szx;         cnt = op[i].tc;       }       l = t;     }     void merge(int a, int b) {       int fa = find(a), fb = find(b);       if (fa != fb) {         if (h[fa] > h[fb]) swap(fa, fb);         op[++l] = (oper){fa, f[fa], h[fa], sz[fa], cnt},         op[++l] = (oper){fb, f[fb], h[fb], sz[fb], cnt};         if (sz[fa] && sz[fb]) cnt -= 2;         f[fa] = fb;         h[fb] = max(h[fb], h[fa] + 1);         sz[fb] ^= sz[fa];       }     }   } T;   int j = 1, ans[N];   vector<int> ed[N << 2];   namespace seg {   int a, b, c;   void add(int x, int l, int r) {     if (a <= l && r <= b)       ed[x].push_back(c);     else {       if (a <= ((l + r) >> 1)) add((x << 1), l, ((l + r) >> 1));       if (b > ((l + r) >> 1)) add(((x << 1) | 1), ((l + r) >> 1) + 1, r);     }   }   }  // namespace seg   void solve(int x, int l, int r) {     int len = ed[x].size(), l0 = T.l;     for (int i = 0; i < len; i++) T.merge(e[ed[x][i]].a, e[ed[x][i]].b);     if (l == r) {       ans[l] = ans[l + 1];       while (j <= m && T.cnt) {         if (e[j].t <= l) {           seg::a = e[j].t, seg::b = l - 1, seg::c = j;           if (seg::a <= seg::b) seg::add(1, 1, m);           T.merge(e[j].a, e[j].b);           ans[l] = e[j].c;         }         j++;       }       if (T.cnt) ans[l] = -1;     } else       solve(((x << 1) | 1), ((l + r) >> 1) + 1, r),           solve((x << 1), l, ((l + r) >> 1));     T.rewind(l0);   }   int main() {     scanf( %d%d , &n, &m);     T.init();     for (int i = 1; i <= m; i++)       scanf( %d%d%d , &e[i].a, &e[i].b, &e[i].c), e[i].t = i;     sort(e + 1, e + m + 1);     solve(1, 1, m);     for (int i = 1; i <= m; i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int a[500005], b[500005];   int main() {     int i, j, k, l, x, y, z, m, n, t;     cin >> t;     while (t--) {       cin >> x >> y >> z;       while (x > 20 && y) {         x = x / 2;         x += 10;         y--;       }       while (x >= 0 && z) {         x = x - 10;         z--;       }       x = max(0, x);       if (x)         cout <<  NO  << endl;       else         cout <<  YES  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     float a, b, c, t;     cin >> a >> b;     if (a > b) swap(a, b);     c = (b - a) / 2;     t = floor(c);     c = ceil(c);     int f = 0, y = 0;     for (int i = 1; i <= c; i++) {       f += i;     }     for (int i = 1; i <= t; i++) {       y += i;     }     cout << f + y;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     map<long long, long long> cn;     set<long long> fac;     while (t--) {       fac.clear();       cn.clear();       long long n;       cin >> n;       long long temp = n;       for (long long i = 2; i * i <= n; i++) {         while (n % i == 0) {           cn[i]++;           n /= i;           fac.insert(i);         }       }       if (n > 1) cn[n]++, fac.insert(n);       n = temp;       if (fac.size() >= 3) {         cout <<  YES n ;         long long a = *fac.begin(), b = *(++fac.begin());         cout << a <<     << b <<     << n / (a * b) <<   n ;         continue;       } else if (fac.size() == 1 && cn[*(fac.begin())] >= 6) {         cout <<  YES n ;         cout << *(fac.begin()) <<     << (*(fac.begin())) * (*(fac.begin()))              <<                  << n / ((*(fac.begin())) * (*(fac.begin())) * (*(fac.begin())))              <<   n ;         continue;       }       if (fac.size() == 2) {         long long a, ac, b, bc;         a = *(fac.begin());         ac = cn[*(fac.begin())];         b = *(++fac.begin());         bc = cn[*(++fac.begin())];         if (ac + bc >= 4) {           cout <<  YES n ;           cout << a <<     << b <<     << n / (a * b) <<   n ;           continue;         }       }       cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int a[200005];   long long int dist[200005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int n;     cin >> n;     for (long long int i = 0; i < n; i++) dist[i] = INT_MAX;     for (long long int i = 0; i < n; i++) cin >> a[i];     long long int m = INT_MAX;     for (long long int i = 0; i < n; i++) {       if (a[i] == 0) {         m = i;         dist[i] = 0;       }       if (m == INT_MAX) {         dist[i] = INT_MAX;         continue;       }       dist[i] = min(dist[i], i - m);     }     m = INT_MAX;     for (long long int i = n - 1; i > -1; i--) {       if (a[i] == 0) {         m = i;         dist[i] = 0;       }       dist[i] = min(dist[i], m - i);     }     for (long long int i = 0; i < n; i++) cout << dist[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimization( O3 )   using namespace std;   template <typename T>   inline void Cin(T& first) {     char c;     T sign = 1;     first = 0;     for (c = getchar(); c <  0  || c >  9 ; c = getchar())       if (c ==  - ) sign = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) first = first * 10 + c -  0 ;     first *= sign;   }   template <typename T>   inline void Out(T first) {     if (first > 9) Out(first / 10);     putchar(first % 10 +  0 );   }   template <typename T>   inline void Cout(T first, char c) {     if (first < 0) putchar( - );     first = abs(first);     Out(first);     putchar(c);   }   template <typename T, typename... Args>   inline void Cin(T& a, Args&... args) {     Cin(a);     Cin(args...);   }   template <typename T, typename... Args>   inline void Cout(T a, char c, Args... args) {     Cout(a, c);     Cout(args...);   }   const int N = 5002;   const int M = int(5e5) + 2;   const long long oo = (long long)1e10;   int n, k, _a[M], cur[3];   vector<long long> f[3];   struct TIrene {     int first, i;     bool operator<(const TIrene& o) const& { return i < o.i; }   } a[M];   void Enter() {     cin >> k >> n;     for (int i = 0; i < n; ++i) cin >> _a[i];     sort(_a, _a + n);     for (int i = 0; i < n; ++i) {       if (i) a[i].first = _a[i] - _a[i - 1];       a[i].i = i;     }     sort(a + 1, a + n, [](const TIrene& a, const TIrene& b) {       if (a.first != b.first) return a.first < b.first;       return a.i > b.i;     });     n = min(n, 3 * k);     sort(a + 1, a + n);   }   void Solve() {     for (int i = 0; i < 3; ++i) {       f[i].resize(k + 1);       fill(f[i].begin(), f[i].end(), oo);       cur[i] = i;     }     for (int i = 1; i < n; ++i) {       if (i - 1)         f[cur[2]][1] = min(f[cur[1]][1], (long long)a[i].first);       else         f[cur[2]][1] = a[1].first;       for (int j = 2, l = min(k, i); j <= l; ++j) {         if (a[i].i > a[i - 1].i + 1)           f[cur[2]][j] = min(f[cur[1]][j], f[cur[1]][j - 1] + a[i].first);         else           f[cur[2]][j] = min(f[cur[1]][j], f[cur[0]][j - 1] + a[i].first);       }       int t = cur[0];       cur[0] = cur[1], cur[1] = cur[2], cur[2] = t;     }     cout << f[cur[1]][k];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     if (fopen( test                 .inp ,                r )) {       freopen(            test             .inp ,            r , stdin);       freopen(            test             .out ,            w , stdout);     }     Enter(), Solve();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( tune=native )   #pragma GCC optimize( unroll-loops )   using namespace std;   using ll = long long;   const int N = 120005;   struct node_t {     int tag, time, value, number;     ll answer;   } tree[N << 2];   int n, m, top_max, top_min, a[N], stack_max[N], stack_min[N];   vector<pair<int, int>> queries[N];   ll answer[N];   static void add_value(int x, int value) {     tree[x].value += value;     tree[x].tag += value;   }   static void add_time(int x, int value) {     tree[x].time += value;     tree[x].answer += (ll)value * tree[x].number;   }   static void push_up(int x) {     tree[x].value = min(tree[x << 1].value, tree[x << 1 | 1].value);     tree[x].answer = tree[x << 1].answer + tree[x << 1 | 1].answer;     tree[x].number = 0;     if (tree[x].value == tree[x << 1].value) {       tree[x].number += tree[x << 1].number;     }     if (tree[x].value == tree[x << 1 | 1].value) {       tree[x].number += tree[x << 1 | 1].number;     }   }   static void push_down(int x) {     if (tree[x].tag) {       add_value(x << 1, tree[x].tag);       add_value(x << 1 | 1, tree[x].tag);       tree[x].tag = 0;     }     if (tree[x].time) {       if (tree[x].value == tree[x << 1].value) {         add_time(x << 1, tree[x].time);       }       if (tree[x].value == tree[x << 1 | 1].value) {         add_time(x << 1 | 1, tree[x].time);       }       tree[x].time = 0;     }   }   static void build(int x, int l, int r) {     tree[x].value = l;     tree[x].number = 1;     if (l == r) {       return;     }     int mid = (l + r) / 2;     build(x << 1, l, mid);     build(x << 1 | 1, mid + 1, r);   }   static void modify(int x, int l, int r, int ql, int qr, int value) {     if (l == ql && r == qr) {       add_value(x, value);       return;     }     int mid = (l + r) / 2;     push_down(x);     if (qr <= mid) {       modify(x << 1, l, mid, ql, qr, value);     } else if (ql > mid) {       modify(x << 1 | 1, mid + 1, r, ql, qr, value);     } else {       modify(x << 1, l, mid, ql, mid, value);       modify(x << 1 | 1, mid + 1, r, mid + 1, qr, value);     }     push_up(x);   }   static ll query(int x, int l, int r, int ql, int qr) {     if (l == ql && r == qr) {       return tree[x].answer;     }     int mid = (l + r) / 2;     push_down(x);     if (qr <= mid) {       return query(x << 1, l, mid, ql, qr);     } else if (ql > mid) {       return query(x << 1 | 1, mid + 1, r, ql, qr);     } else {       return query(x << 1, l, mid, ql, mid) +              query(x << 1 | 1, mid + 1, r, mid + 1, qr);     }   }   void solve() {     ios::sync_with_stdio(0);     cin.tie(nullptr);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     cin >> m;     for (int i = 1; i <= m; ++i) {       int l, r;       cin >> l >> r;       queries[r].push_back(make_pair(l, i));     }     build(1, 1, n);     for (int i = 1; i <= n; ++i) {       add_value(1, -1);       while (top_max && a[stack_max[top_max]] < a[i]) {         modify(1, 1, n, stack_max[top_max - 1] + 1, stack_max[top_max],                a[i] - a[stack_max[top_max]]);         --top_max;       }       stack_max[++top_max] = i;       while (top_min && a[stack_min[top_min]] > a[i]) {         modify(1, 1, n, stack_min[top_min - 1] + 1, stack_min[top_min],                a[stack_min[top_min]] - a[i]);         --top_min;       }       stack_min[++top_min] = i;       add_time(1, 1);       for (auto q : queries[i]) {         answer[q.second] = query(1, 1, n, q.first, i);       }     }     for (int i = 1; i <= m; ++i) {       cout << answer[i] <<   n ;     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[300005], ans;   int n, num[300005], cnt[2] = {1}, sum[300005];   int change(long long x) {     int ans = 0;     while (x) {       ans += (x % 2);       x /= 2;     }     return ans;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       num[i] = change(a[i]);       sum[i] = sum[i - 1] + num[i];       ans += cnt[sum[i] % 2];       int maxn = 0;       for (int j = i, k = i + 1; j >= 1 && j >= i - 64; j--) {         while (k > j) {           k--;           maxn = max(maxn, num[k]);         }         if (maxn * 2 > sum[i] - sum[j - 1] && (sum[i] - sum[j - 1]) % 2 == 0)           ans--;       }       cnt[sum[i] % 2]++;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100000;   const int MAX_E2 = 1 << 18;   const int MAX_A = 100000;   const int INF = 1 << 30;   int uas[MAX_N];   pair<int, int> ps[MAX_N], cns[MAX_A];   vector<int> cvs[MAX_A];   bool used[MAX_A];   int check(int m, int uan, int c0, int x) {     memset(used, false, sizeof(used));     int c = c0, sum = 0;     for (int i = uan - 1; i >= 0 && cns[i].first > x; i--) {       vector<int> &cv = cvs[cns[i].second];       int maxj = cns[i].first - x;       for (int j = 0; j < maxj; j++)         sum += ps[cv[j]].first, c++, used[cv[j]] = true;     }     for (int i = 0; i < m && c <= x; i++)       if (!used[i]) sum += ps[i].first, c++;     return (c > x) ? sum : INF;   }   int main() {     int n;     scanf( %d , &n);     int m = 0, c0 = 0;     for (int i = 0; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       if (!a)         c0++;       else {         a--;         uas[m] = a;         ps[m++] = pair<int, int>(b, a);       }     }     sort(uas, uas + m);     int uan = unique(uas, uas + m) - uas;     for (int i = 0; i < m; i++) {       int ai = lower_bound(uas, uas + uan, ps[i].second) - uas;       ps[i].second = ai;     }     sort(ps, ps + m);     for (int i = 0; i < m; i++) cvs[ps[i].second].push_back(i);     for (int i = 0; i < uan; i++) cns[i] = pair<int, int>(cvs[i].size(), i);     sort(cns, cns + uan);     int x0 = 0, x1 = cns[uan - 1].first;     while (x0 + 2 < x1) {       int xx0 = (x0 * 2 + x1) / 3;       int xx1 = (x0 + x1 * 2) / 3;       int sum0 = check(m, uan, c0, xx0);       int sum1 = check(m, uan, c0, xx1);       if (sum0 >= sum1)         x0 = xx0;       else         x1 = xx1;     }     int minsum = INF;     for (int x = x0; x <= x1; x++) {       int sum = check(m, uan, c0, x);       if (minsum > sum) minsum = sum;     }     printf( %d n , minsum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     --n;     int right, left, down, up;     right = left = down = up = n / 4;     n = n - up * 4;     if (n != 0) {       ++right;       --n;     }     if (n != 0) {       ++down;       --n;     }     if (n != 0) {       ++left;       --n;     }     if (n != 0) {       ++up;       --n;     }     int centerx = 0, centery = 0;     cout << centerx <<     << centery << endl;     for (int i = 0; i < right; ++i) {       cout << centerx + i + 1 <<     << centery << endl;     }     for (int i = 0; i < left; ++i) {       cout << centerx - i - 1 <<     << centery << endl;     }     for (int i = 0; i < up; ++i) {       cout << centerx <<     << centery + i + 1 << endl;     }     for (int i = 0; i < down; ++i) {       cout << centerx <<     << centery - i - 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int a[n];       long long int freq[200001] = {0};       for (long long int i = 0; i < n; i++) {         cin >> a[i];         freq[a[i]]++;       }       sort(a, a + n);       long long int present = 1;       long long int ans = 1;       long long int expected = 0;       long long int count = 0;       int flag = 0;       while (count < n) {         expected = a[count];         present += freq[a[count]] - 1;         if (present >= expected) {           ans = present + 1;         }         count += freq[a[count]];         present += 1;       }       cout << ans << endl;     }     return 0;   }


// Template begins   #include <iostream>   #include <algorithm>   #include <vector>   #include <set>   #include <stdio.h>   #include <stack>   #include <math.h>   #include <complex>      using namespace std;   #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)   #define ll long long   #define endl   n    #define lb lower_bound   #define ub upper_bound   #define fo(i,a,b) for(i=a;i<=b;i++)   #define all(v) (v).begin(),(v).end()   #define sort0(v) sort(all(v))   #define lbb(a,b,arr,x) lower_bound(arr+a,arr+b+1,x)-arr   #define ubb(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-arr   #define freq(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-lower_bound(arr+a,arr+b+1,x)   typedef pair<int,int> pii;   typedef pair<ll,ll> pll;   #define d0(x) cout<<(x)<<      #define d1(x) cout<<(x)<<endl   #define d2(x,y) cout<<(x)<<   <<(y)<<endl   #define d3(x,y,z) cout<<(x)<<   <<(y)<<   <<(z)<<endl   #define d4(a,b,c,d) cout<<(a)<<   <<(b)<<   <<(c)<<   <<(d)<<endl   #define d5(a,b,c,d,e) cout<<(a)<<   <<(b)<<   <<(c)<<   <<(d)<<   <<(e)<<endl   #define d6(a,b,c,d,e,f) cout<<(a)<<   <<(b)<<   <<(c)<<   <<(d)<<   <<(e)<<   <<(f)<<endl   #define max3(a,b,c) max(max((a),(b)),(c))   #define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))   #define ss second   #define ff first   #define pb push_back   #define mp make_pair   #define printp(x) cout << x.ff <<     << x.ss << endl   template<class T> ostream& operator<<(ostream &os, vector<T> V) {       for(auto v : V) os << v <<    ;       return cout <<   ;   }   template<class T> ostream& operator<<(ostream &os, set<T> S){       for(auto s:S) os<<s<<   ;       return cout <<   ;   }   template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {       return os << P.first <<     << P.second;   }   const ll mod=1e9+7;   #define inf 9999999999999      ll inv(ll i){if(i==1) return 1;return (mod-((mod/i)*inv(mod%i))%mod)%mod;}      ll gcd(ll a,ll b){ if (b==0) return a;return gcd(b,a%b);}      ll pwr(ll a, ll b) {a %= mod; ll res = 1;while (b > 0) {if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1;}return res;}   //Template ends      ll a[200010], t[800010],T[800010];   int n;   void buildm(int v, int tl, int tr){       if(tl>tr) return;       if(tl==tr){           t[v] = a[tl];           return;       }              int tm = (tl+tr)/2;       buildm(2*v,tl,tm);       buildm(2*v+1,tm+1,tr);              t[v] = min(t[2*v], t[2*v+1]);   }      void buildM(int v, int tl, int tr){       if(tl>tr) return;       if(tl==tr){           T[v] = a[tl];           return;       }              int tm = (tl+tr)/2;       buildM(2*v,tl,tm);       buildM(2*v+1,tm+1,tr);              T[v] = max(T[2*v], T[2*v+1]);   }      ll minq(int v, int tl, int tr, int l, int r){       if(l>tr or r<tl) return 1000000000;              if(tl==l and tr==r){           return t[v];       }              int tm = (tl+tr)/2;       return min(minq(2*v,tl,tm,l,min(r,tm)),minq(2*v+1,tm+1,tr,max(tm+1,l),r));   }      ll minn(int l,int r){       return minq(1,1,n,l,r);   }         ll maxq(int v, int tl, int tr, int l, int r){       if(l>tr or r<tl) return 0;              if(tl==l and tr==r){           return T[v];       }              int tm = (tl+tr)/2;       return max(maxq(2*v,tl,tm,l,min(r,tm)),maxq(2*v+1,tm+1,tr,max(tm+1,l),r));   }      ll maxx(int l,int r){       return maxq(1,1,n,l,r);   }      int main(){       fio;       int t0,i;       cin >> t0;       while(t0--){           cin >> n;           for(i=1;i<=n;i++) cin >> a[i];           buildm(1,1,n);           buildM(1,1,n);                      ll curr = 0;              bool z = false;                      for(i=1;i<=n;i++){               curr = max(curr, a[i]);                              int l = i+1;               int r = n-1;                              while(l<=r){                   int mid = (l+r)/2;                   ll val1 = minn(i+1,mid);                   ll val2 = maxx(mid+1,n);                                      //d5(i,mid,val1,val2,curr);                                      if(val1 == val2 and val1 == curr){                       z = true;                       d1( YES );                       d3(i,mid-i,n-mid);                       break;                   }                                      if(val1 < curr or (val1 == curr and val2 < curr)){                       r = mid - 1;                   }                   else{                       l = mid + 1;                   }               }                              if(z) break;           }                      if(z){               continue;           }           else{               d1( NO );           }       }   }


#include <bits/stdc++.h>   const int N = 65550;   int ru[N], sum[N];   int n;   int s[N], t[N], cc = 0;   int main() {     int i;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d%d , &ru[i], &sum[i]);     for (i = 0; i < n; i++) {       int now = i;       while (ru[now] == 1) {         cc++;         s[cc] = now;         t[cc] = sum[now];         ru[now]--;         ru[sum[now]]--;         sum[sum[now]] ^= now;         now = sum[now];       }     }     printf( %d n , cc);     for (i = 1; i <= cc; i++) printf( %d %d n , s[i], t[i]);     return 0;   }


#include <bits/stdc++.h>   int a[200010];   int main() {     long long ans = 0;     int m = 0, n;     scanf( %d n , &n);     for (int i = 1; i <= n; i++) {       int a1, b1, a2, b2;       scanf( %d%d%d%d n , &a1, &b1, &a2, &b2);       if (a1 + b1 >= a2 + b2) {         a[++m] = a1 + b1;         a[++m] = a2 + b2;         ans = ans + a1 + a2;       } else if (a1 > b2)         ans += a1 - b2;       else if (a2 < b1)         ans += a2 - b1;     }     std::sort(a + 1, a + m + 1);     for (int i = 1; i <= m; i++)       if (i & 1) ans -= a[i];     printf( %I64d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 9;   const int MAX = 2e2 + 9;   const double ep = 1e-6;   const int mod = 998244353;   const int INF = 0x3f3f3f3f;   const double inf = 1e20;   const double pi = acos(-1);   vector<int> vec[maxn];   int n, m, k, d[maxn], cnt1, ans[maxn], tot;   bool vis[maxn];   bool solve1() {     queue<int> q;     cnt1 = 0;     for (int i = (1); i <= (n); ++i) {       if (d[i] < k) q.push(i), vis[i] = 1;     }     while (!q.empty()) {       int p = q.front();       q.pop();       cnt1++;       if (d[p] == k - 1) {         ans[tot = 1] = p;         bool ju = 0;         for (int i : vec[p]) {           if (d[i] < k - 1) continue;           for (int j : vec[p]) {             if (i == j) break;             if (d[j] < k - 1) continue;             auto k = lower_bound(vec[j].begin(), vec[j].end(), i);             if (k == vec[j].end() || (*k) != i) {               ju = 1;               break;             }           }           if (ju) break;           ans[++tot] = i;         }         if (!ju && tot == k) {           puts( 2 );           for (int i = (1); i <= (k); ++i) printf( %d  , (ans[i]));           puts(  );           return 1;         }       }       d[p] = 0;       for (int to : vec[p]) {         d[to]--;         if (vis[to]) continue;         if (d[to] < k) {           vis[to] = 1;           q.push(to);         }       }     }     if (n - cnt1 < k) return 0;     printf( %d %d n , (1), (n - cnt1));     for (int i = (1); i <= (n); ++i)       if (!vis[i]) printf( %d  , (i));     puts(  );     return 1;   }   void solve() {     scanf( %d%d%d , &n, &m, &k);     for (int i = (1); i <= (n); ++i) d[i] = 0, vis[i] = 0, vec[i].clear();     for (int i = (1); i <= (m); ++i) {       int u, v;       scanf( %d%d , &(u), &(v));       vec[u].emplace_back(v);       vec[v].emplace_back(u);       d[u]++;       d[v]++;     }     if (1ll * k * (k - 1) / 2 > m) {       puts( -1 );       return;     }     for (int i = (1); i <= (n); ++i) sort(vec[i].begin(), vec[i].end());     if (solve1()) return;     puts( -1 );   }   int main() {     int T = 1;     scanf( %d , &(T));     while (T--) solve();   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   int main() {     long long p, k, rem;     cin >> p >> k;     v.push_back(-p / k);     for (int i = 0;; i++) {       for (long long x = v.back() / k - 1; x <= v.back() / k + 1; x++) {         if (v.back() - x * k >= 0 && v.back() - x * k < k) {           v.push_back(-x);           break;         }       }       if (v[v.size() - 1] * k + v[v.size() - 2] < k && v.back() < k &&           v.back() >= 0)         break;     }     while (v.back() == 0) v.pop_back();     v.push_back(0);     cout << v.size() << endl;     for (int i = 0; i < v.size(); i++) {       if (i)         cout << v[i] * k + v[i - 1] <<    ;       else         cout << v[i] * k + p <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 55;   int x[MAX];   int main() {     int n;     cin >> n;     double sum = 0;     int a[n + 1];     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n, greater<int>());     for (int i = 0; i < n; i++) {       if (i % 2 == 0)         sum += a[i] * a[i];       else         sum -= a[i] * a[i];     }     cout << setprecision(11) << fixed << sum * 3.1415926536;     return 0;   }