#include <bits/stdc++.h>   using namespace std;   const int MX = 200200, MSK = (1 << 20) - 1;   int T, n, m, i, x, y, z, pos, cnt, le, ri, h, fi[MX], lst[MX], s[MX], t[MX],       ch[MX], a[18][MX], npw[MX], L[MX], R[MX], A[MX];   priority_queue<long long, vector<long long>, greater<long long>> q;   long long seg[MX * 88], d[MX], sf, j;   vector<int> g[MX], f[MX];   void dfs(int i, long long dep) {     a[0][++T] = i;     fi[i] = T;     d[i] = dep;     for (int j = 0; j < g[i].size(); j++) {       dfs(g[i][j], dep + f[i][j]);       a[0][++T] = i;     }     lst[i] = T;   }   int lca(int i, int j) {     if (i > j) return lca(j, i);     int len = npw[j - i + 1];     int le = a[len][i];     int ri = a[len][j - (1 << len) + 1];     if (d[le] <= d[ri]) return le;     return ri;   }   int fndmax(int l, int r) {     int res = max(A[l], A[r]), x, nxt;     for (x = l;; x = nxt) {       nxt = (x << 1) - (x & (x - 1));       if (nxt > r) break;       res = max(res, L[x]);     }     res = max(res, A[x]);     for (x = r;; x = nxt) {       nxt = (x & (x - 1));       if (nxt < l) break;       res = max(res, R[x]);     }     res = max(res, A[x]);     return res;   }   void mdf(int i, int v) {     A[i] = max(A[i], v);     for (int x = i; x <= T; x = (x << 1) - (x & (x - 1))) R[x] = max(R[x], v);     for (int x = i; x > 0; x &= x - 1) L[x] = max(L[x], v);   }   void printans(int i) {     for (cnt = x = 0; x < i; x++) {       y = (seg[x] >> 20) & MSK;       if (t[seg[x] & MSK] + d[y] < q.top()) ++cnt;     }     printf( %I64d %d n , q.top(), cnt);   }   bool cmp(long long x, long long y) {     if ((y >> 40) == 0) return false;     if ((x >> 40) == 0) return true;     return t[x >> 40] + d[(x >> 20) & MSK] < t[y >> 40] + d[(y >> 20) & MSK];   }   int main() {     scanf( %d%d , &n, &m);     for (i = 1; i < n; i++) {       scanf( %d%d%d , &x, &y, &z);       g[x].push_back(y);       f[x].push_back(z);     }     for (i = 1; i <= n; i++) ch[i] = int(g[i].size()) - 1;     dfs(1, 0);     for (x = 1; x < 18; x++)       for (i = 1; i <= T; i++) {         a[x][i] = a[x - 1][i];         y = i + (1 << (x - 1));         if (y <= T && d[a[x - 1][y]] < d[a[x][i]]) a[x][i] = a[x - 1][y];       }     for (x = 1, y = -1, i = 1; i <= T; i++) {       if (i == x) {         x *= 2;         y++;       }       npw[i] = y;     }     for (i = 1; i <= m; i++) {       scanf( %d%d , &s[i], &t[i]);       pos = fi[s[i]];       for (j = 1; j != s[i]; j = y) {         z = fndmax(fi[j] + 1, lst[j]);         if (z != 0) {           j = lca(fi[s[z]], pos);           if (j == s[i]) break;         }         y = g[j][ch[j]];         z = fndmax(fi[y], lst[y]);         if (pos < fi[y] || pos > lst[y]) {           le = 0;           ri = int(g[j].size()) - 1;           while (le < ri) {             h = (le + ri) / 2;             if (lst[g[j][h]] < pos)               le = h + 1;             else               ri = h;           }           seg[cnt++] = ((((1LL * z) << 20) ^ j) << 20) ^ i;           y = g[j][ch[j] = ri];         }       }       mdf(pos, i);     }     sort(seg, seg + cnt, cmp);     for (j = i = 0; i < cnt; i++) {       z = (seg[i] >> 40);       y = (seg[i] >> 20) & MSK;       sf = z ? t[z] + d[y] + 1 : 1;       for (; j < sf && !q.empty(); j++) {         if (q.top() < j) {           printans(i);           return 0;         }         q.pop();       }       j = sf;       q.push(t[seg[i] & MSK] + d[y]);     }     while (!q.empty()) {       if (q.top() < j) {         printans(cnt);         return 0;       }       q.pop();       j++;     }     printf( -1 %d n , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long ans = 0;     for (int i = (0); i < (n); ++i) {       long long t, T, x, cost;       cin >> t >> T >> x >> cost;       if (t >= T) {         ans += cost + m * x;         continue;       }       long long aux1 = cost;       if (m > (T - t)) aux1 += m * x;       long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1;       aux2 *= cost;       ans += min(aux1, aux2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   namespace std {   long long abs(long long x) { return x < 0 ? -x : x; }   }  // namespace std   using namespace std;   void dprintf(char* format, ...) {     fprintf(stderr,  DEBUG:  );     va_list argp;     va_start(argp, format);     vfprintf(stderr, format, argp);     va_end(argp);     fprintf(stderr,   n );   }   struct Exception {     const char* message;     const int line;     Exception(const char* m, int l) : message(m), line(l) {}   };   static char stringReader[2097152];   static inline bool ReadLine() {     char* ptr = fgets(stringReader, sizeof(stringReader), stdin);     if (ptr == 0) return false;     int N = strlen(stringReader);     if (stringReader[N - 1] ==   n ) stringReader[N - 1] = 0;     return true;   }   const long long ooLL = 0x3f3f3f3f3f3f3f3fLL;   const int oo = 0x3f3f3f3f;   const double eps = 1e-9;   int main() {     try {       int N;       scanf( %d , &N);       int nt = 0;       int sol = oo;       vector<int> cnt(2 * N + 1, 0);       char t[1024];       scanf( %s , t);       for (int i = 0; i < N; ++i) {         if (t[i] ==  T ) {           ++nt;           cnt[i + 1] = cnt[i + N + 1] = 1;         }       }       for (int i = 1; i <= 2 * N; ++i) {         cnt[i] += cnt[i - 1];       }       int nh = N - nt;       for (int i = 1; i <= N; ++i) {         int have = cnt[i + nt - 1] - cnt[i - 1];         sol = min(sol, nt - have);       }       printf( %d n , sol);       return 0;     } catch (const Exception& exception) {       fprintf(stderr,  ****************************** n );       fprintf(stderr,  ERROR.%d: %s n , exception.line, exception.message);       fprintf(stderr,  ****************************** n );       throw exception;     }   }


#include <bits/stdc++.h>   using namespace std;   int arr[200000 + 10];   int arr2[200000 + 10];   int main() {     int n, num1 = 0, num2 = 0, tem1, l1 = 0, l2 = 0, num = 0;     long long ans = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> tem1;       if (tem1 == 0) {         ans += num;       } else         num++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     char T;     string a[100];     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < a[i].size(); j++) {         if (i % 2 == 0) {           if (j % 2 == 0) {             T =  B ;           } else {             T =  W ;           }         } else {           if (j % 2 == 0) {             T =  W ;           } else {             T =  B ;           }         }         if (a[i][j] ==  . ) {           a[i][j] = T;         } else {           a[i][j] =  - ;         }       }     }     for (int i = 0; i < n; i++) {       cout << a[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, l, c, d, p, nl, np, a, b, f, mina;     cin >> n >> k >> l >> c >> d >> p >> nl >> np;     a = (l * k) / nl;     b = (c * d);     f = p / np;     if (a < b)       mina = a;     else       mina = b;     if (mina > f) mina = f;     cout << (mina / n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[10];   int n;   int cnt[10], sump;   vector<long long> tree;   int rec(int cur, int trees, int treessum) {     if (cur > n) return treessum + (trees > 1) + n - sump;     int ans = (int)1e9;     for (int i = 0; i < tree.size(); ++i)       if (tree[i] % a[cur] == 0) {         tree[i] /= a[cur];         tree.push_back(a[cur]);         ans = min(ans, rec(cur + 1, trees + (!i), treessum + (!i) * cnt[cur]));         tree[i] *= a[cur];         tree.pop_back();       }     return ans;   }   bool cmp(long long a, long long b) { return a > b; }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %I64d , a + i);     sort(a + 1, a + 1 + n, cmp);     for (int i = 1; i <= n; ++i) {       long long x = a[i];       for (int j = 2; 1ll * j * j <= x; ++j)         while (x % j == 0) {           ++cnt[i];           x /= j;         }       if (x > 1) ++cnt[i];       if (cnt[i] == 1) ++sump;     }     tree.push_back(0);     printf( %d n , rec(1, 0, 0));     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:10000000000 )   #pragma GCC optimize( O3 )   using namespace std;   const int MOD = 1000000007;   const int INF = 1000000007LL;   const long long INF2 = 1LL << 62LL;   const long double EPS = 1e-9;   const int SIZE = 200010;   mt19937 rng(time(0));   uniform_int_distribution<int> uid(-1000000000, 1000000000);   int flag, u[SIZE], d[SIZE], a[SIZE], n;   int rec(int i) {     if (i == n - 1) return 1;     if (u[i] == flag) return d[i];     u[i] = flag;     if (a[i] == 1) {       return d[i] = !rec(i + 1);     }     return d[i] = 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tt;     cin >> tt;     for (int rep_iter = 0; rep_iter < tt; ++rep_iter) {       int n;       cin >> n;       string a, b;       cin >> a >> b;       int l = 0, r = n - 1, inv = 0;       for (auto& i : a) i -=  0 ;       for (auto& i : b) i -=  0 ;       vector<int> ans;       for (int len = n; len >= 1; --len) {         if ((a[r] ^ inv) != b[len - 1]) {           if ((a[l] ^ inv) == b[len - 1]) {             ans.push_back(1);             a[l] = !a[l];           }           ans.push_back(len);           inv = !inv;           swap(r, l);         }         if (r >= l)           --r;         else           ++r;       }       cout << ans.size() <<    ;       for (auto& i : ans) cout << i <<    ;       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);     int n, m;     cin >> n >> m;     int A[n][m], row[n], col[m];     char c;     memset(row, 0, sizeof(row));     memset(col, 0, sizeof(col));     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cin >> c;         if (c ==  . )           A[i][j] = 0;         else           A[i][j] = 1;       }     }     for (int i = 0; i < n; ++i) {       if (row[i] == 0) {         for (int j = 0; j < m; ++j) {           if (A[i][j] == 1 && col[j]) {             cout <<  No  << endl;             return 0;           }         }         vector<int> X;         for (int j = i + 1; j < n; ++j) {           int ans = 1;           if (row[j]) continue;           for (int k = 0; k < m; ++k) {             if (A[i][k] != A[j][k]) {               ans = 0;               break;             }           }           if (ans == 1) X.push_back(j);         }         for (int j = 0; j < X.size(); ++j) row[X[j]] = 1;         for (int j = 0; j < m; ++j)           if (A[i][j]) col[j] = 1;       }     }     cout <<  Yes  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100007;   int n, m, q[N], a[N], mn = 100000007, k, l;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> m;     for (int i = 0; i < m; i++) {       cin >> q[i];       mn = min(mn, q[i]);     }     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     for (int i = n - 1; i >= 0; i--) {       k += a[i];       l++;       if (l == mn) {         l = 0;         if (i == 1)           i--;         else if (i >= 2)           i -= 2;       }     }     cout << k;     return 0;   }


