#include <bits/stdc++.h>   using namespace std;   int mat[(int)1e3][(int)1e3], n;   int dp2[(int)1e3][(int)1e3];   int dp5[(int)1e3][(int)1e3];   int changeRow[] = {1, 0};   int changeCol[] = {0, 1};   int pw2[(int)1e3][(int)1e3], pw5[(int)1e3][(int)1e3];   string dir[] = { D ,  R };   int pwr(int n, int k) {     int ret = 0;     while (n >= k and n % k == 0) {       ret++;       n /= k;     }     return ret;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (int x = 0; x < n; x++)       for (int y = 0; y < n; y++) cin >> mat[x][y];     bool hasZero = 0;     pair<int, int> pos;     for (int x = 0; x < n; x++) {       for (int y = 0; y < n; y++) {         if (mat[x][y] == 0) {           pos = make_pair(x, y);           hasZero = true;           break;         }       }       if (hasZero) break;     }     for (int x = 0; x < n; x++) {       for (int y = 0; y < n; y++) {         pw2[x][y] = pwr(mat[x][y], 2);         pw5[x][y] = pwr(mat[x][y], 5);       }     }     for (int x = 0; x < n; x++) {       for (int y = 0; y < n; y++) {         dp2[x][y] = 2e9;         dp5[x][y] = 2e9;       }     }     dp2[0][0] = pw2[0][0];     for (int x = 0; x < n; x++) {       for (int y = 0; y < n; y++) {         for (int z = 0; z < 2; z++) {           int X = x + changeRow[z];           int Y = y + changeCol[z];           if (X == x and Y == y) continue;           if (X >= 0 and Y >= 0 and X < n and Y < n) {             dp2[X][Y] = min(dp2[X][Y], pw2[X][Y] + dp2[x][y]);           }         }       }     }     dp5[0][0] = pw5[0][0];     for (int x = 0; x < n; x++) {       for (int y = 0; y < n; y++) {         for (int z = 0; z < 2; z++) {           int X = x + changeRow[z];           int Y = y + changeCol[z];           if (X == x and Y == y) continue;           if (X >= 0 and Y >= 0 and X < n and Y < n) {             dp5[X][Y] = min(dp5[X][Y], pw5[X][Y] + dp5[x][y]);           }         }       }     }     int res2 = dp2[n - 1][n - 1];     int res5 = dp5[n - 1][n - 1];     int res = min(res2, res5);     string ans =   ;     if (hasZero && res > 1) {       cout <<  1 n ;       for (int x = 0; x < pos.first; x++) cout <<  D ;       for (int x = 0; x < pos.second; x++) cout <<  R ;       for (int x = pos.first; x < n - 1; x++) cout <<  D ;       for (int x = pos.second; x < n - 1; x++) cout <<  R ;     } else if (res == res2) {       cout << res <<   n ;       int i = n - 1, j = n - 1;       while (!(i == 0 and j == 0)) {         for (int z = 0; z < 2; z++) {           int X = i - changeRow[z];           int Y = j - changeCol[z];           if (X == i and Y == j) continue;           if (X >= 0 and Y >= 0 and X < n and Y < n) {             if (dp2[i][j] == dp2[X][Y] + pw2[i][j]) {               ans += dir[z];               i = X;               j = Y;               break;             }           }         }       }       assert(i == 0 and j == 0);       reverse(ans.begin(), ans.end());       for (auto x : ans) cout << x;       cout <<   n ;     } else {       cout << res <<   n ;       assert(res == res5);       int i = n - 1, j = n - 1;       while (!(i == 0 and j == 0)) {         for (int z = 0; z < 2; z++) {           int X = i - changeRow[z];           int Y = j - changeCol[z];           if (X == i and Y == j) continue;           if (X >= 0 and Y >= 0 and X < n and Y < n) {             if (dp5[i][j] == dp5[X][Y] + pw5[i][j]) {               ans += dir[z];               i = X;               j = Y;               break;             }           }         }       }       assert(i == 0 and j == 0);       reverse(ans.begin(), ans.end());       for (auto x : ans) cout << x;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 5e5 + 10;   vector<int> v[31];   long long par[31], X[31], Y[31], vis[31];   int xxx = 31;   void bfs() {     queue<tuple<int, int, int>> qu;     qu.push(make_tuple(1, 0, xxx));     vis[1] = 1;     X[1] = Y[1] = 1ll << xxx;     while (!qu.empty()) {       tuple<int, int, int> xx = qu.front();       qu.pop();       int s = get<0>(xx);       int dd = get<1>(xx);       int pp = get<2>(xx);       int dir = 1;       for (auto it : v[s]) {         if (vis[it]) continue;         vis[it] = 1;         if (dir == dd) dir++;         if (dir == 1) {           X[it] = X[s] + (1ll << (pp - 1));           Y[it] = Y[s];           qu.push(make_tuple(it, 2, pp - 1));           dir++;         } else if (dir == 2) {           X[it] = X[s] - (1ll << (pp - 1));           Y[it] = Y[s];           qu.push(make_tuple(it, 1, pp - 1));           dir++;         } else if (dir == 3) {           X[it] = X[s];           Y[it] = Y[s] - (1ll << (pp - 1));           qu.push(make_tuple(it, 4, pp - 1));           dir++;         } else {           X[it] = X[s];           Y[it] = Y[s] + (1ll << (pp - 1));           qu.push(make_tuple(it, 3, pp - 1));           dir++;         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int flag = 0;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);       if (v[a].size() > 4 || v[b].size() > 4) flag = 1;     }     if (flag)       puts( NO );     else {       bfs();       cout <<  YES n ;       for (int i = 1; i <= n; i++) cout << X[i] <<     << Y[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 233, mxzt = (1 << 20) + 23;   int f[21][mxzt], tmp[2][mxzt][20];   int stv[maxn];   int i, j, k, n, m;   char s[maxn];   int ra, fh;   char rx;   inline int read() {     rx = getchar(), ra = 0, fh = 1;     while (rx < 48) rx ==  -  && (fh = -1), rx = getchar();     while (rx > 47) ra = ra * 10 + rx - 48, rx = getchar();     return ra * fh;   }   inline int getnum1(int x) {     int n = 0;     while (x) n += x & 1, x >>= 1;     return n;   }   inline int min(int a, int b) { return a < b ? a : b; }   int main() {     n = read(), m = read();     int mx = 1 << n;     for (i = 1; i <= n; i++) {       scanf( %s , s + 1);       for (j = 1; j <= m; j++) stv[j] = stv[j] << 1 | (s[j] - 48);     }     for (i = 1; i <= m; i++) f[0][stv[i]]++;     int zt, p, nf;     bool now = 1, pre = 0;     int *nt;     for (i = 1; i <= n; i++, swap(now, pre)) {       for (zt = 0; zt < mx; zt++) {         for (nf = p = 0, nt = tmp[now][zt]; p < n; p++, nt++)           nf += (*nt = f[i - 1][zt ^ (1 << p)] - tmp[pre][zt ^ (1 << p)][p]);         f[i][zt] = nf / i;       }     }     int ans = 1e9;     for (zt = 0; zt < mx; zt++) {       k = 0;       for (j = 0; j <= n && k < ans; j++) k += min(j, n - j) * f[j][zt];       if (j > n) ans = k;     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   int p;   struct seg {     std::vector<int64_t> cuts;     int64_t sum;     int64_t operator()(int64_t x) const {       return x + sum -              p * int64_t(std::upper_bound(begin(cuts), end(cuts), x) -                          begin(cuts));     }   };   seg operator*(seg const& a, seg const& b) {     for (unsigned i = 1; i < a.cuts.size(); ++i)       assert(a.cuts[i] - a.cuts[i - 1] >= p);     for (unsigned i = 1; i < b.cuts.size(); ++i)       assert(b.cuts[i] - b.cuts[i - 1] >= p);     seg out;     out.sum = a.sum + b.sum;     out.cuts.reserve(a.cuts.size() + b.cuts.size());     int64_t x = INT64_MIN / 2;     auto iter1 = begin(a.cuts);     auto iter2 = begin(b.cuts);     while (true) {       auto x1 = x + a.sum - p * int64_t(iter1 - begin(a.cuts));       auto x2 = x1 + b.sum - p * int64_t(iter2 - begin(b.cuts));       assert(iter1 == std::upper_bound(begin(a.cuts), end(a.cuts), x));       assert(a(x) == x1);       assert(iter2 == std::upper_bound(begin(b.cuts), end(b.cuts), x1));       assert(b(x1) == x2);       auto d1 = iter1 == end(a.cuts) ? INT64_MAX : *iter1 - x;       auto d2 = iter2 == end(b.cuts) ? INT64_MAX : *iter2 - x1;       assert(d1 > 0);       assert(d2 > 0);       if (d1 != INT64_MAX)         assert(iter1 != std::upper_bound(begin(a.cuts), end(a.cuts), x + d1));       if (d2 < d1) {         assert(iter1 == std::upper_bound(begin(a.cuts), end(a.cuts), x + d2));         assert(a(x + d2) == x1 + d2);         assert(iter2 != std::upper_bound(begin(b.cuts), end(b.cuts), x1 + d2));         x += d2;         out.cuts.push_back(x);         ++iter2;       } else if (d1 == INT64_MAX) {         break;       } else {         x += d1;         ++iter1;         auto new_x1 = x1 + d1 - p;         assert(a(x) == new_x1);         assert(std::upper_bound(begin(b.cuts), end(b.cuts), new_x1) <= iter2);         if (iter2 != begin(b.cuts) and iter2[-1] > new_x1) {           --iter2;           assert(std::upper_bound(begin(b.cuts), end(b.cuts), new_x1) == iter2);         } else {           out.cuts.push_back(x);         }       }     }     assert(out.cuts.size() == a.cuts.size() + b.cuts.size());     return out;   }   std::vector<seg> st;   int main() {     std::ios::sync_with_stdio(0);     std::cin.tie(0);     int n, nquery;     std::cin >> n >> nquery >> p;     st.resize(n * 2);     for (int i = n; i < 2 * n; ++i) {       int ai;       std::cin >> ai;       st[i].cuts.push_back(p - ai);       st[i].sum = ai;     }     for (int i = n; --i;) st[i] = st[i << 1] * st[i << 1 | 1];     while (nquery--) {       int l, r;       std::cin >> l >> r;       --l;       l += n;       r += n;       int64_t out = 0;       std::vector<seg*> pendr;       while (l < r) {         if (l & 1) out = st[l++](out);         if (r & 1) pendr.push_back(&(st[--r]));         l >>= 1;         r >>= 1;       }       while (not pendr.empty()) {         out = (*pendr.back())(out);         pendr.pop_back();       }       std::cout << out <<   n ;     }   }


#include <bits/stdc++.h>   int main() {     char s[5200] = {0}, next[5200] = {0}, p[5200] = {0}, t[5200] = {0};     while (scanf( %s , s + 1) != EOF) {       s[0] =  a ;       double sum = 0;       int f = 0;       while (sscanf(s,  %*[^0-9]%[0-9.]%[^ 0] , p, next) > 0) {         double num1 = 0, num2 = 0;         int len = strlen(p), flag = 0;         if (len > 3 && p[len - 3] ==  . ) {           sscanf(p + len - 3,  %lf , &num1);           flag = f = 1;         }         if (flag == 1) len = len - 3;         for (int i = 0; i < len; i++) {           if (p[i] ==  . ) continue;           num2 = num2 * 10 + (p[i] -  0 );         }         sum += num1 + num2;         strcpy(s, next);         memset(next, 0, sizeof(next));       }       sprintf(t,  %.2f , sum);       int len = strlen(t), k = 0;       char ans[5200];       if (f == 0) len -= 3;       if (f == 1) {         ans[k++] = t[--len];         ans[k++] = t[--len];         ans[k++] = t[--len];         if (ans[0] ==  0  && ans[1] ==  0 ) k = 0;       }       for (int i = len - 1, counts = 1; i >= 0; i--, counts++) {         if (counts % 3 == 1 && counts != 1) ans[k++] =  . ;         ans[k++] = t[i];       }       for (int i = k - 1; i >= 0; i--) printf( %c , ans[i]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, num[100100];   inline int as(int u) {     int a, b;     if (num[u]) return num[u];     printf( ? %d n , u);     fflush(stdout);     scanf( %d , &a);     return num[u] = a;   }   inline void pd(int u) {     if (as(u) == as(u + m)) {       printf( ! %d n , u);       exit(0);     }   }   int main() {     int i, j, l, r, mid, p, q;     cin >> n;     m = n / 2;     if (m % 2) {       puts( ! -1 );       return 0;     }     as(1), as(m + 1), pd(1);     l = 2, r = m;     for (; l <= r;) {       mid = ((l + r) >> 1);       p = as(mid), q = as(mid + m);       pd(mid);       if ((p > q) ^ (num[1] > num[m + 1]))         r = mid - 1;       else         l = mid + 1;     }   }


