#include <bits/stdc++.h>   using namespace std;   const int N = 400010;   class TWO_SAT {     vector<int> A[N], T[N];     int tag[N];     int noot[N];     vector<int> topo;     bool vis1[N];     void dfs1(int u) {       vis1[u] = true;       for (auto v : A[u])         if (!vis1[v]) dfs1(v);       topo.push_back(u);     }     bool vis2[N];     void dfs2(int u, int k) {       vis2[u] = true;       tag[u] = k;       for (auto v : T[u])         if (!vis2[v]) dfs2(v, k);     }     int dagN;     void makeDag(int n) {       memset(tag, -1, sizeof(tag));       memset(vis1, 0, sizeof(vis1));       memset(vis2, 0, sizeof(vis2));       for (int i = 0; i < n; ++i)         if (!vis1[i]) dfs1(i);       dagN = 0;       reverse(topo.begin(), topo.end());       for (auto u : topo) {         if (!vis2[u]) dfs2(u, dagN++);       }     }     bool did[N];     bool ans[N];     bool solve() {       for (int so : topo) {         if (did[tag[so]]) continue;         int si = noot[so];         if (tag[si] == tag[so]) return false;         ans[tag[si]] = 1;         ans[tag[so]] = 0;         did[tag[si]] = true;         did[tag[so]] = true;       }       return true;     }     int satn = 0;     int mapp[N];     bool exist = false;       public:     TWO_SAT() { memset(mapp, -1, sizeof(mapp)); }     bool Exist() { return exist; }     bool Solve() {       makeDag(satn);       exist = solve();       return exist;     }     void addClaw(int x1, int x2, bool b1, bool b2) {       if (mapp[x1] == -1) {         mapp[x1] = satn++;         noot[mapp[x1]] = satn++;         noot[noot[mapp[x1]]] = mapp[x1];       }       if (mapp[x2] == -1) {         mapp[x2] = satn++;         noot[mapp[x2]] = satn++;         noot[noot[mapp[x2]]] = mapp[x2];       }       x1 = mapp[x1];       if (b1) x1 = noot[x1];       x2 = mapp[x2];       if (b2) x2 = noot[x2];       A[noot[x1]].push_back(x2);       A[noot[x2]].push_back(x1);       T[x1].push_back(noot[x2]);       T[x2].push_back(noot[x1]);     }     bool Ans(int x) { return ans[tag[mapp[x]]]; }   } sat;   const int M = 2020;   char stati[M][M];   char statf[M][M];   char bar[M];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     for (int i = 0; i < n; ++i) cin >> stati[i];     for (int i = 0; i < n; ++i) cin >> statf[i];     cin >> bar;     bool ans = 1;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         stati[i][j] -=  0 ;         statf[i][j] -=  0 ;         if (bar[i] -  0  && bar[j] -  0 ) {           sat.addClaw(2 * i, 2 * j + 1, stati[i][j], 1 ^ statf[i][j]);           sat.addClaw(2 * i, 2 * j + 1, 1 ^ stati[i][j], statf[i][j]);         } else if (bar[j] -  0 ) {           sat.addClaw(2 * i, 2 * i, 1 ^ stati[i][j] ^ statf[i][j],                       1 ^ stati[i][j] ^ statf[i][j]);         } else if (bar[i] -  0 ) {           sat.addClaw(2 * j + 1, 2 * j + 1, 1 ^ stati[i][j] ^ statf[i][j],                       1 ^ stati[i][j] ^ statf[i][j]);         } else if (stati[i][j] ^ statf[i][j]) {           ans = 0;         }       }     }     if (!ans || !sat.Solve()) {       cout << -1 <<   n ;       return 0;     };     int cnt = 0;     for (int i = 0; i < 2 * n; i++) cnt += sat.Ans(i);     cout << cnt <<   n ;     for (int i = 0; i < 2 * n; i += 2)       if (sat.Ans(i)) cout <<  row   << i / 2 <<   n ;     for (int i = 1; i < 2 * n; i += 2)       if (sat.Ans(i)) cout <<  col   << i / 2 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a, b;   bool x[101];   bool y[101];   int main() {     scanf( %d%d , &n, &m);     memset(x, false, sizeof x);     memset(y, false, sizeof y);     scanf( %d , &b);     for (int i = 0; i < b; i++) {       scanf( %d , &a);       x[a] = 1;     }     scanf( %d , &b);     for (int i = 0; i < b; i++) {       scanf( %d , &a);       y[a] = 1;     }     for (int i = 0; i < n * m * 100; i++) {       a = i % n;       b = i % m;       x[a] |= y[b];       y[b] |= x[a];     }     for (int i = 0; i < n; i++)       if (!x[i]) {         puts( No );         return 0;       }     for (int i = 0; i < m; i++)       if (!y[i]) {         puts( No );         return 0;       }     puts( Yes );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void rd(T &t) {     t = 0;     int f = 1;     char p = getchar();     while (p < 48 || p > 57) {       if (p == 45) f = -1;       p = getchar();     }     do {       (t *= 10) += p - 48;       p = getchar();     } while (p > 47 && p < 58);     t *= f;   }   long long m;   int a[999], d[999], vis[999];   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   void dfs(int u) {     vis[u] = true;     ++m;     if (!vis[a[u]]) dfs(a[u]);   }   int main() {     int n, i;     long long ans = 1;     rd(n);     for (i = 1; i <= n; ++i) {       rd(a[i]);       ++d[a[i]];     }     for (i = 1; i <= n; ++i)       if (d[i] != 1) {         puts( -1 );         return 0;       }     for (i = 1; i <= n; ++i)       if (!vis[i]) {         m = 0;         dfs(i);         if (m % 2 == 0) m /= 2;         ans = ans / gcd(m, ans) * m;       }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   const int N = 30;   int dx[N], dy[N], b[N], v[N][N], a[N][N], B[N][N], n, T, tot, slack[N], f[N],       g[N], ret, tot2, opt[N];   pair<int, int> perm[N];   int state[185000], val[185000];   bool hungary(int x) {     if (x == -1) return 1;     f[x] = 1;     for (int i = 0; i < n; i++) {       if (g[i]) continue;       int t = dx[x] + dy[i] - v[x][i];       if (!t) {         g[i] = 1;         if (hungary(b[i])) {           b[i] = x;           return 1;         }       } else         slack[i] = min(slack[i], t);     }     return 0;   }   void dfs(int d, int s1, int s2) {     int s = 0, u = perm[d].second;     for (int i = 0; i < n; i++) s += dx[i] + dy[i];     if (s + opt[d] <= ret) return;     if (d == n) {       int r = 0;       for (int i = 0; i < n; i++) r += dx[i] + dy[i];       ret = max(ret, r);     }     int pdx[30], pdy[30], p[30];     for (int i = 0; i < n; i++) pdx[i] = dx[i], pdy[i] = dy[i], p[i] = b[i];     if (s1 != n / 2) {       for (int j = 0; j < n; j++) v[u][j] = a[u][j];       for (int i = 0; i < n; i++) dx[u] = max(dx[u], v[u][i]);       memset(slack, 0x20, sizeof(slack));       for (int i = 0; i < n; i++) f[i] = g[i] = 0;       while (!hungary(u)) {         int d = 0x20202020;         for (int j = 0; j < n; j++)           if (!g[j]) d = min(d, slack[j]);         for (int j = 0; j < n; j++) {           if (f[j]) dx[j] -= d;           if (g[j]) dy[j] += d;         }         for (int j = 0; j < n; j++) f[j] = g[j] = 0;       }       dfs(d + 1, s1 + 1, s2);       for (int i = 0; i < n; i++) dx[i] = pdx[i], dy[i] = pdy[i], b[i] = p[i];     }     if (s2 != n / 2) {       for (int j = 0; j < n; j++) v[u][j] = B[u][j];       for (int i = 0; i < n; i++) dx[u] = max(dx[u], v[u][i]);       memset(slack, 0x20, sizeof(slack));       for (int i = 0; i < n; i++) f[i] = g[i] = 0;       while (!hungary(u)) {         int d = 0x20202020;         for (int j = 0; j < n; j++)           if (!g[j]) d = min(d, slack[j]);         for (int j = 0; j < n; j++) {           if (f[j]) dx[j] -= d;           if (g[j]) dy[j] += d;         }         for (int j = 0; j < n; j++) f[j] = g[j] = 0;       }       dfs(d + 1, s1, s2 + 1);       for (int i = 0; i < n; i++) dx[i] = pdx[i], dy[i] = pdy[i], b[i] = p[i];     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) scanf( %d , &a[i][j]);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) scanf( %d , &B[i][j]);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) v[i][j] = max(a[i][j], B[i][j]);       perm[i] = make_pair(*max_element(v[i], v[i] + n), i);     }     sort(perm, perm + n);     reverse(perm, perm + n);     for (int i = 0; i < n; i++) b[i] = -1;     for (int d = n - 1; d >= 0; d--) {       int u = perm[d].second;       for (int i = 0; i < n; i++) dx[u] = max(dx[u], v[u][i]);       memset(slack, 0x20, sizeof(slack));       for (int i = 0; i < n; i++) f[i] = g[i] = 0;       while (!hungary(u)) {         int d = 0x20202020;         for (int j = 0; j < n; j++)           if (!g[j]) d = min(d, slack[j]);         for (int j = 0; j < n; j++) {           if (f[j]) dx[j] -= d;           if (g[j]) dy[j] += d;         }         for (int j = 0; j < n; j++) f[j] = g[j] = 0;       }       opt[d] = 0;       for (int i = 0; i < n; i++) opt[d] += dx[i] + dy[i];     }     for (int i = 0; i < n; i++) b[i] = -1, dx[i] = dy[i] = 0;     dfs(0, 0, 0);     printf( %d n , ret);   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 48 + 10;   vector<int> adj[MAX_N];   vector<int> ziro;   bool mark[MAX_N];   int ans[MAX_N][3];   int poi = 0;   vector<int> dfs(int v) {     vector<int> ret;     ret.push_back(v);     mark[v] = 1;     for (auto i : adj[v])       if (!mark[i]) {         vector<int> vec = dfs(i);         while (vec.size()) {           ret.push_back(vec.back());           vec.pop_back();         }       }     return ret;   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--, b--;       adj[a].push_back(b);       adj[b].push_back(a);     }     for (int i = 0; i < n; i++)       if (adj[i].empty()) ziro.push_back(i);     for (int i = 0; i < n; i++)       if (!mark[i]) {         vector<int> vec = dfs(i);         if (vec.size() > 3) {           cout << -1;           return 0;         } else if (vec.size() == 3) {           for (int j = 0; j < 3; j++) ans[poi][j] = vec[j];           poi++;         } else if (vec.size() == 2) {           if (ziro.empty()) {             cout << -1;             return 0;           }           for (int j = 0; j < 2; j++) ans[poi][j] = vec[j];           ans[poi][2] = ziro.back();           ziro.pop_back();           poi++;         }       }     if (ziro.size() % 3 != 0) {       cout << -1;       return 0;     }     while (ziro.size()) {       for (int i = 0; i < 3; i++) {         ans[poi][i] = ziro.back();         ziro.pop_back();       }       poi++;     }     for (int i = 0; i < poi; i++) {       for (int j = 0; j < 3; j++) cout << ans[i][j] + 1 <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXN = 10000;   const int MAXBLOCKS = 10000;   const int MAXRECT = 4 * MAXBLOCKS;   const int MAXGN = 2 + 4 * MAXN + MAXRECT;   const int MAXGM = 6 * MAXN + 2 * 2 * 14 * MAXRECT;   typedef struct R {     int lx, ly, hx, hy;   } R;   int n, h, w;   R b[MAXBLOCKS];   int nb;   bool blocked[MAXN][MAXN];   R r[MAXRECT];   int nr;   typedef struct MF {     int n, m;     int ghead[MAXGN], gnxt[2 * MAXGM], gto[2 * MAXGM], gcap[2 * MAXGM];     void init(int _n) {       n = _n, m = 0;       for (int i = (0); i < (n); ++i) ghead[i] = -1;     }     void addedge(int a, int b, int c) {       gnxt[2 * m + 0] = ghead[a], ghead[a] = 2 * m + 0, gto[2 * m + 0] = b,                    gcap[2 * m + 0] = c;       gnxt[2 * m + 1] = ghead[b], ghead[b] = 2 * m + 1, gto[2 * m + 1] = a,                    gcap[2 * m + 1] = 0;       ++m;     }     int d[MAXGN];     int q[MAXGN], qhead, qtail;     int cur[MAXGN];     int dinic(int s, int t) {       int ret = 0;       int niter = 0;       while (true) {         for (int i = (0); i < (n); ++i) d[i] = INT_MAX;         qhead = qtail = 0;         d[s] = 0, q[qhead++] = s;         while (qtail < qhead && d[t] == INT_MAX) {           int at = q[qtail++];           for (int x = ghead[at]; x != -1; x = gnxt[x]) {             int to = gto[x];             if (gcap[x] == 0 || d[to] != INT_MAX) continue;             d[to] = d[at] + 1;             q[qhead++] = to;           }         }         if (d[t] == INT_MAX) {           return ret;         }         for (int i = (0); i < (n); ++i) cur[i] = ghead[i];         ret += dfs(s, t, INT_MAX);         ++niter;       }     }     int dfs(int at, int t, int rem) {       int ret = 0;       if (at == t) return rem;       if (d[at] >= d[t]) return 0;       for (; cur[at] != -1; cur[at] = gnxt[cur[at]]) {         int to = gto[cur[at]], cap = gcap[cur[at]];         if (d[to] != d[at] + 1 || cap == 0) continue;         int now = dfs(to, t, min(cap, rem));         rem -= now;         ret += now;         gcap[cur[at]] -= now;         gcap[cur[at] ^ 1] += now;         if (rem == 0) return ret;       }       return ret;     }     void print() {       for (int i = (0); i < (m); ++i)         if (gcap[2 * i + 0] == 0)           printf( used %d->%d n , gto[2 * i + 1], gto[2 * i + 0]);     }   } MF;   MF g;   int solve() {     memset(blocked, false, sizeof(blocked));     h = w = n;     for (int i = (0); i < (nb); ++i)       for (int x = (b[i].lx); x <= (b[i].hx); ++x)         for (int y = (b[i].ly); y <= (b[i].hy); ++y) blocked[x][y] = true;     nr = 0;     for (int lx = (0); lx < (h); ++lx)       for (int ly = (0); ly < (w); ++ly)         if (!blocked[lx][ly]) {           int hy = ly;           while (hy + 1 < w && !blocked[lx][hy + 1]) ++hy;           int hx = lx;           while (hx + 1 < h) {             bool ok = true;             for (int y = (ly); y <= (hy); ++y)               if (blocked[hx + 1][y]) {                 ok = false;                 break;               }             if (!ok)               break;             else               ++hx;           }           r[nr].lx = lx, r[nr].ly = ly, r[nr].hx = hx, r[nr].hy = hy, ++nr;           for (int x = (lx); x <= (hx); ++x)             for (int y = (ly); y <= (hy); ++y) blocked[x][y] = true;         }     g.init(2 + 4 * n + nr);     for (int i = (0); i < (n); ++i) g.addedge(0, 2 + n + i, 1);     for (int i = (1); i < (n); ++i)       g.addedge(2 + 2 * i, 2 + i, n), g.addedge(2 + 2 * i + 1, 2 + i, n);     for (int i = (0); i < (n); ++i) g.addedge(2 + 3 * n + i, 1, 1);     for (int i = (1); i < (n); ++i)       g.addedge(2 + 2 * n + i, 2 + 2 * n + 2 * i, n),           g.addedge(2 + 2 * n + i, 2 + 2 * n + 2 * i + 1, n);     for (int i = (0); i < (nr); ++i) {       {         int lidx = n + r[i].lx, ridx = n + r[i].hx + 1;         for (; lidx < ridx; lidx >>= 1, ridx >>= 1) {           if (lidx & 1) g.addedge(2 + lidx, 2 + 4 * n + i, n), ++lidx;           if (ridx & 1) --ridx, g.addedge(2 + ridx, 2 + 4 * n + i, n);         }       }       {         int lidx = n + r[i].ly, ridx = n + r[i].hy + 1;         for (; lidx < ridx; lidx >>= 1, ridx >>= 1) {           if (lidx & 1) g.addedge(2 + 4 * n + i, 2 + 2 * n + lidx, n), ++lidx;           if (ridx & 1) --ridx, g.addedge(2 + 4 * n + i, 2 + 2 * n + ridx, n);         }       }     }     int ret = g.dinic(0, 1);     return ret;   }   void run() {     scanf( %d , &n);     scanf( %d , &nb);     for (int i = (0); i < (nb); ++i) {       int lx, ly, hx, hy;       scanf( %d%d%d%d , &b[i].lx, &b[i].ly, &b[i].hx, &b[i].hy);       --b[i].lx, --b[i].ly, --b[i].hx, --b[i].hy;     }     printf( %d n , solve());   }   void stress() {     n = MAXN;     nb = MAXBLOCKS - 1;     for (int i = (0); i < (nb); ++i) {       b[i].lx = i, b[i].hx = i, b[i].ly = (rand() * 1000 + rand()) % n,       b[i].hy = n - 1;     }     clock_t begin = clock();     printf( %d n , solve());     clock_t end = clock();     printf( %.9lf n , (double)(end - begin) / CLOCKS_PER_SEC);   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000010;   int ro[maxn];   int up(int u) { return (ro[u] == u) ? u : ro[u] = up(ro[u]); }   int me[maxn];   vector<int> no[maxn];   vector<pair<int, int> > q;   int o[maxn];   queue<int> s[2];   int main() {     int n, m, t, k;     scanf( %d%d , &n, &m);     memset(o, 0, sizeof(o));     memset(me, 0, sizeof(me));     for (int x = 0; x < n * m; x++) {       no[x].clear();       scanf( %d , &me[x]);       ro[x] = x;     }     for (int x = 0; x < n; x++) {       q.clear();       for (int y = 0; y < m; y++) {         q.push_back(make_pair(me[x * m + y], y));       }       sort((q).begin(), (q).end());       for (int y = 1; y < m; y++)         if (q[y].first != q[y - 1].first) {           no[x * m + q[y - 1].second].push_back(x * m + q[y].second);           o[x * m + q[y].second]++;         } else {           ro[up(x * m + q[y - 1].second)] = up(x * m + q[y].second);         }     }     for (int x = 0; x < m; x++) {       q.clear();       for (int y = 0; y < n; y++) {         q.push_back(make_pair(me[y * m + x], y));       }       sort((q).begin(), (q).end());       for (int y = 1; y < n; y++)         if (q[y].first != q[y - 1].first) {           no[q[y - 1].second * m + x].push_back(q[y].second * m + x);           o[q[y].second * m + x]++;         } else {           ro[up(q[y - 1].second * m + x)] = up(q[y].second * m + x);         }     }     int tem;     int len;     for (int x = 0; x < n * m; x++)       if (x != up(x)) {         tem = o[x];         o[up(x)] += tem;         o[x] -= tem;         len = no[x].size();         for (int y = 0; y < len; y++) no[up(x)].push_back(up(no[x][y]));         vector<int>().swap(no[x]);       } else {         len = no[x].size();         for (int y = 0; y < len; y++) no[x][y] = up(no[x][y]);       }     while (!s[0].empty()) s[0].pop();     while (!s[1].empty()) s[1].pop();     for (int x = 0; x < n * m; x++)       if (x == ro[x] && o[x] == 0) {         s[0].push(x);       }     t = 0;     int f = 0;     memset(me, 0, sizeof(me));     while (!s[f].empty()) {       t++;       while (!s[f].empty()) {         k = s[f].front();         s[f].pop();         me[k] = t;         len = no[k].size();         for (int x = 0; x < len; x++) {           o[no[k][x]]--;           if (o[no[k][x]] == 0) s[f ^ 1].push(no[k][x]);         }       }       f ^= 1;     }     for (int x = 0; x < n; x++) {       for (int y = 0; y < m; y++) printf( %d  , me[up(x * m + y)]);       putchar(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, x, y, m, ans, f[5000], q[5000];   pair<int, int> t[200000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     cout << n <<    ;     for (int i = 1; i < n; i++) {       cout << i <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return f * x;   }   inline char readch() {     char ch = getchar();     while (ch ==     || ch ==   n ) ch = getchar();     return ch;   }   inline string readstr() {     char ch = getchar();     string ans =   ;     while (ch ==     || ch ==   n ) ch = getchar();     while (ch !=     && ch !=   n ) {       ans += ch;       ch = getchar();     }     return ans;   }   const int MAXN = 100;   int n;   vector<int> V = {0}, K = {0}, X = {0};   int dp[MAXN][MAXN][MAXN][3];   inline int calc(int x, int y, int z, int pos) {     int ans = pos - (x + y + z + 1);     for (int i = 1; i <= x; i++)       if (V[i] >= pos) ans++;     for (int i = 1; i <= y; i++)       if (K[i] >= pos) ans++;     for (int i = 1; i <= z; i++)       if (X[i] >= pos) ans++;     return ans;   }   signed main() {     memset(dp, 0x3f3f3f3f, sizeof(dp));     n = read();     for (int i = 1; i <= n; i++) {       char tmp = readch();       if (tmp ==  V )         V.push_back(i);       else if (tmp ==  K )         K.push_back(i);       else         X.push_back(i);     }     dp[0][0][0][0] = dp[0][0][0][1] = 0;     for (int i = 0; i < V.size(); i++) {       for (int j = 0; j < K.size(); j++) {         for (int k = 0; k < X.size(); k++) {           if (i != 0)             dp[i][j][k][1] =                 min(dp[i][j][k][1], min(dp[i - 1][j][k][0], dp[i - 1][j][k][1]) +                                         calc(i - 1, j, k, V[i]));           if (k != 0)             dp[i][j][k][0] =                 min(dp[i][j][k][0], min(dp[i][j][k - 1][0], dp[i][j][k - 1][1]) +                                         calc(i, j, k - 1, X[k]));           if (j != 0)             dp[i][j][k][0] =                 min(dp[i][j][k][0], dp[i][j - 1][k][0] + calc(i, j - 1, k, K[j]));         }       }     }     cout << min(dp[V.size() - 1][K.size() - 1][X.size() - 1][0],                 dp[V.size() - 1][K.size() - 1][X.size() - 1][1])          << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }   int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }   const long long int MAXN = 1e5 + 3;   long long int dp[20][2][10][10];   vector<long long int> digits;   void convert_to_digits(long long int n) {     digits.clear();     if (n == 0) digits.push_back(0);     while (n > 0) {       digits.push_back(n % 10);       n = n / 10;     }   }   long long int recursion(long long int idx, bool flag, long long int first,                           long long int last) {     if (idx == -1) {       if (first == last && first != 0) return 1;       return 0;     }     if (dp[idx][flag][first][last] != -1) return dp[idx][flag][first][last];     long long int ans = 0;     long long int n = (flag) ? digits[idx] : 9;     for (int i = (0); i <= (n); ++i) {       bool nflag = (i == n) ? flag : 0;       long long int nfirst = (first == 0 and i != 0) ? i : first;       long long int nlast = i;       ans = ans + recursion(idx - 1, nflag, nfirst, nlast);     }     return dp[idx][flag][first][last] = ans;   }   void solve() {     long long int l, r;     cin >> l >> r;     memset(dp, -1, sizeof(dp));     convert_to_digits(r);     long long int ans = recursion(digits.size() - 1, 1, 0, 0);     memset(dp, -1, sizeof(dp));     if (l > 1) {       convert_to_digits(l - 1);       ans -= recursion(digits.size() - 1, 1, 0, 0);     }     cout << ans << endl;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long int t;     t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = (int)2 * 1e5 + 10;   void solve() {     long long n, m;     cin >> n >> m;     vector<long long> arr(n);     for (long long i = 0; i < n; i += 1) {       cin >> arr[i];     }     sort((arr).begin(), (arr).end());     long long sum = 0;     for (long long i = 0; i < m; i++) {       if (arr[i] < 0) {         sum += arr[i];       }     }     cout << abs(sum) <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     solve();     return 0;   }


