#include <bits/stdc++.h>   using namespace std;   int m[367], f[367];   int main() {     memset(m, 0, sizeof(m));     memset(f, 0, sizeof(f));     int N;     cin >> N;     char ch;     int a, b;     for (int i = 0; i < N; ++i) {       cin >> ch >> a >> b;       if (ch ==  M )         for (int j = a; j <= b; ++j) ++m[j];       else         for (int j = a; j <= b; ++j) ++f[j];     }     int res = 0;     for (int i = 1; i <= 366; ++i) res = max(res, min(m[i], f[i]) * 2);     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char t;   int n, m;   char a[11][11];   bool used[11][11];   int kol = 0;   int maxleng = 0;   void dfs(int x, int y, bool ch, int leng = 0) {     if (x < 0 || y < 0 || x >= n || y >= m) return;     if (a[x][y] == 2) return;     if (used[x][y]) return;     used[x][y] = true;     if (ch) ++leng;     if (x - 1 >= 0 && y >= 0 && x - 1 < n && y < m && a[x][y] == !a[x - 1][y])       dfs(x - 1, y, !ch, leng);     if (x >= 0 && y - 1 >= 0 && x < n && y - 1 < m && a[x][y] == !a[x][y - 1])       dfs(x, y - 1, !ch, leng);     if (x >= 0 && y + 1 >= 0 && x < n && y + 1 < m && a[x][y] == !a[x][y + 1])       dfs(x, y + 1, !ch, leng);     if (x + 1 >= 0 && y >= 0 && x + 1 < n && y < m && a[x][y] == !a[x + 1][y])       dfs(x + 1, y, !ch, leng);     maxleng = max(maxleng, leng);   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         cin >> t;         if (t ==  . ) a[i][j] = 2;         if (t ==  P ) a[i][j] = 0;         if (t ==  W ) a[i][j] = 1;         used[i][j] = false;       }     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         if (!used[i][j]) maxleng = 0, dfs(i, j, 0), kol += maxleng;     cout << kol;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)2e5 + 5;   int n, t;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     while (cin >> n) {       int ans = 0;       set<int> s;       for (int i = 1; i <= n && cin >> t; ++i) {         if (t) {           if (s.count(t))             ans++;           else             s.insert(t);         } else           ans++;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   const int inf = 0x3f3f3f3f;   int main() {     int t;     t = 1;     while (t--) {       long long a, b, c, d;       cin >> a >> b >> c >> d;       long long ans = 0;       for (int i = (a); i < (b + 1); i++) {         long long l = b - 1, r = c + 2;         while (l < r - 1) {           long long mid = l + r >> 1;           if (mid + i > c) {             r = mid;           } else {             l = mid;           }         }         if (r <= c && i + r > c) {           if (i + r <= d + 1) {             long long mx = min(i + c, d + 1);             ans += (i + r - c + mx - c) * (mx - (i + r) + 1) / 2;           }           if (i + c > d + 1) {             long long x = max(d + 2 - i, r);             ans += (d + 1 - c) * (c - x + 1);           }         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   double alto, ancho, altomesa, anchomesa, ancho1, alto1, x_1, x_2, y_1, y_2;   double abajo() {     if (altomesa <= y_1) return 0;     return altomesa - y_1;   }   double arriba() {     if (altomesa <= alto - y_2) return 0;     return altomesa - (alto - y_2);   }   double izquierda() {     if (anchomesa <= x_1) return 0;     return anchomesa - x_1;   }   double derecha() {     if (anchomesa <= ancho - x_2) return 0;     return anchomesa - (ancho - x_2);   }   void solve() {     cin >> ancho >> alto;     cin >> x_1 >> y_1 >> x_2 >> y_2;     cin >> anchomesa >> altomesa;     ancho1 = x_2 - x_1, alto1 = y_2 - y_1;     if (ancho1 + anchomesa > ancho && alto1 + altomesa > alto) {       cout << -1;       return;     }     double ans = 100000000;     if (ancho1 + anchomesa <= ancho) {       ans = min(ans, izquierda());       ans = min(ans, derecha());     }     if (alto1 + altomesa <= alto) {       ans = min(ans, arriba());       ans = min(ans, abajo());     }     printf( %.6f , ans);   }   int main() {     int T = 1;     cin >> T;     cout <<   n ;     while (T--) solve(), cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void run();   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(3);     srand(42);     run();   }   template <typename T1, typename T2>   bool mini(T1 &a, const T2 &b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <typename T1, typename T2>   bool maxi(T1 &a, const T2 &b) {     if (a < b) {       a = b;       return true;     }     return false;   }   const long long N = 52;   long long rcnt[N];   long long ccnt[N];   void run() {     long long n, m;     cin >> n >> m;     set<long long> masks;     for (long long i = 0; i < n; i++) {       long long kek = 0;       for (long long j = 0; j < m; j++) {         char c;         cin >> c;         if (c ==  # ) kek |= (1LL << j);       }       masks.insert(kek);     }     for (auto it1 = masks.begin(); it1 != masks.end(); it1++) {       auto it2 = it1;       it2++;       for (; it2 != masks.end(); it2++) {         if ((*it1) & (*(it2))) {           cout <<  No ;           return;         }       }     }     cout <<  Yes ;   }


#include <bits/stdc++.h>   using namespace std;   long long c[2000010];   long long sum[2000010];   int main() {     int n, x, y;     while (cin >> n >> x >> y) {       memset(c, 0, sizeof c);       memset(sum, 0, sizeof sum);       for (int i = 1; i <= n; i++) {         int w;         scanf( %d , &w);         c[w]++;         sum[w] += w;       }       for (int i = 0; i <= 2000000; i++) {         c[i] += c[i - 1];         sum[i] += sum[i - 1];       }       long long ans = 1LL * n * x;       for (int i = 2; i <= 1000000; i++) {         long long tmp = 0;         for (int j = i; j <= 1000000 + i && tmp < ans; j += i) {           int k = max(j - i, j - ((x - 1) / y + 1));           long long h = y * ((c[j] - c[k]) * j - (sum[j] - sum[k]));           h += (c[k] - c[j - i]) * x;           tmp += h;         }         ans = min(ans, tmp);       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int T = 1, inf = 10000000000;   bool check(long long int n) {     long long int flag = 1;     while (n > 0) {       if (n % 10 != 4 && n % 10 != 7) {         flag = 0;         break;       }       n /= 10;     }     return flag;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     while (T--) {       long long int n, sz = 3, ans = 0, blag = 0, u, mn, ev = 0, mx, mini, i, v,                        q, p, j, k, w, h, l, m, x, y, od = 0, total = 0, cc = 0,                        pp = 0, flag = 0, klag = 0, sum = 0;       string s, s3, s1 =  YES , s2 =  NO ;       bool ok = 0;       cin >> n;       for (i = 4; i <= n; i += 1) {         if (n % i == 0) {           if (check(i)) {             cout << s1;             return 0;           }         }       }       cout << s2;       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 2e5 + 10;   const int inf = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const int bit = 32;   const double pi = acos(-1.0);   int a[M];   int dfs(int k, int l, int r) {     if (l > r) return 0;     if (k < 0) return 1;     int mid = r;     int t = 1 << k;     for (int i = l; i <= r; i++) {       if (t & a[i]) {         mid = i - 1;         break;       }     }     int x = dfs(k - 1, l, mid), y = dfs(k - 1, mid + 1, r);     return max(x + min(r - mid, 1), y + min(mid - l + 1, 1));   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + 1 + n);     printf( %d n , n - dfs(30, 1, n));     return 0;   }


#include <bits/stdc++.h>   template <class T>   inline void read(T &x) {     x = 0;     int ne = 0;     char c;     while (!isdigit(c = getchar())) ne = c ==  - ;     x = c - 48;     while (isdigit(c = getchar())) x = (x << 3) + (x << 1) + c - 48;     x = ne ? -x : x;     return;   }   const int maxn = 1005;   const int inf = 0x7fffffff;   int g[maxn][maxn];   int okx[maxn][maxn], oky[maxn][maxn];   int sum[maxn][maxn];   bool flag[maxn][maxn];   char s[maxn];   int n, m;   struct Star {     int x, y, size;     Star(int a, int b, int c) { x = a, y = b, size = c; }     Star() { ; }   } st[1000005];   int tot = 0;   int len;   inline bool solve(int i, int j) {     int p = 1, k = 0;     len = 0;     while (p != 0) {       int x = p + k;       if (j - x >= 1 && j + x <= m && i + x <= n && i - x >= 1 &&           (sum[i][j] - sum[i][j - 1] - sum[i - x - 1][j] +                sum[i - x - 1][j - 1] >=            (x + 1)) &&           (sum[i + x][j] - sum[i + x][j - 1] - sum[i - 1][j] +                sum[i - 1][j - 1] >=            (x + 1))) {         if ((sum[i][j] - sum[i][j - x - 1] - sum[i - 1][j] +                  sum[i - 1][j - x - 1] >=              (x + 1)) &&             (sum[i][j + x] - sum[i - 1][j + x] - sum[i][j - 1] +                  sum[i - 1][j - 1] >=              (x + 1))) {           k += p, p = p << 1;           x = p + k;         } else           p = p / 2;       } else         p = p / 2;       x = p + k;       while (j - x < 1 || j + x > m || i + x > n || i - x < 1 && p) {         p = p >> 1;         x = p + k;       }     }     len = k;     if (!len) return 0;     okx[i][j - len]++, okx[i][j + len + 1]--;     oky[j][i - len]++, oky[j][i + len + 1]--;     return 1;   }   int main() {     read(n), read(m);     for (register int i = 1; i <= n; i++) {       scanf( %s , s + 1);       for (register int j = 1; j <= m; j++) {         if (s[j] ==  * )           g[i][j] = 1;         else           g[i][j] = 0;         sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + g[i][j];       }     }     for (register int i = 1; i <= n; i++) {       for (register int j = 1; j <= m; j++) {         if (g[i][j]) {           if (solve(i, j)) {             st[++tot] = Star(i, j, len);           }         }       }     }     for (register int i = 1; i <= n; i++) {       int tmp = 0;       for (register int j = 1; j <= m; j++) {         tmp += okx[i][j];         if (tmp) flag[i][j] = 1;       }     }     for (register int i = 1; i <= m; i++) {       int tmp = 0;       for (register int j = 1; j <= n; j++) {         tmp += oky[i][j];         if (tmp) flag[j][i] = 1;         if (g[j][i] && !flag[j][i]) {           puts( -1 );           return 0;         }       }     }     printf( %d n , tot);     for (register int i = 1; i <= tot; i++) {       printf( %d %d %d n , st[i].x, st[i].y, st[i].size);     }     return 0;   }


