#include <bits/stdc++.h> n using namespace std; n const int MOD = 998244353; n const int BITS = 60; n struct tree_node { n   int child[2] = {-1, -1}; n   bool full = false; n }; n struct tree { n   vector<tree_node> nodes = {tree_node()}; n   int get_or_create_node(int &node) { n     int answer = node; n     if (node < 0) { n       answer = node = nodes.size(); n       nodes.emplace_back(); n     } n     return answer; n   } n   void recursive_add(int node, int bit, long long prefix, long long start, n                      long long end) { n     long long after = prefix + (1LL << bit); n     if (start <= prefix && after <= end) { n       nodes[node].full = true; n       return; n     } n     if (bit <= 0) return; n     long long mid = (prefix + after) / 2; n     if (start < mid) n       recursive_add(get_or_create_node(nodes[node].child[0]), bit - 1, prefix, n                     start, end); n     if (end > mid) n       recursive_add(get_or_create_node(nodes[node].child[1]), bit - 1, mid, n                     start, end); n   } n   void add_range(long long L, long long R) { recursive_add(0, BITS, 0, L, R); } n }; n tree a_tree, b_tree; n vector<pair<int, int>> options[BITS + 1]; n long long dfs_sum(int bit, long long prefix) { n   for (pair<int, int> &p : options[bit]) n     if (a_tree.nodes[p.first].full || b_tree.nodes[p.second].full) { n       long long count = 1LL << bit; n       long long prefix_sum = (prefix % MOD) * (count % MOD); n       long long bit_sum = (count / 2 % MOD) * ((count - 1) % MOD); n       return (prefix_sum + bit_sum) % MOD; n     } n   if (bit <= 0) return 0; n   long long sum = 0; n   for (int next = 0; next < 2; next++) { n     options[bit - 1].clear(); n     for (pair<int, int> &p : options[bit]) n       for (int left = 0; left < 2; left++) { n         int right = left ^ next; n         int a_child = a_tree.nodes[p.first].child[left]; n         int b_child = b_tree.nodes[p.second].child[right]; n         if (a_child >= 0 && b_child >= 0) n           options[bit - 1].emplace_back(a_child, b_child); n       } n     if (!options[bit - 1].empty()) { n       long long add = (long long)next << (bit - 1); n       sum = (sum + dfs_sum(bit - 1, prefix + add)) % MOD; n     } n   } n   return sum; n } n int main() { n   int A, B; n   cin >> A; n   for (int i = 0; i < A; i++) { n     long long L, R; n     cin >> L >> R; n     R++; n     a_tree.add_range(L, R); n   } n   cin >> B; n   for (int i = 0; i < B; i++) { n     long long L, R; n     cin >> L >> R; n     R++; n     b_tree.add_range(L, R); n   } n   options[BITS].emplace_back(0, 0); n   cout << dfs_sum(BITS, 0) <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   int t, n, i, j, x; n   int n1, n2; n   int a, b, p, q; n   cin >> t; n   for (i = 0; i < t; i++) { n     cin >> n; n     n1 = 0, n2 = 0; n     vector<int> v, v1, v2; n     vector<int> even, odd; n     for (j = 0; j < n; j++) { n       cin >> x; n       if (x % 2) { n         n1++; n         odd.push_back(j); n       } else { n         n2++; n         even.push_back(j); n       } n       v.push_back(x); n       v1.push_back(x); n       v2.push_back(x); n     } n     long long max1 = 0, max2 = 0, max_total; n     int k, temp; n     a = 0, b = 0; n     if (n % 2) { n       if (abs(n1 - n2) != 1) { n         cout <<  -1 n ; n       } else { n         if (n1 < n2) { n           for (k = 0; k < n; k++) { n             if (k % 2) { n               while (a < n && !(v1[a] % 2)) { n                 a++; n               } n               max1 += abs(a - k); n               if (a != k) { n                 temp = v1[a]; n                 v1[a] = v1[k]; n                 v1[k] = temp; n               } n               a++; n             } else { n               while (b < n && v1[b] % 2) { n                 b++; n               } n               max1 += abs(b - k); n               if (b != k) { n                 temp = v1[b]; n                 v1[b] = v1[k]; n                 v1[k] = temp; n               } n               b++; n             } n           } n           cout << max1 <<   n ; n         } else { n           for (k = 0; k < n; k++) { n             if (!(k % 2)) { n               while (a < n && !(v2[a] % 2)) { n                 a++; n               } n               max2 += abs(a - k); n               if (a != k) { n                 temp = v2[a]; n                 v2[a] = v2[k]; n                 v2[k] = temp; n               } n               a++; n             } else { n               while (b < n && v2[b] % 2) { n                 b++; n               } n               max2 += abs(b - k); n               if (b != k) { n                 temp = v2[b]; n                 v2[b] = v2[k]; n                 v2[k] = temp; n               } n               b++; n             } n           } n           cout << max2 <<   n ; n         } n       } n     } else { n       if (n1 != n2) { n         cout <<  -1 n ; n       } else { n         a = 0, b = 0; n         for (k = 0; k < n; k++) { n           if (k % 2) { n             while (a < n && !(v1[a] % 2)) { n               a++; n             } n             max1 += abs(a - k); n             if (a != k) { n               temp = v1[a]; n               v1[a] = v1[k]; n               v1[k] = temp; n             } n             a++; n           } else { n             while (b < n && v1[b] % 2) { n               b++; n             } n             max1 += abs(b - k); n             if (b != k) { n               temp = v1[b]; n               v1[b] = v1[k]; n               v1[k] = temp; n             } n             b++; n           } n         } n         a = 0, b = 0; n         for (k = 0; k < n; k++) { n           if (!(k % 2)) { n             while (a < n && !(v2[a] % 2)) { n               a++; n             } n             max2 += abs(a - k); n             if (a != k) { n               temp = v2[a]; n               v2[a] = v2[k]; n               v2[k] = temp; n             } n             a++; n           } else { n             while (b < n && v2[b] % 2) { n               b++; n             } n             max2 += abs(b - k); n             if (b != k) { n               temp = v2[b]; n               v2[b] = v2[k]; n               v2[k] = temp; n             } n             b++; n           } n         } n         cout << min(max1, max2) <<   n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int a[2005][2005]; n bitset<2000> b[2000]; n bitset<2000> c[2000]; n int u[500005], v[500005]; n template <class T> n void dbg(T x) { n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       cout << (int)x[i][j]; n     } n     cout <<   n ; n   } n   cout <<   n ; n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     cin >> u[i] >> v[i]; n     a[u[i]][v[i]] = 1; n     b[u[i] - 1][v[i] - 1] = 1; n   } n   for (int i = 0; i < n; i++) { n     c[i][i] = 1; n   } n   for (int i = 0; i < n; i++) { n     for (int j = i; j < n; j++) { n       if (b[j][i] == 1) { n         swap(b[i], b[j]); n         swap(c[i], c[j]); n         break; n       } n     } n     for (int j = i + 1; j < n; j++) { n       if (b[j][i]) { n         b[j] ^= b[i]; n         c[j] ^= c[i]; n       } n     } n   } n   for (int i = n - 1; i > 0; i--) { n     for (int j = i - 1; j >= 0; j--) { n       if (b[j][i]) { n         b[j] ^= b[i]; n         c[j] ^= c[i]; n       } n     } n   } n   for (int i = 0; i < m; i++) { n     int x = u[i] - 1, y = v[i] - 1; n     if (c[y][x]) { n       cout <<  NO n ; n     } else { n       cout <<  YES n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long dx4[] = {0, 0, -1, 1}; n long long dy4[] = {-1, 1, 0, 0}; n long long n, m; n long long V[5003]; n long long cnt[5003]; n long long dis(long long x, long long y) { n   if (y > x) n     return y - x; n   else { n     return y + n - x; n   } n } n long long res[5003]; n int main() { n   long long i, j; n   scanf( %lld%lld , &n, &m); n   for (i = 1; i <= n; i++) V[i] = LLONG_MAX; n   for (i = 1; i <= m; i++) { n     long long x, y; n     scanf( %lld%lld , &x, &y); n     V[x] = min(dis(x, y), V[x]); n     cnt[x]++; n   } n   long long Mx = 0; n   for (i = 1; i <= n; i++) { n     long long d = cnt[i]; n     Mx = max(Mx, d); n   } n   long long tot = (Mx - 1) * n; n   long long extra = n, extra1 = n; n   for (i = 1; i <= n; i++) { n     if (i - 1) printf(   ); n     long long Mn = 0; n     for (j = 1; j <= n; j++) { n       if (cnt[j] == Mx) { n         long long f = extra + j - 1; n         f %= n; n         long long ex1 = f + V[j]; n         Mn = max(Mn, ex1); n       } else if (cnt[j] == Mx - 1 && Mx - 1 != 0) { n         long long f = extra1 - j + 1; n         f %= n; n         if (f == 0) f = n; n         long long ex1 = V[j] - f; n         Mn = max(Mn, ex1); n       } n     } n     extra--; n     extra1++; n     printf( %lld , tot + Mn); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using u32 = unsigned; n using u64 = unsigned long long; n int lg_ceil(u64 n) { return 63 - __builtin_clzll(2 * n - 1); } n int lg_floor(u32 n) { return 31 - __builtin_clz(n); } n template <class T> n struct sparse_table { n   sparse_table() {} n   sparse_table(std::vector<T>& V, std::function<T(T, T)> f) n       : M(lg_ceil(V.size()), V), F(f) { n     for (size_t i = 0; i + 1 < M.size(); i++) { n       for (size_t j = 0; j + (1 << i) < M[i].size(); j++) { n         M[i + 1][j] = F(M[i][j], M[i][j + (1 << i)]); n       } n     } n   } n   T query(int l, int r) { n     int k = lg_floor(r - l); n     return F(M[k][l], M[k][r - (1 << k)]); n   } n   std::vector<std::vector<T>> M; n   std::function<T(T, T)> F; n }; n template <class T> n struct mmax { n   T operator()(const T& a, const T& b) { return std::max(a, b); } n }; n template <class T> n struct mmin { n   T operator()(const T& a, const T& b) { return std::min(a, b); } n }; n template <class T> n std::vector<T> read(int n) { n   std::vector<T> res(n); n   for (auto& r : res) { n     std::cin >> r; n   } n   return res; n } n int main() { n   std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0); n   int n; n   std::cin >> n; n   auto r = read<int>(n); n   for (int i = 0; i < 2 * n; i++) { n     r.push_back(r[i]); n   } n   if (n == 1) { n     std::cout << 0 <<   n ; n     return 0; n   } n   int lg = lg_ceil(n); n   std::vector<std::vector<int>> ll(lg + 1, std::vector<int>(3 * n)); n   std::vector<std::vector<int>> rr(lg + 1, std::vector<int>(3 * n)); n   for (int i = 0; i < 3 * n; i++) { n     ll[0][i] = std::max(i - r[i], 0); n     rr[0][i] = std::min(i + r[i] + 1, 3 * n); n   } n   for (int j = 1; j <= lg; j++) { n     sparse_table<int> lo(ll[j - 1], mmin<int>()); n     sparse_table<int> hi(rr[j - 1], mmax<int>()); n     for (int i = 0; i < 3 * n; i++) { n       ll[j][i] = lo.query(ll[j - 1][i], rr[j - 1][i]); n       rr[j][i] = hi.query(ll[j - 1][i], rr[j - 1][i]); n     } n   } n   std::vector<int> left(n), right(n), sum(n), ans(n); n   std::iota(begin(left), end(left), n); n   std::iota(begin(right), end(right), n + 1); n   for (int j = lg; j >= 0; j--) { n     sparse_table<int> lo(ll[j], mmin<int>()); n     sparse_table<int> hi(rr[j], mmax<int>()); n     for (int i = 0; i < n; i++) { n       int nl = lo.query(left[i], right[i]); n       int nr = hi.query(left[i], right[i]); n       if (nr - nl < n) { n         left[i] = nl, right[i] = nr; n         sum[i] += 1 << j; n       } else { n         ans[i] = sum[i] + (1 << j); n       } n     } n   } n   for (int a : ans) { n     std::cout << a <<    ; n   } n   std::cout <<   n ; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200010, P = 1000000007; n int n, q, a[maxn], b[maxn], w[maxn]; n __int128 c1[maxn], c2[maxn]; n void add(__int128 *c, int p, __int128 v) { n   for (; p <= n; p += p & -p) c[p] += v; n } n __int128 sum(__int128 *c, int p) { n   __int128 s = 0; n   for (; p; p -= p & -p) s += c[p]; n   return s; n } n int main() { n   scanf( %d %d , &n, &q); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]), b[i] = i - a[i]; n   } n   for (int i = 1; i <= n; i++) { n     scanf( %d , &w[i]); n     add(c1, i, w[i]), add(c2, i, 1LL * b[i] * w[i]); n   } n   while (q--) { n     int x, y; n     scanf( %d %d , &x, &y); n     if (x < 0) { n       x *= -1, add(c1, x, -w[x]), add(c2, x, -1LL * b[x] * w[x]); n       w[x] = y; n       add(c1, x, w[x]), add(c2, x, 1LL * b[x] * w[x]); n     } else { n       auto chk = [&](int st) { n         int l = x, r = y, p = x - 1; n         while (l <= r) { n           int mid = (l + r) >> 1; n           if (a[mid] <= st + mid - x) n             l = (p = mid) + 1; n           else n             r = mid - 1; n         } n         __int128 s = (st - x) * (sum(c1, p) - sum(c1, x - 1)) + sum(c2, p) - n                      sum(c2, x - 1); n         s -= (st - x) * (sum(c1, y) - sum(c1, p)) + sum(c2, y) - sum(c2, p); n         return s; n       }; n       int l0 = 1, r0 = 1000000000, ans; n       while (l0 <= r0) { n         int mid = (l0 + r0) >> 1; n         auto t1 = chk(mid), t2 = chk(mid + 1); n         if (t1 <= t2) n           ans = t1 % P, r0 = mid - 1; n         else n           l0 = mid + 1; n       } n       printf( %d n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int len = 0, k = 0, a[100005], p, q; n void findlength(long long int n, long long int mul) { n   if (n < 2) return; n   if (n % 2 == 0) { n     len += mul; n   } n   findlength(n / 2, 2 * mul); n } n void findans(long long int n, long long int l, long long int r) { n   if (n < 2) return; n   if (n % 2 == 0) { n     a[k] = (l + r) / 2; n     k++; n   } n   if (p > (l + r) / 2 - 1 || q < l) { n   } else n     findans(n / 2, l, (l + r) / 2 - 1); n   if (p > r || q < (l + r) / 2 + 1) { n   } else n     findans(n / 2, (l + r) / 2 + 1, r); n } n int main() { n   long long int n, l, r, i, left, right; n   cin >> n >> l >> r; n   l--; n   r--; n   p = l; n   q = r; n   findlength(n, 1); n   len += n; n   if (n == 0) len++; n   findans(n, 0, len - 1); n   sort(a, a + k); n   left = 0; n   while (left < k) { n     if (l > a[left]) n       left++; n     else n       break; n   } n   if (left >= k) left--; n   right = 0; n   while (right < k) { n     if (r > a[right]) n       right++; n     else n       break; n   } n   if (right >= k) right--; n   if (a[right] > r) right--; n   if (a[right] > r) right--; n   if (len == n || r < l) { n     cout << r - l + 1 << endl; n   } else { n     cout << (r - l + 1) - (right - left + 1) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ii = pair<int, int>; n using vi = vector<int>; n const int MAXN = 5 + 100000; n vector<int> g[MAXN], s; n bitset<MAXN> vis; n int k, pos[MAXN]; n void dfs(int u) { n   assert(int(g[u].size()) >= k); n   vis[u] = true; n   pos[u] = s.size(); n   s.push_back(u); n   int minp = 1e6; n   for (const int& v : g[u]) { n     if (!vis[v]) { n       dfs(v); n       return; n     } n     minp = min(minp, pos[v]); n   } n   cout << int(s.size()) - minp <<   n ; n   for (int i = minp; i < (int)s.size(); ++i) { n     cout << 1 + s[i] <<    ; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int n, m; n   cin >> n >> m >> k; n   while (m--) { n     int u, v; n     cin >> u >> v; n     g[--u].push_back(--v); n     g[v].push_back(u); n   } n   vis.reset(); n   s.reserve(1 + k); n   dfs(0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n const int N = 1e6 + 6; n struct segt { n   vector<int> t; n   int d; n   segt(vector<int> &a) { n     int n = a.size(); n     for (d = 2; d < n; d <<= 1) n       ; n     t.assign(d * 2, 0); n     for (int i = 0; i < n; ++i) t[i + d] = a[i]; n     for (int i = d - 1; i; --i) t[i] = min(t[i * 2], t[i * 2 + 1]); n   } n   int rmq(int i, int j) { n     int res = 1e9; n     for (i += d, j += d; i <= j; ++i >>= 1, --j >>= 1) { n       if (i & 1) res = min(res, t[i]); n       if (~j & 1) res = min(res, t[j]); n     } n     return res; n   } n }; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n, m; n   cin >> n; n   vector<pair<int, int>> s; n   set<int> u; n   for (int i = 0; i < n; ++i) { n     int l, r; n     cin >> l >> r; n     s.push_back({l, r}); n     u.insert(l); n     u.insert(r); n     u.insert(r + 1); n   } n   vector<int> t((u).begin(), (u).end()); n   vector<int> f(t.size()); n   for (auto p : s) { n     int l = p.first; n     int r = p.second; n     f[lower_bound((t).begin(), (t).end(), l) - t.begin()]++; n     f[lower_bound((t).begin(), (t).end(), r + 1) - t.begin()]--; n   } n   for (int i = 1; i < f.size(); ++i) f[i] += f[i - 1]; n   segt q(f); n   for (int k = 0; k < n; ++k) { n     int l = s[k].first; n     int r = s[k].second; n     int i = lower_bound((t).begin(), (t).end(), l) - t.begin(); n     int j = lower_bound((t).begin(), (t).end(), r) - t.begin(); n     if (q.rmq(i, j) != 1) { n       cout << k + 1 << endl; n       return 0; n     } n   } n   cout << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c; n   long long l; n   cin >> a >> b >> c >> l; n   long long ans = (l + 1) * (l + 3) * (l + 2) / 6; n   for (long long k = 0; k <= l; k++) { n     if (a + k >= b + c) { n       long long j = min(k, (a - b - c + k) / 2); n       ans = ans - (j + 1) * (j + 2) / 2; n     } n     if (b + k >= a + c) { n       long long j = min(k, (b - a - c + k) / 2); n       ans = ans - (j + 1) * (j + 2) / 2; n     } n     if (c + k >= b + a) { n       long long j = min(k, (c - b - a + k) / 2); n       ans = ans - (j + 1) * (j + 2) / 2; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int spf[100000 + 1]; n long long int const MAXN = 100001; n long long int modex(long long int x, long long int y, long long int p); n void getZarr(string str, long long int Z[]); n void sieve(); n vector<long long int> getFactorization(long long int x); n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long int a, b; n   cin >> a >> b; n   for (long long int x = 1; x < a; x++) { n     long long int temp = sqrt(a * a - x * x); n     if (temp * temp == a * a - x * x) { n       if ((b * x) % a == 0 && (b * temp) % a == 0) { n         if (x == -(b * temp) / a || temp == (b * x) / a) continue; n         cout <<  YES  <<   n ; n         cout << 0 <<     << 0 <<   n ; n         cout << x <<     << temp <<   n ; n         cout << -(b * temp) / a <<     << (b * x) / a <<   n ; n         return 0; n       } n     } n   } n   cout <<  NO  <<   n ; n } n void getZarr(string str, long long int Z[]) { n   Z[0] = 0; n   long long int n = str.length(); n   long long int L, R, k; n   L = R = 0; n   for (long long int i = 1; i < n; i++) { n     if (i > R) { n       L = R = i; n       while (R < n && str[R - L] == str[R]) R++; n       Z[i] = R - L; n       R--; n     } else { n       k = i - L; n       if (Z[k] < R - i + 1) n         Z[i] = Z[k]; n       else { n         L = i; n         while (R < n && str[R - L] == str[R]) R++; n         Z[i] = R - L; n         R--; n       } n     } n   } n } n long long int modex(long long int x, long long int y, long long int p) { n   long long int res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n void sieve() { n   spf[1] = 1; n   for (int i = 2; i < MAXN; i++) spf[i] = i; n   for (int i = 4; i < MAXN; i += 2) spf[i] = 2; n   for (int i = 3; i * i < MAXN; i++) { n     if (spf[i] == i) { n       for (int j = i * i; j < MAXN; j += i) n         if (spf[j] == j) spf[j] = i; n     } n   } n } n vector<long long int> getFactorization(long long int x) { n   vector<long long int> ret; n   while (x != 1) { n     ret.push_back(spf[x]); n     x = x / spf[x]; n   } n   return ret; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   vector<int> starts(m), ends(m), results; n   for (int i = 0; i < n; i++) { n     int l, r; n     cin >> l >> r; n     starts[l - 1]++; n     ends[r - 1]++; n   } n   int open = 0; n   for (int i = 0; i < m; i++) { n     open += starts[i]; n     if (open == 0) results.push_back(i + 1); n     open -= ends[i]; n   } n   std::cout << results.size() << std::endl; n   for (auto p : results) cout << p <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a; n stack<int> q; n vector<int> d; n void insert(int x) { n   if (q.empty()) { n     q.push(x); n     return; n   } n   if (q.top() != x) { n     q.push(x); n     return; n   } n   q.pop(); n   insert(x + 1); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a), insert(a); n   while (!q.empty()) d.push_back(q.top()), q.pop(); n   int k = d.size(); n   printf( %d n , k); n   for (int i = k - 1; i >= 0; i--) printf( %d%c , d[i], i ?     :   n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void _exit(string message) { n   if (message !=   ) cout << message << endl; n   exit(0); n } n template <typename T> n ostream &operator<<(ostream &out, const vector<T> &V) { n   if (!V.empty()) { n     out <<  [ ; n     for (auto v : V) out << v <<  ,  ; n     out <<   b b] ; n   } else n     out <<  [] ; n   return out; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   long long n, k, q = 998244353; n   cin >> n >> k; n   long long m = min(n + 1, k); n   vector<vector<int> > T(n + 1, vector<int>(m, 0)); n   vector<vector<int> > PT(n + 1, vector<int>(m, 0)); n   for (int j = 1; j < m; j++) PT[0][j] = T[0][j] = 2; n   T[1][1] = 2; n   for (int j = 1; j < m; j++) PT[1][j] = 2; n   for (int i = 2; i <= n; i++) PT[i][1] = T[i][1] = 2; n   for (int i = 2; i <= n; i++) { n     for (int j = 2; j < m; j++) { n       T[i][j] = (2 * T[i - 1][j]) % q; n       if (i >= j + 1) T[i][j] -= PT[i - 1 - j][j]; n       if (i >= j) T[i][j] += PT[i - j][j - 1]; n       if (T[i][j] < 0) T[i][j] += q; n       if (T[i][j] >= q) T[i][j] = T[i][j] % q; n       PT[i][j] = PT[i][j - 1] + T[i][j]; n       if (PT[i][j] >= q) PT[i][j] = PT[i][j] % q; n     } n   } n   for (int j = 0; j < m; j++) PT[0][j] = T[0][j] = 0; n   long long ans = 0; n   for (int i = 1; i < m; i++) n     ans += n         ((1ll * T[n][i] * PT[n][min(m - 1, (k - 1) / i)]) % q * (q + 1) / 2) % n         q; n   cout << ans % q << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int dp[303030][30]; n int u, v; n int in[303030]; n vector<int> adj[303030]; n char s[303030]; n int main() { n   scanf( %d %d , &n, &m); n   scanf( %s , s); n   for (int i = 0; i < m; ++i) { n     scanf( %d %d , &u, &v); n     --u; n     --v; n     adj[u].push_back(v); n     in[v]++; n   } n   queue<int> q; n   for (int i = 0; i < n; ++i) { n     if (in[i] == 0) { n       q.push(i); n     } n   } n   int cnt = 0; n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     ++cnt; n     dp[u][s[u] -  a ]++; n     for (int v : adj[u]) { n       if (--in[v] == 0) { n         q.push(v); n       } n       for (int i = 0; i < 26; ++i) { n         dp[v][i] = max(dp[v][i], dp[u][i]); n       } n     } n   } n   if (cnt == n) { n     int ans = 0; n     for (int i = 0; i < n; ++i) { n       for (int j = 0; j < 26; ++j) { n         ans = max(ans, dp[i][j]); n       } n     } n     printf( %d n , ans); n   } else { n     printf( -1 n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n const int N = 3e6 + 5; n int a[55][55], b[55][55], aa[55][55], bb[55][55]; n int row(int x, int y) { n   for (int i = 1; i <= x; i++) { n     int k = 1; n     for (int j = 2; j <= y; j++) { n       if (a[i][j] > a[i][k]) { n         k = j; n       } else n         return 0; n     } n   } n   for (int i = 1; i <= x; i++) { n     int k = 1; n     for (int j = 2; j <= y; j++) { n       if (b[i][j] > b[i][k]) { n         k = j; n       } else n         return 0; n     } n   } n   return 1; n } n int col(int x, int y) { n   for (int i = 1; i <= y; i++) { n     int k = 1; n     for (int j = 2; j <= x; j++) { n       if (a[j][i] > a[k][i]) { n         k = j; n       } else n         return 0; n     } n   } n   for (int i = 1; i <= y; i++) { n     int k = 1; n     for (int j = 2; j <= x; j++) { n       if (b[j][i] > b[k][i]) { n         k = j; n       } else n         return 0; n     } n   } n   return 1; n } n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       cin >> aa[i][j]; n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       cin >> bb[i][j]; n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       a[i][j] = min(aa[i][j], bb[i][j]); n       b[i][j] = max(aa[i][j], bb[i][j]); n     } n   } n   if (row(n, m) && col(n, m)) n     cout <<  Possible ; n   else n     cout <<  Impossible ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n multiset<long long> dd; n long long su; n long long revsum[100001]; n struct tab { n   long long l; n   long long d; n } arr[100001]; n long long findsumoftop(long long k) { n   long long ans = 0; n   multiset<long long>::iterator it = dd.begin(); n   while (k--) { n     if (it == dd.end()) { n       break; n     } else { n       ans += *it; n       it++; n     } n   } n   return -ans; n } n bool compare(const tab& t1, const tab& t2) { return t1.l < t2.l; } n int main() { n   long long n; n   cin >> n; n   for (long long i = 0; i < n; ++i) cin >> arr[i].l; n   for (long long i = 0; i < n; ++i) cin >> arr[i].d; n   sort(arr, arr + n, compare); n   for (long long i = n - 1; i >= 0; --i) revsum[i] = arr[i].d + revsum[i + 1]; n   long long st = 0; n   long long en = 1; n   long long ma = 300000000; n   while (st < n) { n     if (arr[st].l == arr[en].l) n       en++; n     else { n       long long matmp = (su - findsumoftop(en - st - 1) + revsum[en]); n       for (long long i = st; i < en; ++i) dd.insert(-arr[i].d), su += arr[i].d; n       ma = min(ma, matmp); n       st = en; n       en++; n     } n   } n   cout << ma << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 550005; n const long long mod = 998244353; n int n, u, v; n vector<int> g[N]; n long long dp[N][2][2]; n inline long long bin(long long x, long long k) { n   long long res = 1; n   while (k) { n     if (k & 1) res = res * x % mod; n     x = x * x % mod; n     k >>= 1; n   } n   return res; n } n vector<long long> pre, su; n inline void dfs(int v, int p = 0) { n   for (int i = 0; i < g[v].size(); ++i) { n     int to = g[v][i]; n     if (to == p) { n       swap(g[v][i], g[v].back()); n       g[v].pop_back(); n       break; n     } n   } n   for (int to : g[v]) { n     dfs(to, v); n   } n   int sz = g[v].size(); n   pre.resize(sz, 0); n   su.resize(sz, 0); n   for (int i = 0; i < sz; ++i) { n     int to = g[v][i]; n     pre[i] = (dp[to][1][0] + dp[to][0][0]) % mod; n     if (i) pre[i] = pre[i - 1] * pre[i] % mod; n   } n   for (int i = sz - 1; i >= 0; --i) { n     int to = g[v][i]; n     su[i] = (dp[to][0][0] + dp[to][1][0]) % mod; n     if (i + 1 < sz) su[i] = su[i] * su[i + 1] % mod; n   } n   long long s = 1; n   for (int to : g[v]) { n     s = s * dp[to][1][0] % mod; n   } n   dp[v][0][0] = 0; n   dp[v][0][1] = 1; n   dp[v][1][0] = s; n   dp[v][1][1] = 0; n   for (int i = 0; i < sz; ++i) { n     int to = g[v][i]; n     long long add = dp[to][0][1]; n     if (i - 1 >= 0) add = add * pre[i - 1] % mod; n     if (i + 1 < sz) add = add * su[i + 1] % mod; n     dp[v][0][0] += add; n     dp[v][0][0] %= mod; n   } n   (dp[v][1][0] += dp[v][0][0]) %= mod; n   for (int to : g[v]) { n     dp[v][0][1] = dp[v][0][1] * (dp[to][1][0] + dp[to][0][0]) % mod; n   } n } n vector<int> e[N]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (long long i = 1; i <= n - 1; ++i) { n     cin >> u >> v; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   int x = min(n, 3); n   dfs(x); n   cout << dp[x][1][0]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   long long n; n   cin >> t; n   for (int i = 0; i < t; i++) { n     cin >> n; n     if (n < 6) { n       cout << 15 << endl; n     } else if (n % 2 == 0) { n       cout << n / 2 * 5 << endl; n     } else { n       n++; n       cout << n / 2 * 5 << endl; n     } n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const int maxn = 1e4 + 5; n int n, k; n int a[maxn], b[maxn], c[maxn], dp1[maxn], dp2[maxn]; n int main() { n   scanf( %d%d , &n, &k); n   memset(dp1, -0x3f, sizeof(dp1)); n   memset(dp2, -0x3f, sizeof(dp2)); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= n; i++) scanf( %d , &b[i]); n   for (int i = 1; i <= n; i++) { n     c[i] = b[i] * k - a[i]; n   } n   dp1[0] = dp2[0] = 0; n   for (int i = 1; i <= n; i++) { n     if (c[i] >= 0) { n       for (int v = 10000; v >= c[i]; v--) n         dp1[v] = max(dp1[v], dp1[v - c[i]] + a[i]); n     } else { n       for (int v = 10000; v >= -c[i]; v--) n         dp2[v] = max(dp2[v], dp2[v + c[i]] + a[i]); n     } n   } n   int ans = 0; n   for (int i = 0; i <= 10000; i++) ans = max(ans, dp1[i] + dp2[i]); n   if (ans) n     printf( %d n , ans); n   else n     printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1e9 + 7; n long long powmod(long long a, long long b, long long mod) { n   long long res = 1; n   a %= mod; n   assert(b >= 0); n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res % mod; n } n const int N = 5e3 + 10; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int k; n   cin >> k; n   cout <<  2000 n ; n   for (int i = 1; i <= 1998; ++i) cout <<  0  ; n   int d = 1999 - k % 1999; n   int x = (k + d) / 1999; n   cout << -d <<     << x + d << endl; n   return 0; n } n


