#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     for (int i = 0; i < k; i++) {       if (n % 10 > 0) {         n--;       } else         n /= 10;     }     cout << n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[100100];   int main() {     int n, m;     scanf( %d %d %s , &n, &m, s);     long long ans = 0, cnt = 1, num = 0;     for (int i = 1; s[i]; i++) {       cnt += s[i] != s[i - 1];     }     ans += cnt * n * (m - 1);     cnt = 1;     for (int i = 1; s[i]; i++) {       if (s[i] != s[i - 1] && (cnt == 1 || s[i] == s[i - 2])) {         cnt++;       } else {         num += cnt * (cnt - 1) / 2;         if (cnt != 1) i--;         cnt = 1;       }     }     num += cnt * (cnt - 1) / 2;     cout << ans - num << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( unroll-loops )   using namespace std;   template <class A, class B>   ostream& operator<<(ostream& out, const pair<A, B>& a) {     return out <<  (  << a.first <<  ,   << a.second <<  ) ;   }   template <class A>   ostream& operator<<(ostream& out, const vector<A>& v) {     out <<  [ ;     for (int i = 0; i < v.size(); i++) {       if (i) out <<  ,  ;       out << v[i];     }     return out <<  ] ;   }   void solve() {     long long n, x;     cin >> n >> x;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     long long sum = 0;     for (int i = 0; i < n; i++) sum += a[i];     if (sum % x != 0)       cout << n <<   n ;     else {       long long res = -1;       long long s = 0;       for (int i = 0; i < n; i++) {         s += a[i];         sum -= a[i];         if (s % x != 0) res = max(res, (long long)i + 1);         if (sum % x != 0) res = max(res, n - i - 1);       }       cout << res <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int q = 1;     cin >> q;     for (int kase = 1; kase <= q; kase++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, s, e;   long long x[5001];   long long a[5001];   long long b[5001];   long long c[5001];   long long d[5001];   long long pd[5001][5001];   long long func(int at, int comp, int left, int right) {     if (comp <= 0 && at != 0) return 0x3f3f3f3f3f3f3f3fll;     if (at == n) return ((comp == 1) ? 0 : 0x3f3f3f3f3f3f3f3fll);     if (pd[at][comp] != -1) return pd[at][comp];     long long ans = 0x3f3f3f3f3f3f3f3fll;     int onlycomp = (comp - left - right);     if (at != s && at != e) {       ans = func(at + 1, comp + 1, left, right) - 2 * x[at] + d[at] + b[at];       if (left) {         ans = min(ans, func(at + 1, comp, left, right) + a[at] + d[at]);         if (onlycomp)           ans = min(ans, func(at + 1, comp - 1, left, right) + a[at] + c[at] +                              2 * x[at]);       }       if (right) {         ans = min(ans, func(at + 1, comp, left, right) + c[at] + b[at]);         if (onlycomp)           ans = min(ans, func(at + 1, comp - 1, left, right) + c[at] + a[at] +                              2 * x[at]);       }       if (onlycomp) {         ans = min(             ans, func(at + 1, comp - 1, left, right) + c[at] + a[at] + 2 * x[at]);         ans = min(ans, func(at + 1, comp, left, right) + b[at] + c[at]);         ans = min(ans, func(at + 1, comp, left, right) + a[at] + d[at]);       }       if (at == n - 1 && comp == 2)         ans = min(             ans, func(at + 1, comp - 1, left, right) + c[at] + a[at] + 2 * x[at]);     } else if (at == s) {       ans = func(at + 1, comp + 1, 1, right) - x[at] + d[at];       if (onlycomp) ans = min(ans, func(at + 1, comp, 1, right) + x[at] + c[at]);       if (at == n - 1 && comp == 1)         ans = min(ans, func(at + 1, comp, 1, right) + c[at] + x[at]);     } else {       ans = func(at + 1, comp + 1, left, 1) - x[at] + b[at];       if (onlycomp) ans = min(ans, func(at + 1, comp, left, 1) + x[at] + a[at]);       if (at == n - 1 && comp == 1)         ans = min(ans, func(at + 1, comp, left, 1) + a[at] + x[at]);     }     return pd[at][comp] = ans;   }   int main() {     scanf( %d %d %d , &n, &s, &e);     s--;     e--;     for (int i = 0; i < n; i++) scanf( %lld , &x[i]);     for (int i = 0; i < n; i++) scanf( %lld , &a[i]);     for (int i = 0; i < n; i++) scanf( %lld , &b[i]);     for (int i = 0; i < n; i++) scanf( %lld , &c[i]);     for (int i = 0; i < n; i++) scanf( %lld , &d[i]);     memset(pd, -1, sizeof pd);     printf( %lld n , func(0, 0, 0, 0));     return 0;   }


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