#include <bits/stdc++.h>   const int oo = 0x7fffffff;   const long long OO = 0x7fffffffffffffff;   using namespace std;   const int NX = 50;   typedef bitset<NX * NX * NX * NX> dp_t;   int n;   array<bitset<NX>, NX> board1, board2, done;   dp_t dp1, dp2;   int ask(int x1, int y1, int x2, int y2) {     cout <<  ?   << (1 + x1) <<     << (1 + y1) <<     << (1 + x2) <<              << (1 + y2) << endl;     int r;     cin >> r;     if (r == -1) exit(0);     return r;   }   void ask_n_set(int x1, int y1, int x2, int y2, bool forward = true) {     int r = ask(x1, y1, x2, y2) ^ 1;     if (forward) {       board1[x2][y2] = r ^ board1[x1][y1];       board2[x2][y2] = r ^ board2[x1][y1];       done[x2][y2] = 1;     } else {       board1[x1][y1] = r ^ board1[x2][y2];       board2[x1][y1] = r ^ board2[x2][y2];       done[x1][y1] = 1;     }   }   void print(const array<bitset<NX>, NX>& B) {     cout <<  ! n ;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) cout << B[i][j];       cout <<   n ;     }     cout << endl;   }   void solve(const array<bitset<NX>, NX>& B, dp_t& dp) {     for (int x1 = 0; x1 < n; ++x1)       for (int y1 = 0; y1 < n; ++y1)         for (int x2 = 0; x2 < n; ++x2)           for (int y2 = 0; y2 < n; ++y2)             if ((abs(x1 - x2) + abs(y1 - y2)) <= 2)               dp[(y2 + NX * (x2 + NX * (y1 + NX * x1)))] = B[x1][y1] == B[x2][y2];     for (int x1 = 0; x1 < n; ++x1)       for (int y1 = 0; y1 < n; ++y1)         for (int x2 = x1 - 1; x2 >= 0; --x2)           for (int y2 = y1 - 1; y2 >= 0; --y2)             dp[(y2 + NX * (x2 + NX * (y1 + NX * x1)))] = 0;     for (int len = 3; len < (2 * n); ++len)       for (int x1 = 0; x1 < n; ++x1)         for (int y1 = 0; y1 < n; ++y1)           for (int x2 = x1; x2 < n; ++x2)             if ((abs(x1 - x2) + abs(y1 - y1)) <= len) {               int d = len - (x2 - x1);               int y2 = y1 + d;               if (y2 >= n) continue;               if (x1 == x2) {                 dp[(y2 + NX * (x2 + NX * (y1 + NX * x1)))] =                     B[x1][y1] == B[x2][y2] and                     dp[(y2 - 1 + NX * (x2 + NX * (y1 + 1 + NX * x1)))];               } else if (y1 == y2) {                 dp[(y2 + NX * (x2 + NX * (y1 + NX * x1)))] =                     B[x1][y1] == B[x2][y2] and                     dp[(y2 + NX * (x2 - 1 + NX * (y1 + NX * x1 + 1)))];               } else {                 dp[(y2 + NX * (x2 + NX * (y1 + NX * x1)))] =                     B[x1][y1] == B[x2][y2] and                     (dp[(y2 + NX * (x2 - 1 + NX * (y1 + NX * x1 + 1)))] or                      dp[(y2 - 1 + NX * (x2 + NX * (y1 + NX * x1 + 1)))] or                      dp[(y2 + NX * (x2 - 1 + NX * (y1 + 1 + NX * x1)))] or                      dp[(y2 - 1 + NX * (x2 + NX * (y1 + 1 + NX * x1)))]);               }             }   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j) done[i][j] = 0;     board2[0][0] = board1[0][0] = 1;     board2[n - 1][n - 1] = board1[n - 1][n - 1] = 0;     done[0][0] = done[n - 1][n - 1] = 1;     board1[0][1] = 1;     board2[0][1] = 0;     done[0][1] = 1;     ask_n_set(0, 1, 2, 1);     ask_n_set(1, 0, 2, 1, false);     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j)         if (not done[i][j]) {           int x, y;           if (i - 2 >= 0) {             x = i - 2;             y = j;           } else if (j - 2 >= 0) {             x = i;             y = j - 2;           } else {             x = i - 1;             y = j - 1;           }           ask_n_set(x, y, i, j);         }     solve(board1, dp1);     solve(board2, dp2);     for (int x1 = 0; x1 < n; ++x1)       for (int x2 = x1; x2 < n; ++x2)         for (int y1 = 0; y1 < n; ++y1)           for (int y2 = y1; y2 < n; ++y2)             if (2 <= y2 - y1 + x2 - x1) {               int r1 = dp1[(y2 + NX * (x2 + NX * (y1 + NX * x1)))],                   r2 = dp2[(y2 + NX * (x2 + NX * (y1 + NX * x1)))];               if (r1 == r2) continue;               int r = ask(x1, y1, x2, y2);               if (r1 == r)                 print(board1);               else                 print(board2);               return 0;             }     print(board1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T& x) {     char c;     bool f = 0;     while ((c = getchar()) <  0  ||  9  < c) f |= (c ==  - );     for (x = (c ^ 48);  0  <= (c = getchar()) && c <=  9 ;          x = (x << 1) + (x << 3) + (c ^ 48))       ;     if (f) x = -x;   }   template <class T>   inline T read(const T sample) {     T x = 0;     char c;     bool f = 0;     while ((c = getchar()) <  0  ||  9  < c) f |= (c ==  - );     for (x = (c ^ 48);  0  <= (c = getchar()) && c <=  9 ;          x = (x << 1) + (x << 3) + (c ^ 48))       ;     return f ? -x : x;   }   template <class T>   void fwrit(const T x) {     if (x < 0) return (void)(putchar( - ), fwrit(-x));     if (x > 9) fwrit(x / 10);     putchar(x % 10 ^ 48);   }   template <class T>   inline T Max(const T x, const T y) {     return x > y ? x : y;   }   template <class T>   inline T Min(const T x, const T y) {     return x < y ? x : y;   }   template <class T>   inline T fab(const T x) {     return x > 0 ? x : -x;   }   inline int gcd(const int a, const int b) { return b ? gcd(b, a % b) : a; }   inline void getInv(int inv[], const int lim, const int MOD) {     inv[0] = inv[1] = 1;     for (int i = 2; i <= lim; ++i)       inv[i] = 1ll * inv[MOD % i] * (MOD - MOD / i) % MOD;   }   inline long long mulMod(const long long a, const long long b,                           const long long mod) {     return ((a * b - (long long)((long double)a / mod * b + 1e-8) * mod) % mod +             mod) %            mod;   }   const int MAXN = 100000;   const int MAXM = 100000;   const int INF = (1 << 30) - 1;   struct edge {     int to, nxt, c;   } e[MAXM * 2 + 5];   int tail[MAXN + 5], ecnt;   inline void add_edge(const int u, const int v, const int c) {     e[++ecnt] = edge{v, tail[u], c};     tail[u] = ecnt;     e[++ecnt] = edge{u, tail[v], c};     tail[v] = ecnt;   }   int n, m;   inline void Init() {     n = read(1), m = read(1);     int u, v;     char ch[5];     for (signed i = (1), i_end_ = (m); i <= i_end_; ++i) {       scanf( %d %d %s , &u, &v, ch);       add_edge(u, v, ch[0] ==  R );     }   }   int rever[MAXN + 5];   void Clear(const int u) {     rever[u] = -1;     for (int i = tail[u]; i; i = e[i].nxt)       if (rever[e[i].to] != -1) Clear(e[i].to);   }   int Judge(const int u, const int rev, const int goal) {     int sum = rev, ret;     rever[u] = rev;     for (int i = tail[u], v, tore; i; i = e[i].nxt) {       v = e[i].to;       tore = goal ^ e[i].c ^ rev;       if (rever[v] != -1 && rever[v] != tore) return -1;       if (rever[v] == -1) {         ret = Judge(v, tore, goal);         if (ret == -1) return -1;         sum += ret;       }     }     return sum;   }   int ans = INF, memo[MAXN + 5];   signed main() {     Init();     int ans1, ans2, f1, f2;     bool flg;     for (signed t = (0), t_end_ = (1); t <= t_end_; ++t) {       flg = false;       memset(rever, -1, sizeof rever);       for (signed i = (1), i_end_ = (n); i <= i_end_; ++i)         if (rever[i] == -1) {           Clear(i), ans1 = Judge(i, 0, t);           Clear(i), ans2 = Judge(i, 1, t);           if (ans1 == -1 && ans2 == -1) {             flg = true;             break;           }           if (ans2 == -1 || ans1 < ans2) {             Clear(i);             Judge(i, 0, t);           }         }       if (!flg) {         int tot = 0;         for (signed i = (1), i_end_ = (n); i <= i_end_; ++i)           if (rever[i] == 1) ++tot;         if (tot > (n / 2)) {           tot = n - tot;           for (signed i = (1), i_end_ = (n); i <= i_end_; ++i)             rever[i] = !rever[i];         }         if (tot < ans) {           ans = tot;           for (signed i = (1), i_end_ = (n); i <= i_end_; ++i) memo[i] = rever[i];         }       }     }     if (ans == INF)       puts( -1 );     else {       fwrit(ans), putchar(  n );       for (signed i = (1), i_end_ = (n); i <= i_end_; ++i)         if (memo[i]) fwrit(i), putchar(   );       putchar(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   clock_t time_p = clock();   void rtime() {     time_p = clock() - time_p;     cerr <<  Time Taken :   << fixed << (float)(time_p) / CLOCKS_PER_SEC <<   n ;   }   bool isPrime(long long n) {     for (long long i = 2; i * i <= n; ++i) {       if (n % i == 0) {         return false;       }     }     return true;   }   long long factorial(long long n) {     return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);   }   long long power(long long x, long long y) {     long long res = 1;     x = x;     while (y > 0) {       if (y & 1) res = (res * x) % mod;       y = y >> 1;       x = (x * x) % mod;     }     return res % mod;   }   long long ncr(long long n, long long r) {     long long res = 1;     if (r > n) return 0;     if (r > n - r) r = n - r;     for (long long i = 0; i < r; i++) {       res *= (n - i);       res /= (i + 1);     }     return res;   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); }   long long max(long long a, long long b) {     long long ans = a > b ? a : b;     return ans;   }   long long min(long long a, long long b) {     long long ans = a < b ? a : b;     return ans;   }   bool cmp(long long x, long long y) { return x > y; }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       if (n == 2)         cout <<  2 n ;       else if (n % 2 == 0)         cout <<  0 n ;       else         cout <<  1 n ;     }     rtime();   }


