#include <bits/stdc++.h>   using namespace std;   int N;   bool indegree[200010];   int a[200010];   bool visited[200010];   vector<pair<int, int> > ans;   int main() {     int i, j, k;     scanf( %d , &N);     for (i = (0); i < (N); i++) scanf( %d , a + i);     for (i = (0); i < (N); i++) a[i]--;     memset((visited), 0, sizeof(visited));     ;     memset((indegree), 0, sizeof(indegree));     ;     for (i = (0); i < (N); i++) indegree[a[i]] = true;     bool f = false;     for (i = (0); i < (N); i++) {       if (indegree[i]) continue;       f = true;       int x = i;       while (!visited[x]) {         visited[x] = true;         indegree[x] = true;         x = a[x];       }       ans.push_back(make_pair(i, x));     }     for (i = (0); i < (N); i++) {       if (visited[i]) continue;       int x = i;       while (!visited[x]) {         visited[x] = true;         x = a[x];       }       ans.push_back(make_pair(i, i));     }     if (!f && ans.size() < 2) {       printf( 0 n );       return 0;     }     ans.push_back(ans[0]);     printf( %d n , ans.size() - 1);     for (i = (0); i < (ans.size() - 1); i++)       printf( %d %d n , ans[i].second + 1, ans[i + 1].first + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string base, s;     cin >> base >> s;     int n = base.size(), m = s.size();     base =  *  + base;     s =  *  + s;     int f[m + 2][n + 2];     memset(f, 0, sizeof(f));     for (int i = m; i >= 1; i--)       for (int j = n; j >= 1; j--)         if (s[i] == base[j]) f[i][j] = f[i + 1][j + 1] + 1;     int g[m + 2][n + 2];     memset(g, 0, sizeof(g));     for (int i = m; i >= 1; i--)       for (int j = 1; j <= n; j++)         if (s[i] == base[j]) g[i][j] = g[i + 1][j - 1] + 1;     vector<pair<int, int>> ans;     for (int i = 1; i <= m;) {       int l1 = max_element(f[i] + 1, f[i] + n + 1) - f[i];       int l2 = max_element(g[i] + 1, g[i] + n + 1) - g[i];       if (!f[i][l1] && !g[i][l2]) {         cout << -1;         return 0;       }       if (f[i][l1] >= g[i][l2])         ans.push_back({l1, l1 + f[i][l1] - 1});       else         ans.push_back({l2, l2 - g[i][l2] + 1});       i += max(f[i][l1], g[i][l2]);     }     cout << ans.size() <<   n ;     for (auto p : ans) cout << p.first <<     << p.second <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, q;     scanf( %lld %lld , &n, &q);     while (q--) {       long long x;       scanf( %lld , &x);       while (x % 2 == 0) {         x += (n - x / 2);       }       printf( %lld n , x / 2 + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, x;     while (cin >> n >> k) {       long long sum = 0;       x = n * (k - 1) / k - 10;       if (x <= 0) {         x = 1;       }       long long c = x;       sum = x;       while (sum < n) {         c /= k;         sum += c;         if (sum >= n) {           break;         }         if (c / k == 0 && sum < n) {           x++;           c = x;           sum = c;         }       }       cout << x << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005, inf = 1e9 + 7;   int fa[maxn];   long long n, m, dp[maxn];   int sz[maxn], costs[maxn];   vector<int> fas;   bool vis[maxn];   int findfa(int x) {     if (fa[x] == x)       return x;     else       return fa[x] = findfa(fa[x]);   }   void bag(int wei, int val) {     for (int i = n; i >= wei; i--) {       dp[i] = min(dp[i], dp[i - wei] + val);     }   }   bool check(int xx) {     while (xx) {       if ((xx % 10) != 4 && (xx % 10) != 7) {         return 0;       }       if (xx < 10) break;       xx /= 10;     }     return 1;   }   int main() {     memset(dp, 1e9 + 7, sizeof(dp));     cin >> n >> m;     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       fa[findfa(x)] = findfa(y);     }     for (int i = 1; i <= n; i++) {       sz[findfa(i)]++;     }     for (int i = 1; i <= n; i++) {       costs[sz[i]]++;     }     dp[0] = 0;     for (int i = 1; i <= n; i++) {       if (costs[i]) {         for (int j = 1; j <= costs[i]; j <<= 1) {           bag(j * i, j);           costs[i] -= j;         }         bag(costs[i] * i, costs[i]);       }     }     long long ans = 1e9 + 7;     for (int i = 1; i <= n; i++) {       if (check(i)) ans = min(ans, dp[i]);     }     if (ans == 1e9 + 7)       cout <<  -1  << endl;     else       cout << ans - 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6 + 10;   const int INF = 1e9 + 7;   int prime[MAX];   int main() {     int x2;     scanf( %d , &x2);     for (int i = 2; i <= x2; i++) {       if (!prime[i]) {         for (int j = i * 2; j <= x2; j += i) prime[j] = i;       }     }     int ans = INF;     for (int i = x2 - prime[x2] + 1; i <= x2; i++) {       if (prime[i] == 0) continue;       ans = min(ans, i - prime[i] + 1);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> A(n);     vector<int> B(n, 1);     for (int i = 0; i < n; i++) {       cin >> A[i];     }     int max1 = B[0];     for (int i = 1; i < n; i++) {       if (A[i] >= A[i - 1]) {         B[i] = B[i - 1] + 1;       }       max1 = max(max1, B[i]);     }     cout << max1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000100], b[5010];   string second[10];   int main() {     int n, sm = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a + 1, a + n);     for (;;) {       if (a[0] <= a[n - 1]) {         a[n - 1]--;         a[0]++;         sm++;       }       sort(a + 1, a + n);       if (a[0] > a[n - 1]) {         cout << sm;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename tp>   inline void read(tp &x) {     x = 0;     char c = getchar();     int f = 0;     for (; c <  0  || c >  9 ; f |= c ==  - , c = getchar())       ;     for (; c >=  0  && c <=  9 ; x = (x << 3) + (x << 1) + c -  0 , c = getchar())       ;     if (f) x = -x;   }   namespace {   const int mo = 1e9 + 7;   inline int add(int x, int y) {     x += y;     return x >= mo ? x - mo : x;   }   inline int sub(int x, int y) {     x -= y;     return x < 0 ? x + mo : x;   }   inline int mul(int x, int y) { return (long long)x * y % mo; }   inline int power(int a, int k = mo - 2) {     int ans = 1;     for (; k; k >>= 1, a = mul(a, a))       if (k & 1) ans = mul(ans, a);     return ans;   }   inline void U(int &x, int y) { x = add(x, y); }   }  // namespace   const int N = 1e5 + 233;   int n, m, coefa, coefb, P, T;   int fac[N], ifac[N], p[N], sump[N];   inline int C(int n, int m) {     return n < m ? 0 : mul(fac[n], mul(ifac[m], ifac[n - m]));   }   int main(void) {     read(n);     read(m);     read(coefa);     read(coefb);     P = mul(coefa, power(coefb));     fac[0] = 1;     for (register int i = 1; i <= (N - 1); i++) fac[i] = mul(fac[i - 1], i);     for (register int i = 0; i < (int)N; i++) ifac[i] = power(fac[i]);     read(T);     for (register int i = 0; i < (int)m + 1; i++) {       if (i <= T)         p[i + 1] = mul(C(T, i), mul(power(P, i), power(1 + mo - P, T - i)));     }     for (register int i = 0; i < (int)m + 1; i++)       sump[i] = add(i ? sump[i - 1] : 0, p[i]);     vector<int> h(m + 2, 0);     h[m] = 1;     for (register int i = 1; i <= (n); i++) {       vector<int> new_h(m + 2, 0);       vector<int> f(m + 2, 0), g(m + 2, 0);       for (int r = 1; r <= m; r++) {         f[r] = add(f[r - 1], h[r]);         g[r] = add(g[r - 1], mul(f[r - 1], p[r]));       }       for (int r = 1; r <= m; r++) {         int rr = m - r + 1;         new_h[r] = sub(mul(sump[r], mul(p[rr], f[m])),                        add(mul(p[rr], g[r]), mul(mul(p[rr], f[m - r]), sump[r])));       }       swap(h, new_h);     }     int ans = 0;     for (auto i : h) U(ans, i);     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int color[10010], c[10010], d[10010], f[10010], N, t, x;   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       scanf( %d , color + i);       if (!f[color[i]]) f[color[i]] = i;     }     int m, col;     for (int i = 1; i <= N; i++) {       m = 1;       col = color[i];       d[col]++;       for (int j = 1; j <= N; j++) {         c[j] = 0;       }       c[color[i]]++;       for (int j = i + 1; j <= N; j++) {         c[color[j]]++;         if ((c[color[j]] > m) || (c[color[j]] == m && color[j] < col)) {           m = c[color[j]];           col = color[j];         }         d[col]++;       }     }     for (int i = 1; i < N; i++) printf( %d  , d[i]);     printf( %d n , d[N]);   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 2e5 + 10, inf = 4e18, mod = 1e9 + 7;   const long double pi = 3.14159265359, eps = 1e-9;   long long n, m;   vector<long long> g[maxn], jj[3];   long long mk[maxn];   bool dfs(long long v, long long p = -1, long long dep = 1) {     mk[v] = dep;     vector<long long> be, sn;     for (auto u : g[v]) {       if (mk[u] != 0 && mk[u] < mk[v]) {         if (u != p) be.push_back(u);         continue;       }       if (mk[u] == 0 && dfs(u, v, dep + 1)) sn.push_back(u);     }     while (be.size() > 1) {       jj[0].push_back(be.back());       be.pop_back();       jj[1].push_back(v);       jj[2].push_back(be.back());       be.pop_back();     }     while (sn.size() > 1) {       jj[0].push_back(sn.back());       sn.pop_back();       jj[1].push_back(v);       jj[2].push_back(sn.back());       sn.pop_back();     }     long long add = 0;     if (be.size()) {       if (sn.size()) {         jj[0].push_back(sn.back());         sn.pop_back();         jj[1].push_back(v);         jj[2].push_back(be.back());         be.pop_back();         return 1;       }       add = be.back();     } else if (sn.size()) {       add = sn.back();     }     if (!add) return 1;     if (p != -1) {       jj[0].push_back(add);       jj[1].push_back(v);       jj[2].push_back(p);     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     long long v, u;     while (m--) {       cin >> v >> u;       g[v].push_back(u);       g[u].push_back(v);     }     for (int i = 1; i <= n; i++) {       if (!mk[i]) dfs(i);     }     cout << jj[0].size() << endl;     for (int i = 0; i < jj[0].size(); i++) {       cout << jj[0][i] <<     << jj[1][i] <<     << jj[2][i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> s[222222], ss[222222];   int n, m, cnt, cnt2, h;   int up[222222][22], fa[222222], deep[211111], q[211111], dfn[211111],       low[211111];   void tarjan(int x) {     int c, i, y;     dfn[x] = low[x] = ++cnt;     q[h] = x;     h++;     c = s[x].size();     for (i = 0; i < c; i++) {       y = s[x][i];       if (dfn[y] == 0) {         tarjan(y);         low[x] = min(low[x], low[y]);         if (low[y] >= dfn[x]) {           cnt2++;           while (h > 0) {             h--;             ss[cnt2].push_back(q[h]);             ss[q[h]].push_back(cnt2);             if (q[h] == y) break;           }           ss[cnt2].push_back(x);           ss[x].push_back(cnt2);         }       } else         low[x] = min(low[x], dfn[y]);     }   }   void make_yfs() {     int i;     cnt = 0, h = 0, cnt2 = n;     tarjan(1);   }   void dfs(int x) {     int c, i, y;     c = ss[x].size();     for (i = 0; i < c; i++) {       y = ss[x][i];       if (fa[x] == y) continue;       fa[y] = up[y][0] = x;       deep[y] = deep[x] + 1;       dfs(y);     }   }   int lca(int x, int y) {     int tmp = 20;     if (deep[x] < deep[y]) swap(x, y);     while (1) {       if ((1 << tmp) <= deep[x] - deep[y]) x = up[x][tmp];       tmp--;       if (tmp < 0) break;     }     if (x == y) return x;     tmp = 20;     while (1) {       if (up[x][tmp] != up[y][tmp]) x = up[x][tmp], y = up[y][tmp];       tmp--;       if (tmp < 0) break;     }     return fa[x];   }   int getdis(int x, int y) {     int L;     L = lca(x, y);     return deep[x] - deep[L] + deep[y] - deep[L];   }   int main() {     int i, m, x, y, q, ans;     scanf( %d%d%d , &n, &m, &q);     for (i = 1; i <= m; i++) {       scanf( %d%d , &x, &y);       s[x].push_back(y);       s[y].push_back(x);     }     make_yfs();     dfs(1);     for (int j = 1; j <= 20; j++)       for (i = 1; i <= cnt2; i++) up[i][j] = up[up[i][j - 1]][j - 1];     while (q--) {       scanf( %d%d , &x, &y);       ans = getdis(x, y) / 2;       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, x;       cin >> n >> x;       int arr[n + 5], brr[n + 5];       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       for (int i = 0; i < n; i++) {         cin >> brr[i];       }       sort(arr, arr + n);       sort(brr, brr + n, greater<int>());       int f = 1;       for (int i = 0; i < n; i++) {         if (arr[i] + brr[i] > x) {           f = 0;           break;         }       }       if (f == 1) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }       if (t != 0) {         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> st;   long long n, q;   vector<int> swp(20, false);   vector<long long> arr;   void build(long long ind, long long l, long long r) {     if (l == r) {       st[ind] = arr[l];       return;     }     long long mid = (l + r) >> 1;     build(2 * ind, l, mid);     build(2 * ind + 1, mid + 1, r);     st[ind] = st[2 * ind] + st[2 * ind + 1];   }   void update(long long ind, long long l, long long r, long long req,               long long level) {     if (req < l || req > r) return;     if (l == r) {       st[ind] = arr[req];       return;     }     long long mid = (l + r) >> 1;     if (swp[level - 1]) {       update(2 * ind + 1, l, mid, req, level - 1);       update(2 * ind, mid + 1, r, req, level - 1);     } else {       update(2 * ind, l, mid, req, level - 1);       update(2 * ind + 1, mid + 1, r, req, level - 1);     }     st[ind] = st[2 * ind + 1] + st[2 * ind];   }   long long query(long long ind, long long l, long long r, long long ql,                   long long qr, long long level) {     if (l > qr || r < ql) return 0;     if (ql <= l && r <= qr) return st[ind];     long long mid = (l + r) / 2;     if (swp[level - 1])       return query(2 * ind + 1, l, mid, ql, qr, level - 1) +              query(2 * ind, mid + 1, r, ql, qr, level - 1);     else       return query(2 * ind, l, mid, ql, qr, level - 1) +              query(2 * ind + 1, mid + 1, r, ql, qr, level - 1);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> q;     long long len = 1 << n;     arr.resize(len);     st.assign(4 * len, 0);     for (long long i = 0; i < len; i++) cin >> arr[i];     build(1, 0, len - 1);     while (q--) {       long long type;       cin >> type;       if (type == 1) {         long long ind, val;         cin >> ind >> val;         ind--;         arr[ind] = val;         update(1, 0, len - 1, ind, n);       } else if (type == 2) {         long long k;         cin >> k;         for (long long i = 0; i < k; i++) swp[i] ^= true;       } else if (type == 3) {         long long k;         cin >> k;         swp[k] ^= true;       } else {         long long l, r;         cin >> l >> r;         l--;         r--;         cout << query(1, 0, len - 1, l, r, n) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   inline long long read() {     long long x = 0, f = 1;     char c = getchar();     for (; c >  9  || c <  0 ; c = getchar()) {       if (c ==  - ) f = -1;     }     for (; c >=  0  && c <=  9 ; c = getchar()) {       x = x * 10 + c -  0 ;     }     return x * f;   }   int a[100005];   std::vector<int> vec[200005];   inline long long q_pow(long long x, int t) {     long long s = 1;     for (; t; t >>= 1) {       if (t & 1) s *= x;       x *= x;     }     return s;   }   inline void divide(int x) {     for (int i = 2; i * i <= x; i++) {       if (x % i != 0) {         vec[i].emplace_back(0);         continue;       }       int cnt = 0;       for (; x % i == 0; x /= i) cnt++;       vec[i].emplace_back(cnt);     }     if (x != 1) vec[x].emplace_back(1);   }   inline void work() {     int n = read();     long long ans = 1;     for (int i = 1; i <= n; i++) {       a[i] = read();       divide(a[i]);     }     for (int i = 1; i <= 200000; i++) {       std::sort(vec[i].begin(), vec[i].end());       if (vec[i].size() < n - 2)         continue;       else if (vec[i].size() == n - 1 && !vec[i].empty())         ans *= q_pow(i, vec[i][0]);       else if (vec[i].size() == n && vec[i].size() >= 2)         ans *= q_pow(i, vec[i][1]);       else if (vec[i].size() == n && !vec[i].empty())         ans *= i;     }     printf( %lld n , ans);   }   int main() {     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 100005;   const int mod = 1e9 + 9;   const int pp = 31;   const int ppp = 56;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int i, j, k, n;     string s, t;     cin >> s >> t >> k;     n = s.length();     vector<int> a(n), p(n);     for (i = 0; i < n; ++i) {       a[i] = t[s[i] -  a ] -  0 ;     }     p[0] = a[0];     for (i = 1; i < n; i++) p[i] = p[i - 1] + a[i];     set<pair<long long, long long>> sz;     vector<long long> p_pow(n + 1), pp_pow(n + 1);     p_pow[0] = 1;     pp_pow[0] = 1;     for (i = 1; i <= n; i++) {       p_pow[i] = (p_pow[i - 1] * pp) % mod;       pp_pow[i] = (pp_pow[i - 1] * ppp) % mod;     }     vector<long long> hsh(n + 1, 0), hshh(n + 1, 0);     for (i = 0; i < n; i++) {       hsh[i + 1] = (hsh[i] + p_pow[i] * (s[i] -  a  + 1)) % mod;       hshh[i + 1] = (hshh[i] + pp_pow[i] * (s[i] -  a  + 1)) % mod;     }     for (i = 1; i <= n; i++) {       for (j = 0; j < n - i + 1; ++j) {         long long cur_h_1 = (hsh[j + i] + mod - hsh[j]) % mod;         long long cur_h_2 = (hshh[j + i] + mod - hshh[j]) % mod;         if (j > 0 && (i - p[j + i - 1] + p[j - 1]) <= k)           sz.insert({cur_h_1 * p_pow[n - j - 1] % mod,                      cur_h_2 * pp_pow[n - j - 1] % mod});         else if (j == 0 && (i - p[j + i - 1]) <= k) {           sz.insert({cur_h_1 * p_pow[n - j - 1] % mod,                      cur_h_2 * pp_pow[n - j - 1] % mod});         }       }     }     cout << sz.size();   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)(1e5) + 123;   const int INF = (int)(1e9);   int n, a[maxn], t[4 * maxn], tt;   pair<int, int> b[maxn];   int gcd(int a, int b) {     while (a > 0 && b > 0) {       if (a > b)         a %= b;       else         b %= a;     }     return a + b;   }   void build(int v, int tl, int tr) {     if (tl == tr)       t[v] = a[tl];     else {       int tm = (tl + tr) / 2;       build(v + v, tl, tm);       build(v + 1 + v, tm + 1, tr);       t[v] = gcd(t[v + v], t[v + 1 + v]);     }   }   int get(int v, int tl, int tr, int l, int r) {     if (l > tr || r < tl) return 0;     if (l <= tl && r >= tr) return t[v];     int tm = (tl + tr) / 2;     return gcd(get(v + v, tl, tm, l, r), get(v + 1 + v, tm + 1, tr, l, r));   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       b[i] = make_pair(a[i], i);     }     sort(b + 1, b + 1 + n);     build(1, 1, n);     cin >> tt;     for (int i = 1; i <= tt; ++i) {       int l, r;       cin >> l >> r;       int cur = get(1, 1, n, l, r);       pair<int, int> now = make_pair(cur, l);       int to = (lower_bound(b + 1, b + 1 + n, now) - (b + 1));       now = make_pair(cur, r + 1);       int from = (lower_bound(b + 1, b + 1 + n, now) - (b + 1));       cout << (r - l + 1) - (from - to) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long f = 1, x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   const int maxn = 5e5 + 5;   char st1[maxn], st2[maxn];   long long ans = 0, pre = 0;   int n, k;   int main() {     n = read(), k = read();     scanf( %s , st1);     scanf( %s , st2);     for (int i = 0; i <= n - 1; i++) {       pre = min(pre * 2 + (int)(st2[i] - st1[i]), 1ll << 36);       ans += min(pre + 1, (long long)k);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double eps = 1e-6;   const int maxn = 3e5 + 10;   const int maxm = 1e6 + 10;   const long long mod = 998244353;   int a[maxn], b[maxn];   bool judge(int mid, int h) {     int temph = h;     for (int i = 0; i < mid; i++) b[i] = a[i];     sort(b, b + mid);     int ans = 0;     for (int i = 0; i < mid; i += 2) {       if (b[i] <= h) ans++;       if (i + 1 < mid && b[i + 1] <= h) ans++;       if (i == mid - 1)         h -= b[i];       else         h -= b[i + 1];       if (h <= 0) break;     }     if (ans >= mid) return true;     ans = 0, h = temph;     for (int i = mid - 1; i >= 0; i -= 2) {       if (b[i] <= h) ans++;       if (i - 1 >= 0 && b[i - 1] <= h) ans++;       h -= b[i];       if (h <= 0) break;     }     return ans >= mid;   }   int main() {     int n, h;     cin >> n >> h;     for (int i = 0; i < n; i++) cin >> a[i];     int ans = 1;     int l = 1, r = n;     while (l <= r) {       int mid = (l + r) >> 1;       if (judge(mid, h))         l = mid + 1, ans = mid;       else         r = mid - 1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p_arr[200005];   int main() {     int n, in, cnt, x, arr[200005];     std::cin >> n;     queue<int> q;     for (int i = 1; i <= n; i++) {       std::cin >> in;       q.push(in);     }     for (int i = 1; i <= n; i++) {       std::cin >> arr[i];     }     cnt = 0;     for (int i = 1; i <= n; i++) {       x = q.front();       while (p_arr[x] == -1) {         q.pop();         x = q.front();       }       x = q.front();       if (x == arr[i]) {         q.pop();       } else {         cnt++;         p_arr[arr[i]] = -1;       }     }     std::cout << cnt <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char g[21][21];   int n, m, id[21][21], cv, cb, var[(1 << 8)],       dr[] = {1, 0, -1, 0}, dc[] = {0, 1, 0, -1}, d[21][21][(1 << 8)];   bool inq[21][21][(1 << 8)];   struct node {     int r, c, msk;   };   queue<node> q;   vector<node> b;   void input() {     scanf( %d%d , &n, &m);     for (int i = 0; i < (n); i++) scanf( %s , g[i]);     memset(id, -1, sizeof(id));     for (int i = 0; i < (n); i++)       for (int j = 0; j < (m); j++)         if (isdigit(g[i][j])) id[i][j] = g[i][j] -  1 , cv++;     for (int i = 0; i < (n); i++)       for (int j = 0; j < (m); j++)         if (g[i][j] ==  B ) id[i][j] = cv + (cb++);     for (int i = 0; i < (n); i++)       for (int j = 0; j < (m); j++) {         if (g[i][j] ==  B ) b.push_back((node){i, j, (1 << id[i][j] >> cv)});         if (isdigit(g[i][j])) b.push_back((node){i, j, (1 << id[i][j] << cb)});       }     for (int i = 0; i < (cv); i++) scanf( %d , &var[1 << i]);   }   int lowbit(int x) { return x & (-x); }   void pretreat() {     for (int i = 0; i < ((1 << 8)); i++)       if (i) var[i] = var[i - lowbit(i)] + var[lowbit(i)];   }   bool invalid(node cur) {     if (cur.r < 0 || cur.r >= n || cur.c < 0 || cur.c >= m) return true;     if (id[cur.r][cur.c] != -1) return true;     if (g[cur.r][cur.c] ==  # ) return true;     return false;   }   void updata(node nxt, int x) {     if (d[nxt.r][nxt.c][nxt.msk] == -1 || d[nxt.r][nxt.c][nxt.msk] > x) {       d[nxt.r][nxt.c][nxt.msk] = x;       if (!inq[nxt.r][nxt.c][nxt.msk]) {         inq[nxt.r][nxt.c][nxt.msk] = 1;         q.push(nxt);       }     }   }   int bfs() {     memset(d, -1, sizeof(d));     memset(inq, 0, sizeof(inq));     node cur, nxt;     int ans = 0;     for (int i = 0; i < (n); i++)       for (int j = 0; j < (m); j++)         if (g[i][j] ==  S ) {           q.push((node){i, j, 0});           d[i][j][0] = 0;           inq[i][j][0] = 1;           break;         }     while (!q.empty()) {       cur = q.front();       q.pop();       inq[cur.r][cur.c][cur.msk] = 0;       if (g[cur.r][cur.c] ==  S  && ((cur.msk & ((1 << cb) - 1)) == 0))         ans = max(ans, var[cur.msk >> cb] - d[cur.r][cur.c][cur.msk]);       for (int i = 0; i < (4); i++) {         nxt.r = cur.r + dr[i];         nxt.c = cur.c + dc[i];         if (invalid(nxt)) continue;         if (i & 1) {           nxt.msk = cur.msk;           for (int j = 0; j < ((int)b.size()); j++) {             if (i == 1) {               if (b[j].r > nxt.r && b[j].c == nxt.c) nxt.msk ^= b[j].msk;             } else {               if (b[j].r > cur.r && b[j].c == cur.c) nxt.msk ^= b[j].msk;             }           }         } else           nxt.msk = cur.msk;         updata(nxt, d[cur.r][cur.c][cur.msk] + 1);       }     }     return ans;   }   int main() {     input();     pretreat();     printf( %d n , bfs());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     ;     vector<int> v(n);     for (int i = 0; i < n; i++) scanf( %d , &v[i]);     ;     int diff = 0;     int ans = v[0];     for (int i = 0; i < n - 1; i++) {       diff += (v[i] - v[i + 1]);       if (diff < 0) {         ans = ans + abs(diff);         diff = 0;       }     }     cout << ans << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int n, a[100005], mi, mid, ma;   long long m, sum;   bool b[100005], flag;   bool check() {     long long sum = 0;     for (int i = 0; i < n; i++) sum += min(a[i], mid);     return sum <= m;   }   int main() {     cin >> n >> m;     sum = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       sum += a[i];     }     if (sum < m) {       printf( -1 n );     } else if (sum == m) {       printf(  n );     } else {       mi = 0;       ma = 1000000000;       while (mi < ma) {         mid = (mi + ma + 1) >> 1;         if (check())           mi = mid;         else           ma = mid - 1;       }       for (int i = 0; i < n; i++) {         m -= min(a[i], mi);         a[i] -= min(a[i], mi);       }       memset(b, true, sizeof(b));       flag = false;       for (int i = 0; b[i]; i = (i + 1) % n) {         if (a[i]) {           if (m) {             a[i]--;             m--;           } else {             if (flag) printf(   );             flag = true;             b[i] = false;             printf( %d , i + 1);           }         }       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2000005;   int lp[N + 1];   vector<int> pr, adj[100005];   vector<int> v[N];   int a[N], ans[100005], depth[100005];   void seive() {     for (int i = 2; i <= N; ++i) {       if (lp[i] == 0) {         lp[i] = i;         pr.push_back(i);       }       for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j)         lp[i * pr[j]] = pr[j];     }   }   void dfs(int s, int p) {     int x = a[s];     while (x > 1) {       int te = lp[x];       while (x % te == 0) x /= te;       int sz = v[te].size();       if (sz > 0) {         ;         if (ans[s] == -1 || depth[ans[s]] < depth[v[te][sz - 1]])           ans[s] = v[te][sz - 1];       }       v[te].push_back(s);     }     for (auto it : adj[s]) {       if (it != p) {         depth[it] = depth[s] + 1;         dfs(it, s);       }     }     x = a[s];     while (x > 1) {       int te = lp[x];       while (x % te == 0) x /= te;       v[te].pop_back();     }   }   int main() {     int n, q, i;     seive();     scanf( %d%d , &n, &q);     memset(ans, -1, sizeof(ans));     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i < n - 1; i++) {       int a, b;       scanf( %d%d , &a, &b);       adj[a - 1].push_back(b - 1);       adj[b - 1].push_back(a - 1);     }     dfs(0, -1);     while (q--) {       int type, v;       scanf( %d%d , &type, &v);       if (type == 1) {         if (ans[v - 1] == -1) ans[v - 1] = -2;         printf( %d n , ans[v - 1] + 1);       } else {         int w;         scanf( %d , &w);         a[v - 1] = w;         memset(ans, -1, sizeof(ans));         dfs(0, -1);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e5 + 5;   const long long MOD = 1e9 + 7;   const long long INF = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, x, y;     cin >> n >> x >> y;     set<double> s;     int count = 0;     while (n--) {       double m;       double a, b;       cin >> a >> b;       a -= x;       b -= y;       if (a != 0) {         m = b / a;         s.insert(m);       } else {         count++;       }     }     cout << (count > 0) + s.size() << endl;   }


