#include <bits/stdc++.h>   using namespace std;   const int N = 205, M = N * N;   using ll = long long;   int n, a[N][N];   struct Edge {     int v, nxt;     ll w, cw;   } e[M << 2];   int head[M], ptr;   void add_edge(int uu, int vv) {     e[ptr] = {vv, head[uu], 1, 0};     head[uu] = ptr++;     e[ptr] = {uu, head[vv], 1, 0};     head[vv] = ptr++;   }   int ss[M], tt[M];   bool vis[M];   bool push(int pos, int fl) {     if (tt[pos] && fl == 1) return 1;     if (ss[pos] && fl == -1) return 1;     vis[pos] = 1;     for (int i = head[pos]; i != -1; i = e[i].nxt) {       int v = e[i].v;       if (fl == 1 && e[i].cw == 1) continue;       if (fl == -1 && e[i].cw != -1) continue;       if (vis[v]) continue;       if (push(v, fl)) {         ++e[i].cw;         --e[i ^ 1].cw;         return 1;       }     }     return 0;   }   inline int id(int x, int y) { return (x - 1) * n + y; }   vector<pair<int, int>> v;   int main() {     ios::sync_with_stdio(false);     cin >> n;     memset(head, -1, sizeof(head));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) cin >> a[i][j];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         if (a[i][j] == -1) continue;         if (i + 1 <= n && a[i + 1][j] >= 0) add_edge(id(i, j), id(i + 1, j));         if (j + 1 <= n && a[i][j + 1] >= 0) add_edge(id(i, j), id(i, j + 1));         if (a[i][j] > 0) {           tt[id(i, j)] = 1;           v.push_back({a[i][j], id(i, j)});         }       }     sort(v.begin(), v.end());     int flow = 0;     ll ans = 0;     for (int i = 0; i < int(v.size()) - 1; i++) {       int pos = v[i].second;       memset(vis, 0, sizeof(vis));       while (push(pos, -1)) --flow, memset(vis, 0, sizeof(vis));       tt[pos] = 0;       ss[pos] = 1;       memset(vis, 0, sizeof(vis));       for (int j = 0; j <= i; j++)         if (!vis[v[j].second])           while (push(v[j].second, 1)) ++flow, memset(vis, 0, sizeof(vis));       ans += ll(v[i + 1].first - v[i].first) * flow;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string A, B;     int ma = 0;     cin >> A >> B;     for (char &ch : A) ma = max(ma, ch -  0 );     for (char &ch : B) ma = max(ma, ch -  0 );     ma++;     int a = 0, b = 0;     for (char &ch : A) {       a = a * ma + ch -  0 ;     }     for (char &ch : B) {       b = b * ma + ch -  0 ;     }     a += b;     int ans = 0;     while (a) ans++, a /= ma;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, ar[11][100005];   int rev[11][100005];   long long mx(int start) {     int val = ar[0][start];     for (int tmp = 0; tmp < n; ++tmp) {       for (int row = 1; row < m; ++row) {         int col = rev[row][val];         if (col + tmp >= n) {           return tmp;         }         int curVal = ar[row][col + tmp];         int val2 = ar[0][start + tmp];         if (curVal != val2) {           return tmp;         }       }     }     return n;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; ++i) {       for (int j = 0; j < n; ++j) {         scanf( %d , ar[i] + j);         rev[i][ar[i][j]] = j;       }     }     long long ans = 0;     for (int i = 0; i < n;) {       long long mxi = mx(i);       ans += (mxi * (mxi + 1) / 2ll);       i += mxi;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 6e5 + 5, mod = 998244353;   vector<int> num;   long long A[N];   int a[N];   long long sumup = 0, sumdown = 0;   long long qpow(long long a, long long b) {     long long c = 1;     while (b) {       if (b & 1) c = (a * c) % mod;       b >>= 1;       a = (a * a) % mod;     }     return c;   }   long long inv(long long x) { return qpow(x, mod - 2); }   int main() {     int n;     cin >> n;     n <<= 1;     A[0] = 1;     for (int i = 1; i <= n; i++) A[i] = (A[i - 1] * i) % mod;     for (int i = 1; i <= n; i++) cin >> a[i];     long long ans = 0;     sort(a + 1, a + n + 1);     for (int i = 1; i <= n / 2; i++) ans -= a[i];     for (int i = n / 2 + 1; i <= n; i++) ans += a[i];     ans = (ans % mod * A[n] % mod * inv(A[n / 2]) % mod * inv(A[n / 2])) % mod;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     x = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     x *= f;   }   const int N = 6666;   const double eps = 1e-9;   int n, m, a[N], b[N];   void Get(double &x, int y) { x -= (double)(x / y); }   int main() {     read(n);     read(m);     for (register int i = 1; i <= n; i++) read(a[i]);     for (register int i = 1; i <= n; i++) read(b[i]);     double l = 0, r = 1e9, res = 2e9;     for (register int t = 70; t >= 1; t--) {       double mid = (l + r) / 2, now = m + mid;       for (register int i = 1; i <= n; i++)         Get(now, a[i]), Get(now, b[i < n ? i + 1 : 1]);       if (now > m - eps)         res = mid, r = mid;       else         l = mid;     }     if (res > 1e9 + eps)       puts( -1 );     else       printf( %.9lf , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   int n, m, q;   long long add[510], a[510][510], dp[510][510], gox[510][510], goy[510][510];   vector<pair<int, int> > vx[510][510], vy[510][510];   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 0; i < q; i++) {       int x, y, t, d, e;       scanf( %d%d%d%d%d , &x, &y, &d, &t, &e);       if (x + y >= t && (x + y - t) % 4 == 0) {         a[x][y] += e;         if (x + y + d >= t && (x + y + d - t) % 4 == 2)           vx[x][y].push_back({x + d, e});         else           vx[x][y].push_back({n, e});         if (x + y + d >= t && (x + y + d - t) % 4 == 3)           vy[x][y].push_back({y + d, e});         else           vy[x][y].push_back({m, e});       }       if (x + y >= t && (x + y - t) % 4 == 1) {         a[x + d][y - d] += e;         vx[x + d][y - d].push_back({n, e});         if (x + y + d >= t && (x + y + d - t) % 4 == 2)           vy[x + d][y - d].push_back({y, e});         else           vy[x + d][y - d].push_back({m, e});       }       if (x + y + d >= t && (x + y + d - t) % 4 == 2) {         a[x + d][y] += e;         vx[x + d][y].push_back({n, e});         vy[x + d][y].push_back({m, e});       }       if (x + y + d >= t && (x + y + d - t) % 4 == 3) {         a[x][y + d] += e;         vx[x][y + d].push_back({n, e});         vy[x][y + d].push_back({m, e});       }     }     for (int x = 0; x < n; x++) {       for (int y = 0; y < m; y++) {         dp[x][y] = INF;         {           long long cur = 0;           for (auto it : vx[x][y]) {             cur += it.second;             add[it.first] += it.second;           }           for (int k = x; k <= n; k++) {             cur -= add[k];             gox[y][k] += cur;             add[k] = 0;           }         }         {           long long cur = 0;           for (auto it : vy[x][y]) {             cur += it.second;             add[it.first] += it.second;           }           for (int k = y; k <= m; k++) {             cur -= add[k];             goy[k][x] += cur;             add[k] = 0;           }         }       }     }     dp[0][0] = a[0][0];     for (int x = 0; x < n; x++) {       for (int y = 0; y < m; y++) {         dp[x][y] -= a[x][y];         for (int k = x + 1; k < n; k++)           dp[k][y] = min(dp[k][y], dp[x][y] + gox[y][k]);         for (int k = y + 1; k < m; k++)           dp[x][k] = min(dp[x][k], dp[x][y] + goy[k][x]);         {           long long cur = 0;           for (auto it : vx[x][y]) {             cur += it.second;             add[it.first] += it.second;           }           for (int k = x; k <= n; k++) {             cur -= add[k];             gox[y][k] -= cur;             add[k] = 0;           }         }         {           long long cur = 0;           for (auto it : vy[x][y]) {             cur += it.second;             add[it.first] += it.second;           }           for (int k = y; k <= m; k++) {             cur -= add[k];             goy[k][x] -= cur;             add[k] = 0;           }         }       }     }     printf( %lld , dp[n - 1][m - 1]);     return 0;   }


