#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m, k;     cin >> n >> m >> k;     long long p[m];     for (long long int i = 0; i < m; i++) cin >> p[i];     sort(p, p + m);     long long an = 0, x = 0, c = 0, cp = 1;     while (1) {       long long y = x, pg = ceil((long double)(p[x] - x) / (k));       while (y < m && ceil((long double)(p[y] - x) / (k)) == pg) y++;       if (y == m) {         cout << an + 1;         return;       }       an++;       x = y;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long TESTS = 1;     while (TESTS--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int requestNum;     cin >> requestNum;     vector<pair<int, pair<int, int>>> vect(requestNum);     for (int i = 0; i < requestNum; i++) {       int num, money;       cin >> num >> money;       vect.push_back(make_pair(money, make_pair(num, i + 1)));     }     sort(vect.rbegin(), vect.rend());     int tablesNum;     cin >> tablesNum;     vector<pair<int, int>> maxPeople(tablesNum);     for (int i = 0; i < tablesNum; i++) {       cin >> maxPeople[i].first;       maxPeople[i].second = i + 1;     }     sort(maxPeople.begin(), maxPeople.end());     vector<bool> tablesFull(tablesNum, false);     long long int totalMoney = 0;     vector<pair<long, long>> result;     for (int i = 0; i < requestNum; i++) {       for (int j = 0; j < tablesNum; j++) {         if (vect[i].second.first <= maxPeople[j].first && !tablesFull[j]) {           result.push_back(make_pair(vect[i].second.second, maxPeople[j].second));           totalMoney += vect[i].first;           tablesFull[j] = true;           break;         }       }     }     cout << result.size() <<     << totalMoney << endl;     for (int i = 0; i < result.size(); i++) {       cout << result[i].first <<     << result[i].second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 5, inf = 1e18, mod = 1e9 + 7;   const double PI = 3.1415926536;   int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   bool is_prime(long long n) {     for (long long i = 2; i * i <= n; ++i) {       if (n % i == 0) {         return false;       }     }     return true;   }   inline long long getPow(long long a, long long b) {     long long res = 1ll, tp = a;     while (b) {       if (b & 1ll) {         res *= tp;       }       tp *= tp;       b >>= 1ll;     }     return res;   }   long long vec_mult(const pair<long long, long long> &t1,                      const pair<long long, long long> &t2,                      const pair<long long, long long> &t3) {     const long long &x1 = t1.first, y1 = t1.second;     const long long &x2 = t2.first, y2 = t2.second;     const long long &x3 = t3.first, y3 = t3.second;     return ((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1));   }   void ok() {     cout <<  YES  << endl;     exit(0);   }   void no() {     cout <<  NO  << endl;     exit(0);   }   inline long long nxt() {     long long x;     cin >> x;     return x;   }   long long otr(long long num) {     long long cur = 0;     long long ct = 1;     while (num) {       cur += ct * (9 - num % 10);       num /= 10;       ct *= 10;     }     return cur;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     long long l = nxt(), r = nxt();     long long t = 1ll;     long long ans = -1;     while (t <= r) {       long long left = max(l, t);       long long right = min(r, 10ll * t - 1);       while (right - left > 2) {         long long len = (right - left + 1) / 3;         long long t1 = left + len;         long long t2 = right - len;         if (t1 * otr(t1) >= t2 * otr(t2)) {           right = t2;         } else {           left = t1;         }       }       while (left <= right) {         ans = max(ans, left * otr(left));         left++;       }       t *= 10ll;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void faster() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   string s, x, t, ans;   long long q, n, a[456789], b[456789], sum, prefa[456789], prefb[456789], k, l,       r, mx;   bool ok;   void dii() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     k = 1;     for (int i = 1; i <= n; i++) {       if (a[i] <= 2 * a[i - 1]) {         k++;       } else {         k = 1;       }       if (k > mx) {         mx = k;       }     }     cout << mx;   }   int main() {     faster();     q = 1;     while (q--) {       dii();     }     return 0;   }


#include <bits/stdc++.h>   const int INF = 1 << 29;   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     ;     int n;     std::cin >> n;     std::vector<int> v(n);     for (int &it : v) std::cin >> it;     int alice = v[0];     int sum = std::accumulate(v.begin(), v.end(), 0);     int target = sum / 2 + 1;     std::vector<int> ans;     ans.push_back(1);     int cur = alice;     for (int i = 0; i < n; i++) {       if (alice < v[i] * 2) continue;       cur += v[i];       ans.push_back(i + 1);       if (cur >= target) break;     }     if (cur < target) {       std::cout << 0;       exit(0);     } else {       std::cout << ans.size() <<   n ;       for (int it : ans) std::cout << it <<    ;     }     return 0;   }


#include <bits/stdc++.h>   void dfs(int64_t node, int64_t from,            const std::vector<std::vector<int64_t> > &g,            std::vector<bool> &visited, int64_t &count, bool &cycle, bool &self) {     if (visited[node]) {       return;     }     visited[node] = 1;     ++count;     for (int64_t p = 0; p < g[node].size(); p++) {       int64_t u = g[node][p];       if (u == from) {         continue;       } else if (u == node) {         self = true;       } else if (visited[u]) {         cycle = true;       } else {         dfs(u, node, g, visited, count, cycle, self);       }     }     return;   }   int main() {     const int64_t MOD = 1000000007;     int64_t n;     scanf( %lld , &n);     std::vector<std::vector<int64_t> > g(2 * n);     for (int64_t p = 0; p < n; p++) {       int64_t x, y;       scanf( %lld %lld , &x, &y);       --x;       --y;       g[x].push_back(y);       g[y].push_back(x);     }     std::vector<bool> visited(2 * n, false);     int64_t total(1);     for (int64_t p = 0; p < 2 * n; p++) {       if (visited[p]) {         continue;       }       int64_t count(0);       bool cycle(false), self(false);       dfs(p, -1, g, visited, count, cycle, self);       if (self) {         count = 1;       } else if (cycle) {         count = 2;       }       total *= count;       total %= MOD;     }     printf( %lld n , total);     return 0;   }


#include <bits/stdc++.h>   const int N = 1010, M = 2010;   int las[M], nxt[M], to[M], cnt;   int l[M], r[M], siz[M], mx[N][N], f[N];   inline void add(int u, int v) {     cnt++;     to[cnt] = v;     nxt[cnt] = las[u];     las[u] = cnt;   }   int n, m;   inline void fmin(int &a, int b) {     if (a > b) a = b;   }   inline void fmax(int &a, int b) {     if (a < b) a = b;   }   void dfs(int now) {     int i;     siz[now] = now != 1;     if (las[now]) l[now] = n, r[now] = 0;     for (i = las[now]; i; i = nxt[i])       dfs(to[i]), siz[now] += siz[to[i]], fmin(l[now], l[to[i]]),           fmax(r[now], r[to[i]]);     fmax(mx[l[now]][r[now]], siz[now]);   }   int main() {     int i, j, x;     scanf( %d , &n);     scanf( %d , &m);     for (i = 2; i <= m; i++) scanf( %d , &x), add(x, i);     for (i = 1; i <= n; i++) scanf( %d , &x), l[x] = r[x] = i;     dfs(1);     cnt = 0;     memset(las, 0, sizeof las);     scanf( %d , &m);     for (i = 2; i <= m; i++) scanf( %d , &x), add(x, i);     for (i = 1; i <= n; i++) scanf( %d , &x), l[x] = r[x] = i;     dfs(1);     for (i = 1; i <= n; i++)       for (j = 1; j <= i; j++)         if (mx[j][i]) fmax(f[i], f[j - 1] + mx[j][i]);     printf( %d n , f[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n, ans[N], an;   struct edge {     int to, nx, id, dl;   } ee[N];   int eq[N], en = 1;   void dfs(int d) {     for (int j = eq[d], k; k = ee[j].to, j; j = ee[j].nx)       if (!ee[j].dl) {         ee[j].dl = 1;         dfs(k);         ans[--an] = ee[j].id;       }   }   int main() {     scanf( %d , &n);     if (n & 1) {       printf( -1 n );       return 0;     }     for (int x = 0, t1, t2; x < n; x++) {       t1 = (x * 2 + 0) % n;       t2 = (x * 2 + 1) % n;       ee[++en] = (edge){((t1) / 2 + 1), eq[((x) / 2 + 1)], x, 0},       eq[((x) / 2 + 1)] = en;     }     an = n;     dfs(1);     for (int s = 0; s < n; s++)       if (ans[s] == 0) {         for (int i = 0; i < n; i++) printf( %d  , ans[(s + i) % n]);         printf( 0 n );         return 0;       }   }


#include <bits/stdc++.h>   using namespace std;   void _print(long long t) { cerr << t; }   void _print(int t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long t) { cerr << t; }   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<  , ;     _print(p.second);     cerr <<  } ;   }   template <class T>   void _print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(unordered_map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(list<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tc = 0, T;     cin >> T;     while (++tc <= T) {       int N;       cin >> N;       cout << (int)sqrt(N) + (int)cbrt(N) - (int)sqrt((int)cbrt(N)) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const double pi = acos(-1);   const double EPS = 1e-9;   long long binpowmod(long long a, long long b) {     a %= MOD;     long long ret = 1;     while (b) {       if (b & 1) ret = ret * a % MOD;       a = a * a % MOD;       b >>= 1;     }     return ret % MOD;   }   long long gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   const int N = 1 << 18;   const int E = N * 2;   bool good(long long n) {     long long t = n;     int sumofdigits = 0;     while (n) {       sumofdigits += n % 10;       n /= 10;     }     return (gcd(t, sumofdigits) > 1);   }   int n, m, ans;   vector<vector<int> > a;   bool good(int i, int j) {     for (int k = 0; k < m; ++k) {       if (a[i][k] != a[j][k]) return false;     }     return true;   }   void solveit(int l = 0, int r = n - 1, int c = 1) {     int len = r - l + 1;     if (len % 2) return;     int i = l, j = r;     while (i < j) {       if (!good(i, j)) return;       i++;       j--;     }     ans = min(ans, n / (1 << c));     int mid = (l + r) / 2;     solveit(l, mid, c + 1);     solveit(mid + 1, r, c + 1);   }   void solve() {     cin >> n >> m;     ans = n;     a.assign(n, vector<int>(m));     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) cin >> a[i][j];     solveit();     cout << ans <<   n ;   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tc = 1;     while (tc--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     scanf( %d%d , &n, &k);     long long ans1 = 1, ans2 = 1;     for (int i = 1; i <= k - 1; i++) ans1 = ans1 * k % 1000000007;     for (int i = 1; i <= n - k; i++) ans2 = ans2 * (n - k) % 1000000007;     printf( %I64d n , ans1 * ans2 % 1000000007);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 25, mod = 1e9 + 7;   int a[N][N], used[N][N], cur, first, n, m, k;   long long ans;   int count(int x) {     int ans = 0;     for (; x; x -= x & -x) ans++;     return ans;   }   void dfs(int x, int y) {     if (x == n) {       int p = count(cur & ~first), q = count(((1 << k) - 1) & ~first);       long long curans = 1;       while (p--) {         curans = (curans * q) % mod;         q--;       }       ans = (ans + curans) % mod;       return;     }     int nx = x, ny = y + 1;     if (ny == m) {       nx++;       ny = 0;     }     if (a[x][y]) {       dfs(nx, ny);       return;     } else {       bool flag = true;       int can = (1 << k) - 1;       can &= ~used[x][y];       for (int i = 0; (1 << i) <= can; i++) {         if (!((can >> i) & 1)) continue;         bool preused[N][N], preusedcur;         preusedcur = true;         memset(preused, false, sizeof(preused));         if (!((cur >> i) & 1)) {           if (flag)             flag = false;           else             continue;           preusedcur = false;         }         cur |= 1 << i;         for (int px = x; px < n; px++)           for (int py = y; py < m; py++) {             if ((used[px][py] >> i) & 1)               preused[px][py] = true;             else               used[px][py] |= 1 << i;           }         dfs(nx, ny);         if (!preusedcur) cur &= ~(1 << i);         for (int px = x; px < n; px++)           for (int py = y; py < m; py++) {             if (!preused[px][py]) used[px][py] &= ~(1 << i);           }       }     }   }   int main() {     scanf( %d%d%d , &n, &m, &k);     if (n + m - 1 > k) {       printf( 0 n );       return 0;     }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         scanf( %d , &a[i][j]);         if (a[i][j]) {           first |= 1 << a[i][j] - 1;           if ((used[i][j] >> a[i][j] - 1) & 1) {             printf( 0 n );             return 0;           }           for (int r = 0; r < n; r++)             for (int c = 0; c < m; c++) {               if (r <= i && c <= j || r >= i && c >= j)                 used[r][c] |= 1 << a[i][j] - 1;             }         }       }     cur = first;     dfs(0, 0);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int p1, p2, p3, p4, a, b;     cin >> p1 >> p2 >> p3 >> p4 >> a >> b;     int m = min(min(min(p1, p2), p3), p4);     cout << max(0, min(b + 1, m) - a) << endl;     return 0;   }