#include <bits/stdc++.h>   using namespace std;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   const int nmax = 2e5 + 5;   int t, n, a[nmax], b[nmax], f[nmax], L[nmax], R[nmax], d[nmax];   long long ans;   vector<int> v1[nmax], v2[nmax];   int main() {     srand(time(NULL));     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       ans = 0;       cin >> n;       for (int i = 1; i <= n; i++) {         v1[i].clear();         v2[i].clear();         f[i] = 0;         d[i] = 0;       }       R[n + 1] = 0;       for (int i = 1; i <= n; i++) {         cin >> a[i] >> b[i];         f[b[i]]++;         v1[a[i]].emplace_back(b[i]);         v2[b[i]].emplace_back(a[i]);       }       for (int i = 1; i <= n; i++) L[i] = L[i - 1] + v2[i].size();       for (int i = n; i >= 1; i--) R[i] = R[i + 1] + v2[i].size();       for (int i = 2; i < n; i++)         ans = ans + 1ll * v2[i].size() * L[i - 1] * R[i + 1];       for (int i = 1; i <= n; i++) L[i] = L[i - 1] + v1[i].size();       for (int i = n; i >= 1; i--) R[i] = R[i + 1] + v1[i].size();       for (int i = 2; i < n; i++)         ans = ans + 1ll * v1[i].size() * L[i - 1] * R[i + 1];       for (int i = 1; i <= n; i++) sort(v1[i].begin(), v1[i].end());       for (int i = 1; i <= n; i++)         if (v1[i].size() > 0) {           int dem = 1;           for (int j = 1; j < v1[i].size(); j++)             if (v1[i][j] != v1[i][j - 1]) {               int x = v1[i][j - 1];               ans = ans - 1ll * dem * (L[i - 1] - d[x]) *                               (R[i + 1] - (f[x] - d[x] - dem));               dem = 1;             } else               dem++;           int x = v1[i][v1[i].size() - 1];           ans = ans -                 1ll * dem * (L[i - 1] - d[x]) * (R[i + 1] - (f[x] - d[x] - dem));           for (auto p : v1[i]) d[p]++;         }       for (int i = 1; i <= n; i++) d[i] = 0;       long long res = 0;       for (int i = 1; i <= n; i++)         if (v1[i].size() > 0) {           int dem = 1;           for (int j = 1; j < v1[i].size(); j++)             if (v1[i][j] != v1[i][j - 1]) {               int x = v1[i][j - 1];               res = res - 1ll * dem * d[x];               dem = 1;             } else               dem++;           int x = v1[i][v1[i].size() - 1];           res = res - 1ll * dem * d[x];           ans = ans + 1ll * v1[i].size() * res;           dem = 1;           for (int j = 1; j < v1[i].size(); j++)             if (v1[i][j] != v1[i][j - 1]) {               int x = v1[i][j - 1];               res = res + 1ll * dem * (f[x] - d[x] - dem);               dem = 1;             } else               dem++;           x = v1[i][v1[i].size() - 1];           res = res + 1ll * dem * (f[x] - d[x] - dem);           for (auto p : v1[i]) d[p]++;         }       for (int i = 1; i <= n; i++) d[i] = 0;       for (int i = 1; i <= n; i++)         if (v1[i].size() > 0) {           int dem = 1;           for (int j = 1; j < v1[i].size(); j++)             if (v1[i][j] != v1[i][j - 1]) {               int x = v1[i][j - 1];               ans = ans - 1ll * d[x] * (f[x] - d[x] - dem);               dem = 1;             } else               dem++;           int x = v1[i][v1[i].size() - 1];           ans = ans - 1ll * d[x] * (f[x] - d[x] - dem);           for (auto p : v1[i]) d[p]++;         }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int nMAX = 20;   long long comb[nMAX][nMAX];   long long mem[10][20];   int cnt[10];   long long nCr(int n, int k) {     if (n < k) return 0;     if (k == 0 || n == 0) return 1;     if (~comb[n][k]) return comb[n][k];     if (n - k < k) return comb[n][k] = nCr(n, n - k);     return comb[n][k] = nCr(n - 1, k - 1) + nCr(n - 1, k);   }   long long dp(int digit, int mad) {     if (digit == 10) return 1;     long long &ret = mem[digit][mad];     ret = 0;     if (!cnt[digit]) ret = dp(digit + 1, mad);     for (int takenSoFar = 1; takenSoFar < (int)cnt[digit] + 1; ++takenSoFar)       ret +=           nCr(digit == 9 ? takenSoFar + mad - 1 : takenSoFar + mad, takenSoFar) *           dp(digit + 1, mad + takenSoFar);     return ret;   }   string s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(mem, -1, sizeof mem);     memset(comb, -1, sizeof comb);     cin >> s;     for (int i = 0; i < (int)(int)s.size(); ++i) cnt[s[i] -  0 ]++;     reverse(cnt, cnt + 10);     cout << dp(0, 0) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int coolness[6001];   int main() {     int n;     while (scanf( %d , &n) != EOF) {       fill(coolness, coolness + 6001, 0);       for (int i = 0; i < n; i++) {         int temp;         scanf( %d , &temp);         coolness[temp]++;       }       int cost = 0;       for (int i = 1; i <= n; i++) {         for (; coolness[i] > 1; coolness[i]--) {           for (int j = i + 1;; j++) {             if (coolness[j] == 0) {               coolness[j]++;               cost += j - i;               break;             }           }         }       }       printf( %d n , cost);     }   }