#include <bits/stdc++.h>   int main() {     int h, w, bh, bw, th, tw;     long long ar, ba;     bh = bw = ba = 0;     scanf( %d %d , &h, &w);     int tmp;     for (int i = 30; i >= 0; i--) {       tmp = (1 << i);       if (tmp <= w) {         long long x = (long long)tmp * 8;         long long y = (long long)tmp * 125;         if (x % 10 != 0)           x = x / 10 + 1;         else           x = x / 10;         y /= 100;         if (y <= h) {           th = y;           tw = tmp;           ar = (long long)th * (long long)tw;           if (ar > ba || ar == ba && th > bh) {             bh = th;             bw = tw;             ba = (long long)bh * (long long)bw;           }         } else if (x <= h) {           th = h;           tw = tmp;           ar = (long long)th * (long long)tw;           if (ar > ba || ar == ba && th > bh) {             bh = th;             bw = tw;             ba = (long long)bh * (long long)bw;           }         }       }     }     for (int i = 30; i >= 0; i--) {       tmp = (1 << i);       if (tmp <= h) {         int x = (int)((double)tmp / 1.25);         int y = (int)((double)tmp / 0.8);         if ((double)y * 0.8 < (double)tmp) y++;         if ((double)x * 1.25 > (double)tmp) x--;         if (y <= w) {           th = tmp;           tw = y;           ar = (long long)th * (long long)tw;           if (ar > ba || ar == ba && th > bh) {             bh = th;             bw = tw;             ba = (long long)bh * (long long)bw;           }         } else if (x < w) {           th = tmp;           tw = w;           ar = (long long)th * (long long)tw;           if (ar > ba || ar == ba && th > bh) {             bh = th;             bw = tw;             ba = (long long)bh * (long long)bw;           }         }       }     }     if (bw > bh && bw <= h) std::swap(bw, bh);     printf( %d %d n , bh, bw);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int r1, r2, c1, c2, d1, d2;   int main() {     scanf( %d%d%d%d%d%d , &r1, &r2, &c1, &c2, &d1, &d2);     for (int i = 1; i <= 9; ++i)       for (int j = 1; j <= 9; ++j)         for (int ii = 1; ii <= 9; ++ii)           for (int jj = 1; jj <= 9; ++jj) {             if (i != j && i != ii && i != jj && j != ii && j != jj && ii != jj)               if (i + j == r1 && jj + ii == r2 && i + ii == c1 && j + jj == c2 &&                   i + jj == d1 && j + ii == d2) {                 printf( %d %d n%d %d , i, j, ii, jj);                 return 0;               }           }     printf( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double a[100010], ans1, ans2;   int n, n1, n2;   bool cmp(double a, double b) { return a > b; }   int main() {     scanf( %d%d%d , &n, &n1, &n2);     if (n1 > n2) swap(n1, n2);     for (int i = 1; i <= n; i++) scanf( %lf , &a[i]);     sort(a + 1, a + n + 1, cmp);     for (int i = 1; i <= n1; i++) ans1 += a[i];     for (int i = n1 + 1; i <= n1 + n2; i++) ans2 += a[i];     printf( %.8f n , ans1 / n1 + ans2 / n2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, long long> bismarck, dp;   long long n;   void factorization(long long x) {     for (long long i = 2; i * i <= x; i++) {       if (x % i == 0) {         long long c = 0;         while (x % i == 0) {           c++;           x /= i;         }         dp[i] |= 1 << (c - 1);       }     }     if (x > 1) {       dp[x] |= 1;     }   }   long long grundy(long long x) {     if (x == 0) return 0;     if (bismarck.count(x)) return bismarck[x];     unordered_set<long long> s;     for (long long i = 0; x >> i; i++) {       s.insert(grundy(x >> i + 1 | (x & (1 << i) - 1)));     }     long long mex = 0;     while (s.count(mex)) mex++;     return bismarck[x] = mex;   }   int main() {     long long x, ans = 0;     cin >> n;     while (n--) {       cin >> x;       factorization(x);     }     for (auto t : dp) {       ans ^= grundy(t.second);     }     if (ans)       cout <<  Mojtaba ;     else       cout <<  Arpa ;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long res = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       res = res * 10 + c - 48;       c = getchar();     }     return res * f;   }   const long long N = 610;   long long f[N][N];   long long a[N][N];   long long n, m, mod;   long long in[N], o[N], s[N], t[N], tots, tott, tot;   long long head[N], to[N * N], nxt[N * N], res;   queue<long long> q;   long long id[N];   long long qpow(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % mod;       a = a * a % mod;       b >>= 1;     }     return res;   }   void add(long long x, long long y) {     nxt[++tot] = head[x];     head[x] = tot;     to[tot] = y;   }   void guess(long long n) {     res = 1;     for (long long i = 1; i <= n; ++i) {       for (long long j = i + 1; j <= n; ++j) {         while (a[j][i]) {           long long v = a[i][i] * qpow(a[j][i], mod - 2) % mod;           for (long long k = i; k <= n; ++k)             a[i][k] = ((a[i][k] - 1LL * v * a[j][k] % mod) + mod) % mod;           swap(a[i], a[j]), res = -res;         }       }     }     for (long long i = 1; i <= n; ++i) {       res = (1ll * res * a[i][i] % mod + mod) % mod;     }   }   signed main() {     n = read(), m = read(), mod = read();     for (long long i = 1; i <= m; ++i) {       long long x = read(), y = read();       in[y]++, o[x]++;       add(x, y);     }     for (long long i = 1; i <= n; ++i) {       if (in[i] == 0) s[++tots] = i;       if (o[i] == 0) t[++tott] = i;     }     for (long long i = 1; i <= n; ++i)       if (!in[i]) q.push(i);     tot = 0;     while (q.size()) {       long long u = q.front();       q.pop();       id[++tot] = u;       for (long long i = head[u]; i; i = nxt[i]) {         long long v = to[i];         --in[v];         if (!in[v]) q.push(v);       }     }     for (long long i = 1; i <= n; ++i) {       long long u = id[i];       f[u][u] = 1;       for (long long j = i; j <= n; ++j) {         long long v = id[j];         for (long long k = head[v]; k; k = nxt[k]) {           long long vv = to[k];           f[u][vv] = (f[u][vv] + f[u][v]) % mod;         }       }     }     for (long long i = 1; i <= tots; ++i) {       for (long long j = 1; j <= tott; ++j) {         a[i][j] = f[s[i]][t[j]];       }     }     guess(tots);     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     int A, B;     cin >> A >> B;     string a, b;     cin >> a >> b;     int p = 0, m = a.size();     for (int i = 0; i + a.size() <= b.size(); i++) {       int k = 0;       for (int j = 0; j < a.size(); j++) {         if (a[j] != b[i + j]) k++;       }       if (k < m) {         m = k;         p = i;       }     }     vector<int> v;     for (int i = 0; i < a.size(); i++) {       if (a[i] != b[i + p]) v.push_back(i);     }     cout << v.size() << endl;     for (int i = 0; i < v.size(); i++) {       cout << v[i] + 1 <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, n, m, k, l;   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     cin >> n >> m >> k >> l;     if ((n / m) * m < k + l) {       cout <<  -1 n ;       return 0;     }     cout << (k + l) / m + ((k + l) % m != 0) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int temp, sum = 0;     int size, counter = 0;     cin >> size;     for (int i = 0; i < size; i++) cin >> temp, sum += temp;     if (sum % size == 0)       cout << size << endl;     else       cout << size - 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct __s {     __s() {       if (1) {         ios_base::Init i;         cin.sync_with_stdio(0);         cin.tie(0);       }     }     ~__s() {       if (!1)         fprintf(stderr,  Execution time: %.3lf s. n ,                 (double)clock() / CLOCKS_PER_SEC);       long long n;       cin >> n;     }   } __S;   int main(void) {     long long n, m;     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < (long long)(n); i++) {       cin >> a[i];     }     cin >> m;     long long b = 0;     for (long long i = 0; i < (long long)(m); i++) {       long long x;       cin >> x;       b += x - 1;     }     vector<long long> c;     while (c.size() < 3 * max(m, n)) {       for (long long i = 0; i < (long long)(n - 1); i++) {         c.push_back(i);       }       for (long long i = 0; i < (long long)(n - 1); i++) {         c.push_back(n - 1 - i);       }     }     long long d = 0;     for (long long i = 0; i < (long long)(m); i++) {       b -= c[i];       if (i) d += abs(a[c[i]] - a[c[i - 1]]);     }     set<long long> ans;     for (long long i = m; i < c.size(); i++) {       if (b == 0) {         ans.insert(d);       }       b -= c[i];       b += c[i - m];       d -= abs(a[c[i - m]] - a[c[i - m + 1]]);       d += abs(a[c[i]] - a[c[i - 1]]);     }     if (ans.size() != 1)       cout << -1 <<   n ;     else       cout << *ans.begin() <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 * 1000;   int n, m;   int ar1[maxn];   int ar2[maxn];   void read();   int main() {     read();     int i, j;     int s1, s2;     int file;     i = j = s1 = s2 = file = 0;     while (i < n) {       if (s1 == 0)         s1 += ar1[i++];       else {         if (s1 < s2)           s1 += ar1[i++];         else if (s1 == s2) {           s1 = s2 = 0;           file++;         } else           s2 += ar2[j++];       }     }     if (s1 > 0) file++;     cout << file << endl;     return 0;   }   void read() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> ar1[i];     for (int j = 0; j < m; j++) cin >> ar2[j];   }


#include <bits/stdc++.h>   using namespace std;   long long qpow(long long a, long long k) {     long long b = 1LL;     while (k) {       if (k % 2 == 1) b = (b * a) % 1000000007;       a = (a * a) % 1000000007;       k = k / 2;     }     return b;   }   int main() {     char s[105] = {0};     scanf( %s , s);     int len = strlen(s);     long long ans = 0;     for (int i = len - 1; i >= 0; i--) {       ans = ans * 2;       ans = ans % 1000000007;       if (s[i] ==  1 ) {         ans = ans + qpow(4LL, (long long)(len - 1 - i));         ans = ans % 1000000007;       }     }     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, y, u, v, to[600005], nxt[600005], p[300005], sz[300005];   void dfs(int x, int lst) {     sz[x] = 1;     for (int i = p[x]; i != -1; i = nxt[i])       if (to[i] != lst) {         dfs(to[i], x);         sz[x] += sz[to[i]];       }   }   int main() {     scanf( %d%d%d , &n, &x, &y);     memset(p, -1, sizeof p);     for (int i = 1; i < n; i++) {       scanf( %d%d , &u, &v);       to[i * 2 - 1] = v, nxt[i * 2 - 1] = p[u], p[u] = i * 2 - 1;       to[i * 2] = u, nxt[i * 2] = p[v], p[v] = i * 2;     }     dfs(x, -1);     long long ans = sz[y];     dfs(y, -1);     ans *= sz[x];     cout << 1LL * n * (n - 1) - ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const int maxn = 100;   const int MAXN = 2750131;   long long T, n, m, i, j;   long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); }   long long g[200005];   int main() {     ios::sync_with_stdio(false);     long long a[20];     long long k = 1, s = 1, sum = 9;     for (i = 0; s < 1e12; i++) {       a[i] = s * sum * k;       s *= 10;       k++;     }     cin >> n;     if (n < 10) {       cout << n << endl;       return 0;     }     sum = 0;     i = 0;     k = 1;     s = 1;     long long m = n;     while (m > a[i]) {       m -= a[i];       i++;       k++;       s = pow(10, i);       sum = s - 1;     }     long long ans = (m) / k + sum;     if (m % k) {       ans++;     }     long long sk = m % k;     if (sk == 0) {       sk = k;     }     while (ans > 0) {       if (sk == k) {         cout << ans % 10 << endl;         break;       } else {         ans /= 10;         k--;       }     }     return 0;   }