#include <bits/stdc++.h>   int D[61];   int main() {     int i, j, k, cnt;     for (i = 0; i <= 60; i++) {       cnt = 0;       for (j = 1, k = i; k > 0; j++, k -= j) cnt++;       D[i] = cnt;     }     int n, x, p = 0;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &x);       p ^= D[x];     }     printf( %s n , p == 0 ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool win(long long a, long long b) {     if (a > b) swap(a, b);     if (a == 0) return false;     if (!win(b % a, a)) return true;     long long df = b - b % a;     if (a % 2)       return df % 2 == 0;     else       return df / a % (a + 1) % 2 == 0;   }   void solve() {     long long a, b;     cin >> a >> b;     if (win(a, b))       cout <<  First  << endl;     else       cout <<  Second  << endl;   }   int main() {     ios_base::sync_with_stdio(0);     int T;     cin >> T;     for (int _ = 0; _ < (int)(T); _++) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a;     cin >> n;     int hasil[101] = {0};     for (int i = 1; i <= n; i++) {       cin >> a;       if (a / 2 != 1) {         while (a % 2 != 0) {           a++;           hasil[i]++;         }       } else {         a++;         hasil[i]++;         while (a % 2 != 0) {           a++;           hasil[i]++;         }       }     }     for (int i = 1; i <= n; i++) {       cout << hasil[i] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   int n;   char s[N];   struct SuffixAutomaton {     struct node {       int ch[26], par;       int len;     } t[N << 1];     int root, tail, cnt;     inline int newnode(int len) {       t[++cnt].len = len;       return cnt;     }     inline void init() { root = tail = newnode(0); }     inline int extend(int c) {       int p = tail, np = newnode(t[tail].len + 1);       for (; p && !t[p].ch[c]; p = t[p].par) t[p].ch[c] = np;       if (!p)         t[np].par = root;       else if (t[t[p].ch[c]].len == t[p].len + 1)         t[np].par = t[p].ch[c];       else {         int q = t[p].ch[c], nq = newnode(t[p].len + 1);         memcpy(t[nq].ch, t[q].ch, sizeof(t[nq].ch));         t[nq].par = t[q].par;         t[np].par = t[q].par = nq;         for (; p && t[p].ch[c] == q; p = t[p].par) t[p].ch[c] = nq;       }       return tail = np;     }   } SAM;   int id[N];   namespace tree {   int hed[N << 1], to[N << 1], nxt[N << 1], fa[N << 1], cnt, anc[N << 1][20];   int fromlen[N << 1];   inline void adde(int u, int v) {     ++cnt;     to[cnt] = v, nxt[cnt] = hed[u];     hed[u] = cnt;   }   vector<pair<int, int> > tags[N << 1];   inline void dfs(int x, int pre) {     fa[x] = pre;     anc[x][0] = fa[x];     fromlen[x] = SAM.t[SAM.t[x].par].len + 1;     if (x == 1) fromlen[x] = 0;     for (int i = 1; i < 20; i++) anc[x][i] = anc[anc[x][i - 1]][i - 1];     for (int i = hed[x]; i; i = nxt[i]) {       int v = to[i];       dfs(v, x);     }   }   inline void pushtag(int x, int id, int f) {     int pos = x;     for (int i = 19; ~i; i--) {       if (SAM.t[anc[pos][i]].len > f) pos = anc[pos][i];     }     while (tags[pos].size() == 0 || tags[pos].back().first <= f) {       if (tags[pos].size() != 0 && tags[pos].back().first == SAM.t[pos].len)         break;       tags[pos].push_back(pair<int, int>(min(SAM.t[pos].len, f), id));       pos = fa[pos];     }   }   inline int find(int x, int id) {     int pos = x;     for (int i = 19; ~i; i--) {       int nxtpos = anc[pos][i];       if (!nxtpos) continue;       if (tags[nxtpos].size() == 0)         pos = nxtpos;       else {         if (fromlen[nxtpos] + tags[nxtpos][0].second > id) {           pos = nxtpos;         }       }     }     pos = fa[pos];     if (!pos) return 0;     int l = 0, r = (int)tags[pos].size() - 1;     while (l < r) {       int mid = (l + r + 1) >> 1;       int stlen = (mid == 0 ? fromlen[pos] : tags[pos][mid - 1].first + 1);       if (stlen + tags[pos][mid].second <= id)         l = mid;       else         r = mid - 1;     }     int finalend = min(tags[pos][l].first, id - tags[pos][l].second);     return finalend;   }   }  // namespace tree   int f[N];   int main() {     SAM.init();     cin >> n;     scanf( %s , s + 1);     reverse(s + 1, s + n + 1);     for (int i = 1; i <= n; ++i) id[i] = SAM.extend(s[i] -  a );     for (int i = 1; i <= SAM.cnt; i++)       if (SAM.t[i].par) tree::adde(SAM.t[i].par, i);     tree::dfs(1, 0);     int ans = 0;     for (int i = 1; i <= n; i++) {       f[i] = max(f[i], tree::find(id[i], i - 1) + 1);       if (i < n) f[i + 1] = max(f[i + 1], tree::find(id[i], i) + 1);       ans = max(ans, f[i]);       tree::pushtag(id[i], i, f[i]);     }     cout << ans << endl;   }


#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 = 4000001;   const int INF = 1000000000;   int n, r;   vector<pair<int, int> > xy;   struct Tree {     vector<long long> lazy;     vector<long long> t;     Tree(int n) {       t.resize(4 * n);       lazy.resize(4 * n, 0);     }     void push(int v, int tl, int tr) {       t[v] += lazy[v];       if (tl != tr) {         lazy[2 * v] += lazy[v];         lazy[2 * v + 1] += lazy[v];       }       lazy[v] = 0;     }     void update(int v, int tl, int tr, int l, int r, int x) {       push(v, tl, tr);       if (l == tl && r == tr) {         lazy[v] += x;         push(v, tl, tr);         return;       }       int tm = (tl + tr) / 2;       if (r <= tm) {         update(2 * v, tl, tm, l, r, x);         push(2 * v + 1, tm + 1, tr);       } else if (l > tm) {         update(2 * v + 1, tm + 1, tr, l, r, x);         push(2 * v, tl, tm);       } else {         update(2 * v, tl, tm, l, tm, x);         update(2 * v + 1, tm + 1, tr, tm + 1, r, x);       }       t[v] = max(t[2 * v], t[2 * v + 1]);     }     long long mx(int v, int tl, int tr, int l, int r) {       push(v, tl, tr);       if (l == tl && r == tr) {         return t[v];       }       int tm = (tl + tr) / 2;       if (r <= tm)         return mx(2 * v, tl, tm, l, r);       else if (l > tm)         return mx(2 * v + 1, tm + 1, tr, l, r);       else {         return max(mx(2 * v, tl, tm, l, tm),                    mx(2 * v + 1, tm + 1, tr, tm + 1, r));       }     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.setf(ios::fixed);     cout.precision(20);     cin >> n >> r;     xy.resize(n);     int mn = 1e9;     for (int(i) = 0; (i) < n; (i)++) {       int x, y;       cin >> x >> y;       xy[i].first = x + y;       xy[i].second = x - y;       mn = min(mn, xy[i].second);     }     for (int(i) = 0; (i) < n; (i)++) {       xy[i].second -= mn;     }     sort((xy).begin(), (xy).end());     int itl = 0, itr = 0;     r *= 2;     long long ans = 0;     Tree t(MAXN);     while (itl != n) {       if (itr < n && xy[itr].first - xy[itl].first <= r) {         t.update(1, 0, MAXN - 1, max(0, xy[itr].second - r), xy[itr].second, 1);         ans = max(ans, t.mx(1, 0, MAXN - 1, 0, MAXN - 1));         itr++;       } else {         t.update(1, 0, MAXN - 1, max(0, xy[itl].second - r), xy[itl].second, -1);         itl++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     long long ans = 0;     char last =    , ch = getchar();     while (ch <  0  || ch >  9 ) last = ch, ch = getchar();     while (ch >=  0  && ch <=  9 ) ans = ans * 10 + ch -  0 , ch = getchar();     if (last ==  - ) ans = -ans;     return ans;   }   const int N = 2e5 + 5;   int n;   long long k, sum, tmp, suf[N], a[N], c, ans;   long long accCeil(long long a, long long b) {     long long res = a / b;     if (res * b < a) res++;     return res;   }   int main() {     int T = read();     while (T--) {       n = read(), k = read();       sum = 0;       for (int i = 1; i <= n; ++i) {         a[i] = read();         sum += a[i];       }       if (sum <= k) {         printf( 0 n );         continue;       }       if (n == 1) {         printf( %lld n , sum - k);         continue;       }       sort(a + 1, a + n + 1);       suf[n + 1] = 0;       ans = 1e18;       for (int i = n; i > 1; --i) {         suf[i] = suf[i + 1] + a[i];         tmp = sum - k - suf[i] + (n - i + 1) * a[1];         c = max(accCeil(tmp, n - i + 2), 0ll);         ans = min(ans, n - i + 1 + c);       }       printf( %lld n , min(ans, sum - k));     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int x, y, n;     int k, i, t;     scanf( %d , &t);     for (i = 0; i < t; i++) {       scanf( %d %d %d , &x, &y, &n);       if (n - n % x + y <= n) {         k = n - n % x + y;       } else {         k = n - n % x - (x - y);       }       printf( %d n , k);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(string s) {     for (int i = 0; i < s.size() - 1; i++) {       if (s[i] == s[i + 1]) return false;     }     return true;   }   void solve() {     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  ?  && i != 0 && i != s.size() - 1) {         if (s[i - 1] ==  a  && s[i + 1] ==  c  ||             s[i - 1] ==  c  && s[i + 1] ==  a )           s[i] =  b ;         else if (s[i - 1] ==  a  && s[i + 1] ==  b  ||                  s[i - 1] ==  b  && s[i + 1] ==  a )           s[i] =  c ;         else if (s[i - 1] ==  b  && s[i + 1] ==  c  ||                  s[i - 1] ==  c  && s[i + 1] ==  b )           s[i] =  a ;         else if (s[i - 1] ==  a )           s[i] =  b ;         else if (s[i - 1] ==  b )           s[i] =  c ;         else if (s[i - 1] ==  c )           s[i] =  a ;       } else if (s[i] ==  ?  && i == 0) {         if (s[i + 1] ==  a )           s[i] =  b ;         else if (s[i + 1] ==  b )           s[i] =  c ;         else if (s[i + 1] ==  c )           s[i] =  a ;         else           s[i] =  a ;       } else if (s[i] ==  ?  && i == s.size() - 1) {         if (s[i - 1] ==  a )           s[i] =  b ;         else if (s[i - 1] ==  b )           s[i] =  c ;         else if (s[i - 1] ==  c )           s[i] =  a ;         else           s[i] =  a ;       }     }     if (check(s)) {       cout << s << endl;     } else       cout << -1 << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[555][555];   char ans[555];   void die() {     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         if (i != j) {           if (abs(ans[i] - ans[j]) <= 1 && !a[i][j]) {             cout <<  No n ;             exit(0);           }           if (abs(ans[i] - ans[j]) > 1 && a[i][j]) {             cout <<  No n ;             exit(0);           }         }       }     }     cout <<  Yes n ;     ans[n] = 0;     cout << ans << endl;     exit(0);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; ++i) {       int first, second;       scanf( %d%d , &first, &second);       --first;       --second;       a[first][second] = a[second][first] = 1;     }     int A = -1, B = -1, C = -1;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         for (int k = 0; k < n; ++k) {           if (i == j || j == k) {             continue;           }           if (a[i][j] && a[i][k]) {             if (!a[j][k]) {               A = j;               B = i;               C = k;             }           }         }       }     }     if (A == -1) {       ans[0] =  a ;       for (int i = 1; i < n; ++i) {         if (a[0][i]) {           ans[i] =  a ;         } else {           ans[i] =  c ;         }       }       die();     }     ans[B] =  b ;     ans[A] =  a ;     ans[C] =  c ;     for (int i = 0; i < n; ++i) {       if (i == A || i == B || i == C) continue;       if (a[A][i] && a[B][i] && a[C][i])         ans[i] =  b ;       else if (a[A][i] && a[B][i])         ans[i] =  a ;       else         ans[i] =  c ;     }     die();   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   typedef int ll;   const ll MAX = 1e3;   const ll mod = 1e4;   const ll inf = 1e9;   struct FlowEdge {     int v, u;     int cap, flow = 0;     FlowEdge(int v, int u, int cap) : v(v), u(u), cap(cap) {}   };   struct Dinic {     const int flow_inf = 1e9;     vector<FlowEdge> edges;     vector<vector<int>> adj;     int n, m = 0;     int s, t;     vector<int> level, ptr;     queue<int> q;     Dinic(int n, int s, int t) : n(n), s(s), t(t) {       adj.resize(n);       level.resize(n);       ptr.resize(n);     }     void add_edge(int v, int u, int cap) {       edges.emplace_back(v, u, cap);       edges.emplace_back(u, v, 0);       adj[v].push_back(m);       adj[u].push_back(m + 1);       m += 2;     }     bool bfs() {       while (!q.empty()) {         int v = q.front();         q.pop();         for (int id : adj[v]) {           if (edges[id].cap - edges[id].flow < 1) continue;           if (level[edges[id].u] != -1) continue;           level[edges[id].u] = level[v] + 1;           q.push(edges[id].u);         }       }       return level[t] != -1;     }     int dfs(int v, int pushed) {       if (pushed == 0) return 0;       if (v == t) return pushed;       for (int& cid = ptr[v]; cid < (int)adj[v].size(); cid++) {         int id = adj[v][cid];         int u = edges[id].u;         if (level[v] + 1 != level[u] || edges[id].cap - edges[id].flow < 1)           continue;         int tr = dfs(u, min(pushed, edges[id].cap - edges[id].flow));         if (tr == 0) continue;         edges[id].flow += tr;         edges[id ^ 1].flow -= tr;         return tr;       }       return 0;     }     int flow() {       int f = 0;       while (true) {         fill(level.begin(), level.end(), -1);         level[s] = 0;         q.push(s);         if (!bfs()) break;         fill(ptr.begin(), ptr.end(), 0);         while (int pushed = dfs(s, flow_inf)) {           f += pushed;         }       }       return f;     }   };   int c[MAX], ans[MAX];   vector<ll> adj[MAX];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int tc, n, m, k, s, t, u, v;     cin >> tc;     while (tc--) {       cin >> n >> m >> k;       s = 0, t = n + m + 1;       Dinic dinic(n + m + 2, s, t);       for (ll i = 1; i < (ll)m + 1; i++) {         cin >> u >> v;         c[u]++, c[v]++;         dinic.add_edge(n + i, t, 1);         dinic.add_edge(u, n + i, 1);         dinic.add_edge(v, n + i, 1);       }       int to = 0;       for (ll i = 1; i < (ll)n + 1; i++)         if (c[i] > k) dinic.add_edge(s, i, 2 * (c[i] - k)), to += 2 * (c[i] - k);       if (dinic.flow() == to) {         for (FlowEdge it : dinic.edges) {           if (1 <= it.v && it.v <= n && n + 1 <= it.u && it.u <= n + m &&               it.flow == 1) {             adj[it.v].push_back(it.u - n);           }         }         ll col = 1;         for (ll i = 1; i < (ll)n + 1; i++) {           for (ll j = 0; j < (ll)adj[i].size(); j += 2)             ans[adj[i][j]] = ans[adj[i][j + 1]] = col++;         }         for (ll i = 1; i < (ll)m + 1; i++)           if (ans[i] == 0) ans[i] = col++;       }       for (ll i = 1; i < (ll)m + 1; i++) cout << ans[i] <<    , ans[i] = 0;       cout << endl;       for (ll i = 1; i < (ll)n + 1; i++) adj[i].clear(), c[i] = 0;     }     return 0;   }