#include <bits/stdc++.h> n int dis[1048576]; n std::vector<int> node[1048576], rnode[1048576]; n int main() { n   int n, m, s, t; n   scanf( %d%d , &n, &m); n   while (m--) { n     int u, v; n     scanf( %d%d , &u, &v); n     node[u].push_back(v); n     rnode[v].push_back(u); n   } n   scanf( %d%d , &s, &t); n   memset(dis + 1, (int)0x7f7f7f7f, sizeof(int) * n); n   dis[t] = 0; n   std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >, n                       std::greater<std::pair<int, int> > > n       pq; n   pq.push(std::pair<int, int>(0, t)); n   while (!pq.empty()) { n     const int u = pq.top().second, cu = pq.top().first; n     pq.pop(); n     if (cu != dis[u]) continue; n     for (auto v : rnode[u]) { n       if (dis[v] <= dis[u]) continue; n       int max = 0, min = dis[v]; n       for (auto k : node[v]) { n         max = std::max(max, dis[k]); n         min = std::min(min, dis[k]); n       } n       const int cv = std::min(max, min + 1); n       if (cv < dis[v]) pq.push(std::pair<int, int>(dis[v] = cv, v)); n     } n   } n   printf( %d n , dis[s] == (int)0x7f7f7f7f ? -1 : dis[s]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5005; n const long long p = 1e9 + 7; n long long dp[N], dp1[N]; n long long modexp(long long a, long long b, long long p) { n   long long ans = 1LL; n   a %= p; n   while (b) { n     if (b & 1) ans = ans * a % p; n     b >>= 1; n     a = a * a % p; n   } n   return ans; n } n int main() { n   memset(dp, 0, sizeof(dp)); n   int n, k; n   scanf( %d%d , &n, &k); n   dp[0] = 1LL; n   for (int i = 1; i <= k; i++) { n     for (int j = 0; j < N; j++) { n       if (j) { n         dp1[j] += j * 1LL * dp[j]; n         dp1[j] %= p; n       } n       if (dp[j]) { n         dp1[j + 1] += (n - j) * 1LL * dp[j]; n         dp1[j + 1] %= p; n       } n     } n     for (int j = 0; j < N; j++) dp[j] = dp1[j]; n     memset(dp1, 0, sizeof(dp1)); n   } n   long long ans = 0; n   for (int i = 0; i <= min(n, N - 1); i++) n     ans = (ans + dp[i] * modexp(2, n - i, p) % p) % p; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n struct KMP { n   int n, at; n   string s; n   vector<int> nxt; n   vector<int> nxtdiff; n   void init(int _n) { n     n = _n, at = 0, s = string(n,  ? ), nxt = nxtdiff = vector<int>(n + 1, 0); n   } n   void add(char c) { n     s[at++] = c; n     int x = nxt[at - 1]; n     while (x != 0 && s[x] != c) x = nxt[x]; n     if (at >= 2 && s[x] == c) ++x; n     nxt[at] = x; n     nxtdiff[at - 1] = s[nxt[at - 1]] != c ? nxt[at - 1] : nxtdiff[nxt[at - 1]]; n   } n }; n struct RMQ { n   int n; n   vector<int> val; n   void init(int _n) { n     n = _n; n     val = vector<int>(4 * n, 0); n   } n   void _set(int x, int l, int r, int IDX, int VAL) { n     if (l == r) { n       val[x] = VAL; n     } else { n       int m = l + (r - l) / 2; n       if (IDX <= m) n         _set(2 * x + 1, l, m, IDX, VAL); n       else n         _set(2 * x + 2, m + 1, r, IDX, VAL); n       val[x] = min(val[2 * x + 1], val[2 * x + 2]); n     } n   } n   void set(int idx, int v) { _set(0, 0, n - 1, idx, v); } n   int _get(int x, int l, int r, int L, int R) { n     if (L <= l && r <= R) { n       return val[x]; n     } else { n       int m = l + (r - l) / 2, ret = INT_MAX; n       if (L <= m) ret = min(ret, _get(2 * x + 1, l, m, L, R)); n       if (m + 1 <= R) ret = min(ret, _get(2 * x + 2, m + 1, r, L, R)); n       return ret; n     } n   } n   int get(int l, int r) { return _get(0, 0, n - 1, l, r); } n }; n const int BASE = 1000000000; n const int BASEDIGITS = 9; n struct BigInt { n   vector<int> val; n   BigInt() {} n }; n void print(const BigInt &a) { n   if (((int)(a.val).size()) == 0) { n     printf( 0 ); n     return; n   } n   for (int i = ((int)(a.val).size()) - 1; i >= 0; --i) { n     if (i == ((int)(a.val).size()) - 1) n       printf( %d , a.val[i]); n     else n       printf( %0*d , BASEDIGITS, a.val[i]); n   } n } n BigInt operator+(const BigInt &a, unsigned long long b) { n   BigInt c = a; n   for (int i = 0; b > 0; ++i) { n     if (i >= ((int)(c.val).size())) c.val.push_back(0); n     b += c.val[i]; n     c.val[i] = b % BASE; n     b /= BASE; n   } n   return c; n } n BigInt operator+(const BigInt &a, const BigInt &b) { n   BigInt c; n   int carry = 0; n   for (int i = 0; n        i < ((int)(a.val).size()) || i < ((int)(b.val).size()) || carry > 0; n        ++i) { n     if (i < ((int)(a.val).size())) carry += a.val[i]; n     if (i < ((int)(b.val).size())) carry += b.val[i]; n     c.val.push_back(carry % BASE); n     carry /= BASE; n   } n   return c; n } n BigInt operator-(const BigInt &a, unsigned long long b) { n   BigInt c = a; n   for (int i = 0; b > 0; ++i) { n     assert(i < ((int)(c.val).size())); n     int cur = b % BASE; n     b /= BASE; n     if (cur <= c.val[i]) n       c.val[i] -= cur; n     else n       c.val[i] += BASE - cur, ++b; n   } n   while (((int)(c.val).size()) > 0 && c.val.back() == 0) c.val.pop_back(); n   return c; n } n int operator%(const BigInt &a, int b) { n   int ret = 0; n   for (int i = ((int)(a.val).size()) - 1; i >= 0; --i) n     ret = ((unsigned long long)ret * BASE + a.val[i]) % b; n   return ret; n } n int operator&(const BigInt &a, int b) { return (a % (1 << 30)) & b; } n struct RelaxableSet { n   BigInt sum; n   map<int, int> cnt; n   void init() { n     sum = BigInt(); n     cnt = map<int, int>(); n   } n   void relax(int lim) { n     int rem = 0; n     while (((int)(cnt).size()) > 0) { n       auto it = prev(cnt.end()); n       if (it->first <= lim) break; n       sum = sum - (unsigned long long)it->first * it->second, rem += it->second, n       cnt.erase(it); n     } n     if (rem > 0) cnt[lim] += rem, sum = sum + (unsigned long long)lim * rem; n   } n   void remove(int val) { n     auto it = cnt.find(val); n     assert(it != cnt.end()); n     if (it->second == 1) n       cnt.erase(it); n     else n       --it->second; n     sum = sum - val; n   } n   void add(int val) { n     ++cnt[val]; n     sum = sum + val; n   } n   void print() { n     for (auto it = cnt.begin(); it != cnt.end(); ++it) n       printf(  %d=%d , it->first, it->second); n     puts(  ); n   } n }; n const int MAXN = 600000; n const int MASK = (1 << 30) - 1; n int n; n char c[MAXN]; n int w[MAXN]; n BigInt ans[MAXN]; n KMP kmp; n RMQ rmq; n RelaxableSet have; n void solve() { n   kmp.init(n); n   rmq.init(n); n   have.init(); n   BigInt prv; n   for (int i = (0); i < (n); ++i) { n     char cc = (prv + (unsigned long long)(c[i] -  a )) % 26 +  a ; n     int ww = w[i] ^ (prv & MASK); n     kmp.add(cc); n     int len = i; n     while (len >= 1) { n       if (kmp.s[len] != cc) { n         int val = rmq.get(i - len, i - 1); n         have.remove(val); n         len = kmp.nxt[len]; n       } else { n         len = kmp.nxtdiff[len]; n       } n     } n     rmq.set(i, ww); n     have.relax(ww); n     if (cc == kmp.s[0]) have.add(ww); n     ans[i] = prv + have.sum; n     prv = ans[i]; n   } n } n void run() { n   scanf( %d , &n); n   for (int i = (0); i < (n); ++i) scanf(  %c%d , &c[i], &w[i]); n   solve(); n   for (int i = (0); i < (n); ++i) print(ans[i]), puts(  ); n } n int main() { n   run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int C = 20, A = 40; n int n, liq; n int dp[1 << C]; n long long k[A]; n int main() { n   scanf(  %d %d , &n, &liq); n   for (int i = 0; i < n; i++) n     for (int j = 0, first; j < n; j++) n       cin >> first, k[i] |= (long long)(first || i == j) << j; n   for (int i = 1; i < (1 << max(0, n - C)); i++) { n     int first = i; n     for (int j = 0; j < C; j++) n       if ((i >> j) & 1) first &= k[j + C] >> C; n     if (first == i) dp[i] = __builtin_popcount(i); n   } n   for (int i = 1; i < (1 << max(0, n - C)); i++) n     for (int j = 0; j < C; j++) n       if ((i >> j) & 1) dp[i] = max(dp[i], dp[i ^ (1 << j)]); n   int ans = 0; n   for (int i = 0; i < (1 << min(C, n)); i++) { n     int first = i, second = (1 << max(0, n - C)) - 1; n     for (int j = 0; j < min(C, n); j++) n       if ((i >> j) & 1) first &= k[j] & ((1 << C) - 1), second &= k[j] >> C; n     if (first != i) continue; n     ans = max(ans, __builtin_popcount(i) + dp[second]); n   } n   long double l = liq, a = ans; n   cout << fixed << setprecision(7) << (l * l * (a - 1)) / 2 / a << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<int64_t> A(8, 8); n   vector<int64_t> A_high(8, 0); n   vector<int64_t> B(8, 8); n   vector<int64_t> B_high(8, 8); n   int64_t amax = 8; n   int64_t bmax = 8; n   char k; n   for (int64_t i = 0; i < 8; i++) { n     for (int64_t j = 0; j < 8; j++) { n       cin >> k; n       if (k ==  B ) { n         if (B_high[j] > i) { n           B_high[j] = i; n         } n         B[j] = 7 - i; n       } else if (k ==  W ) { n         A_high[j] = i; n         if (A[j] > i) { n           A[j] = i; n         } n       } n     } n   } n   for (int64_t i = 0; i < 8; i++) { n     if (amax > A[i] && (B_high[i] > A[i])) { n       amax = A[i]; n     } n     if (bmax > B[i] && (A_high[i] < 7 - B[i])) { n       bmax = B[i]; n     } n   } n   if (amax <= bmax) { n     cout <<  A  << endl; n   } else { n     cout <<  B  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   map<string, int> mp; n   int n, m; n   cin >> n >> m; n   int same = 0; n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     mp[s] = 1; n   } n   for (int i = 0; i < m; i++) { n     string s; n     cin >> s; n     if (mp[s]) same++; n   } n   n = n - same; n   m = m - same; n   if (same % 2 == 1) n     n >= m ? cout <<  YES  : cout <<  NO ; n   else n     n > m ? cout <<  YES  : cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n long long fpow(long long b, long long x) { n   long long res = 1; n   while (x) { n     if (x & 1) res = (res * b) % MOD; n     b = (b * b) % MOD; n     x >>= 1; n   } n   return res; n } n long long c(long long k, long long r) { n   if (r < 0) return 0; n   if (r == 0) return 1; n   return c(k, r - 1) * (k - r + 1) % MOD * fpow(r, MOD - 2) % MOD; n } n int main() { n   long long n, m, g; n   cin >> n >> m >> g; n   if (m == 1) { n     if (n & 1) { n       if (g) n         cout << (n - 1) / 2 << endl; n       else n         cout << (n - 1) / 2 + 2 << endl; n     } else { n       if (g) n         cout << n / 2 + 1 << endl; n       else n         cout << n / 2 << endl; n     } n     return 0; n   } n   if (m == 0) { n     if (g == !(n & 1)) n       printf( 1 n ); n     else n       printf( 0 n ); n     return 0; n   } n   if (n == 0) { n     if (g) n       printf( 0 n ); n     else n       printf( 1 n ); n     return 0; n   } n   long long k = 1 + g; n   long long C = c(n + m - k, m - 1); n   long long ans = C; n   for (k = k + 2; k <= n + 1; k += 2) { n     C = C * (n - k + 2) % MOD * (n - k + 3) % MOD * n         fpow(n + m - k + 2, MOD - 2) % MOD * fpow(n + m - k + 1, MOD - 2) % MOD; n     ans = (ans + C) % MOD; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool chmax(T& a, const T& b) { n   if (a < b) { n     a = b; n     return 1; n   } n   return 0; n } n template <class T> n bool chmin(T& a, const T& b) { n   if (b < a) { n     a = b; n     return 1; n   } n   return 0; n } n template <typename T> n class Grid { n   struct Pos { n     int i, j; n     Pos(int i, int j) : i(i), j(j) {} n   }; n   int H, W; n   vector<vector<T>> G; n   vector<int> di8 = {1, 1, 0, -1, -1, -1, 0, 1}, n               dj8 = {0, 1, 1, 1, 0, -1, -1, -1}; n   vector<int> di4 = {1, 0, -1, 0}, dj4 = {0, 1, 0, -1}; n   vector<Pos> neighbor(int i, int j, const vector<int>& dis, n                        const vector<int>& djs) const { n     vector<Pos> res; n     for (int k = 0; k < dis.size(); ++k) { n       if (in(i + dis[k], j + djs[k])) res.emplace_back(i + dis[k], j + djs[k]); n     } n     return res; n   } n  n  public: n   static bool in(int H, int W, int i, int j) { n     return 0 <= i && i < H && 0 <= j && j < W; n   } n   Grid(int H, int W) : H(H), W(W) { G.resize(H, vector<T>(W)); } n   Grid(int H, int W, T zero) : H(H), W(W) { G.resize(H, vector<T>(W, zero)); } n   vector<T>& operator[](int i) { return G[i]; } n   bool in(int i, int j) const { return (0 <= i && i < H && 0 <= j && j < W); } n   vector<Pos> neighbor8(int i, int j) const { return neighbor(i, j, di8, dj8); } n   vector<Pos> neighbor4(int i, int j) const { return neighbor(i, j, di4, dj4); } n   int to1DIndex(int i, int j) { return i * W + j; } n   Pos to2DIndex(int i) { return Pos(i / W, i % W); } n   void scanFrom(istream& strm) { n     for (int i = 0; i < (int)(H); ++i) n       for (int j = 0; j < (int)(W); ++j) strm >> G[i][j]; n   } n   void outputTo(ostream& strm) { n     for (int i = 0; i < (int)(H); ++i) { n       for (int j = 0; j < (int)(W); ++j) cout << G[i][j]; n       strm << endl; n     } n   } n }; n template <typename T> n inline istream& operator>>(istream& strm, Grid<T>& g) { n   g.scanFrom(strm); n   return strm; n } n template <typename T> n inline ostream& operator<<(ostream& strm, Grid<T>& g) { n   g.outputTo(strm); n   return strm; n } n int n; n int X[1010][1010], Y[1010][1010]; n char ans[1010][1010]; n bool in(int i, int j) { return 0 <= i && i < n && 0 <= j && j < n; } n int di[4] = {1, 0, -1, 0}; n int dj[4] = {0, 1, 0, -1}; n int main() { n   cin >> n; n   for (int i = 0; i < (int)(n); ++i) n     for (int j = 0; j < (int)(n); ++j) { n       ans[i][j] =  ? ; n       scanf( %d %d , &X[i][j], &Y[i][j]); n       if (X[i][j] != -1) --X[i][j]; n       if (Y[i][j] != -1) --Y[i][j]; n     } n   unordered_map<int, unordered_map<int, char>> dir; n   dir[1][0] =  D ; n   dir[-1][0] =  U ; n   dir[0][1] =  R ; n   dir[0][-1] =  L ; n   function<void(int, int, int, int)> sink = [&](int i, int j, int x, int y) { n     for (int k = 0; k < (int)(4); ++k) { n       int ni = i + di[k], nj = j + dj[k]; n       if (!in(ni, nj)) continue; n       if (ans[ni][nj] !=  ? ) continue; n       if (X[ni][nj] != x || Y[ni][nj] != y) continue; n       ans[ni][nj] = dir[i - ni][j - nj]; n       sink(ni, nj, x, y); n     } n   }; n   for (int i = 0; i < (int)(n); ++i) n     for (int j = 0; j < (int)(n); ++j) { n       if (ans[i][j] !=  ? ) continue; n       if (X[i][j] == -1) { n         for (int k = 0; k < (int)(4); ++k) { n           int ni = i + di[k], nj = j + dj[k]; n           if (!in(ni, nj)) continue; n           if (X[ni][nj] != -1) continue; n           ans[i][j] = dir[ni - i][nj - j]; n           ans[ni][nj] = dir[i - ni][j - nj]; n           sink(i, j, -1, -1); n           sink(ni, nj, -1, -1); n         } n       } else { n         if (ans[X[i][j]][Y[i][j]] !=  ? ) break; n         if (X[X[i][j]][Y[i][j]] != X[i][j] || Y[X[i][j]][Y[i][j]] != Y[i][j]) n           break; n         ans[X[i][j]][Y[i][j]] =  X ; n         sink(X[i][j], Y[i][j], X[i][j], Y[i][j]); n       } n     } n   for (int i = 0; i < (int)(n); ++i) n     for (int j = 0; j < (int)(n); ++j) { n       if (ans[i][j] ==  ? ) { n         cout <<  INVALID  << endl; n         return 0; n       } n     } n   cout <<  VALID  << endl; n   for (int i = 0; i < (int)(n); ++i) { n     for (int j = 0; j < (int)(n); ++j) cout << ans[i][j]; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<string> vec_splitter(string s) { n   for (char& c : s) c = c ==  ,  ?     : c; n   stringstream ss; n   ss << s; n   vector<string> res; n   for (string z; ss >> z; res.push_back(z)) n     ; n   return res; n } n void debug_out(vector<string> args, int idx) { cerr << endl; } n template <typename Head, typename... Tail> n void debug_out(vector<string> args, int idx, Head H, Tail... T) { n   if (idx > 0) cerr <<  ,  ; n   stringstream ss; n   ss << H; n   cerr << args[idx] <<   =   << ss.str(); n   debug_out(args, idx + 1, T...); n } n void localTest() {} n const long long N = 2e5 + 5, MOD = 998244353; n long long A[N], fac[N], ifac[N]; n long long power(long long a, long long b, long long c) { n   long long ret = 1; n   while (b) { n     if (b & 1) { n       ret = (ret * a) % c; n     } n     b >>= 1; n     a = (a * a) % c; n   } n   return ret; n } n long long C(long long n, long long r) { n   if (n < r) { n     return 0; n   } n   long long ret = fac[n]; n   ret = (ret * ifac[r]) % MOD; n   ret = (ret * ifac[n - r]) % MOD; n   return ret; n } n int main() { n   localTest(); n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   fac[0] = ifac[0] = 1; n   for (long long i = 1; i < N; ++i) { n     fac[i] = (i * fac[i - 1]) % MOD; n     ifac[i] = power(fac[i], MOD - 2, MOD); n   } n   long long n, k; n   cin >> n >> k; n   for (long long i = 1; i <= n; ++i) { n     cin >> A[i]; n   } n   if (k == 1) { n     cout <<  0 n ; n     return 0; n   } n   long long ans = power(k, n, MOD), val = 0, fixed = 0, move = n, sum = 0; n   for (long long i = 1; i <= n; ++i) { n     if (A[i] == A[i % n + 1]) { n       fixed++; n       move--; n     } n   } n   val = power(k, fixed, MOD); n   for (long long i = 0; i <= move / 2; ++i) { n     long long mul = C(move, i) * C(move - i, i) % MOD; n     mul = (mul * power(k - 2, move - 2 * i, MOD)) % MOD; n     sum += mul; n     sum %= MOD; n   } n   val = (val * sum) % MOD; n   ans = (ans - val + MOD) % MOD; n   ans = (ans * power(2, MOD - 2, MOD)) % MOD; n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC optimize( Ofast,unroll-loops ) n const long long int MAXN = 4e3 + 20, md = 1e9 + 7, inf = 5e18; n int dp[MAXN][100][100], a[MAXN], ps[MAXN], sp[MAXN]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   memset(dp, -63, sizeof(dp)); n   long long int n, sq; n   cin >> n >> a[0]; n   ps[0] = a[0]; n   sq = ceil(sqrt(2 * n)); n   for (int i = 1; i < n; i++) { n     cin >> a[i]; n     ps[i] = ps[i - 1] + a[i]; n   } n   sp[n - 1] = a[n - 1]; n   for (int i = n - 2; i >= 0; i--) { n     sp[i] = sp[i + 1] + a[i]; n   } n   if (n == 1) { n     cout << a[0] <<   n ; n     return 0; n   } n   if (n == 2) { n     cout << a[0] + abs(a[1]) <<   n ; n     return 0; n   } n   if (n == 3) { n     int h = a[0] + a[1], q; n     q = -a[2] - abs(a[1]); n     cout << max(h, q + a[0]) <<   n ; n     return 0; n   } n   for (int i = n / 2 - 1; i >= 0; i--) { n     for (int k = 1; k <= sq; k++) { n       for (int j = 0; j <= k; j++) { n         int l = i, r = n - l - j - 1, h1, h2; n         if (r <= l) break; n         l += k; n         r -= k; n         if (r <= l) { n           r += k; n           if (l < r) { n             h1 = ps[l] - sp[r]; n           } else { n             l -= k; n             dp[i][k][j] = ps[l] - sp[r]; n             continue; n           } n         } else { n           h1 = dp[l][k][j]; n           r--; n           if (l < r) { n             h1 = min(h1, dp[l][k + 1][j + 1]); n           } n         } n         l = i; n         r = n - l - j - 1; n         l += k + 1; n         r -= k + 1; n         if (r <= l) { n           r += k + 1; n           if (l < r) { n             h2 = ps[l] - sp[r]; n           } else { n             dp[i][k][j] = h1; n             continue; n           } n         } else { n           h2 = dp[l][k + 1][j]; n           r--; n           if (l < r) { n             h2 = min(h2, dp[l][k + 2][j + 1]); n           } n         } n         dp[i][k][j] = max(h1, h2); n       } n     } n   } n   int h1 = min(dp[1][2][0], (dp[1][3][1] < -1e6 ? 500000000 : dp[1][3][1])), n       h2 = min(dp[0][1][0], dp[0][2][1]); n   cout << max(h1, h2) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double PI = 3.1415926535897932384626433832795; n const long double EPS = 1e-11; n pair<int, int> c1, c2, r1, r2; n int ans = 0; n long double dst(pair<int, int> a, pair<int, int> b) { n   return (a.first - b.first) * (a.first - b.first) + n          (a.second - b.second) * (a.second - b.second); n } n int main() { n   cout << setiosflags(ios::fixed) << setprecision(10); n   cin >> c1.first >> c1.second >> r1.first >> r1.second; n   cin >> c2.first >> c2.second >> r2.first >> r2.second; n   long double D = dst(c1, c2); n   if (D > r1.first * r1.first) { n     if ((sqrt(D) >= r1.first + r2.second) || (sqrt(D) + r1.first <= r2.first)) n       ans++; n   } else { n     if ((sqrt(D) + r2.second <= r1.first) || (sqrt(D) + r1.first <= r2.first)) n       ans++; n   } n   if (D > r2.first * r2.first) { n     if ((sqrt(D) >= r2.first + r1.second) || (sqrt(D) + r2.first <= r1.first)) n       ans++; n   } else { n     if ((sqrt(D) + r1.second <= r2.first) || (sqrt(D) + r2.first <= r1.first)) n       ans++; n   } n   if (D > r1.second * r1.second) { n     if ((sqrt(D) >= r1.second + r2.second) || (sqrt(D) + r1.second <= r2.first)) n       ans++; n   } else { n     if ((sqrt(D) + r2.second <= r1.second) || (sqrt(D) + r1.second <= r2.first)) n       ans++; n   } n   if (D > r2.second * r2.second) { n     if ((sqrt(D) >= r2.second + r1.second) || (sqrt(D) + r2.second <= r1.first)) n       ans++; n   } else { n     if ((sqrt(D) + r1.second <= r2.second) || (sqrt(D) + r2.second <= r1.first)) n       ans++; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int mx = 0; n string a, b; n string ba, bb; n int sum[123] = {}; n void solve(int last) { n   int cursum1[123]; n   int cursum2[123]; n   memcpy(cursum1, sum, sizeof sum); n   memcpy(cursum2, sum, sizeof sum); n   if (cursum1[last] == 0 || cursum2[(10 - last) % 10] == 0) { n     int mn = min(cursum1[0], cursum2[0]); n     if (mn == 0) return; n     if (mn > mx) { n       mx = mn; n       sort(ba.begin(), ba.end(), greater<char>()); n       sort(bb.begin(), bb.end(), greater<char>()); n     } n     return; n   } n   string na, nb; n   string zero; n   cursum1[last]--; n   cursum2[(10 - last) % 10]--; n   na += last +  0 ; n   nb += ((10 - last) % 10) +  0 ; n   int now = 1; n   for (;;) { n     bool fnd = false; n     for (int put = 0; put <= 9; put++) { n       int need = (9 - put) % 10; n       if (cursum1[put] > 0 && cursum2[need] > 0) { n         na += put +  0 ; n         nb += need +  0 ; n         cursum1[put]--; n         cursum2[need]--; n         fnd = true; n         break; n       } n     } n     if (fnd) n       ++now; n     else { n       int mn = min(cursum1[0], cursum2[0]); n       cursum1[0] -= mn; n       cursum2[0] -= mn; n       for (int i = 0; i < mn; i++) { n         zero +=  0 ; n       } n       now += mn; n       for (int put = 0; put <= 9; put++) { n         for (int u = 0; u < cursum1[put]; u++) na += put +  0 ; n       } n       for (int put = 0; put <= 9; put++) { n         for (int u = 0; u < cursum2[put]; u++) nb += put +  0 ; n       } n       break; n     } n   } n   if (now > mx) { n     mx = now; n     reverse(na.begin(), na.end()); n     reverse(nb.begin(), nb.end()); n     ba = na + zero; n     bb = nb + zero; n   } n } n void solveAll(string& str) { n   a = str; n   memset(sum, 0, sizeof sum); n   mx = 0; n   for (int i = 0; i < a.size(); i++) sum[a[i] -  0 ]++; n   ba = bb = a; n   for (int last = 1; last <= 9; last++) { n     solve(last); n   } n } n int parse(const string& str) { n   int ret = 0; n   for (int i = 0; i < str.size(); i++) { n     ret = ret * 10 + str[i] -  0 ; n   } n   return ret; n } n int count(int num) { n   int ret = 0; n   while (num) { n     if (num % 10 == 0) n       ++ret; n     else n       break; n     num /= 10; n   } n   return ret; n } n void test() { n   for (int i = 0; i < 1231; i++) { n     string ran; n     ran += (rand() % 9) + 1 +  0 ; n     int len = rand() % 6; n     ++len; n     for (int u = 1; u < len; u++) { n       ran += (rand() % 10) +  0 ; n     } n     solveAll(ran); n     int mx1 = 0; n     sort(ran.begin(), ran.end()); n     do { n       string ran2 = ran; n       sort(ran2.begin(), ran2.end()); n       do { n         int num1 = parse(ran); n         int num2 = parse(ran2); n         num1 += num2; n         int howmany = count(num1); n         mx1 = max(mx1, howmany); n       } while (next_permutation(ran2.begin(), ran2.end())); n     } while (next_permutation(ran.begin(), ran.end())); n     if (mx != mx1) { n       cout << ran <<    wrong  << endl; n       exit(0); n     } n   } n   cout <<  OK  << endl; n } n int main() { n   cin >> a; n   solveAll(a); n   cout << ba << endl << bb << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int l, r, k; n     cin >> l >> r >> k; n     if (k < l) { n       cout << k << endl; n     } else { n       cout << (r / k + 1) * k << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 500010; n int n, m; n char a[maxn], b[maxn]; n char s[maxn * 2], c[maxn * 3]; n int z[maxn * 3]; n int lcp[maxn]; n int lcs[maxn]; n void z_init(int len) { n   int l = 1, r = 1; n   z[1] = len; n   for (int i = 2; i <= len; i++) { n     if (i > r) { n       l = i; n       r = i; n       while (r <= len && c[r - i + 1] == c[r]) r++; n       z[i] = r - l; n       r--; n     } else { n       int k = i - l + 1; n       if (z[k] < r - i + 1) n         z[i] = z[k]; n       else { n         l = i; n         while (r <= len && c[r - i + 1] == c[r]) r++; n         z[i] = r - l; n         r--; n       } n     } n   } n } n void init() { n   for (int i = 1; i <= m; i++) c[i] = s[i]; n   c[m + 1] =  # ; n   for (int i = 1; i <= n; i++) c[m + 1 + i] = a[i]; n   c[n + m + 2] =   0 ; n   z_init(n + m + 1); n   for (int i = 1; i <= n; i++) lcp[i] = z[m + 1 + i]; n   for (int i = 1; i <= m; i++) c[i] = s[m + 1 - i]; n   c[m + 1] =  # ; n   for (int i = 1; i <= n; i++) c[m + 1 + i] = b[n + 1 - i]; n   c[n + m + 2] =   0 ; n   z_init(n + m + 1); n   for (int i = 1; i <= n; i++) lcs[i] = z[m + 1 + n + 1 - i]; n } n long long cnt[maxn * 2], sum[maxn * 2]; n int lowbit(int x) { return x & (-x); } n void add(int v) { n   int x = v; n   while (x <= n) sum[x] += v, cnt[x]++, x += lowbit(x); n } n void sub(int v) { n   int x = v; n   while (x <= n) sum[x] -= v, cnt[x]--, x += lowbit(x); n } n long long get_sum(int x) { n   long long res = 0; n   while (x) res += sum[x], x -= lowbit(x); n   return res; n } n long long get_cnt(int x) { n   long long res = 0; n   while (x) res += cnt[x], x -= lowbit(x); n   return res; n } n int main() { n   scanf( %d%d , &n, &m); n   scanf( %s%s%s , a + 1, b + 1, s + 1); n   init(); n   long long ans = 0; n   for (int i = 1; i <= min(n, m - 1); i++) add(max(1, m - lcs[i])); n   for (int i = 1, r; i <= n; i++) { n     r = min(m - 1, lcp[i]); n     ans += 1LL * (r + 1) * get_cnt(r) - get_sum(r); n     sub(max(1, m - lcs[i])); n     if (i + m - 1 <= n) add(max(1, m - lcs[i + m - 1])); n   } n   printf( %I64d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cin.tie(0); n   ios::sync_with_stdio(false); n   int t; n   cin >> t; n   int n, k; n   string s; n   while (t--) { n     cin >> n >> k >> s; n     vector<int> A(n + 1); n     for (int i = 0; i < (int)(n); i++) { n       if (s[i] ==  1 ) { n         A[max(0, i - k)]++; n         A[min(n - 1, i + k) + 1]--; n       } n     } n     for (int i = 0; i < (int)(n + 1); i++) { n       if (i > 0) A[i] += A[i - 1]; n     } n     int cnt = 0; n     int i = 0; n     while (i < n) { n       if (A[i] == 0) { n         cnt++; n         i += k + 1; n       } else n         i++; n     } n     cout << cnt << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double PI = 3.141592653589793238462643383279; n const double EPS = 1e-9; n const long long MOD = 1000000007; n const int inf = 1 << 30; n const long long linf = 1LL << 60; n int n; n int a[100]; n vector<pair<vector<int>, int> > v1, v2; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < (int)n; i++) scanf( %d , a + i); n   for (int i = 0; i < (int)(1 << 15); i++) { n     { n       int pre = __builtin_popcount((a[0] ^ i) & ((1 << 15) - 1)); n       vector<int> tmp; n       for (int k = 1; k < n; k++) { n         int now = __builtin_popcount((a[k] ^ i) & ((1 << 15) - 1)); n         tmp.push_back(pre - now); n         pre = now; n       } n       v1.push_back(pair<vector<int>, int>(tmp, i)); n       if (i == 3) { n       } n     } n     { n       int pre = __builtin_popcount((a[0] >> 15) ^ i); n       vector<int> tmp2; n       for (int k = 1; k < n; k++) { n         int now = __builtin_popcount((a[k] >> 15) ^ i); n         tmp2.push_back(now - pre); n         pre = now; n       } n       v2.push_back(pair<vector<int>, int>(tmp2, i * (1 << 15))); n     } n   } n   sort(v1.begin(), v1.end(), n        [](const pair<vector<int>, int>& l, const pair<vector<int>, int>& r) { n          for (int i = 0; i < (int)n - 1; i++) { n            if (l.first[i] < r.first[i]) return true; n            if (l.first[i] > r.first[i]) return false; n          } n          return l.second < r.second; n        }); n   sort(v2.begin(), v2.end(), n        [](const pair<vector<int>, int>& l, const pair<vector<int>, int>& r) { n          for (int i = 0; i < (int)n - 1; i++) { n            if (l.first[i] < r.first[i]) return true; n            if (l.first[i] > r.first[i]) return false; n          } n          return l.second < r.second; n        }); n   int pos = 0; n   for (pair<vector<int>, int>& p : v1) { n     while (pos < (int)v2.size()) { n       pair<vector<int>, int>& q = v2[pos]; n       bool ok = true; n       bool con = false; n       for (int i = 0; i < (int)n - 1; i++) { n         if (q.first[i] < p.first[i]) { n           pos++; n           ok = false; n           con = true; n           break; n         } n         if (q.first[i] > p.first[i]) { n           ok = false; n           break; n         } n       } n       if (ok) { n         printf( %d n , p.second + q.second); n         return 0; n       } n       if (!con) break; n     } n   } n   puts( -1 ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k, l, m, n, d, x = 0; n   cin >> k; n   cin >> l; n   cin >> m; n   cin >> n; n   cin >> d; n   int arr[] = {k, l, m, n}; n   for (int i = 1; i <= d; i++) { n     for (int j = 0; j < 4; j++) { n       if (i % arr[j] == 0) { n         x++; n         break; n       } n     } n   } n   cout << x; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, input; n   int count = 1; n   int s = 3; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &input); n     if (input == 10) { n       if (s == 1) { n         count++; n       } n       s = 0; n     } else if (input == 1) { n       if (s == 0) { n         count++; n       } n       s = 1; n     } n   } n   printf( %d , count); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int T; n   T = 1; n   while (T--) { n     string t, s, s1, s2; n     cin >> t; n     s = t; n     int i, j, x, l, a = 0; n     for (i = 0; i < t.length(); i++) { n       if (t[i] ==  a ) a = i; n     } n     for (i = 0; i < t.length(); i++) { n       if (t[i] ==  a ) { n         t.erase(i, 1); n         i--; n       } n     } n     l = t.length(); n     s1 = t.substr(0, l / 2); n     s2 = t.substr(l / 2, l - l / 2); n     if (s1 == s2) { n       for (i = 0, j = 0; j < s1.length();) { n         if (s[i] !=  a ) { n           i++; n           j++; n         } else n           i++; n       } n       while (s[i] ==  a ) { n         i++; n       } n       if (i > a) { n         s1 = s.substr(0, i); n         cout << s1 << endl; n       } else n         cout <<  :( n ; n     } else { n       cout <<  :( n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int p, x, y; n   cin >> p >> x >> y; n   for (int i = x; i >= y; i -= 50) { n     int t = ((i / 50) % 475); n     set<int> tr; n     for (int j = 0; j < 25; j++) { n       t = (t * 96 + 42) % 475; n       tr.insert(26 + t); n     } n     if (tr.find(p) != tr.end()) { n       cout <<  0 n  <<   n ; n       return 0; n     } n   } n   for (int i = x;; i += 50) { n     int t = ((i / 50) % 475); n     set<int> tr; n     for (int j = 0; j < 25; j++) { n       t = (t * 96 + 42) % 475; n       tr.insert(26 + t); n     } n     if (tr.find(p) != tr.end()) { n       (i - x) % 100 == 0 ? cout << (i - x) / 100 n                          : cout << (i - x) / 100 + 1 <<   n ; n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i = 2, c = 0, v = 1; n   cin >> n; n   int x = 5; n   while (n - x > 0) { n     n = n - x; n     x = x * 2; n     v = v * 2; n   } n   while (n - v >= 1) { n     n = n - v; n     c++; n   } n   if (c + 1 == 1) { n     cout <<  Sheldon ; n   } n   if (c + 1 == 2) { n     cout <<  Leonard ; n   } n   if (c + 1 == 3) { n     cout <<  Penny ; n   } n   if (c + 1 == 4) { n     cout <<  Rajesh ; n   } n   if (c + 1 == 5) { n     cout <<  Howard ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e5 + 520; n long long A[N]; n long long dp[N]; n long long maxl[N]; n long long n, m; n long long get(long long x, long long y) { n   if (x == 0) return N - 1; n   return (x - 1) * m + y; n } n int main() { n   cin >> n >> m; n   A[N - 1] = 0; n   for (long long i = 1; i <= n * m; i++) cin >> A[i]; n   for (long long i = 1; i <= m; i++) n     for (long long j = 1; j <= n; j++) { n       if (j == 1) { n         long long a = get(j, i); n         dp[a] = 1; n         maxl[j] = max(maxl[j], 1ll); n         continue; n       } n       long long a = get(j, i); n       long long b = get(j - 1, i); n       long long xia = A[a]; n       long long shang = A[b]; n       if (xia >= shang) { n         dp[a] = dp[b] + 1; n         maxl[j] = max(maxl[j], dp[a]); n       } else { n         dp[a] = 1; n         maxl[j] = max(maxl[j], dp[a]); n       } n     } n   long long t; n   cin >> t; n   while (t--) { n     long long l, r; n     cin >> l >> r; n     if (r - maxl[r] + 1 <= l) { n       cout <<  Yes  << endl; n       continue; n     } n     cout <<  No  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n ifstream F( p.in ); n const int M = 1000000007; n const int K = 110; n const int N = 100100; n int dp[K][N], b[N], c[N][K]; n int n, m; n void add(int &x, int y) { x = ((x + y) % M + M) % M; } n int main() { n   ios::sync_with_stdio(0); n   for (int n = 0; n < N; ++n) { n     c[n][0] = 1; n     for (int k = 1; k <= min(n, K - 1); ++k) n       c[n][k] = (c[n - 1][k - 1] + c[n - 1][k]) % M; n   } n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) cin >> b[i]; n   for (int tt = 1, l, r, k; tt <= m; ++tt) { n     cin >> l >> r >> k; n     add(dp[k][l], 1); n     for (int i = 0; i <= k; ++i) n       add(dp[i][r + i + 1], -c[r - l + k + 1][k - i]); n   } n   for (int k = 100; k >= 0; --k) n     for (int i = 1; i <= n; ++i) { n       if (k > 0) add(dp[k - 1][i], dp[k][i]); n       add(dp[k][i + 1], dp[k][i]); n     } n   for (int i = 1; i <= n; ++i) cout << (dp[0][i] + b[i]) % M <<    ; n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, a[100100], b[100100]; n long long ans; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) scanf( %d , &a[i]); n   for (int i = 0; i < m; i++) scanf( %d , &b[i]); n   sort(a, a + n); n   sort(b, b + m, greater<int>()); n   n = min(n, m); n   for (int i = 0; i < n and a[i] < b[i]; i++) { n     ans += b[i] - a[i]; n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k; n long long c2(long long n) { return n * (n - 1) / 2; } n void solve(long long x, long long y) { n   if (x == 0) return; n   if (y + 1 >= x) { n     cout <<  ( ; n     solve(x - 1, y - x + 1); n     cout <<  ) ; n     return; n   } else { n     cout <<  () ; n     solve(x - 1, y); n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cout.tie(0); n   cin >> n >> k; n   if (c2(n) < k) { n     cout <<  Impossible ; n     return 0; n   } n   solve(n, k); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 150100; n long long n, m, l, r; n long long P; n vector<int> p; n long long sum; n long long _dfs(long long d, long long x, long long y) { n   if (d == p.size()) { n     long long n = abs(y / x); n     sum += n * (n + 1) / 2 * x; n     return y / x; n   } n   return (_dfs(d + 1, x, y) + _dfs(d + 1, -x * p[d], y)); n } n int gcdnumber(long long a, long long y) { n   p.clear(); n   for (long long i = 2; i * i <= a; i++) { n     if (a % i == 0) { n       p.push_back(i); n       while (a % i == 0) a /= i; n     } n   } n   sum = 0; n   if (a != 1) p.push_back(a); n   return _dfs(0, 1, y); n } n long long calc(long long radiu, int add) { n   long long y = radiu; n   long long ret = 0; n   for (long long i = 1; i <= radiu; i++) { n     while (y && i * i + y * y > radiu * radiu - add) y--; n     if (y >= m) y = m; n     if (i <= n && y > 0) { n       long long tmp = gcdnumber(i, y); n       ret += (n - i + 1) * (tmp * (m + 1) - sum); n       ret %= P; n     } n   } n   return ret; n } n int main() { n   cin >> n >> m; n   cin >> l >> r >> P; n   long long ans = 0; n   if (l == 1) ans = n * (m + 1) + m * (n + 1); n   ans %= P; n   ans += (calc(r, 0) - calc(l, 1)) * 2; n   while (ans < 0) ans += P; n   ans %= P; n   cout << ans << endl; n } n