#include <bits/stdc++.h>   int x1, x2, x3, y11, y2, y3, length;   int main() {     scanf( %d %d %d %d %d %d , &x1, &y11, &x2, &y2, &x3, &y3);     length = (int)(sqrt(x1 * y11 + x2 * y2 + x3 * y3) + 0.01);     if (x1 * y11 + x2 * y2 + x3 * y3 != length * length) {       printf( -1 n );       return 0;     }     if (x1 < y11) {       int temp = x1;       x1 = y11;       y11 = temp;     }     if (x2 < y2) {       int temp = x2;       x2 = y2;       y2 = temp;     }     if (x3 < y3) {       int temp = x3;       x3 = y3;       y3 = temp;     }     if (x1 == length && x2 == length && x3 == length) {       printf( %d n , length);       for (int i = 0; i < y11; i++) {         for (int j = 0; j < x1; j++) printf( A );         printf(  n );       }       for (int i = 0; i < y2; i++) {         for (int j = 0; j < x2; j++) printf( B );         printf(  n );       }       for (int i = 0; i < y3; i++) {         for (int j = 0; j < x3; j++) printf( C );         printf(  n );       }     } else if (x1 == length) {       printf( %d n , length);       if (x2 != length - y11) {         int temp = x2;         x2 = y2;         y2 = temp;       }       if (x3 != length - y11) {         int temp = x3;         x3 = y3;         y3 = temp;       }       for (int i = 0; i < y11; i++) {         for (int j = 0; j < x1; j++) printf( A );         printf(  n );       }       for (int i = 0; i < length - y11; i++) {         for (int j = 0; j < y2; j++) printf( B );         for (int j = 0; j < y3; j++) printf( C );         printf(  n );       }     } else if (x2 == length) {       printf( %d n , length);       if (x1 != length - y2) {         int temp = x1;         x1 = y11;         y11 = temp;       }       if (x3 != length - y2) {         int temp = x3;         x3 = y3;         y3 = temp;       }       for (int i = 0; i < y2; i++) {         for (int j = 0; j < x2; j++) printf( B );         printf(  n );       }       for (int i = 0; i < length - y2; i++) {         for (int j = 0; j < y11; j++) printf( A );         for (int j = 0; j < y3; j++) printf( C );         printf(  n );       }     } else if (x3 == length) {       printf( %d n , length);       if (x1 != length - y3) {         int temp = x1;         x1 = y11;         y11 = temp;       }       if (x2 != length - y3) {         int temp = x2;         x2 = y2;         y2 = temp;       }       for (int i = 0; i < y3; i++) {         for (int j = 0; j < x3; j++) printf( C );         printf(  n );       }       for (int i = 0; i < length - y3; i++) {         for (int j = 0; j < y11; j++) printf( A );         for (int j = 0; j < y2; j++) printf( B );         printf(  n );       }     } else {       printf( -1 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e3;   bool possible, check[N << 2], mark[N << 2];   vector<int> topol, from[N << 2], to[N << 2];   int n, m, c, d[N], com[N << 2], row[N], col[N], a[N][N], b[N][N];   void dfs_scc(int u, int c) {     com[u] = c;     mark[u] = true;     for (auto v : to[u])       if (!mark[v]) dfs_scc(v, c);   }   void strongly_connected_components() {     memset(mark, false, sizeof mark);     for (int i = 0; i < n << 2; i++)       if (check[i] && !mark[i]) dfs_scc(i, ++c);   }   void dfs_topolo(int u) {     mark[u] = true;     for (auto v : from[u])       if (!mark[v]) dfs_topolo(v);     topol.push_back(u);   }   void topological_sort() {     for (int i = 0; i < n << 2; i++)       if (check[i] && !mark[i]) dfs_topolo(i);     reverse(topol.begin(), topol.end());   }   void input(int w) {     for (int i = 0; i < n; i++) {       string s;       cin >> s;       for (int j = 0; j < n; j++) (w ? a[i][j] : b[i][j]) = s[j] -  0 ;     }   }   void add_edge(int u, int v) {     check[u] = check[v] = true;     from[u].push_back(v);     from[v].push_back(u);     to[u].push_back(v);     to[v].push_back(u);   }   void add_clause(int u, int v) {     add_edge(u ^ 1, v);     add_edge(u, v ^ 1);   }   void F2(int u, int v) {     int k = a[u][v] + b[u][v];     if (k == 1) (d[v] & 1 ? row[u] : col[v]) = 1;   }   void F1(int u, int v, int k) {     k += a[u][v] + b[u][v];     if (k == 3) {       add_clause(u << 1, (v + n) << 1);       return;     }     if (k == 1) {       cout << -1;       exit(0);     }     if (k == 4 || (!a[u][v] && k == 2)) {       add_clause(u << 1 ^ 1, (v + n) << 1);       return;     }   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     input(1), input(0);     string s;     cin >> s;     for (int i = 0; i < n; i++) d[i] = s[i] -  0 ;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) d[i] == d[j] ? F1(i, j, d[i] + d[j]) : F2(i, j);     topological_sort();     strongly_connected_components();     for (int i = 0; i < n << 1; i++)       if (check[i << 1] && com[i << 1] == com[i << 1 ^ 1]) {         cout << -1;         return 0;       } else if (check[i << 1] && com[i << 1] < com[i << 1 ^ 1])         i >= n ? col[i - n] = 1 : row[i] = true;     int cnt = 0;     for (int i = 0; i < n; i++) cnt += row[i] + col[i];     cout << cnt << endl;     for (int i = 0; i < n; i++)       if (row[i]) cout <<  row   << i << endl;     for (int i = 0; i < n; i++)       if (col[i]) cout <<  col   << i << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     int index1 = 0;     int index2 = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 1)         index1 = i + 1;       else if (a[i] == n)         index2 = i + 1;     }     int ans = max(max(max(index2 - 1, n - index2), index1 - 1), n - index1);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double eps(1e-10);   int sign(const double& x) { return (x > eps) - (x + eps < 0); }   bool equal(const double& x, const double& y) {     return x + eps > y && y + eps > x;   }   struct Point {     double x, y, z;     Point() {}     Point(const double& x, const double& y, const double& z) : x(x), y(y), z(z) {}     void print() const { printf( %f%f%f n , x, y, z); }     void scan() { scanf( %lf%lf%lf , &x, &y, &z); }     double sqrlen() const { return x * x + y * y + z * z; }     double len() const { return sqrt(max(0., sqrlen())); }     bool operator<(const Point& b) const {       if (!equal(x, b.x)) {         return x < b.x;       }       if (!equal(y, b.y)) {         return y < b.y;       }       if (!equal(z, b.z)) {         return z < b.z;       }       return false;     }     double dirlen() const { return len() * ((*this) < Point(0, 0, 0) ? -1 : 1); }     Point operator+(const Point& b) const {       return Point(x + b.x, y + b.y, z + b.z);     }     Point operator-(const Point& b) const {       return Point(x - b.x, y - b.y, z - b.z);     }     double operator%(const Point& b) const { return x * b.x + y * b.y + z * b.z; }     Point operator*(const Point& b) const {       return Point(y * b.z - z * b.y, z * b.x - x * b.z, x * b.y - y * b.x);     }     Point zoom(const double& l) const {       double lambda(l / len());       return Point(lambda * x, lambda * y, lambda * z);     }   };   inline Point operator*(const double& x, const Point& a) {     return Point(x * a.x, x * a.y, x * a.z);   }   struct Plane {     Point o, norm;   };   struct Line {     Point s, d;     Line(const Point& s, const Point& d) : s(s), d(d) {}   };   Point intersection(const Line& a, const Line& b) {     double lambda(((b.s - a.s) * b.d).dirlen() / (a.d * b.d).dirlen());     return a.s + lambda * a.d;   }   vector<pair<Point, pair<int, int>>> evts;   void calc(const vector<Point>& points, const vector<Point>& q) {     Plane p1, p2;     p1.o = points[0];     p2.o = q[0];     p1.norm = (points[0] - points[1]) * (points[2] - points[0]);     p2.norm = (q[0] - q[1]) * (q[2] - q[0]);     p1.norm = p1.norm.zoom(1);     p2.norm = p2.norm.zoom(1);     if (sign((p1.norm * p2.norm).len()) == 0) {       return;     }     Point d(p1.norm * p2.norm);     Point g(d * p1.norm);     d = d.zoom(1);     g = g.zoom(1);     Line l(p1.o + (p2.o - p1.o) % p2.norm / (g % p2.norm) * g, d);     static vector<pair<Point, pair<int, int>>> vec;     vec.clear();     for (int i(0); i < (int)points.size(); i++) {       Point a(points[i]), b(points[(i + 1) % (int)points.size()]);       int da(sign((a - l.s) % g)), db(sign((b - l.s) % g));       if (da == db) {       } else {         Point crs(intersection(Line(a, b - a), l));         if (da != 0 && db != 0) {           evts.push_back(make_pair(crs, make_pair(da, 0)));         } else {           vec.push_back(make_pair(crs, make_pair(da, db)));         }       }     }     for (int i(0); i < (int)vec.size(); i++) {       if (vec[i].second.second == 0) {         if (vec[i].second.first != vec[(i + 1) % (int)vec.size()].second.second) {           evts.push_back(               make_pair(vec[i].first, make_pair(vec[i].second.first, 0)));         }       }     }   }   vector<Point> vec[2];   int main() {     for (int d(0); d < 2; d++) {       int n;       scanf( %d , &n);       for (int i(0); i < n; i++) {         Point p;         p.scan();         vec[d].push_back(p);       }     }     calc(vec[0], vec[1]);     for (auto& evt : evts) {       evt.second.second = 1;     }     calc(vec[1], vec[0]);     sort(evts.begin(), evts.end());     int ans(0);     int cur(0);     for (auto evt : evts) {       if (evt.second.second == 1) {         cur += evt.second.first;       } else {         if (cur != 0) {           ans += evt.second.first;         }       }     }     printf( %s n , ans != 0 ?  YES  :  NO );   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int idx, sum;     int left, right;   } tree[3000000];   int cnt;   long long sumVal;   char ch[10];   void addNode(int cur, int def, int h, int val) {     if (tree[cur].idx == def) {       tree[cur].sum += val;       return;     }     tree[cur].sum += val;     if ((1 << (h)) & def) {       if (tree[cur].right == 0) {         tree[cur].right = ++cnt;         tree[cnt].idx = tree[cur].idx * 2 + 1;         tree[cnt].sum = 0;         tree[cnt].left = tree[cnt].right = 0;       }       addNode(tree[cur].right, def, h - 1, val);     } else {       if (tree[cur].left == 0) {         tree[cur].left = ++cnt;         tree[cnt].idx = tree[cur].idx * 2;         tree[cnt].sum = 0;         tree[cnt].left = tree[cnt].right = 0;       }       addNode(tree[cur].left, def, h - 1, val);     }   }   void decayNode(int cur, int h, int maxVal) {     if (h == 0) {       sumVal += max(maxVal, tree[cur].sum);       return;     }     int u = tree[cur].left, v = tree[cur].right;     if (tree[u].sum > tree[v].sum) {       long long t = max(maxVal, tree[cur].sum - tree[v].sum);       sumVal += (long long)(1 << (h - 1)) * t;       maxVal = max(maxVal, tree[cur].sum - tree[u].sum);       decayNode(u, h - 1, maxVal);     } else {       long long t = max(maxVal, tree[cur].sum - tree[u].sum);       sumVal += (long long)(1 << (h - 1)) * t;       maxVal = max(maxVal, tree[cur].sum - tree[v].sum);       decayNode(v, h - 1, maxVal);     }   }   int main(int argc, char** argv) {     int n, m, k, e;     scanf( %d%d , &n, &m);     cnt = 1;     tree[1].idx = 1;     tree[1].sum = 0;     tree[0].sum = 0;     tree[1].left = tree[1].right = 0;     for (int i = 1; i <= m; i++) {       scanf( %s , ch);       if (ch[0] ==  d ) {         sumVal = 0;         decayNode(1, n, 0);         double ans = (double)sumVal / (double)(1 << (n));         printf( %.8lf n , ans);       } else {         scanf( %d%d , &k, &e);         int h = 0, p = k / 2;         while (p) {           p /= 2;           h += 1;         }         addNode(1, k, h - 1, e);       }     }     return (EXIT_SUCCESS);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   char a[65];   void pre() {     int j = 1;     for (j = 1; j <= 10; j++) a[j - 1] = (char)(j - 1 + 48);     for (int i = 0; i < 26; i++) a[j++] = (char)(i + 97);     for (int i = 0; i < 26; i++) a[j++] = (char)(i + 65);     a[10] =  Z ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     pre();     int T;     cin >> T;     while (T--) {       vector<int> val(65, 0);       int r, c, k;       cin >> r >> c >> k;       string s[r], ans[r];       int R = 0;       for (int i = 0; i < r; i++) {         cin >> s[i];         for (int j = 0; j < s[i].size(); j++) {           if (s[i][j] ==  R ) R++;           ans[i] +=  . ;         }       }       int x = R / k;       R = R % k;       for (int i = 0; i < k; i++) {         val[i] = x;         if (R) {           R--;           val[i]++;         }       }       int gg = 0;       for (int i = 0; i < r; i++) {         if (i % 2 == 0) {           for (int j = 0; j < c; j++) {             ans[i][j] = a[gg];             if (s[i][j] ==  R ) {               val[gg]--;               if (!val[gg]) {                 gg++;               }             }             if (gg >= k - 1) gg = k - 1;           }         } else {           for (int j = c - 1; j >= 0; j--) {             ans[i][j] = a[gg];             if (s[i][j] ==  R ) {               val[gg]--;               if (!val[gg]) {                 gg++;               }             }             if (gg >= k - 1) gg = k - 1;           }         }       }       for (int i = 0; i < r; i++) cout << ans[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 4;   const int M = 1e9 + 7;   vector<pair<int, int> > g[N];   const int inf = 1e9 + 10;   vector<int> dist(N, inf);   void dijkstra(int source) {     dist[source] = 0;     set<pair<int, int> > s;     s.insert({0, source});     while (!s.empty()) {       auto x = *(s.begin());       s.erase(x);       for (auto it : g[x.second])         if (dist[it.first] > max(dist[x.second], it.second)) {           s.erase({dist[it.first], it.first});           dist[it.first] = max(dist[x.second], it.second);           s.insert({dist[it.first], it.first});         }     }   }   void solve() {     int n, m, k;     cin >> n >> m >> k;     int x[k];     for (int i = 0; i < k; i++) cin >> x[i];     for (int i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       if (u != v) {         g[u].push_back({v, w});         g[v].push_back({u, w});       }     }     dijkstra(x[0]);     int ans = 0;     for (int i = 0; i < k; i++) ans = max(ans, dist[x[i]]);     for (int i = 0; i < k; i++) cout << ans <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int to_reach(long long int number, long long int moves,                          long long int target) {     if (target == 0) {       return (number / moves);     } else {       long long int res = (target - number) / moves;       return res;     }   }   int main() {     long long int n, m, xc, yc, dxi, dyi, step;     cin >> n >> m;     cin >> xc >> yc;     long long int k, count = 0;     cin >> k;     for (int i = 0; i < k; i++) {       cin >> dxi >> dyi;       long long int toReachX, toReachY;       if (dxi == 0)         toReachX = 10000000000;       else if (dxi > 0)         toReachX = to_reach(xc, dxi, n);       else         toReachX = to_reach(1 - xc, dxi, 0);       if (dyi == 0)         toReachY = 10000000000;       else if (dyi > 0)         toReachY = to_reach(yc, dyi, m);       else         toReachY = to_reach(1 - yc, dyi, 0);       long long int tomove = min(toReachX, toReachY);       xc = xc + dxi * tomove, yc = yc + dyi * tomove;       count += tomove;     }     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( O3 )   #pragma GCC target( avx )   const long long MOD = 1000000007;   const long double PI = 3.1415926535898;   const long long LIM = 100005;   using namespace std;   long long fpow(long long x, long long y) {     long long temp;     if (y == 0) return 1;     temp = fpow(x, y / 2);     if (y % 2 == 0)       return temp * temp;     else       return x * temp * temp;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   void sieve(long long n) {     bool prime[5 * LIM];     memset(prime, true, sizeof(prime));     for (long long p = 2; p * p <= n; p++)       if (prime[p] == true)         for (long long i = p * p; i <= n; i += p) prime[i] = false;     prime[1] = 0;   }   inline long long read() {     long long p = 1, ans = 0;     char ch = getchar();     while (ch < 48 || ch > 57) {       if (ch ==  - ) p = -1;       ch = getchar();     }     while (ch >= 48 && ch <= 57) {       ans = (ans << 3) + (ans << 1) + ch - 48;       ch = getchar();     }     return ans * p;   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   map<long long, long long> primeFactors(long long n) {     map<long long, long long> make_pair;     while (n % 2 == 0) {       if (make_pair.count(2) == 1)         make_pair[2]++;       else         make_pair.insert({2, 1});       n = n / 2;     }     for (long long i = 3; i <= sqrt(n); i = i + 2) {       while (n % i == 0) {         if (make_pair.count(i) == 1)           make_pair[i]++;         else           make_pair.insert({i, 1});         n = n / i;       }     }     if (n > 2) {       if (make_pair.count(n) == 1)         make_pair[n]++;       else         make_pair.insert({n, 1});     }     return make_pair;   }   long long compare(string a, string b) {     if (a.empty()) return 0;     for (long long i = 0; i < a.length(); i++) {       if (a[i] > b[i])         return 1;       else if (a[i] < b[i])         return -1;     }     return 0;   }   bool isPalindrome(string str) {     long long l = 0;     long long h = str.length() - 1;     while (h > l) {       if (str[l++] != str[h--]) {         return false;       }     }     return true;   }   long long maxSum(vector<long long> a) {     long long max_so_far = a[0];     long long curr_max = a[0];     for (long long i = 1; i < a.size(); i++) {       curr_max = max(a[i], curr_max + a[i]);       max_so_far = max(max_so_far, curr_max);     }     return max_so_far;   }   long long maxlength(vector<long long> a) {     long long size = a.size();     long long max_so_far = INT_MIN, max_ending_here = 0, start = 0, end = 0,               s = 0;     for (long long i = 0; i < size; i++) {       max_ending_here += a[i];       if (max_so_far < max_ending_here) {         max_so_far = max_ending_here;         start = s;         end = i;       }       if (max_ending_here <= 0) {         max_ending_here = 0;         s = i + 1;       }     }     return (end - start + 1);   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     for (long long tt = 1; tt <= t; ++tt) {       long long n, r, p, s, cnt = 0;       cin >> n >> r >> p >> s;       string str;       cin >> str;       vector<char> ans(n,  A );       for (long long i = 0; i < str.length(); i++) {         if (str[i] ==  R  && p > 0) {           ans[i] =  P ;           cnt++;           p--;         }         if (str[i] ==  P  && s > 0) {           ans[i] =  S ;           cnt++;           s--;         }         if (str[i] ==  S  && r > 0) {           ans[i] =  R ;           cnt++;           r--;         }       }       if (cnt < ceil(n / 2.0))         cout <<  NO               <<   n ;       else {         cout <<  YES               <<   n ;         for (long long i = 0; i < n; i++) {           if (ans[i] ==  A ) {             if (p > 0) {               ans[i] =  P ;               p--;             } else if (r > 0) {               ans[i] =  R ;               r--;             } else if (s > 0) {               ans[i] =  S ;               s--;             }           }           cout << ans[i];         }         cout <<   n ;       }     }     return 0;   }