#include <bits/stdc++.h>   const int MAXN = 1005;   int a[MAXN];   int cnt[MAXN];   int main() {     int n, k;     while (scanf( %d%d , &n, &k) + 1) {       memset(cnt, 0, sizeof(cnt));       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           if ((j - i) * k == a[j] - a[i]) {             cnt[i]++;           }         }       }       int mm = 0;       int p = 0;       for (int i = 1; i <= n; i++) {         if (cnt[i] > mm && a[i] - (i - 1) * k > 0) {           mm = cnt[i];           p = i;         }       }       printf( %d n , n - mm);       for (int i = 1; i <= n; i++) {         if ((i - p) * k != a[i] - a[p]) {           if (a[i] - a[p] > (i - p) * k) {             printf( - %d %d n , i, a[i] - a[p] - (i - p) * k);           } else {             printf( + %d %d n , i, (i - p) * k - a[i] + a[p]);           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b;       cin >> a >> b;       cout << a <<     << a * 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, pair<long long, long long>> ChthollyTree;   map<long long, pair<long long, long long>>::iterator split(       long long p, map<long long, pair<long long, long long>>::iterator *pre) {     map<long long, pair<long long, long long>>::iterator pos =         ChthollyTree.lower_bound(p);     if (pos->first == p) return pos;     pos--;     if (pos->second.first < p) return ChthollyTree.end();     long long left = pos->first, right = pos->second.first;     long long value = pos->second.second;     if (pre && *pre == pos) {       ChthollyTree.erase(pos);       *pre = ChthollyTree.insert(make_pair(left, make_pair(p - 1, value))).first;     } else {       ChthollyTree.erase(pos);       ChthollyTree[left] = make_pair(p - 1, value);     }     return ChthollyTree.insert(make_pair(p, make_pair(right, value))).first;   }   void add(long long l, long long r, long long diff) {     map<long long, pair<long long, long long>>::iterator s = split(l, NULL),                                                          e = split(r + 1, &s);     while (s != e) {       s->second.second += diff;       s++;     }   }   void assign(long long l, long long r, long long x) {     map<long long, pair<long long, long long>>::iterator s = split(l, NULL),                                                          e = split(r + 1, &s);     map<long long, pair<long long, long long>>::iterator tmp;     while (s != e) {       tmp = s;       s++;       ChthollyTree.erase(tmp);     }     ChthollyTree[l] = make_pair(r, x);   }   long long kSmallest(long long l, long long r, long long k) {     map<long long, pair<long long, long long>>::iterator s = split(l, NULL),                                                          e = split(r + 1, &s);     vector<pair<long long, long long>> buff;     while (s != e) {       buff.push_back(make_pair(s->second.second, s->second.first - s->first + 1));       s++;     }     sort(buff.begin(), buff.end());     unsigned int length = buff.size();     for (unsigned int i = 0; i < length; i++) {       k -= buff[i].second;       if (k <= 0) return buff[i].first;     }     return -1;   }   long long fastPowMod(long long base, long long p, long long mod) {     long long ret = 1;     base %= mod;     do {       if (p & 1) ret = ret * base % mod;       base = base * base % mod;     } while (p >>= 1);     return ret;   }   long long intervalPowSum(long long l, long long r, long long p, long long mod) {     map<long long, pair<long long, long long>>::iterator s = split(l, NULL),                                                          e = split(r + 1, &s);     long long ret = 0;     while (s != e) {       ret = (ret + fastPowMod(s->second.second, p, mod) % mod *                        (s->second.first - s->first + 1)) %             mod;       s++;     }     return ret;   }   inline long long rnd(long long &seed) {     long long ret = seed;     seed = (seed * 7 + 13) % 1000000007;     return ret;   }   inline void swap(long long &a, long long &b) {     long long t = a;     a = b;     b = t;   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(NULL);     long long n, m, seed, v;     long long op, l, r, x, y;     cin >> n >> m >> seed >> v;     for (long long i = 1; i <= n; i++) {       ChthollyTree[i] = make_pair(i, rnd(seed) % v + 1);     }     for (long long i = 0; i < m; i++) {       op = rnd(seed) % 4 + 1;       l = rnd(seed) % n + 1;       r = rnd(seed) % n + 1;       if (l > r) swap(l, r);       if (op == 3)         x = (rnd(seed) % (r - l + 1)) + 1;       else         x = rnd(seed) % v + 1;       if (op == 4) y = rnd(seed) % v + 1;       switch (op) {         case 1:           add(l, r, x);           break;         case 2:           assign(l, r, x);           break;         case 3:           cout << kSmallest(l, r, x) <<   n ;           break;         case 4:           cout << intervalPowSum(l, r, x, y) <<   n ;           break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int ans = 6;     for (int i = 4; i <= n; i++) {       ans += (i - 1) * i;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int kbo[1001];   int main() {     int s, k, i;     scanf( %d%d , &s, &k);     kbo[0] = 0;     kbo[1] = 1;     kbo[2] = 1;     for (i = 3;; i++) {       if (i - k - 1 > 0)         kbo[i] = 2 * kbo[i - 1] - kbo[i - k - 1];       else         kbo[i] = 2 * kbo[i - 1];       if (kbo[i] > s) break;     }     for (int j = 0; j < i; ++j) {     }     int res[100], cnt = 0;     while (s > 0) {       i--;       if (s - kbo[i] >= 0) {         s -= kbo[i];         res[cnt++] = kbo[i];       }     }     if (cnt == 1)       printf( 2 n0 %d , res[0]);     else {       printf( %d n , cnt);       for (int j = 0; j < cnt; j++) printf( %d  , res[j]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10, K = 105, MOD = 998244353;   int p[N][K], dp[N][K], a[N], ans[N] = {1};   int n, k, len;   int sum(int l, int r, int x) {     l = max(l, 1);     r = min(r, n);     return p[r][x] - p[l - 1][x];   }   int main() {     cin >> n >> k >> len;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] == -1) a[i]++;       p[i][a[i]]++;       for (int j = 0; j <= k; j++) {         p[i][j] += p[i - 1][j];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= k; j++) {         if (a[i] == 0 || a[i] == j) {           dp[i][j] = ans[i - 1];           if (sum(i - len + 1, i, j) + sum(i - len + 1, i, 0) == len) {             dp[i][j] -= ans[i - len] - dp[i - len][j];             if (dp[i][j] < 0) dp[i][j] += MOD;             if (dp[i][j] >= MOD) dp[i][j] -= MOD;           }         }       }       for (int j = 1; j <= k; j++) {         ans[i] += dp[i][j];         if (ans[i] >= MOD) ans[i] -= MOD;       }     }     cout << ans[n] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 200011;   long long a[MAXN], v[MAXN];   int main() {     long long ii, tt, i, j, k, m, n, d, md, maxt, mx, t, ct, oct, res1, res2, sum,         osum, L, R, M;     cin >> tt;     for (ii = 0; ii < tt; ii++) {       cin >> n >> m >> maxt;       for (i = 0; i < n; i++) {         cin >> a[i];         v[i] = a[i];       }       sort(v, v + n);       mx = 0;       md = 1;       L = 0;       R = n;       while (L + 1 < R) {         M = (L + R) / 2;         d = v[M];         osum = 0;         sum = 0;         oct = 0;         ct = 0;         t = 0;         for (i = 0; i < n; i++) {           if (a[i] <= d) {             sum += a[i];             osum += a[i];             ct++;             if (osum > maxt) break;             oct++;             if (ct == m) {               ct = 0;               osum += sum;               sum = 0;               if (osum > maxt) break;             }           }         }         if (oct >= mx) {           mx = oct;           md = d;         }         if (osum <= maxt) {           L = M;         } else {           R = M;         }       }       d = v[L];       osum = 0;       sum = 0;       oct = 0;       ct = 0;       t = 0;       for (i = 0; i < n; i++) {         if (a[i] <= d) {           sum += a[i];           osum += a[i];           ct++;           if (osum > maxt) break;           oct++;           if (ct == m) {             ct = 0;             osum += sum;             sum = 0;             if (osum > maxt) break;           }         }       }       if (oct >= mx) {         mx = oct;         md = d;       }       md = min(md, maxt);       cout << mx <<     << md << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int max(long long int a, long long int b) {     if (a > b)       return a;     else       return b;   }   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long int lcm(long long int a, long long int b) {     return (a * b) / gcd(a, b);   }   bool isPowerOfTwo(long long int n) {     if (n == 0) return false;     return (ceil(log2(n)) == floor(log2(n)));   }   bool comp(const pair<long long int, bool>& a,             const pair<long long int, bool>& b) {     if (a.second != b.second) {       return a.first < b.first;     }     return false;   }   void solve() {     long long int n, k;     cin >> n >> k;     long long int arr[n][n];     for (long long int i = 0; i < n; i++)       for (long long int j = 0; j < n; j++) arr[i][j] = 0;     long long int x = ceil(k * 1.0 / (n * 1.0));     bool f = 0;     for (long long int l = 1; l <= x && k; l++) {       for (long long int i = 0; i < n && k; i++) {         for (long long int j = 0; j < n && k; j++) {           if (i + j == n + l - 2 || i + j == l - 2) arr[i][j] = 1, k--;         }       }     }     long long int ans = 0, rma = 0, rmi = INT_MAX, cma = 0, cmi = INT_MAX;     for (long long int i = 0; i < n; i++) {       long long int c = 0;       for (long long int j = 0; j < n; j++)         if (arr[i][j]) c++;       rma = max(rma, c);       rmi = min(rmi, c);     }     for (long long int i = 0; i < n; i++) {       long long int c = 0;       for (long long int j = 0; j < n; j++)         if (arr[j][i]) c++;       cma = max(cma, c);       cmi = min(cmi, c);     }     ans = (pow(rma - rmi, 2) + pow(cma - cmi, 2));     cout << ans << endl;     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < n; j++) cout << arr[i][j];       cout <<   n ;     }   }   void solve1() {     long long int n;     cin >> n;     if (n & 1)       cout <<  NO n ;     else {       n /= 2;       if (n & 1)         cout <<  NO n ;       else         cout <<  YES n ;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   const int NINF = INT_MIN;   const long long INF_LL = LLONG_MAX;   const long long NINF_LL = LLONG_MIN;   const double PI = acos(-1.0);   const int MOD = 1e9 + 7;   int main() {     long long n, m;     cin >> n >> m;     long long ans = n * n;     int nr = 0, nc = 0;     vector<bool> r(n, false), c(n, false);     while (m--) {       int y, x;       cin >> y >> x;       --x, --y;       bool ds = false;       if (!r[y] and !c[x]) {         --ans;         ds = true;       }       if (!r[y]) {         ans -= (n - nc - ds);       }       if (!c[x]) {         ans -= (n - nr - ds);       }       if (!r[y]) {         nr++;         r[y] = true;       }       if (!c[x]) {         nc++;         c[x] = true;       }       cout << ans;       if (m) cout <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename _Tp>   inline _Tp read(_Tp& x) {     char c11 = getchar(), ob = 0;     x = 0;     while (c11 ^  -  && !isdigit(c11)) c11 = getchar();     if (c11 ==  - ) ob = 1, c11 = getchar();     while (isdigit(c11)) x = x * 10 + c11 -  0 , c11 = getchar();     if (ob) x = -x;     return x;   }   const int N = 201000;   const long long inf = 0x3f3f3f3f3f3f3f3f;   struct Edge {     int v, nxt, w;   } a[N << 1];   int head[N], is[N], st[N], vis[N];   long long f[N], pre[N];   long long gl[N], gr[N], hl[N], hr[N], hhl[N], hhr[N], ggl[N], ggr[N];   int n, m, _, top;   long long Ans;   void get_cir(int x, int las) {     if (vis[x]) {       int p = top;       while (st[p] ^ x) --p;       for (register int i = p; i <= top; ++i) is[st[i - p + 1] = st[i]] = 1;       st[0] = -1;       top -= p - 1;       return;     }     vis[st[++top] = x] = 1;     for (int i = head[x]; i && ~st[0]; i = a[i].nxt)       if (a[i].v ^ las) get_cir(a[i].v, x);     if (~st[0]) vis[st[top--]] = 0;   }   void dfs(int x, int las) {     long long sec = 0ll;     for (int i = head[x]; i; i = a[i].nxt)       if (!is[a[i].v] && a[i].v ^ las) {         dfs(a[i].v, x);         f[a[i].v] += a[i].w;         if (f[a[i].v] >= f[x])           sec = f[x], f[x] = f[a[i].v];         else if (f[a[i].v] > sec)           sec = f[a[i].v];       }     Ans = max(Ans, f[x] + sec);   }   inline long long G(int x) { return x ? f[st[x]] - pre[x] : -inf; }   inline long long H(int x) { return x ? f[st[x]] + pre[x] : -inf; }   void work() {     st[0] = st[top];     for (register int x = 1; x <= top; ++x) {       for (register int i = head[st[x - 1]]; i; i = a[i].nxt)         if (a[i].v == st[x]) {           pre[x] = pre[x - 1] + a[i].w;           break;         }       dfs(st[x], 0);     }     for (register int i = 1; i <= top; ++i) {       gl[i] = gl[i - 1], ggl[i] = ggl[i - 1];       hl[i] = hl[i - 1], hhl[i] = hhl[i - 1];       if (G(i) > G(gl[i]))         ggl[i] = gl[i], gl[i] = i;       else if (G(i) > G(ggl[i]))         ggl[i] = i;       if (H(i) > H(hl[i]))         hhl[i] = hl[i], hl[i] = i;       else if (H(i) > H(hhl[i]))         hhl[i] = i;     }     for (register int i = top; i; --i) {       gr[i] = gr[i + 1], ggr[i] = ggr[i + 1];       hr[i] = hr[i + 1], hhr[i] = hhr[i + 1];       if (G(i) > G(gr[i]))         ggr[i] = gr[i], gr[i] = i;       else if (G(i) > G(ggr[i]))         ggr[i] = i;       if (H(i) > H(hr[i]))         hhr[i] = hr[i], hr[i] = i;       else if (H(i) > H(hhr[i]))         hhr[i] = i;     }     long long ans;     if (hl[top] != gl[top])       ans = G(gl[top]) + H(hl[top]);     else       ans = max(G(ggl[top]) + H(hl[top]), G(gl[top]) + H(hhl[top]));     for (register int i = 1; i < top; ++i) {       long long val = pre[top] + H(hl[i]) + G(gr[i + 1]);       long long tmp;       if (gl[i] ^ hl[i])         tmp = G(gl[i]) + H(hl[i]);       else         tmp = max(G(ggl[i]) + H(hl[i]), G(gl[i]) + H(hhl[i]));       val = max(val, tmp);       ++i;       if (gr[i] ^ hr[i])         tmp = G(gr[i]) + H(hr[i]);       else         tmp = max(G(ggr[i]) + H(hr[i]), G(gr[i]) + H(hhr[i]));       val = max(val, tmp);       --i;       ans = min(ans, val);     }     cout << max(ans, Ans) << endl;   }   void init();   void work();   int main() {     init();     work();     return 0;   }   void init() {     read(n);     int u, v, w;     for (register int i = 1; i <= n; ++i) {       read(u), read(v), read(w);       a[++_].v = v, a[_].w = w, a[_].nxt = head[u], head[u] = _;       a[++_].v = u, a[_].w = w, a[_].nxt = head[v], head[v] = _;     }     get_cir(1, 1);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, x, a, b;       cin >> n >> x >> a >> b;       if (abs(a - b) + x >= n)         cout << n - 1 << endl;       else {         cout << abs(a - b) + x << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2 * 1e5 + 5;   double sum;   int i, j, l, o, n, k, a[maxn];   int main() {     scanf( %d %d , &n, &k);     for (int j = 1; j <= n; j++) scanf( %d , &a[j]);     for (i = 1; i <= n; i++) {       if (i <= k) {         if (n - k + 1 >= i)           sum += 1.0 * i * a[i];         else {           l = i + k - 1 - n;           l = i - l;           sum += 1.0 * l * a[i];         }       } else {         if (n - k + 1 >= i)           sum += 1.0 * k * a[i];         else {           sum += 1.0 * (n - i + 1) * a[i];         }       }     }     sum /= (n - k + 1);     printf( %.10lf n , sum);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long int LINF = 0x3f3f3f3f3f3f3f3fll;   const long double pi = acos(-1);   const int MOD = 1e9 + 7;   const int N = 310;   int l[N], c[N];   map<long long int, int> mapa;   int mdc(int a, int b) {     if (b == 0) return a;     return mdc(b, a % b);   }   bool add(int x, int custo) {     if (mapa.count(x)) {       if (mapa[x] > custo) {         mapa[x] = custo;         return true;       }       return false;     } else {       mapa[x] = custo;       return true;     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &l[i]);     for (int i = 0; i < n; i++) scanf( %d , &c[i]);     set<int> q;     for (int i = 0; i < n; i++) {       add(l[i], c[i]);       q.insert(l[i]);     }     for (int i = 0; i < 100000; i++) {       if (q.size() == 0) break;       int x = *q.begin();       q.erase(q.begin());       for (int j = 0; j < n; j++) {         int valnovo = mdc(x, l[j]);         int custonovo = c[j] + mapa[x];         if (add(valnovo, custonovo)) q.insert(valnovo);       }     }     if (mapa.count(1)) {       printf( %d n , mapa[1]);     } else {       int coco = -1;       printf( %d n , coco);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   struct node {     int u, v, w;     friend bool operator<(node a, node b) { return a.w > b.w; }   } itm[200005];   int fa[200005];   int gf(int x) {     if (x != fa[x]) return fa[x] = gf(fa[x]);     return fa[x];   }   int main() {     while (~scanf( %d%d , &n, &m)) {       for (int i = 1; i <= n; i++) fa[i] = i;       priority_queue<node> q;       for (int i = 0; i < m; i++) {         scanf( %d%d%d , &itm[i].u, &itm[i].v, &itm[i].w);         q.push(itm[i]);       }       int cnt = 0, ans = 0;       while (!q.empty() && cnt < (n - 1)) {         node sta = q.top();         q.pop();         queue<node> q1, q2;         q1.push(sta);         while (!q.empty() && q.top().w == sta.w) {           q1.push(q.top());           q.pop();         }         while (!q1.empty()) {           node cur = q1.front();           q1.pop();           int f1 = gf(cur.u);           int f2 = gf(cur.v);           if (f1 != f2) q2.push(cur);         }         if (!q2.empty()) {           node cur = q2.front();           q2.pop();           int f1 = gf(cur.u);           int f2 = gf(cur.v);           fa[f1] = f2;           cnt++;           while (!q2.empty()) {             node tp = q2.front();             q2.pop();             f1 = gf(tp.u);             f2 = gf(tp.v);             if (f1 == f2)               ans++;             else               fa[f1] = f2, cnt++;           }         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 2e5 + 100;   int a[M], b[M];   int n, x, y;   int di[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   bool check(int xx, int yy) {     if (xx < 1 || xx > x || yy < 1 || yy > y) return 0;     return 1;   }   bool bfs() {     queue<int> q;     int l = 0;     q.push(a[l]);     l++;     while (q.size()) {       if (l == n) return 1;       int ans = q.front();       int y1, x1;       if (ans % y == 0) {         y1 = y;         x1 = ans / y;       } else {         y1 = ans % y;         x1 = ans / y + 1;       }       q.pop();       for (int i = 0; i < 4; i++) {         int nx = x1 + di[i][0], ny = y1 + di[i][1];         int res = (nx - 1) * y + ny;         if (check(nx, ny) && res == a[l]) {           q.push(a[l]);           l++;           break;         }       }     }     if (l == n + 1)       return 1;     else       return 0;   }   int main() {     while (~scanf( %d , &n)) {       int mac = 0;       for (int i = 0; i < n; i++) {         scanf( %d , &a[i]);         mac = max(a[i], mac);       }       int l = 0;       bool f = 1;       for (int i = 0; i < n - 1; i++) {         if (l == 0 && abs(a[i] - a[i + 1]) > 1) l = abs(a[i] - a[i + 1]);         if (l && abs(a[i] - a[i + 1]) > 1)           if (l != abs(a[i] - a[i + 1])) {             f = 0;             break;           }       }       if (!f)         printf( NO n );       else {         if (l == 0) {           x = 1;           y = mac;         } else {           y = l;           x = mac / l + 1;         }         bool tt = bfs();         if (tt) {           printf( YES n );           printf( %d %d n , x, y);         } else           printf( NO n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, i, j, ans, sum1, sum2;   long long x[100000], y[100000];   int main() {     scanf( %I64d , &n);     sum1 = 0;     sum2 = 0;     ans = 0;     for (i = 0; i < n; i++) {       scanf( %I64d %I64d , &x[i], &y[i]);       ans += (n * (x[i] * x[i] + y[i] * y[i]));       sum1 += x[i];       sum2 += y[i];     }     ans -= (sum1 * sum1);     ans -= (sum2 * sum2);     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int arr[n][n];     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) scanf( %d , &arr[i][j]);     int q;     scanf( %d , &q);     int res = 0;     for (int k = 0; k < n; k++) {       res += arr[k][k];       res %= 2;     }     for (int p = 0; p < q; p++) {       int t;       scanf( %d , &t);       switch (t) {         case 1: {           int k;           scanf( %d , &k);           res = 1 - res;         } break;         case 2: {           int k;           scanf( %d , &k);           k--;           res = 1 - res;         } break;         case 3: {           printf( %d , res);         } break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     long long int n, i, j, x, in = 0;     string s;     vector<pair<string, long long int>> v;     priority_queue<long long int, vector<long long int>, greater<long long int>>         pq;     cin >> n;     long long int mn = 1000000000000000000LL, dummy = -1;     for (i = 1; i <= n; i++) {       cin >> s;       if (s ==  insert ) {         cin >> x;         v.push_back(make_pair(s, x));         pq.push(x);       } else if (s ==  getMin ) {         cin >> x;         if (pq.size() != 0)           mn = pq.top();         else           mn = -1;         if (x != mn) {           if (x > mn) {             while (x > mn && pq.size() != 0) {               mn = pq.top();               if (mn >= x) break;               pq.pop();               v.push_back(make_pair( removeMin , -1));             }             if (x == mn && pq.size() != 0) {               v.push_back(make_pair(s, x));             } else if ((mn > x && pq.size() != 0) || pq.size() == 0) {               v.push_back(make_pair( insert , x));               pq.push(x);               v.push_back(make_pair(s, x));             }           } else {             v.push_back(make_pair( insert , x));             pq.push(x);             v.push_back(make_pair(s, x));           }         } else {           v.push_back(make_pair(s, x));         }       } else if (s ==  removeMin ) {         if (pq.size() != 0)           pq.pop();         else {           v.push_back(make_pair( insert , 0));         }         v.push_back(make_pair(s, -1));       }     }     cout << v.size() << endl;     for (i = 0; i < v.size(); i++) {       cout << v[i].first <<    ;       if (v[i].first !=  removeMin )         cout << v[i].second << endl;       else         cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int MOD = 1e9 + 7;   const int MAXN = 2e5 + 17;   const int magic = (1 << 7);   using namespace std;   struct p {     long double x, y;     p(long double x, long double y) : x(x), y(y) {}     p() {}     long double len() const { return sqrt(x * x + y * y); }   };   p operator-(const p &a, const p &b) { return p(a.x - b.x, a.y - b.y); }   string s;   bool solve(int l, int r) {     int q = 0;     map<char, int> c;     int num = 0;     for (int i = l; i <= r; i++) {       if (s[i] ==  ? )         q++;       else         c[s[i]]++;     }     if (c.size() + q >= 26) {       for (int i = l; i <= r; i++) {         if (s[i] ==  ? )           for (int x = int( A ); x <= int( Z ); x++) {             if (c[char(x)] == 0) {               s[i] = char(x), c[char(x)]++;               break;             }           }       }       return true;     }     return false;   }   int main() {     if (1) {       ios_base::sync_with_stdio(false);       cin.tie(nullptr);       cout.tie(nullptr);     }     long long n;     cin >> n;     long long cur = 2;     for (long long i = 1; i <= n; i++) {       cout << (i * (i + 1) * (i + 1) - cur / i) <<   n ;       cur = i * (i + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   const int N = 1e5 + 19;   long long A[N], day[N];   signed main() {     long long n, m, d;     set<pair<long long, int> > S;     n = read();     m = read();     d = read();     for (int i = 1; i <= n; ++i) {       long long x;       x = read();       S.insert(pair<long long, int>(x, i));     }     int now = 0;     while (S.size()) {       ++now;       pair<long long, int> tmp = *S.begin();       long long s = tmp.first;       day[tmp.second] = now;       S.erase(S.begin());       for (auto iter = S.lower_bound(pair<long long, int>(s + d + 1, 0));            iter != S.end();            iter = S.lower_bound(pair<long long, int>(s + d + 1, 0))) {         day[iter->second] = now;         s = iter->first;         S.erase(iter);       }     }     printf( %d n , now);     for (int i = 1; i <= n; ++i) printf( %I64d  , day[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 1e6;   namespace IO {   const int MAXSIZE = 1 << 20;   char buf[MAXSIZE], *p1, *p2;   inline int gc() {     return (p1 == p2 &&                     (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2)                 ? EOF                 : *p1++);   }   inline int rd() {     int x = 0, f = 1;     char c = gc();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = gc();     }     while (isdigit(c)) x = x * 10 + (c ^ 48), c = gc();     return x * f;   }   inline char getc() {     char c = gc();     while (!isgraph(c)) {       c = gc();     }     return c;   }   char pbuf[MAXSIZE], *pp = pbuf;   inline void push(const char &c) {     if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;     *pp++ = c;   }   inline void flush() { fwrite(pbuf, 1, pp - pbuf, stdout), pp = pbuf; }   inline void write(int x) {     static int sta[35];     int top = 0;     do {       sta[top++] = x % 10, x /= 10;     } while (x);     while (top) push(sta[--top] +  0 );   }   }  // namespace IO   int main() {     int n, m;     n = IO::rd();     m = IO::rd();     vector<char> a(n * m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) a[((i)*m + (j))] = IO::getc();     vector<int> dp(n * m, INF);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (a[((i)*m + (j))] !=  X )           dp[((i)*m + (j))] = 0;         else {           if (i && j)             dp[((i)*m + (j))] =                 min(dp[((i - 1) * m + (j - 1))],                     min(dp[((i - 1) * m + (j))], dp[((i)*m + (j - 1))])) +                 1;           else             dp[((i)*m + (j))] = 1;         }       }     int l = 0, r = min(n, m);     auto dp2 = dp;     while (l < r) {       int mid = (l + r + 1) / 2;       int ok = 1;       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) {           if (dp[((i)*m + (j))] < mid) dp[((i)*m + (j))] = 0;         }       for (int i = n - 1; i >= 0; i--)         for (int j = m - 1; j >= 0; j--) {           if (i != n - 1)             dp[((i)*m + (j))] =                 max(dp[((i)*m + (j))], dp[((i + 1) * m + (j))] - 1);           if (j != m - 1)             dp[((i)*m + (j))] = max(dp[((i)*m + (j))], dp[((i)*m + (j + 1))] - 1);           if (i != n - 1 && j != m - 1)             dp[((i)*m + (j))] =                 max(dp[((i)*m + (j))], dp[((i + 1) * m + (j + 1))] - 1);           if (dp[((i)*m + (j))] == 0 && a[((i)*m + (j))] ==  X ) {             ok = 0;             goto zml;           }         }     zml:       if (ok) {         l = mid;       } else {         r = mid - 1;       }       dp = dp2;     }     int ans = l;     IO::write((ans - 1) / 2);     int a1 = (ans - 1) / 2;     int a2 = ans / 2;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         a[((i)*m + (j))] =  . ;         if (dp[((i)*m + (j))] >= ans) {           a[((i - a1) * m + (j - a1))] =  X ;           a[((i - a1) * m + (j - a2))] =  X ;           a[((i - a2) * m + (j - a1))] =  X ;           a[((i - a2) * m + (j - a2))] =  X ;         }       }     IO::push(  n );     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) IO::push(a[((i)*m + (j))]);       IO::push(  n );     }     IO::flush();   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, ans, a[2000010], a0[2000010];   struct Node {     long long MaxL, MaxR, Max;   };   Node tree[2000010];   long long Sign(long long x) {     if (x > 0) {       return 1;     }     if (x == 0) {       return 0;     }     return -1;   }   void Merge(long long idx, long long l, long long r) {     if (l == r) {       return;     }     long long mid = (l + r) / 2;     tree[idx].Max = max(tree[idx * 2 + 1].Max, tree[idx * 2 + 2].Max);     if (!a[mid] or !a[mid + 1] or Sign(a[mid]) < Sign(a[mid + 1])) {       tree[idx].MaxL = tree[idx * 2 + 1].MaxL;       tree[idx].MaxR = tree[idx * 2 + 2].MaxR;     } else {       tree[idx].Max =           max(tree[idx].Max, tree[idx * 2 + 1].MaxR + tree[idx * 2 + 2].MaxL);       if (tree[idx * 2 + 1].MaxL == mid - l + 1) {         tree[idx].MaxL = tree[idx * 2 + 1].MaxL + tree[idx * 2 + 2].MaxL;       } else {         tree[idx].MaxL = tree[idx * 2 + 1].MaxL;       }       if (tree[idx * 2 + 2].MaxR == r - mid) {         tree[idx].MaxR = tree[idx * 2 + 2].MaxR + tree[idx * 2 + 1].MaxR;       } else {         tree[idx].MaxR = tree[idx * 2 + 2].MaxR;       }     }   }   void Init(long long idx, long long l, long long r) {     if (l == r) {       if (a[l]) {         tree[idx] = {1, 1, 1};       } else {         tree[idx] = {0, 0, 0};       }       return;     }     long long mid = (l + r) / 2;     Init(idx * 2 + 1, l, mid);     Init(idx * 2 + 2, mid + 1, r);     Merge(idx, l, r);   }   void Update(long long idx, long long x, long long val, long long l,               long long r) {     if (l == r) {       a[l] += val;       if (a[l]) {         tree[idx] = {1, 1, 1};       } else {         tree[idx] = {0, 0, 0};       }       return;     }     long long mid = (l + r) / 2;     if (x <= mid) {       Update(idx * 2 + 1, x, val, l, mid);     } else {       Update(idx * 2 + 2, x, val, mid + 1, r);     }     Merge(idx, l, r);   }   signed main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     cin >> n;     for (long long i = 0; i < n; ++i) {       cin >> a0[i];     }     for (long long i = 0; i < n - 1; ++i) {       a[i] = a0[i + 1] - a0[i];     }     if (n > 1) {       Init(0, 0, n - 2);     }     cin >> m;     for (long long i = 0; i < m; ++i) {       long long l, r, x;       cin >> l >> r >> x;       if (n == 1) {         cout <<  1 n ;         continue;       }       if (l >= 2) {         Update(0, l - 2, x, 0, n - 2);       }       if (r < n) {         Update(0, r - 1, -x, 0, n - 2);       }       cout << tree[0].Max + 1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mm = 1e6 + 1;   const int mx = 1 << 20;   const int N = 3e5 + 10;   int a[N], b[N];   int seg_t[mx * 2 + 10], tag[mx * 2 + 10];   void up(int o) { seg_t[o] = max(seg_t[o << 1], seg_t[o << 1 | 1]); }   void down(int o) {     if (tag[o] == 0) {       return;     }     seg_t[o << 1] += tag[o];     tag[o << 1] += tag[o];     seg_t[o << 1 | 1] += tag[o];     tag[o << 1 | 1] += tag[o];     tag[o] = 0;   }   void update(int o, int l, int r, int ql, int qr, int v) {     if (ql <= l && r <= qr) {       seg_t[o] += v;       tag[o] += v;       return;     }     down(o);     int mid = (l + r) / 2;     if (mid >= ql) update(o << 1, l, mid, ql, qr, v);     if (mid < qr) update(o << 1 | 1, mid + 1, r, ql, qr, v);     up(o);   }   int query(int o, int l, int r) {     if (seg_t[o] <= 0) return -1;     if (l == r) return l;     down(o);     int mid = (l + r) / 2;     if (seg_t[o << 1 | 1] > 0) {       return query(o << 1 | 1, mid + 1, r);     }     return query(o << 1, l, mid);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];       update(1, 1, mm, 1, a[i], 1);     }     for (int i = 0; i < m; i++) {       cin >> b[i];       update(1, 1, mm, 1, b[i], -1);     }     int q;     cin >> q;     while (q--) {       int opt, x, y;       cin >> opt >> x >> y;       --x;       if (opt == 1 && a[x] != y) {         update(1, 1, mm, 1, a[x], -1);         a[x] = y;         update(1, 1, mm, 1, a[x], 1);       } else if (opt == 2 && b[x] != y) {         update(1, 1, mm, 1, b[x], 1);         b[x] = y;         update(1, 1, mm, 1, b[x], -1);       }       cout << query(1, 1, mm) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     long long int x1, y1;     cin >> x1 >> y1;     long long int x2, y2;     cin >> x2 >> y2;     int n;     cin >> n;     int ans = 0;     for (int i = 0; n > i; i++) {       long long int a, b, c;       cin >> a >> b >> c;       long long int res1 = a * x1 + b * y1 + c;       long long int res2 = a * x2 + b * y2 + c;       if ((res1 < 0 && res2 > 0) || (res1 > 0 && res2 < 0)) {         ans++;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long N;   long long F[20][10][10] = {{{0}}};   int to[20][10][10] = {{{0}}};   long long Ans[20][10] = {{0}};   void done() {     for (int i = 0; i <= 9; i++) {       for (int j = 0; j <= 9; j++) {         int x = max(i, j);         if (i == 0 || i < x) {           F[1][i][j] = 0;           to[1][i][j] = i;           continue;         }         F[1][i][j] = F[1][i - x][j] + 1;         to[1][i][j] = to[1][i - x][j];       }     }     for (int l = 2; l <= 18; l++) {       for (int i = 0; i <= 9; i++)         for (int j = 0; j <= 9; j++) {           long long cost = 0;           int cnt = i;           for (int x = 9; x >= 1; x--) {             cost += F[l - 1][cnt][max(x, j)];             cnt = to[l - 1][cnt][max(x, j)];             cost++;             cnt = 10 + cnt - max(max(j, x), cnt);           }           cost += F[l - 1][cnt][j];           cnt = to[l - 1][cnt][j];           F[l][i][j] = cost;           to[l][i][j] = cnt;         }     }     long long Ans = 0;     int Len = 0;     long long Cnt = N;     for (; Cnt > 0; Cnt /= 10, Len++)       ;     int remains = N % 10;     N /= 10;     for (int i = 1; i <= Len - 1; i++) {       int Need = N % 10;       N /= 10;       int Max = 0;       for (Cnt = N; Cnt > 0; Cnt /= 10) Max = max((long long)Max, Cnt % 10);       for (; Need >= 0; Need--) {         Ans += F[i][remains][max(Max, Need)];         remains = to[i][remains][max(Max, Need)];         if (Need > 0 || N > 0) {           Ans++;           remains = remains + 10 - max(max(Max, Need), remains);         }       }       N--;     }     cout << Ans << endl;     return;   }   int main() {     cin >> N;     if (N <= 9)       cout << (N > 0) << endl;     else       done();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int testcases;     cin >> testcases;     while (testcases--) {       long long int n, m;       cin >> n >> m;       char a[n][m];       for (long long int(i) = 0; (i) < (n); (i)++) {         for (long long int(j) = 0; (j) < (m); (j)++) cin >> a[i][j];       }       long long int cnt = 0;       for (long long int j = 0; j < m - 1; j++) {         if (a[n - 1][j] ==  D ) cnt++;       }       for (long long int(i) = 0; (i) < (n - 1); (i)++) {         if (a[i][m - 1] ==  R ) cnt++;       }       cout << cnt <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {-1, 1, 0, 0, 1, -1, 1, -1};   int dy[] = {0, -0, -1, 1, 1, -1, -1, 1};   void run() {}   int fixMod(int a, int b) { return ((a % b) + b) % b; }   long long gcd(long long a, long long b) {     return (b == 0 ? abs(a) : gcd(b, a % b));   }   void fast() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int n, m;   vector<vector<char>> grid;   bool flag = 0;   pair<int, int> per[1510][1510];   bool vis[1510][1510];   int stx, sty;   bool dfs(int x, int y) {     int xm = (x + n * 2000) % n;     int ym = (y + m * 2000) % m;     if (grid[xm][ym] ==  # ) return 0;     if (vis[xm][ym]) {       return per[xm][ym] != make_pair(x, y);     }     vis[xm][ym] = 1;     per[xm][ym] = {x, y};     bool ret = 0;     for (int i = 0; i < 4; i++) {       ret |= dfs(x + dx[i], y + dy[i]);     }     return ret;   }   int main() {     run();     fast();     cin >> n >> m;     grid.resize(n);     for (int i = 0; i < n; i++) {       grid[i].resize(m);       for (int j = 0; j < m; j++) {         cin >> grid[i][j];         if (grid[i][j] ==  S ) stx = i, sty = j;       }     }     if (dfs(stx, sty))       cout <<  YES             <<   n ;     else       cout <<  NO             <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     double x, y, r;   };   double dis(node a, node b) {     double dx = a.x - b.x, dy = a.y - b.y;     return sqrt(dx * dx + dy * dy);   }   double R, d;   node origin = {0, 0};   bool check(node a) {     double distance = dis(a, origin);     if (distance - a.r >= R - d && distance + a.r <= R) return true;     return false;   }   int main() {     scanf( %lf%lf , &R, &d);     int k, ans = 0;     scanf( %d , &k);     while (k--) {       node now;       scanf( %lf%lf%lf , &now.x, &now.y, &now.r);       if (check(now)) ans++;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300050;   const int M = 2 * N;   char s[M];   int tot, sa[M], id[M], fwid[N], bwid[N];   vector<pair<pair<int, int>, int> > tmp;   void BuildSuffixArray() {     int i, j, cnt;     s[++tot] =  a  + 26;     for (i = 1; i <= tot; i++) id[i] = s[i] -  a ;     for (j = 0; j < 20; j++) {       tmp.clear();       for (i = 1; i <= tot; i++)         tmp.push_back(make_pair(make_pair(id[i], id[i + (1 << j)]), i));       sort(tmp.begin(), tmp.end());       cnt = 0;       for (i = 0; i < tmp.size(); i++) {         id[tmp[i].second] = cnt;         cnt += (tmp[i].first != tmp[i + 1].first);       }       if (cnt == tot) break;     }     for (i = 1; i <= tot; i++) id[i]++;     for (i = 1; i <= tot; i++) sa[id[i]] = i;   }   int max(int a, int b) { return a > b ? a : b; }   int min(int a, int b) { return a > b ? b : a; }   int lcp[M];   void BuildLCPArray() {     int i, k = 0, j;     for (i = 1; i <= tot; i++) {       if (id[i] == tot) continue;       j = sa[id[i] + 1];       while (max(i, j) + k <= tot && s[i + k] == s[j + k]) k++;       lcp[id[i]] = k;       if (k > 0) k--;     }   }   int logs[M];   void Preprocess() {     for (int i = 2; i < M; i++) logs[i] = logs[i >> 1] + 1;   }   int rmq[M][21];   void BuildSparseTable() {     int i, j;     for (i = 1; i <= tot; i++) rmq[i][0] = lcp[i];     for (j = 1; j < 21; j++) {       for (i = 1; i <= tot - (1 << j) + 1; i++) {         rmq[i][j] = min(rmq[i][j - 1], rmq[i + (1 << j - 1)][j - 1]);       }     }   }   void Swap(int &a, int &b) {     a ^= b;     b ^= a;     a ^= b;   }   int RMQ(int l, int r) {     l = id[l];     r = id[r];     if (l > r) Swap(l, r);     if (l == r) return tot - sa[l] + 1;     r--;     int k = logs[r - l + 1];     return min(rmq[l][k], rmq[r - (1 << k) + 1][k]);   }   int sz[N], dep[N], par[N][19];   vector<int> E[N];   void DFS(int u, int p) {     dep[u] = dep[p] + 1;     sz[u] = 1;     par[u][0] = p;     int i;     for (i = 1; i < 19; i++) par[u][i] = par[par[u][i - 1]][i - 1];     for (i = 0; i < E[u].size(); i++) {       int v = E[u][i];       if (v != p) DFS(v, u), sz[u] += sz[v];     }   }   int LCA(int u, int v) {     if (dep[u] < dep[v]) return LCA(v, u);     int i;     for (i = 18; ~i; i--)       if (dep[par[u][i]] >= dep[v]) u = par[u][i];     for (i = 18; ~i; i--)       if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i];     return v == u ? v : par[v][0];   }   int Chain[N];   vector<int> Head, Tail[N];   void HLD(int u, int p) {     if (!Chain[u]) {       Chain[u] = Head.size();       Head.push_back(u);     }     Tail[Chain[u]].push_back(u);     int i, HC = 0;     for (i = 0; i < E[u].size(); i++) {       int v = E[u][i];       if (v != p && sz[v] > sz[HC]) HC = v;     }     if (HC) {       Chain[HC] = Chain[u];       HLD(HC, u);       for (i = 0; i < E[u].size(); i++) {         int v = E[u][i];         if (v != p && v != HC) HLD(v, u);       }     }   }   char ch[N];   void BuildString() {     int i, j;     for (i = 1; i < Head.size(); i++) {       for (j = Tail[i].size() - 1; ~j; j--) {         int v = Tail[i][j];         fwid[v] = ++tot;         s[tot] = ch[v];       }       for (j = 0; j < Tail[i].size(); j++) {         int v = Tail[i][j];         bwid[v] = ++tot;         s[tot] = ch[v];       }     }   }   vector<pair<int, int> > Take(int u, int v) {     vector<pair<int, int> > ret, tmp;     int lca = LCA(u, v), i;     while (Chain[u] != Chain[lca]) {       ret.push_back(make_pair(fwid[u], fwid[Head[Chain[u]]]));       u = par[Head[Chain[u]]][0];     }     while (Chain[v] != Chain[lca]) {       tmp.push_back(make_pair(bwid[Head[Chain[v]]], bwid[v]));       v = par[Head[Chain[v]]][0];     }     if (v != lca)       ret.push_back(make_pair(bwid[lca], bwid[v]));     else       ret.push_back(make_pair(fwid[u], fwid[lca]));     for (i = tmp.size() - 1; ~i; i--) ret.push_back(tmp[i]);     return ret;   }   int main() {     Head.push_back(69 & -69);     int n, q, i, j, u, v, a, b, c, d, k;     scanf( %i , &n);     scanf( %s , ch + 1);     for (i = 1; i < n; i++)       scanf( %i %i , &u, &v), E[u].push_back(v), E[v].push_back(u);     DFS(1, 0);     HLD(1, 0);     BuildString();     BuildSuffixArray();     BuildLCPArray();     Preprocess();     BuildSparseTable();     scanf( %i , &q);     while (q--) {       scanf( %i %i %i %i , &a, &b, &c, &d);       if (ch[a] != ch[c]) {         printf( 0 n );         continue;       }       vector<pair<int, int> > tmp1, tmp2;       tmp1 = Take(a, b);       tmp2 = Take(c, d);       i = 0;       j = 0;       int ans = 0;       while (i < tmp1.size() && j < tmp2.size()) {         int sol = RMQ(tmp1[i].first, tmp2[j].first);         sol = min(sol, tmp1[i].second - tmp1[i].first + 1);         sol = min(sol, tmp2[j].second - tmp2[j].first + 1);         ans += sol;         tmp1[i].first += sol;         tmp2[j].first += sol;         bool ok = 0;         if (tmp1[i].first > tmp1[i].second) i++, ok = 1;         if (tmp2[j].first > tmp2[j].second) j++, ok = 1;         if (!ok) break;       }       printf( %i n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nMAX = 100000 + 5;   const int NMAX = 2 * nMAX;   int n, m;   string S, T;   int Q;   int N;   string str;   const int MOD[] = {1000000000 + 7, 1000000000 + 9};   struct Hash {     int h[sizeof(MOD) / sizeof(int)];     Hash() {       for (int i = 0; i < sizeof(MOD) / sizeof(int); ++i) h[i] = 0;     }     Hash(int v0, int v1) { h[0] = v0, h[1] = v1; }     Hash operator+(const Hash &hs) const {       Hash res;       for (int i = 0; i < sizeof(MOD) / sizeof(int); ++i) {         res.h[i] = h[i] + hs.h[i];         if (res.h[i] >= MOD[i]) res.h[i] -= MOD[i];       }       return res;     }     Hash operator-(const Hash &hs) const {       Hash res;       for (int i = 0; i < sizeof(MOD) / sizeof(int); ++i) {         res.h[i] = h[i] - hs.h[i];         if (res.h[i] < 0) res.h[i] += MOD[i];       }       return res;     }     Hash operator*(const Hash &hs) const {       Hash res;       for (int i = 0; i < sizeof(MOD) / sizeof(int); ++i)         res.h[i] = (1LL * h[i] * hs.h[i]) % MOD[i];       return res;     }     bool operator==(const Hash &hs) const {       for (int i = 0; i < sizeof(MOD) / sizeof(int); ++i)         if (h[i] != hs.h[i]) return false;       return true;     }     bool operator!=(const Hash &hs) const {       for (int i = 0; i < sizeof(MOD) / sizeof(int); ++i)         if (h[i] != hs.h[i]) return true;       return false;     }   };   const Hash C = {666013, 666017};   Hash powC[NMAX];   Hash sPart[NMAX];   void precomputeHashes() {     powC[0] = Hash(1, 1);     for (int i = 1; i <= N; ++i) powC[i] = powC[i - 1] * C;     for (int i = 1; i <= N; ++i)       sPart[i] = sPart[i - 1] * C + Hash(str[i], str[i]);   }   Hash getHashS(int l, int r) {     Hash hr = sPart[r];     Hash hl = sPart[l - 1];     return hr - hl * powC[r - l + 1];   }   Hash getHashT(int l, int r) {     Hash hr = sPart[r + n + 1];     Hash hl = sPart[l - 1 + n + 1];     return hr - hl * powC[r - l + 1];   }   bool lcp(int l, int r) {     int st = 1;     int dr = min(N - l + 1, N - r + 1);     int ans = 0;     while (st <= dr) {       int mid = (st + dr) >> 1;       if (getHashS(l, l + mid - 1) == getHashS(r, r + mid - 1)) {         ans = mid;         st = mid + 1;       } else         dr = mid - 1;     }     return str[l + ans] < str[r + ans];   }   int lcpSS(int l, int r) { return lcp(l, r); }   int lcpST(int l, int r) { return lcp(l, r + n + 1); }   int lcpTS(int l, int r) { return lcp(l + n + 1, r); }   int lcpTT(int l, int r) { return lcp(l + n + 1, r + n + 1); }   bool cmpPlacement(const int &_a, const int &_b) {     int a = _a + 1, b = _b + 1;     bool rev = false;     if (b < a) {       swap(a, b);       rev = true;     }     if (b <= a + m) {       if (getHashT(1, b - a) != getHashS(a, b - 1))         return lcpTS(1, a) ^ rev;       else if (getHashT(b - a + 1, m) != getHashT(1, a + m - b))         return lcpTT(b - a + 1, 1) ^ rev;       else if (getHashS(a, b - 1) != getHashT(a + m - b + 1, m)) {         return lcpST(a, a + m - b + 1) ^ rev;       }     } else {       if (getHashT(1, m) != getHashS(a, a + m - 1))         return lcpTS(1, a) ^ rev;       else if (getHashS(a, b - m - 1) != getHashS(a + m, b - 1)) {         return lcpSS(a, a + m) ^ rev;       } else if (getHashS(b - m, b - 1) != getHashT(1, m))         return lcpST(b - m, 1) ^ rev;     }     return false;   }   string ins(string a, string b, int pos) {     a.insert(pos, b);     return a;   }   int ord[NMAX];   int inv[NMAX];   int logar2[NMAX];   void precLogar2() {     for (int i = 2; i <= N; ++i) logar2[i] = 1 + logar2[i >> 1];   }   const int RAD = 150;   struct RMQ {     vector<int> v;     int dims;     int **dp;     void destroy() {       v.clear();       for (int i = 0; i <= dims; ++i) delete dp[i];       delete dp;       dims = 0;     }     void computeDp() {       dims = logar2[v.size()];       if ((1 << dims) < v.size()) ++dims;       dp = new int *[dims + 1];       for (int i = 0; i <= dims; ++i) {         dp[i] = new int[v.size()];       }       for (int i = 0; i < v.size(); ++i) dp[0][i] = v[i];       for (int i = 1; i <= dims; ++i)         for (int j = 0; j + (1 << i) - 1 < v.size(); ++j)           if (inv[dp[i - 1][j]] < inv[dp[i - 1][j + (1 << (i - 1))]])             dp[i][j] = dp[i - 1][j];           else             dp[i][j] = dp[i - 1][j + (1 << (i - 1))];     }     int query(int a, int b) {       if (b < a) return n + 1;       int y = logar2[b - a + 1];       if (inv[dp[y][a]] < inv[dp[y][b - (1 << y) + 1]]) return dp[y][a];       return dp[y][b - (1 << y) + 1];     }   } all;   RMQ rmqs[RAD + 5];   struct Query {     int l, r, x, y;     int pos;   };   vector<Query> queries[RAD + 5];   int anss[NMAX];   int main() {     ios_base ::sync_with_stdio(false);     cin >> S >> T >> Q;     n = S.size();     m = T.size();     str =  #  + S +  #  + T;     N = str.size() - 1;     str +=  # ;     precomputeHashes();     for (int i = 0; i <= n; ++i) ord[i] = i;     stable_sort(ord, ord + n + 1, cmpPlacement);     for (int i = 0; i <= n; ++i) inv[ord[i]] = i;     inv[n + 1] = n + 2;     precLogar2();     all.v.resize(n + 1);     for (int i = 0; i <= n; ++i) {       all.v[i] = i;     }     all.computeDp();     for (int i = 1; i <= Q; ++i) {       int l, r, k, x, y;       cin >> l >> r >> k >> x >> y;       int ans = n + 1;       if (k > RAD) {         if (x <= l % k && l % k <= y) {           ans = all.query(l, min(r, l + y - l % k));           l += y - l % k + 1;         }         l += (k + x - l % k) % k;         while (l <= r) {           int aux = all.query(l, min(r, l + y - x));           if (inv[aux] < inv[ans]) ans = aux;           l += k;         }         if (ans == n + 1)           anss[i] = -1;         else           anss[i] = ans;       } else {         queries[k].push_back({l, r, x, y, i});       }     }     for (int k = 1; k <= RAD; ++k) {       for (int i = 0; i <= n; ++i) rmqs[i % k].v.push_back(i);       for (int res = 0; res < k; ++res) rmqs[res].computeDp();       for (auto it : queries[k]) {         int x = it.x;         int y = it.y;         int l = it.l;         int r = it.r;         int pos = it.pos;         int ans = n + 1;         for (int res = x; res <= y && res <= r; ++res) {           int a, b;           b = (r - res) / k;           if (l - res < 0)             a = 0;           else             a = (l - res + k - 1) / k;           int qu = rmqs[res].query(a, b);           if (inv[qu] < inv[ans]) ans = qu;         }         if (ans == n + 1)           anss[pos] = -1;         else           anss[pos] = ans;       }       for (int res = 0; res < k; ++res) rmqs[res].destroy();     }     for (int i = 1; i <= Q; ++i) cout << anss[i] <<    n [i == Q];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, s;   int a[105];   double f[105][10005];   int main() {     cin >> n >> x;     for (int i = 1; i <= n; i++) cin >> a[i], s += a[i];     f[0][0] = 1;     for (int i = 1; i <= n; i++)       for (int j = i; j >= 1; j--)         for (int k = s; k >= a[i]; k--)           f[j][k] += f[j - 1][k - a[i]] * j / (n - j + 1);     double ans = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= s; j++)         ans += f[i][j] * (min((n + i) * x, j * 2) / 2.0) / i;     printf( %.10lf , ans);     return 0;   }