#include <bits/stdc++.h>   long num[1000000];   int main() {     long long ans;     long i, j, k, n;     long long max1, max2;     scanf( %ld , &n);     ans = 0;     for (i = 1; i <= n; i++) {       scanf( %ld , &num[i]);       ans += num[i];     }     max1 = 0;     max2 = 0;     for (i = 1; i <= n; i++) {       scanf( %ld , &num[i]);       if (num[i] > max1) {         max2 = max1;         max1 = num[i];       } else {         if (num[i] > max2) {           max2 = num[i];         }       }     }     if (max1 + max2 < ans) {       printf( NO n );     } else {       printf( YES n );     }     return 0;   }


#include <bits/stdc++.h>   long long n, m, Now, Ans, i;   long long sumi(long long a, long long b);   int main() {     scanf( %I64d %I64d , &n, &m);     Now = sumi(2, m);     if (Now == 0)       Now = 1000000009 - 1;     else       Now--;     Ans = 1;     for (i = 1; i <= n; i++) {       Ans *= Now;       Ans %= 1000000009;       if (Now == 0)         Now = 1000000009 - 1;       else         Now--;     }     printf( %I64d n , Ans);     return 0;   }   long long sumi(long long a, long long b) {     long long ret = 1, i, c = a;     for (i = 1; i <= b; i += i) {       if ((b & i) > 0) {         ret *= c;         ret %= 1000000009;       }       c *= c;       c %= 1000000009;     }     return ret;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n, m, val, i, j = 0, sum = 0, k = 0;     vector<long> toys;     vector<long> selected;     cin >> n >> m;     for (i = 0; i < n; i++) {       cin >> val;       toys.push_back(val);     }     sort(toys.begin(), toys.end());     for (i = 0; i < 1000000000; i++) {       if (j < (long)toys.size()) {         if (toys[j] == (i + 1)) {           j++;         } else {           if (sum + i + 1 <= m) {             selected.push_back(i + 1);             sum += i + 1;             k++;           } else {             break;           }         }       } else if (sum + i + 1 <= m) {         selected.push_back(i + 1);         sum += i + 1;         k++;       } else {         break;       }     }     cout << k << endl;     for (auto t : selected) {       cout << t <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   const long long inf = 0x3f3f3f3f3f3f3f3f;   int n, m, q, u[N], v[N], w[N];   long long d[2][N];   bool vis[N];   vector<pair<long long, int> > g[N];   pair<long long, int> pre[N];   void dij(int s, long long d[]) {     for (int i = (1); i < (n + 1); i++) d[i] = inf, vis[i] = 0;     d[s] = 0;     priority_queue<pair<long long, int> > q;     q.push(pair<long long, int>(0, s));     while (!q.empty()) {       int u = q.top().second;       q.pop();       if (vis[u]) continue;       vis[u] = 1;       for (auto it : g[u]) {         if (d[u] + w[it.second] < d[it.first]) {           d[it.first] = d[u] + w[it.second];           pre[it.first] = pair<long long, int>(u, it.second);           q.push(pair<long long, int>(-d[it.first], it.first));         }       }     }   }   int k[N], e[N];   bool used[N], in[N];   vector<long long> ad[N], del[N];   long long mn[N];   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = (1); i < (m + 1); i++) {       scanf( %d%d%d , &u[i], &v[i], &w[i]);       g[u[i]].push_back(pair<long long, int>(v[i], i));       g[v[i]].push_back(pair<long long, int>(u[i], i));     }     dij(n, d[1]);     dij(1, d[0]);     vector<int> vec;     for (int i = (2); i < (n + 1); i++) used[pre[i].second] = 1;     pre[1] = pair<long long, int>(0, 0);     for (int i = n; i >= 1; i = pre[i].first)       in[pre[i].second] = 1, vec.push_back(i);     int cnt = 0;     reverse(vec.begin(), vec.end());     for (auto v : vec) k[v] = ++cnt;     for (int i = (1); i < (n + 1); i++) {       if (d[0][i] == inf) continue;       if (!k[i]) {         int u = i;         for (; !k[u]; u = pre[u].first)           ;         for (int v = i; !k[v]; v = pre[v].first) k[v] = k[u];       }     }     for (int i = (1); i < (m + 1); i++) {       if (used[i]) continue;       int l = k[u[i]], r = k[v[i]];       if (l == r) continue;       if (l > r) swap(u[i], v[i]), swap(l, r);       ad[l].push_back(d[0][u[i]] + w[i] + d[1][v[i]]);       del[r].push_back(d[0][u[i]] + w[i] + d[1][v[i]]);     }     multiset<long long> S;     S.insert(inf);     for (int i = (1); i < (cnt); i++) {       for (auto v : del[i]) S.erase(S.find(v));       for (auto v : ad[i]) S.insert(v);       mn[i] = *(S.begin());     }     int x, y;     while (q--) {       scanf( %d%d , &x, &y);       long long ans = min(d[0][u[x]] + d[1][v[x]], d[0][v[x]] + d[1][u[x]]) + y;       if (!in[x]) {         ans = min(ans, d[0][n]);       } else {         ans = min(ans, mn[min(k[u[x]], k[v[x]])]);       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> graph[200002];   int visited[200002], sub[200002];   int subsize(int root) {     visited[root] = 1;     for (int child : graph[root]) {       if (!visited[child]) sub[root] += subsize(child);     }     return sub[root];   }   void destroy(int root, int par) {     for (int child : graph[root]) {       if (child != par && (sub[child] % 2 == 0)) destroy(child, root);     }     printf( %d n , root);     for (int child : graph[root]) {       if (child != par && (sub[child] & 1)) destroy(child, root);     }   }   int main() {     for (int i = 0; i < 200002; i++) sub[i] = 1;     int n, x;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       if (x) {         graph[x].push_back(i);         graph[i].push_back(x);       }     }     if (n % 2 == 0)       printf( NO );     else {       subsize(1);       printf( YES n );       destroy(1, 0);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, crush[100005], ans = -1;   bool exi[100005];   long long ms(int o, int x, int p) {     if (p > 2 * n) return -1;     if (crush[x] == x) return p ? -1 : 0;     if ((x == o) && p) return 0;     int t = ms(o, crush[x], p + 1);     return (t < 0 ? t : t + 1);   }   long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }   long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , &crush[i]);       exi[crush[i]] = 1;     }     for (int i = 1; i <= n; i++) {       if (!exi[i]) {         ans = -1;         break;       }       long long tmp = ms(i, i, 0);       if (tmp <= 0) tmp = 1;       tmp /= (2 - (tmp & 1));       ans = ans < 0 ? tmp : lcm(ans, tmp);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Array[100005], Left[100005];   int Right[100005];   int main() {     int N, i;     scanf( %d , &N);     for (i = 1; i <= N; ++i) {       scanf( %d , Array + i);       Left[i] = min(Left[i - 1] + 1, Array[i]);     }     for (i = N; i >= 1; --i) Right[i] = min(Right[i + 1] + 1, Array[i]);     int Ans = 0;     for (i = 1; i <= N; ++i) Ans = max(Ans, min(Left[i], Right[i]));     printf( %d n , Ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > di = {{2, 1},   {1, 2},   {-1, 2}, {-2, 1},                                 {-2, -1}, {-1, -2}, {1, -2}, {2, -1}};   int n, m;   int X1, Y1, X2, Y2;   queue<pair<int, int> > q1, q2;   bool isValid(pair<int, int> cell) {     return (1 <= cell.first && cell.first <= n && 1 <= cell.second &&             cell.second <= m);   }   int dist1[1009][1009];   int dist2[1009][1009];   pair<int, int> dad1[1009][1009];   pair<int, int> dad2[1009][1009];   bool was1[1009][1009];   bool was2[1009][1009];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     cin >> X1 >> Y1 >> X2 >> Y2;     q1.push({n / 2, m / 2});     dist1[n / 2][m / 2] = 0;     was1[n / 2][m / 2] = true;     while (!q1.empty()) {       pair<int, int> cur = q1.front();       q1.pop();       for (pair<int, int> d : di) {         pair<int, int> neighbour;         neighbour.first = cur.first + d.first;         neighbour.second = cur.second + d.second;         if (!isValid(neighbour)) continue;         if (was1[neighbour.first][neighbour.second]) continue;         dist1[neighbour.first][neighbour.second] =             dist1[cur.first][cur.second] + 1;         dad1[neighbour.first][neighbour.second] = cur;         was1[neighbour.first][neighbour.second] = true;         q1.push(neighbour);       }     }     q2.push({n / 2 + 1, m / 2});     dist2[n / 2 + 1][m / 2] = 0;     was2[n / 2 + 1][m / 2] = true;     while (!q2.empty()) {       pair<int, int> cur = q2.front();       q2.pop();       for (pair<int, int> d : di) {         pair<int, int> neighbour;         neighbour.first = cur.first + d.first;         neighbour.second = cur.second + d.second;         if (!isValid(neighbour)) continue;         if (was2[neighbour.first][neighbour.second]) continue;         dist2[neighbour.first][neighbour.second] =             dist2[cur.first][cur.second] + 1;         dad2[neighbour.first][neighbour.second] = cur;         was2[neighbour.first][neighbour.second] = true;         q2.push(neighbour);       }     }     if (dist1[X1][Y1] < dist1[X2][Y2] && dist1[X1][Y1] <= dist2[X2][Y2]) {       cout <<  WHITE  << endl;       fflush(stdout);       while (1) {         pair<int, int> uj = dad1[X1][Y1];         X1 = uj.first;         Y1 = uj.second;         cout << X1 <<     << Y1 << endl;         fflush(stdout);         if (X1 == n / 2 && Y1 == m / 2) return 0;         cin >> X2 >> Y2;         if (X2 == -1 && Y2 == -1) return 0;       }     }     if (dist2[X2][Y2] + 1 < dist2[X1][Y1] && dist2[X2][Y2] < dist1[X1][Y1]) {       cout <<  BLACK  << endl;       fflush(stdout);       cin >> X1 >> Y1;       if (X1 == -1 && Y1 == -1) return 0;       while (1) {         pair<int, int> uj = dad2[X2][Y2];         X2 = uj.first;         Y2 = uj.second;         cout << X2 <<     << Y2 << endl;         fflush(stdout);         if (X2 == n / 2 + 1 && Y2 == m / 2) return 0;         cin >> X1 >> Y1;         if (X1 == -1 && Y1 == -1) return 0;       }     }     if ((X1 + Y1) % 2 != (X2 + Y2) % 2) {       cout <<  WHITE  << endl;       fflush(stdout);       bool reached = false;       if (X1 == n / 2 + 1 && Y1 == m / 2) {         reached = true;       }       while (1) {         if (reached) break;         pair<int, int> uj = dad2[X1][Y1];         X1 = uj.first;         Y1 = uj.second;         cout << X1 <<     << Y1 << endl;         fflush(stdout);         if (X1 == X2 && Y1 == Y2) return 0;         if (X1 == n / 2 + 1 && Y1 == m / 2) break;         cin >> X2 >> Y2;         if (X2 == -1 && Y2 == -1) return 0;       }       if (!reached) cin >> X2 >> Y2;       int ddx = abs(X1 - X2);       int ddy = abs(Y1 - Y2);       if ((ddx == 1 && ddy == 2) || (ddx == 2 && ddy == 1)) {         cout << X2 <<     << Y2 << endl;         fflush(stdout);         return 0;       }       cout << (n / 2) <<     << (m / 2) + 2 << endl;       fflush(stdout);       if (n / 2 == X2 && m / 2 + 2 == Y2) return 0;       cin >> X2 >> Y2;       cout << (n / 2) + 2 <<     << (m / 2) + 1 << endl;       fflush(stdout);       if (n / 2 + 2 == X2 && m / 2 + 1 == Y2) return 0;       cin >> X2 >> Y2;       cout << (n / 2) <<     << (m / 2) << endl;       fflush(stdout);       return 0;     } else {       cout <<  BLACK  << endl;       fflush(stdout);       cin >> X1 >> Y1;       if (X1 == -1 && Y1 == -1) return 0;       int dx = abs(X2 - (n / 2 + 1));       int dy = abs(Y2 - m / 2);       if ((dx == 1 && dy == 2) || (dx == 2 && dy == 1)) {         cout << n / 2 + 1 <<     << m / 2 << endl;         fflush(stdout);         return 0;       }       bool reached = false;       if (X2 == n / 2 && Y2 == m / 2) {         reached = true;       }       while (1) {         if (reached) break;         pair<int, int> uj = dad1[X2][Y2];         X2 = uj.first;         Y2 = uj.second;         cout << X2 <<     << Y2 << endl;         fflush(stdout);         if (X1 == X2 && Y1 == Y2) return 0;         if (X2 == n / 2 && Y2 == m / 2) break;         cin >> X1 >> Y1;         if (X1 == -1 && Y1 == -1) return 0;       }       if (!reached) cin >> X1 >> Y1;       int ddx = abs(X1 - X2);       int ddy = abs(Y1 - Y2);       if ((ddx == 1 && ddy == 2) || (ddx == 2 && ddy == 1)) {         cout << X1 <<     << Y1 << endl;         fflush(stdout);         return 0;       }       cout << (n / 2) + 2 <<     << (m / 2) + 1 << endl;       fflush(stdout);       if (n / 2 + 2 == X1 && m / 2 + 1 == Y1) return 0;       cin >> X1 >> Y1;       cout << (n / 2) <<     << (m / 2) + 2 << endl;       fflush(stdout);       if (n / 2 == X1 && m / 2 + 2 == Y1) return 0;       cin >> X1 >> Y1;       cout << (n / 2) + 1 <<     << (m / 2) << endl;       fflush(stdout);       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, t;   int dp[21][5][11][11][2];   int solve(int pos, int h, int mn, int mx, bool w) {     if (mn > t - 1 || mx > t) return 0;     if (pos == n) return mx == t && mn == t - 1;     int &ref = dp[pos][h][mn][mx][w];     if (ref != -1) return ref;     ref = 0;     for (int i = 1; i < 5; ++i) {       if (i == h) continue;       bool wp = i > h;       if (!pos)         ref += solve(pos + 1, i, mn, mx, w);       else if (pos == 1)         ref += solve(pos + 1, i, mn, mx, wp);       else         ref += solve(pos + 1, i, mn + (!w & wp), mx + (w & !wp), wp);     }     return ref;   }   int main() {     scanf( %d %d , &n, &t);     memset(dp, -1, sizeof(dp));     int sol = solve(0, 0, 0, 0, 0);     printf( %d n , sol);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using uint = unsigned;   using ll = long long;   using ull = unsigned long long;   using vi = vector<int>;   using vvi = vector<vi>;   using vl = vector<ll>;   using vvl = vector<vl>;   using vd = vector<double>;   using vvd = vector<vd>;   using vs = vector<string>;   template <typename T1, typename T2>   ostream& operator<<(ostream& os, const pair<T1, T2>& p) {     return os <<  (  << p.first <<  ,  << p.second <<  ) ;   }   template <typename Tuple>   void print_tuple(ostream&, const Tuple&) {}   template <typename Car, typename... Cdr, typename Tuple>   void print_tuple(ostream& os, const Tuple& t) {     print_tuple<Cdr...>(os, t);     os << (sizeof...(Cdr) ?  ,  :   ) << get<sizeof...(Cdr)>(t);   }   template <typename... Args>   ostream& operator<<(ostream& os, const tuple<Args...>& t) {     print_tuple<Args...>(os <<  ( , t);     return os <<  ) ;   }   template <typename Ch, typename Tr, typename C>   basic_ostream<Ch, Tr>& operator<<(basic_ostream<Ch, Tr>& os, const C& c) {     os <<  [ ;     for (auto i = begin(c); i != end(c); ++i)       os << (i == begin(c) ?    :    ) << *i;     return os <<  ] ;   }   constexpr int INF = 1e9;   constexpr int MOD = 1e9 + 7;   constexpr double EPS = 1e-9;   int main() {     for (int n; cin >> n && n;) {       vi a(n);       for (int i = int(0); i < int(n); i++) cin >> a[i];       ll mx = *max_element(begin(a), end(a)),          sum = accumulate(begin(a), end(a), 0ll);       cout << max<ll>(2 * mx - sum, 0) + 1 << endl;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   using ii = pair<int, int>;   using ll = long long;   const int mod = 1e9 + 7;   const int N = 1e6 + 5;   const int M = 29;   int ans[N];   int dp[3][N];   struct suffixAutomaton {     struct state {       int len;       int link;       int next[M];       ll cnt;       bool terminal;       state() {         len = 0, link = -1, cnt = 0;         terminal = false;         for (int i = 0; i < M; i++) next[i] = -1;       }     };     int get(char c) {       if (c ==  @ ) return 0;       if (c ==  # ) return 1;       if (c ==  $ ) return 2;       return 3 + c -  a ;     }     vector<state> st;     int sz, last, l;     char offset =  a ;     suffixAutomaton() {}     int pos[3];     int getLen(int x) {       if (~x) return st[x].len;       return 0;     }     suffixAutomaton(string s) {       int l = s.length();       st.resize(2 * l);       for (int i = 0; i < 2 * l; i++) st[i] = state();       sz = 1, last = 0;       st[0].len = 0;       st[0].link = -1;       for (int i = 0; i < l; i++) {         addChar(get(s[i]));       }       for (int i = last; i != -1; i = st[i].link) st[i].terminal = true;       vector<vector<int>> adj(2 * l);       memset(dp, -1, sizeof dp);       for (int i = 0; i < sz; i++) {         ans[getLen(st[i].link) + 1] +=             solve(0, i) * 1ll * solve(1, i) * 1ll * solve(2, i) % mod;         ans[getLen(i) + 1] -=             solve(0, i) * 1ll * solve(1, i) * 1ll * solve(2, i) % mod;         if (ans[getLen(st[i].link) + 1] >= mod)           ans[getLen(st[i].link) + 1] -= mod;         if (ans[getLen(i) + 1] < 0) ans[getLen(i) + 1] += mod;       }     }     int solve(int f, int idx) {       if (idx == pos[f]) return 1;       if (idx == pos[0] || idx == pos[1] || idx == pos[2]) return 0;       int &ret = dp[f][idx];       if (~ret) return ret;       ret = 0;       for (int i = 0; i < M; i++)         if (~st[idx].next[i]) {           ret += solve(f, st[idx].next[i]);           if (ret >= mod) ret -= mod;         }       return ret;     }     void addChar(int c) {       int cur = sz++;       assert(cur < N * 2);       if (c < 3) pos[c] = cur;       st[cur].len = st[last].len + 1;       st[cur].cnt = 1;       int p = last;       while (p != -1 and st[p].next[c] == -1) {         st[p].next[c] = cur;         p = st[p].link;       }       last = cur;       if (p == -1) {         st[cur].link = 0;         return;       }       int q = st[p].next[c];       if (st[q].len == st[p].len + 1) {         st[cur].link = q;         return;       }       int clone = sz++;       for (int i = 0; i < M; i++) st[clone].next[i] = st[q].next[i];       st[clone].link = st[q].link;       st[clone].len = st[p].len + 1;       st[clone].cnt = 0;       while (p != -1 and st[p].next[c] == q) {         st[p].next[c] = clone;         p = st[p].link;       }       st[q].link = st[cur].link = clone;       return;     }     bool contains(string &t) {       int cur = 0;       for (int i = 0; i < t.length(); i++) {         cur = st[cur].next[t[i] - offset];         if (cur == -1) return false;       }       return true;     }     ll numberOfSubstrings() {       ll res = 0;       for (int i = 1; i < sz; i++) res += st[i].len - st[st[i].link].len;       return res;     }     void numberOfOccPreprocess() {       vector<ii> v;       for (int i = 1; i < sz; i++) v.push_back(make_pair(st[i].len, i));       sort(v.begin(), v.end(), greater<ii>());       for (int i = 0; i < sz - 1; i++) {         int suf = st[v[i].second].link;         st[suf].cnt += st[v[i].second].cnt;       }     }     ll numberOfOcc(string &t) {       int cur = 0;       for (int i = 0; i < t.length(); i++) {         cur = st[cur].next[t[i] - offset];         if (cur == -1) return 0;       }       return st[cur].cnt;     }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     string a, b, c;     cin >> a >> b >> c;     suffixAutomaton SA(a +  @  + b +  #  + c +  $ );     int mn = min(a.size(), min(b.size(), c.size()));     int cur = 0;     for (int i = 1; i <= mn; i++) {       cur += ans[i];       if (cur >= mod) cur -= mod;       if (cur < 0) cur += mod;       cout << cur <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace IO {   char buf[1 << 22], *p1 = buf, *p2 = buf;   template <typename T>   inline void read(T &x) {     x = 0;     register char ch =         (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)              ? EOF              : *p1++);     while (!(ch >= 48 && ch <= 57))       ch =           (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++);     while ((ch >= 48 && ch <= 57)) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch =           (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++);     }   }   template <typename T, typename... Args>   inline void read(T &t, Args &...args) {     read(t);     read(args...);   }   }  // namespace IO   using namespace IO;   const int N = 1e5 + 10, inf = 0x3f3f3f3f;   struct ALTXDY {     int tp, t, x, y, id;     bool operator<(ALTXDY const &a) const {       return x == a.x ? tp < a.tp : x < a.x;     }   };   ALTXDY q[N << 1];   int n, m, tot, bus[N], ans[N], c[N << 1], dat[N << 2], ls[N << 2], rs[N << 2];   void update(int &i, int l, int r, int x, int k) {     if (!i) i = ++tot;     if (bus[dat[i]] < bus[k]) dat[i] = k;     if (l == r) return;     int mid = (l + r) >> 1;     if (x <= mid)       update(ls[i], l, mid, x, k);     else       update(rs[i], mid + 1, r, x, k);   }   int query(int i, int l, int r, int x, int y, int val) {     if (l == r) return dat[i];     int mid = (l + r) >> 1, t = -1;     if (x <= mid && ls[i] && bus[dat[ls[i]]] >= val)       t = query(ls[i], l, mid, x, y, val);     if (t == -1 && y >= mid + 1 && rs[i] && bus[dat[rs[i]]] >= val)       t = query(rs[i], mid + 1, r, x, y, val);     return t;   }   int main() {     read(n, m);     for (int i = 1; i <= n; i++) {       int s, f, t;       read(s, f, t);       q[i] = (ALTXDY){0, t, s, f, i};       c[i] = t;       bus[i] = f;     }     for (int i = 1; i <= m; i++) {       int b, l, r;       read(l, r, b);       q[i + n] = (ALTXDY){1, b, l, r, i};       c[i + n] = b;     }     sort(c + 1, c + 1 + n + m);     register int k = unique(c + 1, c + 1 + n + m) - c - 1;     for (int i = 1; i <= n + m; i++)       q[i].t = lower_bound(c + 1, c + 1 + k, q[i].t) - c;     sort(q + 1, q + 1 + n + m);     register int rt = 0;     for (int i = 1; i <= n + m; i++)       if (q[i].tp == 0)         update(rt, 1, k, q[i].t, q[i].id);       else         ans[q[i].id] = query(rt, 1, k, q[i].t, k, q[i].y);     for (int i = 1; i <= m; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, ini_pos;   vector<int> v[2020];   int a[2020], MAX;   map<int, int> mp;   int dist(int a, int b) {     if (a < b) swap(a, b);     return min(a - b, n - a + b);   }   void input() {     scanf( %d %d , &n, &ini_pos);     for (int i = 1; i <= n; i++) scanf( %d , a + i), mp[a[i]] = 0;     for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) {       mp[it->first] = ++MAX;     }     for (int i = 1; i <= n; i++) a[i] = mp[a[i]], v[a[i]].push_back(i);   }   int f[2020], en[2020];   int same[2020], Same[2020], nxt[2020];   void prepare() {     v[0].push_back(ini_pos);     for (int m = MAX; m >= 0; m--) {       if (m < MAX) {         for (int i, j = 0; j < v[m].size(); j++) {           i = v[m][j];           int t = m ? i : 0;           en[t] = -1;           for (int ii, jj = 0; jj < v[m + 1].size(); jj++) {             ii = v[m + 1][jj];             int d = dist(i, ii);             if (en[t] == -1 || en[t] > d + f[ii]) {               nxt[t] = ii;               en[t] = d + f[ii];             }           }         }       }       if (!m) break;       int s = v[m].size();       for (int ii, i, j = 0; j < s; j++) {         i = v[m][j];         ii = v[m][(j + 1) % s];         same[i] = +1;         Same[i] = ii;         f[i] = en[ii] + (n - (ii >= i ? ii - i : ii - i + n));         if (ii == i) {           f[i] = en[ii];           continue;         }         ii = v[m][(j - 1 + s) % s];         int ff = en[ii] + (n - (i >= ii ? i - ii : i - ii + n));         if (f[i] > ff) f[i] = ff, same[i] = -1, Same[i] = ii;       }     }   }   void move(int a, int b) {     int d = dist(a, b);     if (d == b - a || d == b + n - a)       printf( %+d n , d);     else       printf( %+d n , -d);   }   void a_a(int s, int cur, int type) {     if (type == -1) reverse(v[s].begin(), v[s].end());     for (int I = -1, i = 0; i < v[s].size(); i = (i + 1) % (int(v[s].size()))) {       int t = v[s][i];       if (I == -1) {         if (t == cur) I = i;         continue;       }       if (I == i) return;       move(cur, t);       cur = t;     }   }   void solve() {     int cur = ini_pos;     printf( %d n , en[0]);     for (int s = 0; s < MAX;) {       int t = nxt[s ? cur : 0];       move(cur, t);       cur = t;       ++s;       a_a(s, cur, -same[cur]);       cur = Same[cur];     }   }   int main() {     input();     prepare();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[201000];   long long vis[201000];   int main() {     int t;     cin >> t;     while (t--) {       int n;       scanf( %d , &n);       for (int i = 1; i <= n; i++) scanf( %lld , &a[i]), vis[i] = 0;       int m;       scanf( %d , &m);       for (int i = 1; i <= m; i++) {         long long x, y;         scanf( %lld%lld , &x, &y);         vis[y] = max(vis[y], x);       }       for (int i = n - 1; i >= 1; i--) {         if (vis[i] < vis[i + 1]) vis[i] = vis[i + 1];       }       long long ans = 1;       long long num = 0, co = 0;       int vis1 = 0;       for (int i = 1; i <= n; i++) {         num++;         if (vis[num] >= max(co, a[i])) {           co = max(co, a[i]);         } else {           ans++;           num--;           if (vis[1] < a[i]) vis1 = 1;           num = 1, co = a[i];         }       }       if (vis1)         printf( -1 n );       else         printf( %lld n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int k;     cin >> k;     if (k == 0) return cout <<  + n , 0;     vector<string> ats = { ++ ,  +* };     while (ats.size() < (1 << k)) {       auto cp = ats;       for (auto& s : cp)         for (auto& ch : s) ch = (ch ==  +  ?  *  :  + );       for (int i = 0; i < cp.size(); i++) {         ats.push_back(ats[i] + cp[i]);         ats[i] += ats[i];       }     }     for (auto& s : ats) cout << s <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int t[107][107];   int mini;   int a;   int maxi;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       mini = 1000000009;       for (int j = 1; j <= m; j++) {         scanf( %d , &a);         if (a < mini) {           mini = a;         }       }       if (mini > maxi) maxi = mini;     }     printf( %d , maxi);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   const int N = 100005;   struct Node {     char c;     int pos;     Node() {}     Node(char _c, int _pos) : c(_c), pos(_pos) {}     bool operator<(const Node& rhs) const {       if (c != rhs.c) return c < rhs.c;       return pos < rhs.pos;     }   };   Node p[N];   vector<int> q[26];   int main() {     int n, k;     scanf( %d%d , &n, &k);     string s;     cin >> s;     for (int i = 0; i < s.size(); ++i) {       p[i].c = s[i];       p[i].pos = i + 1;     }     int len = s.size();     sort(p, p + len);     for (int i = 0; i < len; ++i) {       q[p[i].c -  a ].push_back(p[i].pos);     }     for (int i = 1; i <= n; ++i) {       string t;       cin >> t;       LL res = 0;       for (int i = 0; i < t.size(); ++i) {         if (q[t[i] -  a ].size() == 0) {           res += t.size();         } else {           int d = 0;           int pos =               lower_bound(q[t[i] -  a ].begin(), q[t[i] -  a ].end(), i + 1) -               q[t[i] -  a ].begin();           if (pos == q[t[i] -  a ].size())             d = abs(i + 1 - q[t[i] -  a ][pos - 1]);           else if (pos == 0) {             d = abs(i + 1 - q[t[i] -  a ][pos]);           } else {             d = min(abs(i + 1 - q[t[i] -  a ][pos - 1]),                     abs(i + 1 - q[t[i] -  a ][pos]));           }           res += d;         }       }       printf( %lld n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long x, maxi = 0, sum = 0;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(NULL);     int x;     cin >> x;     int one = 0, zero = 0;     string s;     cin >> s;     for (int i = 0; i < x; i++) {       if (s[i] -  0  == 1)         one++;       else         zero++;     }     cout << abs(one - zero);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long a;     cin >> a;     long long m = 0;     vector<long long> c;     long long b[a];     for (int i = 0; i < a; i++) {       cin >> b[i];     }     for (int y = 0; y < a; y++) {       m = 0;       for (int i = 0; i < a; i++) {         long long x = abs(i - y) + i + y;         x = x * b[i] * 2;         m = m + x;       }       c.push_back(m);     }     sort(c.begin(), c.end());     cout << c[0];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   struct node {     int mx[11], mn[11], num;     friend bool operator<(const node &A, const node &B) {       int ok = 1;       for (int i = 1; i <= k; i++) ok &= A.mx[i] < B.mn[i];       return ok;     }     friend node operator+(const node &A, const node &B) {       node C;       C.num = A.num + B.num;       for (int i = 1; i <= k; i++)         C.mx[i] = max(A.mx[i], B.mx[i]), C.mn[i] = min(A.mn[i], B.mn[i]);       return C;     }   };   inline int read(register int a = 0, register char ch = getchar()) {     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 )       a = (a << 3) + (a << 1) + (ch ^ 48), ch = getchar();     return a;   }   set<node> QAQ;   int main() {     n = read(), k = read();     for (int i = 1; i <= n; i++) {       node tmp;       tmp.num = 1;       for (int j = 1; j <= k; j++) tmp.mx[j] = tmp.mn[j] = read();       set<node>::iterator it = QAQ.find(tmp);       while (it != QAQ.end()) {         tmp = tmp + (*it);         QAQ.erase(it);         it = QAQ.find(tmp);       }       QAQ.insert(tmp);       printf( %d n , (*QAQ.rbegin()).num);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n;     string s;     int finish_x, finish_y;     cin >> n >> s >> finish_x >> finish_y;     if (n < abs(finish_x) + abs(finish_y) ||         n % 2 != (abs(finish_x) + abs(finish_y)) % 2) {       cout << -1;       return 0;     }     vector<int> dx(n + 1), dy(n + 1);     dx[n] = dy[n] = 0;     map<char, pair<int, int>> m;     m[ U ] = {0, 1};     m[ D ] = {0, -1};     m[ L ] = {-1, 0};     m[ R ] = {1, 0};     for (int i = n - 1; i >= 0; --i) {       auto &[cdx, cdy] = m[s[i]];       dx[i] = dx[i + 1] + cdx;       dy[i] = dy[i + 1] + cdy;     }     vector<int> x(n + 1), y(n + 1);     x[0] = y[0] = 0;     for (int i = 0; i < n; ++i) {       auto [cdx, cdy] = m[s[i]];       x[i + 1] = x[i] + cdx;       y[i + 1] = y[i] + cdy;     }     int l = -1, r = n;     while (r - l > 1) {       int m = (l + r) / 2;       bool good = false;       for (int i = 0; i <= n - m; ++i) {         int u = x[i] + dx[i + m];         int v = y[i] + dy[i + m];         if (abs(finish_x - u) + abs(finish_y - v) <= m) {           good = true;           break;         }       }       if (good)         r = m;       else         l = m;     }     cout << r;   }