#include <bits/stdc++.h>   const int inf = (1 << 30) - 1;   const double eps = 1e-9;   using namespace std;   int a[111111], n, k, mx = 0, aa;   long long s[111111];   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];     for (int i = 1; i <= n; i++) {       int l = 1, r = i;       while (r > l) {         int m = (l + r) / 2;         long long ss = s[i] - s[m - 1];         if (1ll * a[i] * (i - m + 1) - ss > k)           l = m + 1;         else           r = m;       }       if (i - r + 1 > mx) {         mx = i - r + 1;         aa = a[i];       }     }     cout << (mx) <<    ;     cout << (aa) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int pr[] = {2, 3, 5, 7, 11, 13, 17, 19};   int big[50000005];   int c[10];   int ans[10100];   int main() {     int k;     scanf( %d , &k);     big[1] = 0;     for (int i = 0; i < 7; i++) big[pr[i]] = i + 1;     for (int i = 2; i <= 2 * k * k; i++) {       if (big[i] == 0) continue;       for (int j = 0; j < 7; j++) {         if (i * pr[j] <= 2 * k * k) {           big[i * pr[j]] = max(big[i], j + 1);         }       }       for (int j = big[i] - 1; j < 7; j++) c[j]++;     }     for (int j = 0; j < 7; j++)       if (c[j] >= k) {         int sz = 0;         for (int i = 2 * k * k; i >= 0; i--)           if (big[i] != 0 && big[i] - 1 <= j &&               big[i / pr[big[i] - 1]] - 1 < big[i] - 1) {             ans[sz++] = i;             if (sz == k) break;           }         if (sz < k) continue;         for (int i = sz - 1; i >= 0; i--) printf( %d  , ans[i]);         printf(  n );         return 0;       }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e7 + 5;   int s[maxn];   int a[maxn];   int main() {     int n;     scanf( %d , &n);     long long ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &s[i]);     }     sort(s + 1, s + n + 1);     for (int i = 1; i <= n / 2; i++) {       a[i] = s[i] + s[n + 1 - i];       ans += a[i] * a[i];     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-9;   long long Power(long long a, long long b) {     if (b == 0) return 1;     long long p = Power(a, b / 2);     p = (p * p);     if (b & 1) {       p = (p * a);     }     return p;   }   long long Gcd(long long a, long long b) {     if (b == 0) return a;     if (a < b) return Gcd(b, a);     return Gcd(b, a % b);   }   void Solve() {     int n, m;     long long l;     cin >> n >> m >> l;     vector<long long> arr(n), seg(n, -1);     for (int i = 0; i < n; i++) cin >> arr[i];     int curr = 0, prev = -1;     for (int i = 0; i < n; i++) {       if (arr[i] > l) {         seg[i] = 0;         if (prev == -1) {           curr++;         }         prev = 0;       } else {         prev = -1;         seg[i] = -1;       }     }     while (m--) {       int t;       cin >> t;       if (t == 0) {         cout << curr <<   n ;       } else {         int p;         long long d;         cin >> p >> d;         p--;         arr[p] += d;         if (seg[p] == -1 && arr[p] > l) {           seg[p] = 0;           if (p == 0) {             if (p + 1 < n && seg[p + 1] == -1) {               curr++;             } else if (n == 1) {               curr++;             }           } else if (p == n - 1) {             if (p - 1 >= 0 && seg[p - 1] == -1) {               curr++;             } else if (n == 1) {               curr++;             }           } else {             if (seg[p - 1] == 0 && seg[p + 1] == 0) {               curr--;             } else if (seg[p - 1] == -1 && seg[p + 1] == -1) {               curr++;             }           }         }       }     }   }   int main() {     int t = 1;     while (t--) {       Solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e4 + 5;   char s[N];   int dp[10][N];   int ans[N];   int len;   int dfs(int num, int idx) {     if (~dp[num][idx]) return dp[num][idx];     if (idx == len)       return 1;     else if (idx > len)       return 0;     int &ret = dp[num][idx];     ret = dfs(num ^ 1, idx + num);     bool flag = false;     for (int i = idx; i < idx + num; ++i) {       if (s[i] != s[i + num]) {         flag = true;         break;       }     }     if (flag) {       ret = max(ret, dfs(num, idx + num));     }     return ret;   }   const int B = 333;   int cal(char a, char b, char c) { return a * B * B + b * B + c; }   int cal(char a, char b) { return a * B * B + b * B; }   void prt(int x) {     printf( %c , x / (B * B));     printf( %c , x % (B * B) / B);     if (x % B) {       printf( %c , x % B);     }     puts(  );   }   int main() {     while (~scanf( %s , s)) {       memset(dp, -1, sizeof(dp));       int cnt = 0;       len = strlen(s);       for (int i = len - 2; i >= 5; --i) {         if (dfs(2, i) == 1) {           ans[cnt++] = (cal(s[i], s[i + 1]));         }         if (dfs(3, i) == 1) {           ans[cnt++] = (cal(s[i], s[i + 1], s[i + 2]));         }       }       sort(ans, ans + cnt);       cnt = unique(ans, ans + cnt) - ans;       printf( %d n , cnt);       for (int i = 0; i < cnt; ++i) {         prt(ans[i]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const int mod = 1e9 + 7;   const int N = 100 + 10;   inline int add(int x, int y) {     x += y;     if (x >= mod) x -= mod;     return x;   }   inline int mul(int x, int y) {     x = (1LL * x * y) % mod;     return x;   }   vector<pair<int, int> > G[N];   int dp[N][N][30][2];   int f(int i, int j, int last, int turn) {     int &ret = dp[i][j][last][turn];     if (~ret) return ret;     ret = 0;     if (turn == 1) {       for (auto it : G[i]) {         int nxt = it.first;         int ed = it.second;         if (ed >= last) {           int x = f(nxt, j, ed, 0);           if (x == 0) return ret = 1;         }       }     } else {       for (auto it : G[j]) {         int nxt = it.first;         int ed = it.second;         if (ed >= last) {           int x = f(i, nxt, ed, 1);           if (x == 0) return ret = 1;         }       }     }     return ret;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     memset(dp, -1, sizeof(dp));     int n, m;     cin >> n >> m;     for (int i = 0; i <= m - 1; ++i) {       int u, v;       cin >> u >> v;       char c;       cin >> c;       int x = c -  a ;       G[u].push_back({v, x});     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         int curr = f(i, j, 0, 1);         if (curr == 0)           cout <<  B ;         else           cout <<  A ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;      const int N = 1e5 + 5;      struct query {    int i, type, l, r, k, p, x;   };      int n, m;   vector<int> a, _a;   query q[N];   int queryCnt;   int block_size;   int ans[N];   int freqA[N];   int freqL[N], freqR[N], freqV[N];      void increaseFreq(int f) {    freqR[f]++, freqL[f - 1]++, freqV[freqR[f] - 1] = f;   }      void decreaseFreq(int f) {    freqR[f]--, freqL[f - 1]--, freqV[freqR[f]] = f - 1;   }      void include(int i) {    increaseFreq(++freqA[a[i]]);   }      void remove(int i) {    decreaseFreq(freqA[a[i]]--);   }      void go(int& fromL, int& fromR, int toL, int toR) {    // debug() << name(fromL) name(fromR) name(toL) name(toR);    while (fromL > toL) include(--fromL);    while (fromR < toR) include(fromR++);    while (fromL < toL) remove(fromL++);    while (fromR > toR) remove(--fromR);   }      void update(int qi, int L, int R) {    if (L <= q[qi].p && q[qi].p < R) remove(q[qi].p);    a[q[qi].p] = q[qi].x;    if (L <= q[qi].p && q[qi].p < R) include(q[qi].p);   }      int answer(int k) {    vector<pair<int, int>> v;    for (int at = freqV[1]; at != 0; ) {     v.push_back({at, freqR[at] - freqL[at]});     at = freqV[freqR[at]];    }    reverse(v.begin(), v.end());        int ret = -1;    for (int l = 0, r = 0, cnt = 0; l < v.size(); cnt -= v[l++].second) {     r = max(l, r);     while (r < v.size() && cnt < k) cnt += v[r++].second;     if (cnt >= k) {      int _ret = v[r - 1].first - v[l].first;      ret = ret == -1 ? _ret : min(ret, _ret);     }    }       // debug() << name(k) name(v) name(ret);        return ret;   }      int main() {    scanf( %d %d , &n, &m);    _a.resize(n + 1);    for (int i = 1; i <= n; i++) scanf( %d , &_a[i]); a = _a;    for (int i = 1; i <= m; i++) {     q[i].i = i;     scanf( %d , &q[i].type);     if (q[i].type == 1) scanf( %d %d %d , &q[i].l, &q[i].r, &q[i].k);     else scanf( %d %d , &q[i].p, &q[i].x);     queryCnt += q[i].type == 1;    }        block_size = ceil(cbrt((long double)2 * n * n));        sort(q + 1, q + m + 1, [](const query& q1,const query& q2) {     int l1 = (q1.l - 1) / block_size, r1 = (q1.r - 1) / block_size;     int l2 = (q2.l - 1) / block_size, r2 = (q2.r - 1) / block_size;     auto p1 = make_pair(l1, r1);     auto p2 = make_pair(l2, r2);          if (q1.type == 1) {      if (q2.type == 1) return make_pair(p1, q1.i) < make_pair(p2, q2.i);      else return true;     } else {      if (q2.type == 1) return false;      else return q1.i < q2.i;     }    });        // for (int i = 1; i <= m; i++) debug() << name(i) name(q[i].type) name(q[i].i);        fill(ans, ans + N, -2);    fill(freqL, freqL + N, 1);    fill(freqR, freqR + N, 1);    freqR[0] = N;        pair<int, int> qp = {-1, -1};    int qAt;    int L = 1, R = 1;    for (int i = 1; i <= m && q[i].type == 1; i++) {     int ql = (q[i].l - 1) / block_size, qr = (q[i].r - 1) / block_size;     pair<int, int> _qp = {ql, qr};     if (qp != _qp) {      go(L, R, block_size * ql + 1, block_size * ql + 1);      a = _a;      qAt = queryCnt + 1;      qp = _qp;     }          while (qAt <= m && q[qAt].i < q[i].i) {      update(qAt, L, R);      qAt++;     }          go(L, R, q[i].l, q[i].r + 1);          // debug() << name(q[i].i);     ans[q[i].i] = answer(q[i].k);    }        for (int i = 1; i <= m; i++) if (ans[i] >= -1) printf( %d n , ans[i]);        return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<long long, pair<long long, long long> > stree[4000005];   char sa[1000005];   void build(long long node, long long start, long long end) {     if (start == end) {       stree[node].first = 0;       stree[node].second.first = 0;       stree[node].second.second = 0;       if (sa[start] ==  ( )         stree[node].second.first = 1;       else if (sa[start] ==  ) )         stree[node].second.second = 1;     } else {       long long mid = (start + end) / 2;       build(2 * node, start, mid);       build(2 * node + 1, mid + 1, end);       long long com =           min(stree[2 * node].second.first, stree[2 * node + 1].second.second);       long long left =           stree[2 * node].second.first + stree[2 * node + 1].second.first - com;       long long right =           stree[2 * node].second.second + stree[2 * node + 1].second.second - com;       stree[node].first = stree[2 * node].first + stree[2 * node + 1].first + com;       stree[node].second.first = left;       stree[node].second.second = right;     }   }   pair<long long, pair<long long, long long> > query(long long node,                                                      long long start,                                                      long long end, long long l,                                                      long long r) {     if (l > end || start > r) return make_pair(0, make_pair(0, 0));     if (l <= start && r >= end) return stree[node];     long long mid = (start + end) / 2;     pair<long long, pair<long long, long long> > p1 =         query(2 * node, start, mid, l, r);     pair<long long, pair<long long, long long> > p2 =         query(2 * node + 1, mid + 1, end, l, r);     long long a = min(p1.second.first, p2.second.second);     long long b = p1.second.first + p2.second.first - a;     long long c = p1.second.second + p2.second.second - a;     return make_pair(p1.first + p2.first + a, make_pair(b, c));   }   int main() {     string str;     cin >> str;     long long n, q;     n = str.length();     cin >> q;     for (long long i = 1; i <= n; i++) sa[i] = str[i - 1];     build(1, 1, n);     while (q-- != 0) {       long long x, y;       cin >> x >> y;       long long ans = 2 * query(1, 1, n, x, y).first;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t, ss, tt;     int bc;     vector<int> res;     cin >> bc >> s >> t;     ss = s;     tt = t;     sort(ss.begin(), ss.end());     sort(tt.begin(), tt.end());     if (ss != tt) {       cout << -1;       return 0;     }     if (!is_permutation(s.begin(), s.end(), t.begin())) return cout << -1, 0;     for (int i = 0; i < t.size(); ++i) {       for (int j = i; j < s.size(); ++j)         if (t[t.size() - i - 1] == s[j]) {           res.insert(res.end(), {(int)s.size(), j, 1});           reverse(s.begin() + j, s.end());           rotate(s.begin(), s.begin() + s.size() - 1, s.end());           break;         }     }     cout << res.size() <<   n ;     for (int i = 0; i < res.size(); i++) {       cout << res[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   typename T::value_type arr_sum(const T& v, int n) {     typename T::value_type sum = 0;     for (int i = 0; i < n; ++i) sum += v[i];     return sum;   }   struct Sync_stdio {     Sync_stdio() {       cin.tie(NULL);       ios_base::sync_with_stdio(false);     }   } _sync_stdio;   int n, m;   vector<string> w(n);   void print_square(int x1, int x2, int y1, int y2) {     for (int i = x1; i < x2 + 1; ++i) {       if (w[i][y1] !=  w ) {         w[i][y1] =  + ;       }       if (w[i][y2] !=  w ) {         w[i][y2] =  + ;       }     }     for (int i = y1; i < y2 + 1; ++i) {       if (w[x1][i] !=  w ) {         w[x1][i] =  + ;       }       if (w[x2][i] !=  w ) {         w[x2][i] =  + ;       }     }     for (auto i : w) {       cout << i <<   n ;     }     exit(0);   }   void check1(vector<pair<int, int> >& v) {     int max1 = -1, min1 = 100001;     int max2 = -1, min2 = 100001;     for (int i = 0; i < v.size(); ++i) {       max1 = max(max1, v[i].first);       min1 = min(min1, v[i].first);       max2 = max(max2, v[i].second);       min2 = min(min2, v[i].second);     }     int left = 0, up = 0, right = 0, down = 0;     for (int i = 0; i < v.size(); ++i) {       if (v[i].first == min1 && min2 < v[i].second && v[i].second < max2) {         up = 1;       }       if (v[i].first == max1 && min2 < v[i].second && v[i].second < max2) {         down = 1;       }       if (v[i].second == min2 && min1 < v[i].first && v[i].first < max1) {         left = 1;       }       if (v[i].second == max2 && min1 < v[i].first && v[i].first < max1) {         right = 1;       }       if (min1 < v[i].first && v[i].first < max1 && min2 < v[i].second &&           v[i].second < max2) {         cout << -1;         exit(0);       }     }     if (max1 == min1) {       up = 0;       down = 0;     }     if (min2 == max2) {       left = 0;       right = 0;     }     if (max1 - min1 == max2 - min2) {       print_square(min1, max1, min2, max2);     }     if (up && down && left && right) {       cout << -1;       exit(0);     }     int diff = (max1 - min1) - (max2 - min2);     if (diff > 0) {       if (!left && max2 + (min1 - max1) >= 0) {         print_square(min1, max1, max2 + (min1 - max1), max2);       }       if (!right && min2 + (max1 - min1) < m) {         print_square(min1, max1, min2, min2 + (max1 - min1));       }       if (!left && !right && max1 - min1 < m) {         print_square(min1, max1, 0, max1 - min1);       }     }     if (diff < 0) {       if (!up && max1 + (min2 - max2) >= 0) {         print_square(max1 + (min2 - max2), max1, min2, max2);       }       if (!down && min1 + (max2 - min2) < n) {         print_square(min1, min1 + (max2 - min2), min2, max2);       }       if (!up && !down && max2 - min2 < n) {         print_square(0, max2 - min2, min2, max2);       }     }     cout << -1;     exit(0);   }   int main() {     cin >> n >> m;     vector<pair<int, int> > v;     for (int i = 0; i < n; ++i) {       string t;       cin >> t;       w.push_back(t);       for (int j = 0; j < m; ++j) {         if (t[j] ==  w ) {           v.push_back({i, j});         }       }     }     check1(v);   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int q;     cin >> q;     while (q--) {       ll a, b, m;       cin >> a >> b >> m;       if (a == b) {         cout << 1 <<     << a <<   n ;         continue;       }       bool f = false;       for (int k = 1; k <= 49 && (1ll << (k - 1)) <= b / a; k++) {         ll t = (1ll << (k - 1)) * a;         ll b_tmp = b - t;         vector<ll> rs(k + 1);         rs[0] = a;         for (int cur = 1; cur <= k; cur++) {           ll pw = (cur == k) ? 1 : (1ll << (k - cur - 1));           rs[cur] = 1;           b_tmp -= pw * rs[cur];         }         if (b_tmp < 0) {           continue;         }         for (int cur = 1; cur <= k; cur++) {           ll pw = (cur == k) ? 1 : (1ll << (k - cur - 1));           ll now = min(m - 1, b_tmp / pw);           b_tmp -= pw * now;           rs[cur] += now;         }         if (b_tmp == 0) {           f = true;           cout << k + 1 <<    ;           vector<ll> ans;           for (int i = 0; i <= k; i++) {             ll cur = rs[i];             for (int j = i - 1; j >= 0; j--) {               cur += ans[j];             }             ans.push_back(cur);             cout << cur <<    ;           }           cout <<   n ;           break;         }       }       if (!f) cout << -1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(string s) {     string t = s;     reverse(t.begin(), t.end());     return (s == t);   }   int main() {     string s;     cin >> s;     int l = 0, r = ((int)s.length()) - 1;     set<char> all;     while (l < r) {       all.insert(s[l]);       all.insert(s[r]);       l++;       r--;     }     if (all.size() <= 1) {       cout <<  Impossible  << endl;       return 0;     }     for (int i = 0; i < ((int)s.length()) - 1; i++) {       string fi =   , se =   ;       for (int j = 0; j <= i; j++) fi += s[j];       for (int j = i + 1; j < (int)s.length(); j++) se += s[j];       if (check(se + fi) && (se + fi != s)) {         cout << 1 << endl;         return 0;       }     }     cout << 2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T MAX(T a, T b) {     if (a > b) return a;     return b;   }   template <class T>   inline T MIN(T a, T b) {     if (a < b) return a;     return b;   }   template <class T>   inline T ABS(T x) {     if (x < 0) return -x;     return x;   }   inline void OPEN(const string &s) {     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);   }   const static int inf = 1000000000;   int n, m, x, y, z, p;   int a, b;   vector<pair<int, int> > cek;   void rotate90(int &a, int &b, int &r, int &c) {     int tempa = a;     int tempb = b;     a = tempb;     b = r - tempa + 1;     swap(r, c);   }   void flipH(int &a, int &b, int &r, int &c) { b = c - b + 1; }   void rotate(int &a, int &b, int &r, int &c) {     int tempa = a;     int tempb = b;     a = c - tempb + 1;     b = tempa;     swap(r, c);   }   int main() {     scanf( %d%d%d%d%d%d , &n, &m, &x, &y, &z, &p);     for (int(i) = (0); (i) < (p); ++(i)) {       scanf( %d%d , &a, &b);       cek.push_back(make_pair(a, b));     }     x %= 4;     z %= 4;     y %= 2;     for (int(i) = (0); (i) < (cek.size()); ++(i)) {       a = cek[i].first;       b = cek[i].second;       int r = n, c = m;       for (int(j) = (0); (j) < (x); ++(j)) rotate90(a, b, r, c);       for (int(j) = (0); (j) < (y); ++(j)) flipH(a, b, r, c);       for (int(j) = (0); (j) < (z); ++(j)) rotate(a, b, r, c);       printf( %d %d n , a, b);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[] = {0, -1, 0, 1, -1, -1, 1, 1};   const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};   int n, pre = 0;   int a[1005], b[1005], p[1005];   vector<int> num;   bool vis[1005];   bool valid() {     int na = 0;     set<int> st;     for (int j = 0; j < n; ++j) {       if (a[j] == p[j]) ++na;       st.insert(p[j]);     }     return ((st.size()) == n && na == n - 1);   }   int main() {     int v;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     for (int i = 0; i < n; ++i) {       scanf( %d , &b[i]);       p[i] = b[i];       if (vis[p[i]]) v = p[i];       vis[p[i]] = 1;     }     vis[v] = 0;     for (int i = 0; i < n; ++i)       if (b[i] == v) num.push_back(i);     int tmp1 = p[num[0]], tmp2 = p[num[1]];     for (int j = 1; j <= n; ++j) {       if (!vis[j]) {         vis[j] = 1;         p[num[0]] = j;         for (int k = 1; k <= n; ++k) {           if (!vis[k]) {             vis[k] = 1;             p[num[1]] = k;             break;           }         }         if (valid())           break;         else {           vis[p[num[0]]] = vis[p[num[1]]] = 0;           p[num[0]] = tmp1;           p[num[1]] = tmp2;         }       }     }     for (int i = 0; i < n; ++i) printf( %d  , p[i]);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> g[100001], vc;   int judge(int x) {     vc.clear();     int need = x - g[0].size(), ans = 0;     for (int i = 1; i < 100001; i++) {       for (int j = 0; j < g[i].size(); j++) {         if (g[i].size() - j >= x) {           need--;           ans += g[i][j];         } else           vc.push_back(g[i][j]);       }     }     sort(vc.begin(), vc.end());     for (int i = 0; i < need; i++) ans += vc[i];     return ans;   }   int main() {     scanf( %d , &n);     int a, b;     for (int i = 0; i < n; i++) {       scanf( %d%d , &a, &b);       g[a].push_back(b);     }     for (int i = 1; i < 100001; i++) {       sort(g[i].begin(), g[i].end());     }     int l = g[0].size(), r = n;     while (l < r) {       int mid = (l + l + r) / 3, mmid = (l + r + r) / 3;       if (judge(mid) > judge(mmid)) {         if (l == mid)           break;         else           l = mid;       } else {         if (r == mmid)           break;         else           r = mmid;       }     }     int ans = 0x3f3f3f3f;     for (int i = l; i <= r; i++) ans = min(ans, judge(i));     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y, z;     int sum1 = 0, sum2 = 0, sum3 = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> y >> z;       sum1 += x;       sum2 += y;       sum3 += z;     }     if ((sum1 == 0) && (sum2 == 0) && (sum3 == 0)) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, j, n;   void solve() {     int n;     long long l;     cin >> n >> l;     long long a[n];     for (i = 0; i < n; i++) cin >> a[i];     ;     sort(a, a + n);     long long m = 2 * max(a[0], l - a[n - 1]);     for (i = 0; i < n - 1; i++) {       m = max(m, a[i + 1] - a[i]);     }     long double d = 1.0 * m / 2;     cout << setprecision(9) << d;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   const int maxd = 205;   struct Node {     int l, d;   } leg[maxn];   bool operator<(const Node &a, const Node &b) { return a.l > b.l; }   int n, tot[maxd], td = 0, md = 0;   int Solve(int st, int ed) {     int cnt = ed - st;     int res = td;     for (int i = md; i >= 0 && cnt > 0; i--) {       res -= min(cnt, tot[i]) * i;       cnt -= min(cnt, tot[i]);     }     return res;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> leg[i].l;     for (int i = 0; i < n; i++) cin >> leg[i].d;     for (int i = 0; i < n; i++) md = max(md, leg[i].d);     sort(leg, leg + n);     for (int i = 0; i < n; i++) {       tot[leg[i].d]++;       td += leg[i].d;     }     int p = 0;     int res = INT_MAX, tot_d = 0;     while (p < n) {       int p1 = p + 1;       while (p1 < n && leg[p1].l == leg[p].l) p1++;       p1--;       for (int i = p; i <= p1; i++) {         tot[leg[i].d]--;         td -= leg[i].d;       }       int tmp = tot_d + Solve(p, p1);       res = min(tmp, res);       for (int i = p; i <= p1; i++) tot_d += leg[i].d;       p = p1 + 1;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     register long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   const long long N = 1e5 + 10;   long long n, m, k, p;   long long h[N], a[N];   long long c[N];   struct node {     long long t, id;     bool operator<(const node& x) const { return t > x.t; }   };   priority_queue<node> q;   bool check(long long x) {     while (!q.empty()) q.pop();     memset(c, 0, sizeof c);     for (long long i = 1; i <= n; i++)       if (x - a[i] * m < h[i]) q.push((node){x / a[i], i});     for (long long i = 1; !q.empty() && i <= m; i++)       for (long long j = 1; !q.empty() && j <= k; j++) {         node u = q.top();         q.pop();         if (u.t < i) return 0;         ++c[u.id];         if (x + c[u.id] * p - a[u.id] * m < h[u.id])           q.push((node){(x + c[u.id] * p) / a[u.id], u.id});       }     return q.empty();   }   signed main() {     n = read(), m = read(), k = read(), p = read();     for (long long i = 1; i <= n; i++) h[i] = read(), a[i] = read();     long long l = 0, r = 1e15, ans;     while (l <= r) {       long long mid = l + r >> 1;       if (check(mid))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   struct data {     int idx, val;     bool operator<(const data &a1) const {       if (a1.val == val) {         return a1.idx < idx;       }       return val > a1.val;     }     data(int t, int w) : idx(t), val(w) {}   };   set<data> coastline;   set<data>::iterator it, it2;   int main() {     int N;     scanf( %d , &N);     string ans[N];     int a;     for (int i = 0; i < N; i++) {       scanf( %d , &a);       if (a == 0) {         int sz = coastline.size();         if (sz == 0) {           ans[i] =  0 ;         } else if (sz == 1) {           ans[i] =  1 popStack ;           it = coastline.begin();           ans[it->idx] =  pushStack ;         } else if (sz == 2) {           ans[i] =  2 popStack popQueue ;           it = coastline.begin();           ans[it->idx] =  pushQueue ;           it++;           ans[it->idx] =  pushStack ;           it++;         } else {           ans[i] =  3 popStack popQueue popFront ;           it = coastline.begin();           ans[it->idx] =  pushFront ;           it++;           ans[it->idx] =  pushQueue ;           it++;           ans[it->idx] =  pushStack ;           it++;         }         coastline.clear();       } else {         coastline.insert(data(i, a));       }     }     for (int i = 0; i < N; i++) {       if (ans[i].size() == 0) {         cout <<  pushBack  << endl;       } else         cout << ans[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   #define ll long long   #define mod 1000000007   using namespace std;      ll dp[10][200001];   string s =  abcdefghijklmnopqrstuvwxyz ;   ll findgcd(ll a, ll b) {       if (b == 0) {           return a;       }       return findgcd(b, a % b);   }      bool ispalindrome(string s) {       int n = s.length();       bool flag = true;       for (int i = 0; i < n / 2; i++) {           if (s[i] != s[n - 1 - i]) {               flag = false;               break;           }       }       return flag;   }      ll factorial(ll n) {       vector<ll> v(n + 1);       for (ll i = 0; i <= n; i++) {           if (i == 0 || i == 1) {               v[i] = 1;           }           else {               v[i] = (i * v[i - 1]) % mod;           }       }       return v[n];   }      void calculatedp() {       for (ll i = 0; i <= 9; i++) {           ll temp = 10 - i;           for (ll j = 0; j <= 200000; j++) {               if (j < temp) {                   dp[i][j] = 1;               }               else if (j == temp) {                   dp[i][j] = 2;               }               else {                   break;               }           }       }       dp[1][10] = 2;       for (ll i = 11; i <= 200000; i++) {           int temp1 = i - 10;           int temp2 = i - 9;           dp[0][i] = (dp[0][temp1] + dp[1][temp1]) % mod;           dp[1][i] = (dp[0][temp2] + dp[1][temp2]) % mod;       }       for (ll i = 2; i <= 9; i++) {           ll temp = 10 - i;           for (ll j = temp + 1; j <= 200000; j++) {               dp[i][j] = (dp[0][j - temp] + dp[1][j - temp]) % mod;           }       }   }      void solve() {       // ll m;       // cin >> s;       // cin >> m;       // ll ans = 0;       // for (int i = 0; i < s.length(); i++) {       //     ans = (ans + (dp[s[i] -  0 ][m])) % mod;       // }       // cout << ans <<   n ;       int n, k;       cin >> n >> k;          string ans =   ;          for (int i = 0 ; i < k ; i++) {           ans += s[i];           for (int j = i + 1 ; j < k ; j++) {               ans += s[i];               ans += s[j];           }       }          if (n < ans.size()) {           cout << ans.substr(0, n) << endl;       }       else {           int j = ans.length();           int i = 0;           while (j < n) {               ans += ans[i];               i++;               j++;           }              cout << ans << endl;       }   }   int main() {   #ifndef ONLINE_JUDGE       //for getting input from input.txt       freopen( input.txt ,  r , stdin);       //for writing output to output.txt       freopen( output.txt ,  w , stdout);   #endif       ios_base::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);       // calculatedp();       // for (int i = 0; i <= 10; i++) {       //     for (int j = 0; j <= 10; j++) {       //         cout << dp[i][j] <<    ;       //     }       //     cout <<   n ;       // }       int t;       t = 1;       // cin >> t;       while (t--) {           solve();       }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline int popcount(T t) {     if (std::numeric_limits<T>::digits <=         std::numeric_limits<unsigned int>::digits) {       return __builtin_popcount(t);     } else {       return __builtin_popcountll(t);     }   }   const long double EPS = 1e-8;   const long double PI = acosl(0.0) * 2;   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < int(n); ++i) cin >> a[i];     for (int i = 30; i >= 0; --i) {       vector<int> b;       int mask = (1 << i) - 1;       for (int x : a) {         if ((x >> i) & 1) {           b.push_back(x);           mask &= x;         }       }       if (!mask) {         cout << b.size() << endl;         for (int x : b) {           cout << x <<    ;         }         cout << endl;         return;       }     }     assert(false);   }   int main() {     ios_base::sync_with_stdio(false);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n1, n2, n3, n4;     long long ans;     unordered_map<char, int> m;     string s;     while (cin >> n1 >> n2 >> n3 >> n4) {       ans = 0;       m[ 1 ] = n1;       m[ 2 ] = n2;       m[ 3 ] = n3;       m[ 4 ] = n4;       cin >> s;       for (int i = 0; i < s.size(); i++) {         ans += m[s[i]];       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(double a, double b) { return a > b; }   int n;   double a[110], x, sum, ans;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lf , &a[i]);     sort(a, a + n, cmp);     ans = 0;     for (int i = 1; i <= n; i++) {       sum = 0;       for (int j = 0; j < i; j++) {         x = a[j];         for (int k = 0; k < i; k++) {           if (j != k) x *= 1 - a[k];         }         sum += x;       }       ans = max(sum, ans);     }     printf( %.12lf n , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long int a[200][3];   int main() {     ios ::sync_with_stdio(false);     cin.tie(0);     ;     long long int i, k, l, n, j;     cin >> n;     for (i = 0; i <= n - 1; i++) cin >> a[i][0] >> a[i][1];     cin >> j;     for (i = 0; i <= n - 1; i++)       if (j >= a[i][0] && j <= a[i][1]) {         cout << n - i << endl;         return 0;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, K;   string S;   int vis[5050][5050];   vector<pair<int, int>> nex[26];   void dfs(int cur, int mask) {     if (vis[cur][mask] || cur + 1 + mask > N) return;     vis[cur][mask] = 1;     int i;     nex[S[cur] -  a ].push_back({cur + 1, mask});     for (i = 0; i < (K); i++)       if (mask & (1 << i)) dfs(cur + (1 << i), mask ^ (1 << i));   }   void solve() {     int i, j, k, l, r, x, y;     string s;     cin >> S;     N = S.size();     while (1 << (K + 1) <= N) K++;     vector<pair<int, int>> now;     now.push_back({0, (1 << K) - 1});     while (now.size()) {       for (i = 0; i < (26); i++) nex[i].clear();       for (auto& n : now) dfs(n.first, n.second);       char c =  z  + 1;       for (i = 25; i >= 0; i--)         if (nex[i].size()) c =  a  + i;       if (c ==  z  + 1) break;       cout << c;       swap(now, nex[c -  a ]);     }     cout << endl;   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);     for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<double, double> get_vec_rotate(pair<double, double> nv, double fi) {     return make_pair(nv.first * cos(fi) - nv.second * sin(fi),                      nv.second * cos(fi) + nv.first * sin(fi));   }   pair<double, double> get_normal(pair<double, double> vec) {     double len = sqrt(vec.first * vec.first + vec.second * vec.second);     vec.first /= len;     vec.second /= len;     return vec;   }   pair<double, double> end_p(pair<double, double> start_p,                              pair<double, double> nv, double len) {     nv.first *= len;     nv.second *= len;     return make_pair(nv.first + start_p.first, nv.second + start_p.second);   }   double a, b, c, d;   pair<double, double> p, v, ToWrite;   pair<double, double> len_fi[7];   int main() {     cin >> p.first >> p.second >> v.first >> v.second >> a >> b >> c >> d;     v = get_normal(v);     len_fi[0].first = b;     len_fi[0].second = 0;     len_fi[1].first = a / 2;     len_fi[1].second = M_PI / 2;     len_fi[2].first = c / 2;     len_fi[2].second = M_PI / 2;     len_fi[3].first = sqrt(c * c + 4 * d * d) / 2;     len_fi[3].second = M_PI / 2 + atan(2 * d / c);     len_fi[4].first = sqrt(c * c + 4 * d * d) / 2;     len_fi[4].second = 3 * M_PI / 2 - atan(2 * d / c);     len_fi[5].first = c / 2;     len_fi[5].second = 3 * M_PI / 2;     len_fi[6].first = a / 2;     len_fi[6].second = 3 * M_PI / 2;     cout.precision(10);     for (int i = 0; i < 7; i++) {       ToWrite = end_p(p, get_vec_rotate(v, len_fi[i].second), len_fi[i].first);       cout << fixed << ToWrite.first <<     << ToWrite.second << endl;     }     return 0;   }