#include <bits/stdc++.h>   int main() {     const int N = 3 * 3;     bool buttons[N] = {0};     int k(0);     while (k < N) {       char temp;       scanf( %c , &temp);       if (temp ==  X ) {         buttons[k++] = 1;       } else if (temp ==  . ) {         buttons[k++] = 0;       }     }     bool symmetric(1);     for (int k = 0; k < N; k++) {       if (buttons[k] != buttons[N - 1 - k]) {         symmetric = 0;         break;       }     }     if (symmetric) {       puts( YES );     } else {       puts( NO );     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int ans;     ans = n / 2 + 1;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 7;   int main() {     int n, k;     scanf( %d%d , &n, &k);     vector<int> ans;     int a = (n - k) / 2;     while (ans.size() < n) {       for (int i = 0; i < a; i++) ans.push_back(0);       ans.push_back(1);     }     for (int i = 0; i < n; i++) printf( %d , ans[i]);     puts(  );   }


#include <bits/stdc++.h>   long long mod = 1000000007;   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   void solve() {     long long n;     cin >> n;     long long odd = 0, even = 0;     string s = to_string(n);     for (int i = 0; i < s.size(); i++) {       long long d = s[i] -  0 ;       if (i % 2 == 0) {         even = (even * 10) + d;       } else {         odd = (odd * 10) + d;       }     }     long long ans = ((even + 1) * (odd + 1)) - 2;     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> a(n);     {       for (auto &e : (a)) cin >> e;     }     sort((a).begin(), (a).end());     vector<int> used(1, a[0]);     for (auto e : a) {       bool go = 0;       for (auto ee : used) {         if (e % ee == 0) {           go = 1;         }       }       if (!go) used.push_back(e);     }     cout << used.size();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, seed, vmax;   const int mod = 1e9 + 7;   int rnd() {     int rlt = seed;     seed = (1ll * seed * 7 + 13) % mod;     return rlt;   }   int expmod(int a, int b, int P) {     int rlt = 1;     while (b) {       if (b & 1) rlt = 1ll * a * rlt % P;       a = 1ll * a * a % P;       b >>= 1;     }     return rlt;   }   long long a[101010], b[101010];   int op, le, ri, x, y;   void get_query() {     op = (rnd() % 4) + 1;     le = (rnd() % n) + 1;     ri = (rnd() % n) + 1;     if (le > ri) swap(le, ri);     if (op == 3)       x = (rnd() % (ri - le + 1)) + 1;     else       x = (rnd() % vmax) + 1;     if (op == 4) y = (rnd() % vmax) + 1;   }   void put_query() {     printf( %d %d %d %d , op, le, ri, x);     if (op == 4)       printf(  %d n , y);     else       puts(  );   }   long long add[101010 << 2], to[101010 << 2];   void refresh(int id) {     if (add[id] && to[id] != -1) to[id] += add[id], add[id] = 0;   }   void push_down(int id) {     refresh(id);     if (to[id] != -1) {       to[id << 1] = to[id];       add[id << 1] = 0;       to[(id << 1) ^ 1] = to[id];       add[(id << 1) ^ 1] = 0;     } else {       add[id << 1] += add[id];       add[(id << 1) ^ 1] += add[id];       add[id] = 0;     }   }   void build(int L, int R, int id) {     if (L == R) {       to[id] = a[L];       return;     }     int mid = (L + R) >> 1;     build(L, mid, id << 1);     build(mid + 1, R, (id << 1) ^ 1);   }   void update(int le, int ri, int d, int L, int R, int id) {     if (le > R || L > ri) return;     if (le <= L && R <= ri) {       refresh(id);       if (to[id] != -1) {         to[id] += d;         return;       }       add[id] += d;       return;     }     int mid = (L + R) >> 1;     push_down(id);     to[id] = -1;     update(le, ri, d, L, mid, id << 1);     update(le, ri, d, mid + 1, R, (id << 1) ^ 1);   }   void change(int le, int ri, int d, int L, int R, int id) {     if (le > R || L > ri) return;     if (le <= L && R <= ri) {       refresh(id);       add[id] = 0;       to[id] = d;       return;     }     int mid = (L + R) >> 1;     push_down(id);     to[id] = -1;     change(le, ri, d, L, mid, id << 1);     change(le, ri, d, mid + 1, R, (id << 1) ^ 1);   }   int query(int le, int ri, int x, int y, int L, int R, int id) {     if (le > R || L > ri) return 0;     if (to[id] != -1) {       refresh(id);       int len = min(R, ri) - max(L, le) + 1;       return (int)((1ll * expmod(to[id] % y, x, y) * len) % y);     }     int mid = (L + R) >> 1;     push_down(id);     to[id] = -1;     int ans1 = query(le, ri, x, y, L, mid, id << 1);     int ans2 = query(le, ri, x, y, mid + 1, R, (id << 1) ^ 1);     return (ans1 + ans2) % y;   }   priority_queue<pair<long long, int> > pq;   void calc(int le, int ri, int L, int R, int id) {     if (le > R || L > ri) return;     if (to[id] != -1) {       refresh(id);       int len = min(R, ri) - max(L, le) + 1;       pq.push(make_pair(to[id], len));       return;     }     int mid = (L + R) >> 1;     push_down(id);     to[id] = -1;     calc(le, ri, L, mid, id << 1);     calc(le, ri, mid + 1, R, (id << 1) ^ 1);   }   int main() {     scanf( %d %d %d %d , &n, &m, &seed, &vmax);     for (int i = 1; i <= n; i++) a[i] = (rnd() % vmax) + 1;     memset(to, -1, sizeof to);     build(1, n, 1);     while (m--) {       get_query();       if (op == 1) {         update(le, ri, x, 1, n, 1);       } else if (op == 2) {         change(le, ri, x, 1, n, 1);       } else if (op == 3) {         while (!pq.empty()) pq.pop();         calc(le, ri, 1, n, 1);         int tot = 0;         x = ri - le + 1 - x;         pair<long long, int> tmp;         while (1) {           tmp = pq.top();           x -= tmp.second;           if (x < 0) {             printf( %I64d n , tmp.first);             break;           }           pq.pop();         }       } else {         int ans = 0;         ans = query(le, ri, x, y, 1, n, 1);         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double v1, v2, s1, s2, t, f, c;     double m;     int co;     while (cin >> v1 >> v2 >> t >> f >> c) {       if (v2 <= v1)         cout << 0 << endl;       else {         s1 = t * v1;         s2 = 0;         m = v2 - v1;         co = 0;         while (s1 < c) {           s1 += (s1 / m) * v1;           if (s1 >= c) break;           co++;           s1 += (s1 / v2 + f) * v1;         }         cout << co << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (1 << 30);   const long long llinf = (1ll << 60);   const double eps = (1e-10);   const int xx[8] = {1, 0, -1, 0, 1, -1, 1, -1};   const int yy[8] = {0, 1, 0, -1, -1, 1, -1, 1};   int main() {     int n;     scanf( %d , &n);     int cnt[10] = {0};     bool fl = true;     char input[4][4];     getchar();     for (int i = 0; i < 4; i++) {       for (int j = 0; j < 4; j++) {         char x;         scanf( %c , &x);         if (x ==  . ) continue;         cnt[x -  0 ]++;         if (cnt[x -  0 ] > (n * 2)) fl = false;       }       getchar();     }     if (fl)       cout <<  YES n ;     else       cout <<  NO n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const long long L = 1e9;   int n, m, p, r, par[N];   long long size[N];   vector<int> adj[N];   vector<pair<long long, int> > ans;   priority_queue<pair<long long, int> > q;   int find_par(int v) { return par[v] == v ? v : par[v] = find_par(par[v]); }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m >> p >> r;     if (!m && r == n) {       cout << (p ?  NO  :  YES ) <<   n ;       return 0;     }     for (int i = 0; i < n; i++) par[i] = i, size[i] = 0;     for (int i = 0; i < m; i++) {       int u, v, l;       cin >> u >> v >> l;       u = find_par(--u), v = find_par(--v);       if (u != v) par[u] = v, size[v] += size[u];       size[v] += l;     }     for (int i = 0; i < n; i++)       if (par[i] == i) q.push(pair<long long, int>(-size[i], i));     while (p && q.size() > r) {       p--;       pair<long long, int> a, b;       a = q.top(), q.pop();       b = q.top(), q.pop();       long long l = min(L, -a.first + -b.first + 1);       q.push(pair<long long, int>(a.first + b.first - l, a.second));       ans.push_back(pair<long long, int>(a.second + 1, b.second + 1));       par[b.second] = a.second;     }     if (q.size() != r)       cout <<  NO n ;     else {       cout <<  YES n ;       for (int i = 0; i < ans.size(); i++)         cout << ans[i].first <<     << ans[i].second <<   n ;       for (int v = 0; v < n; v++)         if (par[v] != v) {           while (p--) cout << v + 1 <<     << par[v] + 1 <<   n ;           break;         }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   long long i, j;   long long const size = 1e5;   long long power(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;   }   long long modd(string num, long long a) {     int res = 0;     for (int i = 0; i < num.length(); i++)       res = (res * 10 + (int)num[i] -  0 ) % a;     return res;   }   int check_xor(int n) {     if ((n % 4) == 0)       return n;     else if ((n % 4) == 1)       return 1;     else if ((n % 4) == 2)       return n + 1;     else       return 0;   }   vector<long long> sieve(long long n) {     vector<bool> prime(n + 1, true);     prime[0] = false;     prime[1] = false;     long long range = sqrt(n);     for (i = 2; i <= range; i++) {       if (prime[i]) {         for (j = i * 2; j <= n; j = j + i) {           prime[j] = false;         }       }     }     vector<long long> ans;     for (i = 0; i < n; i++) {       if (prime[i]) ans.push_back(i);     }     return ans;   }   bool iszero(long long n) { return n == 0; }   vector<long long> sieve_range(long long s, long long e) {     vector<long long> v1 = sieve(s);     vector<long long> v2 = sieve(e);     vector<long long> ans(e - s);     set_difference(v2.begin(), v2.end(), v1.begin(), v1.end(), ans.begin());     auto it = remove_if(ans.begin(), ans.end(), iszero);     ans.resize(it - ans.begin());     return ans;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     ;     long long t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       if (n * 2 <= m)         cout << n <<     << 2 * n <<   n ;       else         cout << -1 <<     << -1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000000 + 10;   const int MAXM = 600000 + 10;   int a[64][64];   int ans, n, m;   inline int sg(int x) { return 1 - 2 * x; }   inline int sg(int s, int x) { return sg(s >> x & 1); }   int main() {     ios::sync_with_stdio(false);     cin >> n;     m = n >> 1;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) cin >> a[i][j];     int ans = 0;     for (int s = 0; s < (1 << m + 1); s++) {       int ret = a[m][m] * sg(s, m);       for (int j = 0; j < m; j++)         ret +=             a[m][j] * sg(s, j) + a[m][j + m + 1] * sg(s >> j & 1 ^ (s >> m & 1));       for (int i = 0; i < m; i++) {         int tmp1 = a[i][m] + a[i + m + 1][m] * sg(s, m);         int tmp2 = -tmp1;         for (int j = 0; j < m; j++)           tmp1 += abs(a[i][j] + a[i + m + 1][j] * sg(s, j) + a[i][j + m + 1] +                       a[i + m + 1][j + m + 1] * sg(s >> j & 1 ^ (s >> m & 1)));         for (int j = 0; j < m; j++)           tmp2 +=               abs(a[i][j] + a[i + m + 1][j] * sg(s, j) - a[i][j + m + 1] +                   a[i + m + 1][j + m + 1] * sg(s >> j & 1 ^ (s >> m & 1) ^ 1));         ret += max(tmp1, tmp2);       }       ans = max(ans, ret);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, ans = 0;     cin >> n;     long long int ar[n];     for (int i = 0; i < n; i++) {       cin >> ar[i];     }     sort(ar, ar + n);     long long int s = 0;     for (int i = 0; i < n; i++) {       if (s <= ar[i]) {         s += ar[i];         ans++;       }     }     cout << ans;   }   int main() {     int t = 1;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   int arr[1000];   int main() {     int count, i, j, n;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , &arr[i]);     count = 0;     i = 0;     while (i < n) {       j = i;       while ((j < n) && (arr[j] == 1)) j++;       if (j > i) count += j - i + 1;       i = j + 1;     }     if (count > 0)       printf( %d n , count - 1);     else       printf( 0 n );     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   vector<long long> g[100000 + 10];   map<pair<long long, long long>, long long> mp;   map<long long, pair<long long, long long> > road;   long long cnt[100000 + 10];   long long ans = 0;   int visited[100000 + 10];   int L[100000 + 100];   long long n;   void dfs(long long u) {     visited[u] = 1;     long long l = g[u].size();     cnt[u] = 1;     for (int i = 0; i < l; i++) {       long long v = g[u][i];       if (visited[v] == 0) {         L[v] = L[u] + 1;         visited[v] = 1;         dfs(v);         cnt[u] += cnt[v];         ans += mp[make_pair(u, v)] * cnt[v] * (n - cnt[v]);       }     }   }   int main() {     scanf( %lld , &(n));     for (int i = 1; i < n; i++) {       long long u, v, w;       scanf( %lld , &(u));       scanf( %lld , &(v));       scanf( %lld , &(w));       g[u].push_back(v);       g[v].push_back(u);       mp[make_pair(u, v)] = w;       mp[make_pair(v, u)] = w;       road[i] = make_pair(u, v);     }     L[1] = 1;     dfs(1);     int q;     scanf( %d , &(q));     while (q--) {       long long r;       long long w;       scanf( %lld , &(r));       scanf( %lld , &(w));       pair<long long, long long> x;       x = road[r];       if (L[x.first] > L[x.second]) {         long long tmp = x.first;         x.first = x.second;         x.second = tmp;       }       ans += (cnt[x.second]) * (n - cnt[x.second]) * (w - mp[x]);       mp[x] = w;       mp[make_pair(x.second, x.first)] = w;       double num = ans * 6.0 / (n * (n - 1));       printf( %.10f n , num);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double inf = 1e9;   const double eps = 1e-7;   int main() {     int n, width, height, begin0, begin1;     cin >> n >> width >> height >> begin0 >> begin1;     vector<pair<int, pair<double, double>>> a(n + 1);     a[0] = make_pair(0, make_pair(1, begin1 - begin0));     for (int i = 1; i <= n; ++i) {       int x, y;       cin >> a[i].first >> x >> y;       a[i].second = make_pair(1 - (double)height / y, (double)x * height / y);     }     auto check = [&](double v) {       double l = begin0, r = begin0;       for (int i = 1; i <= n; ++i) {         double delta = v * (a[i].first - a[i - 1].first);         double k0 = a[i - 1].second.first, b0 = a[i - 1].second.second;         double k1 = a[i].second.first, b1 = a[i].second.second;         double k = k0 / k1, tl, tr;         if (k1 > 0) {           tl = (b0 - delta - b1) / k1;           tr = (b0 + delta - b1) / k1;         } else {           tl = (b0 + delta - b1) / k1;           tr = (b0 - delta - b1) / k1;         }         if (fabs(k0 - k1) < eps) {           tl = max(tl, -delta);           tr = min(tr, delta);           if (tl > tr + eps) {             return false;           }           l += tl;           r += tr;         } else {           double ml = (tl + delta) / (1 - k), mr = (tr - delta) / (1 - k);           double nl = inf, nr = -inf;           if (k > 1) {             {               double left = max(l, mr), right = min(r, ml);               if (right >= left - eps) {                 nl = min(nl, left - delta);                 nr = max(nr, right + delta);               }             }             {               double left = max(l, max(ml, mr)), right = r;               if (right >= left - eps) {                 right = min(right, (delta - tl) / (k - 1));                 if (right >= left - eps) {                   nl = min(nl, k * left + tl);                   nr = max(nr, right + delta);                 }               }             }             {               double left = l, right = min(r, min(ml, mr));               if (right >= left - eps) {                 left = max(left, -(delta + tr) / (k - 1));                 if (right >= left - eps) {                   nl = min(nl, left - delta);                   nr = max(nr, k * right + tr);                 }               }             }             {               double left = max(l, ml), right = min(r, mr);               if (right >= left - eps) {                 nl = min(nl, k * left + tl);                 nr = max(nr, k * right + tr);               }             }           } else {             {               double left = max(l, ml), right = min(r, mr);               if (right >= left - eps) {                 if (k > 0) {                   nl = min(nl, k * left + tl);                   nr = max(nr, k * right + tr);                 } else {                   nl = min(nl, k * right + tl);                   nr = max(nr, k * left + tr);                 }               }             }             {               double left = l, right = min(r, min(ml, mr));               if (right >= left - eps) {                 left = max(left, (tl - delta) / (1 - k));                 if (right >= left - eps) {                   if (k > 0) {                     nl = min(nl, k * left + tl);                   } else {                     nl = min(nl, k * right + tl);                   }                   nr = max(nr, right + delta);                 }               }             }             {               double left = max(l, max(ml, mr)), right = r;               if (right >= left - eps) {                 right = min(right, (tr + delta) / (1 - k));                 if (right >= left - eps) {                   nl = min(nl, left - delta);                   if (k > 0) {                     nr = max(nr, k * right + tr);                   } else {                     nr = max(nr, k * left + tr);                   }                 }               }             }             {               double left = max(l, mr), right = min(r, ml);               if (right >= left - eps) {                 nl = min(nl, left - delta);                 nr = max(nr, right + delta);               }             }           }           if (nl > nr + eps) {             return false;           }           l = nl;           r = nr;         }         l = max(l, (double)0);         r = min(r, (double)width);         if (k1 > 0) {           l = max(l, -b1 / k1);           r = min(r, (width - b1) / k1);         } else {           l = max(l, (width - b1) / k1);           r = min(r, -b1 / k1);         }         if (l > r + eps) {           return false;         }       }       return true;     };     if (!check(width + 1)) {       cout << -1 << endl;     } else {       double l = 0, r = width;       for (int t = 0; t < 50; ++t) {         double m = (l + r) / 2;         if (check(m)) {           r = m;         } else {           l = m;         }       }       cout << fixed << setprecision(6) << r << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int num;     long long x;   } tmp;   bool cmp(node a, node b) { return a.x > b.x; }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int t;     vector<node> v;     cin >> t;     while (t--) {       v.clear();       long long n, w;       long long x;       cin >> n >> w;       for (int i = 1; i <= n; i++) {         cin >> x;         if (x > w)           continue;         else {           tmp.x = x;           tmp.num = i;           v.push_back(tmp);         }       }       if (v.empty()) {         cout <<  -1 n ;         continue;       }       sort(v.begin(), v.end(), cmp);       int flag = 0;       for (int i = 0; i < v.size(); i++) {         if (v[i].x >= w / 2 + w % 2) {           cout <<  1 n ;           cout << v[i].num <<   n ;           flag = 1;           break;         }       }       if (flag == 0) {         long long ssum = 0;         int k;         for (k = v.size() - 1; k >= 0; k--) {           ssum += v[k].x;           if (ssum >= w / 2 + w % 2) break;         }         if (k >= 0) {           cout << v.size() - k <<   n ;           for (int i = v.size() - 1; i >= k; i--) {             cout << v[i].num <<    ;           }           cout <<   n ;         } else           cout <<  -1 n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     bool neg = false;     for (int i = 1; i <= n / 4 && !neg; i++) {       for (int k = 0; k <= n - 1 - 4 * i; k++)         if (s[k] ==  *  && s[k + i] ==  *  && s[k + 2 * i] ==  *  &&             s[k + 3 * i] ==  *  && s[k + 4 * i] ==  * )           neg = true;     }     if (neg)       cout <<  yes ;     else       cout <<  no ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF =       sizeof(long long) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;   const long long MOD = (long long)(1e9) + 7;   const double PI = acos(-1);   const double EPS = 1e-9;   using pii = pair<long long, long long>;   template <typename T, typename S>   istream &operator>>(istream &is, pair<T, S> &p) {     is >> p.first >> p.second;     return is;   }   template <typename T, typename S>   ostream &operator<<(ostream &os, pair<T, S> &p) {     os << p.first <<     << p.second;     return os;   }   template <typename T>   void printvv(const vector<vector<T>> &v) {     cerr << endl;     for (long long i = (0); i < (v.size()); i++)       for (long long j = (0); j < (v[i].size()); j++) {         if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {           cerr <<  INF ;         } else           cerr << v[i][j];         cerr << (j == v[i].size() - 1 ?   n  :    );       }     cerr << endl;   }   void YES(bool f) { cout << (f ?  YES  :  NO ) << endl; }   void Yes(bool f) { cout << (f ?  Yes  :  No ) << endl; }   template <class T>   bool chmax(T &a, const T &b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <class T>   bool chmin(T &a, const T &b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <long long MOD>   struct ModInt {     static const long long Mod = MOD;     unsigned x;     ModInt() : x(0) {}     ModInt(signed sig) {       long long sigt = sig % MOD;       if (sigt < 0) sigt += MOD;       x = sigt;     }     ModInt(signed long long sig) {       long long sigt = sig % MOD;       if (sigt < 0) sigt += MOD;       x = sigt;     }     long long get() const { return (long long)x; }     ModInt &operator+=(ModInt that) {       if ((x += that.x) >= MOD) x -= MOD;       return *this;     }     ModInt &operator-=(ModInt that) {       if ((x += MOD - that.x) >= MOD) x -= MOD;       return *this;     }     ModInt &operator*=(ModInt that) {       x = (unsigned long long)x * that.x % MOD;       return *this;     }     ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }     ModInt operator+(ModInt that) const { return ModInt(*this) += that; }     ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }     ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }     ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }     ModInt inverse() const {       signed a = x, b = MOD, u = 1, v = 0;       while (b) {         signed t = a / b;         a -= t * b;         std::swap(a, b);         u -= t * v;         std::swap(u, v);       }       if (u < 0) u += MOD;       ModInt res;       res.x = (unsigned)u;       return res;     }   };   template <long long MOD>   ostream &operator<<(ostream &os, const ModInt<MOD> &m) {     return os << m.x;   }   template <long long MOD>   istream &operator>>(istream &is, ModInt<MOD> &m) {     signed long long s;     is >> s;     m = ModInt<MOD>(s);     return is;   };   template <long long MOD>   ModInt<MOD> pow(ModInt<MOD> a, unsigned long long k) {     ModInt<MOD> r = 1;     while (k) {       if (k & 1) r *= a;       a *= a;       k >>= 1;     }     return r;   }   using mint = ModInt<1000000007>;   vector<mint> fact, factinv;   void nCr_compute_factinv(long long N) {     N = min(N, mint::Mod - 1);     fact.resize(N + 1);     factinv.resize(N + 1);     fact[0] = 1;     for (long long i = (1); i < (N + 1); i++) fact[i] = fact[i - 1] * i;     factinv[N] = fact[N].inverse();     for (long long i = N; i >= 1; i--) factinv[i - 1] = factinv[i] * i;   }   mint nCr(long long n, long long r) {     if (n >= mint::Mod)       return nCr(n % mint::Mod, r % mint::Mod) *              nCr(n / mint::Mod, r / mint::Mod);     return r > n ? 0 : fact[n] * factinv[n - r] * factinv[r];   }   mint nHr(long long n, long long r) { return r == 0 ? 1 : nCr(n + r - 1, r); }   mint f(long long x, long long y) {     if (x != y)       return mint(y) * pow(mint(x), x - y - 1);     else       return mint(1);   }   signed main(signed argc, char *argv[]) {     long long N, M;     cin >> N >> M;     long long a, b;     cin >> a >> b;     nCr_compute_factinv(N + M + 10);     mint ans;     for (long long i = (0); i < (N - 1); i++) {       if (N - 2 - i >= 0 and i <= M - 1) {         ;         ;         ans += fact[N - 2] / fact[N - 2 - i] * nCr(M - 1, i) *                pow(mint(M), N - 1 - i - 1) * f(N, i + 2);         ;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 2e3 + 20;   const long long int mod = 998244353;   long long int dp[5050][5050];   bool mark[N * N + 10];   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     for (int i = 0; i <= 5000; ++i)       for (int j = 0; j <= 5000; j++) {         if (!i || !j)           dp[i][j] = 1;         else           dp[i][j] = (dp[i - 1][j] + j * dp[i - 1][j - 1]) % mod;       }     long long int a, b, c;     cin >> a >> b >> c;     return cout << (((dp[a][b] * dp[a][c]) % mod) * dp[b][c]) % mod, 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   int n, T, A[N], ch[N][26], son[N], fa[N], sz[N], m, tail[N], tg[N], ans[N],       dfn[N], idx, top[N];   int MN[N], out[N];   struct smt {     int t[N << 2], tag[N << 2];     void build(int l, int r, int p) {       if (l == r) {         t[p] = 0x3f3f3f3f;         return;       }       int mid = l + r >> 1;       build(l, mid, p << 1);       build(mid + 1, r, p << 1 | 1);       t[p] = min(t[p << 1], t[p << 1 | 1]);     }     inline void pushdown(int p) {       if (tag[p]) {         tag[p << 1] += tag[p];         tag[p << 1 | 1] += tag[p];         t[p << 1] += tag[p];         t[p << 1 | 1] += tag[p];         tag[p] = 0;       }     }     void modify(int l, int r, int o, const int& pos, const int& val) {       if (l == r)         t[o] = min(t[o], val);       else {         const int mid = l + r >> 1;         pushdown(o);         if (pos <= mid)           modify(l, mid, o << 1, pos, val);         else           modify(mid + 1, r, o << 1 | 1, pos, val);         t[o] = min(t[o << 1], t[o << 1 | 1]);       }     }     void change(int l, int r, int a, int b, int p, int v) {       if (a <= l && r <= b) {         tag[p] += v, t[p] += v;         return;       }       pushdown(p);       int mid = l + r >> 1;       if (a <= mid) change(l, mid, a, b, p << 1, v);       if (b > mid) change(mid + 1, r, a, b, p << 1 | 1, v);       t[p] = min(t[p << 1], t[p << 1 | 1]);     }     int query(int l, int r, int o, const int& L, const int& R) {       if (L <= l && r <= R) return t[o];       pushdown(o);       const int mid = l + r >> 1;       if (L <= mid && mid < R)         return min(query(l, mid, o << 1, L, R),                    query(mid + 1, r, o << 1 | 1, L, R));       if (L <= mid) return query(l, mid, o << 1, L, R);       return query(mid + 1, r, o << 1 | 1, L, R);     }     inline void out(int l, int r, int o) {       if (l == r)         cout << t[o] <<    ;       else {         pushdown(o);         const int mid = l + r >> 1;         out(l, mid, o << 1), out(mid + 1, r, o << 1 | 1);       }     }   } sgt;   void dfs(int now) {     sz[now] = 1;     for (int i = 0; i < 26; ++i)       if (int to = ch[now][i]) {         dfs(to);         sz[now] += sz[to];         if (!son[now] || sz[son[now]] < sz[to]) son[now] = to;       }   }   void dfs2(int now) {     dfn[now] = idx++;     if (son[now]) top[son[now]] = top[now], dfs2(son[now]);     for (int i = 0; i < 26; ++i) {       int to = ch[now][i];       if (to && to != son[now]) dfs2(top[to] = to);     }   }   void add(int x) {     while (top[x] != top[0])       sgt.change(0, n, dfn[top[x]], dfn[x], 1, 1), x = fa[top[x]];     sgt.change(0, n, 0, dfn[x], 1, 1);   }   int query(int x) {     int ret = 0x3f3f3f3f;     while (top[x] != top[0])       ret = min(ret, sgt.query(0, n, 1, dfn[top[x]], dfn[x])), x = fa[top[x]];     ret = min(ret, sgt.query(0, n, 1, 0, dfn[x]));     return ret;   }   void DFS(int now) {     sgt.modify(0, n, 1, dfn[now], MN[now] + !!tg[now]);     for (int i = 0; i < 26; ++i)       if (int to = ch[now][i]) {         MN[to] = min(MN[to], MN[now] + 1);         if (tg[to]) {           add(to);           MN[to] = min(MN[to], query(to));         }         DFS(to);       }   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       int pre;       char s[12];       cin >> pre >> s;       fa[i] = pre;       ch[pre][*s -  a ] = i;     }     cin >> m;     for (int i = 1; i <= m; ++i) {       int x;       cin >> x;       tg[x] = i;     }     dfs(0), dfs2(0);     sgt.build(0, n, 1);     memset(MN, 0x3f, sizeof MN);     MN[0] = 0;     DFS(0);     for (int i = 0; i <= n; ++i)       if (tg[i]) out[tg[i]] = MN[i];     for (int i = 1; i <= m; ++i) cout << out[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     vector<int> h(n), res(n);     for (int i = 0; i < (int)(n); i++) {       scanf( %d , &h[i]);     }     int bad = 0;     int ans = 0;     for (int i = 0; i < (int)(n); i++) {       bad = min(bad, h[i] - i - 1);       res[i] = i + 1 + bad;     }     bad = n + 1;     for (int i = (int)(n)-1; i >= 0; i--) {       bad = min(bad, h[i] + i + 1);       res[i] = min(res[i], bad - i - 1);       ans = max(ans, res[i]);     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > arr[111];   int vis[111], maxs;   void dfs(int now, int wei) {     if (vis[now]) return;     vis[now] = 1;     maxs = max(maxs, wei);     for (int e = 0; e < arr[now].size(); e++) {       int next = arr[now][e].first, n_wei = wei + arr[now][e].second;       if (vis[next]) continue;       dfs(next, n_wei);     }   }   int main(void) {     int n;     cin >> n;     for (int e = 0; e < n - 1; e++) {       int a, b, c;       cin >> a >> b >> c;       arr[a].push_back(make_pair(b, c));       arr[b].push_back(make_pair(a, c));     }     dfs(0, 0);     cout << maxs;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const long long N = 1 << 20 | 1, M = 998244353;   long long a[N], Ans[N], n, m, x, cnt[N], b[N], Q, wn[N], rev[N], w[N];   inline long long ksm(long long x, long long y) {     long long ans = 1;     for (; y; y >>= 1, x = x * x % M)       if (y & 1) ans = ans * x % M;     return ans;   }   inline void init(long long len) {     for (long long i = 1; i < len; i++)       rev[i] = rev[i >> 1] >> 1 | ((i & 1) * len / 2);   }   inline void reduce(long long &x) { x += x >> 31 & M; }   inline void ntt(long long y[], long long len, long long opt) {     for (long long i = 1; i < len; i++)       if (rev[i] > i) swap(y[i], y[rev[i]]);     for (long long h = 1; h < len; h <<= 1)       for (long long j = 0; j < len; j += h + h)         for (long long k = 0; k < h; ++k) {           const long long x = y[h + j + k] * w[h + k] % M;           reduce(y[h + j + k] = y[j + k] - x);           reduce(y[j + k] += x - M);         }     if (opt == -1) {       long long temp = ksm(len, M - 2);       for (long long i = 0; i < len; i++) y[i] = y[i] * temp % M;       reverse(y + 1, y + len);     }   }   inline void solve(long long l, long long r, long long a[]) {     if (l > r) {       a[0] = 1;       return;     }     if (l == r) {       a[0] = 1;       if (cnt[l] > 0) a[1] = 2;       if (cnt[l] > 1) a[2] = 1;       return;     }     long long len = 1;     while (len <= b[r] - b[l - 1]) len <<= 1;     long long mid = (l + r) / 2, b[len], c[len];     memset(b, 0, sizeof b);     memset(c, 0, sizeof c);     solve(l, mid, b);     solve(mid + 1, r, c);     init(len);     ntt(b, len, 1);     ntt(c, len, 1);     for (long long i = 0; i < len; i++) a[i] = b[i] * c[i] % M;     ntt(a, len, -1);   }   inline long long read() {     long long x = 0;     char c = 0;     for (; c <  0  || c >  9 ; c = getchar())       ;     for (; c >=  0  && c <=  9 ; c = getchar()) x = x * 10 + c - 48;     return x;   }   signed main() {     n = read();     m = read();     for (long long i = 1; i <= n; i++) cnt[read()]++;     ;     for (long long i = 1; i <= 300000; i++) b[i] = b[i - 1] + min(cnt[i], 2ll);     long long len = 1;     while (len <= 300000) len <<= 1;     for (long long mid = 1; mid < len; mid <<= 1) {       const long long wn = ksm(3, M / mid / 2);       w[mid] = 1;       for (long long i = 1; i < mid; ++i) w[i + mid] = w[i + mid - 1] * wn % M;     }     while (m--) {       scanf( %lld , &x);       memset(a, 0, sizeof a);       solve(1, x - 1, a);       for (long long i = 0; i <= 300000; i++) (Ans[i + x + 1] += a[i]) %= M;     }     Q = read();     while (Q--) {       x = read();       printf( %lld n , Ans[x / 2]);     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, hd[100010], x, y, cnt, sta[600010], tp, d[100010], la;   struct node {     int to, next, la, fro;   } e[600010];   void addedge(int x, int y) {     e[++cnt] = (node){y, hd[x], 0, x}, e[hd[x]].la = cnt, hd[x] = cnt;     e[++cnt] = (node){x, hd[y], 0, y}, e[hd[y]].la = cnt, hd[y] = cnt;     d[x]++, d[y]++;   }   int rev(int i) { return (i & 1) ? (i + 1) : (i - 1); }   void del(int x, int i) {     if (hd[x] == i)       hd[x] = e[i].next, e[hd[x]].la = 0;     else       e[e[i].next].la = e[i].la, e[e[i].la].next = e[i].next;   }   void work(int x) {     for (int i = hd[x]; i; i = hd[x]) {       del(x, i), del(e[i].to, rev(i));       work(e[i].to), sta[++tp] = i;     }   }   int main() {     scanf( %d%d , &n, &m), cnt = 0, memset(hd, 0, sizeof(hd)), la = 0;     for (int i = 1; i <= m; i++) scanf( %d%d , &x, &y), addedge(x, y);     for (int x = 1; x <= n; x++)       if (d[x] & 1) {         if (!la)           la = x;         else           addedge(la, x), la = 0;       }     for (int x = 1; x <= n; x++)       if ((d[x] >> 1) & 1) {         if (!la)           la = x;         else           la = 0;       }     if (la) addedge(la, la);     work(1), la = 0, printf( %d n , tp);     for (int i = tp; i; i--) {       if ((d[e[sta[i]].fro] >> 1) & 1) {         if (la)           d[la] += 2, d[e[sta[i]].fro] += 2, la = 0;         else           la = e[sta[i]].fro;       }       if (la)         printf( %d %d n , e[sta[i]].to, e[sta[i]].fro);       else         printf( %d %d n , e[sta[i]].fro, e[sta[i]].to);     }     return 0;   }


