#include <bits/stdc++.h>   using namespace std;   static const int N = 1000;   int t[N][N];   int d[4][N][N];   int di[4] = {1, 0, -1, 0};   int dj[4] = {0, 1, 0, -1};   int n, m, q;   int p[N];   bool check(int k, int i) {     if (i < 0) return 0;     if (k) return i < m;     return i < n;   }   int solve(int c, int b) {     int glob = 1;     int res = 0;     int l = c;     int d = c;     while (glob) {       while (check(b, d + 1) && p[d] == p[d + 1]) d++;       while (check(b, l - 1) && p[l] == p[l - 1]) l--;       if (res < (d - l + 1) * (min(p[l], p[d])))         res = (d - l + 1) * (min(p[l], p[d]));       if (!check(b, l - 1) && !check(b, d + 1))         glob = 0;       else {         if (!check(b, l - 1))           d++;         else {           if (!check(b, d + 1))             l--;           else {             if (p[d + 1] > p[l - 1])               d++;             else               l--;           }         }       }     }     return res;   }   int main() {     scanf( %i , &n);     scanf( %i , &m);     scanf( %i , &q);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %i , &t[i][j]);     int si, sj, ei, ej;     for (int k = 0; k < 4; k++) {       si = di[k] * di[k] * ((n - 1) * (1 - di[k]) / 2);       sj = dj[k] * dj[k] * ((m - 1) * (1 - dj[k]) / 2);       ei = n - si - 1;       ej = m - sj - 1;       int i = si;       int j = sj;       int sum = 0;       while ((!di[k] && i < n) || (!dj[k] && j < m)) {         if (t[i][j])           sum += t[i][j];         else           sum = 0;         d[k][i][j] = sum;         i += di[k];         j += dj[k];         if (!di[k] && (dj[k] * j > dj[k] * ej)) {           j = sj;           i++;           sum = 0;         }         if (!dj[k] && (di[k] * i > di[k] * ei)) {           i = si;           j++;           sum = 0;         }       }     }     int x, y, b;     for (int l = 0; l < q; l++) {       scanf( %i , &b);       scanf( %i , &x);       scanf( %i , &y);       x--;       y--;       if (b - 1) {         int best = 0;         int res;         for (int k = 0; k < 4; k++) {           int i = x;           int j = y;           if (di[k]) {             p[j] = d[k][i][j];             int cmin = p[j];             for (int f = j; f < m; f++) {               if (d[k][i][f] < cmin) cmin = d[k][i][f];               p[f] = cmin;             }             cmin = p[j];             for (int f = j; f >= 0; f--) {               if (d[k][i][f] < cmin) cmin = d[k][i][f];               p[f] = cmin;             }             res = solve(j, 1);           } else {             p[i] = d[k][i][j];             int cmin = p[i];             for (int f = i; f < n; f++) {               if (d[k][f][j] < cmin) cmin = d[k][f][j];               p[f] = cmin;             }             cmin = p[i];             for (int f = i; f >= 0; f--) {               if (d[k][f][j] < cmin) cmin = d[k][f][j];               p[f] = cmin;             }             res = solve(i, 0);           }           if (res > best) best = res;         }         printf( %i n , best);       } else {         t[x][y] ^= 1;         for (int k = 0; k < 4; k++) {           int i = !di[k] * x + di[k] * di[k] * ((n - 1) * (1 - di[k]) / 2);           int j = !dj[k] * y + dj[k] * dj[k] * ((m - 1) * (1 - dj[k]) / 2);           int sum = 0;           while (i >= 0 && i < n && j >= 0 && j < m) {             if (t[i][j])               sum += t[i][j];             else               sum = 0;             d[k][i][j] = sum;             i += di[k];             j += dj[k];           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   int x[1000], y[1000];   using namespace std;   int main() {     int n, counter = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];       if (x[i] != y[i]) {         cout <<  rated ;         return 0;       }     }     for (int i = 0; i < n; i++) {       if (x[i] < x[i + 1]) {         cout <<  unrated ;         return 0;       }     }     cout <<  maybe ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (cin >> n) {       vector<int> a(n);       for (int i = 0; i < n; scanf( %d , &a[i++]))         ;       sort(a.begin(), a.end());       bool ok = 0;       for (int i = 0; i < n; i++) {         if (a[i] != i + 1) {           cout << i + 1 << endl;           ok = 1;           break;         }       }       if (!ok) cout << n + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a0, a1, n, ans, table[500];   int getans(int);   int main() {     scanf( %d%d%d , &a0, &a1, &n);     printf( %d n , getans(n));     return 0;   }   int getans(int an) {     if (an == 0) return a0;     if (an == 1) return a1;     return getans(an - 1) + getans(an - 2);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int a[maxn], b[maxn], ww[maxn], www[maxn];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       ww[a[i]] = 1;     }     for (int i = 1; i <= n; i++) {       scanf( %d , &b[i]);       www[b[i]] = i;     }     int t1 = 1;     while (t1 <= n && b[t1] == 0) t1++;     if (t1 == n + 1) {       printf( %d n , n);     } else {       int f = 1;       for (int i = t1; i <= n; i++) {         if (b[i] != i - t1 + 1) {           f = 0;           break;         }       }       if (f) {         printf( %d n , t1 - 1);       } else {         int x = b[n];         int fx = 0;         for (int i = n - 1; i >= 1; i--) {           if (b[i + 1] == 1) {             fx = 1;             break;           }           if (b[i] != b[i + 1] - 1) {             break;           }         }         int ans = 0;         int fx2 = 0;         if (fx) {           ans = n - b[n];           if (!ww[b[n] + 1]) {             fx2 = 1;           }           for (int i = b[n] + 2; i <= n; i++) {             if (www[i] > i - b[n] - 1) {               fx2 = 1;               break;             }           }         }         if (fx2 || fx == 0) {           for (int i = 1; i <= n; i++) {             if (ww[i]) continue;             ans = max(ans, max(0, www[i] + 1 - i) + n);           }         }         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[110][110];   int main() {     int n, v;     cin >> n >> v;     for (int i = 1; i <= v; i++) dp[1][i] = i;     for (int i = 2; i <= n; i++) {       for (int j = 0; j < v; j++) {         dp[i][j] = min(dp[i - 1][j + 1], dp[i - 1][j] + i);       }       dp[i][v] = dp[i - 1][v] + i;     }     int ans = 1000000000;     for (int i = 0; i < v + 1; i++) ans = min(ans, dp[n][i]);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gi() {     int x = 0, w = 1;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) w = 0, ch = getchar();     while (ch >=  0  && ch <=  9 )       x = (x << 3) + (x << 1) + ch -  0 , ch = getchar();     return w ? x : -x;   }   const int N = 3e5 + 5;   int n, m, to[N << 1], nxt[N << 1], head[N], cnt, ls[N], rs[N], dis[N], rt[N],       top[N], vis[N], key[N], tag[N];   long long ans;   void cover(int x, int v) {     if (!x) return;     key[x] += v;     tag[x] += v;   }   void down(int x) {     if (!tag[x]) return;     cover(ls[x], tag[x]);     cover(rs[x], tag[x]);     tag[x] = 0;   }   int merge(int x, int y) {     if (!x || !y) return x | y;     if (key[x] > key[y]) swap(x, y);     down(x);     rs[x] = merge(rs[x], y);     if (dis[ls[x]] < dis[rs[x]]) swap(ls[x], rs[x]);     dis[x] = dis[rs[x]] + 1;     return x;   }   void dfs(int u, int f) {     for (int e = head[u]; e; e = nxt[e])       if (to[e] ^ f) dfs(to[e], u), rt[u] = merge(rt[u], rt[to[e]]);     if (u ^ 1) {       vis[u] = 1;       while (vis[top[rt[u]]]) rt[u] = merge(ls[rt[u]], rs[rt[u]]);       if (!rt[u]) puts( -1 ), exit(0);       ans += key[rt[u]];       cover(rt[u], -key[rt[u]]);     }   }   int main() {     n = gi();     m = gi();     for (int i = 1; i < n; ++i) {       int u = gi(), v = gi();       to[++cnt] = v;       nxt[cnt] = head[u];       head[u] = cnt;       to[++cnt] = u;       nxt[cnt] = head[v];       head[v] = cnt;     }     for (int i = 1; i <= m; ++i) {       int u = gi();       top[i] = gi();       key[i] = gi();       rt[u] = merge(rt[u], i);     }     dfs(1, 0);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 1;   int bit[N] = {0};   void update(int x, int val) {     for (; x <= N; x += x & (-x)) bit[x] += val;   }   int query(int x) {     int sum = 0;     for (; x >= 1; x -= x & (-x)) sum += bit[x];     return sum;   }   int a[N];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     int ans = 0;     for (int i = n - 1; i >= 0; i--) {       int ele = a[i];       ans += query(a[i]);       update(a[i], 1);     }     int q;     cin >> q;     while (q--) {       int a, b;       cin >> a >> b;       int r = b - a;       int x = r * (r + 1);       x /= 2;       ans += x;       if (ans % 2 == 0)         cout <<  even n ;       else         cout <<  odd n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 101;   int n, a[N][30];   long long nd[N][N], num[N];   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) cin >> nd[i][j];     memset(a, 0, sizeof(a));     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j) {         int run = 29;         while (run >= 0) {           if (nd[i][j] & (1 << (29 - run))) a[i][run] = a[j][run] = 1;           --run;         }       }     for (int i = 1; i <= n; ++i)       for (int k = 0; k <= 29; ++k) num[i] += (1 << k) * (a[i][29 - k]);     for (int i = 1; i <= n; ++i) cout << num[i] <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   inline int Getlen(int x) {     int res = 0;     while (x) {       res++;       x /= 10;     }     return res;   }   int PP[5];   int a[51], len[51], n, p;   int id[51];   int res[51], tot;   inline void dfs(int now, int Gmod, int Gxor) {     if (Gmod == 0 && Gxor == 0 && tot > 0) {       puts( Yes );       cout << tot << endl;       for (int i = 0; i < tot; i++) cout << res[i] <<    ;       exit(0);     }     if (now > n) return;     dfs(now + 1, Gmod, Gxor);     res[tot++] = id[now];     dfs(now + 1, (Gmod * PP[len[now]] + a[now]) % p, Gxor ^ a[now]);     tot--;   }   int main() {     rand();     rand();     rand();     rand();     rand();     rand();     int tmpp;     tmpp = 0;     tmpp++;     tmpp++;     tot = 0;     PP[0] = 1;     for (int i = 1; i <= 3; i++) PP[i] = PP[i - 1] * 10;     scanf( %d%d , &n, &p);     int now = 0, tmp;     for (int i = 1; i <= n; i++) {       scanf( %d , &tmp);       if (tmp <= 31) a[++now] = tmp, len[now] = Getlen(a[now]), id[now] = i;     }     n = now;     dfs(1, 0, 0);     puts( No );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n + 5];     for (int i = 1; i <= n; i++) cin >> a[i];     int m = 1;     for (int i = 2; i < n; i++) {       if (abs(a[i] - a[i + 1]) < abs(a[m] - a[m + 1])) m = i;     }     if (abs(a[n] - a[1]) < abs(a[m] - a[m + 1])) {       cout << n <<     << 1;     } else       cout << m <<     << m + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   constexpr long long maxN = 1e5 + 43;   long long n, d;   vector<long long> a;   long long suff[maxN];   long long had_max[maxN];   signed main() {     ios_base::sync_with_stdio(false);     cin >> n >> d;     a.resize(n + 1);     for (long long i = 1; i <= n; ++i) cin >> a[i];     long long ans = 0;     long long maxx = 0, minn = 0;     for (long long i = 1; i <= n; ++i) {       if (a[i] != 0) {         maxx += a[i];         minn += a[i];         maxx = min(maxx, d);         if (minn > d) {           cout << -1;           return 0;         }       } else {         if (maxx < 0) {           maxx = d;           minn = 0;           ++ans;         } else {           minn = max((long long)0, minn);         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void output() {     long long n;     cin >> n;     long long a[n], i;     for (i = 0; i < n; i++) cin >> a[i];     map<long long, bool> make_pair;     long long s = 0;     make_pair[0] = true;     long long c = 0;     for (i = 0; i < n; i++) {       s += a[i];       if (make_pair[s]) {         c++;         make_pair.clear();         s = a[i];         make_pair[s] = true;         make_pair[0] = true;       } else {         make_pair[s] = true;       }     }     cout << c << endl;   }   signed main() {     long long t;     t = 1;     while (t--) output();   }