#include <bits/stdc++.h>   using namespace std;   int read(int &x) { return scanf( %d , &x); }   int read(int &x, int &y) { return scanf( %d%d , &x, &y); }   int read(int &x, int &y, int &z) { return scanf( %d%d%d , &x, &y, &z); }   int read(long long &x) { return scanf( %lld , &x); }   int read(long long &x, long long &y) { return scanf( %lld%lld , &x, &y); }   int read(double &x) { return scanf( %lf , &x); }   char buff[2000010];   int read(string &s) {     int r = scanf( %s , buff);     s = buff;     return r;   }   int main() {     vector<int> PHI(1000002);     for (int i = 1; i < PHI.size(); ++i) {       PHI[i] = i;     }     for (int i = 2; i < PHI.size(); ++i) {       if (PHI[i] == i) {         for (int j = i; j < PHI.size(); j += i) {           PHI[j] = PHI[j] / i * (i - 1);         }       }     }     int N, K;     read(N, K);     if (K == 1) {       cout << 3 << endl;       return 0;     }     sort(PHI.begin() + 3, PHI.begin() + N + 1);     cout << accumulate(PHI.begin() + 3, PHI.begin() + 3 + K, 2LL) << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline )   #pragma GCC optimize( -fgcse )   #pragma GCC optimize( -fgcse-lm )   #pragma GCC optimize( -fipa-sra )   #pragma GCC optimize( -ftree-pre )   #pragma GCC optimize( -ftree-vrp )   #pragma GCC optimize( -fpeephole2 )   #pragma GCC optimize( -ffast-math )   #pragma GCC optimize( -fsched-spec )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( -falign-jumps )   #pragma GCC optimize( -falign-loops )   #pragma GCC optimize( -falign-labels )   #pragma GCC optimize( -fdevirtualize )   #pragma GCC optimize( -fcaller-saves )   #pragma GCC optimize( -fcrossjumping )   #pragma GCC optimize( -fthread-jumps )   #pragma GCC optimize( -funroll-loops )   #pragma GCC optimize( -fwhole-program )   #pragma GCC optimize( -freorder-blocks )   #pragma GCC optimize( -fschedule-insns )   #pragma GCC optimize( inline-functions )   #pragma GCC optimize( -ftree-tail-merge )   #pragma GCC optimize( -fschedule-insns2 )   #pragma GCC optimize( -fstrict-aliasing )   #pragma GCC optimize( -fstrict-overflow )   #pragma GCC optimize( -falign-functions )   #pragma GCC optimize( -fcse-skip-blocks )   #pragma GCC optimize( -fcse-follow-jumps )   #pragma GCC optimize( -fsched-interblock )   #pragma GCC optimize( -fpartial-inlining )   #pragma GCC optimize( no-stack-protector )   #pragma GCC optimize( -freorder-functions )   #pragma GCC optimize( -findirect-inlining )   #pragma GCC optimize( -frerun-cse-after-loop )   #pragma GCC optimize( inline-small-functions )   #pragma GCC optimize( -finline-small-functions )   #pragma GCC optimize( -ftree-switch-conversion )   #pragma GCC optimize( -foptimize-sibling-calls )   #pragma GCC optimize( -fexpensive-optimizations )   #pragma GCC optimize( -funsafe-loop-optimizations )   #pragma GCC optimize( inline-functions-called-once )   #pragma GCC optimize( -fdelete-null-pointer-checks )   using namespace std;   struct node {     char c;     long long l;     bool operator==(const node &b) const { return (c == b.c) && (l == b.l); }     bool operator<=(const node &b) const { return (c == b.c) && (l <= b.l); }   } a[200010], b[200010];   long long n, m, pi[200010];   long long ans;   void mk(node *a, long long &n) {     long long m = 0;     for (long long i = 0; i < n; i++) {       if (m == 0 || a[m - 1].c != a[i].c)         a[m++] = a[i];       else         a[m - 1].l += a[i].l;     }     n = m;   }   signed main() {     scanf( %lld%lld , &n, &m);     for (long long i = 0; i < n; i++) scanf( %lld-%c , &a[i].l, &a[i].c);     for (long long i = 0; i < m; i++) scanf( %lld-%c , &b[i].l, &b[i].c);     mk(a, n), mk(b, m);     if (m == 1) {       for (long long i = 0; i < n; i++)         if (b[0] <= a[i]) ans += a[i].l - b[0].l + 1;     } else if (m == 2) {       for (long long i = 0; i < n - 1; i++)         if (b[0] <= a[i] && b[1] <= a[i + 1]) ans++;     } else {       pi[1] = 0;       for (long long i = 2; i < m - 1; i++) {         long long j = pi[i - 1];         while (j > 0 && !(b[j + 1] == b[i])) j = pi[j];         if (b[j + 1] == b[i]) j++;         pi[i] = j;       }       for (long long i = 1, j = 0; i < n - 1; i++) {         while (j > 0 && (!(b[j + 1] == a[i]))) j = pi[j];         if (b[j + 1] == a[i]) j++;         if (j == m - 2) {           if (b[0] <= a[i - j] && b[j + 1] <= a[i + 1]) ans++;           j = pi[j];         }       }     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cerr.tie(0);     string s;     long long p = 0, q = 0;     cin >> s;     for (int i = s.size() - 1; i > -1; i--) {       if (s[i] ==  a ) {         p += q;         p = p % 1000000007;         q = (2 * q) % 1000000007;       } else {         q = (q + 1) % 1000000007;       }     }     cout << p;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char w[1555][1555];   int nm[1555][1555];   int n, m;   struct cell {     int x, y;   };   void mark(int x, int y, int c) {     queue<cell> q;     cell T;     T.x = x;     T.y = y;     q.push(T);     while (!q.empty()) {       T = q.front();       q.pop();       if (T.x < 0 || T.x >= n || T.y < 0 || T.y >= m || w[T.x][T.y] ==  #  ||           nm[T.x][T.y] != 0)         continue;       nm[T.x][T.y] = c;       cell W;       W.x = T.x;       W.y = T.y - 1;       q.push(W);       W.x = T.x;       W.y = T.y + 1;       q.push(W);       W.x = T.x + 1;       W.y = T.y;       q.push(W);       W.x = T.x - 1;       W.y = T.y;       q.push(W);     }   }   int kn;   int Sn;   const int M = 1555 * 20;   int fir[1555 * 1555], tov[M], nxt[M], dx[M], dy[M];   int ke;   void add(int x, int y, int Dx, int Dy) {     nxt[++ke] = fir[x];     tov[ke] = y;     fir[x] = ke;     dx[ke] = Dx;     dy[ke] = Dy;     if (ke & 1) add(y, x, -Dx, -Dy);   }   bool u[1555 * 1555];   int vx[1555 * 1555], vy[1555 * 1555];   bool cool = false;   void dfs(int c, int x, int y) {     if (u[c]) {       if (vx[c] != x || vy[c] != y) {         cool = true;       }       return;     }     u[c] = true;     vx[c] = x;     vy[c] = y;     for (int t = fir[c]; t; t = nxt[t]) {       dfs(tov[t], x + dx[t], y + dy[t]);     }   }   int main() {     scanf( %d%d , &n, &m);     cin.ignore();     for (int i = 0; i < n; ++i) {       gets(w[i]);     }     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         if (w[i][j] !=  #  && nm[i][j] == 0) {           mark(i, j, ++kn);         }         if (w[i][j] ==  S ) {           Sn = nm[i][j];         }       }     for (int i = 0; i < n; ++i) {       if (w[i][0] !=  #  && w[i][m - 1] !=  # ) {         add(nm[i][0], nm[i][m - 1], -1, 0);       }     }     for (int i = 0; i < m; ++i) {       if (w[0][i] !=  #  && w[n - 1][i] !=  # ) {         add(nm[0][i], nm[n - 1][i], 0, -1);       }     }     dfs(Sn, 0, 0);     if (cool)       puts( Yes );     else       puts( No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int sz = 1e5 + 50;   map<int, int> prime, mark;   void init() {     prime[2] = 1;     int limit = sqrt(sz) + 1;     for (int i = 3; i <= sz; i += 2) {       if (!mark[i]) {         prime[i] = 1;         if (i <= limit) {           for (int j = i * i; j <= sz; j += i * 2) mark[j] = 1;         }       }     }   }   int main() {     init();     int n, a;     scanf( %d , &n);     int o = 0, t = 0;     while (n--) {       scanf( %d , &a);       a == 1 ? o++ : t++;     }     int sum = 0;     vector<int> v;     while (t || o) {       if (o > 0 && prime[sum + 1]) {         o--;         sum += 1;         v.push_back(1);       } else if (t > 0 && prime[sum + 2]) {         t--;         sum += 2;         v.push_back(2);       } else {         if (t)           sum += 2, t--, v.push_back(2);         else           sum++, o--, v.push_back(1);       }     }     for (auto i : v) printf( %d  , i);     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100 + 7;   const int M = 59;   const int mid = M / 2;   const int mod = 1e9 + 9;   const int inf = 1e6 + 3;   const long long linf = 1ll * inf * inf;   const double pi = acos(-1);   const double eps = 1e-7;   const double ep = 1e-5;   const int maxn = 1e5 + 7;   const double PI = acos(-1);   int C, W, H;   int dp[2][107];   struct matrix {     long long a[N][N];     int n, m;     matrix(int _n, int _m) {       n = _n;       m = _m;       memset(a, 0, sizeof(a));     }     matrix(int _n, int _m, bool itype) {       n = _n;       m = _m;       if (itype) {         for (int i = (1); i < (n + 1); i++) a[i][i] = 1;       }     }     matrix operator*(matrix u) {       matrix c(n, u.m);       for (int i = 1; i <= c.n; i++) {         for (int j = 1; j <= c.m; j++) {           long long tmp = 0;           for (int t = 1; t <= m; t++)             tmp = (tmp + (long long)a[i][t] * u.a[t][j]) % inf;           c.a[i][j] = tmp;         }       }       return c;     }     void print() {       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= m; ++j) printf( %lld  , a[i][j]);         printf(  n );       }     }   };   void solve() {     cin >> C >> W >> H;     matrix b(W + 1, W + 1);     for (int i = (2); i < (W + 2); i++) {       b.a[i - 1][i] = H;     }     for (int i = (1); i < (W + 2); i++) b.a[i][1] = 1;     matrix I(W + 1, W + 1, true);     while (C > 0) {       if (C & 1) {         I = I * b;       }       b = b * b;       C >>= 1;     }     matrix res(1, W + 1);     res.a[1][1] = 1;     res = res * I;     int ans = 0;     for (int i = (1); i < (res.m + 1); i++) ans = (ans + res.a[1][i]) % inf;     cout << ans;   }   int main() {     int T = 1;     for (int i = (1); i < (T + 1); i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int arr[1001];   int main() {     int n, m, c;     cin >> n >> m >> c;     fill(arr, arr + n + 1, -1);     int mid = (c + 1) / 2;     bool done = 0;     for (int j = 0; !done && j < m; j++) {       int x;       cin >> x;       if (x > mid) {         for (int i = n; i >= 1; i--) {           if (arr[i] == -1 || arr[i] < x) {             arr[i] = x;             cout << i << endl;             break;           }         }       } else {         for (int i = 1; i <= n; i++) {           if (arr[i] == -1 || arr[i] > x) {             arr[i] = x;             cout << i << endl;             break;           }         }       }       done = 1;       for (int i = 1; done && i <= n; i++) {         if (arr[i] == -1) {           done = 0;           break;         }         if (i < n && arr[i + 1] == -1) {           done = 0;           break;         }         if (i < n && arr[i] > arr[i + 1]) {           done = 0;           break;         }       }     }     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     unsigned long long a[n], M;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     stack<unsigned long long> s;     M = *max_element(a, a + n);     for (int i = 0; i < n; ++i) {       a[i] = (M - a[i]) % 2;       if (s.empty() || s.top() != a[i])         s.push(a[i]);       else         s.pop();     }     bool ans2 = false;     for (int i = 0; i < n - 1 && !ans2; ++i) {       ans2 = ans2 || (a[i] == a[i + 1]);     }     bool all1 = true, all0 = true;     while (!s.empty()) {       all0 = all0 && (s.top() == 0);       all1 = all1 && (s.top() == 1);       s.pop();     }     bool ans = all0 || all1;     cout << (ans ?  YES  :  NO ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 500 + 5, inf = 0x3f3f3f3f;   namespace network_flow {   struct edge {     int to, nxt, val, cost;   } e[N << 5];   int head[N], cnt = 1, maxflow, vis[N], dis[N], nxt[N];   int s, t;   void add_edge(int x, int y, int z) {     e[++cnt].to = y;     e[cnt].val = z;     e[cnt].nxt = head[x];     head[x] = cnt;   }   void add(int x, int y, int z) {     add_edge(x, y, z);     add_edge(y, x, 0);   }   queue<int> q;   bool spfa() {     memset(dis, 0x3f, sizeof(dis));     dis[s] = 0;     q.push(s);     while (!q.empty()) {       int u = q.front();       q.pop();       vis[u] = 0;       for (int i = head[u]; i; i = e[i].nxt)         if (e[i].val && dis[e[i].to] > dis[u] + 1) {           dis[e[i].to] = dis[u] + 1;           if (!vis[e[i].to]) vis[e[i].to] = 1, q.push(e[i].to);         }     }     return (dis[t]) ^ inf;   }   bool flag[N];   int n;   int dfs(int u, int limit) {     if (u == t) return limit;     int flow = 0;     for (int i = head[u]; i && limit; i = e[i].nxt)       if (e[i].val && dis[e[i].to] == dis[u] + 1) {         int k = dfs(e[i].to, min(limit, e[i].val));         if (k > 0) {           e[i].val -= k;           e[i ^ 1].val += k;           limit -= k;           flow += k;         }       }     if (!flow) dis[u] = inf;     return flow;   }   void Dinic() {     for (int i = 2; i <= cnt; ++i) e[i].val += e[i ^ 1].val, e[i ^ 1].val = 0;     maxflow = 0;     while (spfa()) maxflow += dfs(s, inf);   }   };  // namespace network_flow   int ans[N], ccnt, Ans;   namespace mincut_tree {   struct edge {     int nxt, to, val, vis;   } e[N << 4];   int head[N], cnt = 1;   void add(int x, int y, int z) {     e[++cnt].to = y;     e[cnt].val = z;     e[cnt].nxt = head[x];     head[x] = cnt;     e[++cnt].to = x;     e[cnt].val = z;     e[cnt].nxt = head[y];     head[y] = cnt;   }   int x, y, mn, pos;   void dfs(int u, int fath) {     for (int i = head[u]; i; i = e[i].nxt)       if (e[i].to != fath && e[i].vis == 0) {         if (mn > e[i].val) mn = e[i].val, pos = i, x = u, y = e[i].to;         dfs(e[i].to, u);       }   }   void solve(int u) {     mn = inf;     dfs(u, 0);     if (mn == inf) return ans[++ccnt] = u, void(0);     Ans += mn;     e[pos].vis = e[pos ^ 1].vis = 1;     int a = x, b = y;     solve(a);     solve(b);   }   }  // namespace mincut_tree   int node[N], tmp1[N], tmp2[N];   void build(int l, int r) {     if (l == r) return;     network_flow::s = node[l];     network_flow::t = node[l + 1];     network_flow::Dinic();     int cnt1 = 0, cnt2 = 0;     mincut_tree::add(network_flow::s, network_flow::t, network_flow::maxflow);     for (int i = l; i <= r; ++i)       if (network_flow::dis[node[i]] ^ inf)         tmp1[++cnt1] = node[i];       else         tmp2[++cnt2] = node[i];     for (int i = 1; i <= cnt1; ++i) node[l + i - 1] = tmp1[i];     for (int i = 1; i <= cnt2; ++i) node[l + cnt1 + i - 1] = tmp2[i];     build(l, l + cnt1 - 1);     build(l + cnt1, r);   }   int main() {     int u, v, n, m, val;     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       cin >> u >> v >> val;       network_flow::add(u, v, val);       network_flow::add(v, u, val);     }     for (int i = 1; i <= n; ++i) node[i] = i;     build(1, n);     mincut_tree::solve(1);     cout << Ans << endl;     for (int i = 1; i <= ccnt; ++i) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, i, j, a[100005], l, r;   string s;   int main(int argc, char *argv[]) {     ios_base::sync_with_stdio(0), cin.tie(NULL);     ;     cin >> n;     for (__typeof(i) i = 0; i < n; ++i) {       cin >> a[i];     }     cin >> s;     l = -1000000000;     r = 1000000000;     int cur = 0;     int m = 0;     for (__typeof(i) i = 4; i < n; ++i) {       if (s[i] -  0  != cur) {         if (cur) {           m = INT_MAX;           for (__typeof(j) j = -4; j <= 0; ++j) {             m = min(m, a[i + j]);           }           r = min(r, m - 1);           cur = 0;         } else {           m = INT_MIN;           for (__typeof(j) j = -4; j <= 0; ++j) {             m = max(m, a[i + j]);           }           l = max(l, m + 1);           cur = 1;         }       }     }     cout << l <<     << r << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, j, k, l, x, y, z, m, n, ans;   string s, a;   int ara[10];   int main() {     cin >> a >> s;     for (int i = 0; i < s.size(); i++) {       int x = s[i] -  0 ;       ara[x]++;     }     for (int i = 0; i < a.size(); i++) {       int x = a[i] -  0 ;       for (int j = 9; j > x; j--) {         if (ara[j]) {           ara[j]--;           a[i] =  0  + j;           break;         }       }     }     cout << a << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long int n, k;   bool prime[10000001];   vector<long int> v;   void sieve(long int n) {     prime[0] = false;     prime[1] = false;     long int m = (long int)sqrt(n);     for (long int i = 2; i <= m; i++)       if (prime[i])         for (long int k = i * i; k <= n; k += i) prime[k] = false;   }   int main() {     long int i, j, a, b, c;     scanf( %ld %ld , &n, &k);     memset(prime, true, sizeof(prime));     a = 1000 * 1000;     sieve(a);     for (i = 1; i <= a; i++) {       if (prime[i] == true) {         v.push_back(i);       }     }     if (k == 0 && n == 1) {       printf( 1 );     } else if (n < 2) {       printf( -1 );     } else {       if (n % 2 == 1) {         a = (n - 1) / 2;       } else {         a = n / 2;       }       if (a > k) {         printf( -1 );       } else if (a == k) {         i = 1;         vector<long int>::iterator it;         for (it = v.begin(); it != v.end() && (i <= a); ++it) {           if (*it == 2) {             continue;           } else {             printf( %ld %ld  , *it, *it + 1);             i++;           }         }         if (n % 2 == 1) {           printf( %ld , *it);         }       } else {         b = k - (a - 1);         printf( %ld %ld  , b, 2 * b);         i = 1;         vector<long int>::iterator it;         for (it = v.begin(); it != v.end() && (i < a); ++it) {           if (*it == 2) {             continue;           }           if ((*it == b) || ((*it + 1) == b) || ((*it + 1) == (2 * b))) {             continue;           } else {             printf( %ld %ld  , *it, *it + 1);             i++;           }         }         if (n % 2 == 1) {           while ((*it == b) || ((*it + 1) == b) || ((*it + 1) == (2 * b))) {             ++it;           }           printf( %ld , *it);         }       }     }     return 0;   }


