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


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


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


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


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


#include <bits/stdc++.h> n using namespace std; n int t[1000006], c[1000006]; n int main() { n   int n, a, i, x; n   scanf( %d , &n); n   scanf( %d , &a); n   t[a] = 1; n   for (i = 0; i < n; i++) { n     scanf( %d , &x); n     if (x == a) { n       c[x]++; n     } else { n       c[x]++; n       if (c[x] <= c[a]) { n         t[x] = 1; n       } n     } n   } n   for (i = 1; i <= 1000000; i++) { n     if (!t[i] && c[i] >= c[a]) { n       cout << i; n       return 0; n     } n   } n   cout << -1; n   return 0; n } n


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, m; n   cin >> n >> m; n   vector<string> v, l, b; n   for (long long int i = 0; i < n; i++) { n     string s; n     cin >> s; n     v.push_back(s); n   } n   long long int c = -1; n   for (long long int i = 0; i < n; i++) { n     for (long long int j = 0; j < m + 2; j++) { n       if (v[i][j] ==  1 ) { n         c = i; n         break; n       } n     } n     if (c != -1) break; n   } n   if (c == -1) { n     cout << 0; n     return 0; n   } n   for (long long int i = c; i < n; i++) { n     l.push_back(v[i]); n   } n   n = n - c; n   long long int f = n; n   for (long long int i = n - 1; i >= 0; i--) { n     for (long long int j = 0; j < m + 2; j++) { n       if (l[i][j] ==  1 ) { n         f = i; n         break; n       } n     } n     if (f != n) break; n   } n   if (f == n) { n     cout << 0; n     return 0; n   } n   for (long long int i = 0; i <= f; i++) { n     b.push_back(l[i]); n   } n   long long int g = n; n   n = f + 1; n   long long int k = 0; n   for (long long int i = m + 1; i >= 0; i--) { n     if (b[n - 1][i] ==  1 ) { n       k = i; n       break; n     } n   } n   if (n == 1) { n     cout << k + g - 1 - f; n   } else { n     long long int a[n][m + 2]; n     memset(a, 0, sizeof(a)); n     a[n - 1][0] = 2 * k; n     a[n - 1][m + 1] = m + 1; n     a[n - 2][0] = 2 * k + 1; n     a[n - 2][m + 1] = m + 2; n     for (long long int i = n - 2; i > 0; i--) { n       long long int x1 = 0; n       long long int x2 = m + 1; n       for (long long int j = m + 1; j >= 0; j--) { n         if (b[i][j] ==  1 ) { n           x1 = j; n           break; n         } n       } n       for (long long int j = 0; j <= (m + 1); j++) { n         if (b[i][j] ==  1 ) { n           x2 = j; n           break; n         } n       } n       a[i - 1][0] = 1 + min(m + 1 + a[i][m + 1], a[i][0] + 2 * x1); n       a[i - 1][m + 1] = n           1 + min(m + 1 + a[i][0], a[i][m + 1] + 2 * (m + 1 - x2)); n     } n     long long int x1 = 0; n     long long int x2 = m + 1; n     for (long long int j = m + 1; j >= 0; j--) { n       if (b[0][j] ==  1 ) { n         x1 = j; n         break; n       } n     } n     for (long long int j = 0; j <= (m + 1); j++) { n       if (b[0][j] ==  1 ) { n         x2 = j; n         break; n       } n     } n     cout << min(a[0][0] + x1, a[0][m + 1] + m + 1 - x2) + g - 1 - f << endl; n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long x = 8 * 9 * 7 * 5; n   long long n; n   cin >> n; n   cout << n / x <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef long long ll; n const int N = 1000; n const int MAX_WEIGHT = 20000; n const ll INF =10000000000000; n  n int n, m; n vector<int> b[2], a[2]; n vector<int> suff[2]; n map<int,bool> exist; n  n int get(int i, int j, int c) { n   int result = 0; n   int value = b[i][j] + c - 1; n   int s = j, e = b[i].size() - 1, mid ,best = j; n   while (s <= e) { n     mid = s + e; n     mid >>= 1; n     if (b[i][mid] <= value) { n       best = mid; n       s = mid + 1; n     } else { n       e = mid - 1; n     } n   } n   result = best - j + 1; n   return result; n } n  n void solve() { n   for (int i = 0 ; i < 2 ; i++) { n     sort(a[i].begin(), a[i].end()); n     sort(b[i].begin(), b[i].end()); n     suff[i].clear(); n     suff[i].resize(a[i].size() + 1); n   } n  n   suff[0][a[0].size()] = suff[1][a[1].size()] = 0; n  n   for (int j = 0 ; j < 2 ; j++) n     for (int i = a[j].size() - 1 ; i >= 0 ; i--) { n       suff[j][i] = suff[j][i + 1] + exist[(j == 0 ? 1 : -1) * a[j][i]]; n     } n   int answer = 0; n   for (int i = 0 ; i < 2 ; i++) { n     if (a[i].size() == 0) n       continue; n     int last_moved = 0; n     int mx = 0; n     int num_moved = 1; n     for (int j = 0 ; j < (int) b[i].size() ; j++) { n       if (b[i][j] < a[i][0]) n         continue; n       while (last_moved != (int) a[i].size() && a[i][last_moved] < b[i][j] + num_moved) n         last_moved++, num_moved++; n       num_moved--; n       last_moved--; n       mx = max(mx, suff[i][last_moved + 1] + get(i, j, num_moved)); n     } n     answer += mx; n   } n   cout << answer << endl; n  n } n  n void read() { n   cin >> n>> m; n   a[0].clear(); n   b[0].clear(); n   a[1].clear(); n   b[1].clear(); n   exist.clear(); n   for (int i = 0, a ; i < n ; i++) { n     scanf( %d , &a); n     ::a[a < 0].push_back(a * (a < 0 ? -1 : 1)); n   } n   for (int i = 0, b ; i < m ; i++) { n     scanf( %d , &b); n     exist[b] = true; n     ::b[b < 0].push_back(b * (b < 0 ? -1 : 1)); n   } n } n  n signed main() { n   int t = 1; n   cin >> t; n   while (t--) { n     read(); n     solve(); n   } n  n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const int maxn = 1e5 + 15; n const int maxm = 1e6 + 15; n const int mod = 1e9 + 7; n struct Edge { n   int to, next; n } edge[maxm]; n int head[maxn], dfn[maxn], bccno[maxn], low[maxn]; n int ecnt, cnt, bcnt; n void add(int u, int v) { n   edge[ecnt].to = v; n   edge[ecnt].next = head[u]; n   head[u] = ecnt++; n } n void init() { n   ecnt = 0; n   memset(dfn, 0, sizeof dfn); n   memset(head, -1, sizeof head); n } n stack<int> Stack; n void tarjan(int fa, int u) { n   dfn[u] = low[u] = ++cnt; n   Stack.push(u); n   for (int i = head[u]; ~i; i = edge[i].next) { n     int v = edge[i].to; n     if (!dfn[v]) { n       tarjan(u, v); n       low[u] = min(low[u], low[v]); n     } else if (v != fa) n       low[u] = min(low[u], dfn[v]); n   } n   if (low[u] == dfn[u]) { n     int v; n     bcnt++; n     do { n       v = Stack.top(); n       Stack.pop(); n       bccno[v] = bcnt; n     } while (v != u); n   } n } n long long quickMod(long long y) { n   long long res = 1, x = 2; n   while (y) { n     if (y & 1) res = res * x % mod; n     x = x * x % mod; n     y >>= 1; n   } n   return res; n } n int w[maxn], x[maxn], y[maxn]; n namespace hld { n int son[maxn], par[maxn], size[maxn], top[maxn]; n int tid[maxn], dep[maxn], c[maxn], tot, n; n void init(int _n) { n   n = _n, tot = 0; n   memset(tid, 0, sizeof tid); n   memset(c, 0, sizeof c); n } n void dfs1(int u, int fa, int depth = 0) { n   par[u] = fa; n   dep[u] = depth; n   size[u] = 1; n   son[u] = 0; n   int maxx = 0; n   for (int i = head[u]; ~i; i = edge[i].next) { n     int v = edge[i].to; n     if (v == fa) continue; n     dfs1(v, u, depth + 1); n     size[u] += size[v]; n     if (size[v] > maxx) { n       maxx = size[v]; n       son[u] = v; n     } n   } n } n int lowbit(int x) { return x & -x; } n void Add(int x, int y) { n   for (; x <= n; x += lowbit(x)) c[x] += y; n } n void dfs2(int u, int acs) { n   tid[u] = ++tot, top[u] = acs; n   if (w[u]) Add(tot, 1); n   if (!son[u]) return; n   dfs2(son[u], acs); n   for (int i = head[u]; ~i; i = edge[i].next) { n     int v = edge[i].to; n     if (tid[v]) continue; n     dfs2(v, v); n   } n } n int sum(int x) { n   int res = 0; n   for (; x; x -= lowbit(x)) res += c[x]; n   return res; n } n int query(int u, int v) { n   int f1 = top[u], f2 = top[v], res = 0; n   while (f1 != f2) { n     if (dep[f1] < dep[f2]) swap(f1, f2), swap(u, v); n     res += sum(tid[u]) - sum(tid[f1] - 1); n     u = par[f1], f1 = top[u]; n   } n   if (dep[u] > dep[v]) swap(u, v); n   return res += sum(tid[v]) - sum(tid[u] - 1); n } n }  // namespace hld n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   init(); n   for (int i = 1; i <= m; i++) { n     int u, v; n     scanf( %d %d , &u, &v); n     add(u, v); n     add(v, u); n     x[i] = u, y[i] = v; n   } n   for (int i = 1; i <= n; i++) n     if (!dfn[i]) tarjan(0, i); n   for (int i = 1; i <= n; i++) w[bccno[i]]++; n   for (int i = 1; i <= bcnt; i++) w[i] = (w[i] == 1 ? 0 : 1); n   ecnt = 0; n   memset(head, -1, sizeof head); n   for (int i = 1; i <= m; i++) { n     int u = bccno[x[i]], v = bccno[y[i]]; n     if (u == v) continue; n     add(u, v), add(v, u); n   } n   int k; n   scanf( %d , &k); n   hld::init(n); n   hld::dfs1(1, 0), hld::dfs2(1, 1); n   while (k--) { n     int u, v; n     scanf( %d %d , &u, &v); n     long long ans = quickMod(hld::query(bccno[u], bccno[v])); n     if (ans >= mod) ans -= mod; n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 55; n int n; n int xi[maxn], yi[maxn]; n int ans1 = 0, ans2 = 0; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &xi[i]), ans1 += xi[i]; n   for (int i = 1; i <= n; i++) scanf( %d , &yi[i]), ans2 += yi[i]; n   if (ans1 < ans2) n     printf( No n ); n   else n     printf( Yes n ); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC target( avx2 ) n #pragma GCC optimization( O3 ) n #pragma GCC optimization( unroll-loops ) n using namespace std; n template <class T1, class T2> n ostream &operator<<(ostream &os, const pair<T1, T2> &p) { n   os <<  {  << p.first <<  ,  << p.second <<  } ; n   return os; n } n const int N = 3e5 + 5; n const int oo = 1e9 + 7; n int a[N]; n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   int tot1 = 0; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     tot1 += a[i]; n   } n   bool res = a[1]; n   for (int i = 2; i <= n; i++) { n     res = !res or a[i]; n   } n   if (res == 0) { n     cout <<  YES n  << a[1]; n     for (int i = 2; i <= n; i++) cout <<  ->  << a[i]; n     cout <<   n ; n   } else if (a[n] == 1 or n <= 2 or (a[n - 2] == 1 and tot1 == n - 2)) { n     cout <<  NO n ; n   } else if (a[n - 2] == 0) { n     cout <<  YES n  << a[1]; n     for (int i = 2; i <= n - 3; i++) cout <<  ->  << a[i]; n     cout <<  ->(  << a[n - 2] <<  ->  << a[n - 1] <<  )->  << a[n] <<   n ; n   } else { n     int zero = -1; n     for (int i = n - 3; i >= 1; i--) n       if (a[i] == 0) { n         zero = i; n         break; n       } n     assert(zero != -1); n     cout <<  YES n ; n     if (zero > 1) { n       cout << a[1]; n       for (int i = 2; i < zero; i++) { n         cout <<  ->  << a[i]; n       } n       cout <<  -> ; n     } n     cout <<  (  << a[zero] <<  ->((  << a[zero + 1]; n     for (int i = zero + 2; i <= n - 2; i++) cout <<  ->  << a[i]; n     cout <<  )->  << a[n - 1] <<  ))->  << a[n] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 502; n vector<int> adj[maxn]; n bool vis[maxn]; n bool fin[maxn]; n vector<pair<int, int> > edgesInCycle; n int n; n bool dfs(int node) { n   vis[node] = 1; n   for (int ch : adj[node]) { n     edgesInCycle.push_back({node, ch}); n     if (!vis[ch]) { n       if (dfs(ch)) return 1; n     } else if (!fin[ch]) n       return 1; n     edgesInCycle.pop_back(); n   } n   fin[node] = 1; n   return 0; n } n bool checkDag() { n   memset(vis, 0, sizeof(vis)); n   memset(fin, 0, sizeof(fin)); n   for (int i = 1; i <= n; ++i) { n     if (!vis[i] && dfs(i)) return 0; n   } n   return 1; n } n bool solve() { n   if (checkDag()) return 1; n   vector<pair<int, int> > edges = edgesInCycle; n   for (pair<int, int> edge : edges) { n     int u = edge.first; n     int v = edge.second; n     auto it = find(adj[u].begin(), adj[u].end(), v); n     assert(it != adj[u].end()); n     adj[u].erase(it); n     if (checkDag()) return 1; n     adj[u].push_back(v); n   } n   return 0; n } n int main() { n   int m; n   cin >> n >> m; n   int u, v; n   for (int i = 0; i < m; ++i) { n     cin >> u >> v; n     adj[u].push_back(v); n   } n   cout << (solve() ?  YES n  :  NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, t; n   cin >> n >> t; n   if (n == 1 && t == 10) { n     cout <<  -1  << endl; n     return 0; n   } n   cout << ((t == 10) ? 1 : t); n   while (n-- > 1) { n     cout <<  0 ; n   } n   return 0; n } n


#include <iostream> n #include <algorithm> n #include <cstdio> n #include <vector> n #include <stack> n #include <string> n #include <cstring> n #include <queue> n #include <map> n #include <set> n #include <cmath> n #include <climits> n #include <functional> n  n typedef long long ll; n  n using namespace std; n  n int main() n { n #ifdef ONLINE_JUDGE n #else n     freopen( in1.txt ,  r , stdin); n     // freopen( w.txt ,  w , stdout); n #endif n     // ios::sync_with_stdio(false); n      n     ll T, d, k; n     for (cin >> T; T--;) { n         cin >> d >> k; n  n         ll cnt = 0; n         while ((cnt * k) * (cnt * k) * 2 <= d * d) { n             ++cnt; n         } n         --cnt; n          n         ll res = (cnt * k) * (cnt * k) + (cnt * k + k) * (cnt * k + k); n  n         cout << (res <= d * d ?  Ashish  :  Utkarsh ) << endl; n  n     } n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   static char data[100015]; n   static int a[100015]; n   static int b[100015]; n   memset(a, 0, sizeof(a)); n   memset(b, 0, sizeof(b)); n   int i, j, N, len; n   N = 0; n   scanf( %s n , data); n   len = strlen(data); n   if (len > N) N = len; n   for (i = 0; i < len; i++) { n     a[len - i - 1] = (int)(data[i] -  0 ); n   } n   scanf( %s , data); n   len = strlen(data); n   if (len > N) N = len; n   for (i = 0; i < len; i++) { n     b[len - i - 1] = (int)(data[i] -  0 ); n   } n   N += 5; n   for (i = N; i >= 0; i--) { n     j = i; n     while ((a[j]) && (a[j + 1])) { n       a[j] = 0; n       a[j + 1] = 0; n       a[j + 2] = 1; n       j += 2; n     } n     j = i; n     while ((b[j]) && (b[j + 1])) { n       b[j] = 0; n       b[j + 1] = 0; n       b[j + 2] = 1; n       j += 2; n     } n   } n   i = N; n   while ((i >= 0) && (a[i] == b[i])) i--; n   if (i < 0) n     printf( = ); n   else if (a[i] > b[i]) n     printf( > ); n   else n     printf( < ); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long powr(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b % 2 == 1) res = res * a % 1000000007; n     a = a * a % 1000000007; n     b /= 2; n   } n   return res; n } n int main() { n   int p, k; n   cin >> p >> k; n   vector<int> g[p]; n   bool x[p]; n   memset(x, false, sizeof x); n   vector<set<long long>> a; n   if (k == 0) { n     long long ans = powr(p, p - 1); n     cout << ans <<   n ; n     return 0; n   } n   for (int i = 0; i < p; ++i) { n     if (x[i]) continue; n     x[i] = 1; n     long long yy = i; n     set<long long> xz; n     xz.insert(i); n     do { n       yy *= k; n       yy %= p; n       x[yy] = 1; n       xz.insert(yy); n     } while (yy != i); n     a.push_back(xz); n   } n   long long ans = 1; n   ans = powr(p, a.size() - 1); n   if (k == 1) { n     ans *= p; n     ans %= 1000000007; n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n int n, m, k; n int main() { n   cin >> n >> m >> k; n   cout << m * (m - 1) / 2 << endl; n   for (int i = 1; i <= m; i++) { n     for (int j = i + 1; j <= m; j++) { n       if (k) n         cout << j <<     << i << endl; n       else n         cout << i <<     << j << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using uint = unsigned int; n using rl = double; n using pii = pair<int, int>; n const int MAXN = 3 * 100009; n int n, m; n struct Vert { n   vector<int> to; n   vector<pair<int, int>> qlist; n   int depth; n   ll vsum; n } v[MAXN]; n ll psum[2 * MAXN]; n void dfs(int it, int p, ll sum) { n   v[it].depth = v[p].depth + 1; n   for (auto q : v[it].qlist) { n     psum[v[it].depth] += q.first; n     psum[v[it].depth + q.second + 1] -= q.first; n   } n   sum += psum[v[it].depth]; n   v[it].vsum = sum; n   for (auto t : v[it].to) { n     if (t == p) continue; n     dfs(t, it, sum); n   } n   for (auto q : v[it].qlist) { n     psum[v[it].depth] -= q.first; n     psum[v[it].depth + q.second + 1] += q.first; n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     int a, b; n     scanf( %d %d , &a, &b); n     v[a].to.push_back(b); n     v[b].to.push_back(a); n   } n   scanf( %d , &m); n   for (int i = 0; i < m; i++) { n     int it, d, x; n     scanf( %d %d %d , &it, &d, &x); n     v[it].qlist.push_back({x, min(d, n - 1)}); n   } n   dfs(1, 0, 0); n   for (int i = 1; i <= n; i++) { n     printf( %lld  , v[i].vsum); n   } n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n char a[100005]; n int b[100005]; n map<pair<int, int>, int> maps; n int main() { n   int nx, ny, x, y, x1, y1, n; n   scanf( %d%d%d%d , &nx, &ny, &x, &y); n   scanf(  %s , a); n   for (int i = 0; i < 100005; i++) b[i] = 0; n   b[0] = 1; n   maps[make_pair(x, y)] = 1; n   for (n = 0; a[n] !=   0 ; n++) n     ; n   for (int i = 0; i < n; i++) { n     switch (a[i]) { n       case  L : n         y1 = y - 1; n         x1 = x; n         break; n       case  R : n         y1 = y + 1; n         x1 = x; n         break; n       case  U : n         x1 = x - 1; n         y1 = y; n         break; n       case  D : n         x1 = x + 1; n         y1 = y; n         break; n     } n     if (x1 <= nx && y1 <= ny && x1 > 0 && y1 > 0) { n       if (maps[make_pair(x1, y1)] == 0) { n         b[i + 1]++; n         maps[make_pair(x1, y1)] = 1; n       } n       x = x1; n       y = y1; n     } n   } n   b[n] += nx * ny - maps.size(); n   for (int i = 0; i <= n; i++) printf( %d  , b[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   stack<char> st; n   for (int i = 0; i < s.length(); i++) { n     if (st.empty()) { n       st.push(s[i]); n     } else if (st.top() == s[i]) { n       st.pop(); n     } else { n       st.push(s[i]); n     } n   } n   if (st.empty()) { n     cout <<  Yes ; n   } else { n     cout <<  No ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 1e5 + 5; n const long long int mod = 1e15 + 7; n long long int dx[] = {1, -1, 0, 0}; n long long int dy[] = {0, 0, 1, -1}; n long long int y[N], yy[N], len[N]; n long long int n, m, low, high, mid1, mid2; n double ans = (double)mod; n long long int ans_n, ans_m; n long long int a, b; n double find_distance(double x, double y, double u, double v) { n   double temp = ((x - u) * (x - u) + (y - v) * (y - v)); n   temp = sqrt(temp); n   return temp; n } n int main() { n   cin >> n >> m >> a >> b; n   for (long long int i = 1; i < n + 1; i++) { n     cin >> y[i]; n   } n   for (long long int i = 1; i < m + 1; i++) { n     cin >> yy[i]; n   } n   for (long long int i = 1; i < m + 1; i++) { n     cin >> len[i]; n   } n   for (long long int i = 1; i < m + 1; i++) { n     low = 1; n     high = n; n     while ((high - low) > 5) { n       mid1 = low + (high - low) / 3; n       mid2 = low + 2 * (high - low) / 3; n       double dis1 = find_distance(0, 0, a, y[mid1]) + n                     find_distance(a, y[mid1], b, yy[i]) + len[i]; n       double dis2 = find_distance(0, 0, a, y[mid2]) + n                     find_distance(a, y[mid2], b, yy[i]) + len[i]; n       if (dis1 < dis2) { n         high = mid2; n       } else { n         low = mid1; n       } n     } n     for (long long int zz = low; zz < high + 1; zz++) { n       double temp = find_distance(0, 0, a, y[zz]) + n                     find_distance(a, y[zz], b, yy[i]) + len[i]; n       if (temp < ans) { n         ans = temp; n         ans_n = zz; n         ans_m = i; n       } n     } n   } n   cout << ans_n <<     << ans_m << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ii = tuple<long long, long long>; n const long long N = 1e6 + 7, inf = 1e9 + 42; n long long binpow(long long a, long long b) { n   if (b == 0) return 1; n   long long res = binpow(a, b / 2); n   if (b % 2) n     return (res * res * a) % 1000000007; n   else n     return (res * res) % 1000000007; n } n bool compare(pair<long long, long long> a, pair<long long, long long> b) { n   return (a.first - a.second > b.first - b.second); n } n long long n; n vector<long long> prime_factors; n signed main() { n   puts( Odd ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using pil = pair<long long, long long>; n using pii = pair<long long, long long>; n using pid = pair<double, double>; n long long mod = 1e9 + 7; n long long power(long long a, long long n) { n   long long res = 1; n   while (n) { n     if (n % 2) res = (res * a) % mod; n     a = (a * a) % mod; n     n /= 2; n   } n   return res; n } n void solve() { n   long long a, b; n   cin >> a >> b; n   long long B = (b * (b - 1) / 2) % mod; n   long long A = ((a * (a + 1) / 2) % mod) * b + a; n   A %= mod; n   long long ans = (A * B) % mod; n   cout << ans << endl; n } n int32_t main() { n   long long t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 20; n int n, m; n struct line { n   int type, x, y, lag; n   line() { type = x = y = lag = 0; } n   line(int a, int b, int c, int d) { type = a, x = b, y = c, lag = d; } n   bool operator<(const line &a) const { return y > a.y; } n } t[7 * N]; n int a[N], qu; n set<int> s[N]; n long long f[N], ans[N]; n void add(int x, int y) { n   while (x <= n) { n     f[x] += y; n     x += x & (-x); n   } n } n long long query(int x) { n   long long ret = 0; n   while (x) { n     ret += f[x]; n     x -= x & (-x); n   } n   return ret; n } n void cdq(int l, int r) { n   if (l == r) return; n   int mid = l + r >> 1; n   cdq(l, mid), cdq(mid + 1, r); n   int j = l; n   for (int i = mid + 1; i <= r; i++) { n     while (j <= mid && t[j].y >= t[i].y) { n       if (t[j].type == 0) add(t[j].x, (t[j].x - t[j].y) * t[j].lag); n       j++; n     } n     if (t[i].type == 1) ans[t[i].lag] += query(t[i].x); n   } n   for (int i = l; i < j; i++) n     if (t[i].type == 0) add(t[i].x, -(t[i].x - t[i].y) * t[i].lag); n   sort(t + l, t + r + 1); n } n set<int>::iterator it; n int main() { n   scanf( %d%d , &n, &m); n   int cnt = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     if (s[a[i]].size()) { n       it = s[a[i]].end(); n       it--; n       t[++cnt] = line(0, i, *it, 1); n     } else n       t[++cnt] = line(0, i, 0, 1); n     s[a[i]].insert(i); n   } n   int opt, x, y; n   for (int i = 1; i <= m; i++) { n     scanf( %d%d%d , &opt, &x, &y); n     if (opt == 1) { n       int L = 0, R = 0; n       it = s[a[x]].find(x); n       if (it != s[a[x]].begin()) t[++cnt] = line(0, x, L = *--it, -1), it++; n       if (++it != s[a[x]].end()) t[++cnt] = line(0, R = *it, x, -1); n       if (L && R) t[++cnt] = line(0, R, L, 1); n       s[a[x]].erase(x); n       s[a[x] = y].insert(x); n       it = s[y].find(x), L = R = 0; n       if (it != s[y].begin()) t[++cnt] = line(0, x, L = *--it, 1), it++; n       if (++it != s[y].end()) t[++cnt] = line(0, R = *it, x, 1); n       if (L && R) t[++cnt] = line(0, R, L, -1); n     } else n       t[++cnt] = line(1, y, x, ++qu); n   } n   cdq(1, cnt); n   for (int i = 1; i <= qu; i++) printf( %lld n , ans[i]); n   return 0; n } n