#include <bits/stdc++.h>   using namespace std;   int X[1 << 11];   int Y[1 << 11];   int B[1 << 11];   int NX[1 << 11];   int NY[1 << 11];   int E[1 << 11][1 << 11];   int gN;   int dfs(int a) {     if (a == gN - 1) return 1;     B[a] = 1;     int i;     for (i = (0); i < (gN); ++i)       if (B[i] == 0 && E[a][i] > 0 && dfs(i) != 0) {         --E[a][i];         ++E[i][a];         return 1;       }     return 0;   }   void fwd(int a) {     B[a] = 1;     int i;     for (i = (0); i < (gN); ++i)       if (B[i] == 0 && E[a][i] > 0) fwd(i);   }   void bwd(int a) {     B[a] = 1;     int i;     for (i = (0); i < (gN); ++i)       if (B[i] == 0 && E[i][a] > 0) bwd(i);   }   int main() {     int n;     scanf( %d , &n);     int i, j;     for (i = (0); i < (n); ++i) scanf( %d%d , &X[i], &Y[i]);     vector<pair<pair<int, int>, int>> vx(n), vy(n);     for (i = (0); i < (n); ++i) {       vx[i] = make_pair(pair<int, int>(X[i], Y[i]), i);       vy[i] = make_pair(pair<int, int>(Y[i], X[i]), i);     }     sort((vx).begin(), (vx).end());     sort((vy).begin(), (vy).end());     vector<pair<int, int>> x, y;     for (i = (1); i < (n); ++i)       if (vx[i].first.first == vx[i - 1].first.first)         x.push_back(pair<int, int>(vx[i - 1].second, vx[i].second));     for (i = (1); i < (n); ++i)       if (vy[i].first.first == vy[i - 1].first.first)         y.push_back(pair<int, int>(vy[i - 1].second, vy[i].second));     int nx = int((x).size());     int ny = int((y).size());     memset(NX, -1, sizeof(NX));     memset(NY, -1, sizeof(NY));     for (i = (0); i < (nx); ++i) NX[x[i].first] = x[i].second;     for (i = (0); i < (ny); ++i) NY[y[i].first] = y[i].second;     memset(E, 0, sizeof(E));     for (i = (0); i < (nx); ++i)       for (j = (0); j < (ny); ++j) {         int ax = x[i].first;         int bx = x[i].second;         int ay = y[j].first;         int by = y[j].second;         if (Y[ay] <= Y[ax] || Y[bx] <= Y[ay]) continue;         if (X[ax] <= X[ay] || X[by] <= X[ax]) continue;         E[i][nx + j] = 1;       }     for (i = (0); i < (nx); ++i) E[nx + ny][i] = 1;     for (i = (0); i < (ny); ++i) E[i + nx][nx + ny + 1] = 1;     gN = nx + ny + 2;     int flow = 0;     for (i = (0); i < (nx); ++i)       for (j = (0); j < (ny); ++j)         if (E[gN - 2][i] > 0 && E[i][nx + j] > 0 && E[nx + j][gN - 1] > 0) {           --E[gN - 2][i];           ++E[i][gN - 2];           --E[i][nx + j];           ++E[nx + j][i];           --E[nx + j][gN - 1];           ++E[gN - 1][nx + j];           ++flow;         }     while (true) {       memset(B, 0, sizeof(B));       if (dfs(nx + ny) == 0) break;       ++flow;     }     for (i = (0); i < (nx); ++i)       if (B[i] == 0) {         int a = x[i].first;         int b = x[i].second;         NX[a] = -1;       }     for (i = (0); i < (ny); ++i)       if (B[nx + i] != 0) {         int a = y[i].first;         int b = y[i].second;         NY[a] = -1;       }     memset(B, 0, sizeof(B));     vector<pair<pair<int, int>, pair<int, int>>> rx;     for (i = (0); i < (int((vx).size())); ++i) {       int a = vx[i].second;       if (B[a] != 0) continue;       B[a] = 1;       int b = a;       while (NX[b] != -1) {         b = NX[b];         B[b] = 1;       }       if (X[a] != X[b]) throw 0;       rx.push_back(           make_pair(pair<int, int>(X[a], Y[a]), pair<int, int>(X[b], Y[b])));     }     memset(B, 0, sizeof(B));     vector<pair<pair<int, int>, pair<int, int>>> ry;     for (i = (0); i < (int((vy).size())); ++i) {       int a = vy[i].second;       if (B[a] != 0) continue;       B[a] = 1;       int b = a;       while (NY[b] != -1) {         b = NY[b];         B[b] = 1;       }       if (Y[a] != Y[b]) throw 0;       ry.push_back(           make_pair(pair<int, int>(X[a], Y[a]), pair<int, int>(X[b], Y[b])));     }     if (int((rx).size()) + int((ry).size()) != 2 * n - (nx + ny - flow)) throw 0;     printf( %d n , int((ry).size()));     for (i = (0); i < (int((ry).size())); ++i)       printf( %d %d %d %d n , ry[i].first.first, ry[i].first.second,              ry[i].second.first, ry[i].second.second);     printf( %d n , int((rx).size()));     for (i = (0); i < (int((rx).size())); ++i)       printf( %d %d %d %d n , rx[i].first.first, rx[i].first.second,              rx[i].second.first, rx[i].second.second);     return 0;   };


#include <bits/stdc++.h>   using namespace std;   vector<int> scs(const string& s) {     int n = s.size();     vector<int> p(n), c(s.begin(), s.end());     vector<vector<int>> g(max(n, 256));     for (int i = 0; i < n; i++) g[c[i]].push_back(i);     int b = 0;     for (auto& gr : g) {       for (int x : gr) p[b++] = x;       gr.clear();     }     for (int h = 1; h < n; h <<= 1) {       vector<int> p2(n), c2(n);       for (int j : p) {         int jp = (j + n - h) % n;         g[c[jp]].push_back(jp);       }       b = 0;       for (auto& gr : g) {         for (int x : gr) p2[b++] = x;         gr.clear();       }       b = 0;       c2[p2[0]] = 0;       for (int i = 1; i < n; i++) {         int x = p2[i];         int y = p2[i - 1];         if (c[x] == c[y] && c[(x + h) % n] == c[(y + h) % n])           c2[x] = b;         else           c2[x] = ++b;       }       swap(c, c2);       swap(p, p2);     }     return p;   }   struct stvar {     int a, b;     stvar(int x = 0) : a(x), b(min(0, x)) {}     stvar(int p, int q) : a(p), b(q) {}     stvar operator+(const stvar& o) const {       return stvar(a + o.a, min(b, a + o.b));     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     string s;     cin >> s;     int n = s.size();     vector<int> p = scs(s);     vector<stvar> pref(n + 1), suff(n + 1);     for (int i = 0; i < n; i++)       pref[i + 1] = pref[i] + stvar(s[i] ==  (  ? 1 : -1);     for (int i = n - 1; i >= 0; i--)       suff[i] = stvar(s[i] ==  (  ? 1 : -1) + suff[i + 1];     for (int j : p) {       auto t = suff[j] + pref[j];       if (t.a < 0) {         if (t.a == t.b) {           cout << string(-t.a,  ( ) << s.substr(j) << s.substr(0, j) <<   n ;           return 0;         }       } else {         if (t.b == 0) {           cout << s.substr(j) << s.substr(0, j) << string(t.a,  ) ) <<   n ;           return 0;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, tot;   bool ok(int i, int j) {     if (i < 0 or i >= n or j < 0 or j >= m) return 0;     return 1;   }   long long int c[20][20] = {0};   void matcpy(long long int a[20][20], long long int b[20][20]) {     for (int i = 0; i < tot; i++) {       for (int j = 0; j < tot; j++) {         a[i][j] = b[i][j];       }     }   }   void mul(long long int a[20][20], long long int b[20][20]) {     for (int i = 0; i < tot; i++) {       for (int j = 0; j < tot; j++) {         c[i][j] = 0;         for (int k = 0; k < tot; k++) {           c[i][j] += (a[i][k] * b[k][j]) % 1000000007;           c[i][j] %= 1000000007;         }       }     }     matcpy(a, c);   }   long long int id[20][20] = {0};   int cat[20][20] = {0};   void bpow(long long int a[20][20], int k) {     for (int i = 0; i < tot; i++) {       for (int j = 0; j < tot; j++) {         if (i == j)           id[i][j] = 1;         else           id[i][j] = 0;       }     }     while (k > 0) {       if (k & 1) mul(id, a);       mul(a, a);       k /= 2;     }     matcpy(a, id);   }   long long int mat[20][20] = {0};   long long int T[20][20] = {0};   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int q, x, y, t, tp;     cin >> n >> m >> q;     tot = n * m;     int prev = 1;     for (int i = 0; i < tot; i++) {       for (int j = 0; j < tot; j++) {         if (i == j)           mat[i][j] = 1;         else           mat[i][j] = 0;       }     }     while (q--) {       cin >> tp >> x >> y >> t;       x--;       y--;       for (int i1 = 0; i1 < n; i1++) {         for (int j1 = 0; j1 < m; j1++) {           for (int i2 = 0; i2 < n; i2++) {             for (int j2 = 0; j2 < m; j2++) {               if (!cat[i1][j1] and !cat[i2][j2] and                   abs(i1 - i2) + abs(j1 - j2) <= 1) {                 T[m * i1 + j1][m * i2 + j2] = 1;               } else {                 T[m * i1 + j1][m * i2 + j2] = 0;               }             }           }         }       }       bpow(T, t - prev);       prev = t;       mul(mat, T);       if (tp == 1) {         cout << mat[0][m * x + y] <<   n ;       } else if (tp == 2) {         cat[x][y] = 1;       } else {         cat[x][y] = 0;       }     }   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300050;   int a[maxn << 2];   int ll[maxn], rr[maxn], x[maxn], N, M;   void getdown(int cur) {     a[cur << 1] = a[cur];     a[(cur << 1) | 1] = a[cur];     a[cur] = 0;   }   void Insert(int cur, int L, int R, int l, int r, int u) {     int mid = (L + R) >> 1;     if (l <= L && R <= r) {       a[cur] = u;       return;     }     if (a[cur]) getdown(cur);     if (l <= mid) Insert(((cur) << 1), L, mid, l, r, u);     if (r > mid) Insert((((cur) << 1) | 1), (mid + 1), R, l, r, u);   }   int Query(int cur, int L, int R, int p) {     int mid = (L + R) >> 1;     if (a[cur]) return a[cur];     if (L == R) return a[cur];     if (p <= mid)       return Query(((cur) << 1), L, mid, p);     else       return Query((((cur) << 1) | 1), (mid + 1), R, p);   }   int main() {     scanf( %d%d , &N, &M);     for (int i = 1; i <= M; i++) {       scanf( %d%d%d , &ll[i], &rr[i], &x[i]);     }     for (int i = M; i >= 1; i--) {       if (ll[i] < x[i]) Insert(1, 1, N, ll[i], x[i] - 1, x[i]);       if (x[i] < rr[i]) Insert(1, 1, N, x[i] + 1, rr[i], x[i]);     }     printf( %d , Query(1, 1, N, 1));     for (int i = 2; i <= N; i++) printf(  %d , Query(1, 1, N, i));     printf(  n );     return 0;   }