#include<bits/stdc++.h>   using namespace std;   const int P=1e9+7,N=209,iv=P+1>>1;   int f[N][N],ans[N][N],d[N],sz[N],fa[N];   basic_string<int>g[N];   void dfs(int x,int y){    sz[x]=1,fa[x]=y;    for(int i:g[x])if(i!=y)d[i]=d[x]+1,dfs(i,x),sz[x]+=sz[i];   }   int qp(int a,int b){    int r=1;    for(;b;b>>=1,a=a*1ll*a%P)if(b&1)r=r*1ll*a%P;    return r;   }   int main(){    int n,i,j,k,u,w=0,o;    scanf( %d ,&n);    for(i=1;i<=n;++i){     memset(f,0,sizeof f);     for(j=1;j<i;++j)f[0][j]=1,f[j][i+1]=0;     for(j=1;j<i;++j)for(k=i-1;k>=j;--k)f[j][k]=(f[j-1][k]+f[j][k+1])*1ll*iv%P;     for(j=1;j<i;++j)ans[i][j]=f[j][j];     ans[i][0]=1;    }    for(i=1;i<n;++i)scanf( %d%d ,&j,&k),g[j]+=k,g[k]+=j;    for(i=1;i<=n;++i){     d[i]=0,dfs(i,0);     for(j=1;j<i;++j){      u=d[j],k=j,o=sz[j];      while(1){       k=fa[k];       w=(w+(sz[k]-o)*1ll*ans[u][d[k]])%P;       o=sz[k];       if(k==i)break;      }     }    }    printf( %lld ,w*1ll*qp(n,P-2)%P);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6 + 9, N = 1e3 + 9;   const int qwer[] = {-1, 0, 1, 0}, asdf[] = {0, 1, 0, -1};   int n, m, a[N][N], arr[MAX], sizee[MAX], number, c[N][N], vv, cnt;   long long k;   struct node {     int id, x, y;   } b[MAX];   int root(int x) { return x == arr[x] ? x : arr[x] = root(arr[x]); }   void merge(int x, int y) {     int zxcv = root(x), fy = root(y);     if (sizee[zxcv] < sizee[fy]) swap(zxcv, fy);     if (zxcv == fy) return;     arr[fy] = zxcv;     sizee[zxcv] += sizee[fy];   }   bool cmp(const node& x, const node& y) { return x.id > y.id; }   void dfs(int x, int y) {     if (c[x][y]) return;     if (number)       c[x][y] = vv, number--;     else       return;     for (int i = 0; i < 4; i++) {       int nx = x + qwer[i];       int ny = y + asdf[i];       if (nx < 1 || nx > n || ny < 1 || ny > m) continue;       if (a[nx][ny] < vv) continue;       dfs(nx, ny);     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         cin >> a[i][j], cnt++, b[cnt].x = i, b[cnt].y = j, b[cnt].id = a[i][j];     sort(b + 1, b + cnt + 1, cmp);     for (int i = 1; i <= cnt; i++) arr[i] = i, sizee[i] = 1;     int i;     for (i = 1; i <= cnt; i++) {       int dd = (b[i].x - 1) * m + b[i].y;       for (int j = 0; j < 4; j++) {         int nx = b[i].x + qwer[j];         int ny = b[i].y + asdf[j];         if (nx < 1 || nx > n || ny < 1 || ny > m || a[nx][ny] < b[i].id) continue;         merge(dd, (nx - 1) * m + ny);       }       if (k % b[i].id == 0 && sizee[root(dd)] >= k / b[i].id) break;     }     if (i > cnt) return cout <<  NO , 0;     vv = b[i].id, number = k / b[i].id, dfs(b[i].x, b[i].y);     cout <<  YES n ;     for (int i = 1; i <= n; i++, cout <<   n )       for (int j = 1; j <= m; j++) cout << c[i][j] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long Readint() {     long long ret = 0;     int f = 1;     char ch;     do {       ch = getchar();       if (ch ==  - ) f *= -1;     } while (ch >= 0 && (ch <  0  || ch >  9 ));     while ( 0  <= ch && ch <=  9 ) {       ret = ret * 10 + ch -  0 ;       ch = getchar();     }     return ret * f;   }   void open() {     freopen( E.in ,  r , stdin);     freopen( E.out ,  w , stdout);   }   void close() {     fclose(stdin);     fclose(stdout);   }   const int MAXN = 101010;   set<int> sp[2];   char s[MAXN];   vector<int> ans;   int n;   void init() {     int cntl = 0, cntr = 0;     scanf( %s , s + 1);     n = strlen(s + 1);     for (int i = 1, _END_ = n; i <= _END_; i++)       if (s[i] ==  L )         cntl++;       else         cntr++;     if (cntl < cntr || (cntl == cntr && s[1] ==  R )) {       for (int i = 1, _END_ = n; i <= _END_; i++)         if (s[i] ==  L )           s[i] =  R ;         else           s[i] =  L ;     }     for (int i = 1, _END_ = n; i <= _END_; i++)       if (s[i] ==  L )         sp[0].insert(i);       else         sp[1].insert(i);   }   void work() {     int type = 0;     set<int>::iterator now;     int num = 0;     int tot = 0;     now = sp[0].begin();     num = *now;     sp[0].erase(now);     for (int i = 1, _END_ = n; i < _END_; i++) {       ans.push_back(num);       now = sp[type ^ 1].lower_bound(num);       if (now == sp[type ^ 1].end()) {         tot++;         now = sp[type ^ 1].begin();         num = *now;         sp[type ^ 1].erase(num);         type ^= 1;       } else {         if (sp[type].lower_bound(*now) == sp[type].end()) {           int mn = 0x3f3f3f3f;           if (sp[0].begin() != sp[0].end()) mn = min(mn, *sp[0].begin());           if (sp[1].begin() != sp[1].end()) mn = min(mn, *sp[1].begin());           if (mn < num && s[mn] != s[num]) {             tot++;             num = mn;             sp[type ^ 1].erase(num);             type ^= 1;             continue;           }         }         num = *now;         sp[type ^ 1].erase(num);         type ^= 1;       }     }     ans.push_back(num);     printf( %d n , tot);     for (int i = 0, _END_ = ans.size(); i < _END_; i++) printf( %d  , ans[i]);   }   int main() {     int _ = 0;     init();     work();     close();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long k, a[500005];   int chack1(int x) {     long long k1 = 0, c = 0;     for (int i = 0; i < n; i++) {       if (a[i] > x)         k1 += (a[i] - x);       else         c += (x - a[i]);     }     if (k1 <= k && c >= k1)       return 1;     else       return 0;   }   int chack2(int x) {     long long k2 = 0, c1 = 0;     for (int i = 0; i < n; i++) {       if (a[i] < x)         k2 += (x - a[i]);       else         c1 += (a[i] - x);     }     if (k2 <= k && c1 >= k2)       return 1;     else       return 0;   }   int main() {     while (cin >> n >> k) {       for (int i = 0; i < n; i++) cin >> a[i];       sort(a, a + n);       int max = a[n - 1], min = a[0];       int low = min, high = max;       while (low <= high) {         int mid = (low + high) / 2;         long long k1 = 0, c = 0;         if (chack1(mid))           high = mid - 1, max = mid;         else           low = mid + 1;       }       low = 0, high = a[n - 1];       while (low <= high) {         int mid = (low + high) / 2;         if (chack2(mid))           low = mid + 1, min = mid;         else           high = mid - 1;       }       cout << max - min << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXM = 101000;   pair<int, int> a[MAXM];   vector<pair<int, int> > b[MAXM << 1];   vector<int> c[MAXM << 1], d[MAXM << 1];   int main() {     int n, m, i, j, k, x, y;     int f, l, r, top;     while (scanf( %d%d , &n, &m) != EOF) {       for (i = 0; i < m; i++) {         scanf( %d%d , &x, &y);         a[i] = make_pair(x, y);       }       sort(a, a + m);       for (i = 0; i + n - 1 < m; i++)         if (a[i].first == a[i + n - 1].first) break;       if (i + n - 1 < m && a[i].first == a[i + n - 1].first) {         puts( -1 );         continue;       }       if (a[0].first == 1) {         b[0].push_back(make_pair(1, a[0].second - 1));         f = 1;         top = 0;       } else {         b[0].push_back(make_pair(1, n));         b[1].push_back(make_pair(1, a[0].second - 1));         f = a[0].first;         top = 1;       }       for (i = 1; i < m; i++) {         if (a[i].first > f) {           if (a[i - 1].second != n)             b[top].push_back(make_pair(a[i - 1].second + 1, n));           top++;           if (a[i].first - f > 1) b[top++].push_back(make_pair(1, n));           if (a[i].second > 1) b[top].push_back(make_pair(1, a[i].second - 1));           f = a[i].first;         } else {           if (a[i].second - a[i - 1].second > 1)             b[top].push_back(make_pair(a[i - 1].second + 1, a[i].second - 1));         }       }       if (a[m - 1].second != n)         b[top].push_back(make_pair(a[m - 1].second + 1, n));       top++;       if (a[m - 1].first != n) b[top++].push_back(make_pair(1, n));       c[0].push_back(b[0][0].first);       d[0].push_back(b[0][0].second);       for (i = 1; i < top; i++) {         f = b[i].size();         for (j = 0; j < f; j++) {           k = lower_bound(d[i - 1].begin(), d[i - 1].end(), b[i][j].first) -               d[i - 1].begin();           if (k >= 0 && k < d[i - 1].size() && d[i - 1][k] >= b[i][j].first &&               c[i - 1][k] <= b[i][j].second) {             c[i].push_back(max(b[i][j].first, c[i - 1][k]));             d[i].push_back(b[i][j].second);           }         }         if (c[i].size() == 0) break;       }       if (d[top - 1].size() != 0 && d[top - 1][d[top - 1].size() - 1] == n)         printf( %d n , 2 * n - 2);       else         puts( -1 );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000000 + 7;   int n, bas, lim;   int go[210][22];   int trie[210][22], tn;   int upper[210], lower[210], val[210], str[210];   int fail[210];   int bound[210];   int f[2][210][210][510];   queue<int> q;   inline int min(int a, int b) { return a < b ? a : b; }   int work() {     int p = 200;     while (p >= 0 && !bound[p]) {       --p;     }     if (p < 0) return 0;     memset(f, 0, sizeof(f));     f[0][0][0][0] = 1;     int ans = 0;     for (int i = 0; i <= p; i++) {       for (int j = 0; j <= tn; j++) {         for (int k = 0; k < 2; k++) {           for (int v = 0; v <= lim; v++) {             if (!f[k][i][j][v]) continue;             for (int fil = 0; fil < bas; fil++) {               int& nxt = f[(fil == bound[i] && k) || fil > bound[i]][i + 1]                           [go[j][fil]][min(lim + 1, v + val[go[j][fil]])];               nxt += f[k][i][j][v];               if (nxt >= MOD) nxt -= MOD;               if (fil && v + val[go[j][fil]] <= lim &&                   (!((fil == bound[i] && k) || fil > bound[i]) || i < p)) {                 ans += f[k][i][j][v];                 if (ans >= MOD) ans -= MOD;               }             }           }         }       }     }     return ans;   }   void mminus() {     for (int i = 0; i <= 200; i++) {       --bound[i];       if (bound[i] >= 0) break;       bound[i] += bas;     }   }   int main() {     scanf( %d%d%d , &n, &bas, &lim);     int len, lenl, lenr;     scanf( %d , &lenl);     for (int i = lenl - 1; i >= 0; i--) scanf( %d , lower + i);     scanf( %d , &lenr);     for (int i = lenr - 1; i >= 0; i--) scanf( %d , upper + i);     while (n--) {       scanf( %d , &len);       for (int i = len; i >= 1; i--) scanf( %d , str + i);       int cur = 0;       for (int i = 1; i <= len; i++) {         if (!trie[cur][str[i]]) trie[cur][str[i]] = ++tn;         cur = trie[cur][str[i]];       }       int v;       scanf( %d , &v);       val[cur] += v;     }     q.push(0);     while (!q.empty()) {       int cur = q.front();       q.pop();       for (int i = 0; i < bas; i++) {         if (trie[cur][i]) {           go[cur][i] = trie[cur][i];           int ff;           for (ff = fail[cur]; ff && !trie[ff][i]; ff = fail[ff])             ;           if (ff == cur)             fail[trie[cur][i]] = 0;           else             fail[trie[cur][i]] = trie[ff][i];           val[trie[cur][i]] += val[fail[trie[cur][i]]];           q.push(trie[cur][i]);         } else {           int ff;           for (ff = fail[cur]; ff && !trie[ff][i]; ff = fail[ff])             ;           go[cur][i] = trie[ff][i];         }       }     }     for (int i = 200; i >= 0; i--) bound[i] = upper[i];     int ans = work();     for (int i = 200; i >= 0; i--) bound[i] = lower[i];     mminus();     ans -= work();     if (ans < 0) ans += MOD;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline ostream &operator<<(ostream &_out, const vector<T> &_v) {     if (_v.empty()) return _out;     _out << _v.front();     for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) _out <<     << *_it;     return _out;   }   template <typename T>   inline istream &operator>>(istream &_in, vector<T> &_v) {     for (auto &_i : _v) _in >> _i;     return _in;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const set<T> &_s) {     if (_s.empty()) return _out;     _out << *_s.begin();     for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out <<     << *_it;     return _out;   }   template <typename T, typename U>   inline ostream &operator<<(ostream &_out, const map<T, U> &_m) {     if (_m.empty()) return _out;     _out <<  (  << _m.begin()->first <<  :   << _m.begin()->second <<  ) ;     for (auto _it = ++_m.begin(); _it != _m.end(); ++_it)       _out <<  , (  << _it->first <<  :   << _it->second <<  ) ;     return _out;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   inline void solve() {     int n;     cin >> n;     vector<int> p(n);     cin >> p;     int begin_of_current_segment = 0;     bool increase = p[1] > p[0];     vector<bool> mask(n, false);     for (int i = 2; i < n; ++i) {       if (p[i] > p[i - 1]) {         if (!increase) {           increase = true;           mask[begin_of_current_segment] = true;           mask[i - 1] = true;           begin_of_current_segment = i - 1;         }       } else {         if (increase) {           increase = false;           mask[begin_of_current_segment] = true;           mask[i - 1] = true;           begin_of_current_segment = i - 1;         }       }     }     mask[begin_of_current_segment] = true;     mask.back() = true;     cout << accumulate(mask.begin(), mask.end(), 0) <<   n ;     for (int i = 0; i < n; ++i) {       if (mask[i]) cout << p[i] <<    ;     }     cout <<   n ;   }   inline void tsolve() {     int t;     cin >> t;     while (t--) solve();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     tsolve();     return 0;   }