#pragma GCC optimize( Ofast )   #include<bits/stdc++.h>   #define int long long   using namespace std;   void fileio(const string &s)   {    freopen((s+ .in ).c_str(), r ,stdin);    freopen((s+ .out ).c_str(), w ,stdout);   }   const int INF=4e18;   inline int read()   {    int x=0;    bool flag=1;    char c=getchar();    while(c< 0 ||c> 9 )    {     if(c== - )      flag=0;     c=getchar();    }    while(c>= 0 &&c<= 9 )    {     x=(x<<1)+(x<<3)+c- 0 ;     c=getchar();    }    return (flag?x:~(x-1));   }   int t,tx,ty,ax,ay,bx,by;    void solve()   {    ax=read();    ay=read();    bx=read();    by=read();    int ans=abs(ax-bx)+abs(ay-by);    tx=read();    ty=read();    if(tx==ax&&tx==bx)    {     if(ay<ty&&ty<by)      ans+=2;     if(ay>ty&&ty>by)      ans+=2;    }    if(ty==ay&&ty==by)    {     if(ax<tx&&tx<bx)      ans+=2;     if(ax>tx&&tx>bx)      ans+=2;    }    cout<<ans<<endl;   }   signed main()   {    t=read();    while(t--)     solve();    return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   long long n, a[100007], x, ans, t, res, tmp;   vector<long long> v, cur;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (long int i = 0; i < n; i++) {       cin >> x;       if (x) v.push_back(i);     }     if (v.size() < 2) {       cout << -1;       return 0;     }     if (v.size() < 4) {       if (v.size() == 2)         cout << v[1] - v[0];       else         cout << v[2] - v[0];       return 0;     }     ans = 1e12;     for (long int i = 2; i * i <= v.size(); i++) {       if (v.size() % i != 0) continue;       tmp = i;       for (long int k = 0; k < 2; k++, i = v.size() / i) {         t = 0;         res = 0;         for (auto j : v) {           cur.push_back(j);           t++;           if (t % i == 0) {             t = 0;             for (auto h : cur) res += abs(cur[i / 2] - h);             cur.clear();           }         }         ans = min(ans, res);       }       i = tmp;     }     res = 0;     for (auto i : v) {       res += abs(i - v[v.size() / 2]);     }     cout << min(res, ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     vector<int> a;     for (int i = 1; i <= n; i++)       if (n % i == 0) a.push_back(i);     for (int i = 1; i < a.size(); i++) {       for (int j = 0; j < a[i] / 2; j++) swap(s[j], s[a[i] - j - 1]);     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int key;     vector<int> v;     for (int i = 0; i < n; ++i) {       cin >> key;       v.push_back(key);     }     int max = v[0];     int min = v[0];     int amz = 0;     for (int i = 1; i < n; ++i) {       if (v[i] > max) {         amz++;         max = v[i];       }       if (v[i] < min) {         amz++;         min = v[i];       }     }     cout << amz;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int n;       cin >> n;       vector<int> p(n), result;       for (int& j : p) {         cin >> j;       }       vector<int> maximums;       vector<bool> used(n, false);       result.push_back(p[0]);       used[p[0] - 1] = true;       int idx = 0;       for (idx; idx < p[0] - 1; idx++) {         maximums.push_back(idx + 1);       }       idx++;       for (int j = 1; j < n; j++) {         if (p[j] > p[j - 1]) {           result.push_back(p[j]);           used[p[j] - 1] = true;           for (idx; idx < p[j] - 1; idx++) {             if (!used[idx]) maximums.push_back(idx + 1);           }           idx++;         } else {           if (maximums.size() > 0) {             used[maximums[maximums.size() - 1] - 1] = true;             result.push_back(maximums[maximums.size() - 1]);             maximums.pop_back();           }         }       }       if (result.size() < n)         cout << -1 << endl;       else {         for (int& i : result) {           cout << i <<    ;         }         cout << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int mat[105][105];   int nodes[105];   int n, m;   int cycles = 0;   void cycle_det(int cur, int parent);   int main() {     cin >> n >> m;     memset(mat, 0, sizeof mat);     memset(nodes, 0, sizeof nodes);     for (int i = 0; i < m; i++) {       int _1, _2;       cin >> _1 >> _2;       mat[_1 - 1][_2 - 1] = 1;       mat[_2 - 1][_1 - 1] = 1;     }     cycle_det(0, -1);     int count = 0;     for (int i = 0; i < n; i++)       if (nodes[i] == 1) count++;     if (cycles != 2 || count != n)       cout <<  NO n ;     else       cout <<  FHTAGN! n ;   }   void cycle_det(int cur, int parent) {     if (cycles > 2) return;     nodes[cur] = 1;     for (int i = 0; i < n; i++) {       int tmp = 0;       if (mat[cur][i] == 1 && !nodes[i]) {         nodes[i] = 1;         cycle_det(i, cur);       } else if (mat[cur][i] == 1 && i != parent && nodes[i]) {         cycles++;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int MAXN = 1e6 + 7;   const double EPS = 1e-8;   long long power(long long a, long long k) {     if (!k) {       return 1;     }     long long b = power(a, k / 2);     b = b * b % INF;     if (k % 2) {       return a * b % INF;     } else {       return b;     }   }   vector<vector<long long> > gr;   vector<long long> p, r;   long long all_sz = 0;   long long get(long long v) { return (p[v] == v ? v : p[v] = get(p[v])); }   bool uni(long long v, long long u) {     v = p[v];     u = p[u];     if (v == u) {       return false;     }     if (r[v] == r[u]) {       r[u]++;     }     if (r[v] > r[u]) {       swap(v, u);     }     p[v] = u;     all_sz--;     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m, k;     cin >> n >> m >> k;     p.resize(n, 0);     iota(p.begin(), p.end(), 0);     r.resize(n, 0);     vector<long long> c(n);     for (long long i = 0; i < n; i++) {       cin >> c[i];     }     long long all = power(2, n + k);     gr.resize(n);     map<long long, vector<pair<long long, long long> > > d;     for (long long i = 0; i < m; i++) {       long long v, u;       cin >> v >> u;       v--, u--;       d[c[v] ^ c[u]].push_back({v, u});     }     long long bad = 0;     for (auto pt : d) {       all_sz = n;       set<long long> used;       for (auto t : pt.second) {         long long v = t.first, u = t.second;         used.insert(v);         used.insert(u);         if (get(v) == get(u)) continue;         bad = (bad + power(2, all_sz - 1)) % INF;         uni(v, u);       }       for (long long v : used) {         p[v] = v;         r[v] = 0;       }     }     cout << (all - bad + INF) % INF;   }


#include <bits/stdc++.h>   using namespace std;   long double pi = 3.141592653589793238;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long t;     cin >> t;     while (t--) {       string x;       cin >> x;       long long n = x.length();       if (n == 0) {         cout << 0 << endl;       }       if (n == 1) {         cout << 5 << endl;         continue;       }       set<tuple<long long, long long, long long, long long>> r1;       long long curx = 0;       long long cury = 0;       long long cnt = 5;       if (x[0] ==  N ) {         cury++;         r1.insert(make_tuple(curx, cury - 1, curx, cury));         r1.insert(make_tuple(curx, cury, curx, cury - 1));       }       if (x[0] ==  S ) {         cury--;         r1.insert(make_tuple(curx, cury + 1, curx, cury));         r1.insert(make_tuple(curx, cury, curx, cury + 1));       }       if (x[0] ==  E ) {         curx++;         r1.insert(make_tuple(curx - 1, cury, curx, cury));         r1.insert(make_tuple(curx, cury, curx - 1, cury));       }       if (x[0] ==  W ) {         curx--;         r1.insert(make_tuple(curx + 1, cury, curx, cury));         r1.insert(make_tuple(curx, cury, curx + 1, cury));       }       for (long long i = 1; i < n; i++) {         if (x[i] ==  N ) {           cury++;           if (r1.find(make_tuple(curx, cury - 1, curx, cury)) == r1.end()) {             r1.insert(make_tuple(curx, cury - 1, curx, cury));             cnt += 5;             r1.insert(make_tuple(curx, cury, curx, cury - 1));           } else             cnt++;         }         if (x[i] ==  S ) {           cury--;           if (r1.find(make_tuple(curx, cury + 1, curx, cury)) == r1.end()) {             r1.insert(make_tuple(curx, cury + 1, curx, cury));             cnt += 5;             r1.insert(make_tuple(curx, cury, curx, cury + 1));           } else             cnt++;         }         if (x[i] ==  E ) {           curx++;           if (r1.find(make_tuple(curx - 1, cury, curx, cury)) == r1.end()) {             r1.insert(make_tuple(curx - 1, cury, curx, cury));             cnt += 5;             r1.insert(make_tuple(curx, cury, curx - 1, cury));           } else             cnt++;         }         if (x[i] ==  W ) {           curx--;           if (r1.find(make_tuple(curx + 1, cury, curx, cury)) == r1.end()) {             r1.insert(make_tuple(curx + 1, cury, curx, cury));             cnt += 5;             r1.insert(make_tuple(curx, cury, curx + 1, cury));           } else             cnt++;         }       }       cout << cnt << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e3 + 10;   long long n, k;   char s[MAXN];   int num[33];   int main() {     while (cin >> s) {       cin >> k;       int len = strlen(s);       if (len < k) {         cout <<  impossible  << endl;       } else {         memset(num, 0, sizeof num);         for (int i = 0; i < len; ++i) {           num[s[i] -  a ]++;         }         long long ans = 0;         for (int i = 0; i < 26; ++i) {           if (num[i]) ++ans;         }         if (ans <= k)           cout << k - ans << endl;         else           cout << 0 << endl;       }     }     return 0;   }