#include <bits/stdc++.h>   int len, rest;   int space[10][110] = {0};   int num = 0;   int ans[21000][3] = {0};   void Check() {     for (int i = 1; i <= len; i++)       if (space[1][i] != 0 && space[1][i] == space[2][i]) {         num++;         rest--;         ans[num][0] = space[2][i];         ans[num][1] = 1;         ans[num][2] = i;         space[2][i] = 0;       }     for (int i = 1; i <= len; i++)       if (space[4][i] != 0 && space[3][i] == space[4][i]) {         num++;         rest--;         ans[num][0] = space[3][i];         ans[num][1] = 4;         ans[num][2] = i;         space[3][i] = 0;       }     return;   }   void Rotate() {     int px = 0, py = 0;     for (int k = 2; k <= 3 && !px; k++)       for (int i = 1; i <= len && !px; i++)         if (space[k][i] == 0) {           px = k;           py = i;         }     for (int time = 1; time < len * 2; time++) {       int nx, ny;       if (px == 2)         if (py < len) {           nx = 2;           ny = py + 1;         } else {           nx = 3;           ny = len;         }       else if (py > 1) {         nx = 3;         ny = py - 1;       } else {         nx = 2;         ny = 1;       }       if (space[nx][ny] != 0) {         num++;         ans[num][0] = space[nx][ny];         ans[num][1] = px;         ans[num][2] = py;         space[px][py] = space[nx][ny];         space[nx][ny] = 0;       }       px = nx;       py = ny;     }     return;   }   int main() {     int num_car;     scanf( %d%d , &len, &num_car);     rest = num_car;     for (int k = 1; k <= 4; k++)       for (int i = 1; i <= len; i++) scanf( %d , &space[k][i]);     Check();     if (rest == num_car && num_car == len * 2) {       printf( -1 n );       return 0;     }     while (rest) {       Rotate();       Check();     }     printf( %d n , num);     for (int i = 1; i <= num; i++)       printf( %d %d %d n , ans[i][0], ans[i][1], ans[i][2]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void enable_comma() {}   string tostring(char c) {     string s =   ;     s += c;     return s;   }   string tostring(string s) { return     + s +    ; }   string tostring(const char *c) { return tostring((string)c); }   string tostring(long long x) {     if (x < 0) return  -  + tostring(-x);     if (x > 9)       return tostring(x / 10) + tostring(char( 0  + x % 10));     else       return tostring(char( 0  + x));   }   string tostring(int x) { return tostring((long long)x); }   string tostring(unsigned long long x) {     if (x > 9)       return tostring((long long)(x / 10)) + tostring(char( 0  + x % 10));     else       return tostring(char( 0  + x));   }   string tostring(unsigned x) { return tostring((long long)x); }   string tostring(double x) {     static char res[114];     sprintf(res,  %lf , x);     string s = tostring(res);     return s.substr(1, (int)s.size() - 2);   }   string tostring(long double x) { return tostring((double)x); }   template <class A, class B>   string tostring(pair<A, B> p) {     return  (  + tostring(p.first) +  ,  + tostring(p.second) +  ) ;   }   template <class T>   string tostring(T v) {     string res =   ;     for (auto p : v) res += (res.size() ?  ,  :  { ) + tostring(p);     return res.size() ? res +  }  :  {} ;   }   template <class A>   string tostring(A *a, int L, int R) {     return tostring(vector<A>(a + L, a + R + 1));   };   template <class A>   string tostring(A a, int L, int R) {     return tostring(a.data(), L, R);   }   string tostrings() { return   ; }   template <typename Head, typename... Tail>   string tostrings(Head H, Tail... T) {     return tostring(H) +     + tostrings(T...);   }   long long read() {     long long x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f = ch ==  - , ch = getchar();     while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();     return f ? -x : x;   }   template <class T>   void ckmax(T &x, const T y) {     if (x < y) x = y;   }   template <class T>   void ckmin(T &x, const T y) {     if (x > y) x = y;   }   const int mod = 1e9 + 7;   int Pow(int x, long long y) {     y = (y % (mod - 1) + (mod - 1)) % (mod - 1);     int ans = 1;     for (; y; y >>= 1, x = (long long)x * x % mod)       if (y & 1) ans = (long long)ans * x % mod;     return ans;   }   void Add(int &x, int y) {     if ((x += y) >= mod) x -= mod;   }   void Del(int &x, int y) {     if ((x -= y) < 0) x += mod;   }   int Add(int x) { return x >= mod ? x - mod : x; }   int Del(int x) { return x < 0 ? x + mod : x; }   int md(long long x) { return (x % mod + mod) % mod; }   const int N = 1000005;   int n, m;   char s[N];   int a[N];   int id[10], cnt = 0;   vector<int> e[N];   int v10[N], l10[N], f[N];   vector<int> r[N];   int dd[N];   void solve() {     scanf( %s , s + 1);     n = strlen(s + 1);     m = read();     for (int i = (0); i <= (9); i++) id[i] = ++cnt;     for (int i = (1); i <= (n); i++) a[i] = id[s[i] -  0 ];     while (m--) {       scanf( %s , s + 1);       int len = strlen(s + 1);       int v = s[1] -  0 ;       int i = id[v];       id[v] = ++cnt;       for (int j = (4); j <= (len); j++) {         e[i].push_back(id[s[j] -  0 ]);         r[id[s[j] -  0 ]].push_back(i);         dd[i]++;       }     }     queue<int> Q;     for (int i = (1); i <= (cnt); i++)       if (!dd[i]) Q.push(i);     for (int i = (0); i <= (9); i++) {       f[id[i]] = 1;       v10[id[i]] = i;       l10[id[i]] = 10;     }     while (!Q.empty()) {       int i = Q.front();       Q.pop();       for (auto j : r[i])         if (!--dd[j]) Q.push(j);       if (f[i]) continue;       l10[i] = 1;       v10[i] = 0;       for (auto j : e[i]) {         v10[i] = ((long long)v10[i] * l10[j] + v10[j]) % mod;         l10[i] = (long long)l10[i] * l10[j] % mod;       }     }     enable_comma();     enable_comma();     enable_comma();     enable_comma();     enable_comma();     int ans = 0;     for (int i = (1); i <= (n); i++) {       ans = ((long long)ans * l10[a[i]] + v10[a[i]]) % mod;     }     cout << ans << endl;   }   int main() {     int T = 1;     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4002;   int n = 0, a;   char ch[N];   long long ans = 0, sum[N][N], all;   long long d[N * 9];   int val(int ind) { return ch[ind - 1] -  0 ; }   int main() {     cin >> a;     while (cin >> ch[n]) n++;     for (int i = 1; i <= n; ++i) {       for (int j = i; j <= n; ++j) {         sum[i][j] = val(j) + sum[1][j - 1] - sum[1][i - 1];         d[sum[i][j]]++;       }     }     for (int tt = 0; tt <= 4000 * 9; ++tt) all += d[tt];     for (int i = 1; i <= n; ++i) {       for (int j = i; j <= n; ++j) {         if (sum[i][j] == 0) {           if (a == 0) ans += all;           continue;         }         int cur = a / sum[i][j];         if (cur * sum[i][j] == a) {           if (cur >= 0 && cur <= 4000 * 9) ans += d[cur];         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int md = 998244853;   long long ans, f[4005][4005], x, y, n, m;   int main() {     cin >> n >> m;     for (int i = 0; i <= n + m; i++) f[i][0] = f[i][i] = 1;     for (int i = 0; i <= n + m; i++)       for (int j = 0; j < i; j++)         f[i][j] = (f[i - 1][j - 1] % md + f[i - 1][j] % md) % md;     for (int i = n; i && i >= n - m; i--) {       x = (f[n + m][n - i] - y + md) % md;       (ans += (x * i) % md) %= md;       (y += x) %= md;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_BUF_SIZE = 16384;   char BUFOR[MAX_BUF_SIZE];   int BUF_SIZE, BUF_POS;   char ZZZ;   const int MXN = 50010;   const int C = 262144;   const int INF = 1000000001;   int n, czas, skla;   vector<int> G[6 * MXN], GT[6 * MXN], H[6 * MXN], vert[6 * MXN];   vector<int> pre, skl, fu;   class SAT2 {     SAT2() {}     int neg(int v1) { return (v1 + n) % (2 * n); }     void addEdge(int v1, int v2) {       G[neg(v1)].push_back(v2);       GT[v2].push_back(neg(v1));       G[neg(v2)].push_back(v1);       GT[v1].push_back(neg(v2));     }     void dfs(int x) {       pre[x] = ++czas;       for (__typeof((G[x]).begin()) it = ((G[x]).begin()); it != (G[x]).end();            ++it)         if (!pre[*it]) dfs(*it);       fu.push_back(x);     }     void dfs2(int x) {       skl[x] = skla;       vert[skla].push_back(x);       for (__typeof((GT[x]).begin()) it = ((GT[x]).begin()); it != (GT[x]).end();            ++it)         if (!skl[*it]) dfs2(*it);     }     void dfs3(int x) {       pre[x] = 1;       for (__typeof((H[x]).begin()) it = ((H[x]).begin()); it != (H[x]).end();            ++it)         if (!pre[*it]) dfs3(*it);       fu.push_back(x);     }       public:     void clear() {       fu.clear();       pre.clear();       skl.clear();       for (int i = (0); i <= (2 * n); i++) {         G[i].clear();         GT[i].clear();         vert[i].clear();         H[i].clear();       }     }     SAT2(int _n) {       clear();       czas = 0;       skla = 0;       n = _n;       pre.resize(2 * n, 0);       skl.resize(2 * n, 0);     }     void add(int v1, bool pos1, int v2, bool pos2) {       addEdge((pos1 ? neg(v1) : v1), (pos2 ? neg(v2) : v2));     }     pair<bool, vector<bool> > solve() {       for (int i = (0); i <= (2 * n - 1); i++)         if (!pre[i]) dfs(i);       for (int i = ((int)(fu).size() - 1); i >= (0); i--) {         int w = fu[i];         if (!skl[w]) {           skla++;           dfs2(w);         }       }       skla++;       for (int i = (0); i <= (n - 1); i++)         if (skl[i] == skl[i + n]) return make_pair(false, vector<bool>());       for (int i = (0); i <= (2 * n - 1); i++) {         for (__typeof((G[i]).begin()) it = ((G[i]).begin()); it != (G[i]).end();              ++it)           H[skl[i]].push_back(skl[*it]);       }       fu.clear();       pre = vector<int>(skla, 0);       for (int i = (0); i <= (skla - 1); i++)         if (!pre[i]) dfs3(i);       vector<bool> res(2 * n, 0);       vector<int> tmp(skla + 1, -1);       for (int i = ((int)(fu).size() - 1); i >= (0); i--) {         int w = fu[i];         if (tmp[w] == -1) tmp[w] = 0;         if (tmp[w] == 1)           for (__typeof((H[w]).begin()) it = ((H[w]).begin()); it != (H[w]).end();                ++it)             tmp[*it] = 1;         for (__typeof((vert[w]).begin()) it = ((vert[w]).begin());              it != (vert[w]).end(); ++it) {           tmp[skl[neg(*it)]] = !tmp[w];           res[*it] = tmp[w];           res[neg(*it)] = !tmp[w];         }       }       return make_pair(true, res);     }   };   int n2, m;   vector<pair<int, pair<int, int> > > G2[MXN];   int c[MXN], t[MXN];   pair<bool, vector<bool> > check(int second) {     SAT2 SAT(3 * m);     for (int i = (0); i <= (m - 1); i++)       if (t[i] > second) SAT.add(i, 1, i, 1);     for (int i = (1); i <= (n2); i++) {       for (int j = (0); j <= ((int)(G2[i]).size() - 1); j++) {         int iter = j;         while (iter < (int)(G2[i]).size() && G2[i][j].first == G2[i][iter].first)           iter++;         if (iter - j > 2)           return make_pair(false, vector<bool>());         else if (iter - j == 2)           SAT.add(G2[i][j].second.second, 0, G2[i][j + 1].second.second, 0);         j = iter - 1;       }       int last = -1;       for (int j = (0); j <= ((int)(G2[i]).size() - 1); j++) {         int ei = G2[i][j].second.second;         int pi = ei;         if (i < G2[i][j].second.first)           pi += m;         else           pi += 2 * m;         SAT.add(pi, 1, ei, 1);         if (last != -1) {           SAT.add(ei, 1, last, 0);           SAT.add(pi, 1, last, 0);         }         last = pi;       }     }     return SAT.solve();   }   void test() {     scanf( %d %d , &n2, &m);     int mx = 0;     for (int i = (1); i <= (m); i++) {       int a, b;       scanf( %d %d %d %d , &a, &b, &c[i - 1], &t[i - 1]);       mx = max(mx, t[i - 1]);       G2[a].push_back(make_pair(c[i - 1], make_pair(b, i - 1)));       G2[b].push_back(make_pair(c[i - 1], make_pair(a, i - 1)));     }     for (int i = (1); i <= (n2); i++) sort((G2[i]).begin(), (G2[i]).end());     int res = INF;     int L = 0, R = mx;     vector<bool> ans;     while (L <= R) {       int second = (L + R) / 2;       pair<bool, vector<bool> > p1 = check(second);       if (p1.first) {         if (res > second) {           res = second;           ans = p1.second;         }         R = second - 1;       } else         L = second + 1;     }     if (res != INF) {       printf( Yes n );       int cnt = 0;       for (int i = (0); i <= (m - 1); i++)         if (ans[i]) cnt++;       printf( %d %d n , res, cnt);       for (int i = (0); i <= (m - 1); i++)         if (ans[i]) printf( %d  , i + 1);       printf(  n );     } else       printf( No n );   }   int main() {     int te = 1;     while (te--) test();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long a;     cin >> a;     vector<long long> x;     for (long long i = 0; i < a; i++) {       long long b;       cin >> b;       x.push_back(b);     }     bool done[101] = {false};     sort(x.begin(), x.end());     long long counter = 0;     long long ans = 0;     while (counter != a) {       long long num = 0;       for (long long i = 0; i < a; i++) {         if (x[i] >= num && !done[i]) {           num++;           counter++;           done[i] = true;         }       }       ans++;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ar[100001], csum[100001];   int main() {     ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);     int n, q;     cin >> n;     for (int i = 0; i < n; i++) cin >> ar[i];     for (int i = 1; i <= n; i++) {       csum[i] = csum[i - 1] + ar[i - 1];     }     cin >> q;     while (q--) {       int l, r;       cin >> l >> r;       cout << (csum[r] - csum[l - 1]) / 10 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int main() {     int n;     cin >> n;     cout << n / 2 - 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   long long a[N], b[N];   deque<int> mx, mn;   int main() {     long long n;     cin >> n;     long long i;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= n; i++) cin >> b[i];     long long j, ans = 0;     for (j = 1, i = 1; i <= n; i++) {       while (!mx.empty() and a[mx.back()] <= a[i]) mx.pop_back();       while (!mn.empty() and b[mn.back()] >= b[i]) mn.pop_back();       mx.push_back(i), mn.push_back(i);       while (j <= i and a[mx.front()] - b[mn.front()] > 0) {         j++;         while (!mx.empty() and mx.front() < j) mx.pop_front();         while (!mn.empty() and mn.front() < j) mn.pop_front();       }       if (!mx.empty() and !mn.empty() and a[mx.front()] == b[mn.front()])         ans += min(mx.front(), mn.front()) - j + 1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const double eps = 1e-8;   const int mod = 8 * 9 * 7 * 11 * 13 * 5;   const int maxn = 205;   const double pi = acos(-1.0);   const int INF = 0x7f7f7f7f;   const double inf = 1e50;   template <class T>   inline T minx(T a, T b) {     return (a == -1 || b < a) ? b : a;   }   template <class T>   inline T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <class T>   inline T lcm(T a, T b) {     return a * (b / gcd(a, b));   }   template <class T>   inline T getbit(T n) {     return n ? (1 + getbit(n & (n - 1))) : 0;   }   template <class T>   inline T lowbit(T n) {     return n & (-n);   }   using namespace std;   long long dp[mod + 2];   long long a, b, k, c, y = 0, l, i, t;   int main() {     cin >> a >> b >> k;     while (a > b) {       l = 1;       for (i = 2; i <= k; i++) {         t = a % i;         if ((t > l) && (a - t) >= b) l = t;       }       y++, a -= l;       if (dp[a % mod]) {         c = y - dp[a % mod];         y += c * ((a - b) / mod);         a -= ((a - b) / mod) * mod;       }       dp[a % mod] = y;     }     cout << y << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4786)   #pragma warning(disable : 4996)   using namespace std;   int c[200005], d[200005];   int main() {     int n;     scanf( %d , &n);     int val = 0;     int lb, ub;     lb = -1000000000;     ub = 1000000000;     for (int i = 1; i <= n; i++) {       scanf( %d %d , &c[i], &d[i]);       if (d[i] == 1) {         lb = ((lb) > (1900 - val) ? (lb) : (1900 - val));       } else {         ub = ((ub) < (1899 - val) ? (ub) : (1899 - val));       }       val += c[i];     }     if (lb > ub) {       printf( Impossible n );       return 0;     }     val = ub;     for (int i = 1; i <= n; i++) {       val += c[i];     }     if (val >= 100000000)       printf( Infinity n );     else       printf( %d n , val);     return 0;   }