#include <bits/stdc++.h>   const int INF = (int)1e9;   const double PI = acos(-1.);   using namespace std;   string s;   long long sumr, suml, need;   int main() {     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  ^ ) need = i;     }     for (int i = need - 1; i >= 0; i--) {       if (s[i] !=  = ) {         suml += (s[i] -  0 ) * (need - i);       }     }     for (int i = need + 1; i < s.length(); i++) {       if (s[i] !=  = ) {         sumr += (s[i] -  0 ) * (i - need);       }     }     if (sumr == suml)       cout <<  balance ;     else if (suml > sumr)       cout <<  left ;     else       cout <<  right ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s =  abcdefghijklmnopqrstuvwxyz ;     string s2 =   ;     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) s2 += s[i % k];     cout << s2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int forbidInd;   int A[100000 + 10];   long long int memo[60][60][60];   long long int solve(int i, int k, int x) {     if (k < 0 || x < 0) return 0;     if (i == 0) {       if (x == 0 && k == 0) return 1;       if (k == 1 && x == A[i] && forbidInd != 0)         return 1;       else         return 0;     }     if (memo[i][k][x] != -1) return memo[i][k][x];     long long int ret = 0;     ret = solve(i - 1, k, x);     if (i != forbidInd) ret += solve(i - 1, k - 1, x - A[i]);     return memo[i][k][x] = ret;   }   long long int C[60][60];   int main() {     for (int i = 0; i < 51; i++)       for (int j = 0; j < 51; j++)         if (i == j || j == 0)           C[i][j] = 1;         else           C[i][j] = C[i - 1][j] + C[i - 1][j - 1];     int n, P, x;     while (cin >> n) {       int sum = 0;       for (int i = 0; i < n; i++) {         cin >> A[i];         sum += A[i];       }       cin >> P;       double ans = 0;       for (int k = 0; k < n; k++) {         forbidInd = k;         memset(memo, -1, sizeof memo);         for (int s = 1; s <= n - 1; s++)           for (int x = P - A[k] + 1; x <= P; x++) {             long long int ret = solve(n - 1, s, x);             long long int tmp = C[n][s] * (n - s);             ans = ans + ((ret * s * 1.) / (tmp * 1.0));           }       }       if (sum <= P) ans = n * 1.;       printf( %.10lf n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nsz = 1e5, ksz = 8, msksz = (1 << ksz) - 1, inf = 0x3f3f3f3f;   bool vis[nsz + 5];   int n, m, k, full, p[nsz + 5], q[ksz + 5], dp[2][msksz + 5], ans;   struct event {     int pos, id, st;     event(int pos = 0, int id = 0, int st = 0) {       this->pos = pos, this->id = id, this->st = st;     }   };   vector<event> dat;   bool inline operator<(event a, event b) {     return a.pos != b.pos ? a.pos < b.pos : a.st < b.st;   }   void inline upd(int &a, int b) { a < b && (a = b); }   string inline bin(int S, int len) {     string s;     for (int i = 0; i < len; ++i) {       s += (S >> i & 1) ^ 48;     }     return s;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; ++i) {       int l, r;       scanf( %d%d , &l, &r);       dat.push_back(event(l, i, +1));       dat.push_back(event(r + 1, i, -1));     }     sort(dat.begin(), dat.end());     memset(dp, -inf, sizeof(dp));     int o = 0, x = 1, l = dat[0].pos, i = 0, k = 0;     for (; i < dat.size() && dat[i].pos == l; ++i) {       p[dat[i].id] = k;       q[k] = dat[i].id;       ++k;     }     full = (1 << k) - 1;     for (int S = 0; S <= full; ++S) {       dp[o][S] = 0;     }     for (; i < dat.size();) {       l = dat[i].pos;       int il = i, ir = i, len = dat[i].pos - dat[i - 1].pos, pk = k, dk = 0,           pfull = full, dfull;       memset(vis, 0, sizeof(vis));       for (; i < dat.size() && dat[i].pos == l; ++i, ++ir) {         if (dat[i].st == -1) {           --k;           vis[p[dat[i].id]] = 1;         }       }       for (int i = 0, j = 0; i < pk; ++i) {         if (vis[i]) continue;         p[q[i]] = j;         q[j] = q[i];         ++j;       }       for (int i = il; i <= ir - 1; ++i) {         if (dat[i].st == +1) {           p[dat[i].id] = k;           q[k] = dat[i].id;           ++k;           ++dk;         }       }       full = (1 << k) - 1;       dfull = (1 << dk) - 1;       for (int S = 0; S <= pfull; ++S) {         int val = dp[o][S] + (__builtin_popcount(S) & 1) * len, nS = 0, j = 0;         if (val < 0) continue;         for (int i = 0; i < pk; ++i) {           if (vis[i]) continue;           nS |= (S >> i & 1) << j;           ++j;         }         if (dk <= 0) {           upd(dp[x][nS], val);         } else {           for (int dS = 0; dS <= dfull; ++dS) {             int nnS = nS | (dS << j);             upd(dp[x][nnS], val);           }         }       }       swap(o, x);       memset(dp[x], -inf, sizeof(dp[x]));     }     for (int S = 0; S <= full; ++S) {       upd(ans, dp[o][S]);     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   template <class T1, class T2>   struct cmpf {     bool rev;     inline bool operator()(const pair<T1, T2>& a, const pair<T1, T2>& b) const {       return (a.first < b.first) ^ rev;     }     cmpf(bool b = false) { rev = b; }   };   template <class T1, class T2>   struct cmps {     bool rev;     inline bool operator()(const pair<T1, T2>& a, const pair<T1, T2>& b) const {       return (a.second < b.second) ^ rev;     }     cmps(bool b = false) { rev = b; }   };   string to_string(const char& c) { return string(1, c); }   string to_string(const string& s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(const bool& b) { return (b ?  true  :  false ); }   string to_string(const vector<bool>& v, const string& sep =    ) {     string s =  [ ;     for (int i = 0; i < v.size(); i++) {       if (i) {         s += sep;       }       s += to_string(v[i]);     }     return s +  ] ;   }   template <size_t N>   string to_string(const bitset<N>& v) {     string s =  [ ;     for (size_t i = 0; i < N; i++) s += v[i] ?  1  :  0 ;     return s +  ] ;   }   template <class T1, class T2>   string to_string(const pair<T1, T2>& p, const string& sep =  , );   template <class T>   string to_string(const T& v, const string& sep =    ) {     bool first = true;     string s =  { ;     for (const auto& x : v) {       if (!first)         s += sep;       else         first = false;       s += to_string(x);     }     return s +  } ;   }   template <class T>   string to_string(const T& v, const int& sz, const string& sep =    ) {     string s =  [ ;     for (int i = 0; i < sz; i++) {       if (i) {         s += sep;       }       s += to_string(v[i]);     }     return s +  ] ;   }   template <class T1, class T2>   string to_string(const pair<T1, T2>& p, const string& sep) {     return  (  + to_string(p.first) + sep + to_string(p.second) +  ) ;   }   long long binpow(const long long& x, const long long& p, const long long& mod) {     assert(mod > 0);     if (p == 0) return 1;     if (p == 1) return x % mod;     if (p & 1) return (binpow((x * x) % mod, p / 2, mod) * x) % mod;     return binpow((x * x) % mod, p / 2, mod) % mod;   }   template <class T>   void chmn(T& a, const T& b) {     if (a > b) a = b;   }   template <class T>   void chmx(T& a, const T& b) {     if (a < b) a = b;   }   void setIO() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);   }   int chr[8] = {-1, 0, 1, 0, -1, -1, 1, 1};   int chc[8] = {0, 1, 0, -1, -1, 1, -1, 1};   const long long MOD = 1e9 + 7;   const int INIT = 1001001001;   const int MN = 10001;   long long BIT[MN];   void inc(int pos) {     for (; pos < MN; pos |= pos + 1) ++BIT[pos];   }   long long query(int pos) {     long long res = 0;     for (; pos > 0; pos &= pos - 1) res += BIT[pos - 1];     return res;   }   long long N, P;   long long A[MN];   long long f(long long x) {     long long cur = 1;     for (int i = 0; i < N; i++) {       long long q = query(x + i + 1);       if (q <= i) return -1;       cur = (cur * (q - i)) % P;     }     return cur;   }   void solve() {     cin >> N >> P;     for (int i = 0; i < N; i++) {       cin >> A[i];       inc(A[i]);     }     vector<int> ans;     for (int x = 1; x < 4000; x++) {       if (f(x) > 0) {         ans.push_back(x);       }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       if (i) cout <<    ;       cout << ans[i];     }     cout << endl;   }   int main() {     setIO();     long long T = 1;     while (T-- > 0) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 200000000;   struct Point {     int x, y;     Point(int _x, int _y) {       x = _x;       y = _y;     }   };   bool operator<(const Point a, const Point b) { return a.x < b.x; }   long long solve(vector<Point> v) {     int n = (int)v.size();     vector<int> MINI(n + 1);     vector<int> MAXI(n + 1);     MINI[n] = inf;     MAXI[n] = -inf;     for (int i = n - 1; i >= 0; i--) {       MINI[i] = min(v[i].y, MINI[i + 1]);       MAXI[i] = max(v[i].y, MAXI[i + 1]);     }     long long lo = 0, hi = 1LL * inf * inf, mi;     int mini2, maxi2;     while (lo <= hi) {       mi = (lo + hi) / 2;       bool ok = 0;       int mini = inf, maxi = -inf;       for (int i = 0, j = -1; i < n; i++) {         ok = 1;         while (j + 1 <= i) {           if (1LL * (v[j + 1].x - v[i].x) * (v[j + 1].x - v[i].x) > mi) {             mini = min(mini, v[j + 1].y);             maxi = max(maxi, v[j + 1].y);             j++;           } else {             break;           }         }         mini2 = min(mini, MINI[i + 1]), maxi2 = max(maxi, MAXI[i + 1]);         if (maxi2 < mini2) {           ok = 1;         } else {           if (1LL * (maxi2 - mini2) * (maxi2 - mini2) > mi) ok = 0;           if (1LL * mini2 * mini2 + 1LL * v[i].x * v[i].x > mi) {             ok = 0;           }           if (1LL * maxi2 * maxi2 + 1LL * v[i].x * v[i].x > mi) {             ok = 0;           }           if (1LL * mini2 * mini2 + 1LL * v[j + 1].x * v[j + 1].x > mi) {             ok = 0;           }           if (1LL * maxi2 * maxi2 + 1LL * v[j + 1].x * v[j + 1].x > mi) {             ok = 0;           }         }         if (!ok) {         } else {           ok = 1;           break;         }       }       if (ok)         hi = mi - 1;       else         lo = mi + 1;     }     return lo;   }   int main() {     int n;     vector<Point> v;     cin >> n;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       v.push_back(Point(x, y));     }     sort(v.begin(), v.end());     long long ans = solve(v);     ans = min(1LL * (v[0].x - v[n - 1].x) * (v[0].x - v[n - 1].x), ans);     for (int i = 0; i < n; i++) {       swap(v[i].x, v[i].y);     }     sort(v.begin(), v.end());     ans = min(1LL * (v[0].x - v[n - 1].x) * (v[0].x - v[n - 1].x), ans);     ans = min(ans, solve(v));     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long int aib[15][100005];   inline void update(long long int aib[], int pos, long long int val) {     for (; pos <= n; pos += ((pos) & (-(pos)))) aib[pos] += val;   }   inline long long int query(long long int aib[], int pos) {     long long int ans = 0;     for (; pos; pos -= ((pos) & (-(pos)))) ans += aib[pos];     return ans;   }   long long int dp[15][100005];   int main() {     ios_base ::sync_with_stdio(false);     int k;     cin >> n >> k;     ++k;     long long int ans = 0;     int val;     for (int i = 1; i <= n; ++i) {       cin >> val;       dp[1][i] = val;       update(aib[1], val, 1);       for (int j = 2; j <= k; ++j) {         dp[j][i] = query(aib[j - 1], val - 1);         update(aib[j], val, dp[j][i]);       }       ans += dp[k][i];     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   #define Mid ((l + r) >> 1)   #define lson (rt << 1)   #define rson (rt << 1 | 1)   using namespace std;   int read(){    char c; int num, f = 1;    while(c = getchar(),!isdigit(c)) if(c ==  - ) f = -1; num = c -  0 ;    while(c = getchar(), isdigit(c)) num = num * 10 + c -  0 ;    return f * num;   }   const int N = 2e5 + 1009;   int a, b, k;   int x[N], y[N];   signed main()   {    a = read(); b = read(); k = read();    if(k == 0) {     printf( Yes n );     for(int i = 1; i <= b; i++) printf( 1 );     for(int i = 1; i <= a; i++) printf( 0 );printf(  n );     for(int i = 1; i <= b; i++) printf( 1 );     for(int i = 1; i <= a; i++) printf( 0 );printf(  n );     return 0;    }    if(a + b < k + 2 || (a > 0 && b == 1) || a == 0) {     printf( No n );     return 0;    }    if(a >= k) {     y[1] = 1;     x[k + 1] = 1;     for(int i = a + 2; i <= a + b; i++)      x[i] = y[i] = 1;    } else {     y[1] = 1;     x[k + 1] = 1;     for(int i = a + 1; i <= k; i++) {      x[i] = y[i] = 1;     }     for(int i = k + 2; i <= a + b; i++)      x[i] = y[i] = 1;    }    reverse(x + 1, x + 1 + a + b);    reverse(y + 1, y + 1 + a + b);    printf( Yes n );    for(int i = 1; i <= a + b; i++) printf( %d , x[i]); printf(  n );    for(int i = 1; i <= a + b; i++) printf( %d , y[i]); printf(  n );    return 0;   }   /*   两个位置都为1   表示这两个位置之间的数都变成1   也就是说只用两个1就可以构造出来了      可以把中间一对0换成1   可以减少0的数量   至少需要2+k   */


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, r;     cin >> s;     int k, l, x, n;     cin >> k;     l = s.length();     if (l % k != 0) {       cout <<  NO n ;       return 0;     }     x = l / k;     for (int i = 0; i < l; i += x) {       r = s.substr(i, x);       n = r.length() - 1;       for (int j = 0; j <= n / 2; j++) {         if (r[j] != r[n - j]) {           cout <<  NO n ;           return 0;         }       }     }     cout <<  YES n ;     return 0;   }