#include <bits/stdc++.h>   const int maxn = 1e5 + 5, lim = 62, maxm = 65;   const long long inf = 1e18;   template <typename T>   inline T min(T a, T b) {     return a < b ? a : b;   }   int n;   long long a[maxn], mod, dp[maxm][maxn];   inline bool Comp(long long a, long long b) { return a > b; }   void radix_sort() {     std::vector<long long> bit[2];     for (int i = 1; i <= n; i++) {       bit[(a[i] & (1ll << (mod - 1))) > 0ll].push_back(a[i]);     }     int cnt = 0;     for (int i = 0; i < bit[1].size(); i++) a[++cnt] = bit[1][i];     for (int i = 0; i < bit[0].size(); i++) a[++cnt] = bit[0][i];   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     std::sort(a + 1, a + n + 1, Comp);     for (int i = n; i >= 1; i--) a[i] = a[1] - a[i];     for (int i = 0; i <= lim; i++)       for (int j = 0; j <= n; j++) dp[i][j] = inf;     dp[0][0] = 0;     for (int i = 0; i < lim; i++) {       mod = i;       if (i) radix_sort();       long long cnt = 0, tot = 0;       mod = 1ll << i;       for (int j = 1; j <= n; j++) cnt += a[j] & mod ? 1 : 0;       for (int j = 0; j <= n; j++) {         tot += a[j] & mod ? 1 : 0;         dp[i + 1][cnt - tot + j] =             min(dp[i + 1][cnt - tot + j], dp[i][j] + tot + (n - j) - (cnt - tot));         dp[i + 1][tot] = min(dp[i + 1][tot], dp[i][j] + j - tot + cnt - tot);       }     }     printf( %lld n , dp[lim][0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 5;   int n;   int s[N], c[N];   map<int, int> a, b;   int main() {     int i;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &s[i]);       c[i] = s[i];     }     printf( YES n );     if (n == 1) {       printf( 0 n%d n , s[0]);       return 0;     }     sort(c, c + n);     int m = (n + 2) / 3;     for (i = 0; i < n; i++) {       if (i < m) {         a[c[i]] = 0;         b[c[i]] = c[i];       } else if (i < m + m) {         a[c[i]] = c[i];         b[c[i]] = 0;       } else {         a[c[i]] = n - (i + 1);         b[c[i]] = c[i] - (n - (i + 1));       }     }     for (i = 0; i < n; i++) {       printf( %d , a[s[i]]);       if (i == n - 1)         printf(  n );       else         printf(   );     }     for (i = 0; i < n; i++) {       printf( %d , b[s[i]]);       if (i == n - 1)         printf(  n );       else         printf(   );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 5;   long long a[maxn];   map<long long, long long> mp, show;   int main() {     long long n, k, ans = 0;     scanf( %lld%lld , &n, &k);     for (int i = 0; i < n; i++) scanf( %lld , a + i);     for (int i = n - 1; i >= 0; i--) {       ans += mp[a[i]];       if (a[i] % k == 0) mp[a[i] / k] += show[a[i] * k];       show[a[i]]++;     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const long double eps = 1e-7;   const int inf = 1000000010;   const long long INF = 10000000000000010LL;   const int mod = 1000000007;   const int MAXN = 200010, LOG = 20;   int n, m, k, u, v, x, y, t, a, b;   long long A[MAXN];   int par[MAXN][LOG];   long long dist[MAXN][LOG];   int ans[MAXN];   vector<int> G[MAXN];   void dfs(int node) {     for (int i = 1; i < LOG; i++) par[node][i] = par[par[node][i - 1]][i - 1];     for (int i = 1; i < LOG; i++)       dist[node][i] =           min(1ll * inf, dist[par[node][i - 1]][i - 1] + dist[node][i - 1]);     for (int v : G[node]) {       dfs(v);       ans[node] += ans[v];     }     ans[par[node][0]]++;     long long v = node, tmp = A[node];     for (int i = LOG - 1; i >= 0; i--)       if (dist[v][i] <= tmp) {         tmp -= dist[v][i];         v = par[v][i];       }     v = par[v][0];     ans[v]--;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> A[i];     for (int i = 2; i <= n; i++) {       cin >> par[i][0] >> dist[i][0];       G[par[i][0]].push_back(i);     }     par[1][0] = 0;     dfs(1);     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t, n, a[100011], sum[100011], ans;   map<long long, long long> mp;   signed main() {     scanf( %lld , &t);     while (t--) {       mp.clear();       scanf( %lld , &n);       memset(a, 0, sizeof a);       memset(sum, 0, sizeof sum);       ans = 0;       for (register long long i = 1; i <= n; ++i) {         a[i] = getchar() -  0 ;         while (a[i] < 0 || a[i] > 9) a[i] = getchar() -  0 ;         a[i] = (a[i]) ? a[i] - 1 : -1;         sum[i] = sum[i - 1] + a[i];       }       mp[0] = 1;       for (register long long i = 1; i <= n; ++i) {         ans += mp[sum[i]];         ++mp[sum[i]];       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     int i, ans, j, t;     int num[2005];     while (scanf( %d%d , &n, &k) != EOF) {       ans = 0;       for (i = 0; i < n; i++) scanf( %d , &num[i]);       for (i = 0; i < n; i++)         for (j = 0; j < n - i - 1; j++)           if (num[j] > num[j + 1]) {             t = num[j];             num[j] = num[j + 1];             num[j + 1] = t;           }       for (i = n - 1; i >= 0; i = i - k) ans += (num[i] - 1) * 2;       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 3e18 + 5;   int N;   long long pt[100005][3];   long long ans[3];   pair<long long, long long> gSeg[4];   void input() {     cin >> N;     for (int i = 0; i < (N); i++) cin >> pt[i][0] >> pt[i][1] >> pt[i][2];   }   inline long long mod2(long long x) { return (x % 2 + 2) % 2; }   bool check(long long v) {     for (int rem = 0; rem < (2); rem++) {       pair<long long, long long> seg[4];       for (int i = 0; i < (4); i++) {         seg[i].first = gSeg[i].first - v;         seg[i].second = gSeg[i].second + v;         if (mod2(seg[i].first) != rem) seg[i].first++;         if (mod2(seg[i].second) != rem) seg[i].second--;       }       int fail = 0;       for (int i = 0; i < (4); i++)         if (seg[i].first > seg[i].second) {           fail = 1;         }       if (fail) continue;       if (seg[0].second < seg[1].first + seg[2].first + seg[3].first) continue;       if (seg[0].first > seg[1].second + seg[2].second + seg[3].second) continue;       long long sum = seg[1].first + seg[2].first + seg[3].first;       for (int i = (1); i <= (3); i++) {         if (sum >= seg[0].first) break;         if (sum + seg[i].second - seg[i].first < seg[0].first) {           sum += seg[i].second - seg[i].first;           seg[i].first = seg[i].second;         } else {           seg[i].first += seg[0].first - sum;           if (mod2(seg[i].first) != rem) seg[i].first++;           if (seg[i].first > seg[i].second) {             seg[i].first--;             sum--;           } else {             break;           }         }       }       ans[0] = (seg[2].first + seg[3].first) / 2;       ans[1] = (seg[1].first + seg[3].first) / 2;       ans[2] = (seg[1].first + seg[2].first) / 2;       assert(mod2(seg[2].first + seg[3].first) == 0);       assert(mod2(seg[1].first + seg[3].first) == 0);       assert(mod2(seg[1].first + seg[2].first) == 0);       return true;     }     return false;   }   void solve() {     for (int i = 0; i < (4); i++) gSeg[i] = pair<long long, long long>(-INF, INF);     for (int i = 0; i < (N); i++) {       long long x = pt[i][0];       long long y = pt[i][1];       long long z = pt[i][2];       gSeg[0].first = max(gSeg[0].first, x + y + z);       gSeg[0].second = min(gSeg[0].second, x + y + z);       gSeg[1].first = max(gSeg[1].first, -x + y + z);       gSeg[1].second = min(gSeg[1].second, -x + y + z);       gSeg[2].first = max(gSeg[2].first, x - y + z);       gSeg[2].second = min(gSeg[2].second, x - y + z);       gSeg[3].first = max(gSeg[3].first, x + y - z);       gSeg[3].second = min(gSeg[3].second, x + y - z);     }     long long l = 0, r = 4e18 + 5;     while (l < r) {       long long m = (l + r) / 2;       if (check(m))         r = m;       else         l = m + 1;     }     assert(check(l));     cout << ans[0] <<     << ans[1] <<     << ans[2] <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     int ts;     cin >> ts;     for (int t = 0; t < (ts); t++) {       input();       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, j, k, sum;   string a;   int main() {     cin >> a;     int l = a.size();     j = 0;     for (i = 0; i < l; i++) {       if (a[i] ==  a ) {         k++;       }     }     if (k > l / 2) {       j = l;     } else {       for (i = l - 1; i > 0; i--) {         if (k > i / 2) {           j = i;           break;         }       }     }     cout << j << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   mt19937 rnf(2106);   const int N = 100005;   bool c[(1 << 22)];   int d[(1 << 22)];   int p[(1 << 22)];   void solv0(int n) {     vector<int> v;     for (int x = 0; x < n; ++x) {       for (int y = x + 1; y < n; ++y) {         for (int z = y + 1; z < n; ++z) {           if (y - x == z - y) {             v.push_back(((1 << x) | (1 << y) | (1 << z)));           }         }       }     }     for (int x = 0; x < (1 << n); ++x) c[x] = false;     queue<int> q;     c[0] = true;     d[0] = 0;     q.push(0);     while (!q.empty()) {       int x = q.front();       q.pop();       for (int i = 0; i < ((int)(v).size()); ++i) {         int h = (x ^ v[i]);         if (!c[h]) {           c[h] = true;           d[h] = d[x] + 1;           p[h] = v[i];           q.push(h);         }       }     }     return;     for (int x = 0; x < (1 << n); ++x) {       if (!c[x]) {         for (int i = 0; i < n; ++i) {           if ((x & (1 << i)))             cout <<  1 ;           else             cout <<  0 ;         }         cout << endl;       }     }     int maxu = 0;     for (int x = 0; x < (1 << n); ++x) {       if (!c[x]) continue;       maxu = max(maxu, d[x]);     }     cout << maxu <<   n ;     for (int x = 0; x < (1 << n); ++x) {       if (!c[x]) continue;       if (maxu == d[x]) {         for (int i = 0; i < n; ++i) {           if ((x & (1 << i)))             cout <<  1 ;           else             cout <<  0 ;         }         cout << endl;         cout << endl;         while (x) {           for (int i = 0; i < n; ++i) {             if ((p[x] & (1 << i)))               cout <<  1 ;             else               cout <<  0 ;           }           cout << endl;           x ^= p[x];         }         return;       }     }   }   void solv6() {     int n = 6;     vector<int> v;     for (int x = 0; x < n; ++x) {       for (int y = x + 1; y < n; ++y) {         for (int z = y + 1; z < n; ++z) {           if (y - x == z - y) {             v.push_back(((1 << x) | (1 << y) | (1 << z)));           }         }         if (x - (y - x) < 0) v.push_back(((1 << x) | (1 << y)));       }       v.push_back((1 << x));     }     for (int x = 0; x < (1 << n); ++x) c[x] = false;     queue<int> q;     c[0] = true;     d[0] = 0;     q.push(0);     while (!q.empty()) {       int x = q.front();       q.pop();       for (int i = 0; i < ((int)(v).size()); ++i) {         int h = (x ^ v[i]);         if (!c[h]) {           c[h] = true;           d[h] = d[x] + 1;           p[h] = v[i];           q.push(h);         }       }     }     return;     for (int x = 0; x < (1 << n); ++x) {       if (!c[x]) {         for (int i = 0; i < n; ++i) {           if ((x & (1 << i)))             cout <<  1 ;           else             cout <<  0 ;         }         cout << endl;       }     }     int maxu = 0;     for (int x = 0; x < (1 << n); ++x) {       if (!c[x]) continue;       maxu = max(maxu, d[x]);     }     cout << maxu <<   n ;     for (int x = 0; x < (1 << n); ++x) {       if (!c[x]) continue;       if (maxu == d[x]) {         for (int i = 0; i < n; ++i) {           if ((x & (1 << i)))             cout <<  1 ;           else             cout <<  0 ;         }         cout << endl;         cout << endl;         while (x) {           for (int i = 0; i < n; ++i) {             if ((p[x] & (1 << i)))               cout <<  1 ;             else               cout <<  0 ;           }           cout << endl;           x ^= p[x];         }         return;       }     }   }   int n;   int a[N];   vector<tuple<int, int, int> > ans;   void ubd(int x, int y, int z) {     assert(x >= 1 && x <= n && y >= 1 && y <= n && z >= 1 && z <= n);     assert(x < y && y < z && (y - x) == (z - y));     ans.push_back(tie(x, y, z));     a[x] ^= 1;     a[y] ^= 1;     a[z] ^= 1;   }   void solv() {     cin >> n;     for (int i = 1; i <= n; ++i) cin >> a[i];     solv6();     while (n >= 14) {       int x = 0;       for (int i = n - 5; i <= n; ++i) {         x += (a[i] * (1 << (i - (n - 5))));       }       while (x) {         vector<int> v;         for (int i = 0; i < 6; ++i) {           if ((p[x] & (1 << i))) v.push_back(n - 5 + i);         }         if (((int)(v).size()) == 3)           ubd(v[0], v[1], v[2]);         else if (((int)(v).size()) == 2)           ubd(v[0] - (v[1] - v[0]), v[0], v[1]);         else           ubd(n - 6 - (v[0] - (n - 6)), n - 6, v[0]);         x ^= p[x];       }       n -= 6;     }     solv0(n);     int x = 0;     for (int i = 1; i <= n; ++i) x += (a[i] * (1 << (i - 1)));     if (!c[x]) {       cout <<  NO n ;       return;     }     while (x) {       vector<int> v;       for (int i = 0; i < n; ++i) {         if ((p[x] & (1 << i))) v.push_back(i + 1);       }       ubd(v[0], v[1], v[2]);       x ^= p[x];     }     for (int i = 1; i <= n; ++i) assert(!a[i]);     cout <<  YES n ;     cout << ((int)(ans).size()) <<   n ;     for (int i = 0; i < ((int)(ans).size()); ++i)       cout << get<0>(ans[i]) <<     << get<1>(ans[i]) <<     << get<2>(ans[i])            <<   n ;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     int tt = 1;     while (tt--) {       solv();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void cp() {     ios ::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   long long power(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = res * x;       y = y >> 1;       x = x * x;     }     return res;   }   int main() {     cp();     {       long long a;       cin >> a;       ;       long long b;       cin >> b;       ;       if (a == b)         cout <<  0 ;       else {         long long y = log2(a ^ b) + 1;         cout << power(2, y) - 1;       }     }     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int first) { cerr << first; }   void __print(long first) { cerr << first; }   void __print(long long first) { cerr << first; }   void __print(unsigned first) { cerr << first; }   void __print(unsigned long first) { cerr << first; }   void __print(unsigned long long first) { cerr << first; }   void __print(float first) { cerr << first; }   void __print(double first) { cerr << first; }   void __print(long double first) { cerr << first; }   void __print(char first) { cerr <<      << first <<     ; }   void __print(const char *first) { cerr <<     << first <<    ; }   void __print(const string &first) { cerr <<     << first <<    ; }   void __print(bool first) { cerr << (first ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &first) {     cerr <<  { ;     __print(first.first);     cerr <<  , ;     __print(first.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &first) {     int f = 0;     cerr <<  { ;     for (auto &i : first) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     long long a[n + 1];     for (long long i = 1; i < n + 1; i++) cin >> a[i];     vector<long long> b;     b.push_back(0), b.push_back(0);     for (long long i = 1; i < n + 1; i++) b.push_back(a[i]);     for (long long i = 1; i < n + 1; i++) b.push_back(a[i]);     ;     vector<long long> dp(b.size());     for (long long i = 2; i < b.size(); i++) dp[i] = dp[i - 2] + b[i];     ;     long long best = 0;     for (long long i = 2; i < b.size(); i++) {       if (i + n - 1 >= b.size()) break;       best = max(best, dp[i + n - 1] - dp[i - 2]);     }     cout << best <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     return b == 0 ? a : gcd(b, a % b);   }   template <class T>   inline T lcm(T a, T b) {     return (a / gcd(a, b)) * b;   }   int main() {     int n;     int d = 210;     cin >> n;     if (n < 3) {       cout << -1 << endl;       return 0;     }     if (n == 3) {       cout << 210 << endl;       return 0;     }     cout << 1;     int m = 1;     for (int i = 0; i < (n - 1); i++) {       m *= 10;       m %= 210;       if (i < n - 4) cout << 0;     }     int r = 210 - m;     if (r < 10)       cout << 00 << r << endl;     else if (r < 100)       cout << 0 << r << endl;     else       cout << r << endl;     return 0;   }


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