#include<bits/stdc++.h>      #define mamun()         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);   #define endl              n    #define tab               t    #define ll              long long   #define lli             long long int   #define pb              push_back   #define fin(file)       freopen(file .txt ,  r , stdin)   #define fout(file)      freopen(file .txt ,  w , stdout)   #define FOR(i, a, b)    for (int i=a; i<=b; i++)   #define loop(i, n)      for (int i=0; i<n; i++)   #define srt(v)          sort(v.begin(), v.end())   #define rsrt(v)         sort(v.rbegin(), v.rend())   #define Fill(ar, val)   memset(ar, val, sizeof(ar))   #define testcase()      ll t; cin>>t; while(t--)      using namespace std;      int main()   {       mamun();       //fin( input );          testcase()       {           ll n, Ecnt=0, Ocnt=0;           cin>> n;           vector<ll> v(2*n);              loop(i, 2*n) cin>> v[i];           // srt(v);              loop(i, 2*n)           {               if(v[i] % 2 == 0)               {                   Ecnt++;               }               else               {                   Ocnt++;               }           }           if(Ecnt == Ocnt)               cout<<  Yes  << endl;           else               cout<<  No  << endl;       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string ans, word;   vector<int> get_pi(string s) {     int j = 0, k = -1;     vector<int> q;     q.clear();     q.push_back(-1);     while (j < s.size()) {       if (k == -1 || s[j] == s[k]) {         q.push_back(++k);         ++j;       } else {         k = q[k];       }     }     return q;   }   int main() {     ios::sync_with_stdio(false);     ans =   ;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> word;       int l = min(word.size(), ans.size());       string s = word +  # ;       s.insert(s.end(), ans.end() - l, ans.end());       vector<int> pi = get_pi(s);       int move = pi[pi.size() - 1];       ans.insert(ans.end(), word.begin() + move, word.end());     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dcount(long long i) {     int c = 0;     while (i > 0) {       i = i / 10;       c++;     }     return c;   }   int main() {     long long n, cnt = 0;     cin >> n;     int num = dcount(n);     for (long long int i = 0; i < num; i++) {       cnt += n > (pow(10, i + 1) - 1) ? (pow(10, i + 1) - pow(10, i)) * (i + 1)                                       : (n - pow(10, i) + 1) * (i + 1);     }     cout << cnt;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int a = 1, b = 2;     while (n--) {       int c;       cin >> c;       if (c == a) {         b = 6 - (a + b);       } else if (c == b) {         a = 6 - (a + b);       } else {         cout <<  NO n ;         return 0;       }     }     cout <<  YES n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   long long a[N];   struct tr {     int l, r, maxi;   } t[N * 4];   int sign(long long x) {     if (x > 0) return 1;     if (x < 0) return -1;     return 0;   }   inline void cal(int cur, int l, int r) {     int m = (l + r) / 2;     int dcur = cur + cur, u = dcur, v = u + 1;     t[cur].maxi = max(t[u].maxi, t[v].maxi);     t[cur].l = t[u].l;     t[cur].r = t[v].r;     if ((!a[m] || !a[m + 1] || sign(a[m]) < sign(a[m + 1]))) {     } else {       t[cur].maxi = max(t[cur].maxi, t[u].r + t[v].l);       if (t[u].maxi == m - l + 1) {         t[cur].l = t[u].l + t[v].l;       }       if (t[v].maxi == r - m) {         t[cur].r = t[v].r + t[u].r;       }     }   }   void build(int pos, int l, int r) {     if (l == r) {       int x = !!a[l];       t[pos].l = t[pos].r = t[pos].maxi = x;       return;     }     int mid = (l + r) >> 1;     build(pos * 2, l, mid);     build(pos * 2 + 1, mid + 1, r);     cal(pos, l, r);   }   void update(int pos, int l, int r, int k, int d) {     int mid = (l + r) >> 1;     if (l == r) {       a[l] += d;       int x = !!a[l];       t[pos].l = t[pos].r = t[pos].maxi = x;       return;     } else {       int mid = (l + r) >> 1;       if (k <= mid)         update(pos * 2, l, mid, k, d);       else         update(pos * 2 + 1, mid + 1, r, k, d);       cal(pos, l, r);     }   }   int main() {     int u, v, n, i, m, l, r, d;     cin >> n;     cin >> u;     for (i = 1; i < n; ++i) scanf( %d , &v), a[i - 1] = v - u, u = v;     if (n > 1) build(1, 0, n - 2);     cin >> m;     while (m--) {       scanf( %d%d%d , &l, &r, &u);       if (n == 1) {         printf( 1 n );       } else {         if (l > 1) update(1, 0, n - 2, l - 2, u);         if (r < n) update(1, 0, n - 2, r - 1, -u);         printf( %d n , t[1].maxi + 1);       }     }   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   map<long long, int> mp, mpp;   long long ans[200005];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       long long l, r;       cin >> l >> r;       if (!mpp[l]) {         v.push_back(l);         mpp[l] = 1;       }       if (!mpp[r + 1]) {         v.push_back(r + 1);         mpp[r + 1] = 1;       }       mp[l]++;       mp[r + 1]--;     }     sort(v.begin(), v.end());     long long prev = 0;     int active = 0;     for (int i = 0; i < v.size(); i++) {       ans[active] += v[i] - prev;       active += mp[v[i]];       prev = v[i];     }     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   inline void normal(long long int &a) {     a %= 1000000007;     (a < 0) && (a += 1000000007);   }   inline long long int modMul(long long int a, long long int b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     return (a * b) % 1000000007;   }   inline long long int modAdd(long long int a, long long int b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     return (a + b) % 1000000007;   }   inline long long int modSub(long long int a, long long int b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     a -= b;     normal(a);     return a;   }   inline long long int modPow(long long int b, long long int p) {     long long int r = 1;     while (p) {       if (p & 1) r = modMul(r, b);       b = modMul(b, b);       p >>= 1;     }     return r;   }   inline long long int modInverse(long long int a) {     return modPow(a, 1000000007 - 2);   }   inline long long int modDiv(long long int a, long long int b) {     return modMul(a, modInverse(b));   }   inline bool isInside(pair<int, int> p, long long int n, long long int m) {     return (p.first >= 0 && p.first < n && p.second >= 0 && p.second < m);   }   inline bool isInside(pair<int, int> p, long long int n) {     return (p.first >= 0 && p.first < n && p.second >= 0 && p.second < n);   }   inline bool isSquare(long long int x) {     long long int s = sqrt(x);     return (s * s == x);   }   inline bool isFib(long long int x) {     return isSquare(5 * x * x + 4) || isSquare(5 * x * x - 4);   }   inline bool isPowerOfTwo(long long int x) {     return ((1LL << (long long int)log2(x)) == x);   }   template <typename first, typename second>   ostream &operator<<(ostream &os, const pair<first, second> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  { ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  } ;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   template <typename first, typename second>   ostream &operator<<(ostream &os, const map<first, second> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << it->first <<   =   << it->second;     }     return os <<  ] ;   }   clock_t tStart = clock();   void faltu() { cerr << endl; }   template <typename T>   void faltu(T a[], int n) {     for (int i = 0; i < n; ++i) cerr << a[i] <<    ;     cerr << endl;   }   template <typename T, typename... hello>   void faltu(T arg, const hello &...rest) {     cerr << arg <<    ;     faltu(rest...);   }   struct func {     bool operator()(pair<int, int> const &a, pair<int, int> const &b) {       if (a.first == b.first) return (a.second < b.second);       return (a.first < b.first);     }   };   const long long int INF = 0x3f3f3f3f3f3f3f3f;   const long double EPS = 1e-9;   const int inf = 0x3f3f3f3f;   const int mx = (int)1e5 + 9;   long long int n, m, a, b, t, i, j, d, cs = 0, counT = 0, k, ans = 0, l = 0,                                         sum1 = 0, sum = 0, Max, Min, num;   vector<long long int> vc;   map<long long int, long long int> mp;   int main() {     ios_base::sync_with_stdio(false);     ;     t = 1;     cin >> t;     while (t--) {       cin >> n;       for (i = n; i >= 1; i--) cout << i <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   int dp[550][550], A[550], B[550], path[550][550], n, m;   bool print(int x) {     if (!x) return false;     if (print(path[n][x]))       printf(  %d , B[x]);     else       printf( %d , B[x]);     return true;   }   int main() {     int i, j, tp, ans, pos;     while (~scanf( %d , &n)) {       for (i = 1; i <= n; i++) scanf( %d , &A[i]);       scanf( %d , &m);       for (i = 1; i <= m; i++) scanf( %d , &B[i]);       memset(dp, 0, sizeof dp);       for (i = 1; i <= n; i++) {         tp = pos = 0;         for (j = 1; j <= m; j++) {           dp[i][j] = dp[i - 1][j];           path[i][j] = path[i - 1][j];           if (A[i] == B[j] && tp + 1 > dp[i][j])             dp[i][j] = tp + 1, path[i][j] = pos;           if (B[j] < A[i] && dp[i - 1][j] > tp) tp = dp[i - 1][j], pos = j;         }       }       ans = 1;       for (i = 1; i <= m; i++)         if (dp[n][i] > dp[n][ans]) ans = i;       printf( %d n , dp[n][ans]);       if (dp[n][ans]) print(ans);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } debug;   template <typename T1, typename T2>   inline ostream& operator<<(ostream& os, const pair<T1, T2>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   inline ostream& operator<<(ostream& os, const vector<T>& v) {     bool first = true;     os <<  [ ;     for (typename vector<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {       if (!first) os <<  ,  ;       os << *ii;       first = false;     }     return os <<  ] ;   }   const int NN = (1 << 18);   int seg[NN], dp[NN];   int od[NN], ans[NN];   bool vowel(char ch) {     ch = tolower(ch);     if (ch ==  a  or ch ==  e  or ch ==  i  or ch ==  o  or ch ==  u )       return true;     return false;   }   bool cmp(int x, int y) {     if (dp[x] == dp[y]) return (x < y);     return (dp[x] < dp[y]);   }   void update(int i, int v) {     for (i += 5; i < NN; i += i & -i) seg[i] += v;   }   int findcum(int cum) {     int id = 0, bitmask = NN >> 1;     while (bitmask != 0) {       int tid = id + bitmask;       if (seg[tid] < cum) cum -= seg[tid], id = tid;       bitmask >>= 1;     }     return id + 1 - 5;   }   void solve() {     string msg;     cin >> msg;     int n = (int)msg.size();     dp[0] = od[0] = 0;     for (int i = 1; i <= n; ++i)       dp[i] = dp[i - 1] + ((vowel(msg[i - 1])) ? -1 : 2), od[i] = i;     sort(od, od + n + 1, cmp);     int res = numeric_limits<int>::min();     for (int i = 0; i <= n; ++i) {       update(od[i], 1);       int id = findcum(1);       if (id < od[i]) res = max(res, od[i] - id), ++ans[od[i] - id];     }     if (res <= 0)       puts( No solution );     else       cout << res <<     << ans[res] << endl;   }   int main() {     ios_base::sync_with_stdio(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const int MOD = INF + 7;   int memo[3000 + 1][100 + 1][100];   int N;   vector<int> a, b;   int solve(int len, int w, int nouse) {     if (len == 0) return 1;     if (len < 0) return 0;     if (memo[len][w][nouse] != -1) return memo[len][w][nouse];     int res = 0;     for (int i = 0; i < N; i++)       if (i != nouse) {         if (a[i] == w)           res = (res + solve(len - b[i], b[i], i)) % MOD;         else if (b[i] == w)           res = (res + solve(len - a[i], a[i], i)) % MOD;       }     memo[len][w][nouse] = res;     return res;   }   int main() {     ios_base::sync_with_stdio(false);     memset(memo, -1, sizeof(memo));     int l;     cin >> N >> l;     a.resize(N);     b.resize(N);     for (int i = 0, _n = N; i < _n; i++) {       cin >> a[i] >> b[i];     }     int res = 0;     for (int i = 0, _n = 100; i < _n; i++)       res = (res + solve(l, i + 1, -1)) % MOD;     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   void solve() {     long long n;     cin >> n;     string s;     cin >> s;     vector<long long> v(n);     for (long long i = 0; i <= n - 1; i++) cin >> v[i];     long long ans = mod;     for (long long i = 0; i <= n - 2; i++) {       if (s[i] ==  R  && s[i + 1] ==  L ) ans = min(ans, abs(v[i] - v[i + 1]));     }     if (ans == mod)       cout << -1;     else       cout << ans / 2;   }   int main() {     long long tc = 1;     while (tc--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int A[100000];   int main() {     int n;     cin >> n;     int sh = 0;     for (int i = 0; i < n - 1; i++) {       int a;       cin >> a;       A[i] = A[i] + a;       int k = n - i - 1;       int l = 1;       while (l <= k) {         if (l * 2 > k) {           break;         } else {           l = l * 2;         }       }       A[i + l] = A[i + l] + A[i];       sh = sh + A[i];       cout << sh <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const long long mod = 1e9 + 7;   const long long N = 1e5 + 10;   struct node {     int ind, type, row, color;     node(int a, int b, int c, int d) {       ind = a;       type = b;       row = c;       color = d;     }   };   bool comp(node x, node y) { return x.ind < y.ind; }   int main() {     ios::sync_with_stdio(false);     int n, m, k;     cin >> n >> m >> k;     vector<vector<int> > ans(n, vector<int>(m, 0));     vector<vector<pair<int, int> > > v(2, vector<pair<int, int> >(max(n, m)));     for (int i = 0; i < k; i++) {       int a, b, c;       cin >> a >> b >> c;       v[a - 1][b - 1] = make_pair(i, c);     }     vector<node> vec;     for (int i = 0; i < 2; i++)       for (int j = 0; j < max(n, m); j++)         if (v[i][j].second != 0)           vec.push_back(node(v[i][j].first, i, j, v[i][j].second));     sort(vec.begin(), vec.end(), comp);     for (int i = 0; i < vec.size(); i++) {       if (vec[i].type == 0) {         for (int j = 0; j < m; j++) ans[vec[i].row][j] = vec[i].color;       } else {         for (int j = 0; j < n; j++) ans[j][vec[i].row] = vec[i].color;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cout << ans[i][j] <<    ;       cout << endl;     }     return 0;   }