#include <bits/stdc++.h>   int T;   int n, m;   bool get() {     char ch = getchar();     while (ch !=  O  && ch !=  X ) ch = getchar();     return (ch ==  X );   }   int map[21][21], con[4001][2], top, cnt[4001], head[401], nxt[100001],       b[100001], k = 1, dis[4001], pre[4001];   char ans[41][41];   int q[4001], h, t;   void push(int s, int t) {     nxt[++k] = head[s];     head[s] = k;     b[k] = t;   }   bool iscut[4001], chosen[4001], lim[4001], good[4001][4001];   std::vector<int> vec[4001];   int Cnt;   int hash(int i, int j) { return (i - 1) * m + j; }   void dfs(int x, bool *vis) {     if (vis[x]) return;     ++Cnt;     vis[x] = 1;     for (int i = head[x]; i; i = nxt[i])       if (!chosen[i >> 1]) dfs(b[i], vis);   }   int main() {     scanf( %d , &T);     for (int fd = 1; fd <= T; fd++) {       scanf( %d%d , &n, &m);       int all = 0;       top = 0;       memset(chosen, 0, sizeof chosen);       memset(lim, 0, sizeof lim);       memset(head, 0, sizeof head);       k = 1;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) map[i][j] = get(), all += (!map[i][j]);       for (int i = 1; i < n; i++)         for (int j = 1; j <= m; j++)           if (!map[i][j] && !map[i + 1][j]) {             ++top;             con[top][0] = hash(i, j);             con[top][1] = hash(i + 1, j);             push(hash(i, j), hash(i + 1, j));             push(hash(i + 1, j), hash(i, j));           }       for (int i = 1; i <= n; i++)         for (int j = 1; j < m; j++)           if (!map[i][j] && !map[i][j + 1]) {             ++top;             con[top][0] = hash(i, j);             con[top][1] = hash(i, j + 1);             push(hash(i, j), hash(i, j + 1));             push(hash(i, j + 1), hash(i, j));           }       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++)           if ((i + j) % 2 == 0 && (i > 1 || j > 1)) lim[hash(i, j)] = 1;       memset(cnt, 0, sizeof cnt);       for (int i = 1; i <= top; i++) {         ++cnt[con[i][0]], ++cnt[con[i][1]];       }       bool cando = 1;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++)           if (lim[hash(i, j)] && cnt[hash(i, j)] <= 1 && !map[i][j]) {             cando = 0;           }       memset(good[0], 0, sizeof good[0]);       Cnt = 0;       dfs(1, good[0]);       if (Cnt < all) cando = 0;       if (!cando)         puts( NO );       else {         for (;;) {           memset(cnt, 0, sizeof cnt);           for (int i = 1; i <= top; i++)             if (!chosen[i]) {               if (lim[con[i][0]])                 ++cnt[con[i][0]];               else                 ++cnt[con[i][1]];               Cnt = 0;               chosen[i] = 1;               memset(good[i], 0, sizeof good[i]);               dfs(1, good[i]);               iscut[i] = (Cnt < all);               chosen[i] = 0;             }           for (int i = 1; i <= top; i++) vec[i].clear();           for (int i = 1; i <= top; i++)             if (chosen[i])               for (int j = 1; j <= top; j++)                 if (!chosen[j]) {                   int u = (lim[con[i][0]] ? con[i][0] : con[i][1]),                       v = (lim[con[j][0]] ? con[j][0] : con[j][1]);                   if (u == v || cnt[v] >= 3) {                     vec[j].push_back(i);                   }                   if (!iscut[j] || good[j][con[i][0]] != good[j][con[i][1]]) {                     vec[i].push_back(j);                   }                 }           h = t = 0;           for (int i = 1; i <= top; i++) {             dis[i] = 0x7f7f7f7f;             pre[i] = 0;             if (!chosen[i] && !iscut[i]) dis[i] = 0, q[++t] = i;           }           while (h < t) {             ++h;             for (int i = 0; i < vec[q[h]].size(); i++)               if (dis[vec[q[h]][i]] == 0x7f7f7f7f) {                 dis[vec[q[h]][i]] = dis[q[h]] + 1;                 q[++t] = vec[q[h]][i];                 pre[vec[q[h]][i]] = q[h];               }           }           int p = 0;           for (int i = 1; i <= top; i++) {             if (!chosen[i] && (cnt[con[i][0]] >= 3 || !lim[con[i][0]]) &&                 (cnt[con[i][1]] >= 3 || !lim[con[i][1]]) &&                 dis[i] != 0x7f7f7f7f) {               if (!p || dis[p] > dis[i]) p = i;             }           }           if (!p) break;           while (p) {             chosen[p] ^= 1;             p = pre[p];           }         }         Cnt = 0;         for (int i = 1; i <= top; i++) Cnt += (!chosen[i]);         if (Cnt != all - 1)           puts( NO );         else {           puts( YES );           for (int i = 1; i <= (n << 1); i++)             for (int j = 1; j <= (m << 1); j++) ans[i][j] =    ;           for (int i = 1; i <= n; i++)             for (int j = 1; j <= m; j++)               ans[(i << 1) - 1][(j << 1) - 1] = (map[i][j]) ?  X  :  O ;           for (int i = 1; i <= top; i++)             if (!chosen[i]) {               int u = con[i][0], v = con[i][1];               if (v == u + 1)                 ans[(((u - 1) / m + 1) << 1) - 1][((u - 1) % m + 1) << 1] =  O ;               else                 ans[(((u - 1) / m + 1) << 1)][(((u - 1) % m + 1) << 1) - 1] =  O ;             }           for (int i = 1; i < (n << 1); i++, putchar(  n ))             for (int j = 1; j < (m << 1); j++) putchar(ans[i][j]);         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int active;     set<int> prev, next;     node() : active(1) {}   };   int main() {     int n, k, m, i, j;     int a, b;     cin >> n >> m;     int cnt = 1;     set<int> sh;     set<int>::iterator it;     for (i = 0; i < n; i++) sh.insert(i);     node* graf = new node[n];     for (i = 0; i < m; i++) {       cin >> a >> b;       a--, b--;       if (graf[a].active == 0) continue;       if (graf[b].prev.size() == 0) sh.erase(b);       graf[a].next.insert(b);       graf[b].prev.insert(a);       while (sh.size() == 1) {         k = *sh.begin();         cnt++;         if (cnt == n) {           cout << i + 1 << endl;           return 0;         }         for (it = graf[k].next.begin(); it != graf[k].next.end(); it++) {           j = *it;           graf[j].prev.erase(k);           if (graf[j].prev.size() == 0) sh.insert(j);         }         sh.erase(k);         graf[k].active = 0;       }     }     cout << -1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 2e5 + 7;   struct Node {     long long x, y;   } node[maxn];   bool cmp(Node a, Node b) { return a.x < b.x; }   long long n, k;   long long len[maxn];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       cin >> n >> k;       for (int i = 0; i < n; i++) cin >> node[i].x;       for (int i = 0; i < n; i++) cin >> node[i].y;       sort(node, node + n, cmp);       long long tarl, tarr;       for (tarr = tarl = 0; tarr < n; tarr++) {         while (node[tarl].x < node[tarr].x - k) tarl++;         len[tarr] = tarr - tarl + 1;       }       long long ans = 0, Max = 0;       for (tarr = tarl = 0; tarr < n; tarr++) {         while (node[tarl].x < node[tarr].x - k) {           Max = max(Max, len[tarl]);           tarl++;         }         ans = max(Max + len[tarr], ans);       }       cout << ans << endl;       for (int i = 0; i < n; i++) len[i] = 0;     }   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC target( avx2 )   #pragma GCC optimization( unroll-loops )   #pragma GCC optimize( O2 )   constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};   constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};   constexpr long long INF = 1999999999999999997;   constexpr int inf = INT_MAX;   constexpr int MAXSIZE = int(1e6) + 5;   constexpr auto PI = 3.14159265358979323846L;   constexpr auto oo = numeric_limits<int>::max() / 2 - 2;   constexpr auto eps = 1e-6;   constexpr auto mod = 1000000007;   constexpr auto MOD = 1000000007;   constexpr auto MOD9 = 1000000009;   constexpr auto maxn = 100006;   template <typename T, size_t N>   int SIZE(const T (&t)[N]) {     return N;   }   template <typename T>   int SIZE(const T &t) {     return t.size();   }   string to_string(string s, int x1 = 0, int x2 = 1e9) {     return     + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) :   ) +    ;   }   string to_string(const char *s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(char c) { return string({c}); }   template <size_t N>   string to_string(bitset<N> &b, int x1 = 0, int x2 = 1e9) {     string t =   ;     for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1);          __iii__ <= __jjj__; ++__iii__) {       t += b[__iii__] +  0 ;     }     return     + t +    ;   }   template <typename A, typename... C>   string to_string(A(&v), int x1 = 0, int x2 = 1e9, C... coords);   int l_v_l_v_l = 0, t_a_b_s = 0;   template <typename A, typename B>   string to_string(pair<A, B> &p) {     l_v_l_v_l++;     string res =  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;     l_v_l_v_l--;     return res;   }   template <typename A, typename... C>   string to_string(A(&v), int x1, int x2, C... coords) {     int rnk = rank<A>::value;     string tab(t_a_b_s,    );     string res =   ;     bool first = true;     if (l_v_l_v_l == 0) res +=   n ;     res += tab +  [ ;     x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v));     auto l = begin(v);     advance(l, x1);     auto r = l;     advance(r, (x2 - x1) + (x2 < SIZE(v)));     for (auto e = l; e != r; e = next(e)) {       if (!first) {         res +=  ,  ;       }       first = false;       l_v_l_v_l++;       if (e != l) {         if (rnk > 1) {           res +=   n ;           t_a_b_s = l_v_l_v_l;         };       } else {         t_a_b_s = 0;       }       res += to_string(*e, coords...);       l_v_l_v_l--;     }     res +=  ] ;     if (l_v_l_v_l == 0) res +=   n ;     return res;   }   void dbgs() { ; }   template <typename Heads, typename... Tails>   void dbgs(Heads H, Tails... T) {     cout << to_string(H) <<   |  ;     dbgs(T...);   }   int main() {     int n, d;     cin >> n >> d;     int m;     cin >> m;     while (m--) {       int x, y;       cin >> x >> y;       if (x + y - d >= 0 && y + x - 2 * n + d <= 0 && y - x - d <= 0 &&           x - y - d <= 0)         cout <<  YES               <<   n ;       else {         cout <<  NO               <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int mxN = 2e5 + 10;   vector<int> a[mxN];   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       int cnt = 0, x;       cin >> x;       while (true) {         a[x].push_back(cnt);         if (!x) break;         x >>= 1;         cnt++;       }     }     int ans = 1e9;     for (int i = 0; i < mxN; i++) {       if (a[i].size() >= k) {         sort(a[i].begin(), a[i].end());         int cnt = 0;         for (int j = 0; j < k; j++) cnt += a[i][j];         ans = min(ans, cnt);       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1LL << 28;   const long long mod = 1LL;   vector<int> adj[30];   long long b_search(int val, int indx) {     int lo, hi, mid;     long long ans = 1e12;     lo = 0;     hi = (int)adj[indx].size() - 1;     while (lo <= hi) {       mid = (lo + hi) / 2;       if (adj[indx][mid] == val) return 0;       if (adj[indx][mid] < val)         lo = mid + 1;       else         hi = mid - 1;       ans = min(ans, (long long)abs(val - adj[indx][mid]));     }     return ans;   }   int main() {     int n, k, i, j;     long long l;     string s, c;     while (scanf( %d %d , &n, &k) == 2) {       for (i = 0; i < 26; i++) adj[i].clear();       cin >> s;       for (i = 0; i < s.length(); i++) {         adj[s[i] -  a ].push_back(i);       }       while (n--) {         l = 0;         cin >> c;         for (i = 0; i < c.length(); i++) {           if ((int)adj[c[i] -  a ].size() == 0)             l += (int)c.size();           else             l += b_search(i, c[i] -  a );         }         printf( %I64d n , l);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool umax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   long long dp[200009][2], a, par[200009];   priority_queue<long long> bg;   priority_queue<long long, vector<long long>, greater<long long> > sm;   void upd(long long type, long long x) {     if (!type)       sm.push(x);     else       bg.push(x);   }   long long tap(long long type) {     if (!type) return sm.top();     return bg.top();   }   int main() {     memset(dp, -1, sizeof dp);     scanf( %lld , &a);     for (long long i = 1; i <= a; i++) {       long long x;       scanf( %lld , &x);       par[i] = par[i - 1] + x;     }     long long ans = -100000000924052357;     upd(0, -par[a]);     upd(1, par[a]);     for (long long i = a; i >= 3; i--) {       dp[i][0] = tap(1);       dp[i][1] = tap(0);       upd(0, dp[i][0] - par[i - 1]);       upd(1, dp[i][1] + par[i - 1]);       umax(ans, dp[i][1] + par[i - 1]);     }     printf( %lld n , max(ans, par[a]));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long SZ = 1e5 + 4;   const double EPS = 1e-7;   const long long mod = 1e9 + 7;   const long long hashpow = 2;   const long long inf = 2e9;   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   long long n;   void read() {     cin >> n;     --n;   }   void solve() {     long long x = 1;     long long m = n % 3;     n /= 3;     long long cnt = 0;     while (n >= x) {       n -= x;       x *= 4;       ++cnt;     }     long long a = 1;     long long b = 2;     long long c = 3;     vector<long long> y;     while (n) {       y.push_back(n % 4);       n /= 4;     }     while (y.size() < cnt) {       y.push_back(0);     }     for (long long i = (long long)(y.size()) - 1; i >= 0; --i) {       a *= 4;       b *= 4;       c *= 4;       if (y[i] == 1) {         a += 1;         b += 2;         c += 3;       } else if (y[i] == 2) {         a += 2;         b += 3;         c += 1;       } else if (y[i] == 3) {         a += 3;         b += 1;         c += 2;       }     }     if (m == 0) {       cout << a <<   n ;     } else if (m == 1) {       cout << b <<   n ;     } else {       cout << c <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long t;     cin >> t;     for (long long i = 0; i < t; ++i) {       read();       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct segTree {     long long* data;     int n;     segTree(int n) : n(n) { data = new long long[n * 2](); }     void add(int i, long long v) {       for (i += n; i; i >>= 1) data[i] += v;     }     int find(long long v) {       int i = 1;       while (i < n) {         i *= 2;         if (v >= data[i]) v -= data[i++];       }       return i - n;     }     long long sum(int i) {       long long r = data[i + n];       for (i += n; i > 1; i >>= 1) {         if (i & 1) r += data[i - 1];       }       return r;     }   };   segTree count_tree(1 << 17), sum_tree(1 << 17);   long long x[100000], t[100000];   vector<pair<int, long long>> child[100000];   map<int, int> ti_map;   int ti_list[100000];   long long dp[100000], dp2[100000];   void dfs(int p, long long T) {     if (T <= 0) return;     count_tree.add(ti_map[t[p]], x[p]);     sum_tree.add(ti_map[t[p]], x[p] * t[p]);     int i = sum_tree.find(T);     dp[p] = count_tree.sum(i - 1);     assert(sum_tree.sum(i - 1) <= T);     assert(i >= 1e5 + 10 || sum_tree.sum(i) > T);     if (i < 1e5 + 10) dp[p] += (T - sum_tree.sum(i - 1)) / ti_list[i];     vector<long long> child_vals;     for (auto e : child[p]) {       dfs(e.first, T - e.second * 2);       child_vals.push_back(dp2[e.first]);     }     sort(child_vals.rbegin(), child_vals.rend());     dp2[p] = dp[p];     if (child_vals.size() >= 2) dp2[p] = max(dp2[p], child_vals[1]);     if (p == 0) dp2[p] = max(dp2[p], child_vals[0]);     count_tree.add(ti_map[t[p]], -x[p]);     sum_tree.add(ti_map[t[p]], -x[p] * t[p]);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n, T;     cin >> n >> T;     for (int i = 0; i < n; i++) cin >> x[i];     for (int i = 0; i < n; i++) {       cin >> t[i];       ti_map[t[i]];     }     int c = 1;     for (auto& p : ti_map) {       ti_list[c] = p.first;       p.second = c++;     }     for (int i = 1; i < n; i++) {       long long p, l;       cin >> p >> l;       child[p - 1].push_back({i, l});     }     dfs(0, T);     cout << dp2[0] << endl;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const long long inf = numeric_limits<long long>::max() / 2;   const long double eps = 1e-9;   const long double pi = acos(-1);   template <typename T>   inline bool mineq(T& a, T b) {     return (a > b) ? (a = b, 1) : 0;   }   template <typename T>   inline bool maxeq(T& a, T b) {     return (a < b) ? (a = b, 1) : 0;   }   inline void solve(), read();   const string file =   ;   int main() {     if (file !=   ) {       freopen((file +  .in ).c_str(),  r , stdin);       freopen((file +  .out ).c_str(),  w , stdout);     }     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     read();     solve();     return 0;   }   long long n;   vector<long long> a;   vector<pair<long long, long long> > b;   inline void solve() {     for (long long i = 0; i < n; i++) {       if (i && a[i] == a[i - 1]) {         ++b.back().second;       } else if (i == 0 || a[i] == a[i - 1] + 1) {         b.push_back({a[i], 1});       } else {         cout <<  NO               <<   n ;         return;       }     }     for (long long i = 0; i < (long long)((b).size()) - 2; i++) {       b[i + 1].second -= b[i].second;       if (b[i + 1].second <= 0) {         cout <<  NO               <<   n ;         return;       }     }     if (b[(long long)((b).size()) - 1].second !=         b[(long long)((b).size()) - 2].second) {       cout <<  NO             <<   n ;       return;     }     cout <<  YES           <<   n ;   }   inline void read() {     cin >> n;     a.resize(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     sort((a).begin(), (a).end());   }