#include <iostream>   #include <algorithm>   using namespace std;   inline int gcd(int a, int b) {       int Max = max(a, b);       int Min = min(a, b);       if (Max % Min == 0)           return Min;       else           return gcd(Min, Max % Min);   }   inline int lcm(int a, int b) {       return a * b / gcd(a, b);   }   int main()   {       int t; cin >> t;       int n, k;       while (t--) {           cin >> n >> k;           int temp1 = k - (n - k);           for (int i = 1; i < temp1; ++i)               cout << i <<    ;           for (int i = k; i >= temp1; --i)               cout << i <<    ;           cout <<   n ;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300005;   int q, n;   int a[MAXN], lef[MAXN], rig[MAXN];   vector<int> v;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> q;     while (q--) {       cin >> n;       for (int i = 1; i <= n; i++) {         lef[i] = rig[i] = -1;       }       v.clear();       for (int i = 1; i <= n; i++) {         cin >> a[i];         v.push_back(a[i]);         if (lef[a[i]] == -1) lef[a[i]] = i;         rig[a[i]] = i;       }       sort(v.begin(), v.end());       v.erase(unique(v.begin(), v.end()), v.end());       int cnt = 1, mx = 0;       for (int i = 0; i < v.size(); i++) {         if (i == v.size() - 1 || lef[v[i + 1]] < rig[v[i]]) {           mx = max(mx, cnt);           cnt = 0;         }         cnt++;       }       cout << v.size() - mx <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, j, qan, n, m, k, l, p;   bool mark[102];   char s;   int main() {     cin >> n;     for (i = 1; i <= n; i++) {       cin >> s;       if (s ==  * ) {         mark[i] = true;       }     }     qan = (n - 5) / 4;     for (i = 0; i <= qan; i++) {       for (j = 1; j <= n - 4 - 4 * i; j++) {         if (mark[j] == true && mark[j + i + 1] == true &&             mark[j + 2 * i + 2] == true && mark[j + 3 * i + 3] == true &&             mark[4 * i + j + 4] == true) {           cout <<  yes  << endl;           return 0;         }       }     }     cout <<  no  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int test;     cin >> test;     while (test--) {       char str[10000], cpy[10000], st[10000];       cin >> str;       int ln = strlen(str), ck = 0;       for (int i = 0, j = ln - 1; i < ln; i++, j--) {         cpy[j] = str[i];       }       for (int i = 0; i < ln; i++) {         if (str[i] == cpy[i]) {           ck = 1;         } else {           ck = 0;           cout << str << endl;           break;         }       }       if (ck) {         strcpy(st, str);         sort(str, str + ln);         if (!strcmp(str, st))           printf( -1 n );         else           cout << str << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   int a[MAXN];   int cnt[101][101];   int main() {     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       cnt[i % k][a[i]]++;     }     int ans = 0;     for (int i = 0; i < k; i++) {       ans += min(cnt[i][1], cnt[i][2]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1001001001;   const long long INFLL = 1001001001001001001LL;   template <typename T>   void pv(T a, T b) {     for (T i = a; i != b; ++i) cout << *i <<    ;     cout << endl;   }   template <typename T>   void chmin(T& a, T b) {     if (a > b) a = b;   }   template <typename T>   void chmax(T& a, T b) {     if (a < b) a = b;   }   int in() {     int x;     scanf( %d , &x);     return x;   }   double fin() {     double x;     scanf( %lf , &x);     return x;   }   long long lin() {     long long x;     scanf( %lld , &x);     return x;   }   int N, K, P, A[500005], S[500005], nxt[500005][101];   vector<int> pos[101];   int dp[101][10001];   int main() {     N = in();     K = in();     P = in();     int s = 0;     for (int i = 0; i < N; ++i) {       A[i] = in() % P;       S[i] = ((s += A[i]) %= P);       pos[s].push_back(i);     }     vector<int> nx(P, INF);     for (int i = 0; i < P; ++i) {       pos[i].push_back(INF);       nx[i] = pos[i][0];     }     s = 0;     for (int i = 0; i < N; ++i) {       for (int j = 0; j < P; ++j) {         nxt[i][(j - s + P) % P] = nx[j];       }       (s += A[i]) %= P;       nx[s] = *upper_bound(pos[s].begin(), pos[s].end(), i);     }     for (int i = 0; i <= 100; ++i) {       fill(dp[i], dp[i] + 10001, INF);     }     dp[0][0] = 0;     for (int k = 0; k + 1 < K; ++k) {       for (int x = 0; x < K * P; ++x) {         if (dp[k][x] >= N) continue;         const int f = dp[k][x];         for (int p = 0; p < P; ++p) {           if (nxt[f][p] == INF) continue;           chmin(dp[k + 1][x + p], nxt[f][p] + 1);         }       }     }     int res = INF;     for (int x = 0; x < K * P; ++x) {       if (dp[K - 1][x] >= N) continue;       int v = dp[K - 1][x];       int t = (S[N - 1] - S[v - 1] + P) % P;       chmin(res, x + t);     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int sizePermute, sizebkp, x, minimum = 100, maximum = 0, maximumIndex,                                  minimumIndex, counter = 0;     cin >> sizePermute;     sizebkp = sizePermute;     vector<int> myvec(sizePermute);     myvec.clear();     while (sizePermute != 0) {       cin >> x;       if (x < minimum) {         minimum = x;         minimumIndex = counter;       }       if (x > maximum) {         maximum = x;         maximumIndex = counter;       }       myvec.push_back(x);       sizePermute--;       counter++;     }     if (maximumIndex == (sizebkp - 1) && minimumIndex == 0) {       cout << sizebkp - 1 << endl;       return 0;     } else if (minimumIndex == (sizebkp - 1) && maximumIndex == 0) {       cout << sizebkp - 1 << endl;       return 0;     } else if (maximumIndex < minimumIndex &&                (((sizebkp - 1) - minimumIndex) > (maximumIndex - 0))) {       cout << sizebkp - 1 - maximumIndex << endl;       return 0;     } else if (maximumIndex < minimumIndex &&                (((sizebkp - 1) - minimumIndex) < (maximumIndex - 0))) {       cout << minimumIndex << endl;       return 0;     } else if (maximumIndex > minimumIndex &&                (((sizebkp - 1) - maximumIndex) > (minimumIndex - 0))) {       cout << sizebkp - 1 - minimumIndex << endl;       return 0;     } else if (maximumIndex > minimumIndex &&                (((sizebkp - 1) - maximumIndex) < (minimumIndex - 0))) {       cout << maximumIndex << endl;       return 0;     } else if (maximumIndex > minimumIndex &&                (((sizebkp - 1) - maximumIndex) == (minimumIndex - 0))) {       cout << sizebkp - 1 - minimumIndex << endl;       return 0;     } else if (maximumIndex < minimumIndex &&                (((sizebkp - 1) - minimumIndex) == (maximumIndex - 0))) {       cout << sizebkp - 1 - maximumIndex << endl;       return 0;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c;     cin >> a >> b >> c;     long long power = 0, l = 0, emp = 1, aa = 0;     for (long long i = 0; i > -1; i++) {       if (i != 0) {         for (long long j = 0; j < i; j++) {           emp = emp * c;         }       }       if (emp >= a && emp <= b) {         cout << emp <<    ;         power++;       }       if (emp > b / c) {         break;       }       emp = 1;     }     if (power == 0) {       cout <<  -1  << endl;     }     return 0;   }