#include<bits/stdc++.h> n using namespace std; n typedef long long ll; n typedef long double lf; n typedef unsigned long long ull; n typedef pair<ll,int>P; n const int inf = 0x7f7f7f7f; n const ll INF = 1e16; n const int N = 2e5+10; n const ull base = 131; n const ll mod =  1e9+7; n const double PI = acos(-1.0); n const double eps = 1e-4; n  n inline int read(){int x=0,f=1;char ch=getchar();while(ch< 0 ||ch> 9 ){if(ch== - )f=-1;ch=getchar();}while(ch>= 0 &&ch<= 9 ){x=x*10+ch- 0 ;ch=getchar();}return x*f;} n inline string readstring(){string str;char s=getchar();while(s==   ||s==  n ||s==  r ){s=getchar();}while(s!=   &&s!=  n &&s!=  r ){str+=s;s=getchar();}return str;} n int random(int n){return (int)(rand()*rand())%n;} n void writestring(string s){int n = s.size();for(int i = 0;i < n;i++){printf( %c ,s[i]);}} n  n  n int a[N]; n int b[N],c[N]; n  n void solve(){ n     int n = read(); n     memset(b,0,sizeof b); n     memset(c,0,sizeof c); n     set<int>st1,st2; n     for(int i = 1;i <= n;i++){ n         st1.insert(i); n         st2.insert(i); n     } n     for(int i = 1;i <= n;i++){ n         a[i] = read(); n     } n     b[1] = c[1] = a[1]; n     st1.erase(a[1]); n     st2.erase(a[1]); n     for(int i = 2;i <= n;i++){ n         if(a[i] != a[i-1]){ n             b[i] = c[i] = a[i]; n             st1.erase(a[i]); n             st2.erase(a[i]); n         } n     } n  n  n     for(int i = 1;i <= n;i++){ n         if(b[i] == 0){ n             int x = *st1.begin(); n             b[i] = x; n             //cout<<x<<endl; n             st1.erase(x); n         } n  n         if(c[i] == 0){ n             auto it = st2.upper_bound(c[i-1]); n             it--; n             c[i] = *it; n             st2.erase(c[i]); n         } n  n     } n  n  n     for(int i = 1;i <= n;i++){ n         printf( %d  ,b[i]); n     } n     puts(  ); n     for(int i = 1;i <= n;i++){ n         printf( %d  ,c[i]); n     } n     puts(  ); n  n } n int main(){ n     int t = read(); n     while(t--){ n         solve(); n     } n     return 0; n } n  n


