#include <bits/stdc++.h> n using std::pair; n using std::vector; n vector<int64_t> ReadInput(std::istream& in_stream = std::cin); n void WriteAnswer(size_t min, size_t max, std::ostream& out_stream = std::cout); n pair<size_t, size_t> GetRange(const vector<int64_t>& input); n int main() { n   std::ios_base::sync_with_stdio(false); n   std::cin.tie(nullptr); n   auto input = ReadInput(); n   auto result = GetRange(input); n   WriteAnswer(result.first, result.second); n   return 0; n } n vector<int64_t> Power2(); n pair<vector<size_t>, vector<size_t>> ChainsExtra(const vector<int64_t>& input); n template <class Integral, class Functional, class Check> n Integral BinSearch(Integral left, Integral right, Functional func, Check check); n pair<size_t, size_t> GetRange(const vector<int64_t>& input) { n   auto chains_extra = ChainsExtra(input); n   vector<size_t> chains = std::move(chains_extra.first); n   vector<size_t> extra = std::move(chains_extra.second); n   size_t sum_chains = 0, sum_extra = 0; n   for (size_t i = chains.size(); i > 0; n        --i, sum_chains += chains[i], sum_extra += extra[i]) { n     if (sum_extra > sum_chains) { n       return {1, 0}; n     } n   } n   if (sum_extra > sum_chains) { n     return {1, 0}; n   } n   size_t min = sum_chains, max = sum_chains; n   for (size_t i = 0; i < chains.size(); ++i) { n     if (min - chains[i] >= sum_extra + chains[i] * i) { n       min -= chains[i]; n       sum_extra += chains[i] * i; n     } else { n       auto enouht = [min, &chains, sum_extra, sum_chains, i](size_t remove) { n         return min - remove >= sum_extra + remove * i; n       }; n       auto diff = [](size_t l, size_t r) { return r <= l + 1; }; n       min -= BinSearch(size_t(0), chains[i], enouht, diff); n       break; n     } n   } n   return {min, max}; n } n template <class Integral, class Functional, class Check> n Integral BinSearch(Integral left, Integral right, Functional func, Check check); n pair<vector<size_t>, vector<size_t>> ChainsExtra(const vector<int64_t>& input) { n   vector<int64_t> pow2 = Power2(); n   vector<size_t> count_pow2(pow2.size(), 0); n   vector<size_t> extra(pow2.size(), 0); n   auto diff = [](size_t l, size_t r) { return r <= l + 1; }; n   for (auto elem : input) { n     size_t pos = BinSearch( n         size_t(0), pow2.size(), n         [&pow2, elem](size_t pos) { return pow2[pos] <= elem; }, diff); n     if (elem == pow2[pos]) { n       ++count_pow2[pos]; n     } else { n       ++extra[pos + 1]; n     } n   } n   auto get_last = [&count_pow2]() { n     for (int i = 0; i < count_pow2.size(); ++i) { n       if (count_pow2[i] == 0) { n         return i; n       } n     } n     return static_cast<int>(count_pow2.size()); n   }; n   vector<size_t> chains(pow2.size(), 0); n   while (get_last() != 0) { n     auto pos = get_last(); n     auto chains_count = n         *std::min_element(count_pow2.begin(), count_pow2.begin() + pos); n     chains[pos] = chains_count; n     std::for_each(count_pow2.begin(), count_pow2.begin() + pos, n                   [chains_count](size_t& count) { count -= chains_count; }); n   } n   for (size_t i = 0; i < pow2.size(); ++i) { n     extra[i] += count_pow2[i]; n   } n   return {chains, extra}; n } n template <class Integral, class Functional, class Check> n Integral BinSearch(Integral left, Integral right, Functional func, n                    Check check) { n   auto dir = func(left); n   while (!check(left, right)) { n     Integral mid = (left + right) / 2; n     if (func(mid) == dir) { n       left = mid; n     } else { n       right = mid; n     } n   } n   return left; n } n vector<int64_t> Power2() { n   std::vector<int64_t> power2{1}; n   while (power2.back() < 1ll * 2000 * 1000 * 1000 * 1000) { n     power2.push_back(power2.back() * 2); n   } n   return power2; n } n void WriteAnswer(size_t min, size_t max, std::ostream& out_stream) { n   if (min > max) { n     out_stream << -1; n     return; n   } n   for (size_t i = min; i <= max; ++i) { n     std::cout << i <<    ; n   } n } n vector<int64_t> ReadInput(std::istream& in_stream) { n   size_t input_size; n   in_stream >> input_size; n   vector<int64_t> input(input_size); n   for (auto& elem : input) { n     in_stream >> elem; n   } n   return input; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int g[30][30]; n char s[20]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %s , s); n     int len = strlen(s); n     for (int j = 0; j < len; j++) s[j] -=  a ; n     for (int j = 0; j < 26; j++) { n       if (g[j][s[0]] || j == s[0]) n         g[j][s[len - 1]] = max(g[j][s[len - 1]], g[j][s[0]] + len); n     } n   } n   int maxn = 0; n   for (int i = 0; i < 26; i++) maxn = max(maxn, g[i][i]); n   printf( %d n , maxn); n } n


#include <cstdio> n #include <iostream> n #include <cstdlib> n #include <cstring> n #include <string> n #include <algorithm> n #include <cmath> n #define LL long long n using namespace std; n LL T; n LL n, arr[300000], cnt[300000], dp[300000]; n int main (){ n     cin >> T; n     while (T--){ n         scanf( %lld , &n); n         for (LL i = 1; i <= 200000; ++ i) n             cnt[i] = 0; n         for (LL i = 1; i <= n; ++ i){ n             scanf( %lld , &arr[i]); n             cnt[arr[i]] ++; n         } n         for (LL i = 1; i <= 200000; ++ i) n             dp[i] = cnt[i]; n         //sort(arr + 1, arr + 1 + n); n         for (LL i = 1;i <= 200000; ++ i){ n             for (LL j = i * 2; j <= 200000; j += i){ n                 dp[j] = max(dp[j], dp[i] + cnt[j]); n             } n         } n         printf( %lld n , n - *max_element(dp + 1, dp + 200001)); n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   set<string> st; n   string s; n   cin >> t; n   getchar(); n   while (t--) { n     getline(cin, s); n     st.insert(s); n   } n   cout << st.size() << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 100; n int ans[N], link[N]; n int main() { n   ios_base ::sync_with_stdio(0); n   cin.tie(0); n   int n, k; n   cin >> n >> k; n   for (int i = 1; i <= n; ++i) { n     int x; n     cin >> x; n     int down = max(1, i - k); n     int up = min(n, i + k); n     int down2 = max(1, x - k); n     int up2 = min(n, x + k); n     if (x == 0) { n       ans[i] = up - down + 1 + ans[x]; n     } else { n       if (up2 < down) n         ans[i] = up - down + 1 + ans[x]; n       else n         ans[i] = up - down + 1 + ans[x] - (up2 - down + 1); n     } n     cout << ans[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   for (int i = 0; i < t; i++) { n     int ans = 0; n     string s; n     cin >> s; n     if (s.size() % 2 == 0) { n       for (int j = 0; j < s.size() / 2; j++) { n         if (s[j] != s[s.size() / 2 + j]) { n           ans = 1; n           cout <<  NO  << endl; n           break; n         } n       } n       if (ans != 1) { n         cout <<  YES  << endl; n       } n     } else { n       cout <<  NO  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, q, a[200010]; n struct node { n   int l, r, color; n   node(int ll = 0, int rr = 0, int cc = 0) : l(ll), r(rr), color(cc) {} n }; n node p[200010]; n vector<int> vec[200010]; n bool cmp(node a, node b) { n   if (a.l != b.l) return a.l < b.l; n   return a.r > b.r; n } n int main() { n   cin >> n >> q; n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n     vec[a[i]].push_back(i); n   } n   int cnt = 0; n   for (int i = 1; i <= 200000; ++i) { n     if (!vec[i].size()) continue; n     int l = vec[i][0], r = vec[i][vec[i].size() - 1]; n     p[++cnt] = node(l, r, i); n   } n   sort(p + 1, p + 1 + cnt, cmp); n   p[cnt + 1].l = 1e9 + 10; n   int ans = 0, l = 1e9 + 10, r = 0, tmp = 0; n   for (int i = 1; i <= cnt + 1; ++i) { n     if (i == 1 || p[i].l < r) { n       l = min(l, p[i].l); n       r = max(r, p[i].r); n       tmp = max(tmp, (int)vec[p[i].color].size()); n     } else { n       ans += r - l + 1 - tmp; n       l = p[i].l; n       r = p[i].r; n       tmp = vec[p[i].color].size(); n     } n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> stations[200001]; n int nxt[200001]; n int main() { n   int d, n, m; n   scanf( %d%d%d , &d, &n, &m); n   for (int i = 0; i < m; i++) { n     scanf( %d%d , &stations[i].first, &stations[i].second); n   } n   sort(stations, stations + m); n   stack<int> s; n   for (int i = m - 1; i > -1; i--) { n     nxt[i] = -1; n     while (!s.empty()) { n       if (stations[s.top()].second > stations[i].second) { n         s.pop(); n       } else { n         nxt[i] = s.top(); n         break; n       } n     } n     s.push(i); n   } n   long long cost = 0; n   int gas = n; n   for (int i = 0; i < m; i++) { n     gas -= stations[i].first - (i == 0 ? 0 : stations[i - 1].first); n     if (gas < 0) { n       cout << -1 << endl; n       return 0; n     } n     int needed; n     if (nxt[i] == -1 || stations[nxt[i]].first - stations[i].first > n) { n       needed = min(n, d - stations[i].first); n     } else { n       needed = stations[nxt[i]].first - stations[i].first; n     } n     if (gas < needed) { n       cost += (long long)stations[i].second * (needed - gas); n       gas = needed; n     } n   } n   gas -= d - stations[m - 1].first; n   if (gas < 0) { n     cout << -1 << endl; n   } else { n     cout << cost << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int tree[N << 2], Max[N << 2], Min[N << 2], cnt; n bool fu[N << 2]; n pair<int, int> a[N]; n void build(int l, int r, int rt) { n   if (l == r) { n     tree[rt] = a[l].first; n     Max[rt] = Min[rt] = tree[rt]; n     return; n   } n   int m = (l + r) >> 1; n   build(l, m, rt << 1); n   build(m + 1, r, rt << 1 | 1); n   Max[rt] = max(Max[rt << 1], Max[rt << 1 | 1]); n   Min[rt] = min(Min[rt << 1], Min[rt << 1 | 1]); n } n bool qu(int f, int x, int rt) { n   int ma, mi; n   ma = Max[rt], mi = Min[rt]; n   if ((f ==  >  && mi > x) || (f ==  <  && ma < x)) n     return true; n   else n     return false; n } n bool qu2(int f, int x, int rt) { n   int ma, mi; n   ma = Max[rt], mi = Min[rt]; n   if ((f ==  >  && ma > x) || (f ==  <  && mi < x)) n     return true; n   else n     return false; n } n void ff(int rt) { n   fu[rt] = !fu[rt]; n   swap(Max[rt], Min[rt]); n   Max[rt] *= -1; n   Min[rt] *= -1; n } n void updata(int l, int r, int rt, char f, int x) { n   if (qu(f, x, rt)) { n     ff(rt); n     return; n   } n   int m = (l + r) >> 1; n   if (fu[rt]) ff(rt << 1), ff(rt << 1 | 1), fu[rt] = 0; n   if (qu2(f, x, rt << 1)) updata(l, m, rt << 1, f, x); n   if (qu2(f, x, rt << 1 | 1)) updata(m + 1, r, rt << 1 | 1, f, x); n   Max[rt] = max(Max[rt << 1], Max[rt << 1 | 1]); n   Min[rt] = min(Min[rt << 1], Min[rt << 1 | 1]); n } n int ans[N]; n void print(int l, int r, int rt) { n   if (l == r) { n     if (fu[rt]) tree[rt] *= -1; n     ans[a[l].second] = tree[rt]; n     return; n   } n   int m = (l + r) >> 1; n   if (fu[rt]) ff(rt << 1), ff(rt << 1 | 1), fu[rt] = 0; n   print(l, m, rt << 1); n   print(m + 1, r, rt << 1 | 1); n } n int main() { n   int n, q; n   cin >> n >> q; n   for (int i = 1; i <= n; i++) cin >> a[i].first, a[i].second = i; n   sort(a + 1, a + n + 1); n   build(1, n, 1); n   while (q--) { n     char f; n     int x; n     cin >> f >> x; n     updata(1, n, 1, f, x); n   } n   print(1, n, 1); n   for (int i = 1; i <= n; i++) printf( %d  , ans[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 1212; n int num, n, x, i, j, cur, t, s[MX], a[MX][3], r[MX], mx[MX], mxs[MX]; n priority_queue<pair<int, int>> q[2]; n vector<int> v[MX]; n bool u[MX]; n int main() { n   scanf( %d , &n); n   for (i = 0; i < 3 * n; i++) { n     scanf( %d , &x); n     u[x] = true; n   } n   for (i = 1; i <= 6 * n; i++) n     if (t > 1 && u[s[t]] == u[i] && u[s[t - 1]] == u[i]) { n       a[++num][0] = s[t - 1]; n       a[num][1] = s[t]; n       a[num][2] = i; n       t -= 2; n       for (j = 0; j < 3; j++) mxs[num] = max(mxs[num], mx[a[num][j]]); n       v[s[t]].push_back(num); n       mx[s[t]] = max(mx[s[t]], mxs[num] + 1); n     } else n       s[++t] = i; n   for (i = 0; i < v[0].size(); i++) n     q[int(u[a[v[0][i]][0]])].push({mxs[v[0][i]], v[0][i]}); n   for (i = 0; i < 2 * n; i++) { n     cur = i & 1; n     x = q[cur].top().second; n     q[cur].pop(); n     r[2 * n - i - 1] = x; n     cur = 1 - cur; n     for (j = 0; j < 3; j++) n       for (int k : v[a[x][j]]) q[cur].push({mxs[k], k}); n   } n   for (i = 0; i < 2 * n; i++) n     for (j = 0; j < 3; j++) printf( %d%c , a[r[i]][j], (j == 2) ?   n  :    ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[405][405]; n int q[405 * 405], d[405], t, h, ans; n bool vis[405]; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   while (m--) { n     int u, v; n     scanf( %d %d , &u, &v); n     a[u][v] = a[v][u] = 1; n   } n   t = h = 0; n   q[h++] = 1; n   vis[1] = 1; n   memset(d, -1, sizeof d); n   d[1] = 0; n   while (t < h) { n     int u = q[t++]; n     for (int i = 1; i <= n; i++) { n       if (vis[i] || a[u][i] == 0) continue; n       d[i] = d[u] + 1; n       vis[i] = 1; n       q[h++] = i; n     } n   } n   if (d[n] == -1) { n     puts( -1 ); n     return 0; n   } n   ans = d[n]; n   t = h = 0; n   q[h++] = 1; n   memset(vis, 0, sizeof vis); n   vis[1] = 1; n   memset(d, -1, sizeof d); n   d[1] = 0; n   while (t < h) { n     int u = q[t++]; n     for (int i = 1; i <= n; i++) { n       if (vis[i] || a[u][i]) continue; n       d[i] = d[u] + 1; n       vis[i] = 1; n       q[h++] = i; n     } n   } n   if (d[n] == -1) { n     puts( -1 ); n     return 0; n   } n   ans = max(ans, d[n]); n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n long long t, n; n char str[200005]; n void solve() { n   long long i, b = 0, c, s = 1, min = 0; n   char a; n   a = str[0]; n   str[n] = str[0]; n   for (i = 1; i < n; ++i) { n     if (str[i] != a) { n       b = i; n       break; n     } else { n       s++; n     } n   } n   if (b) { n     for (i = n - 1; i >= b; --i) { n       if (str[i] != a) { n         c = i; n         break; n       } else { n         s++; n       } n     } n   } n   if (b) { n     min += s / 3; n     a = str[b]; n     s = 1; n     for (i = b + 1; i <= c; ++i) { n       if (str[i] == a) { n         s++; n       } else { n         a = str[i]; n         min += s / 3; n         s = 1; n       } n     } n     min += s / 3; n     cout << min <<   n ; n   } else { n     min += (s + 2) / 3; n     cout << min <<   n ; n   } n } n void nhap() { n   long long i; n   cin >> n; n   cin >> str; n } n int main() { n   long long i; n   cin >> t; n   for (i = 1; i <= t; ++i) { n     nhap(); n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int main() { n   scanf( %d%d , &n, &m); n   if (n == 1 && m == 1) { n     puts( YES n1 ); n     return 0; n   } n   if ((n == 1 && m <= 3) || (m == 1 && n <= 3) || (n == 2 && m <= 3) || n       (m == 2 && n <= 3)) { n     puts( NO ); n     return 0; n   } n   if (n == 1 && m == 4) { n     puts( YES n2 4 1 3 ); n     return 0; n   } n   if (n == 4 && m == 1) { n     puts( YES n2 n4 n1 n3 ); n     return 0; n   } n   if (n == 1 && m >= 5) { n     puts( YES ); n     for (int i = 1; i <= m; i += 2) printf( %d  , i); n     for (int i = 2; i <= m; i += 2) printf( %d  , i); n     return 0; n   } n   if (n >= 5 && m == 1) { n     puts( YES ); n     for (int i = 1; i <= n; i += 2) printf( %d n , i); n     for (int i = 2; i <= n; i += 2) printf( %d n , i); n     return 0; n   } n   if (n == m && n == 3) { n     puts( YES n6 1 8 n7 5 3 n2 9 4 ); n     return 0; n   } n   vector<vector<int> > g; n   g.resize(n); n   for (int i = 0, u = 1; i < n; i++) { n     g[i].resize(m); n     for (int j = 0; j < m; j++) g[i][j] = u++; n   } n   if (n <= m) { n     for (int i = 0; i < n; i++) n       if (i & 1) { n         vector<int> tmp; n         for (int j = 0; j < m; j++) tmp.push_back(g[i][(j + 2) % m]); n         tmp.swap(g[i]); n       } n     for (int j = 0; j < m; j++) n       if (j & 1) { n         vector<int> tmp; n         for (int i = 0; i < n; i++) tmp.push_back(g[(i - 1 + n) % n][j]); n         for (int i = 0; i < n; i++) g[i][j] = tmp[i]; n       } n   } else { n     for (int i = 0; i < n; i++) n       if (i & 1) { n         vector<int> tmp; n         for (int j = 0; j < m; j++) tmp.push_back(g[i][(j - 1 + m) % m]); n         tmp.swap(g[i]); n       } n     for (int j = 0; j < m; j++) n       if (j & 1) { n         vector<int> tmp; n         for (int i = 0; i < n; i++) tmp.push_back(g[(i + 2) % n][j]); n         for (int i = 0; i < n; i++) g[i][j] = tmp[i]; n       } n   } n   puts( YES ); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) printf( %d  , g[i][j]); n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t = 0; n   int l, r, n, m, x; n   cin >> n >> x; n   int sum; n   int temp = 0; n   for (int i = 1; i <= n; i++) { n     cin >> l >> r; n     sum = 0; n     while (1) { n       t = t + x; n       if (t >= l) { n         t = (t - x); n         sum = sum + (r - t); n         t = t + sum; n         break; n       } n     } n     temp = temp + sum; n   } n   cout << temp << endl; n } n