#include <bits/stdc++.h>   using namespace std;   long double eps = (long double)1 / 1e9;   long long inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;   long long sqr(long long a) { return a * a; }   long long qb(long long a) { return a * a * a; }   long long gcd(long long a, long long b) { return !a ? b : gcd(b % a, a); }   long long binpow(long long a, long long b, long long mod) {     return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod                       : sqr(binpow(a, b / 2, mod)) % mod)              : 1;   }   long long binmult(long long a, long long b, long long mod) {     return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod                       : (2 * binmult(a, b / 2, mod)) % mod)              : 0;   }   long long b[51], kl[27];   bool used[51];   char ans[51];   int main() {     cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0);     long long q, n, i, j, ps, kt;     string a;     cin >> q;     while (q--) {       cin >> a >> n;       ps = 25;       for (i = 0; i < 26; i++) kl[i] = 0;       for (i = 0; i < a.size(); i++) kl[a[i] -  a ]++;       for (i = 1; i <= n; i++) cin >> b[i], used[i] = 0;       while (1) {         kt = 0;         for (i = 1; i <= n; i++)           if (!b[i] && !used[i]) kt++;         if (!kt) break;         while (kl[ps] < kt) ps--;         vector<long long> vc;         for (i = 1; i <= n; i++)           if (!b[i] && !used[i]) used[i] = 1, vc.push_back(i);         for (auto f : vc) {           ans[f] =  a  + ps;           for (j = 1; j <= n; j++)             if (!used[j]) b[j] -= abs(j - f);         }         ps--;       }       for (i = 1; i <= n; i++) cout << ans[i];       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long infLL = 0x3f3f3f3f3f3f3f3fLL;   const int hash_mod = 1000037;   const double eps = 1e-10;   const double pi = acos(-1);   const int maxn = 5000 + 5;   int n, m;   char s[maxn];   int f[maxn][maxn], g[maxn];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       scanf( %s , s + 1);       for (int j = 1; j <= m; ++j)         if (s[j] ==  1 ) f[i][j] = f[i][j - 1] + 1;     }     int res = 0;     for (int j = 1; j <= m; ++j) {       memset(g, 0, sizeof(g));       for (int i = 0; i < n; ++i) g[f[i][j]]++;       int t = 0;       for (int i = j; i > 0; --i) {         t += g[i];         res = max(res, i * t);       }     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<long long> s;   void dfs(int a, int b, long long sum, int d, int& n) {     if (d >= 0) {       if (sum <= n && sum > 0) {         s.insert(sum);       }     }     if (d == 0) {       return;     }     dfs(a, b, sum * 10 + a, d - 1, n);     dfs(a, b, sum * 10 + b, d - 1, n);   }   int main() {     int n;     cin >> n;     int c = 0, nn = n;     while (nn) {       nn /= 10;       ++c;     }     for (int i = 0; i <= 9; ++i) {       for (int j = i + 1; j <= 9; ++j) {         dfs(i, j, 0, c, n);       }     }     cout << s.size() << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 53e4, mod = 998244353;   int n, nn, L, A, B, ans, fac[N], inv[N], a[N], b[N], c[N], R[N];   int C(int a, int b) { return 1ll * fac[a] * inv[b] % mod * inv[a - b] % mod; }   int qpow(int a, int b) {     int ret = 1;     while (b) {       if (b & 1) ret = 1ll * ret * a % mod;       a = 1ll * a * a % mod, b >>= 1;     }     return ret;   }   void init(int n) {     nn = 1, L = 0;     while (nn <= 2 * n) nn <<= 1, ++L;     for (int i = 1; i < nn; ++i) R[i] = (R[i >> 1] >> 1) | ((i & 1) << L - 1);   }   void NTT(int* a, int tp) {     for (int i = 0; i < nn; ++i)       if (i < R[i]) swap(a[i], a[R[i]]);     for (int i = 1; i < nn; i <<= 1) {       int wn = qpow(3, tp * (mod / (i * 2)) + mod - 1);       for (int j = 0; j < nn; j += i * 2)         for (int k = 0, w = 1; k < i; ++k, w = 1ll * w * wn % mod) {           int x = a[j + k], y = 1ll * w * a[j + k + i] % mod;           a[j + k] = (x + y) % mod;           a[j + k + i] = (x - y + mod) % mod;         }     }     if (tp == 1) return;     int invn = qpow(nn, mod - 2);     for (int i = 0; i < nn; ++i) a[i] = 1ll * a[i] * invn % mod;   }   void solve(int n) {     if (n == 1) {       a[1] = 1;       return;     }     if (n & 1) {       solve(n - 1);       for (int i = n - 1; ~i; --i)         a[i + 1] = (a[i + 1] + a[i]) % mod, a[i] = 1ll * (n - 1) * a[i] % mod;       return;     }     int l = n / 2;     solve(l), init(l);     for (int i = 0; i < nn; ++i) b[i] = c[i] = 0;     int tmp = 1;     for (int i = 0; i <= l; ++i)       b[i] = 1ll * a[i] * fac[i] % mod, c[i] = 1ll * tmp * inv[i] % mod,       tmp = 1ll * tmp * l % mod;     reverse(b, b + l + 1);     NTT(b, 1), NTT(c, 1);     for (int i = 0; i < nn; ++i) b[i] = 1ll * b[i] * c[i] % mod;     NTT(b, -1);     reverse(b, b + l + 1);     for (int i = 0; i <= l; ++i) b[i] = 1ll * inv[i] * b[i] % mod;     for (int i = l + 1; i < nn; ++i) b[i] = 0;     init(n);     NTT(a, 1), NTT(b, 1);     for (int i = 0; i < nn; ++i) a[i] = 1ll * a[i] * b[i] % mod;     NTT(a, -1);   }   int main() {     scanf( %d%d%d , &n, &A, &B);     if (n == 1) {       if (A == 1 && B == 1)         puts( 1 );       else         puts( 0 );       return 0;     }     if (A < 1 || B < 1 || A + B > n + 1 || A + B == 2) {       puts( 0 );       return 0;     }     fac[0] = inv[0] = 1;     for (int i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;     inv[n] = qpow(fac[n], mod - 2);     for (int i = n; i; --i) inv[i - 1] = 1ll * inv[i] * i % mod;     solve(n - 1);     ans = 1ll * a[A + B - 2] * C(A + B - 2, A - 1) % mod;     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   int n, c[25], coin[25];   int ans = 0;   bool can;   int p_b;   bool good() {     int cnt = 0;     for (int i = 0; i < 25; i++) cnt += coin[i];     return cnt == 1;   }   void rec(int s, int r, int p) {     if (r == 1) {       if (c[p] > 1) coin[c[p]]++;       p++;       if (p < n) r = c[p];       s = 1;     }     if (p == n && good()) can = true;     for (int i = s; i < c[p] - 1; i++) {       for (int j = 0; j <= coin[i]; j++) {         if (r - i * j >= 1) {           coin[i] -= j;           rec(i + 1, r - i * j, p);           coin[i] += j;         }         if (can) return;       }     }     if (r == 1) {       p--;       if (c[p] > 1) coin[c[p]]--;     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &c[i]);       if (c[i] == 1) coin[1]++;     }     sort(c, c + n);     int start_pos = 0;     for (int i = 0; i < n; i++)       if (c[i] != 1) {         start_pos = i;         break;       }     rec(1, c[start_pos], start_pos);     if (can) {       cout <<  YES ;     } else       cout <<  NO ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     double m, n;     double i;     cin >> m >> n;     double ans = 0;     for (i = 1; i <= m; i++) {       ans = ans + i * (pow((i / m), n) - pow(((i - 1) / m), n));     }     printf( %.9lf , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int pre[5005][5005];   int main() {     int n, k;     bool flag = true;     scanf( %d%d , &n, &k);     map<int, int> m;     for (int i = 1; i <= n; i++) {       int yy;       scanf( %d , &yy);       m[yy]++;       pre[yy][m[yy]] = i;       if (m[yy] > k) flag = false;     }     int xx = 0;     bool flag1 = false;     int p[5005];     for (int i = 1; i <= 5000; i++) {       for (int j = 1; j <= m[i]; j++) {         p[pre[i][j]] = ++xx;         if (xx == k) {           flag1 = true;           xx = 0;         }       }     }     if (flag == false || flag1 == false)       puts( NO );     else {       puts( YES );       for (int i = 1; i <= n; i++) {         cout << p[i] <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const long double PI = 4 * atan((long double)1);   const long long int INF = 1e18;   const long long int NINF = -1e18;   long long int get_hash(string s) {     long long int N = 1000001;     long long int base[N], A = 11, MD = 1110111110111;     base[0] = 1;     for (long long int i = (1); i < (N); ++i) base[i] = (base[i - 1] * A) % MD;     long long int hs = 0;     for (long long int i = (0); i < (s.size()); ++i) {       hs += (s[i] * base[i]);       hs %= MD;     }     return hs;   }   long long power(long long a, long long n) {     long long res = 1;     while (n) {       if (n % 2) res *= a;       a *= a;       n /= 2;     }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n, m;     cin >> n >> m;     map<int, int> mpc;     long long int a[n], b[m];     for (long long int i = (0); i < (n); ++i) cin >> a[i];     int arr[n];     map<int, int> mpa, mpb;     int k = 0;     for (long long int i = (0); i < (m); ++i) {       cin >> b[i];       if (mpa[b[i]] != 1) {         arr[k] = b[i];         k++;         mpa[b[i]] = 1;       }     }     if (k != n) {       for (long long int i = (1); i < (n + 1); ++i) {         if (mpa[i] != 1) {           mpa[i] = 1;           arr[k] = i;           k++;         }       }     }     stack<int> st, st1;     for (int i = n - 1; i >= 0; i--) st.push(arr[i]);     long long int ans = 0;     for (long long int i = (0); i < (m); ++i) {       int x = b[i];       while (st.top() != x) {         st1.push(st.top());         ans += a[st.top() - 1];         st.pop();       }       st.pop();       while (!st1.empty()) {         st.push(st1.top());         st1.pop();       }       st.push(x);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   int main() {     int n;     cin >> n;     int arr[n + 1];     for (int i = 1; i <= n; i++) cin >> arr[i];     int long long ans = 0;     for (int mx = 0; mx < 31; mx++) {       int long long cur = 0;       int long long best = 0;       for (int i = 1; i < n + 1; i++) {         int val = (arr[i] > mx ? -INF : arr[i]);         cur += val;         best = min(best, cur);         ans = max(ans, (cur - best) - mx);       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int aux;     string a;     cin >> a;     cout << (a.size() * 25) + 26 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, x, y, sum, cnt, ans;   int main() {     printf( red n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class U>   T &ctmax(T &x, const U &y) {     return x = max<T>(x, y);   }   template <class T, class U>   T &ctmin(T &x, const U &y) {     return x = min<T>(x, y);   }   int main() {     cin.tie(0)->sync_with_stdio(0);     cin.exceptions(ios::badbit | ios::failbit);     int n, c1, c2;     cin >> n >> c1 >> c2;     vector<int> a(n);     for (auto i = 0; i < n; ++i) {       cin >> a[i];     }     long long res = numeric_limits<long long>::max();     vector<int> primes;     auto get_primes = [&](int x) {       for (auto p = 2; p * p <= x; ++p) {         if (x % p == 0) {           primes.push_back(p);           while (x % p == 0) {             x /= p;           }         }       }       if (x >= 2) {         primes.push_back(x);       }     };     get_primes(a.front() - 1), get_primes(a.front()), get_primes(a.front() + 1);     get_primes(a.back() - 1), get_primes(a.back()), get_primes(a.back() + 1);     sort(primes.begin(), primes.end());     primes.erase(unique(primes.begin(), primes.end()), primes.end());     for (auto p : primes) {       array<long long, 3> dp{};       for (auto x : a) {         array<long long, 3> dp_next{};         dp_next.fill(numeric_limits<long long>::max() / 2);         if (x % p == 0) {           ctmin(dp_next[0], dp[0]);           ctmin(dp_next[2], min(dp[1], dp[2]));         }         ctmin(dp_next[1], min(dp[0], dp[1]) + c1);         if ((x + 1) % p == 0 || (x - 1) % p == 0) {           ctmin(dp_next[0], dp[0] + c2);           ctmin(dp_next[2], min(dp[1], dp[2]) + c2);         }         swap(dp, dp_next);       }       ctmin(res, *min_element(dp.begin(), dp.end()));     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a[1111];   queue<int> p;   int ji[1111], f = 1, b[1111], c[1111];   void dfs(int p) {     ji[p]++;     for (int i = 0; i < a[p].size(); i++) {       if (ji[a[p][i]] >= 3) {         f = 0;         return;       }       dfs(a[p][i]);     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       a[x].push_back(y);       b[y]++;       c[x]++;       c[y]++;     }     int h = 0;     for (int i = 1; i <= n; i++) {       if (!b[i] && c[i]) {         p.push(i);         ji[i]++;         h++;       }     }     while (!p.empty()) {       int k = p.front();       p.pop();       ji[k]++;       for (int i = 0; i < a[k].size(); i++) {         int x = a[k][i];         b[x]--;         if (!b[x] && !ji[x]) {           p.push(x);           h++;           ji[x]++;         }       }     }     if (h == n)       printf( yes n );     else       printf( no n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > adj;   bool vis[100100];   int mx = 0;   int far = -1;   void dfs(int cur, int len) {     if (vis[cur]++) return;     if (len > mx) {       mx = len;       far = cur;     }     for (int x : adj[cur]) dfs(x, len + 1);   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     adj = vector<vector<int> >(n);     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       adj[x - 1].push_back(y - 1);       adj[y - 1].push_back(x - 1);     }     bool ok = (m == n - 1);     dfs(0, 0);     memset(vis, 0, sizeof(vis));     dfs(far, 0);     printf( %d , mx);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   ll mod = 1e9 + 7;   ll bpow(ll a, ll b, ll m) {     a %= m;     ll res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   bool cmp(vector<ll> v1, vector<ll> v2) { return v1[1] < v2[1]; }   ll power(ll x, ll y) {     ll result = 1;     while (y > 0) {       if (y % 2 == 0) {         x = x * x;         y = y / 2;       } else {         result = result * x;         y = y - 1;       }     }     return result;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       ll n;       cin >> n;       ll a[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       sort(a, a + n);       ll count = 0;       ll tar = n / 2;       for (int i = 1; i < n; i++) {         cout << a[i] <<     << a[0] << endl;         count++;         if (count == tar) break;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n;     vector<string> v;     cin >> n;     for (int i = 0; i < int(n); i++) {       string s;       cin >> s;       v.push_back(s);     }     for (int i = 0; i < int(10); i++) {       cout <<  ??  << i <<  >>  << i <<  ??  << endl;     }     cout <<  ??>>?  << endl;     for (int i = 0; i < int(9); i++) {       cout << i <<  ?             <<  <>  << i + 1 << endl;     }     cout <<  9?>>?0  << endl;     cout <<  ?<>1  << endl;     cout <<  >>??  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> G[500005];   void solve() {     int n, m, i, a, b;     cin >> n >> m;     vector<pair<int, int>> topics(n + 1);     vector<int> assigned(n + 1, 1);     vector<bool> done(n + 1, 0);     for (i = 0; i < m; ++i) {       cin >> a >> b;       G[a].push_back(b);       G[b].push_back(a);     }     for (i = 1; i <= n; ++i) {       cin >> topics[i].first;       topics[i].second = i;     }     sort(topics.begin() + 1, topics.end());     for (i = 1; i <= n; ++i) {       if (assigned[topics[i].second] != topics[i].first) {         cout << -1 << endl;         return;       }       done[topics[i].second] = 1;       for (int child : G[topics[i].second]) {         if (!done[child] && assigned[child] == assigned[topics[i].second])           assigned[child] = assigned[topics[i].second] + 1;       }     }     for (i = 1; i <= n; ++i) cout << topics[i].second <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c, d, e, i, j, n;   int main() {     map<string, long long> m, m1;     cin >> a >> b;     string s;     for (i = 1; i <= a; i++) {       cin >> s;       m[s]++;     }     d = b;     for (i = 1; i <= b; i++) {       cin >> s;       if (m[s] > 0) {         n++;         a--;         d--;         m[s]--;       }     }     if (n % 2 == 1) {       if (d > a)         cout <<  NO ;       else         cout <<  YES ;     } else {       if (a > d)         cout <<  YES ;       else         cout <<  NO ;     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   const double PI = 4 * atan(1);   const int INF = 0x3f3f3f3f;   const ll LINF = 0x3f3f3f3f3f3f3f3f;   const int MOD = 1e9 + 7;   const int MAX_N = 2e6 + 10;   int n;   int a[MAX_N], b[MAX_N], p[MAX_N];   void solve() {     for (int i = 1; i <= n; ++i) {       p[b[i]] = i;     }     if (p[1]) {       int i = 2;       for (; p[i] == p[1] + i - 1; ++i)         ;       if (p[i - 1] == n) {         int j;         for (j = i; j <= n && p[j] <= j - i; ++j)           ;         if (j > n) {           cout << n - i + 1 <<   n ;           return;         }       }     }     int ans = 0;     for (int i = 1; i <= n; ++i) ans = max(ans, p[i] - i + 1 + n);     cout << ans <<   n ;   }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= n; ++i) cin >> b[i];     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   const long long mod = 95542721;   const double eps = 1e-9;   const double pi = 3.1415926535897932384626;   const int DX[] = {1, 0, -1, 0}, DY[] = {0, 1, 0, -1};   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   long long powmod(long long a, long long b, long long mod) {     long long res = 1;     a %= mod;     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   namespace flow {   const int M = 300000, N = 30000;   int y[M], nxt[M], gap[N], fst[N], c[N], pre[N], q[N], dis[N];   int f[M];   int S, T, tot, Tn;   void init(int s, int t, int tn) {     tot = 1;     memset(fst, 0, sizeof(fst));     S = s;     T = t;     Tn = tn;   }   void add(int u, int v, int c1, int c2 = 0) {     tot++;     y[tot] = v;     f[tot] = c1;     nxt[tot] = fst[u];     fst[u] = tot;     tot++;     y[tot] = u;     f[tot] = c2;     nxt[tot] = fst[v];     fst[v] = tot;   }   int sap() {     int u = S, t = 1;     int flow = 0;     for (int i = 0; i < (int)Tn; i++) c[i] = fst[i], dis[i] = Tn, gap[i] = 0;     q[0] = T;     dis[T] = 0;     pre[S] = 0;     for (int i = 0; i < (int)t; i++) {       int u = q[i];       for (int j = fst[u]; j; j = nxt[j])         if (dis[y[j]] > dis[u] + 1 && f[j ^ 1])           q[t++] = y[j], dis[y[j]] = dis[u] + 1;     }     for (int i = 0; i < (int)Tn; i++) gap[dis[i]]++;     while (dis[S] <= Tn) {       while (c[u] && (!f[c[u]] || dis[y[c[u]]] + 1 != dis[u])) c[u] = nxt[c[u]];       if (c[u]) {         pre[y[c[u]]] = c[u] ^ 1;         u = y[c[u]];         if (u == T) {           int minf = inf;           for (int p = pre[T]; p; p = pre[y[p]]) minf = min(minf, f[p ^ 1]);           for (int p = pre[T]; p; p = pre[y[p]]) f[p ^ 1] -= minf, f[p] += minf;           flow += minf;           u = S;         }       } else {         if (!(--gap[dis[u]])) break;         int mind = Tn;         c[u] = fst[u];         for (int j = fst[u]; j; j = nxt[j])           if (f[j] && dis[y[j]] < mind) mind = dis[y[j]], c[u] = j;         dis[u] = mind + 1;         gap[dis[u]]++;         if (u != S) u = y[pre[u]];       }     }     return flow;   }   };  // namespace flow   int n, m, g, w, k, Sx, fg, ans;   int sx[10100], c[20];   int main() {     scanf( %d%d%d , &n, &m, &g);     flow::init(0, n + m + 1, n + m + 2);     for (int i = 0; i < (int)n; i++) scanf( %d , sx + i);     for (int i = 0; i < (int)n; i++) {       scanf( %d , &w);       if (sx[i] == 0)         flow::add(0, i + 1, w);       else         flow::add(i + 1, n + m + 1, w);     }     for (int i = 0; i < (int)m; i++) {       scanf( %d%d%d , &Sx, &w, &k);       for (int j = 0; j < (int)k; j++) scanf( %d , c + j);       scanf( %d , &fg);       ans += w;       if (fg) w += g;       if (Sx == 0) {         flow::add(0, i + n + 1, w);         for (int j = 0; j < (int)k; j++) flow::add(i + n + 1, c[j], inf);       } else {         flow::add(i + n + 1, n + m + 1, w);         for (int j = 0; j < (int)k; j++) flow::add(c[j], i + n + 1, inf);       }     }     printf( %d n , ans - flow::sap());   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 100 * 1000 * 1000;   int n1, n2, k1, k2;   long long dp[2][101][101];   int solve(int a, int b, int c) {     if (b == 0 || c == 0) {       if (a == 0) {         dp[a][b][c] = (b <= k1);         return dp[a][b][c];       }       dp[a][b][c] = (c <= k2);       return dp[a][b][c];     }     if (dp[a][b][c] != -1) return dp[a][b][c];     long long ret = 0LL;     if (a == 0) {       for (int i = 1; (i <= k1 && i <= b); ++i)         ret = (ret + solve(1, b - i, c)) % MOD;     }     if (a == 1) {       for (int i = 1; (i <= k2 && i <= c); ++i)         ret = (ret + solve(0, b, c - i)) % MOD;     }     dp[a][b][c] = ret;     return dp[a][b][c];   }   int main() {     memset(dp, -1, sizeof(dp));     cin >> n1 >> n2 >> k1 >> k2;     int ans = (solve(0, n1, n2) + solve(1, n1, n2)) % MOD;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef int (*uniopi)(int);   typedef long long (*uniopl)(long long);   typedef int (*binopi)(int, int);   typedef long long (*binopl)(long long, long long);   typedef int (*tupopi)(int, int, int);   typedef long long (*tupopl)(long long, long long, long long);   const long double PI = acos(0) * 2;   const int INF = 0x3f2f1f0f;   const long long LINF = 1ll * INF * INF;   int X4[] = {-1, 0, 1, 0}, Y4[] = {0, -1, 0, 1};   int X8[] = {-1, -1, -1, 0, 1, 1, 1, 0}, Y8[] = {-1, 0, 1, 1, 1, 0, -1, -1};   template <typename T>   inline bool uax(T& a, T b) {     return a < b ? (a = b, 1) : 0;   }   template <typename T>   inline bool uin(T& a, T b) {     return a > b ? (a = b, 1) : 0;   }   template <typename T1, typename T2>   istream& operator>>(istream& is, pair<T1, T2>& p) {     return is >> p.first >> p.second;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& os, const pair<T1, T2>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     for (int i = 0; i < (int)v.size(); i++) {       os << v[i];       if (i + 1 < (int)v.size()) os <<    ;     }     return os;   }   const int MAX_N = 3e5 + 1;   int N, A[MAX_N], B[MAX_N];   long long D[MAX_N][3];   int main() {     ios::sync_with_stdio(0);     cin.tie(nullptr);     cout << std::setprecision(10);     cout << fixed;     int q;     cin >> q;     while (q--) {       cin >> N;       for (int i = 1; i <= N; i++) cin >> A[i] >> B[i];       for (int i = N; i >= 0; i--) {         for (int j = 0; j < 3; j++) {           long long& d = D[i][j] = LINF;           int a = A[i] + j, b = B[i], c = j * b, na = A[i + 1];           if (a != na) uin(d, D[i + 1][0] + c);           if (a != na + 1) uin(d, D[i + 1][1] + c);           if (a != na + 2) uin(d, D[i + 1][2] + c);         }       }       cout << D[0][0] << endl;       for (int i = 1; i <= (N); i++)         for (int j = 0; j < (3); j++) D[i][j] = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct BIT {     vector<pair<int, int> > f;     void init() {       f.push_back(make_pair(-1e9, 0));       f.push_back(make_pair(0, 0));       f.push_back(make_pair(1e9, 0));       sort(f.begin(), f.end());     }     void update(int i, int val, bool fake = 0) {       if (fake) {         f.push_back(make_pair(i, 0));         return;       }       i = lower_bound(f.begin(), f.end(), make_pair(i, 0)) - f.begin();       for (; i < f.size(); i += i & -i) f[i].second = max(f[i].second, val);     }     int get(int i, bool fake = 0) {       if (fake) {         f.push_back(make_pair(i, 0));         return 0;       }       i = lower_bound(f.begin(), f.end(), make_pair(i, 0)) - f.begin();       int ret = 0;       for (; i; i -= i & -i) ret = max(ret, f[i].second);       return ret;     }   } f[100005];   struct data {     int u, v, c;     data(int _u, int _v, int _c) : u(_u), v(_v), c(_c){};   };   int n, m;   vector<data> e;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int u, v, c;       cin >> u >> v >> c;       e.push_back(data(u, v, c));     }     for (auto &it : e) {       f[it.u].get(it.c - 1, 1);       f[it.v].update(it.c, 0, 1);     }     for (int i = 1; i <= n; i++) f[i].init();     int ans = 0;     for (auto &it : e) {       int rec = f[it.u].get(it.c - 1);       ans = max(ans, rec + 1);       f[it.v].update(it.c, rec + 1);     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int t, n, k, d, a[200010];   int num[1000010];   bool check(int mid) {     int l = 1, r = 1, nl = 1, nr = 1, cnt = 1;     num[a[1]]++;     while (nr < n) {       nr++;       num[a[nr]]++;       if (num[a[nr]] == 1) {         cnt++;       }       while (cnt > mid) {         num[a[nl]]--;         if (num[a[nl]] == 0) {           cnt--;         }         nl++;       }       if (r - l + 1 < nr - nl + 1) {         l = nl, r = nr;       }     }     for (register int i = nl; i <= nr; i++) {       num[a[i]]--;     }     return r - l + 1 >= d;   }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d%d%d , &n, &k, &d);       for (register int i = 1; i <= n; i++) {         scanf( %d , &a[i]);       }       int l = 1, r = n, mid, res;       while (l <= r) {         mid = (l + r) >> 1;         if (check(mid)) {           res = mid;           r = mid - 1;         } else {           l = mid + 1;         }       }       printf( %d n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c, d, e, z[509], x[509], pi, g, s;   vector<int> v[509];   bool m, rr;   pair<int, int> p[509];   void dfs(int w) {     if (m == 1) return;     z[w] = 1;     for (vector<int>::iterator it = v[w].begin(); it != v[w].end(); it++) {       if (x[(*it)] == c) {         p[pi].first = w;         p[pi].second = (*it);         pi++;         m = 1;         g = (*it);         return;       }       if (z[(*it)] == 0) {         x[(*it)] = c;         p[pi].first = w;         p[pi].second = (*it);         pi++;         dfs((*it));         if (m == 1) return;       }     }     x[w] = 0;   }   void dfss(int w) {     if (rr == 1) {       x[w] = 0;       return;     }     z[w] = d + 1;     for (vector<int>::iterator it = v[w].begin(); it != v[w].end(); it++) {       if ((((*it) == p[d].second && w == p[d].first))) continue;       if (x[(*it)] == d + 1) {         s = 1;         rr = 1;         x[w] = 0;         return;       }       if (z[(*it)] != d + 1) {         x[(*it)] = d + 1;         dfss((*it));         if (rr == 1) {           x[w] = 0;           return;         }       }     }     x[w] = 0;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> a >> b;     for (c = 1; c <= b; c++) {       cin >> d >> e;       v[d].push_back(e);     }     for (c = 1; c <= a; c++) {       if (z[c] == 0) {         x[c] = c;         dfs(c);         if (m == 1) break;       }     }     if (g == 0) {       cout <<  YES ;       return 0;     }     for (d = 0; d < pi; d++) {       if (p[d].first == g) break;     }     for (c = 0; c <= 502; c++) z[c] = 0, x[c] = 0;     for (d = d; d < pi; d++) {       for (c = 1; c <= a; c++) {         if (z[c] != d + 1) {           x[c] = d + 1;           rr = 0;           dfss(c);           if (rr == 1) break;         }       }       if (rr == 0) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[101];   vector<int> vec;   int main(void) {     int n;     long long k;     long long sum;     scanf( %d %lld , &n, &k);     sum = k;     vec.push_back(1);     for (int i = 0; i < n; i++) {       scanf( %d , &arr[i]);       sum += arr[i];       vec.push_back(arr[i]);       for (int j = 2; j * j <= arr[i]; j++) {         if (arr[i] % j == 0) {           vec.push_back(j);           vec.push_back(arr[i] / j);         } else {           vec.push_back(j);           vec.push_back(arr[i] / j + 1);         }       }     }     sort(vec.begin(), vec.end());     vec.resize(unique(vec.begin(), vec.end()) - vec.begin());     int len = vec.size();     long long ans = 0;     for (int i = len - 1; i >= 0; i--) {       long long llsum = 0;       for (int j = 0; j < n; j++) {         llsum += (arr[j] / vec[i]);         if (arr[j] % vec[i] != 0) llsum++;       }       long long d = sum / llsum;       if (d >= vec[i]) {         ans = max(ans, d);       }     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int m[200];   int n;   int S, E;   bool is_ok(int lim) {     int s = 0, e = 0;     for (int i = 0; i < lim; ++i) s += m[i];     for (int j = lim; j <= n; ++j) e += m[j];     return s <= E && e <= E && s >= S && e >= S;   }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) cin >> m[i];     cin >> S >> E;     for (int i = 1; i <= n; ++i)       if (is_ok(i)) {         cout << i << endl;         break;       } else if (i == n)         cout << 0 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 105;   map<string, int> H1[maxn], H2[maxn];   vector<char> ans;   char getA(string a, string b) {     int c[30];     for (int i = 0; i < 26; i++) c[i] = 0;     for (int i = 0; i < a.size(); i++) c[a[i] -  a ]++;     for (int i = 0; i < b.size(); i++) c[b[i] -  a ]--;     for (int i = 0; i < 26; i++) {       if (c[i] > 0) return i +  a ;     }   }   int main() {     int n;     cin >> n;     if (n == 1) {       cout <<  ? 1 1  << endl;       string sss;       cin >> sss;       cout <<  !   << sss << endl;     } else {       cout <<  ? 1   << n << endl;       for (int i = 0; i < n * (n + 1) / 2; i++) {         string s;         cin >> s;         sort(s.begin(), s.end());         H1[s.size()][s]++;       }       cout <<  ? 2   << n << endl;       for (int i = 0; i < n * (n - 1) / 2; i++) {         string s;         cin >> s;         sort(s.begin(), s.end());         H2[s.size()][s]++;       }       for (int i = 1; i <= n; i++) {         for (auto p : H2[i]) {           H1[i][p.first] -= H2[i][p.first];         }         for (auto p : H1[i]) {           if (p.second > 0) {             string new1 =   ;             for (int j = 0; j < ans.size(); j++) new1 += ans[j];             ans.push_back(getA(p.first, new1));           }         }       }       string new1 =   ;       for (int j = 0; j < ans.size(); j++) new1 += ans[j];       cout <<  !   << new1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int C[50][50];   int main() {     C[0][0] = 1;     for (int i = 1; i <= 30; i++) {       C[i][0] = C[i][i] = 1;       for (int j = 1; j <= 30; j++) {         C[i][j] = C[i - 1][j] + C[i - 1][j - 1];       }     }     string p =  aaaaaaaaab ;     int pSize = (int)p.size() - 1;     string result =   ;     int n;     cin >> n;     for (int i = 30; i >= 9; i--) {       while (n >= C[i][pSize]) {         n -= C[i][pSize];         result +=  b ;       }       result +=  a ;     }     reverse(result.begin(), result.end());     result = p.substr(0, pSize - 1) + result;     long long cnt = 0;     int aCnt = 0;     for (int i = 0; i < result.size(); i++) {       aCnt += result[i] ==  a ;       if (result[i] ==  b ) cnt += C[aCnt][pSize];     }     cout << result <<     << p <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long b[1510100], n, x;   long long Mod, C;   long long power(long long a, long long n, long long mod) {     if (n == 0) return 1;     long long y;     y = power(a, n / 2, mod);     if (n & 1) {       return (((y * y) % mod) * a) % mod;     } else {       return (y * y) % mod;     }   }   bool func(int mid) {     int i, j, k;     long long EX, sum;     EX = power(x, mid, Mod);     sum = 0;     for (i = 0; i < n; i++) {       if (b[i] >= mid)         break;       else {         sum += power(x, b[i], EX);         sum %= EX;       }     }     if (sum == 0)       return true;     else       return false;   }   int main() {     int i, j, k;     scanf( %d , &n);     scanf( %d , &x);     long long mx, quan;     mx = 0;     quan = 0;     int a[n];     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       mx = max(mx, (long long)a[i]);       quan += a[i];     }     quan = quan - mx;     for (i = 0; i < n; i++) {       b[i] = mx - a[i];     }     sort(b, b + n);     int hi, lo, mid;     hi = mx;     lo = 0;     Mod = 1000000007;     while (hi != lo) {       mid = (hi + lo + 1) / 2;       if (func(mid)) {         lo = mid;       } else {         hi = mid - 1;       }     }     quan += hi;     cout << power(x, quan, Mod);   }