#include <bits/stdc++.h> n using namespace std; n map<int, int> mm; n int mv[100000] = {0}; n int bfs(int n, int m) { n   queue<int> mq; n   mq.push(n); n   mv[n] = 0; n   while (!mq.empty()) { n     int r = mq.front(); n     if (r == m) return mv[r]; n     mq.pop(); n     int x, y; n     x = r - 1; n     y = r * 2; n     if (x > 0 && x < 10001 && mv[x] == 0) { n       mv[x] = mv[r] + 1; n       mq.push(x); n     } n     if (y > 0 && y < 10001 && mv[y] == 0) { n       mv[y] = mv[r] + 1; n       mq.push(y); n     } n   } n } n int main() { n   int n, m; n   cin >> n >> m; n   int k = bfs(n, m); n   cout << k << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using pll = pair<ll, ll>; n using dd = long double; n namespace { n static bool constexpr dbg = 0; n ll constexpr N = -999; n ll n, k; n bool ok(string const &s1, string const &s2) { n   do { n     if (dbg) { n       bool b = (s1.size() == s2.size() + 1); n       if (!b) n         cerr <<  s1.size() == s2.size() + 1  n              <<  : failed! n ; n     } n   } while (0); n   if (s1.size() != s2.size()) return s1.size() > s2.size(); n   for (int i = 0; i < n; ++i) n     if (s1[i] != s2[i]) return s1[i] > s2[i]; n   return true; n } n string solve() { n   string s; n   cin >> n >> k >> s; n   cout << n <<   n ; n   auto sub = s.substr(0, k); n   while (sub.size() < n) sub.push_back(sub[sub.size() - k]); n   if (ok(sub, s)) return sub; n   int i = k - 1; n   for (; i >= 0; --i) n     if (s[i] !=  9 ) break; n   ++s[i]; n   for (++i; i < k; ++i) s[i] =  0 ; n   for (int j = k; j < n; ++j) s[j] = s[j - k]; n   return s; n } n }  // namespace n int main() { n   if (!dbg) { n     std::ios::sync_with_stdio(0); n     cin.tie(0); n     cout.tie(0); n   } n   cout << fixed << setprecision(20); n   cout << solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, x, sum; n vector<long long> my, temp; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(); n   cout.tie(); n   cin >> n; n   for (long long i = 0; i < n; i++) { n     cin >> x; n     my.push_back(x); n     temp.push_back(x); n   } n   for (long long i = 0; i < n; i++) my.push_back(temp[i]); n   long long maxi = 0; n   for (long long i = 0; i < my.size(); i++) { n     if (my[i] == 1) { n       sum++; n       maxi = max(maxi, sum); n     } else n       sum = 0; n   } n   cout << maxi << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   if (n <= 4) n     cout <<  No solution  << endl; n   else { n     double alpha = 2 * M_PI / n; n     cout << fixed << setprecision(6); n     double x = 0, y = 0; n     for (int i = 1; i <= n - 2; i++) { n       cout << x <<     << y << endl; n       double l = 500; n       l += 0.01 * i; n       x += l * cos(alpha * i), y += l * sin(alpha * i); n     } n     cout << x <<     << y << endl; n     x -= y / sin(alpha * (n - 1)) * cos(alpha * (n - 1)), y = 0; n     cout << x <<     << y << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   vector<int> ans; n   if (k == 1) { n     printf( %d n , n); n     return 0; n   } n   for (int i = 2; i * i <= n; i++) { n     while (n % i == 0) { n       n /= i; n       ans.push_back(i); n       if (((int)ans.size()) == k - 1) break; n     } n     if (((int)ans.size()) == k - 1) break; n   } n   if (n == 1 || ((int)ans.size()) != k - 1) { n     puts( -1 ); n     return 0; n   } n   ans.push_back(n); n   for (int x : ans) printf( %d  , x); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void Debug(vector<int> v) { n   for (int i : v) { n     cerr << i <<    ; n   } n } n void Debug(int a[]) { n   for (int i = 0; i < 5; i++) { n     cerr << a[i] <<    ; n   } n } n void Debug(int a) { cerr << a; } n void Debug(string a) { cerr << a; } n void Debug(long long a) { cerr << a; } n void Debug(unsigned long long a) { cerr << a; } n void Debug(float a) { cerr << a; } n void Debug(double a) { cerr << a; } n void Debug(char a) { cerr << a; } n int32_t main() { n   int64_t l; n   cin >> l; n   int64_t a, b; n   cin >> a >> b; n   int64_t speed = a + b; n   double time = (double)l / speed; n   cout << time * a; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long MOD = 1e9 + 7; n long long MAX = 1e17; n bool b[1000]; n int main() { n   ios_base::sync_with_stdio(0); n   ; n   int m, t, r, ans = 0; n   cin >> m >> t >> r; n   int w[m]; n   for (int i = 0; i < m; i++) cin >> w[i]; n   if (r > t) { n     cout << -1 << endl; n     return 0; n   } n   for (int i = 0; i < m; i++) w[i] += t + 10; n   for (int i = 0; i < m; i++) { n     int k = r; n     for (int j = w[i] - t; j < w[i]; j++) n       if (b[j]) k--; n     if (k <= 0) continue; n     for (int j = w[i] - 1; j > w[i] - t - 1; j--) { n       if (!b[j]) { n         b[j] = 1; n         k--; n         ans++; n       } n       if (k == 0) break; n       if (j == w[i] - t) { n         cout << -1 << endl; n         return 0; n       } n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 1; n vector<int> e[N]; n int s[N], seg[N << 2], num[N << 2], chg[N << 2], dfn[N][2], dfsns[N], n     sgn[N] = {-1}, stamp; n void dfs(int now, int pre) { n   dfn[now][0] = ++stamp; n   dfsns[stamp] = now; n   sgn[dfn[now][0]] = sgn[dfn[pre][0]] == 1 ? -1 : 1; n   for (int i = 0; i < e[now].size(); i++) n     if (e[now][i] != pre) dfs(e[now][i], now); n   dfn[now][1] = stamp; n } n void pushup(int rt) { seg[rt] = seg[rt << 1] + seg[rt << 1 | 1]; } n void pushdown(int rt, int l, int r) { n   if (chg[rt]) { n     seg[rt << 1] += num[rt << 1] * chg[rt]; n     seg[rt << 1 | 1] += num[rt << 1 | 1] * chg[rt]; n     chg[rt << 1] += chg[rt]; n     chg[rt << 1 | 1] += chg[rt]; n     chg[rt] = 0; n   } n } n void build(int l, int r, int rt) { n   if (l == r) { n     seg[rt] = s[dfsns[l]]; n     num[rt] = sgn[l]; n     return; n   } n   int m = l + r >> 1; n   build(l, m, rt << 1); n   build(m + 1, r, rt << 1 | 1); n   num[rt] = num[rt << 1] + num[rt << 1 | 1]; n   pushup(rt); n } n void update(int l, int r, int rt, int L, int R, int v) { n   if (L <= l && r <= R) { n     seg[rt] += num[rt] * v; n     chg[rt] += v; n     return; n   } n   int m = l + r >> 1; n   pushdown(rt, l, r); n   if (L <= m) update(l, m, rt << 1, L, R, v); n   if (m < R) update(m + 1, r, rt << 1 | 1, L, R, v); n   pushup(rt); n } n int query(int l, int r, int rt, int p) { n   if (l == r) return seg[rt]; n   int m = l + r >> 1; n   pushdown(rt, l, r); n   if (p <= m) n     return query(l, m, rt << 1, p); n   else n     return query(m + 1, r, rt << 1 | 1, p); n } n int main() { n   ios::sync_with_stdio(0); n   int n, k; n   cin >> n >> k; n   for (int i = 1; i <= n; i++) cin >> s[i]; n   for (int i = 1; i < n; i++) { n     int tmp1, tmp2; n     cin >> tmp1 >> tmp2; n     e[tmp1].push_back(tmp2); n     e[tmp2].push_back(tmp1); n   } n   dfs(1, 0); n   build(1, n, 1); n   for (int i = 0; i < k; i++) { n     int op, tmp1, tmp2; n     cin >> op; n     if (op == 1) { n       cin >> tmp1 >> tmp2; n       update(1, n, 1, dfn[tmp1][0], dfn[tmp1][1], sgn[dfn[tmp1][0]] * tmp2); n     } else { n       cin >> tmp1; n       cout << query(1, n, 1, dfn[tmp1][0]) << endl; n     } n   } n   return 0; n } n


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