#include <bits/stdc++.h> n int main() { n   int n, k, l, c, d, p, nl, np, a, b, r; n   scanf( %d %d %d %d %d %d %d %d , &n, &k, &l, &c, &d, &p, &nl, &np); n   a = (k * l) / (n * nl); n   b = c * d / n; n   r = p / (n * np); n   int x; n   if ((a < 1) || (b < 1) || (r < 1)) n     x = 0; n   else { n     x = (a < b) ? ((a < r) ? a : r) : ((b < r) ? b : r); n   } n   printf( %d , x); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool umin(T& a, T b) { n   if (a > b) { n     a = b; n     return 1; n   } n   return 0; n } n template <class T> n bool umax(T& a, T b) { n   if (a < b) { n     a = b; n     return 1; n   } n   return 0; n } n int arr[100009], n, s[100009 << 2]; n int M[2][100009][20], LOG[100009], s1, s2; n void upd(int l, int r, int nd, int x, int y) { n   if (l > y or x > r) return; n   if (l <= x and y <= r) { n     s[nd] = 1; n     return; n   } n   int mid = (x + y) >> 1; n   upd(l, r, nd << 1, x, mid); n   upd(l, r, nd << 1 | 1, mid + 1, y); n } n int tap(int p, int nd, int x, int y) { n   if (x == y) return s[nd]; n   int mid = (x + y) >> 1; n   if (p <= mid) return tap(p, nd << 1, x, mid) | s[nd]; n   return tap(p, nd << 1 | 1, mid + 1, y) | s[nd]; n } n int get(int p, int l, int r) { n   int k = LOG[r - l + 1]; n   if (!p) return max(M[0][l][k], M[0][r - (1 << k) + 1][k]); n   return min(M[1][l][k], M[1][r - (1 << k) + 1][k]); n } n bool ok(int x, int y) { n   memset(s, 0, sizeof s); n   arr[0] = y; n   for (int i = 0; i < n; i++) { n     if (i and !tap(i, 1, 1, n)) continue; n     int st = i + 1, en = n; n     while (st + 1 < en) { n       int mid = (st + en) >> 1; n       int mx = get(0, i + 1, mid), mn = get(1, i + 1, mid); n       if (abs(mx - arr[i]) <= x and abs(mn - arr[i]) <= x) n         st = mid; n       else n         en = mid; n     } n     int mx = get(0, i + 1, en), mn = get(1, i + 1, en); n     if (abs(mx - arr[i]) <= x and abs(mn - arr[i]) <= x) n       upd(i + 1, en, 1, 1, n); n     else if (abs(arr[i] - arr[i + 1]) <= x) n       upd(i + 1, st, 1, 1, n); n   } n   return tap(n, 1, 1, n); n } n int main() { n   scanf( %d%d%d , &n, &s1, &s2); n   for (int i = 1; i <= n; i++) { n     scanf( %d , arr + i); n     M[0][i][0] = M[1][i][0] = arr[i]; n     LOG[i] = log2(i); n   } n   for (int j = 1; j <= 17; j++) n     for (int i = 1; i <= n; i++) { n       if (i + (1 << (j - 1)) <= n) n         M[0][i][j] = max(M[0][i][j - 1], M[0][i + (1 << (j - 1))][j - 1]); n       else n         M[0][i][j] = M[0][i][j - 1]; n     } n   for (int j = 1; j <= 17; j++) n     for (int i = 1; i <= n; i++) { n       if (i + (1 << (j - 1)) <= n) n         M[1][i][j] = min(M[1][i][j - 1], M[1][i + (1 << (j - 1))][j - 1]); n       else n         M[1][i][j] = M[0][1][j - 1]; n     } n   int st = abs(s1 - s2), en = 1e9; n   while (st + 1 < en) { n     int mid = (st + en) >> 1; n     if (ok(mid, s1) or ok(mid, s2)) n       en = mid; n     else n       st = mid; n   } n   if (ok(st, s1) or ok(st, s2)) n     printf( %d n , st); n   else n     printf( %d n , en); n   return 0; n } n