#include <bits/stdc++.h>   using namespace std;   const int Max = 3e5 + 10;   const int E = Max * 2;   int son[Max], maxson[Max], fa[Max], zx[Max];   int head[Max], nex[E], pnt[E], edge;   int vis[Max];   void Init() {     edge = 0;     memset(son, 0, sizeof(son));     memset(maxson, 0, sizeof(maxson));     memset(fa, -1, sizeof(fa));     memset(head, -1, sizeof(head));     memset(vis, 0, sizeof(vis));   }   void Addedge(int u, int v) {     pnt[edge] = v;     nex[edge] = head[u];     head[u] = edge++;   }   void dfs1(int u) {     son[u] = 1;     vis[u] = 1;     maxson[u] = 0;     int v;     for (int e = head[u]; e != -1; e = nex[e]) {       v = pnt[e];       if (!vis[v]) {         dfs1(v);         son[u] += son[v];         maxson[u] = max(maxson[u], son[v]);       }     }   }   bool is_ok(int u, int v) {     if (son[u] >= maxson[v] * 2 && son[u] >= (son[u] - son[v]) * 2) return 1;     return 0;   }   void dfs2(int u) {     vis[u] = 1;     if (son[u] == 1) {       zx[u] = u;       return;     }     int v, z = u;     for (int e = head[u]; e != -1; e = nex[e]) {       v = pnt[e];       if (!vis[v]) {         dfs2(v);         if (maxson[u] == son[v]) {           z = zx[v];         }       }     }     while (!is_ok(u, z) && fa[z] != -1) {       z = fa[z];     }     zx[u] = z;   }   int main() {     int n, m;     while (~scanf( %d%d , &n, &m)) {       Init();       int u, v;       for (int i = 2; i <= n; i++) {         scanf( %d , &u);         fa[i] = u;         Addedge(u, i);         Addedge(i, u);       }       dfs1(1);       memset(vis, 0, sizeof(vis));       dfs2(1);       while (m--) {         scanf( %d , &u);         printf( %d n , zx[u]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m;   int main() {     cin >> n >> m;     if (n > m) swap(n, m);     if (n == 1) {       cout << 6 * (m / 6) + 2 * max(m % 6 - 3, (long long)0);       return 0;     }     if (n == 2) {       if (m == 2) {         cout << 0;         return 0;       }       if (m == 3) {         cout << 4;         return 0;       }       if (m == 7) {         cout << 12;         return 0;       }     }     if (n % 2 == 0 || m % 2 == 0) {       cout << n * m;       return 0;     }     cout << n * m - 1;     return 0;   }