#include <bits/stdc++.h>   const int N = 500005, M = 105, INF = 0x3f3f3f3f;   int n, K, p, sum[N], f[M][N], t[105], g[N];   void solveC2() {     for (int i = 1; i <= n; i++) f[0][i] = INF;     for (int i = 1; i <= K; i++) {       for (int j = 0; j < p; j++) t[j] = INF;       if (i == 1) t[0] = 0;       for (int j = 1; j <= n; j++) {         f[i][j] = INF;         for (int k = 0; k < p; k++)           f[i][j] = std::min(f[i][j], t[k] + (sum[j] - k + p) % p);         t[sum[j]] = std::min(t[sum[j]], f[i - 1][j]);       }     }     printf( %d , f[K][n]);   }   void solveC3() {     memset(g, 0x3f, sizeof g);     for (int i = 1; i < n; i++)       *std::upper_bound(g + 1, g + 1 + n, sum[i]) = sum[i];     if (g[K - 1] <= sum[n])       printf( %d , sum[n]);     else       printf( %d , sum[n] + p);   }   int main() {     scanf( %d%d%d , &n, &K, &p);     for (int i = 1; i <= n; i++)       scanf( %d , &sum[i]), sum[i] = (sum[i] + sum[i - 1]) % p;     if (K * p > n)       solveC2();     else       solveC3();     return 0;   }