#include <bits/stdc++.h>   const long long mod = 1000 * 1000 * 1000 + 7;   const long long mod1 = 998244353;   const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;   using namespace std;   long long power(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = (long long)(res * x);       y = y >> 1;       x = (long long)(x * x);     }     return res;   }   bool vis[3000];   vector<long long> a[3000];   vector<pair<long long, long long> > fin[3000];   map<long long, long long> suc;   long long val[3000];   long long c[3000];   long long cur = 1;   bool dfs(long long parent) {     long long f = 0;     long long s = 0;     for (auto edge : a[parent]) {       f += 1;       if (!vis[edge]) {         vis[edge] = true;         bool x = dfs(edge);         if (x == false) return false;         s += int((fin[edge]).size());         for (int j = 0; j < int((fin[edge]).size()); j++)           fin[parent].push_back(fin[edge][j]);       }     }     if (f == 1 and parent != a[0][0]) {       if (c[parent] > s) return false;       while (suc[cur] != 0) cur += 1;       fin[parent].push_back({cur, parent});       val[parent] = cur;       suc[cur] = 1;     } else {       if (c[parent] > s)         return false;       else {         sort(fin[parent].begin(), fin[parent].end());         if (c[parent] == 0) {           val[parent] = fin[parent][0].first;           suc[val[parent]] = 1;           for (int j = 0; j < int((fin[parent]).size()); j++) {             fin[parent][j].first += 1;             val[fin[parent][j].second] += 1;           }           suc[fin[parent].back().first] = 1;           fin[parent].push_back({val[parent], parent});         } else if (c[parent] == s) {           val[parent] = fin[parent].back().first + 1;           suc[val[parent]] = 1;           fin[parent].push_back({val[parent], parent});         } else {           val[parent] = fin[parent][c[parent]].first;           suc[val[parent]] = 1;           for (int j = c[parent]; j < int((fin[parent]).size()); j++) {             fin[parent][j].first += 1;             val[fin[parent][j].second] += 1;           }           suc[fin[parent].back().first] = 1;           fin[parent].push_back({val[parent], parent});         }       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     for (int(i) = (0); (i) < (n); ++(i)) {       long long x, y;       cin >> x >> y;       if (x != 0) a[i + 1].push_back(x);       a[x].push_back(i + 1);       c[i + 1] = y;     }     if (n == 1) {       if (c[1] == 0) {         cout <<  YES               <<   n ;         cout << 1;         return 0;       }     }     vis[a[0][0]] = true;     bool ans = dfs(a[0][0]);     if (ans == false) {       cout <<  NO ;     } else {       cout <<  YES             <<   n ;       for (int i = 1; i <= n; i++) cout << val[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 10005;   int a[N], sorted[N], n, m, sum[20][N], tree[20][N];   inline void build(int deep, int l, int r) {     int i, mid = (l + r) >> 1, lm = mid - l + 1, lp = l, rp = mid + 1;     for (i = l; i <= mid; i++)       if (sorted[i] > sorted[mid]) lm--;     for (i = l; i <= r; i++) {       if (i == l)         sum[deep][i] = 0;       else         sum[deep][i] = sum[deep][i - 1];       if (tree[deep][i] == sorted[mid]) {         if (lm) {           lm--;           sum[deep][i]++;           tree[deep + 1][lp++] = tree[deep][i];         } else           tree[deep + 1][rp++] = tree[deep][i];       } else if (tree[deep][i] > sorted[mid]) {         sum[deep][i]++;         tree[deep + 1][lp++] = tree[deep][i];       } else         tree[deep + 1][rp++] = tree[deep][i];     }     if (l != r) {       build(deep + 1, l, mid);       build(deep + 1, mid + 1, r);     }   }   int ask(int deep, int l, int r, int ql, int qr, int k) {     int s, ss, mid = (l + r) >> 1;     if (l == r) return tree[deep][l];     if (l == ql) {       s = 0;       ss = sum[deep][qr];     } else {       s = sum[deep][ql - 1];       ss = sum[deep][qr] - s;     }     if (k <= ss)       return ask(deep + 1, l, mid, l + s, l + s + ss - 1, k);     else       return ask(deep + 1, mid + 1, r, mid - l + 1 + ql - s,                  mid - l + 1 + qr - s - ss, k - ss);   }   inline bool cmp(int a, int b) { return a > b; }   inline int read() {     int x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline void write(int a) {     if (a >= 10) write(a / 10);     putchar( 0  + a % 10);   }   int main() {     n = read();     m = read();     for (int i = 1; i <= n; i++) a[i] = tree[0][i] = sorted[i] = read();     sort(sorted + 1, sorted + 1 + n, cmp);     build(0, 1, n);     while (m--) {       int s1 = read(), s2 = read(), s3 = read();       if (ask(0, 1, n, s1, s2, s2 - s3 + 1) == a[s3])         puts( Yes );       else         puts( No );     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 210, INF = 1 * 1000 * 1000 * 1000 + 10, maxm = 150, maxk = 10;   int n, m, k, sar, now, par[maxn], x[maxk], c[maxn], d[maxn], f[maxn][maxn],       dp[maxm][maxn], dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1}, cur, X, Y,                       save;   vector<int> t[maxm][maxn], path[maxn][maxn];   queue<int> q;   bool mark[maxn];   char ans[maxn][maxn];   inline bool valid(int &a, int &b) { return a >= 0 && a < n && b >= 0 && b < m; }   inline void SPFA() {     while (!q.empty()) {       sar = q.front();       X = sar / m;       Y = sar % m;       q.pop();       mark[sar] = 0;       for (int i = 0; i < 4; i++) {         X += dx[i];         Y += dy[i];         save = X * m + Y;         if (valid(X, Y) && d[save] > d[sar] + c[save]) {           d[save] = d[sar] + c[save];           par[save] = sar;           if (!mark[save]) {             q.push(save);             mark[save] = 1;           }         }         X -= dx[i];         Y -= dy[i];       }     }   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> m >> k;     for (int i = 0; i < n * m; i++) cin >> c[i];     for (int i = 0; i < n * m; i++) {       for (int j = 0; j < n * m; j++) d[j] = INF;       d[i] = 0;       par[i] = -1;       mark[i] = 1;       q.push(i);       SPFA();       for (int j = 0; j < n * m; j++) {         f[i][j] = d[j];         now = j;         while (par[now] != -1) {           path[i][j].push_back(now);           now = par[now];         }       }     }     memset(dp, 63, sizeof dp);     for (int i = 0; i < k; i++) {       cin >> X >> Y;       X--;       Y--;       x[i] = X * m + Y;       for (int j = 0; j < n * m; j++) {         dp[1 << i][j] = f[x[i]][j] + c[x[i]];         t[1 << i][j] = path[x[i]][j];         t[1 << i][j].push_back(x[i]);       }     }     for (int i = 3; i < (1 << k); i++) {       if (__builtin_popcount(i) > 1) {         for (int j = 0; j < n * m; j++) {           for (int sub = i; sub; sub = (sub - 1) & i) {             if (sub == i) continue;             cur = i ^ sub;             for (int p = 0; p < n * m; p++) {               if (dp[sub][p] + dp[cur][p] + f[p][j] - c[p] < dp[i][j]) {                 dp[i][j] = dp[sub][p] + dp[cur][p] + f[p][j] - c[p];                 save = sub;                 X = p;               }             }           }           cur = i ^ save;           t[i][j] = path[X][j];           for (int p = 0; p < ((int(t[save][X].size()))); p++)             t[i][j].push_back(t[save][X][p]);           for (int p = 0; p < ((int(t[cur][X].size()))); p++) {             if (t[cur][X][p] != X) t[i][j].push_back(t[cur][X][p]);           }         }       }     }     cout << dp[(1 << k) - 1][x[0]];     for (int i = 0; i < ((int(t[(1 << k) - 1][x[0]].size()))); i++)       ans[t[(1 << k) - 1][x[0]][i] / m][t[(1 << k) - 1][x[0]][i] % m] =  X ;     for (int i = 0; i < n; i++) {       cout << endl;       for (int j = 0; j < m; j++) {         if (ans[i][j] ==  X )           cout << ans[i][j];         else           cout <<  . ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1 << 21 | 1;   int n, p[N];   long long a[N], b[N], c[N];   char s[N], t[N];   void OR(long long* a) {     int i, j, u, v, l, t;     for (i = 2; i <= n; i <<= 1)       for (j = 0, t = i >> 1; j < n; j += i)         for (u = j, v = l = j + t; u < l; ++u, ++v) a[v] += a[u];   }   void IOR(long long* a) {     int i, j, u, v, l, t;     for (i = 2; i <= n; i <<= 1)       for (j = 0, t = i >> 1; j < n; j += i)         for (u = j, v = l = j + t; u < l; ++u, ++v) a[v] -= a[u];   }   int main() {     int m, i;     scanf( %d%s%s , &m, s, t), n = 1 << m;     for (i = 1; i < n; ++i) p[i] = p[i - (i & -i)] + 2;     for (i = 0; i < n; ++i)       a[i] = (s[i] - 48ll) << p[i], b[i] = (t[i] - 48ll) << p[i];     OR(a), OR(b);     for (i = 0; i < n; ++i) c[i] = a[i] * b[i];     IOR(c);     for (i = 0; i < n; ++i) putchar(c[i] >> p[i] & 3 | 48);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 100;   const double PI = 3.14159;   vector<int> v;   long long n, m, k, t, ans, sum, r, l, b, c, d, a;   bool f;   string s;   set<int> st;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n >> m;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       sum += x;       ans += sum / m;       sum %= m;       cout << ans <<    ;       ans = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int INF = 1e9 + 5;   const long long INF64 = 1e18;   string to_string(const string &s) { return     + s +    ; }   string to_string(bool b) { return b ?  true  :  false ; }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename T>   string to_string(const vector<T> &v) {     string ret =  < ;     for (auto it : v) ret += to_string(it) +  ,  ;     ret.pop_back();     ret.pop_back();     ret +=  > ;     return ret;   }   void debug_print() { cerr << endl; }   template <typename T, typename... U>   void debug_print(T t, U... u) {     cerr <<     << to_string(t);     debug_print(u...);   }   const int N = 1e5 + 5;   long long mulmod(long long a, long long b) {     a %= MOD;     b %= MOD;     return (a * b) % MOD;   }   long long f(long long n) {     long long r = (n + 1) / 2;     if (n & 1) return mulmod(r, r);     return mulmod(r, r + 1);   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       n += 2;       n /= 2;       cout << f(n) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   bool vis[N];   int n, a[N], go[N];   pair<int, int> v[N];   bool isLucky(int x) {     while (x > 0) {       if (x % 10 != 4 && x % 10 != 7) return false;       x /= 10;     }     return true;   }   void solve() {     bool hasLN = false;     for (int i = (0); i < (n); ++i)       if (isLucky(a[i])) {         hasLN = true;         break;       }     if (!hasLN) {       for (int i = (0); i < (n - 1); ++i)         if (a[i] > a[i + 1]) {           puts( -1 );           return;         }       puts( 0 );       return;     }     for (int i = (0); i < (n); ++i) v[i] = make_pair(a[i], i);     sort(v, v + n);     for (int i = (0); i < (n); ++i) go[v[i].second] = i;     vector<pair<int, int> > ans;     for (int i = (0); i < (n); ++i)       if (!vis[i] && isLucky(a[i])) {         vector<int> vec;         int x = go[i];         while (!vis[x]) {           vec.push_back(x), vis[x] = true;           x = go[x];         }         if (((int)(vec).size()) == 1) continue;         for (int j = (((int)(vec).size()) - 1) - 1; j >= (0); --j) {           ans.push_back(make_pair(vec[j], vec[j + 1]));           swap(a[vec[j]], a[vec[j + 1]]);         }       }     int p;     for (int i = (0); i < (n); ++i)       if (vis[i] && isLucky(a[i])) {         p = i;         break;       }     for (int i = (0); i < (n); ++i)       if (!vis[i]) {         vector<int> vec;         int x = i;         while (!vis[x]) {           vec.push_back(x), vis[x] = true;           x = go[x];         }         if (((int)(vec).size()) == 1) continue;         for (int j = (((int)(vec).size())) - 1; j >= (0); --j) {           ans.push_back(make_pair(p, vec[j]));           swap(p, vec[j]);           swap(a[p], a[vec[j]]);         }         ans.push_back(make_pair(p, vec.back()));         swap(p, vec.back());         swap(a[p], a[vec.back()]);       }     if (((int)(ans).size()) > 2 * n) {       puts( -1 );       return;     }     printf( %d n , ((int)(ans).size()));     for (int i = (0); i < (((int)(ans).size())); ++i) {       int x, y;       tie(x, y) = ans[i];       printf( %d %d n , x + 1, y + 1);     }   }   int main() {     scanf( %d , &n);     for (int i = (0); i < (n); ++i) scanf( %d , a + i);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   namespace IO {   bool REOF = 1;   inline char nc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && REOF &&                    (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? (REOF = 0, EOF)                : *p1++;   }   template <class T>   inline bool read(T &x) {     if (!REOF) return false;     char c = nc();     bool f = 0;     x = 0;     while (c <  0  || c >  9 ) c ==  -  && (f = 1), c = nc();     while (c >=  0  && c <=  9 ) x = (x << 3) + (x << 1) + (c ^ 48), c = nc();     if (f) x = -x;     return true;   }   template <typename T, typename... T2>   inline bool read(T &x, T2 &...rest) {     if (!REOF) return false;     read(x);     return read(rest...);   }   inline bool need(char &c) {     return ((c >=  a ) && (c <=  z )) || ((c >=  0 ) && (c <=  9 )) ||            ((c >=  A ) && (c <=  Z ));   }   inline bool read_str(char *a) {     if (!REOF) return false;     while ((*a = nc()) && need(*a) && REOF) ++a;     *a =   0 ;     return true;   }   inline bool read_dbl(double &x) {     if (!REOF) return false;     bool f = 0;     char ch = nc();     x = 0;     while (ch <  0  || ch >  9 ) {       f |= (ch ==  - );       ch = nc();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10.0 + (ch ^ 48);       ch = nc();     }     if (ch ==  . ) {       double tmp = 1;       ch = nc();       while (ch >=  0  && ch <=  9 ) {         tmp = tmp / 10.0;         x = x + tmp * (ch ^ 48);         ch = nc();       }     }     if (f) x = -x;     return true;   }   template <class TH>   void _dbg(const char *sdbg, TH h) {     cerr << sdbg <<  =  << h <<   n ;   }   template <class TH, class... TA>   void _dbg(const char *sdbg, TH h, TA... a) {     while (*sdbg !=  , ) cerr << *sdbg++;     cerr <<  =  << h <<  ,  <<    ;     _dbg(sdbg + 1, a...);   }   template <class T>   ostream &operator<<(ostream &os, vector<T> V) {     os <<  [ ;     for (auto vv : V) os << vv <<  , ;     return os <<  ] ;   }   template <class L, class R>   ostream &operator<<(ostream &os, pair<L, R> P) {     return os <<  (  << P.st <<  ,  << P.nd <<  ) ;   }   }  // namespace IO   using namespace IO;   const int maxn = 2e5 + 5;   const int mod = 998244353;   const int INF = 1e9 + 7;   const double eps = 1e-12;   int dx[4] = {0, 0, 1, -1};   int dy[4] = {1, -1, 0, 0};   int n, x, y;   int best() {     int z = x + y + 1;     return max(z - n, 1);   }   int worst() {     int z = x + y;     return min(z - 1, n);   }   void solve() {     read(n, x, y);     if (x > y) swap(x, y);     if (x == 1 && y == 1) {       printf( 1 1 n );       return;     }     if (x == n && y == n) {       printf( %d %d n , n, n);       return;     }     printf( %d %d n , best(), worst());   }   int main() {     int _T;     read(_T);     for (int _ = 1; _ <= _T; _++) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long int a, b, c, l;   int main() {     ios::sync_with_stdio(false);     cin >> a >> b >> c >> l;     unsigned long long int ans = ((l + 3) * (l + 2) * (l + 1)) / (6);     for (int i = 0; i <= l; i++) {       if (a + i >= b + c) {         unsigned long long int x =             ((a + i - b - c) < (l - i) ? (a + i - b - c) : (l - i));         ans -= ((x + 2) * (x + 1)) / (2);       }     }     for (int i = 0; i <= l; i++) {       if (b + i >= a + c) {         unsigned long long int x =             ((b + i - a - c) < (l - i) ? (b + i - a - c) : (l - i));         ans -= ((x + 2) * (x + 1)) / (2);       }     }     for (int i = 0; i <= l; i++) {       if (c + i >= b + a) {         unsigned long long int x =             ((c + i - a - b) < (l - i) ? (c + i - a - b) : (l - i));         ans -= ((x + 2) * (x + 1)) / (2);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 5;   string s;   long long a, b;   long long v[N], pre[N], suf[N];   int32_t main() {     cin >> s >> a >> b;     long long n = s.size();     for (long long i = 1; i <= n; i++) v[i] = s[i - 1] -  0 ;     for (long long i = 1; i <= n; i++) {       pre[i] = pre[i - 1] * 10 + v[i];       pre[i] %= a;     }     long long curpow = 1;     for (long long i = n; i >= 1; i--) {       suf[i] = v[i] * curpow + suf[i + 1];       curpow *= 10;       curpow %= b;       suf[i] %= b;     }     long long check = 0, ind;     for (long long i = 1; i < n; i++) {       if (pre[i] == 0 && suf[i + 1] == 0 && v[i + 1] != 0) {         ind = i;         check = 1;       }     }     if (check) {       cout <<  YES             <<   n ;       for (long long i = 1; i <= ind; i++) {         cout << v[i];       }       cout <<   n ;       for (long long i = ind + 1; i <= n; i++) {         cout << v[i];       }     } else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int de(int x) {     if (x == 0) return 0;     if (x & 1) return de(x / 2) + 1;     return de(x / 2);   }   long long val[101000];   int main() {     int n, i, j, a;     while (scanf( %d , &n) != EOF) {       memset(val, 0, sizeof(val));       for (i = 0; i < n; i++) {         scanf( %d , &a);         val[de(a)]++;       }       long long ans = 0;       for (i = 0; i <= 50000; i++) ans += (val[i] * (val[i] - 1)) / 2;       printf( %I64d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string n, r;     cin >> n;     r = n;     reverse(r.begin(), r.end());     cout << n << r <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       bool usa[n], usb[n];       for (int i = 0; i < n; ++i) {         usa[i] = 1;         usb[i] = 1;       }       for (int i = 0; i < n; ++i) {         int a;         cin >> a;         bool f = 1;         for (int j = 0; j < a; j++) {           int b;           cin >> b;           if (usb[b - 1] && f) {             usb[b - 1] = 0;             usa[i] = 0;             f = 0;           }         }       }       bool c = 0, d = 0;       int x, y;       for (int i = 0; i < n; ++i) {         if (usa[i] && !c) {           x = i + 1;           c = 1;         }         if (usb[i] && !d) {           y = i + 1;           d = 1;         }       }       if (c)         cout <<  IMPROVE  << endl << x <<     << y << endl;       else         cout <<  OPTIMAL  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     bool f = false;     char ch = getchar();     while (!isdigit(ch)) {       f |= ch ==  - ;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return f ? -x : x;   }   void write(int x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) write(x / 10);     putchar(x % 10 + 48);   }   const int N = 2505, INF = 0x7fffffff;   int n;   int a[N][N];   int fa[N], d[N];   bool vis[N];   inline void prim() {     for (int i = 2; i <= n; i++) fa[i] = 1, d[i] = a[1][i];     memset(vis, false, sizeof(vis));     vis[1] = true;     int k, minn;     for (int tot = 2; tot <= n; tot++) {       minn = INF;       for (int i = 1; i <= n; i++)         if (minn > d[i] && !vis[i]) minn = d[i], k = i;       vis[k] = true;       for (int i = 1; i <= n; i++)         if (a[k][i] < d[i] && !vis[i]) d[i] = a[k][i], fa[i] = k;     }   }   int dep[N];   void getdep(int x) {     if (!dep[fa[x]]) getdep(fa[x]);     dep[x] = dep[fa[x]] + 1;   }   int main() {     n = read();     for (register int i = 1; i <= n; i++)       for (register int j = 1; j <= n; j++) a[i][j] = read();     for (register int i = 1; i <= n; i++)       if (a[i][i]) return puts( NOT MAGIC ), 0;     for (register int i = 1; i <= n; i++)       for (register int j = i + 1; j <= n; j++)         if (a[i][j] != a[j][i]) return puts( NOT MAGIC ), 0;     prim();     dep[1] = 1;     for (register int i = 2; i <= n; i++)       if (!dep[i]) getdep(i);     for (register int i = 1; i <= n; i++)       for (register int j = i + 1; j <= n; j++) {         int x = i, y = j;         if (dep[x] < dep[y]) swap(x, y);         if (a[x][y] > max(a[fa[x]][y], a[fa[x]][x])) return puts( NOT MAGIC ), 0;       }     return puts( MAGIC ), 0;   }