#include <bits/stdc++.h>   namespace FastIO {   bool IOerror = 0;   inline char nc() {     static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;     if (p1 == pend) {       p1 = buf;       pend = buf + fread(buf, 1, 100000, stdin);       if (pend == p1) {         IOerror = 1;         return -1;       }     }     return *p1++;   }   inline bool blank(char ch) {     return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ;   }   template <class T>   inline bool read(T& x) {     bool sign = 0;     char ch = nc();     x = 0;     for (; blank(ch); ch = nc())       ;     if (IOerror) return false;     if (ch ==  - ) sign = 1, ch = nc();     for (; ch >=  0  && ch <=  9 ; ch = nc()) x = x * 10 + ch -  0 ;     if (sign) x = -x;     return true;   }   template <class T, class... U>   bool read(T& h, U&... t) {     return read(h) && read(t...);   }   };  // namespace FastIO   using namespace std;   using namespace FastIO;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int INF = 0x3f3f3f3f;   const int mod = 998244353;   const int N = 2e5 + 10;   long long fac[N], invfac[N];   long long qpow(long long x, int n) {     long long res = 1;     while (n) {       if (n & 1) res = res * x % mod;       x = x * x % mod;       n /= 2;     }     return res;   }   void init() {     fac[0] = invfac[0] = 1;     for (int i = 1; i < N; i++) {       fac[i] = fac[i - 1] * i % mod;       invfac[i] = qpow(fac[i], mod - 2);     }   }   long long comb(int n, int m) {     if (m > n) return 0;     return fac[n] * invfac[m] % mod * invfac[n - m] % mod;   }   int main() {     long long n, k;     read(n, k);     long long ans = 0;     if (k < n) {       init();       k = n - k;       for (int i = 0; i <= k; i++)         ans = (ans + (i % 2 ? -1 : 1) * comb(k, i) * qpow(k - i, n) + mod) % mod;       if (n != k) ans = 2 * ans * comb(n, k) % mod;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int y, next, id;   };   const int maxn = 100010, maxk = 20;   int n, m, num, head[maxn], depth[maxn], f[maxn][maxk], pre[maxn], ans[maxn],       s[maxn];   edge e[maxn << 1];   inline void add(int a, int b, int id) {     num++;     e[num].next = head[a];     head[a] = num;     e[num].y = b;     e[num].id = id;   }   void dfs(int k, int deep) {     depth[k] = deep;     for (int temp = head[k]; temp >= 0; temp = e[temp].next) {       int j = e[temp].y;       if (j != f[k][0]) {         pre[j] = e[temp].id;         f[j][0] = k;         int i = 0;         for (int i = 0; f[f[j][i]][i] > 0; i++) f[j][i + 1] = f[f[j][i]][i];         dfs(j, deep + 1);       }     }   }   inline int LCA(int a, int b) {     if (depth[a] < depth[b]) swap(a, b);     for (int i = 17; depth[a] > depth[b]; i--)       if (f[a][i] > 0 && depth[f[a][i]] >= depth[b]) a = f[a][i];     if (a == b) return a;     for (int i = 17; f[a][0] != f[b][0]; i--)       if (f[a][i] > 0 && f[a][i] != f[b][i]) {         a = f[a][i];         b = f[b][i];       }     return f[a][0];   }   void slove(int k) {     for (int temp = head[k]; temp >= 0; temp = e[temp].next) {       int j = e[temp].y;       if (j != f[k][0]) {         slove(j);         s[k] += s[j];       }     }     if (k > 1) ans[pre[k]] = s[k];   }   int main() {     scanf( %d , &n);     memset(head, -1, sizeof(head));     num = -1;     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       add(a, b, i);       add(b, a, i);     }     memset(f, -1, sizeof(f));     dfs(1, 0);     scanf( %d , &m);     memset(ans, 0, sizeof(ans));     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       int lca = LCA(a, b);       s[a]++;       s[b]++;       s[lca] -= 2;     }     slove(1);     for (int i = 1; i < n; i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, ans, du[2010], d[2010], mx, sz, dp[2010];   int num, k, now, a[2010], dfn[2010], low[2010], st[2010], b[2010];   bool in[2010];   int cnt, head[2010], to[200010], nxt[200010];   vector<int> v[2010];   void add(int x, int y) {     cnt++;     to[cnt] = y;     nxt[cnt] = head[x];     head[x] = cnt;   }   void tarjan(int x, int fa) {     now++;     dfn[x] = low[x] = now;     st[k] = x;     k++;     in[x] = true;     for (int i = head[x]; i; i = nxt[i]) {       int y = to[i];       if (y == fa) {         continue;       }       if (!dfn[y]) {         tarjan(y, x);         low[x] = min(low[x], low[y]);       } else if (in[y]) {         low[x] = min(low[x], dfn[y]);       }     }     if (low[x] == dfn[x]) {       num++;       int y;       do {         y = st[k - 1];         a[y] = num;         in[y] = false;         k--;       } while (k > 0 && y != x);     }   }   void dfs(int x) {     dfn[x] = true;     for (int i = 0; i < v[x].size(); i++) {       int y = v[x][i];       if (dfn[y]) {         continue;       }       dfs(y);       if (du[y] > 1) {         mx = max(mx, dp[x] + dp[y] + 1);         dp[x] = max(dp[x], dp[y]);       }     }     if (du[x] <= 1) {       return;     }     sz++;     dp[x]++;     mx = max(mx, dp[x]);   }   void work(int x) {     if (du[x] > 1) {       dfs(x);       return;     }     for (int i = 0; i < v[x].size(); i++) {       int y = v[x][i];       if (du[y] > 1) {         dfs(y);         return;       }     }     dfs(x);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       add(x, y);       add(y, x);     }     for (int i = 1; i <= n; i++) {       if (!dfn[i]) {         tarjan(i, 0);       }     }     for (int i = 1; i <= n; i++) {       for (int j = head[i]; j; j = nxt[j]) {         int y = to[j];         if (a[i] != a[y]) {           v[a[i]].push_back(a[y]);           du[a[i]]++;         }       }     }     ans = n - num;     memset(dfn, 0, sizeof(dfn));     for (int i = 1; i <= num; i++) {       if (!dfn[i]) {         ans++;         mx = sz = 0;         work(i);         ans += sz - mx;       }     }     ans--;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T sqr(T x) {     return x * x;   }   const double EPS = 1e-6;   const int INF = 0x3fffffff;   const long long LINF = INF * 1ll * INF;   const double PI = acos(-1.0);   using namespace std;   struct PointSet {     char val;     int num;   } ps[1000005];   char s[1000005];   int len;   void unionPoint() {     int cnt = 0;     for (int i = 1; i <= len; i++) {       if (ps[i].num > 0) {         if (ps[i].val == ps[cnt].val)           ps[cnt].num += ps[i].num;         else           ps[++cnt] = ps[i];       }     }     len = cnt;   }   int main() {     scanf( %s , s + 1);     len = strlen(s + 1);     ps[0] = { # , 0};     for (int i = 1; i <= len; i++) {       ps[i].val = s[i];       ps[i].num = 1;     }     unionPoint();     int ans = 0;     while (len > 1) {       ans++;       for (int i = 1; i <= len; i++) {         if (i == 1 || i == len)           ps[i].num--;         else           ps[i].num -= 2;       }       unionPoint();     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, l, r;   vector<long long> A[200001];   set<pair<int, int> > se;   void add(long long y) {     for (auto b : A[y]) se.insert({b, y});   }   void del(long long y) {     for (auto b : A[y]) se.erase({b, y});   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m >> l >> r;     for (long long i = 1; i <= 200000; ++i)       for (long long j = i; j <= 200000; j += i)         if (j <= 200000) A[j].push_back(i);     long long L = m + 1;     long long R = m;     for (long long x = 1; x <= n; ++x) {       long long L_ = (l + x - 1) / x;       long long R_ = min(m, r / x);       if (L_ > R_) goto L1;       while (L > L_) add(--L);       while (R > R_) del(R--);       for (long long a : A[x]) {         auto it = se.upper_bound({a + 1, 0});         if (it != se.end()) {           long long b = it->first;           long long y = it->second;           if (x * b <= n * a) {             cout << x <<     << y <<     << x * b / a <<     << y * a / b;             goto L2;           }         } else           goto L1;       }     L1:       cout << -1;     L2:       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct jdb {     int x, y;     friend long long operator^(const jdb &a, const jdb &b) {       return 1ll * a.x * b.y - 1ll * a.y * b.x;     }     friend long long operator*(const jdb &a, const jdb &b) {       return 1ll * a.x * b.x + 1ll * a.y * b.y;     }     friend bool operator<(const jdb &a, const jdb &b) {       return (a.x != b.x ? a.x < b.x : a.y < b.y);     }     friend jdb operator-(const jdb &a, const jdb &b) {       return (jdb){a.x - b.x, a.y - b.y};     }   } p[300005], st[300005];   struct que {     int x, y;     long long ans;     que() { ans = -(1ll << 62); };   } q[300005];   vector<jdb> vec[300005 * 4];   int L[300005], pos[300005];   bool fl[300005], isq[300005];   int n, m, tot, top, cnt;   void insert(int k, int l, int r, int x, int y, int v) {     if (l == x && r == y) {       vec[k].push_back(p[v]);       return;     }     int mid = (l + r) / 2;     if (y <= mid)       insert(k * 2, l, mid, x, y, v);     else if (x > mid)       insert(k * 2 + 1, mid + 1, r, x, y, v);     else       insert(k * 2, l, mid, x, mid, v),           insert(k * 2 + 1, mid + 1, r, mid + 1, y, v);   }   void query(int i) {     if (!top) return;     jdb tmp = (jdb){q[i].x, q[i].y};     int l = 1, r = top;     while (r - l >= 3) {       int m1 = l + (r - l) / 3;       int m2 = r - (r - l) / 3;       if (tmp * st[m1] > tmp * st[m2])         r = m2;       else         l = m1;     }     for (int j = l; j <= r; j++) q[i].ans = max(q[i].ans, tmp * st[j]);   }   void solve(int k, int l, int r) {     long long mid = (l + r) / 2;     if (l < r) {       solve(k * 2, l, mid);       solve(k * 2 + 1, mid + 1, r);     }     top = 0;     sort(vec[k].begin(), vec[k].end());     for (int i = 0; i < vec[k].size(); i++) {       for (; top > 1 && ((vec[k][i] - st[top]) ^ (st[top] - st[top - 1])) <= 0;            top--)         ;       st[++top] = vec[k][i];     }     for (int i = l; i <= r; i++)       if (isq[i]) query(i);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int tp, x, y;       scanf( %d , &tp);       if (tp == 1) {         scanf( %d%d , &x, &y);         p[++tot] = (jdb){x, y};         L[tot] = i;         pos[i] = tot;         cnt++;       }       if (tp == 2) {         scanf( %d , &x);         x = pos[x];         insert(1, 1, n, L[x], i, x);         L[x] = 0;         cnt--;       }       if (tp == 3) {         scanf( %d , &q[i].x);         q[i].y = 1;         isq[i] = 1;         if (!cnt) {           fl[i] = 1;           q[i].x = q[i].y = isq[i] = 0;         }       }     }     for (int i = 1; i <= tot; i++)       if (L[i]) insert(1, 1, n, L[i], n, i);     solve(1, 1, n);     for (int i = 1; i <= n; i++) {       if (fl[i]) puts( EMPTY SET );       if (isq[i]) printf( %I64d n , q[i].ans);     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   using min_pq = priority_queue<T, vector<T>, greater<T>>;   template <typename T>   using max_pq = priority_queue<T>;   const int inf = 2e9 + 5;   const long long l_inf = 2e18 + 5;   const int mod_v = 1e9 + 7;   const int max_n = 1e5 + 5;   const int dx[4] = {-1, 0, 1, 0};   const int dy[4] = {0, 1, 0, -1};   template <typename T>   T gcd(T a, T b) {     while (b) {       T temp = a % b;       a = b;       b = temp;     }     return a;   }   template <typename T>   tuple<T, T, T> egcd(T a, T b) {     T x1 = 1, x2 = 0, y1 = 0, y2 = 1;     while (b) {       T q = a / b, r = a % b;       T new_x = x1 - q * x2, new_y = y1 - q * y2;       x1 = x2, y1 = y2, x2 = new_x, y2 = new_y;       a = b, b = r;     }     return make_tuple(a, x1, y1);   }   inline long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   template <typename T>   inline T mod(T a, T b = mod_v) {     return (a % b + b) % b;   }   template <typename T>   inline T mod_inv(T a, T b = mod_v) {     return mod(get<1>(egcd(a, b)), b);   }   template <typename T>   inline T sum(T a, T b, T m = mod_v) {     return mod(mod(a, m) + mod(b, m), m);   }   template <typename T>   inline T difference(T a, T b, T m = mod_v) {     return mod(mod(a, m) - mod(b, m), m);   }   inline long long product(long long a, long long b, long long m = mod_v) {     return mod(mod(a, m) * mod(b, m), m);   }   inline long long quotient(long long a, long long b, long long m = mod_v) {     return mod(mod(a, m) * mod_inv(b, m), m);   }   template <typename T, typename T2>   ostream &operator<<(ostream &s, const pair<T, T2> &p) {     return s << p.first <<     << p.second <<    ;   }   template <typename T, typename T2>   istream &operator>>(istream &s, pair<T, T2> &p) {     return s >> p.first >> p.second;   }   template <typename T>   ostream &operator<<(ostream &s, const vector<T> &v) {     for (auto it : v) s << it <<    ;     return s;   }   template <typename T>   istream &operator>>(istream &s, vector<T> &v) {     for (auto it = (v).begin(), it_ = (v).end(); it != it_; ++it) s >> *it;     return s;   }   template <typename T>   void read_range(T beg, T end) {     while (beg != end) cin >> *beg++;   }   template <typename T>   void print_range(T beg, T end) {     while (beg != end) cout << *beg++ <<    ;   }   struct reader {     template <typename T>     reader &operator,(T &v) {       cin >> v;       return *this;     }   } rdr;   struct debugger {     template <typename T>     debugger &operator,(const T &v) {       cerr << v <<  ,  ;       return *this;     }   } dbg;   int cnt[300];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     rdr, n;     ;     string s;     rdr, s;     ;     if (n > 26) {       cout << -1;       return 0;     }     int ans = 0;     for (char ch : s) {       if (cnt[ch] != 0) ++ans;       ++cnt[ch];     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     int x, y, a, b;     cin >> x >> y >> a >> b;     int t = gcd(a, b);     a /= t;     b /= t;     x /= a;     y /= b;     cout << a * min(x, y) <<     << b * min(x, y);     cin >> a;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long inf = 1e18;   double eps = 1e-8;   double pi = acos(-1);   ifstream in( input.txt );   ofstream out( output.txt );   int main() {     int n;     cin >> n;     vector<int> a;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       a.push_back(t);     }     sort(a.begin(), a.end());     for (int i = 0; i < n; i++) {       if (i + 1 != a[i]) {         cout << i + 1 << endl;         return 0;       }     }     cout << n + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> a, v, val;   long long int n, x;   long long int eval(long long int d, long long int i) {     if ((d + x - 1) <= a[i]) {       long long int ans = ((d + x - 1) * (d + x)) / 2 - ((d - 1) * (d)) / 2;       return ans;     } else {       long long int c = x - (a[i] - d + 1);       long long int l, r, mid, m, ans = 0;       l = i + 1;       r = 2 * n;       while (l <= r) {         mid = l + (r - l) / 2;         if ((v[mid] - v[i]) >= c) {           m = mid;           r = mid - 1;         } else           l = mid + 1;       }       ans += ((a[i]) * (a[i] + 1)) / 2 - ((d - 1) * (d)) / 2;       ans += val[m - 1] - val[i];       c -= v[m - 1] - v[i];       ans += c * (c + 1) / 2;       return ans;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int i, ans = 0, l, r, m1, m2, c, b;     cin >> n >> x;     a.resize(2 * n + 2);     v.resize(2 * n + 2);     val.resize(2 * n + 2);     for (i = 1; i <= n; i++) {       cin >> a[i];       a[i + n] = a[i];     }     for (i = 1; i <= 2 * n; i++) {       v[i] = v[i - 1] + a[i];       val[i] = val[i - 1] + (a[i] * (a[i] + 1)) / 2;     }     for (i = 1; i <= n; i++) {       l = 1;       r = a[i];       m1 = l;       while (l <= r) {         m1 = l + (r - l) / 3;         m2 = r - (r - l) / 3;         c = eval(m1, i);         b = eval(m2, i);         ans = max(ans, c);         ans = max(ans, b);         if (c >= b)           r = m2 - 1;         else           l = m1 + 1;       }       ans = max(ans, eval(m1, i));     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void maxi(T &x, T y) {     if (y > x) x = y;   }   template <class T>   inline void mini(T &x, T y) {     if (y < x) x = y;   }   const int N = 2e5, B = 0x7fffffff;   int t;   int main() {     scanf( %d , &t);     for (int tt = 1; tt <= t; tt++) {       long long x, y, p, q;       scanf( %lld %lld %lld %lld , &x, &y, &p, &q);       long long l = 0, r = 1000000000;       long long ans = -1;       while (l <= r) {         long long mid = (l + r) >> 1;         if (mid * p >= x && mid * q >= y) {           if ((mid * q) - y >= (mid * p) - x)             ans = mid, r = mid - 1;           else             l = mid + 1;         } else           l = mid + 1;       }       if (ans == -1)         puts( -1 );       else         printf( %lld n , (ans * q) - y);     }     return !!0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 5e5 + 1, mod = 1e9 + 7, base = 17;   int n, m, d, c, up;   int f[N];   int sum[N];   int it[N * 4];   int common[N];   int small[N * 2];   int tmp[N];   int flag[N * 2][30];   unsigned long long hashes[N];   long long pw[N];   string srr;   vector<int> idx[N * 2];   int convert(char c) {     if (c ==  ( ) {       return 7;     }     return 13;   }   long long ask(int l, int r) {     long long sub = 0;     if (l > 0) {       sub = hashes[l - 1];     }     return (hashes[r] - sub * pw[r - l + 1]);   }   int lcp(int x, int y) {     int low = 0, high = srr.size() - min(x, y) - 1, ans = -1;     while (low <= high) {       int val = (low + high) >> 1;       if (ask(x, x + val) == ask(y, y + val)) {         ans = val;         low = val + 1;       } else {         high = val - 1;       }     }     return ans;   }   bool cmp(int u, int v) {     if (small[u] != small[v]) {       return small[u] < small[v];     }     return small[u + up] < small[v + up];   }   void build(int i, int l, int r) {     if (l == r) {       it[i] = sum[l];       return;     }     int mid = (l + r) >> 1;     build(i * 2, l, mid);     build(i * 2 + 1, mid + 1, r);     it[i] = min(it[i * 2], it[i * 2 + 1]);   }   int query(int i, int l, int r) {     if (d > r || l > c) {       return N;     }     if (l >= d && r <= c) {       return it[i];     }     int mid = (l + r) >> 1;     return min(query(i * 2, l, mid), query(i * 2 + 1, mid + 1, r));   }   int range(int l, int r) {     int lgr = log2(r - l + 1);     return min(flag[l][lgr], flag[r - (1 << lgr) + 1][lgr]);   }   bool correct(int l, int r) {     int sub = 0;     if (l > 0) {       sub = sum[l - 1];     }     return (sum[r] == sub && range(l, r) >= sub);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> srr;     for (int i = 0; i < srr.size(); ++i) {       f[i] = i;       small[i] = srr[i];     }     hashes[0] = convert(srr[0]);     for (int i = 1; i < srr.size(); ++i) {       hashes[i] = (1LL * hashes[i - 1] * base + convert(srr[i]));     }     pw[0] = 1;     for (int i = 1; i <= srr.size(); ++i) {       pw[i] = (pw[i - 1] * base);     }     for (up = 1; up <= srr.size(); up *= 2) {       sort(f, f + n, cmp);       tmp[f[0]] = 0;       for (int i = 1; i < srr.size(); ++i) {         tmp[f[i]] = tmp[f[i - 1]] + cmp(f[i - 1], f[i]);       }       for (int i = 0; i < srr.size(); ++i) {         small[i] = tmp[i];       }       if (small[f[n - 1]] == n - 1) {         break;       }     }     for (int i = 1; i < srr.size(); ++i) {       common[i] = lcp(f[i - 1], f[i]) + 1;     }     sum[0] = (srr[0] ==  (  ? 1 : -1);     for (int i = 1; i < srr.size(); ++i) {       sum[i] = sum[i - 1] + (srr[i] ==  (  ? 1 : -1);     }     for (int i = 0; i < srr.size(); ++i) {       for (int j = 0; j < 30; ++j) {         flag[i][j] = N * 2;       }     }     for (int i = 0; i < srr.size(); ++i) {       flag[i][0] = sum[i];     }     for (int j = 1; j <= 20; ++j) {       for (int i = 0; i < srr.size(); ++i) {         flag[i][j] = min(flag[i][j - 1], flag[i + (1 << (j - 1))][j - 1]);       }     }     for (int i = 0; i < srr.size(); ++i) {       idx[sum[i] + N].push_back(i);     }     long long answer = 0;     for (int i = 0; i < srr.size(); ++i) {       int least = common[i] + 1, u = f[i];       int values = 0;       if (u > 0) {         values = sum[u - 1];       }       int curr = values + N;       int low = lower_bound(idx[curr].begin(), idx[curr].end(), u + least - 1) -                 idx[curr].begin();       if (low == idx[curr].size()) {         continue;       }       int high = idx[curr].size() - 1, ans = low - 1, old = low;       while (low <= high) {         int mid = (low + high) >> 1;         int tt = idx[curr][mid];         if (range(u, tt) >= values) {           low = mid + 1;           ans = mid;         } else {           high = mid - 1;         }       }       answer += (ans - old + 1);     }     cout << answer;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long test;     test = 1;     while (test--) {       long long n;       cin >> n;       long long a[n], b[n];       for (long long i = 0; i < n; i++) cin >> a[i];       for (long long i = 0; i < n; i++) cin >> b[i];       long long aalone = 0, balone = 0;       for (long long i = 0; i < n; i++) {         if (a[i] == 1 && b[i] == 0)           aalone++;         else if (a[i] == 0 && b[i] == 1)           balone++;       }       if (aalone == 0)         cout <<  -1 ;       else {         if ((balone + 1) % aalone == 0)           cout << (balone + 1) / aalone;         else {           cout << (balone + 1) / aalone + 1;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T1>   void deb(T1 e1) {     cout << e1 << endl;   }   template <class T1, class T2>   void deb(T1 e1, T2 e2) {     cout << e1 <<     << e2 << endl;   }   template <class T1, class T2, class T3>   void deb(T1 e1, T2 e2, T3 e3) {     cout << e1 <<     << e2 <<     << e3 << endl;   }   template <class T1, class T2, class T3, class T4>   void deb(T1 e1, T2 e2, T3 e3, T4 e4) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl;   }   template <class T1, class T2, class T3, class T4, class T5>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl;   }   template <class T1, class T2, class T3, class T4, class T5, class T6>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6          << endl;   }   const long long int mod = 10000000000007;   vector<pair<long long int, long long int> > adj1[1000005];   vector<pair<long long int, long long int> > adj2[1000005];   long long int come[1000005];   long long int bak[1000005];   long long int pre[1000005];   int main() {     int n, m, k;     scanf( %d %d %d , &n, &m, &k);     for (int i = 1; i <= m; i++) {       long long int u, v, d, c;       scanf( %lld %lld %lld %lld , &d, &u, &v, &c);       if (u == 0) {         adj2[d].push_back(make_pair(v, c));       } else {         adj1[d].push_back(make_pair(u, c));       }     }     for (int i = 1; i <= n; i++) {       pre[i] = mod;       come[0] += pre[i];     }     for (int i = 1; i < 1000005; i++) {       long long int now = come[i - 1];       for (int j = 0; j < adj1[i].size(); j++) {         int u = adj1[i][j].first;         long long int cost = adj1[i][j].second;         if (pre[u] > cost) {           now -= pre[u];           pre[u] = cost;           now += pre[u];         }       }       come[i] = now;     }     for (int i = 1; i <= n; i++) {       pre[i] = mod;       bak[1000005 - 1] += pre[i];     }     for (int i = 1000005 - 2; i >= 1; i--) {       long long int now = bak[i + 1];       for (int j = 0; j < adj2[i].size(); j++) {         int u = adj2[i][j].first;         long long int cost = adj2[i][j].second;         if (pre[u] > cost) {           now -= pre[u];           pre[u] = cost;           now += pre[u];         }       }       bak[i] = now;     }     long long int ans = mod * 100;     for (int i = 1; i + k < 1000005; i++) {       ans = min(ans, come[i - 1] + bak[i + k]);     }     if (ans >= mod) ans = -1;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int a;     string type;     node() {}     node(int x, const char *s) {       a = x;       type = s;     }   };   map<string, node> h;   char str[100];   int main() {     int n;     scanf( %d , &n);     char a[100], b[100];     int x, y;     h[ void ] = node(0,  void );     for (int i = 1; i <= n; i++) {       scanf( %s , str);       if (strcmp(str,  typedef ) == 0) {         scanf( %s %s , a, b);         x = y = 0;         int j = 0;         while (a[j] ==  & ) j++, x++;         j = strlen(a) - 1;         while (a[j] ==  * ) j--, y++;         a[j + 1] = 0;         node tmp;         if (h.find(a + x) == h.end()) {           tmp = node(0,  errtype );         } else           tmp = h[a + x];         x -= y;         tmp.a += x;         if (tmp.a > 0) {           tmp.type =  errtype ;         }         h[b] = tmp;       } else {         scanf( %s , a);         x = y = 0;         int j = 0;         while (a[j] ==  & ) j++, x++;         j = strlen(a) - 1;         while (a[j] ==  * ) j--, y++;         a[j + 1] = 0;         node t;         if (h.find(a + x) == h.end()) {           t = node(0,  errtype );         } else           t = h[a + x];         x -= y;         t.a += x;         if (t.a > 0) {           cout <<  errtype  << endl;         } else {           cout << t.type;           if (t.type !=  errtype ) {             for (int i = 1; i <= -t.a; i++) putchar( * );           }           puts(  );         }       }     }     return 0;   }