#include <bits/stdc++.h> n const long double eps = 0.00000001; n const long long MOD = 1e9 + 7; n const double PI = 3.141592653589793238463; n using namespace std; n long long ans; n int was[1010][1010]; n int main() { n   fflush(stdin); n   cout << fixed, cout.precision(18); n   ios_base::sync_with_stdio(false); n   int i, j, n, m; n   cin >> n >> m; n   string second[n]; n   for (i = 0; i < n; ++i) cin >> second[i]; n   vector<pair<pair<int, int>, int>> ve; n   for (i = 1; i < n - 1; ++i) { n     for (j = 1; j < m - 1; ++j) { n       if (second[i][j] ==  . ) continue; n       int max_len = min(min(i, n - i - 1), min(j, m - j - 1)); n       if (max_len == 0) continue; n       int x = i, y = j; n       for (int len = 1; len <= max_len; ++len) { n         if (second[i + len][j] ==  *  && second[i - len][j] ==  *  && n             second[i][j - len] ==  *  && second[i][j + len] ==  * ) { n           was[i][j] = 1; n           was[i + len][j] = was[i - len][j] = was[i][j - len] = n               was[i][j + len] = 1; n           if (len == max_len) ve.push_back({{i + 1, j + 1}, len}); n           continue; n         } n         if (len - 1 > 0) ve.push_back({{i + 1, j + 1}, len - 1}); n         break; n       } n     } n   } n   bool b = true; n   for (i = 0; i < n; ++i) n     for (j = 0; j < m; ++j) n       if (second[i][j] ==  *  && !was[i][j]) b = false; n   if (!b) return cout << -1, 0; n   cout << ve.size() << endl; n   for (i = 0; i < ve.size(); ++i) { n     printf( %d %d %d n , ve[i].first.first, ve[i].first.second, ve[i].second); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5e5 + 5; n int n, k, a[maxn], b[maxn]; n void work(long long g); n long long as, ct; n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %d , a + i); n   for (int i = 1; i <= n; i++) scanf( %d , b + i); n   long long l = 0, r = 1e12, mid, ot; n   while (l < r) { n     work(mid = l + r >> 1); n     if (ct >= k) n       r = mid, ot = mid; n     else n       l = mid + 1; n   } n   work(ot), printf( %lld n , as + 2 * k * ot); n   return 0; n } n void work(long long g) { n   priority_queue<pair<long long, int> > q; n   as = ct = 0; n   long long tp; n   for (int i = 1; i <= n; i++) { n     q.push({g - a[i], 1}); n     if ((tp = b[i] - q.top().first - g) <= 0) { n       as += tp, ct += q.top().second, q.pop(), q.push({b[i] - g, 0}); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void IO(T &x) { n   char c = getchar(); n   T sgn = 1; n   while (c <  0  || c >  9 ) { n     if (c ==  - ) sgn = -1; n     c = getchar(); n   } n   x = 0; n   while (c >=  0  && c <=  9 ) { n     x = (T)(x << 1) + (x << 3) + c -  0 ; n     c = getchar(); n   } n   x *= sgn; n } n template <class T> n T POW(T b, T push) { n   T res = 1; n   while (push > 0) { n     if (push & 1) res *= b; n     push >>= (1ll), b *= b; n   } n   return res; n } n template <class T> n T bMOD(T a, T push, T m) { n   if (push == 0) return (T)1; n   if (!(push & 1)) { n     T temp = bMOD(a, push / 2, m); n     return ((temp % m) * (temp % m)) % m; n   } n   return ((a % m) * (bMOD(a, push - 1, m) % m)) % m; n } n template <class T> n T inMOD(T a, T m) { n   return bMOD(a, m - 2, m); n } n template <class T> n bool isPrime(T n) { n   for (T i = 2; i * i <= n; i++) { n     if (n % i == 0) return false; n   } n   return true; n } n template <class T> n string toString(T n) { n   stringstream second; n   string num; n   second << n; n   second >> num; n   return num; n } n template <class T> n T sq(T n) { n   return (n * n); n } n template <class T> n T gcd(T a, T b) { n   return (b == 0) ? a : gcd(b, a % b); n } n template <class T> n T lcm(T a, T b) { n   return (a / gcd(a, b)) * b; n } n bool iseq(double a, double b) { return fabs(a - b) < 1e-9; } n template <class T> n T toDeg(T x) { n   return (180.0 * x) / ((T)acos(-1.0)); n } n template <class T> n T toReg(T x) { n   return (x * (T)acos(-1.0)) / (180.0); n } n template <class T> n double _distance(T x1, T y1, T x2, T y2) { n   return 1.0 * sqrt(sq(x1 - x2) + sq(y1 - y2)); n } n int kx[] = {-2, -2, +2, +2, +1, -1, +1, -1}; n int ky[] = {+1, -1, +1, -1, -2, -2, +2, +2}; n int dx[] = {+0, +0, -1, +1, +1, +1, -1, -1}; n int dy[] = {+1, -1, +0, +0, -1, +1, +1, -1}; n int x[] = {+0, +0, +1, -1}; n int y[] = {+1, -1, +0, +0}; n int main() { n   int h1, m1, h2, m2; n   scanf( %d:%d , &h1, &m1); n   scanf( %d:%d , &h2, &m2); n   int hour = h1 * 60 + h2 * 60 + m1 + m2; n   hour /= 2; n   int hm = hour / 60; n   int mm = hour % 60; n   if (hm < 10) { n     printf( 0%d: , hm); n   } else { n     printf( %d: , hm); n   } n   if (mm < 10) { n     printf( 0%d n , mm); n   } else { n     printf( %d n , mm); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10; n pair<int, int> A[N]; n int factorial[N]; n int twos[N]; n int main() { n   ios::sync_with_stdio(false); n   int n; n   cin >> n; n   for (int i = (int)0; i < (int)2 * n; i++) { n     cin >> A[i].first; n     A[i].second = i % n; n   } n   sort(A, A + 2 * n); n   int MOD; n   cin >> MOD; n   factorial[0] = 1; n   twos[0] = 0; n   for (int i = (int)1; i < (int)2 * n + 1; i++) { n     if (i % 2 == 0) n       twos[i] = 1 + twos[i / 2]; n     else n       twos[i] = 0; n     int ti = i; n     while (ti % 2 == 0) ti /= 2; n     factorial[i] = (ti * (long long int)factorial[i - 1]) % MOD; n   } n   for (int i = (int)0; i < (int)2 * n; i++) twos[i + 1] += twos[i]; n   n *= 2; n   int ans = 1; n   for (int i = 0; i < n;) { n     int endi = i; n     while (endi < n and A[endi].first == A[i].first) endi++; n     int numduplicates = 0; n     for (int j = (int)i; j < (int)endi; j++) n       if (j + 1 < endi and A[j].second == A[j + 1].second) numduplicates++; n     int len = endi - i; n     ans = (ans * (long long int)factorial[len]) % MOD; n     int ntwos = twos[len] - numduplicates; n     for (int x = (int)0; x < (int)ntwos; x++) { n       ans = (ans * 2) % MOD; n     } n     i = endi; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int power(long long int a, long long int b) { n   if (b == 0) return 1; n   long long int p = power(a, b / 2); n   if (b % 2 == 0) n     return p * p; n   else n     return a * p * p; n } n long int gcd(long int a, long int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n int main() { n   std::ios_base::sync_with_stdio(false); n   long long int n, i, j, k, c = 0; n   cin >> n; n   int a[n]; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n   } n   vector<long int> fac; n   for (i = 1; i <= sqrt(n); i++) { n     if (n % i == 0) { n       if (i > 2) fac.push_back(i); n       if (n != i * i) fac.push_back(n / i); n     } n   } n   for (i = 0; i < fac.size(); i++) { n     for (j = 0; j < n / fac[i]; j++) { n       c = 0; n       for (k = j; k < n; k += n / fac[i]) { n         if (a[k] != 1) n           break; n         else n           c++; n       } n       if (c == fac[i]) break; n     } n     if (j != n / fac[i]) break; n   } n   if (i != fac.size()) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n int N, M, A, B; n char table[60][60]; n int rows[60]; n int cols[60]; n int solve() { n   scanf( %d%d%d%d , &N, &M, &A, &B); n   if (A * N != B * M) { n     puts( NO ); n     return 0; n   } n   memset(table, 0, sizeof(table)); n   memset(rows, 0, sizeof(rows)); n   memset(cols, 0, sizeof(cols)); n   std::vector<std::pair<int, int>> sorted_cols; n   for (int i = 0; i < N; ++i) { n     for (int j = 0; j < M; ++j) { n       table[i][j] =  0 ; n     } n     sorted_cols.clear(); n     for (int j = 0; j < M; ++j) { n       sorted_cols.push_back(std::make_pair(cols[j], j)); n     } n     std::sort(sorted_cols.begin(), sorted_cols.end()); n     for (int j = 0; j < A; ++j) { n       int col_index = sorted_cols[j].second; n       int col_value = sorted_cols[j].first; n       if (col_value >= B) { n         puts( NO ); n         return 0; n       } n       table[i][col_index] =  1 ; n       ++rows[i]; n       ++cols[col_index]; n     } n   } n   puts( YES ); n   for (int i = 0; i != N; ++i) { n     puts(table[i]); n   } n   return 0; n } n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n int main(int argc, char const *argv[]) { n   string a; n   cin >> a; n   long long n = a.length(); n   char p[n]; n   p[0] = a[0]; n   long long i; n   for (i = 1; i < n; i++) p[i] = (p[i - 1] > a[i]) ? a[i] : p[i - 1]; n   for (int i = 0; i < int(n); i++) { n     if (a[i] > p[i]) n       cout <<  Ann  << endl; n     else n       cout <<  Mike  << endl; n   } n } n