#include <bits/stdc++.h> n int main(void) { n   int a[101]; n   int b, c, d, i, j, count = 0, num, number; n   scanf( %d %d , &b, &c); n   for (i = 0; i < b; i++) { n     scanf( %d , &a[i]); n   } n   for (i = 0; i < b - 1; i++) { n     for (j = i + 1; j < b; j++) { n       if (a[i] > a[j]) { n         d = a[i]; n         a[i] = a[j]; n         a[j] = d; n       } n     } n   } n   for (i = 0; i < b; i++) { n     num = 0; n     number = 1; n     for (j = i + 1; j < b; j++) { n       num += a[j] - a[j - 1]; n       if (num > c) { n         break; n       } else { n         number++; n       } n     } n     if (number > count) { n       count = number; n     } n   } n   printf( %d n , b - count); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n int a[(int)(1e6 + 10)], b[(int)(1e6 + 10)]; n int c[(int)(1e6 + 10)]; n int p[(int)(1e6 + 10)]; n int rk[(int)(1e6 + 10)]; n bool color[(int)(1e6 + 10)]; n int find(int x) { return p[x] == x ? x : find(p[x]); } n void init() { n   for (int i = 1; i <= 1e6; i++) p[i] = i, rk[i] = 1; n } n struct revo { n   int px, py, rkx, rky; n }; n stack<revo> st; n void merge(int x, int y) { n   int px = find(x), py = find(y); n   revo tmp = {px, py, rk[px], rk[py]}; n   st.push(tmp); n   if (rk[px] > rk[py]) swap(px, py); n   p[px] = py; n   rk[py] = max(rk[py], rk[px] + 1); n } n void revocation(int k) { n   while (k--) { n     revo node = st.top(); n     st.pop(); n     p[node.px] = node.px; n     p[node.py] = node.py; n     rk[node.px] = node.rkx; n     rk[node.py] = node.rky; n   } n } n map<pair<int, int>, vector<pair<int, int> > > mp; n long long ans; n int main() { n   ios::sync_with_stdio(0); n   init(); n   cin >> n >> m >> k; n   for (int i = 1; i <= n; i++) cin >> c[i]; n   for (int i = 1; i <= m; i++) cin >> a[i] >> b[i]; n   for (int i = 1; i <= m; i++) { n     if (c[a[i]] == c[b[i]]) { n       int x = find(a[i]), y = find(b[i]); n       if (x != y) n         merge(a[i], b[i] + n), merge(b[i], a[i] + n); n       else n         color[c[a[i]]] = 1; n     } n   } n   for (int i = 1; i <= m; i++) { n     if (c[a[i]] == c[b[i]]) continue; n     if (color[c[a[i]]] || color[c[b[i]]]) continue; n     if (c[a[i]] > c[b[i]]) swap(a[i], b[i]); n     mp[{c[a[i]], c[b[i]]}].emplace_back(a[i], b[i]); n   } n   for (auto node : mp) { n     int cnt = 0; n     for (auto it : node.second) { n       int x, y; n       tie(x, y) = it; n       int px = find(x), py = find(y); n       if (px != py) n         merge(x, y + n), merge(y, x + n), cnt += 2; n       else { n         ans--; n         break; n       } n     } n     revocation(cnt); n   } n   long long cnt = 0; n   for (int i = 1; i <= k; i++) n     if (!color[i]) cnt++; n   ans += cnt * (cnt - 1) / 2; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n const double EPS = 1e-9; n using namespace std; n template <class T> n inline T gcd(T a, T b) { n   while (b) { n     a %= b; n     swap(a, b); n   } n   return a; n } n template <class T> n inline T lcm(T a, T b) { n   return a / gcd(a, b) * b; n } n inline int nxt() { n   int wow; n   scanf( %d , &wow); n   return wow; n } n inline long long int lxt() { n   long long int wow; n   scanf( %lld , &wow); n   return wow; n } n inline double dxt() { n   double wow; n   scanf( %lf , &wow); n   return wow; n } n bool comp(string xx, string yy) { n   if (xx.length() == yy.length()) n     return xx < yy; n   else n     return xx.length() > yy.length(); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   map<string, vector<string>> phone, book; n   set<string> st; n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     st.insert(s); n     int m; n     cin >> m; n     for (int i = 0; i < m; i++) { n       string num; n       cin >> num; n       phone[s].push_back(num); n     } n   } n   for (auto it = st.begin(); it != st.end(); ++it) { n     sort(phone[*it].begin(), phone[*it].end(), comp); n     for (int i = 0; i < phone[*it].size(); i++) { n       bool dup = false; n       for (int j = 0; j < book[*it].size(); j++) { n         bool match = true; n         for (int k = phone[*it][i].length() - 1, l = book[*it][j].length() - 1; n              k >= 0; k--, l--) { n           if (phone[*it][i][k] != book[*it][j][l]) match = false; n         } n         if (match == true) dup = true; n       } n       if (dup == false) book[*it].push_back(phone[*it][i]); n     } n   } n   cout << st.size() << endl; n   for (auto it = st.begin(); it != st.end(); ++it) { n     cout << *it <<     << book[*it].size(); n     for (int i = 0; i < book[*it].size(); i++) cout <<     << book[*it][i]; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, i, x, k, j = 0; n   scanf( %d%d , &n, &k); n   for (i = 0; i < n; i++) { n     for (x = 0; x < n; x++) { n       if (i == j && x == j) { n         printf( %d  , k); n       } else n         printf( 0  ); n     } n     j++; n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[200011], c[200011], isc[200011], cn, pow2[200011] = {1}, seen[200011]; n int main() { n   int ans = 1, mod = 1e9 + 7; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , a + i); n     pow2[i] = pow2[i - 1] * 2LL % mod; n   } n   for (int i = 1; i <= n; i++) { n     if (seen[i] < 0) continue; n     ++cn; n     int j; n     for (j = i; seen[j] >= 0; j = a[j]) seen[j] = -cn, ++c[cn]; n     if (seen[j] == -cn) isc[cn] = 1; n     if (isc[cn]) { n       int clen = 1; n       for (int k = a[j]; seen[k] == -cn && k != j; k = a[k]) ++clen; n       ans = (ans * 1LL * (pow2[clen] - 2 + mod) % mod) % mod; n       ans = (ans * 1LL * pow2[c[cn] - clen]) % mod; n     } else { n       ans = (ans * 1LL * pow2[c[cn]]) % mod; n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> teams(200000); n int main() { n   ios_base::sync_with_stdio(false); n   int N; n   cin >> N; n   for (int i = 0; i < N; i++) cin >> teams[i]; n   for (int i = 0; i < N; i++) { n     if (teams[i] == 0) { n       continue; n     } n     if (teams[i] >= 2) { n       teams[i] %= 2; n     } n     if (teams[i] == 1 && i != N - 1) { n       teams[i + 1] -= 1; n       teams[i] -= 1; n     } n     if (teams[i] != 0) { n       cout <<  NO  n            <<   n ; n       return 0; n     } n   } n   cout <<  YES  n        <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int p = n + 1; n   int cnt = 0; n   cout << ((n + 1) * 3) + 1 << endl; n   for (int i = 0; i < p; i++) { n     cout << i <<     << i << endl; n     cout << i + 1 <<     << i << endl; n     cout << i <<     << i + 1 << endl; n     cnt += 3; n   } n   cout << p <<     << p << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, s, i, j; n   cin >> n >> m >> s; n   long long ans = 0; n   for (i = 1; i <= n; i += 2) { n     for (j = 1; j <= m; j += 2) { n       long long cnt = (n - i + 1) * (m - j + 1); n       long long tmp = 0; n       if (i * j == s) { n         tmp = (i + 1) / 2 * (j + 1) / 2; n         ans += cnt * (tmp * 2 - 1); n       } n       if (i * j > s) { n         int x, ss = i * j; n         if ((ss - s) % 4) continue; n         int res = (ss - s) / 4; n         for (int k = 1; k <= j / 2; k++) { n           if (res % k) continue; n           x = res / k; n           if (x > i / 2) continue; n           tmp += 2; n         } n         ans += cnt * tmp; n       } n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long mod(long long n, long long m) { n   long long ret = n % m; n   if (ret < 0) ret += m; n   return ret; n } n long long gcd(long long a, long long b) { n   return (b == 0LL ? a : gcd(b, a % b)); n } n long long exp(long long a, long long b, long long m) { n   if (b == 0LL) return 1LL; n   if (b == 1LL) return mod(a, m); n   long long k = mod(exp(a, b / 2, m), m); n   if (b & 1LL) { n     return mod(a * mod(k * k, m), m); n   } else n     return mod(k * k, m); n } n const int N = 660; n vector<int> g[N]; n vector<int> nada; n map<vector<int>, int> cache; n int ask(vector<int> v) { n   sort(v.begin(), v.end()); n   int k = (int)v.size(); n   if ((int)v.size() == 1) return 0; n   if (cache.count(v)) return cache[v]; n   cout <<  ?   << k <<   n ; n   for (int x : v) cout << x <<    ; n   cout <<   n ; n   cout.flush(); n   int m; n   cin >> m; n   if (m == -1) { n     exit(0); n   } n   return cache[v] = m; n } n int vis[N]; n int ed; n int n; n struct dsu { n   vector<int> p, ps; n   dsu(int n) { n     p = vector<int>(n + 1), ps = vector<int>(n + 1, 1); n     for (int i = 0; i < (n + 1); ++i) p[i] = i; n   } n   int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); } n   bool join(int x, int y) { n     x = find(x), y = find(y); n     if (x == y) return 0; n     if (ps[x] > ps[y]) swap(x, y); n     p[x] = y, ps[y] += ps[x]; n     return 1; n   } n }; n dsu D(N); n void addEdge(int a, int b) { n   g[a].push_back(b); n   g[b].push_back(a); n   ed++; n   assert(ed < n); n } n void go(int id, vector<int> cur) { n   int tam = (int)cur.size(); n   if (tam == 0) return; n   if (tam == 1) { n     if (D.find(id) == D.find(cur[0])) return; n     cur.push_back(id); n     int m = ask(cur); n     if (m == 1) { n       D.join(id, cur[0]); n       addEdge(id, cur[0]); n     } n     return; n   } n   vector<int> L, R; n   for (int i = 0; i < tam / 2; i++) { n     L.push_back(cur[i]); n   } n   if ((int)L.size()) { n     int m1 = ask(L); n     vector<int> aux = L; n     aux.push_back(id); n     int m11 = ask(aux); n     if (m1 != m11) { n       go(id, L); n     } n   } n   for (int i = tam / 2; i < (int)cur.size(); i++) { n     R.push_back(cur[i]); n   } n   cur.clear(); n   if ((int)R.size()) { n     int m1 = ask(R); n     vector<int> aux = R; n     aux.push_back(id); n     int m11 = ask(aux); n     if (m1 != m11) { n       go(id, R); n     } n   } n   return; n } n vector<int> cor[2]; n int pai[N]; n int H[N]; n vector<int> path(int a, int b) { n   vector<int> vL, vR; n   while (a != b) { n     if (H[a] > H[b]) { n       vL.push_back(a); n       a = pai[a]; n     } else if (H[b] > H[a]) { n       vR.push_back(b); n       b = pai[b]; n     } else { n       vL.push_back(a); n       a = pai[a]; n     } n   } n   vector<int> ans; n   vL.push_back(a); n   for (int x : vL) ans.push_back(x); n   reverse(vR.begin(), vR.end()); n   for (int x : vR) ans.push_back(x); n   return ans; n } n void vai(vector<int> v, int tot) { n   if ((int)v.size() <= 1 or tot == 0) return; n   vector<int> L, R; n   int tam = (int)v.size(); n   for (int i = 0; i < tam / 2; i++) { n     L.push_back(v[i]); n   } n   for (int i = tam / 2; i < tam; i++) { n     R.push_back(v[i]); n   } n   v.clear(); n   int m1 = ask(L); n   int m2 = ask(R); n   if (m1 + m2 == tot) { n     vai(L, m1); n     vai(R, m2); n     return; n   } n   assert((int)R.size() > 0); n   for (int x : L) { n     vector<int> aux = R; n     aux.push_back(x); n     int mn = ask(aux); n     if (mn == m2) continue; n     while ((int)R.size() > 1) { n       int mid = (int)R.size() / 2; n       vector<int> v1, v2; n       for (int i = 0; i < mid; i++) { n         v1.push_back(R[i]); n       } n       for (int i = mid; i < (int)R.size(); i++) { n         v2.push_back(R[i]); n       } n       aux = v1; n       aux.push_back(x); n       int t1 = ask(v1); n       int t2 = ask(aux); n       if (t1 < t2) { n         R = v1; n       } else n         R = v2; n     } n     int ca = x, cb = R[0]; n     assert(D.find(ca) == D.find(cb)); n     vector<int> cic = path(ca, cb); n     cout <<  N   << (int)cic.size() <<   n ; n     for (int y : cic) cout << y <<    ; n     cout <<   n ; n     exit(0); n   } n } n void tenta(int c) { n   if ((int)cor[c].size() == 0) return; n   int m = ask(cor[c]); n   if (m == 0) return; n   vai(cor[c], m); n } n int tt = 0; n vector<int> vec; n int comp = 0; n void dfs(int v, int c, int p) { n   cor[c].push_back(v); n   tt++; n   vec.push_back(v); n   vis[v] = 1; n   if (tt > N) exit(0); n   for (int to : g[v]) { n     if (to != p) { n       pai[to] = v; n       H[to] = H[v] + 1; n       dfs(to, 1 - c, v); n     } n   } n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     nada.clear(); n     for (int j = 1; j <= n; j++) n       if (D.find(i) != D.find(j)) nada.push_back(j); n     go(i, nada); n   } n   for (int i = 1; i <= n; i++) { n     vis[i] = 0; n   } n   for (int i = 1; i <= n; i++) { n     if (!vis[i]) { n       H[i] = 1; n       pai[i] = 0; n       vec.clear(); n       dfs(i, 0, i); n       int cnt = 0; n       for (int x : vec) cnt += (H[x] == 1); n       assert(cnt == 1); n       vector<int> mark(n + 1, 0); n       int aqui = i; n       for (int x : vec) { n         mark[x] = 1; n         assert(D.find(aqui) == D.find(i)); n       } n       for (int j = 1; j <= n; j++) { n         if (!mark[j]) { n           assert(D.find(j) != D.find(i)); n         } n       } n       for (int x : vec) { n         int cur = x; n         while (cur != i and cur > 0) cur = pai[cur]; n         assert(cur == i); n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     assert(H[i] == H[pai[i]] + 1); n   } n   tenta(0); n   tenta(1); n   if ((int)cor[0].size() < (int)cor[1].size()) swap(cor[0], cor[1]); n   cout <<  Y   << (int)cor[0].size() <<   n ; n   for (int x : cor[0]) cout << x <<    ; n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, tot, res = 0, f[666666], g[666666], q[666666], ans[666666][3]; n struct edge { n   int adj, nex; n   bool vis; n   edge(int a_ = 0, int n_ = 0) { n     adj = a_; n     nex = n_; n     vis = false; n   } n } e[666666]; n void add(int u, int v) { n   e[++tot] = edge(v, e[u].nex); n   e[u].nex = tot; n   e[++tot] = edge(u, e[v].nex); n   e[v].nex = tot; n } n void bfs(int x) { n   int l = 0, r = 1; n   q[1] = x; n   f[x] = -1; n   while (l < r) { n     for (int i = e[q[++l]].nex; i; i = e[i].nex) { n       if (!f[e[i].adj]) { n         q[++r] = e[i].adj; n         f[e[i].adj] = q[l]; n       } n     } n   } n   for (int i = r; i; i--) { n     g[0] = 0; n     for (int j = e[q[i]].nex; j; j = e[j].nex) { n       if (!e[j].vis && e[j].adj != f[q[i]]) { n         g[++g[0]] = j; n       } n     } n     for (int j = e[q[i]].nex; j; j = e[j].nex) { n       if (!e[j].vis && e[j].adj == f[q[i]]) { n         g[++g[0]] = j; n         break; n       } n     } n     for (int j = 1; j < g[0]; j += 2) { n       e[g[j]].vis = e[g[j] ^ 1].vis = e[g[j + 1]].vis = e[g[j + 1] ^ 1].vis = n           true; n       ans[++res][0] = e[g[j]].adj; n       ans[res][1] = q[i]; n       ans[res][2] = e[g[j + 1]].adj; n     } n   } n } n int main() { n   int u, v; n   scanf( %d%d , &n, &m); n   tot = n | 1; n   for (int i = 1; i <= m; i++) { n     scanf( %d%d , &u, &v); n     add(u, v); n   } n   for (int i = 1; i <= n; i++) { n     if (!f[i]) { n       bfs(i); n     } n   } n   printf( %d n , res); n   for (int i = 1; i <= res; i++) { n     printf( %d %d %d n , ans[i][0], ans[i][1], ans[i][2]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; n struct date { n   int arr[3]; n   void read() { n     string s; n     cin >> s; n     for (int i = 0; i < 3; i++) { n       arr[i] = (s[i * 3] -  0 ) * 10 + (s[i * 3 + 1] -  0 ); n     } n   } n   void next() { next_permutation(arr, arr + 3); } n   bool valid() { n     if (arr[1] > 12) return false; n     if (arr[0] > (days[arr[1] - 1] + (arr[1] == 2 && arr[2] % 4 == 0))) n       return false; n     return true; n   } n   bool operator<=(const date& oth) const { n     for (int i = 2; i >= 0; i--) { n       if (arr[i] != oth.arr[i]) { n         return arr[i] < oth.arr[i]; n       } n     } n     return true; n   } n }; n int main() { n   date a, b; n   a.read(); n   b.read(); n   for (int i = 0; i < 6; i++) { n     if (b.valid()) { n       b.arr[2] += 18; n       if (b <= a) { n         cout <<  YES n ; n         return 0; n       } n       b.arr[2] -= 18; n     } n     b.next(); n   } n   cout <<  NO n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int T; n   cin >> T; n   while (T--) { n     int result = 0; n     int a[105]; n     int n; n     cin >> n; n     for (int i = 1; i <= n; i++) { n       cin >> a[i]; n       if (a[i] - result - i > 0) { n         result += a[i] - result - i; n       } n     } n     cout << result << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n vector<int> v; n vector<tuple<int, int, int> > g[300002]; n vector<pair<int, long long int> > vv[300002]; n vector<pair<long long int, long long int> > V[300002]; n long long int dist[300002]; n priority_queue<pair<long long int, int>, vector<pair<long long int, int> >, n                greater<pair<long long int, int> > > n     q; n struct st { n   long long int dp[2][2]; n   int l; n   int r; n   st() { n     dp[0][0] = dp[0][1] = dp[1][0] = dp[1][1] = LLONG_MAX; n     l = -1; n     r = -1; n   } n   void set_node(int x) { n     dp[0][0] = 0; n     dp[1][1] = 0; n     dp[0][1] = dist[x]; n     dp[1][0] = dist[x]; n     l = r = x; n   } n   st flip() { n     swap(l, r); n     swap(dp[0][1], dp[1][0]); n     return (*this); n   } n }; n map<pair<int, int>, long long int> mp; n pair<long long int, long long int> look[300002]; n int dep[300002]; n int lcc[19][300002]; n st pat[19][300002]; n inline long long int ds(int t1, int node1, int t2, int node2) { n   if (lcc[0][node1] != node2) swap(node1, node2); n   if (t1 == 0) { n     return look[node1].first; n   } else { n     return look[node1].second; n   } n } n inline st merge(st a, st b) { n   if (a.l == -1) { n     return b; n   } n   if (b.l == -1) { n     return a; n   } n   st r; n   r.l = a.l; n   r.r = b.r; n   long long int w[] = {ds(0, a.r, 0, b.l), ds(1, a.r, 1, b.l)}; n   for (int i = 0; i < 2; i++) { n     for (int j = 0; j < 2; j++) { n       for (int k = 0; k < 2; k++) { n         long long int cs = a.dp[i][j] + b.dp[j][k]; n         cs += w[j]; n         r.dp[i][k] = min(r.dp[i][k], cs); n       } n     } n   } n   return r; n } n inline void dfs(int a, int d = 0, int p = -1, n                 pair<long long int, long long int> c = make_pair(-1, -1)) { n   lcc[0][a] = p; n   dep[a] = d; n   look[a] = c; n   int idx = 0; n   for (auto go : vv[a]) { n     if (go.first == p) { n       idx++; n       continue; n     } n     dfs(go.first, d + 1, a, V[a][idx]); n     idx++; n   } n } n int lca(int a, int b) { n   if (dep[a] < dep[b]) swap(a, b); n   for (int i = 0; i < 19; i++) { n     if (((dep[a] - dep[b]) >> i) & 1) { n       a = lcc[i][a]; n     } n   } n   if (a == b) return a; n   for (int i = 19 - 1; i >= 0; i--) { n     if (lcc[i][a] != lcc[i][b]) { n       a = lcc[i][a]; n       b = lcc[i][b]; n     } n   } n   return lcc[0][a]; n } n inline st go(int a, int f) { n   st r; n   if (f == 0) { n     return r; n   } n   for (int i = 0; i < 19; i++) { n     if ((f >> i) & 1) { n       r = merge(r, pat[i][a]); n       a = lcc[i][a]; n     } n   } n   return r; n } n int qq; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     long long int w; n     scanf( %lld , &w); n     v.push_back(w); n     vv[n].push_back(make_pair(i, w)); n   } n   for (int i = 1; i < n; i++) { n     long long int a, b, c, d; n     scanf( %lld%lld%lld%lld , &a, &b, &c, &d); n     a--; n     b--; n     if (a < b) mp[make_pair(a, b)] = c; n     if (b < a) mp[make_pair(b, a)] = c; n     if (a < b) mp[make_pair(a + n, b + n)] = d; n     if (b < a) mp[make_pair(b + n, a + n)] = d; n     g[a].push_back(make_tuple(b, c, d)); n     g[b].push_back(make_tuple(a, c, d)); n     vv[a].push_back(make_pair(b, c + d)); n     vv[b].push_back(make_pair(a, c + d)); n     V[a].push_back(make_pair(c, d)); n     V[b].push_back(make_pair(c, d)); n   } n   memset(dist, -1, sizeof(dist)); n   dist[n] = 0; n   q.push(make_pair(0, n)); n   while (!q.empty()) { n     int b = q.top().second; n     long long int cc = q.top().first; n     q.pop(); n     if (dist[b] != cc) continue; n     for (auto go : vv[b]) { n       if (dist[go.first] == -1 || dist[go.first] > dist[b] + go.second) { n         dist[go.first] = dist[b] + go.second; n         q.push(make_pair(dist[go.first], go.first)); n       } n     } n   } n   dfs(0); n   for (int j = 0; j < n; j++) { n     pat[0][j].set_node(j); n   } n   for (int i = 0; i + 1 < 19; i++) { n     for (int j = 0; j < n; j++) { n       if (lcc[i][j] != -1) { n         lcc[i + 1][j] = lcc[i][lcc[i][j]]; n         pat[i + 1][j] = merge(pat[i][j], pat[i][lcc[i][j]]); n       } else { n         lcc[i + 1][j] = -1; n       } n     } n   } n   cin >> qq; n   while (qq--) { n     int l, r; n     scanf( %d%d , &l, &r); n     l--; n     r--; n     l = (l / 2) + (l % 2) * n; n     r = (r / 2) + (r % 2) * n; n     int L = l; n     int R = r; n     if (L >= n) L -= n; n     if (R >= n) R -= n; n     swap(l, L); n     swap(r, R); n     int lc = lca(l, r); n     st ret = merge(go(l, dep[l] - dep[lc] + 1), go(r, dep[r] - dep[lc]).flip()); n     printf( %lld n , ret.dp[L >= n][R >= n]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int h1, m1, h2, m2; n   scanf( %d:%d %d:%d , &h1, &m1, &h2, &m2); n   if (m1 < m2) m1 += 60, h2++; n   if (h1 < h2) h1 += 24; n   printf( %.2d:%.2d n , h1 - h2, m1 - m2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool cmp(const pair<long long, long long> &a, n          const pair<long long, long long> &b) { n   return (a.second < b.second); n } n long long power(long long x, long long y) { n   long long res = 1; n   x = x; n   if (x == 0) return 0; n   while (y > 0) { n     if (y & 1) res = (res * x); n     y = y >> 1; n     x = (x * x); n   } n   return res; n } n int main() { n   long long t = 1, i, j, k, x, y, z, n, m; n   cin >> t; n   while (t--) { n     cin >> n; n     if (n == 1) { n       cout <<  0 n ; n       continue; n     } n     long long p = 8; n     long long sum = 0; n     for (i = 1; i <= (n / 2); i++) { n       p = 8 * i; n       sum = sum + (p * i); n     } n     cout << sum << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> primes; n bool vis[20000000]; n vector<long long> a, b; n long long v[20000000]; n void genp() { n   for (long long i = 2; i < 20000000; i++) { n     if (!vis[i]) { n       primes.push_back(i); n       for (long long j = 1; j * i < 20000000; j++) vis[j * i] = 1; n     } n   } n } n void mark(long long x) { n   for (long long i = 2; i <= sqrt(x); i++) { n     long long z = i; n     if (x % z == 0) { n       long long f = x / z; n       for (long long j = 1; j * z < 20000000; j++) v[j * z] = 1; n       for (long long j = 1; j * f < 20000000; j++) v[j * f] = 1; n     } n   } n   long long z = x; n   for (long long j = 1; j * z < 20000000; j++) v[j * z] = 1; n } n int main() { n   ios_base::sync_with_stdio(0); n   genp(); n   v[0] = 1; n   v[1] = 1; n   long long n; n   cin >> n; n   for (long long i = 0; i < n; i++) { n     long long x; n     cin >> x; n     a.push_back(x); n   } n   bool ok = 0; n   long long s = 2; n   for (long long i = 0; i < n; i++) { n     if (!ok) { n       long long x = a[i]; n       if (!v[x]) { n         b.push_back(x); n         mark(x); n       } else { n         ok = 1; n         for (long long k = x + 1; k <= 1e9; k++) { n           if (!v[k]) { n             b.push_back(k); n             mark(k); n             break; n           } n         } n       } n     } else { n       for (s = s; s <= 1e9; s++) { n         if (!v[s]) { n           b.push_back(s); n           mark(s); n           break; n         } n       } n     } n   } n   for (long long i = 0; i < n; i++) cout << b[i] <<    ; n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = int(2e9) + 9; n const double eps = 1e-9; n const double pi = 3.14159265358979323846264338327950; n int main() { n   int p, n; n   int a[305]; n   scanf( %d %d , &p, &n); n   memset(a, -1, sizeof(a)); n   for (int i = 1; i <= n; i++) { n     int x; n     scanf( %d , &x); n     if (a[x % p] != -1) { n       printf( %d n , i); n       return 0; n     } n     a[x % p] = 1; n   } n   printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n char a[55][55]; n int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1}; n vector<pair<int, int> > G[2555]; n int vis[2555]; n int bfs(int i, int j) { n   memset(vis, -1, sizeof vis); n   deque<pair<int, int> > q; n   q.push_front(make_pair(i * m + j, 0)); n   int mx = 0; n   while (!q.empty()) { n     pair<int, int> cur = q.front(); n     q.pop_front(); n     int u = cur.first, w = cur.second; n     vis[u] = w; n     if (a[u / m][u % m] ==  B ) mx = w; n     for (int k = 0; k < (int)G[u].size(); k++) { n       int v = G[u][k].first, w2 = G[u][k].second; n       if (vis[v] == -1) { n         vis[v] = w + w2; n         if (w2 == 0) n           q.push_front(make_pair(v, w)); n         else n           q.push_back(make_pair(v, w + w2)); n       } n     } n   } n   return mx; n } n int main() { n   bool ok = 0; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) scanf( %s , a[i]); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) n       if (a[i][j] ==  B ) ok = 1; n   if (!ok) { n     printf( 0 n ); n     return 0; n   } n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       for (int k = 0; k < 4; k++) { n         int newI = i + dx[k], newJ = j + dy[k]; n         if (newI < 0 || newJ < 0 || newI >= n || newJ >= m) continue; n         if (a[i][j] == a[newI][newJ]) n           G[i * m + j].push_back(make_pair(newI * m + newJ, 0)); n         else n           G[i * m + j].push_back(make_pair(newI * m + newJ, 1)); n       } n     } n   int mn = n * m + 1; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       mn = min(mn, bfs(i, j)); n     } n   printf( %d n , mn + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long cnt[3], dp[1010][4], n, p; n struct seg { n   long long l, r, v; n   seg() {} n   seg(long long _l, long long _r, long long _v) { l = _l, r = _r, v = _v; } n }; n vector<seg> v; n long long cal(long long x, long long y) { n   if (v[x].v != 0 && v[y].v != 0) return 0; n   if (v[x].v != 1 && v[y].v != 1) return 1; n   return 2; n } n long long get(long long x, long long y) { n   if (x % 3 == 0) return -(!(y & 1)); n   if (x % 3 == 2) return (y & 1); n   return 0; n } n long long npair(long long a, long long b) { n   return ((a + b) * (a - b + 1) / 2) % 1000000007; n } n void upd(long long& a, long long b) { a = (a + b) % 1000000007; } n int main() { n   cin >> n >> p; n   v.push_back(seg(1, 2, 0)); n   long long nxt = 3; n   while (nxt <= p) { n     long long x = nxt / 3, y = nxt - x, id1, id2; n     for (long long i = 0; i < ((long long)(v).size()); i++) { n       if (v[i].l <= x && x <= v[i].r) id1 = i; n       if (v[i].l <= y && y <= v[i].r) id2 = i; n     } n     long long g = cal(id1, id2); n     long long cnt1 = v[id1].r - x + 1; n     long long cnt2 = v[id2].r - y + 1; n     cnt1 = (cnt1 - 1) * 3 + 3 - (nxt % 3); n     cnt2 = cnt2 + cnt2 / 2 + get(nxt, cnt2); n     long long end = nxt + min(cnt1, cnt2) - 1; n     while (!v.empty() && g == v[((long long)(v).size()) - 1].v) n       nxt = v[((long long)(v).size()) - 1].l, v.pop_back(); n     v.push_back(seg(nxt, end, g)); n     nxt = end + 1; n   } n   for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++) n     upd(cnt[it->v], npair(p - it->l, p - min(p, it->r))); n   dp[0][0] = 1; n   for (long long i = 1; i <= n; i++) n     for (long long j = 0; j < 4; j++) n       for (long long k = 0; k < 3; k++) n         upd(dp[i][j], dp[i - 1][j ^ k] * cnt[k]); n   cout << (dp[n][1] + dp[n][2] + dp[n][3]) % 1000000007 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n struct str { n   long long cnt[26], len = 0; n   pair<long long, long long> pref = {0, 0}, suf = {0, 0}; n   str() { memset(cnt, 0, sizeof(cnt)); } n   str(string s) { n     memset(cnt, 0, sizeof(cnt)); n     len = ((int)s.size()); n     pair<long long, long long> mx = {0, 0}; n     for (int i = 0; i < ((int)s.size()); ++i) { n       if (s[i] -  a  != mx.first) n         mx = {s[i] -  a , 1}; n       else n         mx.second++; n       cnt[mx.first] = max(cnt[mx.first], mx.second); n     } n     mx = {s[0] -  a , 0}; n     for (int i = 0; i < ((int)s.size()); ++i) { n       if (s[i] -  a  == mx.first) n         mx.second++; n       else n         break; n     } n     pref = mx; n     mx = {s[((int)s.size()) - 1] -  a , 0}; n     for (int i = ((int)s.size()) - 1; i >= 0; --i) { n       if (s[i] -  a  == mx.first) n         mx.second++; n       else n         break; n     } n     suf = mx; n   } n }; n int n; n void debug(str x) { n   cerr <<  x.len  n        <<   =   << x.len << endl; n   cerr <<  x.pref.first  n        <<   =   << x.pref.first << endl; n   cerr <<  x.pref.second  n        <<   =   << x.pref.second << endl; n   cerr <<  x.suf.first  n        <<   =   << x.suf.first << endl; n   cerr <<  x.suf.second  n        <<   =   << x.suf.second << endl; n   for (int i = 0; i < 26; ++i) cout << x.cnt[i] <<    ; n   cout <<   n n ; n } n str merge(str A, str B) { n   str ret = str(); n   ret.pref = B.pref; n   ret.suf = B.suf; n   if (A.len + B.len > 1e9) n     ret.len = -1; n   else n     ret.len = A.len * B.len + A.len + B.len; n   if (A.pref.second == A.len && B.pref.second == B.len) { n     if (A.pref.first == B.pref.first) { n       ret.pref = ret.suf = {A.pref.first, ret.len}; n       ret.cnt[A.pref.first] = ret.len; n     } else { n       ret.cnt[A.pref.first] = 1; n       ret.cnt[B.pref.first] = B.pref.second; n     } n   } else { n     for (int i = 0; i < 26; ++i) { n       ret.cnt[i] = B.cnt[i]; n       if (A.cnt[i]) ret.cnt[i] = max(ret.cnt[i], 1LL); n       if (B.pref.second == B.len && i == B.pref.first && A.cnt[i] > 0) { n         ret.cnt[i] = max(ret.cnt[i], B.len * A.cnt[i] + A.cnt[i] + B.len); n         if (A.pref.first == B.pref.first) n           ret.pref = {A.pref.first, n                       B.len * A.pref.second + A.pref.second + B.len}; n         if (A.suf.first == B.pref.first) n           ret.suf = {A.suf.first, B.len * A.suf.second + A.suf.second + B.len}; n       } else { n         if (i == B.pref.first) n           ret.cnt[i] = max(ret.cnt[i], B.pref.second + (A.cnt[i] > 0)); n         if (i == B.suf.first) n           ret.cnt[i] = max(ret.cnt[i], B.suf.second + (A.cnt[i] > 0)); n         if (B.pref.first == B.suf.first && B.pref.first == i && A.cnt[i] > 0) n           ret.cnt[i] = max(ret.cnt[i], B.pref.second + B.suf.second + 1); n       } n       if (ret.cnt[i] > 1e9) ret.cnt[i] = 1; n     } n   } n   return ret; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   string s; n   cin >> s; n   str sol = str(s); n   for (int i = 0; i < n - 1; ++i) { n     cin >> s; n     str x = str(s); n     sol = merge(sol, x); n   } n   long long pr = 0; n   for (int i = 0; i < 26; ++i) pr = max(pr, sol.cnt[i]); n   cout << pr; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n const double eps = 1e-11; n const int inf = 0x7FFFFFFF; n template <class T> n inline void checkmin(T &a, T b) { n   if (b < a) a = b; n } n template <class T> n inline void checkmax(T &a, T b) { n   if (b > a) a = b; n } n template <class T> n inline T sqr(T x) { n   return x * x; n } n template <class T> n void show(T a, int n) { n   for (int i = 0; i < n; ++i) cout << a[i] <<    ; n   cout << endl; n } n template <class T> n void show(T a, int r, int l) { n   for (int i = 0; i < r; ++i) show(a[i], l); n   cout << endl; n } n int sgn(double x) { return x < -eps ? -1 : x > eps; } n int main() { n   double y1, y2, yw, xb, yb, r; n   while (cin >> y1 >> y2 >> yw >> xb >> yb >> r) { n     if (sgn(y2 - y1 - 2 * r) < 0) { n       puts( -1 ); n       continue; n     } else { n       double y = (y1 + r), yyw = yw - r; n       double ax = (yyw - y) / (yyw - y + yyw - yb) * xb; n       double ds = (y2 - y) * ax / (sqrt(sqr(ax) + sqr(yyw - y))); n       if (sgn(ds - r) <= 0) { n         puts( -1 ); n         continue; n       } n       printf( %.12lf n , ax); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 5; n int a[N], ret[N]; n pair<pair<int, int>, int> qi[N]; n int pen[N]; n void update(int ind, int add) { n   while (ind < N) { n     pen[ind] += add; n     ind += ind & (-ind); n   } n } n int query(int ind) { n   int ret = 0; n   while (ind > 0) { n     ret = ret + pen[ind]; n     ind = ind & (ind - 1); n   } n   return ret; n } n pair<int, int> seg[N * 4]; n int lazy[N * 4]; n void init(int pos, int l, int r) { n   if (l == r) { n     seg[pos] = {a[l], l}; n     return; n   } n   int mid = (l + r) / 2; n   init(pos * 2, l, mid); n   init(pos * 2 + 1, mid + 1, r); n   seg[pos] = max(seg[pos * 2], seg[pos * 2 + 1]); n } n void push(int pos, int l, int r) { n   if (lazy[pos] != 0) { n     seg[pos].first += lazy[pos]; n     if (l != r) { n       lazy[pos * 2] += lazy[pos]; n       lazy[pos * 2 + 1] += lazy[pos]; n     } n     lazy[pos] = 0; n   } n } n pair<int, int> query(int pos, int l, int r, int ql, int qr) { n   push(pos, l, r); n   if (r < ql || qr < l) { n     return {-1e9, 0}; n   } n   if (ql <= l && r <= qr) { n     return seg[pos]; n   } n   int mid = (l + r) / 2; n   return max(query(pos * 2, l, mid, ql, qr), n              query(pos * 2 + 1, mid + 1, r, ql, qr)); n } n void update(int pos, int l, int r, int ql, int qr, int val) { n   push(pos, l, r); n   if (r < ql || qr < l) { n     return; n   } n   if (ql <= l && r <= qr) { n     lazy[pos] = val; n     push(pos, l, r); n     return; n   } n   int mid = (l + r) / 2; n   update(pos * 2, l, mid, ql, qr, val); n   update(pos * 2 + 1, mid + 1, r, ql, qr, val); n   seg[pos] = max(seg[pos * 2], seg[pos * 2 + 1]); n } n void update(int pos, int l, int r, int ind, pair<int, int> val) { n   push(pos, l, r); n   if (r < ind || ind < l) { n     return; n   } n   if (l == r) { n     seg[pos] = val; n     return; n   } n   int mid = (l + r) / 2; n   update(pos * 2, l, mid, ind, val); n   update(pos * 2 + 1, mid + 1, r, ind, val); n   seg[pos] = max(seg[pos * 2], seg[pos * 2 + 1]); n } n void solve() { n   int n, q; n   scanf( %d %d , &n, &q); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n   } n   int t = 0; n   for (int i = 1; i <= n; ++i) { n     if (i - t <= a[i] && a[i] <= i) { n       a[i] = i - a[i] - t; n       ++t; n       update(i, 1); n     } else { n       a[i] = -1e9; n     } n   } n   init(1, 1, n); n   for (int i = 0; i < q; ++i) { n     scanf( %d %d  , &qi[i].first.first, &qi[i].first.second); n     qi[i].second = i; n   } n   sort(qi, qi + q); n   int pos = 0; n   for (int i = 0; i < q; ++i) { n     int x = qi[i].first.first, y = qi[i].first.second; n     while (pos + 1 <= x) { n       ++pos; n       if (query(1, 1, n, pos, pos).first == 0) { n         update(1, 1, n, pos + 1, n, 1); n         update(1, 1, n, pos, {-1e9, 0}); n         update(pos, -1); n       } n       while (true) { n         pair<int, int> qr = query(1, 1, n, 1, n); n         if (qr.first <= 0) { n           break; n         } n         update(qr.second, -1); n         update(1, 1, n, qr.second, {-1e9, 0}); n         update(1, 1, n, qr.second, n, 1); n       } n     } n     ret[qi[i].second] = query(n - y); n   } n   for (int i = 0; i < q; ++i) { n     printf( %d n , ret[i]); n   } n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e5 + 5; n int n, m; n long long t[MAX << 2], tag[MAX << 2]; n int sz = 1; n inline void Period(int k, int l, int r, int a, int b, long long x) { n   if (a > r || b < l) return; n   if (a >= l && b <= r) { n     tag[k] = t[k] = x; n     return; n   } n   Period(k << 1, l, r, a, (a + b) >> 1, x); n   Period((k << 1) + 1, l, r, ((a + b) >> 1) + 1, b, x); n   t[k] = max(t[k << 1], t[(k << 1) + 1]); n } n inline long long Query(int k, int l, int r, int a, int b) { n   if (tag[k]) { n     t[k] = tag[k]; n     tag[k << 1] = max(tag[k << 1], tag[k]); n     tag[(k << 1) + 1] = max(tag[(k << 1) + 1], tag[k]); n     tag[k] = 0; n   } n   if (a > r || b < l) return 0; n   if (a >= l && b <= r) return t[k]; n   return max(Query(k << 1, l, r, a, (a + b) >> 1), n              Query((k << 1) + 1, l, r, ((a + b) >> 1) + 1, b)); n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n; n   while (sz < n) sz <<= 1; n   for (int i = 1; i <= n; i++) { n     long long x; n     cin >> x; n     Period(1, i, i, 1, sz, x); n   } n   cin >> m; n   while (m--) { n     int x; n     long long h; n     cin >> x >> h; n     long long res = Query(1, 1, x, 1, sz); n     cout << res << endl; n     Period(1, 1, x, 1, sz, res + h); n   } n   return 0; n } n