#include <bits/stdc++.h>   const int INF = 1e6;   using namespace std;   const int maxn = 1e5 + 5;   const int N = 1e6;   const int big = 1e9;   long long int get(long long int a, long long int b, long long int x,                     long long int y) {     x--;     y--;     long long int temp = (y * (y - 1) - x * (x - 1)) / 2;     return a * (y - x) + b * temp;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long int a, b, n, i, l, m, t;     cin >> a >> b >> n;     for (i = 0; i < n; i++) {       cin >> l >> t >> m;       long long int st = l;       long long int en = 2e6 + 5;       while (en - st > 1) {         long long int mid = st + (en - st) / 2;         if ((a + (mid - 2) * b) <= t && get(a, b, l, mid) <= m * t)           st = mid;         else           en = mid;       }       if (st == l) st = 0;       cout << st - 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   queue<pair<int, int> > q;   vector<pair<int, int> > v;   vector<vector<int> > g;   set<pair<int, int> > out;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       v.push_back({x, y});       if (x == 1) q.push({i, y});     }     while (!q.empty()) {       pair<int, int> x = q.front();       q.pop();       int y = x.second;       v[y].second ^= x.first;       v[y].first--;       out.insert({min(x.first, y), max(x.first, y)});       if (v[y].first == 1) {         q.push({y, v[y].second});       }     }     cout << out.size() <<   n ;     for (auto a : out) {       cout << a.first <<     << a.second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, x, y, i, s = 0, k = 0;     vector<pair<long long int, long long int> > v;     cin >> n >> m;     for (i = 0; i < m; i++) {       cin >> x >> y;       v.push_back(make_pair(y, x));     }     sort(v.begin(), v.end());     for (i = v.size() - 1; i >= 0; i--) {       if (n > 0) {         if (v[i].second >= n) {           s = s + n * v[i].first;           n = 0;         } else {           s = s + v[i].second * v[i].first;           n = n - v[i].second;         }       } else {         k = -1;         cout << s << endl;         break;       }     }     if (k == 0) cout << s << endl;   }


#include <bits/stdc++.h>   using namespace std;   int v[100010];   int main() {     int n, k;     scanf( %d %d , &n, &k);     int low = 1000000001;     for (int i = 0; i < n; i++) {       scanf( %d , &v[i]);       low = min(low, v[i]);     }     long long ans = 0;     for (int i = 0; i < n && ans != -1; i++) {       if ((v[i] - low) % k == 0) {         ans += (v[i] - low) / k;       } else         ans = -1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     stack<char> a;     int count = 0, flag = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  {  || s[i] ==  [  || s[i] ==  <  || s[i] ==  ( )         a.push(s[i]);       else {         if (a.size() == 0) {           cout <<  Impossible ;           return 0;         }         if (a.top() ==  (  && s[i] !=  )  || a.top() ==  {  && s[i] !=  }  ||             a.top() ==  [  && s[i] !=  ]  || a.top() ==  <  && s[i] !=  > )           count++;         a.pop();       }     }     if (a.size() == 0 && flag == 0)       cout << count;     else       cout <<  Impossible ;     return 0;   }


#include <bits/stdc++.h>      using namespace std;   using ll = long long;      #ifdef LOCAL   #define debug(...) {       std::cout <<  [  << __FUNCTION__ <<  :  << __LINE__ <<  ]   << #__VA_ARGS__ <<      << __VA_ARGS__ << std::endl;       }   #else   #define debug(...)   #endif      const long long mod = 1000000007;   #define MOD(x) ((x)%mod)   struct UnionFind {    vector<int> par;    vector<int> siz;    vector<int> val;    UnionFind(int N) {     par.resize(N);     siz.resize(N);     val.resize(N);        for (int i = 0; i < N; i++) {      par[i] = i;      siz[i] = 1;         val[i] = 0;     }    }    int& operator[](const int &x) {     return val[getParent(x)];    }    int getParent(int x) {     int t = x;        while (par[x] != x) {      x = par[x];     }        par[t] = x;     return x;    }    int getSize(const int &x) {     return siz[getParent(x)];    }    bool merge(int x, int y) {     x = getParent(x);     y = getParent(y);        if (x == y) {      return false;     }        if (val[x] and val[y]) {      return false;     }        if (siz[x] > siz[y]) {      swap(x, y);    // siz[x] is smaller     }        par[x] = y;     siz[y] += siz[x];     val[y] = val[x] or val[y];     return true;       }    bool connected(const int &x, const int &y) {     return getParent(x) == getParent(y);    }   };   long long power(long long x, long long n) {    int i = 0;    long long d = x;    long long ats = 1;       while (n > 0) {     if (n & (1ll << i)) {      n ^= (1ll << i);      ats *= d;      ats %= mod;     }        i++;     d = (d * d) % mod;    }       return ats;   }   /*input   3 2   1 1   1 2   2 2 1   */   /*input   2 3   2 1 3   2 1 2   */   /*input   3 5   2 1 2   1 3   1 4   */   int main() {    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);    long long n, m;    cin >> n >> m;       UnionFind par(m);       set<int> imt;       for (int i = 0; i < n; ++i) {     int k;     cin >> k;        if (k == 1) {      int a;      cin >> a;      a--;         if (!par[a]) {       par[a] = true;       imt.insert(i);      }     }     else if (k == 2) {      int a, b;      cin >> a >> b;      a--, b--;         if (par.merge(a, b)) {       imt.insert(i);      }     }    }       long long vis = 0;       for (int i = 0; i < m; ++i) {     if (par.getParent(i) == i) {      if (par.val[i]) {       vis += par.siz[i];      }      else {       vis += par.siz[i] - 1;      }     }    }       cout << power(2, vis) <<     << imt.size() <<   n ;       for (auto &&i : imt) {     cout << i + 1 <<    ;    }   }


#include <bits/stdc++.h>   using namespace std;   int const maxn = int(2 * 1e5 + 5);   int dp1[maxn], dp2[maxn], dp3[maxn], n, k, t;   string second;   char chuyen(char c) {     if (c ==  R ) return  G ;     if (c ==  G ) return  B ;     if (c ==  B ) return  R ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> t;     while (t--) {       cin >> n >> k >> second;       second =     + second;       for (int i = 0; i <= second.length(); i++) {         dp1[i] = dp2[i] = dp3[i] = 0;       }       char c =  R ;       for (int i = 1; i <= second.length() - 1; i++) {         if (second[i] != c)           dp1[i] = dp1[i - 1] + 1;         else           dp1[i] = dp1[i - 1];         c = chuyen(c);       }       c =  G ;       for (int i = 1; i <= second.length() - 1; i++) {         if (second[i] != c)           dp2[i] = dp2[i - 1] + 1;         else           dp2[i] = dp2[i - 1];         c = chuyen(c);       }       c =  B ;       for (int i = 1; i <= second.length() - 1; i++) {         if (second[i] != c)           dp3[i] = dp3[i - 1] + 1;         else           dp3[i] = dp3[i - 1];         c = chuyen(c);       }       int res = int(1e9 + 5);       for (int i = 1; i <= second.length() - k; i++) {         res = min(res, dp1[i + k - 1] - dp1[i - 1]);         res = min(res, dp2[i + k - 1] - dp2[i - 1]);         res = min(res, dp3[i + k - 1] - dp3[i - 1]);       }       cout << res <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   int main() {     int h, w, k, count = 0;     scanf( %d %d %d , &h, &w, &k);     for (size_t i = 0; i < k; i++) {       if (h == 1 && w == 1) {         count++;       } else if (h == 1) {         count += w;       } else if (w == 1) {         count += h;       } else {         count += (h * 2) + (w - 2) * 2;       }       h -= 4;       w -= 4;     }     printf( %d n , count);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   int x[2001], y[2001];   bool sameLine(int i, int j, int k) {     return (y[i] - y[j]) * (x[k] - x[j]) == (y[k] - y[j]) * (x[i] - x[j]);   }   int main() {     scanf( %d , &N);     for (int i = 0; i < N; i++) scanf( %d %d , &x[i], &y[i]);     long long ans = 0;     for (int i = 0; i < N; i++) {       for (int j = i + 1; j < N; j++) {         for (int k = j + 1; k < N; k++) {           if (!sameLine(i, j, k)) ans++;         }       }     }     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int f(long long p) {     int ans = 0;     while (p) {       ans += p % 10;       p /= 10;     }     return ans;   }   long long g(long long a) {     if (a == 0) return 0;     int digit = 0;     long long b = a;     while (b >= 10) {       digit++;       b /= 10;     }     int b_digit = b;     long long ans = b * digit;     for (int i = 0; i < digit; i++) ans *= 10, b *= 10;     ans *= 9;     ans /= 2;     for (int i = 0; i < b_digit; i++) ans += i * (b / b_digit);     ans += g(a - b) + b_digit * (a - b + 1);     return ans;   }   int main() {     long long a;     scanf( %lld , &a);     long long l = 1, r = 20000000000000000LL;     while (l < r) {       long long mid = (l + r) / 2;       if (g(mid) >= a)         r = mid;       else         l = mid + 1;     }     l = 1;     long long cur = g(r);     while (cur != a) {       if (cur > a) {         cur -= f(l);         l++;       } else {         cur += f(r + 1);         r++;       }     }     printf( %lld %lld , l, r);   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T euclideanistance(T x1, T x2, T y1, T y2) {     return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));   }   template <class T>   T digitSum(T n) {     T sum = 0;     while (n > 0) sum += n % 10, n /= 10;     return sum;   }   const double INF = 1e+9;   const double EPS = 1e-9;   const double PI = 3.1415926;   const int knightDir[8][2] = {{-2, -1}, {-2, 1}, {-1, 2},  {1, 2},                                {2, -1},  {2, 1},  {-1, -2}, {1, -2}};   const int dx[] = {-1, 0, 1, 0};   const int dy[] = {0, 1, 0, -1};   int chk(pair<int, int> a, pair<int, int> b) {     if (a.first == b.first && a.first != b.second && a.second != b.first &&         a.second != b.second)       return 1;     if (a.first != b.first && a.first == b.second && a.second != b.first &&         a.second != b.second)       return 1;     if (a.first != b.first && a.first != b.second && a.second == b.first &&         a.second != b.second)       return 1;     if (a.first != b.first && a.first != b.second && a.second != b.first &&         a.second == b.second)       return 1;     return 0;   }   int getIndex(pair<int, int> a, pair<int, int> b) {     if (a.first == b.first && a.first != b.second && a.second != b.first &&         a.second != b.second)       return a.first;     if (a.first != b.first && a.first == b.second && a.second != b.first &&         a.second != b.second)       return a.first;     if (a.first != b.first && a.first != b.second && a.second == b.first &&         a.second != b.second)       return a.second;     if (a.first != b.first && a.first != b.second && a.second != b.first &&         a.second == b.second)       return a.second;   }   int main() {     int n, m, can = 0, all = 0;     vector<pair<int, int> > a, b;     scanf( %d%d , &n, &m);     a.resize(n);     b.resize(m);     for (int i = 0; i < n; i++) scanf( %d%d , &a[i].first, &a[i].second);     for (int i = 0; i < m; i++) scanf( %d%d , &b[i].first, &b[i].second);     vector<int> alls(10);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (chk(a[i], b[j])) {           vector<int> c1(10);           vector<int> c2(10);           for (int k = 0; k < m; k++) {             if (chk(a[i], b[k])) {               c1[getIndex(a[i], b[k])] = 1;             }           }           for (int k = 0; k < n; k++) {             if (chk(a[k], b[j])) {               c2[getIndex(a[k], b[j])] = 1;             }           }           if (count(c1.begin(), c1.end(), 1) == 1 &&               count(c2.begin(), c2.end(), 1) == 1)             can++;           alls[getIndex(a[i], b[j])] = 1;           all++;         }       }     }     if (count(alls.begin(), alls.end(), 1) == 1) {       for (int i = 1; i <= 10; i++) {         if (alls[i]) {           printf( %d n , i);           return 0;         }       }     }     if (can == all) {       printf( 0 n );       return 0;     }     printf( -1 n );   }


#include <bits/stdc++.h>   using namespace std;   long long lcis(long long a[], long long n) {     unordered_map<long long, long long> make_pair;     long long dp[n], lastIndex;     memset(dp, 0, sizeof(dp));     ;     long long mx = INT_MIN;     for (long long i = 0; i < n; i++) {       if (make_pair.find(a[i] - 1) != make_pair.end())         lastIndex = make_pair[a[i] - 1] - 1, dp[i] = 1 + dp[lastIndex];       else         dp[i] = 1;       make_pair[a[i]] = i + 1;       mx = max(mx, dp[i]);     }     return mx;   }   int main() {     long long n;     cin >> n;     long long arr[n];     for (long long i = 0; i < n; i++) cin >> arr[i];     long long li = lcis(arr, n);     cout << n - li << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e16 + 3;   const int mod = 1e9 + 7;   const int lim = 2e5 + 2;   int q, ni;   string str;   void solve() {     cin >> q;     while (q--) {       cin >> ni >> str;       if (ni > 2) {         cout <<  YES               <<   n ;         cout << 2 <<   n ;         cout << str[0] <<    ;         for (int i = 1; i < ni; i++) cout << str[i];         cout <<   n ;       } else {         int f = str[0] -  0 ;         int s = str[1] -  0 ;         if (f < s) {           cout <<  YES                 <<   n ;           cout << 2 <<   n ;           cout << str[0] <<     << str[1] <<   n ;         } else           cout <<  NO                 <<   n ;       }     }   }   void fastIO() {     cin.sync_with_stdio(false);     cin.tie(0);   }   void IO() {     if (fopen( d:  lmo.in ,  r ) != NULL) {       freopen( d:  lmo.in ,  r , stdin);     } else if (fopen( /media/luismo/Pablo s Destruction/lmo.in ,  r ) != NULL) {       freopen( /media/luismo/Pablo s Destruction/lmo.in ,  r , stdin);     }   }   int main() {     IO();     fastIO();     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2e9;   const long long LINF = 2e18;   void inv(bool e);   template <typename T>   void die(T& a);   bool brute, alter;   int cnt_tests = 1;   const int N = (1 << 17) + 1;   int degree[N], xr[N];   int n;   void inp() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> degree[i] >> xr[i];     }   }   set<int> friends[N];   void solve() {     for (int i = 0; i < n; i++) {       friends[degree[i]].insert(i);     }     int newbie, parent;     auto& cur = friends[1];     vector<pair<int, int> > ans;     while (!cur.empty()) {       newbie = *cur.begin();       cur.erase(cur.begin());       parent = xr[newbie];       friends[degree[parent]].erase(parent);       friends[degree[parent] - 1].insert(parent);       degree[parent]--;       ans.push_back({newbie, parent});       xr[parent] ^= newbie;     }     cout << ((int)(ans).size()) << endl;     for (auto x : ans) {       cout << x.first <<     << x.second << endl;     }   }   void stress() {}   void naive() {}   void run();   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     if (0) {       freopen( stack.in ,  r , stdin);       freopen( stack.out ,  w , stdout);     }     brute = false;     for (int i = 0; (i < cnt_tests); i++) {       run();     }     cerr << endl <<  Time:   << clock() / 1000.0 <<   ms ;     return 0;   }   void run() {     if (!brute) {       inp();     } else {       stress();     }     solve();   }   template <typename T>   void die(T& a) {     cout << a;     exit(0);   }   void inv(bool e) {     if (!e) {       vector<int> a;       a[-1] += 1;     }   }


#include <bits/stdc++.h>   using namespace std;   void ga(int N, int *A) {     for (int i(0); i < N; i++) scanf( %d , A + i);   }   char s[64][64];   int N, M, x = int(1e9 + 1), X, y = int(1e9 + 1), Y;   int main(void) {     scanf( %d%d , &N, &M);     for (int i(0); i < N; i++) scanf( %s , s[i]);     for (int i(0); i < N; i++)       for (int j(0); j < M; j++)         if (s[i][j] == 42)           x = min(x, i), X = max(X, i), y = min(y, j), Y = max(Y, j);     for (int k(x); k < X + 1; k++) {       for (int l(y); l < Y + 1; l++) putchar(s[k][l]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 10;   int mapp[110][110];   int b[110][110];   int main() {     int Cas = 1;     scanf( %d , &Cas);     while (Cas--) {       int n, m;       scanf( %d%d , &n, &m);       memset(mapp, 0, sizeof(mapp));       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) {           scanf( %d , &mapp[i][j]);           int flag = (i + j) % 2;           if (mapp[i][j] % 2 == flag)             b[i][j] = mapp[i][j];           else             b[i][j] = mapp[i][j] + 1;         }       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) printf( %d%c , b[i][j], j == m ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mxn = 1e5 + 1;   string s, s1, s2, s3;   char ch[10000][10000];   int main() {     long long int n, m, i, z, j, a = 0, ans = 0, k = 0, cnt = 0, b;     long long int c = 0, x, y, d = 0, sum = 0, mn = INT_MAX, mx = 0;     string ss, strn;     char ch;     cin >> n;     long long int evn[n + 1], odd[n + 1], e = 0, o = 0;     long long int ara[n + 2], bra[n + 1], cra[n + 1];     map<long long int, long long int> mp;     set<long long int> st;     set<long long int>::iterator sit;     priority_queue<long long int> pq;     for (i = 1; i <= n; i++) {       cin >> ara[i];     }     sort(ara + 1, ara + n + 1);     for (i = n; i > 1; i--) {       x = abs(ara[i] - ara[i - 1]);       if (x <= 1) {         if (!cnt) a = ara[i - 1];         if (cnt == 1) b = ara[i - 1];         cnt++;         if (cnt == 2) {           ans += (a * b);           cnt = 0;         }         --i;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int T = 1000;   const long long MAX = 1000000000000007;   const long long MOD = 100000000;   long long n, m, k;   vector<long long> A[T];   vector<pair<char, int> > ans;   long long K[T];   long long N[T];   int main() {     cin >> n;     for (int i = (int)0; i <= (int)n - 1; i++) {       cin >> N[i];     }     cin >> k;     for (int i = (int)0; i <= (int)k - 1; i++) {       cin >> K[i];     }     int j = 0;     for (int i = (int)0; i <= (int)k - 1; i++) {       long long sum = 0;       while (sum < K[i] && j <= n - 1) {         sum += N[j];         A[i].push_back(N[j]);         j++;       }       if (sum != K[i]) {         cout <<  NO  << endl;         return 0;       }       if (A[i].size() == 1) {         continue;       }       long long ma = 0;       for (int g = (int)0; g <= (int)A[i].size() - 1; g++) {         ma = max(ma, A[i][g]);       }       bool can = false;       for (int g = (int)0; g <= (int)A[i].size() - 1; g++) {         if (A[i][g] == ma) {           if (g != 0 && A[i][g - 1] < ma ||               g != A[i].size() - 1 && A[i][g + 1] < ma) {             can = true;           }           if (can) {             while (A[i].size() != 1) {               if (g != 0 && A[i][g - 1] < ma) {                 ma = ma + A[i][g - 1];                 A[i][g - 1] = ma;                 ans.push_back(make_pair( L , i + g + 1));                 A[i].erase(A[i].begin() + g - 1);                 g--;               } else {                 if (g != A[i].size() - 1 && A[i][g + 1] < ma) {                   ma = ma + A[i][g + 1];                   A[i][g] = ma;                   ans.push_back(make_pair( R , i + g + 1));                   A[i].erase(A[i].begin() + g);                 }               }             }             break;           }         }       }       if (!can) {         cout <<  NO  << endl;         return 0;       }     }     if (j == n) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;       return 0;     }     for (int i = (int)0; i <= (int)ans.size() - 1; i++) {       cout << ans[i].second <<     << ans[i].first << endl;     }     return 0;   }


#include <bits/stdc++.h>   int n, i, j, k, t, len;   char st[200];   int main() {     scanf( %d , &n);     while (n--) {       scanf( %s , st);       len = strlen(st);       t = 8;       for (i = 0; i < len; i++)         if (st[i] !=  : ) {           t--;           while (i < len && st[i] !=  : ) i++;         }       j = 0;       for (i = 0; i < len; i++) {         if (st[i] ==  : ) {           if (j != i) {             if (j != 0) printf( : );             for (k = 0; k < 4 - i + j; k++) printf( 0 );             for (k = j; k < i; k++) printf( %c , st[k]);           }           if (st[i + 1] ==  : ) {             if (j == i)               printf( 0000 );             else               printf( :0000 );             for (k = 1; k < t; k++) printf( :0000 );             i++;           }           j = i + 1;         }       }       if (st[len - 1] !=  : ) {         printf( : );         for (k = 0; k < 4 - i + j; k++) printf( 0 );         for (k = j; k < i; k++) printf( %c , st[k]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Z = (int)1e5 + 111;   const int inf = (int)1e9 + 111;   const long long llinf = (long long)1e18 + 5;   const int MOD = (int)1e9 + 7;   vector<int> ans[Z];   int a[Z];   pair<int, int> b[Z];   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       b[i].first = a[i];       b[i].second = i;     }     int cnt = 0;     sort(b + 1, b + 1 + n);     for (int i = 1; i <= n; ++i) {       if (a[i] == -inf) continue;       set<int> cur_pos;       cur_pos.insert(i);       int pos = lower_bound(b + 1, b + 1 + n, make_pair(a[i], -inf)) - b;       while (!cur_pos.count(pos)) {         int x = pos;         cur_pos.insert(pos);         pos = lower_bound(b + 1, b + 1 + n, make_pair(a[pos], -inf)) - b;         a[x] = -inf;       }       cnt++;       for (int to : cur_pos) {         ans[cnt].push_back(to);       }     }     cout << cnt <<   n ;     for (int i = 1; i <= cnt; ++i) {       cout << (int)ans[i].size() <<    ;       for (int j = 0; j < (int)ans[i].size(); ++j) {         cout << ans[i][j] <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const long long INF = 1e9;   const long long LINF = INF * INF;   const int MAX = 1 << 10;   void go(pair<int, int> s, pair<int, int> f, vector<pair<int, int> >& a) {     a.push_back(s);     while (s.first > f.first) {       s.first--;       a.push_back(s);     }     while (s.first < f.first) {       s.first++;       a.push_back(s);     }     while (s.second > f.second) {       s.second--;       a.push_back(s);     }     while (s.second < f.second) {       s.second++;       a.push_back(s);     }     a.push_back(f);   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     vector<pair<int, int> > a(3);     for (int i = (0); i < (3); ++i) cin >> a[i].first >> a[i].second;     vector<pair<int, int> > ans1, ans2;     sort(a.begin(), a.end());     go(a[0], a[1], ans1);     go(a[1], a[2], ans1);     go(a[0], {a[1].first, a[2].second}, ans2);     go(a[1], {a[1].first, a[2].second}, ans2);     go(a[2], {a[1].first, a[2].second}, ans2);     sort(ans1.begin(), ans1.end());     ans1.resize(unique(ans1.begin(), ans1.end()) - ans1.begin());     sort(ans2.begin(), ans2.end());     ans2.resize(unique(ans2.begin(), ans2.end()) - ans2.begin());     vector<pair<int, int> > ans = ans1;     if ((int)((ans2).size()) < (int)((ans1).size())) ans = ans2;     sort(ans.begin(), ans.end());     ans.resize(unique(ans.begin(), ans.end()) - ans.begin());     cout << (int)((ans).size()) << endl;     for (auto i : ans) cout << i.first <<     << i.second << endl;     cerr <<  Time elapsed:   << clock() / (double)CLOCKS_PER_SEC << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, h, j, w;   string s, t, v;   pair<string, int> k;   stack<int> p;   vector<pair<string, int>> a;   int main() {     cin >> s;     v = s;     t = s;     for (i = 0; i < s.size(); i++)       if (s[i] ==  (  || s[i] ==  [ ) p.push(i);     while (!p.empty()) {       j = p.top();       if (s[j] ==  (  && s[j + 1] ==  ) )         v[j] =  0 , v[v.find( ) , j)] =  0 , s.erase(j, 2);       if (s[j] ==  [  && s[j + 1] ==  ] )         v[j] =  0 , v[v.find( ] , j)] =  0 , s.erase(j, 2);       p.pop();     }     for (i = 0; i < v.size(); i++) {       if (v[i] ==  0 ) {         k.first += t[i];         if (t[i] ==  [ ) k.second++;       }       if (v[i] !=  0  && k.first.size() || i == v.size() - 1 && k.first.size())         a.push_back(k), k.first.clear(), h = max(h, k.second), k.second = 0;     }     if (!h)       cout << 0;     else if (!a.size())       cout << k.second << endl << k.first;     else {       for (i = 0; i < a.size(); i++)         if (a[i].second == h) {           cout << h << endl << a[i].first;           break;         }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k, p, x, y;     cin >> n >> k >> p >> x >> y;     long long int sum = 0;     long long int cov = 0;     for (int i = 0; i < k; i++) {       long long int kk;       cin >> kk;       if (kk < y) cov++;       sum += kk;     }     int used = k;     int remain;     if (cov > (n / 2)) {       cout <<  -1 ;       return 0;     } else {       remain = (n / 2) - cov;       if (remain > n - k) remain = n - k;       sum += remain;       used += remain;     }     int finalre = n - used;     if (sum + finalre * y <= x) {       for (int i = 0; i < remain; i++)         cout <<  1               <<    ;       for (int i = 0; i < finalre; i++) cout << y <<    ;     } else       cout <<  -1  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[110];   void in(long long &x, long long &y) {     scanf( %s , str);     int len = strlen(str);     int at;     for (int i = 0; i < len; i++)       if (str[i] ==  / ) at = i;     x = 0;     for (int i = 0; i < at; i++) x = x * 10 + (str[i] -  0 );     y = 0;     for (int i = at + 1; i < len; i++) y = y * 10 + (str[i] -  0 );   }   struct Point {     long long x, y;     void in() { scanf( %I64d %I64d , &x, &y); }   } p[100010], q[100010];   bool cmp_y(Point a, Point b) { return a.y > b.y; }   struct Node {     long long up, down;     int id;     bool operator==(Node a) { return up * a.down == down * a.up; }   } e[100010];   bool cmp(Node a, Node b) { return a.up * b.down < b.up * a.down; }   Point mark[100010];   int X[100010];   int Y[100010];   int totalx, totaly;   int max_value[100010 * 4];   void pushup(int rt) {     max_value[rt] = max(max_value[rt << 1], max_value[rt << 1 | 1]);   }   void update(int pos, int s, int l, int r, int rt) {     if (l == r) {       max_value[rt] = max(max_value[rt], s);       return;     }     int m = (l + r) / 2;     if (pos <= m)       update(pos, s, l, m, rt << 1);     else       update(pos, s, m + 1, r, rt << 1 | 1);     pushup(rt);   }   int query(int L, int R, int l, int r, int rt) {     if (R == 0) return 0;     if (L <= l && r <= R) return max_value[rt];     int m = (l + r) / 2;     int tmp = 0;     if (L <= m) tmp = max(tmp, query(L, R, l, m, rt << 1));     if (R > m) tmp = max(tmp, query(L, R, m + 1, r, rt << 1 | 1));     return tmp;   }   int pp[100010];   int qq;   int main() {     int n;     scanf( %d , &n);     long long Ax, Ay, Bx, By;     in(Ax, Ay);     in(Bx, By);     int m = 0;     for (int i = 0; i < n; i++) {       p[i].in();       if (Ax * p[i].x >= Ay * p[i].y || Bx * p[i].x <= By * p[i].y) continue;       q[m++] = p[i];     }     if (m == 0 || Ay == 0 || Bx == 0) {       printf( 0 n );       return 0;     }     n = m;     for (int i = 0; i < n; i++) p[i] = q[i];     for (int i = 0; i < n; i++) {       e[i].id = i;       e[i].up = p[i].y * Ay - p[i].x * Ax;       e[i].down = Ay;     }     sort(e, e + n, cmp);     totalx = 0;     X[e[0].id] = ++totalx;     for (int i = 1; i < n; i++) {       if (e[i] == e[i - 1])         X[e[i].id] = X[e[i - 1].id];       else         X[e[i].id] = ++totalx;     }     for (int i = 0; i < n; i++) {       e[i].id = i;       e[i].up = p[i].y * By - p[i].x * Bx;       e[i].down = By;       if (By == 0) {         e[i].up = -p[i].x;         e[i].down = 1;       }     }     sort(e, e + n, cmp);     totaly = 0;     Y[e[0].id] = ++totaly;     for (int i = 1; i < n; i++) {       if (e[i] == e[i - 1])         Y[e[i].id] = Y[e[i - 1].id];       else         Y[e[i].id] = ++totaly;     }     for (int i = 0; i < n; i++) mark[i].x = X[i], mark[i].y = Y[i];     sort(mark, mark + n, cmp_y);     memset(max_value, 0, sizeof(max_value));     int ans = 0;     int j = 0;     for (int i = 0; i < n; i = j) {       for (j = i; j < n; j++)         if (mark[i].y != mark[j].y) break;       for (int k = i; k < j; k++) {         int tmp = query(1, mark[k].x - 1, 1, n, 1) + 1;         ans = max(ans, tmp);         pp[k] = tmp;       }       for (int k = i; k < j; k++) update(mark[k].x, pp[k], 1, n, 1);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     int m;     cin >> n >> m;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     int ans = 0;     for (int i = 0; i < m; i++) {       if (a[i] >= 0) break;       ans += a[i];     }     cout << abs(ans) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct __s {     __s() {       if (1) {         ios_base::Init i;         cin.sync_with_stdio(0);         cin.tie(0);       }     }     ~__s() {       if (!1)         fprintf(stderr,  Execution time: %.3lf s. n ,                 (double)clock() / CLOCKS_PER_SEC);       long long n;       cin >> n;     }   } __S;   long long d[311111];   long long s[311111];   long long I[311111];   bool u[311111];   bool comp(long long i, long long j) { return d[i] < d[j]; }   int main(void) {     long long n, k;     cin >> n >> k;     long long cnt = 0;     for (long long i = 1; i <= n; i++) {       for (long long j = 2 * i; j <= n; j += i) {         d[j]++;       }       cnt += d[i];       s[i] = s[i - 1] + d[i];     }     d[1] = 1e18;     if (cnt < k) {       cout <<  No  <<   n ;       return 0;     }     for (long long i = 1; i <= n; i++) {       u[i] = true;       I[i] = i;       if (s[i] >= k) {         n = i;         cnt = s[i];         break;       }     }     sort(I + n / 2 + 1, I + n + 1, comp);     long long m = n;     for (long long ii = n; ii >= 1; ii--) {       long long i = I[ii];       if (k <= cnt - d[i]) {         cnt -= d[i];         u[i] = false;         m--;       }     }     cout <<  Yes  <<   n ;     cout << m <<   n ;     for (long long i = 1; i <= n; i++) {       if (u[i]) cout << i <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> nums;   int liking[7][7];   bool usable[7];   int team[7];   vector<int> members[3];   int mindifference, maxliking;   int a, b, c;   void teaming(int currteam, int memberno) {     int i, j, t;     if (currteam == 2 && memberno == 7) {       int exp1 = a / members[0].size(), exp2 = b / members[1].size(),           exp3 = c / members[2].size();       int minexp = min(exp1, min(exp2, exp3));       int maxexp = max(exp1, max(exp2, exp3));       int diff = maxexp - minexp;       int lliking = 0;       for (t = 0; t < 3; t++) {         for (i = 0; i < members[t].size(); i++) {           for (j = 0; j < 7; j++) {             if (liking[members[t][i]][j] == 1 && team[j] == t &&                 team[members[t][i]] == t)               lliking++;           }         }       }       if (diff < mindifference ||           (diff == mindifference && lliking > maxliking)) {         mindifference = diff;         maxliking = lliking;       }       return;     }     if (memberno >= 7) return;     for (i = 0; i < 7; i++)       if (usable[i]) {         usable[i] = false;         team[i] = currteam;         members[currteam].push_back(i);         teaming(currteam, memberno + 1);         members[currteam].pop_back();         if (currteam < 2 && members[currteam].size() > 0) {           team[i] = currteam + 1;           members[currteam + 1].push_back(i);           teaming(currteam + 1, memberno + 1);           members[currteam + 1].pop_back();         }         team[i] = -1;         usable[i] = true;       }   }   int main() {     int i, j, n;     nums.insert(make_pair( Anka , 0));     nums.insert(make_pair( Chapay , 1));     nums.insert(make_pair( Cleo , 2));     nums.insert(make_pair( Troll , 3));     nums.insert(make_pair( Dracul , 4));     nums.insert(make_pair( Snowy , 5));     nums.insert(make_pair( Hexadecimal , 6));     scanf( %d , &n);     for (i = 0; i < 7; i++)       for (j = 0; j < 7; j++) liking[i][j] = 0;     for (i = 0; i < 7; i++) {       usable[i] = true;       team[i] = -1;     }     for (i = 0; i < n; i++) {       char name1[30], tmp[30], name2[30];       scanf( %s %s %s , name1, tmp, name2);       liking[nums[name1]][nums[name2]] = 1;     }     scanf( %d %d %d , &a, &b, &c);     mindifference = 2000000000;     maxliking = 0;     teaming(0, 0);     printf( %d %d , mindifference, maxliking);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   int n, m;   int a[66], w[66];   long long dp[66][66][66];   int sa, sb, sum;   long long inv[10010];   void solve1(int x) {     memset(dp, 0, sizeof(dp));     dp[0][0][0] = 1;     long long zi, mu;     for (int i = 0; i < m; ++i)       for (int j = 0; j <= i; ++j)         for (int k = j; k <= i; ++k) {           if (!dp[i][j][k]) continue;           mu = inv[sum + k * 2 - i];           zi = (w[x] + j) % mod;           (dp[i + 1][j + 1][k + 1] += dp[i][j][k] * zi % mod * mu % mod) %= mod;           zi = (sa + k - j - w[x] + mod) % mod;           (dp[i + 1][j][k + 1] += dp[i][j][k] * zi % mod * mu % mod) %= mod;           zi = (sb - i + k + mod) % mod;           (dp[i + 1][j][k] += dp[i][j][k] * zi % mod * mu % mod) %= mod;         }     long long r = 0;     for (int j = 0; j <= m; ++j)       for (int k = j; k <= m; ++k) {         if (!dp[m][j][k]) continue;         r += dp[m][j][k] * (w[x] + j) % mod;         r %= mod;       }     printf( %lld n , r);     return;   }   void solve2(int x) {     memset(dp, 0, sizeof(dp));     dp[0][0][0] = 1;     long long zi, mu;     for (int i = 0; i < m; ++i)       for (int j = 0; j <= i; ++j)         for (int k = j; k <= i; ++k) {           if (!dp[i][j][k]) continue;           mu = inv[sum - k * 2 + i];           zi = (w[x] - j) % mod;           (dp[i + 1][j + 1][k + 1] += dp[i][j][k] * zi % mod * mu % mod) %= mod;           zi = (sb - w[x] - k + j + mod) % mod;           (dp[i + 1][j][k + 1] += dp[i][j][k] * zi % mod * mu % mod) %= mod;           zi = (sa + i - k + mod) % mod;           (dp[i + 1][j][k] += dp[i][j][k] * zi % mod * mu % mod) %= mod;         }     long long r = 0;     for (int j = 0; j <= m; ++j)       for (int k = j; k <= m; ++k) {         if (!dp[m][j][k]) continue;         r += dp[m][j][k] * max(0, w[x] - j) % mod;         r %= mod;       }     printf( %lld n , r);     return;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= n; ++i) {       scanf( %d , &w[i]);       sa += a[i] * w[i];       sb += (a[i] ^ 1) * w[i];     }     sum = sa + sb;     inv[1] = 1;     for (int i = 2; i <= 10000; ++i)       inv[i] = (mod - mod / i) * inv[mod % i] % mod;     for (int i = 1; i <= n; ++i)       if (a[i])         solve1(i);       else         solve2(i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, n;     string str;     cin >> n >> a >> b >> str;     if (str[b - 1] == str[a - 1])       cout <<  0 n ;     else       cout <<  1 n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     string a, b;     cin >> a >> b;     if (a == b)       cout << a << endl;     else       cout <<  1  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> m1;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n, k, t;     cin >> n >> k >> t;     int temp = n * k * t / 100;     int cnt = 0;     while (n--) {       if (temp > 0) {         if (temp < k) {           cout << temp <<    ;           temp = 0;         } else {           cout << k <<    ;           temp -= k;         }       } else         cout << 0 <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e8;   const double EPS = 1e-9;   const long long MOD = (long long)(1e9 + 7);   const long long MAXV = (long long)(5e3 + 10);   const long long MAXE = (long long)(1e5 + 10);   int n, m;   int c[200];   vector<pair<int, int> > aux;   bool cmp(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }   vector<int> L, R;   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       c[a]++;     }     for (int i = 0; i <= 100; i++)       if (c[i]) aux.push_back(pair<int, int>(c[i], i));     sort(aux.begin(), aux.end(), cmp);     int r = aux[0].first;     for (int i = 0; i < aux.size(); i++)       for (int j = 0; j < aux[i].first; j++) L.push_back(aux[i].second);     R = L;     rotate(R.begin(), R.begin() + r, R.end());     int cnt = 0;     for (int i = 0; i < L.size(); i++)       if (L[i] != R[i]) cnt++;     cout << cnt <<   n ;     for (int i = 0; i < L.size(); i++) cout << L[i] <<     << R[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[400100];   int b[400100];   int main() {     int n;     cin >> n;     int k = 0;     for (int i = 1; i <= n; i++) {       int l;       cin >> l;       if (l == 0) {         k = 1;       } else {         if (k == 1)           a[i - 1] = l;         else           a[i] = l;       }     }     k = 0;     for (int i = 1; i <= n; i++) {       int l;       cin >> l;       if (l == 0) {         k = 1;       } else {         if (k == 1)           b[i - 1] = l;         else           b[i] = l;       }     }     int uk = n;     int uk1 = 1;     for (int i = 1; i < n; i++) {       if (b[i] != a[1]) {         b[uk] = b[i];         uk++;       } else {         uk1 = i;         break;       }     }     for (int i = 1; i < n; i++) {       if (a[i] != b[uk1]) {         cout <<  NO ;         exit(0);       }       uk1++;     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   double fRand(double fMin, double fMax) {     double f = (double)rand() / RAND_MAX;     return fMin + f * (fMax - fMin);   }   template <class T>   T min(T a, T b, T c) {     return min(a, min(b, c));   }   template <class T>   T max(T a, T b, T c) {     return max(a, max(b, c));   }   struct pt {     long long x, y;     int id;     pt operator+(pt p) { return {x + p.x, y + p.y}; }     pt operator-(pt p) { return {x - p.x, y - p.y}; }     pt operator*(long long k) { return {x * k, y * k}; }     pt operator/(long long k) { return {x / k, y / k}; }     long long operator*(pt p) { return x * p.y - y * p.x; }     long long operator%(pt p) { return x * p.x + y * p.y; }     friend istream& operator>>(istream& is, pt& p) {       is >> p.x >> p.y;       return is;     }     friend ostream& operator<<(ostream& os, const pt& p) {       os << p.id <<  -(  << p.x <<  ,   << p.y <<  ) ;       return os;     }   };   long long sq(pt p) { return p.x * p.x + p.y * p.y; }   bool half(pt p) { return (p.y > 0 || (p.y == 0 && p.x < 0)); }   struct cmpPt {     bool operator()(pt v, pt w) {       return make_tuple(half(v), 0, sq(v)) < make_tuple(half(w), v * w, sq(w));     }   };   set<pt, cmpPt> s;   pt piv;   set<pt>::iterator nextCir(set<pt>::iterator it, int k = 1) {     for (int i = 0; i < k; ++i) {       ++it;       if (it == s.end()) it = s.begin();     }     return it;   }   set<pt>::iterator prevCir(set<pt>::iterator it, int k = 1) {     for (int i = 0; i < k; ++i) {       if (it == s.begin()) it = s.end();       --it;     }     return it;   }   long long orient(pt a, pt b, pt c) { return (b - a) * (c - a); }   bool half(pt a, pt p) { return a * p >= 0; }   bool crossesRay(pt a, pt p, pt q) {     return (half(a, q) - half(a, p)) * orient(a, p, q) > 0;   }   bool onSegment(pt p, pt a, pt b) {     return orient(p, a, b) == 0 && (a - p) % (b - p) <= 0;   }   bool isIn(pt a) {     if (a.x == 0 && a.y == 0) return true;     set<pt>::iterator it = s.lower_bound(a);     if (it == s.end()) it = s.begin();     pt q = *it;     pt p = *prevCir(it);     return (onSegment(a, p, q) || crossesRay(a, p, q));   }   void insert(pt a) {     if (isIn(a)) return;     set<pt>::iterator it = s.lower_bound(a);     if (it == s.end()) it = s.begin();     while ((int)s.size() > 2 && orient(a, *it, *nextCir(it)) <= 0) {       it = nextCir(it);       s.erase(prevCir(it));     }     it = prevCir(it);     while ((int)s.size() > 2 && orient(a, *it, *prevCir(it)) >= 0) {       it = prevCir(it);       s.erase(nextCir(it));     }     s.insert(a);   }   int main() {     ios::sync_with_stdio(false);     int q;     cin >> q;     pt p, a[3];     int type;     for (int i = (0); i <= (2); ++i) {       cin >> type >> a[i];       piv = piv + a[i];       a[i] = a[i] * 3;     }     for (int i = (0); i <= (2); ++i) {       pt p = a[i] - piv;       p.id = i + 1;       s.insert(p);     }     for (int i = (4); i <= (q); ++i) {       cin >> type >> p;       p = p * 3;       p = p - piv;       p.id = i;       if (type == 2) {         bool ans = isIn(p);         cout << (ans ?  YES  :  NO ) << endl;       } else {         insert(p);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a[100000];     long long n, i;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     a[0] = 1;     for (i = 1; i <= n - 1; i++) {       if (a[i] == a[i - 1] || a[i] == a[i - 1] + 1)         continue;       else         a[i] = a[i - 1] + 1;     }     cout << a[n - 1] + 1;     return 0;   }