#include <bits/stdc++.h>   const int oo = 0x7fffffff;   const long long OO = 0x7fffffffffffffff;   template <class T>   std::ostream& operator<<(std::ostream& O, const std::vector<T>& V) {     for (const T& x : V) O << x <<    ;     O <<   n ;     return O;   }   template <class T1, class T2>   std::ostream& operator<<(std::ostream& O, const std::pair<T1, T2>& P) {     return O <<  (  << P.first <<  ,   << P.second <<  ) ;   }   std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());   using namespace std;   int main() {     long double y1, y2, yw, xb, yb, r;     cin >> y1 >> y2 >> yw >> xb >> yb >> r;     yw -= r, y1 += r;     long double a = atan2(xb, (yw - yb) + (yw - y1));     long double dr = (y2 - y1) * sin(a);     if (dr < r)       cout <<  -1 n ;     else {       long double xw = (yw - y1) * xb / (yw - yb + yw - y1);       cout.precision(10);       cout << fixed << xw <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s1[100002], s2[100002];   int diff[100002] = {0};   int main() {     scanf( %s , s1);     scanf( %s , s2);     int i, len = strlen(s1), count = 0, temp;     for (i = 0; i < len; i++) {       if (s1[i] != s2[i]) {         diff[i] = 1;         count++;       }     }     if (count & 1)       cout <<  impossible ;     else {       temp = count >> 1;       for (i = 0; i < len; i++) {         printf( %c , s1[i]);         if (s1[i] != s2[i]) temp--;         if (temp == 0) break;       }       i++;       for (; i < len; i++) printf( %c , s2[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 151;   const int inf = 0x7f7f7f7f;   const int mod = (int)(1e9 + 7);   const long long INF = 0x7f7f7f7f7f7f7f7fLL;   const double eps = 1e-8;   const double pi = acos(-1.0);   const int mask = 65535;   int a[maxn];   int b[maxn];   void handle(int a[], int n) {     if (n == 1) {       a[0] = 1;       return;     }     if (n == 2) {       a[0] = 3;       a[1] = 4;       return;     }     if (n & 1) {       std::fill(a, a + maxn, 1);       a[0] = 2;       a[n - 1] = (n + 1) >> 1;     } else {       std::fill(a, a + maxn, 1);       a[n - 1] = (n - 1) >> 1;     }   }   int main() {     ios::sync_with_stdio(false);     int n, m;     int i, j;     cin >> n >> m;     handle(a, n);     handle(b, m);     for (i = 0; i < n; ++i) {       for (j = 0; j < m; ++j) {         if (j) cout <<    ;         cout << a[i] * b[j];       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int N = 4e2 + 5;   int n, f[N][N];   int main() {     scanf( %d , &n);     f[1][0] = f[1][1] = 1;     for (int top = 1; top < n; ++top) {       for (int i = 0; i <= n; ++i) {         for (int j = 0; j <= n - i + 1; ++j) {           int tmp = (long long)f[top][i] * f[top][j] % MOD;           if (i + j <= n)             f[top + 1][i + j] =                 (f[top + 1][i + j] + (long long)(2 * i + 2 * j + 1) * tmp % MOD) %                 MOD;           if (i + j + 1 <= n)             f[top + 1][i + j + 1] = (f[top + 1][i + j + 1] + tmp) % MOD;           if (i + j - 1 <= n)             f[top + 1][i + j - 1] =                 (f[top + 1][i + j - 1] +                  (long long)(i + j - 1) * (i + j) % MOD * tmp % MOD) %                 MOD;         }       }     }     printf( %d n , f[n][1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   int n, m;   char s[maxn];   long long ans[maxn];   int sz[maxn];   int cnt[1 << 20];   vector<int> g[maxn];   bool die[maxn];   int getsz(int x, int f) {     sz[x] = 1;     for (int y : g[x])       if (y != f && !die[y]) sz[x] += getsz(y, x);     return sz[x];   }   int getrt(int tot, int x, int f) {     for (int y : g[x])       if (y != f && !die[y])         if (sz[y] * 2 >= tot) return getrt(tot, y, x);     return x;   }   int h(int x) { return 1 << (s[x] -  a ); }   void update(int x, int f, int coe, int pre) {     cnt[pre ^= h(x)] += coe;     for (int y : g[x])       if (y != f && !die[y]) update(y, x, coe, pre);   }   long long query(int x, int f, int pre) {     long long pass = cnt[pre ^= h(x)];     for (int i = 0; i < 20; i++) pass += cnt[pre ^ (1 << i)];     for (int y : g[x])       if (y != f && !die[y]) pass += query(y, x, pre);     ans[x] += pass;     return pass;   }   void solve(int x) {     die[x] = 1;     update(x, 0, 1, h(x));     long long pass = cnt[h(x)];     for (int i = 0; i < 20; i++) pass += cnt[(1 << i) ^ h(x)];     for (int y : g[x])       if (!die[y]) {         update(y, x, -1, 0);         pass += query(y, x, h(x));         update(y, x, 1, 0);       }     update(x, 0, -1, h(x));     ans[x] += pass / 2 + 1;     for (int y : g[x])       if (!die[y]) solve(getrt(getsz(y, x), y, x));   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     scanf( %s , s + 1);     solve(getrt(getsz(1, 0), 1, 0));     for (int i = 1; i <= n; i++) printf( %lld  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n, a, o;       vector<pair<pair<int, int>, int> > M;       scanf( %d , &n);       M.push_back(make_pair(make_pair(0, 0), 0));       for (int i = 1; i <= n * 2 - 1; i++) {         scanf( %d%d , &a, &o);         M.push_back(make_pair(make_pair(a, o), i));       }       sort(M.begin(), M.end());       long long s[2] = {0};       for (int i = 1; i <= n * 2 - 1; i++) {         s[i & 1] += M[i].first.second;       }       printf( YES n );       if (s[1] > s[0]) {         for (int i = 1; i <= n * 2 - 1; i += 2) {           printf( %d  , M[i].second);         }       } else {         for (int i = 2; i <= n * 2 - 1; i += 2) {           printf( %d  , M[i].second);         }         printf( %d , M[n * 2 - 1].second);       }       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const int N = (int)2e6 + 5;   int n, q, a[N], l[N], r[N];   int main() {     for (scanf( %d , &q); q--;) {       scanf( %d , &n);       for (int i = 1; i <= n; ++i) scanf( %d , a + i);       for (int i = 1; i <= n; ++i) l[i] = n + 1, r[i] = -1;       for (int i = 1; i <= n; ++i)         l[a[i]] = min(l[a[i]], i), r[a[i]] = max(r[a[i]], i);       int mx = 0, now = 0, pos = -1, typ = 0;       for (int i = 1; i <= n; ++i)         if (r[i] != -1) {           ++typ;           if (now == 0) {             now = 1;             pos = r[i];           } else {             if (pos < l[i]) {               pos = r[i];               ++now;             } else               pos = r[i], now = 1;           }           mx = max(mx, now);         }       printf( %d n , typ - mx);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long modPower(long long num, long long r) {     if (r == 0) return 1;     if (r == 1) return num % 1000000007;     long long ans = modPower(num, r / 2) % 1000000007;     if (r % 2 == 0) {       return (ans * ans) % 1000000007;     }     return (((ans * ans) % 1000000007) * num) % 1000000007;   }   long long nCr(long long n, long long r) {     long long res = 1;     if (r > n - r) {       r = n - r;     }     for (long long i = 0; i < r; i++) {       res *= (n - i);       res /= (i + 1);     }     return res;   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   int pos(int a) {     if (a < 0)       return (-1) * a;     else       return a;   }   unsigned long long highestPowerof2(unsigned long long n) {     unsigned long long p = (unsigned long long)log2(n);     return (unsigned long long)pow(2, p);   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   vector<int> fprint(vector<int> A, int n) {     vector<int> fprint;     for (int i = 0; i < n - 1; i++) {       fprint.push_back(A[i] + A[i + 1]);     }     sort(fprint.begin(), fprint.end());     return fprint;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long grr;     cin >> grr;     while (grr--) {       long long count = 0;       long long n, s;       cin >> n >> s;       long long c = n, rev = 0;       long long x = 10;       long long sum = 0, sum2 = 0, len = 0;       while (c > 0) {         sum += c % 10;         rev = rev * 10 + c % 10;         len++;         c = c / 10;       }       if (sum <= s)         cout << 0 <<   n ;       else {         sum2 = 0;         while (sum2 + rev % 10 < s && rev > 0) {           count++;           sum2 += rev % 10;           rev /= 10;         }         long long x = len - count, y = 1;         while (x--) {           y *= 10;         }         n = n % y;         x = 10;         while (n / x != 0) {           x *= 10;         }         cout << x - n <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     cin >> n;     cin >> s;     int count = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  8 ) {         count++;       }     }     int a = n / 11;     if (count >= a) {       cout << a;     } else {       cout << count;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long p = 1e9 + 7;   const long double pi = 3.1415926535898;   int main() {     int s, n;     cin >> s >> n;     vector<pair<int, int> > a(n);     for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;     sort(a.begin(), a.end());     for (int i = 0; i < n; i++) {       if (a[i].first >= s) {         cout <<  NO ;         return 0;       }       s += a[i].second;     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : (-x);   }   template <class T>   T sqr(T x) {     return x * x;   }   int a[100000][2];   void save() {     printf( -1 n );     exit(0);   }   const int n = 65536;   int tree[57000 * 4 + 10];   int delta[57000 * 4 + 10];   void Set(int pos, int newval, int i = 1, int l = 0, int r = n - 1) {     if (l == r) {       tree[i] = newval;       return;     }     int m = (l + r) / 2;     if (pos <= m)       Set(pos, newval, i * 2, l, m);     else       Set(pos, newval, i * 2 + 1, m + 1, r);     tree[i] = min(tree[2 * i], tree[2 * i + 1]);   }   void multiinc(int l0, int r0, int val, int i = 1, int l = 0, int r = n - 1) {     if (l >= l0 && r <= r0) {       delta[i] += val;       return;     }     if (min(r, r0) < max(l, l0)) return;     int m = (l + r) / 2;     multiinc(l0, r0, val, 2 * i, l, m);     multiinc(l0, r0, val, 2 * i + 1, m + 1, r);     tree[i] = min(tree[2 * i] + delta[2 * i], tree[2 * i + 1] + delta[2 * i + 1]);   }   int get(int l0, int r0, int i = 1, int l = 0, int r = n - 1) {     if (min(r, r0) < max(l, l0)) return 100000000;     if (l >= l0 && r <= r0) return tree[i] + delta[i];     int m = (l + r) / 2;     return delta[i] +            min(get(l0, r0, 2 * i, l, m), get(l0, r0, 2 * i + 1, m + 1, r));   }   int main() {     memset(tree, 0, sizeof(tree));     string s;     cin >> s;     for (int i = 0; i < ((int)((s).size())); i++) {       if (s[i] !=  ? ) continue;       scanf( %d%d , &a[i][0], &a[i][1]);     }     set<pair<int, int> > up, down;     int cur = 0;     long long cost = 0;     for (int i = 0; i < ((int)((s).size())); i++) {       if (s[i] ==  ? ) {         if (a[i][0] < a[i][1]) {           s[i] =  ( ;           cost += a[i][0];           down.insert(pair<int, int>(a[i][1] - a[i][0], i));           cur++;         } else {           s[i] =  ) ;           cost += a[i][1];           up.insert(pair<int, int>(a[i][0] - a[i][1], i));           cur--;         }       } else {         cur += s[i] ==  (  ? 1 : -1;       }       if (cur < 0) {         if (up.empty()) save();         set<pair<int, int> >::iterator it = up.begin();         cost += it->first;         s[it->second] =  ( ;         cur += 2;         up.erase(it);         down.clear();       }     }     int ss = 0;     for (int i = 0; i < ((int)((s).size())); i++) {       ss += s[i] ==  (  ? 1 : -1;       Set(i + 1, ss);     }     while (cur > 0) {       if (down.empty()) save();       set<pair<int, int> >::iterator it = down.begin();       int delt = it->first;       int ind = it->second;       down.erase(it);       multiinc(ind + 1, ((int)((s).size())), -2);       int opt = get(1, ((int)((s).size())));       if (opt < 0) {         multiinc(ind + 1, ((int)((s).size())), 2);         continue;       }       cur -= 2;       s[ind] =  ) ;       cost += delt;     }     cout << cost <<   n  << s <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ull = unsigned long long;   using ll = long long;   const int mod = 1e9 + 7;   const int inf = 2e9 + 5;   const int N = 501;   int n, m, a[N][N], b[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> n >> m;     int q;     cin >> q;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> a[i][j];     for (int i = 0; i < n; i++) {       int cur = 0, best = 0;       for (int j = 0; j < m; j++) {         if (a[i][j] == 1)           cur += 1;         else           cur = 0;         best = max(best, cur);       }       b[i] = best;     }     while (q--) {       int i, j;       cin >> i >> j;       --i;       --j;       a[i][j] = 1 - a[i][j];       int cur = 0, best = 0;       for (int k = 0; k < m; k++) {         if (a[i][k] == 1)           cur += 1;         else           cur = 0;         best = max(best, cur);       }       b[i] = best;       cout << *max_element(b, b + n) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   struct node {     node() { zuo = you = he = 0; }     int zuo, you, he;   } a[1000002];   char s[1000002];   int sum(int l, int r) {     int ans = 0, you = 0;     while (r >= l) {       while (r && r - l + 1 >= (r & -r)) {         ans += a[r].he;         if (a[r].zuo >= you) {           ans += you;           you = 0;         } else {           ans += a[r].zuo;           you -= a[r].zuo;         }         you += a[r].you;         r -= r & -r;       }       if (r >= l) {         if (s[r] ==  ( ) {           if (you) {             ++ans;             --you;           }         } else           ++you;         --r;       }     }     return ans;   }   int main() {     scanf( %s , s + 1);     int n = strlen(s + 1), x;     for (int i = 1; i <= n; ++i) {       x = i;       if (s[x] ==  ( ) {         while (x <= n) {           ++a[x].zuo;           x += x & -x;         }       } else {         while (x <= n) {           if (a[x].zuo) {             --a[x].zuo;             ++a[x].he;           } else             ++a[x].you;           x += x & -x;         }       }     }     int m, l, r;     scanf( %d , &m);     while (m--) {       scanf( %d%d , &l, &r);       printf( %d n , sum(l, r) << 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long long s, mn, mx;   };   node T[303030];   node operator+(node l, node r) {     node x;     x.s = l.s + r.s;     x.mn = min(l.mn, l.s + r.mn);     x.mx = max(l.mx, l.s + r.mx);     return x;   }   int A[100009];   void init(int idx, int s, int e) {     if (s == e) {       T[idx] = {A[s], min(A[s], 0), max(A[s], 0)};       return;     }     int m = s + e >> 1;     init(idx * 2, s, m);     init(idx * 2 + 1, m + 1, e);     T[idx] = T[idx * 2] + T[idx * 2 + 1];   }   node get(int idx, int s, int e, int l, int r) {     if (r < s || e < l) return (node){0, 0, 0};     if (l <= s && e <= r) return T[idx];     int m = s + e >> 1;     return get(idx * 2, s, m, l, r) + get(idx * 2 + 1, m + 1, e, l, r);   }   int main() {     int N, Q;     scanf( %d%d , &N, &Q);     for (int i = 1; i <= N; i++) scanf( %d , &A[i]);     for (int i = 1; i <= N; i++) {       int x;       scanf( %d , &x);       A[i] = x - A[i];     }     init(1, 1, N);     while (Q--) {       int l, r;       scanf( %d%d , &l, &r);       node x = get(1, 1, N, l, r);       if (x.mn < 0 || x.s != 0)         puts( -1 );       else         printf( %lld n , x.mx);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int w, h, k, sum = 0;     cin >> w >> h >> k;     while (k != 0) {       sum = sum + ((2 * w) + (2 * h) - 4);       w = w - 4;       h = h - 4;       k = k - 1;     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T a, T b) {     if (a == 0) return b;     return gcd(b % a, a);   }   template <typename T>   T pow(T a, T b, long long m) {     T ans = 1;     while (b > 0) {       if (b % 2 == 1) ans = (ans * a) % m;       b /= 2;       a = (a * a) % m;     }     return ans % m;   }   const long long N = 1e6 + 5;   const long long MOD = 1e9 + 7;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long q;     cin >> q;     while (q--) {       long long n;       cin >> n;       if (n == 1 || n == 2 || n == 3 || n == 5 || n == 7 || n == 11) {         cout <<  -1               <<   n ;         continue;       }       long long ans = n / 4;       long long rem = n % 4;       if (rem % 2) ans--;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int nn, mm;   struct Dinic {     struct edge {       int to, flow, cap;     };     const static int N = 20007;     vector<edge> e;     vector<int> g[N + 7];     int dp[N + 7];     int ptr[N + 7];     void clear() {       for (int i = 0; i < N + 7; i++) g[i].clear();       e.clear();     }     void addEdge(int a, int b, int cap) {       g[a].push_back(e.size());       e.push_back({b, 0, cap});       g[b].push_back(e.size());       e.push_back({a, 0, 0});     }     int minFlow, start, finish;     bool bfs() {       for (int i = 0; i < N; i++) dp[i] = -1;       dp[start] = 0;       vector<int> st;       int uk = 0;       st.push_back(start);       while (uk < st.size()) {         int v = st[uk++];         for (int to : g[v]) {           auto ed = e[to];           if (ed.cap - ed.flow >= minFlow && dp[ed.to] == -1) {             dp[ed.to] = dp[v] + 1;             st.push_back(ed.to);           }         }       }       return dp[finish] != -1;     }     int dfs(int v, int flow) {       if (v == finish) return flow;       for (; ptr[v] < g[v].size(); ptr[v]++) {         int to = g[v][ptr[v]];         edge ed = e[to];         if (ed.cap - ed.flow >= minFlow && dp[ed.to] == dp[v] + 1) {           int add = dfs(ed.to, min(flow, ed.cap - ed.flow));           if (add) {             e[to].flow += add;             e[to ^ 1].flow -= add;             return add;           }         }       }       return 0;     }     int dinic(int start, int finish) {       Dinic::start = start;       Dinic::finish = finish;       int flow = 0;       for (minFlow = (1 << 30); minFlow; minFlow >>= 1) {         while (bfs()) {           for (int i = 0; i < N; i++) ptr[i] = 0;           while (int now = dfs(start, (int)2e9 + 7)) flow += now;         }       }       return flow;     }   } dinic;   pair<int, int> aa[5555];   bool can(int val) {     dinic.clear();     for (int i = 0; i < nn; i++) {       dinic.addEdge(nn + mm, i, val);     }     for (int i = 0; i < mm; i++) {       dinic.addEdge(nn + i, nn + mm + 1, 1);     }     for (int i = 0; i < mm; i++) {       dinic.addEdge(aa[i].first, nn + i, 1);       dinic.addEdge(aa[i].second, nn + i, 1);     }     int ans = dinic.dinic(nn + mm, nn + mm + 1);     return ans == mm;   }   int main() {     cin >> nn >> mm;     for (int i = 0; i < mm; i++) cin >> aa[i].first >> aa[i].second;     for (int i = 0; i < mm; i++) aa[i].first--, aa[i].second--;     int vl = 0, vr = mm;     while (vl + 1 < vr) {       int vm = (vl + vr) >> 1;       if (can(vm))         vr = vm;       else         vl = vm;     }     cout << vr <<   n ;     can(vr);     for (int i = 0; i < nn; i++) {       for (int to : dinic.g[i]) {         if (dinic.e[to].flow == 1) {           cout << i + 1 <<                    << aa[dinic.e[to].to - nn].first + aa[dinic.e[to].to - nn].second -                       i + 1                <<   n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int n;     long long m;     cin >> n >> m;     long long arr[n], sum = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       sum += arr[i];     }     sort(arr, arr + n);     long long hneed = arr[n - 1], extra = 0;     for (int i = n - 1; i >= 0; i--) {       if (arr[i] >= hneed) {         hneed--;         continue;       } else {         extra += (hneed - arr[i]);         hneed = arr[i] - 1;       }     }     hneed = max(hneed, 0LL);     cout << sum - n - extra - hneed;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt[100500];   int bestAns, start, len;   int longest[100500];   inline void updAns(int L, int R) {     int val = cnt[R + 1] - cnt[L];     if (val > bestAns) {       bestAns = val;       start = L;       len = R - L + 1;     }   }   int main() {     stack<pair<char, int> > seq;     string s;     cin >> s;     int n = s.size();     for (int i = 1; i <= n; i++) {       cnt[i] = s[i - 1] ==  [ ;       cnt[i] += cnt[i - 1];       longest[i - 1] = n + 234;     }     for (int i = 0; i < n; i++) {       pair<char, int> cur(s[i], i);       if (seq.empty())         seq.push(cur);       else {         char pr = seq.top().first;         if (s[i] ==  ]  and pr ==  [  or s[i] ==  )  and pr ==  ( ) {           pair<char, int> ws = seq.top();           seq.pop();           int low = ws.second, high = i;           longest[i] = min(longest[i], low);           if (low > 0 and longest[low - 1] < low - 1) {             longest[i] = min(longest[i], longest[low - 1]);           }           updAns(longest[i], i);         } else           seq.push(cur);       }     }     cout << bestAns << endl;     cout << s.substr(start, len) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long a[n + 1];     memset(a, 0, sizeof(a));     for (long long i = 1; i <= n; i++) cin >> a[i];     sort(a, a + n + 1);     long long sum[n + 1];     memset(sum, 0, sizeof(sum));     sum[1] = a[1];     for (int i = 2; i <= n; i++) {       sum[i] = sum[i - 1] + a[i];     }     long long ans = 0;     for (int i = 0; i <= n; i++) {       ans = ans + a[i] + (sum[n] - sum[i]);     }     cout << ans - a[n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   ostream& operator<<(ostream& out, const pair<T1, T2> p) {     out <<  (  << p.first <<  ,  << p.second <<  ) ;     return out;   }   template <class T1, class T2>   istream& operator>>(istream& in, pair<T1, T2>& p) {     in >> p.first >> p.second;     return in;   }   template <class T>   istream& operator>>(istream& in, vector<T>& v) {     for (T& x : v) in >> x;     return in;   }   template <class T>   ostream& operator<<(ostream& out, const vector<vector<T> >& v) {     for (const vector<T>& x : v) out << x <<   n ;     return out;   }   template <class T>   ostream& operator<<(ostream& out, const vector<T>& v) {     for (const T& x : v) out << x <<    ;     return out;   }   long long power(long long a, long long b) {     return b ? power(a * a % 1000000007ll, b / 2) * (b % 2 ? a : 1) % 1000000007ll              : 1;   }   bool possible(vector<string>& s, string a) {     for (long long i = 1; i < (long long)(s).size(); i++) {       long long diff = 0;       for (long long j = 0; j < (long long)(a).size(); j++) {         if (a[j] != s[i][j]) diff++;       }       if (diff > 1) return false;     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long T;     cin >> T;     while (T--) {       long long n, m;       cin >> n >> m;       vector<string> s(n);       cin >> s;       string a = s[0];       if (possible(s, a)) {         cout << a << endl;       } else {         string ans =   ;         for (long long i = 0; i < (long long)(s[0]).size() && ans ==   ; i++) {           char temp = s[0][i];           for (long long c =  a ; c <=  z  && ans ==   ; c++) {             s[0][i] = c;             if (possible(s, s[0])) {               ans = s[0];               break;             }           }           s[0][i] = temp;         }         if (ans ==   ) {           cout << -1 << endl;         } else           cout << ans << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long int MOD = 1000000007;   unsigned long long int B = 13331;   bool cmp(const int &a, const int &b) { return a < b; }   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int lcm(int a, int b) { return a * (b / gcd(a, b)); }   double func(double mod, double x) {     int n = (int)(x / (2.0 * mod));     x -= n * 2.0 * mod;     while (x < 0.0) x += 2.0 * mod;     while (x > 2.0 * mod) x -= 2.0 * mod;     if (x > mod) x = 2.0 * mod - x;     return x;   }   int main(void) {     int i;     double a, b, m, vx, vy, vz;     cin >> a >> b >> m >> vx >> vy >> vz;     double x = func(a, a / 2.0 + vx * (m / (-vy)));     double z = func(b, vz * (m / (-vy)));     printf( %.9f %.9f n , x, z);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 15;   const int mod = 1e9 + 7;   const int inf = 1e9 + 3;   int t, n;   string a[3], s;   int flag;   int conv(string q) {     int ans = 0;     for (int i = 0; i < q.size(); i++) {       ans *= 10;       ans += q[i] -  0 ;     }     return ans;   }   int main() {     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  .  || s[i] ==  e )         t++;       else         a[t] += s[i];     }     for (int i = a[1].size() - 1; i >= 0; i--) {       if (a[1][i] ==  0 )         flag++;       else         break;     }     cout << a[0];     n = conv(a[2]);     for (int i = 0; i < a[1].size() - flag; i++) {       if (n == 0) cout <<  . ;       n--;       cout << a[1][i];     }     while ((n--) > 0) cout << 0;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  { ;     string sep;     for (const auto &x : v) os << sep << x, sep =  ,  ;     return os <<  } ;   }   template <typename T, size_t size>   ostream &operator<<(ostream &os, const array<T, size> &arr) {     os <<  { ;     string sep;     for (const auto &x : arr) os << sep << x, sep =  ,  ;     return os <<  } ;   }   template <typename A, typename B>   ostream &operator<<(ostream &os, const pair<A, B> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   void dbg_out() { cerr << endl; }   template <typename Head, typename... Tail>   void dbg_out(Head H, Tail... T) {     cerr <<     << H;     dbg_out(T...);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int N, M;     cin >> N >> M;     vector<int> which_tower(N);     vector<set<int>> towers(M);     int answer = N - 1;     for (int i = 0; i < N; i++) {       cin >> which_tower[i];       which_tower[i]--;       towers[which_tower[i]].insert(i);       if (i > 0 && which_tower[i] == which_tower[i - 1]) answer--;     }     auto &&merge_into = [&](int from, int to) {       if (towers[from].size() > towers[to].size()) swap(towers[from], towers[to]);       for (auto &x : towers[from]) {         answer -= int(towers[to].count(x - 1));         answer -= int(towers[to].count(x + 1));       }       for (auto &x : towers[from]) towers[to].insert(x);       towers[from].clear();     };     cout << answer <<   n ;     for (int q = 0; q < M - 1; q++) {       int a, b;       cin >> a >> b;       a--;       b--;       merge_into(b, a);       cout << answer <<   n ;     }   }