#include <bits/stdc++.h>   using namespace std;   long long base = 31, M = 1000000007, base1 = 29, M1 = 1000000009;   long long fpow(long long x, long long y) {     if (y == 0) return 1;     if (y == 1) return x;     long long p = fpow(x, y / 2) % M;     p *= p;     p %= M;     if (y & 1) p *= x;     return p % M;   }   long long po1[5005], pr[5005], po[5005], pr1[5005], suf[5005], suf1[5005];   int ans[5005][5005], dp[5005][5005];   pair<long long, long long> gethash(int i, int j) {     long long has = pr[j];     if (i != 0) has -= (pr[i - 1] * po[j - i + 1]) % M;     has += M;     has %= M;     long long has1 = pr1[j];     if (i != 0) has1 -= (pr1[i - 1] * po1[j - i + 1]) % M1;     has1 += M1;     has1 %= M1;     return {has, has1};   }   pair<long long, long long> gethash1(int i, int j) {     long long has = suf[j];     if (i != 0) has -= (suf[i - 1] * po[j - i + 1]) % M;     has += M;     has %= M;     long long has1 = suf1[j];     if (i != 0) has1 -= (suf1[i - 1] * po1[j - i + 1]) % M1;     has1 += M1;     has1 %= M1;     return {has, has1};   }   int main() {     po[0] = 1;     po1[0] = 1;     for (int i = 1; i <= 5001; i++) {       po[i] = po[i - 1] * base;       po1[i] = po1[i - 1] * base1;       po[i] %= M;       po1[i] %= M1;     }     string s, t;     char c[100005];     scanf( %s , &c);     s = c;     int n = s.size();     t = s;     reverse(t.begin(), t.end());     int q;     scanf( %d , &q);     pr[0] = s[0] -  a  + 1;     pr1[0] = s[0] -  a  + 1;     suf[0] = t[0] -  a  + 1;     suf1[0] = t[0] -  a  + 1;     for (int i = 1; i < s.size(); i++) {       long long x = s[i] -  a  + 1;       long long y = t[i] -  a  + 1;       pr[i] = (pr[i - 1] * base + x) % M;       pr1[i] = (pr1[i - 1] * base1 + x) % M1;       suf[i] = (suf[i - 1] * base + y) % M;       suf1[i] = (suf1[i - 1] * base1 + y) % M1;     }     for (int i = 0; i < n; i++) {       for (int j = i; j < n; j++) {         pair<long long, long long> o = gethash(i, j);         pair<long long, long long> os = gethash1(n - 1 - j, n - 1 - i);         if (o.first == os.first && o.second == os.second) ans[i][j]++;         if (j != i) ans[i][j] += ans[i][j - 1];       }     }     for (int i = n - 1; i >= 0; i--) {       for (int j = i; j >= 0; j--) {         dp[j][i] = dp[j + 1][i] + ans[j][i];       }     }     int l, r;     while (q--) {       scanf( %d%d , &l, &r);       l--;       r--;       printf( %d n , dp[l][r]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)3e5 + 50;   struct node {     int sum, suf;     void add(int val) {       sum += val;       suf = max(sum, 0);     }   };   node merge(node L, node R) {     return {L.sum + R.sum, max(R.sum + L.suf, R.suf)};   }   struct Tree {     node dat[4 * N];     void init(int n) { fill(dat, dat + 4 * n, node{0, 0}); }     void update(int pos, int x, int l, int r, int val) {       if (l == r) {         dat[x].add(val);         return;       }       int mid = (l + r) / 2;       if (pos <= mid)         update(pos, 2 * x + 1, l, mid, val);       else         update(pos, 2 * x + 2, mid + 1, r, val);       dat[x] = merge(dat[2 * x + 1], dat[2 * x + 2]);     }   } tree;   int n;   int loc[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     tree.init(n);     for (int i = 0; i < n; i++) {       int x;       cin >> x;       x--;       loc[x] = i;     }     int cur = n - 1;     for (int i = 0; i < n; i++) {       while (cur >= 0 && tree.dat[0].suf == 0) {         tree.update(loc[cur--], 0, 0, n - 1, 1);       }       cout << cur + 2 <<    ;       int q;       cin >> q;       q--;       tree.update(q, 0, 0, n - 1, -1);     }   }


