#include <bits/stdc++.h>   using namespace std;   long long ans = 0;   int n, m, x, y;   int main() {     while (scanf( %d%d%d%d , &n, &x, &m, &y) == 4) {       if (x > y) {         n ^= m ^= n ^= m;         x ^= y ^= x ^= y;       }       ans = n + 1;       int l, r;       for (int i = 1; i <= m; ++i) {         l = y - i;         r = y + i;         if (l <= x - n || l >= x + n)           ++ans;         else {           r = min(r - 1, n + x);           if (l >= x)             ans += ((r - l) << 1);           else             ans += ((r - x - (x - l)) << 1) + 1;         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long paw[30];   void pw() {     paw[0] = 1;     for (int i = 1; i < 20; i++) paw[i] = 10 * paw[i - 1];   }   long long rev(long long a) {     long long ret = 0;     vector<int> v;     while (a > 0) {       v.push_back(a % 10);       a /= 10;     }     for (int i = 0; i < v.size(); i++) ret += (v[i] * paw[v.size() - i - 1]);     return ret;   }   int main() {     long long a1, a2;     cin >> a1 >> a2;     pw();     cout << a1 + rev(a2) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int count = 0, k = 0, res = 0;       string s;       cin >> s;       for (int i = 0; i < s.length(); i++) {         count = count + (s[i] -  0 );       }       for (int i = 0; i < s.length(); i++) {         if (s[i] ==  1 ) {           k = 1;           count--;         }         if (s[i] ==  0  && k == 1 && count > 0) {           res++;         }       }       cout << res << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int xp, nb;     cin >> xp >> nb;     cout << min(xp, min(nb, (xp + nb) / 3));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   int n, c[N][N];   struct node {     int v, pos;   } a[N];   inline bool cmp(node x, node y) { return x.v > y.v; }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i].v), a[i].pos = i;     sort(a + 1, a + n + 1, cmp);     for (int i = 1; i <= n; ++i)       for (int j = 1, k = i; j <= a[i].v; ++j, k = k % (n + 1) + 1)         c[k][a[i].pos] = 1;     printf( %d n , n + 1);     for (int i = 1; i <= n + 1; puts(  ), ++i)       for (int j = 1; j <= n; ++j) printf( %d , c[i][j]);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:33554432 )   using namespace std;   int P[1 << 18];   int B[1 << 18];   int C[1 << 18];   int S[1 << 18];   long long R[1 << 18];   vector<pair<int, int> > E[1 << 18];   int gMark, gS;   int Parent(int a) {     if (P[a] == a) return a;     return P[a] = Parent(P[a]);   }   void dfs(int a, int p) {     B[a] = gMark;     int i;     for (i = 0; i < int((E[a]).size()); i++) {       int b = E[a][i].first;       if (b == p) continue;       dfs(b, a);       S[a] += S[b];     }     S[a] += C[a];   }   void dfs2(int a, int p) {     B[a] = gMark;     int i;     for (i = 0; i < int((E[a]).size()); i++) {       int b = E[a][i].first;       if (b == p) continue;       dfs2(b, a);       long long s = S[b];       R[E[a][i].second] = s * (gS - s);     }   }   int main() {     int n;     scanf( %d , &n);     int i, j;     vector<pair<pair<int, int>, pair<int, int> > > v;     for (i = 0; i < n - 1; i++) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       v.push_back(make_pair(pair<int, int>(c, i), pair<int, int>(a - 1, b - 1)));     }     sort((v).begin(), (v).end());     for (i = 0; i < n + n; i++) {       P[i] = i;       C[i] = 1;       S[i] = 0;     }     memset(B, 0, sizeof(B));     gMark = 0;     int prev = 0;     int cnt = n;     for (i = 1; i < n; i++)       if (i == n - 1 || v[i].first.first != v[i - 1].first.first) {         for (j = prev; j < i; j++) {           int a = Parent(v[j].second.first);           int b = Parent(v[j].second.second);           E[a].push_back(pair<int, int>(b, v[j].first.second));           E[b].push_back(pair<int, int>(a, v[j].first.second));         }         ++gMark;         for (j = prev; j < i; j++) {           int a = Parent(v[j].second.first);           if (B[a] != gMark) dfs(a, -1);         }         ++gMark;         for (j = prev; j < i; j++) {           int a = Parent(v[j].second.first);           if (B[a] != gMark) {             gS = S[a];             dfs2(a, -1);           }         }         for (j = prev; j < i; j++) {           int a = Parent(v[j].second.first);           int b = Parent(v[j].second.second);           P[a] = P[b] = cnt;           C[cnt] = C[a] + C[b];           ++cnt;         }         prev = i;       }     long long res = 0;     for (i = 0; i < n - 1; i++) res = max(res, R[i]);     vector<int> ret;     for (i = 0; i < n - 1; i++)       if (R[i] == res) ret.push_back(i + 1);     printf( %lld %d n , res + res, int((ret).size()));     for (i = 0; i < int((ret).size()); i++)       printf( %d%c , ret[i], i == int((ret).size()) - 1 ?   n  :    );     return 0;   };


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   vector<long long> v;   void lucky(long long x) {     queue<long long> q;     q.push(x);     while (x < 1e9) {       x = q.front();       q.pop();       x *= 10;       q.push(x + 4);       q.push(x + 7);       v.push_back(x + 4);       v.push_back(x + 7);     }   }   int next(long long x) {     int str = 0, ed = v.size() - 1, ans;     while (str <= ed) {       int mid = str + ((ed - str) / 2);       if (v[mid] >= x) {         ans = mid;         ed = mid - 1;       } else         str = mid + 1;     }     return ans;   }   int main() {     long long x, y;     cin >> x >> y;     lucky(0);     unsigned long long sum = 0;     sort(v.begin(), v.end());     int z = next(x);     if (y <= v[z])       return cout << (y - x + 1) * v[z], 0;     else {       sum += (v[z] - x + 1) * v[z];       int i;       for (i = z + 1; v[i] <= y; i++) {         sum += (v[i] - v[i - 1]) * v[i];       }       sum += (y - v[i - 1]) * v[i];     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   void pairsort(long long a[], long long b[], long long n) {     pair<long long, long long> pairt[n];     for (long long i = 0; i < n; i++) {       pairt[i].first = a[i];       pairt[i].second = b[i];     }     sort(pairt, pairt + n);     for (long long i = 0; i < n; i++) {       a[i] = pairt[i].first;       b[i] = pairt[i].second;     }   }   int32_t main() {     long long n, k;     cin >> n >> k;     long long a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     long long f = 0;     long long c = 0;     for (long long i = 0; i < n - 1; i++) {       c += a[i] / k;       a[i] = a[i] % k;       if (a[i] != 0) {         if (k - a[i] < a[i + 1])           a[i + 1] -= (k - a[i]);         else           a[i + 1] = 0;         c += 1;       }       a[i] = 0;     }     c += a[n - 1] / k;     if (a[n - 1] % k != 0) c += 1;     cout << c;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000LL * 1000 * 1000 + 7;   const int INF = 1000 * 1000 * 1000;   const long long base = 1e18;   const int MAXN = 600000;   const double EPS = 1e-9;   const double PI = acos(-1.);   long long binPow(long long a, long long x) {     long long res = 1;     while (x) {       if (x & 1) {         res *= a;         res %= MOD;       }       a *= a;       a %= MOD;       x /= 2;     }     return res;   }   long long dpT[200000][2];   long long n, m;   long long a[200000];   long long b[200000];   long long dp(int pos, int more) {     if (pos == n) {       return more;     }     if (dpT[pos][more] != -1) return dpT[pos][more];     if (more == 1) {       long long ans = dp(pos + 1, more);       if (a[pos] == 0) {         ans *= m;         ans %= MOD;       }       if (b[pos] == 0) {         ans *= m;         ans %= MOD;       }       return dpT[pos][more] = ans;     }     if (a[pos] && b[pos] && a[pos] < b[pos]) return dpT[pos][more] = 0;     if (a[pos] && b[pos] && a[pos] > b[pos])       return dpT[pos][more] = dp(pos + 1, 1);     if (a[pos] && b[pos] && a[pos] == b[pos]) {       return dpT[pos][more] = dp(pos + 1, 0);     }     if (a[pos] == 0 && b[pos]) {       long long res = 0;       res += (dp(pos + 1, 1) * (m - b[pos])) % MOD;       res %= MOD;       res += dp(pos + 1, 0);       res %= MOD;       return dpT[pos][more] = res;     }     if (a[pos] && b[pos] == 0) {       long long res = 0;       res += (dp(pos + 1, 1) * (a[pos] - 1)) % MOD;       res %= MOD;       res += dp(pos + 1, 0);       res %= MOD;       return dpT[pos][more] = res;     }     long long res = 0;     long long cur = (m * (m - 1) / 2) % MOD;     res += (dp(pos + 1, 1) * (cur)) % MOD;     res %= MOD;     res += (dp(pos + 1, 0) * m) % MOD;     res %= MOD;     return dpT[pos][more] = res;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     int cnt = 0;     for (int i = (0); i < (n); ++i) {       cin >> a[i];       if (!a[i]) cnt++;     }     for (int i = (0); i < (n); ++i) {       cin >> b[i];       if (!b[i]) cnt++;     }     memset(dpT, -1, sizeof dpT);     long long div = binPow(m, cnt);     long long y = binPow(div, MOD - 2);     cout << (dp(0, 0) * y) % MOD;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, s, p;   int main() {     scanf( %d %d %d , &t, &s, &p);     int l = t;     int x1 = 0, x2 = s;     int co = 1;     while (x1 < l) {       x1 = x1 + p;       x2 = x2 + p - 1;       if (x1 >= l && x2 >= l)         break;       else if (x1 >= x2) {         x1 = 0;         co++;       }     }     cout << co << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   int main()   {       ios_base::sync_with_stdio(false);       cin.tie(0);       int t;       cin >> t;       while (t--) {           int u, v; cin >> u >> v;           if (u > v)               printf( NO n );           else if (u == v)               printf( YES n );           else {               int U = 0, V = 0, fail = 0;               // (u) 1 0111 0111 -> 1 1010 0110 (v)               // bit0: {0, 1, 2, 4, 5, 6, 8} -> bit1: {1, 2, 5, 7, 8}               for (int i = 0; i < 30; i++) {                   U += u >> i & 1;                   V += v >> i & 1;                   fail |= U < V;               }               printf(fail ?  NO n  :  YES n );           }       }       return 0;   }   /*   3 12   YES   6 9   NO   */


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long m, n;     cin >> m >> n;     long ar[n], br[n];     for (int i = 0; i < n; i++) {       cin >> ar[i] >> br[i];     }     int tmp;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n - 1; j++) {         if (br[j] < br[j + 1]) {           tmp = br[j];           br[j] = br[j + 1];           br[j + 1] = tmp;           tmp = ar[j];           ar[j] = ar[j + 1];           ar[j + 1] = tmp;         }       }     }     int cnt = 0, i = 0;     long sum = 0;     while (cnt != m && i < n) {       while (ar[i] != 0) {         sum += br[i];         ar[i]--;         cnt++;         if (cnt == m) break;       }       i++;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int inp[200200];   int sum[200200];   char str[200200];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &inp[i]);     scanf( %s , str);     int len = strlen(str);     reverse(inp, inp + n);     reverse(str, str + len);     sum[n] = 0;     for (int i = n - 1; ~i; --i) sum[i] = sum[i + 1] + inp[i];     int v = 0, ans = 0;     for (int i = 0; i < len; ++i) {       if (str[i] ==  1 ) {         ans = max(ans, v + sum[i + 1]);         v += inp[i];       }       if (0) printf(  << i %2d, v %2d, ans %2d n , i, v, ans);     }     if (0) {       for (int i = 0; i < n; ++i) printf(  %d n , inp[i]);       puts(  );       for (int i = 0; i < n; ++i) printf(  %d n , sum[i]);       puts(  );     }     if (0) printf( < v %d n , v);     printf( %d n , max(ans, v));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> V[2001010];   int cnt[2002];   long long cum[2002], N;   string s;   void make(int l, int r) {     while (l >= 0 && r < (int)s.size()) {       if (s[l] == s[r]) {         V[N++] = (make_pair(l, r));         cnt[l]++;       } else         break;       l--, r++;     }   }   int main() {     N = 0;     cin >> s;     memset(cnt, 0, sizeof(cnt));     for (int i = 0; i < (int)s.size(); ++i) {       make(i, i);       make(i - 1, i);     }     cum[0] = 0;     for (int i = 0; i < (int)s.size(); ++i) cum[i + 1] = cum[i] + cnt[i];     long long Sm = cum[s.size()];     long long c = 0;     for (int i = 0; i < N; ++i) {       c += (Sm - cum[V[i].second + 1]);     }     cout << c << endl;   }


#include <bits/stdc++.h>   using namespace std;   char a[200][200];   int lef[200], righ[200];   bool is[200];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, bot = 0;     cin >> n >> m;     for (int i = 0; i < n + 1; i++) {       lef[i] = m - 1;       righ[i] = 0;     }     for (int i = 0; i < n; i++) {       bool f = 0;       for (int j = 0; j < m; j++) {         cin >> a[i][j];         if (a[i][j] ==  W ) {           lef[i] = min(j, lef[i]);           righ[i] = max(j, righ[i]);           f = 1;           bot = i;         }       }       is[i] = f;     }     int cur = 0, ans = 0;     for (int i = 0; i <= bot; i++) {       if (is[i + 1] == 0 && is[i] == 0) continue;       if (i % 2 == 0) {         ans += abs(cur - max(righ[i + 1], righ[i]));         cur = max(righ[i + 1], righ[i]);       } else {         ans += abs(cur - min(lef[i + 1], lef[i]));         cur = min(lef[i + 1], lef[i]);       }     }     cout << ans + bot;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool cmin(T &a_, T b_) {     return a_ > b_ ? (a_ = b_, true) : false;   }   template <class T>   bool cmax(T &a_, T b_) {     return a_ < b_ ? (a_ = b_, true) : false;   }   template <class T>   void OUT(T s_) {     cout << s_ <<   n ;     exit(0);   }   const int maxn = 1.0001e6;   const long long mod = 998244353;   long long n;   long long gt[maxn];   long long power(long long a, long long b) {     if (!b) return 1LL;     long long c = power(a, b >> 1);     c *= c;     c %= mod;     if (b & 1) {       c *= a;       c %= mod;     }     return c;   }   long long f(long long a, long long b) {     if (a == b) return 1;     return (gt[a] * power((gt[b] * gt[a - b]) % mod, mod - 2)) % mod;   }   void Fan_chipu() {     cin >> n;     gt[0] = 1;     for (int i = (int)(1); i <= (int)(maxn - 1); ++i)       gt[i] = gt[i - 1] * i, gt[i] %= mod;     long long ans = 0LL;     for (int i = (int)(0); i <= (int)(n); ++i) {       ans += (f(n, i) * (((gt[i] - i + mod) * gt[n - i]) % mod)) % mod;       ans %= mod;     }     cout << ans % mod <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(10);     cout << fixed;     Fan_chipu();   }


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


#include <bits/stdc++.h>   bool isVowel(char c) {     return (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u  ||             c ==  A  || c ==  E  || c ==  I  || c ==  O  || c ==  U  ||             c ==  y  || c ==  Y );   };   int main() {     char word[100];     scanf( %s , word);     int i;     int length;     length = strlen(word);     for (i = 0; i < length; i++) {       if (!isVowel(word[i])) {         printf( .%c , tolower(word[i]));       }     }     return 0;   }


#include <bits/stdc++.h>   struct node {     int v;     node *next;   } edge[400000 * 2 + 10], *adj[200000 + 10], *ecnt = &edge[0];   struct Edge {     int u, v;     Edge() {}     Edge(int u, int v) : u(u), v(v) {}   } e[400000 + 10], ans[400000 + 10];   int n, m, s, t, ds, dt, col[200000 + 10], cntcol, cnta, fa[200000 + 10],       belong[200000 + 10];   int able[2][200000 + 10], link[2][200000 + 10];   template <class T>   void Read(T &x) {     char c;     while (c = getchar(), c != EOF)       if (c >=  0  && c <=  9 ) {         x = c -  0 ;         while (c = getchar(), c >=  0  && c <=  9 ) x = x * 10 + c -  0 ;         ungetc(c, stdin);         return;       }   }   void read() {     Read(n), Read(m);     for (int i = 1; i <= m; i++) Read(e[i].u), Read(e[i].v);     Read(s), Read(t), Read(ds), Read(dt);   }   void addedge(int u, int v) {     node *p = ++ecnt;     p->v = v;     p->next = adj[u];     adj[u] = p;   }   void dfs(int u) {     col[u] = cntcol;     for (node *p = adj[u]; p; p = p->next)       if (!col[p->v]) dfs(p->v);   }   int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); }   void solve() {     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= m; i++) {       if (e[i].u == s || e[i].u == t || e[i].v == s || e[i].v == t) continue;       if (Find(e[i].u) != Find(e[i].v)) {         fa[Find(e[i].u)] = Find(e[i].v);         ans[++cnta] = e[i];         addedge(e[i].u, e[i].v), addedge(e[i].v, e[i].u);       }     }     for (int i = 1; i <= n; i++)       if (!col[i]) {         ++cntcol;         dfs(i);       }     for (int i = 1; i <= m; i++)       if (e[i].u == s || e[i].u == t || e[i].v == s || e[i].v == t)         addedge(e[i].u, e[i].v), addedge(e[i].v, e[i].u);     int cnts = 0, cntt = 0;     belong[col[s]]++;     for (node *p = adj[s]; p; p = p->next)       if (!belong[col[p->v]]) belong[col[p->v]]++;     belong[col[t]]++;     for (node *p = adj[t]; p; p = p->next)       if (!belong[col[p->v]]) {         ans[++cnta] = Edge(t, p->v), cntt++;         belong[col[p->v]] = -1;       } else if (belong[col[p->v]] == 1) {         belong[col[p->v]]++;         able[1][col[p->v]] = p->v;       }     for (node *p = adj[s]; p; p = p->next)       if (belong[col[p->v]] == 1) {         ans[++cnta] = Edge(s, p->v), cnts++;         belong[col[p->v]] = -1;       } else if (belong[col[p->v]] == 2)         able[0][col[p->v]] = p->v;     if (cnts > ds || cntt > dt)       puts( No );     else {       ds -= cnts, dt -= cntt;       bool f = false;       for (node *p = adj[s]; p; p = p->next)         if (belong[col[p->v]] == 2 && ds && p->v != t) {           ds--;           ans[++cnta] = Edge(s, p->v);           link[0][col[p->v]] = p->v;           belong[col[p->v]] = 0;         }       if (ds && dt && belong[col[t]] == 2) {         f = true;         ans[++cnta] = Edge(s, t);         belong[col[s]] = 0;         dt--;       }       for (node *p = adj[t]; p; p = p->next)         if (belong[col[p->v]] == 2 && p->v != s) {           if (!dt) {             puts( No );             return;           }           dt--;           ans[++cnta] = Edge(t, p->v);           link[1][col[p->v]] = p->v;           belong[col[p->v]] = 0;         }       if (!f && dt && ds && belong[col[s]] == 2) {         f = true;         ans[++cnta] = Edge(s, t);         ds--;       }       if (!f && (ds || dt)) {         if (ds) {           for (int i = 1; i <= cntcol; i++)             if (able[0][i] && link[1][i]) {               f = true;               ans[++cnta] = Edge(s, able[0][i]);               break;             }         }         if (!f && dt) {           for (int i = 1; i <= cntcol; i++)             if (able[1][i] && link[0][i]) {               f = true;               ans[++cnta] = Edge(t, able[1][i]);               break;             }         }       }       if (f) {         puts( Yes );         for (int i = 1; i <= cnta; i++) printf( %d %d n , ans[i].u, ans[i].v);       } else         puts( No );     }   }   int main() {     read();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 0;     cin >> n;     int a = (int)sqrt(n);     if (a * a == n) {       cout << a * 4 << endl;     } else if (a * (a + 1) >= n) {       cout << a * 4 + 2 << endl;     } else {       cout << a * 4 + 4 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   void solve() {     string s;     cin >> s;     int cntr1 = 10, cntr2 = 10;     int wt1 = 0, wt2 = 0;     for (int i = 0; i < 10; i++) {       if (i % 2 == 0) {         if (s[i] ==  1  || s[i] ==  ? ) wt1++;       } else {         if (s[i] ==  1 ) wt2++;       }       int left_t1 = 0, left_t2 = 0;       for (int j = i + 1; j < 10; j++) {         if (j % 2 == 0) {           left_t1++;         } else {           left_t2++;         }       }       if (wt1 > wt2 + left_t2) {         cntr1 = i + 1;         break;       }       if (wt2 > wt1 + left_t1) {         cntr1 = i + 1;         break;       }     }     wt1 = 0, wt2 = 0;     for (int i = 0; i < 10; i++) {       if (i % 2 == 0) {         if (s[i] ==  1 ) wt1++;       } else {         if (s[i] ==  1  || s[i] ==  ? ) wt2++;       }       int left_t1 = 0, left_t2 = 0;       for (int j = i + 1; j < 10; j++) {         if (j % 2 == 0) {           left_t1++;         } else {           left_t2++;         }       }       if (wt1 > wt2 + left_t2) {         cntr2 = i + 1;         break;       }       if (wt2 > wt1 + left_t1) {         cntr2 = i + 1;         break;       }     }     cout << min(cntr1, cntr2);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t-- > 0) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n, a, b;     cin >> n >> a >> b;     long long int c = 0;     vector<long long int> v(n);     for (long long int i = 0; i < n; i++) cin >> v[i];     long long int ans = accumulate(v.begin(), v.end(), 0);     for (long long int i = 0; i < n; i++) {       if (v[i] == 1) {         if (a > 0)           a--, ans--;         else if (b > 0)           b--, c++, ans--;         else if (c > 0)           c--, ans--;       } else {         if (b >= 1) b--, ans -= 2;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = (int)2147483647;   const double PI = 2 * acos(0.0);   const long double eps = 1e-11;   int diri[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};   int dirk[] = {1, 0, -1, 0, 1, -1, 1, -1, 0};   int main() {     int n, m;     double k;     cin >> n >> m >> k;     k += eps;     map<string, int> mp;     for (int i = ((int)0); i <= ((int)n - 1); i++) {       string s;       int l;       cin >> s >> l;       if (l * k >= 100) mp[s] = (int)l * k;     }     for (int i = ((int)0); i <= ((int)m - 1); i++) {       string s;       cin >> s;       if (!mp[s]) mp[s] = 0;     }     cout << mp.size() << endl;     for (__typeof(mp).begin() it = (mp).begin(); it != (mp).end(); it++)       cout << it->first <<     << it->second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000500;   typedef struct treap *ptreap;   struct treap {     int v, c, y;     ptreap l, r;     treap() {}     treap(int v) : v(v), c(1), y(rand()), l(0), r(0) {}   };   int cnt(ptreap t) { return t ? t->c : 0; }   void recalc(ptreap t) {     if (t) t->c = cnt(t->l) + cnt(t->r) + 1;   }   void split(ptreap t, int key, ptreap &l, ptreap &r) {     if (!t) {       l = r = 0;       return;     }     int cur_key = cnt(t->l);     if (key < cur_key) {       split(t->l, key, l, t->l);       r = t;     } else {       split(t->r, key - cur_key - 1, t->r, r);       l = t;     }     recalc(t);   }   void merge(ptreap l, ptreap r, ptreap &t) {     if (!l || !r) {       t = l ? l : r;       return;     }     if (l->y < r->y) {       merge(l->r, r, l->r);       t = l;     } else {       merge(l, r->l, r->l);       t = r;     }     recalc(t);   }   void print(ptreap t) {     if (!t) return;     print(t->l);     cout << t->v;     print(t->r);   }   int n, m, val, r, cur, a[maxn];   ptreap t;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     srand(time(0));     cin >> n >> m;     for (int i = 0; i < m; ++i) {       cin >> a[i];       --a[i];     }     for (int i = 0; i < n; ++i) {       cin >> val;       if (val == -1) {         for (int j = 0; j < r; ++j) {           ptreap q, w;           split(t, a[j] - j, q, t);           split(q, a[j] - j - 1, w, q);           merge(w, t, t);         }         cur -= r;         while (r > 0 && a[r - 1] > cur - 1) --r;       } else {         ptreap tmp = new treap(val);         merge(t, tmp, t);         ++cur;         if (a[r] == cur - 1) ++r;       }     }     if (!cur)       cout <<  Poor stack! ;     else       print(t);     return 0;   }


////#include <iostream>   ////#include <cstdio>   ////#include <cstring>   ////#include <algorithm>   ////   ////#define LL long long   ////   ////LL gcd(LL a,LL b) {   ////    if(b == 0) return a;   ////    else return gcd(b,a % b);   ////}   ////   ////inline LL calc(LL x) {   ////    LL ret = 0;   ////    while(x) {   ////        ret += x % 10;   ////        x /= 10;   ////    }   ////    return ret;   ////}   ////   ////int main() {   ////    int T; scanf( %d ,&T);   ////    LL n,x;   ////    while(T--) {   ////        scanf( %lld ,&n);   ////        x = 0;   ////        for(LL i=n; i; i++) {   ////            if(gcd(i,calc(i)) >= 2) {   ////                printf( %lld n ,i);   ////                break;   ////            }   ////        }   ////    }   ////    return 0;   ////}   //   //#include <iostream>   //#include <cstring>   //#include <cstdio>   //#include <algorithm>   //#include <map>   //#define Maxn 100005   //using namespace std;   //int a[1005000];   //map<int,int> mp;   //int main(int argc,char* argv[]) {   //    int T; scanf( %d ,&T);   //   //    while(T--) {   //        mp.clear();   //        int k = 524288,tmp = k;   //        while (tmp) {   //            a[tmp] = 0;   //            tmp >>= 1;   //        }   //        int n,w,x,ans = 0;   //        cin >> n >> w;   //        for(int i=0; i<n; i++) cin >> x,a[x]++;   //        while(n) {   //            int tmp = k,sum = w;   //            while(tmp) {   //                if(a[tmp]) {   //                    int cnt = sum / tmp;   //                    cnt = min(cnt,a[tmp]);   //                    sum -= cnt * tmp;   //                    a[tmp] -= cnt;   //                    n -= cnt;   //                }   //                tmp >>= 1;   //            }   //            ans++;   //        }   //        cout << ans << endl;   //    }   //    return 0;   //}      #include <iostream>   #include <cstring>   #include <cstdio>   #define Maxn 1005   using namespace std;   int dp[Maxn][Maxn];   const int Mod = 1e9 + 7;      int solve(int n,int k,int total) {       if(n <= 0 || k <= 1) return 1;       else {           if(dp[n][k] == -1)               dp[n][k] = ((solve(n - 1,k,total) % Mod + solve(total - n,k - 1,total) % Mod)) % Mod;           return (dp[n][k] % Mod);       }   }      int main(int argc,char* argv[]) {       int T,n,k; scanf( %d ,&T);       while(T--) {           scanf( %d %d ,&n,&k);           memset(dp,-1,sizeof(dp));           cout << solve(n,k,n) << endl;       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     int n;     int fn[200005] = {};     int a, b, c;     vector<string> st(t);     for (int j = 0; j < t; j++) {       cin >> n;       int rn[n];       for (int i = 0; i < n; i++) {         cin >> rn[i];         fn[rn[i]] = i + 1;       }       string s =  1 ;       a = min(fn[1], fn[2]);       b = max(fn[1], fn[2]);       for (int i = 2; i <= n; i++) {         c = fn[i];         if (a >= c)           a = c;         else if (b <= c)           b = c;         if (b - a == i - 1)           s.insert(i - 1,  1 );         else           s.insert(i - 1,  0 );       }       st[j] = s;     }     for (int j = 0; j < t; j++) {       cout << st[j] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n + 1];     for (int i = 0; i < n; i++) {       int k;       cin >> k;       arr[k] = i + 1;     }     int m;     long long int vas = 0, pet = 0;     cin >> m;     for (int i = 0; i < m; i++) {       int k;       cin >> k;       vas += arr[k];       pet += n + 1 - arr[k];     }     cout << vas <<     << pet;     return 0;   }


#pragma GCC optimize( Ofast ,  unroll-loops ,  no-stack-protector )       #include <bits/stdc++.h>       using namespace std;      #define all(a) (a).begin(), (a).end()   #define sz(a) (int)(a).size()      using ll = long long;   using ld = long double;    // using ld = __float128;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using uint = unsigned int;   using ull = unsigned long long;      mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   default_random_engine generator;      void solve();      int main() {   #ifdef LOCAL       freopen( input.txt ,  r , stdin);       // freopen( output.txt ,  w , stdout);    #endif           ios_base::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);       cout << setprecision(10) << fixed;       cerr << setprecision(10) << fixed;          int tests = 1;       // cin >> tests;          for (int test = 1; test <= tests; ++test) {           // cout <<  Case #  << test <<  :  ;           solve();       }      #ifdef LOCAL       cerr <<  Time:   << double(clock()) / CLOCKS_PER_SEC << endl;   #endif   }      // -----------------------------------------------------------------       const int MAXN = 200200;   vector<int> g[MAXN];   int w[MAXN];      vector<int> arr;   int dfs(int v, int p = -1) {       arr.push_back(v);       w[v] = 1;       for (int u : g[v]) {           if (u == p) {               continue;           }           w[v] += dfs(u, v);       }       return w[v];   }      vector<int> f;      bool check(int root, int k) {       arr.clear();       dfs(root);       if (sz(arr) != f[k]) {           return false;       }       if (k <= 1) {           return true;       }          for (int v : arr) {           if (w[v] == f[k - 1] || w[v] == f[k - 2]) {               int u;               for (int uu : g[v]) {                   if (w[uu] > w[v]) {                       u = uu;                   }               }                  for (int i = 0; i < sz(g[u]); ++i) {                   if (g[u][i] == v) {                       swap(g[u][i], g[u].back());                       g[u].pop_back();                       break;                   }               }               for (int i = 0; i < sz(g[v]); ++i) {                   if (g[v][i] == u) {                       swap(g[v][i], g[v].back());                       g[v].pop_back();                       break;                   }               }                  if (w[v] == f[k - 1]) {                   if (!check(v, k - 1)) {                       return false;                   }                   if (!check(u, k - 2)) {                       return false;                   }               } else {                   if (!check(v, k - 2)) {                       return false;                   }                   if (!check(u, k - 1)) {                       return false;                   }               }               return true;           }       }       return false;   }      void solve() {         int n;       cin >> n;          int k = 2;       f = {1, 1};       for (; f.back() < n; ++k) {           f.push_back(f[k - 2] + f[k - 1]);       }          for (int i = 1; i < n; ++i) {           int u, v;           cin >> u >> v;           --u; --v;           g[u].push_back(v);           g[v].push_back(u);       }          cout << (check(0, sz(f) - 1) ?  YES n  :  NO n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int v;     cin >> v;     v == 1 || v == 2 ? cout << v : cout << 1;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, j;     cin >> t;     for (j = 0; j < t; j++) {       long long a, b, c, p = 0, r = 0;       cin >> a >> b >> c;       if (a >= c)         p = -1;       else         p = 1;       if ((c / b) >= a)         r = -1;       else         r = b;       cout << p <<     << r << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   namespace io {   template <class T>   void re(complex<T>& x);   template <class T1, class T2>   void re(pair<T1, T2>& p);   template <class T>   void re(vector<T>& a);   template <class T, size_t SZ>   void re(array<T, SZ>& a);   template <class T>   void re(T& x) {     cin >> x;   }   void re(double& x) {     string t;     re(t);     x = stod(t);   }   void re(ld& x) {     string t;     re(t);     x = stold(t);   }   template <class T, class... Ts>   void re(T& t, Ts&... ts) {     re(t);     re(ts...);   }   template <class T>   void re(complex<T>& x) {     T a, b;     re(a, b);     x = {a, b};   }   template <class T1, class T2>   void re(pair<T1, T2>& p) {     re(p.f, p.s);   }   template <class T>   void re(vector<T>& a) {     for (int i = (0) - (1 - 2 * (0 > ((int)a.size())) < 0);          (1 - 2 * (0 > ((int)a.size()))) > 0 ? i < (((int)a.size()))                                              : i >= (((int)a.size()));          i += (1 - 2 * (0 > ((int)a.size()))))       re(a[i]);   }   template <class T, size_t SZ>   void re(array<T, SZ>& a) {     for (int i = (0) - (1 - 2 * (0 > SZ) < 0);          (1 - 2 * (0 > SZ)) > 0 ? i < (SZ) : i >= (SZ); i += (1 - 2 * (0 > SZ)))       re(a[i]);   }   void pr(int x) { cout << x; }   void pr(long x) { cout << x; }   void pr(ll x) { cout << x; }   void pr(unsigned x) { cout << x; }   void pr(unsigned long x) { cout << x; }   void pr(unsigned long long x) { cout << x; }   void pr(float x) { cout << x; }   void pr(double x) { cout << x; }   void pr(ld x) { cout << x; }   void pr(char x) { cout << x; }   void pr(const char* x) { cout << x; }   void pr(const string& x) { cout << x; }   void pr(bool x) { pr(x ?  true  :  false ); }   template <class T>   void pr(const complex<T>& x) {     cout << x;   }   template <class T1, class T2>   void pr(const pair<T1, T2>& x);   template <class T>   void pr(const T& x);   template <class T, class... Ts>   void pr(const T& t, const Ts&... ts) {     pr(t);     pr(ts...);   }   template <class T1, class T2>   void pr(const pair<T1, T2>& x) {     pr( { , x.f,  ,  , x.s,  } );   }   template <class T>   void pr(const T& x) {     pr( { );     bool fst = 1;     for (const auto& a : x) pr(!fst ?  ,   :   , a), fst = 0;     pr( } );   }   void ps() { pr(  n ); }   template <class T, class... Ts>   void ps(const T& t, const Ts&... ts) {     pr(t);     if (sizeof...(ts)) pr(   );     ps(ts...);   }   void pc() { pr( ] n ); }   template <class T, class... Ts>   void pc(const T& t, const Ts&... ts) {     pr(t);     if (sizeof...(ts)) pr( ,  );     pc(ts...);   }   }  // namespace io   using namespace io;   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   ll n;   unordered_map<ll, vector<int>> mp;   int find(int u, int v) {     if (u == v) return mp[v].size();     int n = ((int)mp[u].size()), m = ((int)mp[v].size());     int i = 0, j = 0, ans = 1, last;     bool cur = 0;     if (mp[u][i] < mp[v][j]) {       cur = 0;       last = mp[u][i];       i++;     } else {       cur = 1;       last = mp[v][j], j++;     }     while (i < n or j < m) {       if (i == n) {         if (cur == 0 and last < mp[v].back())           return ans + 1;         else           return ans;       } else if (j == m) {         if (cur == 1 and last < mp[u].back()) {           return ans + 1;         } else           return ans;       } else if (cur == 0) {         while (j < m and mp[v][j] < last) j++;         if (j < m) last = mp[v][j], ans++, j++, cur = 1;       } else {         while (i < n and mp[u][i] < last) i++;         if (i < n) last = mp[u][i], ans++, i++, cur = 0;       }     }     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     re(n);     int a[n];     unordered_set<ll> st;     for (int i = (0) - (1 - 2 * (0 > n) < 0);          (1 - 2 * (0 > n)) > 0 ? i < (n) : i >= (n); i += (1 - 2 * (0 > n)))       re(a[i]), mp[a[i]].push_back(i), st.insert(a[i]);     int ans = 0;     vector<int> ss;     for (auto i : st) ss.push_back(i);     for (int ii = (0) - (1 - 2 * (0 > ((int)ss.size())) < 0);          (1 - 2 * (0 > ((int)ss.size()))) > 0 ? ii < (((int)ss.size()))                                               : ii >= (((int)ss.size()));          ii += (1 - 2 * (0 > ((int)ss.size())))) {       for (int jj = (ii) - (1 - 2 * (ii > ((int)ss.size())) < 0);            (1 - 2 * (ii > ((int)ss.size()))) > 0 ? jj < (((int)ss.size()))                                                  : jj >= (((int)ss.size()));            jj += (1 - 2 * (ii > ((int)ss.size())))) {         int i = ss[ii], j = ss[jj];         ckmax(ans, find(i, j));       }     }     ps(ans);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   multiset<int> gr[maxn];   vector<int> order, odd;   int n, m;   void go(int cur) {     for (auto it = gr[cur].begin(); gr[cur].size() != 0; it = gr[cur].begin()) {       int v = *it;       gr[cur].erase(it);       gr[v].erase(gr[v].find(cur));       go(v);     }     order.push_back(cur);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       a--, b--;       gr[a].insert(b);       gr[b].insert(a);     }     for (int i = 0; i < n; i++)       if (gr[i].size() % 2 != 0) odd.push_back(i);     for (int i = 0; i < (int)odd.size() / 2; i++) {       gr[odd[2 * i]].insert(odd[2 * i + 1]);       gr[odd[2 * i + 1]].insert(odd[2 * i]);     }     if ((odd.size() / 2 + m) % 2 == 1) {       gr[0].insert(0);       gr[0].insert(0);     }     go(0);     printf( %d n , order.size() - 1);     for (int i = 0; i < (int)order.size() - 1; i++) {       if (i % 2 == 0)         printf( %d %d n , order[i] + 1, order[i + 1] + 1);       else         printf( %d %d n , order[i + 1] + 1, order[i] + 1);     }     return 0;   }


#include <iostream>   #include <iomanip>   #include <cstdio>   #include <vector>   #include <algorithm>   #include <cmath>   #include <cstring>   #include <cassert>   #include <string>   #include <set>   #include <map>   #include <random>   #include <bitset>   #include <string>   #include <unordered_set>   #include <unordered_map>   #include <deque>   #include <queue>   #define rep(i, n) for (int i = 0; i < (n); i++)   #define all(x) (x).begin(), (x).end()   #define rall(x) (x).rbegin(), (x).rend()      using namespace std;   using ll = long long;   using ul = unsigned long long;   using ld = long double;      const int MOD = 998244353, N = 100002;   ll f[N], rf[N];      ll pw(ll x, ll k) {     ll r = 1;     while (k) {       if (k & 1)         r = r * x % MOD;       x = x * x % MOD;       k >>= 1;     }     return r;   }      ll c(ll n, ll k) {     return f[n] * rf[k] % MOD * rf[n - k] % MOD;   }      int main() {     ios_base::sync_with_stdio(0); cin.tie(0);     f[0] = 1;     for (int i = 1; i < N; ++i)       f[i] = f[i - 1] * i % MOD;     rf[N - 1] = pw(f[N - 1], MOD - 2);     for (int i = N - 1; i > 0; --i)       rf[i - 1] = rf[i] * i % MOD;     int t, n;     cin >> t;     while (t--) {       string s;       cin >> n >> s;       int l = 1, z = 0, g = 0;       rep(i, n)         if (s[i] ==  0 ) {           z++;           if (l == i % 2)             g++;           l = i % 2;         }       cout << c((n - z - g) / 2 + z, z) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e6 + 50;   vector<int> v;   int vis[N] = {0}, n;   int flag[N] = {0}, ans = 0;   void dfs(int k) {     if (vis[k]) return;     vis[k] = 1;     if (flag[k]) dfs(k ^ ((1 << n) - 1));     for (int i = 0; i < n; i++)       if ((1 << i) & k) dfs(k ^ (1 << i));   }   int main() {     int m;     scanf( %d %d , &n, &m);     int temp;     for (int i = 1; i <= m; i++) {       scanf( %d , &temp);       v.push_back(temp);       flag[temp] = 1;     }     for (auto vv : v) {       if (!vis[vv]) {         ans++;         vis[vv] = 1;         dfs(vv ^ ((1 << n) - 1));       }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int cnt[10];   int main() {     int n;     while (scanf( %d , &n) != EOF) {       int sum = 0;       memset(cnt, 0, sizeof(cnt));       for (int i = 0; i < n; i++) {         int j;         scanf( %d , &j);         cnt[j]++;         sum += j;       }       int ans = -1;       for (int i = 0; i <= n; i++)         if (4 * i <= sum && (sum - 4 * i) % 3 == 0 &&             (sum - 4 * i) / 3 <= n - i) {           int j = (sum - 4 * i) / 3;           int cost = min(max(cnt[4] - i, 0), j);           int p = cnt[1] + cnt[2] + cnt[3] + cnt[4];           for (int k = 1; k <= 4 && p > i + j; k++) {             cost += min(p - i - j, cnt[k]) * k;             p -= min(p - i - j, cnt[k]);           }           if (cost < ans || ans == -1) ans = cost;         }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   struct node {     int v, nxt;   } edge[maxn << 1];   int first[maxn], tot = 0;   void add(int u, int v) {     edge[++tot].v = v;     edge[tot].nxt = first[u];     first[u] = tot;   }   int n, m;   double dp[maxn], p[maxn], ans = 0;   int f[maxn];   void dfs(int u, int fa) {     ans += (1.0 - p[u]) * p[fa];     for (int i = first[u]; i; i = edge[i].nxt) {       int v = edge[i].v;       if (v == fa) continue;       dfs(v, u);       f[v] = u;       dp[u] += 1.0 - p[v];     }   }   int main() {     scanf( %d , &n);     p[0] = 1.0;     for (int i = 1; i <= n; i++) scanf( %lf , &p[i]);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       x++, y++;       add(x, y);       add(y, x);     }     dfs(1, 0);     scanf( %d , &m);     while (m--) {       int u;       double pp;       scanf( %d%lf , &u, &pp);       u++;       ans -= dp[u] * p[u] + (1.0 - p[u]) * p[f[u]];       dp[f[u]] -= 1.0 - p[u];       p[u] = pp;       ans += dp[u] * p[u] + (1.0 - p[u]) * p[f[u]];       dp[f[u]] += 1.0 - p[u];       printf( %.5f n , ans);     }     return 0;   }


#include <bits/stdc++.h>   int main() {     puts( INTERCAL );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Ask(int x1, int y1, int x2, int y2, bool rot = false) {     if (!rot) {       cout <<  ?   << x1 <<     << y1 <<     << x2 <<     << y2 << endl;     } else {       cout <<  ?   << y1 <<     << x1 <<     << y2 <<     << x2 << endl;     }   }   int Find(int n, bool rot) {     int l = 1, r = n;     while (l < r) {       int m = (l + r) >> 1;       Ask(1, 1, m, n, rot);       int res;       cin >> res;       if (res == 0) {         l = m + 1;       } else {         r = m;       }     }     Ask(1, 1, l, n, rot);     int res;     cin >> res;     if (res != 1) {       return -1;     }     int v = l;     ++l;     r = n;     while (l < r) {       int m = (l + r) >> 1;       Ask(l, 1, m, n, rot);       int res;       cin >> res;       if (res == 0) {         l = m + 1;       } else {         r = m;       }     }     Ask(v + 1, 1, l, n, rot);     cin >> res;     if (res != 1) {       return -1;     }     return v;   }   int FindR(int x1, int y1, int x2, int y2, bool rot) {     int l = x1, r = x2;     while (l < r) {       int m = (l + r) >> 1;       Ask(x1, y1, m, y2, rot);       int res;       cin >> res;       if (res == 0) {         l = m + 1;       } else {         r = m;       }     }     return l;   }   int FindL(int x1, int y1, int x2, int y2, bool rot) {     int l = x1, r = x2;     while (l < r) {       int m = (l + r + 1) >> 1;       Ask(m, y1, x2, y2, rot);       int res;       cin >> res;       if (res == 0) {         r = m - 1;       } else {         l = m;       }     }     return l;   }   int FindD(int x1, int y1, int x2, int y2, bool rot) {     int l = y1, r = y2;     while (l < r) {       int m = (l + r) >> 1;       Ask(x1, y1, x2, m, rot);       int res;       cin >> res;       if (res == 0) {         l = m + 1;       } else {         r = m;       }     }     return l;   }   int FindU(int x1, int y1, int x2, int y2, bool rot) {     int l = y1, r = y2;     while (l < r) {       int m = (l + r + 1) >> 1;       Ask(x1, m, x2, y2, rot);       int res;       cin >> res;       if (res == 0) {         r = m - 1;       } else {         l = m;       }     }     return l;   }   int main() {     std::ios_base::sync_with_stdio(false);     int n;     cin >> n;     bool rot = false;     int line = Find(n, rot);     if (line == -1) {       rot = true;       line = Find(n, rot);     }     int x11 = FindL(1, 1, line, n, rot);     int x12 = FindR(1, 1, line, n, rot);     int y11 = FindU(1, 1, line, n, rot);     int y12 = FindD(1, 1, line, n, rot);     int x21 = FindL(line + 1, 1, n, n, rot);     int x22 = FindR(line + 1, 1, n, n, rot);     int y21 = FindU(line + 1, 1, n, n, rot);     int y22 = FindD(line + 1, 1, n, n, rot);     if (rot) {       swap(x11, y11);       swap(x12, y12);       swap(x21, y21);       swap(x22, y22);     }     cout <<  !   << x11 <<     << y11 <<     << x12 <<     << y12;     cout <<     << x21 <<     << y21 <<     << x22 <<     << y22 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solution() {     int n, k, i, j, sum = 0;     cin >> n >> k;     string s;     cin >> s;     if (k == 2) {       int c1 = 0, c2 = 0;       for (i = 0; i < n; i++) {         c1 += abs(s[i] - 65 - (i % 2));         c2 += abs(s[i] - 65 - (i + 1) % 2);       }       if (c1 < c2) {         cout << c1 <<   n ;         for (i = 0; i < n; i++) cout << (char)(65 + i % 2);       } else {         cout << c2 <<   n ;         for (i = 0; i < n; i++) cout << (char)(65 + (i + 1) % 2);       }       return;     }     for (i = 0; i < n - 1; i++) {       char c =  A ;       if (s[i] == s[i + 1]) {         sum++;         while (s[i + 2] == c || s[i] == c) {           c = (char)(c + 1);         }         s[i + 1] = c;       }     }     cout << sum <<   n  << s;   }   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       solution();     }     cerr <<   n  << (float)clock() / CLOCKS_PER_SEC * 1000 <<   ms  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1100;   const long long M = 260;   const long long mod = 998244353;   const long long MOD = 998244353;   const long double eps = 0.000000001;   const long long P = 1336;   const long long inf = 1e16;   mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());   long long n, k;   vector<pair<long long, long long> > a;   long long dp[N][N];   long long solve(long long x) {     for (long long j = 0; j < k; j++) {       for (long long i = 0; i < n; i++) {         dp[j][i] = 0;         if (j == 0) dp[j][i] = 1;       }     }     long long ans = 0;     for (long long j = 1; j < k; j++) {       long long uk = 0, s = 0;       for (long long i = 0; i < n; i++) {         while (uk < n && a[uk].first + x <= a[i].first) {           s += dp[j - 1][uk];           s %= mod;           uk++;         }         dp[j][i] = s;         if (j == k - 1) {           ans += dp[j][i];           ans %= mod;         }       }     }     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     srand(time(0));     cin >> n >> k;     a.resize(n);     long long ma = 0;     for (long long i = 0; i < n; i++) {       cin >> a[i].first;       ma = max(ma, a[i].first);       a[i].second = i;     }     sort(a.begin(), a.end());     long long ans = 0, s = 0;     for (long long i = ma / (k - 1); i >= 1; i--) {       long long c = solve(i);       c -= s;       c += mod;       c %= mod;       s += c;       s %= mod;       c *= i;       c %= mod;       ans += c;       ans %= mod;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using uint = unsigned int;   using ull = unsigned long long;   template <typename T>   using pair2 = pair<T, T>;   using pii = pair<int, int>;   using pli = pair<ll, int>;   using pll = pair<ll, ll>;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   inline void fmin(ll &x, ll y) {     if (y < x) x = y;   }   inline void fmax(ll &x, ll y) {     if (y > x) x = y;   }   double startTime;   double getCurrentTime() {     return ((double)clock() - startTime) / CLOCKS_PER_SEC;   }   const ll INF = 0x3f3f3f3f3f3f3f3f;   const int N = 100100;   const int M = (1 << 7) + 7;   vector<int> a[N];   int n, k, p;   int ppc[M];   ll dp[2][M];   int main() {     for (int i = 0; i < M; i++) ppc[i] = ppc[i / 2] + (i & 1);     scanf( %d%d%d , &n, &p, &k);     for (int i = 0; i < n; i++) {       a[i].resize(p + 1);       scanf( %d , &a[i][0]);     }     for (int i = 0; i < n; i++)       for (int j = 1; j <= p; j++) scanf( %d , &a[i][j]);     sort(a, a + n);     reverse(a, a + n);     for (int mask = 0; mask < 1 << p; mask++) dp[0][mask] = -INF;     dp[0][0] = 0;     for (int i = 0; i < n; i++) {       for (int mask = 0; mask < 1 << p; ++mask) dp[1][mask] = -INF;       for (int mask = 0; mask < (1 << p); ++mask) {         for (int j = 0; j < p; j++) {           if (mask & (1 << j)) continue;           fmax(dp[1][mask | (1 << j)], dp[0][mask] + a[i][j + 1]);         }         ll w = dp[0][mask];         if (ppc[mask] + k > i) w += a[i][0];         fmax(dp[1][mask], w);       }       for (int mask = 0; mask < (1 << p); ++mask) dp[0][mask] = dp[1][mask];     }     printf( %lld n , dp[0][(1 << p) - 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[200005];   int sz[200005];   int n, k;   long long int ans;   void dfs(int u, int p) {     for (int v : adj[u]) {       if (v == p) continue;       dfs(v, u);       sz[u] += sz[v];       ans += min(sz[v], 2 * k - sz[v]);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (int i = 0; i < 2 * k; i++) {       int x;       cin >> x;       sz[x] = 1;     }     int u, v;     for (int i = 0; i < n - 1; i++) {       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1, 0);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int spf[5000002];   int f[5000002];   void init() {     spf[0] = spf[1] = 1;     for (int i = 2; i < 5000002; ++i) {       if (spf[i] == 0) {         spf[i] = i;         long long int start = 1LL * i * i;         for (long long int j = start; j < 5000002; j += i) {           if (spf[j] == 0) spf[j] = i;         }       }     }     f[0] = f[1] = 0;     for (int i = 2; i < 5000002; ++i) {       int x = spf[i];       int y = i / x;       long long int val = 1LL * y * x * (x - 1) / 2 + f[y];       f[i] = val % 1000000007;     }   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(NULL);     init();     int t, l, r;     cin >> t >> l >> r;     long long int ans = 0, mul = 1;     for (int i = 0; i <= r - l; ++i) {       ans = ans + (mul * f[i + l]) % 1000000007;       mul = (mul * t) % 1000000007;     }     cout << ans % 1000000007 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   long long mas[1000100];   long long dmas[1000100];   int main() {     ios::sync_with_stdio(0);     int n;     cin >> n;     long long x;     long long ans = -100000000000000000;     int ansl, ansr;     for (int i = 0; i < n; ++i) {       cin >> x;       dmas[i] = x;       if (x >= 0) mas[i] = x;       if (i > 0) mas[i] += mas[i - 1];       if (mp.count(x) == 0)         mp[x] = i;       else {         long long d = 0;         if (x < 0) d = x * 2;         ans = max(ans, mas[i] - mas[mp[x] - 1] + d);         if (ans == mas[i] - mas[mp[x] - 1] + d) {           ansl = mp[x];           ansr = i;         }       }     }     cout << ans <<    ;     int c = 0;     for (int i = 0; i < n; ++i) {       if (i < ansl)         ++c;       else if (i > ansr)         ++c;       else if (i < ansr && i > ansl && dmas[i] < 0)         ++c;     }     cout << c <<   n ;     for (int i = 0; i < n; ++i) {       if (i < ansl)         cout << i + 1 <<    ;       else if (i > ansr)         cout << i + 1 <<    ;       else if (i < ansr && i > ansl && dmas[i] < 0)         cout << i + 1 <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000 * 1000 * 1000 + 7;   const int INF = 2000 * 1000 * 1000;   const double EPS = 1e-9;   const double pi = acos(-1.0);   const int maxn = 1010;   const int maxsum = 10010;   template <typename T>   inline T sqr(T n) {     return (n * n);   }   int n, a[maxn], mem[maxn][2 * maxsum];   int* dp[maxn];   long long ans;   int main() {     scanf( %d , &n);     dp[0] = mem[0] + maxsum;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       dp[i] = mem[i] + maxsum;     }     dp[0][0] = 1;     ans = 0;     for (int i = 1; i <= n; i++) {       for (int sum = -10000; sum <= 10000; sum++) {         if (sum + a[i] <= 10000) dp[i][sum] += dp[i - 1][sum + a[i]];         if (sum - a[i] >= -10000) dp[i][sum] += dp[i - 1][sum - a[i]];         dp[i][sum] %= MOD;       }       ans += dp[i][0];       ans %= MOD;       dp[i][0]++;     }     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   const int mod = 1000000007;   using namespace std;   long long c[100005];   int v[100005];   set<int> s;   int n, k;   long long all, ans;   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %I64d , &c[i]);     for (int i = 0; i < k; i++) scanf( %d , &v[i]);     all = 0;     ans = 0;     for (int i = 1; i <= n; i++) all += c[i];     for (int i = 1; i < n; i++) ans += c[i] * c[i + 1];     ans += c[n] * c[1];     s.clear();     for (int i = 0; i < k; i++) {       all -= c[v[i]];       s.insert(v[i]);       long long tmp = all;       if (v[i] < n && s.find(v[i] + 1) == s.end()) tmp -= c[v[i] + 1];       if (v[i] == n && s.find(1) == s.end()) tmp -= c[1];       if (v[i] > 1 && s.find(v[i] - 1) == s.end()) tmp -= c[v[i] - 1];       if (v[i] == 1 && s.find(n) == s.end()) tmp -= c[n];       ans += c[v[i]] * tmp;     }     printf( %I64d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 1;   const int N = 200123;   int z, n, s;   deque<int> dq;   int t[N];   int main() {     ios_base::sync_with_stdio(0);     int ans = 0;     cin >> n >> s;     for (int i = 0; i < n; i++) {       cin >> t[i];       if (i + 1 == s) {         ans += (t[i] != 0);         n--;         i--;         s = inf;       } else if (t[i] == 0)         t[i] = n + 5;     }     sort(t, t + n);     for (int i = 0; i < n; i++) {       dq.push_back(t[i]);     }     int nxt = 1;     while (dq.size()) {       while (dq.size() && nxt < dq.front()) {         dq.pop_back();         nxt++;         ans++;       }       if (dq.size()) {         nxt = max(nxt, dq.front() + 1);         dq.pop_front();       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s, idx;     cin >> n >> s;     s--;     int a[n], b[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       cin >> b[i];     }     if (a[0] == 1) {       for (int i = 0; i < n; i++) {         if (i == s && a[i] == 1) {           cout <<  YES ;           return 0;         } else if (i > s && a[i] == 1 && b[i] == 1) {           for (int j = i; j >= 0; j--) {             if (j == s && b[j] == 1) {               cout <<  YES ;               return 0;             }           }         }       }     }     cout <<  NO ;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int s, n;       cin >> s >> n;       int temp = s, p = 1;       while (temp > 0) {         temp /= 10;         p *= 10;       }       p /= 10;       while (n > 1) {         if (s - p >= n - 1) {           cout << p <<    ;           s -= p;           n--;         } else           p /= 10;       }       cout << s << endl;     }   }


#include <bits/stdc++.h>   const double PI = 3.141592653589793238463;   using namespace std;   inline long long add(long long a, long long b) {     a += b;     if (a >= 1000000007) a -= 1000000007;     return a;   }   inline long long sub(long long a, long long b) {     a -= b;     if (a < 0) a += 1000000007;     return a;   }   inline long long mul(long long a, long long b) {     return (long long)((long long)a * b % 1000000007);   }   long long fast_power(long long base, long long power) {     long long result = 1;     while (power > 0) {       if (power % 2 == 1) {         result = (result * base) % 1000000007;       }       base = (base * base) % 1000000007;       power = power / 2;     }     return result;   }   long long min(long long a, long long b) { return a > b ? b : a; }   long long max(long long a, long long b) { return a > b ? a : b; }   void dfs(long long s, vector<vector<long long>> &adj, vector<bool> &vis,            vector<long long> &arr) {     if (vis[s]) return;     vis[s] = true;     arr.push_back(s);     for (auto x : adj[s]) {       if (vis[x] == false) {         dfs(x, adj, vis, arr);       }     }   }   void bfs(long long x, vector<bool> &vis, vector<vector<long long>> &adlist,            vector<long long> &level, vector<long long> &parent) {     queue<long long> q;     vis[x] = true;     q.push(x);     while (!q.empty()) {       long long s = q.front();       q.pop();       for (auto u : adlist[s]) {         if (vis[u]) continue;         vis[u] = true;         parent[u] = s;         level[u] = level[s] + 1;         q.push(u);       }     }   }   bool bpchk(vector<vector<long long>> &adj, vector<long long> &color) {     color[1] = 1;     queue<long long> q;     q.push(1);     while (!q.empty()) {       long long u = q.front();       q.pop();       for (auto x : adj[u]) {         if (color[x] == -1) {           color[x] = color[u] ^ 1;           q.push(x);         }       }     }     for (long long i = 1; i < adj.size(); i++) {       for (auto x : adj[i]) {         if (color[x] == color[i]) return false;       }     }     return true;   }   void swap(long long *a, long long *b) {     long long tmp = *a;     *a = *b;     *b = tmp;   }   void SieveOfEratosthenes(long long n, set<long long> &s) {     vector<bool> prime(n + 1, true);     for (long long p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (long long i = p * p; i <= n; i += p) prime[i] = false;       }     }     for (long long p = 2; p <= n; p++)       if (prime[p]) s.insert(p);   }   vector<long long> r(1000, 0), c(1000, 0);   vector<long long> rsum(1e6 + 1, 0), csum(1e6 + 1, 0);   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, k, p;     cin >> n >> m >> k >> p;     long long temp;     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         cin >> temp;         r[i] += temp;         c[j] += temp;       }     }     priority_queue<long long> rs, cs;     for (long long i = 0; i < n; i++) {       rs.push(r[i]);     }     for (long long i = 0; i < m; i++) {       cs.push(c[i]);     }     for (long long i = 1; i <= k; i++) {       rsum[i] = rs.top() + rsum[i - 1];       temp = rs.top();       rs.pop();       temp -= m * p;       rs.push(temp);       csum[i] = cs.top() + csum[i - 1];       temp = cs.top();       cs.pop();       temp -= n * p;       cs.push(temp);     }     long long ans = LLONG_MIN;     for (long long i = 0; i <= k; i++) {       ans = max(ans, rsum[i] + csum[k - i] - i * (k - i) * p);     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 150005;   const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;   const double pi = 3.14159265359;   int n, t[maxn], ans, cnt;   vector<int> v, vp;   inline bool check(const vector<int> &vt) {     for (const int &i : vt) {       if (i == 0) {         if (t[i] >= t[i + 1])           return false;         else           continue;       } else if (i == n - 1) {         if (i % 2 == 0 && t[i] >= t[i - 1])           return false;         else if (i % 2 == 1 && t[i] <= t[i - 1])           return false;         else           continue;       } else if (i % 2 == 1 && (t[i] <= t[i - 1] || t[i] <= t[i + 1]))         return false;       else if (i % 2 == 0 && (t[i] >= t[i - 1] || t[i] >= t[i + 1]))         return false;     }     return true;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &t[i]);     if (t[0] < t[1])       vp.push_back(0);     else {       cnt++;       v.push_back(0);     }     if ((n - 1) % 2 == 0 && t[n - 1] < t[n - 2])       vp.push_back(n - 1);     else if ((n - 1) % 2 == 1 && t[n - 1] > t[n - 2])       vp.push_back(n - 1);     else {       cnt++;       v.push_back(n - 1);     }     for (int i = int(1); i < int(n - 1); i++) {       if (i % 2 == 0 && t[i] < t[i - 1] && t[i] < t[i + 1])         vp.push_back(i);       else if (i % 2 == 1 && t[i] > t[i - 1] && t[i] > t[i + 1])         vp.push_back(i);       else {         cnt++;         v.push_back(i);       }     }     if (v.size() > 6) {       printf( %d n , 0);       exit(0);     }     for (int i = 0; i < v.size() - 1; i++) {       for (int j = int(i + 1); j < int(v.size()); j++) {         swap(t[v[i]], t[v[j]]);         if (check(v)) ans++;         swap(t[v[i]], t[v[j]]);       }     }     for (const int &i : v) {       for (const int &j : vp) {         swap(t[i], t[j]);         vector<int> vt(v);         vt.push_back(j);         if (check(vt)) ans++;         swap(t[i], t[j]);       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename F>   class SegTree {     int n;     T uni;     F f;     vector<T> dat;       public:     SegTree(int _n, F f, T uni) : f(f), uni(uni) {       n = 1;       while (n < _n) n *= 2;       dat = vector<T>(2 * n, uni);     }     void set(int k, const T x) { dat[k + n] = x; }     void build() {       for (int i = n - 1; i >= 0; i--) {         dat[i] = f(dat[2 * i], dat[2 * i + 1]);       }     }     void update(int k, T x) {       k += n;       dat[k] = x;       while (k >>= 1) {         dat[k] = f(dat[2 * k], dat[2 * k + 1]);       }     }     T query(int a, int b) {       T l = uni, r = uni;       for (a += n, b += n; a < b; a >>= 1, b >>= 1) {         if (a & 1) l = f(l, dat[a++]);         if (b & 1) r = f(dat[--b], r);       }       return f(l, r);     }   };   int main() {     int n, k, d;     scanf( %d %d %d , &n, &k, &d);     int a[n];     for (int i = 0; i < (int)n; i++) scanf( %d , &a[i]);     sort(a, a + n);     auto f = [](int a, int b) { return a + b; };     SegTree<int, decltype(f)> st(n + 1, f, 0);     st.update(0, 1);     for (int i = 0; i < (int)n; i++) {       int l = lower_bound(a, a + n, a[i] - d) - a;       int r = max(0, i - k + 2);       if (st.query(l, r) > 0) st.update(i + 1, 1);     }     cout << (st.query(n, n + 1) ?  YES  :  NO ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, w, s, a[110];   int in[110], out[110];   int main() {     scanf( %d%d , &n, &w);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       s += a[i];     }     if (n == 1 && w == a[0]) {       puts( Yes );       for (int i = 0; i < w * 2; i++) {         printf( 1  );       }     } else if (n >= 2 && w >= 2 && w <= s) {       in[0] = a[0] - 1;       in[1] = a[1] - 1;       for (int i = 2; i < n; i++) {         in[i] = a[i];       }       for (int i = 0; i < n; i++) {         int x = min(w - 2, in[i]);         in[i] -= x;         out[i] += x;         w -= x;       }       puts( Yes );       for (int i = 0; i < n; i++) {         for (int j = 0; j < out[i] * 2; j++) {           printf( %d  , i + 1);         }       }       printf( 1  );       for (int i = 1; i < n; i++) {         for (int j = 0; j < in[i] * 2; j++) {           printf( %d  , i + 1);         }       }       printf( 1 2  );       for (int i = 0; i < in[0] * 2; i++) {         printf( 1  );       }       puts( 2 );     } else if (n >= 2 && w == 1) {       int k = 0;       while (k < n && a[k] != 1) {         k++;       }       if (k == n) {         puts( No );       } else {         puts( Yes );         printf( %d  , k + 1);         for (int i = 0; i < n; i++) {           if (i == k) {             continue;           }           for (int j = 0; j < a[i] * 2; j++) {             printf( %d  , i + 1);           }         }         printf( %d n , k + 1);       }     } else {       puts( No );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char ar[1002][1002];     int n, m, i, j, count, ar1[1002];     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++) {       scanf( %s , ar[i]);     }     for (i = 0; i < m; i++) {       ar1[i] = 1;     }     for (i = 1; i < n; i++) {       for (j = 0; j < m; j++) {         if (ar1[j] == 1) {           if (ar[i][j] < ar[i - 1][j]) {             ar1[j] = 0;             i = 0;             break;           }           if (ar[i][j] > ar[i - 1][j]) {             break;           }         }       }     }     count = 0;     for (i = 0; i < m; i++) {       count += 1 - ar1[i];     }     printf( %d n , count);     return 0;   }


#include <bits/stdc++.h>   template <class T>   inline bool rd(T &ret) {     char c;     int sgn;     if (c = getchar(), c == EOF) return 0;     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     sgn = (c ==  - ) ? -1 : 1;     ret = (c ==  - ) ? 0 : (c -  0 );     while (c = getchar(), c >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 );     ret *= sgn;     return 1;   }   template <class T>   inline void pt(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) pt(x / 10);     putchar(x % 10 +  0 );   }   using namespace std;   const long long N = 200050;   long long n, m;   struct node {     long long op, l, r, num, id;   } a[N * 2];   bool cmp(node x, node y) {     if (x.r != y.r) return x.r < y.r;     if (x.op != y.op) return x.op < y.op;   }   long long top, b[N];   void input() {     top = 0;     for (long long i = 1; i <= n; i++) {       rd(a[top].l);       rd(a[top].r);       a[top].op = 0;       a[top].id = i;       top++;     }     rd(m);     for (long long i = 1; i <= m; i++) {       rd(a[top].l);       rd(a[top].r);       rd(a[top].num);       a[top].op = 1;       a[top].id = i;       top++;     }     sort(a, a + top, cmp);   }   struct Edge {     long long id, l;     bool operator<(const Edge &e) const {       if (e.l != l) return e.l > l;       return e.id > id;     }     Edge(long long a = 0, long long b = 0) : id(a), l(b) {}   } tmp;   set<Edge> s;   set<Edge>::iterator p;   int main() {     while (cin >> n) {       input();       long long ans = 0;       s.clear();       for (long long i = 0; i < top; i++) {         if (a[i].op) {           while (s.size() && a[i].num--) {             p = s.lower_bound(Edge(0, a[i].l));             if (p == s.end()) break;             tmp = *p;             b[tmp.id] = a[i].id;             s.erase(p);             ans++;           }         } else {           s.insert(Edge(a[i].id, a[i].l));         }       }       if (ans == n) {         puts( YES );         for (long long i = 1; i <= n; i++) {           pt(b[i]);           putchar(   );         }       } else         puts( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   int clean(vector<pair<int, int> > &I) {     for (int i = 0; i < (int)I.size(); i++) {       swap(I[i].first, I[i].second);       I[i].second *= -1;     }     sort(begin(I), end(I));     for (int i = 0; i < (int)I.size(); i++) {       I[i].second *= -1;       swap(I[i].first, I[i].second);     }     vector<pair<int, int> > I_nw;     int lastb = -1;     for (int i = 0; i < (int)I.size(); i++) {       if (lastb < I[i].first) I_nw.push_back(I[i]);       lastb = max(lastb, I[i].first);     }     I = I_nw;     return I_nw.size();   }   long long pw(long long a, long long e, long long mod) {     if (e <= 0) return 1;     long long x = pw(a, e / 2, mod);     x = (x * x) % mod;     if (e % 2) x = (x * a) % mod;     return x;   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(10);     int K, N[2];     cin >> K >> N[0] >> N[1];     vector<pair<int, int> > I[2];     map<int, int> M;     M[0] = M[K] = 0;     for (int k = 0; k < 2; k++) {       I[k].resize(N[k]);       for (int i = 0; i < N[k]; i++) {         cin >> I[k][i].first >> I[k][i].second;         I[k][i].first--;       }       N[k] = clean(I[k]);       for (int i = 0; i < N[k]; i++) M[I[k][i].first] = M[I[k][i].second] = 0;     }     int m = 0, last = 0;     vector<int> len;     vector<long long> cnt;     for (auto it = M.begin(); it != M.end(); it++) {       it->second = m++;       if (it->first != last) len.push_back(it->first - last);       last = it->first;     }     int L = len.size();     cnt.resize(L);     for (int i = 0; i < L; i++) cnt[i] = (pw(2, len[i], mod) + mod - 2) % mod;     for (int k = 0; k < 2; k++)       for (int i = 0; i < N[k]; i++) {         I[k][i].first = M[I[k][i].first];         I[k][i].second = M[I[k][i].second];       }     vector<long long> ans[3];     for (int k = 0; k < 3; k++) ans[k].resize(L + 1, 0);     ans[2][0] = 1;     vector<long long> sum_ans[3];     for (int k = 0; k < 3; k++) sum_ans[k].resize(L + 1, 0);     int pos[2] = {0, 0}, last_st[2] = {-1, -1};     for (int i = 0; i < L; i++) {       for (int k = 0; k < 3; k++)         sum_ans[k][i + 1] = (sum_ans[k][i] + ans[k][i]) % mod;       ans[2][i + 1] = (ans[0][i] + ans[1][i] + ans[2][i]) * cnt[i] % mod;       for (int k = 0; k < 2; k++) {         while (pos[1 - k] < N[1 - k] && I[1 - k][pos[1 - k]].second <= i + 1) {           last_st[1 - k] = I[1 - k][pos[1 - k]].first;           pos[1 - k]++;         }         ans[k][i + 1] =             (sum_ans[2][i + 1] - sum_ans[2][last_st[1 - k] + 1] +              sum_ans[1 - k][i + 1] - sum_ans[1 - k][last_st[1 - k] + 1]) %             mod;       }     }     long long ansF = (ans[0][L] + ans[1][L] + ans[2][L]) % mod;     if (ansF < 0) ansF += mod;     cout << ansF <<   n ;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 50;   #define int long long   #define ll long long   #define pb push_back   #define mp make_pair   #define debug(a) cout << #a <<     << a <<   n ;   #define debug2(a , b) cout << #a <<     << a <<   ||   << #b <<     << b <<   n ;   #define ye cout <<  YES n    #define no cout <<  NO n    #define cn cout <<   n     const int mod = 1e9 + 7;   using namespace std;      int a[maxn];   signed main()    {    ios::sync_with_stdio(false);    cin.tie(0);    cout.tie(0);     int t;    cin >> t;    while(t --){     int n , k;     cin >> n >> k;     for(int i = 1 ; i <= n ; i ++) cin >> a[i];     if(k == 0){      cout << n <<   n ;      continue;     }     sort(a + 1 , a + 1 + n);     int ok = 1;     for(int i = 1 ; i <= n ; i ++){      if(a[i] != i - 1) {       ok = 0;       break;      }     }     if(ok){      cout << n + k <<   n ;      continue;     }     int ans = n;     int one = -1;     if(a[1] != 0)one = 0;     else{      for(int i = 1 ; i <= n ; i ++){       if(a[i] - a[i - 1] > 1){        one = a[i - 1] + 1;        break;       }      }     }     if(one == -1) one = a[n] + 1;     //debug(one)     one = ((one + a[n]) % 2 == 0 ? (one + a[n]) / 2 : (one + a[n] + 1) / 2);     ans ++;     //debug(one)     for(int i = 1 ; i <= n ; i ++){      if(a[i] > one) break;      if(one == a[i]){       ans --;       break;       }     }     cout << ans <<   n ;    }     return 0;    }   /*      0 1 2   0 1 2 3      */


#include <bits/stdc++.h>   using namespace std;   const long long MX = 1e2 + 5;   vector<long long> g[MX];   long long vis[2][MX], ways[2][MX], dist[2][MX];   void bfs(long long x, long long idx) {     vis[idx][x] = 1;     queue<long long> q;     q.push(x);     ways[idx][x] = 1;     while (!q.empty()) {       long long node = q.front();       q.pop();       for (auto it : g[node]) {         if (!vis[idx][it]) {           dist[idx][it] = dist[idx][node] + 1;           vis[idx][it] = 1;           ways[idx][it] += ways[idx][node];           q.push(it);         } else {           if (dist[idx][node] + 1 == dist[idx][it])             ways[idx][it] += ways[idx][node];         }       }     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, m;     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     bfs(1, 0);     bfs(n, 1);     long long mx = -1;     for (long long i = 1; i <= n; i++) {       if (dist[0][i] + dist[1][i] != dist[0][n]) continue;       long long cur = ways[0][i] * ways[1][i];       if (i != 1 and i != n) cur *= 2;       mx = max(mx, cur);     }     long double ans = (long double)mx / ways[0][n];     cout << fixed << setprecision(12) << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, y, z, t1, t2, t3;     cin >> x >> y >> z >> t1 >> t2 >> t3;     if (abs(x - y) * t2 + t3 * 3 + t2 * abs(z - x) <= abs(x - y) * t1)       cout <<  YES ;     else       cout <<  No ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[156], T, n, k, ans, lw, que[100];   int main() {     int T;     cin >> T;     while (T--) {       cin >> k;       lw = 0;       for (int i = 1; i <= 7; i++) {         cin >> a[i];         a[i + 7] = a[i];         lw += a[i];       }       int n = k / lw;       if (k % lw == 0) {         int maxx = 0, ll = 0;         for (int i = 1; i <= 14; i++) {           if (a[i] == 0) {             ll++;             maxx = max(maxx, ll);           } else             ll = 0;         }         ans = n * 7 - maxx;       } else {         int yu = k % lw, front = 0, ll = 0, minn = 1000;         queue<int> q;         while (!q.empty()) q.pop();         for (int i = 1; i <= 14; i++) {           if (a[i] == 0) continue;           if (a[i] == 1) {             ll++;             q.push(i);             if (ll >= yu) {               front = q.front();               q.pop();               minn = min(i - front + 1, minn);             }           }         }         ans = n * 7 + minn;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000 * 1000 * 1000;   const double EPS = 1e-9;   const double PI = 2 * acos(0.);   const int N = 10;   const int dx[] = {-2, -1, 1, 2, 2, 1, -1, -2};   const int dy[] = {-1, -2, -2, -1, 1, 2, 2, 1};   char a[N][N];   bool r[N];   int main() {     int ans = 0;     for (int i = 0; i < int(8); ++i) {       for (int j = 0; j < int(8); ++j) scanf( %c , &a[i][j]);       scanf(  n );     }     for (int i = 0; i < int(8); ++i) {       bool flag = true;       for (int j = 0; j < int(8); ++j)         if (a[i][j] !=  B ) {           flag = false;           break;         }       if (flag) {         r[i] = true;         ++ans;       }     }     for (int j = 0; j < int(8); ++j) {       bool flag = false;       for (int i = 0; i < int(8); ++i)         if (a[i][j] ==  B  && !r[i]) {           flag = true;           break;         }       if (flag) ++ans;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC optimize( unroll-loops )   using namespace std;   const int BLK = 320;   const int MXN = 1e5 + 5;   const int MOD = 998244353;   int add(int x, int y) { return (x += y) < MOD ? x : x - MOD; }   int sub(int x, int y) { return (x -= y) >= 00 ? x : x + MOD; }   int b[BLK];   int q[BLK][2 * BLK + 5];   int n, k;   int d[MXN];   int dp[MXN];   int arr[MXN];   int last1[MXN];   int last2[MXN];   void add(int pos) {     int id = (pos - 1) / BLK;     for (int i = BLK; i <= 2 * BLK; ++i) {       q[id][i] = add(q[id][i], dp[pos - 1]);     }   }   void update(int pos, int sgn) {     int id = (pos - 1) / BLK;     b[id] += sgn;     for (int i = pos; i > id * BLK; --i) {       if (sgn == +1) q[id][d[i] + BLK] = sub(q[id][d[i] + BLK], dp[i - 1]);       d[i] += sgn;       if (sgn == -2) {         q[id][d[i] + BLK] = add(q[id][d[i] + BLK], dp[i - 1]),                      q[id][d[i] + BLK + 1] =                          add(q[id][d[i] + BLK + 1], dp[i - 1]);       }     }   }   int get(int pos) {     int ret = 0;     int id = (pos - 1) / BLK;     for (int i = pos; i > id * BLK; --i) {       if (d[i] <= k) ret = add(ret, dp[i - 1]);     }     int sum = b[id];     while (--id >= 0) {       if (abs(sum - k) <= BLK) {         ret = add(ret, q[id][k - sum + BLK]);       } else if (sum < k) {         ret = add(ret, q[id][BLK + BLK]);       }       sum += b[id];     }     return ret;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     dp[0] = 1;     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       cin >> arr[i];       add(i);       update(i, 1);       if (last1[arr[i]]) update(last1[arr[i]], -2);       if (last2[arr[i]]) update(last2[arr[i]], +1);       dp[i] = get(i);       last2[arr[i]] = last1[arr[i]];       last1[arr[i]] = i;     }     cout << dp[n] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int SIGMA_SIZE = 26;   const int MAXNODE = 1000010;   struct AhoCorasickAutomata {     int ch[MAXNODE][SIGMA_SIZE];     int f[MAXNODE];     int match[MAXNODE];     int mp[MAXNODE];     int sz;     void init() { sz = 1; }     int idx(char c) {       if (c <=  z  && c >=  a )         return c -  a ;       else         return 0;     }     void insert(char *s, int v) {       int u = 0, n = strlen(s);       for (int i = 0; i < n; i++) {         int c = idx(s[i]);         if (!ch[u][c]) {           ch[u][c] = sz++;         }         u = ch[u][c];       }       match[u] = 1;       mp[v] = u;     }     void getFail() {       queue<int> q;       f[0] = 0;       for (int c = 0; c < SIGMA_SIZE; c++) {         int u = ch[0][c];         if (u) {           f[u] = 0;           q.push(u);         }       }       while (!q.empty()) {         int r = q.front();         q.pop();         for (int c = 0; c < SIGMA_SIZE; c++) {           int u = ch[r][c];           if (!u) {             ch[r][c] = ch[f[r]][c];             continue;           }           q.push(u);           int v = f[r];           while (v && !ch[v][c]) v = f[v];           f[u] = ch[v][c];         }       }     }   };   AhoCorasickAutomata ac;   vector<int> edge[MAXNODE];   char str[MAXNODE];   bool flag[MAXNODE];   int L[MAXNODE];   int R[MAXNODE];   int tot;   struct node {     int l, r;   };   struct Segtree {     int add[MAXNODE << 2], sum[MAXNODE << 2];     node seg[MAXNODE << 2];     void build(int o, int l, int r) {       seg[o].l = l, seg[o].r = r;       if (l == r) return;       int m = (l + r) >> 1;       build(o << 1, l, m);       build(o << 1 | 1, m + 1, r);     }     void pushdown(int o) {       if (add[o]) {         int len = seg[o].r - seg[o].l + 1;         add[o << 1] += add[o];         add[o << 1 | 1] += add[o];         sum[o << 1] += add[o] * (seg[o << 1].r - seg[o << 1].l + 1);         sum[o << 1 | 1] += add[o] * (seg[o << 1 | 1].r - seg[o << 1 | 1].l + 1);         add[o] = 0;       }     }     void pushup(int o) { sum[o] = sum[o << 1] + sum[o << 1 | 1]; }     void update(int o, int l, int r, int val) {       if (l <= seg[o].l && seg[o].r <= r) {         add[o] += val;         sum[o] += val;         return;       }       pushdown(o);       int m = (seg[o].l + seg[o].r) >> 1;       if (l <= m) update(o << 1, l, r, val);       if (r > m) update(o << 1 | 1, l, r, val);       pushup(o);     }     int query(int o, int pos) {       if (seg[o].l == seg[o].r) return sum[o];       pushdown(o);       int m = (seg[o].l + seg[o].r) >> 1;       if (pos <= m) return query(o << 1, pos);       if (pos > m) return query(o << 1 | 1, pos);     }   } tree;   void dfs(int u) {     L[u] = ++tot;     for (int i = 0; i < edge[u].size(); i++) {       int v = edge[u][i];       dfs(v);     }     R[u] = tot;   }   int main() {     ios::sync_with_stdio(false);     int n, k;     while (cin >> n >> k) {       ac.init();       for (int i = 0; i < k; i++) {         cin >> str;         ac.insert(str, i + 1);       }       ac.getFail();       memset(flag, 1, sizeof(flag));       for (int i = 1; i <= ac.sz; i++) edge[ac.f[i]].push_back(i);       dfs(0);       tree.build(1, 1, ac.sz);       for (int i = 1; i <= ac.sz; i++) {         if (ac.match[i]) {           tree.update(1, L[i], R[i], 1);         }       }       while (n--) {         cin >> str;         int len = strlen(str);         if (str[0] ==  ? ) {           int u = 0, ans = 0;           for (int i = 1; i < len; i++) {             int c = ac.idx(str[i]);             u = ac.ch[u][c];             ans += tree.query(1, L[u]);           }           cout << ans << endl;         }         if (str[0] ==  + ) {           int num = 0;           for (int i = 1; i < len; i++) {             num = num * 10 + str[i] -  0 ;           }           if (flag[num]) continue;           flag[num] = 1;           tree.update(1, L[ac.mp[num]], R[ac.mp[num]], 1);         }         if (str[0] ==  - ) {           int num = 0;           for (int i = 1; i < len; i++) {             num = num * 10 + str[i] -  0 ;           }           if (!flag[num]) continue;           flag[num] = 0;           tree.update(1, L[ac.mp[num]], R[ac.mp[num]], -1);         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long Gcd(long long a, long long b) {     if (a % b == 0) return b;     return Gcd(b, a % b);   }   long long Max(long long a, long long b) {     if (a > b) return a;     return b;   }   long long Min(long long a, long long b) {     if (a < b) return a;     return b;   }   long long gcdExtended(long long a, long long b, long long *x, long long *y) {     if (a == 0) {       *x = 0, *y = 1;       return b;     }     long long x1, y1;     long long gcd = gcdExtended(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long modInverse(long long a, long long m) {     long long x, y;     long long g = gcdExtended(a, m, &x, &y);     if (g != 1)       return -1;     else {       long long res = (x % m + m) % m;       return res;     }   }   vector<int> primeFactors(int n) {     vector<int> v;     while (n % 2 == 0) {       v.push_back(2);       n = n / 2;     }     for (int i = 3; i <= sqrt(n); i = i + 2) {       while (n % i == 0) {         v.push_back(i);         n = n / i;       }     }     if (n > 2) v.push_back(n);     return v;   }   long long spf[100001];   void sieve() {     spf[1] = 1;     for (int i = 2; i < 100001; i++) spf[i] = i;     for (int i = 4; i < 100001; i += 2) spf[i] = 2;     for (int i = 3; i * i < 100001; i++) {       if (spf[i] == i) {         for (int j = i * i; j < 100001; j += i)           if (spf[j] == j) spf[j] = i;       }     }   }   long long binarySearch(long long arr[], long long l, long long r, long long x) {     if (r >= l) {       long long mid = l + (r - l) / 2;       if (arr[mid] == x) return mid;       if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);       return binarySearch(arr, mid + 1, r, x);     }     return -1;   }   const long long N = 100000;   long long n;   long long tree[2 * N];   void build(long long arr[]) {     for (long long i = 0; i < n; i++) {       tree[n + i] = arr[i];     }     for (long long i = n - 1; i > 0; --i) {       tree[i] = tree[i << 1] + tree[i << 1 | 1];     }   }   void updateTreeNode(long long p, long long value) {     tree[p + n] = value;     p = p + n;     for (long long i = p; i > 1; i >>= 1) {       tree[i >> 1] = tree[i] + tree[i ^ 1];     }   }   long long query(long long l, long long r) {     long long res = 0;     for (l += n, r += n; l < r; l >>= 1, r >>= 1) {       if (l & 1) {         res += tree[l++];       }       if (r & 1) {         res += tree[--r];       }     }     return res;   }   void dfs(std::vector<long long> v[], long long s, bool visited[]) {     visited[s] = true;     for (long long i = 0; i < v[s].size(); ++i) {       if (!visited[v[s][i]]) {         dfs(v, v[s][i], visited);       }     }   }   long long C[2001][2000];   void binomialCoeff(long long n, long long k) {     long long i, j;     for (i = 0; i <= n; i++) {       for (j = 0; j <= k; j++) {         if (j == 0 || j == i)           C[i][j] = 1;         else           C[i][j] =               (C[i - 1][j - 1] % 998244353 + C[i - 1][j] % 998244353) % 998244353;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m, k;     cin >> n >> m >> k;     binomialCoeff(n, k);     long long mminus1 = power(m - 1, k, 998244353);     mminus1 %= 998244353;     long long ans = 1;     ans *= mminus1 % 998244353;     ans = ((ans % 998244353) * (m)) % 998244353;     ans = ((ans % 998244353) * (C[n - 1][k])) % 998244353;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long cdiv(long long x, long long y) { return x / y + (x % y > 0); }   long long w(long long a, long long b) {     return cdiv(a, 2) * cdiv(b, 2) + (a / 2) * (b / 2);   }   long long W(long long x1, long long y1, long long x2, long long y2) {     return w(x2, y2) - w(x2, y1 - 1) - w(x1 - 1, y2) + w(x1 - 1, y1 - 1);   }   long long B(long long x1, long long y1, long long x2, long long y2) {     return (y2 - y1 + 1) * (x2 - x1 + 1) - W(x1, y1, x2, y2);   }   int main() {     int t;     cin >> t;     while (t--) {       int x1, x2, x3, x4, y1, y2, y3, y4;       long long n, m;       cin >> n >> m;       cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;       long long white = W(1, 1, m, n);       long long black = B(1, 1, m, n);       white = white + B(x1, y1, x2, y2);       black = black - B(x1, y1, x2, y2);       white = white - W(x3, y3, x4, y4);       black = black + W(x3, y3, x4, y4);       if (max(x1, x3) <= min(x2, x4) && max(y1, y3) <= min(y2, y4)) {         white = white - B(max(x1, x3), max(y1, y3), min(x2, x4), min(y2, y4));         black = black + B(max(x1, x3), max(y1, y3), min(x2, x4), min(y2, y4));       }       cout << white <<     << black <<   n ;     }   }


/*      author : Piyush Singh   */   #include <bits/stdc++.h>   #define IOS ios::sync_with_stdio(false), cin.tie(0)   #undef _GLIBCXX_DEBUG   using namespace std;      int main(){    IOS;    int tt;    cin >> tt;    while (tt--) {     int a, b, k;     cin >> a >> b >> k;     vector<int> A(k);     for (int i = 0; i<k; i++) {      cin >> A[i];     }     vector<int> B(k);     for (int i = 0; i<k; i++) {      cin >> B[i];     }     map<int, int> ma;     map<int, int> mb;     for (int i = 0; i<k; i++) {      ma[A[i]] += 1;      mb[B[i]] += 1;     }     long long ans = 0;     for (int i = 0; i<k; i++) {      ans += (k-1) - (ma[A[i]] - 1) - (mb[B[i]] - 1);     }     cout << ans / 2 <<   n ;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long m;   inline long long Nr(long long n) {     long long cnt = 0, k, lim, put;     for (k = 2; 1LL * k * k * k <= n; ++k) {       put = 1LL * k * k * k;       lim = n / put;       if (1LL * lim * put > n) --lim;       if (1LL * (lim + 1) * put <= n) ++lim;       cnt += lim;     }     return cnt;   }   int main() {     int i, j, x, y;     cin >> m;     long long st = 0, dr = 100000000000000000LL, mij, sol = -1;     while (st <= dr) {       mij = (st + dr) / 2;       long long x = Nr(mij);       if (x > m)         dr = mij - 1;       else if (x < m)         st = mij + 1;       else {         sol = mij;         dr = mij - 1;       }     }     cout << sol;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, K, M;   int main() {     scanf( %d%d , &N, &K);     if (K <= 1)       printf( -1 n );     else if (K >= 2 * N)       printf( 1 n );     else if (K > N)       printf( 3 n );     else if (N == K)       printf( 5 n );     else if (K == 2) {       if (N == 3)         printf( 11 n );       else         printf( -1 n );     } else if (K == 3) {       if (N == 4)         printf( 9 n );       else if (N == 5)         printf( 11 n );       else         printf( -1 n );     } else {       N -= (K - 2);       M = 4;       if (K >= 2 * N)         ++M;       else if (K > N)         M += 3;       else if (K == N)         M += 5;       else {         N -= K;         M += 2 * (N / (K / 2 - 1));         N %= (K / 2 - 1);         N += K;         if (N > K) {           N -= (K / 2 - 1);           M += 2;         }         if (K >= 2 * N)           ++M;         else if (K > N)           M += 3;         else           M += 5;       }       printf( %d n , M);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y;     int cnt = 0;     cin >> x >> y;     if (x != y)       cout << min(x, y) <<    ;     else       cout << x <<    ;     if (x > y) {       x = x - y;       for (int i = 2; i <= x; i += 2) {         cnt++;       }       cout << cnt;     } else if (y > x) {       y = y - x;       for (int i = 2; i <= y; i += 2) {         cnt++;       }       cout << cnt;     } else       cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, ans, final = 0, play = 0, study = 0, big, small, i, j;     cin >> n >> m;     int a[n + 1];     for (i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] == 1) {         study++;       } else {         play++;       }     }     for (i = 1; i <= m; i++) {       j = i;       big = study;       small = play;       while (j <= n) {         if (a[j] == 1) {           big--;         } else {           small--;         }         j += m;       }       ans = abs(big - small);       if (ans > final) {         final = ans;       }     }     cout << final;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int amin = 10, bmin = 10;     char mat[8][8];     map<int, int> mapping;     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) {         cin >> mat[i][j];       }       getchar();     }     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) {         if (mat[i][j] ==  B ) mapping[j] = 1;         if (mat[i][j] ==  W  && mapping.find(j) == mapping.end()) {           if (i < amin) amin = i;           mapping[j] = 1;           break;         }       }     }     mapping.clear();     for (int i = 7; i >= 0; i--) {       for (int j = 7; j >= 0; j--) {         if (mat[i][j] ==  W ) mapping[j] = 1;         if (mat[i][j] ==  B  && mapping.find(j) == mapping.end()) {           if (7 - i < bmin) bmin = 7 - i;           mapping[j] = 1;           break;         }       }     }     if (amin <= bmin) {       cout <<  A  << endl;     } else       cout <<  B  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[1 << 20], w[25][25];   string s[25];   pair<int, int> alph[25][26];   int ma[25][26];   int cost[1 << 20];   vector<pair<int, int> > rco;   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> s[i];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cin >> w[i][j];     }     fill(cost, cost + (1 << 20), (int)1e9);     cost[0] = 0;     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         cost[1 << j] = min(cost[1 << j], w[j][i]);         alph[i][(s[j][i] -  a )].first |= (1 << j);         alph[i][(s[j][i] -  a )].second += w[j][i];         ma[i][s[j][i] -  a ] = max(ma[i][s[j][i] -  a ], w[j][i]);       }       for (int j = 0; j < 26; j++) {         alph[i][j].second -= ma[i][j];         cost[alph[i][j].first] = min(cost[alph[i][j].first], alph[i][j].second);       }     }     for (int i = 1; i < (1 << 20); i++) {       if (cost[i] != (int)1e9) rco.push_back(make_pair(i, cost[i]));     }     fill(dp, dp + (1 << n), (int)1e9);     dp[0] = 0;     for (int i = 0; i < rco.size(); i++) {       const int mask = rco[i].first, co = rco[i].second;       for (int j = 0; j < (1 << n); j++) {         dp[j | mask] = min(dp[j | mask], dp[j] + co);       }     }     cout << dp[(1 << n) - 1];   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b;     cin >> n >> a >> b;     if (b) b = (b / abs(b)) * (abs(b) % n);     if (!b) {       cout << a;       return 0;     }     if (b > 0) {       int i, cnt = 0;       for (i = a; cnt != b; (i != n) ? (i++) : i = 1) {         cnt++;       }       cout << i;       return 0;     }     if (b < 0) {       b = abs(b);       int i, cnt = 0;       for (i = a; cnt != b; (i != 1) ? (i--) : i = n) {         cnt++;       }       cout << i;       return 0;     }   }


#include <bits/stdc++.h>   using namespace std;   int ret[1001];   int main() {     int N;     scanf( %d n , &N);     char s[1000];     scanf( %s , s);     fill(ret, ret + N, 1);     for (int i = 0; i < N; i++) {       int t = 1;       for (int j = i; j < N; j++)         if (s[j] ==  R )           break;         else if (s[j] ==  L )           t++;       ret[i] = max(ret[i], t);       t = 1;       for (int j = i - 1; j >= 0; j--)         if (s[j] ==  L )           break;         else if (s[j] ==  R )           t++;       ret[i] = max(ret[i], t);     }     printf( %d , ret[0]);     for (int i = 1; i < N; i++) printf(  %d , ret[i]);     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);     };     long long t;     cin >> t;     while (t--) {       long long a, b, n, s;       cin >> a >> b >> n >> s;       bool ans = false;       long long f = s / n;       s -= min(f, a) * n;       if (s <= b) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int sign = 1, tmp = 0, ans = 0;     for (int i = 0; i < s.size(); i++) {       if (!(s[i] >=  0  && s[i] <=  9 )) {         ans += tmp * sign;         if (s[i] ==  - )           sign = -1;         else           sign = 1;         tmp = 0;       }       tmp = (s[i] -  0 ) + tmp * 10;     }     ans += tmp * sign;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long double pi = acos(-1);   const int MOD = 1e9 + 7;   const long long int LINF = 0x3f3f3f3f3f3f3f3f;   bitset<4096> bs[100050];   pair<int, int> carac[100005][15];   int c[15][100005];   int n, k, q;   int type[100050];   int a[100050];   int b[100050];   int qte;   int pega(int x, int y) {     int mask = 0;     for (int i = k - 1; i >= 0; i--) {       mask ^= (1 << carac[y][i].second);       if (bs[x][mask]) {         return carac[y][i].first;       }     }   }   int main() {     scanf( %d%d%d , &n, &k, &q);     for (int i = 0; i < k; i++) {       for (int j = 0; j < n; j++) {         scanf( %d , &c[i][j]);         carac[j][i] = make_pair(c[i][j], i);       }     }     for (int i = 0; i < k; i++) {       for (int j = 0; j < (1 << k); j++) {         if ((1 << i) & j) bs[i][j] = 1;       }     }     for (int i = 0; i < n; i++) {       sort(carac[i], carac[i] + k);     }     qte = k;     for (int i = 0; i < q; i++) {       int t, x, y;       cin >> t >> x >> y;       if (t == 1) {         type[qte] = 1;         x--, y--;         bs[qte] = bs[x] | bs[y];         qte++;       } else if (t == 2) {         x--, y--;         type[qte] = 2;         bs[qte] = bs[x] & bs[y];         qte++;       } else if (t == 3) {         x--;         y--;         cout << pega(x, y) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 203;   const int MOD = 1e9 + 7;   int n, ssz;   string s;   int len[N][2];   int dp[N][N][N][2];   int calc(const string &t) {     int tsz = t.size();     for (int i = tsz; i > 0; --i) {       if (s.substr(0, i) == t.substr(tsz - i, i)) return i;     }     return 0;   }   void add(int &a, int b) {     a += b;     if (a >= MOD) a -= MOD;   }   int main() {     cin >> n >> s;     ssz = s.size();     if (s[0] ==  ( )       len[0][0] = 1;     else       len[0][1] = 1;     string pref;     for (int i = 0; i < ssz; ++i) {       pref += s[i];       pref +=  ( ;       len[i + 1][0] = calc(pref);       pref.pop_back();       pref +=  ) ;       len[i + 1][1] = calc(pref);       pref.pop_back();     }     dp[0][0][0][0] = 1;     for (int i = 0; i < 2 * n; ++i) {       for (int j = 0; j <= n; ++j) {         for (int pos = 0; pos <= ssz; ++pos) {           for (int f = 0; f < 2; ++f) {             if (dp[i][j][pos][f] == 0) continue;             if (j + 1 <= n && (2 * n - i - 1) >= (j + 1))               add(dp[i + 1][j + 1][len[pos][0]][f | (len[pos][0] == ssz)],                   dp[i][j][pos][f]);             if (j > 0)               add(dp[i + 1][j - 1][len[pos][1]][f | (len[pos][1] == ssz)],                   dp[i][j][pos][f]);           }         }       }     }     int ans = 0;     for (int i = 0; i <= ssz; ++i) add(ans, dp[2 * n][0][i][1]);     cout << ans << endl;     return 0;   }