//I ll always miss you like a darling.   #include <bits/stdc++.h>   using namespace std;      #define LL long long   #define LD long double   #define ull unsigned long long   #define x first   #define y second   #define pb push_back   #define pf push_front   #define mp make_pair   #define Pair pair<int,int>   #define pLL pair<LL,LL>   #define pii pair<double,double>   #define LOWBIT(x) x & (-x)      #define rep(i,a,b) for (int i=a;i<=b;i++)   #define REP(i,a,b) for (int i=a;i>=b;i--)      const int INF=2e9;   const LL LINF=2e16;   const int magic=348;   const int MOD=1e9+7;   const double eps=1e-10;   const double pi=acos(-1);      struct fastio   {       static const int S=1e7;       char rbuf[S+48],wbuf[S+48];int rpos,wpos,len;       fastio() {rpos=len=wpos=0;}       inline char Getchar()       {           if (rpos==len) rpos=0,len=fread(rbuf,1,S,stdin);           if (!len) return EOF;           return rbuf[rpos++];       }       template <class T> inline void Get(T &x)       {           char ch;bool f;T res;           while (!isdigit(ch=Getchar()) && ch!= - ) {}           if (ch== - ) f=false,res=0; else f=true,res=ch- 0 ;           while (isdigit(ch=Getchar())) res=res*10+ch- 0 ;           x=(f?res:-res);       }       inline void getstring(char *s)       {           char ch;           while ((ch=Getchar())<=32) {}           for (;ch>32;ch=Getchar()) *s++=ch;           *s=  0 ;       }       inline void flush() {fwrite(wbuf,1,wpos,stdout);fflush(stdout);wpos=0;}       inline void Writechar(char ch)       {           if (wpos==S) flush();           wbuf[wpos++]=ch;       }       template <class T> inline void Print(T x,char ch)       {           char s[20];int pt=0;           if (x==0) s[++pt]= 0 ;           else           {               if (x<0) Writechar( - ),x=-x;               while (x) s[++pt]= 0 +x%10,x/=10;           }           while (pt) Writechar(s[pt--]);           Writechar(ch);       }       inline void printstring(char *s)       {           int pt=1;           while (s[pt]!=  0 ) Writechar(s[pt++]);       }   }io;      template<typename T> inline void check_max(T &x,T cmp) {x=max(x,cmp);}   template<typename T> inline void check_min(T &x,T cmp) {x=min(x,cmp);}   template<typename T> inline T myabs(T x) {return x>=0?x:-x;}   template<typename T> inline T mygcd(T x,T y) {return y==0?x:mygcd(y,x%y);}   inline int add(int x) {if (x>=MOD) x-=MOD;return x;}   inline int add(int x,int MO) {if (x>=MO) x-=MO;return x;}   inline int sub(int x) {if (x<0) x+=MOD;return x;}   inline int sub(int x,int MO) {if (x<0) x+=MO;return x;}   inline void Add(int &x,int y) {x=add(x+y);}   inline void Add(int &x,int y,int MO) {x=add(x+y,MO);}   inline void Sub(int &x,int y) {x=sub(x-y);}   inline void Sub(int &x,int y,int MO) {x=sub(x-y,MO);}   template<typename T> inline int quick_pow(int x,T y) {int res=1;while (y) {if (y&1) res=1ll*res*x%MOD;x=1ll*x*x%MOD;y>>=1;}return res;}   template<typename T> inline int quick_pow(int x,T y,int MO) {int res=1;while (y) {if (y&1) res=1ll*res*x%MO;x=1ll*x*x%MO;y>>=1;}return res;}      int print(int l,int r)   {       printf( ? %d %d n ,l,r);       fflush(stdout);       int res;scanf( %d ,&res);return res;   }      int main ()   {   #ifndef ONLINE_JUDGE       double TIME=clock();       cerr<< Running... <<endl;   #endif       int n;scanf( %d ,&n);       int pos=print(1,n);int l=1,r=n;       while (r-l+1>=4)       {           int mid=(l+r)>>1;           if (l<=pos && pos<=r)           {               if (pos<=mid)               {                   int res=print(l,mid);                   if (res==pos) r=mid; else l=mid+1;               }               else               {                   int res=print(mid+1,r);                   if (res==pos) l=mid+1; else r=mid;               }           }           else           {               if (pos<l)               {                   int res=print(pos,mid);                   if (res==pos) r=mid; else l=mid+1;               }               else               {                   int res=print(mid+1,pos);                   if (res==pos) l=mid+1; else r=mid;               }           }       }       if (l==r) printf( ! %d n ,l);       else if (l+1==r)       {           int res=print(l,r),ans=l+r-res;           printf( ! %d n ,ans);       }       else       {           int res=print(l,r);           if (res==l)           {               int rres=print(l+1,r),ans=l+1+r-rres;               printf( ! %d n ,ans);           }           else if (res==r)           {               int rres=print(l,r-1),ans=l+r-1-rres;               printf( ! %d n ,ans);           }           else           {               int rres=print(l,r-1);               if (rres==r-1) printf( ! %d n ,l); else printf( ! %d n ,r);           }       }   #ifndef ONLINE_JUDGE       cerr<< Exec Time:  <<(clock()-TIME)/CLOCKS_PER_SEC<<endl;   #endif       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, p, num, mi = 1000000, ma = 0, ans = 1;     cin >> n >> p;     vector<long long> v, res;     for (long long i = 0; i < n; i++) {       cin >> num;       v.push_back(num);       mi = min(mi, num);       ma = max(ma, num);     }     sort(v.begin(), v.end());     for (long long i = mi; i <= ma; i++) {       ans = 1;       for (long long j = 0; j < n; j++) {         auto it = upper_bound(v.begin(), v.end(), i + j);         it--;         ans *= (distance(v.begin(), it) + 1 - j);         ans = ans % p;       }       if (ans) {         if (ans % p != 0) res.push_back(i);       }     }     cout << res.size() << endl;     for (long long i = 0; i < res.size(); i++) cout << res[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int a, b;       cin >> a >> b;       long long int r1 = 45;       long long int s1 = 10;       long long int r2 = 20;       long long int s2 = 5;       long long int r3 = 45;       long long int s3 = 10;       long long int r4 = 20;       long long int s4 = 5;       long long int r5 = 5;       long long int s5 = 2;       long long int r6 = 20;       long long int s6 = 5;       long long int r7 = 45;       long long int s7 = 10;       long long int r8 = 20;       long long int s8 = 5;       long long int r9 = 45;       long long int s9 = 10;       long long int digit = b % 10;       long long int sum = 0;       if (digit == 1) {         sum = (a / (b * s1)) * r1;         long long int loop = ((b * s1) * (a / (b * s1))) + b;         for (long long int i = loop; i <= a; i = i + b) {           sum += i % 10;         }       }       if (digit == 2) {         sum = (a / (b * s2)) * r2;         long long int loop = ((b * s2) * (a / (b * s2))) + b;         for (long long int i = loop; i <= a; i = i + b) {           sum += i % 10;         }       }       if (digit == 3) {         sum = (a / (b * s3)) * r3;         long long int loop = ((b * s3) * (a / (b * s3))) + b;         for (long long int i = loop; i <= a; i = i + b) {           sum += i % 10;         }       }       if (digit == 4) {         sum = (a / (b * s4));         sum *= r4;         long long int loop = (a / (b * s4));         loop *= (b * s4);         loop += b;         for (long long int i = loop; i <= a; i = i + b) {           sum += i % 10;         }       }       if (digit == 5) {         sum = (a / (b * s5)) * r5;         long long int loop = ((b * s5) * (a / (b * s5))) + b;         for (long long int i = loop; i <= a; i = i + b) {           sum += i % 10;         }       }       if (digit == 6) {         sum = (a / (b * s6)) * r6;         long long int loop = ((b * s6) * (a / (b * s6))) + b;         for (long long int i = loop; i <= a; i = i + b) {           sum += i % 10;         }       }       if (digit == 7) {         sum = (a / (b * s7)) * r7;         long long int loop = ((b * s7) * (a / (b * s7))) + b;         for (long long int i = loop; i <= a; i = i + b) {           sum += i % 10;         }       }       if (digit == 8) {         sum = (a / (b * s8)) * r8;         long long int loop = ((b * s8) * (a / (b * s8))) + b;         for (long long int i = loop; i <= a; i = i + b) {           sum += i % 10;         }       }       if (digit == 9) {         sum = (a / (b * s9)) * r9;         long long int loop = ((b * s9) * (a / (b * s9))) + b;         for (long long int i = loop; i <= a; i = i + b) {           sum += i % 10;         }       }       cout << sum <<   n ;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int getint() {     unsigned int c;     int x = 0;     while (((c = getchar()) -  0 ) >= 10) {       if (c ==  - ) return -getint();       if (!~c) exit(0);     }     do {       x = (x << 3) + (x << 1) + (c -  0 );     } while (((c = getchar()) -  0 ) < 10);     return x;   }   int getc_str(char str[]) {     unsigned int c, n = 0;     while ((c = getchar()) <=    )       ;     if (!~c) exit(0);     do {       str[n++] = c;     } while ((c = getchar()) >    );     str[n] =   0 ;     return n;   }   char in[100];   int main() {     int i, j, tcc, tc = 1 << 28;     for (tcc = 0; tcc < tc; tcc++) {       int n = getint();       getc_str(in);       bool ok = 1;       for (i = 0; i < n; i++) {         if (in[i] !=  4  and in[i] !=  7 ) ok = 0;       }       int firstSum = 0, secondSum = 0;       for (i = 0; i < n / 2; i++) firstSum += in[i];       for (i = 0; i < n / 2; i++) secondSum += in[i + n / 2];       if (firstSum != secondSum) ok = 0;       if (ok) {         puts( YES );       } else {         puts( NO );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int dx4[] = {-1, 0, 1, 0};   const int dy4[] = {0, 1, 0, -1};   const int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};   const int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};   inline long long Int() {     long long num = 0;     char c = getchar_unlocked();     bool sign = true;     while (!((c >=  0  && c <=  9 ) || c ==  - )) c = getchar_unlocked();     if (c ==  - ) {       sign = false;       c = getchar_unlocked();     }     while (c >=  0  && c <=  9 ) {       num = (num << 1) + (num << 3) + c -  0 ;       c = getchar_unlocked();     }     return sign ? num : -num;   }   template <class S, class T>   ostream& operator<<(ostream& out, const pair<S, T>& P) {     out <<  {  << P.first <<  ,   << P.second <<  } ;     return out;   }   template <class T>   ostream& operator<<(ostream& out, const vector<T>& v) {     out <<  [ ;     for (int i = 0; i < (int)v.size(); ++i) {       out << v[i];       if (i + 1 < (int)v.size()) out <<  ,  ;     }     out <<  ] ;     return out;   }   template <class S, class T>   ostream& operator<<(ostream& out, const map<S, T>& mp) {     out <<  [ n ;     for (const auto& x : mp) {       out <<  {  << x.first <<  ,   << x.second <<  } n ;     }     out <<  ] n ;     return out;   }   template <class T>   ostream& operator<<(ostream& out, const set<T>& cs) {     out <<  { ;     for (auto it = cs.begin(); it != cs.end();) {       out << *it;       it++;       if (it != cs.end())         out <<  ,  ;       else         out <<  } ;     }     return out;   }   void solve();   int main() {     cout << fixed << setprecision(15);     cerr << fixed << setprecision(15);     solve();     return 0;   }   const double eps = 1e-10;   const int mod = (int)1e9 + 7;   const int N = (int)2e5 + 5;   int sm(string S) {     int r = 0;     for (char c : S) r += (c - 48);     return r;   }   int sm(long long x) {     int r = 0;     while (x) {       r += (x % 10);       x /= 10;     }     return r;   }   string sub(string a, string b) {     reverse((a).begin(), (a).end());     reverse((b).begin(), (b).end());     while (((int)(b).size()) < ((int)(a).size())) b +=  0 ;     string res =   ;     int carry = 0;     for (int i = 0; i < (((int)(a).size())); ++i) {       int x = a[i] - 48, y = b[i] - 48;       int add = -1;       if (x >= y + carry) {         add = x - (y + carry);         carry = 0;       } else {         add = (x + 10) - (y + carry);         carry = 1;       }       res += (char)(add + 48);     }     if (carry) {       cout <<  ERROR  <<   n ;       return   ;     }     reverse((res).begin(), (res).end());     return res;   }   void print(string b) {     int i = 0;     while (i < ((int)(b).size()) && b[i] ==  0 ) ++i;     while (i < ((int)(b).size())) putchar(b[i++]);   }   void solve() {     int n = Int(), m = Int();     string ab =   ;     for (int i = 0; i < (m); ++i) ab +=  1 ;     string a =   ;     for (int i = 0; i < (n); ++i) a +=  1 ;     while (((int)(ab).size()) < ((int)(a).size()) + 1) ab +=  0 ;     cout << a <<   n ;     string b = sub(ab, a);     print(b);     putchar(  n );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 333;   long long n, ans[N], a[N][N], pos[N];   long long absv(long long val) {     if (val < 0) val *= -1;     return val;   }   int main() {     std::ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i <= n; i++) {       for (int j = 0; j < n; j++) cin >> a[i][j];     }     for (int i = 0; i < n; i++) pos[i] = N;     for (int i = 0; i < n; i++) {       long long num = i + 1, num2 = i + 1, jx = 0;       for (int j = 0; j < n; j++) {         if (a[n][j] <= num) {           num = a[n][j];           jx = j;           break;         }       }       for (int j = jx + 1; j < n; j++) {         if (a[n][j] <= num2) {           num2 = a[n][j];           break;         }       }       for (int j = 0; j < n; j++) {         long long tmp = num;         if (j + 1 == num)           if (num != num2)             num = num2;           else             continue;         for (int k = 0; k < n; k++) {           if (a[j][k] == num)             if (k < pos[j]) {               pos[j] = k;               ans[j] = i + 1;             }         }         num = tmp;       }     }     for (int i = 0; i < n; i++) cout << ans[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int a[3] = {0};     int n, t;     cin >> n;     while (n--) {       cin >> t;       a[t]++;     }     int res = min(a[1], a[2]);     a[1] -= a[2];     if (a[1] <= 0) a[1] = 0;     res += a[1] / 3;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   const int LEN = 300;   const int MAX = (100000 + LEN - 1) / LEN;   int n;   int m;   int was[100000], x[100000], y[100000];   int l[MAX], r[MAX], w[MAX];   vector<pair<pair<int, int>, int> > v;   vector<int> res;   int get(int a, int b) {     int A = a / LEN;     int B = b / LEN;     if (abs(A - B) <= 1) {       for (int i = a; i <= b; i++)         if (!was[i]) return i;     } else {       for (int i = a; i <= r[A]; i++)         if (!was[i]) return i;       for (int i = A + 1; i < B; i++)         if (w[i] > 0) {           for (int j = l[i]; j <= r[i]; j++)             if (!was[j]) return j;         }       for (int i = l[B]; i <= b; i++)         if (!was[i]) return i;     }     return -1;   }   int add(int x) {     was[x] = 1;     int y = x / LEN;     w[y]--;     return 0;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d%d , &x[i], &y[i]);       x[i]--;       y[i]--;       v.push_back(make_pair(make_pair(x[i], y[i]), i));     }     int NUM = (n + LEN - 1) / LEN;     for (int i = 0; i < NUM; i++) {       l[i] = i * LEN;       r[i] = min((i + 1) * LEN, n) - 1;       w[i] = r[i] - l[i] + 1;     }     sort((v).begin(), (v).end());     for (int i = 0; i < m; i++) {       int j = v[i].second;       int a = n - y[j] - 1;       int b = x[j];       int c = get(a, b);       if (c != -1) {         res.push_back(j + 1);         add(c);       }     }     sort((res).begin(), (res).end());     printf( %d n , ((int)(res).size()));     for (int i = 0; i < ((int)(res).size()); i++) printf( %d  , res[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename item>   item abs(item i) {     if (i < 0) i = -i;     return i;   }   char *s;   int n;   int pos;   int main() {     cin >> n;     cin >> pos;     s = new char[n + 2];     cin >> s + 1;     int cnt = 0;     if (n == 1) {       cout << 0;       return 0;     }     if (n % 2 == 1 and pos == n / 2 + 1) pos++, cnt++;     if (pos > n / 2) pos = n - pos + 1;     int last = n / 2, fst = 1;     while (fst < n - fst + 1 and s[fst] == s[n - fst + 1]) fst++;     while (last > 0 and s[last] == s[n + 1 - last]) last--;     if (pos >= fst and pos <= last) {       int a = pos - fst, b = last - pos;       cnt += 2 * (min(a, b)) + max(a, b);     } else if (pos >= fst and pos >= last)       cnt += pos - min(fst, last);     else if (pos <= last and pos <= fst)       cnt += max(fst, last) - pos;     for (int i = 1; i <= n / 2; i++) {       int cmp = n - i + 1;       if (s[i] > s[cmp]) swap(s[i], s[cmp]);       int a = abs((int)(s[i] - s[cmp])), b =  z  - s[cmp] + s[i] -  a  + 1;       cnt += min(a, b);     }     cout << cnt;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5000;   const double INF = 1e18;   const double ep = 1e-8;   struct Edge {     int from, to;     long long cap, flow;     int id;     Edge() {}     Edge(int u, int v, long long c, long long f, int id_)         : from(u), to(v), cap(c), flow(f), id(id_) {}   };   struct Dinic {     int n, m, s, t;     vector<Edge> edges;     vector<int> G[maxn];     int d[maxn], cur[maxn];     bool vis[maxn];     void init(int n) {       for (int i = 0; i < maxn; i++) G[i].clear();       edges.clear();     }     void add(int from, int to, long long cap, int id) {       edges.push_back(Edge(from, to, cap, 0, id));       edges.push_back(Edge(to, from, 0, 0, -1));       m = edges.size();       G[from].push_back(m - 2);       G[to].push_back(m - 1);     }     bool BFS() {       memset(vis, 0, sizeof(vis));       queue<int> Q;       Q.push(s);       d[s] = 0;       vis[s] = 1;       while (!Q.empty()) {         int x = Q.front();         Q.pop();         for (int i = 0; i < G[x].size(); i++) {           Edge& e = edges[G[x][i]];           if (!vis[e.to] && e.cap - e.flow > ep) {             vis[e.to] = 1;             d[e.to] = d[x] + 1;             Q.push(e.to);           }         }       }       return vis[t];     }     long long DFS(int x, long long a) {       if (x == t || a == 0) return a;       long long flow = 0, f;       for (int& i = cur[x]; i < G[x].size(); i++) {         Edge& e = edges[G[x][i]];         if (d[x] + 1 == d[e.to] && (f = DFS(e.to, min(a, e.cap - e.flow))) > 0) {           e.flow += f;           edges[G[x][i] ^ 1].flow -= f;           flow += f;           a -= f;           if (a == 0) break;         }       }       return flow;     }     long long maxFlow(int s, int t) {       this->s = s;       this->t = t;       long long flow = 0;       while (BFS()) {         memset(cur, 0, sizeof(cur));         flow += DFS(s, INF);       }       return flow;     }     void show() {       for (auto& e : edges) {         printf( (%d -> %d) => cap = %lld , flow = %lld n , e.from, e.to, e.cap,                e.flow);       }     }     void DFS2(int v) {       vis[v] = true;       for (int i = 0; i < G[v].size(); ++i) {         Edge e = edges[G[v][i]];         if (!vis[e.to] && e.cap - e.flow > ep) {           DFS2(e.to);         }       }     }     void showMinCut(int v) {       DFS2(v);       for (auto& e : edges) {         if (vis[e.from] && !vis[e.to] && e.cap != 0 && e.flow != 0)           printf( (%d -> %d) => cap = %lld , flow = %lld n , e.from, e.to, e.cap,                  e.flow);       }     }   };   int N1, N2, M;   int deg[4005];   vector<int> ans[2005];   int s, t, tot;   int main() {     Dinic G;     scanf( %d %d %d , &N1, &N2, &M);     tot = N1 + N2 + 15;     s = tot - 2, t = tot - 1;     G.init(tot);     for (int i = 1; i <= M; ++i) {       int x, y;       scanf( %d %d , &x, &y);       G.add(x, N1 + y, 1, i);       ++deg[x];       ++deg[y + N1];     }     int min_deg = M + 10;     for (int i = 1; i <= N1 + N2; ++i) {       min_deg = min(min_deg, deg[i]);     }     for (int i = 1; i <= N1; ++i) {       G.add(s, i, deg[i] - min_deg, -1);     }     for (int i = 1; i <= N2; ++i) {       G.add(i + N1, t, deg[i + N1] - min_deg, -1);     }     for (int k = min_deg; ~k; --k) {       G.maxFlow(s, t);       for (auto& e : G.edges) {         if (e.from >= 1 && e.from <= N1 && e.to >= N1 + 1 && e.to <= N2 + N1) {           if (e.flow == 0 && e.cap == 1) {             ans[k].push_back(e.id);           }         }       }       for (int i = 1; i <= N1; ++i) {         G.add(s, i, 1, -1);       }       for (int i = 1; i <= N2; ++i) {         G.add(i + N1, t, 1, -1);       }     }     for (int i = 0; i <= min_deg; ++i) {       printf( %d  , (int)ans[i].size());       for (int j : ans[i]) {         printf( %d  , j);       }       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = (1e9) + 7;   const long double EPS = 0.0000001;   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     string t;     cin >> t;     int szs = s.size();     int szt = t.size();     int cur = 0;     int pref[szt + 1];     int suff[szt + 1];     for (int i = 0; i < szs; i++) {       if (s[i] == t[cur]) {         pref[cur] = i;         cur++;       }       if (cur == szt) break;     }     cur--;     for (int i = szs - 1; i >= 0; i--) {       if (s[i] == t[cur]) {         suff[cur] = i;         cur--;       }       if (cur == -1) break;     }     int ans = 0;     ans = max(ans, szs - 1 - suff[szt - 1]);     ans = max(ans, suff[0]);     ans = max(ans, pref[0]);     ans = max(ans, szs - 1 - pref[szt - 1]);     for (int i = 0; i < szt - 1; i++) {       ans = max(ans, suff[i + 1] - pref[i] - 1);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int num = 0;     char c = getchar();     if (c ==  - ) return -read();     while (c >=  0  && c <=  9 ) {       num = (num << 3) + (num << 1) + c -  0 ;       c = getchar();     }     return num;   }   inline long long READ() {     long long num = 0;     char c = getchar();     if (c ==  - ) return -READ();     while (c >=  0  && c <=  9 ) {       num = (num << 3) + (num << 1) + c -  0 ;       c = getchar();     }     return num;   }   vector<int> nz[100007], nf[100007];   pair<int, int> en[100007];   int cost[100007];   int djg = 0;   bool lgl[100007], l8[100007];   int minv = ((int)0x3f3f3f3f), mincnt = 0;   long long ans = 1, ans2 = 0;   int n, m;   void dfs(int now) {     l8[now] = 1;     for (int i = 0; i < ((int)(nz[now]).size()); i++)       if (!l8[nz[now][i]]) dfs(nz[now][i]);     en[now] = make_pair(djg++, now);   }   void dfs2(int now) {     lgl[now] = 1;     if (cost[now] < minv) {       minv = cost[now];       mincnt = 1;     } else if (cost[now] == minv)       mincnt++;     for (int i = 0; i < ((int)(nf[now]).size()); i++)       if (!lgl[nf[now][i]]) dfs2(nf[now][i]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , cost + i);     scanf( %d , &m);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       nz[a].push_back(b);       nf[b].push_back(a);     }     for (int i = 1; i <= n; i++)       if (!l8[i]) dfs(i);     sort(en + 1, en + n + 1);     for (int i = n; i >= 1; i--)       if (!lgl[en[i].second]) {         minv = ((int)0x3f3f3f3f);         dfs2(en[i].second);         ans = ans * mincnt % 1000000007;         ans2 += minv;       }     printf( %I64d %I64d n , ans2, ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int slope[150 + 1];   int main(void) {     int w, h;     scanf( %d%d , &w, &h);     for (int i = 0; i < 2; i++) {       int ww, hh;       scanf( %d%d , &ww, &hh);       slope[hh] = ww;     }     while (h > 0) {       w += h;       if (slope[h] > 0) w = max(0, w - slope[h]);       h--;     }     printf( %d n , w);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, t, s, ma;   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> t;       s += t;       ma = max(ma, t);     }     cout << max(ma, (2 * s + n) / n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long sign(long long x) { return x < 0 ? -1 : 1; }   pair<long long, long long> part(long long from, long long to, long long s,                                   long long dir) {     pair<long long, long long> res{dir, abs(to - from)};     if (to != from && sign(to - from) != sign(dir)) {       res.first *= -1;       res.second += 2 * abs(from - (dir == -1 ? 0 : s));     }     return res;   }   long long solve(long long s, long long x1, long long x2, long long t1,                   long long t2, long long p, long long d) {     auto toTram = part(p, x1, s, d);     return min(part(x1, x2, s, sign(x2 - x1)).second * t2,                (toTram.second + part(x1, x2, s, toTram.first).second) * t1);   }   void tests() {     assert(7 == solve(10, 3, 8, 1, 2, 1, 1));     assert(9 == solve(10, 3, 8, 1, 2, 1, -1));     assert(10 == solve(10, 3, 8, 1, 2, 2, -1));     assert(12 == solve(10, 3, 8, 1, 5, 4, -1));     assert(24 == solve(10, 3, 8, 1, 5, 4, 1));     assert(20 == solve(10, 3, 8, 1, 4, 4, 1));     assert(15 == solve(10, 3, 8, 1, 3, 10, -1));     assert(18 == solve(10, 3, 8, 1, 4, 10, -1));     assert(19 == solve(10, 3, 8, 1, 4, 9, 1));     assert(20 == solve(10, 3, 8, 2, 4, 9, 1));     assert(5 == solve(10, 3, 8, 1, 4, 3, 1));     assert(11 == solve(10, 3, 8, 1, 4, 3, -1));     assert(20 == solve(10, 3, 8, 1, 5, 8, 1));     assert(16 == solve(10, 3, 8, 1, 4, 8, -1));     assert(5 + 4 + 5 == solve(10, 8, 3, 1, 4, 3, 1));     assert(6 + 5 + 4 + 5 == solve(10, 8, 3, 1, 5, 3, -1));     assert(4 + 5 == solve(10, 8, 3, 1, 4, 8, 1));     assert(5 == solve(10, 8, 3, 1, 4, 8, -1));     assert(8 == solve(4, 2, 4, 3, 4, 1, 1));     assert(7 == solve(5, 4, 0, 1, 2, 3, 1));   }   int main() {     tests();     long long s, x1, x2, t1, t2, p, d;     while (cin >> s >> x1 >> x2 >> t1 >> t2 >> p >> d) {       cout << solve(s, x1, x2, t1, t2, p, d) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int f1(long int x, long int a) {     if ((x < 0 && x > (-1 * ((double)a) / 2)) || (x > 0 && x < ((double)a) / 2) ||         x == 0)       return 1;     else       return 0;   }   long long int f2(long long int x, long long int a) {     if ((x < 0 && x > (-1 * ((double)a))) || (x > 0 && x < ((double)a)))       return 1;     else       return 0;   }   int main() {     long long int x, y, a, num, p, flag = 1, ans;     cin >> a >> x >> y;     num = (y - a) % (2 * a);     ans = (y - a - num) / a;     ans = 1 + (ans / 2) * 3;     p = num / a;     if (p * a == num)       flag = 0;     else {       if (y < a) {         if (!f1(x, a)) flag = 0;       } else {         if (p < 1) {           if (f1(x, a))             ans += 1;           else             flag = 0;         } else {           if (f2(x, a)) {             if (x < 0)               ans += 2;             else               ans += 3;           } else             flag = 0;         }       }     }     if (flag)       cout << ans;     else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, x = 1e18;   int main() {     cin >> a;     cout << a - x % a * 9 % a * 9 % a <<     << a - x % a * 9 % a * 9 % a + x - 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const int maxn = 1e5 + 5;   const int inf = 0x3f3f3f3f;   const double PI = acos(-1.0);   const long long INF = 0x3f3f3f3f3f3f3f3f;   int a[maxn], val[maxn];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       val[i] = a[i] + 1;     }     for (int i = 1; i <= n; ++i) {       val[i] = max(val[i], val[i - 1]);     }     for (int i = n; i > 0; --i) {       val[i] = max(val[i + 1] - 1, val[i]);     }     long long ans = 0;     for (int i = 1; i <= n; ++i) {       ans += val[i] - a[i] - 1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:268435456 )   using namespace std;   const double PI = 3.1415926535897932384626433832795;   template <class T>   T min(T &a, T &b) {     return (a < b) ? a : b;   }   template <class T>   T max(T &a, T &b) {     return (a > b) ? a : b;   }   template <class T>   T sqr(T a) {     return a * a;   }   template <class T>   T abs(T &a) {     return (a < 0) ? (-a) : a;   }   inline void read(int &x) { scanf( %d , &x); }   inline void readln(int &x) { scanf( %d n , &x); }   inline void write(int x) { printf( %d , x); }   inline void writeln(int x) { printf( %d n , x); }   inline void read(long long &x) { scanf( %lld , &x); }   inline void readln(long long &x) { scanf( %lld n , &x); }   inline void write(long long x) { printf( %lld , x); }   inline void writeln(long long x) { printf( %lld n , x); }   inline void read(double &x) { scanf( %lf , &x); }   inline void readln(double &x) { scanf( %lf n , &x); }   inline void write(double x) { printf( %.15lf , x); }   inline void writeln(double x) { printf( %.15lf n , x); }   inline void read(char *s) { scanf( %s , s); }   inline void readln(char *s) { scanf( %s n , s); }   inline void write(char *s) { printf( %s , s); }   inline void writeln(char *s) { printf( %s n , s); }   inline int readInt() {     int x;     read(x);     return x;   }   inline long long readLong() {     long long x;     read(x);     return x;   }   inline double readDouble() {     double x;     read(x);     return x;   }   inline void showTime() {}   const double eps = 1e-10;   double x, y, yw, r;   double ya, yb, yao, ybo;   double wp(double x1, double y1, double x2, double y2) {     return x1 * y2 - x2 * y1;   }   double dist(double x1, double y1, double x2, double y2) {     return sqrt(sqr(x1 - x2) + sqr(y1 - y2));   }   bool goodb(double xt) {     double x1 = x;     double y1 = y;     double x2 = xt;     double y2 = yw;     double s = wp(x2 - x1, y2 - y1, 0 - x1, ybo - y1);     double d = s / dist(x1, y1, x2, y2);     if (d < r + eps) return false;     return true;   }   bool gooda(double xt) {     double x1 = x;     double y1 = y;     double x2 = xt;     double y2 = yw;     double s = wp(x2 - x1, y2 - y1, 0 - x1, yao - r - y1);     double d = s / dist(x1, y1, x2, y2);     if (d > -eps) return false;     return true;   }   int main() {     srand((unsigned)time(NULL));     cin >> ya >> yb >> yw >> x >> y >> r;     yw -= r;     yao = 2 * yw - ya;     ybo = 2 * yw - yb;     double xt = 0;     double step = x;     while (step > eps) {       if (!goodb(xt + step)) xt += step;       step /= 2;     }     while (!goodb(xt + step)) xt += step;     xt += step * 100000;     if (gooda(xt)) {       cout.setf(ios::fixed);       cout.precision(10);       cout << xt;     } else {       cout << -1;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   const double pi = acos(-1.0);   const long long int inf = 0x3f3f3f3f3f3f3f3f;   const long long int mod = 998244353;   bool isPowerOfTwo(int x) { return x && (!(x & (x - 1))); }   void fast() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   string s[2];   int n, k, h;   bool a[2][100005];   void dfs(int x, int y) {     if (s[x][y] !=  -  || a[x][y] == true || y < h) return;     if (y + k >= n) {       cout <<  YES ;       exit(0);     }     h++;     a[x][y] = true;     dfs(1 - x, y + k);     dfs(x, y + 1);     dfs(x, y - 1);     h--;   }   int main() {     cin >> n >> k >> s[0] >> s[1];     dfs(0, 0);     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 3, K = 11, M = N * 4;   const long long MOD = 998244353, oo = 1e9, OO = 1e18, mod = MOD;   const double pi = acos(-1), eps = 1e-17;   long long di[] = {0, 0, 1, -1};   long long dj[] = {1, -1, 0, 0};   long long pos[N];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     ;     long long ret = 1;     long long n;     cin >> n;     long long arr2[n * n];     for (long long i = 0; i < n * n; i++) cin >> arr2[i];     vector<long long> v;     for (long long i = 0; i < n * n; i++) v.push_back(i);     do {       long long arr[n * n];       for (long long i = 0; i < n * n; i++) arr[i] = arr2[v[i]];       map<long long, long long> mp;       long long sum = 0;       for (long long i = 0; i < n; i++) {         sum += arr[i * n + i];       }       mp[sum]++;       if (mp.size() > 1) continue;       sum = 0;       for (long long i = 0; i < n; i++) {         sum = 0;         for (long long j = 0; j < n; j++) sum += arr[i * n + j];         mp[sum]++;         if (mp.size() > 1) continue;       }       for (long long j = 0; j < n; j++) {         sum = 0;         for (long long i = 0; i < n; i++) sum += arr[i * n + j];         mp[sum]++;         if (mp.size() > 1) continue;       }       long long r = 0, c = n - 1;       sum = 0;       while (c >= 0) {         sum += arr[r * n + c];         r++, c--;       }       mp[sum]++;       if (mp.size() > 1) continue;       if (mp.size() == 1) {         cout << sum <<   n ;         for (long long i = 0; i < n * n; i++) {           if (i && i % 3 == 0) cout <<   n ;           cout << arr[i] <<    ;         }         return 0;       }     } while (next_permutation(v.begin(), v.end()));   }