#include <bits/stdc++.h> n int n, m; n char a[10000]; n char b[10000]; n int main() { n   scanf( %s %s , a, b); n   n = strlen(a); n   m = strlen(b); n   int minn = 10000000; n   for (int i = -m + 1; i < n; i++) { n     int count = 0; n     for (int j = 0; j < m; j++) { n       if (i + j < 0 || i + j >= n) { n         count++; n       } else if (a[i + j] != b[j]) n         count++; n     } n     if (count < minn) minn = count; n   } n   printf( %d n , minn); n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 gen(time(NULL)); n const long double eps = 1e-9; n const int inf = 1e9; n const int mod = 1e9 + 7; n const long long infinity = 2 * 1e18; n vector<int> g[100005]; n int n, m, q; n int p2[100005], d[100005], cmp[100005]; n int rt[100005]; n vector<int> plen[100005]; n vector<int> cs[100005]; n vector<long long> csp[100005]; n int s[100005]; n void dfs_cl(int u, int e, int cl) { n   cmp[u] = cl; n   cs[cl].push_back(u); n   for (auto v : g[u]) n     if (v != e) dfs_cl(v, u, cl); n } n int dfs(int u, int e) { n   for (auto v : g[u]) n     if (v != e) plen[u].push_back(dfs(v, u) + 1); n   int maxc = 0; n   sort(plen[u].begin(), plen[u].end(), greater<int>()); n   for (auto v : plen[u]) maxc = max(v, maxc); n   if (plen[u].size()) { n     if (plen[u].size() == 1) n       d[cmp[u]] = max(d[cmp[u]], plen[u].back()); n     else n       d[cmp[u]] = max(d[cmp[u]], plen[u][0] + plen[u][1]); n   } n   return p2[u] = maxc; n } n void path(int u, int e, int carry) { n   p2[u] = max(p2[u], carry); n   if (plen[u].size() <= 1) { n     for (auto v : g[u]) n       if (v != e) path(v, u, carry + 1); n     return; n   } n   for (auto v : g[u]) n     if (v != e) { n       int x = p2[v] + 1; n       int t = 0; n       if (x == plen[u][0]) t++; n       path(v, u, max(carry + 1, plen[u][t] + 1)); n     } n } n map<pair<int, int>, double> memo; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m >> q; n   int u, v; n   for (int i = 0; i < m; i++) { n     cin >> u >> v; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   int cl = 0; n   for (int i = 1; i <= n; i++) n     if (!cmp[i]) { n       dfs_cl(i, i, ++cl); n       rt[cl] = i; n     } n   for (int i = 1; i <= n; i++) s[cmp[i]]++; n   for (int i = 1; i <= cl; i++) dfs(rt[i], -1); n   for (int i = 1; i <= cl; i++) path(rt[i], -1, 0); n   for (int i = 1; i <= cl; i++) n     sort(cs[i].begin(), cs[i].end(), n          [&](int a, int b) { return p2[a] < p2[b]; }); n   for (int i = 1; i <= cl; i++) n     for (auto v : cs[i]) n       csp[i].push_back(csp[i].size() ? csp[i].back() + p2[v] + 1 : p2[v] + 1); n   for (int i = 0; i < q; i++) { n     cin >> u >> v; n     u = cmp[u], v = cmp[v]; n     if (u == v) n       cout << -1 <<   n ; n     else { n       if (s[u] > s[v]) swap(u, v); n       if (memo.count(make_pair(u, v))) n         cout << memo[make_pair(u, v)] <<   n ; n       else { n         long long ans = 0; n         int dp = max(d[u], d[v]); n         for (auto x : cs[u]) { n           if (cs[v].size() == 1) { n             ans += max(dp, p2[x] + p2[cs[v].back()] + 1); n             continue; n           } n           int l = -1, r = cs[v].size() - 1; n           while (l < r - 1) { n             int m = (l + r) / 2; n             if (p2[cs[v][m]] + p2[x] + 1 < dp) n               l = m; n             else n               r = m; n           } n           ans += (r * 1LL * dp + p2[x] * 1LL * (s[v] - r) + csp[v].back() - n                   (r ? csp[v][r - 1] : 0)); n         } n         memo[make_pair(u, v)] = (double)ans / (s[v] * 1LL * s[u]); n         cout << fixed << setprecision(10) << memo[make_pair(u, v)] <<   n ; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 10; n const int inf = 2147483647; n const long double pi = acos(-1); n inline unsigned long long read() { n   unsigned long long data = 0, w = 1; n   char ch = getchar(); n   while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar(); n   if (ch ==  - ) w = -1, ch = getchar(); n   while (ch <=  9  && ch >=  0 ) data = data * 10 + ch - 48, ch = getchar(); n   return data * w; n } n inline void file() { n   freopen( n        a  n        .in , n        r , stdin); n   freopen( n        a  n        .out , n        w , stdout); n } n int n; n inline int check(unsigned long long x) { n   int mx = 1; n   for (int i = 2; 1ll * i * i <= x; i++) n     if (x % i == 0) n       mx = max((unsigned long long)mx, max((unsigned long long)i, x / i)); n   return mx; n } n int main() { n   n = read(); n   for (int i = 1; i <= n; i++) { n     unsigned long long x = read(), r = x; n     int cnt = 0; n     while (r) { n       cnt++; n       r >>= 1; n     } n     if (x == (1ll << cnt) - 1) n       printf( %d n , check(x)); n     else n       printf( %I64d n , (1ll << cnt) - 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   int n, max_len = 0, tmpl, tmpr; n   pair<int, int> fmaxl, fminr, smaxl(-1, -1), sminr(-1, -1); n   cin >> n >> tmpl >> tmpr; n   fmaxl = make_pair(tmpl, tmpr); n   fminr = make_pair(tmpl, tmpr); n   for (int i = 1; i < n; i++) { n     cin >> tmpl >> tmpr; n     if (tmpl >= fmaxl.first) { n       smaxl = fmaxl; n       fmaxl = make_pair(tmpl, tmpr); n     } n     if (tmpr <= fminr.second) { n       sminr = fminr; n       fminr = make_pair(tmpl, tmpr); n     } n     if (smaxl.first == -1 || (tmpl < fmaxl.first && tmpl > smaxl.first)) n       smaxl = make_pair(tmpl, tmpr); n     if (sminr.first == -1 || (tmpr > fminr.second && tmpr < sminr.second)) n       sminr = make_pair(tmpl, tmpr); n   } n   if (fmaxl == fminr && smaxl == sminr) n     cout << sminr.second - sminr.first; n   else if (fmaxl == fminr) n     cout << max((sminr.second - smaxl.first), (sminr.second - smaxl.first)); n   else { n     max_len = max((fminr.second - smaxl.first), (sminr.second - fmaxl.first)); n     max_len < 0 ? cout << 0 : cout << max_len; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1000005]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int i, j, k, l, m, n, t, r, cnt; n   int flag = 0; n   long long ans = 0, an = 0; n   t = 1; n   while (t--) { n     cin >> n >> m; n     cout << min(n, m) + 1 << endl; n     int x, y; n     x = 0; n     y = m; n     while (x <= n && y >= 0) { n       cout << x <<     << y << endl; n       x++; n       y--; n     } n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n inline long long sqr(long long x) { return x * x; } n mt19937 Random((int)time(0)); n inline long long rnd(long long x) { return Random() % x; } n const long long INF = (long long)1e9 + 2018; n const long long MOD = (long long)1e9 + 7; n const long double PI = acos(-1.0); n pair<int, int> cnt(int n) { n   if (n & 1) { n     return {sqr(n / 2 + 1) + sqr(n / 2), n * n - sqr(n / 2 + 1) - sqr(n / 2)}; n   } else { n     return {n * n / 2, n * n / 2}; n   } n } n void $main() { n   int n; n   cin >> n; n   int a = 0, b = 0; n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s >> s; n     a += s ==  hard ; n     b += s ==  soft ; n   } n   for (int i = 1;; i++) { n     pair<int, int> res = cnt(i); n     if ((res.first >= a && res.second >= b) || n         (res.second >= a && res.first >= b)) { n       cout << i; n       return; n     } n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cout.setf(ios_base::fixed, ios_base::floatfield); n   cout.precision(10); n   $main(); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e5 + 7; n int T, n, vis[N], can[N]; n map<char, int> mp, ha = {{ ? , 0}, { V , 1}, { K , 2}}; n char s[N]; n bool check(int l) { n   static int vis[N]; n   for (int i = 0; i < l; ++i) { n     int who = ha[s[i]], now = i + l; n     while (now < n) { n       if (who && s[now] !=  ?  && who != ha[s[now]]) return false; n       if (s[now] !=  ? ) who = ha[s[now]]; n       now += l; n     } n   } n   return true; n } n int main() { n   cin >> T; n   while (T--) { n     scanf( %d , &n); n     scanf( %s , s); n     memset(vis, 0, sizeof(int) * (n + 1)); n     memset(can, 0, sizeof(int) * (n + 1)); n     mp.clear(); n     for (int i = 0; i < n; ++i) mp[s[i]] = 1; n     if (mp[ V ] + mp[ K ] <= 1) { n       printf( %d n , n); n       for (int i = 1; i <= n; ++i) printf( %d%c , i, i == n ?   n  :    ); n       continue; n     } n     for (int i = 2; i <= n; ++i) { n       if (!vis[i]) { n         if (check(i)) { n           for (int j = i; j <= n; j += i) can[j] = true, vis[j] = 0; n           can[i] = true; n         } n       } n     } n     int ans = 0, first = 1; n     for (int i = 2; i <= n; ++i) ans += can[i]; n     printf( %d n , ans); n     for (int i = 2; i <= n; ++i) { n       if (can[i]) { n         if (first) n           first = false; n         else n           putchar(   ); n         printf( %d , i); n       } n     } n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n int getbit(T s, int i) { n   return (s >> i) & 1; n } n template <class T> n T onbit(T s, int i) { n   return s | (T(1) << i); n } n template <class T> n T offbit(T s, int i) { n   return s & (~(T(1) << i)); n } n template <class T> n int cntbit(T s) { n   return __builtin_popcount(s); n } n template <class T> n T gcd(T a, T b) { n   T r; n   while (b != 0) { n     r = a % b; n     a = b; n     b = r; n   } n   return a; n } n template <class T> n T lcm(T a, T b) { n   return a / gcd(a, b) * b; n } n int test; n int n; n long long RR; n vector<int> KK[105]; n long long HH(long long x) { return x * x * x * x * 3 + 425689 * x - 23156667; } n long long go(int par, int u) { n   long long res = 32131; n   for (int i = 0; i < (((int)(KK[u]).size())); ++i) { n     int v = KK[u][i]; n     if (v == par) continue; n     res += HH(go(u, v)); n   } n   return res; n } n long long hash_tree(vector<pair<int, int> > V) { n   int d[105]; n   memset(d, 0, sizeof(d)); n   for (int i = (1); i <= (n); ++i) n     if (((int)(KK[i]).size())) KK[i].clear(); n   for (int i = 0; i < (((int)(V).size())); ++i) { n     int u = V[i].first, v = V[i].second; n     KK[u].push_back(v); n     KK[v].push_back(u); n     d[u]++; n     d[v]++; n   } n   int number = 0; n   int que[105], size = 0, que1[105], size1 = 0; n   for (int i = (1); i <= (n); ++i) { n     if (d[i] >= 1) number++; n     if (d[i] == 1) que[size++] = i; n   } n   while (true) { n     if (size <= 2) break; n     size1 = 0; n     for (int t = 0; t < (size); ++t) { n       que1[size1++] = que[t]; n     } n     size = 0; n     for (int t = 0; t < (size1); ++t) { n       int u = que1[t]; n       for (int j = 0; j < (((int)(KK[u]).size())); ++j) { n         int v = KK[u][j]; n         d[v]--; n         if (d[v] == 1) { n           que[size++] = v; n         } n       } n     } n   } n   long long res = 325843; n   vector<long long> Vll; n   for (int i = 0; i < (size); ++i) { n     Vll.push_back(go(0, que[i])); n   } n   sort((Vll).begin(), (Vll).end()); n   for (int i = 0; i < (size); ++i) { n     res = res * 1000000007 + Vll[i]; n   } n   return res; n } n long long hash_forest(vector<pair<int, int> > V) { n   bool flag[105]; n   vector<int> VV[105]; n   memset(flag, 0, sizeof(flag)); n   for (int i = 0; i < (((int)(V).size())); ++i) { n     int u = V[i].first, v = V[i].second; n     VV[u].push_back(v); n     VV[v].push_back(u); n   } n   vector<long long> Vll; n   for (int i = 1; i <= n; i++) n     if (!flag[i]) { n       flag[i] = 1; n       int que[105], size = 0; n       que[size++] = i; n       vector<pair<int, int> > temp; n       for (int t = 0; t < (size); ++t) { n         int u = que[t]; n         for (int j = 0; j < (((int)(VV[u]).size())); ++j) { n           int v = VV[u][j]; n           if (!flag[v]) { n             flag[v] = 1; n             que[size++] = v; n             temp.push_back(make_pair(u, v)); n           } n         } n       } n       Vll.push_back(hash_tree(temp)); n     } n   sort((Vll).begin(), (Vll).end()); n   long long res = 132435; n   for (int i = 0; i < ((int)(Vll).size()); i++) res = res * 1000000007 + Vll[i]; n   return res; n } n long long hash_alot(vector<vector<pair<int, int> > > V) { n   vector<long long> Vll; n   for (int i = 0; i < ((int)(V).size()); i++) { n     Vll.push_back(hash_forest(V[i])); n   } n   sort((Vll).begin(), (Vll).end()); n   long long res = 132435; n   for (int i = 0; i < ((int)(Vll).size()); i++) res = res * 1000000007 + Vll[i]; n   return res; n } n bool calcu(vector<pair<int, int> > V) { n   vector<vector<pair<int, int> > > VV; n   for (int i = (1); i <= (n); ++i) { n     vector<pair<int, int> > temp; n     for (int j = 0; j < (((int)(V).size())); ++j) { n       if (V[j].first != i && V[j].second != i) { n         temp.push_back(V[j]); n       } n     } n     VV.push_back(temp); n   } n   long long res = hash_alot(VV); n   return res == RR; n } n void cal(vector<pair<int, int> > V) { n   bool have[105]; n   memset(have, 0, sizeof(have)); n   for (int i = 0; i < (((int)(V).size())); ++i) { n     int u = V[i].first, v = V[i].second; n     have[u] = 1; n     have[v] = 1; n   } n   for (int i = (1); i <= (n); ++i) n     if (!have[i]) { n       for (int j = (1); j <= (n); ++j) n         if (j != i) { n           vector<pair<int, int> > VV; n           VV = V; n           VV.push_back(make_pair(i, j)); n           if (calcu(VV)) { n             cout <<  YES n ; n             for (int t = 0; t < (((int)(VV).size())); ++t) { n               cout << VV[t].first <<     << VV[t].second <<   n ; n             } n             return; n           } n         } n     } n   cout <<  NO n ; n } n void solve() { n   cin >> n >> n; n   vector<vector<pair<int, int> > > V; n   for (int i = 0; i < (n); ++i) { n     int num; n     cin >> num; n     vector<pair<int, int> > temp; n     for (int j = 0; j < (num); ++j) { n       int u, v; n       cin >> u >> v; n       temp.push_back(make_pair(u, v)); n     } n     V.push_back(temp); n   } n   RR = hash_alot(V); n   for (int i = 0; i < n; i++) { n     if (((int)(V[i]).size()) == n - 2) { n       cal(V[i]); n       break; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> test; n   for (int itest = 0; itest < (test); ++itest) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, res; n int mat[405][405]; n int cnt[405][405][4]; n bool valid(int x1, int y1, int x2, int y2) { n   int num = 2; n   if (x1 == x2) num = 1; n   if (y1 == y2) num = 0; n   if (x1 + y1 == x2 + y2) num = 3; n   return cnt[x1][y1][num] == cnt[x2][y2][num]; n } n void check(int x1, int y1, int x2, int y2, int x3, int y3) { n   if (x1 < 1 || y1 < 1 || x2 < 1 || y2 < 1 || x3 < 1 || y3 < 1) return; n   if (x1 > n || y1 > m || x2 > n || y2 > m || x3 > n || y3 > m) return; n   if (mat[x1][y1] || mat[x2][y2] || mat[x3][y3]) return; n   if (!valid(x1, y1, x2, y2)) return; n   if (!valid(x2, y2, x3, y3)) return; n   if (!valid(x1, y1, x3, y3)) return; n   res++; n } n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       char c; n       cin >> c; n       mat[i][j] = (c -  0 ); n       cnt[i][j][0] = cnt[i - 1][j][0] + mat[i][j]; n       cnt[i][j][1] = cnt[i][j - 1][1] + mat[i][j]; n       cnt[i][j][2] = cnt[i - 1][j - 1][2] + mat[i][j]; n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = m; j >= 1; j--) { n       cnt[i][j][3] = cnt[i - 1][j + 1][3] + mat[i][j]; n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       for (int k = 1; k <= min(n, m); k++) { n         check(i, j, i + k, j, i, j + k); n         check(i, j, i - k, j, i, j + k); n         check(i, j, i + k, j, i, j - k); n         check(i, j, i - k, j, i, j - k); n         check(i - k, j, i, j + k, i, j - k); n         check(i + k, j, i, j + k, i, j - k); n         check(i + k, j, i - k, j, i, j - k); n         check(i + k, j, i - k, j, i, j + k); n       } n     } n   } n   cout << res <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline bool upmin(T &x, T y) { n   return y < x ? x = y, 1 : 0; n } n template <typename T> n inline bool upmax(T &x, T y) { n   return x < y ? x = y, 1 : 0; n } n const long double eps = 1e-11; n const long double pi = acos(-1); n const int oo = 1 << 30; n const long long loo = 1ll << 62; n const int MAXN = 5005; n const int mods = 998244353; n const int INF = 0x3f3f3f3f; n inline int read() { n   int f = 1, x = 0; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = (x << 3) + (x << 1) + (c ^ 48); n     c = getchar(); n   } n   return x * f; n } n int f[MAXN][MAXN][2], g[MAXN][2], cnt[MAXN], num = 0, n; n vector<int> e[MAXN]; n void tree_dp(int x, int father) { n   int flag = 0; n   for (auto v : e[x]) n     if (v != father) flag = 1, tree_dp(v, x); n   if (!flag) n     f[x][0][0] = f[x][1][1] = 0, cnt[x] = 1; n   else n     f[x][0][0] = f[x][0][1] = cnt[x] = 0; n   for (auto v : e[x]) n     if (v != father) { n       cnt[x] += cnt[v]; n       for (int i = cnt[x]; i >= 0; i--) { n         g[i][0] = INF, g[i][1] = INF; n         for (int j = min(cnt[v], i); j >= 0; j--) { n           upmin(g[i][0], min(f[x][i - j][0] + f[v][j][0], n                              f[x][i - j][0] + f[v][j][1] + 1)); n           upmin(g[i][1], min(f[x][i - j][1] + f[v][j][0] + 1, n                              f[x][i - j][1] + f[v][j][1])); n         } n         f[x][i][0] = g[i][0], f[x][i][1] = g[i][1]; n       } n     } n } n signed main() { n   n = read(); n   for (int i = 1, u, v; i < n; i++) n     u = read(), v = read(), e[u].push_back(v), e[v].push_back(u); n   for (int i = 0; i <= n; i++) n     for (int j = 0; j <= n; j++) f[i][j][0] = f[i][j][1] = INF; n   for (int i = 1; i <= n; i++) n     if (e[i].size() > 1) { n       tree_dp(i, 0); n       printf( %d n , min(f[i][cnt[i] / 2][0], f[i][cnt[i] / 2][1])); n       return 0; n     } n   puts( 1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long md = 1e9 + 7; n int t; n int dp[52][1005][1005]; n int dp2[52][1005]; n int c[1501][60]; n long long f[100]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> t; n   dp[0][0][1] = 1; n   f[0] = 1; n   for (long long i = 1; i <= 50; ++i) f[i] = (f[i - 1] * i) % md; n   for (int i = 0; i <= 50; ++i) { n     for (int j = 0; j <= 1001; ++j) { n       long long sum = 0; n       for (int k = 0; k <= 1001; ++k) { n         sum = sum + dp[i][j][k]; n         if (sum > md) sum -= md; n         if (j + k <= 1000) { n           dp[i + 1][j + k][k + 1] = dp[i + 1][j + k][k + 1] + sum; n           if (dp[i + 1][j + k][k + 1] > md) dp[i + 1][j + k][k + 1] -= md; n         } n       } n       for (int k = 1; k <= 1001; ++k) { n         dp2[i][j] = (dp2[i][j] + dp[i][j][k]); n         if (dp2[i][j] > md) dp2[i][j] -= md; n       } n       dp2[i][j] = (dp2[i][j] * f[i]) % md; n     } n   } n   c[0][0] = 1; n   for (int i = 1; i <= 1500; ++i) n     for (int j = 0; j <= min(55, i); ++j) { n       c[i][j] = c[i - 1][j]; n       if (j) c[i][j] += c[i - 1][j - 1]; n       if (c[i][j] >= md) c[i][j] -= md; n     } n   for (int i = 1; i <= t; ++i) { n     int x, y; n     cin >> x >> y; n     long long res = 0; n     if (y > 50) { n       cout <<  0  <<   n ; n       continue; n     } n     for (int i = 0; i <= x; ++i) n       res = (res + n              (long long)((long long)dp2[y][i] * (long long)c[x - i + y][y]) % n                  md) % n             md; n     cout << res <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int a[n + 1]; n   int i, m, k, l, x, y; n   for (i = 1; i <= n; i++) cin >> a[i]; n   cin >> m; n   for (i = 0; i < m; i++) { n     cin >> x >> y; n     a[x - 1] += y - 1; n     a[x + 1] += (a[x] - y); n     a[x] = 0; n   } n   for (i = 1; i <= n; i++) cout << a[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long t; n   cin >> t; n   while (t--) { n     long long n, m, x, y; n     cin >> n >> m >> x >> y; n     if (2 * x < y) y = 2 * x; n     vector<vector<long long>> grid(n, vector<long long>(m)); n     for (long long i = 0; i < n; i++) { n       for (long long j = 0; j < m; j++) { n         char c; n         cin >> c; n         if (c ==  . ) n           grid[i][j] = 0; n         else n           grid[i][j] = 1; n       } n     } n     long long sum = 0; n     for (long long i = 0; i < n; i++) { n       vector<pair<long long, long long>> all; n       all.push_back({grid[i][0], 1}); n       for (long long j = 1; j < m; j++) { n         if (grid[i][j] == all.back().first) n           all.back().second++; n         else n           all.push_back({grid[i][j], 1}); n       } n       for (auto it : all) { n         if (it.first == 0) { n           long long a = it.second / 2, b = it.second % 2; n           sum += a * y; n           sum += b * x; n         } n       } n     } n     cout << sum <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   int jou[n + 1]; n   vector<bool> u(n + 1, false); n   int k = 1; n   for (int i = 1; i < n + 1; i++) { n     cin >> jou[i]; n     if (u[jou[i]] == false) { n       u[jou[i]] = true; n     } else n       k++; n   } n   cout << k; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long rdtsc() { n   long long tmp; n   asm( rdtsc  :  =A (tmp)); n   return tmp; n } n inline int myrand() { return abs((rand() << 15) ^ rand()); } n inline int rnd(int x) { return myrand() % x; } n const int INF = (int)1.01e9; n const long double EPS = 1e-9; n void precalc() {} n long long x; n bool read() { n   if (scanf( %lld , &x) < 1) { n     return 0; n   } n   return 1; n } n void solve() { n   vector<pair<long long, long long> > ans; n   for (long long t = 1;; ++t) { n     long long a = t * (t + 1) / 2; n     long long b = a * (2 * t + 1) / 3; n     if (b > x) { n       break; n     } n     long long left = x - b; n     if (left % a) { n       continue; n     } n     left /= a; n     ans.push_back(make_pair(t, t + left)); n     if (left) { n       ans.push_back(make_pair(t + left, t)); n     } n   } n   printf( %d n , ((int)(ans).size())); n   sort(ans.begin(), ans.end()); n   for (int i = 0; i < ((int)(ans).size()); ++i) { n     printf( n          %lld  n             n          %lld  n           n , n         ans[i].first, ans[i].second); n   } n } n int main() { n   srand(rdtsc()); n   precalc(); n   while (1) { n     if (!read()) { n       break; n     } n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Mod = 1e9 + 7; n int n, inv; n long long m; n long long A[30]; n inline int Qpow(int a, int b) { n   int ans = 1; n   while (b) { n     if (b & 1) ans = (long long)ans * a % Mod; n     b >>= 1; n     a = (long long)a * a % Mod; n   } n   return ans; n } n inline int C(long long a) { n   if (a < (n - 1)) return 0; n   long long res = 1; n   for (int i = 0; i < n - 1; i++) res = res * ((a - i) % Mod) % Mod; n   return res * inv % Mod; n } n inline void Init() { n   cin >> n >> m; n   inv = 1; n   for (int i = 2; i < n; i++) inv = (long long)inv * i % Mod; n   inv = Qpow(inv, Mod - 2); n   for (int i = 1; i <= n; i++) cin >> A[i]; n } n inline void Work() { n   int res = 0; n   for (int i = 0; i < (1 << n); i++) { n     long long a = n + m - 1; n     int flag = 1; n     for (int j = 0; j < n; j++) { n       if ((i >> j) & 1) { n         flag *= -1; n         a -= A[j + 1] + 1; n       } n     } n     res = ((long long)res + (long long)flag * C(a) % Mod) % Mod; n   } n   cout << (res + Mod) % Mod << endl; n } n int main() { n   Init(); n   Work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, K, bs[500005], hs[500005], ht[500005], ht2[500005], lpos[500005], n     rpos[500005], ansl, ansr; n bool flag; n set<int> S; n set<int>::iterator it; n struct node { n   int len, id; n } a[500005]; n char s[500005], t[500005]; n int Hashs(int fr, int to) { n   return (-(long long)hs[fr - 1] * bs[to - fr + 1] % 1000000007 + hs[to] + n           1000000007) % n          1000000007; n } n bool check(int fr, int l) { return ht[l] == Hashs(fr, fr + l - 1); } n bool check2(int to, int l) { return ht2[m - l + 1] == Hashs(to - l + 1, to); } n bool cmp1(const node &lhs, const node &rhs) { return lhs.len > rhs.len; } n int main() { n   scanf( %d%d%d , &n, &m, &K); n   scanf( %s , s + 1); n   scanf( %s , t + 1); n   bs[0] = 1; n   for (int i = 1; i <= n; ++i) bs[i] = (long long)bs[i - 1] * 8741 % 1000000007; n   for (int i = 1; i <= n; ++i) n     hs[i] = ((long long)hs[i - 1] * 8741 + s[i]) % 1000000007; n   for (int i = 1; i <= m; ++i) n     ht[i] = ((long long)ht[i - 1] * 8741 + t[i]) % 1000000007; n   for (int i = 1; i <= n; ++i) { n     int l = 0, r = min(m, n - i + 1), mid; n     while (l < r) { n       mid = (l + r + 1) >> 1; n       if (check(i, mid)) n         l = mid; n       else n         r = mid - 1; n     } n     a[i] = (node){l, i}; n   } n   sort(a + 1, a + n + 1, cmp1); n   S.clear(); n   int now = 1; n   for (int i = m; i >= 1; --i) { n     for (; a[now].len == i && now <= n; now++) { n       S.insert(a[now].id); n     } n     if (i == m) { n       it = S.lower_bound(1); n       if (it != S.end()) n         lpos[i] = *it; n       else n         lpos[i] = 1000000000; n     } else { n       it = S.lower_bound(K - i + 1); n       if (it != S.end()) n         lpos[i] = *it; n       else n         lpos[i] = 1000000000; n     } n   } n   for (int i = m; i >= 1; --i) { n     ht2[i] = (-(long long)ht[i - 1] * bs[m - i + 1] % 1000000007 + ht[m] + n               1000000007) % n              1000000007; n   } n   S.clear(); n   for (int i = 1; i <= n; ++i) { n     int l = 0, r = i, mid; n     while (l < r) { n       mid = (l + r + 1) >> 1; n       if (check2(i, mid)) n         l = mid; n       else n         r = mid - 1; n     } n     a[i] = (node){l, i}; n   } n   sort(a + 1, a + n + 1, cmp1); n   now = 1; n   for (int i = m; i >= 1; --i) { n     for (; a[now].len == i && now <= n; now++) { n       S.insert(a[now].id); n     } n     if (i == m) { n       it = S.lower_bound(K); n       if (it != S.end()) n         rpos[i] = *it; n       else n         rpos[i] = -1000000000; n     } else { n       it = S.upper_bound(n + i - K); n       if (it != S.begin()) { n         it--; n         rpos[i] = *it; n       } else n         rpos[i] = -1000000000; n     } n   } n   flag = 0; n   for (int i = 1; i < m; ++i) { n     int x = lpos[i], y = rpos[m - i]; n     if (i > K || m - i > K) continue; n     if (x + i - 1 <= y - m + i) { n       flag = 1; n       ansl = x + i - K, ansr = y - m + i + 1; n       break; n     } n   } n   if (!flag && m <= K) { n     if (max(K, lpos[m] + m - 1) + K <= n) { n       flag = 1; n       ansl = max(lpos[m] + m - 1, K) - K + 1, ansr = n - K + 1; n     } n     if (min(n - K + 1, rpos[m] - m + 1) - K >= 1) { n       flag = 1; n       ansl = 1, ansr = min(n - K + 1, rpos[m] - m + 1); n     } n   } n   if (flag) n     printf( Yes n%d %d n , ansl, ansr); n   else n     printf( No n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100 + 10; n const int inf = 1e9; n vector<int> getArray(int *a, int n, int k) { n   vector<int> ret; n   for (int i = 0; i < n * k; i++) { n     if (i < n) n       ret.push_back(a[i]); n     else n       ret.push_back(a[i % n]); n   } n   return ret; n } n vector<int> myLIS(vector<int> a, int n) { n   vector<int> dp, ret; n   dp.resize(n + 1); n   dp[0] = -inf; n   for (int i = 1; i <= n; i++) dp[i] = 1000; n   for (int i = 0; i < n; i++) { n     int tmp = upper_bound(dp.begin(), dp.end(), a[i]) - dp.begin(); n     ret.push_back(tmp); n     dp[tmp] = a[i]; n   } n   return ret; n } n int main() { n   int n, T, a[maxn]; n   scanf( %d%d , &n, &T); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   int ret = 0; n   if (T <= 1000) { n     vector<int> prefix = myLIS(getArray(a, n, T), n * T); n     for (int i = 0; i < n * T; i++) { n       ret = max(ret, prefix[i]); n     } n   } else { n     vector<int> newA = getArray(a, n, n); n     vector<int> prefix = myLIS(newA, n * n); n     for (int i = 0; i < newA.size(); i++) { n       newA[i] = -newA[i]; n     } n     reverse(newA.begin(), newA.end()); n     vector<int> suffix = myLIS(newA, n * n); n     for (int i = 0; i < n; i++) { n       int cnt = 0; n       for (int j = 0; j < n; j++) n         if (a[i] == a[j]) cnt++; n       for (int j = 0; j < n; j++) { n         if (a[j] < a[i]) continue; n         ret = max(ret, prefix[(n - 1) * n + i] + cnt * (T - 2 * n) + n                            suffix[n * n - j - 1]); n       } n     } n   } n   cout << ret << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int a[n]; n   set<int> st; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     st.insert(a[i]); n   } n   set<int>::iterator it = st.begin(); n   it++; n   if (it == st.end()) n     cout <<  NO ; n   else n     cout << (*it); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   long a, b, c; n   scanf( %ld%ld%ld , &a, &b, &c); n   if (b == a) { n     printf( YES n ); n   } else if (c > 0) { n     if (b < a) { n       printf( NO n ); n     } else if (((b - a) % c) == 0) { n       printf( YES n ); n     } else { n       printf( NO n ); n     } n   } else if (c < 0) { n     if (b > a) { n       printf( NO n ); n     } else if (((a - b) % c) == 0) { n       printf( YES n ); n     } else { n       printf( NO n ); n     } n   } else { n     printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e4 + 100; n const long long inf = 0x3f3f3f3f3f; n int n; n int a[maxn]; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     if (i != n) { n       int q; n       cout <<  ?  n            <<   1  n            <<     << i + 1 << endl; n       cin >> q; n       a[i + 1] = q; n     } else { n       int q; n       cout <<  ?  n            <<     n            <<  2  n            <<     << 3 << endl; n       cin >> q; n       a[1] = (a[2] + a[3] - q) / 2; n     } n   } n   cout <<  !  ; n   for (int i = 1; i <= n; i++) { n     if (i == 1) n       cout << a[1] <<    ; n     else n       cout << a[i] - a[1] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int n, q; n long long int gcd(long long int a, long long int b) { n   if (b == 0) { n     return a; n   } n   return gcd(b, a % b); n } n long long int powe(long long int a, long long int b) { n   long long int res = 1; n   while (b > 0) { n     if (b % 2 == 1) { n       res = (res * a); n     } n     a = (a * a); n     b /= 2; n   } n   return res; n } n long long int power(long long int a, long long int b, long long int M) { n   a %= M; n   long long int res = 1; n   while (b > 0) { n     if (b % 2 == 1) { n       res = (res * a) % M; n     } n     a = (a * a) % M; n     b /= 2; n   } n   return res; n } n long long int extendedEuclid(long long int A, long long int B, long long int &x, n                              long long int &y) { n   if (B == 0) { n     x = 1; n     y = 0; n     return A; n   } else { n     long long int x1, y1; n     long long int gcd = extendedEuclid(B, A % B, x1, y1); n     y = x1 - (A / B) * y1; n     x = y1; n     return gcd; n   } n } n long long int mi(long long int A, long long int M) { n   long long int x, y; n   extendedEuclid(A, M, x, y); n   if (x < 0) { n     x += (long long int)1000000007; n   } n   return x; n } n template <typename T> n void read(T &x) { n   cin >> x; n } n template <typename T, typename T0> n void read(T &x, T0 &y) { n   cin >> x >> y; n } n template <typename T, typename T0, typename T1> n void read(T &x, T0 &y, T1 &z) { n   cin >> x >> y >> z; n } n template <typename T, typename T0, typename T1, typename T2> n void read(T &x, T0 &y, T1 &z, T2 &w) { n   cin >> x >> y >> z >> w; n } n template <typename T, typename T0> n void read(pair<T, T0> &p) { n   cin >> p.first >> p.second; n } n template <typename T, typename T0> n void write(pair<T, T0> &p) { n   write(p.first); n   write(p.second); n } n template <typename T> n void read(vector<T> &oneD, long long int n) { n   for (long long int i = 0; i < n; i++) { n     long long int x; n     read(x); n     oneD.push_back(x); n   } n } n template <typename T> n void read(T oneD[], long long int n) { n   for (long long int i = 0; i < n; i++) { n     read(oneD[i]); n   } n } n template <typename T> n void write(T oneD[], int n) { n   for (long long int i = 0; i < n; i++) { n     write(oneD[i]); n   } n   cout << endl; n } n vector<bool> sieve(1000000, true); n void Sieve() { n   sieve[0] = false; n   sieve[1] = false; n   for (long long int i = 2; i * i <= 1000000; i++) { n     if (sieve[i] == true) { n       for (long long int j = i * i; j < 1000000; j += i) sieve[j] = false; n     } n   } n } n vector<long long int> sieve_spf; n void Sieve_spf() { n   const long long int n = 1e6 + 5; n   sieve_spf.resize(n); n   for (long long int i = 0; i < n; i++) sieve_spf[i] = i; n   sieve_spf[0] = -1; n   sieve_spf[1] = 1; n   for (long long int i = 2; i <= n; i += 2) sieve_spf[i] = 2; n   for (long long int i = 3; i <= n; i += 2) n     if (sieve_spf[i] == i) n       for (long long int j = i * i; j <= n; j += i) n         if (sieve_spf[j] == j) sieve_spf[j] = i; n } n bool oppositeSigns(long long int x, long long int y) { return ((x ^ y) < 0); } n int mpt(long long int n) { n   long long int c = 0; n   long long int n1 = pow(2, c); n   while (n1 < n) { n     c++; n     n1 = pow(2, c); n   } n   return c; n } n void the_happiest_place_on_earth() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n } n int main() { n   the_happiest_place_on_earth(); n   long long int t; n   read(t); n   while (t--) { n     read(n); n     cout << n - 1 <<     << 1; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int mob[2000005], vis[2000005], p[1000005]; n long long cnt[2000005], cnt2[2000005], pnum; n bool prime[1000005]; n long long mod = 1e9 + 7; n int read() { n   char c; n   for (c = getchar(); c <  0  || c >  9 ; c = getchar()) n     ; n   int x = c - 48; n   for (c = getchar(); c >=  0  && c <=  9 ; c = getchar()) x = x * 10 + c - 48; n   return x; n } n void Mobius() { n   int i, j; n   pnum = 0; n   memset(prime, true, sizeof(prime)); n   mob[1] = 1; n   for (i = 2; i < 1000005; i++) { n     if (prime[i]) { n       p[pnum++] = i; n       mob[i] = -1; n     } n     for (j = 0; j < pnum && (long long)i * p[j] < 1000005; j++) { n       prime[i * p[j]] = false; n       if (i % p[j] == 0) { n         mob[i * p[j]] = 0; n         break; n       } n       mob[i * p[j]] = -mob[i]; n     } n   } n } n int main(void) { n   int n, m, x, T, MAX, ca = 1; n   long long ans, temp, k, kk, nnn, res, i, j; n   Mobius(); n   n = read(); n   k = read(); n   kk = read(); n   nnn = k / kk; n   memset(cnt, 0, sizeof(cnt)); n   memset(cnt2, 0, sizeof(cnt2)); n   MAX = 1; n   for (i = 1; i <= n; i++) { n     x = read(); n     cnt[x]++; n     cnt2[x] += x; n     MAX = max(MAX, x); n   } n   for (int i = 1; i <= 2000000; i++) { n     cnt[i] += cnt[i - 1]; n     cnt2[i] += cnt2[i - 1]; n   } n   ans = -1; n   T = 0; n   for (i = p[T]; T < pnum; i = p[T]) { n     T++; n     res = 0; n     for (j = i; j <= 1000000 + i; j += i) { n       if (nnn >= i) { n         res += (((cnt[j - 1] - cnt[j - i]) * j) - (cnt2[j - 1] - cnt2[j - i])) * n                kk; n       } else { n         res += (cnt[j - nnn - 1] - cnt[j - i]) * k; n         res += (((cnt[j - 1] - cnt[j - nnn - 1]) * j) - n                 (cnt2[j - 1] - cnt2[j - nnn - 1])) * n                kk; n       } n     } n     if (ans == -1) ans = res; n     ans = min(ans, res); n   } n   printf( %I64d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int n; n string s; n set<vector<int> > DP[10001]; n bool R[4]; n int main() { n   cin >> n; n   cin >> s; n   for (int i = 0; i < s.size(); i++) n     if (s[i] ==  G ) n       s[i] =  0 ; n     else if (s[i] ==  S ) n       s[i] =  1 ; n     else if (s[i] ==  H ) n       s[i] =  2 ; n     else if (s[i] ==  R ) n       s[i] =  3 ; n   vector<int> E(4, 0); n   DP[0].insert(E); n   for (int i = 0; i < n; i++) { n     set<vector<int> >::iterator it; n     for (it = DP[i].begin(); it != DP[i].end(); it++) { n       vector<int> T; n       T = *it; n       int q = min(T[0], min(T[1], min(T[2], T[3]))); n       for (int j = 0; j < 4; j++) { n         if ((s[i] !=  ?  && (j == (s[i] -  0 )) || n              (s[i] ==  ?  && T[j] == q))) { n           vector<int> N; n           N = T; n           N[j]++; n           int p = min(N[0], min(N[1], min(N[2], N[3]))); n           for (int l = 0; l < 4; l++) N[l] -= p; n           DP[i + 1].insert(N); n         } n       } n     } n   } n   set<vector<int> >::iterator it; n   for (it = DP[n].begin(); it != DP[n].end(); it++) { n     vector<int> T; n     T = *it; n     int q = min(T[0], min(T[1], min(T[2], T[3]))); n     for (int j = 0; j < 4; j++) n       if (T[j] == q) R[j] = true; n   } n   if (R[0]) cout <<  Gryffindor  << endl; n   if (R[2]) cout <<  Hufflepuff  << endl; n   if (R[3]) cout <<  Ravenclaw  << endl; n   if (R[1]) cout <<  Slytherin  << endl; n   cin >> n; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n, k, d; n   scanf( %d%d%d , &n, &k, &d); n   vector<int> v(n); n   for (int &x : v) { n     scanf( %d , &x); n   } n   map<int, int> m_map; n   int mn = 0, cnt = 0; n   for (int i = 0; i < d; i++) { n     if (m_map[v[i]] == 0) { n       cnt++; n     } n     m_map[v[i]]++; n   } n   mn = cnt; n   for (int i = d; i < n; i++) { n     m_map[v[i - d]]--; n     if (m_map[v[i - d]] == 0) cnt--; n     if (m_map[v[i]] == 0) cnt++; n     m_map[v[i]]++; n     mn = min(mn, cnt); n   } n   printf( %d n , mn); n } n int main() { n   int testcase; n   scanf( %d , &testcase); n   for (int i = 1; i <= testcase; i++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n  n #define ll long long n  n using namespace std; n  n int t; n  n int main() { n     ios_base::sync_with_stdio(false); n     cin.tie(0); n     cout.tie(0); n     cin >> t; n     while (t--) { n         int n; n         cin >> n; n         vector<pair<int, int> > a(n + 1); n         for (int i = 1; i <= n; i++) { n             cin >> a[i].first; n             a[i].second = i; n         } n         sort(a.begin() + 1, a.end()); n         if (a[1].first == a[2].first) { n             cout << a[n].second << endl; n         } else { n             cout << a[1].second << endl; n         } n     } n  n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k; n   string s; n   map<char, int> m1; n   cin >> k >> s; n   int n = s.length(); n   for (int i = 0; i < n; i++) { n     m1[s[i]]++; n   } n   map<char, int>::iterator it; n   int flag = 0; n   for (it = m1.begin(); it != m1.end(); it++) { n     if ((it->second) % k) { n       flag = 1; n       break; n     } n   } n   if (flag) { n     cout <<  -1 ; n   } else { n     it = m1.begin(); n     int val = k; n     string s1 =   ; n     for (it = m1.begin(); it != m1.end(); it++) { n       int num = (it->second) / k; n       while (num--) s1 += it->first; n     } n     while (k--) cout << s1; n   } n   return 0; n } n