#include <bits/stdc++.h>   using namespace std;   int nn[100000], np[100000][19], ni[100000], nl[100000], nh[100000], nc[100000],       nv[100000], nd[100000], dist[100000];   vector<int> ne[100000];   int es[100000], ee[100000];   bool eb[100000];   int curp[100000];   int trav = 0;   bool dfs(int n, int p) {     ni[n] = nl[n] = nh[n] = trav++;     nc[n] = 1;     for (int i = 0; i < ne[n].size(); i++) {       int other = es[ne[n][i]];       if (other == n) {         other = ee[ne[n][i]];       }       if (other == p) continue;       if (ni[other] == -1) {         if (dfs(other, n)) {           eb[ne[n][i]] = true;         }         nc[n] += nc[other];         nl[n] = min(nl[n], nl[other]);         nh[n] = max(nh[n], nh[other]);       } else {         nl[n] = min(nl[n], ni[other]);         nh[n] = max(nh[n], ni[other]);       }     }     if (nl[n] == ni[n] && nh[n] < ni[n] + nc[n]) {       return true;     }     return false;   }   class queue_order {    public:     int n;     bool bridge;     queue_order(int a, bool b) {       n = a;       bridge = b;     }   };   struct cmp {     bool operator()(queue_order* a, queue_order* b) {       if (a->bridge == b->bridge) return false;       if (a->bridge) return true;       return false;     }   };   void condense() {     int curnn = 0;     priority_queue<queue_order*, vector<queue_order*>, cmp> pq;     pq.push(new queue_order(0, false));     while (pq.size() > 0) {       queue_order* o = pq.top();       pq.pop();       if (nn[o->n] != -1) continue;       if (o->bridge) curnn++;       nn[o->n] = curnn;       for (int i = 0; i < ne[o->n].size(); i++) {         int other = es[ne[o->n][i]];         if (other == o->n) {           other = ee[ne[o->n][i]];         }         if (nn[other] != -1) continue;         pq.push(new queue_order(other, eb[ne[o->n][i]]));       }     }   }   void dfs2(int n, int p, int d) {     curp[d] = n;     nd[n] = d;     for (int i = 0; i < 18; i++) {       if (d - (1 << i) >= 0) {         np[n][i] = curp[d - (1 << i)];       } else {         np[n][18] = i - 1;         break;       }     }     for (int i = 0; i < ne[n].size(); i++) {       int other = es[ne[n][i]];       if (other == n) {         other = ee[ne[n][i]];       }       if (other == p) continue;       dfs2(other, n, d + 1);     }   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     memset(nv, 0, n * sizeof(int));     memset(nn, -1, n * sizeof(int));     memset(ni, -1, n * sizeof(int));     memset(nc, 0, n * sizeof(int));     memset(eb, false, m * sizeof(bool));     for (int i = 0; i < m; i++) {       scanf( %d %d , &es[i], &ee[i]);       es[i]--;       ee[i]--;       ne[es[i]].push_back(i);       ne[ee[i]].push_back(i);     }     dfs(0, 0);     condense();     for (int i = 0; i < n; i++) {       ne[i].clear();     }     for (int i = 0; i < m; i++) {       es[i] = nn[es[i]];       ee[i] = nn[ee[i]];       if (es[i] != ee[i]) {         ne[es[i]].push_back(i);         ne[ee[i]].push_back(i);       }     }     int root = 0;     queue<int> q;     queue<int> d;     q.push(root);     nv[root] = 1;     while (q.size() > 0) {       int cur = q.front();       q.pop();       root = cur;       for (int i = 0; i < ne[cur].size(); i++) {         int other = es[ne[cur][i]];         if (other == cur) {           other = ee[ne[cur][i]];         }         if (nv[other] < 1) {           nv[other] = 1;           q.push(other);         }       }     }     q.push(root);     d.push(0);     nv[root] = 2;     int maxd = 0;     while (q.size() > 0) {       int cur = q.front();       q.pop();       int curd = d.front();       d.pop();       maxd = curd;       dist[curd] = cur;       for (int i = 0; i < ne[cur].size(); i++) {         int other = es[ne[cur][i]];         if (other == cur) {           other = ee[ne[cur][i]];         }         if (nv[other] < 2) {           nv[other] = 2;           q.push(other);           d.push(curd + 1);         }       }     }     root = dist[maxd / 2];     dfs2(root, root, 0);     int k, s, e, s2, e2;     scanf( %d , &k);     while (k-- > 0) {       scanf( %d %d , &s, &e);       s = s2 = nn[s - 1];       e = e2 = nn[e - 1];       while (s2 != e2) {         if (nd[s2] < nd[e2]) {           for (int i = np[e2][18]; i >= 0; i--) {             if (nd[e2] - (1 << i) >= nd[s2]) {               e2 = np[e2][i];             }           }         } else if (nd[s2] > nd[e2]) {           for (int i = np[s2][18]; i >= 0; i--) {             if (nd[s2] - (1 << i) >= nd[e2]) {               s2 = np[s2][i];             }           }         } else {           for (int i = np[s2][18]; i > 0; i--) {             if (np[s2][i] != np[e2][i]) {               s2 = np[s2][i];               e2 = np[e2][i];             }           }           s2 = np[s2][0];           e2 = np[e2][0];         }       }       printf( %d n , nd[s] + nd[e] - 2 * nd[s2]);     }     return 0;   }