#include <bits/stdc++.h>   int main() {     int n, b;     scanf( %d%d , &n, &b);     int a[100], s = b;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       s += a[i];     }     for (int i = 0; i < n; i++)       if (s < a[i] * n) {         puts( -1 );         return 0;       }     for (int i = 0; i < n; i++) printf( %.8lf n , 1. * s / n - a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mo = 1e9 + 7;   const int N = 1000010;   const int inf = 0x3f3f3f3f;   using namespace std;   int n, m, q, tot, ans[N], fa[N], mark[N], pa[N], tmp;   struct node {     int a, b, c;     bool operator<(const node &x) const { return c < x.c; }   } e[N], ed[N];   struct info {     int a, b;     bool operator<(const info &x) const {       if (e[a].c != e[x.a].c) return e[a].c < e[x.a].c;       return b < x.b;     }   } t[N];   int find(int x) {     if (!fa[x]) return x;     return fa[x] = find(fa[x]);   }   int find2(int x) {     if (mark[x] != tmp) pa[x] = fa[x], mark[x] = tmp;     if (!pa[x]) return x;     return pa[x] = find2(pa[x]);   }   int main() {     int a, b, c, k, x, A, B;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &a, &b, &c);       e[i] = (node){a, b, c};       ed[i] = e[i];     }     scanf( %d , &q);     for (int j = 1; j <= q; j++) {       scanf( %d , &k);       for (int i = 1; i <= k; i++) scanf( %d , &x), t[++tot] = (info){x, j};     }     sort(t + 1, t + tot + 1);     sort(ed + 1, ed + m + 1);     for (int i = 1, pos = 1, po = 1; i <= tot; i = pos) {       while (ed[po].c < e[t[i].a].c && po <= m) {         A = find(ed[po].a);         B = find(ed[po].b);         if (A != B) fa[B] = A;         po++;       }       while (e[t[pos].a].c == e[t[i].a].c && pos <= tot) {         if (t[pos].b != t[pos - 1].b || pos == i) tmp++;         x = t[pos].a;         A = find2(e[x].a);         B = find2(e[x].b);         if (A == B)           ans[t[pos].b] = 1;         else           pa[B] = A;         pos++;       }     }     for (int i = 1; i <= q; i++) {       if (!ans[i])         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <iostream>   #include <algorithm>   using namespace std;         int main()   {       int64_t k;       int64_t n, x, t;       cin >> k;       while(k--) {           cin >> n >> x >> t;           int64_t zero = 0;           int64_t ans = max(zero, n - t/x) * (t / x) + min(t/x, n) * min(t/x - 1, n - 1) / 2;           cout << ans << endl;       }             return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1010;   int q1[MAXN], q2[MAXN], r1, r2;   int n, c, m;   int a[MAXN];   bool check() {     for (int i = 1; i <= n; i++)       if (!a[i] || (a[i] < a[i - 1])) return false;     return true;   }   int main() {     cin >> n >> m >> c;     while (!check()) {       int x;       cin >> x;       if (x > c / 2) {         bool flag = false;         for (int i = 1; i <= r2; i++)           if (x > q2[i]) {             q2[i] = x;             printf( %d n , n - i + 1);             flag = true;             a[n - i + 1] = x;             break;           }         if (!flag) {           q2[++r2] = x;           printf( %d n , n - r2 + 1);           a[n - r2 + 1] = x;         }       } else {         bool flag = false;         for (int i = 1; i <= r1; i++)           if (x < q1[i]) {             q1[i] = x;             printf( %d n , i);             flag = true;             a[i] = x;             break;           }         if (!flag) {           q1[++r1] = x;           printf( %d n , r1);           a[r1] = x;         }       }       fflush(stdout);     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000 )   using namespace std;   const long double pi = acos(-1.0);   const long long inf = (long long)1e18;   const int N = (int)1e6;   int n, m;   long long need[N], start[N];   bool check(long long x) {     int lowest = 0;     for (int i = 0; (i < n) && (lowest < m); ++i) {       long long pos = start[i], can = x;       if (need[lowest] <= pos) {         if (pos - need[lowest] > can)           return false;         else           can = max(can - 2 * (pos - need[lowest]),                     (can - (pos - need[lowest])) / 2);       }       while ((lowest < m) && (need[lowest] - pos <= can)) ++lowest;     }     return (lowest == m);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) scanf( %I64d , &start[i]);     for (int i = 0; i < m; ++i) scanf( %I64d , &need[i]);     if (check(0)) {       printf( 0 n );       return 0;     }     long long l = 0, r = inf;     while (l < r - 1) {       long long m = (l + r) / 2;       if (check(m))         r = m;       else         l = m;     }     printf( %I64d n , r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   int main() {     int n, k;     scanf( %d , &n), scanf( %d , &k);     if (k % 2 == 0) {       int ans = 0;       while (n--) {         int x;         scanf( %d , &x);         if (x == 1) ans ^= 1;         if (x == 2) ans ^= 2;         if (x > 2) ans ^= !(x % 2);       }       if (ans)         printf( Kevin n );       else         printf( Nicky n );       return 0;     }     function<int(int)> f = [&f](int i) {       if (i == 0) return 0;       if (i == 1) return 1;       if (i == 2) return 0;       if (i == 3) return 1;       if (i == 4) return 2;       if (i == 5) return 0;       if (i % 2 == 1) return 0;       set<int> second;       second.insert(f(i - 1));       second.insert(f(i / 2));       int ret = 0;       while (second.count(ret)) ret++;       return ret;     };     int ans = 0;     while (n--) {       int x;       scanf( %d , &x);       ans ^= f(x);     }     if (ans)       printf( Kevin n );     else       printf( Nicky n );     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   int n, k, i, a[100010];   set<int> r;   int main() {     scanf( %d%d , &n, &k);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n);     for (i = 0; i < n; i++) {       if (a[i] % k == 0 && r.count(a[i] / k)) continue;       r.insert(a[i]);     }     printf( %d n , int(r.size()));     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   int n, k;   int d[2][10000];   void solution() {     scanf( %d %d , &n, &k);     for (int i = 0, _n = (n - 1); i < _n; ++i) d[0][i] = 1;     int cur = 0, nxt = 1;     for (int it = 0, _n = (k); it < _n; ++it) {       for (int i = 0, _n = (n); i < _n; ++i) {         int need = n - i - 1 - d[cur][i];         int lo = 0, hi = n - 1;         while (hi - lo > 1) {           int m = (lo + hi) / 2;           if (d[cur][m] <= need)             hi = m;           else             lo = m;         }         if (lo < hi && d[cur][lo] <= need) hi = lo;         if (d[cur][hi] > need) throw 1;         d[nxt][i] = d[cur][i] + d[cur][hi];         printf( %d  , hi + 1);       }       swap(cur, nxt);       puts(  );     }     for (int i = 0, _n = (n); i < _n; ++i)       if (d[cur][i] != n - i - 1) throw 1;   }   int main() {     solution();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int sum = 0;     bool ok = false;     for (int i = 1; i <= n; i++) {       sum = i + sum;       if (n == 1 || n == sum) {         cout <<  YES  << endl;         break;       }       if (sum > n) {         ok = true;         break;       }     }     if (ok) cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   inline long long int input() {     long long int n;     cin >> n;     return n;   }   long long int pw(long long int a, long long int b) {     return (!b ? 1 : (b & 1 ? a * pw(a * a, b / 2) : pw(a * a, b / 2)));   }   const long long int MAXN = 2e5 + 10;   const long long int MAXA = 101;   const long long int INF = 8e18;   const long long int MOD = 1e9 + 7;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());     ;     long long int t;     cin >> t;     while (t--) {       long long int L, v, l, r;       cin >> L >> v >> l >> r;       long long int bib = L / v;       long long int bib1 = l / v - (l % v == 0), bib2 = r / v;       long long int x = bib2 - bib1;       cout << bib - x << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   int n;   int m;   int t[4 * N];   void upd(int l, int r, int v = 1, int tl = 1, int tr = N) {     if (l > r) return;     if (l <= tl && tr <= r) {       t[v]++;       return;     }     int tm = (tl + tr) / 2;     upd(l, min(tm, r), v * 2, tl, tm);     upd(max(tm + 1, l), r, v * 2 + 1, tm + 1, tr);   }   int get(int pos, int v = 1, int tl = 1, int tr = N) {     if (tl == tr) return t[v];     int tm = (tl + tr) / 2;     if (pos <= tm)       return t[v] + get(pos, v * 2, tl, tm);     else       return t[v] + get(pos, v * 2 + 1, tm + 1, tr);   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     long long res = 1;     vector<pair<int, int>> left;     vector<pair<int, int>> right;     for (int i = 1; i <= n; i++) {       int y, l, r;       cin >> y >> l >> r;       if (l == 0 && r == N) res++;       if (l == 0)         left.push_back({y, r});       else         right.push_back({y, l});     }     sort(left.begin(), left.end());     sort(right.begin(), right.end());     vector<pair<int, int>> top;     vector<pair<int, int>> bottom;     for (int i = 1; i <= m; i++) {       int x, l, r;       cin >> x >> l >> r;       if (l == 0 && r == N) res++;       if (l == 0)         bottom.push_back({r, x});       else         top.push_back({l, x});     }     sort(bottom.begin(), bottom.end());     int i1 = 0, i2 = 0;     for (int i = 0; i < (int)bottom.size(); i++) {       while (i1 < (int)left.size() && left[i1].first <= bottom[i].first) {         upd(0, left[i1].second);         i1++;       }       while (i2 < (int)right.size() && right[i2].first <= bottom[i].first) {         upd(right[i2].second, N);         i2++;       }       res += get(bottom[i].second);     }     memset(t, 0, sizeof t);     sort(top.rbegin(), top.rend());     reverse(left.begin(), left.end());     reverse(right.begin(), right.end());     i1 = 0, i2 = 0;     for (int i = 0; i < (int)top.size(); i++) {       while (i1 < (int)left.size() && left[i1].first >= top[i].first) {         upd(0, left[i1].second);         i1++;       }       while (i2 < (int)right.size() && right[i2].first >= top[i].first) {         upd(right[i2].second, N);         i2++;       }       res += get(top[i].second);     }     cout << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   char s[2000010], t[2000010];   int main(void) {     int n;     scanf( %d , &n);     scanf( %s , s);     scanf( %s , t);     int count_s, count_t, count_com;     count_s = count_t = count_com = 0;     for (int i = 0; i < 2 * n; ++i) {       if (s[i] ==  1  && t[i] ==  1 ) {         ++count_com;       }       if (s[i] ==  1  && t[i] !=  1 ) {         ++count_s;       }       if (s[i] !=  1  && t[i] ==  1 ) {         ++count_t;       }     }     if (count_com % 2 == 0) {       if (count_s > count_t) {         puts( First );       } else if (count_s >= count_t - 1) {         puts( Draw );       } else {         puts( Second );       }     } else {       if (count_s >= count_t) {         puts( First );       } else if (count_s >= count_t - 2) {         puts( Draw );       } else {         puts( Second );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void cmax(T& a, T b) {     a = max(a, b);   }   template <class T>   void cmin(T& a, T b) {     a = min(a, b);   }   void _BG(const char* s) {}   template <class T, class... TT>   void _BG(const char* s, T a, TT... b) {     for (int c = 0; *s && (c || *s !=  , ); ++s) {       cerr << *s;       for (char x :  ([{ ) c += *s == x;       for (char x :  )]} ) c -= *s == x;     }     cerr <<   =   << a;     if (*s) {       cerr <<  ,  ;       _BG(++s, b...);     } else       cerr << endl;   }   bool RD() { return 1; }   bool RD(char& a) { return scanf(  %c , &a) == 1; }   bool RD(char* a) { return scanf( %s , a) == 1; }   bool RD(double& a) { return scanf( %lf , &a) == 1; }   bool RD(int& a) { return scanf( %d , &a) == 1; }   bool RD(long long& a) { return scanf( %lld , &a) == 1; }   template <class T, class... TT>   bool RD(T& a, TT&... b) {     return RD(a) && RD(b...);   }   void PT(const char& a) { putchar(a); }   void PT(char const* const& a) { fputs(a, stdout); }   void PT(const double& a) { printf( %.16f , a); }   void PT(const int& a) { printf( %d , a); }   void PT(const long long& a) { printf( %lld , a); }   template <char s =    , char e =   n >   void PL() {     if (e) PT(e);   }   template <char s =    , char e =   n , class T, class... TT>   void PL(const T& a, const TT&... b) {     PT(a);     if (sizeof...(b) && s) PT(s);     PL<s, e>(b...);   }   const int N = 1e5 + 87;   int n, a[N];   set<int> p[N];   struct node {     long long s;     node *lc, *rc;   } * ver[N];   void upd(node*& t, int l, int r, int i, int x) {     if (!t) t = new node();     t->s += x;     if (r - l == 1) {       return;     }     int m = l + (r - l) / 2;     if (i < m)       upd(t->lc, l, m, i, x);     else       upd(t->rc, m, r, i, x);   }   long long qry(node* t, int l, int r, int i, int j) {     if (!t || r <= i || j <= l) return 0;     if (i <= l && r <= j) return t->s;     int m = (l + r) / 2;     return qry(t->lc, l, m, i, j) + qry(t->rc, m, r, i, j);   }   void upd(int i, int j, int x) {     if (i < 1 || i > n || j < 1 || j > n) return;     for (; i <= n; i += i & -i) upd(ver[i], 1, n + 1, j, x);   }   long long qry(int i, int l, int r) {     long long x = 0;     for (; i; i ^= i & -i) x += qry(ver[i], 1, n + 1, l, r);     return x;   }   long long qry(int i, int j) { return qry(j, i, j + 1); }   void del(int i) {     int v = a[i];     auto it = p[v].upper_bound(i);     int l = 0, r = n + 1;     if (it != p[v].end()) r = *it;     it = prev(it);     if (it != p[v].begin()) l = *prev(it);     upd(r, l, r - l);     upd(r, i, -(r - i));     upd(i, l, -(i - l));     p[v].erase(it);   }   void ins(int i, int v) {     auto it = p[v].upper_bound(i);     int l = 0, r = n + 1;     if (it != p[v].end()) r = *it;     if (it != p[v].begin()) l = *prev(it);     upd(r, l, -(r - l));     upd(r, i, r - i);     upd(i, l, i - l);     p[v].insert(it, i);     a[i] = v;   }   int main() {     int m;     RD(n, m);     for (int i(1); i < ((n) + 1); ++i) {       int x;       RD(x);       ins(i, x);     }     for (int __i(0); __i < (m); ++__i) {       int t, x, y;       RD(t, x, y);       if (t == 1) {         if (a[x] == y) continue;         del(x);         ins(x, y);       } else {         PL(qry(x, y));       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long r[1003], c[1003], g[1003][1003];   int main() {     long long w, h;     scanf( %lld %lld , &h, &w);     for (int i = 0; i < h; i++) scanf( %lld , &r[i]);     for (int i = 0; i < w; i++) scanf( %lld , &c[i]);     memset(g, -1, sizeof g);     for (int i = 0; i < h; i++) {       for (int j = 0; j < r[i]; j++) {         g[i][j] = 0;       }       g[i][r[i]] = 1;     }     for (int j = 0; j < w; j++) {       for (int i = 0; i < c[j]; i++) {         if (g[i][j] == 1) {           printf( 0 );           return 0;         }         g[i][j] = 0;       }       if (g[c[j]][j] == 0) {         printf( 0 );         return 0;       }       g[c[j]][j] = 1;     }     long long ans = 1;     for (int i = 0; i < h; i++) {       for (int j = 0; j < w; j++) {         if (g[i][j] == -1) ans = (ans * 2) % 1000000007;       }     }     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;      #define ll long long   #define fi first   #define se second      const int MAX = 2 * 1e5 + 10;   const int MOD = 1e9 + 7;   ll t;   ll n, m, k;   ll a, b, x, y, x2, y2;   ll bio[MAX];   ll arr[MAX];   vector <ll> v;   string s;      int main() {       cin >> t;          while (t--) {           cin >> n;           cin >> s;              b = 0;           for (int i = 0; i < n; i++) {               if (s[i] ==  b ) b++;           }              for (int i = 0; i < b; i++) {               cout <<  b ;           }           for (int i = 0; i < n; i++) {               if (s[i] ==  b ) continue;               cout << s[i];           }              cout <<   n ;       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3fLL;   const long long mod = 1e9 + 7;   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long pct(long long x) { return __builtin_popcount(x); }   long long bit(long long x) { return 31 - __builtin_clz(x); }   long long cdiv(long long a, long long b) {     return a / b + !(a < 0 || a % b == 0);   }   void DBG() { cerr <<  ]  << endl; }   template <class H, class... T>   void DBG(H h, T... t) {     cerr << to_string(h);     if (sizeof...(t)) cerr <<  ,  ;     DBG(t...);   }   const long long maxn = 1e5 * 3 + 20;   long long n, _, q, k;   void solve() {     cin >> _;     while (_--) {       cin >> n;       long long sm = 0;       vector<long long> a(n);       vector<long long> b(n);       for (signed i = 0; i < n; i++) {         cin >> a[i];       }       for (signed i = 0; i < n; i++) {         cin >> b[i];         sm += b[i];       }       vector<long long> order(n);       iota(order.begin(), order.end(), 0);       sort(begin(order), end(order),            [&a](long long i, long long j) { return a[i] < a[j]; });       long long ans = sm;       for (long long x : order) {         long long tmp = max(sm - b[x], a[x]);         if (tmp < ans) {           sm -= b[x];           ans = tmp;         }       }       cout << ans << endl;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   int n, c[1011], vao[1011], save[1011];   vector<int> ke[1011];   bool mark[1011];   int get(int start) {     for (int i = (1), _b = (n); i <= _b; i++) vao[i] = save[i];     int done = 0, res = 0;     memset(mark, false, sizeof mark);     while (done < n) {       int inc = 0;       for (int i = (1), _b = (n); i <= _b; i++)         if (!mark[i] && vao[i] == 0 && c[i] == start) {           mark[i] = true;           ++done;           ++inc;           for (int x = 0, _a = (ke[i].size()); x < _a; x++) {             int u = ke[i][x];             vao[u]--;           }         }       if (done == n) break;       if (!inc) {         if (start == 3)           start = 1;         else           ++start;         ++res;       }     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = (1), _b = (n); i <= _b; i++) scanf( %d , &c[i]);     for (int i = (1), _b = (n); i <= _b; i++) {       scanf( %d , &save[i]);       for (int x = (1), _b = (save[i]); x <= _b; x++) {         int u;         scanf( %d , &u);         ke[u].push_back(i);       }     }     int res = n * 4;     for (int start = (1), _b = (3); start <= _b; start++) {       res = min(res, get(start));     }     cout << res + n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n, k, p, x, y;     cin >> n >> k >> p >> x >> y;     vector<int> a(n);     int sum = 0;     for (int i = 0; i < k; i++) {       cin >> a[i];       sum += a[i];     }     if (sum + n - k > x) {       cout << -1 <<   n ;       exit(0);     }     x -= sum;     for (int i = k; i < n; i++) {       if (y + n - 1 - i <= x) {         a[i] = y;         x -= y;       } else {         a[i] = 1;         x -= 1;       }     }     vector<int> b = a;     sort(b.begin(), b.end());     if (b[n >> 1] >= y) {       for (int i = k; i < n; i++) {         cout << a[i] <<    ;       }       cout <<   n ;     } else {       cout << -1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = (1000000007LL);   inline long long mult(long long a, long long b) { return (a * b) % mod; }   inline long long poww(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return res;   }   long long gcd(long long a, long long b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   int n, m, q, k, v[300050], ans;   pair<int, int> w[300050];   string second;   int leaf[300050], root, dp[300050], qtd[300050][2];   int ini[300050], yes = 1;   vector<int> grafo[300050];   void dfs(int x, int p) {     int can = 0;     if (leaf[x] and dp[x] == 1) yes = 0;     for (auto v : grafo[x]) {       if (v == p) continue;       if (leaf[v]) can = 1;       dp[v] = (dp[x] ^ 1);       dfs(v, x);       for (int j = 0; j < 2; j++) {         if (qtd[x][j] > 0 and qtd[v][j ^ dp[v] ^ 1]) yes = 0;       }       qtd[x][0] += qtd[v][0];       qtd[x][1] += qtd[v][1];     }     if ((can or p == root) and !leaf[x]) ans++;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       grafo[a].push_back(b);       grafo[b].push_back(a);     }     ans = n - 1;     root = 1;     for (int i = 1; i <= n; i++) {       if ((int)(grafo[i]).size() == 1) leaf[i] = 1, root = i, ans--;     }     dfs(root, root);     cout << (yes ? 1 : 3) <<     << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int val;     int type;   } N[500000];   int main() {     long long n, a, b, c, d, start, len;     cin >> n >> a >> b >> c >> d >> start >> len;     for (int i = 1; i <= n; i++) {       cin >> N[i].val >> N[i].type;     }     long long s = 1, t = 1, sum_st = start, ans = 0;     long long low = 0;     N[0].val = -1;     for (int s = 1; s <= n; s++) {       while (t <= n && N[t].val - N[s].val <= len) {         if (N[t].type == 1)           ans += c;         else if (N[t].type == 0)           ans -= d;         low = min(low, ans);         t++;       }       if (sum_st + low >= 0) {         cout << N[s - 1].val + 1 << endl;         return 0;       }       if (N[s].type == 1) {         ans -= c;         low -= c;         sum_st += a;       } else {         ans += d;         low += d;         sum_st -= b;       }       if (sum_st < 0) {         cout << -1 << endl;         return 0;       }     }     cout << N[n].val + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long long INF = 4e18 + 10;   long long n;   long long a[55];   vector<vector<long long> > ans;   long long findpos(long long x) {     for (long long i = 0; i < n; i++)       if (a[i] == x) return i;   }   void p1(long long x) {     long long xx = findpos(x);     vector<long long> v;     if (xx > 0) v.push_back(xx);     if (n - x + 1 - xx > 0) v.push_back(n - x + 1 - xx);     for (long long i = n - x + 1; i < n; i++) v.push_back(1);     ans.push_back(v);     long long b[n];     long long i = 0;     for (i = 0; i < x - 1; i++) b[i] = i + 1;     for (long long j = xx; j <= n - x; j++) {       b[i] = a[j];       i++;     }     for (long long j = 0; j < xx; j++) {       b[i] = a[j];       i++;     }     for (long long j = 0; j < n; j++) {       a[j] = b[j];     }   }   void p2(long long x) {     long long xx = findpos(x);     vector<long long> v;     for (long long i = 0; i < x - 1; i++) v.push_back(1);     if (xx + 1 - x + 1 > 0) v.push_back(xx + 1 - x + 1);     if (n - 1 - xx > 0) v.push_back(n - 1 - xx);     ans.push_back(v);     long long b[n];     long long i = 0;     for (long long j = xx + 1; j < n; j++) {       b[i] = a[j];       i++;     }     for (long long j = x - 1; j <= xx; j++) {       b[i] = a[j];       i++;     }     for (long long j = 0; j < x - 1; j++) {       b[i] = j + 1;       i++;     }     for (long long j = 0; j < n; j++) {       a[j] = b[j];     }   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cout << fixed << setprecision(10);     long long t = 1;     while (t--) {       cin >> n;       for (long long i = 0; i < n; i++) cin >> a[i];       long long x = findpos(1);       if (n % 2 == 1) {         if (x == 0) {         } else {           vector<long long> v;           v.push_back(x);           v.push_back(n - x);           ans.push_back(v);           long long b[n];           long long i = 0;           for (long long j = x; j < n; j++) {             b[i] = a[j];             i++;           }           for (long long j = 0; j < x; j++) {             b[i] = a[j];             i++;           }           for (long long j = 0; j < n; j++) {             a[j] = b[j];           }         }         for (long long i = 2; i <= n; i++) {           if (i % 2 == 1)             p1(i);           else             p2(i);         }       } else {         if (x == n - 1) {         } else {           vector<long long> v;           v.push_back(x + 1);           v.push_back(n - x - 1);           ans.push_back(v);           long long b[n];           long long i = 0;           for (long long j = x + 1; j < n; j++) {             b[i] = a[j];             i++;           }           for (long long j = 0; j <= x; j++) {             b[i] = a[j];             i++;           }           for (long long j = 0; j < n; j++) {             a[j] = b[j];           }         }         for (long long i = 2; i <= n; i++) {           if (i % 2 == 1)             p2(i);           else             p1(i);         }       }       cout << ans.size() << endl;       for (long long i = 0; i < ans.size(); i++) {         cout << ans[i].size() <<    ;         for (long long j = 0; j < ans[i].size(); j++) {           cout << ans[i][j] <<    ;         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   char s[4][12];   char t[12][25][12];   int num[12];   int main() {     int i, j;     int ans = 0, p = 0;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %s , s[i]);     scanf( %d , &m);     for (i = 0; i < m; i++) {       scanf( %d , &num[i]);       for (j = 0; j < num[i]; j++) scanf( %s , t[i][j]);     }     int mark[4];     int rec[25];     for (int k = 0; k < m; k++) {       memset(mark, 0, sizeof(mark));       memset(rec, -1, sizeof(rec));       for (i = 0; i < 4; i++) {         for (j = 0; j < num[k]; j++) {           if (strcmp(s[i], t[k][j]) == 0) {             mark[i] = 1;             rec[j] = i;           }         }       }       int sum = 0;       for (i = 0; i < n; i++) sum += mark[i];       if (sum < n) continue;       int id[4] = {0, 1, 2, 3};       do {         j = 0;         for (i = 0; i < num[k]; i++) {           if (rec[i] == id[j]) {             j++;             if (j == n) break;           }         }         int x = 0;         for (i = 0; i < n - 1; i++)           for (int tt = i + 1; tt < n; tt++)             if (id[i] > id[tt]) x++;         if (j == n && n * (n - 1) / 2 - x + 1 > p) {           ans = k + 1;           p = n * (n - 1) / 2 - x + 1;         }       } while (next_permutation(id, id + n));     }     if (ans == 0)       printf( Brand new problem! n );     else {       printf( %d n , ans);       printf( [: );       for (i = 0; i < p; i++) printf( | );       printf( :] n );     }     return 0;   }