#include <bits/stdc++.h> n const double pi = acos(-1.0); n const int maxn = (5e2 + 10); n const int inf = 0x3f3f3f3f; n const long long mod = 1e9 + 7; n using namespace std; n map<long long, long long> ys; n long long a[200010]; n int main() { n   cin.tie(0); n   ios::sync_with_stdio(false); n   long long n; n   long double ans = 0, sum = 0; n   cin >> n; n   for (long long i = 1; i <= n; i++) { n     cin >> a[i]; n     sum += a[i]; n     ys[a[i]] += 1; n   } n   for (long long i = 1; i <= n; i++) { n     ans += sum - (long double)(n - i + 1) * (long double)a[i]; n     ans += ys[a[i] - 1] - ys[a[i] + 1]; n     sum -= a[i]; n     ys[a[i]] -= 1; n   } n   cout << fixed << setprecision(0) << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct query { n   int id, n; n }; n vector<query> ql[101000]; n query now; n int m, len, n, ans[101000], sum[101000], qm, fac[201000], inv[201000], n     ex[110000]; n char str[101000]; n const int mod = 1e9 + 7; n int power(int a, int n) { n   if (n == 0) return 1; n   int res = power(a, n / 2); n   res = (int)((long long)res * (long long)res % mod); n   if (n % 2) res = (int)((long long)res * (long long)a % mod); n   return res; n } n int main() { n   int i, j, s, p, q, flag, sz = 0, tmp; n   qm = (int)((long long)25 * (long long)power(26, mod - 2) % mod); n   for (i = 0; i <= 100000; i++) { n     if (i == 0) n       ex[i] = 1; n     else n       ex[i] = (int)((long long)ex[i - 1] * (long long)qm % mod); n   } n   for (i = 0; i <= 200000; i++) { n     if (i == 0) n       fac[i] = 1; n     else n       fac[i] = (int)((long long)fac[i - 1] * (long long)i % mod); n   } n   inv[200000] = power(fac[200000], mod - 2); n   for (i = 199999; i >= 0; i--) n     inv[i] = (int)((long long)(i + 1) * (long long)inv[i + 1] % mod); n   scanf( %d%s , &m, str); n   len = strlen(str); n   while (m--) { n     scanf( %d , &flag); n     if (flag == 1) { n       scanf( %s , str); n       len = strlen(str); n     } else { n       scanf( %d , &n); n       now.id = sz++; n       now.n = n; n       ql[len].push_back(now); n     } n   } n   for (i = 1; i <= 100000; i++) { n     int ax = 0; n     for (j = 0; j < ql[i].size(); j++) { n       if (ax < ql[i][j].n) ax = ql[i][j].n; n     } n     for (j = 0; j <= ax - i; j++) { n       tmp = (int)((long long)fac[j + i - 1] * (long long)inv[j] % mod); n       tmp = (int)((long long)tmp * (long long)inv[i - 1] % mod); n       tmp = (int)((long long)tmp * (long long)ex[j] % mod); n       if (j > 0) n         sum[j] = (sum[j - 1] + tmp) % mod; n       else n         sum[j] = tmp; n     } n     for (j = 0; j < ql[i].size(); j++) { n       if (ql[i][j].n < i) n         ans[ql[i][j].id] = 0; n       else n         ans[ql[i][j].id] = (int)((long long)power(26, ql[i][j].n - i) * n                                  (long long)sum[ql[i][j].n - i] % mod); n     } n   } n   for (i = 0; i < sz; i++) printf( %d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int INF = 1000000007; n string s; n int n, k, c, v, ans; n int fat[1000100], siz[1000100]; n vector<int> edge[1000100]; n struct node { n   int l, r, xo; n   node(int _l = 0, int _r = 0, int _xo = 0) : l(_l), r(_r), xo(_xo) {} n   int get() { return min(l, r); } n   void operator+=(node th) { n     l += th.l; n     r += th.r; n     if (l > INF) l = INF; n     if (r > INF) r = INF; n   } n } val[1000100]; n pair<int, int> uu, vv; n pair<int, int> trace(int x) { n   if (fat[x] < 0) return make_pair(x, 0); n   pair<int, int> pp = trace(fat[x]); n   fat[x] = pp.first; n   val[x].xo ^= pp.second; n   return make_pair(fat[x], val[x].xo); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n >> k >> s; n   s =  ?  + s; n   for (int i = 1; i <= k; i++) { n     fat[i] = -1; n     siz[i] = 1; n     val[i] = node(1, 0, 0); n     cin >> c; n     for (int j = 1; j <= c; j++) { n       cin >> v; n       edge[v].push_back(i); n     } n   } n   int ans = 0; n   int id; n   for (int i = 1; i <= n; i++) { n     int tp = (s[i] -  0 ) ^ 1; n     if (edge[i].size() == 1) { n       id = edge[i][0]; n       uu = trace(id); n       ans -= val[uu.first].get(); n       val[uu.first] += node((tp == uu.second) * INF, (tp != uu.second) * INF); n       ans += val[uu.first].get(); n     } else if (edge[i].size() == 2) { n       id = edge[i][0]; n       uu = trace(id); n       id = edge[i][1]; n       vv = trace(id); n       if (uu.first != vv.first) { n         ans -= (val[uu.first].get() + val[vv.first].get()); n         if (siz[uu.first] > siz[vv.first]) swap(uu, vv); n         if (uu.second ^ vv.second ^ tp) { n           swap(val[vv.first].l, val[vv.first].r); n           val[vv.first].xo = 1; n         } n         siz[uu.first] += siz[vv.first]; n         fat[vv.first] = uu.first; n         val[uu.first] += val[vv.first]; n         ans += val[uu.first].get(); n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n, m; n   cin >> n >> m; n   string a, b; n   cin >> a >> b; n   reverse(a.begin(), a.end()); n   reverse(b.begin(), b.end()); n   vector<long long> v(n, 0), u(m, 0); n   for (long long i = 0; i < n; i++) { n     if (a[i] ==  1 ) { n       v[i] = 1; n     } n   } n   for (long long i = 0; i < m; i++) { n     if (b[i] ==  1 ) { n       u[i] = 1; n     } n   } n   for (long long i = m - 2; i >= 0; i--) { n     u[i] += u[i + 1]; n   } n   map<long long, long long> mp; n   mp[0] = 1; n   for (long long i = 1; i < 2 * pow(10, 5) + 4; i++) { n     mp[i] = mp[i - 1] * 2 % 998244353; n   } n   long long ans = 0; n   for (long long i = 0; i < min(v.size(), u.size()); i++) { n     if (v[i] == 1) { n       long long x = (mp[i] % 998244353 * u[i] % 998244353) % 998244353; n       ans = (ans + x) % 998244353; n     } n   } n   cout << ans << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   long long test = 1; n   while (test--) solve(); n } n


