#include <bits/stdc++.h>   using namespace std;   int a[200001];   void op(int i) {     int res = a[i] ^ a[i + 1] ^ a[i + 2];     a[i] = a[i + 1] = a[i + 2] = res;   }   vector<int> push_left(int i) {     vector<int> v;     while (i - 2 >= 1 && a[i] == 0 && a[i - 1] == 1 && a[i - 2] == 1) {       op(i - 2);       v.push_back(i - 2);       i -= 2;     }     return v;   }   vector<int> push_right(int i, int n) {     vector<int> v;     while (i + 2 <= n && a[i] == 0 && a[i + 1] == 1 && a[i + 2] == 1) {       op(i);       v.push_back(i);       i += 2;     }     return v;   }   int main() {     int i, t;     for (scanf( %d , &t); t--;) {       int n;       vector<int> v, ans;       int cum = 0;       for (scanf( %d , &n), i = 1; i <= n; ++i) {         scanf( %d , a + i);         cum += a[i];       }       if (cum == 0) {         printf( YES n0 n );         continue;       } else if ((cum & 1) || cum == n) {         printf( NO n );         continue;       }       int cur = 1;       if (a[1]) {         cum = a[1];         cur = 2;         while (cur <= n && a[cur]) cum += a[cur], ++cur;         if (cum & 1) {           --cur;           bool y = 1;           while (cur <= n && a[cur]) {             if (cur + 2 <= n) {               if (a[cur] + a[cur + 1] + a[cur + 2] == 3) {                 cur += 2;               } else if (a[cur + 1] + a[cur + 2] == 0) {                 ans.push_back(cur);                 op(cur);                 cur += 2;               } else if (a[cur + 1] == 0 && a[cur + 2] == 1) {                 ans.push_back(cur);                 op(cur);                 auto push_vec = push_left(cur);                 ans.insert(ans.end(), push_vec.begin(), push_vec.end());                 cur += 3;                 break;               } else {                 auto push_vec = push_left(cur + 2);                 ans.insert(ans.end(), push_vec.begin(), push_vec.end());                 cur += 3;                 break;               }             } else {               y = 0;               break;             }           }           if (y == 0) {             printf( NO n );             continue;           }         } else {           ans = push_left(cur);         }       }       cur = 1;       while (cur + 2 <= n) {         if (a[cur] == 0 && a[cur + 1] + a[cur + 2] == 2) {           op(cur);           ans.push_back(cur);           cur += 2;         } else if (a[cur]) {           int st = cur - 1;           while (1) {             if (cur + 2 <= n && a[cur + 1] + a[cur + 2] == 2)               cur += 2;             else if (cur + 2 <= n && a[cur + 1] + a[cur + 2] == 0) {               op(cur);               ans.push_back(cur);               cur += 2;             } else if (cur + 2 <= n && a[cur + 1] == 0 && a[cur + 2] == 1) {               op(cur);               ans.push_back(cur);               break;             } else {               break;             }           }           auto push_vec = push_right(st, n);           ans.insert(ans.end(), push_vec.begin(), push_vec.end());         } else           ++cur;       }       cum = 0;       for (i = 1; i <= n; ++i) cum += a[i];       if (cum == 0) {         printf( YES n%d n , ans.size());         for (auto x : ans) printf( %d  , x);         puts(  );       } else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T& x) {     x = 0;     char s = (char)getchar();     bool f = false;     while (!(s >=  0  && s <=  9 )) {       if (s ==  - ) f = true;       s = (char)getchar();     }     while (s >=  0  && s <=  9 ) {       x = (x << 1) + (x << 3) + s -  0 ;       s = (char)getchar();     }     if (f) x = (~x) + 1;   }   const long long N = 2e6 + 5, mod = 998244353, MAX = 2e6;   long long power[N], fac[N], inv[N];   inline long long quickpow(long long a, long long b, long long p = mod) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % p;       a = a * a % p;       b >>= 1;     }     return res;   }   inline long long C(long long n, long long m) {     if (n < m) return 0;     return fac[n] * inv[m] % mod * inv[n - m] % mod;   }   long long n;   long long ans[N];   void init() {     long long limit = 2e5;     long long x = 810;     ans[1] = 10;     ans[2] = 180;     for (register long long i = 3; i <= limit; ++i) {       ans[i] = ans[i - 1] * 10 + x;       x *= 10;       ans[i] %= mod, x %= mod;     }   }   signed main() {     init();     long long n;     cin >> n;     for (register long long i = n; i >= 1; --i) cout << ans[i] <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int kN = 100 + 1;   const int kA = 256;   bool dp[kN][kN][kA];   bool used[kN][kN][kA];   vector<pair<int, int> > g[kN];   bool Dp(int u, int v, int mark) {     if (!used[u][v][mark]) {       used[u][v][mark] = true;       dp[u][v][mark] = false;       for (const auto& edge : g[u]) {         if (edge.second < mark) {           continue;         }         dp[u][v][mark] = dp[u][v][mark] || !Dp(v, edge.first, edge.second);       }     }     return dp[u][v][mark];   }   void Solve() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int u, v;       char ch;       cin >> u >> v >> ch;       g[u - 1].emplace_back(v - 1, int(ch));     }     for (int u = 0; u < n; ++u) {       for (int v = 0; v < n; ++v) {         cout << (Dp(u, v, 0) ?  A  :  B );       }       cout <<   n ;     }   }   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(NULL);     int tests_count = 1;     for (int test_index = 0; test_index < tests_count; ++test_index) {       Solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int n, S, L;   int a[300005];   int dp[300005];   void solve() {     deque<pair<int, int> > dqmin, dqmax, dqdp;     int pos = 0;     for (int i = 1; i <= n; i++) {       if (i >= L) {         while (dqdp.size() && dqdp.back().first >= dp[i - L]) dqdp.pop_back();         dqdp.push_back(make_pair(dp[i - L], i - L));       }       while (dqmax.size() && dqmax.back().first <= a[i]) dqmax.pop_back();       dqmax.push_back(make_pair(a[i], i));       while (dqmin.size() && dqmin.back().first >= a[i]) dqmin.pop_back();       dqmin.push_back(make_pair(a[i], i));       while (dqmax.size() && dqmax.front().first - dqmin.front().first > S) {         pos++;         if (dqmax.front().second < pos) dqmax.pop_front();         if (dqmin.front().second < pos) dqmin.pop_front();       }       while (dqdp.size() && dqdp.front().second < pos - 1) dqdp.pop_front();       if (dqdp.size()) dp[i] = dqdp.front().first + 1;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     cin >> S >> L;     for (int i = 1; i <= n; i++) {       cin >> a[i];       dp[i] = n + 1;     }     solve();     if (dp[n] <= n)       cout << dp[n];     else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MaxN = 600005;   template <class t>   inline void rd(t &s) {     s = 0;     register char c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();     return;   }   long long a[MaxN], b[MaxN], vis[MaxN * 3];   struct Quetion {     long long idx, pos, val;   } que[MaxN];   struct SegTree {     struct Node {       long long val, lazy;     };     Node tr[MaxN << 2];     inline void clear() {       memset(tr, 0, sizeof tr);       return;     }     inline void pushup(long long u) {       tr[u].val = max(tr[(u << 1)].val, tr[(u << 1 | 1)].val);       return;     }     inline void pushdown(long long u, long long l, long long r) {       if (tr[u].lazy) {         tr[(u << 1)].lazy += tr[u].lazy;         tr[(u << 1 | 1)].lazy += tr[u].lazy;         tr[(u << 1)].val += tr[u].lazy;         tr[(u << 1 | 1)].val += tr[u].lazy;         tr[u].lazy = 0;       }       return;     }     inline void buildtr(long long u, long long l, long long r) {       if (l == r) {         tr[u].val = 0;         return;       }       register long long mid = (l + r) >> 1;       buildtr((u << 1), l, mid);       buildtr((u << 1 | 1), mid + 1, r);       pushup((u >> 1));       return;     }     inline void change(long long u, long long l, long long r, long long ql,                        long long qr, long long x) {       if (ql == l && r == qr) {         tr[u].val += x;         tr[u].lazy += x;         return;       }       if (l == r) return;       register long long mid = (l + r) >> 1;       pushdown(u, l, r);       if (qr <= mid)         change((u << 1), l, mid, ql, qr, x);       else if (mid < ql)         change((u << 1 | 1), mid + 1, r, ql, qr, x);       else {         change((u << 1), l, mid, ql, mid, x);         change((u << 1 | 1), mid + 1, r, mid + 1, qr, x);       }       pushup(u);       return;     }     inline long long query(long long u, long long l, long long r, long long ql,                            long long qr) {       if (l == r) return l;       register long long mid = (l + r) >> 1;       pushdown(u, l, r);       if (tr[(u << 1 | 1)].val > 0)         return query((u << 1 | 1), mid + 1, r, ql, qr);       else         return query((u << 1), l, mid, ql, qr);     }   } segtree;   signed main(void) {     long long n, m, q;     register long long cnt = 0;     rd(n);     rd(m);     for (long long i = 1; i <= n; ++i) rd(a[i]), vis[++cnt] = a[i];     for (long long i = 1; i <= m; ++i) rd(b[i]), vis[++cnt] = b[i];     rd(q);     for (long long i = 1; i <= q; ++i) {       rd(que[i].idx);       rd(que[i].pos);       rd(que[i].val);       vis[++cnt] = que[i].val;     }     sort(vis + 1, vis + cnt + 1);     cnt = unique(vis + 1, vis + cnt + 1) - vis - 1;     for (long long i = 1; i <= n; ++i)       a[i] = lower_bound(vis + 1, vis + cnt + 1, a[i]) - vis;     for (long long i = 1; i <= m; ++i)       b[i] = lower_bound(vis + 1, vis + cnt + 1, b[i]) - vis;     for (long long i = 1; i <= q; ++i)       que[i].val = lower_bound(vis + 1, vis + cnt + 1, que[i].val) - vis;     segtree.buildtr(1, 1, cnt);     for (long long i = 1; i <= n; ++i) segtree.change(1, 1, cnt, 1, a[i], 1);     for (long long i = 1; i <= m; ++i) segtree.change(1, 1, cnt, 1, b[i], -1);     for (long long i = 1; i <= q; ++i) {       if (que[i].idx == 1) {         segtree.change(1, 1, cnt, 1, a[que[i].pos], -1);         a[que[i].pos] = que[i].val;         segtree.change(1, 1, cnt, 1, a[que[i].pos], 1);       } else {         segtree.change(1, 1, cnt, 1, b[que[i].pos], 1);         b[que[i].pos] = que[i].val;         segtree.change(1, 1, cnt, 1, b[que[i].pos], -1);       }       if (segtree.tr[1].val <= 0)         puts( -1 );       else         printf( %lld n , vis[segtree.query(1, 1, cnt, 1, cnt)]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void printvec(vector<T>& vec) {     for (long long int i = 0; i < vec.size(); i++) {       cout << vec[i] <<    ;     }     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     long long int n;     cin >> n;     vector<pair<long long int, long long int> > inp;     for (long long int i = 0; i < n; i++) {       long long int a, b, c, d;       cin >> a >> b >> c >> d;       a = a + b + c + d;       inp.push_back(make_pair(-a, i));     }     sort(inp.begin(), inp.end());     for (long long int i = 0; i < n; i++) {       if (inp[i].second == 0) {         cout << i + 1 <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int s = 1000000;   int a[1000001];   bool belongs[1000001];   bool used[1000001];   vector<int> ans;   int main() {     int n;     cin >> n;     for (int i = 0; i <= s; i++) belongs[i] = used[i] = false;     for (int i = 0; i < n; i++) {       scanf( %i , &a[i]);       belongs[a[i]] = true;     }     int u = 1;     for (int i = 0; i < n; i++)       if (!used[a[i]]) {         if (belongs[a[i]] && !belongs[s - a[i] + 1] && !used[s - a[i] + 1]) {           ans.push_back(s - a[i] + 1);           used[s - a[i] + 1] = true;           used[a[i]] = true;         } else if (belongs[a[i]] && belongs[s - a[i] + 1]) {           while (u <= s &&                  (belongs[u] || belongs[s - u + 1] || used[u] || used[s - u + 1]))             u++;           used[u] = true;           used[s - u + 1] = true;           used[s - a[i] + 1] = true;           used[a[i]] = true;           ans.push_back(u);           ans.push_back(s - u + 1);           u++;         } else           assert(false);       }     cout << int(ans.size()) << endl;     for (int i = 0; i < int(ans.size()); i++) printf( %i  , ans[i]);     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string n;   int sz;   long long mul;   long long ans;   long long powe(long long a, long long b) {     if (!b) return 1;     long long tmp = powe(a, b / 2);     tmp = (tmp * tmp) % 1000000007;     if (b % 2 == 1)       return (tmp * a) % 1000000007;     else       return tmp;   }   int main() {     cin >> n;     sz = ((int)n.size());     mul = powe(2, sz - 1);     long long tp = 1;     for (int i = sz - 1; i >= 0; i--) {       if (n[i] ==  1 ) {         ans = (ans + ((tp * mul) % 1000000007)) % 1000000007;       }       tp = (tp * 2) % 1000000007;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma )   #pragma GCC optimize( unroll-loops )   using namespace std;   long long MOD = 998244353;   double eps = 1e-12;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     string s;     cin >> s;     int coins = 0;     int x, y;     if (s[0] ==  U ) {       x = 0;       y = 1;     } else {       x = 1;       y = 0;     }     for (int i = 1; i < n; i++) {       if (s[i] ==  U ) {         if (x == y) {           if (s[i - 1] ==  U ) coins++;         }         y++;       } else {         if (x == y) {           if (s[i - 1] ==  R ) coins++;         }         x++;       }     }     cout << coins;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 10000;   const int maxm = 20000;   const int maxk = 10;   const int inf = 25;   int tot_edge, sz;   int head[maxn];   int nxt[maxm];   int to[maxm];   int cap[maxm];   int flow[maxk + 1][maxm];   int qu[maxn];   int prv[maxn];   int when[maxn];   int pass_flow[maxn];   int last_time;   int level[maxn], edge_pos[maxn];   int read() {     int xx = 0, ff = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) ff = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       xx = (xx << 3) + (xx << 1) + ch -  0 ;       ch = getchar();     }     return xx * ff;   }   void add_edge(int u, int v, int w) {     nxt[tot_edge] = head[u];     head[u] = tot_edge;     to[tot_edge] = v;     cap[tot_edge] = w;     tot_edge++;   }   bool bfs(int s, int t, int *flow) {     sz = 0;     qu[sz++] = t;     int pnt = 0;     memset(level, -1, sizeof(level));     level[t] = 0;     while (pnt < sz && level[s] == -1) {       int u = qu[pnt++];       for (int e = head[u]; e >= 0; e = nxt[e]) {         int v = to[e];         if (level[v] == -1 && flow[e ^ 1] < cap[e ^ 1]) {           level[v] = level[u] + 1;           qu[sz++] = v;         }       }     }     return level[s] != -1;   }   int dinic(int s, int t, int *flow) {     int ret = 0;     while (bfs(s, t, flow)) {       copy(head, head + maxn, edge_pos);       function<int(int, int)> find_path = [&](int u, int res) {         if (u == t) return res;         for (int &e = edge_pos[u]; e >= 0; e = nxt[e]) {           int v = to[e];           if (flow[e] == cap[e] || level[u] - 1 != level[v]) continue;           int push = find_path(v, min(res, cap[e] - flow[e]));           if (push > 0) {             flow[e] += push;             flow[e ^ 1] -= push;             if (flow[e] == cap[e]) e = nxt[e];             return push;           }         }         return 0;       };       for (int f; (f = find_path(s, 1e9)) > 0;) ret += f;     }     return ret;   }   int augment(int s, int t, int *flow) {     last_time++;     sz = 0;     qu[sz++] = s;     when[s] = last_time;     int pnt = 0;     pass_flow[s] = inf;     pass_flow[t] = 0;     while (pnt < sz && when[t] != last_time) {       int u = qu[pnt++];       assert(pass_flow[u] > 0);       for (int e = head[u]; e >= 0; e = nxt[e]) {         int v = to[e];         if (when[v] != last_time && flow[e] < cap[e]) {           pass_flow[v] = min(pass_flow[u], cap[e] - flow[e]);           prv[v] = e;           when[v] = last_time;           qu[sz++] = v;           if (v == t) break;         }       }     }     int f = pass_flow[t];     if (f == 0) return f;     do {       int e = prv[t];       flow[e] += f;       flow[e ^ 1] -= f;       assert(to[e] == t);       t = to[e ^ 1];     } while (t != s);     return f;   }   int max_flow(int s, int t, int *flow) {     int res = 0, cur = 0;     do {       cur = augment(s, t, flow);       res += cur;     } while (cur);     return res;   }   int n, m, k, q;   int masked[1 << maxk];   void go(int n, int m, int mask, int pointer) {     for (int i = 0; (mask >> i & 1) == 0 && i < k; ++i) {       int n_mask = mask | (1 << i);       copy(flow[pointer], flow[pointer] + m, flow[pointer + 1]);       cap[2 * i] = inf;       masked[n_mask] = masked[mask] + max_flow(0, n - 1, flow[pointer + 1]);       go(n, m, n_mask, pointer + 1);       cap[2 * i] = 0;     }   }   int wei[maxk];   int suma[1 << maxk];   int eptr;   struct info {     int u, v, w;   } edges[maxm];   vector<int> adj[maxn];   void relabel(int n, int m) {     sz = 0;     qu[sz++] = 0;     int pnt = 0;     memset(level, -1, sizeof(level));     level[0] = 0;     level[n - 1] = n - 1;     while (pnt < sz) {       int u = qu[pnt++];       for (auto v : adj[u]) {         if (level[v] == -1) {           level[v] = sz;           qu[sz++] = v;         }       }     }     for (int i = 0; i < n; ++i)       if (level[i] == -1) level[i] = sz++;     for (int i = 0; i < m; ++i) {       edges[i].u = level[edges[i].u];       edges[i].v = level[edges[i].v];     }   }   int main() {     memset(head, -1, sizeof head);     n = read();     m = read();     k = read();     q = read();     for (int i = 0; i < m; ++i) {       int u, v, w;       u = read();       v = read();       w = read();       u--;       v--;       edges[i] = {u, v, w};       adj[u].push_back(v);     }     relabel(n, m);     for (int i = 0; i < m; ++i) {       add_edge(edges[i].u, edges[i].v, edges[i].w);       add_edge(edges[i].v, edges[i].u, 0);     }     masked[0] = dinic(0, n - 1, flow[0]);     go(n, 2 * m, 0, 0);     int top = (1 << k) - 1;     for (int i = 0; i < q; ++i) {       for (int j = 0; j < k; ++j) wei[j] = read();       int answer = masked[top];       for (int j = 1; j < (1 << k); j++) {         int x = __builtin_ctz(j);         suma[j] = suma[j ^ (1 << x)] + wei[x];         answer = min(answer, masked[top ^ j] + suma[j]);       }       printf( %d n , answer);     }     return 0;   }


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


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const int maxn = 1000100;   int cnt_neg = 0, cnt_pos = 0;   int arr[maxn << 1];   int main() {     int n;     scanf( %d , &n);     for (int e = 1; e <= n; e++) scanf( %d , arr + e), arr[e + n] = arr[e];     int hi = 2 * n, lo = n + 1, nowlo = n;     long long sum = 0;     set<pair<int, int> > go;     unordered_set<int> removido;     for (int cur = hi; cur >= lo; cur--) {       if (arr[cur] <= nowlo)         cnt_pos++;       else         cnt_neg++, go.insert(make_pair(arr[cur] - nowlo, cur));       sum += abs(arr[cur] - nowlo);       nowlo--;     }     long long ans = sum, shift = 0, state = 0;     for (; lo > 1;) {       if (arr[hi] <= n)         cnt_pos--;       else         cnt_neg--;       sum -= abs(arr[hi] - n);       removido.insert(hi);       shift++;       sum += -cnt_neg + cnt_pos;       sum += abs(arr[lo - 1] - 1);       if (sum < ans) ans = sum, state = shift;       if (arr[lo - 1] > 1)         cnt_neg++, go.insert(make_pair(shift + arr[lo - 1] - 1, lo - 1));       else         cnt_pos++;       while (!go.empty()) {         int shi, val;         tie(shi, val) = *go.begin();         int removal = removido.count(val);         if (!(removal || shi == shift)) break;         if (!removal)           cnt_neg--, cnt_pos++;         else           removido.erase(go.begin()->second);         go.erase(go.begin());       }       lo--;       hi--;     }     printf( %lld %lld n , ans, state);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod(long long v, long long k, long long p) {     long long res = 1;     for (long long i = 0; i < 4; i++) res *= v, res %= p;     res -= ((k * v) % p);     if (res < 0) res += p;     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, p, k;     cin >> n >> p >> k;     long long Array[n];     for (long long i = 0; i < n; i++) cin >> Array[i];     long long B[n];     for (long long i = 0; i < n; i++) B[i] = mod(Array[i], k, p);     vector<long long> out;     sort(B, B + n);     long long cnt = 1;     for (long long i = 0; i < n - 1; i++) {       if (B[i + 1] != B[i] and cnt != 1)         out.push_back(cnt), cnt = 1;       else if (B[i + 1] == B[i])         cnt++;     }     if (cnt != 1) out.push_back(cnt);     long long sum = 0;     for (long long i = 0; i < out.size(); i++)       sum += ((out[i] * (out[i] - 1)) / 2);     cout << sum <<   n ;     return 0;   }


//頑張って   #include <bits/stdc++.h>   #define ff first   #define ss second   #define ll long long   #define rep(i, n) for (int i = 0; i < n; i++)   using namespace std;   #define all(x) x.begin(), x.end()   void solve() {      int n;      cin >> n;      vector <int> a(n);      for (auto &i : a)         cin >> i;      int mxn = accumulate(all(a), 0);      vector <bool> dp(mxn + 1);      dp[0] = true;      for (int i = 0; i < n; i++) {         for (int j = mxn - a[i]; j >= 0; j--) {            if (dp[j] == true)               dp[a[i] + j] = true;         }      }      if ((mxn % 2 == 0 && !dp[mxn / 2]) || mxn % 2) {         cout <<  0 n ;         return;      }      while (true) {         for (int i = 0; i < n; i++) {            if (a[i] % 2 != 0) {               cout <<  1 n  << i + 1 <<   n ;               return;            }            a[i] /= 2;         }      }   }   int main() {   #ifndef ONLINE_JUDGE      freopen( inp.in ,  r , stdin);      freopen( outp.in ,  w , stdout);   #endif      ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);      solve();      return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = (long long)1e18;   const int N = 1234567;   long long a[N], b[N];   int main() {     int n, k;     scanf( %d %d , &n, &k);     n++;     for (int i = 0; i < n; i++) {       int foo;       scanf( %d , &foo);       a[i] = foo;     }     long long z = 0;     int up = 0;     for (int i = 0; i < n; i++) {       z += a[i];       b[i] = z;       if (z % 2 != 0) {         break;       }       up++;       z /= 2;     }     long long value = 0;     int ans = 0;     for (int i = n - 1; i >= 0; i--) {       if (i <= up) {         long long tmp = value * 2 + b[i];         long long z = a[i] - tmp;         if (-k <= z && z <= k && (i != n - 1 || z != 0)) {           ans++;         }       }       value = value * 2 + a[i];       if (value < -inf || value > inf) {         break;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int di[] = {-1, 0, 1, 0};   const int dj[] = {0, 1, 0, -1};   const long long MOD = 1e9 + 7;   const long long INF = 1e9;   const double EPS = 1e-11;   class UnionFind {    private:     vector<long long> p, rank, setSize;     int numSets;       public:     UnionFind(int N) {       setSize.assign(N, 1);       numSets = N;       rank.assign(N, 0);       p.assign(N, 0);       for (int i = 0; i < N; i++) p[i] = i;     }     int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }     bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }     void unionSet(int i, int j) {       if (!isSameSet(i, j)) {         numSets--;         int x = findSet(i), y = findSet(j);         if (rank[x] > rank[y]) {           p[y] = x;           setSize[x] += setSize[y];         } else {           p[x] = y;           setSize[y] += setSize[x];           if (rank[x] == rank[y]) rank[y]++;         }       }     }     int numDisjointSets() { return numSets; }     int sizeOfSet(int i) { return setSize[findSet(i)]; }   };   int main() {     ios::sync_with_stdio(false), cin.tie(0);     int n;     cin >> n;     vector<long long> num(n);     map<int, int> idx, vis;     for (int i = 0; i < n; ++i) cin >> num[i], idx[num[i]] = i;     vector<long long> num2 = num;     sort(num2.begin(), num2.end());     UnionFind dsu(n);     for (int i = 0; i < n; ++i) {       swap(num[i], num[idx[num2[i]]]);       dsu.unionSet(i, idx[num2[i]]);     }     for (int i = 0; i < n; ++i) num[i] = dsu.findSet(i);     map<int, vector<long long> > r;     for (int i = 0; i < n; ++i) r[num[i]].push_back(i + 1);     cout << r.size() << endl;     for (map<int, vector<long long> >::iterator i = r.begin(); i != r.end();          ++i) {       cout << i->second.size() <<    ;       for (int j = 0; j < i->second.size(); ++j)         cout << i->second[j] <<    n [j == i->second.size() - 1];     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   using minheap = priority_queue<T, vector<T>, greater<T>>;   int main() {     ios_base::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       long long w, h;       cin >> w >> h;       vector<vector<long long>> a(4);       for (int i = 0; i < 4; i++) {         int k, temp;         cin >> k;         for (int j = 0; j < k; j++) {           cin >> temp;           a[i].push_back(temp);         }       }       long long ans = 0;       ans = max(ans, (a[0].back() - a[0][0]) * h);       ans = max(ans, (a[1].back() - a[1][0]) * h);       ans = max(ans, (a[2].back() - a[2][0]) * w);       ans = max(ans, (a[3].back() - a[3][0]) * w);       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   char a[5][6] = { aabb ,  abab ,  abba ,  aaaa };   char s[5][10005];   bool f[5];   int find(char s[], int k) {     int p1 = -1;     int len = strlen(s);     int cnt = 0;     for (int i = len - 1; i >= 0; i--) {       if (s[i] ==  a  || s[i] ==  e  || s[i] ==  i  || s[i] ==  o  || s[i] ==  u )         cnt++;       if (cnt == k) return i;     }     return -1;   }   bool check(char s[], char t[], int k) {     int p = find(s, k), q = find(t, k);     if (p == -1) return false;     if (q == -1) return false;     int l1 = strlen(s), l2 = strlen(t);     if (l1 - p != l2 - q) return false;     int j = q;     for (int i = p; i < l1; i++) {       if (s[i] == t[j])         j++;       else         return false;     }     return true;   }   int main() {     int n, k;     while (scanf( %d%d , &n, &k) > 0) {       memset(f, false, sizeof(f));       for (int i = 1; i <= n; i++) {         for (int j = 0; j < 4; j++) scanf( %s , s[j]);         if (!check(s[0], s[1], k)) {           f[0] = true;           f[3] = true;         }         if (!check(s[2], s[3], k)) {           f[0] = true;           f[3] = true;         }         if (!check(s[0], s[2], k)) {           f[1] = true;           f[3] = true;         }         if (!check(s[1], s[3], k)) {           f[1] = true;           f[3] = true;         }         if (!check(s[0], s[3], k)) {           f[2] = true;           f[3] = true;         }         if (!check(s[2], s[1], k)) {           f[2] = true;           f[3] = true;         }       }       bool sol = false;       if (!f[0] && !f[1] && !f[2]) {         puts( aaaa );         continue;       }       for (int i = 2; i >= 0; i--) {         if (!f[i]) {           puts(a[i]);           sol = true;           break;         }       }       if (!sol) puts( NO );     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   struct edge {     int to, index;     edge(int t = 0, int i = 0) {       to = t;       index = i;     }   };   vector<edge> g[N];   int num[N], ans[N], dep[N], fa[18][N], n, m;   void add(int from, int to, int index) { g[from].push_back(edge(to, index)); }   void dfs(int x, int ffa, int d) {     fa[0][x] = ffa;     dep[x] = d;     for (int i = 0; i < g[x].size(); i++) {       int y = g[x][i].to;       if (y == ffa) continue;       dfs(y, x, d + 1);     }   }   void init() {     m = 0;     while (n >= (1 << m)) m++;     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) {         if (fa[i - 1][j] < 0)           fa[i][j] = -1;         else {           fa[i][j] = fa[i - 1][fa[i - 1][j]];         }       }     }   }   int LCA(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     for (int i = m; i >= 0; i--) {       if ((dep[x] - dep[y]) & (1 << i)) x = fa[i][x];     }     if (x == y) return x;     for (int i = m; i >= 0; i--) {       if (fa[i][x] != fa[i][y]) {         x = fa[i][x];         y = fa[i][y];       }     }     return fa[0][x];   }   void dfs2(int x, int fa, int z) {     for (int i = 0; i < g[x].size(); i++) {       int y = g[x][i].to;       if (y == fa) continue;       dfs2(y, x, g[x][i].index);       num[x] += num[y];     }     ans[z] = num[x];   }   int main() {     int x, y, rt;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scanf( %d%d , &x, &y);       add(x, y, i);       add(y, x, i);     }     dfs(1, -1, 0);     init();     int TA;     scanf( %d , &TA);     while (TA--) {       scanf( %d%d , &x, &y);       rt = LCA(x, y);       num[x]++;       num[y]++;       num[rt] -= 2;     }     dfs2(1, -1, 0);     for (int i = 1; i < n; i++) printf( %d  , ans[i]);     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   int n, a[2 * 100004], b[2 * 100004], c[2 * 100004], poz, x;   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       c[a[i]] = 1;     }     poz = 1;     for (int i = 1; i <= n; ++i) {       cin >> b[i];       if (c[b[i]] == 0) {         cout <<  0  ;         continue;       }       for (int j = poz; j <= n; ++j) {         c[a[j]] = 0;         if (a[j] == b[i]) {           cout << j - poz + 1 <<    ;           poz = j + 1;           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, cou = 0;     cin >> n;     string s;     cin >> s;     int res = n + 1;     for (int i = 0; i < n; i++) {       if (s[i] ==  H ) cou++;     }     for (int i = 0; i < n; i++) {       int cnt = 0;       for (int j = 0; j < cou; j++) {         if (s[(i + j) % n] ==  T ) cnt++;       }       res = min(res, cnt);     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int x[55], y[55];   int main(int argc, char** argv) {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &x[i]);     for (int i = 1; i <= n; i++) scanf( %d , &y[i]);     int sum = 0;     for (int i = 1; i <= n; i++) {       sum += x[i] - y[i];     }     if (sum >= 0)       cout <<  Yes ;     else       cout <<  No ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void read(T &x) {     T res = 0, f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       res = (res << 3) + (res << 1) + c -  0 ;       c = getchar();     }     x = res * f;   }   const long long N = 200000 + 10;   long long w, a[N], n, mn = 1e13, mx = -1e13, sum;   int main() {     read(n), read(w);     for (int i = 1; i <= n; i++) {       read(a[i]);       sum += a[i];       mn = min(mn, sum);       mx = max(mx, sum);     }     if (abs(mx) > w || abs(mn) > w) {       printf( 0 );       return 0;     }     long long l = 0, r = w;     if (mn < 0) {       l = 0 - mn;     }     if (mx > 0) {       r = w - mx;     }     long long ans = r - l + 1;     if (ans > 0)       printf( %lld , r - l + 1);     else       printf( 0 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long getint() {     long long _x = 0, _tmp = 1;     char _tc = getchar();     while ((_tc <  0  || _tc >  9 ) && _tc !=  - ) _tc = getchar();     if (_tc ==  - ) _tc = getchar(), _tmp = -1;     while (_tc >=  0  && _tc <=  9 ) _x *= 10, _x += (_tc -  0 ), _tc = getchar();     return _x * _tmp;   }   inline long long add(long long _x, long long _y,                        long long _mod = 1000000007ll) {     long long _ = _x + _y;     if (_ >= _mod) _ -= _mod;     return _;   }   inline long long sub(long long _x, long long _y,                        long long _mod = 1000000007ll) {     long long _ = _x - _y;     if (_ < 0) _ += _mod;     return _;   }   inline long long mul(long long _x, long long _y,                        long long _mod = 1000000007ll) {     long long _ = _x * _y;     if (_ >= _mod) _ %= _mod;     return _;   }   long long mypow(long long _a, long long _x, long long _mod) {     if (_x == 0) return 1ll;     long long _tmp = mypow(_a, _x / 2, _mod);     _tmp = mul(_tmp, _tmp, _mod);     if (_x & 1) _tmp = mul(_tmp, _a, _mod);     return _tmp;   }   long long mymul(long long _a, long long _x, long long _mod) {     if (_x == 0) return 0ll;     long long _tmp = mymul(_a, _x / 2, _mod);     _tmp = add(_tmp, _tmp, _mod);     if (_x & 1) _tmp = add(_tmp, _a, _mod);     return _tmp;   }   inline bool equal(double _x, double _y) {     return _x > _y - 1e-9 && _x < _y + 1e-9;   }   int __ = 1, _cs;   void build() {}   long long n, m, a, b;   void init() {     n = getint();     m = getint();     a = getint() - 1;     b = getint() - 1;   }   void solve() {     long long ai = a / m, aj = a % m;     long long bi = b / m, bj = b % m;     if (ai == bi || (a == 0 && b == n - 1) || m == 1) {       puts( 1 );       exit(0);     }     if (aj == 0 && (bj == m - 1 || b == n - 1)) {       puts( 1 );       exit(0);     }     if (aj == 0 || bj == m - 1 || bi == ai + 1 || bj + 1 == aj || b == n - 1) {       puts( 2 );       exit(0);     }     puts( 3 );   }   int main() {     build();     while (__--) {       init();       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   template <class L, class R>   ostream &operator<<(ostream &os, pair<L, R> P) {     return os <<  (  << P.first <<  ,  << P.second <<  ) ;   }   template <class T>   ostream &operator<<(ostream &os, vector<T> V) {     os <<  [ ;     for (auto vv : V) os << vv <<  , ;     return os <<  ] ;   }   template <class TH>   void _dbg(const char *sdbg, TH h) {     cerr << sdbg <<  =  << h <<   n ;   }   template <class TH, class... TA>   void _dbg(const char *sdbg, TH h, TA... a) {     while (*sdbg !=  , ) cerr << *sdbg++;     cerr <<  =  << h <<  , ;     _dbg(sdbg + 1, a...);   }   const long long N = 4e5 + 7;   long long n, a[N], pre[N], ansLen, ansIdx;   double ans = -1.0;   double sum(long long l, long long r) {     return pre[r] - (l > 0 ? pre[l - 1] : 0);   }   double f(long long len, long long idx) {     double ret = pre[idx] - pre[idx - len - 1];     ret += pre[n] - pre[n - len];     ret /= len + len + 1;     ret -= a[idx];     if (ret > ans) {       ans = ret;       ansIdx = idx;       ansLen = len;     }     return ret;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> n;     for (long long i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + n + 1);     for (long long i = 1; i <= n; i++) pre[i] = a[i] + pre[i - 1];     for (long long i = 1; i <= n; i++) {       long long cnt = min(i - 1, n - i);       long long lo = 0, hi = cnt;       while (hi - lo > 3) {         long long m1 = lo + (hi - lo) / 3, m2 = hi - (hi - lo) / 3;         if (f(m1, i) < f(m2, i))           lo = m1;         else           hi = m2;       }       for (long long k = lo; k <= hi; k++) f(k, i);     }     cout << 2 * ansLen + 1 <<   n ;     for (long long i = ansIdx; i >= ansIdx - ansLen; i--) cout << a[i] <<    ;     for (long long i = n - ansLen + 1; i <= n; i++) cout << a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n, a, j, b, m, s = 0, t = 0;     int x[105] = {0};     cin >> n >> m;     for (i = 1; i <= m; ++i) {       cin >> a;       for (j = a; j <= n; ++j) {         if (x[j] != 0) break;         x[j] = a;       }     }     for (i = 1; i <= n; ++i) cout << x[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 100;   const int MAXM = 15;   int N, Q, M;   int log2(int v) {     int r = 1;     while (v >>= 1) r++;     return r;   }   int a[MAXN];   int t[2][MAXN];   struct ST {     int v[3 * MAXN][2][MAXM];     int l[3 * MAXN], r[3 * MAXN];     bool lz[3 * MAXN];     int NXT;     int sz;     void updv(const int& n) {       assert(n != -1 and l[n] != -1 and r[n] != -1);       for (int i = 0; i <= M; i++)         for (int j = 0; j < 2; j++) v[n][j][i] = v[l[n]][j][v[r[n]][j][i]];     }     void init(int n, int nl, int nr) {       assert(n != -1 and nl < nr);       lz[n] = false;       l[n] = r[n] = -1;       if (nr - nl == 1) {         for (int i = 0; i < M; i++)           for (int j = 0; j < 2; j++) v[n][j][i] = i + 1;         v[n][a[nl]][M] = M, v[n][!a[nl]][M] = 0;       }       if (nr - nl > 1) {         int m = nl + ((nr - nl) >> 1);         init(l[n] = NXT++, nl, m);         init(r[n] = NXT++, m, nr);         updv(n);       }     }     ST() {}     ST(const int& s, bool ini) {       sz = s;       NXT = 0;       if (ini) init(NXT++, 0, sz);     }     void prop(int n, int nl, int nr) {       if (!lz[n]) return;       for (int i = 0; i <= M; i++) swap(v[n][0][i], v[n][1][i]);       if (nr - nl > 1) {         lz[l[n]] = !lz[l[n]];         lz[r[n]] = !lz[r[n]];       }       lz[n] = false;     }     void upd(int n, int nl, int nr, int gl, int gr) {       if (gl <= nl and gr >= nr) {         lz[n] = !lz[n];         prop(n, nl, nr);         return;       }       if (nr - nl > 1) {         prop(n, nl, nr);         int m = nl + ((nr - nl) >> 1);         if (gl < m)           upd(l[n], nl, m, gl, gr);         else           prop(l[n], nl, m);         if (gr > m)           upd(r[n], m, nr, gl, gr);         else           prop(r[n], m, nr);         updv(n);         return;       }       assert(false);     }     void upd(int gl, int gr) { upd(0, 0, sz, gl, gr); }     int qry(int n, int nl, int nr, int gl, int gr, int c = M) {       prop(n, nl, nr);       if (gl <= nl and gr >= nr) {         return v[n][0][c];       }       if (nr - nl > 1) {         int m = nl + ((nr - nl) >> 1);         if (gr > m) c = qry(r[n], m, nr, gl, gr, c);         if (gl < m) c = qry(l[n], nl, m, gl, gr, c);         return c;       }       assert(false);       return -1;     }     int qry(int gl, int gr) { return qry(0, 0, sz, gl, gr); }   } st;   void q1() {     int l, r, v;     scanf( %d%d%d , &l, &r, &v);     if (v & 1) st.upd(--l, r);   }   void q2() {     int l, r;     scanf( %d%d , &l, &r);     printf( %d n , (st.qry(--l, r) == 0 ? 2 : 1));   }   int main() {     scanf( %d%d%d , &N, &M, &Q);     for (int i = 0, v; i < N; i++) {       scanf( %d , &v);       a[i] = v & 1;     }     st = *(new ST(N, true));     for (int i = 0, type; i < Q; i++) {       scanf( %d , &type);       if (type == 1)         q1();       else if (type == 2)         q2();     }     return 0;   }


#include <bits/stdc++.h>   const int N = (int)2e5 + 5;   const int MOD = (int)1e9 + 7;   const bool MULTI_TEST = true;   const double PI = acos(-1.0);   using namespace std;   void solve() {     int n;     cin >> n;     int a[n];     int max = 0, index = -1;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > max) {         max = a[i];       }     }     if (*min_element(a, a + n) == max)       cout <<  -1 n ;     else {       for (int i = 0; i < n - 1; i++) {         if (a[i] == max && a[i] > a[i + 1]) index = i + 1;       }       if (index != -1) {         cout << index <<   n ;         return;       } else {         for (int i = 1; i < n; i++) {           if (a[i] == max && a[i] > a[i - 1]) index = i + 1;         }       }       cout << index << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     int t = 1;     if (MULTI_TEST) cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100500], c[300], dp[100500][305], z, cnt, tmp, e, s, l, r, n, m, x,       y, k, j, p, k1, k2, i, cur, rez;   vector<long long> f[100500];   long long Abs(long long x) {     if (x < 0) return -x;     return x;   }   int main() {     cin >> n >> m >> s >> e;     for (i = 0; i < n; i++) cin >> a[i];     for (j = 0; j < m; j++) {       cin >> x;       f[x].push_back(j);     }     for (i = 0; i <= n; i++)       for (j = 0; j <= s / e; j++) dp[i][j] = m + 1;     dp[0][0] = -1;     for (i = 0; i < n; i++) {       for (j = 0; j <= s / e; j++)         if (dp[i][j] != m + 1) {           long long tmp = upper_bound(f[a[i]].begin(), f[a[i]].end(), dp[i][j]) -                           f[a[i]].begin();           if (tmp != f[a[i]].size())             dp[i + 1][j + 1] = min(dp[i + 1][j + 1], f[a[i]][tmp]);           dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);         }     }     rez = 0;     for (i = 0; i <= n; i++) {       for (j = 0; j <= s / e; j++) {         if (i + dp[i][j] + 1 + j * e <= s && dp[i][j] != m + 1) rez = max(rez, j);       }     }     cout << rez << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct data {     float x, a;   } h[1005];   bool cmp(data a, data b) { return a.x < b.x; };   int main() {     int n, ans = 2;     float t, d;     cin >> n >> t;     for (int i = 1; i <= n; i++) cin >> h[i].x >> h[i].a;     sort(h + 1, h + n + 1, cmp);     for (int i = 1; i < n; i++) {       d = h[i + 1].x - h[i].x - h[i].a / 2 - h[i + 1].a / 2;       if (d > t) ans += 2;       if (abs(d - t) < 1e-6) ans++;     }     cout << ans << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   template <typename T>   using minpq = priority_queue<T, vector<T>, greater<T>>;   const int N = 5e5 + 5;   int n;   long long a[N], x;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = (0); i < ((n + 1) / 2); i++) cin >> a[i];     cin >> x;     long long sum = 0, mn = n / 2 + 1, mx = n;     vector<pair<long long, long long>> ve;     for (int i = (n + 1) / 2 - 1; i >= 0; i--) {       sum += a[i];       if (x > 0) {         if (sum <= 0) {           mn = max(mn,                    min((long long)n - i + 1, (-sum + x) / x + (n + 1) / 2 - i));         }       } else if (x < 0) {         if (sum > 0) {           long long val = (sum - x - 1) / -x - 1 + (n + 1) / 2 - i;           if (n - i + 1 > val) {             ve.emplace_back(val + 1, n - i);           }         } else {           mn = max(mn, (long long)n - i + 1);         }       } else if (sum <= 0) {         mn = max(mn, (long long)n - i + 1);       }     }     reverse((ve).begin(), (ve).end());     for (auto &p : ve) {       if (p.first <= mx && mx <= p.second) {         mx = p.first - 1;       }     }     if (mn <= mx) {       cout << mx <<   n ;     } else {       cout <<  -1 n ;     }   }


#include <bits/stdc++.h>   const long long Inf = 1e18;   const long double eps = 1e-7;   long long LINF = (long long)2e18;   using namespace std;   long long mod = 1e9 + 7;   long long mod5 = 1e9 + 9;   long long mod3 = 998244353;   long long mod4 = 1000003;   long long mod2 = 1e9 + 123;   const int MAXN = 10100000;   const int INF = 1000000000;   vector<vector<int> > a;   int n, m;   vector<pair<int, int> > mx;   int rec(int pos, vector<int> mxs) {     if (pos == m) {       int ss = 0;       for (long long(i) = 0; (i) < n; (i)++) {         ss += mxs[i];       }       return ss;     }     int cur = 0;     int ss = 0;     for (long long(i) = 0; (i) < n; (i)++) {       cur += mxs[i];       ss += mxs[i];     }     int ans = cur;     for (long long(i) = 0; (i) < n; (i)++) {       cur = ss;       vector<int> lol = mxs;       for (long long(j) = 0; (j) < n; (j)++) {         if (a[(i + j) % n][mx[pos].second] > mxs[j]) {           cur += a[(i + j) % n][mx[pos].second] - mxs[j];           lol[j] = a[(i + j) % n][mx[pos].second];         }       }       ans = max(ans, rec(pos + 1, lol));     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.setf(ios::fixed);     cout.precision(20);     int tt;     cin >> tt;     while (tt--) {       cin >> n >> m;       a.clear();       a.resize(n, vector<int>(m));       for (long long(i) = 0; (i) < n; (i)++) {         for (long long(j) = 0; (j) < m; (j)++) {           cin >> a[i][j];         }       }       mx.clear();       for (long long(i) = 0; (i) < m; (i)++) {         int cur = -1;         for (long long(j) = 0; (j) < n; (j)++) {           cur = max(cur, a[j][i]);         }         mx.push_back({cur, i});       }       sort((mx).rbegin(), (mx).rend());       mx.resize(min(4, m));       m = min(m, 4);       vector<int> kek(n, 0);       cout << rec(0, kek) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long M = 1000000007;   int main() {     int n, x, y;     cin >> n >> x >> y;     string s;     cin >> s;     int ans = 0;     for (int i = 0; i < x; i++) {       int pos = n - i - 1;       char current =  0 ;       if (i == y) {         current =  1 ;       }       if (current != s[pos]) {         ans++;       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10, OO = 0x3f3f3f3f;   int dx[] = {1, 0, -1, 0};   int dy[] = {0, 1, 0, -1};   int tc, n, m;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     cin >> tc;     while (tc--) {       cin >> n >> m;       cin >> s;       vector<long long> freq(n + 1, 0);       vector<int> indx(m);       for (int i = 0; i < int(m); i++) {         cin >> indx[i];         freq[0]++;         freq[indx[i]]--;       }       freq[0]++;       for (int i = int(1); i <= int(n - 1); i++) freq[i] += freq[i - 1];       vector<long long> karakter(26, 0);       for (int i = 0; i < int(n); i++) karakter[s[i] -  a ] += freq[i];       for (int i = 0; i < int(26); i++) cout << karakter[i] <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int a[N];   int sum[11];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       sum[a[i]]++;     }     while (1) {       int i, aa[11];       memset(aa, 0, sizeof(aa));       for (i = 1; i < 11; ++i) aa[i] = sum[i];       sort(aa, aa + 11);       for (i = 0; i < 11; ++i)         if (aa[i]) break;       if (aa[10] - aa[i] > 1) {         if (aa[i] == 1) {           if (aa[i + 1] == aa[10]) {             cout << n;             break;           }         }       } else if (aa[i] == aa[10]) {         if (aa[i] == 1 || i == 10) {           cout << n;           break;         }       } else {         if (aa[i] == 1) {           if (aa[i + 1] == aa[10]) {             cout << n;             break;           }         }         if (aa[i] == aa[9]) {           cout << n;           break;         }       }       sum[a[n]]--;       n--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool umax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   long long a, b, c, type, ric[300007], par[300007], cost[300007], d[300007], n,       m, lvl[300007], P[300007][20 * 2];   vector<pair<long long, long long> > E[300007];   pair<pair<long long, long long>, long long> way[300007];   long long atabul(long long x) {     if (ric[x] == x) return x;     return ric[x] = atabul(ric[x]);   }   void dfs(long long x, long long y, long long z) {     lvl[x] = lvl[y] + 1;     P[x][0] = y;     cost[x] = z;     if (z == 1) {       ric[x] = y;       atabul(x);     }     for (int i = 0; i < int(E[x].size()); i++)       if (E[x][i].first != y) dfs(E[x][i].first, x, E[x][i].second);   }   void build_table() {     for (int j = 1; j <= 20; j++)       for (int i = 1; i <= n; i++)         if (P[i][j - 1] > 0) P[i][j] = P[P[i][j - 1]][j - 1];   }   void form_LCA() {     for (int i = 0; i <= n; i++)       for (int j = 0; j <= 20; j++) P[i][j] = -1;     dfs(1, 0, 0);     build_table();   }   long long LCA(long long x, long long y) {     if (lvl[x] < lvl[y]) swap(x, y);     for (int i = 20; i >= 0; i--)       if (lvl[x] - (1 << i) >= lvl[y]) x = P[x][i];     if (x == y) return x;     for (int i = 20; i >= 0; i--)       if (P[x][i] > 0 && P[x][i] != P[y][i]) x = P[x][i], y = P[y][i];     return P[x][0];   }   int main() {     scanf( %lld%lld , &n, &m);     ric[n] = n;     for (int i = 1; i < n; i++) {       scanf( %lld%lld%lld , &a, &b, &c);       E[a].push_back(make_pair(b, c));       E[b].push_back(make_pair(a, c));       ric[i] = i;       way[i] = {{a, b}, c};     }     form_LCA();     while (m--) {       scanf( %lld , &type);       if (type == 1) {         scanf( %lld%lld%lld , &a, &b, &c);         long long tr = LCA(a, b);         while (atabul(a) != atabul(tr) && c > 0) {           if (cost[a] == 1) {             a = atabul(a);             continue;           }           c /= cost[a];           a = P[a][0];         }         while (atabul(b) != atabul(tr) && c > 0) {           if (cost[b] == 1) {             b = atabul(b);             continue;           }           c /= cost[b];           b = P[b][0];         }         printf( %lld n , c);       } else {         scanf( %lld%lld , &a, &b);         long long qm = way[a].first.first, gr = way[a].first.second;         if (lvl[qm] < lvl[gr]) swap(qm, gr);         cost[qm] = b;         if (b == 1) {           ric[qm] = gr;           atabul(qm);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int in() {     int32_t x;     scanf( %d , &x);     return x;   }   inline string get() {     char ch[1000010];     scanf( %s , ch);     return ch;   }   const int MAX_LG = 60;   const long long maxn = 1e6 + 100;   const long long base = 29;   const long long mod = 1e9 + 7;   const long long INF = 1e18 + 100;   struct state {     long long a = 0, b = 0, tp = 0;     state() {}     state(long long a, long long b, long long tp) : a(a), b(b), tp(tp) {}   };   long long cnt[maxn];   long long di[51][51][2];   long long C[51][51];   long long ways[51][51][2];   queue<state> q;   int32_t main() {     long long n = in(), k = in();     for (long long i = 0; i < n; i++) cnt[in() / 51]++;     q.push({cnt[0], cnt[1], 0});     for (long long i = 0; i <= 50; i++)       for (long long j = 0; j <= 50; j++) di[i][j][0] = di[i][j][1] = INF;     for (long long i = 0; i <= 50; i++) {       for (long long j = 0; j <= i; j++) {         if (j == 0)           C[i][j] = 1;         else           C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;       }     }     di[cnt[0]][cnt[1]][0] = 0;     ways[cnt[0]][cnt[1]][0] = 1;     while (q.empty() == false) {       state now = q.front();       q.pop();       long long a2 = cnt[0] - now.a;       long long b2 = cnt[1] - now.b;       for (long long i = 0; i <= now.a; i++) {         for (long long j = 0; j <= now.b; j++) {           if (i + j == 0) continue;           if (i * 50 + j * 100 > k) continue;           long long d2 = di[now.a][now.b][now.tp] + 1;           long long *d3 = &di[a2 + i][b2 + j][now.tp ^ 1];           if (*d3 == INF) {             *d3 = d2;             q.push({a2 + i, b2 + j, now.tp ^ 1});           }           if (*d3 == d2) {             ways[a2 + i][b2 + j][now.tp ^ 1] += ways[now.a][now.b][now.tp] *                                                 C[now.a][i] % mod * C[now.b][j] %                                                 mod;             if (ways[a2 + i][b2 + j][now.tp ^ 1] > mod)               ways[a2 + i][b2 + j][now.tp ^ 1] -= mod;           }         }       }     }     if (ways[cnt[0]][cnt[1]][1] == 0)       return cout << -1 <<   n  << 0 <<   n , 0;     else {       cout << di[cnt[0]][cnt[1]][1] <<   n ;       cout << ways[cnt[0]][cnt[1]][1] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long modulo(long long base, long long exponent, long long modulus);   long long choose(long long n, long long k);   long long inverse(long long a, long long m);   void build();   void fileio();   long long ncr(long long n, long long r);   const int nax = 1e6 + 10;   const int LG = log2(nax) + 1;   vector<long long> fact(nax);   long long dp[1LL << 20];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     string s;     cin >> s;     long long freq[m][m];     memset(freq, 0, sizeof(freq));     for (int i = 1; i < n; i++) {       freq[s[i] -  a ][s[i - 1] -  a ]++;       freq[s[i - 1] -  a ][s[i] -  a ]++;     }     for (int i = 0; i < (1LL << m); i++) dp[i] = 1000000000000000;     for (int mask = 0; mask < (1LL << m); mask++) {       long long cost = 0;       for (int i = 0; i < m; i++) {         for (int j = i + 1; j < m; j++) {           if ((mask >> i & 1) ^ (mask >> j & 1)) {             cost += freq[i][j];           }         }       }       for (int i = 0; i < m; i++) {         if ((mask & (1LL << i)) == 0) continue;         dp[mask] = min(dp[mask], dp[mask ^ (1LL << i)] + cost);         if ((mask ^ (1LL << i)) == 0) dp[mask] = cost;       }     }     long long ans = dp[(1LL << m) - 1];     cout << ans <<   n ;     return 0;   }   long long ncr(long long n, long long r) {     if (r > n || r < 0 || n < 0) return 0;     long long ans = fact[n];     long long temp = (fact[n - r] * fact[r]) % 1000000007;     ans = (ans * inverse(temp, 1000000007)) % 1000000007;     return ans;   }   void fileio() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   void build() {     fact[0] = 1;     for (long long i = 1; i < nax; i++) fact[i] = (fact[i - 1] * i) % 1000000007;   }   long long modulo(long long base, long long exponent, long long modulus) {     if (modulus == 1) return 0;     long long result = 1;     base = base % modulus;     while (exponent > 0) {       if (exponent % 2 == 1) {         result = (result * base) % modulus;       }       exponent = exponent >> 1;       base = (base * base) % modulus;     }     return result;   }   long long choose(long long n, long long k) {     if (k == 0) return 1;     return (n * choose(n - 1, k - 1)) / k;   }   void EE(long long a, long long b, long long &co1, long long &co2) {     if (a % b == 0) {       co1 = 0;       co2 = 1;       return;     }     EE(b, a % b, co1, co2);     long long temp = co1;     co1 = co2;     co2 = temp - co2 * (a / b);   }   long long inverse(long long a, long long m) {     long long x, y;     EE(a, m, x, y);     if (x < 0) x += m;     return x;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[100500];   int c[100500];   int n;   bool vis[100500];   bool dfs(int u, int cu) {     if (vis[u]) return 0;     vis[u] = 1;     bool r = 0;     if (c[u] != cu) return 1;     for (int v : g[u]) r |= dfs(v, cu);     return r;   }   int main() {     scanf( %d , &n);     for (int i = 0, qwe = n - 1; i < qwe; ++i) {       int u, v;       scanf( %d%d , &u, &v);       u--;       v--;       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 0, qwe = n; i < qwe; ++i) scanf( %d , c + i);     int u = -1, sz = 0;     for (int i = 0, qwe = n; i < qwe; ++i) {       set<int> s;       for (int v : g[i])         if (c[i] != c[v]) s.insert(v);       if (s.size() > sz) u = i, sz = s.size();     }     if (u == -1) {       puts( YES n1 );       return 0;     }     vis[u] = 1;     for (int i = 0, qwe = g[u].size(); i < qwe; ++i)       if (dfs(g[u][i], c[g[u][i]])) {         puts( NO );         return 0;       }     printf( YES n%d n , u + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[105][105];   int main() {     scanf( %d %d , &n, &m);     if (n + m == 3 or n + m == 4)       printf( -1 n );     else {       int num = 2;       if (n >= m) {         for (int i = 1; i <= n; i++)           for (int j = 1; j <= m; j++) {             if (num > m * n) num = 1;             a[i][j] = num;             num += 2;           }       } else         for (int j = 1; j <= m; j++)           for (int i = 1; i <= n; i++) {             if (num > m * n) num = 1;             a[i][j] = num;             num += 2;           }       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) {           printf( %d , a[i][j]);           if (j == m)             printf(  n );           else             printf(   );         }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const inline int __GET_INT() {     int ret;     scanf( %d , &ret);     return ret;   }   const int maxn = 2002;   int n, m;   char grid[maxn][maxn];   int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};   int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};   int cntStar(int r, int c) {     return (grid[r][c] ==  * ) + (grid[r + 1][c] ==  * ) +            (grid[r][c + 1] ==  * ) + (grid[r + 1][c + 1] ==  * );   }   void dfs(int r, int c) {     if (r < 0 || c < 0 || (r + 1) >= n || (c + 1) >= m) {       return;     }     if (cntStar(r, c) != 1) {       return;     }     grid[r][c] = grid[r + 1][c] = grid[r][c + 1] = grid[r + 1][c + 1] =  . ;     for (int i = 0; i < 2; ++i)       for (int j = 0; j < 2; ++j) {         for (int k = 0; k < 8; ++k) {           dfs(r + i + dx[k], c + j + dy[k]);         }       }   }   int main() {     n = __GET_INT();     m = __GET_INT();     for (int i = 0; i < n; ++i) {       scanf( %s , grid[i]);     }     for (int i = 0; (i + 1) < n; ++i)       for (int j = 0; (j + 1) < m; ++j) {         dfs(i, j);       }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) printf( %c , grid[i][j]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[200005];   int b[200005];   int n, k, Q;   long long ans;   int l, r;   int main() {     scanf( %d , &Q);     while (Q--) {       scanf( %d%d , &n, &k);       for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);       for (int i = 1; i <= k; i++) scanf( %d , &b[i]);       sort(a + 1, a + 1 + n);       sort(b + 1, b + 1 + k);       int l, r;       ans = 0;       l = 1;       r = n;       for (int i = 1; i <= k; i++) {         if (b[i] == 1)           ans += a[r] + a[r];         else           break;         r--;       }       for (int i = k; i >= 1; i--) {         if (b[i] == 1) break;         ans += a[l] + a[r];         r--;         l += b[i] - 1;       }       printf( %lld n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) {     if (a > b) return a;     return b;   }   long long min(long long a, long long b) {     if (a < b) return a;     return b;   }   const int MOD = 1e9 + 7, N = 102, L = 3005, INF = INT_MAX;   pair<long long, long long> a[N];   long long dp[L][N][2];   int main() {     int n, l;     cin >> n >> l;     for (int i = 0; i < n; i++) {       cin >> a[i].first >> a[i].second;     }     for (int i = 1; i <= l; i++) {       for (int j = 0; j < n; j++) {         if (a[j].first == i)           dp[i][j][0] = 1;         else if (a[j].first < i) {           for (int c = 0; c < n; c++) {             if (c == j) continue;             if (a[c].second == a[j].first)               dp[i][j][0] += dp[i - a[j].first][c][0];             if (a[c].first == a[j].first && a[c].first != a[c].second)               dp[i][j][0] += dp[i - a[j].first][c][1];             dp[i][j][0] %= MOD;           }         }         if (a[j].second == i)           dp[i][j][1] = 1;         else if (a[j].second < i) {           for (int c = 0; c < n; c++) {             if (c == j) continue;             if (a[c].second == a[j].second)               dp[i][j][1] += dp[i - a[j].second][c][0];             if (a[c].first == a[j].second && a[c].first != a[c].second)               dp[i][j][1] += dp[i - a[j].second][c][1];             dp[i][j][1] %= MOD;           }         }       }     }     long long ans = 0;     for (int i = 0; i < n; i++) {       ans += dp[l][i][0];       if (a[i].first != a[i].second) ans += dp[l][i][1];       ans %= MOD;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 11, N = 2e5 + 5;   int n, k;   int a[N];   map<int, int> rem[M];   long long solve() {     long long ans = 0;     for (int i = 0; i < n; ++i) {       unsigned long long f = 10;       int ln = ((int)(to_string(a[i])).size());       for (int l = 1; l < M; ++l) {         int r = (k - (int)((f * a[i]) % k)) % k;         ans += rem[l][r];         if (l == ln && r == a[i] % k) ans--;         f *= 10;       }     }     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> n >> k;     for (int i = 0; i < n; ++i) {       cin >> a[i];       int l = ((int)(to_string(a[i])).size());       rem[l][a[i] % k]++;     }     cout << solve() <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, x;     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> k >> x;       cout << x + (k - 1) * 9 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 5;   int main() {     long long v, w1, w2, v1, v2;     cin >> v >> w1 >> w2 >> v1 >> v2;     long long x = max(v1, v2);     if (x * x >= v) {       if (v1 < v2) swap(v1, v2), swap(w1, w2);       long long ans = 0;       for (int i = 0; i <= v / v1; i++) {         ans = max(ans, i * w1 + (v - i * v1) / v2 * w2);       }       cout << ans << endl;     } else {       if (1.0 * w1 / v1 > 1.0 * w2 / v2) {         swap(v1, v2), swap(w1, w2);       }       long long ans = 0;       for (int i = 0; i < v2; i++) {         ans = max(ans, i * w1 + (v - i * v1) / v2 * w2);       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int mod = 1000000007;   const int inf = 1000000009;   const long long INF = 1000000000000000009;   const long long big = 1000000000000000;   const long double eps = 0.000000000000000000001;   using namespace std;   const int M = 100000;   int W[M + 5], U[M + 5], cnt[M + 5];   vector<int> D[M + 5], S;   long long int funkcja(int x) {     long long int wynik = 0;     for (auto v : D[x]) wynik += cnt[v] * U[v];     return wynik;   }   void aktualizuj(int x, int c) {     for (auto v : D[x]) cnt[v] += c;   }   int main() {     ios::sync_with_stdio(false);     cin.tie();     cout.tie();     int n;     cin >> n;     for (int i = 1; i <= M; i++) {       for (int j = i; j <= M; j += i) D[j].push_back(i);       if (i == 1)         U[i] = 1;       else if ((i / D[i][1]) % D[i][1] == 0)         U[i] = 0;       else         U[i] = -U[i / D[i][1]];     }     long long int wynik = 0;     for (int i = 1; i <= n; i++) {       int a;       cin >> a;       wynik = max(wynik, (long long int)a);       for (auto v : D[a]) W[v] = 1;     }     for (int j = M; j >= 1; j--) {       if (!W[j]) continue;       while (funkcja(j)) {         wynik = max(wynik, (long long int)j * S.back());         aktualizuj(S.back(), -1);         S.pop_back();       }       aktualizuj(j, 1);       S.push_back(j);     }     cout << wynik;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, sum, x;   int main() {     cin >> a >> b;     while (a) {       sum += a;       x += a % b;       a /= b;       a += x / b;       x %= b;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, arr[500010], temp, j, i, ans;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> arr[i];     };     sort(arr, arr + n);     i = 0, j = n / 2;     ans = n;     while (i < n / 2) {       while (j < n) {         if (arr[i] * 2 <= arr[j]) {           ans--;           j++;           break;         } else           j++;       }       i++;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int l[210000], r[210000];   vector<pair<int, int> > v;   int n, m, k;   int mp[1000];   int lbit[1000];   int dp[210000][300];   int msk[210000];   int main() {     for (int i = 0; i < 210000; i++)       for (int j = 0; j < 300; j++) dp[i][j] = -0x3f3f3f3f;     dp[0][0] = 0;     for (int i = 0; i < (1 << 9); i++) {       int cnt = 0;       for (int j = 0; j < 8; j++)         if (i & (1 << j)) {           mp[i]++;         } else if (lbit[i] == 0) {           lbit[i] = (1 << j);         }     }     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       scanf( %d%d , &l[i], &r[i]);       v.push_back({l[i] - 1, i});       v.push_back({r[i], -i});     }     sort(v.begin(), v.end());     int tim = 0;     int posmsk = 0;     int ans = 0;     int lst = 0;     for (auto p : v) {       tim++;       if (p.second < 0) {         for (int j = 0; j < (1 << 8); j++)           if (j & msk[-p.second])             dp[tim][j ^ msk[-p.second]] =                 max(dp[tim][j ^ msk[-p.second]],                     dp[tim - 1][j] + max(0, p.first - lst) * (mp[j] & 1));           else {             dp[tim][j] =                 max(dp[tim][j], dp[tim - 1][j] + (p.first - lst) * (mp[j] & 1));           }         posmsk ^= msk[-p.second];       } else {         msk[p.second] = lbit[posmsk];         posmsk ^= msk[p.second];         for (int j = 0; j < (1 << 8); j++)           if ((j & msk[p.second]) == 0) {             dp[tim][j ^ msk[p.second]] =                 max(dp[tim][j ^ msk[p.second]],                     dp[tim - 1][j] + (max(0, p.first - lst)) * (mp[j] & 1));             dp[tim][j] =                 max(dp[tim][j], dp[tim - 1][j] + (p.first - lst) * (mp[j] & 1));           }       }       lst = p.first;     }     cout << dp[2 * n][0];     return ~~(0 ^ 0 ^ 0);   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int N = 3005;   int n, c, a[N], dp[N][N], g[N][N], freq[N], mul[N], imul[N], pw[N], cnt[N];   int dp2[2][N][1 << 12];   int inverse(int n) {     if (n == 1) return 1;     return inverse(mod % n) * 1LL * (mod - mod / n) % mod;   }   inline void add(int &x, int y) {     x += y;     if (x >= mod) x -= mod;   }   void solve1() {     for (int i = 1; i <= n; i++) {       a[i]--;     }     memset(dp2, 0, sizeof(dp2));     int flg = 0;     dp2[0][0][0] = 1;     for (int i = 1; i <= n; i++) {       for (int p = 0; p * c <= i; p++) {         for (int mask = 0; mask < (1 << c); mask++) {           dp2[flg ^ 1][p][mask] = 0;         }       }       for (int p = 0; p * c <= i; p++) {         for (int mask = 0; mask + 1 < (1 << c); mask++) {           int nmask = mask | (1 << a[i]);           if (nmask + 1 == (1 << c)) {             add(dp2[flg ^ 1][p + 1][0], dp2[flg][p][mask]);           } else {             add(dp2[flg ^ 1][p][nmask], dp2[flg][p][mask]);           }           add(dp2[flg ^ 1][p][mask], dp2[flg][p][mask]);         }       }       flg ^= 1;     }     memset(cnt, 0, sizeof(cnt));     for (int p = 0; p <= n; p++) {       for (int mask = 0; mask + 1 < (1 << c); mask++) {         add(cnt[p], dp2[flg][p][mask]);       }     }     add(cnt[0], mod - 1);     for (int i = 0; i <= n; i++) {       cout << cnt[i] <<    ;     }     cout <<   n ;   }   void solve2() {     mul[0] = 0;     pw[0] = 1;     for (int i = 1; i <= n; i++) {       mul[i] = mul[i - 1] + mul[i - 1] + 1;       if (mul[i] >= mod) mul[i] -= mod;       imul[i] = inverse(mul[i]);       pw[i] = mul[i] + 1;     }     memset(g, 0, sizeof(g));     for (int i = 1; i <= n; i++) {       int cnt = 0;       long long prd = 1;       memset(freq, 0, sizeof(freq));       for (int j = i; j <= n; j++) {         if (freq[a[j]] == 0) {           cnt++;         } else {           (prd *= imul[freq[a[j]]]) %= mod;         }         freq[a[j]]++;         (prd *= mul[freq[a[j]]]) %= mod;         if (cnt == c) {           g[i][j] = prd * imul[freq[a[j]]] % mod;         }       }     }     memset(dp, 0, sizeof(dp));     for (int i = 1; i <= n; i++) {       dp[i][1] = g[1][i];       for (int j = 1; j <= i; j++) {         for (int p = 2; p * c <= i; p++) {           dp[i][p] += dp[j - 1][p - 1] * 1LL * g[j][i] % mod;           if (dp[i][p] >= mod) dp[i][p] -= mod;         }       }     }     memset(cnt, 0, sizeof(cnt));     for (int i = 1; i <= n; i++) {       for (int p = 1; p * c <= i; p++) {         cnt[p] += dp[i][p] * 1LL * pw[n - i] % mod;         if (cnt[p] >= mod) cnt[p] -= mod;       }     }     cnt[0] = mul[n] + mod - cnt[1];     if (cnt[0] >= mod) cnt[0] -= mod;     for (int p = 1; p <= n; p++) {       cnt[p] += mod - cnt[p + 1];       if (cnt[p] >= mod) cnt[p] -= mod;     }     for (int i = 0; i <= n; i++) {       cout << cnt[i] <<    ;     }     cout <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> c;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     if (c <= 10) {       solve1();     } else {       solve2();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans[101000], mark[101000];   char s[101000];   int n, top, now, n_;   int main() {     do s[++n_] = getchar();     while (s[n_] !=  = );     scanf( %d , &n);     mark[1] = 0;     top = 1;     for (int i = 3; i < n_; i += 4) mark[++top] = (s[i] ==  - );     now = 0;     for (int i = 1; i <= top; i++) ans[i] = 1;     for (int i = 1; i <= top; i++)       if (mark[i])         now--;       else         now++;     while (now != n) {       if (now < n) {         int q = 0;         for (int i = 1; i <= top; i++)           if (!mark[i] && ans[i] < n) {             q = i;             break;           }         if (!q) {           printf( Impossible );           return 0;         }         int inc = min(n - ans[q], n - now);         ans[q] += inc;         now += inc;       } else {         int q = 0;         for (int i = 1; i <= top; i++)           if (mark[i] && ans[i] < n) {             q = i;             break;           }         if (!q) {           printf( Impossible );           return 0;         }         int inc = min(n - ans[q], now - n);         ans[q] += inc;         now -= inc;       }     }     printf( Possible n );     printf( %d , ans[1]);     for (int i = 2; i <= top; i++) {       putchar(   );       if (mark[i])         putchar( - );       else         putchar( + );       putchar(   );       printf( %d , ans[i]);     }     printf(  = %d , n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 4e5 + 5;   long long a[maxn], f[maxn], d[maxn];   int q[maxn];   int main() {     int n, i, j, l, r;     long long c;     scanf( %d%lld , &n, &c);     for (i = 1; i < (n << 1); i++) {       scanf( %lld , &a[i]);       a[i] += a[i - 1];     }     l = r = 1;     j = q[1] = 0;     for (i = 1; i <= n; i++) {       while (j < i && a[(i << 1) - 1] - a[j << 1] > c) j++;       while (l <= r && q[l] < j) l++;       if (j) f[i] = f[j - 1] + c;       if (l <= r) f[i] = max(f[i], d[q[l]] + a[(i << 1) - 1]);       d[i] = f[i] - a[i << 1];       while (l <= r && d[i] > d[q[r]]) r--;       q[++r] = i;     }     printf( %lld n , f[n]);     return 0;   }


#include <bits/stdc++.h>   template <typename T>   std::istream& operator>>(std::istream& input, std::vector<T>& v) {     for (T& a : v) input >> a;     return input;   }   void answer(bool v) {     constexpr const char* s[2] = { NO ,  YES };     std::cout << s[v] <<   n ;   }   void solve(const std::vector<unsigned>& a) {     const size_t n = a.size();     for (size_t i = 1; i < n; ++i) {       if (a[i] >= a[i - 1]) return answer(true);     }     answer(false);   }   void test_case() {     size_t n;     std::cin >> n;     std::vector<unsigned> a(n);     std::cin >> a;     solve(a);   }   int main() {     size_t t;     std::cin >> t;     while (t-- > 0) test_case();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; };   void __print(long x) { cerr << x; };   void __print(long long x) { cerr << x; };   void __print(unsigned x) { cerr << x; };   void __print(unsigned long x) { cerr << x; };   void __print(unsigned long long x) { cerr << x; };   void __print(float x) { cerr << x; };   void __print(double x) { cerr << x; };   void __print(long double x) { cerr << x; };   void __print(char x) { cerr <<      << x <<     ; };   void __print(const char *x) { cerr <<     << x <<    ; };   void __print(const string &x) { cerr <<     << x <<    ; };   void __print(bool x) { cerr << (x ?  true  :  false ); }   long long powmod(long long a, long long b) {     long long res = 1;     a %= 1000000007;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % 1000000007;       a = a * a % 1000000007;     }     return res;   }   long long string_to_int(string s) {     long long ans = 0;     long long p = 1;     for (long long i = s.size() - 1; i >= 0; i--) {       ans += (s[i] -  0 ) * p;       p *= 10;     }     return ans;   }   long long fast_pow(long long a, long long b) {     if (b == 1) return a;     if (b == 0) return 1;     long long x = fast_pow(a, b / 2);     x *= x;     if (b & 1) x *= a;     return x;   }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     long long f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   void t_c_c() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, k;     cin >> n >> m >> k;     long long arr[m];     for (long long i = 0; i < m; i++) {       cin >> arr[i];     }     long long days = 0;     long long pages = k;     long long point = 0;     long long x = 0;     long long xx = 0;     for (long long i = 0; i < m;) {       if (arr[i] - x <= pages) {         while (arr[i] - xx <= pages) {           ;           x++;           i++;         }         xx = x;         days++;       } else {         long long factor = ((arr[i] - x) - pages) / k;         pages +=             (((arr[i] - x) - pages) % k == 0 ? factor * k : (factor + 1) * k);       }     }     cout << days <<   n ;   }   int32_t main() {     t_c_c();     return 0;   }


/**    *    author:  Ujjwal Tripathi    *    created: 15.04.2021 18:04:04   **/              #include<bits/stdc++.h>   using namespace std;       #define ar array<ll, 2>   #define ll long long   #define in insert   #define pb push_back   #define pii pair<ll,ll>   #define vt vector   #define P_Q(x) priority_queue<x>   #define p_q(x) priority_queue<x, vector<x>, greater<x>>   #define For(i, n) for(ll i = 0; i < n; i++)   #define Rev(i, n) for(ll i = n-1; i >= 0; i--)   #define FOR(i, n) for(ll i = 1; i <= n; i++)   #define REV(i, n) for(ll i = n; i >= 1; i--)   #define Rep(i,a,b) for(ll i = a; i <= b; i++)   #define all(x) (x).begin(),(x).end()   #define rall(x) (x).rbegin(), (x).rend()   #define sz(x) (int) (x).size()       // Maximum priority queue   template <typename T>   using mxpq = priority_queue<T>;       // Minimum priority queue   template <typename T>   using mnpq = priority_queue<T, vt<T>, greater<T>>;           // x | (x + 1) sets lowest unset bit of x   // x & (x - 1) unsets lowest set bit of x       const ll mod = 1e9L + 7;   const ll INF = 1e18L + 5;   const ll mxN = 2e5 + 1;           ll n;   ll dp[1000004];   // remember to read no of test_cases   void solve()   {      cin>>n;      vt<ll> v(n);      For(i,n)      {       cin>>v[i];       if(v[i]%2==0)       {           cout<<v[i]<<   ;       }      }           For(i,n)       {         if(v[i]%2==1)         {           cout<<v[i]<<   ;         }       }       cout<<endl;   }       int main()   {     ios::sync_with_stdio(0);  cin.tie(0);     ll t = 1;     cin >> t;     FOR(tt, t) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200010], b[200010], n, cnt = 0;   int main() {     ios::sync_with_stdio(0);     cin >> n;     for (int i = 2; i <= n; i++) cin >> a[i];     for (int tmp = n; tmp; tmp = a[tmp]) b[++cnt] = tmp;     reverse(b + 1, b + cnt + 1);     for (int i = 1; i <= cnt; i++) cout << b[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     int t;     long long n;     cin >> t;     for (int i = 0; i < t; i++) {       cin >> n;       cout << (-1 * n) + 1 <<     << n <<   n ;     }   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   bool sort_descending(int a, int b) { return (a > b); }


#include <bits/stdc++.h>   using namespace std;   const int seed = 131;   const long long LLMAX = 2e18;   const int MOD = 1e9 + 7;   const double eps = 1e-8;   const int MAXN = 1e5 + 10;   const int hmod1 = 0x48E2DCE7;   const int hmod2 = 0x60000005;   inline long long sqr(long long x) { return x * x; }   inline int sqr(int x) { return x * x; }   inline double sqr(double x) { return x * x; }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long exgcd(long long a, long long b, long long &x, long long &y) {     long long d;     (b == 0 ? (x = 1, y = 0, d = a)             : (d = exgcd(b, a % b, y, x), y -= a / b * x));     return d;   }   long long qpow(long long a, long long n) {     long long sum = 1;     while (n) {       if (n & 1) sum = sum * a % MOD;       a = a * a % MOD;       n >>= 1;     }     return sum;   }   inline int dcmp(double x) {     if (fabs(x) < eps) return 0;     return (x > 0 ? 1 : -1);   }   long long need[MAXN], tim[MAXN], v[MAXN][2], cnt = 0;   struct node {     long long id, a, b;     node() {}     node(long long x, long long y, long long z) { id = x, a = y, b = z; }     bool operator<(const node &n) const {       if (a - b == n.a - n.b) return a > n.a;       return a - b > n.a - n.b;     }   } in[MAXN];   long long check(long long n, long long a, long long b) {     long long sum = 0;     for (int i = 0; i <= n; i++) tim[i] = need[i];     for (int i = 0; i < cnt; i++) {       if (tim[in[i].id]) {         long long minn = min(tim[in[i].id], a);         sum += in[i].a * minn;         tim[in[i].id] -= minn;         a -= minn;       }       if (tim[in[i].id]) {         long long minn = min(tim[in[i].id], b);         sum += in[i].b * minn;         tim[in[i].id] -= minn;         b -= minn;       }     }     return sum;   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, s, sum = 0, ans = 0;     cin >> n >> s;     for (int i = 0; i < n; i++) {       cin >> need[i] >> v[i][0] >> v[i][1];       sum += need[i];       in[cnt++] = node(i, v[i][0], v[i][1]);     }     long long all = (sum + s - 1) / s, l = 0, r = all;     need[n] = all * s - sum;     in[cnt++] = node(n, 0, 0);     sort(in, in + cnt);     while (l + 3 < r) {       long long m1 = (l + r) / 2, m2 = (m1 + r) / 2;       if (check(n, m1 * s, (all - m1) * s) > check(n, m2 * s, (all - m2) * s))         r = m2;       else         l = m1;     }     for (long long i = l; i <= r; i++)       ans = max(ans, check(n, i * s, (all - i) * s));     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long poww(long long a, long long b, long long md) {     return (!b ? 1                : (b & 1 ? a * poww(a * a % md, b / 2, md) % md                         : poww(a * a % md, b / 2, md) % md));   }   const long long MAXN = 1e6 + 10;   const long long INF = 8e18;   const long long MOD = 1e9 + 7;   vector<pair<pair<long long, long long>, int>> v;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       v.clear();       int n;       cin >> n;       n = n * 2 - 1;       v.resize(n);       for (int i = 0; i < n; i++)         cin >> v[i].first.first >> v[i].first.second, v[i].second = i + 1;       sort((v).begin(), (v).end(),            greater<pair<pair<long long, long long>, int>>());       vector<int> ans = {v.front().second};       for (int i = 1; i < n; i += 2) {         if (v[i].first.second < v[i + 1].first.second)           ans.push_back(v[i + 1].second);         else           ans.push_back(v[i].second);       }       sort((ans).begin(), (ans).end());       cout <<  YES  <<   n ;       for (int e : ans) cout << e <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t, x, sum = 0, y, z, flag = 0, a, p, l, r, b, c, q, i, j, k, n,                         m, maxi = LONG_MIN, mini = LONG_MAX, mul = 1;     string s, s1;     vector<long long int> v, va, vb;     map<long long int, long long int> mp, mp1;     cin >> n;     for (i = 0; i < n; i++) {       cin >> x;       mp[x]++;       mp1[x]++;     }     auto it = mp.begin();     auto it1 = mp1.begin();     while (it1 != mp1.end()) {       if (it->first == it1->first) it1++;       if (it1 == mp1.end()) break;       x = it->second;       y = it1->second;       for (i = 0; i < x && i < y; i++) {         mp[it->first]--;         sum++;         mp1[it1->first]--;       }       if (x == i) it++;       if (y == i) it1++;     }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct ele {     long long next, prev, delta, y;   };   long long r, c, k, n, curcnt = 0, ans = 0;   vector<ele> a;   vector<long long> deltaleft, deltaright;   vector<vector<long long> > X, id;   vector<pair<long long, long long> > tmp;   void init() {     X.clear();     X.resize(r + 1);     id.resize(r + 1);   }   void remove(long long id) {     long long cur = id;     deltaleft.clear();     deltaright.clear();     for (long long i = 0; i <= k; i++) {       if (cur == -1 || a[cur].delta == -1) break;       deltaleft.push_back(a[cur].delta);       cur = a[cur].prev;     }     cur = a[id].next;     for (long long i = 0; i <= k; i++) {       if (cur == -1 || a[cur].delta == -1) break;       deltaright.push_back(a[cur].delta);       cur = a[cur].next;     }     curcnt -= deltaright[0] * deltaleft[0];     curcnt -= deltaright[0] * (deltaright[0] - 1) / 2 +               deltaleft[0] * (deltaleft[0] - 1) / 2;     curcnt +=         (deltaright[0] + deltaleft[0]) * (deltaright[0] + deltaleft[0] - 1) / 2;     for (long long i = 0; i <= k; i++) {       if (i < deltaleft.size() && k - i < deltaright.size())         curcnt += deltaleft[i] * deltaright[k - i];     }     a[a[id].prev].next = a[id].next;     a[a[id].next].prev = a[id].prev;     a[a[id].next].delta += a[id].delta;   }   long long cmp(pair<long long, long long> a, pair<long long, long long> b) {     return X[a.first][a.second] < X[b.first][b.second];   }   void solve(long long r1) {     tmp.clear();     for (long long i = r1; i <= r; i++) {       for (long long j = 0; j < X[i].size(); j++) {         tmp.push_back({i, j});       }     }     sort(tmp.begin(), tmp.end(), cmp);     a.resize(tmp.size() + 2);     a[0].prev = -1;     a[0].next = 1;     a[0].y = 0;     a[tmp.size() + 1].prev = (long long)tmp.size();     a[tmp.size() + 1].next = -1;     a[tmp.size() + 1].y = c + 1;     for (long long i = 0; i < tmp.size(); i++) {       id[tmp[i].first][tmp[i].second] = i + 1;       a[i + 1].y = X[tmp[i].first][tmp[i].second];       a[i + 1].prev = i;       a[i + 1].next = i + 2;     }     a[0].delta = -1;     for (long long i = 1; i < a.size(); i++) {       a[i].delta = a[i].y - a[i - 1].y;     }     curcnt = 0;     for (long long i = 1; i < a.size(); i++) {       curcnt += (a[i].delta - 1) * a[i].delta / 2;       for (long long j = 1; j <= k; j++) {         if (i - j <= 0) break;         curcnt += a[i].delta * a[i - j].delta;       }     }     for (long long i = r; i >= r1; i--) {       ans += curcnt;       for (long long j = 0; j < X[i].size(); j++) {         remove(id[i][j]);       }     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> r >> c >> n >> k;     k--;     init();     for (long long i = 1; i <= n; i++) {       long long u, v;       cin >> u >> v;       X[u].push_back(v);     }     for (long long i = 1; i <= r; i++) {       id[i].resize(X[i].size());     }     for (long long i = 1; i <= r; i++) {       solve(i);     }     ans = (r + 1) * r / 2 * (c + 1) * c / 2 - ans;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300007;   struct tup {     int u, v, pos;     friend bool operator<(tup x, tup y) {       if (x.v < y.v) {         return 1;       }       return 0;     }   } ans[maxn];   int rec[maxn], n;   int solve() {     int cnt = 0;     rec[cnt++] = n;     ans[n].v = 2 * n + 1;     for (int i = n - 1; i >= 0; --i) {       if (ans[i].u < ans[rec[cnt - 1]].v && ans[i].u < ans[i].v) {         rec[cnt++] = i;       }     }     return cnt;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &ans[i].u, &ans[i].v);       ans[i].pos = i;     }     sort(ans, ans + n);     int cnt1 = solve() - 1;     int tmp[maxn];     for (int i = 1; i <= cnt1; ++i) {       tmp[i] = ans[rec[i]].pos + 1;     }     for (int i = 0; i < n; ++i) {       ans[i].u = -ans[i].u;       ans[i].v = -ans[i].v;     }     sort(ans, ans + n);     int cnt = solve() - 1;     if (cnt <= cnt1) {       printf( %d n , cnt1);       for (int i = 1; i <= cnt1; ++i) {         printf( %d  , tmp[i]);       }     } else {       printf( %d n , cnt);       for (int i = 1; i <= cnt; ++i) {         printf( %d  , ans[rec[i]].pos + 1);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int n, q, counts = 0;     cin >> n;     int s[n];     for (int i = 0; i < n; i++) cin >> s[i];     cin >> q;     int l[q], r[q];     for (int i = 0; i < q; i++) cin >> l[i] >> r[i];     int sums[n + 1];     sums[0] = 0;     for (int i = 1; i < n + 1; i++) sums[i] = sums[i - 1] + s[i - 1];     for (int i = 0; i < q; i++)       cout << (sums[r[i]] - sums[l[i] - 1]) / 10 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   const int M = 107;   const int inf = 1e9 + 7;   vector<int> g[N], a[M];   int w[N][M], d[N];   void bfs(int u) {     queue<int> q;     memset(d, inf, sizeof(d));     for (int i = 0; i < (int)a[u].size(); ++i) {       q.push(a[u][i]);       d[a[u][i]] = 0;     }     while (!q.empty()) {       int v = q.front();       q.pop();       w[v][u] = d[v];       for (int i = 0; i < (int)g[v].size(); ++i) {         int to = g[v][i];         if (d[to] > d[v] + 1) {           d[to] = d[v] + 1;           q.push(to);         }       }     }   }   int main() {     int n, m, k, second;     scanf( %d %d %d %d , &n, &m, &k, &second);     for (int i = 1, x; i <= n; ++i) {       scanf( %d , &x);       a[x].push_back(i);     }     for (int i = 0, u, v; i < m; ++i) {       scanf( %d %d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 1; i <= k; ++i) bfs(i);     for (int i = 1; i <= n; ++i) {       sort(w[i] + 1, w[i] + k + 1);       int ans = 0;       for (int j = 1; j <= second; ++j) ans += w[i][j];       printf( %d  , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, m, x;     unordered_map<int, int> mp;     cin >> t;     int a[t];     for (int i = 1; i <= t; i++) {       cin >> a[i];       mp[i] = a[i];     }     for (int i = 1; i <= t; i++) {       n = mp[i];       m = mp[n];       x = mp[m];       if (i == x) {         cout <<  YES ;         return 0;       }     }     cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 23;   const int mod = 1000 * 1000 * 1000 + 7;   int dp[2][1 << maxN];   int a[maxN];   int res[maxN][maxN];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     dp[0][1] = 1;     dp[0][0] = mod;     memset(res, -1, sizeof res);     for (int i = 0; i < n; i++)       for (int j = 0; j < i; j++)         for (int k = 0; k < i; k++)           if (a[j] + a[k] == a[i]) res[i][j] = k;     for (int i = 1; i < n; i++) {       int u = i & 1;       for (int mask = 0; mask < (1 << (i + 1)); mask++) dp[u][mask] = mod;       for (int mask = 0; mask < (1 << i); mask++) {         for (int j = 0; j < i; j++) {           if (res[i][j] == -1) continue;           if (mask >> j & 1)             if (mask >> res[i][j] & 1) {               int tmp = mask ^ (1 << i);               dp[u][tmp] =                   min(dp[u][tmp], max(__builtin_popcount(tmp), dp[!u][mask]));               for (int k = 0; k < i; k++) {                 if (mask >> k & 1) {                   dp[u][tmp ^ (1 << k)] =                       min(dp[u][tmp ^ (1 << k)], dp[!u][mask]);                 }               }               break;             }         }       }     }     int ans = mod;     for (int mask = 0; mask < (1 << n); mask++)       ans = min(ans, dp[(n - 1) & 1][mask]);     if (ans == mod)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MN = 51;   char a[MN][MN], b[MN][MN];   const char L =  L , R =  R , U =  U , D =  D ;   vector<pair<int, int> > sol, sol2;   int n, m;   void show() {     ;     for (int i = 0; i < n; ++i)       ;     ;     ;     for (int i = 0; i < n; ++i)       ;     ;   }   bool move(char arr[MN][MN], int i, int j) {     ;     if (arr[i][j] == U && arr[i][j + 1] == U && arr[i + 1][j] == D &&         arr[i + 1][j + 1] == D) {       ;       arr[i][j] = arr[i + 1][j] = L;       arr[i][j + 1] = arr[i + 1][j + 1] = R;     } else if (arr[i][j] == L && arr[i + 1][j] == L && arr[i][j + 1] == R &&                arr[i + 1][j + 1] == R) {       ;       arr[i][j] = arr[i][j + 1] = U;       arr[i + 1][j] = arr[i + 1][j + 1] = D;     } else {       ;       return false;     }     sol.emplace_back(i, j);     return true;     ;     show();   }   void push(char arr[MN][MN], int i, int k, bool ver) {     char aim = ver ? U : L;     ;     show();     assert(arr[i][k] == L || arr[i][k] == U);     if (arr[i][k] != aim) {       if (!move(arr, i, k)) {         push(arr, i + ver, k + !ver, !ver);         move(arr, i, k);       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) scanf( %s , a[i]);     for (int i = 0; i < n; ++i) scanf( %s , b[i]);     if (n % 2) {       ;       for (int k = 0; k < m; k += 2)         for (int i = 0; i < n; ++i) push(a, i, k, false);       swap(sol, sol2);       ;       for (int k = 0; k < m; k += 2)         for (int i = 0; i < n; i++) push(b, i, k, false);     } else {       ;       for (int i = 0; i < n; i += 2)         for (int k = 0; k < m; k++) push(a, i, k, true);       swap(sol, sol2);       ;       for (int i = 0; i < n; i += 2)         for (int k = 0; k < m; k++) push(b, i, k, true);     }     printf( %d n , (int)(sol.size() + sol2.size()));     reverse(sol.begin(), sol.end());     for (auto x : sol2) printf( %d %d n , x.first + 1, x.second + 1);     for (auto x : sol) printf( %d %d n , x.first + 1, x.second + 1);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t-- > 0) {       int l, r;       cin >> l >> r;       cout << l <<     << 2 * l <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, Mod, p[100010], a[200010], nxt[200010], w[200010], tot, root,       size[100010], son[100010], cnt;   bool vis[100010];   long long ans, mul[100010];   struct record {     int dep, step;     record(int D = 0, int S = 0) {       dep = D;       step = S;     }   } pre[100010], suf[100010];   int comp(record a, record b) { return a.dep < b.dep; }   void add(int x, int y, int val) {     tot++;     a[tot] = y;     nxt[tot] = p[x];     w[tot] = val;     p[x] = tot;   }   void getroot(int u, int fa, int N) {     size[u] = 1;     son[u] = 0;     for (int i = p[u]; i != 0; i = nxt[i])       if (a[i] != fa && vis[a[i]] == false) {         getroot(a[i], u, N);         size[u] += size[a[i]];         son[u] = max(son[u], size[a[i]]);       }     son[u] = max(son[u], N - size[u]);     if (son[u] < son[root]) root = u;   }   void getdeep(int u, int fa, long long pred, int step, long long sufd) {     pre[++cnt] = record(pred, step);     suf[cnt] = record(sufd, step);     for (int i = p[u]; i != 0; i = nxt[i])       if (a[i] != fa && vis[a[i]] == false)         getdeep(a[i], u, (pred * 10 + w[i]) % Mod, step + 1,                 (sufd + w[i] * mul[step] % Mod) % Mod);   }   int findL(int l, int r, int x, record *v) {     int mid;     while (l != r) {       mid = (l + r) >> 1;       if (v[mid].dep >= x)         r = mid;       else         l = mid + 1;     }     if (v[l].dep != x) return 1000000000;     return l;   }   int findR(int l, int r, int x, record *v) {     int mid, ans = 0;     while (l <= r) {       mid = (l + r) >> 1;       if (v[mid].dep <= x) {         ans = max(ans, mid);         l = mid + 1;       } else         r = mid - 1;     }     if (v[ans].dep != x) return 0;     return ans;   }   long long getnum(int l, int r, int now, record *v) {     int L, R;     if (l > r) return 0;     L = findL(l, r, now, v);     R = findR(l, r, now, v);     if (L <= R) return R - L + 1;     return 0;   }   void exgcd(int a, int b, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;       return;     }     long long t;     exgcd(b, a % b, x, y);     t = x;     x = y;     y = t - (a / b) * y;   }   int getinv(long long A, long long B) {     long long x, y;     exgcd(A, Mod, x, y);     x = (x % Mod + Mod) % Mod;     x = (x * B) % Mod;     return x;   }   long long calc(int u, int pre0, int s0, int suf0) {     long long sum = 0;     cnt = 0;     getdeep(u, 0, pre0, s0, suf0);     sort(pre + 1, pre + cnt + 1, comp);     sort(suf + 1, suf + cnt + 1, comp);     for (int i = 1; i <= cnt; i++) {       int now = getinv(mul[pre[i].step], Mod - pre[i].dep);       sum += getnum(1, cnt, now, suf);       if (now == 0) --sum;     }     return sum;   }   void work(int u) {     ans += calc(u, 0, 0, 0);     vis[u] = true;     for (int i = p[u]; i != 0; i = nxt[i])       if (vis[a[i]] == false) {         ans -= calc(a[i], w[i] % Mod, 1, w[i] % Mod);         root = 0;         getroot(a[i], 0, size[a[i]]);         work(root);       }   }   int main() {     scanf( %d%d , &n, &Mod);     for (int i = 1; i < n; i++) {       int x, y, v;       scanf( %d%d%d , &x, &y, &v);       ++x;       ++y;       add(x, y, v);       add(y, x, v);     }     son[0] = 1000000000;     root = 0;     mul[0] = 1;     for (int i = 1; i <= n; i++) mul[i] = mul[i - 1] * 10 % Mod;     getroot(1, 0, n);     work(root);     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <class T>   inline T LCM(T a, T b) {     if (a < 0) return LCM(-a, b);     if (b < 0) return LCM(a, -b);     return a * (b / gcd(a, b));   }   vector<int> arr;   const int N = 50005;   int memo[5001];   int save[N];   int visit[N];   int find(int pos, int &xr) {     for (int i = 0; i < N; i++) visit[i] = 0;     vector<int> toAdd;     int end = pos;     visit[arr[pos]] = 1;     for (int i = 0; i < pos; i++) {       visit[arr[i]] = 2;     }     if (visit[arr[pos]] == 2) {       return -1;     }     bool cant = false;     for (int i = pos; i < arr.size(); i++) {       if (visit[arr[i]] == 2) {         cant = true;       }       if (visit[arr[i]] == 1) {         if (cant) return -1;         for (int j = 0; j < toAdd.size(); j++) {           visit[toAdd[j]] = 1;         }         toAdd.clear();         end = i;       } else {         toAdd.push_back(arr[i]);       }     }     xr = 0;     for (int i = 0; i < N; i++) {       if (visit[i] == 1) {         xr = xr ^ i;       }     }     return end;   }   int solve(int from) {     int txr = 0;     int ret = 0;     if (from >= arr.size()) return 0;     if (memo[from] != -1) {       return memo[from];     }     int end = find(from, txr);     if (end != -1) {       ret = max(txr + solve(end + 1), solve(from + 1));     } else {       ret = solve(from + 1);     }     memo[from] = ret;     return ret;   }   int main() {     int n, i, temp, j;     for (i = (int)0; i < (int)5001; ++i) {       memo[i] = -1;     }     scanf( %d , &n);     for (i = (int)0; i < (int)n; ++i) {       scanf( %d , &temp);       arr.push_back(temp);     }     int xx;     cout << solve(0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c, d;   void solve() {     double m = max((3.0) * a / (10.0), (double)(a - a * c / 250));     double v = max((3.0) * b / (10.0), (double)(b - b * d / 250));     if (m > v) cout <<  Misha  << endl;     if (m == v) cout <<  Tie  << endl;     if (m < v) cout <<  Vasya  << endl;   }   int main() {     while (cin >> a >> b >> c >> d) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string op;   bool check(int l, int r) {     char c;     cout <<  ?   << l <<     << r << endl;     cin >> c;     return c ==  x ;   }   int main() {     while (cin >> op) {       if (op ==  end ) {         return 0;       }       int l = 1, r = 2;       while (1) {         if (check(l, r)) break;         l <<= 1, r <<= 1;       }       while (l + 1 < r) {         int mid = (l + r) >> 1;         if (check(l - 1, mid))           r = mid;         else           l = mid + 1;       }       if (l == 1 && r == 2) {         if (check(2, 3))           cout <<  ! 1  << endl;         else           cout <<  ! 2  << endl;       } else {         if (l == r)           cout <<  !   << l << endl;         else {           if (check(l, l + 1))             cout <<  !   << l + 1 << endl;           else             cout <<  !   << l << endl;         }       }     }   }