#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;   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long n;     cin >> n;     string s =   ;     long long i = 0;     while (i < n) {       if (i < n) {         s +=  a ;         i++;       }       if (i < n) {         s +=  a ;         i++;       }       if (i < n) {         s +=  b ;         i++;       }       if (i < n) {         s +=  b ;         i++;       }     }     cout << s <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 105;   int n, m, a[maxn][maxn];   int sumr[maxn], sumc[maxn];   bool ar[maxn], ac[maxn];   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> a[i][j];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) sumr[i] += a[i][j];     }     for (int j = 0; j < m; j++) {       for (int i = 0; i < n; i++) sumc[j] += a[i][j];     }     while (1) {       bool b = 0;       for (int i = 0; i < n; i++)         if (sumr[i] < 0) {           b = 1;           ar[i] ^= 1;           for (int j = 0; j < m; j++) sumc[j] -= 2 * a[i][j], a[i][j] = -a[i][j];           sumr[i] *= -1;         }       for (int j = 0; j < m; j++)         if (sumc[j] < 0) {           b = 1;           ac[j] ^= 1;           for (int i = 0; i < n; i++) sumr[i] -= 2 * a[i][j], a[i][j] = -a[i][j];           sumc[j] *= -1;         }       if (!b) break;     }     vector<int> vr, vc;     for (int i = 0; i < n; i++)       if (ar[i]) vr.push_back(i);     for (int i = 0; i < m; i++)       if (ac[i]) vc.push_back(i);     cout << vr.size() <<    ;     for (int i : vr) cout << i + 1 <<    ;     cout <<   n ;     cout << vc.size() <<    ;     for (int i : vc) cout << i + 1 <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int x1, y1;     cin >> x1 >> y1;     int x2, y2;     cin >> x2 >> y2;     int ans = 0x3f3f3f3f;     for (int i = -1; i <= 1; i++) {       for (int j = -1; j <= 1; j++) {         if (i == 0 && j == 0) {           continue;         }         ans = min(ans, abs(x1 - (x2 + i)) + abs(y1 - (y2 + j)));       }     }     cout << 2 * ans + 8;   }