#include <bits/stdc++.h> n int main() { n   long long n; n   int i = 0; n   scanf( %lld , &n); n   while (n - i > 0) { n     n = n - i; n     i++; n   } n   printf( %lld , n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, s1 = 0, s2 = 0; n   cin >> n; n   vector<int> v1(n); n   for (int i = 0; i < n; i++) cin >> v1[i]; n   cin >> m; n   vector<int> v2(m); n   for (int i = 0; i < m; i++) cin >> v2[i]; n   sort(v1.begin(), v1.end()); n   sort(v2.begin(), v2.end()); n   int res = 0; n   while (s1 < n && s2 < m) { n     if (abs(v1[s1] - v2[s2]) <= 1) { n       res++; n       s1++; n       s2++; n     } else if (v1[s1] > v2[s2]) n       s2++; n     else n       s1++; n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target( avx,avx2,fma ) n using namespace std; n const int N = 1500 + 5, lg = 27, mod = 5e4 + 7; n bool check(int a, int b, int c, int d) { n   double k = 1.0 * (a + b + c + d) / 4; n   double k1 = 1.0 * (b + c) / 2; n   double k2 = d - a; n   return k == k1 && k1 == k2 && a > 0 && b > 0 && c > 0 && d > 0; n } n void solve() { n   int n; n   cin >> n; n   vector<int> v(4, 1e6 + 5); n   for (int i = 0; i < n; i++) { n     cin >> v[i]; n   } n   sort(v.begin(), v.end()); n   if (!n) { n     cout <<  YES n  n          <<  1 n1 n3 n3 ; n   } else { n     if (n == 4) { n       if (check(v[0], v[1], v[2], v[3])) { n         cout <<  YES n ; n       } else { n         cout <<  NO ; n       } n     } else if (n == 1) { n       cout <<  YES n ; n       int x = v[0]; n       cout << x <<   n  << 3 * x <<   n  << 3 * x; n     } else if (n == 2) { n       v[3] = v[0] * 3; n       v[2] = v[0] * 4 - v[1]; n       if (check(v[0], v[1], v[2], v[3])) { n         cout <<  YES n ; n         cout << v[2] <<   n  << v[3]; n       } else { n         cout <<  NO n ; n       } n     } else { n       for (int i = 1; i < 1505; i++) { n         vector<int> k = v; n         k.push_back(i); n         sort(k.begin(), k.end()); n         if (check(k[0], k[1], k[2], k[3])) { n           cout <<  YES n ; n           cout << i; n           return; n         } n       } n       cout <<  NO ; n     } n   } n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int testCases = 1; n   while (testCases--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n const int Maxn = 100000; n const int Maxv = 100000; n int n; n struct Node { n   int x, y; n   Node(int _x = 0, int _y = 0) { x = _x, y = _y; } n   friend Node operator+(Node a, Node b) { return Node(a.x + b.x, a.y + b.y); } n   friend Node operator-(Node a, Node b) { return Node(a.x - b.x, a.y - b.y); } n   friend long long operator/(Node a, Node b) { n     return 1ll * a.x * b.y - 1ll * a.y * b.x; n   } n   long long find_len() { return 1ll * x * x + 1ll * y * y; } n } a[Maxn * 6 + 5]; n Node S; n bool cmp_1_less(Node a, Node b) { n   if (a.x == b.x) { n     return a.y < b.y; n   } n   return a.x < b.x; n } n bool cmp_1_equal(Node a, Node b) { return a.x == b.x && a.y == b.y; } n bool cmp_2(Node a, Node b) { n   if ((a - S) / (b - S) == 0) { n     return (a - S).find_len() < (b - S).find_len(); n   } n   return (a - S) / (b - S) > 0; n } n int len; n int st[Maxn * 6 + 5], st_top; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     int x, y, v; n     scanf( %d%d%d , &x, &y, &v); n     if (x < v) { n       a[++len] = Node(0, std::max(y - v + x, 0)); n       a[++len] = Node(0, std::min(y + v - x, Maxv)); n     } else { n       a[++len] = Node(x - v, y); n     } n     if (x + v > Maxv) { n       a[++len] = Node(Maxv, std::max(y - v + (Maxv - x), 0)); n       a[++len] = Node(Maxv, std::min(y + v - (Maxv - x), Maxv)); n     } else { n       a[++len] = Node(x + v, y); n     } n     if (y < v) { n       a[++len] = Node(std::max(x - v + y, 0), 0); n       a[++len] = Node(std::min(x + v - y, Maxv), 0); n     } else { n       a[++len] = Node(x, y - v); n     } n     if (y + v > Maxv) { n       a[++len] = Node(std::max(x - v + (Maxv - y), 0), Maxv); n       a[++len] = Node(std::min(x + v - (Maxv - y), Maxv), Maxv); n     } else { n       a[++len] = Node(x, y + v); n     } n   } n   std::sort(a + 1, a + 1 + len, cmp_1_less); n   len = std::unique(a + 1, a + 1 + len, cmp_1_equal) - a - 1; n   S = a[1]; n   std::sort(a + 2, a + 1 + len, cmp_2); n   st[++st_top] = 1; n   for (int i = 2; i <= len; i++) { n     while (st_top > 1 && n            (a[i] - a[st[st_top]]) / (a[st[st_top]] - a[st[st_top - 1]]) >= 0) { n       st_top--; n     } n     st[++st_top] = i; n   } n   st[0] = st[st_top], st[st_top + 1] = st[1]; n   int pos = -1; n   double ans = 0; n   for (int i = 1; i <= st_top; i++) { n     Node e_a = a[st[i]] - a[st[i - 1]], e_b = a[st[i + 1]] - a[st[i]], n          e_c = a[st[i + 1]] - a[st[i - 1]]; n     double tmp = sqrt(e_a.find_len()) * sqrt(e_b.find_len()) * n                  sqrt(e_c.find_len()) / (std::abs(e_a / e_b)); n     if (tmp > ans) { n       pos = i; n       ans = tmp; n     } n   } n   printf( %d %d n , a[st[pos - 1]].x, a[st[pos - 1]].y); n   printf( %d %d n , a[st[pos]].x, a[st[pos]].y); n   printf( %d %d n , a[st[pos + 1]].x, a[st[pos + 1]].y); n   return 0; n } n