#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::deque;   using std::endl;   using std::map;   using std::max;   using std::min;   using std::multiset;   using std::pair;   using std::queue;   using std::set;   using std::sort;   using std::stack;   using std::string;   using std::vector;   int main() {     string a, b, c;     cin >> a >> b >> c;     int dataA[26] = {         0,     };     int dataB[26] = {         0,     };     int dataC[26] = {         0,     };     for (int i = 0; i < a.size(); i++) {       dataA[a[i] -  a ]++;     }     for (int i = 0; i < b.size(); i++) {       dataB[b[i] -  a ]++;     }     for (int i = 0; i < c.size(); i++) {       dataC[c[i] -  a ]++;     }     int cntB = 0;     int cntC = 0;     for (int cnt = 0; cnt <= 100000; cnt++) {       int tempA[26];       for (int i = 0; i < 26; i++) {         tempA[i] = dataA[i];       }       int flag = 1;       for (int i = 0; i < 26; i++) {         long long t = (long long)tempA[i] - (long long)cnt * dataB[i];         tempA[i] -= cnt * dataB[i];         if (t < 0) {           flag = 0;         }       }       if (flag == 0) {         break;       }       int x = 1000000;       for (int i = 0; i < 26; i++) {         if (dataC[i] == 0) continue;         x = max(0, min(x, tempA[i] / dataC[i]));       }       if (cnt + x > cntB + cntC) {         cntB = cnt;         cntC = x;       }     }     for (int i = 0; i < 26; i++) {       dataA[i] -= cntB * dataB[i];       dataA[i] -= cntC * dataC[i];     }     for (int i = 0; i < cntB; i++) {       cout << b;     }     for (int i = 0; i < cntC; i++) {       cout << c;     }     for (int i = 0; i < 26; i++) {       for (int j = 0; j < dataA[i]; j++) printf( %c , i +  a );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   struct EDGE {     int num, next;   } e[MAXN * 2];   int en = 0, start[MAXN];   inline void Add_edge(int p, int q) {     en++;     e[en].num = q;     e[en].next = start[p];     start[p] = en;     en++;     e[en].num = p;     e[en].next = start[q];     start[q] = en;   }   double stp[MAXN], edp[MAXN];   int n;   bool u[MAXN];   int size[MAXN];   double sst[MAXN], pro[MAXN];   void dfs(int p) {     u[p] = true;     size[p] = 1;     sst[p] = stp[p];     for (int i = start[p]; i != 0; i = e[i].next)       if (!u[e[i].num]) {         dfs(e[i].num);         size[p] += size[e[i].num];         sst[p] += sst[e[i].num];         pro[p] += size[e[i].num] * sst[e[i].num];       }     pro[p] += (n - size[p]) * (1 - sst[p]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int p, q;       scanf( %d%d , &p, &q);       Add_edge(p, q);     }     double stps = 0, edps = 0;     for (int i = 1; i <= n; i++) scanf( %lf%lf , &stp[i], &edp[i]);     for (int i = 1; i <= n; i++) {       stps += stp[i];       edps += edp[i];     }     for (int i = 1; i <= n; i++) {       stp[i] /= stps;       edp[i] /= edps;     }     dfs(1);     double ans = 0;     for (int i = 1; i <= n; i++) ans += pro[i] * edp[i];     printf( %.11lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   bool graph[101][101];   bool traversed[101];   void search(int x) {     for (int i = 0; i <= m; i++)       if (graph[x][i])         for (int k = 0; k < n; k++)           if (graph[k][i] && !traversed[k]) {             traversed[k] = true;             search(k);           }   }   int main() {     cin >> n >> m;     int size, lang;     int need = 0;     int all = 0;     for (int i = 0; i < n; i++) {       cin >> size;       if (size == 0) all++;       for (int k = 0; k < size; k++) {         cin >> lang;         graph[i][lang] = true;       }     }     if (all == n)       cout << all << endl;     else {       for (int i = 0; i < n; i++) {         if (!traversed[i]) {           need++;           traversed[i] = true;           search(i);         }       }       cout << need - 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s1(const pair<string, string> &x) { return x.first.substr(0, 3); }   string s2(const pair<string, string> &x) {     return x.first.substr(0, 2) + x.second.substr(0, 1);   }   const int MAXN = 1050;   vector<int> g[MAXN], mt;   int used[MAXN];   bool dfs(const int &v, const int &now) {     if (used[v] == now) return false;     used[v] = now;     for (auto to : g[v]) {       if (mt[to] == -1 || dfs(mt[to], now)) {         mt[to] = v;         return true;       }     }     return false;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n;     cin >> n;     vector<pair<string, string>> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i].first >> a[i].second;     }     map<string, int> str_idx;     map<string, bool> banned;     vector<string> idx_str;     for (char c1 =  A ; c1 <=  Z ; ++c1) {       for (char c2 =  A ; c2 <=  Z ; ++c2) {         for (char c3 =  A ; c3 <=  Z ; ++c3) {           string name =   ;           name += c1;           name += c2;           name += c3;           str_idx[name] = idx_str.size();           idx_str.emplace_back(name);         }       }     }     vector<bool> precalced(n);     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         if (s1(a[i]) == s1(a[j])) {           precalced[i] = precalced[j] = true;         }       }     }     int cnt = 0;     for (int i = 0; i < n; ++i) {       if (precalced[i]) {         string name = s2(a[i]);         if (banned[name]) {           cout <<  NO ;           return 0;         }         ++cnt;         banned[name] = true;       }     }     for (int i = 0; i < n; ++i) {       if (!precalced[i]) {         string name1 = s1(a[i]);         string name2 = s2(a[i]);         if (!banned[name1]) {           g[i].emplace_back(str_idx[name1]);         }         if (!banned[name2]) {           g[i].emplace_back(str_idx[name2]);         }       }     }     mt.resize(30 * 30 * 30, -1);     for (int i = 0; i < n; ++i) {       if (!precalced[i]) dfs(i, i + 1);     }     for (int i = 0; i < 30 * 30 * 30; ++i) {       if (mt[i] != -1) ++cnt;     }     if (cnt == n) {       cout <<  YES n ;       vector<string> ans(n);       for (int i = 0; i < n; ++i) {         if (precalced[i]) ans[i] = s2(a[i]);       }       for (int i = 0; i < 30 * 30 * 30; ++i) {         if (mt[i] != -1) ans[mt[i]] = idx_str[i];       }       for (auto s : ans) cout << s <<   n ;     } else {       cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5;   int vis[N][N][N];   int l[N], r[N];   double get_frac(int x, int y) { return (1.0 * x) / (1.0 * y); }   double dfs(vector<vector<vector<double>>> &dp, int b, int cur, int g, int e,              int n) {     if (cur == n) {       if (g == 0)         return (e > 1) ? 1.0 : 0.0;       else if (g == 1)         return (e > 0) ? 1.0 : 0.0;       return 0.0;     }     if (vis[cur][g][e] == -1) {       vis[cur][g][e] = 0;       double p = 0;       if (g == 0 && r[cur] > b)         p += get_frac(r[cur] - max(b, l[cur] - 1), r[cur] - l[cur] + 1) *              dfs(dp, b, cur + 1, g + 1, e, n);       if (l[cur] <= b && r[cur] >= b)         p += get_frac(1, r[cur] - l[cur] + 1) * dfs(dp, b, cur + 1, g, e + 1, n);       if (l[cur] < b)         p += get_frac(min(r[cur] + 1, b) - l[cur], r[cur] - l[cur] + 1) *              dfs(dp, b, cur + 1, g, e, n);       dp[cur][g][e] = p;     }     return dp[cur][g][e];   }   double solve() {     int n, mn = 1e4 + 5, mx = 0;     double res = 0, sum = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> l[i] >> r[i];       mn = min(mn, l[i]);       mx = max(mx, r[i]);     }     for (int i = mn; i <= mx; i++) {       memset(vis, -1, sizeof(vis));       vector<vector<vector<double>>> dp(           n, vector<vector<double>>(n, vector<double>(n)));       res += 1.0 * i * dfs(dp, i, 0, 0, 0, n);     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(12);     cout << solve() <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long solve() {     long long n;     cin >> n;     string str1, str2;     cin >> str1 >> str2;     long long freq1[26] = {0};     long long freq2[26] = {0};     for (long long i = 0; i < n; i++) {       freq1[str1[i] -  a ]++;       freq2[str2[i] -  a ]++;     }     for (long long i = 0; i < 26; i++) {       if (freq1[i] != freq2[i]) {         cout <<  NO n ;         return 0;       }     }     for (long long i = 0; i < 26; i++) {       if (freq1[i] >= 2) {         cout <<  YES n ;         return 0;       }     }     for (long long i = 0; i < n - 2; i++) {       long long pos = -1;       for (long long j = i; j < n; j++) {         if (str1[i] == str2[j]) {           pos = j;           break;         }       }       long long cnt = 0;       while (pos > i) {         swap(str2[pos], str2[pos - 1]);         cnt++;         pos--;       }       cnt = cnt % 2;       if (cnt == 0)         continue;       else         swap(str2[n - 1], str2[n - 2]);     }     for (long long i = 0; i < n; i++) {       if (str1[i] != str2[i]) {         cout <<  NO n ;         return 0;       }     }     cout <<  YES n ;     return 0;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     ;     long long t = 1;     cin >> t;     while (t-- != 0) {       long long stat = solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; ++i) cin >> v[i];     for (int i = 0; i < n; ++i) {       if (v[i] != i + 1) {         for (int j = n - 1; j >= 0; --j) {           if (v[j] != j + 1) {             reverse(begin(v) + i, begin(v) + j + 1);             for (int k = i; k <= j; ++k) {               if (v[k] != k + 1) goto __bad;             }             cout << i + 1 <<     << j + 1 << endl;             return 0;           }         }       }     }   __bad:     cout <<  0 0 n ;     return 0;   }