#include <bits/stdc++.h>   int luckyDigits(long long int *a) {     int count1 = 0, dig;     while (*a != 0) {       dig = *a % 10;       if (dig == 4 || dig == 7) {         count1++;       }       *a = *a / 10;     }     return count1;   }   int main() {     long long int i, j, k, n, a, count = 0;     scanf( %lld%lld , &n, &k);     for (i = 0; i < n; i++) {       a = 0;       scanf( %lld , &a);       if (luckyDigits(&a) <= k) {         count++;       }     }     printf( %lld , count);   }


#include <bits/stdc++.h>   using namespace std;   static const int INF = 500000000;   template <class T>   void debug(T a, T b) {     for (; a != b; ++a) cerr << *a <<    ;     cerr << endl;   }   template <class T>   void chmin(T& a, const T& b) {     if (a > b) a = b;   }   template <class T>   void chmax(T& a, const T& b) {     if (a < b) a = b;   }   string s, t;   bool check() {     cin >> s;     t = s;     reverse((t).begin(), (t).end());     if (t != s) return false;     for (int i = 0; i < (s.size()); ++i) {       if (s[i] ==  A  || s[i] ==  H  || s[i] ==  I  || s[i] ==  M  ||           s[i] ==  O  || s[i] ==  T  || s[i] ==  U  || s[i] ==  V  ||           s[i] ==  W  || s[i] ==  X  || s[i] ==  Y )         ;       else         return false;     }     return true;   }   int main() {     if (check())       puts( YES );     else       puts( NO );     return 0;   }