#include <bits/stdc++.h>   using namespace std;   int m, n;   int R[1005];   map<int, int> cnt;   long long bell[1005][1005];   void geneBell() {     bell[0][0] = 1;     for (int i = 1; i < m + 2; i++) {       bell[i][0] = bell[i - 1][i - 1];       for (int j = 1; j <= i; j++) {         bell[i][j] = (bell[i][j - 1] + bell[i - 1][j - 1]) % 1000000007;       }     }   }   int main() {     cin >> m >> n;     geneBell();     string tmp;     for (int i = 0; i < n; i++) {       cin >> tmp;       for (int j = 0; j < m; j++) {         R[j] = R[j] * 10 + tmp[j] -  0 ;       }     }     for (int i = 0; i < m; i++) {       cnt[R[i]]++;     }     map<int, int>::iterator it;     long long ans = 1;     for (it = cnt.begin(); it != cnt.end(); ++it) {       if ((it->second) > 0) {         ans = (ans * bell[it->second][0]) % 1000000007;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, a, b;     cin >> n >> a >> b;     if (a + b > n - 1 || a == n - 1 && n > 1)       cout << -1 << endl;     else {       if (n == 1)         cout << 1 << endl;       else {         cout << 1 <<    ;         n--;         int c;         n -= (a + b);         for (int i = 1; i <= b; i++) {           c = 1 << i;           cout << c <<    ;         }         while (n > 0) {           cout << c <<    ;           n--;         }         while (a > 0) {           c++;           cout << c <<    ;           a--;         }       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       int a, b, c, d;       cin >> a >> b >> c >> d;       cout << max(a + b, c + d) << endl;     }   }