#include <bits/stdc++.h>   using lint = long long int;   using pii = std::pair<int, int>;   using std::vector;   int ve[200100];   bool check[200100];   int main(void) {     int N, hol = 0;     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       int temp;       scanf( %d , &temp);       ve[i] = temp;     }     for (int i = 1; i <= N; i++) {       int temp;       scanf( %d , &temp);       hol += temp;     }     int cou = 0;     for (int i = 1; i <= N; i++) {       if (!check[i]) {         int ind = i;         cou++;         while (!check[ind]) {           check[ind] = true;           ind = ve[ind];         }       }     }     int ans = 1 - (hol % 2);     if (cou != 1) {       ans += cou;     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int etf(int n) {     int res = n, i = 2;     while (n > 1) {       if (n % i == 0) {         res -= res / i;         while (n % i == 0) n /= i;       }       ++i;       if (i * i > n) i = n;     }     return res;   }   int main() {     ios::sync_with_stdio(0);     int p;     cin >> p;     cout << etf(p - 1) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   int n, w, a[N];   int main() {     cin >> n >> w;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int lo = 0, hi = w, n_lo = 0, n_hi = w;     for (int i = 0; i < n; i++) {       n_lo += a[i];       n_hi += a[i];       if (n_lo > w || n_hi < 0) return cout << 0 <<   n , 0;       if (n_lo < 0) {         lo += -n_lo;         n_lo = 0;       }       if (n_hi > w) {         hi -= n_hi - w;         n_hi = w;       }     }     cout << (hi - lo + 1) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000010;   struct node {     int v, id;   } MAX[MAXN], MMAX[MAXN];   int n, f[MAXN];   int main() {     scanf( %d , &n);     n++;     MAX[1].v = MMAX[1].v = 0;     MAX[1].id = MMAX[1].id = 1;     for (register int i = 2; i <= n; i++) {       scanf( %d , &f[i]);       MAX[i].v = 0;       MMAX[i].v = 0;       MAX[i].id = MMAX[i].id = i;       int now = i;       while (now) {         if (MAX[f[now]].id == now) {           if (max(MAX[now].v, MMAX[now].v + 1) > MAX[f[now]].v) {             MAX[f[now]].v = max(MAX[now].v, MMAX[now].v + 1);           } else {             break;           }         } else if (MMAX[f[now]].id == now) {           if (max(MAX[now].v, MMAX[now].v + 1) > MAX[f[now]].v) {             swap(MAX[f[now]], MMAX[f[now]]);             MAX[f[now]].v = max(MAX[now].v, MMAX[now].v + 1);           } else if (max(MAX[now].v, MMAX[now].v + 1) > MMAX[f[now]].v) {             MMAX[f[now]].v = max(MAX[now].v, MMAX[now].v + 1);           } else {             break;           }         } else {           if (max(MAX[now].v, MMAX[now].v + 1) > MAX[f[now]].v) {             swap(MAX[f[now]], MMAX[f[now]]);             MAX[f[now]].v = max(MAX[now].v, MMAX[now].v + 1);             MAX[f[now]].id = now;           } else if (max(MAX[now].v, MMAX[now].v + 1) > MMAX[f[now]].v) {             MMAX[f[now]].v = max(MAX[now].v, MMAX[now].v + 1);             MMAX[f[now]].id = now;           } else {             break;           }         }         now = f[now];       }       printf( %d  , MAX[1].v);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[10000001];   int main() {     int n, k = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a + 1, a + n);     while (a[0] <= a[n - 1]) {       a[0]++;       a[n - 1]--;       k++;       sort(a + 1, a + n);     }     cout << k;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   auto t1 = chrono::high_resolution_clock::now();   bool prime[100001];   long long int expo(long long int a, long long int b) {     a = a % 1000000007;     b = b % 1000000007;     if (b == 0) return 1;     if (b % 2)       return ((a % 1000000007) *               (expo((a * a) % 1000000007, b / 2) % 1000000007)) %              1000000007;     return expo((a * a) % 1000000007, b >> 1) % 1000000007;   }   long long int mul(long long int a, long long int b) {     a = a % 1000000007;     b = b % 1000000007;     if (b == 0) return 0;     if (b % 2)       return ((a % 1000000007) +               (mul((a + a) % 1000000007, b / 2) % 1000000007)) %              1000000007;     return mul((a + a) % 1000000007, b >> 1) % 1000000007;   }   bool ispoweroftwo(long long int x) { return x && !(x & (x - 1)); }   long long int xorcal(long long int n) {     if (n % 4 == 0) return n;     if (n % 4 == 1) return 1;     if (n % 4 == 2) return n + 1;     if (n % 4 == 3) return 0;   }   void sieve(long long int n) {     memset(prime, true, sizeof(prime));     prime[0] = false;     prime[1] = false;     for (long long int i = 2; i * i <= n; i++) {       if (prime[i] == true) {         for (long long int j = i * i; j <= n; j += i) {           prime[j] = false;         }       }     }   }   bool isprime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 or n % 3 == 0) return false;     for (long long int i = 5; i * i <= n; i += 6) {       if (n % i == 0 or n % (i + 2) == 0) return false;     }     return true;   }   long long int modinverse(long long int a, long long int m) {     long long int m0 = m;     long long int y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       long long int q = a / m;       long long int t = m;       m = a % m;       a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   long long int gcd(long long int a, long long int b) {     if (a == 0) {       return b;     }     return (b % a, a);   }   long long int power(long long int A, long long int B) {     if (A == 0) return 0;     if (B == 0) return 1;     long long int y;     if (B % 2 == 0) {       y = power(A, B / 2);       y = (y * y) % 1000000007;     } else {       y = A % 1000000007;       y = (y * power(A, B - 1) % 1000000007) % 1000000007;     }     return (long long int)((y + 1000000007) % 1000000007);   }   bool ispalindrome(string s) {     string t = s;     reverse(t.begin(), t.end());     if (t == s) return true;     return false;   }   void binary(long long int a[], long long int n) {     for (long long int i = 64 - 1; i >= 0; i--) {       long long int k = n >> i;       a[i] = k & (long long int)1;     }   }   long long int countBits(long long int n) {     if (n == 0) return 0;     return 1 + countBits(n & (n - 1));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int a, b, c;     cin >> a >> b >> c;     for (long long int i = 0; i <= c; i += a) {       if ((c - i) % b == 0) {         cout <<  Yes  <<   n ;         return 0;       }     }     cout <<  No  <<   n ;     auto t2 = chrono::high_resolution_clock::now();     auto duration = chrono::duration_cast<chrono::milliseconds>(t2 - t1).count();     clog <<  Time taken =   << duration * 1.0 / 1000 <<   seconds  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, l, a, x, y, sum, t[1000009], px, py;     sum = 0;     px = py = 0;     cin >> n >> l >> a;     for (int i = 0; i <= n; i++) {       if (i == n) {         t[i] = l - (px + py);         break;       }       cin >> x >> y;       if (i == 0) {         t[i] = x - 0;         px = x;         py = y;       } else {         t[i] = x - (px + py);       }       px = x;       py = y;     }     for (int i = 0; i <= n; i++) {       if (t[i] >= a) {         sum += (t[i] / a);       }     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void print(vector<long long int> &v) {     long long int n = v.size();     for (long long int i = 0; i < n; i++) cout << v[i] <<    ;     cout <<   n ;     ;     return;   }   vector<long long int> parent(200001);   vector<long long int> size1(200001);   long long int find(long long int a) {     if (a == parent[a]) return a;     return parent[a] = find(parent[a]);   }   void union1(long long int a, long long int b) {     long long int a1 = find(a);     long long int b1 = find(b);     if (a1 == b1) return;     long long int t1 = size1[a1];     long long int t2 = size1[b1];     if (t1 < t2) {       parent[a1] = b1;       size1[b1] += size1[a1];     } else {       parent[b1] = a1;       size1[a1] += size1[b1];     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long int n;     cin >> n;     for (long long int i = 0; i < n + 1; i++) {       parent[i] = i;       size1[i] = 1;     }     vector<string> v(n);     vector<vector<bool> > ar(n, vector<bool>(26, 0));     for (long long int i = 0; i < n; i++) {       cin >> v[i];       long long int p = v[i].length();       for (long long int j = 0; j < p; j++) {         ar[i][v[i][j] -  a ] = 1;       }     }     for (long long int j = 0; j < 26; j++) {       long long int prev = -1;       for (long long int i = 0; i < n; i++) {         if (ar[i][j] == 1) {           if (prev == -1)             prev = i;           else {             union1(prev, i);           }         }       }     }     set<long long int> st;     for (long long int i = 0; i < n; i++) {       st.insert(find(i));     }     cout << st.size() <<   n ;     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     return f == -1 ? ~x + 1 : x;   }   long long n, m;   long long a[4010];   long long ls[4010], rs[4010];   long long stk[4010], top;   void build() {     for (long long i = 1; i <= n; ++i) {       while (top && a[stk[top]] > a[i]) {         rs[stk[top]] = ls[i], ls[i] = stk[top];         --top;       }       if (top) rs[stk[top]] = i;       stk[++top] = i;     }   }   long long sz[4010], dp[4010][4010], tmp[4010];   void dfs(long long x) {     sz[x] = 1;     dp[x][1] = (m - 1) * a[x];     if (ls[x]) {       dfs(ls[x]);       for (long long i = 0; i <= sz[x] + sz[ls[x]]; ++i) tmp[i] = 0;       for (long long i = 0; i <= sz[x]; ++i) {         for (long long j = 0; j <= sz[ls[x]]; ++j) {           tmp[i + j] =               max(tmp[i + j], dp[x][i] + dp[ls[x]][j] - 2 * i * j * a[x]);         }       }       sz[x] += sz[ls[x]];       for (long long i = 0; i <= sz[x]; ++i) dp[x][i] = tmp[i];     }     if (rs[x]) {       dfs(rs[x]);       for (long long i = 0; i <= sz[x] + sz[rs[x]]; ++i) tmp[i] = 0;       for (long long i = 0; i <= sz[x]; ++i) {         for (long long j = 0; j <= sz[rs[x]]; ++j) {           tmp[i + j] =               max(tmp[i + j], dp[x][i] + dp[rs[x]][j] - 2 * i * j * a[x]);         }       }       sz[x] += sz[rs[x]];       for (long long i = 0; i <= sz[x]; ++i) dp[x][i] = tmp[i];     }   }   signed main() {     n = read(), m = read();     for (long long i = 1; i <= n; ++i) a[i] = read();     build();     dfs(stk[1]);     printf( %lld n , dp[stk[1]][m]);   }