#include<iostream>   using namespace std;   int main()   {       int t;       cin>>t;       while(t--){           int a,b;           cin>>a>>b;           if(a==0&&b==0)               cout<< 0 n ;           else if(a==0&&b!=0)               cout<<2*b-1<<endl;           else if(a!=0&&b==0)               cout<<2*a-1<<endl;           else{               if(a>b){                   int x=(2*b)+(2*(a-b)-1);                   cout<<x<<endl;               }               else if(a<b){                   int x=(2*a)+(2*(b-a)-1);                   cout<<x<<endl;               }               else if(a==b)                   cout<<2*a<<endl;               }           }       }


#include <bits/stdc++.h>   using namespace std;   bool comp(const vector<int> &l, const vector<int> &r) {     if (l[0] % 2 && r[0] % 2) {       return l[1] < r[1];     }     if ((l[0] % 2) && (r[0] % 2 == 0)) return true;     if ((l[0] % 2 == 0) && (r[0] % 2))       return false;     else       return true;   }   int main() {     int tmp, ans, test, c, i, j, n, k, t, odd, ans1 = 0, ans2 = 0;     vector<int> ar[102], v;     scanf( %d , &test);     for (int i = 1; i <= test; i++) {       scanf( %d , &n);       ar[i].push_back(n);       if (n % 2 == 0) {         ans = 0;         for (k = 1; k <= n / 2; k++) {           scanf( %d , &t);           ans += t;         }         ar[i].push_back(ans);         ans = 0;         for (k = 1; k <= n / 2; k++) {           scanf( %d , &t);           ans += t;         }         ar[i].push_back(ans);         ar[i].push_back(-1);       } else {         ans = 0;         for (k = 1; k <= n / 2; k++) {           scanf( %d , &t);           ans += t;         }         ar[i].push_back(ans);         scanf( %d , &odd);         ans = 0;         for (k = 1; k <= n / 2; k++) {           scanf( %d , &t);           ans += t;         }         ar[i].push_back(ans);         ar[i].push_back(odd);         v.push_back(odd);       }     }     for (i = 1; i <= test; i++) {       if (1 || ar[i][0] % 2 == 0) {         ans1 += ar[i][1];         ans2 += ar[i][2];       }     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     bool ok = true;     for (i = 0; i < v.size(); i++) {       if (ok)         ans1 += v[i];       else         ans2 += v[i];       ok = !ok;     }     cout << ans1 <<     << ans2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = (long long)1e9 + 7;   const int N = 105;   const int M = 5005;   long long dp[N][M];   int x[N];   int y[N];   long long c[M][N];   int sum[N];   int rSum[N];   int h[N];   int main() {     int n, i, j, k, l;     long long ans = 0;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &x[i]);     }     for (i = 1; i <= n; i++) {       scanf( %d , &y[i]);     }     for (i = 0; i < M; i++) {       c[i][0] = 1;       if (i <= 100) {         c[i][i] = 1;       }       for (j = 1; j < min(i, N); j++) {         c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MOD;       }     }     for (i = 1; i <= n; i++) {       sum[i] = sum[i - 1] + x[i];     }     for (i = n; i >= 1; i--) {       rSum[i] = rSum[i + 1] + y[i] - x[i];     }     for (i = 1; i <= n; i++) {       h[i] = x[i] + min(sum[i - 1], rSum[i]);     }     for (j = x[n]; j <= y[n]; j++) {       dp[n][j] = 1;     }     for (i = n - 1; i >= 1; i--) {       for (j = x[i]; j <= h[i]; j++) {         for (k = 0; k <= min(y[i], j); k++) {           dp[i][j] = (dp[i][j] + c[j][k] * dp[i + 1][x[i + 1] + j - k]) % MOD;         }       }     }     ans = dp[1][x[1]];     int num = sum[n];     for (i = 1; i <= n; i++) {       ans = (ans * c[num][x[i]]) % MOD;       num -= x[i];     }     printf( %d n , (int)ans);   }