#include <bits/stdc++.h>   using std ::max;   using std ::min;   const int maxx = 300000 + 25;   int n, m, x, y, z, k, num;   int cnt, ans, tot;   int front, back, kr;   int cur[maxx];   std ::priority_queue<int, std ::vector<int>, std ::greater<int> > quq;   class Node {    public:     int x;     int y;     int id;   };   Node a[maxx];   bool cmp(Node a, Node b) { return a.x == b.x ? a.y < b.y : a.x < b.x; }   int main() {     scanf( %d%d , &n, &k);     for (int i = (1), i_END = (n); i <= (i_END); ++i) {       scanf( %d%d , &a[i].x, &a[i].y);       a[i].id = i;     }     std ::sort(a + 1, a + n + 1, cmp);     for (int i = (1), i_END = (n); i <= (i_END); ++i) {       quq.push(a[i].y);       tot++;       if (tot > k) {         quq.pop();         tot--;       }       if (tot == k) {         if (quq.top() - a[i].x + 1 > ans) {           ans = quq.top() - a[i].x + 1;           front = a[i].x;           back = quq.top();         }       }     }     printf( %d n , ans);     if (ans == 0) {       for (int i = (1), i_END = (k); i <= (i_END); ++i) printf( %d  , i);       putchar(10);       return 0;     }     for (int i = (1), i_END = (n); i <= (i_END); ++i) {       if (front >= a[i].x && a[i].y >= back) {         printf( %d  , a[i].id);         kr++;       }       if (kr == k) break;     }     putchar(10);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int k = 0; k < t; k++) {       int x, y, d = 0;       cin >> x >> y;       if (x >= y || x > 3) {         cout <<  YES  << endl;         d = 1;       }       if (d == 0) {         if (x == 1) {           cout <<  NO  << endl;         } else {           if (y > 3) {             cout <<  NO  << endl;           } else {             cout <<  YES  << endl;           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int mx = 0, i, n, m, d, h, ld, lh;     cin >> n >> m;     for (i = 0; i < m; i++) {       cin >> d >> h;       if (i == 0) {         ld = d;         lh = h;         mx = lh + ld - 1;         continue;       }       if (abs(h - lh) > d - ld) {         cout <<  IMPOSSIBLE ;         return 0;       }       if (h - lh < 0)         mx = max(mx, lh + (d - ld - abs(h - lh)) / 2);       else         mx = max(mx, h + (d - ld - abs(h - lh)) / 2);       ld = d;       lh = h;     }     mx = max(mx, lh + n - ld);     cout << mx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string bad;   int k, ans = 0;   struct node {     node *edges[26];     node() {       for (int i = 0; i < 26; i++) edges[i] = NULL;     }   };   void insert(node *trie, string s) {     for (int i = 0; i < s.size(); i++) {       if (trie->edges[s[i] -  a ] == NULL) trie->edges[s[i] -  a ] = new node();       trie = trie->edges[s[i] -  a ];     }   }   void dfs(node *trie, int b) {     if (b <= k) ans++;     for (int i = 0; i < 26; i++) {       if (trie->edges[i]) {         int add = 0;         if (bad[i] ==  0 ) add++;         dfs(trie->edges[i], b + add);       }     }   }   int main() {     string s;     cin >> s >> bad >> k;     node *root = new node();     string t =   ;     for (int i = s.size() - 1; i >= 0; i--) {       t = s[i] + t;       insert(root, t);     }     dfs(root, 0);     cout << ans - 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int l, ans;   string s;   char t[1000005];   int cal(string s) {     int l = s.size(), p = 0, q = 0, cnt1 = 0, flag = 0;     char ch;     for (int i = 0; i < l; i++) {       ch = (q & 1) ?  R  :  L ;       if (s[i] ==  X ) {         q++;       } else {         if (s[i] == ch) {           p++;           q++;           flag = 0;         } else {           p++;           q += 2;           cnt1 += flag;           flag = !flag;         }       }     }     if (q & 1) {       q++;       cnt1 += flag;     }     if (p * 2 > q) {       p -= cnt1;       q -= cnt1 * 2;     }     return (long long)p * 100000000 / q;   }   int main() {     s =   ;     scanf( %s , &t);     l = strlen(t);     for (int i = 0; i < l; i++) {       if (i > 0 && t[i] == t[i - 1] && t[i] !=  X ) {         s +=  X ;       }       s += t[i];     }     if (s[0] == s[s.size() - 1] && s[0] !=  X ) {       ans = max(cal(s +  X ), cal( X  + s));     } else {       ans = cal(s);     }     printf( %d.%.06d n , ans / 1000000, ans % 1000000);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename V>   ostream &operator<<(ostream &out, const pair<T, V> x) {     out <<  {  << x.first <<   :   << x.second <<  } ;     return out;   }   template <typename T>   ostream &operator<<(ostream &out, const set<T> x) {     for (auto &it : x) {       out << it <<    ;     }     return out;   }   template <typename T>   ostream &operator<<(ostream &out, const multiset<T> x) {     for (auto &it : x) {       out << it <<    ;     }     return out;   }   template <typename T, typename V>   ostream &operator<<(ostream &out, const map<T, V> x) {     for (auto &it : x) {       out <<  [  << it.first <<  ]            <<   =   << it.second <<   n ;     }     return out;   }   template <typename T>   ostream &operator<<(ostream &out, const vector<T> x) {     for (int i = 0; i < x.size() - 1; ++i) {       out << x[i] <<    ;     }     out << x.back();     return out;   }   template <typename T>   ostream &operator<<(ostream &out, const vector<vector<T> > x) {     for (int i = 0; i < x.size() - 1; ++i) {       out <<  [  << i <<  ]            <<   = {  << x[i] <<  } n ;     }     out <<  [  << x.size() - 1 <<  ]          <<   = {  << x.back() <<  } n ;     return out;   }   const int N = 1e6 + 5;   const int MOD = 1e9 + 7;   const int INF = 1e9;   vector<vector<char> > a, ans;   vector<vector<int> > cnt, dst;   int n, m;   long long get(long long x1, long long y1, long long x2, long long y2) {     --x1, --y1;     if (x1 < 0 || y1 < 0) return 0;     return cnt[x2][y2] - cnt[x1][y2] - cnt[x2][y1] + cnt[x1][y1];   }   queue<pair<long long, long long> > qu;   void bfs(long long x) {     while (!qu.empty()) {       pair<long long, long long> cr = qu.front();       qu.pop();       for (int i = -1; i <= 1; ++i) {         for (int j = -1; j <= 1; ++j) {           if (dst[cr.first + i][cr.second + j] == 0) {             if (cr.first + i <= 0 || cr.first + i > n || cr.second + j <= 0 ||                 cr.second + j > m)               continue;             dst[cr.first + i][cr.second + j] = dst[cr.first][cr.second] + 1;             qu.push({cr.first + i, cr.second + j});           }         }       }     }   }   bool solve(long long x) {     while (!qu.empty()) qu.pop();     long long sz = 2 * x + 1;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         ans[i][j] =  . ;         dst[i][j] = 0;         long long c = get(i - sz + 1, j - sz + 1, i, j);         if (c == sz * sz) ans[i - x][j - x] =  X ;         if (i >= x && j >= x && ans[i - x][j - x] ==  X ) {           qu.push({i - x, j - x});           dst[i - x][j - x] = 1;         }       }     }     if (qu.empty()) return false;     bfs(x);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         if (a[i][j] ==  X  && dst[i][j] > x + 1) return false;       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     a.resize(n + 2, vector<char>(m + 2));     ans.resize(n + 2, vector<char>(m + 2));     cnt.resize(n + 2, vector<int>(m + 2));     dst.resize(n + 2, vector<int>(m + 2));     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         cin >> a[i][j];         cnt[i][j] =             cnt[i][j - 1] + cnt[i - 1][j] - cnt[i - 1][j - 1] + (a[i][j] ==  X );       }     }     int l = 0, r = INF;     while (r - l > 1) {       int mid = (l + r) >> 1;       if (solve(mid)) {         l = mid;       } else {         r = mid;       }     }     if (solve(r))       cout << r;     else if (solve(l))       cout << l;     cout <<   n ;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         cout << ans[i][j];       }       cout <<   n ;     }     return 0;   }