#include<bits/stdc++.h>      #define fill(arr,c) memset(arr,c,sizeof(arr))   #define perm(r) next_permutation(all(r))   //it gives bool value ans permute the string lexoggraphically   #define sortdesc greater<int>()   #define ll long long int    //std::setfill( 0 ) << std::setw(5) << 25; it adds leaing zeroes;   #define f(i,a) for(ll i=0;i<a;i++)   #define fo(i,a) for(ll i=1;i<=a;i++)   #define foo(i,x,n,c) for(ll i=x;i<n;i+=c)   #define foi(i,x,n,c) for(ll i=x;i>=n;i+=c)   #define fauto(i,m) for(auto i:m)   #define forall(a) for( auto itr=a.begin();itr!=a.end();itr++)   #define ld long double   #define in push_back   #define mll map<ll,ll>   #define mcl map<char,ll>   #define msl map<string,ll>   #define vi vector<int >   #define vl vector<ll >   #define vp vector< pair<int,int> >   #define vs vector <string>    #define vc vector <char>    #define o(a) cout<<a   #define os(a) cout<<a<<      #define en cout<<  n ;   #define testcase ll t ;cin>>t; while(t--)   #define ff first   #define ss second   #define pl pair<ll,ll>   #define pi pair<int,int>   #define all(a) (a).begin(), (a).end()      #define sz(a)  (a).size()   #define prec(n) fixed<<setprecision(n)   #define mp make_pair   #define bitcount  __builtin_popcountll   #define imin o( imin );en;   using namespace std;   bool comp(const pair<int,int> &a , const pair<int,int> &b){       if(a.first == b.first)  return a.second < b.second;        return a.first < b.first;   }   bool comps(const pair<int,int> &a , const pair<int,int> &b){       if(a.second == b.second)  return a.first< b.first;        return a.second < b.second;   }    bool prime[1000005];    void primeseries(ll n)   {          memset(prime, true, sizeof(prime));             for (ll p=2; p*p<=n; p++)        {            // If prime[p] is not changed, then it is a prime            if (prime[p] == true)            {                // Update all multiples of p greater than or                 // equal to the square of it                // numbers which are multiple of p and are                // less than p^2 are already been marked.                 for (ll i=p*p; i<=n; i += p)                    prime[i] = false;            }        }   //return prime;       }   struct custom_hash {       size_t operator()(uint64_t x) const {           static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();           x ^= FIXED_RANDOM;           return x ^ (x >> 16);       }   };   bool compmx(int a, int b)    {        return (a < b);    }    // bool isprime(int x){   //     for(int i = 2; i*i <= x; i++){   //         if(x%i == 0) return false;   //     }   //     return true;   // }   //   //ll pi=acos(0.0)*2;   void fastio()   {        ios::sync_with_stdio(0);   cin.tie(0);      }   ll mod=1E9+7;   void inout()   {          #ifndef ONLINE_JUDGE       freopen( input.txt ,  r , stdin);           freopen( output.txt ,  w , stdout);        #endif   }   unsigned long long power(unsigned long long x,                                      int y, int p)   {       unsigned long long res = 1; // Initialize result           x = x % p; // Update x if it is more than or       // equal to p           while (y > 0)        {                   // If y is odd, multiply x with result           if (y & 1)               res = (res * x) % p;               // y must be even now           y = y >> 1; // y = y/2           x = (x * x) % p;       }       return res;   }       // Returns n^(-1) mod p   unsigned long long modInverse(unsigned long long n,                                                 int p)   {       return power(n, p - 2, p);   }       // Returns nCr % p using Fermat s little   // theorem.   unsigned long long nCr(unsigned long long n,                                    int r, int p)   {       // If n<r, then nCr should return 0       if (n < r)           return 0;       // Base case       if (r == 0)           return 1;           // Fill factorial array so that we       // can find all factorial of r, n       // and n-r       unsigned long long fac[n + 1];       fac[0] = 1;       for (int i = 1; i <= n; i++)           fac[i] = (fac[i - 1] * i) % p;           return (fac[n] * modInverse(fac[r], p) % p               * modInverse(fac[n - r], p) % p)              % p;   }   bool chk(ll i,ll a,ll b,ll n)    {    ll x=i*a+(n-i)*b;    bool r=true;    while(x)        {     if(x%10!=a && x%10!=b)     return false;     x/=10;    }    return true;   }   //ll a[1001][1001];      int main()   {   //fastio();   //os(1);;   testcase   {         ll n,m,u,v;   cin>>n>>m>>u>>v;   ll a[m];   f(i,m)   cin>>a[i];   sort(a,a+m);   f(i,m)   a[i]++;   ll ans=0;   if(u>v)   {    u=n-u+1;    v=n-v+1;   }   ll prev=m;   f(i,v)   {    ll x=upper_bound(a,a+prev,v-i-1)-a;    x--;    prev=x;    if(x>=0)    ans++;    else    break;   }   o(min(ans,v-u-1));      en;   }   return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {     bool first = true;     os <<  [ ;     for (unsigned int i = 0; i < v.size(); i++) {       if (!first) os <<  ,  ;       os << v[i];       first = false;     }     return os <<  ] ;   }   template <typename T>   inline std::ostream& operator<<(std::ostream& os, const std::set<T>& v) {     bool first = true;     os <<  [ ;     for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end();          ++ii) {       if (!first) os <<  ,  ;       os << *ii;       first = false;     }     return os <<  ] ;   }   template <typename T1, typename T2>   inline std::ostream& operator<<(std::ostream& os, const std::map<T1, T2>& v) {     bool first = true;     os <<  [ ;     for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end();          ++ii) {       if (!first) os <<  ,  ;       os << *ii;       first = false;     }     return os <<  ] ;   }   struct debugger {     bool first;     debugger() { first = true; }     template <typename T>     debugger& operator,(const T& v) {       if (!first) cout <<  ,  ;       cout << v;       first = false;       return *this;     }   };   long long n;   long long arr[10000000];   long long solve() {     vector<long long> st;     long long mx = 0;     for (long long i = 0; i < n; i++) {       while (!st.empty() && st.back() < arr[i]) st.pop_back();       st.push_back(arr[i]);       if (st.size() >= 2) mx = max(mx, st[st.size() - 1] ^ st[st.size() - 2]);     }     return mx;   }   int32_t main(void) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (long long i = 0; i < n; i++) cin >> arr[i];     long long mx = solve();     reverse(arr, arr + n);     cout << max(mx, solve());   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int find_first_num_index(long long &k, long long n) {     if (n == 1) {       return 0;     }     n--;     int first_num_index;     long long n_partial_fact = n;     while (k >= n_partial_fact && n > 1) {       n_partial_fact *= (n - 1);       n--;     }     first_num_index = k / n_partial_fact;     k %= n_partial_fact;     return first_num_index;   }   vector<long long> find_kth_permutation(long long n, long long k) {     vector<long long> Ans;     set<long long> S;     for (int i = 1; i <= n; i++) {       S.insert(i);     }     auto itr = S.begin();     k -= 1;     for (int i = 0; i < n; i++) {       int index = find_first_num_index(k, n - i);       advance(itr, index);       Ans.push_back((*itr));       S.erase(itr);       itr = S.begin();     }     return Ans;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long n, q, t, x = 1;     cin >> n >> q;     long long suff_len = min(14LL, n);     long long pref_len = n - suff_len;     long long Sil[20];     Sil[0] = 1;     for (int i = 1; i <= suff_len; i++) {       Sil[i] = Sil[i - 1] * i;     }     vector<long long> Suff = find_kth_permutation(suff_len, 1);     while (q--) {       cin >> t;       if (t == 1) {         long long l, r, ans = 0;         cin >> l >> r;         int r_pr = min(r, pref_len);         if (l <= r_pr) {           ans += 1ll * (l + r_pr) * (r_pr - l + 1) / 2;         }         r -= pref_len + 1;         l -= pref_len + 1;         r_pr = max(r_pr - pref_len - 1, 0LL);         for (int i = max(l, 0LL); i <= r; i++) {           ans += pref_len + Suff[i];         }         cout << ans << endl;       } else {         int dx;         cin >> dx;         x += dx;         x = min(x, Sil[suff_len]);         Suff = find_kth_permutation(suff_len, x);       }     }     return 0;   }


#include <bits/stdc++.h>   inline int read() {     char c;     int x;     for (c = getchar(); !isdigit(c); c = getchar())       ;     for (x = 0; isdigit(c); c = getchar()) {       x = x * 10 + c -  0 ;     }     return x;   }   int n;   long long ans;   std::priority_queue<int> que;   int main() {     n = read();     for (int i = 0; i < n; i++) {       int x = read();       que.push(-x);       if (que.top() + x > 0) {         ans += que.top() + x;         que.push(-x);         que.pop();       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     int n, m, k;     while (t--) {       cin >> n >> m >> k;       if (n % 2 == 0 && k % 2 == 1) {         cout <<  NO n ;         continue;       }       if (n % 2 == 0 && k % 2 == 0) {         if (m % 2 == 0)           cout <<  YES n ;         else {           if (k > n * (m - 1) / 2)             cout <<  NO n ;           else             cout <<  YES n ;         }         continue;       }       if (m / 2 % 2 == 0) {         if (k % 2 == 0 && k >= m / 2)           cout <<  YES n ;         else           cout <<  NO n ;       } else {         if (k % 2 == 1 && k >= m / 2)           cout <<  YES n ;         else           cout <<  NO n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e7;   const long long MOD = 1e9 + 7;   const long long mod = 998244353;   const int MAX_N = 1e5 + 5;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 << endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   vector<int> adj[1005];   int tsz[1005];   bool ga[1005];   void dfs(int u, int v = -1) {     tsz[u] = 1;     if (adj[u].size() == 1) ga[u] = true;     for (auto xd : adj[u]) {       if (xd == v) continue;       dfs(xd, u);       tsz[u] += tsz[xd];     }   }   int main() {     int tc;     cin >> tc;     while (tc--) {       for (int i = 0; i < 1005; i++) {         adj[i].clear();         tsz[i] = 0;       }       int n, x;       cin >> n >> x;       for (int i = 0; i < n - 1; i++) {         int a, b;         cin >> a >> b;         adj[a].push_back(b);         adj[b].push_back(a);       }       dfs(x);       if (adj[x].size() <= 1) {         cout <<  Ayush  << endl;         continue;       }       long long p = tsz[x] - 1;       if (p % 2 == 0)         cout <<  Ashish  << endl;       else         cout <<  Ayush  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 152;   int previ[maxn];   int curr[maxn];   int temp[maxn];   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     previ[0] = 1;     curr[1] = 1;     for (int i = 0; i < n - 1; i++) {       temp[0] = 0;       for (int j = 0; j <= i + 1; j++) {         temp[j + 1] = curr[j];       }       for (int j = 0; j <= i; j++) {         temp[j] = (temp[j] + previ[j]) % 2;       }       for (int j = 0; j <= i + 2; j++) {         previ[j] = curr[j];         curr[j] = temp[j];       }     }     cout << n << endl;     for (int i = 0; i <= n; i++) {       cout << curr[i] <<    ;     }     cout << endl;     cout << n - 1 << endl;     for (int i = 0; i <= n - 1; i++) {       cout << previ[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &dig) {     dig = 0;     bool flag = false;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - ) flag = true, c = getchar();     while (isdigit(c)) dig = dig * 10 + c -  0 , c = getchar();     if (flag) dig = -dig;   }   const int MAXN = (int)5e3 + 5;   int n, maxn = INT_MIN;   int times[MAXN], prep[MAXN];   inline void init() {     read(n);     for (register int i = (1); i <= (n); ++i) read(times[i]), prep[i] = times[i];     for (register int i = (2); i <= (n); ++i) prep[i] += prep[i - 1];   }   inline void solve() {     for (register int i = (1); i <= (n); ++i) {       for (register int j = (i); j <= (n); ++j) {         if (100 * (j - i + 1) < prep[j] - prep[i - 1])           maxn = max(maxn, j - i + 1);         else           continue;       }     }     printf( %d , maxn == INT_MIN ? 0 : maxn);   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, cnt;     double ans, a, dp[100005] = {0}, pr[100005] = {0};     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a;       pr[i] = pr[i - 1] * a + a;       dp[i] = dp[i - 1] + a * (2 * pr[i - 1] + 1);     }     printf( %.15lf , dp[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int fa[5010], ba[5010], b[5010];   int main() {     ios_base::sync_with_stdio(0);     int i, j, k, l, n, m, t, tt, x = 0, y;     string s, second;     cin >> s;     n = s.length();     fa[0] = 0;     ba[n + 1] = 0;     b[0] = 0;     for (j = 1; j <= n; j++) {       fa[j] = fa[j - 1];       b[j] = b[j - 1];       if (s[j - 1] ==  a )         fa[j] = fa[j] + 1;       else         b[j] = b[j] + 1;     }     if (fa[n] == n) {       cout << n <<   n ;       return 0;     }     for (j = n; j > 0; j--) {       ba[j] = ba[j + 1];       if (s[j - 1] ==  a ) ba[j] = ba[j] + 1;     }     int mx = 0;     for (i = 1; i <= n; i++) {       for (j = i; j <= n; j++) {         mx = max(fa[i - 1] + b[j] - b[i - 1] + ba[j + 1], mx);       }     }     cout << mx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int maxn;   int vis[100010], a[100010], in[100010], temp[100010], res[100010];   vector<int> q[100010];   int bfs(int x) {     int i, sum = 1, hash[100010] = {0};     hash[x] = 1;     while (in[x] < 2) {       temp[sum++] = x;       if (!hash[q[x][0]]) {         if (q[x][0] == 0) break;         x = q[x][0];       }     }     return sum - 1;   }   int main() {     int i, n;     while (scanf( %d , &n) != EOF) {       maxn = 0;       memset(in, 0, sizeof(in));       for (i = 1; i <= n; i++) scanf( %d , &vis[i]);       for (i = 1; i <= n; i++) {         scanf( %d , &a[i]);         in[a[i]]++;         q[i].push_back(a[i]);       }       for (i = 1; i <= n; i++) {         if (vis[i]) {           int t = bfs(i);           if (t > maxn) {             maxn = t;             for (int j = 1; j <= maxn; j++) res[j] = temp[j];           }         }       }       printf( %d n , maxn);       for (i = maxn; i > 0; i--) {         if (i != maxn) printf(   );         printf( %d , res[i]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   template <typename T>   inline void read(T &x) {     bool b = 0;     char c;     while (!isdigit(c = getchar()) && c !=  - )       ;     if (c ==  - ) c = getchar(), b = 1;     x = c - 48;     while (isdigit(c = getchar())) x = (x << 3) + (x << 1) + c - 48;     if (b) x = -x;   }   template <typename T>   inline void write(T x) {     if (x > 9) write(x / 10);     putchar(x % 10 + 48);   }   using namespace std;   const int N = 1e5 + 11;   int n, pos1, pos0, a[N], ans[N], ke[N], num[2];   int Max0(int pos) {     int res = 0;     for (int i = 1; i <= pos; i++) {       num[a[i]]++;       if (a[i])         res++;       else         res = max(res, num[0]);     }     num[0] = num[1] = 0;     return res;   }   int Max1(int pos) {     int res = 0;     for (int i = 1; i <= pos; i++) {       num[ans[i]]++;       if (ans[i])         res++;       else         res = max(res, num[0]);     }     num[0] = num[1] = 0;     return res;   }   int main() {     char c;     while (isdigit(c = getchar())) a[++n] = c - 48;     for (int i = 1; i <= n; i++) ans[i] = a[i];     ke[n + 1] = n;     ke[n] = n;     for (int i = n - 1; i > 0; i--) {       if (a[i] == a[i + 1])         ke[i] = ke[i + 1];       else         ke[i] = i;     }     for (int i = 1; i <= n; i++)       if (a[i]) {         pos1 = i;         break;       }     while (pos1 <= n) {       pos0 = ke[pos1] + 1;       int num0 = ke[pos0] - pos0 + 1;       int num1 = ke[pos1] - pos1 + 1;       if (num0 < num1) {         num1 -= num0;         for (int i = 1; i <= num1; i++) {           ans[pos1 + i - 1] = 0;           if (Max0(pos1 + i - 1) != Max1(pos1 + i - 1) || Max0(n) != Max1(n))             ans[pos1 + i - 1] = 1;         }       }       pos1 = ke[pos0] + 1;     }     for (int i = 1; i <= n; i++) cout << ans[i];   }