#include <bits/stdc++.h>   using namespace std;   int *s;   int fenzhi(int left, int right, int d) {     int mins = 0x3f3f3f3f;     ;     for (int i = left; i <= right; i++) mins = min(mins, s[i] - d);     int ans = 0;     for (int i = left; i <= right; i++)       if (s[i] > mins + d) {         int j = i;         while (s[j + 1] > mins + d && j + 1 <= right) j++;         ans += fenzhi(i, j, mins + d);         i = j + 1;       }     return min(right - left + 1, mins + ans);   }   int main() {     int n;     cin >> n;     s = new int[n];     for (int i = 0; i < n; i++) cin >> s[i];     cout << fenzhi(0, n - 1, 0) << endl;     delete[] s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a;     cin >> a;     for (int i = 0; i < a.length(); i++) {       if (isupper(a[i])) a[i] = tolower(a[i]);     }     string s =    ;     for (int i = 0; i < a.length(); i++) {       if (a[i] ==  a  || a[i] ==  o  || a[i] ==  u  || a[i] ==  e  ||           a[i] ==  i  || a[i] ==  y )         continue;       s +=  . ;       s += a[i];     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[112], dp[312][312], mnix[312];   int **func(int **mat1, int **mat2, int mx) {     int **ans;     ans = new int *[mx + 2];     for (int i = 1; i <= mx; i++) {       ans[i] = new int[mx + 2];       for (int j = 1; j <= mx; j++) {         ans[i][j] = 0;         for (int k = i; k <= j; k++)           ans[i][j] = max(ans[i][j], mat1[i][k] + mat2[k][j]);       }     }     return ans;   }   int main() {     int n, k, mx = 0;     cin >> n >> k;     for (int i = 0; i < 312; i++) {       mnix[i] = 500;       for (int j = 0; j < 312; j++) {         dp[i][j] = 0;       }     }     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       mx = max(mx, a[i]);       mnix[a[i]] = min(mnix[a[i]], i);     }     int **mat;     mat = new int *[312];     for (int i = 0; i < 312; i++) {       mat[i] = new int[312];       for (int j = 0; j < 312; j++) mat[i][j] = 0;     }     for (int st = 1; st <= mx; st++) {       if (mnix[st] > 200) continue;       for (int j = 1; j <= mx; j++) {         if (j >= st)           dp[mnix[st]][j] = 1;         else           dp[mnix[st]][j] = 0;       }       for (int i = mnix[st] + 1; i < n; i++) {         for (int j = 1; j <= mx; j++) {           if (a[i] < st)             dp[i][j] = dp[i - 1][j];           else if (j < a[i])             dp[i][j] = dp[i - 1][j];           else if (j == a[i])             dp[i][j] = dp[i - 1][j] + 1;           else             dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);         }       }       for (int j = 1; j <= mx; j++) {         if (j < st) mat[st][j] = 0;         mat[st][j] = dp[n - 1][j];       }       for (int i = 0; i <= mx; i++) {         for (int j = 0; j <= mx; j++) {           dp[i][j] = 0;         }       }     }     int **ans;     ans = new int *[mx + 2];     for (int i = 0; i <= mx; i++) {       ans[i] = new int[mx + 2];       for (int j = 0; j <= mx; j++) ans[i][j] = 0;     }     while (k) {       if (k % 2 == 1) ans = func(ans, mat, mx);       mat = func(mat, mat, mx);       k = k / 2;     }     int fans = 0;     for (int j = 1; j <= mx; j++) fans = max(fans, ans[j][mx]);     cout << fans << endl;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     vector<long long> v(n + 1);     long long s = 0;     for (long long i = 1; i <= n; i++) {       cin >> v[i];       s += v[i] - i, v[i] = i;     }     for (long long i = 1; i <= n; i++) v[i] += s / n;     for (long long i = 1; i <= s % n; i++) v[i]++;     for (long long i = 1; i <= n; i++) cout << v[i] <<    n [i == n];   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     long long t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> q;   long long i, j, n, k, m = 1000000007, ww = 1, a[20005], b[20005], c[20005],                         w[20005];   bool flag;   bool otv(int n, bool sign) {     long long t = n;     for (long long j = 0; j < q.size(); j++) {       if (t % q[j] == 0) {         t /= q[j];         if (sign)           w[j]++;         else           w[j]--;         j--;       }       if (t == 1) break;     }     if (t > 1) ww = (ww * t) % m;     return 0;   }   long long ans() {     long long i, j, first = 1;     for (i = 0; i < q.size(); i++)       for (j = 0; j < w[i]; j++) first = (first * q[i]) % m;     first = (ww * first) % m;     return first;   }   int main() {     cin >> n >> k;     for (i = 1; i <= n; i++) cin >> a[i];     if (k == 0) {       for (i = 1; i <= n; i++) cout << a[i] <<    ;       return 0;     }     for (i = 2; i <= 30000; i++) {       flag = 0;       for (j = 0; j < q.size(); j++)         if (i % q[j] == 0) {           flag = 1;           break;         }       if (!flag) q.push_back(i);     }     b[1] = 1;     k--;     for (i = 2; i <= n; i++) {       otv(i + k - 1, 1);       otv(i - 1, 0);       b[i] = ans();     }     for (i = 1; i <= n; i++)       for (j = 0; j < i; j++) c[i] = ((a[i - j] * b[j + 1]) % m + c[i]) % m;     for (i = 1; i <= n; i++) cout << c[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct circle {     long double x, y, r;   };   struct mod {     long double theta, op;   };   struct node {     long double x, y, theta;   };   int n, d, i, j, tot, S, ans, gg;   circle c[20005];   mod l[2000005];   node A, B;   long double D, k, t, L, R, dis1, dis2, dis3;   void getAB() {     long double x = c[i].x, y = c[i].y, r = c[i].r, delta;     if (x == 0) {       t = (r * r - x * x - y * y - D * D) / (-2 * y);       k = -x / y;       delta = (2 * t * k) * (2 * t * k) - 4 * (k * k + 1) * (t * t - D * D);       if (delta < 0) {         A.x = A.y = 0;         return;       }       A.x = (-(2 * t * k) + sqrt(delta)) / (2 * (k * k + 1));       B.x = (-(2 * t * k) - sqrt(delta)) / (2 * (k * k + 1));       A.y = (r * r - x * x - y * y - D * D + 2 * x * A.x) / (-2 * y);       B.y = (r * r - x * x - y * y - D * D + 2 * x * B.x) / (-2 * y);     } else {       t = (r * r - x * x - y * y - D * D) / (-2 * x);       k = -y / x;       delta = (2 * t * k) * (2 * t * k) - 4 * (k * k + 1) * (t * t - D * D);       if (delta < 0) {         A.x = A.y = 0;         return;       }       A.y = (-(2 * t * k) + sqrt(delta)) / (2 * (k * k + 1));       B.y = (-(2 * t * k) - sqrt(delta)) / (2 * (k * k + 1));       A.x = (r * r - x * x - y * y - D * D + 2 * y * A.y) / (-2 * x);       B.x = (r * r - x * x - y * y - D * D + 2 * y * B.y) / (-2 * x);     }   }   void insert(long double L, long double R) {     tot++;     l[tot].theta = L;     l[tot].op = 1;     tot++;     l[tot].theta = R + 0.0000000001;     l[tot].op = -1;   }   int comp(mod A, mod B) {     return ((A.theta < B.theta) || ((A.theta == B.theta) && (A.op < B.op)));   }   int main() {     scanf( %d%d , &n, &d);     for (i = 1; i <= n; i++) {       scanf( %Lf%Lf%Lf , &c[i].x, &c[i].y, &c[i].r);     }     for (i = 1; i <= n; i++) {       gg = sqrt(c[i].x * c[i].x + c[i].y * c[i].y) / d;       for (D = (long double)max(gg - 100, 1) * (long double)d;            D <= (long double)(gg + 100) * (long double)d; D += (long double)d) {         getAB();         if ((A.x == 0) && (A.y == 0)) continue;         A.theta = atan2(A.x, A.y);         B.theta = atan2(B.x, B.y);         if (A.theta > B.theta) swap(A, B);         L = A.theta;         R = B.theta;         if (R - L > 3.1415926535) swap(L, R);         if (L <= R)           insert(L, R);         else           insert(-3.1415926535, R), insert(L, 3.1415926535);       }     }     sort(l + 1, l + 1 + tot, comp);     for (i = 1; i <= tot; i++) {       S += l[i].op;       ans = max(ans, S);     }     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> a;     for (int i = (0); i < (n); i++) {       int t;       cin >> t;       a.push_back(t);     }     vector<int> b;     for (int i = (0); i < (n); i++) {       int t;       cin >> t;       b.push_back(t);     }     sort(a.begin(), a.end(), greater<int>());     sort(b.begin(), b.end(), greater<int>());     long long r = 0;     long long r1 = 0;     int i = 0;     int j = 0;     int nn = 2 * n;     int s = 1;     while (nn--) {       if (s == 1) {         if (i < n && j < n) {           if (a[i] > b[j]) {             r += a[i];             i++;           } else {             j++;           }         } else if (j < n) {           j++;         } else if (i < n) {           r += a[i];           i++;         }       } else {         if (i < n && j < n) {           if (b[j] > a[i]) {             r1 += b[j];             j++;           } else {             i++;           }         } else if (j < n) {           r1 += b[j];           j++;         } else if (i < n) {           i++;         }       }       s ^= 1;     }     cout << r - r1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, k;     cin >> n >> k;     if (k == 1) {       cout <<  Yes  << endl;       return;     }     vector<int> divs;     for (int i = 2; i < k; ++i)       if (!(k % i)) {         cerr << i << endl;         divs.push_back(1);         while (!(k % i)) k /= i, divs.back() *= i;       }     if (k > 1) divs.push_back(k);     set<int> div(divs.begin(), divs.end());     int a;     for (int i = 0; i < n; ++i) {       cin >> a;       set<int>::iterator it = div.begin();       while (it != div.end()) {         if (a % (*it))           ++it;         else           it = div.erase(it);       }     }     if (div.size())       cout <<  No  << endl;     else       cout <<  Yes  << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, color[510];   bool g[510][510];   vector<int> nbr[510];   bool dfs(int x, int c) {     color[x] = c;     for (int i = 0; i < nbr[x].size(); i++) {       int y = nbr[x][i];       if (color[y] == c) return 0;       if (color[y] == 0 && dfs(y, 3 - c) == 0) return 0;     }     return 1;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       g[x][y] = g[y][x] = 1;     }     for (int i = 1; i < n; i++)       for (int j = i + 1; j <= n; j++)         if (g[i][j] == 0) {           nbr[i].push_back(j);           nbr[j].push_back(i);         }     for (int i = 1; i <= n; i++) {       if (color[i] || nbr[i].size() == 0) continue;       if (dfs(i, 1) == 0) {         puts( No );         return 0;       }     }     for (int i = 1; i < n; i++)       for (int j = i + 1; j <= n; j++)         if (color[i] + color[j] == 3 && g[i][j]) {           puts( No );           return 0;         }     puts( Yes );     for (int i = 1; i <= n; i++) {       if (color[i] == 0)         cout <<  b ;       else if (color[i] == 1)         cout <<  a ;       else if (color[i] == 2)         cout <<  c ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     int Deb = 0;     int Fin = 9;     int Tab[10];     for (int j = 0; j < 10; j++) Tab[j] = 0;     char Cuck;     for (int j = 0; j < T; j++) {       cin >> Cuck;       if (Cuck ==  L ) {         Tab[Deb] = 1;         int curDeb = Deb;         while (Tab[curDeb] == 1 && curDeb < 10) curDeb++;         Deb = curDeb;       } else if (Cuck ==  R ) {         Tab[Fin] = 1;         int curFin = Fin;         while (Tab[curFin] == 1 && curFin >= 0) curFin--;         Fin = curFin;       } else {         int Ind = Cuck - 48;         Tab[Ind] = 0;         int curDeb = 0;         while (Tab[curDeb] == 1 && curDeb < 10) curDeb++;         Deb = curDeb;         int curFin = 9;         while (Tab[curFin] == 1 && curFin >= 0) curFin--;         Fin = curFin;       }     }     for (int j = 0; j < 10; j++) cout << Tab[j];   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     char ch = getchar();     x = 0;     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();   }   int n, m, a[238][238], x[238], y[238];   signed main() {     read(n), read(m);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) read(a[i][j]);     if (n == 1) {       puts( YES );       puts( 0 );       for (int i = 1; i <= m; ++i) a[1][i] ? putchar(48) : putchar(49);       return 0;     }     if (m == 1) {       puts( YES );       for (int i = 1; i <= n; ++i) a[i][1] ? putchar(48) : putchar(49);       puts(  );       return putchar(48), 0;     }     int ok = 1, cnt = 0, w, qwq;     for (int i = 1; i <= m; ++i) y[i] = a[1][i];     for (int i = 2; i <= n; ++i) {       int tmp = 0;       for (int j = 2; j <= m; ++j)         if ((a[i][j] ^ y[j]) != (a[i][j - 1] ^ y[j - 1]))           ++tmp, qwq = (a[i][j] ^ y[j]);       if (tmp) {         cnt += tmp, w = i;         if (cnt > 1) {           ok = 0;           break;         }       }     }     if (ok) {       puts( YES );       if (cnt) {         for (int i = 2; i < w; ++i) x[i] = a[i][1] ^ y[1];         x[w] = qwq ^ 1;         for (int i = w + 1; i <= n; ++i) x[i] = a[i][1] ^ y[1] ^ 1;       } else         for (int i = 2; i <= n; ++i) x[i] = a[i][1] ^ y[1];       for (int i = 1; i <= n; ++i) putchar(x[i] + 48);       puts(  );       for (int i = 1; i <= m; ++i) putchar(y[i] + 48);       return 0;     }     ok = 1, cnt = 0;     for (int i = 1; i <= m; ++i) y[i] = a[n][i] ^ 1;     for (int i = 1; i < n; ++i) {       int tmp = 0;       for (int j = 2; j <= m; ++j)         if ((a[i][j] ^ y[j]) != (a[i][j - 1] ^ y[j - 1]))           ++tmp, qwq = (a[i][j] ^ y[j]);       if (tmp) {         cnt += tmp, w = i;         if (cnt > 1) {           ok = 0;           break;         }       }     }     if (ok) {       puts( YES );       if (cnt) {         for (int i = 1; i < w; ++i) x[i] = a[i][1] ^ y[1];         x[w] = qwq ^ 1;         for (int i = w + 1; i < n; ++i) x[i] = a[i][1] ^ 1 ^ y[1];       } else         for (int i = 1; i < n; ++i) x[i] = a[i][1] ^ y[1];       for (int i = 1; i <= n; ++i) putchar(x[i] + 48);       puts(  );       for (int i = 1; i <= m; ++i) putchar(y[i] + 48);       return 0;     }     return puts( NO ), 0;   }