#include <bits/stdc++.h>   int main() {     char a[1000005];     scanf( %s , a);     int i;     long long ans = 0, b = 0;     for (i = strlen(a) - 1; i >= 0; i--) {       if (a[i] ==  b )         b++;       else if (a[i] ==  a ) {         ans += b;         b <<= 1;       }       ans %= 1000000007;       b %= 1000000007;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string ff, ll;     cin >> ff >> ll;     string ans =   ;     ans += ff[0];     for (int i = 1; i < ff.length(); i++) {       if (ff[i] >= ll[0]) {         ans += ll[0];         break;       }       ans += ff[i];       if (i == ff.length() - 1) {         ans += ll[0];       }     }     if (ff.length() == 1) ans += ll[0];     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> a(n);     int psum = 0, msum = 0;     int zero = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > 0) psum += a[i];       if (a[i] < 0) msum += a[i];     }     if (psum > abs(msum)) {       puts( YES );       sort(a.begin(), a.end(), greater<int>());       for (int i = 0; i < n; i++) {         cout << a[i] <<    ;       }       cout <<   n ;     } else if (psum < abs(msum)) {       puts( YES );       sort(a.begin(), a.end());       for (int i = 0; i < n; i++) {         cout << a[i] <<    ;       }       cout <<   n ;     } else       puts( NO );   }   int main() {     int tc;     cin >> tc;     while (tc--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p;     scanf( %d %d , &n, &p);     int nums[n];     int sum = 0;     for (int i = 0; i < n; i++) {       cin >> nums[i];       nums[i] %= p;       sum += nums[i];       sum %= p;     }     int max_part = 0;     int left = 0;     int right = sum;     for (int i = 0; i < n; i++) {       left += nums[i];       left %= p;       right -= nums[i];       while (right < 0) {         right += p;       }       int part = left + right;       if (part > max_part) {         max_part = part;       }     }     cout << max_part;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   template <class T>   using vec = std::vector<T>;   template <class T>   using vec2d = std::vector<std::vector<T>>;   template <class T>   vec2d<T> makeVec2d(const int n1, const int n2, const T initValue) {     return vec2d<T>(n1, vec<T>(n2, initValue));   }   bool __hack = std::ios::sync_with_stdio(false);   auto __hack1 = cin.tie(nullptr);   struct Input {     Input(istream &in) : in(&in) {}     template <class T>     T next() const {       T x;       *in >> x;       return x;     }     int ni() const { return next<int>(); }     istream *in;   };   Input in(cin);   class Output {    private:     ostream *out;     template <typename T>     void printSingle(const T &value) {       *out << value;     }       public:     Output(ostream &out) : out(&out) {}     inline void print() {}     template <typename T, typename... Ts>     inline void print(const T &f, const Ts &...args) {       printSingle(f);       if (sizeof...(args) != 0) {         *out <<    ;         print(args...);       }     }     template <typename... Ts>     inline void println(const Ts &...args) {       print(args...);       *out <<   n ;     }     template <typename... Ts>     inline void operator()(const Ts &...args) {       println(args...);     }   };   Output out(cout);   namespace template_util {   constexpr int bytecount(uint64_t x) { return x ? 1 + bytecount(x >> 8) : 0; }   template <int N>   struct bytetype {};   template <uint64_t N>   struct minimal_uint : bytetype<bytecount(N)> {};   }  // namespace template_util   template <typename T>   static constexpr T wrap_pos(T a, T m) {     return a < 0 ? a + m : a;   }   template <typename T>   static constexpr T mod(T a, T m) {     return wrap_pos(a % m, m);   }   template <typename T>   static constexpr T inverse2(T a, T m) {     return a <= 1 ? a : mod((1 - inverse2(m % a, a) * m) / a, m);   }   template <typename T>   static constexpr T inverse(T a, T m) {     return inverse2(mod(a, m), m);   }   template <typename T, typename C, T Modulus>   class MR {    private:     struct tag_plus {};     struct tag_minus {};     struct tag_good {};     static_assert(std::numeric_limits<C>::max() / Modulus / Modulus > 0,                    compute type is too small );     static_assert(Modulus < std::numeric_limits<T>::max() / 2,                    storage type is too small );     static constexpr T reduce(T value, tag_plus) {       return value >= Modulus ? value - Modulus : value;     }     static constexpr T reduce(T value, tag_minus) {       return value < 0 ? value + Modulus : value;     }     static constexpr T reduce(T value, tag_good) { return value; }       public:     T value;     constexpr MR() : value(0) {}     constexpr MR(C value) : value(reduce(value % Modulus, tag_minus())) {}     template <typename tag_t>     constexpr MR(T value, tag_t tag) : value(reduce(value, tag)) {}     MR &operator=(C value) {       this->value = reduce(value % Modulus, tag_minus());       return *this;     }     constexpr MR operator*(MR b) const {       return MR(C(value) * C(b.value) % Modulus, tag_good());     }     MR &operator+=(MR b) {       value = reduce(value + b.value, tag_plus());       return *this;     }     constexpr T get() const { return value; }     constexpr MR inverse() const {       return MR(::inverse(C(value), C(Modulus)), tag_good());     }     constexpr MR operator/(MR b) const { return *this * b.inverse(); }   };   template <typename T, typename C, T Modulus>   static inline std::ostream &operator<<(std::ostream &o, MR<T, C, Modulus> mr) {     return o << mr.get();   }   template <class T>   vector<T> getFactorials(int n) {     vector<T> res(n);     res[0] = T(1);     for (int i = 1; i < n; ++i) {       res[i] = res[i - 1] * i;     }     return res;   }   template <class T>   inline T setBit(T mask, int bit) {     assert(0 <= bit && bit < numeric_limits<T>::digits);     return mask | ((T)(1) << bit);   }   template <class T>   inline bool getBit(T mask, int bit) {     assert(0 <= bit && bit < numeric_limits<T>::digits);     return mask & ((T)(1) << bit);   }   template <class T>   inline int bitCnt(T mask);   template <>   inline int bitCnt(int32_t mask) {     return __builtin_popcount(mask);   }   struct Component {     vec<int> vs;     vec2d<MR<int, int64_t, 998244353>> dp;     Component() {}   };   void solve(istream &inStream, ostream &outStream) {     in = Input(inStream);     out = Output(outStream);     auto n = in.ni();     auto m = in.ni();     vec2d<pair<int, int>> events(n + 2);     for (int i = 0; i < (n); ++i) {       auto x = in.ni();       auto y = in.ni() + 1;       events[x].push_back({1, i});       events[y].push_back({0, i});     }     vec2d<int> g(n);     set<pair<int, int>> edges;     for (int i = 0; i < (m); ++i) {       auto x = in.ni() - 1;       auto y = in.ni() - 1;       edges.insert({x, y});       edges.insert({y, x});       g[x].push_back(y);       g[y].push_back(x);     }     vec<int> u(n, 0);     vec<int> vs;     vec<Component> components;     function<void(int)> dfs = [&](int v) {       u[v] = true;       vs.push_back(v);       for (auto to : g[v]) {         if (!u[to]) {           dfs(to);         }       }     };     for (int i = 0; i < (n); ++i) {       if (u[i]) continue;       if (g[i].empty()) {         continue;       }       vs.clear();       dfs(i);       Component cc;       cc.vs = vs;       int cn = (int)vs.size();       cc.dp = makeVec2d<MR<int, int64_t, 998244353>>(1 << cn, cn + 1, 0);       for (int mask = 0; mask < (1 << cn); ++mask) {         bool good = true;         for (int b1 = 0; b1 < (cn); ++b1) {           if (getBit(mask, b1)) {             for (int b2 = 0; b2 < (b1); ++b2) {               if (getBit(mask, b2)) {                 if (edges.find({cc.vs[b1], cc.vs[b2]}) != edges.end()) {                   good = false;                   break;                 }               }             }             if (!good) break;           }         }         if (good) {           cc.dp[mask][bitCnt(mask)] = 1;         }       };       ;       for (int j = 0; j < (cn); ++j) {         for (int b = 0; b < (cn); ++b) {           for (int mask = 0; mask < (1 << cn); ++mask) {             if (!getBit(mask, b)) {               cc.dp[setBit(mask, b)][j] += cc.dp[mask][j];             }           }         }       }       components.push_back(cc);     }     auto fs = getFactorials<MR<int, int64_t, 998244353>>(n + 1);     auto rfs = fs;     for (int i = 0; i < (rfs.size()); ++i) {       rfs[i] = MR<int, int64_t, 998244353>(1) / rfs[i];     }     auto C = [&](int n, int k) -> MR<int, int64_t, 998244353> {       return fs[n] * rfs[k] * rfs[n - k];     };     unordered_set<int> presentIds;     presentIds.reserve(1 << 16);     presentIds.max_load_factor(0.25);     MR<int, int64_t, 998244353> res = 0;     for (int i = (1); i < (n + 1); ++i) {       for (const auto &e : events[i]) {         if (e.first == 0) {           presentIds.erase(e.second);         } else {           presentIds.insert(e.second);         }       }       vec<MR<int, int64_t, 998244353>> dp(2 * m + 1, 0);       dp[0] = 1;       int inC = 0;       for (const auto &c : components) {         int mask = 0;         for (int i = 0; i < c.vs.size(); ++i) {           if (presentIds.find(c.vs[i]) != presentIds.end()) {             mask = setBit(mask, i);           }         }         inC += bitCnt(mask);         for (int j = (int)dp.size() - 1; j >= 0; --j) {           for (int add = (1); add < (c.vs.size() + 1); ++add) {             if (j + add < dp.size()) {               dp[j + add] += dp[j] * c.dp[mask][add];             }           }         }       }       for (int j = 0; j < (dp.size()); ++j) {         if (presentIds.size() - inC >= i - j && i - j >= 0) {           res += dp[j] * C(presentIds.size() - inC, i - j);         }       }     }     out(res);   }   int main() {     solve(cin, cout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const long long N = 2e5 + 1;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     vector<long long> nums(n);     for (long long i = 0; i < n; i++) {       long long k;       cin >> k;       nums[i] = abs(k);     }     sort(nums.begin(), nums.end());     long long ans = 0;     for (long long i = 0; i < n; i++) {       long long cur = nums[i];       long long ub = cur * 2;       if (ub == 0) {         continue;       }       long long low = i + 1;       long long high = n - 1;       long long pos = -1;       while (low <= high) {         long long mid = low + (high - low) / 2;         if (nums[mid] <= ub) {           pos = mid;           low = mid + 1;         } else {           high = mid - 1;         }       }       if (pos != -1) {         ans += (pos - i);       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   class point {    public:     int x, y;     point(int _x, int _y) {       x = _x;       y = _y;     }     string str() {       stringstream ss;       ss <<  (  << x <<  ,   << y <<  ) ;       return ss.str();     }   };   int main() {     int n;     cin >> n;     point min = point(31400, 31400), max = point(0, 0);     int used_area = 0;     for (int i = 0; i < n; i++) {       int x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       point p1 = point(x1, y1), p2 = point(x2, y2);       if (x1 < min.x) min.x = x1;       if (y1 < min.y) min.y = y1;       if (x2 > max.x) max.x = x2;       if (y2 > max.y) max.y = y2;       used_area += (x2 - x1) * (y2 - y1);     }     int total_area = (max.x - min.x) * (max.y - min.y);     if (used_area == total_area && (max.x - min.x) == (max.y - min.y))       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long long mx, sm, idx;     node() {       mx = 0;       sm = 0;       idx = 0;     }   };   struct segTree {     long long n;     vector<node> st;     segTree(long long n) {       this->n = n;       st.resize(4 * n + 5);     }     void combine(long long pos, long long lc, long long rc) {       st[pos].sm = st[lc].sm + st[rc].sm;       if (st[lc].mx >= st[rc].mx)         st[pos].mx = st[lc].mx, st[pos].idx = st[lc].idx;       else         st[pos].mx = st[rc].mx, st[pos].idx = st[rc].idx;     }     void _build(long long l, long long r, long long pos, long long *arr) {       if (l == r) {         st[pos].mx = arr[l];         st[pos].sm = arr[l];         st[pos].idx = l;         return;       }       long long lc = pos << 1, rc = lc ^ 1, mid = (l + r) >> 1;       _build(l, mid, lc, arr);       _build(mid + 1, r, rc, arr);       combine(pos, lc, rc);     }     void _upd(long long id, long long val, long long l, long long r,               long long pos) {       if (l == r) {         st[pos].mx = val;         st[pos].sm = val;         st[pos].idx = l;         return;       }       long long lc = pos << 1, rc = lc ^ 1, mid = (l + r) >> 1;       if (id <= mid)         _upd(id, val, l, mid, lc);       else         _upd(id, val, mid + 1, r, rc);       combine(pos, lc, rc);     }     pair<long long, long long> _qrymax(long long ql, long long qr, long long l,                                        long long r, long long pos) {       if (qr < l || ql > r)         return make_pair(-LONG_LONG_MAX, -1);       else if (ql <= l && qr >= r)         return make_pair(st[pos].mx, st[pos].idx);       long long lc = pos << 1, rc = lc ^ 1, mid = (l + r) >> 1;       pair<long long, long long> lef = _qrymax(ql, qr, l, mid, lc),                                  rig = _qrymax(ql, qr, mid + 1, r, rc);       if (lef.first >= rig.first) return lef;       return rig;     }     long long _qrysm(long long ql, long long qr, long long l, long long r,                      long long pos) {       if (qr < l || ql > r)         return 0;       else if (ql <= l && qr >= r)         return st[pos].sm;       long long lc = pos << 1, rc = lc ^ 1, mid = (l + r) >> 1;       return _qrysm(ql, qr, l, mid, lc) + _qrysm(ql, qr, mid + 1, r, rc);     }     pair<long long, long long> qry_max(long long ql, long long qr) {       return _qrymax(ql, qr, 1, n, 1);     }     void upd(long long idx, long long val) { _upd(idx, val, 1, n, 1); }     long long qry_sum(long long ql, long long qr) {       return _qrysm(ql, qr, 1, n, 1);     }     void build(long long *arr) { _build(1, n, 1, arr); }   };   const long long N = 1e5 + 5;   long long n, m, a[N];   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     segTree S(n);     S.build(a);     while (m--) {       long long type;       cin >> type;       if (type == 1) {         long long l, r;         cin >> l >> r;         cout << S.qry_sum(l, r) <<   n ;       } else if (type == 2) {         long long l, r, x;         cin >> l >> r >> x;         pair<long long, long long> pp = S.qry_max(l, r);         while (pp.first >= x) {           long long newval = pp.first % x, idx = pp.second;           S.upd(idx, newval);           pp = S.qry_max(l, r);         }       } else {         long long idx, val;         cin >> idx >> val;         S.upd(idx, val);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 6e6 + 500;   int pt[N << 1], tn, m;   pair<int, pair<int, int> > seg1[N], seg2[N];   int n1, n2;   int getdep(const pair<int, int> &u) { return u.first + u.second; }   int lowbit(const int &x) {     if (!x) return 1 << 30;     return x & -x;   }   pair<int, int> getfa(const pair<int, int> &u) {     if (!u.first || !u.second) return make_pair(0, 0);     return lowbit(u.first) < lowbit(u.second) ? make_pair(u.first - 1, u.second)                                               : make_pair(u.first, u.second - 1);   }   pair<int, int> gettop(const pair<int, int> &u) {     if (!u.first || !u.second) return make_pair((u.first != 0), (u.second != 0));     if (lowbit(u.first) < lowbit(u.second)) {       return make_pair(1 + (u.first & (~(lowbit(u.second) - 1))), u.second);     } else {       return make_pair(u.first, 1 + (u.second & (~(lowbit(u.first) - 1))));     }   }   void ins(pair<int, int> u, pair<int, int> v) {     pair<int, int> tpu, tpv;     while ((tpu = gettop(u)) != (tpv = gettop(v))) {       if (getdep(tpu) > getdep(tpv)) {         if (lowbit(u.second) < lowbit(u.first))           seg1[++n1] = make_pair(u.first, make_pair(tpu.second, u.second));         else           seg2[++n2] = make_pair(u.second, make_pair(tpu.first, u.first));         u = getfa(tpu);       } else {         if (lowbit(v.second) < lowbit(v.first))           seg1[++n1] = make_pair(v.first, make_pair(tpv.second, v.second));         else           seg2[++n2] = make_pair(v.second, make_pair(tpv.first, v.first));         v = getfa(tpv);       }     }     if (getdep(u) > getdep(v)) swap(u, v);     if (lowbit(u.second) < lowbit(u.first))       seg1[++n1] = make_pair(u.first, make_pair(u.second, v.second));     else       seg2[++n2] = make_pair(u.second, make_pair(u.first, v.first));   }   int main() {     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       pair<int, int> u, v;       scanf( %d%d%d%d , &u.first, &u.second, &v.first, &v.second);       ins(u, v);     }     sort(seg1 + 1, seg1 + n1 + 1), sort(seg2 + 1, seg2 + n2 + 1);     for (int i = 1, j; i <= n1; i = j + 1) {       j = i;       while (j + 1 <= n1 && seg1[j + 1].first == seg1[j].first) ++j;       int l = seg1[i].second.first, r = seg1[i].second.second;       for (int k = i + 1; k <= j; k++) {         int tl = seg1[k].second.first, tr = seg1[k].second.second;         if (tl <= r + 1)           r = max(r, tr);         else           pt[++tn] = l + seg1[i].first, pt[++tn] = r + seg1[i].first + 1, l = tl,           r = tr;       }       pt[++tn] = l + seg1[i].first, pt[++tn] = r + seg1[i].first + 1;     }     for (int i = 1, j; i <= n2; i = j + 1) {       j = i;       while (j + 1 <= n2 && seg2[j + 1].first == seg2[j].first) ++j;       int l = seg2[i].second.first, r = seg2[i].second.second;       for (int k = i + 1; k <= j; k++) {         int tl = seg2[k].second.first, tr = seg2[k].second.second;         if (tl <= r + 1)           r = max(r, tr);         else           pt[++tn] = l + seg2[i].first, pt[++tn] = r + seg2[i].first + 1, l = tl,           r = tr;       }       pt[++tn] = l + seg2[i].first, pt[++tn] = r + seg2[i].first + 1;     }     sort(pt + 1, pt + tn + 1);     int ans = 0;     for (int i = 1, j; i <= tn; i = j + 1) {       j = i;       if (!pt[i]) continue;       while (j + 1 <= tn && pt[j + 1] == pt[i]) ++j;       if (((j - i + 1) & 1)) ++ans;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000000 + 7;   const long long int N = 10000000 + 6;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m, k;     cin >> n >> m >> k;     int ind[k + 1];     int arr[k];     for (int i = 0; i < k; i++) {       cin >> arr[i];       ind[arr[i]] = i + 1;     }     long long int ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int v;         cin >> v;         ans = ans + ind[v];         int temp = ind[v];         for (int l = 1; l <= k; l++) {           if (ind[l] < temp) ind[l]++;         }         ind[v] = 1;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> graf[300007];   struct zap {     long long zmiana;     long long gle;   };   vector<zap> z[300007];   int ojc[300007];   long long liczba[300007];   map<long long, long long> zmiany;   void licz(int poz, int pop, long long zmiana, long long gl) {     for (int i = 0; i < z[poz].size(); i++) {       zmiana += z[poz][i].zmiana;       zmiany[gl + z[poz][i].gle] += z[poz][i].zmiana;     }     liczba[poz] = zmiana;     zmiana -= zmiany[gl];     for (int i = 0; i < graf[poz].size(); i++) {       if (graf[poz][i] != pop) {         licz(graf[poz][i], poz, zmiana, gl + 1);       }     }     for (int i = 0; i < z[poz].size(); i++) {       zmiany[gl + z[poz][i].gle] -= z[poz][i].zmiana;     }   }   int main() {     ios_base::sync_with_stdio(0);     int n, m;     cin >> n;     int a, b;     for (int i = 1; i < n; i++) {       cin >> a >> b;       graf[a].push_back(b);       graf[b].push_back(a);     }     cin >> m;     for (int i = 0; i < m; i++) {       cin >> a;       long long dl, ile;       cin >> dl >> ile;       zap x;       x.zmiana = ile;       x.gle = dl;       z[a].push_back(x);     }     licz(1, -1, 0, 0);     for (int i = 1; i <= n; i++) cout << liczba[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x;     cin >> x;     int j;     for (j = 1; (j * j + 1) < 2 * x; j = j + 2)       ;     if (x == 3) j = 5;     cout << j << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s[1000];     scanf( %d , &n);     for (int i = 0; i < n; i++) {       cin >> s[i];     }     char ch = s[0][0];     int flg = 0, cnc = 0, cnch = 0;     char c = s[0][1];     if (c == ch) flg = 1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (s[i][j] == c) {           cnc++;         } else if (s[i][j] == ch) {           cnch++;         } else           flg = 1;       }     }     if (cnch != 2 * n - 1)       flg = 1;     else if (n * n - cnch != cnc)       flg = 1;     for (int j = 0, i = 0; i < n / 2; i++) {       if (s[i][i] == s[i][n - i - 1] && ch == s[i][i]) {       } else         flg = 1;     }     if (s[n / 2][n / 2] != ch) flg = 1;     for (int j = 0, i = n - 1; i > n / 2; j++, i--) {       if (s[i][j] == s[i][n - 1 - j] && ch == s[i][j]) {       } else         flg = 1;     }     if (flg)       cout <<  NO  << endl;     else       cout <<  YES  << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long t = 1, tt;   void solve() {     long long n;     cin >> n;     string a, b;     cin >> a >> b;     if (n == 1) {       if (a == b)         cout << 0;       else         cout << 1;       return;     }     long long ans = 0;     for (long long i = 0; i < n / 2; i += 1) {       set<char> ss;       map<char, long long> mapa;       ss.insert(a[i]);       mapa[a[i]]++;       ss.insert(a[n - i - 1]);       mapa[a[n - i - 1]]++;       ss.insert(b[i]);       mapa[b[i]]++;       ss.insert(b[n - i - 1]);       mapa[b[n - i - 1]]++;       if (int((ss).size()) == 4) ans += 2;       if (int((ss).size()) == 3) {         if (a[i] == a[n - i - 1])           ans += 2;         else           ans += 1;       }       if (int((ss).size()) == 2) {         if (mapa[a[i]] == 1 || mapa[a[i]] == 3) ans += 1;       }     }     if (n % 2 == 1) {       if (a[n / 2] != b[n / 2]) ans += 1;     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     tt = t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100100;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int tree[N << 2];   void pushup(int ind) { tree[ind] = gcd(tree[ind << 1], tree[ind << 1 | 1]); }   int a[N];   void build(int ind, int ll, int rr) {     if (ll == rr) {       tree[ind] = a[ll];       return;     }     int mid = (ll + rr) >> 1;     build(((ind) << 1), ll, mid);     build(((ind) << 1 | 1), mid + 1, rr);     pushup(ind);   }   int query(int ind, int ll, int rr, int l, int r) {     if (ll == l && rr == r) {       return tree[ind];     }     int mid = (ll + rr) >> 1;     if (r <= mid) {       return query(((ind) << 1), ll, mid, l, r);     } else if (l > mid) {       return query(((ind) << 1 | 1), mid + 1, rr, l, r);     } else {       int a = query(((ind) << 1), ll, mid, l, mid);       int b = query(((ind) << 1 | 1), mid + 1, rr, mid + 1, r);       return gcd(a, b);     }   }   pair<int, int> re[N];   int t[N], w[N], cnt;   struct PBT {     int ls[N * 20], rs[N * 20], c[N * 20], tree[N * 20];     int idx, mx;     int build(int l, int r) {       int rt = idx++;       c[rt] = 0;       if (l != r) {         int mid = (l + r) >> 1;         ls[rt] = build(l, mid);         rs[rt] = build(mid + 1, r);       }       return rt;     }     int update(int rt, int pos, int val) {       int nrt = idx++, ret = nrt;       c[nrt] = c[rt] + val;       int l = 1, r = mx;       while (l != r) {         int mid = (l + r) >> 1;         if (pos <= mid) {           ls[nrt] = idx++;           rs[nrt] = rs[rt];           nrt = ls[nrt];           rt = ls[rt];           r = mid;         } else {           rs[nrt] = idx++;           ls[nrt] = ls[rt];           nrt = rs[nrt];           rt = rs[rt];           l = mid + 1;         }         c[nrt] = c[rt] + val;       }       return ret;     }     int query(int lrt, int rrt, int pos) {       int l = 1, r = mx;       while (l != r) {         int mid = (l + r) >> 1;         if (pos <= mid) {           lrt = ls[lrt];           rrt = ls[rrt];           r = mid;         } else {           lrt = rs[lrt];           rrt = rs[rrt];           l = mid + 1;         }       }       return c[rrt] - c[lrt];     }   } pbt;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     build(1, 1, n);     int q;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       scanf( %d%d , &re[i].first, &re[i].second);       t[++cnt] = query(1, 1, n, re[i].first, re[i].second);       w[i] = t[cnt];     }     sort(t + 1, t + cnt + 1);     cnt = unique(t + 1, t + cnt + 1) - t - 1;     map<int, int> idx;     for (int i = 1; i <= cnt; i++) {       idx[t[i]] = i;     }     pbt.mx = cnt;     pbt.tree[0] = pbt.build(1, cnt);     for (int i = 1; i <= n; i++) {       if (idx.count(a[i])) {         int x = idx[a[i]];         pbt.tree[i] = pbt.update(pbt.tree[i - 1], x, 1);       } else {         pbt.tree[i] = pbt.tree[i - 1];       }     }     for (int i = 0; i < q; i++) {       int x = re[i].first, y = re[i].second;       int ret = pbt.query(pbt.tree[x - 1], pbt.tree[y], idx[w[i]]);       printf( %d n , re[i].second - re[i].first + 1 - ret);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int gi() {     int data = 0, fu = 1;     char ch = 0;     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) fu = -1, ch = getchar();     while ( 0  <= ch && ch <=  9 )       data = (data << 1) + (data << 3) + (ch ^ 48), ch = getchar();     return data * fu;   }   int n, nq, q[200005];   map<long long, long long> M;   struct Node {     long long x, y;   } p[200005];   const long double eps = 1e-8;   inline long double Slope(int i, int j) {     return (long double)(p[i].y - p[j].y) / (long double)(p[i].x - p[j].x);   }   inline bool cmp(Node a, Node b) { return a.x ^ b.x ? a.x < b.x : a.y < b.y; }   int main() {     n = gi();     for (long long i = 1, x, y; i <= n; ++i) {       x = gi(), y = gi();       y -= x * x;       if (M.find(x) == M.end()) M[x] = -1e18;       M[x] = max(M[x], y);     }     n = 0;     for (map<long long, long long>::iterator it = M.begin(); it != M.end();          it++) {       long long X = it->first, Y = it->second;       long long i;       p[i = ++n].x = X, p[i].y = Y;     }     sort(p + 1, p + n + 1, cmp);     nq = 0;     for (long long i = 1; i <= n; ++i) {       while (nq >= 2 &&              Slope(q[nq - 1], q[nq]) - eps <= Slope(q[nq - 1], i) + eps)         --nq;       q[++nq] = i;     }     cout << nq - 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e+6 + 5;   long long big = 1e+18 + 3;   long long mod = 1e+9 + 7;   long long freq[26] = {0}, vis[N];   long long maxv = -1;   long long sz = 0;   void dfs(string &s, vector<vector<long long>> &gr, long long ind) {     vis[ind] = 1;     sz++;     freq[s[ind] - (long long) a ]++;     for (auto it : gr[ind])       if (!vis[it]) dfs(s, gr, it);   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n;       long long k;       cin >> n >> k;       string s;       for (long long i = 0; i <= n; i++) vis[i] = 0;       vector<vector<long long>> gr(n + 1);       long long moves = 0;       cin >> s;       for (long long i = 0; i <= n - 1; i++) {         if (i + k < n) gr[i].push_back(i + k), gr[i + k].push_back(i);         if (i - k >= 0) gr[i].push_back(i - k), gr[i - k].push_back(i);         gr[i].push_back(n - i - 1);         gr[n - i - 1].push_back(i);       }       for (long long i = 0; i <= n - 1; i++) {         if (vis[i]) continue;         dfs(s, gr, i);         for (long long x = 0; x <= 25; x++) maxv = max(maxv, freq[x]);         moves += (sz - maxv);         for (long long x = 0; x <= 25; x++) freq[x] = 0;         maxv = -1;         sz = 0;       }       cout << moves <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 30;   int Par[N], cnt_S, cnt_M, ok = 1, n, m;   struct Edge {     int v, u;     char col;     bool mark;   } E[N];   int Find(int x) { return (Par[x] == x ? x : Par[x] = Find(Par[x])); }   bool Union(int e) {     int x = Find(E[e].v), y = Find(E[e].u);     if (x == y) return 0;     Par[x] = y;     return 1;   }   int main() {     cin >> n >> m;     if ((n - 1) & 1) ok = 0;     for (int i = 0; i < m; i++) cin >> E[i].v >> E[i].u >> E[i].col;     for (int i = 0; i < N; i++) Par[i] = i;     for (int i = 0; i < m; i++)       if (E[i].col ==  M ) Union(i);     for (int i = 0; i < m; i++)       if (E[i].col ==  S  && Union(i)) E[i].mark = true, cnt_S++;     for (int i = 0; i < N; i++) Par[i] = i;     for (int i = 0; i < m; i++)       if (E[i].mark) Union(i);     for (int i = 0; i < m; i++)       if (cnt_S != (n - 1) >> 1 && E[i].col ==  S  && Union(i))         E[i].mark = true, cnt_S++;     for (int i = 0; i < m; i++)       if (E[i].col ==  M  && Union(i)) E[i].mark = true, cnt_M++;     if (cnt_S != (n - 1) >> 1 || cnt_M != (n - 1) >> 1 || !ok)       return cout <<  -1 n , 0;     cout << n - 1 <<   n ;     for (int i = 0; i < m; i++)       if (E[i].mark) cout << i + 1 <<    ;     return (0);   }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long INF = 1000 * 1000 * 1000;   const double eps = 1e-9;   int main() {     string s;     cin >> s;     int pos = 0;     for (char c =  z ; c >=  a ; c--) {       int tek = pos;       for (int i = tek; i < s.size(); i++)         if (s[i] == c) {           cout << s[i];           pos = i;         }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void addEdge(vector<long long> adj[], long long u, long long v) {     adj[u].push_back(v);     adj[v].push_back(u);   }   void DFSUtil(vector<long long> adj[], long long v, bool visited[]) {     visited[v] = true;     for (long long i = 0; i < adj[v].size(); ++i)       if (!visited[adj[v][i]]) DFSUtil(adj, adj[v][i], visited);   }   long long f1(vector<long long> adj[], long long n) {     bool* visited = new bool[n];     long long count = 0;     for (long long v = 0; v < n; v++) visited[v] = false;     for (long long v = 0; v < n; v++) {       if (visited[v] == false) {         DFSUtil(adj, v, visited);         count += 1;       }     }     return count;   }   bool isCyclicUtil(vector<long long> adj[], long long v, bool visited[],                     long long parent) {     bool flag = false;     visited[v] = true;     for (long long i = 0; i < adj[v].size(); ++i) {       if (!visited[adj[v][i]]) {         if (isCyclicUtil(adj, adj[v][i], visited, v)) flag = true;       } else if (adj[v][i] != parent)         flag = true;     }     return flag;   }   long long isCyclic(vector<long long> adj[], long long n) {     bool* visited = new bool[n];     for (long long i = 0; i < n; i++) visited[i] = false;     long long ans = 0;     for (long long u = 0; u < n; u++) {       if (!visited[u]) {         if (isCyclicUtil(adj, u, visited, -1)) {           ans++;         }       }     }     return ans;   }   void solve() {     long long n, m;     cin >> n >> m;     vector<long long> adj[n];     for (long long i = 0; i < m; i++) {       long long x, y;       cin >> x >> y;       x--;       y--;       adj[x].push_back(y);       adj[y].push_back(x);     }     long long x = f1(adj, n);     long long y = isCyclic(adj, n);     cout << x - y << endl;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, vector<int>> pos;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       int n;       cin >> n;       vector<int> a(n), b(n);       for (int i = 0; i < n; i++) {         cin >> a[i];       }       for (int i = 0; i < n; i++) {         cin >> b[i];       }       pos.clear();       for (int i = n - 1; i >= 0; i--) {         pos[a[i]].push_back(i);       }       vector<int> tree(4 * n);       function<void(int, int, int)> build = [&](int v, int l, int r) {         if (l + 1 == r) {           tree[v] = a[l];           return;         }         int mid = (l + r) / 2;         build(2 * v, l, mid);         build(2 * v + 1, mid, r);         tree[v] = min(tree[2 * v], tree[2 * v + 1]);       };       function<int(int, int, int, int, int)> query_min =           [&](int ql, int qr, int v, int l, int r) {             if (ql <= l && r <= qr) return tree[v];             if (r <= ql || qr <= l) return int(1e6);             int mid = (l + r) / 2;             return min(query_min(ql, qr, 2 * v, l, mid),                        query_min(ql, qr, 2 * v + 1, mid, r));           };       function<void(int, int, int, int)> update = [&](int x, int v, int l,                                                       int r) {         if (l == x && r == l + 1) {           tree[v] = int(1e6);           return;         }         int mid = (l + r) / 2;         if (x < mid)           update(x, 2 * v, l, mid);         else           update(x, 2 * v + 1, mid, r);         tree[v] = min(tree[2 * v], tree[2 * v + 1]);       };       bool ok = true;       build(1, 0, n);       for (int i = 0; i < n; i++) {         if (pos[b[i]].size() == 0) {           ok = false;           break;         }         int x = pos[b[i]].back();         pos[b[i]].pop_back();         if (query_min(0, x + 1, 1, 0, n) != b[i]) {           ok = false;           break;         }         update(x, 1, 0, n);       }       if (ok)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxtop = 1025;   const int maxn = 100010;   const int mo = 1000000007;   int top;   int repeat[maxtop + 1];   int rest;   int a[maxn + 1];   int n, K;   int C[maxn + 1];   int f[2][maxtop + 1], old, now;   long long result;   void init() {     int i;     scanf( %d%d , &n, &K);     for (i = 1; i <= n; ++i) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);   }   bool lucky(int x) {     int t;     while (x) {       t = x % 10;       if ((t != 4) && (t != 7)) return false;       x /= 10;     }     return true;   }   void calc_repeat() {     int i, j;     top = rest = 0;     i = 1;     while (i <= n) {       if (lucky(a[i])) {         j = i;         while ((j + 1 <= n) && (a[j + 1] == a[i])) ++j;         repeat[++top] = j - i + 1;         i = j + 1;       } else {         ++rest;         ++i;       }     }   }   int power(int x, int y) {     long long a, b;     b = x;     a = 1;     while (y) {       if (y & 1) a = (a * b) % mo;       b = (b * b) % mo;       y = (y >> 1);     }     return a;   }   void calc_C() {     int i;     long long tmp;     C[0] = 1;     if (rest == 0) return;     C[1] = rest;     for (i = 2; i <= rest; ++i) {       tmp = C[i - 1];       tmp = (tmp * (rest - i + 1)) % mo;       tmp = (tmp * power(i, mo - 2)) % mo;       C[i] = tmp;     }   }   void calc_result() {     int i, j, k;     long long tmp;     now = 0;     for (i = 1; i <= top; ++i) f[now][i] = 0;     f[now][0] = 1;     for (i = 1; i <= top; ++i) {       old = now;       now = 1 - now;       f[now][0] = 1;       for (j = 1; j <= i; ++j) {         if (j > K) break;         f[now][j] = 0;         if (j < i) f[now][j] += f[old][j];         tmp = f[old][j - 1];         tmp = (tmp * repeat[i]) % mo;         f[now][j] = (f[now][j] + tmp) % mo;       }     }     result = 0;     for (i = 0; i <= top; ++i) {       if (i > K) break;       if (K - i > rest) continue;       tmp = f[now][i];       tmp = (tmp * C[K - i]) % mo;       result += tmp;       if (result >= mo) result -= mo;     }   }   void work() {     calc_repeat();     calc_C();     calc_result();   }   void output() { printf( %d n , result); }   int main() {     init();     work();     output();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   long long res, rem;   long long narr[100001];   long long tempint;   int main() {     scanf( %I64d , &n);     for (int i = 0; i < n; ++i) scanf( %I64d , narr + i);     sort(narr, narr + n);     reverse(narr, narr + n);     for (int i = 0; i < n; ++i) res += narr[i];     tempint = n - 1;     for (int i = 0; i < n; ++i, tempint -= 2) res += 2 * narr[i] * (tempint);     long long ores = res, on = n;     while (1) {       rem = ores % on;       if (rem == 0) {         break;       }       ores = on;       on = rem;     }     printf( %I64d %I64d , res / on, n / on);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1005;   char mp[MAXN][MAXN];   int ansmp[MAXN][MAXN];   int dire[4][2] = {0, -1, 0, 1, -1, 0, 1, 0};   int n, m;   void fillansmap(int x0, int y0, int x1, int y1) {     bool colorflag[5];     int dx = (x1 - x0 > 0);     int dy = (y1 - y0 > 0);     int dcolor;     for (int i = 1; i <= 4; i++) colorflag[i] = true;     for (int x = x0, y = y0; x <= x1 && y <= y1; x += dx, y += dy) {       for (int i = 0; i < 4; i++) {         int xx = x + dire[i][0];         int yy = y + dire[i][1];         if (0 <= xx && xx < n && 0 <= yy && yy < m)           colorflag[ansmp[xx][yy]] = false;       }     }     for (int i = 1; i <= 4; i++)       if (colorflag[i]) {         dcolor = i;         break;       }     for (int x = x0, y = y0; x <= x1 && y <= y1; x += dx, y += dy)       ansmp[x][y] = dcolor, mp[x][y] =  . ;     return;   }   bool CheckMap() {     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (mp[i][j] !=  . ) return false;     return true;   }   int main() {     bool ansflag = true;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , mp[i]);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (mp[i][j] ==  b ) {           if (i > 0 && mp[i - 1][j] ==  w  && i < n - 1 && mp[i + 1][j] ==  w )             fillansmap(i - 1, j, i + 1, j);           else if (j > 0 && mp[i][j - 1] ==  w  && j < m - 1 &&                    mp[i][j + 1] ==  w )             fillansmap(i, j - 1, i, j + 1);         }     if (CheckMap()) {       printf( YES n );       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++)           if (ansmp[i][j] == 0)             printf( . );           else             printf( %c , ansmp[i][j] - 1 +  a );         printf(  n );       }     } else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const int INF = 2e9 + 9;   const long long INF1 = 1e18 + 9;   const long long MAXN = 4e5 + 7;   const long long MAXN1 = 1 << 11;   const long long MAXN2 = 4e6 + 9;   const long long MOD = 1e9 + 7;   const long long MOD1 = 1e9 + 9;   const long long ALPH = 50;   const long long PW1 = 239;   const long long PW2 = 199;   const long long PW3 = 193;   const long long PW4 = 117;   const long double EPS = 1e-9;   const long long BLOCK = 3684;   const long long BLOCK1 = 1 << 9;   void solve();   signed main() {     srand( a  +  l  +  e  +  x  +  X  +  5  +  1  +  2 );     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int q = 1;     if (0) cin >> q;     while (q--) solve();   }   set<int> v[MAXN];   void solve() {     int n, m;     cin >> n >> m;     vector<int> v1(n), v2(n);     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       v[a].emplace(b);       v[b].emplace(a);     }     for (int i = 1; i <= n; ++i) {       v[i].emplace(i);       if (v[i].size() == n) continue;       for (int j = 1; j <= n; ++j) {         if (v[i].find(j) == v[i].end()) {           cout <<  YES n ;           v2[i - 1] = v2[j - 1] = v1[i - 1] = 1;           v1[j - 1] = 2;           int ind = 2;           for (int t = 0; t < n; ++t)             if (v1[t] == 0) v1[t] = ++ind;           ind = 2;           for (int t = 0; t < n; ++t)             if (v2[t] == 0) v2[t] = ++ind;           for (auto &i : v1) cout << i <<    ;           cout <<   n ;           for (auto &i : v2) cout << i <<    ;           return;         }       }     }     cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = 1e4 + 10;   int a[MAXN], b[MAXN], c[MAXN];   int n;   void fun(int pre) {     for (int i = 0; i < n; i++) c[i] = a[i];     for (int i = 0; i <= pre; i++) {       c[i] = a[n - pre - 1 + i];       c[n - pre - 1 + i] = a[i];     }     for (int i = 0; i < n; i++) a[i] = c[i];   }   int main() {     int T;     cin >> T;     while (T--) {       cin >> n;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) cin >> b[i];       if ((n % 2 == 1) && a[n / 2] != b[n / 2]) {         cout <<  No  << endl;       } else {         int retflag = 1;         for (int i = n / 2 - 1; i >= 0 && retflag; i--) {           if (a[i] == b[i] && a[n - i - 1] == b[n - i - 1]) continue;           int flag = 1;           for (int j = 0; j <= i && flag; j++) {             if (flag && a[j] == b[i] && a[n - j - 1] == b[n - i - 1]) {               flag = 0;               fun(j);               fun(i);             }             if (flag && a[j] == b[n - i - 1] && a[n - j - 1] == b[i]) {               flag = 0;               fun(j);               fun(0);               fun(i);             }           }           if (flag) retflag = 0;         }         if (retflag)           cout <<  Yes  << endl;         else           cout <<  No  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int a[n + 2];     a[0] = 0;     for (int i = 1; i < n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i < n; i++) {       a[i] = a[i - 1] + a[i];     }     int x, y;     scanf( %d%d , &x, &y);     printf( %d , a[y - 1] - a[x - 1]);   }