#include <bits/stdc++.h>   clock_t t = clock();   namespace my_std {   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   template <typename T>   inline T rnd(T l, T r) {     return uniform_int_distribution<T>(l, r)(rng);   }   template <typename T>   inline bool chkmax(T& x, T y) {     return x < y ? x = y, 1 : 0;   }   template <typename T>   inline bool chkmin(T& x, T y) {     return x > y ? x = y, 1 : 0;   }   template <typename T>   inline void read(T& t) {     t = 0;     char f = 0, ch = getchar();     double d = 0.1;     while (ch >  9  || ch <  0 ) f |= (ch ==  - ), ch = getchar();     while (ch <=  9  && ch >=  0 ) t = t * 10 + ch - 48, ch = getchar();     if (ch ==  . ) {       ch = getchar();       while (ch <=  9  && ch >=  0 ) t += d * (ch ^ 48), d *= 0.1, ch = getchar();     }     t = (f ? -t : t);   }   template <typename T, typename... Args>   inline void read(T& t, Args&... args) {     read(t);     read(args...);   }   char __sr[1 << 21], __z[20];   int __C = -1, __zz = 0;   inline void Ot() { fwrite(__sr, 1, __C + 1, stdout), __C = -1; }   inline void print(register int x) {     if (__C > 1 << 20) Ot();     if (x < 0) __sr[++__C] =  - , x = -x;     while (__z[++__zz] = x % 10 + 48, x /= 10)       ;     while (__sr[++__C] = __z[__zz], --__zz)       ;     __sr[++__C] =   n ;   }   void file() {}   inline void chktime() {}   long long ksm(long long x, int y) {     long long ret = 1;     for (; y; y >>= 1, x = x * x)       if (y & 1) ret = ret * x;     return ret;   }   }  // namespace my_std   using namespace my_std;   int n;   int ans[10][333][10] = {       {{2}, {3, 1, 2, 3}, {3, 1, 2, 3}},       {{4}, {3, 1, 2, 3}, {3, 1, 2, 4}, {3, 1, 3, 4}, {3, 2, 3, 4}},       {{6},        {3, 5, 4, 2},        {3, 3, 1, 5},        {4, 4, 5, 2, 3},        {4, 4, 3, 2, 1},        {3, 4, 2, 1},        {3, 3, 1, 5}},       {{9},        {4, 1, 5, 2, 4},        {4, 1, 6, 3, 4},        {4, 2, 6, 3, 5},        {3, 1, 2, 6},        {3, 2, 3, 4},        {3, 1, 5, 3},        {3, 1, 2, 3},        {3, 4, 5, 6},        {3, 4, 5, 6}}};   int L[333][2], R[333][2];   int Ans[333 * 333][10], cnt;   void addcir(int s, int l) {     for (int i = (1); i <= (ans[s][0][0]); i++) {       assert(ans[s][i][0]);       ++cnt;       for (int j = (0); j <= (ans[s][i][0]); j++)         Ans[cnt][j] = ans[s][i][j] + (!!j) * l;     }   }   void solve(int l, int r) {     int s = r - l + 1;     if (s <= 6) return addcir(s - 3, l);     int x, y, c;     if (s & 1) {       x = 3, y = (s - 3) >> 1, c = 1;       ++l;       L[1][0] = l, L[1][1] = l + 1;       L[2][0] = l, L[2][1] = l + 2;       L[3][0] = l + 1, L[3][1] = l + 2;       for (int i = (1); i <= (y); i++)         for (int k = (0); k <= (1); k++) R[i][k] = l + 3 + 2 * (i - 1) + k;       --l;       addcir(0, l);     } else {       x = 2, y = (s - 4) >> 1, c = 2;       ++l;       for (int i = (1); i <= (x); i++)         for (int k = (0); k <= (1); k++) L[i][k] = l + 2 * (i - 1) + k;       for (int i = (1); i <= (y); i++)         for (int k = (0); k <= (1); k++) R[i][k] = l + 4 + 2 * (i - 1) + k;       --l;       addcir(1, l);     }     for (int i = (1); i <= (x); i++)       for (int j = (1); j <= (y); j++)         for (int k = (1); k <= (c); k++)           ++cnt, Ans[cnt][0] = 4, Ans[cnt][1] = L[i][0], Ans[cnt][2] = R[j][0],                  Ans[cnt][3] = L[i][1], Ans[cnt][4] = R[j][1];     solve(l + ((s & 1) ? 3 : 4), r);   }   int main() {     file();     read(n);     solve(0, n - 1);     printf( %d n , cnt);     for (int i = (1); i <= (cnt); i++) {       for (int j = (0); j <= (Ans[i][0]); j++) printf( %d  , Ans[i][j]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     cout.tie(0);     iostream::sync_with_stdio(false);     long long n, m;     cin >> n >> m;     set<int> taken_lines, taken_cols;     long long base = n * n;     for (int i = 0; i < m; ++i) {       int x, y;       cin >> x >> y;       bool lined = false, coled = false;       if (taken_lines.count(x) == 0) lined = true;       if (taken_cols.count(y) == 0) coled = true;       if (lined) {         base -= n - taken_cols.size();       }       if (coled) {         base -= n - taken_lines.size();       }       if (lined && coled) {         base++;       }       taken_lines.insert(x);       taken_cols.insert(y);       cout << base <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     int l = 0;     int r = n - 1;     while (l < n - 1 && a[l] < a[l + 1]) l++;     while (r > 0 && a[r] < a[r - 1]) r--;     for (int i = l + 1; i <= r; i++) {       if (a[l] != a[i]) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Left[1000010];   int mini[1000010];   int main(void) {     cin.tie(0);     ios::sync_with_stdio(false);     int n;     cin >> n;     string S;     cin >> S;     for (int i = 0; i < S.length(); i++) {       if (S[i] ==  ( )         Left[i + 1] = Left[i] + 1;       else         Left[i + 1] = Left[i] - 1;     }     for (int i = 0; i < 1000010; i++) mini[i] = 2000000000;     int ans = 0;     if (Left[n] == 2) {       for (int i = n; i >= 0; i--) mini[i] = min(mini[i + 1], Left[i]);       for (int i = 0; i < n; i++) {         if (i != 0 && Left[i - 1] < 0) break;         if (S[i] ==  (  && mini[i + 1] >= 2 && Left[n] == 2) ans++;       }     } else if (Left[n] == -2) {       for (int i = n; i >= 0; i--) mini[i] = min(mini[i + 1], Left[i]);       for (int i = 0; i < n - 1; i++) {         if (i != 0 && Left[i - 1] < 0) break;         if (S[i] ==  )  && mini[i] >= -2) ans++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1111;   int a[maxn], b[maxn];   int main() {     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     int maxim = 0, num = -1;     for (int i = 1; i <= n; i++) {       b[i] = a[i];       for (int j = 1; j <= n; j++) b[j] = a[i] + (j - i) * k;       int kol = 0;       for (int j = 1; j <= n; j++)         if (a[j] == b[j]) kol++;       if (b[1] > 0 && kol > maxim) {         maxim = kol;         num = i;       }     }     cout << n - maxim << endl;     for (int i = 1; i <= n; i++) {       if (a[num] + (i - num) * k == a[i]) continue;       if (a[num] + (i - num) * k > a[i])         cout <<  +   << i <<     << -(a[i] - a[num] - (i - num) * k) << endl;       else         cout <<  -   << i <<     << -(a[num] + (i - num) * k - a[i]) << endl;     }     cin >> n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, S[2005];   bool mark[2005][2005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     char c;     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> c;         mark[i][j] = c -  0 ;         if (mark[i][j]) S[j]++;       }     bool flag;     for (int i = 1; i <= n; i++) {       flag = 0;       for (int j = 1; j <= m; j++)         if (mark[i][j]) S[j]--;       for (int j = 1; j <= m; j++)         if (S[j] == 0) {           flag = 1;           break;         }       if (!flag) {         cout <<  YES ;         return 0;       }       for (int j = 1; j <= m; j++)         if (mark[i][j]) S[j]++;     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 400500;   long long A[N];   long long B[N];   inline long long mymod2(long long x) {     if (x % 2 == 0)       return 0;     else       return 1;   }   inline long long mydiv2(long long x) {     if (x >= 0)       return x / 2;     else {       if (x % 2 == 0)         return x / 2;       else         return x / 2 - 1;     }   }   void buildB() {     for (int i = 0; i < N; i++) B[i] = A[i];     for (int i = 0; i < N - 1; i++) {       B[i + 1] += mydiv2(B[i]);       B[i] = mymod2(B[i]);     }   }   int main() {     int n, k;     scanf( %d %d , &n, &k);     for (int i = 0; i <= n; i++) {       int x;       scanf( %d , &x);       A[i] = x;     }     buildB();     if (B[N - 1]) {       for (int i = 0; i <= n; i++) A[i] = -A[i];       buildB();     }     int fst = 0;     while (fst != N && B[fst] == 0) {       fst++;     }     assert(fst != N);     long long cur = 0;     bool bad = false;     for (int i = fst; i < N; i++) {       if (B[i]) {         int p = i - fst;         if (p > 40) {           bad = true;           break;         }         cur += 1ll << p;       }     }     int cnt = 0;     if (!bad) {       for (int i = fst; i >= 0; i--) {         if (cur > (1ll << 32)) break;         long long nA = A[i] - cur;         if (abs(nA) <= k && (i != n || nA != 0) && (i <= n)) cnt++;         cur <<= 1;       }     }     printf( %d n , cnt);   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long int n;     cin >> n;     vector<long long int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     sort(v.begin(), v.end());     if (n == 1) {       int q;       cin >> q;       for (int i = 0; i < q; i++) {         long long int l, r;         cin >> l >> r;         cout << r - l + 1 <<    ;       }       return 0;     }     vector<long long int> use(n - 1);     for (int i = 1; i < n; i++) {       use[i - 1] = v[i] - v[i - 1];     }     sort(use.begin(), use.end());     vector<long long int> pref(n - 1);     pref[0] = use[0];     for (int i = 1; i < n - 1; i++) {       pref[i] = pref[i - 1] + use[i];     }     int q;     cin >> q;     for (int i = 0; i < q; i++) {       long long int l, r;       cin >> l >> r;       long long int ans = 0;       long long int val = r - l + 1;       long long int where =           upper_bound(use.begin(), use.end(), val) - use.begin();       if (where) ans = ans + pref[where - 1];       long long int extra = (val) * (n - 1 - where);       ans = ans + extra;       ans = ans + val;       cout << ans <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     char tt =  a ;     int k = s.size(), c = 0;     for (int i = 0; i < k; i++) {       int x = int(tt);       int y = int(s[i]);       int a = abs(x - y);       int b = 26 - a;       b = min(b, a);       c += b;       tt = s[i];     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) { cerr << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   ,  ;     err(++it, args...);   }   namespace fastIO {   bool IOerror = 0;   inline char nc() {     static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;     if (p1 == pend) {       p1 = buf;       pend = buf + fread(buf, 1, 100000, stdin);       if (pend == p1) {         IOerror = 1;         return -1;       }     }     return *p1++;   }   inline bool blank(char ch) {     return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ;   }   inline void read(int &x) {     char ch;     while (blank(ch = nc()))       ;     if (IOerror) return;     for (x = ch -  0 ; (ch = nc()) >=  0  && ch <=  9 ; x = x * 10 + ch -  0 )       ;   }   }  // namespace fastIO   using namespace fastIO;   const double PI = acos(-1.0);   const double eps = 1e-8;   const int mod = 1e9 + 7;   long long qp(long long b, long long n) {     long long r = 1;     if (n < 0) n += mod - 1;     b %= mod;     for (; n; n >>= 1, b = b * b % mod)       if (n & 1) r = r * b % mod;     return r;   }   int sgn(double x) {     if (x < -eps) return -1;     return x > eps ? 1 : 0;   }   const int maxn = 3e5 + 7;   const int N = 1e5 + 10;   int n;   int sum[N], dif[N], a[N];   pair<int, int> p[N];   int main() {     scanf( %d , &n);     long long ans = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       sum[a[i]]++;       ans += (1LL * a[i] * (n - a[i] + 1));     }     for (int i = 1; i <= n; ++i) sum[i] += sum[i - 1];     for (int i = 1; i < n; ++i) {       p[i].first = a[i];       p[i].second = a[i + 1];       if (p[i].first > p[i].second) swap(p[i].first, p[i].second);       ans -= 1LL * p[i].first * (n - p[i].second + 1);     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void checkmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   inline void checkmax(T &a, T b) {     if (b > a) a = b;   }   int N, K;   char cs[100002];   int main() {     scanf( %d%d , &N, &K);     for (int i = (0); i < (int)(N); i++) cs[i] =  1 ;     for (int i = (0); i < (int)(K); i++) cs[i] =  0 ;     cs[N] = 0;     if (K > 1 && K != N) {       int cnt = (N - K) / 2;       for (int i = 0; i < N; i += cnt + 1) {         for (int j = 0; j < cnt + 1 && i + j < N; j++) {           if (j == 0)             cs[i + j] =  0 ;           else             cs[i + j] =  1 ;         }       }     }     printf( %s n , cs);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2025;   const int MOD = 998244353;   int n, k;   namespace Task1 {   int ans;   int f[MAXN][MAXN];   int sum[MAXN][MAXN];   void solve() {     f[0][n] = 1;     for (int i = n; i >= 1; i--) sum[0][i] = 1;     for (int i = 1; i <= n; i++)       for (int j = i; j >= 1; j--) {         f[i][j] = sum[i - j][j];         (ans += f[i][j]) %= MOD;         sum[i][j] = (sum[i][j + 1] + f[i][j]) % MOD;       }     printf( %d n , ans);   }   }  // namespace Task1   namespace Task2 {   int ans, N;   vector<int> f[MAXN][70];   vector<int> sum[MAXN][70];   void solve() {     N = min(n, 65);     for (int i = 0; i <= n; i++) {       f[i][0].resize(MAXN);       sum[i][0].resize(MAXN);       for (int j = 1; j <= N; j++) {         f[i][j].resize(i / j + 2);         sum[i][j].resize(i / j + 2);       }     }     f[0][0][n] = 1;     for (int i = n; i >= 1; i--) sum[0][0][i] = 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= N; j++)         for (int k = i / j; k >= 1; k--) {           if (sum[i - j * k][j - 1].size() > k)             f[i][j][k] = sum[i - j * k][j - 1][k];           (ans += f[i][j][k]) %= MOD;           sum[i][j][k] = (sum[i][j][k + 1] + f[i][j][k]) % MOD;         }     printf( %d n , ans);   }   }  // namespace Task2   namespace Task3 {   int ans;   vector<int> a;   bool chk(vector<int> t) {     int K = k;     while (K--) {       vector<int> tt;       int sum = 0;       for (int i = 0; i < t.size(); i++) sum += t[i];       if (sum > n) return 0;       tt.resize(sum);       int tot = 0;       for (int i = t.size() - 1; i >= 0; i--)         for (int j = 1; j <= t[i]; j++) tt[tot++] = i + 1;       swap(tt, t);     }     return 1;   }   void dfs(int d) {     if (d > 1 && !chk(a)) return;     if (d > 1) ans++;     int t = d > 1 ? a.back() : n;     for (int i = 1; i <= t; i++) {       a.push_back(i);       int tmp = ans;       dfs(d + 1);       a.pop_back();       if (ans == tmp) return;     }   }   void solve() {     dfs(1);     printf( %d n , ans);   }   }  // namespace Task3   int main() {     scanf( %d%d , &n, &k);     if (k == 1) Task1::solve();     if (k == 2) Task2::solve();     if (k >= 3) Task3::solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const int inf = 0x3f3f3f3f;   int n;   vector<int> vec[N];   int dis(int s, int t) {     if (t >= s) return t - s;     return t - s + n;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int m;     cin >> n >> m;     int num = 0;     for (int i = 1; i <= m; i++) {       int a, b;       cin >> a >> b;       vec[a].push_back(dis(a, b));       num = max(num, (int)vec[a].size());     }     for (int i = 1; i <= n; i++) {       sort(vec[i].begin(), vec[i].end());     }     for (int st = 1; st <= n; st++) {       int ans = 0;       for (int i = 1; i <= n; i++) {         if (vec[i].size() > 0)           ans = max(ans, dis(st, i) + ((int)vec[i].size() - 1) * n + vec[i][0]);       }       cout << ans <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     vector<int> silver, gold;     int g = 0, mxg = -1;     ;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  S ) {         gold.push_back(g);         if (g > mxg) mxg = g;         g = 0;         silver.push_back(i);       } else         g++;     }     if (g) gold.push_back(g);     if (g > mxg) mxg = g;     for (int i = 0; i < silver.size(); i++) {       if (i == gold.size() - 1) break;       if (gold[i] > 0 && gold[i + 1]) {         int g = gold[i] + gold[i + 1];         bool found = 0;         for (int p = 0; p < gold.size(); p++) {           if (p != i && p != i + 1 && gold[p] > 0) {             found = true;             break;           }         }         if (found) g++;         if (g > mxg) mxg = g;       } else if (gold[i] > 0) {         int g = gold[i];         bool found = 0;         for (int p = 0; p < gold.size(); p++) {           if (p != i && gold[p] > 0) {             found = true;             break;           }         }         if (found) g++;         if (g > mxg) mxg = g;       } else if (gold[i + 1] > 0) {         int g = gold[i + 1];         bool found = 0;         for (int p = 0; p < gold.size(); p++) {           if (p != i + 1 && gold[p] > 0) {             found = true;             break;           }         }         if (found) g++;         if (g > mxg) mxg = g;       }     }     cout << mxg << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e5 + 10;   const long long MAXL = 20;   long long n, m;   long long v[MAXN], s[MAXN];   long long rmq[MAXL][MAXN];   long long resp[MAXN];   long long best[MAXN];   void buildRMQ() {     for (long long k = 0; k < n; k++) rmq[0][k] = s[k];     for (long long i = 1; i < MAXL; i++)       for (long long k = 0; k < MAXN; k++)         if (k + (1 << i) <= n)           rmq[i][k] = max(rmq[i - 1][k], rmq[i - 1][k + (1 << i - 1)]);   }   long long RMQ(long long a, long long b) {     long long size = b - a + 1;     long long log = 31 - __builtin_clz(size);     return max(rmq[log][a], rmq[log][b - (1 << log) + 1]);   }   long long bs(long long ini, long long fim, long long pos) {     while (ini < fim) {       long long mid = (ini + fim + 1) / 2;       if (RMQ(mid, pos - 1) >= s[pos])         ini = mid;       else         fim = mid - 1;     }     return ini;   }   int main() {     scanf( %lld %lld , &n, &m);     for (long long i = 0; i < n; i++) scanf( %lld , &v[i]);     s[0] = 0;     for (long long i = 1; i < n; i++) s[i] = abs(v[i] - v[i - 1]);     buildRMQ();     while (m--) {       long long p, q;       scanf( %lld %lld , &p, &q);       p--;       q--;       long long ans = 0;       stack<pair<long long, long long> > st;       for (long long i = p; i <= q; i++) {         while (st.size() && st.top().first <= s[i]) st.pop();         if (st.size())           best[i] = st.top().second;         else           best[i] = 0;         st.push(pair<long long, long long>(s[i], i));       }       for (long long i = p; i <= q; i++) {         resp[i] = 0;         long long bt = best[i];         if (s[bt] >= s[i]) {           resp[i] = s[i] * (i - bt) + resp[bt];         } else {           resp[i] = s[i] * (i - p);         }         ans += resp[i];       }       printf( %lld n , ans);     }   }