#include <bits/stdc++.h>   using namespace std;   const int PI = 3.1415926535;   const int inf = 1000111222;   const int mod = 1000000007;   const int N = 100007;   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> ar(n);     for (int i = 0; i < n; i++) cin >> ar[i];     vector<int> entries;     int ans = 0;     for (int i = 30; i >= 0; i--) {       entries.clear();       for (int j = 0; j < n; j++) {         if ((1 << i) & ar[j]) {           entries.push_back(j);         }       }       if (entries.size() == 1) {         ans = entries[0];         break;       }     }     vector<int> order;     order.push_back(ans);     for (int i = 0; i < n; i++) {       if (i != ans) order.push_back(i);     }     for (int i = 0; i < n; i++) {       cout << ar[order[i]] <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int n, k;   long long temp[55];   long long dp[105][55], ans;   vector<int> g[105];   void dfs(int u, int fa) {     dp[u][0] = 1;     dp[u][1 + k] = 1;     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v != fa) {         dfs(v, u);         for (int j = 0; j <= 2 * k + 1; j++) temp[j] = 0;         for (int dep1 = 0; dep1 <= 2 * k + 1; dep1++) {           for (int dep2 = 0; dep2 <= 2 * k; dep2++) {             if (dep1 + dep2 <= 2 * k)               temp[min(dep1, dep2 + 1)] =                   (temp[min(dep1, dep2 + 1)] + dp[u][dep1] * dp[v][dep2] % mod) %                   mod;             else               temp[max(dep1, dep2 + 1)] =                   (temp[max(dep1, dep2 + 1)] + dp[u][dep1] * dp[v][dep2] % mod) %                   mod;           }         }         for (int j = 0; j <= 2 * k + 1; j++) dp[u][j] = temp[j];       }     }   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> k;     for (int i = 1, u, v; i < n; i++) {       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     dfs(1, 0);     for (int i = 0; i <= k; i++) ans = (ans + dp[1][i]) % mod;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005];   int main() {     int n, k, sum = 0;     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       sum += a[i];     }     sort(a, a + n);     int res = a[n - 1];     for (int t = n - k, i = n - k - 1; i >= 0; i--, t++) {       if (res < a[i] + a[t]) {         res = a[i] + a[t];       }     }     if (k == 1)       printf( %d n , sum);     else       printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   struct seg_tree_lazy {     int S, H;     T zero;     std::vector<T> value;     U noop;     std::vector<bool> dirty;     std::vector<U> prop;     seg_tree_lazy<T, U>(int _S, T _zero = T(), U _noop = U());     void set_leaves(std::vector<T> &leaves);     void apply(int i, U &update);     void rebuild(int i);     void propagate(int i);     void upd(int i, int j, U update);     T query(int i, int j);   };   int v[210000];   set<int> ss[33];   int clz(int x) {     if (x == 0) return 32;     return __builtin_clz(x);   }   struct node {     long long s = 0;     node(long long int _s = 0) : s(_s) {}     node operator+(node ot) { return node(s + ot.s); }   };   struct upd {     int v;     upd(int _v = 0) : v(_v) {}     node operator()(node a) {       a.s += v;       return a;     }     upd operator+(upd ot) { return upd(v + ot.v); }   };   int n, q;   void solve() {     scanf( %d %d , &n, &q);     for (int i = 0; i < n; i++) scanf( %d , &v[i]);     vector<node> leaves(n);     for (int i = 0; i < n; i++) {       leaves[i].s = v[i];       ss[clz(v[i])].insert(i);     }     seg_tree_lazy<node, upd> tree(n);     tree.set_leaves(leaves);     for (int i = 0; i < q; i++) {       int p, val;       scanf( %d %d , &p, &val);       p--;       int diff = val - v[p];       ss[clz(v[p])].erase(p);       tree.upd(p, p, diff);       v[p] = val;       ss[clz(v[p])].insert(p);       int f = -1;       for (int i = 0; i < 33 && f == -1; i++) {         auto it = ss[i].begin();         for (int j = 0; j < 2; j++) {           if (it == ss[i].end()) break;           if (tree.query(0, *it).s == 2 * (v[*it])) f = *it + 1;           it++;         }       }       printf( %d n , f != -1 ? f : -1);     }   }   int main() { solve(); }   template <typename T, typename U>   seg_tree_lazy<T, U>::seg_tree_lazy(int _S, T _zero, U _noop) {     zero = _zero, noop = _noop;     for (S = 1, H = 1; S < _S;) S *= 2, H++;     value.resize(2 * S, zero);     dirty.resize(2 * S, false);     prop.resize(2 * S, noop);   }   template <typename T, typename U>   void seg_tree_lazy<T, U>::set_leaves(vector<T> &leaves) {     copy(leaves.begin(), leaves.end(), value.begin() + S);     for (int i = S - 1; i > 0; i--) value[i] = value[2 * i] + value[2 * i + 1];   }   template <typename T, typename U>   void seg_tree_lazy<T, U>::apply(int i, U &update) {     value[i] = update(value[i]);     if (i < S) {       prop[i] = prop[i] + update;       dirty[i] = true;     }   }   template <typename T, typename U>   void seg_tree_lazy<T, U>::rebuild(int i) {     for (int l = i / 2; l; l /= 2) {       T combined = value[2 * l] + value[2 * l + 1];       value[l] = prop[l](combined);     }   }   template <typename T, typename U>   void seg_tree_lazy<T, U>::propagate(int i) {     for (int h = H; h > 0; h--) {       int l = i >> h;       if (dirty[l]) {         apply(2 * l, prop[l]);         apply(2 * l + 1, prop[l]);         prop[l] = noop;         dirty[l] = false;       }     }   }   template <typename T, typename U>   void seg_tree_lazy<T, U>::upd(int i, int j, U update) {     i += S, j += S;     propagate(i), propagate(j);     for (int l = i, r = j; l <= r; l /= 2, r /= 2) {       if ((l & 1) == 1) apply(l++, update);       if ((r & 1) == 0) apply(r--, update);     }     rebuild(i), rebuild(j);   }   template <typename T, typename U>   T seg_tree_lazy<T, U>::query(int i, int j) {     i += S, j += S;     propagate(i), propagate(j);     T res_left = zero, res_right = zero;     for (; i <= j; i /= 2, j /= 2) {       if ((i & 1) == 1) res_left = res_left + value[i++];       if ((j & 1) == 0) res_right = value[j--] + res_right;     }     return res_left + res_right;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, n, r, S, Z, s1, s2, s3, s4, s5, s6, s7, s8, x, y, z, m, j, l, k,         t;     long long a[500005];     long long b[300045];     long long c[300001];     long long d[100001];     long long e[101][101];     pair<long long, long long> aa[200001];     pair<long long, long long> bb[200001];     double h, w, u, v, uu, vv;     string q1;     string q2;     string q3;     string q4;     string s;     string q;     string sq[50005];     string qs[3001];     map<string, long long> g;     map<string, long long>::iterator it;     cin >> n;     for (i = 1; i <= 100; i++) {       b[i] = 0;     }     for (l = 1; l <= n; l++) {       cin >> m;       for (i = 1; i <= m; i++) {         cin >> x;         b[x]++;       }     }     for (i = 1; i <= 100; i++) {       if (b[i] == n) cout << i <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 50100;   vector<int> v;   int n, k, st, x;   int nextchild[maxn], value[maxn];   void get_rand() {     int arr[n + 1];     for (int i = 0; i < n; i++) {       arr[i] = i + 1;     }     srand(time(0));     random_shuffle(arr, arr + n);     for (int i = 0; i < k; i++) {       v.push_back(arr[i]);     }   }   int main() {     cin >> n >> st >> x;     k = min(n, 1000);     get_rand();     memset(nextchild, 0, sizeof(nextchild));     memset(value, -1, sizeof(value));     cout <<  ?   << st <<   n ;     fflush(stdout);     cin >> value[st] >> nextchild[st];     int maxind = st;     int maxval = value[st];     for (int i : v) {       cout <<  ?   << i <<   n ;       fflush(stdout);       cin >> value[i] >> nextchild[i];       if (value[i] <= x && value[i] > maxval) {         maxval = value[i];         maxind = i;       }     }     int curr = maxind;     int answ = maxind;     while (true) {       cout <<  ?   << curr <<   n ;       fflush(stdout);       cin >> value[curr] >> nextchild[curr];       if (value[curr] >= x || nextchild[curr] == -1)         break;       else         curr = nextchild[curr];     }     if (value[curr] >= x) {       cout <<  !   << value[curr] <<   n ;       fflush(stdout);     } else {       cout <<  ! -1 n ;       fflush(stdout);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int l, r, lc, rc;     int dep_a, dep_a_2b, dep_2b_c, dep_2b, dep_a_2b_c, cover;   };   const int N = 200000;   const int root = 0;   struct Segment_Tree {     int num;     node tr[2 * N];     void setRange(int l, int r, int now = root) {       num = 0;       build(l, r, now);     }     void build(int l, int r, int now) {       tr[now].l = l;       tr[now].r = r;       tr[now].dep_2b_c = tr[now].dep_a = tr[now].dep_2b = tr[now].dep_a_2b =           tr[now].dep_a_2b_c = 0;       tr[now].cover = 0;       if (l < r) {         int mid = (l + r) >> 1;         ++num;         tr[now].lc = num;         ++num;         tr[now].rc = num;         build(l, mid, tr[now].lc);         build(mid + 1, r, tr[now].rc);       }     }     void pushup(node &f, node &lc, node &rc) {       f.dep_a = max(lc.dep_a, rc.dep_a);       f.dep_2b = max(lc.dep_2b, rc.dep_2b);       f.dep_a_2b = max(max(lc.dep_a_2b, rc.dep_a_2b), lc.dep_a + rc.dep_2b);       f.dep_2b_c = max(max(lc.dep_2b_c, rc.dep_2b_c), lc.dep_2b + rc.dep_a);       f.dep_a_2b_c = max(max(lc.dep_a_2b_c, rc.dep_a_2b_c),                          max(lc.dep_a + rc.dep_2b_c, lc.dep_a_2b + rc.dep_a));     }     void lazyupdate(int now, int val) {       tr[now].cover += val;       tr[now].dep_a += val;       tr[now].dep_a_2b -= val;       tr[now].dep_2b_c -= val;       tr[now].dep_2b -= 2 * val;     }     void pushdown(int now) {       lazyupdate(tr[now].lc, tr[now].cover);       lazyupdate(tr[now].rc, tr[now].cover);       tr[now].cover = 0;     }     void update(int l, int r, int val, int now = root) {       if (tr[now].l == l && tr[now].r == r) {         lazyupdate(now, val);         return;       } else {         if (tr[now].cover != 0) pushdown(now);         int mid = (tr[now].l + tr[now].r) >> 1;         if (r <= mid)           update(l, r, val, tr[now].lc);         else if (l > mid)           update(l, r, val, tr[now].rc);         else {           update(l, mid, val, tr[now].lc);           update(mid + 1, r, val, tr[now].rc);         }         pushup(tr[now], tr[tr[now].lc], tr[tr[now].rc]);       }     }     node query(int l, int r, int now = root) {       if (tr[now].l == l && tr[now].r == r)         return tr[now];       else {         if (tr[now].cover != 0) pushdown(now);         int mid = (tr[now].l + tr[now].r) >> 1;         if (r <= mid)           return query(l, r, tr[now].lc);         else if (l > mid)           return query(l, r, tr[now].rc);         else {           node f, lc, rc;           lc = query(l, mid, tr[now].lc);           rc = query(mid + 1, r, tr[now].rc);           pushup(f, lc, rc);           return f;         }       }     }   };   Segment_Tree tr;   bool p[200000];   int main() {     int n, q;     char ch[200000];     scanf( %d%d%s , &n, &q, ch);     n = (n - 1) * 2;     tr.setRange(1, n);     for (int i = 0; i < n; ++i) {       if (ch[i] ==  ( ) {         p[i + 1] = true;         tr.update(i + 1, n, 1);       } else {         p[i + 1] = false;         tr.update(i + 1, n, -1);       }     }     printf( %d n , tr.query(1, n).dep_a_2b_c);     while (q--) {       int s, t;       scanf( %d%d , &s, &t);       if (s > t) swap(s, t);       if (p[s] != p[t]) {         p[s] = !p[s];         p[t] = !p[t];         if (p[s]) {           tr.update(s, t - 1, 2);         } else {           tr.update(s, t - 1, -2);         }       }       printf( %d n , tr.query(1, n).dep_a_2b_c);     }   }


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