#include <bits/stdc++.h>   int main() {     int n, m, a, b, t;     while (scanf( %d%d%d%d , &n, &m, &a, &b) != EOF) {       if (b == n) b = (n - 1) / m * m + m;       a--;       b--;       if (a > b)         while (1)           ;       if (a / m == b / m || m == 1)         t = 1;       else if (a % m == 0) {         if (b % m == m - 1)           t = 1;         else           t = 2;       } else {         if (b / m - a / m == 1)           t = 2;         else if (b % m == m - 1)           t = 2;         else if ((b - a + 1) % m == 0)           t = 2;         else           t = 3;       }       printf( %d n , t);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a[1000][7], i, j, m = 0, n;     string ar;     cin >> n;     for (i = 0; i < n; i++) {       cin >> ar;       for (j = 0; j < 7; j++) {         a[i][j] = ar[j] - 48;       }     }     for (j = 0; j < 7; j++) {       long long int l = 0;       for (i = 0; i < n; i++) {         if (a[i][j] == 1) {           l++;         }       }       if (l > m) {         m = l;       }     }     cout << m << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Set(int N, int pos) { return N |= (1LL << pos); }   int Reset(int N, int pos) { return N &= ~(1LL << pos); }   bool Check(int N, int pos) { return N & (1LL << pos); }   int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}, dy[] = {1, -1, 0, 0, 1, -1, -1, 1};   template <class T>   void cmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   void cmax(T &a, T b) {     if (b > a) a = b;   }   template <class T>   int len(const T &c) {     return (int)c.size();   }   template <class T>   int len(char c[]) {     return (int)strlen(c);   }   string itos(long n) {     string s;     while (n) {       s += (n % 10 + 48);       n /= 10;     }     reverse(s.begin(), s.end());     return s;   }   long stoi(string s) {     long n = 0;     for (int i(0), _n(len(s)); i < _n; ++i) n = n * 10 + (s[i] - 48);     return n;   }   long long n, ar[200005], arr[200005], m, a, p, b, aa, bb, mx = 0;   pair<int, int> fun(long d) {     p = upper_bound(ar, ar + n, d) - ar;     a = (p * 2 + (n - p) * 3);     p = upper_bound(arr, arr + m, d) - arr;     b = (p * 2 + (m - p) * 3);     return make_pair(a, b);   }   int main() {     mx = -100000000000000000LL;     cin >> n;     for (int i(0), _n(n); i < _n; ++i) cin >> ar[i];     cin >> m;     for (int i(0), _n(m); i < _n; ++i) cin >> arr[i];     sort(ar, ar + n);     sort(arr, arr + m);     aa = n * 3;     bb = m * 3;     mx = aa - bb;     pair<int, int> pr;     pr = fun(ar[0] - 1);     a = pr.first;     b = pr.second;     if (a - b > mx) {       mx = a - b;       aa = a;       bb = b;     } else if (a - b == mx && a > aa) {       aa = a;       bb = b;     }     for (int i(0), _n(n); i < _n; ++i) {       pr = fun(ar[i]);       a = pr.first;       b = pr.second;       if (a - b > mx) {         mx = a - b;         aa = a;         bb = b;       } else if (a - b == mx && a > aa) {         aa = a;         bb = b;       }     }     for (int i(0), _n(m); i < _n; ++i) {       pr = fun(arr[i]);       a = pr.first;       b = pr.second;       if (a - b > mx) {         mx = a - b;         aa = a;         bb = b;       } else if (a - b == mx && a > aa) {         aa = a;         bb = b;       }     }     pr = fun(ar[n - 1] + 1);     a = pr.first;     b = pr.second;     if (a - b > mx) {       mx = a - b;       aa = a;       bb = b;     } else if (a - b == mx && a > aa) {       aa = a;       bb = b;     }     cout << aa <<  :  << bb;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int getResult(long long y) {     printf( %lld n , y);     fflush(stdout);     int vd;     scanf( %d , &vd);     if (vd <= 0) exit(0);     vd--;     return vd;   }   bool solve(vector<long long> a) {     int maxIndex = 0;     for (int i = 1; i < 3; i++)       if (a[i] > a[maxIndex]) maxIndex = i;     int minIndex = 0;     for (int i = 1; i < 3; i++)       if (a[i] < a[minIndex]) minIndex = i;     int middle = 3 - maxIndex - minIndex;     long long w = 2 * a[maxIndex] - a[minIndex] - a[middle];     int r = getResult(w);     if (r == maxIndex) {       a[maxIndex] += w;       return solve(a);     } else {       int otherone = 3 - maxIndex - r;       long long w2 = a[maxIndex] - a[otherone];       int r2 = getResult(w2);       return r2 == 0;     }   }   int main() {     vector<long long> a(3);     for (int i = 0; i < 3; i++) scanf( %lld , &a[i]);     printf( First n );     fflush(stdout);     solve(a);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-8;   const int INFI = 1000 * 1000 * 1000;   const long long INFL = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;   const int MX_N = 1000;   int N;   string s, t;   string strs[] = { abc ,  acb ,  bac ,  bca ,  cab ,  cba };   int nstrs = 6;   int main() {     cin >> N;     cin >> s >> t;     int dobc = 0;     cout <<  YES  << endl;     if (s[0] == s[1]) ++dobc;     if (t[0] == t[1]) ++dobc;     if (N == 1 || !dobc) {       for (int i = 0; i < nstrs; ++i) {         string s1 = strs[i].substr(0, 2);         string s2 = strs[i].substr(1, 2);         if (s == s1 || s == s2 || t == s1 || t == s2) continue;         for (int j = 0; j < 3; ++j)           for (int k = 0; k < N; ++k) cout << strs[i][j];         putchar(  n );         return 0;       }     } else {       for (int i = 0; i < nstrs; ++i) {         bool pass = true;         string ap = strs[i] + strs[i];         for (int j = 0; j < ap.size() - 1 && pass; ++j) {           string sb = ap.substr(j, 2);           if (s == sb || t == sb) pass = false;         }         if (!pass) continue;         for (int j = 0; j < N; ++j) cout << strs[i];         cout << endl;         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200000];   long long INF = 1e12;   inline bool comp_bit(int x, int y) { return !!(x & y); }   inline int binsearch(int l, int r, int depth) {     return (upper_bound(a + l, a + r, 1 << depth, comp_bit) - a);   }   long long connect(int depth, int l1, int r1, int l2, int r2) {     if (l1 == r1 || l2 == r2) return INF;     if (a[l1] == a[r1 - 1] && a[l2] == a[r2 - 1]) return a[l1] ^ a[l2];     int mid1 = binsearch(l1, r1, depth), mid2 = binsearch(l2, r2, depth);     if (mid1 == l1 && mid2 == r2 || mid1 == r1 && mid2 == l2)       return connect(depth - 1, l1, r1, l2, r2);     else       return min(connect(depth - 1, l1, mid1, l2, mid2),                  connect(depth - 1, mid1, r1, mid2, r2));   }   long long solve(int depth, int l, int r) {     if (!depth) return (a[l] ^ a[r - 1]) & 1;     int mid = binsearch(l, r, depth);     if (mid == l || mid == r)       return solve(depth - 1, l, r);     else       return connect(depth - 1, l, mid, mid, r) + solve(depth - 1, l, mid) +              solve(depth - 1, mid, r);   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     sort(a, a + n);     printf( %lld , solve(29, 0, n));   }