#include <bits/stdc++.h>   using namespace std;   long long solve(vector<long long> arr, int index, int currIndex) {     if (currIndex == index) {       return 1;     } else {       return 1 + solve(arr, index, arr[currIndex] - 1);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long testCase;     cin >> testCase;     while (testCase--) {       long long n;       cin >> n;       vector<long long> arr;       for (int i = 0; i < n; i++) {         long long j;         cin >> j;         arr.push_back(j);       }       std::vector<int> dp(n, 0);       for (int i = 0; i < n; i++) {         if (!dp[i]) {           long long currentIndex = arr[i] - 1;           long long ans = 1;           while (currentIndex != i) {             ans++;             currentIndex = arr[currentIndex] - 1;           }           long long pos = arr[i] - 1;           dp[arr[i] - 1] = ans;           while (pos != i) {             pos = arr[pos] - 1;             dp[pos] = ans;           }         }       }       for (int i = 0; i < n; i++) {         cout << dp[i] <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int N, M;   vector<int> g[maxn];   long long out[maxn], in[maxn];   int main() {     cin >> N >> M;     for (int i = 1; i <= N; ++i) {       g[i].clear();       out[i] = in[i] = 0;     }     for (int i = 1; i <= M; ++i) {       int a, b;       cin >> a >> b;       int x = max(a, b), y = min(a, b);       g[y].push_back(x);       ++out[x];       ++in[y];     }     long long ret = 0;     for (int i = 1; i <= N; ++i) {       ret += out[i] * in[i];     }     int Q;     cin >> Q;     cout << ret << endl;     for (int q = 1; q <= Q; ++q) {       int x;       cin >> x;       ret -= out[x] * in[x];       for (int i : g[x]) {         ret -= out[i] * in[i];         --out[i];         ++in[i];         g[i].push_back(x);         ret += out[i] * in[i];         ++out[x];         --in[x];       }       ret += out[x] * in[x];       g[x].clear();       cout << ret << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<long long> > neib;   struct Square {     long long max;     long long diff;     long long size;   };   vector<long long> a;   vector<Square> stat;   vector<int> color;   void dfs(int u) {     color[u] = 1;     stat[u].max += a[u];     if (neib[u].size() == 1 && u != 0) {       stat[u].max = a[u];       stat[u].diff = 0;       stat[u].size = 1;       return;     }     for (auto to : neib[u]) {       if (color[to] == 1) {         continue;       }       dfs(to);       stat[u].size += stat[to].size;       stat[u].max += stat[to].max;     }   }   int main() {     cin.tie(0);     ios_base::sync_with_stdio(false);     int n;     cin >> n;     neib.resize(n);     a.resize(n);     stat.resize(n);     color.resize(n, 0);     for (long long i = 0; i < (long long)n - 1; i++) {       int v;       cin >> v;       neib[i + 1].push_back(v - 1);       neib[v - 1].push_back(i + 1);     }     for (long long i = 0; i < (long long)n; i++) {       cin >> a[i];     }     if (n == 2) {       cout << a[0] + a[1];     } else {       dfs(0);       long long ans = -1;       for (long long i = 0; i < (long long)n; i++) {         long long t = (stat[i].max + stat[i].size - 1) / stat[i].size;         ans = max(ans, t);       }       cout << ans;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int id[105];   int A[105];   int B[105];   long long dp[77][77];   bool check(int left, int right, int pos1, int pos2) {     for (int i = 0; i < k; i++) {       if (A[i] == pos1) {         if (B[i] == pos2 && id[i] == 1) return false;         if (B[i] <= left || B[i] >= right) {           return false;         }       } else if (A[i] == pos2) {         if (B[i] == pos1 && id[i] == 1) return false;         if (B[i] <= left || B[i] >= right) {           return false;         }       } else if (B[i] == pos1) {         if (A[i] == pos2 && id[i] == 1) return false;         if (A[i] <= left || A[i] >= right) {           if (id[i] == 0) return false;         }       } else if (B[i] == pos2) {         if (A[i] == pos1 && id[i] == 1) return false;         if (A[i] <= left || A[i] >= right) {           if (id[i] == 0) return false;         }       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> k;     for (int i = 0; i < k; i++) {       string s;       cin >> A[i] >> s >> B[i];       if (s ==  < ) {         id[i] = 1;       } else if (s ==  > ) {         id[i] = 1;         swap(A[i], B[i]);       } else if (s ==  = ) {         id[i] = 0;       } else if (s ==  <= ) {         id[i] = 2;       } else {         id[i] = 2;         swap(A[i], B[i]);       }     }     dp[0][2 * n + 1] = 1;     for (int i = 0; i <= 2 * n - 2; i++) {       for (int j = 2 * n + 1; j >= i + 3; j--) {         long long x = dp[i][j];         if (x == 0) continue;         if (j - i > 3 && check(i, j, i + 1, i + 2)) dp[i + 2][j] += x;         if (check(i, j, i + 1, j - 1)) dp[i + 1][j - 1] += x;         if (j - i > 3 && check(i, j, j - 2, j - 1)) dp[i][j - 2] += x;       }     }     long long answer = 0;     for (int i = 1; i < 2 * n; i++) {       answer += dp[i][i + 1];     }     cout << answer << endl;   }


#include <bits/stdc++.h>   using namespace std;   void imp() {     cout << 0 << endl;     exit(0);   }   int n, m, q;   int LCA[20][20];   vector<pair<int, int> > E;   bool mat[20][20];   int mat2[20];   int Count[20][20];   int Bio[20];   int CheckDFS(int id, int p) {     if (Bio[id] == 1) imp();     if (Bio[id] == 2) return Count[id][p];     Bio[id] = 1;     int &r = Count[id][p];     for (int i = (int)(0); i < (int)(n); ++i)       if (mat[id][i] && i != p) r += CheckDFS(i, id);     Bio[id] = 2;     return r;   }   map<pair<int, int>, int> M;   unordered_map<int, int> M2;   int Has[20];   const int None = -1;   int LOW[1 << 13];   int low(int bit) {     if (bit == 0) return -1;     int cnt = 0;     while (bit % 2 == 0) ++cnt, bit >>= 1;     return cnt;   }   bitset<20> CANT[1 << 13];   long long dp(int id, int bit, bool ch = true) {     static long long memo[20][1 << 13][2];     static bool bio[20][1 << 13][2];     long long &R = memo[id][bit][ch];     if (bio[id][bit][ch]++) return R;     R = 0;     if (M2.count(bit))       if (M2[bit] != id) return R = 0;     if (ch)       if ((Has[id] & bit) != Has[id]) return R = 0;     if (CANT[bit][id]) return R = 0;     if (bit == 0) return R = 1;     int bit2 = (bit & mat2[id]);     if (!bit2) {       bit2 = bit;       int t = LOW[bit];       do {         if ((bit2 >> t) & 1) {           if (M.count({bit, bit2})) {             int bl = M[{bit, bit2}];             if (bl != None && ((bit2 >> bl) & 1))               R += dp(bl, bit2 ^ (1 << bl)) * dp(id, bit ^ bit2, false);           } else             for (int i = (int)(0); i < (int)(n); ++i)               if ((bit2 >> i) & 1) {                 R += dp(i, bit2 ^ (1 << i)) * dp(id, bit ^ bit2, false);               }         }         bit2 = (bit & (bit2 - 1));       } while (bit2 != bit);       return R;     }     int t = (1 << LOW[bit2]);     int bit3 = bit;     do {       if ((bit2 & bit3) == t)         if (!M.count({bit, bit3}) || M[{bit, bit3}] == LOW[bit2]) {           R += dp(LOW[bit2], bit3 ^ t) * dp(id, bit ^ bit3, false);         }       bit3 = (bit & (bit3 - 1));     } while (bit3 != bit);     return R;   }   void AddEdge(int u, int v) {     for (int bit = (int)(0); bit < (int)(1 << n); ++bit) {       int bit2 = bit;       do {         if (((bit >> u) & 1) && ((bit >> v) & 1))           if (((bit2 >> u) & 1) && !((bit2 >> v) & 1)) {             if (!M.count({bit, bit2})) M[{bit, bit2}] = v;             if (M[{bit, bit2}] != v) M[{bit, bit2}] = None;           }         bit2 = (bit & (bit2 - 1));       } while (bit2 != bit);     }   }   void AddLCA(int a, int b, int c) {     if (a == b && a != c) imp();     if (a == b) return;     if (c != a) Has[c] |= (1 << a);     if (c != b) Has[c] |= (1 << b);     for (int bit = (int)(0); bit < (int)(1 << n); ++bit) {       if (((bit >> a) & 1) && ((bit >> b) & 1) && !((bit >> c) & 1)) {         if (!M2.count(bit)) M2[bit] = c;         if (M2[bit] != c) M2[bit] = None;       }       if (((bit >> a) & 1) && !((bit >> b) & 1)) {         if (b != c) CANT[bit][b] = 1;       }       if (((bit >> b) & 1) && !((bit >> a) & 1)) {         if (a != c) CANT[bit][a] = 1;       }     }   }   int main() {     memset(LCA, -1, sizeof LCA);     for (int i = (int)(0); i < (int)(1 << 13); ++i) LOW[i] = low(i);     cin >> n >> m >> q;     for (int i = (int)(0); i < (int)(m); ++i) {       int u, v;       cin >> u >> v, --u, --v;       E.push_back({u, v});       AddEdge(u, v);       AddEdge(v, u);       mat[u][v] = mat[v][u] = true;       mat2[u] |= (1 << v);       mat2[v] |= (1 << u);     }     for (int i = (int)(0); i < (int)(q); ++i) {       int a, b, c;       cin >> a >> b >> c, --a, --b, --c;       if (LCA[a][b] != -1 && LCA[a][b] != c) imp();       LCA[a][b] = LCA[b][a] = c;       AddLCA(a, b, c);     }     for (int i = (int)(0); i < (int)(n); ++i) {       memset(Bio, 0, sizeof Bio);       CheckDFS(i, i);     }     cout << dp(0, (1 << n) - 2) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> vc;       vc.clear();       for (int i = 1; i <= sqrt(n); i++) {         if (n / i != i) vc.push_back(n / i);       }       int rt = sqrt(n);       cout << rt + vc.size() + 1 << endl;       cout << 0 <<    ;       for (int i = 1; i <= sqrt(n); i++) {         cout << i <<    ;       }       for (int i = vc.size() - 1; i >= 0; i--) cout << vc[i] <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> XandY, XXX, YYY;   int NOseg;   int query(int x, int y) {     cout << 0 <<     << x <<     << y << endl;     int ret;     cin >> ret;     return ret;   }   void SOLVE(int l, int r) {     if (l > r) return;     int mid = (l + r) / 2;     int x = query(mid, mid);     if (x == 0)       XandY.push_back(mid), x = 1;     else       NOseg = mid;     SOLVE(l, mid - x);     SOLVE(mid + x, r);   }   void solve() {     SOLVE(-100000000, 100000000);     for (int k : XandY) {       if (query(NOseg, k) == 0) YYY.push_back(k);       if (query(k, NOseg) == 0) XXX.push_back(k);     }   }   int main() {     solve();     cout <<  1   << XXX.size() <<     << YYY.size() << endl;     for (int x : XXX) cout << x <<    ;     cout << endl;     for (int y : YYY) cout << y <<    ;     cout << endl;   }