#include <bits/stdc++.h>   using namespace std;   const long long K = 401, MAX = 1e18;   int n, m, k, f;   vector<pair<int, int>> adj[2 * K];   vector<pair<int, pair<int, int>>> E;   vector<long long> sp;   long long dist[2 * K];   bool vis[2 * K];   unordered_map<int, int> tb;   priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>       pq;   void dijkstra(int s) {     memset(vis, 0, sizeof(vis));     for (int i = 0; i < f; i++) dist[i] = MAX;     dist[s] = 0;     pq.push({0, s});     while (!pq.empty()) {       int v = pq.top().second, d = pq.top().first;       vis[v] = 1;       pq.pop();       for (pair<int, int> p : adj[v]) {         int u = p.second, w = p.first;         if (vis[u]) continue;         if (dist[v] + w < dist[u]) {           dist[u] = dist[v] + w;           pq.push({dist[u], u});         }       }     }     for (int i = s + 1; i < f; i++)       if (dist[i] < MAX) {         sp.push_back(dist[i]);       }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m >> k;     for (int i = 0; i < m; i++) {       int x, y, w;       cin >> x >> y >> w;       E.push_back({w, {x, y}});     }     sort(E.begin(), E.end());     for (int i = 0; i < min(k, m); i++) {       int x = E[i].second.first, y = E[i].second.second, w = E[i].first;       if (tb.find(x) == tb.end()) tb[x] = f++;       if (tb.find(y) == tb.end()) tb[y] = f++;       adj[tb[x]].push_back({w, tb[y]});       adj[tb[y]].push_back({w, tb[x]});     }     for (int i = 0; i < f; i++) dijkstra(i);     sort(sp.begin(), sp.end());     cout << sp[k - 1];   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k, n, t, blow, head, d, h, mx, mxd;     cin >> t;     while (t--) {       cin >> blow >> head;       mx = -1;       mxd = 0;       while (blow > 0) {         cin >> d >> h;         mx = max(mx, d - h);         mxd = max(mxd, d);         blow--;       }       if (mx <= 0 && mxd < head) {         cout << -1 << endl;         continue;       }       int val = (head - mxd) / (mx);       if ((head - mxd) % mx != 0) val++;       val++;       if (mxd >= head) val = 1;       cout << val << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char tmp[120];   int n_t, n_v, n_p;   map<string, string> lei;   vector<string> voids[1005];   vector<string> call;   inline bool cmp(vector<string>& v1, vector<string>& v2) {     int i = 0, j = 0;     while (v1[i] ==    && i < v1.size()) i++;     while (v2[j] ==    && j < v2.size()) j++;     if (v1[i] == v2[j]) {       i++;       j++;     } else {       return false;     }     while (i < v1.size() && j < v2.size()) {       if (v1[i] == v2[j]) {         i++;         j++;       } else if (v1[i] ==  T  || v2[j] ==  T ) {         i++;         j++;       } else {         return false;       }     }     return (v1.size() == i && v2.size() == j);   }   inline string readtype(string& t, int& p) {     string s =   ;     while (islower(t[p]) || isupper(t[p]) || isdigit(t[p])) s += t[p++];     return s;   }   int main() {     int i, j;     string t;     scanf( %d , &n_t);     for (i = 0; i < n_t; i++) {       scanf( %s , tmp);       gets(tmp);       t = tmp;       int l = t.size();       int p = 0;       while (t[p] ==    ) ++p;       for (; p < l; p++) {         if (t[p] ==     || t[p] ==  (  || t[p] ==  )  || t[p] ==  , ) continue;         voids[i].push_back(readtype(t, p));       }     }     scanf( %d , &n_v);     for (i = 0; i < n_v; i++) {       string l, nam;       scanf( %s , tmp), l = tmp;       scanf( %s , tmp), nam = tmp;       lei[nam] = l;     }     scanf( %d , &n_p);     gets(tmp);     for (i = 0; i < n_p; i++) {       call.clear();       gets(tmp);       t = tmp;       int p = 0, l = t.size();       while (t[p] ==    ) ++p;       for (; p < l; p++) {         if (t[p] ==     || t[p] ==  (  || t[p] ==  )  || t[p] ==  , ) continue;         string ss = readtype(t, p);         if (!call.empty())           call.push_back(lei[ss]);         else           call.push_back(ss);       }       int cnt = 0;       for (int j = 0; j < n_t; j++)         if (cmp(call, voids[j])) cnt++;       printf( %d n , cnt);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e8 + 5;   long long MAX = 1e9;   long long MOD = 1e9 + 7;   long long Mod = 1e9 + 7;   double EPS = 0.0001;   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); }   const int dx[] = {1, -1, 0, 0, 0, 0};   const int dy[] = {0, 0, 1, -1, 0, 0};   int main() {     int n;     string s1;     cin >> n;     cin >> s1;     if (n == 1 || n == 2) {       cout << s1 << endl;       return 0;     }     vector<char> ans(n,  _ );     ans[(n - 1) / 2] = s1[0];     int indx1 = n % 2 == 0 ? n / 2 : n / 2 - 1;     int indx2 = n % 2 == 0 ? n / 2 - 2 : n / 2 + 1;     int dir1 = n % 2 == 0 ? 1 : -1;     int dir2 = n % 2 == 0 ? -1 : 1;     for (int i = 1; i <= n; i++) {       if (i % 2 != 0 && indx1 >= 0 && indx1 < n) {         ans[indx1] = s1[i];         indx1 += dir1;       }       if (i % 2 == 0 && indx2 >= 0 && indx2 < n) {         ans[indx2] = s1[i];         indx2 += dir2;       }     }     for (auto c : ans) cout << c;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long(n), (m);     scanf( %lld%lld , &(n), &(m));     ;     vector<map<long long, long long>> vals(n);     long long maxi = 1;     for (long long i = 0; i < (m); i++) {       long long(a), (b), (c);       scanf( %lld%lld%lld , &(a), &(b), &(c));       ;       --a;       --b;       auto it = vals[a].lower_bound(c);       long long l;       if (!vals[a].size() || it == vals[a].begin())         l = 1;       else {         it--;         l = (*it).second + 1;       }       maxi = max(maxi, l);       auto it2 = vals[b].upper_bound(c);       if (!vals[b].size())         vals[b][c] = l;       else {         if (it2 != vals[b].begin()) {           it2--;           if ((*it2).second >= l) continue;         }         vals[b][c] = l;         it2 = vals[b].lower_bound(c);         it2++;         vector<long long> v;         while (it2 != vals[b].end() && (it2->second) <= l) {           v.push_back(it2->first);           it2++;         }         for (auto j : v) vals[b].erase(j);       }     }     printf( %lld n , maxi);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, l;     cin >> n >> l;     vector<int> a(n, 0), b(n, 0);     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) cin >> b[i];     if (n == 1)       cout <<  YES n ;     else {       vector<int> a_diff, b_diff, result;       int check_sum = 0;       for (int i = 1; i < n; ++i) {         a_diff.push_back(a[i] - a[i - 1]);         b_diff.push_back(b[i] - b[i - 1]);       }       a_diff.push_back(l - a[n - 1] + a[0]);       b_diff.push_back(l - b[n - 1] + b[0]);       for (int i = 0; i < n; ++i) a_diff.push_back(a_diff[i]);       int i = 0, j = 0, prev_i = 0;       while (i < 2 * n && j < n) {         while (i < 2 * n && b_diff[0] != a_diff[i]) ++i;         j = 0;         prev_i = i;         while (i < 2 * n && j < n && b_diff[j] == a_diff[i]) ++i, ++j;         i = prev_i + 1;         if (j == n) {           cout <<  YES n ;           return 0;         }       }       cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   long long n, m, ans, a, b, temp;   int t;   long long num[maxn];   long long mark[maxn];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> num[i];       num[i] = abs(num[i]);     }     sort(num, num + n);     int l = 0, r = 0;     while (l < n) {       while (r < n && 2 * num[l] >= num[r]) {         r++;       }       ans += r - l - 1;       l++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   void dk_98() {}   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   void solve() {     int n;     cin >> n;     int arr[n][n];     for (long long i = 0; i < (int)(n); i++) {       for (long long j = 0; j < (int)(n); j++) {         cin >> arr[i][j];       }     }     if (n == 1) {       cout << 0;       return;     }     int ans[n];     memset(ans, 0, sizeof(ans));     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (j != i) ans[i] = ans[i] | arr[i][j];       }     }     for (long long i = 0; i < (int)(n); i++) {       cout << ans[i] <<    ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     dk_98();     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000000 + 7;   const long long int N = 1000000 + 6;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int tc;     tc = 1;     while (tc--) {       long long int n, m;       cin >> n >> m;       string s[n];       for (long long int i = 0; i < n; i++) cin >> s[i];       long long int d[m];       for (long long int i = 0; i < m; i++) cin >> d[i];       long long int ans = 0;       for (long long int j = 0; j < m; j++) {         map<char, long long int> p;         long long int t = 0;         for (long long int i = 0; i < n; i++) {           p[s[i][j]]++;           t = max(t, p[s[i][j]]);         }         ans += t * d[j];       }       cout << ans;     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:134217728 )   using namespace std;   char buf[2];   vector<int> sign;   int n;   int main() {     sign.push_back(1);     scanf( %s , buf);     while (1) {       scanf( %s , buf);       if (buf[0] ==  = ) break;       sign.push_back(buf[0] ==  +  ? 1 : -1);       scanf( %s , buf);     }     scanf( %d , &n);     int MIN = 0;     int MAX = 0;     vector<int> res;     for (int i = 0; i < sign.size(); ++i) {       if (sign[i] == 1) {         MIN++;         MAX += n;         res.push_back(n);       } else {         MIN -= n;         MAX--;         res.push_back(1);       }     }     if (MIN <= n && n <= MAX) {       printf( Possible n );       int need = MAX - n;       for (int i = 0; i < res.size(); ++i) {         if (sign[i] == 1) {           int d = min(need, res[i] - 1);           res[i] -= d;           need -= d;         } else {           int d = min(need, n - res[i]);           res[i] += d;           need -= d;         }       }       printf( %d , res[0]);       for (int i = 1; i < res.size(); ++i) {         if (sign[i] == 1)           printf(  +  );         else           printf(  -  );         printf( %d , res[i]);       }       printf(  = %d n , n);     } else       printf( Impossible n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 105;   string name[MAXN], surname[MAXN];   bool u[MAXN];   int n;   int x1[30], x2[30];   int Getn() {     int res = 0;     for (int i = 0; i < 26; i++) res += min(x1[i], x2[i]);     return res;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> name[i];     for (int i = 1; i <= n; i++) cin >> surname[i];     sort(name + 1, name + n + 1);     sort(surname + 1, surname + n + 1);     for (int i = 1; i <= n; i++) x1[name[i][0] -  A ]++;     for (int i = 1; i <= n; i++) x2[surname[i][0] -  A ]++;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++)         if (!u[j]) {           int c = Getn();           x1[name[i][0] -  A ]--;           x2[surname[j][0] -  A ]--;           if (Getn() != c - (name[i][0] == surname[j][0])) {             x1[name[i][0] -  A ]++;             x2[surname[j][0] -  A ]++;             continue;           }           u[j] = true;           cout << name[i] <<     << surname[j];           if (i != n)             cout <<  ,  ;           else             cout << endl;           break;         }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 7;   unordered_map<int, int> f[N];   int n, m, k, ans, p[N], sx[N], sy[N];   inline int sol(int x, int y) {     if (f[x].count(y)) return f[x][y];     int t;     printf( ? %d %d n , x, y), fflush(stdout), scanf( %d , &t);     return f[x][y] = t;   }   inline vector<int> solve(int n, int m, vector<int>& x, vector<int>& y) {     if (n >= m) {       if (n == 1) {         vector<int> z;         z.resize(1), z[0] = 1;         ans = min(ans, sol(x[0], y[0]));         return z;       } else {         vector<int> a, b;         for (int i = 0; i < n; i += 2) a.push_back(x[i]);         for (int i = 0; i < m; i++) b.push_back(y[i]);         vector<int> z = solve((n + 1) / 2, m, a, b), q;         z.push_back(m);         int k = 0;         for (int i = 0; i < n; i++) {           if (i % 2 == 0)             q.push_back(z[k++]);           else {             int sum = 1000000001, pos = 0;             for (int c = z[k - 1]; c <= z[k]; c++) {               int g = sol(x[i], y[c - 1]);               if (sum > g) sum = g, pos = c;             }             q.push_back(pos), ans = min(ans, sum);           }         }         return q;       }     } else {       int l = 1;       sx[l] = 1, sy[l] = 1;       for (int i = 2; i <= m; i++) {         while (l > 0) {           int a = sol(x[sx[l] - 1], y[sy[l] - 1]),               b = sol(x[sx[l] - 1], y[i - 1]);           if (a > b)             l--;           else             break;         }         if (sx[l] != n) l++, sx[l] = sx[l - 1] + 1, sy[l] = i;       }       vector<int> a, b, w;       for (int i = 0; i < n; i++) a.push_back(x[i]);       for (int i = 1; i <= l; i++) b.push_back(y[sy[i] - 1]), w.push_back(sy[i]);       vector<int> z = solve(n, l, a, b), q;       for (int i = 0; i < w.size(); i++) p[i + 1] = w[i];       for (int i = 0; i < z.size(); i++) q.push_back(p[z[i]]);       return q;     }   }   int main() {     cin >> n >> m;     vector<int> a, b;     a.resize(n), b.resize(m), ans = 1000000000;     for (int i = 0; i < n; i++) a[i] = i + 1;     for (int i = 0; i < m; i++) b[i] = i + 1;     solve(n, m, a, b);     printf( ! %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> s;     s =  ?  + s +  ? ;     int c = 0;     bool flag = true;     for (int i = 1; i <= n; i++) {       if (s[i] ==  ? ) {         c++;         if (s[i - 1] == s[i + 1] || s[i - 1] ==  ?  || s[i + 1] ==  ? ) {           flag = false;         }       }       if (s[i] == s[i - 1] && s[i] !=  ? ) {         flag = true;         break;       }     }     cout << (c == 0 || flag ?  NO  :  YES ) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int x[n], y[n];     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];     }     if (n == 1) {       cout << -1 << endl;     } else if (n == 2) {       if (x[0] != x[1] && y[0] != y[1]) {         int a = fabs(x[0] - x[1]), b = fabs(y[0] - y[1]);         cout << a * b << endl;       } else {         cout << -1 << endl;       }     } else if (n == 3 || n == 4) {       sort(x, x + n);       sort(y, y + n);       int a = fabs(x[0] - x[n - 1]), b = fabs(y[0] - y[n - 1]);       cout << a * b << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long t, n, i, j, k, l, r, minn, maxx, ans, x, y;     cin >> t;     while (t--) {       cin >> n;       cin >> maxx >> minn;       for (i = 1; i < n; i++) {         cin >> x >> y;         maxx = max(maxx, x);         minn = min(minn, y);       }       if (maxx <= minn)         ans = 0;       else         ans = maxx - minn;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int q;   int main(void) {     cin >> q;     while (q--) {       long long l, r, ans = 0, num = 0;       cin >> l >> r;       num = r - l + 1;       if (r & 1) {         ans -= num / 2;         if (num & 1) ans -= l;       } else {         ans += num / 2;         if (num & 1) ans += l;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   #define rep(i,a,b) for(int i = (a); i < (b); ++i)   #define rrep(i,a,b) for(int i = (b); i --> (a);)   #define sz(v) int(v.size())   using namespace std;      string inf, zero;      string add(string x, string y, int init){    string res(sz(x),  ? );    int todo = init;    rrep(i,0,sz(x)){     todo += x[i] + y[i] - 2 *  0 ;     res[i] = todo % 2 +  0 ;     todo /= 2;    }    if(todo) return inf;    return res;   }      int main(){    int n, b;    cin >> n >> b;    inf = string(b,  1 );    zero = string(b,  0 );       vector<string> fibs = {zero, zero}; // fibonacci numbers minus one    while(fibs.back() < inf)     fibs.push_back(add(fibs.back(), fibs[sz(fibs)-2], 1));    int todo = sz(fibs)-1;    deque<pair<int, bool>> ls;    rep(i,0,n) ls.push_back({i+1, true});    string lb = zero; // current lower bound    while(!ls.empty()){     string ans;     if(add(lb, fibs[todo], 0) == inf) ans =  no ;     else { cout << ls.back().first <<     << add(lb, fibs[max(0, todo)], 0) << endl;            cin >> ans; }      if(ans ==  yes ){      lb = add(lb, fibs[todo], 1);      while(!ls.empty() && ls[0].second){       ls.pop_front();       todo += 2;      }      if(ls.empty()) break;      ls[0].second = true;     } else {      ls.push_front({ls.back().first, false});      ls.pop_back();     }     if(--todo <= 0){      todo += ls[0].second ? 2 : 1;      ls.pop_front();     }    }    cout << 0 <<     << lb << endl;   }