#include <bits/stdc++.h>   int n, arr[1005][3], sum, cnt;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++)       scanf( %d %d %d , &arr[i][0], &arr[i][1], &arr[i][2]);     for (int i = 0; i < n; i++) {       for (int j = 0; j < 3; j++) sum += arr[i][j];       if (sum >= 2) cnt++;       sum = 0;     }     printf( %d , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n), pmx(n, -1), smx(n, -1);     cin >> a[0];     pmx[0] = 0;     int c = 1;     for (int j = 1; j < n; j++) {       cin >> a[j];       pmx[j] = pmx[j - 1];       smx[j] = (j == 1) + (j != 1) * smx[j - 1];       if (a[j] > a[pmx[j]]) {         smx[j] = pmx[j];         pmx[j] = j;         c++;       } else if (a[j] > a[smx[j]]) {         smx[j] = j;       }     }     vector<int> rec(n, c);     int mx = -1, i;     for (int j = 0; j < n; j++) {       rec[j] -= (pmx[j] == j);     }     for (int j = 1; j < n; j++) {       if (smx[j] != j) continue;       rec[pmx[j]]++;     }     for (int j = 0; j < n; j++) {       if (mx < rec[j]) {         mx = rec[j];         i = j;       } else if (mx == rec[j] && a[j] < i) {         i = j;       }     }     int mn = n;     for (int j = 0; j < n; j++) {       if (rec[i] == rec[j] && mn > a[j]) {         mn = a[j];       }     }     cout << mn;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e3 + 5;   int n, m;   vector<int> g[maxn];   long long dis[maxn][maxn];   vector<pair<long long, long long> > from[maxn], to[maxn];   void bfs(int x) {     queue<int> q;     q.push(x);     dis[x][x] = 0;     while (!q.empty()) {       int now = q.front();       q.pop();       for (int i : g[now]) {         if (dis[x][i] == -1) {           dis[x][i] = dis[x][now] + 1;           q.push(i);         }       }     }   }   int main() {     memset(dis, -1, sizeof(dis));     scanf( %d%d , &n, &m);     for (int u, v, i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       g[u].push_back(v);     }     for (int i = 1; i <= n; i++) bfs(i);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         from[i].push_back({dis[i][j], j});         to[j].push_back({dis[i][j], i});       }     }     for (int i = 1; i <= n; i++) {       sort(from[i].begin(), from[i].end(),            greater<pair<long long, long long> >());       sort(to[i].begin(), to[i].end(), greater<pair<long long, long long> >());     }     int a, b, c, d, cnt = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == j || dis[i][j] == -1) continue;         for (int k = 0; k < 4; k++) {           if (to[i][k].second == j || to[i][k].second == i) continue;           for (int l = 0; l < 4; l++) {             if (from[j][l].second == i || from[j][l].second == to[i][k].second ||                 from[j][l].second == j)               continue;             if (to[i][k].first == -1 || from[j][l].first == -1) continue;             long long now = dis[i][j] + to[i][k].first + from[j][l].first;             if (now > cnt) {               cnt = now;               a = to[i][k].second, b = i, c = j, d = from[j][l].second;             }           }         }       }     }     printf( %d %d %d %d n , a, b, c, d);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       string p, h;       int w = 0;       cin >> p >> h;       sort(p.begin(), p.end());       if (h.size() >= p.size()) {         for (int i = 0; i < (h.size() - p.size() + 1); i++) {           string sub = h.substr(i, p.size());           sort(sub.begin(), sub.end());           if (sub == p) {             w = 1;             break;           }         }         if (w == 1)           cout <<  YES  << endl;         else           cout <<  NO  << endl;       } else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int k;     cin >> k;     int n, m;     n = 2;     m = 3;     int z = (1 << 17);     cout << n <<     << m <<   n ;     cout << z + k <<     << z <<     << k <<   n ;     cout << k <<     << z + k <<     << k <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<int> s;   int ans[1000000];   int main() {     int n, m;     scanf( %d %d , &n, &m);     int i, j, l, r, w;     for (i = 1; i <= n; i++) s.insert(i);     for (i = 0; i < m; i++) {       scanf( %d %d %d , &l, &r, &w);       auto idx1 = s.lower_bound(l);       auto idx2 = s.upper_bound(r);       vector<int> v;       for (auto it = idx1; it != idx2; it++) {         ans[*it] = w;         if (*it != w) v.push_back(*it);       }       for (j = 0; j < v.size(); j++) s.erase(v[j]);     }     ans[w] = 0;     for (i = 1; i <= n; i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }