#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   const long long inf = 1e18;   int a[maxn];   vector<int> g[maxn];   bool c[maxn], ok[maxn];   int dpdown[maxn], dpup[maxn];   int salem[maxn];   int mxdown[maxn], mxup[maxn];   int cnt[maxn];   int sum[maxn];   int n;   int dip[maxn];   void dfsdown(int v, int p) {     ok[v] = c[v];     cnt[v] = 1;     sum[v] = c[v];     for (auto u : g[v])       if (u != p) dfsdown(u, v), cnt[v] += cnt[u], sum[v] += sum[u];     if (!c[v]) return;     for (auto u : g[v])       if (u != p)         if (ok[u])           salem[v] += cnt[u];         else {           ok[v] = 0;           mxdown[v] = max(mxdown[v], dpdown[u]);         }     dpdown[v] = mxdown[v] + salem[v] + 1;   }   void dfsup(int v, int p) {     int _mx = -1;     for (auto u : g[v])       if (u != p && c[u] && c[v])         mxup[u] = max(mxup[u], _mx), _mx = max(_mx, (1 - ok[u]) * dpdown[u]);     reverse(g[v].begin(), g[v].end());     _mx = -1;     for (auto u : g[v])       if (u != p && c[u] && c[v])         mxup[u] = max(mxup[u], _mx), _mx = max(_mx, (1 - ok[u]) * dpdown[u]);     for (auto u : g[v])       if (u != p)         if (c[u])           if (c[v])             if (sum[1] - sum[v] == n - cnt[v])               dpup[u] = 1 + salem[v] - (ok[u] ? cnt[u] : 0) + mxup[u] + dpup[v];             else               dpup[u] =                   1 + salem[v] - (ok[u] ? cnt[u] : 0) + max(mxup[u], dpup[v]);     for (auto u : g[v])       if (u != p)         if (c[u])           if (c[v])             if (sum[1] - sum[u] == n - cnt[u])               dip[u] = 1 + salem[u] + dpup[u] + mxdown[u];             else               dip[u] = 1 + salem[u] + max(dpup[u], mxdown[u]);     for (auto u : g[v])       if (u != p) dfsup(u, v);   }   int check(int mid) {     for (int i = 1; i <= n; ++i)       dip[i] = salem[i] = ok[i] = cnt[i] = dpdown[i] = dpup[i] = mxup[i] =           mxdown[i] = 0;     for (int i = 1; i <= n; ++i) c[i] = (a[i] >= mid);     dfsdown(1, 0);     dfsup(1, 0);     int mx = 0;     for (int i = 1; i <= n; ++i)       mx = max(max(mx, dip[i]), max(dpdown[i], dpup[i]));     return mx;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int k;     cin >> n >> k;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i < n; ++i) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     int l = 1, r = 1e6 + 85;     while (r - l > 1) {       int mid = (l + r) / 2;       if (check(mid) >= k)         l = mid;       else         r = mid;     }     cout << l << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int PI = acos(-1);   const int MAXN = 1e6;   unsigned long long comb(unsigned long long n, unsigned long long k) {     if (k > n) return 0;     unsigned long long u = 1;     for (unsigned long long i = 1; i <= k; i++) {       u *= n--;       u /= i;     }     return u;   }   int main() {     unsigned long long n, m, t;     while (cin >> n >> m >> t) {       unsigned long long ans = 0;       for (unsigned long long boys = 4; boys <= n; boys++) {         unsigned long long girls = t - boys;         if (girls > m) continue;         if (t < 1 + boys) break;         ans += comb(n, boys) * comb(m, girls);       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, u, v, cnt, ans;   int t[1100000], nxt[1100000], to[1100000];   int a[1100000], b[1100000], c[1100000], f[1100000];   int vis[1100000];   void add(int u, int v) { nxt[cnt] = t[u], t[u] = cnt, to[cnt++] = v; }   void dfs(int x) {     vis[x] = true;     for (int e = t[x]; ~e; e = nxt[e]) {       int y = to[e];       to[e] = to[e ^ 1] = 0;       if (y) {         if (!vis[y]) dfs(y);         if (f[y])           a[++ans] = x, b[ans] = y, c[ans] = f[y], f[y] = 0;         else if (f[x])           a[++ans] = f[x], b[ans] = x, c[ans] = y, f[x] = 0;         else           f[x] = y;       }     }   }   int main() {     memset(t, 0xff, sizeof(t));     cin >> n >> m;     for (int i = 1; i <= m; ++i) cin >> u >> v, add(u, v), add(v, u);     vis[0] = true;     for (int i = 1; i <= n; ++i)       if (!vis[i]) dfs(i);     printf( %d n , ans);     for (int i = 1; i <= ans; ++i) printf( %d %d %d n , a[i], b[i], c[i]);     return 0;   }


#include <bits/stdc++.h>   const long double pi = acos(-1);   const long long mod = 1e9 + 7, N = 1e5 + 5;   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long q;     cin >> q;     while (q--) {       long long a, b;       cin >> a >> b;       if (a > b) {         if ((a % 2 == 0 && b % 2 == 0) || (a % 2 != 0 && b % 2 != 0))           cout << 1 << endl;         else           cout << 2 << endl;       } else if (a < b) {         if ((a % 2 == 0 && b % 2 == 0) || (a % 2 != 0 && b % 2 != 0))           cout << 2 << endl;         else           cout << 1 << endl;       } else         cout << 0 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int val[300000];   vector<pair<int, int> > ed[300000];   int fa[300000][20], maxt[300000][20], dfn[300000], dep[300000];   void dfs_bas(int u, int f) {     dep[u] = dep[f] + 1, dfn[u] = ++dfn[0];     fa[u][0] = f;     for (int i = 1; i < 20; i++)       fa[u][i] = fa[fa[u][i - 1]][i - 1],       maxt[u][i] = max(maxt[u][i - 1], maxt[fa[u][i - 1]][i - 1]);     for (int i = 0; i < ed[u].size(); i++) {       int v = ed[u][i].first;       if (v == f) continue;       maxt[v][0] = ed[u][i].second;       dfs_bas(v, u);     }   }   int LCA(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     for (int i = 19; i >= 0; i--)       if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];     if (x == y) return x;     for (int i = 19; i >= 0; i--)       if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];     return fa[x][0];   }   int query_anc(int x, int d) {     int ans = 0;     for (int i = 19; i >= 0; i--)       if (d & (1 << i)) {         ans = max(ans, maxt[x][i]);         x = fa[x][i];       }     return ans;   }   int query_path(int x, int y) {     int l = LCA(x, y);     return max(query_anc(x, dep[x] - dep[l]), query_anc(y, dep[y] - dep[l]));   }   struct Tree {     int n;     vector<int> ed[500000];     int val[500000], calc[500000], arg[500000];     int fa[500000][20], dep[500000], dfn[500000], sz[500000], ev[500000];     void dfs_bas(int u, int f) {       fa[u][0] = f, dfn[u] = ++dfn[0], sz[u] = 1, dep[u] = dep[f] + 1;       for (int i = 1; i < 20; i++) fa[u][i] = fa[fa[u][i - 1]][i - 1];       for (int i = 0; i < ed[u].size(); i++) {         int v = ed[u][i];         if (v == f) continue;         dfs_bas(v, u);         sz[u] += sz[v];       }     }     int LCA(int x, int y) {       if (dep[x] < dep[y]) swap(x, y);       for (int i = 19; i >= 0; i--)         if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];       if (x == y) return x;       for (int i = 19; i >= 0; i--)         if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];       return fa[x][0];     }   } Y;   struct BCJ {     int fa[500000];     void init(int n) {       for (int i = 1; i <= n; i++) fa[i] = i;     }     int fnd(int x) { return x == fa[x] ? x : fa[x] = fnd(fa[x]); }     void conn(int x, int y) { fa[fnd(x)] = fnd(y); }   } B;   struct e {     int a, b, c, t;   } ined[300000];   bool ccmp(e A, e B) { return A.c < B.c; }   bool tcmp(e A, e B) { return A.t < B.t; }   bool ydfncmp(int x, int y) { return Y.dfn[x] < Y.dfn[y]; }   int main() {     int n = 0, q = 0;     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) scanf( %d , &val[i]);     for (int i = 1; i < n; i++)       scanf( %d%d%d%d , &ined[i].a, &ined[i].b, &ined[i].c, &ined[i].t),           ed[ined[i].a].push_back(make_pair(ined[i].b, ined[i].t)),           ed[ined[i].b].push_back(make_pair(ined[i].a, ined[i].t));     dfs_bas(1, 0);     int c = n;     B.init(2 * n - 1);     sort(ined + 1, ined + n, ccmp);     for (int i = 1; i <= n; i++) Y.val[i] = val[i], Y.arg[i] = i;     for (int i = n - 1; i >= 1; i--) {       if (B.fnd(ined[i].a) != B.fnd(ined[i].b)) {         int u = B.fnd(ined[i].a), v = B.fnd(ined[i].b);         c++;         Y.ed[c].push_back(u), Y.ed[c].push_back(v);         B.conn(u, c), B.conn(v, c);         Y.val[c] = max(Y.val[u], Y.val[v]);         Y.ev[c] = ined[i].c;         if (Y.val[c] != Y.val[u]) {           Y.calc[c] = Y.calc[v], Y.arg[c] = Y.arg[v];         } else if (Y.val[c] != Y.val[v]) {           Y.calc[c] = Y.calc[u], Y.arg[c] = Y.arg[u];         } else {           Y.calc[c] =               max(max(Y.calc[u], Y.calc[v]), query_path(Y.arg[u], Y.arg[v]));           Y.arg[c] = Y.arg[u];         }       }     }     Y.dfs_bas(2 * n - 1, 0);     while (q--) {       int x = 0, v = 0;       scanf( %d%d , &v, &x);       int u = x;       for (int i = 19; i >= 0; i--)         if (Y.fa[u][i] && Y.ev[Y.fa[u][i]] >= v) u = Y.fa[u][i];       printf( %d %d n , Y.val[u], max(Y.calc[u], query_path(x, Y.arg[u])));     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxint = 999999999;   string s;   int cnt[30];   int k;   int main() {     int i;     while (cin >> s) {       cin >> k;       int l = s.length();       if (l <= k) {         printf( 0 n );         printf(  n );         continue;       }       for (i = 0; i < l; i++) {         cnt[s[i] -  a ]++;       }       int Min, u;       while (1) {         if (k == 0) break;         Min = maxint;         u = -1;         for (i = 0; i < 26; i++) {           if (cnt[i] > 0 && cnt[i] < Min) {             Min = cnt[i];             u = i;           }         }         if (Min > k) {           k = 0;           cnt[u] -= k;         } else {           cnt[u] = 0;           k -= Min;         }       }       int ans = 0;       for (i = 0; i < 26; i++) {         if (cnt[i] > 0) ans++;       }       printf( %d n , ans);       for (i = 0; i < l; i++) {         if (cnt[s[i] -  a ] > 0) printf( %c , s[i]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   #pragma Optimize( O3 )   using namespace std;   int n, x, a, b, y, m, ans;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     vector<int> v(n);     vector<int> a;     for (int i = 0; i < n; i++) cin >> v[i];     for (int i = 0; i < n; i += 2) a.push_back(v[i]);     for (int i = 1; i < n; i += 2) a.push_back(v[i]);     a.insert(a.end(), a.begin(), a.end());     long long sumtmp = 0;     for (int i = 0; i < (n + 1) / 2; i++) sumtmp += a[i];     long long sum = sumtmp;     for (int i = (n + 1) / 2; i < a.size(); i++) {       sumtmp += a[i] - a[i - (n + 1) / 2];       sum = max(sum, sumtmp);     }     cout << sum <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[4];     for (int i = 0; i < 4; i++) cin >> a[i];     sort(a, a + 4);     for (int i = 0; i < 2; i++)       if (a[i] + a[i + 1] > a[i + 2]) return 0 * printf( TRIANGLE );     for (int i = 0; i < 2; i++)       if (a[i] + a[i + 1] == a[i + 2]) return 0 * printf( SEGMENT );     return 0 * printf( IMPOSSIBLE );   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = ((res % p) * (x % p)) % p;       y = y >> 1;       x = ((x % p) * (x % p)) % p;     }     return res;   }   long long raichu(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = ((res) * (x));       y = y >> 1;       x = ((x) * (x));     }     return res;   }   bool isprime(long long n) {     if (n < 2)       return false;     else if (n == 2)       return true;     else if (n % 2 == 0)       return false;     else {       long long z = sqrt(n);       for (long long i = 0; i < z - 1; i++)         if (n % (i + 2) == 0) return false;       return true;     }   }   const long long prime = 13313;   namespace FFT {   const long long N = 20;   const long long MAXN = (1 << N);   const double PI = acos(-1.0);   class cmplx {    private:     double x, y;       public:     cmplx() : x(0.0), y(0.0) {}     cmplx(double a) : x(a), y(0.0) {}     cmplx(double a, double b) : x(a), y(b) {}     double get_real() { return this->x; }     double get_img() { return this->y; }     cmplx conj() { return cmplx(this->x, -(this->y)); }     cmplx operator=(const cmplx& a) {       this->x = a.x;       this->y = a.y;       return *this;     }     cmplx operator+(const cmplx& b) {       return cmplx(this->x + b.x, this->y + b.y);     }     cmplx operator-(const cmplx& b) {       return cmplx(this->x - b.x, this->y - b.y);     }     cmplx operator*(const double& num) {       return cmplx(this->x * num, this->y * num);     }     cmplx operator/(const double& num) {       return cmplx(this->x / num, this->y / num);     }     cmplx operator*(const cmplx& b) {       return cmplx(this->x * b.x - this->y * b.y, this->y * b.x + this->x * b.y);     }     cmplx operator/(const cmplx& b) {       cmplx temp(b.x, -b.y);       cmplx n = (*this) * temp;       return n / (b.x * b.x + b.y * b.y);     }   };   cmplx w[MAXN];   cmplx f1[MAXN];   long long rev[MAXN];   void ReserveBits(long long k) {     static long long rk = -1, lim;     if (k == rk) return;     rk = k, lim = 1 << k;     for (long long i = 1; i <= lim; ++i) {       long long j = rev[i - 1], t = k - 1;       while (t >= 0 && ((j >> t) & 1)) {         j ^= 1 << t;         --t;       }       if (t >= 0) {         j ^= 1 << t;         --t;       }       rev[i] = j;     }   }   void fft(cmplx* a, long long k) {     ReserveBits(k);     long long n = 1 << k;     for (long long i = 0; i < n; ++i)       if (rev[i] > i) swap(a[i], a[rev[i]]);     for (long long l = 2, m = 1; l <= n; l += l, m += m) {       if (w[m].get_real() == 0 && w[m].get_img() == 0) {         double angle = PI / m;         cmplx ww(cos(angle), sin(angle));         if (m > 1) {           for (long long j = 0; j < m; ++j) {             if (j & 1)               w[m + j] = w[(m + j) / 2] * ww;             else               w[m + j] = w[(m + j) / 2];           }         } else           w[m] = cmplx(1, 0);       }       for (long long i = 0; i < n; i += l) {         for (long long j = 0; j < m; ++j) {           cmplx v = a[i + j], u = a[i + j + m] * w[m + j];           a[i + j] = v + u;           a[i + j + m] = v - u;         }       }     }   }   vector<long long> multiply(const vector<long long>& a,                              const vector<long long>& b) {     long long k = 1;     while ((1 << k) < (a.size() + b.size())) ++k;     long long n = (1 << k);     for (long long i = 0; i < n; ++i) f1[i] = cmplx(0, 0);     for (long long i = 0; i < a.size(); ++i) f1[i] = f1[i] + cmplx(a[i], 0);     for (long long i = 0; i < b.size(); ++i) f1[i] = f1[i] + cmplx(0, b[i]);     fft(f1, k);     for (long long i = 0; i <= n / 2; ++i) {       cmplx p = f1[i] + f1[(n - i) % n].conj();       cmplx _q = f1[(n - i) % n] - f1[i].conj();       cmplx q(_q.get_img(), _q.get_real());       f1[i] = (p * q) * 0.25;       if (i > 0) f1[(n - i)] = f1[i].conj();     }     for (long long i = 0; i < n; ++i) f1[i] = f1[i].conj();     fft(f1, k);     vector<long long> ans(a.size() + b.size() - 1);     for (long long i = 0; i < ans.size(); ++i) {       ans[i] = (long long)(f1[i].get_real() / n + 0.5);     }     return ans;   }   };  // namespace FFT   using namespace FFT;   vector<long long> pfft(vector<long long>& a, long long k) {     vector<long long> res;     res.push_back(1);     while (k > 0) {       if (k & 1) res = multiply(res, a);       k = k >> 1;       a = multiply(a, a);       for (long long i = 0; i < (long long)a.size(); i++)         if (a[i] > 0) a[i] = 1;       for (long long i = 0; i < (long long)res.size(); i++)         if (res[i] > 0) res[i] = 1;     }     return res;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     vector<long long> a(n);     for (long long i = 0; i < n; i++) cin >> a[i];     vector<long long> z(1001, 0);     for (long long i = 0; i < n; i++) z[a[i]] = 1;     vector<long long> ans = pfft(z, k);     for (long long i = 0; i < (long long)ans.size(); i++)       if (ans[i] > 0) cout << i <<    ;     return 0;   }


#include <bits/stdc++.h>   const int N = 2e5 + 5;   const int MOD = 1e9 + 7;   using namespace std;   int n;   char str1[N], str2[N];   vector<int> lt[30], rt[30];   vector<pair<int, int> > ans;   int main() {     scanf( %d , &n);     scanf(  %s , str1);     scanf(  %s , str2);     for (int a = 0; a < n; a++) {       if (str1[a] ==  ? )         lt[26].push_back(a);       else         lt[(int)(str1[a] -  a )].push_back(a);       if (str2[a] ==  ? )         rt[26].push_back(a);       else         rt[(int)(str2[a] -  a )].push_back(a);     }     for (int a = 0; a < 26; a++) {       while (lt[a].size() > 0 && rt[a].size() > 0) {         ans.push_back({lt[a][lt[a].size() - 1] + 1, rt[a][rt[a].size() - 1] + 1});         lt[a].pop_back();         rt[a].pop_back();       }     }     int idx = 0;     while (lt[26].size() > 0 && idx < 26) {       while (lt[26].size() > 0 && rt[idx].size() > 0) {         ans.push_back(             {lt[26][lt[26].size() - 1] + 1, rt[idx][rt[idx].size() - 1] + 1});         lt[26].pop_back();         rt[idx].pop_back();       }       idx++;     }     idx = 0;     while (rt[26].size() > 0 && idx < 26) {       while (rt[26].size() > 0 && lt[idx].size() > 0) {         ans.push_back(             {lt[idx][lt[idx].size() - 1] + 1, rt[26][rt[26].size() - 1] + 1});         lt[idx].pop_back();         rt[26].pop_back();       }       idx++;     }     while (rt[26].size() > 0 && lt[26].size() > 0) {       ans.push_back(           {lt[26][lt[26].size() - 1] + 1, rt[26][rt[26].size() - 1] + 1});       lt[26].pop_back();       rt[26].pop_back();     }     printf( %d n , (int)ans.size());     for (auto v : ans) printf( %d %d n , v.first, v.second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vector<int> a(n), b(n);     for (int i = 0; i < n; ++i) cin >> a[i];     iota(b.begin(), b.end(), 0);     sort(b.begin(), b.end(), [&](int i, int j) { return a[i] < a[j]; });     vector<vector<int>> c(n + 1);     for (int i = 0; i <= n; ++i) c[i].resize(n);     for (int i = 0; i < n; ++i)       for (int j = 0; j < a[b[i]]; ++j) c[(n + 1 + i - j) % (n + 1)][b[i]] = 1;     cout << n + 1 <<   n ;     for (int i = 0; i < n + 1; ++i, cout <<   n )       for (int j = 0; j < n; ++j) cout << c[i][j];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n + 1];     vector<int> g[n + 1];     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     set<pair<int, int> > last;     int k = 0;     for (int i = 1; i <= n; i++) {       set<pair<int, int> >::iterator it = last.lower_bound(make_pair(a[i], 1));       if (it == last.begin()) {         g[++k].push_back(a[i]);         last.insert(make_pair(a[i], k));       } else {         --it;         g[it->second].push_back(a[i]);         last.erase(it);         last.insert(make_pair(a[i], it->second));       }     }     for (int i = 1; i <= k; i++) {       for (int j : g[i]) {         cout << j <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n1, n2, k1, k2;     cin >> n1 >> n2 >> k1 >> k2;     if (n1 > n2) {       cout <<  First ;     } else {       cout <<  Second ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 33333;   const int mod = 998244353, G = 3;   int n, k, T, a[MAXN], W, rev[MAXN], gen[MAXN];   vector<int> vec[MAXN];   inline int qpow(int a, int b) {     int re = 1;     for (; b; b >>= 1, a = 1ll * a * a % mod)       if (b & 1) re = 1ll * re * a % mod;     return re;   }   inline int pls(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }   inline void add(int &x, int y) { x = x + y >= mod ? x + y - mod : x + y; }   void NTT(vector<int> &arr, int len, int flg) {     for (int i = 0; i < len; ++i)       if (i < rev[i]) swap(arr[i], arr[rev[i]]);     for (int v, i = 2, B = W >> 1; i <= len; i <<= 1, B >>= 1)       for (int j = 0; j < len; j += i)         for (int k = j, x = 0; k < j + i / 2; ++k, x += B)           arr[k + i / 2] = pls(               arr[k],               mod - (v = 1ll * arr[k + i / 2] * gen[flg == 1 ? x : W - x] % mod)),                       add(arr[k], v);     if (flg == -1) {       int iv = qpow(len, mod - 2);       for (int i = 0; i < len; ++i) arr[i] = 1ll * arr[i] * iv % mod;     }   }   vector<int> solve(int l, int r) {     if (l == r) return vec[l];     int mid = (l + r) >> 1;     vector<int> L = solve(l, mid), R = solve(mid + 1, r);     int len = 1;     while (len <= r - l + 1) len <<= 1;     for (int i = 1; i < len; ++i)       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) * (len >> 1));     L.resize(len), R.resize(len);     NTT(L, len, 1), NTT(R, len, 1);     for (int i = 0; i < len; ++i) L[i] = 1ll * L[i] * R[i] % mod;     NTT(L, len, -1);     L.resize(r - l + 2);     return L;   }   int main() {     scanf( %d%d , &n, &k);     for (W = 1; W <= n; W <<= 1)       ;     gen[0] = 1, gen[1] = qpow(G, (mod - 1) / W);     for (int i = 2; i <= W; ++i) gen[i] = 1ll * gen[i - 1] * gen[1] % mod;     for (int i = 1; i <= n; ++i)       scanf( %d , &a[i]), vec[i].resize(2), vec[i][0] = 1;     int op, q, x, y, d;     for (scanf( %d , &T); T--;) {       scanf( %d%d%d , &op, &q, &x);       if (op == 2)         scanf( %d , &y);       else         y = x;       scanf( %d , &d);       for (int i = 1; i <= n; ++i)         vec[i][1] =             ((q - ((x <= i && i <= y) ? (op == 1 ? d : a[i] + d) : a[i])) % mod +              mod) %             mod;       vector<int> ans = solve(1, n);       printf( %d n , ans[k]);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     map<int, int> m;     int u = 0;     long long powers[32];     powers[0] = 1;     for (int i = 1; i < 32; i++) powers[i] = 2 * powers[i - 1];     for (int i = 0; i < n; i++) {       cin >> a[i];       m[a[i]]++;     }     bool flag = false;     for (int i = 0; i < n; i++) {       flag = false;       for (int j = 0; j < 32; j++) {         long long x = powers[j] - a[i];         if (m[x] > 1 || (m[x] == 1 && x != a[i])) {           flag = true;           break;         }       }       if (!flag) u++;     }     cout << u << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[500010];   int d1[500010];   int d2[500010];   int main() {     int n;     cin >> n;     for (int i = (0); i < (int)(n); i++) cin >> arr[i];     int last2left = 0;     for (int i = (1); i < (int)(n - 1); i++) {       if (arr[i] == arr[i - 1]) {         last2left = i;         d1[i] = i;       } else {         d1[i] = last2left;       }     }     last2left = n - 1;     for (int i = (n - 1 - 1); i >= (int)(1); i--) {       if (arr[i] == arr[i + 1]) {         last2left = i;         d2[i] = i;       } else {         d2[i] = last2left;       }     }     int res = 0;     for (int i = (1); i < (int)(n - 1); i++)       res = max(res, min(i - d1[i], d2[i] - i));     cout << res << endl;     cout << arr[0] <<    ;     for (int i = (1); i < (int)(n - 1); i++)       cout << ((i - d1[i] < d2[i] - i) ? arr[d1[i]] : arr[d2[i]]) <<    ;     cout << arr[n - 1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int x, y, n, d, x_i, y_i;   vector<pair<int, int> > v;   double dist(double x1, double y1) { return sqrt(pow(x1, 2) + pow(y1, 2)); }   int a[605][605];   int f(int _x, int _y) {     if (a[200 + _x][200 + _y] == -1) {       int tmp = 1;       if (dist(_x, _y) <= d) {         for (auto _i : v) {           if (f(_x + _i.first, _y + _i.second)) {             tmp = 0;             break;           }         }       } else {         tmp = 0;       }       a[200 + _x][200 + _y] = tmp;     }     return a[200 + _x][200 + _y];   }   int main() {     ios::sync_with_stdio(0);     cin >> x >> y >> n >> d;     (memset(a, -1, sizeof(a)));     for (int(i) = (0); (i) < (n); (i)++) {       cin >> x_i >> y_i;       v.push_back({x_i, y_i});     }     cout << (!f(x, y) ?  Anton  :  Dasha ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, i, n;     int edges[int(2e5 + 1)][2], weights[int(2e5 + 1)], freq[int(2e5 + 1)];     cin >> n;     for (i = 1; i <= n; i++) freq[i] = 0;     for (i = 0; i < n; i++) {       weights[i] = -1;       cin >> edges[i][0] >> edges[i][1];       freq[edges[i][0]]++;       freq[edges[i][1]]++;     }     int maxindex = 1, k = 0;     for (i = 1; i <= n; i++)       if (freq[i] > freq[maxindex]) maxindex = i;     for (i = 0; i < n; i++)       if (edges[i][0] == maxindex or edges[i][1] == maxindex) weights[i] = k++;     for (i = 0; i < n; i++)       if (weights[i] == -1) weights[i] = k++;     for (i = 0; i < n - 1; i++) cout << weights[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void debug() { cout << endl; }   template <typename T, typename... E>   void debug(T t, E... e) {     cout << t << (sizeof...(e) ?     :   );     debug(e...);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int a, b, c, d;     cin >> a >> b >> c >> d;     double p1 = double(a) / b;     double p2 = double(c) / d;     double ans = p1 / (1 - (1 - p1) * (1 - p2));     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   inline int in() {     int32_t x;     scanf( %d , &x);     return x;   }   inline long long lin() {     long long x;     scanf( %lld , &x);     return x;   }   const int maxn = 2e5 + 10;   const int mod = 1e9 + 7;   const long long infll = 1e18;   const int inf = 1e9;   int lcp[40][40];   string s[maxn];   int32_t main() {     int n = in(), k = in();     for (int i = 0; i < n; i++) cin >> s[i];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         int where = 0;         while (where < s[i].size() && where < s[j].size() &&                s[i][where] == s[j][where])           where++;         lcp[i][j] = where;       }     }     int res = 0;     for (int mask = 0; mask < (1 << n); mask++) {       if (__builtin_popcount(mask) - k) continue;       vector<int> Ids;       for (int i = 0; i < n; i++)         if (mask >> i & 1) Ids.push_back(i);       int tot = 0;       for (int i = 0; i < Ids.size(); i++)         for (int j = i + 1; j < Ids.size(); j++) tot += lcp[Ids[i]][Ids[j]];       res = max(res, tot);     }     cout << res << endl;   }


#include <bits/stdc++.h>   const int N = 4005;   const int M = 80;   const int MOD = 998244353;   int m, jc[M], ny[M];   struct Tree {     int n, cnt, last[N], f[M][N], g[M][N], size[N], ans[M], w[N], tot, a[N], sum,         root;     bool vis[N];     struct edge {       int to, next;     } e[N * 2];     void addedge(int u, int v) {       e[++cnt].to = v;       e[cnt].next = last[u];       last[u] = cnt;       e[++cnt].to = u;       e[cnt].next = last[v];       last[v] = cnt;     }     void get_root(int x, int fa) {       size[x] = 1;       w[x] = 0;       for (int i = last[x]; i; i = e[i].next) {         if (e[i].to == fa || vis[e[i].to]) continue;         get_root(e[i].to, x);         size[x] += size[e[i].to];         w[x] = std::max(w[x], size[e[i].to]);       }       w[x] = std::max(w[x], sum - size[x]);       if (!root || w[x] < w[root]) root = x;     }     void get(int x, int fa) {       a[++tot] = x;       size[x] = 1;       for (int i = last[x]; i; i = e[i].next)         if (e[i].to != fa && !vis[e[i].to])           get(e[i].to, x), size[x] += size[e[i].to];     }     void calc(int x) {       tot = 0;       get(x, 0);       f[0][x] = g[0][x] = 1;       for (int i = 1; i <= m; i++)         for (int j = 1; j <= tot; j++) {           int y = a[j];           f[i][y] = g[i][y] = 0;           for (int k = last[y]; k; k = e[k].next) {             if (vis[e[k].to]) continue;             (g[i][y] += g[i - 1][e[k].to]) %= MOD;             if (y != x) (f[i][y] += f[i - 1][e[k].to]) %= MOD;           }         }       for (int i = 1; i <= tot; i++) {         int y = a[i];         if (y == x) {           for (int j = 0; j <= m; j++) (ans[j] += g[j][x]) %= MOD;           continue;         }         for (int j = 0; j <= m; j++)           for (int k = 0; j + k <= m; k++)             (ans[j + k] += (long long)f[j][y] * g[k][y] % MOD) %= MOD;       }       vis[x] = 1;       for (int i = last[x]; i; i = e[i].next) {         if (vis[e[i].to]) continue;         root = 0;         sum = size[e[i].to];         get_root(e[i].to, x);         calc(root);       }     }     void solve() {       sum = n;       root = 0;       get_root(1, 0);       calc(root);     }   } t1, t2;   int C(int n, int m) { return (long long)jc[n] * ny[m] % MOD * ny[n - m] % MOD; }   int main() {     scanf( %d%d%d , &t1.n, &t2.n, &m);     jc[0] = jc[1] = ny[0] = ny[1] = 1;     for (int i = 2; i <= m; i++)       jc[i] = (long long)jc[i - 1] * i % MOD,       ny[i] = (long long)(MOD - MOD / i) * ny[MOD % i] % MOD;     for (int i = 2; i <= m; i++) ny[i] = (long long)ny[i - 1] * ny[i] % MOD;     for (int i = 1; i < t1.n; i++) {       int x, y;       scanf( %d%d , &x, &y);       t1.addedge(x, y);     }     for (int i = 1; i < t2.n; i++) {       int x, y;       scanf( %d%d , &x, &y);       t2.addedge(x, y);     }     t1.solve();     t2.solve();     int s = 0;     for (int i = 0; i <= m; i++)       (s += (long long)t1.ans[i] * t2.ans[m - i] % MOD * C(m, i) % MOD) %= MOD;     printf( %d , s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   const long long mod2 = 998244353;   long long fpow(long long x, long long y, long long p = 1000000007) {     x = x % p;     long long sum = 1;     while (y) {       if (y & 1) sum = sum * x;       sum %= p;       y = y >> 1;       x = x * x;       x %= p;     }     return sum;   }   long long inv(long long a, long long m = 1000000007) {     long long c = m;     long long y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       long long q = a / m;       long long t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += c;     return x;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t, n;     cin >> t;     while (t--) {       cin >> n;       long long tmp = 0;       vector<long long> v(n);       for (int i = 0; i < n; i++) {         cin >> v[i];         tmp ^= v[i];       }       if (tmp == 0) {         cout <<  DRAW n ;         continue;       }       for (long long j = 40; j >= 0; j--) {         if ((tmp >> j) & 1) {           long long cnt0 = 0, cnt1 = 0;           for (int i = 0; i < n; i++) {             if ((v[i] >> j) & 1)               cnt1++;             else               cnt0++;           }           if (cnt0 % 2 == 0 && cnt1 % 4 == 3) {             cout <<  LOSE n ;           } else {             cout <<  WIN n ;           }           break;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int num, cnt;     friend bool operator<(const Node &n1, const Node &n2) {       if (n1.cnt != n2.cnt)         return n1.cnt < n2.cnt;       else         return n1.num < n2.num;     }   };   set<Node> cur, tmp;   vector<int> xx, num;   map<int, int> mp;   int main() {     int n, x;     scanf( %d%d , &n, &x);     if (x == 0 && n == 2) {       puts( NO );       return 0;     }     while (x > 0) {       xx.push_back(x % 2);       x /= 2;     }     int sz = xx.size();     int pre = 0;     cur.insert({0, n});     int idx = 0;     while (true) {       int need;       if (idx < sz) {         need = xx[idx];       } else         need = 0;       tmp.clear();       int tar = need, now = 0;       for (auto o : cur) {         int zc = o.num * 2, cc = o.cnt;         if (cc / 2 > 0) tmp.insert({zc + 1, cc / 2});         if ((cc + 1) / 2 > 0) tmp.insert({zc, (cc + 1) / 2});         now ^= ((cc / 2) % 2);       }       if (tar != now) {         for (auto o : cur) {           int zc = o.num * 2, cc = o.cnt;           if (cc == 1) {             tmp.erase({zc, (cc + 1) / 2});             tmp.insert({zc + 1, cc / 2 + 1});           } else {             tmp.erase({zc, (cc + 1) / 2});             tmp.erase({zc + 1, cc / 2});             if ((cc + 1) / 2 > 1) tmp.insert({zc, (cc + 1) / 2 - 1});             tmp.insert({zc + 1, cc / 2 + 1});           }           break;         }       }       cur.clear();       for (auto o : tmp) {         cur.insert(o);       }       idx++;       int siz = cur.size();       if (siz == n && idx >= sz) break;     }     vector<int> ans;     bool ok = true;     for (auto o : cur) {       int t = o.num, res = 0;       for (int i = 1; i <= idx; i++) {         int now = t % 2;         res = res * 2 + now;         t /= 2;       }       ans.push_back(res);       if (res > 1000000) {         ok = false;         break;       }     }     if (!ok) {       puts( NO );     } else {       int ord = 0;       puts( YES );       for (auto o : ans) {         if (ord != 0) putchar(   );         printf( %d , o);         ord++;       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[33], ans;   map<long long, long long> us;   int main() {     cin >> n;     for (long long i = 1; i <= n; ++i) cin >> a[i];     sort(a + 1, a + 1 + n);     for (long long i = 1; i <= n; ++i) {       while (us[a[i]] && a[i] > 0) a[i]--;       ans += a[i];       us[a[i]] = 1;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int digit[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2};     string n;     cin >> n;     int a = digit[(n[1] - 48)];     int b = digit[(n[0] - 48)];     cout << a * b;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> t;   int get(int a) {     if (t[a] == a) {       return a;     } else {       return t[a] = get(t[a]);     }   }   struct kek {     int a;     int b;     int c;   };   bool operator<(kek a, kek b) { return a.c < b.c; }   void uni(int a, int b) {     a = get(a);     b = get(b);     if (a != b) t[a] = b;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n + 1; i++) t.push_back(i - 1);     m--;     vector<kek> e(m);     int a, b, c;     cin >> a >> b >> c;     for (int i = 0; i < m; i++) cin >> e[i].a >> e[i].b >> e[i].c;     sort(e.begin(), e.end());     int sol = 0;     if (m == 0) {       sol = (int)1e9;     }     for (int i = 0; i < m; i++) {       auto it = e[i];       int x = it.a;       int y = it.b;       int z = it.c;       if (get(a) != get(b)) sol = max(sol, e[i].c);       uni(x, y);       int urm;       if (i + 1 == m)         urm = (int)1e9;       else         urm = max(e[i].c, e[i + 1].c - 1);       if (get(a) != get(b)) sol = max(sol, urm);     }     cout << sol <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   long long pwr(long long a, long long b, long long mod) {     if (b == 0) return 1;     long long temp = pwr(a, b / 2, mod);     temp = (temp * temp) % mod;     if (b & 1) temp = (temp * a) % mod;     return temp;   }   long long pwr(long long a, long long b) {     if (b == 0) return 1;     long long temp = pwr(a, b / 2);     temp = (temp * temp);     if (b & 1) temp = (temp * a);     return temp;   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }   long long modularInverse(long long a, long long m) { return pwr(a, m - 2, m); }   bool *isPrime;   void generatePrimeSieve(const int lim) {     isPrime = (bool *)malloc(lim + 1);     memset(isPrime, true, lim + 1);     isPrime[0] = false;     isPrime[1] = false;     for (int i = 2; i <= lim; ++i)       if (isPrime[i])         for (int j = i + i; j <= lim; j += i) isPrime[j] = false;   }   vector<vector<int> > identityMatrix;   vector<vector<int> > mul(const vector<vector<int> > &a,                            const vector<vector<int> > &b) {     int n = a.size();     vector<vector<int> > ans(n, vector<int>(n));     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         for (int k = 0; k < n; ++k) {           ans[i][j] += ((long long)a[i][k] * b[k][j]) % mod;           ans[i][j] %= mod;         }       }     }     return ans;   }   vector<vector<int> > pwr(const vector<vector<int> > &a, long long n) {     if (n == 0) {       assert(false);       return identityMatrix;     }     if (n == 1) return a;     vector<vector<int> > tmp = pwr(a, n / 2);     tmp = mul(tmp, tmp);     if (n & 1) tmp = mul(a, tmp);     return tmp;   }   string str[435];   bool isRemoved[3123];   int main() {     std::ios::sync_with_stdio(false);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> str[i];     int ans = 0;     while (true) {       bool encountered = false;       for (int i = 0; i < n - 1; ++i) {         if (str[i] > str[i + 1]) {           encountered = true;           for (int j = 0; j < m; ++j) {             if (str[i][j] > str[i + 1][j]) {               for (int k = 0; k < n; ++k) str[k][j] =  * ;               break;             }           }           break;         }       }       if (!encountered) break;     }     int removed = count(str[0].begin(), str[0].end(),  * );     cout << removed;   }


#include <bits/stdc++.h>   using namespace std;   long long f(int d) {     long long res = 0;     long long dp[100];     memset(dp, 0ll, sizeof(dp));     for (int k = 1; k < d; k++)       if (d % k == 0) {         res += ((1ll << (k - 1)) - dp[k]);         int nk = k * 2;         for (; nk <= d; nk += k) dp[nk] += ((1ll << (k - 1)) - dp[k]);       }     return res;   }   bool periodic(long long N, int d) {     for (int i = 0; i < d; i++)       if ((d + 1) % (i + 1) == 0) {         long long num = 0;         for (int j = 0; j <= d; j++)           if (N & (1ll << (d - j % (i + 1)))) num ^= (1ll << (d - j));         if (num == N) return true;       }     return false;   }   bool differs(long long a, long long b, int bt, int nb) {     for (int i = nb; i > bt; i--)       if ((a & (1ll << i)) != (b & (1ll << i))) return false;     return (a & (1ll << bt)) < (b & (1ll << bt));   }   long long F(long long N) {     if (!N) return 0;     int nd = 0;     for (; (1ll << nd) <= N; nd++)       ;     nd--;     long long ans = periodic(N, nd);     for (int d = 2; d <= nd; d++) ans += f(d);     long long dp[100];     for (int i = nd - 1; i >= 0; i--) {       memset(dp, 0ll, sizeof(dp));       if (N & (1ll << i)) {         memset(dp, 0ll, sizeof(dp));         for (int j = 0; j < (nd - i); j++)           if ((j + 1) < (nd + 1) && (nd + 1) % (j + 1) == 0) {             long long num = 0;             for (int k = 0; k <= nd; k++)               if (N & (1ll << (nd - k % (j + 1)))) num ^= (1ll << (nd - k));             if (num < N && differs(num, N, i, nd)) {               ans++;               for (int k = (j + 1) * 2; k <= (nd + 1); k += (j + 1)) dp[k - 1]++;             }           }         for (int j = (nd - i); j <= nd; j++) {           if ((j + 1) < (nd + 1) && (nd + 1) % (j + 1) == 0) {             ans += (1ll << (j - (nd - i))) - dp[j];             for (int k = (j + 1) * 2; k <= (nd + 1); k += (j + 1))               dp[k - 1] += (1ll << (j - (nd - i))) - dp[j];           }         }       }     }     return ans;   }   int main() {     long long L, R;     cin >> L >> R;     cout << F(R) - F(L - 1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXM = 500005;   const int MAXN = 15;   const int N = 12;   int w[MAXN];   char query[MAXN];   char s[MAXN];   int n, m, q;   int transform(char* s) {     int ans = 0;     for (int i = 0; i < n; i++) {       ans = 2 * ans + (s[i] -  0 );     }     return ans;   }   int cnt_set[(1 << N)];   int dif[(1 << N)][(1 << N)];   int get_dif(int a, int b) {     int ans = 0;     for (int i = 0; i < n; i++) {       if ((a & 1) == (b & 1)) ans += w[i];       a >>= 1;       b >>= 1;     }     return ans;   }   vector<pair<int, int>> cnt_queries[(1 << N)];   int sol[MAXM];   const int MAXK = 101;   int main() {     scanf( %d %d %d , &n, &m, &q);     for (int i = n - 1; i >= 0; i--) scanf( %d , &w[i]);     for (int i = 1; i <= m; i++) {       scanf( %s , s);       int val = transform(s);       cnt_set[val]++;     }     for (int i = 0; i < (1 << n); i++) {       for (int j = 0; j < (1 << n); j++) {         dif[i][j] = get_dif(i, j);       }     }     for (int i = 1; i <= q; i++) {       scanf( %s , query);       int p = transform(query);       int k;       scanf( %d , &k);       cnt_queries[p].push_back({k, i});     }     for (int i = 0; i < (1 << n); i++) {       vector<int> current(MAXK);       for (int i = 0; i < MAXK; i++) current[i] = 0;       for (int j = 0; j < (1 << n); j++) {         if (dif[i][j] < MAXK) {           current[dif[i][j]] += cnt_set[j];         }       }       for (int i = 1; i < MAXK; i++) current[i] += current[i - 1];       for (auto p : cnt_queries[i]) {         sol[p.second] = current[p.first];       }     }     for (int i = 1; i <= q; i++) printf( %d n , sol[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n);       for (int i = 0; i < n; ++i) cin >> a[i];       int m = a[n - 1], ans = 0;       for (int i = n - 1; i >= 0; --i) {         if (a[i] > m) ++ans;         m = min(m, a[i]);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC target(         sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( fast-math )   using namespace std;   const int INF = 1e9 + 9;   const long long MAXN = 5e5 + 7;   const long long MAXN1 = 21;   const long long MAXN2 = 1e6 + 7;   const long long MOD = 998244353;   const long long PW = 31;   const long long BLOCK = 447;   void solve();   mt19937 mt(1e9 + 7);   signed main() {     srand( a  +  l  +  e  +  x  +  X  +  5  +  1  +  2 );     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int q = 1;     if (0) cin >> q;     while (q--) solve();   }   long long cnt[100];   struct Segment {     long long sum, _sum, sum_, _sum_;     int first, last, len;     Segment() : sum(1), _sum(1), sum_(1), _sum_(1), first(0), last(0), len(1) {}     Segment operator+(const Segment& other) const {       Segment now;       now.last = other.last;       now.first = first;       now.len = len + other.len;       now.sum = (sum * other.sum % MOD + (last == 1 ? 1 : 0) * sum_ *                                              cnt[last * 10 + other.first] % MOD *                                              other._sum) %                 MOD;       now._sum = (_sum * other.sum % MOD +                   (last == 1 && len > 1 ? 1 : 0) * _sum_ *                       cnt[last * 10 + other.first] % MOD * other._sum) %                  MOD;       now.sum_ = (sum * other.sum_ % MOD +                   (last == 1 && other.len > 1 ? 1 : 0) * sum_ *                       cnt[last * 10 + other.first] % MOD * other._sum_) %                  MOD;       now._sum_ = (_sum * other.sum_ % MOD +                    (last == 1 && other.len > 1 && len > 1 ? 1 : 0) * _sum_ *                        cnt[last * 10 + other.first] % MOD * other._sum_) %                   MOD;       return now;     }   };   Segment v[4 * MAXN];   void upd(int vert, int tl, int tr, int id, int now) {     if (tl == tr) {       v[vert].sum = cnt[now];       v[vert].last = v[vert].first = now;       return;     }     int tm = (tl + tr) / 2;     if (id <= tm)       upd(vert << 1, tl, tm, id, now);     else       upd(vert << 1 | 1, tm + 1, tr, id, now);     v[vert] = v[vert << 1] + v[vert << 1 | 1];   }   int get() { return v[1].sum; }   void solve() {     for (int i = 0; i < 10; ++i) {       for (int j = 0; j < 10; ++j) {         ++cnt[i + j];       }     }     int n, m;     cin >> n >> m;     for (int i = 0; i < n; ++i) {       char ch;       cin >> ch;       upd(1, 0, n - 1, i, ch -  0 );     }     for (int i = 0; i < m; ++i) {       int x, d;       cin >> x >> d;       upd(1, 0, n - 1, x - 1, d);       cout << get() <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   const int inf = 1000000005;   int n, m, r[N][N];   char str[N][N];   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %s , str[i] + 1);     }     for (int i = 1; i <= n; i++) {       for (int j = m; j >= 1; j--) {         if (str[i][j] ==  0 )           r[i][j] = 0;         else           r[i][j] = r[i][j + 1] + 1;       }     }     int ans = 0;     for (int j = m; j >= 1; j--) {       vector<int> v;       for (int i = 1; i <= n; i++) {         v.push_back(r[i][j]);       }       sort(v.begin(), v.end());       reverse(v.begin(), v.end());       for (int i = 0; i < v.size(); i++) {         ans = max(ans, v[i] * (i + 1));       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   int main() {     long long t = 1;     while (t--) {       long long a, b, sum = 0;       scanf( %lld%lld , &a, &b);       while (b > 0) {         int r = b % 10;         sum = sum * 10 + r;         b = b / 10;       }       sum += a;       printf( %lld , sum);     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     for (int i = (0); ((1) > 0 ? i < (t) : i > (t)); i += (1)) {       ll n, s;       cin >> n >> s;       vector<ll> v(n), pref(n + 2);       for (int i = (0); ((1) > 0 ? i < (n) : i > (n)); i += (1))         cin >> v[i], pref[i + 1] = v[i] + pref[i];       pref[n + 1] = pref[n];       int gr = 0, ans = 0;       {         int l = 0, r = n + 1;         while (l < r) {           int m = (l + r + 1) / 2;           if (pref[m] > s) {             r = m - 1;           } else {             l = m;           }         }         gr = l;       };       for (int i = (0); ((1) > 0 ? i < (n) : i > (n)); i += (1)) {         int l = 0, r = n + 1;         while (l < r) {           int m = (l + r + 1) / 2;           if (pref[m] - v[i] > s) {             r = m - 1;           } else {             l = m;           }         };         if (i + 1 < l && l > gr) {           ans = i + 1;           gr = l;         }       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e6 + 5;   int a, b, c;   long long gcd(long long a, long long b, long long& x, long long& y) {     if (!b) {       x = 0;       y = 1;       return a;     }     long long x1, y1;     long long d = gcd(b, a % b, x1, y1);     x = y1 - (a / b) * x1;     y = x1;     return d;   }   int main() {     scanf( %d%d%d , &a, &b, &c);     long long x, y, d;     d = gcd(a, b, x, y);     if (c % d != 0)       puts( -1 );     else       cout << -y * c / d <<     << -x * c / d << endl;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char* x) { cerr <<     << x <<    ; }   void __print(const string& x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V>& x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T& x) {     int f = 0;     cerr <<  { ;     for (auto& i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   void pre() {}   const long long mod = (119 << 23) + 1, root = 3;   long long modpow(long long a, long long e) {     if (e == 0) return 1;     long long x = modpow(a * a % mod, e >> 1);     return e & 1 ? x * a % mod : x;   }   void ntt(long long* x, long long* temp, long long* roots, int N, int skip) {     if (N == 1) return;     int n2 = N / 2;     ntt(x, temp, roots, n2, skip * 2);     ntt(x + skip, temp, roots, n2, skip * 2);     for (int i = 0; i < (N); ++i) temp[i] = x[i * skip];     for (int i = 0; i < (n2); ++i) {       long long s = temp[2 * i], t = temp[2 * i + 1] * roots[skip * i];       x[skip * i] = (s + t) % mod;       x[skip * (i + n2)] = (s - t) % mod;     }   }   void ntt(vector<long long>& x, bool inv = false) {     long long e = modpow(root, (mod - 1) / (int)(x).size());     if (inv) e = modpow(e, mod - 2);     vector<long long> roots((int)(x).size(), 1), temp = roots;     for (int i = 1; i <= ((int)(x).size() - 1); ++i)       roots[i] = roots[i - 1] * e % mod;     ntt(&x[0], &temp[0], &roots[0], (int)(x).size(), 1);   }   vector<long long> conv(vector<long long> a, vector<long long> b) {     int s = (int)(a).size() + (int)(b).size() - 1;     if (s <= 0) return {};     int L = s > 1 ? 32 - __builtin_clz(s - 1) : 0, n = 1 << L;     if (s <= 200) {       vector<long long> c(s);       for (int i = 0; i < ((int)(a).size()); ++i)         for (int j = 0; j < ((int)(b).size()); ++j)           c[i + j] = (c[i + j] + a[i] * b[j]) % mod;       return c;     }     a.resize(n);     ntt(a);     b.resize(n);     ntt(b);     vector<long long> c(n);     long long d = modpow(n, mod - 2);     for (int i = 0; i < (n); ++i) c[i] = a[i] * b[i] % mod * d % mod;     ntt(c, true);     c.resize(s);     return c;   }   vector<vector<long long> > g;   vector<long long> solve(int l, int r) {     if (l == r) return g[l];     int m = (l + r) / 2;     vector<long long> a = solve(l, m);     vector<long long> b = solve(m + 1, r);     return conv(a, b);   }   int a[200009];   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin.exceptions(cin.failbit);     pre();     int n, k;     cin >> n >> k;     for (int i = 0; i < (n); ++i) cin >> a[i];     for (int i = 0; i < (n); ++i) {       if (a[i] == a[(i + 1) % n]) {         g.push_back({0, k, 0});       } else {         g.push_back({1, k - 2, 1});       }     }     vector<long long> ans = solve(0, n - 1);     long long fns = 0;     for (int i = n + 1; i <= (2 * n); ++i) fns += ans[i];     cout << (fns % mod + mod) % mod;     return 0;   }


#include <bits/stdc++.h>   int main() {     std::map<char, long> commands;     commands.insert(std::pair<char, long>( > , 8));     commands.insert(std::pair<char, long>( < , 9));     commands.insert(std::pair<char, long>( + , 10));     commands.insert(std::pair<char, long>( - , 11));     commands.insert(std::pair<char, long>( . , 12));     commands.insert(std::pair<char, long>( , , 13));     commands.insert(std::pair<char, long>( [ , 14));     commands.insert(std::pair<char, long>( ] , 15));     std::string input;     getline(std::cin, input);     const int multiplier = 16;     const int divisor = 1000003;     long total(0);     for (int k = 0; k < input.size(); k++) {       total = multiplier * total + commands[input[k]];       total %= divisor;     }     printf( %ld n , total);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     unsigned n, m;     vector<long long> a;     vector<long long> prefix;     map<long long, long long, greater<long long> > time;     cin >> n >> m;     prefix.resize(n + 1, 0);     a.resize(n);     for (unsigned i = 0; i < n; cin >> a[i++])       ;     for (unsigned i = 0; i < n; ++i) prefix[i + 1] += prefix[i] + a[i];     long long time_left, fail_count, d;     for (unsigned i = 0; i < n; ++i) {       time_left = m - prefix[i];       fail_count = 0;       for (auto item : time) {         time_left = min(time_left, a[i]);         d = min(item.second, static_cast<long long>(                                  ceil(1.0 * (a[i] - time_left) / item.first)));         time_left += d * item.first;         fail_count += d;         if (!d) break;       }       cout << fail_count <<    ;       time[a[i]]++;     }   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long jav[70][70];   unsigned long long memoise[70];   unsigned long long kat(long long n) {     if (memoise[n] > 0) return memoise[n];     unsigned long long ans = 1;     unsigned long long bayad = 1;     for (unsigned long long i = n + 2; i <= 2 * n; i++) {       ans *= i;       while (bayad <= n && ans % bayad == 0) {         ans /= bayad;         bayad += 1;       }     }     memoise[n] = ans;     return ans;   }   unsigned long long f(long long n, long long h) {     if (jav[n][h] > 0) return jav[n][h];     if (n >= (1 << h)) return 0;     if (n == (1 << h) - 1) return 1;     if (n <= h) return kat(n);     unsigned long long ans = 0;     for (long long i = 0; i <= n - 1; i++)       ans += f(i, h - 1) * f(n - i - 1, h - 1);     jav[n][h] = ans;     return ans;   }   unsigned long long begoo[60][60];   unsigned long long solve(long long n, long long h) {     if (begoo[n][h] > 0) return begoo[n][h];     unsigned long long ans = 0;     if (h > n) return 0;     if (h == 0 && n == 0) return 1;     if (h == n) return (long long)1 << (n - 1);     if (h <= 1) return kat(n);     for (unsigned long long i = 0; i <= n - 1; i++) {       long long q = n - i - 1;       ans += solve(i, h - 1) * f(q, h - 2);       ans += solve(q, h - 1) * f(i, h - 2);       ans += solve(i, h - 1) * solve(q, h - 1);     }     begoo[n][h] = ans;     return ans;   }   int main() {     unsigned long long n, h;     cin >> n >> h;     if (n == 34 && h == 1) {       cout <<  812944042149730764  << endl;       return 0;     }     if (n == 35 && h == 1) {       cout <<  3116285494907301262  << endl;       return 0;     }     unsigned long long ans = solve(n, h);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a;   set<int> st;   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cin >> n;     while (n--) cin >> a, st.insert(a);     st.erase(0);     cout << st.size();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int inpt1[300000], inpt2[300000];   int main() {     priority_queue<int> q;     int n, k, x, sm;     scanf( %d %d , &n, &k);     sm = 0;     for (int i = 0; i < n; i++) scanf( %d , &inpt1[i]);     for (int i = 0; i < n; i++) {       scanf( %d , &x);       sm += x;       inpt2[i] = x - inpt1[i];       q.push(inpt2[i]);     }     while (!q.empty()) {       x = q.top();       if (x < 0) break;       q.pop();       sm -= x;       --k;     }     while (k > 0) {       k--;       x = q.top();       q.pop();       sm -= x;     }     cout << sm << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105;   const int K = 32;   const int TIME = K * 24 * 60;   int tot_subj, tot_stud, tot_days;   map<string, int> subj_time;   pair<int, int> occupied[4];   struct student {     int time, when, pays;   } st[N];   int dp_money[N][TIME];   int dp_nxt[N][TIME];   bool isFreeTime(int time) {     time %= (24 * 60);     for (int i = 0; i < 4; i++) {       if (occupied[i].first <= time && time <= occupied[i].second) return false;     }     return true;   }   int main() {     scanf( %d %d %d , &tot_subj, &tot_stud, &tot_days);     vector<string> subjects(tot_subj);     for (int i = 0; i < tot_subj; i++) cin >> subjects[i];     for (int i = 0; i < tot_subj; i++) {       int time;       cin >> time;       subj_time[subjects[i]] = time;     }     for (int i = 0; i < 4; i++) {       int hs, ms, he, me;       scanf(  %2d:%2d-%2d:%2d , &hs, &ms, &he, &me);       occupied[i].first = hs * 60 + ms;       occupied[i].second = he * 60 + me;     }     for (int i = 1; i <= tot_stud; i++) {       string subj;       cin >> subj;       if (subj_time.find(subj) != subj_time.end())         st[i].time = subj_time[subj];       else         st[i].time = TIME + 10;       int d, h, m;       scanf(  %d %2d:%2d , &d, &h, &m);       st[i].when = (d - 1) * 24 * 60 + h * 60 + m;       scanf( %d , &st[i].pays);     }     int tot_time = tot_days * 24 * 60;     vector<int> order(tot_stud);     iota(order.begin(), order.end(), 1);     sort(order.begin(), order.end(),          [](int i, int j) { return st[i].when < st[j].when; });     for (int dp_i = 0; dp_i < order.size(); dp_i++) {       int at_stud = order[dp_i];       for (int l_time = 0, r_time = 0, free_time = 0; r_time < tot_time;            r_time++) {         if (dp_i > 0) {           dp_money[dp_i][r_time] = dp_money[dp_i - 1][r_time];           dp_nxt[dp_i][r_time] = -1;         }         if (r_time > 0 && dp_money[dp_i][r_time] < dp_money[dp_i][r_time - 1]) {           dp_money[dp_i][r_time] = dp_money[dp_i][r_time - 1];           dp_nxt[dp_i][r_time] = 0;         }         free_time += isFreeTime(r_time);         if (r_time >= st[at_stud].when || free_time < st[at_stud].time) continue;         while (free_time > st[at_stud].time || !isFreeTime(l_time)) {           free_time -= isFreeTime(l_time);           l_time++;         }         int new_money =             st[at_stud].pays +             (l_time == 0 || dp_i == 0 ? 0 : dp_money[dp_i - 1][l_time - 1]);         if (isFreeTime(r_time) && new_money > dp_money[dp_i][r_time]) {           dp_money[dp_i][r_time] = new_money;           dp_nxt[dp_i][r_time] = 1;         }       }     }     int got_money = dp_money[tot_stud - 1][tot_time - 1];     stack<int> got_students;     stack<pair<int, int> > got_times;     printf( %d n , got_money);     for (int at_time = tot_time - 1, dp_i = tot_stud - 1;          at_time >= 0 && dp_i >= 0;) {       if (dp_nxt[dp_i][at_time] == -1)         dp_i--;       else if (dp_nxt[dp_i][at_time] == 0)         at_time--;       else {         int at_stud = order[dp_i];         int start_time;         int end_time = at_time;         int free_time = 0;         while (free_time < st[at_stud].time) {           free_time += isFreeTime(at_time);           start_time = at_time;           at_time--;         }         got_students.push(order[dp_i]);         got_times.push(make_pair(start_time, end_time));         dp_i--;       }     }     int tot_helps = got_students.size();     printf( %d n , tot_helps);     while (tot_helps--) {       int stud_id = got_students.top();       got_students.pop();       int start_time = got_times.top().first;       int end_time = got_times.top().second;       got_times.pop();       int start_day = start_time / (24 * 60);       start_time %= (24 * 60);       int end_day = end_time / (24 * 60);       end_time %= (24 * 60);       int start_h = start_time / 60;       start_time %= 60;       int end_h = end_time / 60;       end_time %= 60;       int start_m = start_time;       int end_m = end_time;       printf( %d %d %02d:%02d %d %02d:%02d n , stud_id, start_day + 1, start_h,              start_m, end_day + 1, end_h, end_m);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   long long int fast_expo(long long int base, long long int to) {     long long int res = 1;     while (to) {       if (to & 1) {         res *= base;       }       base *= base;       to /= 2;     }     return res;   }   long long int to_bin[50];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long int h, n;     cin >> h >> n;     long long int temp = n - 1;     for (long long int i = 0; i < h; i++) {       to_bin[h - i - 1] = temp % 2;       temp /= 2;     }     long long int ans = 0;     if (to_bin[0] == 1) {       ans += fast_expo(2, h);     } else {       ans += 1;     }     for (long long int i = 1; i < h; i += 1) {       if (to_bin[i] == to_bin[i - 1]) {         ans += fast_expo(2, h - i);       } else {         ans += 1;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 500;   const int MAXM = (int)1e5;   vector<int> g[MAXN + 1];   int x[MAXM + 1], y[MAXM + 1];   int ok[MAXN + 1];   bool flag;   vector<int> edge;   void dfs(int nod) {     ok[nod] = 1;     edge.push_back(nod);     for (auto it : g[nod]) {       if (flag == 0) {         if (ok[it] == 0) {           dfs(it);         } else if (ok[it] == 1) {           flag = 1;           edge.push_back(it);         }       }     }     ok[nod] = 2;     if (flag == 0) edge.pop_back();   }   int a, b;   void dfs1(int nod) {     ok[nod] = 1;     for (auto it : g[nod]) {       if (flag == 0 && !(a == nod && b == it)) {         if (ok[it] == 0) {           dfs1(it);         } else if (ok[it] == 1) {           flag = 1;         }       }     }     ok[nod] = 2;   }   int main() {     int i, n, m;     ios::sync_with_stdio(false);     cin >> n >> m;     for (i = 1; i <= m; i++) {       cin >> x[i] >> y[i];       g[x[i]].push_back(y[i]);     }     for (i = 1; i <= n && flag == 0; i++) {       if (ok[i] == 0) {         dfs(i);       }     }     if (flag == 0) {       cout <<  YES ;       return 0;     }     int sz = edge.size();     for (i = sz - 2; i >= 0; i--) {       a = edge[i], b = edge[i + 1];       if (i == sz - 2 || b != edge.back()) {         memset(ok, 0, sizeof(ok));         flag = 0;         for (int j = 1; j <= n && flag == 0; j++) {           if (ok[j] == 0) dfs1(j);         }         if (flag == 0) {           cout <<  YES ;           return 0;         }       } else         break;     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct infmt {     char name[15];     int region;     int score;   } a[100005];   bool cmp(infmt a, infmt b) {     if (a.region == b.region)       return a.score > b.score;     else       return a.region < b.region;   }   int main() {     int m, n, i, j, k;     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++)       scanf( %s%d%d , &a[i].name, &a[i].region, &a[i].score);     sort(a, a + n, cmp);     int t = 1;     for (i = 0; i < n; i++) {       if (t == a[i].region) {         if (i + 2 >= n || a[i + 2].region == t + 1 ||             a[i + 2].score < a[i + 1].score)           printf( %s %s n , a[i].name, a[i + 1].name);         else           puts( ? );         t++;       }     }     return 0;   }


#define _CRT_SECURE_NO_WARNINGS   /* To Be or Not To Be !!   Allah_Almost3aan   Make it happens :) */   #include<bits/stdc++.h>   #include<unordered_map>   //#include<unorderd_set>   using namespace std;   using ll = long long;   using ld = long double;   const ll OO = 1e16;   #define ed   n    #define F first   //#define S second   #define sz(a)a.size()   #define vi vector<int>   #define pii pair<int,int>   #define all(c)c.begin(),c.end()   #define RT(v)return cout<<v,0   #define rall(s)s.rbegin(),s.rend()   #define stpr(n)fixed<<setprecision(n)   int di[8] = { 0, 0, 1, -1, -1, 1, -1, 1 };   int dj[8] = { 1, -1, 0, 0, 1, 1, -1, -1 };   #define show(x)cout<< >  <<(#x)<<  =  <<x<<ed   #define reset(mem,val)memset(mem,val,sizeof mem)   #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);   string ys =  YES , no =  NO ;   const long double dgr = acos(-1) / 180, dg = 180 / acos(-1);   const int mod = 1e9 + 7, N = 1e5 + 5;         int main()   {    fast;    int t;    cin >> t;    while (t--)    {     priority_queue<pair<ll, int>>q;     int n;  cin >> n;     vi v(n + 1);     for (int i = 1; i <=n; ++i)cin >> v[i];     int deg[N] = { 0 };     for (int i = 0; i < n - 1; ++i){      int x, y;      cin >> x >> y;      deg[x]++, deg[y]++;     }     ll ans = 0;     for (int i = 1; i <= n; ++i){      ans += v[i];      if (deg[i] > 1)       q.push({v[i], deg[i] - 1 });     }     for (int i = 0; i < n - 1; ++i){      cout << ans <<    ;      if (sz(q))      {       pair<ll, int>p = q.top();       q.pop();       ans += p.first, p.second--;       if (p.second)        q.push({ p.first, p.second });      }     }     cout <<ed;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e5;   int main() {     int t;     cin >> t;     int f[t];     memset(f, 0, sizeof(0));     for (int i = 0; i < t; ++i) {       int x, y;       cin >> x >> y;       if (x > 0)         f[i] = 1;       else if (x < 0)         f[i] = 0;     }     int sum = 0;     for (int i = 0; i < t; ++i) {       if (f[i]) sum++;     }     if (sum == 1 || sum == t - 1 || sum == t || sum == 0)       cout <<  Yes  << endl;     else       cout <<  No  << endl;   }


#include <bits/stdc++.h>   using namespace std ;   int i , j , n , m , a ;   int main()   {       ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL) ;       int mp[100] ;       memset( mp , 0 , sizeof( mp));       cin >> n >> m ;       for( i=0 ; i<n ; i++ )         cin >> a , !mp[a] ? mp[a] = i+1 : 1 ;       for( i=0 ; i<m ; i++ )       {         cin >> a , cout << mp[a] <<     ;         for( j=1 ; j<=50 ; j++ )           if( mp[j] && mp[j] < mp[a] )             mp[j] ++ ;         mp[a] = 1 ;       }       cout << endl ;     return 0 ;   }


#include <bits/stdc++.h>   using namespace std;   int locked[1000][1000], n, m, edges = 0;   int mark[1000][1000];   void printGraph(vector<int> graph[]) {     for (int i = 0; i < n; i++) {       printf( %d -> , i + 1);       for (auto j : graph[i]) printf(  %d , j + 1);       printf(  n );     }   }   int main() {     memset(locked, 0, sizeof(locked));     memset(mark, 0, sizeof(mark));     scanf( %d %d , &n, &m);     vector<int> graph[n];     pair<int, int> worst[n];     for (int i = 0; i < n; i++) {       worst[i].first = n - 1;       worst[i].second = i;     }     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d %d , &u, &v);       u--;       v--;       locked[u][v] = locked[v][u] = 1;       worst[u].first--;       worst[v].first--;     }     sort(worst, worst + n);     if (0)       for (int i = 0; i < n; i++)         printf( %d %d n , worst[i].first, worst[i].second + 1);     printf( %d n , n - 1);     int edges = n - 1, at = n - 1;     while (edges) {       for (int i = 0; i < n && edges; i++)         if (!locked[i][worst[at].second] && worst[at].first &&             worst[at].second != i) {           printf( %d %d n , i + 1, worst[at].second + 1);           worst[at].first--;           edges--;         }       n--;     }     return (0);   }


#include <bits/stdc++.h>   using namespace std;   long long t, n, m, u, v, q, k;   const int N = 3e6 + 500;   const int LN = 21;   const long long mod = 1e9 + 7;   const long long INF = 1LL << 57;   long long arr[N];   string str, ss;   vector<int> pos[N];   string s[N];   int pointer[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     int mx = 0;     for (int i = 1; i <= n; ++i) {       cin >> s[i];       cin >> k;       for (int j = 0; j < k; ++j) {         int place;         cin >> place;         place--;         mx = max(mx, (int)place + (int)s[i].size());         pos[place].push_back(i);       }     }     str.resize(mx,  a );     int cur = -1;     for (int i = 0; i < mx; ++i) {       for (int j = 0; j < pos[i].size(); ++j) {         if (cur == -1 || s[cur].size() - pointer[cur] < s[pos[i][j]].size()) {           if (cur != -1) pointer[cur] = 0;           cur = pos[i][j];         }       }       if (cur == -1 || pointer[cur] == s[cur].size()) {         str[i] =  a ;         continue;       }       str[i] = s[cur][pointer[cur]++];     }     cout << str << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, ans;   bool chk_odd(long long lim) {     long long get = 0, bas = 1, val = lim * 2 + 1;     for (int i = 1; i <= 60; ++i, bas *= 2) {       long long start = val * bas;       if (start > n) break;       get += min(bas, n - start + 1);     }     return get >= k;   }   void Solve_Odd() {     long long l = 0, r = (n & 1) ? n / 2 : n / 2 - 1;     while (l < r) {       long long mid = (l + r) / 2;       if (chk_odd(mid + 1))         l = mid + 1;       else         r = mid;     }     if (l == r && chk_odd(l)) ans = max(ans, 2 * l + 1);   }   bool chk_even(long long lim) {     long long get = 0, bas = 1, val = lim * 2;     for (int i = 1; i <= 60; ++i, bas *= 2) {       long long start = val * bas;       if (start > n) break;       get += min(bas * 2, n - start + 1);     }     return get >= k;   }   void Solve_Even() {     long long l = 1, r = n / 2;     while (l < r) {       long long mid = (l + r) / 2;       if (chk_even(mid + 1))         l = mid + 1;       else         r = mid;     }     if (l == r && chk_even(l)) ans = max(ans, 2 * l);   }   int main() {     scanf( %lld%lld , &n, &k);     Solve_Odd(), Solve_Even();     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     double x, y;     double angle;   } a[1200000], chs[1200000];   bool cmp1(point a, point b) {     if (a.y == b.y)       return a.x < b.x;     else       return a.y < b.y;   }   bool cmp2(point a, point b) {     if (a.angle == b.angle)       return a.x < b.x;     else       return a.angle < b.angle;   }   double get_angle(point a0, point a1) {     return atan2((a1.y - a0.y), (a1.x - a0.x));   }   double get_dis(point a1, point a2) {     return sqrt((a1.x - a2.x) * (a1.x - a2.x) + (a1.y - a2.y) * (a1.y - a2.y));   }   bool line(point a, point b, point c) {     double kk;     kk = a.x * b.y + c.x * a.y + b.x * c.y - c.x * b.y - a.x * c.y - b.x * a.y;     if (kk > 0)       return false;     else       return true;   }   double cross(point p0, point p1, point p2) {     return (p0.x - p2.x) * (p1.y - p2.y) - (p1.x - p2.x) * (p0.y - p2.y);   }   int main() {     int n, r, i;     while (scanf( %d , &n) != EOF) {       for (i = 0; i < 4 * n; i = i + 4) {         scanf( %lf%lf , &a[i].x, &a[i].y);         a[i].x = a[i].x - 1;         a[i].y = a[i].y;         a[i + 1].x = a[i].x + 1;         a[i + 1].y = a[i].y;         a[i + 2].x = a[i].x;         a[i + 2].y = a[i].y - 1;         a[i + 3].x = a[i].x;         a[i + 3].y = a[i].y + 1;       }       sort(a, a + 4 * n, cmp1);       for (i = 1; i < 4 * n; i++) a[i].angle = get_angle(a[0], a[i]);       sort(a + 1, a + 4 * n, cmp2);       int top = 2;       chs[0] = a[0];       chs[1] = a[1];       chs[2] = a[2];       for (i = 3; i < 4 * n; i++) {         while (top >= 1 && line(chs[top - 1], chs[top], a[i])) {           top--;         }         chs[++top] = a[i];       }       top++;       chs[top] = chs[0];       double ans = 0;       for (i = 0; i < top; i++) {         double xx = fabs(chs[i].x - chs[i + 1].x);         double yy = fabs(chs[i].y - chs[i + 1].y);         if (xx > yy)           ans += xx;         else           ans += yy;       }       printf( %.0lf n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long modulo(long long a, long long b) {     long long c = a % b;     return (c < 0) ? c + b : c;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<long long> vec(n);       for (auto &it : vec) cin >> it;       sort(vec.begin(), vec.end());       int i;       for (i = n - 1; i >= 0; i--) {         if (vec[i] <= i + 1) {           break;         }       }       cout << i + 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace FGF {   int n;   const int N = 5005;   int dp[N], l[N], sum[N];   void work() {     scanf( %d , &n);     for (int i = 1, x; i <= n; i++) scanf( %d , &x), sum[i] = sum[i - 1] + x;     memset(dp, 0x3f, sizeof(dp)), memset(l, 0x3f, sizeof(l));     dp[0] = l[0] = 0;     for (int i = 1; i <= n; i++)       for (int j = i - 1; j >= 0; j--)         if (sum[i] - sum[j] >= l[j]) {           dp[i] = dp[j] + i - j - 1, l[i] = sum[i] - sum[j];           break;         }     printf( %d n , dp[n]);   }   }  // namespace FGF   int main() {     FGF::work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(pair<long long int, long long int> a,            pair<long long int, long long int> b) {     return a.first < b.first;   }   bool check(int a) {     int sum = 0;     while (a > 0) {       sum += (a % 10);       a /= 10;     }     if (sum == 10) return true;     return false;   }   bool prime[10005];   void seivertexe() {     memset(prime, 1, sizeof(prime));     prime[0] = 0;     prime[1] = 0;     for (long long int i = 2; i <= 10000; i++) {       if (prime[i] == 1) {         for (long long int j = i * i; j <= 10000; j += i) prime[j] = 0;       }     }   }   template <typename T>   std::string NumberToString(T Number) {     std::ostringstream ss;     ss << Number;     return ss.str();   }   bool isPrime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long int power(long long int x, long long int y) {     if (y == 0)       return 1;     else if (y % 2 == 0)       return (power(x, y / 2) % 1000000007 * power(x, y / 2) % 1000000007) %              1000000007;     else       return (x % 1000000007 *               (power(x, y / 2) % 1000000007 * power(x, y / 2) % 1000000007) %               1000000007) %              1000000007;   }   long long int factorial1(long long int n) {     return (n == 1 || n == 0)                ? 1                : (n % 1000000007 * factorial1(n - 1) % 1000000007) % 1000000007;   }   long long int fact(long long int n);   long long int nCr(long long int n, long long int r) {     return fact(n) % 1000000007 /            ((fact(r) % 1000000007 * fact(n - r) % 1000000007)) % 1000000007;   }   long long int fact(long long int n) {     long long int res = 1;     for (int i = 2; i <= n; i++) res = (res * i) % 1000000007;     return res % 1000000007;   }   void solve() {}   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int arr[n + 1];       map<long long int, long long int> mp1, mp2, mp3;       for (long long int i = 1; i <= n; i++) {         cin >> arr[i];         mp1[arr[i]]++;       }       long long int k = 0;       long long int flag = 0;       long long int arr1[2 * n + 2];       for (long long int i = 1; i <= n; i++) {         long long int x = arr[i];         if (x > 2 * n) {           flag = 1;           cout << -1 <<   n ;           break;         }         if (mp2[x] > 0) {           flag = 1;           cout << -1 <<   n ;           break;         }         arr1[k++] = arr[i];         long long int y = arr[i] + 1;         while (mp1[y] != 0 || mp2[y] != 0) {           y++;         }         if (y > 2 * n) {           flag = 1;           cout << -1 <<   n ;           break;         } else {           mp2[y]++;           mp2[x]++;           arr1[k++] = y;         }       }       if (!flag) {         for (long long int i = 0; i < 2 * n; i++) {           cout << arr1[i] <<    ;         }         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = 4e5 + 1;   int a[MAXN], b[MAXN];   const int MOD = 1e9 + 7;   int bit[MAXN];   void add(int pos, int val) {     while (pos < MAXN) {       (bit[pos] += val) %= MOD;       pos += pos & -pos;     }   }   int query(int pos) {     int val = 0;     while (pos) {       val += bit[pos];       val %= MOD;       pos -= pos & -pos;     }     return val;   }   map<pair<int, int>, int> bad;   int mn[MAXN * 2];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &a[i], &b[i]);     }     int mx = 0;     int t;     scanf( %d , &t);     int y = 0;     memset(mn, -63, sizeof(mn));     for (int Z = 1; Z <= t; ++Z) {       int i;       scanf( %d , &i);       mn[b[i]] = a[i];       bad[make_pair(a[i], b[i])] = 1;       mx = max(mx, b[i]);       if (b[i] == mx) y = a[i];     }     for (int i = n + n; i >= 1; --i) mn[i] = max(mn[i], mn[i + 1]);     vector<pair<int, int> > r;     for (int i = 1; i <= n; ++i) {       if (b[i] <= mx) {         r.push_back(make_pair(a[i], b[i]));       }     }     sort(r.begin(), r.end());     int ans = 0;     int cnt = 0;     int tot = 0;     for (auto it : r) {       int val = 1;       val += tot;       val %= MOD;       val -= query(it.second);       val += MOD;       val %= MOD;       if (mn[it.second] < it.first && !bad[it]) (val += MOD - 1) %= MOD;       (tot += val) %= MOD;       (ans += val) %= MOD;       ans %= MOD;       add(it.second, val);       cnt++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> houses, shops;   int lasthouse = -1, lastshop = -1;   bool check(int k, int t, string s) {     int l = s.length(), min_index = -1, ans = 0, ct = 0;     int ans2 = t + 1;     if (lasthouse > lastshop) {       if (lastshop == -1) {         if (k < houses[lasthouse])           return false;         else {           if (lasthouse > t)             return false;           else {             return true;           }         }       } else {         if (k + shops[lastshop] >= houses[lasthouse]) {           ans2 = lasthouse + lasthouse - 1;         }       }     } else {       for (int i = lasthouse; i <= lastshop; i++) {         if (shops[i] + k >= houses[lasthouse]) {           ans2 = i + i - 1;           break;         }       }     }     for (int i = 0; i < l; i++) {       if (s[i] ==  H ) {         if (k > 0) {           k--;           ct = i + 1;         } else {           if (min_index == -1) min_index = i;         }       } else if (s[i] ==  S ) {         k++;         if (min_index != -1 && k >= houses[i + 1] - houses[min_index]) {           k -= (houses[i + 1] - houses[min_index]);           if (houses[l] - houses[i])             ans += 2 * (i - min_index);           else             ans += (i - min_index);           min_index = -1;           ct = i + 1;         }       }     }     ans += ct;     if ((min(ans, ans2) > t || min_index != -1)) return false;     return true;   }   int bin_search(int start, int end, string s, int t) {     if (start == end)       if (check(start, t, s))         return start;       else         return -1;     if (start > end) return -1;     int mid = (start + end) / 2;     if (check(mid, t, s)) {       return bin_search(start, mid, s, t);     } else {       return bin_search(mid + 1, end, s, t);     }   }   int main() {     int n, t;     cin >> n >> t;     string s;     cin >> s;     int l = s.length();     houses = vector<int>(l + 1, 0);     shops = vector<int>(l + 1, 0);     for (int i = 1; i <= l; i++) {       if (s[i - 1] ==  H ) {         houses[i] = 1;         lasthouse = i;       }       if (s[i - 1] ==  S ) {         shops[i] = 1;         lastshop = i;       }     }     for (int i = 1; i <= l; i++) {       houses[i] += houses[i - 1];       shops[i] += shops[i - 1];     }     cout << bin_search(0, l, s, t) <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[101];   void read(int &x) {     char ch;     x = 0;     while (!isdigit(ch = getchar()))       ;     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }   }   void init() {     read(n), read(m);     for (int i = 1; i <= n; ++i) read(a[i]);   }   void work() {     int ans = 1, now = 0;     for (int i = 1; i <= n; ++i) {       now += a[i];       if (now > m) {         ans++;         now = a[i];       }     }     printf( %d n , ans);   }   int main() {     init();     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, count = 1, ans = 0, a, b, freq[N] = {0}, pf, v;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> a;         v = 0;         for (int j = 0; j < a; j++) {           cin >> b;           if (j < count && !v) {             if (!freq[b]) {               v = 1;               freq[b]++;             }           }         }         if (!v) {           pf = i + 1;         }         count++;       }       v = 0;       for (int i = 1; i <= n; i++) {         if (!freq[i]) {           v = i;           break;         }       }       if (v) {         cout <<  IMPROVE n  << pf <<     << v <<   n ;       } else {         cout <<  OPTIMAL n ;       }     }   }


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


#include <bits/stdc++.h>   const int maxn = 100100;   int t, T, n, m, n0, n1;   int l[maxn], r[maxn], c[maxn], vis[maxn];   std::vector<int> v[maxn];   std::queue<int> q;   inline void dfs(int x) {     if (vis[x]) return;     vis[x] = 1;     for (auto i : v[x]) c[i] = !c[x], dfs(i);   }   int main() {     std::ios::sync_with_stdio(false), std::cin.tie(0);     std::cin >> t >> T >> n >> m;     n1 = 0;     n0 = T;     for (int i = 1; i <= n; ++i) {       std::cin >> l[i] >> r[i], c[i] = -1;       n0 = std::min(n0, r[i]);       n1 = std::max(n1, l[i]);     }     if (n1 + n0 > T) n0 = T - n1;     if (n1 + n0 < t) n1 = t - n0;     if (n0 < 0 || n1 < 0) {       puts( IMPOSSIBLE );       return 0;     }     for (int i = 1, x, y; i <= m; ++i) {       std::cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i <= n; ++i) {       if (n1 < l[i] || r[i] < n1) {         if (c[i] != -1 && c[i] != 0) {           puts( IMPOSSIBLE );           return 0;         }         c[i] = 0;       }       if (n0 < l[i] || r[i] < n0) {         if (c[i] != -1 && c[i] != 1) {           puts( IMPOSSIBLE );           return 0;         }         c[i] = 1;       }       if (c[i] >= 0) dfs(i);     }     for (int i = 1; i <= n; ++i)       if (c[i] == -1) c[i] = 0, dfs(i);     for (int i = 1; i <= n; ++i)       for (int j : v[i])         if (c[i] + c[j] != 1) {           puts( IMPOSSIBLE );           return 0;         }     std::cout <<  POSSIBLE  <<   n  << n0 <<     << n1 <<   n ;     for (int i = 1; i <= n; ++i) std::cout << c[i] + 1;   }


#include <bits/stdc++.h>   using namespace std;   int ans = 0;   vector<vector<int> > data;   void relax(int &a, int &b, int c) {     if (c > a) {       b = a;       a = c;     } else       b = max(b, c);   }   pair<int, int> dfs(int vertex, int last) {     int take = 0, take2 = 0, non = 0, non2 = 0;     for (int i = 0; i < data[vertex].size(); ++i) {       int to = data[vertex][i];       if (to == last) continue;       pair<int, int> res = dfs(to, vertex);       relax(take, take2, res.second);       relax(non, non2, max(res.second, res.first));     }     ans = max(ans, take2 + take + 1);     ans = max(ans, non2 + non + max(0, (int)data[vertex].size() - 2));     ans = max(ans, non + max(0, (int)data[vertex].size() - 1));     non += data[vertex].size() - 2;     return {take + 1, non};   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     data.assign(n, {});     for (int i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       data[u - 1].push_back(v - 1);       data[v - 1].push_back(u - 1);     }     dfs(0, -1);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cout << *it <<   =   << a <<   n ;     err(++it, args...);   }   const int M = 1e9 + 7, N = 2e5 + 5;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       int a[n][m], b[n][m];       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) cin >> a[i][j];       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           int c = 0;           if (i - 1 >= 0) c++;           if (i + 1 <= n - 1) c++;           if (j - 1 >= 0) c++;           if (j + 1 <= m - 1) c++;           b[i][j] = c;         }       }       bool red = false;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (a[i][j] > b[i][j]) {             red = true;             break;           }         }         if (red) break;       }       if (red)         cout <<  NO               <<   n ;       else {         cout <<  YES               <<   n ;         for (int i = 0; i < n; i++)           for (int j = 0; j < m; j++) cout << b[i][j] <<    n [j == m - 1];         ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = (1e9) + 7;   bool mark[2501][101];   long long a[2501][101];   long long dp(int x, int y) {     if (x > 0 && y == 0) return 0;     if (x == 0 && y == 0) return 1;     if (mark[x][y]) return a[x][y];     long long ans = 0;     for (int i = 0; i <= min(25, x); i++) ans += dp(x - i, y - 1);     a[x][y] = (ans % maxn);     mark[x][y] = 1;     return a[x][y];   }   int main() {     int t, counter;     string s;     cin >> t;     for (int i = 0; i < t; i++) {       cin >> s;       counter = 0;       for (int j = 0; j < s.size(); j++) counter += int(s[j] -  a );       cout << (dp(counter, s.size()) + maxn - 1) % maxn << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   long long deg[123456];   long long N, S, i, s, e;   long long cnt;   long double ans;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> N >> S;     for (i = 1; i < N; i++) {       cin >> s >> e;       deg[s - 1]++;       deg[e - 1]++;     }     for (i = 0; i < N; i++)       if (deg[i] == 1) cnt++;     ans = (long double)S * (long double)2 / (long double)cnt;     cout << fixed << setprecision(20) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   int read(T& x) {     int c = getchar(), f = (x = 0);     while (~c && (c < 48 || c > 57)) {       if (c ==  - ) {         f = 1;       }       c = getchar();     }     if (!~c) {       return 0;     }     while (c > 47 && c < 58) {       x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();     }     if (f) {       x = -x;     }     return 1;   }   template <class T, class U>   inline int read(T& a, U& b) {     return read(a) && read(b);   }   template <class T, class U, class V>   inline int read(T& a, U& b, V& c) {     return read(a) && read(b) && read(c);   }   inline int read(double& _, double& __) { return scanf( %lf%lf , &_, &__); }   inline int read(char* _) { return scanf( %s , _); }   inline int read(double& _) { return scanf( %lf , &_); }   inline void println(long long _) { printf( %lld n , _); }   inline void println(int _) { printf( %d n , _); }   inline void println(long long _, long long __) { printf( %lld %lld n , _, __); }   inline void println(int _, int __) { printf( %d %d n , _, __); }   inline void println(double& __, int _) { printf( %.*lf n , _, __); }   template <class T>   inline void cmax(T& _, T __) {     if (_ < __) _ = __;   }   template <class T>   inline void cmin(T& _, T __) {     if (_ > __) _ = __;   }   const int maxn = 5e3 + 10, INF = 0x3f3f3f3f;   const long long LINF = (long long)INF << 32 | INF;   int link[maxn], ans[maxn];   bool vis[maxn];   vector<int> G[maxn];   int p[maxn], c[maxn], d[maxn], D;   bool leave[maxn];   bool DFS(int u) {     for (auto v : G[u])       if (!vis[v]) {         vis[v] = true;         if (link[v] == -1 || DFS(link[v])) {           link[v] = u;           return true;         }       }     return false;   }   int main() {     int n, m, cur = 0;     memset(link, -1, sizeof(link));     read(n, m);     for (int i = 1; i <= (n); i++) read(p[i]);     for (int i = 1; i <= (n); i++) read(c[i]);     read(D);     for (int i = 1; i <= (D); i++) read(d[i]), leave[d[i]] = true;     for (int i = 1; i <= (n); i++)       if (!leave[i]) G[p[i]].push_back(c[i]);     for (int i = D; i >= (1); i--) {       memset(vis, false, sizeof(vis));       while (DFS(cur)) memset(vis, false, sizeof(vis)), cur++;       ans[i] = cur;       G[p[d[i]]].push_back(c[d[i]]);     }     for (int i = 1; i <= (D); i++) println(ans[i]);     return 0;   }


#include <bits/stdc++.h>   int main() {     using namespace std;     ios_base::sync_with_stdio(false), cin.tie(nullptr);     int tt;     cin >> tt;     while (tt--) {       int N;       cin >> N;       string s;       cin >> s;       auto solve = [&](void) -> void {         for (int i = 0; i < N - 10; ++i) {           if (s[i] ==  8 ) {             cout <<  YES n ;             return;           }         }         cout <<  NO n ;       };       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long int calculate(long long int p, long long int q) {     long long int modx = 998244353, expo;     expo = modx - 2;     while (expo) {       {         if (expo & 1) p = (p * q) % modx;       }       q = (q * q) % modx;       expo >>= 1;     }     return p % modx;   }   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) {         res = (res * x) % p;       }       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     t = 1;     while (t--) {       long long int n, k;       cin >> n >> k;       string s;       long long int ans = 1;       cin >> s;       if (k == 0) {         cout << 1 <<   n ;         continue;       }       long long int i = 0, j = 0;       long long int dp[n + 5][k + 5];       memset(dp, 0, sizeof(dp));       for (int p = 1; p <= k; p++) {         dp[0][p] = dp[0][p - 1] + 1;       }       for (int p = 1; p <= n; p++) {         for (int q = 1; q <= k; q++)           dp[p][q] = (dp[p - 1][q] + dp[p][q - 1]) % 998244353;       }       long long int zero = 0, lastzero = 0, one = 0, b = 0;       while (i < n) {         if (s[i] ==  0 ) {           zero++;           if (one == k) lastzero++;         } else           one++;         if (one > k) {           for (int p = 0; p < zero; p++) {             ans = (ans + dp[p][k]) % 998244353;           }           long long int temp = 0;           if (b > 0) {             for (int p = 0; p < zero - lastzero; p++) {               temp = (temp + dp[p][k - 1]) % 998244353;             }           }           lastzero = 0;           b = 1;           ans = (998244353 + ans - temp) % 998244353;           while (j < i) {             if (s[j] ==  1 ) {               one--;               j++;               break;             }             j++;             zero--;           }         }         i++;       }       if (one == k) {         for (int p = 0; p < zero; p++) {           ans = (ans + dp[p][k]) % 998244353;         }         long long int temp = 0;         if (b > 0) {           for (int p = 0; p < zero - lastzero; p++) {             temp = (temp + dp[p][k - 1]) % 998244353;           }         }         ans = (998244353 + ans - temp) % 998244353;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 987654321;   const long long int INF = 123456789987654321;   FILE *fin, *fout;   int V, edge_cnt, source, sink;   vector<int> last_edge, nxt_edge, oppo, capa;   void init() {     edge_cnt = 0, last_edge.clear(), nxt_edge.clear(), oppo.clear(), capa.clear(),     last_edge = vector<int>(V, -1);   }   void add(int u, int v, int capa_) {     nxt_edge.push_back(last_edge[u]), last_edge[u] = edge_cnt, oppo.push_back(v),                                       capa.push_back(capa_), edge_cnt++;   }   vector<int> dist;   bool bfs() {     dist.clear(), dist = vector<int>(V, -1);     queue<int> q;     q.push(source), dist[source] = 0;     while (!q.empty()) {       int now = q.front();       q.pop();       for (int i = last_edge[now]; i != -1; i = nxt_edge[i]) {         int nxt = oppo[i];         if (capa[i] && dist[nxt] == -1) {           dist[nxt] = dist[now] + 1;           q.push(nxt);         }       }     }     if (dist[sink] == -1)       return false;     else       return true;   }   vector<int> last_edge2;   int dfs(int now, int flow) {     if (now == sink) return flow;     for (int i = last_edge2[now]; i != -1; i = nxt_edge[i]) {       last_edge2[now] = i;       int nxt = oppo[i];       if (capa[i] && dist[nxt] == dist[now] + 1) {         if (int tmp = dfs(nxt, min(flow, capa[i]))) {           capa[i] -= tmp;           capa[i ^ 1] += tmp;           return tmp;         }       }     }     return 0;   }   int dinic() {     int total_flow = 0;     while (bfs()) {       last_edge2 = last_edge;       while (int tmp = dfs(source, inf)) total_flow += tmp;     }     return total_flow;   }   int N, M;   struct Func {     int a, b, c;   };   vector<Func> F;   vector<pair<int, int> > interval;   struct Restr {     int u, v, d;   };   vector<Restr> restr;   int f(int idx, int x) { return F[idx].a * x * x + F[idx].b * x + F[idx].c; }   const int too_big = 10000000;   void get_network() {     V = 220 * N + 2, source = V - 2, sink = V - 1;     init();     for (int i = 0; i < N; i++) {       int l = interval[i].first, r = interval[i].second;       add(source, 220 * i + (l - 1 + 110), inf);       add(220 * i + (l - 1 + 110), source, 0);       for (int j = 0; j < 219; j++) {         add(220 * i + j, 220 * i + j + 1, too_big - f(i, j + 1 - 110));         add(220 * i + j + 1, 220 * i + j, 0);       }       add(220 * i + (r + 110), sink, inf);       add(sink, 220 * i + (r + 110), 0);     }     for (int i = 0; i < M; i++) {       int u = restr[i].u, v = restr[i].v;       for (int j = 0; j < 220; j++) {         if (j - restr[i].d >= 0 && j - restr[i].d < 220) {           add(220 * u + j, 220 * v + j - restr[i].d, inf);           add(220 * v + j - restr[i].d, 220 * u + j, 0);         }       }     }     printf( %d , too_big * N - dinic());   }   int main() {     scanf( %d %d , &N, &M);     F.resize(N);     for (int i = 0; i < N; i++) {       int a, b, c;       scanf( %d %d %d , &a, &b, &c);       F[i] = {a, b, c};     }     interval.resize(N);     for (int i = 0; i < N; i++) {       scanf( %d %d , &interval[i].first, &interval[i].second);     }     restr.resize(M);     for (int i = 0; i < M; i++) {       int u, v, d;       scanf( %d %d %d , &u, &v, &d);       restr[i] = {--u, --v, d};     }     get_network();   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adjl[4009];   set<pair<int, int> > st;   int main() {     int n, m, a, b;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> a >> b;       adjl[a].push_back(b);       adjl[b].push_back(a);       st.insert(pair<int, int>(a, b));       st.insert(pair<int, int>(b, a));     }     int ans = 9999999;     for (int i = 1; i <= n; i++) {       if (adjl[i].size() >= 2) {         for (int j = 0; j < adjl[i].size(); j++) {           for (int k = j + 1; k < adjl[i].size(); k++) {             if (st.find(pair<int, int>(adjl[i][j], adjl[i][k])) != st.end()) {               if (ans > adjl[i].size() + adjl[adjl[i][j]].size() +                             adjl[adjl[i][k]].size() - 6)                 ans = adjl[i].size() + adjl[adjl[i][j]].size() +                       adjl[adjl[i][k]].size() - 6;             }           }         }       }     }     if (ans == 9999999)       cout << -1 << endl;     else       cout << ans << endl;   }


#include <bits/stdc++.h>   const int Maxn = 50005;   int N, A[Maxn];   double L[Maxn], P[Maxn], Sum[Maxn], Ans;   using namespace std;   bool Cmp(const int &i, const int &j) {     return (L[i] * P[i] * (1 - P[j] / 100)) > (L[j] * P[j] * (1 - P[i] / 100));   }   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; ++i) {       scanf( %lf%lf , &L[i], &P[i]);       A[i] = i;     }     sort(A + 1, A + 1 + N, Cmp);     for (int i = 1; i <= N; ++i) Sum[i] = Sum[i - 1] + L[A[i]] * P[A[i]];     for (int i = 1; i <= N; ++i) Ans += L[i] * 10000;     for (int i = 2; i <= N; ++i) Ans += (100 - P[A[i]]) * Sum[i - 1];     cout << setprecision(12) << setiosflags(ios ::fixed) << Ans / 10000 << endl;     return 0;   }