#include <bits/stdc++.h>   using namespace std;   int n, i, j, m, k;   int a[2000000];   bool bo[2000000];   int l, r, ans, tot;   int main() {     scanf( %d%d%d , &n, &m, &k);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + 1 + n);     int now = 0;     bo[0] = true;     for (i = 1; i <= n; i++) {       tot++;       while (a[i] - a[now] >= m && now <= n) tot -= (!bo[now]), now++;       if (tot >= k) ans++, tot--, bo[i] = true;     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int A[200005];   vector<int> L[105];   int dp[400005];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &A[i]);       L[A[i]].push_back(i);     }     int opt = 0;     int D = 0;     int N = min(n, 100);     for (int i = 1; i <= N; i++) {       if (L[i].size() > L[D].size()) D = i;     }     memset(dp, -1, sizeof(dp));     for (int V = 1; V <= N; V++) {       if (V == D) continue;       if (L[V].empty()) continue;       int bal = 0;       vector<int> T;       T.push_back(bal);       dp[bal + n] = 0;       for (int i = 1; i <= n; i++) {         if (A[i] == D)           bal++;         else if (A[i] == V)           bal--;         if (dp[bal + n] != -1) {           if (i - dp[bal + n] > opt) opt = i - dp[bal + n];         }         if (dp[bal + n] == -1) {           dp[bal + n] = i;           T.push_back(bal);         }       }       for (int v : T) {         dp[v + n] = -1;       }     }     printf( %d n , opt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int K = 26;   struct Vertex {     int next[K];     long long int leaf = 0;     int p = -1;     char pch;     int link = -1;     int go[K];     long long int count = -1;     int leaflink = 0;     Vertex(int p = -1, char ch =  $ ) : p(p), pch(ch) {       fill(begin(next), end(next), -1);       fill(begin(go), end(go), -1);     }   };   vector<Vertex> t(1);   void add_string(string const& s) {     int v = 0;     for (char ch : s) {       int c = ch -  a ;       if (t[v].next[c] == -1) {         t[v].next[c] = t.size();         t.emplace_back(v, ch);       }       v = t[v].next[c];     }     t[v].leaf++;   }   int go(int v, char ch);   int get_link(int v);   long long int cnt(int v) {     if (t[v].count == -1) {       if (v == 0)         t[v].count = 0;       else         t[v].count = cnt(get_link(v)) + t[v].leaf;     }     return t[v].count;   }   int get_link(int v) {     if (t[v].link == -1) {       if (v == 0 || t[v].p == 0)         t[v].link = 0;       else         t[v].link = go(get_link(t[v].p), t[v].pch);     }     return t[v].link;   }   int go(int v, char ch) {     int c = ch -  a ;     if (t[v].go[c] == -1) {       if (t[v].next[c] != -1)         t[v].go[c] = t[v].next[c];       else         t[v].go[c] = v == 0 ? 0 : go(get_link(v), ch);     }     return t[v].go[c];   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     string ts;     cin >> ts;     int n;     cin >> n;     vector<string> v;     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       v.push_back(s);       reverse(s.begin(), s.end());       add_string(s);     }     int m = ts.size();     vector<long long int> a = vector<long long int>(m, 0);     int cs = 0;     for (int i = m - 1; i > -1; --i) {       get_link(cs);       cs = go(cs, ts[i]);       get_link(cs);       a[i] = cnt(cs);     }     t = vector<Vertex>(1);     for (int i = 0; i < n; ++i) {       add_string(v[i]);     }     cs = 0;     long long int sol = 0;     for (int i = 0; i < m - 1; ++i) {       get_link(cs);       cs = go(cs, ts[i]);       get_link(cs);       sol += cnt(cs) * a[i + 1];     }     cout << sol << endl;   }


#include <bits/stdc++.h>   using namespace std;   void swap(int *a, int *b) {     int temp = *a;     *a = *b;     *b = temp;   }   void swap(char *a, char *b) {     char temp = *a;     *a = *b;     *b = temp;   }   int main() {     int xa, xb, xc, ya, yb, yc;     cin >> xa >> ya >> xb >> yb >> xc >> yc;     char ca =  A , cb =  B , cc =  C ;     int area = xa * ya + xb * yb + xc * yc;     int n = sqrt(area);     if (n * n != area) {       cout << -1;       return 0;     }     char arr[n][n];     if (xa < ya) swap(&xa, &ya);     if (xb < yb) swap(&xb, &yb);     if (xc < yc) swap(&xc, &yc);     if (xb == n) {       swap(&xa, &xb);       swap(&ya, &yb);       swap(&ca, &cb);     } else if (xc == n) {       swap(&xc, &xa);       swap(&ya, &yc);       swap(&ca, &cc);     }     if (xa != n) {       cout << -1;       return 0;     }     for (int i = 0; i < ya; i++) {       for (int j = 0; j < n; j++) arr[i][j] = ca;     }     if (yb == yc && xb + xc == n && ya + yb == n) {       for (int i = ya; i < n; i++) {         for (int j = 0; j < n; j++) {           if (j >= xb)             arr[i][j] = cc;           else             arr[i][j] = cb;         }       }     } else if (xb == xc && xb == n && ya + yb + yc == n) {       for (int i = ya; i < n; i++) {         for (int j = 0; j < n; j++) {           if (i >= yb + ya)             arr[i][j] = cc;           else             arr[i][j] = cb;         }       }     } else if (xb == xc && yb + yc == n && ya + xb == n) {       for (int i = ya; i < n; i++) {         for (int j = 0; j < n; j++) {           if (j >= yb)             arr[i][j] = cc;           else             arr[i][j] = cb;         }       }     } else if (xb == yc && yb + xc == n && ya + xb == n) {       for (int i = ya; i < n; i++) {         for (int j = 0; j < n; j++) {           if (j >= yb)             arr[i][j] = cc;           else             arr[i][j] = cb;         }       }     } else if (yb == xc && xb + yc == n && ya + yb == n) {       for (int i = ya; i < n; i++) {         for (int j = 0; j < n; j++) {           if (j >= xb)             arr[i][j] = cc;           else             arr[i][j] = cb;         }       }     } else {       cout << -1;       return 0;     }     cout << n << endl;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) cout << arr[i][j];       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int has = 0;     ;     cin >> n;     int d[n - 1];     for (int i = 0; i < n - 1; i++) cin >> d[i];     int a, b;     cin >> a >> b;     int m;     has = 0;     for (int m = a - 1; m < b - 1; m++) {       has = has + d[m];     }     cout << has << endl;   }