#include <bits/stdc++.h>   using namespace std;   void init_code() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   long long dp[5002][5002];   long long solve(vector<long long>& v, long long k, long long n, long long idx) {     if (k == 0) return 0;     if (idx >= n) return 0;     if (dp[idx][k] != -1) return dp[idx][k];     auto i = (upper_bound(v.begin(), v.end(), v[idx] + 5) - v.begin());     long long cnt = i - idx;     long long temp = solve(v, k - 1, n, i) + cnt;     temp = max(temp, solve(v, k, n, idx + 1));     dp[idx][k] = temp;     return temp;   }   void solve() {     long long n, k;     cin >> n >> k;     vector<long long> v(n);     for (long long i = 0; i < n; i++) cin >> v[i];     sort(v.begin(), v.end());     memset(dp, -1, sizeof(dp));     cout << solve(v, k, n, 0);   }   signed main() {     init_code();     long long tc = 1;     long long num = 1;     while (tc--) {       num++;       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int a1, a2, b1, b2;   bool sol(int a, int b) {     if (b + 1 < a) return 0;     if (b > (a + 1) * 2) return 0;     return 1;   }   int main() {     cin >> a1 >> a2 >> b1 >> b2;     if (sol(a1, b2) || sol(a2, b1))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> arr[1000006];   int main() {     int n, v, ans = 0, i, j, a, b, v1;     scanf( %d , &n);     scanf( %d , &v);     for (i = 0; i < n; ++i) {       scanf( %d , &a);       scanf( %d , &b);       arr[a].first += b;       arr[a + 1].second += b;     }     for (i = 0; i < 4; ++i)       cerr <<  i             <<  :   << i <<   |              <<  arr[i].F             <<  :   << arr[i].first <<   |              <<  arr[i].S             <<  :   << arr[i].second << endl;     ;     v1 = v;     for (i = 0; i < 3002; ++i) {       v1 = v;       if (i <= 3)         cerr <<  i               <<  :   << i <<   |                <<  arr[i].F               <<  :   << arr[i].first <<   |                <<  arr[i].S               <<  :   << arr[i].second <<   |                <<  v               <<  :   << v << endl;       ;       if (arr[i].second > 0) {         if (arr[i].second - v <= 0) {           v -= arr[i].second;           ans += arr[i].second;           arr[i].second = 0;         } else {           ans += v;           arr[i].second -= v;           v = 0;         }       }       if (i <= 3)         cerr <<  i               <<  :   << i <<   |                <<  arr[i].F               <<  :   << arr[i].first <<   |                <<  arr[i].S               <<  :   << arr[i].second <<   |                <<  v               <<  :   << v << endl;       ;       if (arr[i].first > 0) {         if (arr[i].first - v <= 0) {           ans += arr[i].first;           arr[i + 1].second -= arr[i].first;           arr[i].first = 0;           v -= arr[i].first;         } else {           cerr <<  i                 <<  :   << i << endl;           ;           ans += v;           arr[i].first -= v;           arr[i + 1].second -= v;           v = 0;         }       }       v = v1;       if (i <= 3)         cerr <<  i               <<  :   << i <<   |                <<  ans               <<  :   << ans << endl;       ;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t;   int n, q;   vector<int> vi[300005];   bool used[300005];   int pre[300005];   vector<pair<int, int> > pos[300005];   int poss[300005];   int main() {     cin >> t;     while (t--) {       scanf( %d%d , &n, &q);       for (int i = 0; i < q; i++) vi[i].clear();       for (int i = 1; i <= n; i++) {         pre[i] = -1;         used[i] = 0;         pos[i].clear();       }       for (int i = 0; i < q; i++) {         int k;         scanf( %d , &k);         for (int j = 0; j < k; j++) {           int a;           scanf( %d , &a);           vi[i].push_back(a);         }       }       bool answer = 0;       for (int i = 0; i < q; i++) {         if (vi[i].size() < 614) continue;         for (int x = 0; x < vi[i].size(); x++) used[vi[i][x]] = 1;         for (int x = 0; x < vi[i].size(); x++) poss[vi[i][x]] = x;         for (int x = 0; x < vi[i].size(); x++)           if (x) pre[vi[i][x]] = vi[i][x - 1];         for (int j = 0; j < q; j++) {           if (i == j) continue;           bool in = 0;           int prre = 1000000000;           for (int k = 0; k < vi[j].size(); k++) {             if (used[vi[j][k]]) {               if (in) {                 int need = pre[vi[j][k]];                 int real = vi[j][k - 1];                 if (need != real && prre < poss[vi[j][k]]) {                   puts( Human );                   answer = 1;                   goto end;                 }               }               in = 1;               prre = min(prre, poss[vi[j][k]]);             }           }         }         for (int x = 0; x < vi[i].size(); x++) used[vi[i][x]] = 0;         for (int x = 0; x < vi[i].size(); x++)           if (x) pre[vi[i][x]] = -1;       }     end:;       if (answer) continue;       for (int i = 0; i < q; i++) {         if (vi[i].size() >= 614) continue;         for (int x = 0; x < vi[i].size(); x++) {           pos[vi[i][x]].push_back(make_pair(i, x));         }       }       for (int beg = 1; beg <= n; beg++) {         for (int i = 0; i < pos[beg].size(); i++) {           int id = pos[beg][i].first;           int nm = pos[beg][i].second;           for (int j = nm + 1; j < vi[id].size(); j++) {             int cur = vi[id][j];             int prre = vi[id][j - 1];             if (pre[cur] == -1) {               pre[cur] = prre;             } else if (pre[cur] != prre) {               puts( Human );               answer = 1;               goto end2;             }           }         }         for (int i = 0; i < pos[beg].size(); i++) {           int id = pos[beg][i].first;           int nm = pos[beg][i].second;           for (int j = nm + 1; j < vi[id].size(); j++) {             int cur = vi[id][j];             pre[cur] = -1;           }         }       }     end2:;       if (answer) continue;       puts( Robot );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans;     long long sum = 0;     map<long long, int> d;     cin >> n;     ans = n - 1;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       sum += t;       d[sum]++;       ans = min(ans, n - d[sum]);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = (int)s.size();     int pos[n + 1];     int st = 1, end = n;     int temp = 1;     for (auto x : s) {       if (st > end) break;       if (x ==  l ) {         pos[end--] = temp++;       } else {         pos[st++] = temp++;       }     }     for (int i = 1; i <= n; i++) {       printf( %d n , pos[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long max(long long a, long long b) { return a > b ? a : b; }   class Box {    public:     string name;     int type, border, spacing;     vector<Box *> con;     bool hcalc, wcalc;     long long w, h;     Box() { hcalc = wcalc = 0; }     Box(string ni, int t) : name(ni), type(t) {       con.clear();       hcalc = wcalc = 0;       border = spacing = 0;     }     Box(string ni, int t, long long wi, long long hi)         : name(ni), type(t), w(wi), h(hi) {       con.clear();       hcalc = wcalc = 0;       border = spacing = 0;     }     long long getw() {       int i;       if (!wcalc) {         wcalc = 1;         if (type == 0) {         } else if (type == 1) {           if (con.size() == 0)             w = 0;           else {             w = border * 2 + spacing * (con.size() - 1);             for (i = 0; i < con.size(); i++) w += con[i]->getw();           }         } else if (type == 2) {           if (con.size() == 0)             w = 0;           else {             w = 0;             for (i = 0; i < con.size(); i++) w = max(w, con[i]->getw());             w += border * 2;           }         }       }       return w;     }     long long geth() {       int i;       if (!hcalc) {         hcalc = 1;         if (type == 0) {         } else if (type == 2) {           if (con.size() == 0)             h = 0;           else {             h = border * 2 + spacing * (con.size() - 1);             for (i = 0; i < con.size(); i++) h += con[i]->geth();           }         } else if (type == 1) {           if (con.size() == 0)             h = 0;           else {             h = 0;             for (i = 0; i < con.size(); i++) h = max(h, con[i]->geth());             h += border * 2;           }         }       }       return h;     }     const bool operator<(const Box &b) const { return name < b.name; }   };   map<string, int> mp;   int bn;   Box box[205];   int main(void) {     int qn, qi, i, j, w, h, v, u;     char cc[200], zz[200];     string cmd, a, b, c;     scanf( %d , &qn);     gets(cc);     bn = 0;     mp.clear();     for (qi = 0; qi < qn; qi++) {       gets(cc);       cmd = cc;       if (cmd.substr(0, 4) ==  VBox ) {         a = cmd.substr(5);         mp[a] = bn;         box[bn++] = Box(a, 2);       } else if (cmd.substr(0, 4) ==  HBox ) {         a = cmd.substr(5);         mp[a] = bn;         box[bn++] = Box(a, 1);       } else if (cmd.substr(0, 6) ==  Widget ) {         i = 7;         for (j = i + 1; cmd[j] !=  ( ; j++)           ;         a = cmd.substr(i, j - i);         mp[a] = bn;         sscanf(cmd.substr(j).c_str(),  (%d,%d) , &w, &h);         box[bn++] = Box(a, 0, w, h);       } else {         for (i = 0; cmd[i] !=  . ; i++)           ;         a = cmd.substr(0, i);         v = mp[a];         i++;         for (j = i; cmd[j] !=  ( ; j++)           ;         b = cmd.substr(i, j - i);         j++;         c = cmd.substr(j, cmd.length() - j - 1);         if (b ==  pack ) {           u = mp[c];           box[v].con.push_back(box + u);         } else if (b ==  set_border ) {           sscanf(c.c_str(),  %d , &w);           box[v].border = w;         } else if (b ==  set_spacing ) {           sscanf(c.c_str(),  %d , &w);           box[v].spacing = w;         }       }     }     for (i = 0; i < bn; i++) {       box[i].getw();       box[i].geth();     }     std::sort(box, box + bn);     for (i = 0; i < bn; i++) {       cout << box[i].name <<     << box[i].getw() <<     << box[i].geth() << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 7;   vector<long long> vec;   long long solve(vector<long long>& a, long long i) {     if (i == -1) return 0;     vector<long long> a1, a0;     for (long long x : a)       if (x & (1 << i))         a1.push_back(x);       else         a0.push_back(x);     if (a0.empty() || a1.empty()) return solve(a, i - 1);     return min(solve(a1, i - 1), solve(a0, i - 1)) + (1 << i);   }   int32_t main() {     long long n;     cin >> n;     for (long long i = 0, x; i < n; i++) cin >> x, vec.push_back(x);     cout << solve(vec, 30) << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T bigmod(T p, T e, T M) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return (T)ret;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   int dis[4][1001][1001], n, m;   ;   queue<pair<int, int> > Q;   char pp[1011][1011];   int nxt[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};   void go(int c) {     while (!Q.empty()) Q.pop();     for (int i = (0); i < (n); ++i) {       for (int j = (0); j < (m); ++j)         if (pp[i][j] ==  0  + c) {           dis[c][i][j] = 0;           Q.push(make_pair(i, j));         }     }     while (!Q.empty()) {       pair<int, int> p = Q.front();       Q.pop();       for (int i = (0); i < (4); ++i) {         int x = p.first + nxt[i][0], y = p.second + nxt[i][1];         if (x < 0 || x >= n || y < 0 || y >= m || pp[x][y] ==  # ) continue;         if (dis[c][x][y] <= dis[c][p.first][p.second] + 1) continue;         dis[c][x][y] = dis[c][p.first][p.second] + 1;         Q.push(make_pair(x, y));       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = (0); i < (n); ++i) cin >> pp[i];     memset(dis, 126, sizeof dis);     go(1);     go(2);     go(3);     int res = INT_MAX / 3;     for (int i = (1); i < (4); ++i) {       int dd[4];       memset(dd, 126, sizeof dd);       dd[i] = 1;       for (int j = (0); j < (n); ++j) {         for (int k = (0); k < (m); ++k) {           if (pp[j][k] >=  1  && pp[j][k] <=  3  && pp[j][k] !=  0  + i)             dd[pp[j][k] -  0 ] = min(dd[pp[j][k] -  0 ], dis[i][j][k]);         }       }       long long sum = 0;       for (int j = (1); j < (4); ++j) sum += dd[j] - 1;       if (sum < res) res = sum;     }     for (int i = (0); i < (n); ++i) {       for (int j = (0); j < (m); ++j) {         if (pp[i][j] !=  . ) continue;         long long sum = 1;         for (int k = (1); k < (4); ++k) {           sum += dis[k][i][j] - 1;         }         if (sum < res) res = sum;       }     }     if (res > 10000000)       cout << -1 << endl;     else       cout << res << endl;   }