#include <bits/stdc++.h>   using namespace std;   char _;   const long long maxN = 200 * 1000 + 5;   const long long maxM = 5000 + 5;   const long long mod = 1000 * 1000 * 1000 + 7;   const long long base = 701;   const long long SQ = 500;   const long long maxL = 20;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long s, x;     cin >> s >> x;     if (s < x) {       cout << 0 << endl;       return 0;     }     long long ans = 1;     for (long long i = 0; i < 40; i++)       if (x >> i & 1) ans *= 2;     long long carry = 0;     for (long long i = 40; i >= 0; i--) {       long long g = (s >> i & 1), f = (x >> i & 1);       if (carry == 0 && f == 0 && g == 0) continue;       if (carry == 0 && f == 0 && g == 1) {         carry = 1;         continue;       }       if (carry == 0 && f == 1 && g == 0) {         cout << 0 << endl;         return 0;       }       if (carry == 0 && f == 1 && g == 1) continue;       if (carry == 1 && f == 0 && g == 0) {         carry = 0;         continue;       }       if (carry == 1 && f == 0 && g == 1) continue;       if (carry == 1 && f == 1 && g == 0) continue;       if (carry == 1 && f == 1 && g == 1) {         cout << 0 << endl;         return 0;       }     }     if (s == x) ans -= 2;     if (carry)       cout << 0 << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using ul = std::uint32_t;   using li = std::int32_t;   using ull = std::uint64_t;   using ll = std::int64_t;   using llf = long double;   ul n, m, k;   const ul maxn = 2e5;   const ul base = 998244353;   ul plus(ul a, ul b) { return a + b < base ? a + b : a + b - base; }   ul plus(ul a, ul b, ul c) { return plus(plus(a, b), c); }   ul minus(ul a, ul b) { return a < b ? a + base - b : a - b; }   ul mul(ul a, ul b) { return ull(a) * ull(b) % base; }   ul mul(ul a, ul b, ul c) { return mul(mul(a, b), c); }   ul mul(ul a, ul b, ul c, ul d) { return mul(mul(a, b, c), d); }   void exgcd(li a, li b, li& x, li& y) {     if (b) {       exgcd(b, a % b, y, x);       y -= a / b * x;     } else {       x = 1;       y = 0;     }   }   ul inverse(ul a) {     li x, y;     exgcd(a, base, x, y);     return x < 0 ? x + li(base) : x;   }   ul pow(ul a, ul b) {     ul ret = 1;     while (b) {       if (b & 1) {         ret = mul(a, ret);       }       b >>= 1;       a = mul(a, a);     }     return ret;   }   ul h[maxn + 1];   ul fac[maxn + 1];   ul fiv[maxn + 1];   ul twopow[maxn + 1];   ul bi(ul a, ul b) { return mul(fac[a], fiv[b], fiv[a - b]); }   ul g(ul a) {     ul ret = mul(base + 1 >> 1, twopow[a]);     if (~a & 1) {       ret = minus(ret, mul(base + 1 >> 1, bi(a, a >> 1)));     }     return ret;   }   int main() {     fac[0] = 1;     twopow[0] = 1;     for (ul i = 1; i <= maxn; ++i) {       fac[i] = mul(fac[i - 1], i);       twopow[i] = plus(twopow[i - 1], twopow[i - 1]);     }     fiv[maxn] = inverse(fac[maxn]);     for (ul i = maxn; i; --i) {       fiv[i - 1] = mul(fiv[i], i);     }     std::scanf( %u%u , &n, &k);     k %= base;     for (ul i = 1; i <= n; ++i) {       std::scanf( %u , &h[i]);     }     for (ul i = 1; i <= n; ++i) {       m += h[i] != h[i % n + 1];     }     ul ans = 0;     for (ul a = 0; a <= m; ++a) {       ans = plus(ans, mul(bi(m, a), pow(minus(k, 2), m - a), g(a)));     }     ans = mul(ans, pow(k, n - m));     std::printf( %u n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<int> s;   map<int, int> mm;   int a[500005];   int main() {     int n, m, d;     cin >> n >> m >> d;     for (int i = 0; i < n; i++) {       int k;       cin >> k;       s.insert(k);       a[i] = k;     }     set<int>::iterator it1, it2, it3;     int sum = 0;     for (it1 = s.begin(); it1 != s.end(); it1++) {       sum++;       mm[*it1] = sum;       it2 = it1;       while (s.upper_bound((*it2) + d) != s.end()) {         it3 = s.upper_bound((*it2) + d);         mm[*it3] = sum;         it2 = it3;         s.erase(it3);       }     }     cout << sum << endl;     for (int i = 0; i < n; i++) {       cout << mm[a[i]] <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1100;   const int MAXM = 1100;   const int MAXK = 100100;   int n, m, k, len[MAXK], max_len[MAXN][MAXM][4];   int mm[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   char mmap[MAXN][MAXM], dir[MAXK], direction[256];   vector<pair<int, int> > possible;   vector<char> sol;   int get_max_len(int r, int c, int d) {     if (max_len[r][c][d] != -1) return max_len[r][c][d];     if (mmap[r][c] ==  # ) return -1;     int &ml = max_len[r][c][d];     ml = 0;     int nr = r + mm[d][0];     int nc = c + mm[d][1];     ml += 1 + get_max_len(nr, nc, d);     return ml;   }   bool solve(int r, int c) {     for (int i = 0; i < k; i++) {       int d = direction[(int)dir[i]];       int maxd = get_max_len(r, c, d);       if (maxd < len[i]) return false;       r += mm[d][0] * len[i];       c += mm[d][1] * len[i];     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     direction[ N ] = 1;     direction[ S ] = 0;     direction[ E ] = 2;     direction[ W ] = 3;     cin >> n >> m;     for (int i = 0; i <= n + 1; i++)       for (int j = 0; j <= m + 1; j++) {         if (i == 0 || i > n || j == 0 || j > m)           mmap[i][j] =  # ;         else           cin >> mmap[i][j];         if ( A  <= mmap[i][j] && mmap[i][j] <=  Z )           possible.push_back(make_pair(i, j));         max_len[i][j][0] = -1;         max_len[i][j][1] = -1;         max_len[i][j][2] = -1;         max_len[i][j][3] = -1;       }     cin >> k;     for (int i = 0; i < k; i++) cin >> dir[i] >> len[i];     for (int i = 0; i < (int)possible.size(); i++) {       int r = possible[i].first;       int c = possible[i].second;       if (solve(r, c)) sol.push_back(mmap[r][c]);     }     if (sol.empty())       cout <<  no solution  << endl;     else {       sort(sol.begin(), sol.end());       for (int i = 0; i < (int)sol.size(); i++) cout << sol[i];       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, num = 1, mul;     cin >> n;     string s =  codeforces ;     int ln = s.length(), a[12] = {0};     for (long long int i = 2; i <= 100; i++) {       long long int curr = pow(i, 10ll);       if (curr >= n) {         for (int j = 0; j < 10; j++) {           a[j] = i - 1;           num *= (i - 1);         }         mul = i;         break;       }     }     int pos = 0;     while (num < n) {       num /= (mul - 1);       num *= mul;       a[pos] = mul;       pos++;     }     for (int i = 0; i < 10; i++) {       for (int j = 0; j < a[i]; j++) cout << s[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD9 = 1e9 + 7;   const int MOD91 = 1e9 + 9;   const long long MOD12 = 1e12 + 39LL;   const long long MOD15 = 1e15 + 37LL;   const int INF = 1e9;   const int base = 1e9;   const int MAX = 2e5;   const long double EPS = 1e-10;   int n;   int a[200000];   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     sort(a, a + n);     if (a[0] == a[n - 1] && a[0] == 1) {       for (int i = 0; i < n - 1; ++i) {         cout << a[i] <<    ;       }       cout << 2;       return 0;     }     cout << 1 <<    ;     for (int i = 0; i < n - 1; ++i) {       cout << a[i] <<    ;     }     return 0;   }