#include <bits/stdc++.h>   using namespace std;   class SuffixArrayBuilder {     int n, gap;     string s;     vector<int> pos;       public:     SuffixArrayBuilder(string &s) : s(s) {}     bool operator()(int i, int j) {       if (pos[i] != pos[j]) return pos[i] < pos[j];       i += gap;       j += gap;       return ((i < n && j < n) ? pos[i] < pos[j] : i > j);     }     vector<int> buildSA() {       n = (int)(s).size();       vector<int> sa(n), tmp(n);       pos.resize(n);       for (int i = (0); i <= ((int)(sa).size() - 1); ++i)         sa[i] = i, pos[i] = s[i];       for (gap = 1;; gap *= 2) {         sort(sa.begin(), sa.end(), ref(*this));         for (int i = (0); i <= (n - 2); ++i)           tmp[i + 1] = tmp[i] + (*this)(sa[i], sa[i + 1]);         for (int i = (0); i <= (n - 1); ++i) pos[sa[i]] = tmp[i];         if (tmp.back() == n - 1) return sa;       }     }     vector<int> buildLCP(vector<int> &sa) {       vector<int> lcp(n - 1);       for (int i = 0, k = 0; i < n; ++i)         if (pos[i] != n - 1) {           for (int j = sa[pos[i] + 1]; s[i + k] == s[j + k];) k++;           lcp[pos[i]] = k;           if (k) k--;         }       return lcp;     }   };   vector<long long int> solve(string &p, string &q, string &r) {     string s = p +  #  + q +  $  + r;     SuffixArrayBuilder Builder(s);     vector<int> SA = Builder.buildSA();     vector<int> LCP = Builder.buildLCP(SA);     int n = (int)(s).size();     int cnt[3][n];     int len[] = {0, (int)(p).size() + 1, (int)(q).size() + 1,                  (int)(r).size() + 1};     for (int i = (1); i <= (3); ++i) len[i] += len[i - 1];     for (int i = (0); i <= (2); ++i)       for (int j = (0); j <= (n - 1); ++j) {         cnt[i][j] = ((j) ? cnt[i][j - 1] : 0);         cnt[i][j] += (SA[j] >= len[i] && SA[j] < len[i + 1] - 1);       }     vector<pair<int, int> > ord;     for (int i = (0); i <= ((int)(LCP).size() - 1); ++i)       ord.push_back(make_pair(LCP[i], i));     sort(ord.begin(), ord.end());     set<int> S;     S.insert(-1);     S.insert(n - 1);     int m = min({(int)(p).size(), (int)(q).size(), (int)(r).size()});     vector<long long int> agg(m, 0);     for (int i = (0); i <= ((int)(ord).size() - 1); ++i) {       int pos = ord[i].second, L, R;       auto it = S.lower_bound(pos);       R = *it;       it--;       L = *it;       long long int left[3], right[3], whole[3];       for (int i = (0); i <= (2); ++i) {         left[i] = cnt[i][pos] - ((L >= 0) ? cnt[i][L] : 0);         right[i] = cnt[i][R] - cnt[i][pos];         whole[i] = cnt[i][R] - ((L >= 0) ? cnt[i][L] : 0);       }       long long int ans = whole[0] * whole[1] * whole[2] -                           left[0] * left[1] * left[2] -                           right[0] * right[1] * right[2];       ans %= 1000000007;       ans = (ans + 1000000007) % 1000000007;       int val = ord[i].first;       if (val > 0) {         agg[val - 1] += ans;         agg[val - 1] %= 1000000007;       }       S.insert(pos);     }     for (int i = (m - 2); i >= (0); --i)       agg[i] = (agg[i] + agg[i + 1]) % 1000000007;     return agg;   }   int main() {     ios_base::sync_with_stdio(0);     string p, q, r;     cin >> p >> q >> r;     vector<long long int> ans = solve(p, q, r);     for (int i = (0); i <= ((int)(ans).size() - 1); ++i) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   int max(int a, int b) { return a > b ? a : b; }   int main() {     static int aa[200000];     int n, d, q, i, h, j;     scanf( %d%d , &n, &d);     for (i = 0; i < n; i++) scanf( %d , &aa[i]);     scanf( %d , &q);     h = -1;     while (q--) {       int x, di, dj, d_;       double alpha, beta;       scanf( %d , &x);       if (x == 0 || x == aa[n - 1] + 1) {         printf( %.12f n , (atan(1) * 4) / 2);         continue;       }       while (h + 1 < n && aa[h + 1] < x) h++;       di = x - (aa[h] + 1);       dj = aa[h + 1] - x;       if (di == 0 && dj == 0) {         printf( %.12f n , (atan(1) * 4));         continue;       } else if (di == 0 || dj == 0) {         printf( %.12f n , (atan(1) * 4) / 2);         continue;       }       alpha = atan(1.0 / (di < dj ? di : dj));       d_ = (int)(1.0 / tan(alpha / 2.0) + 10);       for (i = h, j = h + 1; i >= 0 && j < n && (di = x - (aa[i] + 1)) < d_ &&                              (dj = aa[j] - x) < d_;)         if (di + 1 < dj)           i--;         else if (di > dj + 1)           j++;         else {           if (alpha < (beta = atan(1.0 / max(di, dj)) * 2)) alpha = beta;           break;         }       printf( %.12f n , alpha);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   using namespace std;   string s;   long long ispalindroma[2005][2005];   long long ispalindrome(long long i, long long j) {     if (i > j) return (1);     if (i == j) return (1);     if (ispalindroma[i][j] != -1) return (ispalindroma[i][j]);     long long ans = 0;     if (s[i] == s[j]) {       ans = ispalindrome(i + 1, j - 1);     }     return (ispalindroma[i][j] = ans);   }   int solve() {     cin >> s;     long long sum[2005], dp[2005];     dp[0] = sum[0] = 0;     for (long long i = 0; i < 2005; i++) {       for (long long j = 0; j < 2005; j++) ispalindroma[i][j] = -1;     }     long long a1 = ispalindrome(0, s.size() - 1);     for (long long i = 0; i < s.size(); i++) {       long long c = 0;       for (long long j = 0; j <= i; j++) {         if (ispalindrome(j, i)) c++;       }       sum[i + 1] = sum[i] + c;     }     for (long long i = 0; i < s.size(); i++) {       long long ans = 0;       for (long long j = 0; j <= i; j++) {         if (ispalindrome(j, i)) ans = ans + sum[j];       }       dp[i + 1] = dp[i] + ans;     }     cout << dp[s.size()] <<   n ;     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, z;     cin >> x >> y >> z;     if (x >= y) {       x = x - y;       if (x > z) {         cout <<  + ;       } else if (x <= z) {         if (z == 0) {           cout <<  0 ;         } else {           cout <<  ? ;         }       }     } else if (y > x) {       y = y - x;       if (y > z) {         cout <<  - ;       } else if (y <= z) {         if (z == 0) {           cout <<  0 ;         } else {           cout <<  ? ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     long long int n, x, y, i, j, k = 0, s;     scanf( %lld %lld %lld , &n, &x, &y);     long long int X[n], Y[n];     for (i = 0; i < n; i++) {       scanf( %lld %lld , &X[i], &Y[i]);       for (j = i - 1; j >= 0; j--) {         s = x * Y[i] + X[i] * Y[j] + X[j] * y - X[i] * y - X[j] * Y[i] - x * Y[j];         if (s == 0) {           break;         }       }       if (j < 0) {         k++;       }     }     printf( %lld n , k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000007;   int d[210][210][510][2];   short vis[210][210][510][2];   int q, n, k, b, cas;   int nex[210][22], out[210];   int fal[210];   int s[210];   int dp(int pos, int len, int w, int m) {     w = min(w, k + 5);     if (vis[pos][len][w][m] == cas) return d[pos][len][w][m];     vis[pos][len][w][m] = cas;     if (w > k) return d[pos][len][w][m] = 0;     if (len == n) return d[pos][len][w][m] = 1;     int res = 0;     for (int i = 0; i < b; ++i) {       if (m == 0 && i > s[len]) break;       int nst = nex[pos][i], mm = m | i < s[len];       int ww = w + out[nst];       res += dp(nst, len + 1, ww, mm);       if (res >= inf) res -= inf;     }     return d[pos][len][w][m] = res;   }   int nn;   void add(int len, int w) {     int pos = 0, i = 0;     while (i < len) {       int ii = s[i++];       if (!nex[pos][ii]) nex[pos][ii] = ++nn;       pos = nex[pos][ii];     }     out[pos] += w;   }   void bfs() {     queue<int> q;     q.push(0);     while (!q.empty()) {       int x = q.front();       q.pop();       for (int i = 0; i < b; ++i) {         if (!nex[x][i])           nex[x][i] = nex[fal[x]][i];         else {           int y = nex[x][i];           if (x == 0)             fal[y] = 0;           else             fal[y] = nex[fal[x]][i];           out[y] += out[fal[y]];           q.push(y);         }       }     }   }   int aa[210], bb[210];   int lena, lenb;   int down() {     int res = 0;     for (int pos = 0, i = 0; i < lena; ++i) {       pos = nex[pos][aa[i]];       res += out[pos];     }     return res <= k;   }   int ask() {     ++cas;     long long ans = 0;     for (int i = 1; i < s[0]; ++i) ans += dp(nex[0][i], 1, out[nex[0][i]], 1);     ans += dp(nex[0][s[0]], 1, out[nex[0][s[0]]], 0);     for (int i = 1; i < n; ++i)       for (int j = 1; j < b; ++j) ans += dp(nex[0][j], i + 1, out[nex[0][j]], 1);     return ans % inf;   }   int main() {     scanf( %d %d %d , &q, &b, &k);     scanf( %d , &lena);     for (int i = 0; i < lena; ++i) scanf( %d , &aa[i]);     scanf( %d , &lenb);     for (int i = 0; i < lenb; ++i) scanf( %d , &bb[i]);     int len, w;     while (q--) {       scanf( %d , &len);       for (int i = 0; i < len; ++i) scanf( %d , &s[i]);       scanf( %d , &w);       add(len, w);     }     bfs();     cas = 1;     n = lena;     for (int i = 0; i < lena; ++i) s[i] = aa[i];     int res = ask();     cas = 2;     n = lenb;     for (int i = 0; i < lenb; ++i) s[i] = bb[i];     int ans = ask();     cout << (ans + down() + inf - res) % inf << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int MOD = (long long int)1e9 + 7;   long long int powmod(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % MOD;       a = (a * a) % MOD;       b = b >> 1;     }     return res % MOD;   }   long long int num_swaps(vector<long long int> &arr, long long int k) {     long long int n = arr.size();     vector<long long int> pos(n);     for (long long int i = 0; i < n; i++) {       long long int val = (n + arr[i] + k) % n;       pos[val] = i;     }     vector<long long int> vis(n, 0);     long long int cnt_cycles = 0;     for (long long int i = 0; i < n; i++) {       if (vis[i] == 0) {         cnt_cycles++;         long long int cur_node = i;         while (1) {           cur_node = pos[cur_node];           if (vis[cur_node] == 1) {             break;           }           vis[cur_node] = 1;         }       }     }     return (n - cnt_cycles);   }   void solve(long long int testnum) {     long long int n, m;     cin >> n >> m;     vector<long long int> a(n), b(n, 0), ans;     for (long long int i = 0; i < n; i++) {       cin >> a[i];       a[i]--;     }     for (long long int i = 0; i < n; i++) {       long long int tmp = (n + i - a[i]) % n;       b[tmp]++;     }     long long int cnt = 0;     for (long long int i = 0; i < n; i++) {       if (b[i] >= n - 2 * m && num_swaps(a, i) <= m) {         ans.push_back(i);       }     }     cout << ans.size() <<    ;     for (long long int val : ans) {       cout << val <<    ;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     cin >> t;     for (long long int i = 1; i <= t; i++) {       solve(i);     }   }


#include <bits/stdc++.h>   using namespace std;   struct st {     long long int num;     long long int big;   } w[200001];   bool cmp(st a, st b) { return a.big < b.big; }   int main() {     std::ios::sync_with_stdio(false);     long long int n, i;     char p;     while (cin >> n) {       queue<long long int> q;       stack<st> ss;       for (i = 0; i < n; i++) {         cin >> w[i].big;         w[i].num = i + 1;       }       long long int t = 0;       sort(w, w + n, cmp);       for (i = 0; i < 2 * n; i++) {         cin >> p;         if (p ==  0 ) {           q.push(w[t].num);           ss.push(w[t]);           t++;         }         if (p ==  1 ) {           st a;           a = ss.top();           q.push(a.num);           ss.pop();         }       }       while (!q.empty()) {         cout << q.front() <<    ;         q.pop();       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int INF = 1e9;   const long long mod = 1e9 + 7;   int n, a, b, v;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       cin >> n >> a >> b >> v;       cin >> s;       int zero = 0, one = 0;       for (auto isi : s) {         if (isi ==  1 )           one++;         else           zero++;       }       cout << min(zero * a + one * b, min(n * a + one * v, n * b + zero * v))            <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10, logn = 20, inf = 2e5 + 10;   int L[maxn * logn], R[maxn * logn], sum[maxn * logn];   int root[maxn];   int sz = 1, rt = 1;   int copy(int v, int &u) {     L[sz] = L[v];     R[sz] = R[v];     sum[sz] = sum[v];     return u = sz++;   }   void add(int x, int v = root[rt - 1], int l = 0, int r = +inf) {     if (r - l == 1) {       sum[v]++;       return;     }     int m = (l + r) / 2;     if (x < m)       add(x, copy(L[v], L[v]), l, m);     else       add(x, copy(R[v], R[v]), m, r);     sum[v] = sum[L[v]] + sum[R[v]];   }   void push(int x) {     copy(root[rt - 1], root[rt]);     rt++;     add(x);   }   int get(int a, int b, int v, int l = 0, int r = +inf) {     if (a <= l && r <= b) return sum[v];     if (r <= a || b <= l) return 0;     int m = (l + r) / 2;     return get(a, b, L[v], l, m) + get(a, b, R[v], m, r);   }   int cnt(int l, int r, int x) {     return get(0, x, root[r - 1]) - get(0, x, root[l - 1]);   }   int x[maxn], y[maxn];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &x[i]), y[i] = x[i];     sort(y, y + n);     for (int i = 0; i < n; i++) {       x[i] = lower_bound(y, y + n, x[i]) - y;       push(x[i]);     }     int ans[n];     memset(ans, 0, sizeof(ans));     for (int k = 1; k < n; k++)       for (int i = 1; k * (i - 1) + 2 <= n; i++)         ans[k - 1] += cnt(k * (i - 1) + 2, min(n + 1, k * i + 2), x[i - 1]);     for (int i = 0; i < n - 1; i++) printf( %d  , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   long long num[100005], sorted[100005];   long long prenum[100005], presorted[100005];   int main() {     int n, q, l, r, op;     cin >> n;     for (__typeof(n) i = 0; i < n; i++) {       cin >> num[i];       sorted[i] = num[i];     }     sort(sorted, sorted + n);     prenum[0] = 0;     presorted[0] = 0;     for (__typeof(n + 1) i = 1; i < n + 1; i++) {       prenum[i] = prenum[i - 1] + num[i - 1];       presorted[i] = presorted[i - 1] + sorted[i - 1];     }     cin >> q;     for (__typeof(q) i = 0; i < q; i++) {       cin >> op >> l >> r;       switch (op) {         case 1:           cout << prenum[r] - prenum[l - 1] << endl;           break;         case 2:           cout << presorted[r] - presorted[l - 1] << endl;           break;       }     }     return 0;   }