#include <bits/stdc++.h>   const int MAX_N = 20;   int n, k, t;   int e[MAX_N + 1][MAX_N + 1];   int choosen[MAX_N + 1];   int mid;   int cnt;   void dfs(int x, int now_cost_sum) {     if (now_cost_sum > mid) return;     if (cnt >= t) return;     if (x > n) {       cnt++;       return;     }     dfs(x + 1, now_cost_sum);     for (int y = 1; y <= n && cnt < t; y++)       if (!choosen[y] && e[x][y]) {         choosen[y] = 1;         dfs(x + 1, now_cost_sum + e[x][y]);         choosen[y] = 0;       }   }   int main() {     scanf( %d%d%d , &n, &k, &t);     for (int i = 1; i <= k; i++) {       int h, w, r;       scanf( %d%d%d , &h, &w, &r);       e[h][w] = r;     }     int low = 0, high = 1000 * n;     while (low < high) {       mid = (low + high) >> 1;       cnt = 0;       dfs(1, 0);       if (cnt >= t)         high = mid;       else         low = mid + 1;     }     printf( %d n , low);   }


#include <bits/stdc++.h>   using namespace std;   priority_queue<pair<long long int, long long int> > p_que;   long long int arr[300005];   long long int ans[300005];   int main(int argc, char const *argv[]) {     long long int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> arr[i];     }     for (int i = 1; i <= k; i++) {       p_que.push(make_pair(arr[i], i));     }     long long int tot = 0;     for (int i = k + 1; i <= n + k; i++) {       if (i <= n) p_que.push(make_pair(arr[i], i));       pair<long long int, long long int> p = p_que.top();       p_que.pop();       tot = tot + (i - p.second) * p.first;       ans[p.second] = i;     }     cout << tot <<   n ;     for (int i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   const long long MX = 2 * 100 * 1000 + 1000, inf = 3e18,                   mod = 1000 * 1000 * 1000 + 7;   using namespace std;   vector<long long> ans[MX];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     long long n = s.size();     long long one = 0, num = 0;     for (long long i = 0; i < n; i++) {       if (s[i] ==  1 ) {         if (one < num) {           ans[one].push_back(i);           one++;         } else {           return cout << -1 << endl, 0;         }       } else {         if (one > 0) {           one--;           ans[one].push_back(i);         } else {           ans[num].push_back(i);           num++;         }       }     }     if (one) {       return cout << -1 << endl, 0;     }     cout << num << endl;     for (long long i = 0; i < num; i++) {       cout << ans[i].size() <<    ;       for (long long j = 0; j < ans[i].size(); j++) {         cout << ans[i][j] + 1 <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<int> V(n);     for (int i = 0; i < m; ++i) {       int k;       cin >> k;       V[k - 1]++;     }     int mn = 1e9;     for (int i = 0; i < n; ++i) mn = min(mn, V[i]);     cout << mn <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000 * 1000];   int main() {     int t;     cin >> t;     double s = 0;     for (int i = 0; i < t; i++) {       cin >> a[i];       s += a[i];     }     vector<int> ind;     for (int i = 0; i < t; i++) {       double p = ((s - a[i]) / (t - 1));       if (a[i] == p) ind.push_back(i + 1);     }     cout << ind.size() << endl;     for (int i = 0; i < ind.size(); i++) {       cout << ind[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   int n;   long long pts[MAXN][2];   unsigned long long area(int i, int j, int k) {     return (abs(pts[i][0] * pts[j][1] + pts[j][0] * pts[k][1] +                 pts[k][0] * pts[i][1] - pts[i][1] * pts[j][0] -                 pts[j][1] * pts[k][0] - pts[k][1] * pts[i][0]));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; ++i) cin >> pts[i][0] >> pts[i][1];     int x = -1, y = -1;     long long c = 2e9, d = 2e9;     for (int i = 0; i < n; ++i) {       if (pts[i][0] < c) {         c = pts[i][0], d = pts[i][1], x = i;       } else if (pts[i][0] == c && pts[i][1] < d) {         c = pts[i][0], d = pts[i][1], x = i;       }     }     c = 2e9, d = 2e9;     for (int i = 0; i < n; ++i) {       if (i == x) continue;       if (pts[i][0] < c) {         c = pts[i][0], d = pts[i][1], y = i;       } else if (pts[i][0] == c && pts[i][1] < d) {         c = pts[i][0], d = pts[i][1], y = i;       }     }     long long minarea = 6e18;     int ind = -1;     for (int i = 0; i < n; ++i) {       if (i == x || i == y) continue;       long long a = area(x, y, i);       if (a == 0) continue;       if (a < minarea) {         minarea = a;         ind = i;       }     }     cout << x + 1 <<     << y + 1 <<     << ind + 1 << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4,avx2,abm,fma,tune=native )   #pragma GCC optimize( unroll-loops )   using namespace std;   const long long INF = 0x3f3f3f3f;   const long long inf = pow(10, 18);   long long modulo = pow(10, 9) + 7;   long long valn[100100];   long long val[100100];   long long dp[100100];   vector<long long> sorted[100100];   vector<long long> g[100100];   long long lca[100100][20];   long long dep[100100];   long long tin[100100];   long long tout[100100];   long long calcval(long long a, long long b) {     return max(abs(a + b), abs(a - b));   }   void dfslca(long long hd, long long pr, long long& tim) {     lca[hd][0] = pr;     tin[hd] = tim;     for (auto hr : g[hd]) {       if (hr == pr) continue;       dep[hr] = dep[hd] + 1;       ++tim;       sorted[hd].push_back(hr);       dfslca(hr, hd, tim);     }     tout[hd] = tim;   }   void pre(long long n) {     for (long long j = 1; j < 20; j++)       for (long long i = 0; i < n; i++) lca[i][j] = lca[lca[i][j - 1]][j - 1];   }   long long LCA(long long a, long long b) {     if (dep[a] < dep[b]) swap(a, b);     for (long long j = 20 - 1; j > -1; j--)       if (dep[lca[a][j]] > dep[b]) a = lca[a][j];     if (dep[a] != dep[b]) a = lca[a][0];     for (long long j = 20 - 1; j > -1; j--)       if (lca[a][j] != lca[b][j]) a = lca[a][j], b = lca[b][j];     if (a != b) a = lca[a][0], b = lca[b][0];     return a;   }   void calcdp(long long hd, long long pr) {     for (auto& hr : g[hd]) {       if (hr == pr) {         continue;       }       dp[hr] = dp[hd] + calcval(val[hd], val[hr]);       calcdp(hr, hd);     }   }   bool isp(long long pr, long long hd) {     return tin[pr] <= tin[hd] && tout[hd] <= tout[pr];   }   long long findChild(long long pr, long long hd) {     long long lo = 0, hi = (long long)sorted[pr].size() - 1;     while (lo < hi) {       long long mid = (lo + hi) / 2 + 1;       long long hr = sorted[pr][mid];       if (tin[hr] > tin[hd]) {         hi = mid - 1;       } else {         lo = mid;       }     }     return sorted[pr][lo];   }   void deal() {     long long n, q;     cin >> n >> q;     for (long long i = 0; i < n; i++) {       cin >> val[i];       valn[i] = val[i];     }     for (long long i = 0; i < n - 1; i++) {       long long ai, bi;       cin >> ai >> bi;       --ai, --bi;       g[ai].push_back(bi);       g[bi].push_back(ai);     }     {       long long tim = 1;       dfslca(0, 0, tim);       pre(n);       calcdp(0, 0);     }     map<long long, long long> dif;     for (long long l = 0; l < q; l++) {       long long ty;       cin >> ty;       if (ty == 1) {         long long u, c;         cin >> u >> c;         --u;         dif[u] = c;         valn[u] = c;       } else {         long long u, v;         cin >> u >> v;         --u, --v;         long long lc = LCA(u, v);         long long ans = dp[u] + dp[v] - 2 * dp[lc];         unordered_set<long long> again;         for (auto& el : dif) {           long long pr = el.first;           long long p1 = isp(pr, u);           long long p2 = isp(pr, v);           if (p1 && (!p2 || pr == lc) && pr != u) {             long long a = pr;             long long b = findChild(pr, u);             if (b < a) {               swap(a, b);             }             again.insert(a * 100100 + b);           }           if (p2 && (!p1 || pr == lc) && pr != v) {             long long a = pr;             long long b = findChild(pr, v);             if (b < a) {               swap(a, b);             }             again.insert(a * 100100 + b);           }           if (lca[pr][0] != pr &&               ((p1 ^ p2) || (lca[pr][0] == lc && (p1 || p2)))) {             long long a = pr;             long long b = lca[pr][0];             if (b < a) {               swap(a, b);             }             again.insert(a * 100100 + b);           }         }         for (auto& el : again) {           long long a = el / 100100, b = el % 100100;           ans -= calcval(val[a], val[b]);           ans += calcval(valn[a], valn[b]);         }         cout << ans <<   n ;       }       if ((long long)dif.size() > 200) {         for (long long i = 0; i < n; i++) {           val[i] = valn[i];         }         calcdp(0, 0);         dif.clear();       }     }   }   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     deal();   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const char E =   n ;   const int N = 20015;   const int NN = 1000000;   const long long md = 1e9 + 7;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     int tttt;     cin >> tttt;     while (tttt--) {       int n;       cin >> n;       vector<long long> a(n + 5);       for (int i = 1; i <= n; i++) {         cin >> a[i];       }       long long l = 1, mn = 1001007000;       long long mx = 0;       for (int i = 2; i <= n; i++) {         if (a[i] < a[l] && i != n) {           mn = min(mn, a[i]);           continue;         }         mn = min(mn, a[i]);         mx = max(mx, a[l] - mn);         mn = 1001007000;         l = i;       }       long long ans = 0;       long long t = 0;       while (t < mx) {         ans++;         t += (1 << (ans - 1));       }       cout << ans << E;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dp[5011][5011];   void solve() {     long long n, m;     cin >> n >> m;     string s1, s2;     cin >> s1 >> s2;     s1 =  .  + s1;     s2 =  .  + s2;     long long ans = 0;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= m; j++) {         dp[i][j] = max({0ll, dp[i - 1][j] - 1, dp[i][j - 1] - 1});         if (s1[i] == s2[j])           dp[i][j] = max(               {0ll, dp[i - 1][j] - 1, dp[i][j - 1] - 1, dp[i - 1][j - 1] + 2});         ans = max(ans, dp[i][j]);       }     }     cout << ans;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) solve();   }


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


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<char> v;     long long ca = 0, ci = 0, cf = 0;     for (long long i = 0; i < n; i++) {       char a;       cin >> a;       v.push_back(a);       if (a ==  A ) ca++;       if (a ==  I ) ci++;       if (a ==  F ) cf++;     }     if (ca + cf == n)       cout << ca;     else {       if (ci > 1)         cout << 0;       else         cout << ci;     }     for (long long i = 1; i < n; i++) {     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const int MAXA = 2e5 + 10;   const int MAX = 2e3 + 10;   int n, m, k;   int a[MAXA];   int M = 0;   pair<int, int> p[MAX];   long long sum[MAX];   long long memo[MAX];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> k;     for (int i = 0; i < n; i++) cin >> a[i];     vector<int> f(MAX, -1);     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       if (x > MAX) continue;       f[x] = max(f[x], y);     }     for (int i = 1; i < MAX; i++) {       if (f[i] == -1) continue;       p[M++] = {i, f[i]};     }     partial_sort(&a[0], &a[min(n, MAX)], &a[n]);     sum[0] = 0;     for (int i = 0; i < k; i++) {       sum[i + 1] = sum[i] + a[i];     }     memo[k] = 0;     for (int i = k - 1; i >= 0; i--) {       long long ans = a[i] + memo[i + 1];       for (int j = 0; j < M; j++) {         if (i + p[j].first > k) break;         long long r = memo[i + p[j].first];         ans = min(ans, sum[i + p[j].first] - sum[i + p[j].second] + r);       }       memo[i] = ans;     }     cout << memo[0] <<   n ;     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, e, f, g;     cin >> a >> b >> c;     d = a + b + c;     e = 2 * (a + b);     f = 2 * (b + c);     g = 2 * (c + a);     if (d <= e && d <= f && d <= g) {       cout << d;     } else if (e <= f && e <= g) {       cout << e;     } else if (f <= g) {       cout << f;     } else {       cout << g;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T BigMod(T b, T p, T m) {     if (p == 0) return 1;     if (p % 2 == 0) {       T s = BigMod(b, p / 2, m);       return ((s % m) * (s % m)) % m;     }     return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;   }   template <typename T>   T ModInv(T b, T m) {     return BigMod(b, m - 2, m);   }   template <typename T>   T gcd(T a, T b) {     if (!b) return a;     return gcd(b, a % b);   }   int a[1004];   vector<int> v;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t, i, j, e, n, k, l, ed, res, p, y, n1, n2, sum, cnt, dif, idx, x, m, val,         cst, st, sz;     cin >> x;     for (i = 1; i <= x; i++) {       cin >> a[i];       if (i > 1) v.push_back(a[i] - a[i - 1]);     }     bool fl = 0;     sz = v.size();     for (i = 0; i <= sz - 1; i++) {       if (i > 0) {         if (v[i] == v[i - 1]) continue;         fl = 1;         break;       }     }     if (fl)       cout << a[x] << endl;     else       cout << a[x] + v[sz - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, s, x, y, nb;   vector<pair<long long, long long> > t, v;   long long dp[102];   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     return a.first + a.second > b.first + b.second;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> s;     for (long long i = 0; i < n; i++) {       cin >> x >> y;       if (y >= 0) {         t.push_back(make_pair(x, y));       } else {         v.push_back(make_pair(y, x));       }     }     sort(t.begin(), t.end());     for (long long i = 0; i < t.size(); i++) {       if (t[i].first > s) break;       s += t[i].second;       nb++;     }     sort(v.begin(), v.end(), cmp);     n = v.size();     for (long long i = 1; i < n + 1; i++) dp[i] = -1;     dp[0] = s;     for (long long i = 0; i < n; i++) {       for (long long j = i + 1; j > 0; j--) {         if (dp[j - 1] >= v[i].second) dp[j] = max(dp[j], dp[j - 1] + v[i].first);       }     }     long long i;     for (i = n; dp[i] == -1; i--)       ;     cout << nb + i <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct dulieu {     long int gt, tt;   };   long int n;   dulieu a[3 * 100005];   bool sx1(dulieu a, dulieu b) { return a.gt < b.gt; }   bool sx2(dulieu a, dulieu b) { return a.tt < b.tt; }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i].gt;       a[i].tt = i;     }     sort(a, a + n, sx1);     for (int i = 0; i < n; i++)       if (a[i].gt <= a[i - 1].gt) a[i].gt = a[i - 1].gt + 1;     sort(a, a + n, sx2);     for (int i = 0; i < n; i++) cout << a[i].gt <<    ;   }