#include <bits/stdc++.h>   using namespace std;   struct tim {     int begin, end;   } t[200005];   int cmp(tim a, tim b) {     if (a.begin != b.begin) return a.begin < b.begin;     return a.end < b.end;   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> t[i].begin >> t[i].end;     sort(t + 1, t + n + 1, cmp);     t[0].end = -1;     int p[3] = {0};     int i;     for (i = 1; i <= n; i++) {       if (t[p[1]].end < t[i].begin) {         p[1] = i;         continue;       }       if (t[p[2]].end < t[i].begin) {         p[2] = i;         continue;       }       break;     }     if (i > n)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 0, -1, 1};   int dy[] = {-1, 1, 0, 0};   const int mod = 1000000007;   const int INF = 1000000010;   int n;   char S[5020];   int L[5010];   int C[5010];   int RV;   pair<int, int> RM;   int lookup[5010];   int val[5010][15];   int hp[5010][5010];   int H[13][(1 << 13) + 3];   void kmr() {     for (int i = (0); i < (n); ++i) H[0][i] = S[i] -  0 ;     pair<pair<int, int>, int> T[n];     for (int s = (0); s < (12); ++s) {       int d = (1 << s);       for (int i = (0); i < (n); ++i)         T[i] = make_pair(pair<int, int>(H[s][i], i + d < n ? H[s][i + d] : 0), i);       sort(T, T + n);       d = 0;       for (int i = (0); i < (n); ++i) {         if (i && T[i - 1].first != T[i].first) ++d;         H[s + 1][T[i].second] = d;       }     }   }   bool eq(pair<int, int> a, pair<int, int> b) {     if (a.second - a.first != b.second - b.first) return 0;     return hp[a.first][a.second] == hp[b.first][b.second];   }   int cmp_d;   bool cmp(pair<int, int> a, pair<int, int> b) {     int ha = hp[a.first][a.second];     int hb = hp[b.first][b.second];     if (ha == hb) return a.first < b.first;     return ha < hb;   }   int diff(pair<int, int> a, pair<int, int> b) {     if (max(a.second - a.first, b.second - b.first) > 12) {       if (!eq(pair<int, int>(a.first, a.second - 12),               pair<int, int>(b.first, b.second - 12)))         return INF;       a.first = a.second - 12;       b.first = b.second - 12;     }     return val[a.first][a.second - a.first] - val[b.first][b.second - b.first];   }   vector<pair<int, pair<int, int> > > P;   pair<int, pair<int, int> > prep(pair<int, int> p) {     return make_pair(hp[p.first][p.second], p);   }   int main() {     scanf( %s , S);     n = strlen(S);     for (int i = (1); i < (n + 1); ++i) {       int d = 0;       while ((1 << (d + 1)) < i) ++d;       lookup[i] = d;     }     for (int i = (0); i < (n); ++i) {       val[i][0] = 0;       for (int d = (1); d < (14); ++d)         val[i][d] = val[i][d - 1] * 2 + S[i + d - 1] -  0 ;     }     kmr();     for (int i = (0); i < (n); ++i)       for (int j = (i + 1); j < (n + 1); ++j)         hp[i][j] = (H[lookup[j - i]][i] << 16) +                    H[lookup[j - i]][j - (1 << lookup[j - i])];     for (int d = (1); d < (n + 1); ++d) {       int m = P.size();       for (int i = (0); i < (n + 1 - d); ++i)         if (S[i] ==  1 ) P.push_back(prep(pair<int, int>(i, i + d)));       sort(P.begin() + m, P.end());     }     C[0] = 1;     for (int i = (1); i < (n + 1); ++i) L[i] = INF;     RV = INF;     for (pair<int, pair<int, int> > p_ : P) {       pair<int, int> p = p_.second;       if (L[p.first] == INF) continue;       C[p.second] = (C[p.second] + C[p.first]) % mod;       L[p.second] = min(L[p.second], L[p.first] + 1);       if (p.second == n) {         if (RV == INF) {           RV = L[n];           RM = p;         } else {           if (diff(p, RM) < RV - L[n]) {             RM = p;             RV = L[n];           }         }       }     }     printf( %d n , C[n]);     int r = 0;     for (int i = (RM.first); i < (RM.second); ++i) r = (2 * r + S[i] -  0 ) % mod;     r = (r + RV) % mod;     printf( %d n , r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int c[210];   int pre[210][210];   int precnt[210];   int cnt[210] = {0};   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < (n); i++) {       scanf( %d , c + i);       c[i] %= 3;     }     for (int i = 0; i < (n); i++)       for (int j = 0; j < (n); j++) pre[i][j] = 0;     for (int i = 0; i < (n); i++) {       scanf( %d , precnt + i);       int t;       for (int j = 0; j < (precnt[i]); j++) {         scanf( %d , &t);         pre[i][t - 1] = 1;       }     }     int mintime = 1000100;     for (int p = 0; p < (3); p++) {       int pos = p, time = 0, done = 0;       for (int i = 0; i < (n); i++) cnt[i] = 0;       while (done < n) {         queue<int> Q;         for (int i = 0; i < (n); i++)           if (precnt[i] == cnt[i] && c[i] == pos) Q.push(i);         while (!Q.empty()) {           int part = Q.front();           Q.pop();           done++;           time++;           cnt[part]++;           for (int i = 0; i < (n); i++)             if (pre[i][part] == 1) {               cnt[i]++;               if (cnt[i] == precnt[i] && c[i] == pos) Q.push(i);             }         }         pos = (pos + 1) % 3;         time++;       }       time--;       if (time < mintime) mintime = time;     }     printf( %d n , mintime);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   bool isPrime(long long n) {     long long c;     if (n <= 1) return false;     c = sqrt(n);     for (int i = 2; i <= c; i++)       if (n % i == 0) return false;     return true;   }   int D(long long n) {     int count = 0;     while (n != 0) {       n = n / 10;       ++count;     }     return count;   }   const long long N = 2e5 + 7;   long long l, k, d, tr, n, m, sum, mini, maxi, a, b, c, x, y;   long long t[5007];   set<int> vis;   vector<int> v;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     for (cin >> tr; tr--;) {       cin >> n;       mini = 0;       cin >> t[0];       for (int i = 1; i < n; i++) {         cin >> t[i];         if (t[i] != t[i - 1]) {           a = i;           c = t[i];           b = i - 1;           mini++;         }       }       if (mini) {         cout <<  YES  << endl;         for (int i = 0; i < n; i++) {           if (i != a) {             if (t[i] != c) {               cout << i + 1 <<     << a + 1 << endl;             } else {               cout << i + 1 <<     << b + 1 << endl;             }           }         }       } else {         cout <<  NO  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 5, LOG = 19, off = 1 << 19;   pair<int, int> t[LOG][2 * off];   void upd(int x, pair<int, int> p, int lg) {     for (x += off; x; x /= 2) {       t[lg][x].first = min(t[lg][x].first, p.first);       t[lg][x].second = max(t[lg][x].second, p.second);     }   }   pair<int, int> get(int x, int lo, int hi, int a, int b, int lg) {     if (lo >= a && hi <= b) {       return t[lg][x];     }     if (lo >= b || hi <= a) {       return {off, 0};     }     int mid = (lo + hi) >> 1;     pair<int, int> lson = get(x * 2, lo, mid, a, b, lg);     pair<int, int> rson = get(x * 2 + 1, mid, hi, a, b, lg);     return pair<int, int>(min(lson.first, rson.first),                           max(lson.second, rson.second));   }   int r[MAXN];   pair<int, int> par[MAXN][LOG];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> r[i];     }     if (n == 1) {       cout << 0;       return 0;     }     for (int i = 0; i < 2 * off; ++i)       for (int lg = 0; lg < LOG; ++lg) {         t[lg][i].first = off;       }     for (int i = 0; i < n; ++i)       for (int j = 0; j < 3; ++j) {         par[i + j * n][0].first = max(0, i + j * n - r[i]);         par[i + j * n][0].second = min(3 * n - 1, i + j * n + r[i]);         upd(i + j * n, par[i + j * n][0], 0);       }     for (int lg = 1; lg < LOG; ++lg) {       for (int i = n; i < 2 * n; ++i) {         par[i][lg] = get(1, 0, off, par[i][lg - 1].first,                          par[i][lg - 1].second + 1, lg - 1);       }       for (int i = 0; i < n; ++i) {         par[i][lg].first = max(0, par[i + n][lg].first - n);         par[i][lg].second = min(3 * n - 1, par[i + n][lg].second - n);       }       for (int i = 2 * n; i < 3 * n; ++i) {         par[i][lg].first = max(0, par[i - n][lg].first + n);         par[i][lg].second = min(3 * n - 1, par[i - n][lg].second + n);       }       for (int i = 0; i < 3 * n; ++i) {         upd(i, par[i][lg], lg);       }     }     for (int j = 0; j < n; ++j) {       int i = n + j;       int lo = i, hi = i, sol = 0;       for (int lg = LOG - 1; lg >= 0; --lg) {         pair<int, int> res = get(1, 0, off, lo, hi + 1, lg);         if (res.second - res.first + 1 < n) {           lo = res.first;           hi = res.second;           sol += (1 << lg);         }       }       cout << sol + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:255000000 )   bool firstout = 1;   template <class T>   T &minn(T &a, T b) {     if (b < a) a = b;     return a;   }   template <class T>   T &maxx(T &a, T b) {     if (a < b) a = b;     return a;   }   int &madd(int &a, int b) {     a += b;     if (a >= 1000000009) a -= 1000000009;     return a;   }   int &msub(int &a, int b) {     a -= b;     if (a < 0) a += 1000000009;     return a;   }   int &mmult(int &a, int b) { return a = (long long)a * b % 1000000009; }   int mdiv(long long a, long long b, long long m) {     a = (a % m + m) % m;     b = (b % m + m) % m;     if (a % b == 0) return a / b;     return (a + m * mdiv(-a, m, b)) / b;   }   int n, m;   int A[201234];   int B[201234];   int R[201234];   int RR[201234];   int P[201234];   vector<int> O[201234];   vector<int> OO[201234];   void fnd(int *R) {     int i, j, k;     for (i = (0); i < (n); ++i) P[B[i]] = i;     for (i = (0); i < (2 * n); ++i) OO[i].clear(), O[i].clear();     for (i = (0); i < (n); ++i) {       j = P[A[i]];       j = (i - j + n) % n;       O[j].push_back(-j);       OO[j + n - i].push_back(-j);     }     for (i = (0); i < (n); ++i) R[i] = 1012345678;     multiset<int> s;     s.clear();     for (i = (0); i < (2 * n); ++i) {       for (k = (0); k < (O[i].size()); ++k) s.insert(O[i][k]);       for (k = (0); k < (OO[i].size()); ++k) s.erase(s.find(OO[i][k]));       if (s.size()) minn(R[i % n], *s.begin() + i);     }   }   int main() {     int i, j, k;     char c;     int a, d;     int ts;     for (ts = 1; scanf( %                          d ,                        &(n)) > 0;          ++ts) {       for (i = (0); i < (n); ++i)         scanf(              %               d ,             &(A[i])),             --A[i];       for (i = (0); i < (n); ++i)         scanf(              %               d ,             &(B[i])),             --B[i];       fnd(R);       reverse(A, A + n);       reverse(B, B + n);       fnd(RR);       int res = 0;       for (i = (0); i < (n); ++i)         printf(              %               d ,             (min(RR[i], R[(n - i) % n]))),             printf(  n ), firstout = 1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<double, int> a;   double b[200007];   inline long long int read() {     long long int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * f;   }   inline void writ(int x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) writ(x / 10);     putchar(x % 10 +  0 );   }   inline void write(int x) {     writ(x);     putchar(   );   }   int main() {     a.clear();     int n = read(), x, y, z;     for (int i = 1; i <= n; ++i)       x = read(), y = read(), z = read(), b[i] = (double)(x + y) / z, ++a[b[i]];     for (int i = 1; i <= n; ++i) write(a[b[i]]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long int n, m, l;   unsigned long long int r, k, nn;   template <class T>   inline T min(T a, T b) {     return ((a < b) ? a : b);   }   char frac[9][500][500];   string p[500];   char isfrac(char a, char b, char c, char d) {     char mx = max(max(a, b), max(c, d));     return (         (((mx & 8) ? (a == mx) : (a == 0)) && ((mx & 4) ? (b == mx) : (b == 0)) &&          ((mx & 2) ? (c == mx) : (c == 0)) && ((mx & 1) ? (d == mx) : (d == 0)))             ? mx             : -1);   }   int main(int argc, char** argv) {     cin >> n >> m;     for (int i = 0; i < n; ++i) {       cin >> p[i];     }     char f = 0;     for (int i = 0; i < (n - 1); ++i) {       for (int j = 0; j < (m - 1); ++j) {         f = 0;         if (p[i][j] ==  . ) {           f += 8;         }         if (p[i][j + 1] ==  . ) {           f += 4;         }         if (p[i + 1][j] ==  . ) {           f += 2;         }         if (p[i + 1][j + 1] ==  . ) {           f += 1;         }         frac[0][i][j] = f;       }     }     int cnt = 0;     int l = 1;     int pw = 2;     while (((2 * pw) <= n) && ((2 * pw) <= m)) {       for (int i = 0; i <= (n - 2 * pw); ++i) {         for (int j = 0; j <= (m - 2 * pw); ++j) {           frac[l][i][j] =               isfrac(frac[l - 1][i][j], frac[l - 1][i][j + pw],                      frac[l - 1][i + pw][j], frac[l - 1][i + pw][j + pw]);           if (frac[l][i][j] >= 0) {             cnt++;           }         }       }       ++l;       pw *= 2;     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bitset<4001> g[4001];   int main() {     int n, m;     cin >> n >> m;     vector<pair<int, int> > v;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       g[a][b] = 1;       g[b][a] = 1;       v.push_back(pair<int, int>(a, b));     }     int minx = 100000000;     bool was = 0;     for (int i = 0; i < v.size(); i++) {       int a = v[i].first;       int b = v[i].second;       for (int j = 0; j < n; j++) {         if (g[a][j] && g[b][j]) {           minx = min(minx, (int)(g[a].count() + g[b].count() + g[j].count()) - 6);           was = true;         }       }     }     if (was)       cout << minx;     else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int N = 1e5 + 4;   const long long MOD = 998244353;   bool ans[2 * N];   long long POW(long long base, long long exponent) {     long long result = 1;     while (exponent > 0) {       if (exponent % 2 == 1) result = (result * base) % MOD;       exponent = exponent >> 1;       base = (base * base) % MOD;     }     return result;   }   long long Inv(long long x) { return POW(x, MOD - 2); }   void BFS(int s, vector<int> &d, vector<int> edge[]) {     d[s] = 0;     queue<int> q;     q.push(s);     while (!q.empty()) {       int v = q.front();       q.pop();       for (auto to : edge[v]) {         if (d[to] == (int)1e9) {           d[to] = d[v] + 1;           q.push(to);         }       }     }   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n];       for (int i = 0; i < n; i++) cin >> a[i];       int l = 0, r = n - 1, ls = 0, rs = 0, al = 0, b = 0, mv = 0;       while (l <= r) {         if (mv & 1) {           rs = 0;           while (rs <= ls and r >= l) rs += a[r--];           b += rs;           mv++;         } else {           ls = 0;           while (ls <= rs and l <= r) ls += a[l++];           al += ls;           mv++;         }       }       cout << mv <<     << al <<     << b <<   n ;     }     return 0;   }