#include <bits/stdc++.h>   const int N = 60;   int G[N][N], n, m, top;   std::vector<int> v[500000];   inline void out() {     puts(  );     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         printf( %d  , G[i][j]);       }       puts(  );     }     puts(  );     return;   }   inline int id(int x, int y) { return (x - 1) * m + y; }   inline bool check() {     return G[n - 1][m - 1] == id(n - 1, m - 1) && G[n - 1][m] == id(n - 1, m) &&            G[n][m - 1] == id(n, m - 1) && G[n][m] == id(n, m);   }   inline void Cir(int x, int y, int f) {     if (f == 0) {       ++top;       v[top].push_back(G[x][y]);       v[top].push_back(G[x][y + 1]);       v[top].push_back(G[x + 1][y + 1]);       v[top].push_back(G[x + 1][y]);       int t = G[x][y];       G[x][y] = G[x + 1][y];       G[x + 1][y] = G[x + 1][y + 1];       G[x + 1][y + 1] = G[x][y + 1];       G[x][y + 1] = t;     } else {       ++top;       v[top].push_back(G[x][y]);       v[top].push_back(G[x + 1][y]);       v[top].push_back(G[x + 1][y + 1]);       v[top].push_back(G[x][y + 1]);       int t = G[x][y];       G[x][y] = G[x][y + 1];       G[x][y + 1] = G[x + 1][y + 1];       G[x + 1][y + 1] = G[x + 1][y];       G[x + 1][y] = t;     }     return;   }   inline void Move(int x, int y, int tx, int ty) {     if (tx == n) {       while (x != tx) {         if (y == m) {           Cir(x, y - 1, 0);           x++;         } else {           Cir(x, y, 1);           x++;         }       }       while (y != ty) {         Cir(x - 1, y - 1, 0);         y--;       }     } else {       if (x == n) {         if (y == m) {           Cir(x - 1, y - 1, 1);           x--;         } else {           Cir(x - 1, y, 0);           x--;         }       }       while (y != ty) {         if (y < ty) {           Cir(x, y, 0);           y++;         } else {           Cir(x, y - 1, 1);           y--;         }       }       while (x != tx) {         Cir(x - 1, y, 0);         x--;       }     }     return;   }   inline void getPos(int &i, int &j, int t) {     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         if (G[i][j] == t) {           return;         }       }     }     return;   }   inline void SwapDown() {     Cir(n - 1, m - 1, 0);     Cir(n - 1, m - 2, 0);     ++top;     v[top].push_back(G[n - 1][m - 2]);     v[top].push_back(G[n][m - 2]);     v[top].push_back(G[n][m - 1]);     v[top].push_back(G[n][m]);     v[top].push_back(G[n - 1][m]);     v[top].push_back(G[n - 1][m - 1]);     int t = G[n - 1][m - 2];     G[n - 1][m - 2] = G[n - 1][m - 1];     G[n - 1][m - 1] = G[n - 1][m];     G[n - 1][m] = G[n][m];     G[n][m] = G[n][m - 1];     G[n][m - 1] = G[n][m - 2];     G[n][m - 2] = t;     return;   }   inline void SwapUp() {     Cir(n - 1, m - 1, 1);     Cir(n - 1, m - 2, 1);     ++top;     v[top].push_back(G[n - 1][m - 2]);     v[top].push_back(G[n - 1][m - 1]);     v[top].push_back(G[n - 1][m]);     v[top].push_back(G[n][m]);     v[top].push_back(G[n][m - 1]);     v[top].push_back(G[n][m - 2]);     int t = G[n - 1][m - 2];     G[n - 1][m - 2] = G[n][m - 2];     G[n][m - 2] = G[n][m - 1];     G[n][m - 1] = G[n][m];     G[n][m] = G[n - 1][m];     G[n - 1][m] = G[n - 1][m - 1];     G[n - 1][m - 1] = t;     return;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &G[i][j]);       }     }     int x, y;     for (int i = 1; i <= n - 2; i++) {       for (int j = 1; j <= m - 2; j++) {         getPos(x, y, id(i, j));         Move(x, y, i, j);       }       getPos(x, y, i * m);       Move(x, y, i, m - 1);       getPos(x, y, i * m - 1);       if (x == i && y == m) {         Cir(x, y - 1, 0);         Cir(x + 1, y - 1, 0);         Cir(x, y - 1, 1);         getPos(x, y, i * m - 1);       }       Move(x, y, i + 1, m - 1);       Cir(i, m - 1, 0);     }     for (int i = 1; i <= m - 2; i++) {       getPos(x, y, id(n - 1, i));       Move(x, y, n, i);       getPos(x, y, id(n, i));       if (x == n - 1 && y == i) {         Cir(x, y, 0);         Cir(x, y + 1, 0);         Cir(x, y, 1);       }       getPos(x, y, id(n, i));       Move(x, y, n, i + 1);       Cir(n - 1, i, 0);     }     int xx, yy;     getPos(x, y, id(n - 1, m - 1));     getPos(xx, yy, id(n - 1, m));     if (abs(x - xx) + abs(y - yy) != 1) {       SwapDown();     }     if (x == n && xx == n) {       Cir(n - 1, m - 1, 0);       Cir(n - 1, m - 1, 0);     }     getPos(x, y, id(n - 1, m - 1));     getPos(xx, yy, id(n - 1, m));     if (x != xx) {       Cir(n - 1, m - 1, y == m);     }     if (G[n][m - 1] > G[n][m]) {       SwapDown();     }     if (G[n - 1][m - 1] > G[n - 1][m]) {       SwapUp();     }     printf( %d n , top);     for (int i = 1; i <= top; i++) {       int len = v[i].size();       printf( %d  , len);       for (int j = 0; j < len; j++) {         printf( %d  , v[i][j]);       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   string s, p;   long long bin[34][34];   void read() {     cin >> n;     for (int i = 0; i <= 30; i++) {       bin[i][0] = bin[i][i] = 1;       for (int j = 1; j < i; j++) {         bin[i][j] = bin[i - 1][j - 1] + bin[i - 1][j];       }     }   }   void solve() {     string res =   ;     for (int i = 30; i >= 9; i--) {       while (n >= bin[i][9]) {         n -= bin[i][9];         res +=  b ;       }       res +=  a ;     }     cout <<  aaaaaaaa ;     for (int i = res.length() - 1; i >= 0; i--) cout << res[i];     cout <<   aaaaaaaaab n ;   }   int main() {     std::ios::sync_with_stdio(false);     read();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c, d, e, f;   void read() { cin >> a >> b >> c >> d >> e >> f; }   void solve() {     int res = 0;     res += (a + b + f) * (a + b + f);     res -= f * f;     res -= b * b;     res -= d * d;     cout << res << endl;   }   int main() {     read();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     int n = 8;     bool ww = 1;     int con = 0;     while (n--) {       string s;       cin >> s;       bool tb = 1;       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  W ) {           tb = 0;         }       }       if (tb == 0 && ww == 1) {         for (int i = 0; i < s.size(); i++) {           if (s[i] ==  B ) {             con++;           }         }         ww = 0;       } else if (tb) {         con++;       }     }     cout << con;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T& x) {     char c;     bool f = 0;     while ((c = getchar()) <  0  ||  9  < c) f |= (c ==  - );     for (x = (c ^ 48);  0  <= (c = getchar()) && c <=  9 ;          x = (x << 1) + (x << 3) + (c ^ 48))       ;     if (f) x = -x;   }   template <class T>   inline T read(const T sample) {     T x = 0;     char c;     bool f = 0;     while ((c = getchar()) <  0  ||  9  < c) f |= (c ==  - );     for (x = (c ^ 48);  0  <= (c = getchar()) && c <=  9 ;          x = (x << 1) + (x << 3) + (c ^ 48))       ;     return f ? -x : x;   }   template <class T>   void fwrit(const T x) {     if (x < 0) return (void)(putchar( - ), fwrit(-x));     if (x > 9) fwrit(x / 10);     putchar(x % 10 ^ 48);   }   template <class T>   inline T Max(const T x, const T y) {     return x > y ? x : y;   }   template <class T>   inline T Min(const T x, const T y) {     return x < y ? x : y;   }   template <class T>   inline T fab(const T x) {     return x > 0 ? x : -x;   }   inline int gcd(const int a, const int b) { return b ? gcd(b, a % b) : a; }   inline void getInv(int inv[], const int lim, const int MOD) {     inv[0] = inv[1] = 1;     for (int i = 2; i <= lim; ++i)       inv[i] = 1ll * inv[MOD % i] * (MOD - MOD / i) % MOD;   }   inline long long mulMod(const long long a, const long long b,                           const long long mod) {     return ((a * b - (long long)((long double)a / mod * b + 1e-8) * mod) % mod +             mod) %            mod;   }   const int MAXN = 100;   const int MAXM = 100;   int n, m, a[MAXN + 5][MAXM + 5];   int x[MAXN + 5], y[MAXN + 5];   vector<int> tx, ty;   inline void Init() {     n = read(1), m = read(1);     for (signed i = (1), i_end_ = (n); i <= i_end_; ++i)       for (signed j = (1), j_end_ = (m); j <= j_end_; ++j) {         a[i][j] = read(1);         x[i] += a[i][j], y[j] += a[i][j];       }     for (signed i = (1), i_end_ = (n); i <= i_end_; ++i)       if (x[i] < 0) tx.push_back(i);     for (signed j = (1), j_end_ = (m); j <= j_end_; ++j)       if (y[j] < 0) ty.push_back(j);   }   bool opx[MAXN + 5], opy[MAXN + 5];   inline void solve() {     int px, py;     while (tx.size() + ty.size() > 0) {       while (!tx.empty()) {         px = tx.back();         tx.pop_back();         x[px] *= -1;         opx[px] ^= 1;         for (signed j = (1), j_end_ = (m); j <= j_end_; ++j) {           y[j] -= a[px][j];           a[px][j] *= -1;           y[j] += a[px][j];         }       }       ty.clear();       for (signed j = (1), j_end_ = (m); j <= j_end_; ++j)         if (y[j] < 0) ty.push_back(j);       while (!ty.empty()) {         py = ty.back();         ty.pop_back();         y[py] *= -1;         opy[py] ^= 1;         for (signed i = (1), i_end_ = (n); i <= i_end_; ++i) {           x[i] -= a[i][py];           a[i][py] *= -1;           x[i] += a[i][py];         }       }       tx.clear();       for (signed i = (1), i_end_ = (n); i <= i_end_; ++i)         if (x[i] < 0) tx.push_back(i);     }   }   inline void writAns() {     int tot = 0;     for (signed i = (1), i_end_ = (n); i <= i_end_; ++i)       if (opx[i]) ++tot;     fwrit(tot);     for (signed i = (1), i_end_ = (n); i <= i_end_; ++i)       if (opx[i]) printf(  %d , i);     putchar(  n );     tot = 0;     for (signed j = (1), j_end_ = (m); j <= j_end_; ++j)       if (opy[j]) ++tot;     fwrit(tot);     for (signed j = (1), j_end_ = (m); j <= j_end_; ++j)       if (opy[j]) printf(  %d , j);     putchar(  n );   }   signed main() {     Init();     solve();     writAns();     return 0;   }