#include <bits/stdc++.h> n using namespace std; n constexpr long long inf = 1e9 + 7, base = 541; n constexpr long long mod = 1e9 + 7, N = 1e6 + 7; n struct piii { n   long long sm = 0, an = 0, cn = 0; n }; n long long n; n long long v[N]; n long long sum[4 * N], ans[4 * N]; n piii calc(piii x, piii y) { n   x.an += y.an + (y.sm * x.cn - x.sm * y.cn); n   x.sm += y.sm; n   x.cn += y.cn; n   return x; n } n inline long long pos(long long l, long long tp) { n   if (tp == 0) n     return (lower_bound(v, v + n + 1, l) - v); n   else n     return (upper_bound(v, v + n + 1, l) - v); n } n void build(long long s = 0, long long e = n, long long tag = 1) { n   if (e - s == 1) { n     sum[tag] = v[s]; n     return; n   } n   long long mid = (s + e) / 2; n   build(s, mid, tag * 2 + 0); n   build(mid, e, tag * 2 + 1); n   sum[tag] = sum[tag * 2] + sum[tag * 2 + 1]; n   ans[tag] = ans[tag * 2] + ans[tag * 2 + 1] + n              (sum[tag * 2 + 1] * (mid - s) - sum[tag * 2] * (e - mid)); n } n piii query(long long l, long long r, long long tag = 1, long long s = 0, n            long long e = n) { n   piii x, y; n   if (s >= r || e <= l) return x; n   if (s >= l && e <= r) { n     x.sm = sum[tag], x.cn = e - s, x.an = ans[tag]; n     return x; n   } n   long long mid = (s + e) / 2; n   x = query(l, r, tag * 2 + 0, s, mid), y = query(l, r, tag * 2 + 1, mid, e); n   return calc(x, y); n } n void builq(long long l, long long r, long long tag = 1, long long s = 0, n            long long e = n) { n   if (s >= r || e <= l) return; n   if (s >= l && e <= r) { n     build(s, e, tag); n     return; n   } n   long long mid = (s + e) / 2; n   builq(l, r, tag * 2 + 0, s, mid), builq(l, r, tag * 2 + 1, mid, e); n   sum[tag] = sum[tag * 2] + sum[tag * 2 + 1]; n   ans[tag] = ans[tag * 2] + ans[tag * 2 + 1] + n              (sum[tag * 2 + 1] * (mid - s) - sum[tag * 2] * (e - mid)); n } n long long a[N]; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     v[i] = a[i]; n   } n   sort(v, v + n); n   build(0, n, 1); n   long long Q; n   cin >> Q; n   for (long long i = n; i < n + 100; i++) v[i] = 1e18 + 7; n   while (Q--) { n     long long type, l, r; n     cin >> type >> l >> r; n     if (type == 2) n       cout << query(pos(l, 0), pos(r, 1)).an << endl; n     else { n       l--; n       long long x = (0 < pos(a[l], 0) ? pos(a[l], 0) : 0), n                 y = (n - 1 > pos(a[l] + r, 0) ? pos(a[l] + r, 0) : n - 1); n       long long ps = x; n       v[x] += r, a[l] += r; n       while (v[ps] > v[ps + 1]) swap(v[ps], v[ps + 1]), ps++; n       while (ps && v[ps] < v[ps - 1]) swap(v[ps], v[ps - 1]), ps--; n       builq((x > y ? y : x), (x < y ? y : x) + 1); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[1000006], n, v[1000006], t[1000006]; n void uma(int x) { n   int i; n   for (i = 0; i < n; i++) v[i] = i; n   for (; x; x >>= 1) { n     if (x & 1) { n       for (i = 0; i < n; i++) v[i] = a[v[i]]; n     } n     for (i = 0; i < n; i++) t[i] = a[a[i]]; n     for (i = 0; i < n; i++) a[i] = t[i]; n   } n   for (i = 0; i < n; i++) a[i] = v[i]; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int m, i, d, k, j, l, p; n   string s, os; n   cin >> s >> m; n   os = s; n   n = s.size(); n   for (i = 0; i < m; i++) { n     cin >> k >> d; n     p = 0; n     for (j = 0; j < d; j++) n       for (l = j; l < k; l += d) a[p++] = l; n     for (j = 0; j < k - 1; j++) a[j] = a[j + 1]; n     for (j = k - 1; j < n - 1; j++) a[j] = j + 1; n     a[j] = 0; n     uma(n - k + 1); n     for (j = 0; a[j]; j++) { n     } n     p = 0; n     for (; j < n; j++) os[p++] = s[a[j]]; n     for (j = 0; a[j]; j++) os[p++] = s[a[j]]; n     s = os; n     cout << s <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long dp[31][31]; n long long solve(int n, int r) { n   if (n == r || r == 0) return 1; n   if (n < r) return 0; n   if (dp[n][r] != -1) { n     return dp[n][r]; n   } n   return dp[n][r] = solve(n - 1, r - 1) + solve(n - 1, r); n } n int main() { n   int t = 1; n   while (t--) { n     long long n, m, k; n     cin >> n >> m >> k; n     if (k == 1) { n       long long ans = 1; n       for (int i = 0; i < n; i++) { n         ans = (ans * m) % 1000000007; n       } n       cout << ans; n     } else if (k == n) { n       int s = n / 2; n       if (n % 2) s++; n       long long ans = 1; n       for (int i = 0; i < s; i++) { n         ans = (ans * m) % 1000000007; n       } n       cout << ans; n     } else if (k > n) { n       long long ans = 1; n       for (int i = 0; i < n; i++) { n         ans = (ans * m) % 1000000007; n       } n       cout << ans; n     } else { n       if (k % 2 == 0) { n         cout << m; n       } else { n         cout << m * m; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long r = 1000000009; n int main() { n   long long m, n, k; n   cin >> n >> m >> k; n   long long d = n % k; n   d += (n / k) * (k - 1); n   if (m <= d) { n     cout << m % r; n     return 0; n   } n   int s = m - d; n   long long sc = (m - s * k) % r; n   long long c = 2; n   if (s < 100000000) { n     for (int i = s; i > 0; i--) { n       sc = (c * k + sc) % r; n       c = (c * 2) % r; n     } n   } else { n     while (s >= 10) { n       c = (c * 1024) % r; n       s -= 10; n     } n     while (s > 0) { n       c = (c * 2) % r; n       s--; n     } n     if (c >= 2) { n       c -= 2; n     } else { n       c += r; n       c -= 2; n     } n     c = (c * k) % r; n     sc = (sc + c) % r; n   } n   cout << sc; n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n const int maxn=1e2+5; n int t,n,m; n int f[maxn<<1]; n int main() n { n     cin.tie(0); cout.tie(0); n     ios::sync_with_stdio(0); n     cin>>t; n     while(t--){ n         memset(f,0,sizeof(f)); n         cin>>n>>m; n         for(int i=1;i<=n;++i){ n             for(int j=1;j<=m;++j){ n                 int x; n                 cin>>x; n                 f[i+j]^=x; n             } n         } n         int ans=0; n         for(int i=2;i<=n+m;++i){ n             ans|=f[i]; n         } n         if(ans) cout<< Ashish <<endl; n         else cout<< Jeel <<endl; n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, q, dfn[200005], low[200005], ibcc[200005], dfncnt, bcccnt; n vector<pair<int, int>> g[200005]; n vector<int> ng[200005]; n int st[200005], stcnt; n void getbcc(int x, int pe) { n   dfn[x] = low[x] = ++dfncnt; n   st[stcnt++] = x; n   for (pair<int, int> &e : g[x]) n     if (!dfn[e.first]) { n       getbcc(e.first, e.second); n       low[x] = min(low[x], low[e.first]); n     } else if (e.second != pe) { n       low[x] = min(low[x], dfn[e.first]); n     } n   if (dfn[x] == low[x]) { n     ibcc[x] = ++bcccnt; n     int y; n     while ((y = st[--stcnt]) != x) { n       ibcc[y] = bcccnt; n     } n   } n } n int dep[200005]; n int fa[200005][18]; n bool vis[200005]; n void dfs4lca(int x, int p, int cd) { n   vis[x] = 1; n   fa[x][0] = p; n   dep[x] = cd; n   for (int &y : ng[x]) n     if (y != p) { n       dfs4lca(y, x, cd + 1); n     } n } n void init4lca() { n   for (int i = 1; i <= bcccnt; i++) n     if (!vis[i]) dfs4lca(i, -1, 0); n   for (int j = 0; j < 17; j++) { n     for (int i = 1; i <= bcccnt; i++) { n       if (fa[i][j] == -1) n         fa[i][j + 1] = -1; n       else n         fa[i][j + 1] = fa[fa[i][j]][j]; n     } n   } n } n int lca(int x, int y) { n   if (dep[x] < dep[y]) swap(x, y); n   for (int i = 17; i >= 0; i--) { n     if (fa[x][i] != -1 && dep[fa[x][i]] >= dep[y]) x = fa[x][i]; n   } n   if (x == y) return x; n   for (int i = 17; i >= 0; i--) { n     if (fa[x][i] != fa[y][i]) { n       x = fa[x][i]; n       y = fa[y][i]; n     } n   } n   return fa[x][0]; n } n int up[200005], down[200005]; n void calc(int x, int p) { n   vis[x] = 1; n   for (int &y : ng[x]) n     if (y != p) { n       calc(y, x); n       up[x] += up[y]; n       down[x] += down[y]; n     } n   if (up[x] && down[x]) { n     puts( No ); n     exit(0); n   } n } n int main() { n   scanf( %d%d%d , &n, &m, &q); n   for (int i = 1; i <= m; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     g[a].emplace_back(b, i); n     g[b].emplace_back(a, i); n   } n   for (int i = 1; i <= n; i++) n     if (!dfn[i]) getbcc(i, -1); n   for (int x = 1; x <= n; x++) { n     for (pair<int, int> &e : g[x]) { n       if (ibcc[x] != ibcc[e.first]) { n         ng[ibcc[x]].emplace_back(ibcc[e.first]); n       } n     } n   } n   init4lca(); n   memset(vis, 0, sizeof(vis)); n   while (q--) { n     int u, v, anc; n     scanf( %d%d , &u, &v); n     u = ibcc[u]; n     v = ibcc[v]; n     if (u == v) continue; n     anc = lca(u, v); n     up[u]++; n     up[anc]--; n     down[v]++; n     down[anc]--; n   } n   for (int i = 1; i <= bcccnt; i++) n     if (!vis[i]) calc(i, -1); n   puts( Yes ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   int otg = 1 << 30, i; n   for (i = 0; i < m; i++) { n     int l, r; n     cin >> l >> r; n     if (r - l + 1 < otg) otg = r - l + 1; n   } n   cout << otg << endl; n   for (i = 0; i < n; i++) cout << i % otg <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300005, mod = 998244353; n int qp(int a, int b) { n   int ans = 1; n   while (b) { n     if (b & 1) ans = 1ll * ans * a % mod; n     a = 1ll * a * a % mod; n     b >>= 1; n   } n   return ans; n } n int rv[N], w[N]; n void ntt(vector<int> &a, int f) { n   int n = a.size(); n   for (int i = 0; i < n; i++) rv[i] = (rv[i >> 1] >> 1) | ((i & 1) * (n >> 1)); n   int wn = qp(f ? (mod + 1) / 3 : 3, (mod - 1) / n); n   w[0] = 1; n   for (int i = 1; i < n; i++) w[i] = 1ll * w[i - 1] * wn % mod; n   for (int i = 0; i < n; i++) n     if (i < rv[i]) swap(a[i], a[rv[i]]); n   for (int mid = 1; mid < n; mid <<= 1) { n     for (int i = 0; i < n; i += (mid << 1)) { n       for (int j = 0; j < mid; j++) { n         int x = a[i + j], n             y = 1ll * a[i + j + mid] * w[n / (mid << 1) * j] % mod; n         a[i + j] = (x + y >= mod ? x + y - mod : x + y); n         a[i + j + mid] = (x - y < 0 ? x - y + mod : x - y); n       } n     } n   } n   if (f) { n     int iv = qp(n, mod - 2); n     for (int i = 0; i < n; i++) a[i] = 1ll * a[i] * iv % mod; n   } n } n vector<int> mul(vector<int> a, vector<int> b) { n   int n = 1, m = a.size() + b.size() - 1; n   while (n < m) n <<= 1; n   a.resize(n), b.resize(n); n   ntt(a, 0), ntt(b, 0); n   for (int i = 0; i < n; i++) a[i] = 1ll * a[i] * b[i] % mod; n   ntt(a, 1); n   a.resize(m); n   return a; n } n vector<int> inv(vector<int> a) { n   int n = a.size(); n   if (n == 1) { n     a[0] = qp(a[0], mod - 2); n     return a; n   } n   int m = 1; n   while (m < (n << 1)) m <<= 1; n   vector<int> a0 = a; n   a0.resize((n + 1) / 2); n   vector<int> b0 = inv(a0); n   a.resize(m), b0.resize(m); n   ntt(a, 0), ntt(b0, 0); n   for (int i = 0; i < m; i++) n     a[i] = 1ll * b0[i] * (2 - 1ll * a[i] * b0[i] % mod + mod) % mod; n   ntt(a, 1); n   a.resize(n); n   return a; n } n vector<int> qd(vector<int> a) { n   int n = a.size(); n   for (int i = 1; i < n; i++) a[i - 1] = 1ll * a[i] * i % mod; n   a.pop_back(); n   return a; n } n vector<int> jf(vector<int> a) { n   int n = a.size(); n   a.push_back(0); n   for (int i = n; i >= 1; i--) a[i] = 1ll * a[i - 1] * qp(i, mod - 2) % mod; n   a[0] = 0; n   return a; n } n vector<int> ln(vector<int> a) { n   a = mul(qd(a), inv(a)); n   return jf(a); n } n vector<int> rev(vector<int> &a) { n   a[0] = 1; n   for (int i = 1; i < a.size(); i++) a[i] = (mod - a[i]) % mod; n   return a; n } n int n, m; n int main() { n   scanf( %d%d , &n, &m); n   vector<int> a(n + 1), b(n + 1); n   int h = 1; n   int hh = 1; n   int cl = m / 2; n   for (int i = 1; i <= n; i++) { n     int t = (m + i) / 2; n     if ((m + i) & 1) { n       hh = 1ll * hh * (t - i + 1) % mod; n       h = 1ll * h * ((cl - i / 2 + mod) % mod) % mod; n     } else { n       hh = 1ll * hh * t % mod; n       h = 1LL * h * (cl + i / 2) % mod; n     } n     h = 1ll * h * qp(i, mod - 2) % mod; n     hh = 1ll * hh * qp(i, mod - 2) % mod; n     if (m & 1) h = hh; n     if (i & 1) n       b[i] = (((i / 2) & 1 ? -1 : 1) * h + mod) % mod; n     else n       a[i] = (((i / 2) & 1 ? 1 : -1) * h + mod) % mod; n   } n   auto d = mul(b, inv(rev(a))); n   auto c = rev(d); n   auto f = ln(inv(a)), g = ln(inv(c)); n   int ans = 1ll * n * (f[n] + g[n]) % mod; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxN = 2e5 + 13, mod = 1e9 + 7; n long long r, g, odp[maxN], ans; n bool can(long long x) { n   if (x * (x + 1) / 2 <= r + g) return 1; n   return 0; n } n int32_t main() { n   cin >> r >> g; n   long long lf = 0, rg = max(r, g) + 1; n   while (rg - lf > 1) { n     long long mid = lf + rg >> 1; n     if (can(mid)) n       lf = mid; n     else n       rg = mid; n   } n   long long h = lf; n   odp[0] = 1; n   for (long long j = 0; j <= h; j++) { n     for (long long i = r; i >= 0; i--) { n       if (!(i == 0 && j == 0)) n         odp[i] = (odp[i] + ((i >= j) ? odp[i - j] : 0)) % mod; n     } n   } n   for (long long i = r; i + g >= h * (h + 1) / 2 && i >= 0; i--) { n     ans = (ans + odp[i]) % mod; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T1, typename T2> n ostream& operator<<(ostream& out, pair<T1, T2>& p) { n   out <<  {  << p.first <<  ,   << p.second <<  }  ; n   return out; n } n template <typename T1, typename T2> n istream& operator>>(istream& in, pair<T1, T2>& p) { n   in >> p.fi > p.se; n   return in; n } n template <typename T> n istream& operator>>(istream& in, vector<T>& arr) { n   for (auto& i : arr) in >> i; n   return in; n } n template <typename T> n ostream& operator<<(ostream& out, vector<T>& arr) { n   for (auto i : arr) out << i + 1 <<    ; n   out << endl; n   return out; n } n const int64_t MAXN = 2e5 + 10; n vector<pair<int64_t, int64_t>> mon, diam; n int64_t n, c, d, t, t1; n int64_t b_ans = 0; n void read() { n   for (int64_t i(0); i < n; i++) { n     int64_t b, p; n     char c; n     cin >> b >> p >> c; n     if (c ==  D ) { n       diam.push_back({p, b}); n     } else { n       mon.push_back({p, b}); n     } n   } n } n void fnd() { n   t = 0; n   t1 = 0; n   for (int64_t i(0); i < mon.size(); i++) { n     if (mon[i].first <= c) { n       t = max(t, mon[i].second); n     } n   } n   for (int64_t i(0); i < diam.size(); i++) { n     if (diam[i].first <= d) { n       t1 = max(t1, diam[i].second); n     } n   } n } n void solve(vector<pair<int64_t, int64_t>>& mon, int64_t kek) { n   multiset<int64_t> s; n   for (int64_t i(0); i < mon.size(); i++) { n     s.insert(mon[i].second); n   } n   int64_t pt = (int64_t)mon.size() - 1; n   for (int64_t i(0); i < mon.size() && mon[i].first <= kek; i++) { n     while (pt >= 0 && mon[pt].first > kek - mon[i].first) { n       s.erase(s.find(mon[pt].second)); n       pt--; n     } n     if (pt >= i) { n       s.erase(s.find(mon[i].second)); n     } n     if (s.size() != 0) { n       b_ans = max(b_ans, mon[i].second + *s.rbegin()); n     } n     if (pt >= i) { n       s.insert(mon[i].second); n     } n   } n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(); n   cout.tie(); n   cin >> n >> c >> d; n   read(); n   sort(mon.begin(), mon.end()); n   sort(diam.begin(), diam.end()); n   fnd(); n   if (t != 0 && t1 != 0) { n     b_ans = t + t1; n   } n   solve(mon, c); n   solve(diam, d); n   cout << b_ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long Mod = 1e9 + 7; n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= Mod; n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % Mod; n     a = a * a % Mod; n   } n   return res; n } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n const int N = 200005; n int main() { n   ios::sync_with_stdio(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     string x; n     cin >> n >> x; n     string ans[2]; n     bool flag = 0; n     for (auto ch : x) { n       if (ch ==  0 ) { n         ans[0] +=  0 ; n         ans[1] +=  0 ; n       } n       if (ch ==  2 ) { n         if (!flag) { n           ans[0] +=  1 ; n           ans[1] +=  1 ; n         } else { n           ans[0] +=  0 ; n           ans[1] +=  2 ; n         } n       } n       if (ch ==  1 ) { n         if (!flag) { n           ans[0] +=  1 ; n           ans[1] +=  0 ; n           flag = 1; n         } else { n           ans[0] +=  0 ; n           ans[1] +=  1 ; n         } n       } n     } n     cout << ans[0] <<   n  << ans[1] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int a, b, c, d, l1, r1, l2, r2, k; n   while (cin >> l1 >> r1 >> l2 >> r2 >> k) { n     if (l2 > r1) n       cout << 0 << endl; n     else if (l1 > r2) n       cout << 0 << endl; n     else { n       long long int ans = 0; n       if (l2 >= l1 && l2 <= r1 && r2 >= r1) { n         ans = r1 - l2 + 1; n         if (k <= r1 && k >= l2) ans--; n       } else if (l2 >= l1 && l2 <= r1 && r2 <= r1) { n         ans = r2 - l2 + 1; n         if (k >= l2 && k <= r2) ans--; n       } else if (l1 >= l2 && r1 >= r2) { n         ans = r2 - l1 + 1; n         if (k >= l1 && k <= r2) ans--; n       } else if (l1 >= l2 && r1 <= r2) { n         ans = r1 - l1 + 1; n         if (k >= l1 && k <= r1) ans--; n       } n       cout << ans << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool ok(double a, double b) { n   if (a - b >= 0) n     return true; n   else n     return false; n } n double a, b; n double calc(double x) { n   int l = 1; n   int r = 1000000000; n   while (l < r) { n     int m = (l + r) / 2 + 1; n     if (ok(x / ((double)m * 2.0), b)) n       l = m; n     else n       r = m - 1; n   } n   return l; n } n int main() { n   int aa, bb; n   cin >> aa >> bb; n   if (aa == bb) { n     cout << aa << endl; n     return 0; n   } n   if (aa < bb) { n     cout << -1 << endl; n     return 0; n   } n   a = aa; n   b = bb; n   double ans; n   double ans0 = (a - b) / (calc(a - b) * 2.0); n   double ans1 = (a + b) / (calc(a + b) * 2.0); n   if (ans0 < b) n     ans = ans1; n   else n     ans = min(ans0, ans1); n   printf( %.10lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long TESTS = 1; n   while (TESTS--) { n     long long n, x, y; n     cin >> n >> x >> y; n     string s; n     cin >> s; n     long long cnt = 0; n     char c = s[0]; n     for (auto i : s) n       if (i == c) n         continue; n       else { n         if (c ==  0 ) cnt++; n         c = i; n       } n     if (c ==  0 ) cnt++; n     if (!cnt) return cout << 0, 0; n     if (x < y) n       cout << x * (cnt - 1) + y; n     else n       cout << cnt * y; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n  n const long long MOD = 998244353; n  n int a[1005][505]; n vector<int> pos[505][505]; n bool removed[505]; n  n void remove1(int x, int n, int layerNum = 0){ n     if(removed[x]){return;} n     removed[x] = true; n  n     vector<int> toRemove; n     for(int j = 1; j <= n; j ++){ n         auto it = find(pos[j][a[x][j]].begin(), pos[j][a[x][j]].end(), x); n         if(layerNum == 0){ n             if(it != pos[j][a[x][j]].end()){ n                 for(int k: pos[j][a[x][j]]){ n                     if(k != x){ n                         toRemove.push_back(k); n                     } n                 } n                 pos[j][a[x][j]] = vector<int>(); n             } n         }else{ n             if(it != pos[j][a[x][j]].end()){ n                 pos[j][a[x][j]].erase(it); n             } n         } n     } n  n     for(int k: toRemove){ n         remove1(k, n, 1); n     } n } n  n void printPosState(int n){ n     for(int i = 1; i <= n; i ++){ n         for(int j = 1; j <= n; j ++){ n             printf( (%d, %d):  , i, j); n  n             for(int k: pos[i][j]){ n                 printf( %d  , k); n             } n  n             printf(  n ); n         } n     } n } n  n int main(){ n     int t; n     scanf( %d , &t); n  n     while(t --){ n         int n; n         scanf( %d , &n); n  n         memset(removed, false, sizeof(removed)); n  n         for(int i = 1; i <= n; i ++){ n             for(int j = 1; j <= n; j ++){ n                 pos[i][j] = vector<int>(); n             } n         } n  n         for(int i = 1; i <= 2*n; i ++){ n             for(int j = 1; j <= n; j ++){ n                 scanf( %d , &a[i][j]); n                 pos[j][a[i][j]].push_back(i); n             } n         } n  n         vector<int> res; n  n         //printPosState(n); n  n         int cnt = 0; n         while(1){ n             bool found = false; n             for(int i = 1; i <= n; i ++){ n                 for(int j = 1; j <= n; j ++){ n                     if((int)pos[i][j].size() == 1){ n                         int x = pos[i][j][0]; n                         remove1(x, n); n                         //printf( %d removed n n , x); n                         //printPosState(n); n                         res.push_back(x); n                         found = true; n                         break; n                     } n                 } n                 if(found){break;} n             } n             if(!found){ n                 cnt ++; n                 for(int i = 1; i <= n; i ++){ n                     for(int j = 1; j <= n; j ++){ n                         if((int)pos[i][j].size() == 2){ n                             int x = pos[i][j][0]; n                             remove1(x, n); n                             //printf( %d removed n n , x); n                             //printPosState(n); n                             res.push_back(x); n                             found = true; n                             break; n                         } n                     } n                     if(found){break;} n                 } n             } n  n             if(!found){break;} n         } n  n         //printf( cnt=%d n , cnt); n  n         long long ans = 1; n         for(int i = 1; i < cnt; i ++){ n             ans = (ans+ans)%MOD; n         } n  n         printf( %lld n , ans); n         for(int x: res){ n             printf( %d  , x); n         } n         printf(  n ); n     } n  n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 400010; n const long long mod = 1000000007; n const long double eps = 1e-9; n const long long inf = ((1ll << 31ll) - 1ll); n const long long INF = 2000000000000000000ll; n const long double pi = acos(-1); n long long qpow(long long b, long long e) { n   if (!e) return 1; n   if (e & 1) return qpow(b, e - 1) * b % mod; n   long long pwur = qpow(b, e >> 1); n   return pwur * pwur % mod; n } n long long modinv(long long x) { return qpow(x, mod - 2); } n long long tc, n, a[maxn]; n vector<long long> ans; n bool sorted() { n   for (long long i = 1; i < n; i++) n     if (a[i] > a[i + 1]) return 0; n   return 1; n } n void shft(long long x) { n   swap(a[x + 2], a[x + 1]); n   swap(a[x + 1], a[x]); n } n void tryl() { n   for (long long i = 1; i <= n - 2; i++) { n     pair<long long, long long> mn = {mod, -1}; n     for (long long j = i; j <= n; j++) { n       if (mn.first > a[j]) { n         mn = {a[j], j}; n       } n     } n     while (mn.second != i) { n       if (mn.second - 2 >= i) { n         shft(mn.second - 2); n         mn.second -= 2; n         ans.push_back(mn.second); n       } else { n         shft(mn.second - 1); n         shft(mn.second - 1); n         mn.second -= 1; n         ans.push_back(mn.second); n         ans.push_back(mn.second); n       } n     } n   } n } n void tryr() { n   for (long long i = n; i >= 3; i--) { n     pair<long long, long long> mx = {-1, -1}; n     for (long long j = 1; j <= i; j++) { n       if (mx.first <= a[j]) { n         mx = {a[j], j}; n       } n     } n     while (mx.second != i) { n       if (mx.second + 2 <= i) { n         shft(mx.second); n         ans.push_back(mx.second); n         mx.second += 2; n       } else { n         shft(mx.second - 1); n         ans.push_back(mx.second - 1); n         mx.second += 1; n       } n     } n   } n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.setf(ios::fixed); n   cout.precision(0); n   srand(time(NULL)); n   cin >> tc; n   while (tc--) { n     ans.clear(); n     cin >> n; n     for (long long i = 1; i <= n; i++) cin >> a[i]; n     long long bu = 10; n     while (bu--) { n       tryl(); n       tryr(); n     } n     for (long long i = 0; i <= 3; i++) { n       if (i) shft(n - 2); n       if (a[n - 2] <= a[n - 1] && a[n - 1] <= a[n]) { n         for (long long j = 1; j <= i; j++) ans.push_back(n - 2); n         break; n       } n     } n     if (!sorted()) { n       cout << -1 <<   n ; n       continue; n     } n     cout << ans.size() <<   n ; n     for (auto i : ans) cout << i <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     vector<int> a(3); n     cin >> a[0] >> a[1] >> a[2]; n     sort(a.begin(), a.end()); n     int v = a[0]; n     int d = min(v, a[2] - a[1]); n     int ans = d; n     a[0] -= d; n     a[2] -= d; n     d = a[0] / 2 + a[0] % 2; n     a[2] = a[2] - d; n     a[1] = a[1] - a[0] / 2; n     ans += a[0]; n     ans += min(a[1], a[2]); n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char const *argv[]) { n   int cases; n   cin >> cases; n   while (cases--) { n     int length, target; n     cin >> length >> target; n     vector<vector<int>> BGR(3, vector<int>(length, 0)); n     string inp; n     cin >> inp; n     for (size_t i = 0, tok; i < inp.length(); ++i) { n       if (inp[i] ==  B ) n         tok = 0; n       else if (inp[i] ==  G ) n         tok = 1; n       else n         tok = 2; n       BGR[(tok + i) % 3][i] = 1; n     } n     int ans = target; n     for (auto x : BGR) { n       size_t j = 0; n       int init = target; n       for (; j < target; ++j) init -= x[j]; n       ans = init < ans ? init : ans; n       for (size_t i = 0; j < x.size(); ++i, ++j) { n         init += x[i] - x[j]; n         ans = init < ans ? init : ans; n       } n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INFint = 2147483647; n const long long INF = 9223372036854775807ll; n const long long MOD = 1000000007ll; n char f[2020][2020]; n int n, m; n bool c(int x, int y, int d, int cnt) { n   int cur = 0; n   cerr << x <<     << y << endl; n   if (x > 0 && y > 0 && x + d - 1 <= n && y + d - 1 <= m) { n     for (int i = x; i < x + d; i++) { n       cur += (f[i][y] ==  w ); n       cur += (f[i][y + d - 1] ==  w ); n     } n     for (int i = y + 1; i < y + d - 1; i++) { n       cur += (f[x][i] ==  w ); n       cur += (f[x + d - 1][i] ==  w ); n     } n     return (cur == cnt); n   } n   return 0; n } n int main() { n   ios_base::sync_with_stdio(0); n   int minx = INFint, miny = INFint, maxx = -INFint, maxy = -INFint; n   cin >> n >> m; n   int cnt = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       cin >> f[i][j]; n       if (f[i][j] ==  w ) { n         minx = min(minx, i); n         miny = min(miny, j); n         maxx = max(maxx, i); n         maxy = max(maxy, j); n         cnt++; n       } n     } n   } n   int d = max(maxx - minx + 1, maxy - miny + 1); n   cerr << d << endl; n   if (d == 1) { n     for (int it = 1; it <= n; it++) { n       for (int l = 1; l <= m; l++) cout << f[it][l]; n       cout << endl; n     } n     return 0; n   } n   int x[3] = {minx, maxx - d + 1, 1}; n   int y[3] = {miny, maxy - d + 1, 1}; n   for (int i = 0; i < 3; i++) cerr << x[i] <<    ; n   cerr << endl; n   for (int i = 0; i < 3; i++) cerr << y[i] <<    ; n   cerr << endl; n   for (int i = 0; i < 3; i++) n     for (int j = 0; j < 3; j++) { n       if (c(x[i], y[j], d, cnt)) { n         for (int it = x[i]; it < x[i] + d; it++) { n           if (f[it][y[j]] !=  w ) f[it][y[j]] =  + ; n           if (f[it][y[j] + d - 1] !=  w ) f[it][y[j] + d - 1] =  + ; n         } n         for (int it = y[j]; it < y[j] + d; it++) { n           if (f[x[i]][it] !=  w ) f[x[i]][it] =  + ; n           if (f[x[i] + d - 1][it] !=  w ) f[x[i] + d - 1][it] =  + ; n         } n         for (int it = 1; it <= n; it++) { n           for (int l = 1; l <= m; l++) cout << f[it][l]; n           cout << endl; n         } n         return 0; n       } n     } n   cout << -1 << endl; n   fprintf(stderr,   nTIME = %lf n , 1.0 * clock() / CLOCKS_PER_SEC); 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   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   int count1 = 0; n   for (int i = 0; i < n; i++) { n     int sum = 0; n     for (int j = 0; j < n; j++) { n       if (i == j) { n         continue; n       } else { n         sum += a[j]; n       } n     } n     if (sum % 2 == 0) { n       count1++; n     } n   } n   cout << count1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int sgn(double x) { return (x > 1e-8) - (x < -1e-8); } n int count_bit(int x) { return x == 0 ? 0 : count_bit(x >> 1) + (x & 1); } n template <class T> n inline void ckmin(T& a, const T b) { n   if (b < a) a = b; n } n template <class T> n inline void ckmax(T& a, const T b) { n   if (b > a) a = b; n } n const int MAXN = 100000 + 10; n struct binary_indexed_tree { n   int a[MAXN], val[MAXN]; n   void clear() { n     memset(a, 0, sizeof(a)); n     memset(val, 0, sizeof(val)); n   } n   void update(int x, int y) { n     val[x] += y; n     for (; x < MAXN; x += ((x) & (-(x)))) { n       a[x] += y; n     } n   } n   int getsum(int x) { n     int ret = 0; n     for (; x; x -= ((x) & (-(x)))) { n       ret += a[x]; n     } n     return ret; n   } n   int getsum(int l, int r) { n     int ret = 0; n     while (l <= r) { n       if (r - ((r) & (-(r))) + 1 >= l) { n         ret += a[r]; n         r -= ((r) & (-(r))); n       } else { n         ret += val[r--]; n       } n     } n     return ret; n   } n } bit; n void filp_left(int& l, int& r, int len) { n   for (int i = (1); i <= (len); ++i) { n     bit.update(l + len + len - i, bit.val[l + i - 1]); n   } n   l += len; n } n void filp_right(int& l, int& r, int len) { n   for (int i = (1); i <= (len); ++i) { n     bit.update(r - len - len + i, bit.val[r - i + 1]); n   } n   r -= len; n } n int main() { n   int n, q; n   while (scanf( %d%d , &n, &q) != EOF) { n     bit.clear(); n     for (int i = 0; i < (n); ++i) { n       bit.update(i + 1, 1); n     } n     int off = 0; n     int l = 1, r = n; n     bool rev = false; n     for (int i = 0; i < (q); ++i) { n       int optype, flen, cl, cr; n       scanf( %d , &optype); n       if (optype == 1) { n         scanf( %d , &flen); n         int clen = r - l + 1; n         if (2 * flen > clen) { n           if (!rev) { n             filp_right(l, r, clen - flen); n           } else { n             filp_left(l, r, clen - flen); n           } n           rev = !rev; n         } else { n           if (!rev) { n             filp_left(l, r, flen); n           } else { n             filp_right(l, r, flen); n           } n         } n       } else { n         scanf( %d%d , &cl, &cr); n         int ret; n         if (!rev) { n           ret = bit.getsum(l + cl, l + cr - 1); n         } else { n           ret = bit.getsum(r - cr + 1, r - cl); n         } n         printf( %d n , ret); n       } 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, m; n   cin >> n >> m; n   int c1 = 0, c2 = 0; n   for (int i = 0; i < n; ++i) { n     int aux; n     cin >> aux; n     c1 += aux == 1; n     c2 += aux == -1; n   } n   for (int i = 0; i < m; ++i) { n     int a, b; n     cin >> a >> b; n     if ((b - a + 1) % 2 == 0) { n       if (c1 >= (b - a + 1) / 2 && c2 >= (b - a + 1) / 2) n         cout <<  1 n ; n       else n         cout <<  0 n ; n     } else n       cout <<  0 n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   char s[15]; n   char a; n   int len; n   scanf( %s , s); n   len = strlen(s); n   a =  a  - 1; n   for (int i = 0; i < len; i++) { n     if (a <= s[i]) { n       a = s[i]; n     } n   } n   for (int i = 0; i < len; i++) { n     if (s[i] == a) printf( %c , s[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000000 + 239; n const int inf = (int)1e9 + 1; n const long long big = (long long)1e18 + 1; n const int P = 31; n const int MOD = (int)1e9 + 7; n const int MOD1 = (int)1e9 + 9; n const double eps = 1e-9; n const double pi = atan2(0, -1); n int a[N]; n vector<int> g[N]; n int d[N]; n void dfs(int u) { n   for (int v : g[u]) { n     dfs(v); n     d[u] = max(d[u], d[v] + 1); n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.precision(20); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 1; i < n; i++) { n     int p; n     cin >> p; n     p--; n     g[p].push_back(i); n   } n   dfs(0); n   int res = 0; n   for (int i = 0; i < n; i++) n     if (d[i] % 2 == 0) res ^= a[i]; n   map<int, int> cnt; n   for (int i = 0; i < n; i++) n     if (d[i] % 2 == 1) cnt[a[i]]++; n   long long ans = 0; n   for (int i = 0; i < n; i++) n     if (d[i] % 2 == 0) ans += cnt[res ^ a[i]]; n   if (res == 0) { n     int cnt0 = 0, cnt1 = 0; n     for (int i = 0; i < n; i++) n       if (d[i] % 2 == 0) n         cnt0++; n       else n         cnt1++; n     ans += (long long)cnt0 * (cnt0 - 1) / 2; n     ans += (long long)cnt1 * (cnt1 - 1) / 2; n   } n   cout << ans << endl; n   return 0; n } n


//#pragma GCC target ( avx2 ) n //#pragma GCC optimization ( O3 ) n //#pragma GCC optimization ( unroll-loops ) n #include<bits/stdc++.h> n //#include <ext/pb_ds/assoc_container.hpp> n //#include <ext/pb_ds/tree_policy.hpp> n //using namespace __gnu_pbds; n #define eps 1e-8 n #define eq(x,y) (fabs((x)-(y)) < eps) n using namespace std; n typedef long long ll; n typedef long double ld; n typedef pair<int,int>pii; n const ll mod= 998244353; n long double PI = acosl(-1); n const ll infl = 1e17+100; n const int inf = 1e9+100; n const int nmax = 3e5+5; n //const int MAXLG = log2(nmax)+1; n //mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); n //typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost; n  n bool vis[nmax]; n vector<int>g[nmax]; n  n void dfs(int u){ n     vis[u] = true; n     for(int v : g[u]) if(!vis[v]) n         dfs(v); n } n  n  n int main(){ n  n     ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); n  n     int tc; n     cin>>tc; n     while(tc--){ n         int n,m; n         cin>>n>>m; n         for(int i=0; i<m; i++){ n             int u,v; n             cin>>u>>v; n             g[u].push_back(v); n             g[v].push_back(u); n         } n         bool hoise = false; n         bool unposibol = false; n         for(int i=1; i<=n; i++){ n             if(!vis[i]){ n                 if(!hoise){ n                     dfs(i); n                     hoise = true; n                 } n                 else unposibol = true; n             } n         } n         if(unposibol) cout<< NO n ; n         else{ n             cout<< YES n ; n             for(int i=1; i<=n; i++) vis[i] = false; n             vector<int>ans; n             set<int>st; st.insert(1); n             while(st.size()){ n                 int u = *st.begin(); n                 st.erase(u); n                 if(vis[u]) continue; n                 vis[u] = true; n                 ans.push_back(u); n                 vector<int>tmp; n                 for(int v : g[u]) if(!vis[v]){ n                     vis[v] = true; n                     tmp.push_back(v); n                 } n                 for(int v : tmp){ n                     for(int z : g[v]) if(!vis[z]){ n                         st.insert(z); n                     } n                 } n             } n             cout<<ans.size()<<  n ; n             for(int x : ans) cout<<x<<   ; n             cout<<  n ; n         } n         for(int i=1; i<=n; i++) vis[i] = false, g[i].clear(); n     } n  n  n } n /* n  n */ n


#include <bits/stdc++.h> n using namespace std; n long long mysqrt(long long x) { n   long long l = 0; n   long long r = 1; n   while (r * r <= x) r *= 2; n   while (r - l > 1) { n     long long m = (l + r) / 2; n     if (m * m <= x) n       l = m; n     else n       r = m; n   } n   return l; n } n int main() { n   long long n; n   cin >> n; n   long long a[n + 2][n + 2]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       cin >> a[i][j]; n     } n   } n   for (int i = 0; i < n; i++) { n     int j = (i + 1) % n; n     int k = (j + 1) % n; n     cout << mysqrt(1ll * a[i][j] * a[i][k] / a[j][k]) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, mx = 0, i, j, value; n   cin >> n; n   vector<int> v(n + 1, 0); n   for (i = 1; i <= n; i++) { n     cin >> v[i]; n     v[i] += v[i - 1]; n   } n   for (i = 1; i <= n; i++) { n     for (j = 0; j < i; j++) { n       if ((v[i] - v[j]) > (100 * (i - j))) { n         mx = max(mx, i - j); n         break; n       } n     } n   } n   cout << mx << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve(); n string conc(long long int a, long long int b) { n   return to_string(a) +  |  + to_string(b); n } n long long int rev(long long int x) { n   long long int ans = 0; n   while (x != 0) { n     ans = ans * 10 + (x % 10); n     x /= 10; n   } n   return ans; n } n long long int numdig(long long int x) { n   long long int ans = 0; n   while (x != 0) { n     ans++; n     x /= 10; n   } n   return ans; n } n void printvec(vector<long long int> &v) { n   for (long long int i = 0; i < v.size(); i++) cout << v[i] <<    ; n   cout <<   n ; n } n void printmat(vector<vector<long long int>> &mat) { n   for (long long int i = 0; i < mat.size(); i++) { n     for (long long int j = 0; j < mat[0].size(); j++) cout << mat[i][j] <<    ; n     cout <<   n ; n   } n } n void solve() { n   long long int n, k; n   cin >> n >> k; n   string s; n   cin >> s; n   vector<long long int> f(26, 0); n   vector<pair<char, long long int>> v; n   long long int vsize = 0; n   for (auto c : s) f[c -  a ]++; n   for (long long int i = 0; i < 26; i++) { n     if (f[i] > 0) { n       v.push_back({ a  + i, f[i]}); n       vsize++; n     } n   } n   if (v[0].second < k) { n     long long int count = 0; n     for (long long int i = 0; i < vsize; i++) { n       count += v[i].second; n       if (count >= k) { n         cout << v[i].first <<   n ; n         return; n       } n     } n     return; n   } n   string init =   ; n   init = init + v[0].first; n   vector<string> words(k, init); n   v[0].second -= k; n   for (long long int i = 0; i < vsize; i++) { n     if (i == vsize - 1) { n       long long int j = 0; n       long long int c = 0; n       while (j < k && words[j] == words[0]) j++; n       while (v[i].second--) { n         words[c] += v[i].first; n         c = (c + 1) % j; n       } n     } else { n       while (v[i].second--) { n         words[0] += v[i].first; n       } n     } n   } n   sort(words.begin(), words.end()); n   cout << words[k - 1] <<   n ; n } n int main(void) { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t; n   t = 1; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 998244353; n pair<int, int> calc(int a, int b) { n   if (a <= b) return {a, 0}; n   int r = a / b; n   if (a % b == 0) return {b, r - 1}; n   return {a / (r + 1), r}; n } n vector<pair<int, int>> compact(const vector<pair<int, int>>& V) { n   vector<pair<int, int>> R; n   int p = -1, c = 0; n   for (auto [a, b] : V) { n     if (a != p && p != -1) { n       R.emplace_back(p, c); n       c = 0; n     } n     p = a; n     c += b; n   } n   R.emplace_back(p, c); n   return R; n } n int main() { n   ios_base::sync_with_stdio(false); n   int tn; n   cin >> tn; n   for (int ti = 0; ti < tn; ++ti) { n     int n; n     cin >> n; n     vector<int> A(n); n     for (int& a : A) cin >> a; n     vector<pair<int, int>> B; n     uint64_t r = 0; n     for (int i = n - 1; i > 0; --i) { n       B.emplace_back(A[i], 1); n       vector<pair<int, int>> C; n       for (auto [x, y] : B) { n         auto [z, t] = calc(A[i - 1], x); n         C.emplace_back(z, y); n         r = (r + 1ull * t * i * y) % MOD; n       } n       sort(C.begin(), C.end()); n       B = compact(C); n     } n     cout << r << endl; n   } n   return 0; n } n


#include<bits/stdc++.h> n #define maxn 1000005 n #define inf 9999999999999999 n #define mod 100003 n typedef long long LL; n using namespace std; n LL a[maxn]; n int main() n { n     ios::sync_with_stdio(false); n     //freopen( bwxnQAQin.txt , r ,stdin); n     LL T; n     cin>>T; n     while(T--) n     { n         LL n; n         cin>>n; n         if(n&1) n         { n             LL zong=n-1,fuyi=zong/2; n             for(LL i=zong;i>=1;i--) n             { n                 for(LL j=1;j<=i-fuyi;j++)cout<< 1  ; n                 for(LL j=1;j<=fuyi;j++)cout<< -1  ; n                 if(fuyi)fuyi--; n             } n             cout<<endl; n         } n         else n         { n             LL zong=n-1,ban=zong/2; n             for(LL i=1;i<=zong;i++) n             { n                 for(LL j=i;j<=zong;j++) n                 { n                     if(j<i+ban)cout<< 1  ; n                     else if(j==i+ban)cout<< 0  ; n                     else cout<< -1  ; n                 } n             } n             cout<<endl; n         } n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n double p[200010]; n int n, cnt; n double ans; n inline void solve(int a, int b) { n   ans += (double)(a - b) / 2; n   p[++cnt] = (double)(a + b) / 2; n } n int main() { n   n = read(); n   for (int i = 1; i <= n; i++) { n     long long a = read(), b = read(), c = read(), d = read(); n     if (a + b >= c + d) { n       solve(a, b); n       solve(c, d); n     } else { n       if (a >= d) solve(a - d, d - a); n       if (b >= c) solve(c - b, b - c); n     } n   } n   sort(p + 1, p + cnt + 1, greater<double>()); n   for (int i = 1; i <= cnt; i++) { n     if (i & 1) n       ans += p[i]; n     else n       ans -= p[i]; n   } n   printf( %.0f n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000010; n int f[N]; n void init() { n   for (int i = 1; i <= N; i++) { n     f[i] = f[i - 1] + i * 2 + (i - 1); n     if (f[i] >= 1e9) { n       break; n     } n   } n } n int Find(int x) { n   int l = 0, r = 25820; n   while (l < r) { n     int mid = (l + r + 1) / 2; n     if (f[mid] <= x) n       l = mid; n     else n       r = mid - 1; n   } n   return l; n } n int main() { n   int T; n   scanf( %d , &T); n   init(); n   while (T--) { n     int x; n     scanf( %d , &x); n     int ans = 0; n     while (true) { n       int t = Find(x); n       if (f[t] <= 0) break; n       x -= f[t]; n       ans++; n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = ~0ull / 2; n const int maxn = 100100; n int seen[maxn]; n int ind[maxn]; n int par[maxn][22]; n int bd[maxn]; n int h[maxn]; n vector<int> adj[maxn]; n vector<int> adlist[maxn]; n vector<int> tree[maxn]; n vector<pair<int, int> > edges; n void dfs1(int root, int dad = -1) { n   seen[root] = 1; n   bd[root] = h[root]; n   for (auto v : adj[root]) { n     if (!seen[v]) { n       h[v] = h[root] + 1; n       dfs1(v, root); n       bd[root] = min(bd[v], bd[root]); n       if (!(bd[v] > h[root])) { n         adlist[root].push_back(v); n         adlist[v].push_back(root); n       } else { n         edges.push_back(make_pair(root, v)); n       } n     } else { n       if (v != dad) { n         adlist[root].push_back(v); n         adlist[v].push_back(root); n         bd[root] = min(bd[root], h[v]); n       } n     } n   } n } n void dfs2(int root, int t) { n   seen[root] = 2; n   ind[root] = t; n   for (auto v : adlist[root]) { n     if (seen[v] == 1) { n       dfs2(v, t); n     } n   } n } n void dfs3(int root, int dad) { n   par[root][0] = dad; n   for (auto v : tree[root]) { n     if (v != dad) { n       h[v] = h[root] + 1; n       dfs3(v, root); n     } n   } n } n int dis(int x, int y) { n   x = ind[x]; n   y = ind[y]; n   if (h[x] < h[y]) swap(x, y); n   int X = x; n   int Y = y; n   int t = 20; n   while (h[x] != h[y]) { n     if (h[par[x][t]] >= h[y]) x = par[x][t]; n     t--; n   } n   if (x == y) return h[X] - h[x]; n   int A; n   t = 20; n   while (par[x][0] != par[y][0] and t >= 0) { n     if (par[x][t] != par[y][t]) { n       x = par[x][t]; n       y = par[y][t]; n     } n     t--; n   } n   A = par[x][0]; n   return (h[X] + h[Y] - 2 * h[A]); n } n int main() { n   ios::sync_with_stdio(false), cin.tie(0); n   int n, m, k; n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int a, b; n     cin >> a >> b; n     a--, b--; n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   dfs1(0); n   int t = 1; n   for (int i = 0; i < n; i++) { n     if (seen[i] == 1) { n       dfs2(i, t); n       t++; n     } n   } n   for (auto e : edges) { n     int x = e.first; n     int y = e.second; n     x = ind[x]; n     y = ind[y]; n     tree[x].push_back(y); n     tree[y].push_back(x); n   } n   h[0] = 0; n   h[1] = 1; n   dfs3(1, 0); n   fill(par[0], par[0] + 22, 0); n   for (int i = 1; i < 22; i++) n     for (int j = 1; j < t; j++) par[j][i] = par[par[j][i - 1]][i - 1]; n   cin >> k; n   for (int i = 0; i < k; i++) { n     int s, l; n     cin >> s >> l; n     s--, l--; n     cout << dis(s, l) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n double dp[maxn], p[maxn]; n int main() { n   int n; n   scanf( %d , &n); n   double ans = 0, d; n   for (int i = 1; i <= n; i++) { n     scanf( %lf , &p[i]); n     ans += p[i]; n   } n   for (int i = 2; i <= n; i++) { n     dp[i] = (dp[i - 1] + p[i - 1]) * p[i]; n     ans += 2 * dp[i]; n   } n   printf( %.10f n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0; n   char c = getchar(); n   bool p = 1; n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) p = 0; n   for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); n   return p ? x : -x; n } n const int N = 1000105; n struct edge { n   int to, nt; n } e[N * 2]; n int n, k, x, y, ans, cnt, head[N], rt = 1, du[N]; n void add(int u, int v) { n   e[++cnt] = (edge){v, head[u]}; n   head[u] = cnt; n } n int dfs(int u, int fa) { n   vector<int> v; n   int i; n   for (i = head[u]; i; i = e[i].nt) n     if (e[i].to != fa) v.push_back(dfs(e[i].to, u) + 1); n   sort(v.begin(), v.end()); n   for (i = v.size() - 1; i > 0; i--) n     if (v[i] + v[i - 1] > k) n       ans++; n     else n       break; n   return v.size() == 0 ? 0 : v[i]; n } n int main() { n   n = read(); n   k = read(); n   for (int i = 1; i < n; i++) { n     x = read(); n     y = read(); n     add(x, y); n     add(y, x); n     du[x]++; n     du[y]++; n     if (du[x] > 1) rt = x; n     if (du[y] > 1) rt = y; n   } n   dfs(rt, 0); n   cout << ans + 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int main() { n   ios_base ::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, m; n   cin >> n >> m; n   long long a[n + 1]; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   long long v, x, add = 0, y, q; n   int t; n   while (m--) { n     cin >> t; n     if (t == 1) { n       cin >> v >> x; n       a[v] = x - add; n     } else if (t == 2) { n       cin >> y; n       add += y; n     } else { n       cin >> q; n       cout << a[q] + add <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double areaa(int x1, int x2, int x3, int y1, int y2, int y3); n int gcd(int x, int y); n int lcm(int x, int y); n int egcd(int a, int b, int& x, int& y); n vector<int> prime_possible_factors(int n); n vector<int> primes_included(int n, int m); n map<int, int> factor(int N); n bool isPrime(int N); n int charType(char c); n double areaa(int x1, int x2, int x3, int y1, int y2, int y3) { n   double area = abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 4.0); n   return area; n } n int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); } n int lcm(int x, int y) { return (x * y / gcd(x, y)); } n int egcd(int a, int b, int& x, int& y) { n   if (b == 0) { n     x = 1; n     y = 0; n     return a; n   } else { n     int d = egcd(b, a % b, x, y); n     x -= a / b * y; n     swap(x, y); n     return d; n   } n } n vector<int> prime_possible_factors(int n) { n   bool* isPrime = new bool[n]; n   for (int i = 0; i < n; i++) { n     isPrime[i] = true; n   } n   vector<int> primes; n   for (int i = 2; i * i <= n; ++i) { n     if (isPrime[i]) { n       primes.push_back(i); n       for (int j = i; j < n; j += i) isPrime[j] = false; n     } n   } n   return primes; n } n vector<int> primes_included(int n, int m) { n   bool* isPrime = new bool[m]; n   for (int i = 0; i < m; i++) { n     isPrime[i] = true; n   } n   vector<int> primes; n   for (int i = 2; i < m; ++i) { n     if (isPrime[i]) { n       if (i >= n) primes.push_back(i); n       for (int j = i; j < m; j += i) isPrime[j] = false; n     } n   } n   return primes; n } n map<int, int> factor(int N) { n   vector<int> primes; n   primes = primes_included(0, N); n   map<int, int> factors; n   for (int i = 0; i < primes.size(); ++i) { n     int prime = primes[i], power = 0; n     while (N % prime == 0) { n       power++; n       N /= prime; n     } n     factors[prime] = power; n   } n   return factors; n } n bool isPrime(int N) { n   vector<int> check = prime_possible_factors(N); n   for (int i = 0; i < check.size(); i++) { n     if (N % check[i] == 0) { n       return false; n     } n   } n   return true; n } n int main() { n   int T; n   long long int n, s, t; n   cin >> T; n   int i = 0; n   for (i; i < T; i++) { n     cin >> n >> s >> t; n     cout << max(n - s, n - t) + 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s, t, tmp1, tmp2; n vector<int> ans; n int cnt, n; n int main() { n   cin >> n; n   cin >> s >> t; n   tmp1 = s, tmp2 = t; n   sort(tmp1.begin(), tmp1.end()); n   sort(tmp2.begin(), tmp2.end()); n   if (tmp1 != tmp2) return cout << -1, 0; n   if (s[0] == t[n - 1]) cnt++; n   while (cnt != n) { n     int i; n     for (i = cnt; i < n; i++) { n       if (s[i] == t[n - cnt - 1]) break; n     } n     ans.push_back(n); n     for (int j = 0; j < n / 2; j++) swap(s[j], s[n - j - 1]); n     s = s.substr(n - i, i) + s.substr(0, n - i); n     for (int j = 0; j < i / 2; j++) swap(s[j], s[i - j - 1]); n     s = s.substr(n - 1, 1) + s.substr(0, n - 1); n     ans.push_back(i); n     ans.push_back(1); n     cnt++; n   } n   cout << ans.size() << endl; n   for (int i = 0; i < (int)ans.size(); i++) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 2; n int a[N], b[N]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   for (int i = 0; i < (int)n; i++) cin >> a[i], b[i + 1] += b[i] + a[i]; n   int t = 0; n   for (int i = 0; i < (int)n; i++) { n     for (int j = 0; j < (int)i + 1; j++) { n       if (b[i + 1] - b[j] > 100 * (i - j + 1)) t = max(t, i - j + 1); n     } n   } n   cout << t <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int MIN(int a, int b) { return a < b ? a : b; }; n int MAX(int a, int b) { return a > b ? a : b; }; n int gcd(int a, int b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n int n, m, q; n int h; n int a[20] = {2,  4,  3,  9,  5,  25, 7,  49, 11, 13, n              17, 19, 23, 29, 31, 37, 41, 43, 47, 53}; n int main() { n   int i, j, x, y, T, num, t; n   string str; n   t = num = 0; n   for (i = 0; i < 20; i++) { n     cout << a[i] << endl; n     cin >> str; n     num++; n     x = a[i]; n     if (str ==  yes ) { n       t++; n     } n     if (t > 1) break; n   } n   if (i == 20) n     cout <<  prime n ; n   else n     cout <<  composite n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n struct edge { n   int from; n   int to; n   int next; n } E[500005 << 1]; n int head[100005]; n int deg[100005]; n int tmp[500005]; n int used[500005 << 1]; n int size = 1; n void add_edge(int u, int v) { n   size++; n   E[size].from = u; n   E[size].to = v; n   E[size].next = head[u]; n   head[u] = size; n } n stack<int> s, ans; n void euler() { n   s.push(1); n   while (!s.empty()) { n     int x = s.top(); n     int i = head[x]; n     while (i != 0 && used[i] == 1) i = E[i].next; n     if (i != 0) { n       s.push(E[i].to); n       used[i] = used[i ^ 1] = 1; n       head[x] = E[i].next; n     } else { n       s.pop(); n       ans.push(x); n     } n   } n } n int main() { n   int u, v; n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= m; i++) { n     scanf( %d %d , &u, &v); n     add_edge(u, v); n     add_edge(v, u); n     deg[u]++; n     deg[v]++; n   } n   int pre = 0; n   int cnt = 0; n   for (int i = 1; i <= n; i++) { n     if (deg[i] % 2 == 1) { n       if (pre != 0) { n         add_edge(pre, i); n         add_edge(i, pre); n         pre = 0; n       } else n         pre = i; n     } n   } n   if (((size - 1) / 2) % 2 == 1) { n     add_edge(1, 1); n     size++; n   } n   euler(); n   printf( %d n , (size - 1) / 2); n   int ptr = 0; n   while (!ans.empty()) { n     tmp[++ptr] = ans.top(); n     ans.pop(); n   } n   for (int i = 1; i <= ptr - 1; i++) { n     if (i & 1) n       printf( %d %d n , tmp[i], tmp[i + 1]); n     else n       printf( %d %d n , tmp[i + 1], tmp[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1123456; n const int MAXINT = 2147483098; n const long long MAXLL = 9223372036854775258LL; n set<pair<int, int> > s; n int ans[MAXN]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, m, d, pos = 0, mx = 0; n   cin >> n >> m >> d; n   for (int i = 1; i <= n; ++i) { n     int a; n     cin >> a; n     s.insert(make_pair(a, i)); n   } n   for (int i = 1; i <= n; ++i) { n     if (!s.size()) break; n     ans[s.begin()->second] = i; n     mx = i; n     long long val = s.begin()->first; n     s.erase(s.begin()); n     while (1) { n       if (!s.size()) break; n       auto it = s.lower_bound(make_pair(val + d + 1, 0LL)); n       if (it == s.end()) break; n       ans[it->second] = i; n       val = it->first; n       s.erase(it); n     } n   } n   cout << mx <<   n ; n   for (int i = 1; i <= n; ++i) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n char s[200005]; n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   getchar(); n   cin >> s; n   int maxn1 = 0; n   for (int i = 0; i < 26; i++) { n     char t =  a  + i; n     int sum1 = 0; n     int maxn = 0; n     for (int j = 0; j < n; j++) { n       if (s[j] == t && s[j + 1] == t) n         sum1++; n       else if (s[j] == t && s[j + 1] != t) { n         sum1++; n         maxn += sum1 / k; n         sum1 = 0; n       } n     } n     maxn1 = max(maxn, maxn1); n   } n   cout << maxn1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200010; n vector<int> G[maxn]; n int n, k; n int u, v; n int siz[maxn], dep[maxn]; n int val[maxn], fa[maxn]; n void dfs(int x, int d) { n   dep[x] = d; n   siz[x] = 1; n   for (int i = 0; i < G[x].size(); ++i) { n     int to = G[x][i]; n     if (to == fa[x]) continue; n     fa[to] = x; n     dfs(to, d + 1); n     siz[x] += siz[to]; n   } n   val[x] = siz[x] - dep[x]; n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i < n; ++i) { n     scanf( %d%d , &u, &v); n     G[u].push_back(v); n     G[v].push_back(u); n   } n   dfs(1, 1); n   sort(val + 1, val + 1 + n); n   long long ans = 0; n   for (int i = k + 1; i <= n; ++i) ans += (long long)val[i]; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, k; n   cin >> n >> k; n   pair<long long, long long> a[n]; n   for (long long i = 0; i < n; i++) { n     cin >> a[i].first; n     a[i].second = i; n   } n   sort(a, a + n); n   queue<long long> q; n   set<long long> s; n   bool turn = true; n   long long ans[n]; n   for (long long i = n - 1; i >= 0; i--) { n     q.push(a[i].second); n     s.insert(i); n   } n   while (!q.empty()) { n     long long top = q.front(); n     q.pop(); n     if (s.find(top) == s.end()) continue; n     vector<long long> v; n     long long count = 0; n     for (auto itr = prev(s.find(top)); count < k && itr != prev(s.begin()); n          itr--) { n       v.push_back(*itr); n       count++; n     } n     count = 0; n     for (auto itr = s.find(top); count <= k && itr != s.end(); itr++) { n       v.push_back(*itr); n       count++; n     } n     for (long long i = 0; i < v.size(); i++) { n       s.erase(v[i]); n       ans[v[i]] = turn; n     } n     turn = !turn; n   } n   for (long long i = 0; i < n; i++) { n     if (ans[i]) n       cout << 1; n     else n       cout << 2; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n, m; n   cin >> n >> m; n   vector<pair<string, int>> a(n); n   int c = 1; n   for (auto &t : a) { n     cin >> t.first; n     t.second = c++; n   } n   for (auto &t : a) { n     for (int i = 1; i < m; i += 2) { n       t.first[i] =  z  - t.first[i] +  a ; n     } n   } n   sort(a.begin(), a.end()); n   for (auto t : a) { n     cout << t.second <<    ; n   } n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> g[100005]; n double dfs(int i, int ult) { n   double ans = 0; n   int c = g[i].size() - (i != 1); n   for (int j = 0; j < g[i].size(); j++) { n     if (g[i][j] != ult) { n       ans += (dfs(g[i][j], i) + 1.0) / c; n     } n   } n   return ans; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     int a, b; n     scanf( %d %d , &a, &b); n     g[a].push_back(b); n     g[b].push_back(a); n   } n   printf( %.15lf n , dfs(1, 0)); n } n


#include <bits/stdc++.h> n using namespace std; n const long long MXN = 2e5 + 10; n const long long LOG = 21; n const long long MXM = (1LL << LOG); n const long long INF = 1e9; n int n, m, ans; n int dp[MXN], ps[MXN], Best[LOG][MXM]; n string S[MXN]; n int Cost(int i, int j) { n   for (int x = m; x; x--) { n     if (S[i].substr(m - x + 1, x) == S[j].substr(1, x)) { n       return m - x; n     } n   } n   return m; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   memset(dp, 31, sizeof dp), memset(Best, 31, sizeof Best); n   cin >> n, ans = INF; n   for (int i = 1; i <= n; i++) { n     cin >> S[i], m = (long long)S[i].size(); n     S[i] =  0  + S[i]; n   } n   ps[1] = dp[1] = m; n   for (int i = 2; i <= n; i++) ps[i] = ps[i - 1] + Cost(i - 1, i); n   for (int i = 2; i <= n; i++) { n     dp[i] = ps[i - 1] + m; n     long long mask = 0; n     for (int x = 0; x <= m; x++) { n       mask = mask * 2 + (S[i][x] -  0 ); n       if (Best[x][mask] < INF) { n         dp[i] = min(dp[i], ps[i - 1] + m - x + Best[x][mask]); n       } n     } n     mask = 0; n     for (int x = 0; x <= m; x++) { n       if (x && S[i - 1][m - x + 1] ==  1 ) { n         mask += (1LL << (x - 1)); n       } n       Best[x][mask] = min(Best[x][mask], dp[i] - ps[i]); n     } n   } n   for (int i = 1; i <= n; i++) ans = min(ans, dp[i] + ps[n] - ps[i]); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> idb[100002]; n int dp[301]; n int main() { n   int n, m, s, e; n   cin >> n >> m >> s >> e; n   vector<int> a(n); n   for (int i = 0; i < n; i++) scanf( %d , &a[i]); n   for (int i = 0; i < m; i++) { n     int b; n     scanf( %d , &b); n     idb[b].push_back(i); n   } n   int ans = 0; n   memset(dp, 127, sizeof dp); n   dp[0] = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 300; j >= 1; j--) { n       int pos2array = dp[j - 1]; n       int nextPos = lower_bound(idb[a[i]].begin(), idb[a[i]].end(), pos2array) - n                     idb[a[i]].begin(); n       if (nextPos == idb[a[i]].size()) continue; n       int abspos2ar = idb[a[i]][nextPos]; n       dp[j] = min(dp[j], abspos2ar + 1); n       if (i + 1 + dp[j] + j * e <= s) ans = max(ans, j); n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 4e5; n int T, n, m, k, f[N + 5], ans[N + 5]; n struct People { n   int a, r, d, u, id; n } p[N + 5]; n struct Info { n   int opt, l, r; n   Info() {} n   Info(int opt, int l, int r) : opt(opt), l(l), r(r) {} n }; n template <int MAX> n struct BIT { n   static const int N = MAX; n   int b[N + 5]; n   void clear() { fill(b + 1, b + N + 1, 0); } n   void modify(int x, int v) { n     for (; x <= N; x += x & -x) b[x] += v; n   } n   int query(int x) { n     int ans = 0; n     for (; x > 0; x ^= x & -x) ans += b[x]; n     return ans; n   } n   int query(int l, int r) { return query(r) - query(l - 1); } n }; n template <int MAX> n struct SegmentTree { n   static const int N = MAX << 2; n   int val[N + 5]; n   void clear() { fill(val + 1, val + N + 1, -1); } n   void modify(int p, int l, int r, int x, int v) { n     if (l == r) { n       val[p] = max(val[p], v); n       return; n     } n     int mid = (l + r) >> 1; n     if (x <= mid) { n       modify((p << 1), l, mid, x, v); n     } else { n       modify((p << 1 | 1), mid + 1, r, x, v); n     } n     val[p] = max(val[(p << 1)], val[(p << 1 | 1)]); n   } n   int query(int p, int l, int r, int x, int y) { n     if (x == l && r == y) return val[p]; n     int mid = (l + r) >> 1; n     if (y <= mid) { n       return query((p << 1), l, mid, x, y); n     } else if (x > mid) { n       return query((p << 1 | 1), mid + 1, r, x, y); n     } else { n       return max(query((p << 1), l, mid, x, mid), n                  query((p << 1 | 1), mid + 1, r, mid + 1, y)); n     } n   } n }; n BIT<N> bit; n SegmentTree<N> seg; n vector<Info> que[N + 5]; n void disc() { n   vector<int> u, v; n   for (int i = 1; i <= n; i++) { n     u.push_back(p[i].r); n     v.push_back(p[i].a); n     v.push_back(p[i].d); n     v.push_back(p[i].u); n   } n   sort(u.begin(), u.end()); n   sort(v.begin(), v.end()); n   u.erase(unique(u.begin(), u.end()), u.end()); n   v.erase(unique(v.begin(), v.end()), v.end()); n   for (int i = 1; i <= n; i++) { n     p[i].r = lower_bound(u.begin(), u.end(), p[i].r) - u.begin() + 1; n     p[i].a = lower_bound(v.begin(), v.end(), p[i].a) - v.begin() + 1; n     p[i].d = lower_bound(v.begin(), v.end(), p[i].d) - v.begin() + 1; n     p[i].u = lower_bound(v.begin(), v.end(), p[i].u) - v.begin() + 1; n   } n } n void calc() { n   sort(p + 1, p + n + 1, n        [](const People &x, const People &y) { return x.r < y.r; }); n   bit.clear(); n   for (int i = 1; i <= n;) { n     int j = i - 1; n     for (; j < n && p[j + 1].r == p[i].r; j++, bit.modify(p[j].a, 1)) n       ; n     for (int k = i; k <= j; k++) { n       f[p[k].id] = bit.query(p[k].d, p[k].u); n     } n     i = j + 1; n   } n   sort(p + 1, p + n + 1, n        [](const People &x, const People &y) { return x.id < y.id; }); n } n void solve() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %d , &p[i].r); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &p[i].a); n     p[i].d = p[i].a - k; n     p[i].u = p[i].a + k; n     p[i].id = i; n   } n   disc(); n   calc(); n   for (int i = 1; i <= n; i++) { n     que[p[i].r].push_back(Info(0, p[i].a, f[i])); n   } n   scanf( %d , &m); n   for (int u, v, i = 1; i <= m; i++) { n     scanf( %d%d , &u, &v); n     int l = max(p[u].d, p[v].d); n     int r = min(p[u].u, p[v].u); n     if (l > r) { n       ans[i] = -1; n     } else { n       que[max(p[u].r, p[v].r)].push_back(Info(i, l, r)); n     } n   } n   seg.clear(); n   for (int i = n; i >= 1; i--) { n     for (const auto &t : que[i]) { n       if (t.opt == 0) { n         seg.modify(1, 1, 3 * n, t.l, t.r); n       } else { n         ans[t.opt] = seg.query(1, 1, 3 * n, t.l, t.r); n       } n     } n     que[i].clear(); n   } n   for (int i = 1; i <= m; i++) printf( %d n , ans[i]); n } n int main() { n   solve(); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int n, K, m; n set<pair<int, int> > Set; n set<int> SS; n int O[524288]; n struct Tree { n   int K[524288 + 524288], M[524288 + 524288]; n   void UDT(int nd) { M[nd] = max(M[nd * 2], M[nd * 2 + 1]); } n   void init(int nd, int b, int e) { n     K[nd] = 0; n     if (b == e) { n       M[nd] = b; n       return; n     } n     int m = (b + e) >> 1; n     init(nd * 2, b, m); n     init(nd * 2 + 1, m + 1, e); n     UDT(nd); n   } n   void Add2(int nd, int x) { n     M[nd] += x; n     K[nd] += x; n   } n   void Spread(int nd) { n     Add2(nd * 2, K[nd]); n     Add2(nd * 2 + 1, K[nd]); n     K[nd] = 0; n   } n   void Add(int nd, int b, int e, int s, int l, int x) { n     if (s > l) return; n     if (s <= b && e <= l) { n       Add2(nd, x); n       return; n     } n     Spread(nd); n     int m = (b + e) >> 1; n     if (s <= m) Add(nd * 2, b, m, s, l, x); n     if (l > m) Add(nd * 2 + 1, m + 1, e, s, l, x); n     UDT(nd); n   } n   int Max(int nd, int b, int e, int s, int l) { n     if (s > l) return -99999999; n     if (s <= b && e <= l) return M[nd]; n     Spread(nd); n     int m = (b + e) >> 1, r = -99999999; n     if (s <= m) r = max(r, Max(nd * 2, b, m, s, l)); n     if (l > m) r = max(r, Max(nd * 2 + 1, m + 1, e, s, l)); n     return r; n   } n } T; n void Solve() { n   int i; n   for (i = 1; i < 524288; i++) O[i] = 1; n   T.init(1, 0, 524288 - 1); n   scanf( %d%d%d , &n, &K, &m); n   for (i = 1; i <= m; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     int t = abs(x - K) + y; n     if (Set.find(pair<int, int>(x, y)) != Set.end()) { n       Set.erase(pair<int, int>(x, y)); n       O[t]++; n       if (O[t] == 1) SS.erase(t); n       T.Add(1, 0, 524288 - 1, t, 524288 - 1, 1); n     } else { n       Set.insert(pair<int, int>(x, y)); n       O[t]--; n       if (O[t] == 0) SS.insert(t); n       T.Add(1, 0, 524288 - 1, t, 524288 - 1, -1); n     } n     if (SS.empty()) { n       puts( 0 ); n       continue; n     } n     t = *SS.rbegin(); n     int t1 = T.Max(1, 0, 524288 - 1, 0, t); n     int t2 = T.Max(1, 0, 524288 - 1, t, t); n     printf( %d n , max(t + (t1 - t2) - n, 0)); n   } n } n int main() { n   int TC = 1; n   while (TC--) { n     Solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n int a[maxn], b[maxn]; n bool v[maxn]; n int main() { n   int n; n   cin >> n; n   a[0] = -1; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     v[a[i]] = 1; n     if (a[i] > a[i - 1]) n       b[i] = a[i - 1]; n     else n       b[i] = -1; n   } n   int c = 0; n   for (int i = 1; i <= n; ++i) { n     if (b[i] == -1) { n       while (v[c]) c++; n       b[i] = c++; n     } n   } n   for (int i = 1; i <= n; ++i) cout << b[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int isTandom(string s, int n) { n   if (n > s.size() / 2) return 0; n   for (int i = 0; i < n; i++) n     if (s[i + n] !=     && s[i] != s[i + n]) return 0; n   return 1; n } n int main() { n   string s; n   int k; n   cin >> s >> k; n   int len = s.size(); n   for (int i = 0; i < k; i++) s +=    ; n   for (int i = s.size() / 2; i >= 1; i--) n     for (int j = 0; j + i < s.size(); j++) n       if (isTandom((s.substr(j, 2 * i)), i)) { n         cout << 2 * i << endl; n         return 0; n       } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, x, y; n   cin >> n; n   long long a[n], b[n - 1], c[n - 2]; n   for (i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   for (i = 0; i < n - 1; i++) cin >> b[i]; n   sort(b, b + (n - 1)); n   for (i = 0; i < n - 2; i++) cin >> c[i]; n   sort(c, c + (n - 2)); n   for (i = 0; i < n; i++) { n     if (a[i] != b[i]) { n       x = a[i]; n       break; n     } n   } n   for (i = 0; i < n - 1; i++) { n     if (b[i] != c[i]) { n       y = b[i]; n       break; n     } n   } n   cout << x << endl; n   cout << y << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, t, x, c, d, ch = 0, caser = 0, lol = 0, sum = 0, rating = -1, n                      upper = 1e9, lower = -1e9; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> c >> d; n     if (i == 0) { n       if (d == 1) n         lower = 1900; n       else n         upper = 1899; n     } else { n       if (d == 2) { n         upper = min(upper, sum + 1899); n       } else { n         lower = max(lower, sum + 1900); n       } n     } n     sum -= c; n   } n   if (upper == 1e9) n     cout <<  Infinity n ; n   else if (lower > upper) n     cout <<  Impossible n ; n   else n     cout << upper - sum << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long f[6][10010], b = 1; n int main() { n   for (int i = 1; i <= 5; ++i) n     for (int j = 1; j <= (i == 5 ? 1 : 10000); ++j) { n       long long now = f[i - 1][j]; n       for (int k = 1; k <= j; ++k) n         now += f[i - 1][min(now + j + 1, 10000ll)] + 1; n       f[i][j] = now; n     } n   for (int i = 5, d; i >= 1; --i) { n     long long now = 0; n     printf( %lld  , min(b, 10000ll)); n     for (int j = 1; j <= min(b, 10000ll); ++j) { n       now += f[i - 1][min(b + now, 10000ll)]; n       printf( %lld  , b + now); n       ++now; n     } n     printf(  n ); n     fflush(stdout); n     scanf( %d , &d); n     if (d == -1) n       break; n     else { n       now = 0; n       for (int j = 1; j <= d; ++j) now += f[i - 1][min(b + now, 10000ll)] + 1; n       b += now; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool kjg[100002]; n int isi[100002]; n long long dp[100002]; n vector<int> adlis[100002], radlis[100002]; n int rut, nvert, u, v; n void ruted(int x) { n   kjg[x] = 1; n   for (int i = 0; i < adlis[x].size(); i++) { n     if (!kjg[adlis[x][i]]) { n       radlis[x].push_back(adlis[x][i]); n       ruted(adlis[x][i]); n     } n   } n } n long long rek(int x) { n   if (radlis[x].size() == 0) { n     return 0; n   } else if (dp[x] != -1) { n     return dp[x]; n   } else { n     dp[x] = 0; n     if (x != rut) { n       isi[x]--; n     } n     int jum = 0; n     vector<long long> cal; n     cal.clear(); n     for (int i = 0; i < radlis[x].size(); i++) { n       if (isi[radlis[x][i]] <= 1) continue; n       if (rek(radlis[x][i]) > 0) { n         cal.push_back(rek(radlis[x][i])); n       } n     } n     for (int i = 0; i < radlis[x].size(); i++) { n       jum += isi[radlis[x][i]]; n     } n     sort(cal.begin(), cal.end()); n     if (cal.size() > 0) { n       for (int i = cal.size() - 1; i >= 0; i--) { n         dp[x] += (long long)cal[i]; n         dp[x] += 2LL; n         isi[x]--; n         if (isi[x] == 0) break; n       } n     } n     if (isi[x] > 0) { n       if (isi[x] < jum) { n         dp[x] += 2LL * isi[x]; n         isi[x] = 0; n       } else { n         dp[x] += 2LL * jum; n         isi[x] -= jum; n       } n     } n     return dp[x]; n   } n } n int main() { n   scanf( %d , &nvert); n   for (int i = 0; i < nvert; i++) { n     scanf( %d , &isi[i]); n   } n   for (int i = 0; i < nvert - 1; i++) { n     scanf( %d%d , &u, &v); n     u--; n     v--; n     adlis[u].push_back(v); n     adlis[v].push_back(u); n   } n   scanf( %d , &rut); n   rut--; n   memset(kjg, 0, sizeof kjg); n   ruted(rut); n   memset(dp, -1, sizeof dp); n   printf( %I64d n , rek(rut)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int main() { n   cin >> n; n   if ((n % 2) == 0) n     cout <<  home ; n   else n     cout <<  contest ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e6 + 7, M = 1e9 + 7; n vector<int> primes; n bool isp[N]; n void sieve() { n   fill(isp, isp + N, 1); n   isp[0] = isp[1] = 0; n   for (int i = 2; i * i < N; i++) n     if (isp[i]) n       for (int j = i * i; j < N; j += i) isp[j] = 0; n   for (int i = 2; i < N; i++) n     if (isp[i]) primes.push_back(i); n } n vector<pair<int, int> > factorize(int x) { n   vector<pair<int, int> > ans; n   for (int i : primes) { n     if (i * i > x) break; n     int cnt = 0; n     while (x % i == 0) cnt++, x /= i; n     if (cnt) ans.push_back(make_pair(i, cnt)); n   } n   if (x > 1) ans.push_back(make_pair(x, 1)); n   return ans; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   sieve(); n   int n; n   cin >> n; n   long long ans = 1; n   map<int, int> fac; n   map<int, int> cnt; n   vector<vector<pair<int, int> > > factors; n   int pp[n]; n   for (int i = 0; i < n; i++) cin >> pp[i]; n   sort(pp, pp + n); n   reverse(pp, pp + n); n   for (int i = 1; i <= n; i++) { n     int p = pp[i - 1]; n     if (fac.count(p) == 0) { n       ans = (ans * p) % M; n       fac[p] = 1; n       cnt[p] = 1; n       vector<pair<int, int> > v; n       v.push_back(make_pair(p, 1)); n       factors.push_back(v); n     } else { n       vector<pair<int, int> > pf = factorize(p - 1); n       factors.push_back(pf); n       for (auto pr : pf) { n         int p = pr.first; n         int e = pr.second; n         int dif = e - fac[p]; n         if (dif < 0) continue; n         if (dif == 0) { n           cnt[p]++; n           continue; n         } n         fac[p] += dif; n         cnt[p] = 1; n         for (int i = 0; i < dif; i++) ans = (ans * p) % M; n       } n     } n   } n   for (auto pf : factors) { n     bool found = true; n     for (auto pr : pf) { n       int p = pr.first; n       int e = pr.second; n       int mx = fac[p]; n       assert(e <= mx); n       if (e == mx && cnt[p] == 1) { n         found = false; n         break; n       } n     } n     if (found) { n       ans++; n       break; n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v[26]; n int A[26], m; n void solve() { n   string s; n   cin >> s; n   for (int i = 0; i < s.length(); i++) v[s[i] -  a ].push_back(i); n   for (int i = 0; i < 26; i++) { n     if (s.find(i +  a ) != string::npos) { n       m = v[i][0] + 1; n       for (int j = 1; j < (int)v[i].size(); j++) n         m = max(m, v[i][j] - v[i][j - 1]); n       m = max(m, (int)s.length() - v[i][(int)v[i].size() - 1]); n       A[i] = m; n     } n   } n   m = INT_MAX; n   for (int i = 0; i < 26; i++) { n     if (A[i] != 0) m = min(m, A[i]); n   } n   cout << m <<   n ; n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t; n   t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5010, mod = 1LL * 1000 * 1000 * 1000 + 7; n long long dp[N][N], inv_fact[N], fact[N], n, k; n long long Pow(long long a, long long b) { n   return b ? (b & 1 ? a : 1) % mod * Pow(a * a % mod, b >> 1) % mod : 1; n } n int C(int r, int n) { n   if (r > n) return 0; n   int num = 1; n   for (int i = n; i >= n - r + 1; i--) num = 1LL * num * i % mod; n   num = 1LL * num * inv_fact[r] % mod; n   return num; n } n int main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   fact[0] = 1; n   for (int i = 1; i < N; i++) fact[i] = 1LL * fact[i - 1] * i % mod; n   inv_fact[N - 1] = Pow(fact[N - 1], mod - 2); n   for (int i = N - 2; i >= 0; i--) n     inv_fact[i] = 1LL * inv_fact[i + 1] * (i + 1) % mod; n   for (int i = 1; i < N; i++) dp[1][i] = 1; n   for (int i = 2; i < N; i++) n     for (int j = i; j < N; j++) n       dp[i][j] = 1LL * (dp[i - 1][j - 1] + dp[i][j - 1]) % mod * i % mod; n   cin >> n >> k; n   long long ans = 0; n   for (int r = 1; r <= min(k, n); r++) { n     long long t = Pow(2, n - r); n     t = 1LL * t * dp[r][k] % mod; n     t = 1LL * t * C(r, n) % mod; n     ans = (1LL * ans + t) % mod; n   } n   cout << ans <<   n ; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n priority_queue<pair<long long int, int> > pq; n vector<pair<int, int> > vp; n map<long long int, int> mp, m; n const int N = 1e5 + 6; n long long int ans[N]; n vector<int> v, v1; n set<long long int> s, s1; n int visit[N]; n struct domingo { n   int val, left, right; n } o[N]; n bool used[102]; n int main() { n   int a, b, c, ct = 1; n   cin >> a >> b >> c; n   a = a % b; n   a *= 10; n   for (int i = 0; i < 1e5 + 5; i++) { n     int x = a / b; n     a %= b; n     if (x == c) return cout << ct, 0; n     a *= 10; n     ct++; n   } n   cout << -1; n } n


#include <bits/stdc++.h> n using namespace std; n const long long M = 1e9 + 7; n const long long N = 1e5 + 10; n const long long INF = 1e9 + 7; n vector<long long> fact(N), ifact(N); n long long gcd(long long x, long long y) { n   if (y % x == 0) return x; n   return gcd(y % x, x); n } n long long inv(long long x) { n   long long res = 1; n   long long b = M - 2; n   while (b) { n     if (b & 1) res = (res * x) % M; n     x = (x * x) % M; n     b >>= 1; n   } n   return res; n } n bool prime[1000006]; n void SieveOfEratosthenes(long long n) { n   for (long long p = 2; p * p <= n; p++) { n     if (prime[p] == true) { n       for (long long i = p * p; i <= n; i += p) prime[i] = false; n     } n   } n } n void init() { n   fact[0] = 1; n   for (long long i = 1; i < N; i++) fact[i] = (fact[i - 1] * i) % M; n   ifact[(long long)2e5] = inv(fact[(long long)2e5]); n   for (long long i = (long long)2e5 - 1; i >= 0; i--) n     ifact[i] = (ifact[i + 1] * (i + 1)) % M; n } n long long ncr(long long n, long long r) { n   if (r > n) return 0; n   long long res = fact[n]; n   res = (res * ifact[r]) % M; n   res = (res * ifact[n - r]) % M; n   return res; n } n long long power(long long x, long long y, long long p) { n   long long res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long lowbit(long long x) { n   for (long long i = 0;; i++) { n     if (x & (1 << i)) return 1 << i; n   } n } n string decimal_to_binary(long long n) { n   long long t = 0; n   long long tt = n; n   while (tt > 0) { n     t++; n     tt /= 2; n   } n   bitset<32> s = bitset<32>(n); n   string str =   ; n   for (long long i = 0; i < s.size(); i++) { n     str += s[i] +  0 ; n   } n   reverse(str.begin(), str.end()); n   return str; n } n bool checkPrime(long long x) { n   if (x == 1) { n     return false; n   } n   if (x <= 3) { n     return true; n   } n   long long t = 2; n   if (x % 2 == 0) { n     return false; n   } n   t = 3; n   for (t; t <= sqrt(x); t += 2) { n     if (x % t == 0) { n       return false; n     } n   } n   return true; n } n vector<long long> primeDivisor(long long x) { n   if (x <= 3) { n     vector<long long> r = {x}; n     return r; n   } n   long long n = floor(sqrt(x)); n   vector<long long> res; n   for (long long i = 2; i <= n; i++) { n     if (x % i == 0) { n       res.push_back(i); n     } n     while (x % i == 0) { n       x = x / i; n     } n     if (x < 2) { n       break; n     } n   } n   if (x > 2) { n     res.push_back(x); n   } n   return res; n } n struct comp { n   bool operator()(const pair<long long, long long> &x, n                   const pair<long long, long long> &y) { n     return x.first < y.first; n   } n }; n void solve() { n   int a, b, c; n   cin >> a >> b >> c; n   int ans = 0; n   if (a) { n     a--; n     ans++; n   } n   if (b) { n     b--; n     ans++; n   } n   if (c) { n     c--; n     ans++; n   } n   if (c == 1) { n     if (a && b) { n       a--; n       b--; n       ans++; n     } n     if (a && c) { n       a--; n       c--; n       ans++; n     } n     if (b && c) { n       b--; n       c--; n       ans++; n     } n   } else { n     if (a && c) { n       a--; n       c--; n       ans++; n     } n     if (b && c) { n       b--; n       c--; n       ans++; n     } n     if (a && b) { n       a--; n       b--; n       ans++; n     } n   } n   if (a && b && c) { n     a--; n     b--; n     c--; n     ans++; n   } n   cout << ans << endl; n   return; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   long long t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using vint = vector<long long>; n using pint = pair<long long, long long>; n using vpint = vector<pint>; n template <typename A, typename B> n inline void chmin(A& a, B b) { n   if (a > b) a = b; n } n template <typename A, typename B> n inline void chmax(A& a, B b) { n   if (a < b) a = b; n } n template <class A, class B> n ostream& operator<<(ostream& ost, const pair<A, B>& p) { n   ost <<  {  << p.first <<  ,  << p.second <<  } ; n   return ost; n } n template <class T> n ostream& operator<<(ostream& ost, const vector<T>& v) { n   ost <<  { ; n   for (long long i = 0; i < v.size(); i++) { n     if (i) ost <<  , ; n     ost << v[i]; n   } n   ost <<  } ; n   return ost; n } n inline long long topbit(unsigned long long x) { n   return x ? 63 - __builtin_clzll(x) : -1; n } n inline long long popcount(unsigned long long x) { n   return __builtin_popcountll(x); n } n inline long long parity(unsigned long long x) { return __builtin_parity(x); } n template <uint32_t mod> n struct ModInt { n   uint32_t a; n   ModInt& s(uint32_t vv) { n     a = vv < mod ? vv : vv - mod; n     return *this; n   } n   ModInt(int64_t x = 0) { s(x % mod + mod); } n   ModInt& operator+=(const ModInt& x) { return s(a + x.a); } n   ModInt& operator-=(const ModInt& x) { return s(a + mod - x.a); } n   ModInt& operator*=(const ModInt& x) { n     a = uint64_t(a) * x.a % mod; n     return *this; n   } n   ModInt& operator/=(const ModInt& x) { n     *this *= x.inv(); n     return *this; n   } n   ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; } n   ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; } n   ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; } n   ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; } n   bool operator==(const ModInt& x) const { return a == x.a; } n   bool operator!=(const ModInt& x) const { return a != x.a; } n   bool operator<(const ModInt& x) const { return a < x.a; } n   ModInt operator-() const { return ModInt() - *this; } n   ModInt pow(int64_t n) const { n     ModInt res(1), x(*this); n     while (n) { n       if (n & 1) res *= x; n       x *= x; n       n >>= 1; n     } n     return res; n   } n   ModInt inv() const { return pow(mod - 2); } n }; n template <uint32_t mod> n istream& operator>>(istream& in, ModInt<mod>& a) { n   return (in >> a.a); n } n template <uint32_t mod> n ostream& operator<<(ostream& out, const ModInt<mod>& a) { n   return (out << a.a); n } n using mint = ModInt<10007>; n using mat = vector<vector<mint>>; n string S; n long long N; n mint dp[210][210][210]; n mat matmul(const mat& A, const mat& B) { n   mat C(A.size(), vector<mint>(A.size())); n   for (long long i = 0; i < A.size(); i++) { n     for (long long j = i; j < A.size(); j++) { n       for (long long k = i; k <= j; k++) { n         C[i][j] += A[i][k] * B[k][j]; n       } n     } n   } n   return C; n } n mat matpow(mat A, long long k) { n   mat ret(A.size(), vector<mint>(A.size())); n   for (long long i = 0; i < (A.size()); i++) ret[i][i] = 1; n   while (k) { n     if (k & 1) ret = matmul(ret, A); n     A = matmul(A, A); n     k >>= 1; n   } n   return ret; n } n signed main() { n   cin >> S >> N; n   N += S.size(); n   for (long long i = 0; i < (S.size()); i++) dp[0][i][i] = 1; n   for (long long i = 0; i < (S.size()); i++) dp[0][i][i + 1] = 1; n   for (long long i = S.size() - 1; i >= 0; i--) { n     for (long long j = i + 2; j <= S.size(); j++) { n       for (long long k = 0; k < S.size(); k++) { n         if (S[i] == S[j - 1]) { n           dp[k][i][j] += dp[k][i + 1][j - 1]; n         } else { n           if (k == 0) continue; n           dp[k][i][j] += dp[k - 1][i + 1][j]; n           dp[k][i][j] += dp[k - 1][i][j - 1]; n         } n       } n     } n   } n   const long long X = S.size(); n   const long long Y = (S.size() + 1) / 2; n   const long long Z = Y; n   vector<vector<mint>> A(X + Y + Z, vector<mint>(X + Y + Z)); n   for (long long i = 0; i < (X); i++) { n     A[i][i] = 24; n     A[i][i + 1] = 1; n   } n   for (long long i = 0; i < (Y); i++) { n     A[X + i][X + i] = 25; n     if (i + 1 < Y) A[X + i][X + i + 1] = 1; n     A[X + i][X + Y + i] = 1; n   } n   for (long long i = 0; i < (Z); i++) { n     A[X + Y + i][X + Y + i] = 26; n   } n   mat C = matpow(A, (N + 1) / 2 - 1); n   A = matmul(C, A); n   mint ans = 0; n   for (long long k = 0; k < S.size(); k++) { n     long long l = (S.size() - k + 1) / 2; n     ans += dp[k][0][S.size()] * A[X - k][X + Y + l - 1]; n     if ((S.size() - k) % 2 == 0 && N % 2) { n       ans -= dp[k][0][S.size()] * C[X - k][X + l - 1]; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using uint = unsigned int; n using ull = unsigned long long; n template <class T> n bool set_max(T &a, const T &b) { n   if (a < b) { n     a = b; n     return true; n   } n   return false; n } n template <class T> n bool set_min(T &a, const T &b) { n   if (a > b) { n     a = b; n     return true; n   } n   return false; n } n template <typename A, typename B> n string to_string(pair<A, B> p); n template <typename A, typename B, typename C> n string to_string(tuple<A, B, C> p); n template <typename A, typename B, typename C, typename D> n string to_string(tuple<A, B, C, D> p); n string to_string(const string &s) { return     + s +    ; } n string to_string(const char *s) { return to_string((string)s); } n string to_string(bool b) { return (b ?  true  :  false ); } n string to_string(vector<bool> v) { n   bool first = true; n   string res =  { ; n   for (int i = 0; i < static_cast<int>(v.size()); i++) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     res += to_string(v[i]); n   } n   res +=  } ; n   return res; n } n template <size_t N> n string to_string(bitset<N> v) { n   string res =   ; n   for (size_t i = 0; i < N; i++) { n     res += static_cast<char>( 0  + v[i]); n   } n   return res; n } n template <typename A> n string to_string(A v) { n   bool first = true; n   string res =  { ; n   for (const auto &x : v) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     res += to_string(x); n   } n   res +=  } ; n   return res; n } n template <typename A, typename B> n string to_string(pair<A, B> p) { n   return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; n } n template <typename A, typename B, typename C> n string to_string(tuple<A, B, C> p) { n   return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + n          to_string(get<2>(p)) +  ) ; n } n template <typename A, typename B, typename C, typename D> n string to_string(tuple<A, B, C, D> p) { n   return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + n          to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ; n } n void debug_out() { cerr << endl; } n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { n   cerr <<     << to_string(H); n   debug_out(T...); n } n const int N = 3e5 + 10; n const int MOD = 1e9 + 7; n const double eps = 1e-6; n const ll INF = 1e18; n const int inf = 1e9; n int a[N]; n void solve() { n   int n; n   cin >> n; n   int sum = 0; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     sum += a[i]; n   } n   if (sum % n) { n     cout <<  -1 n ; n     return; n   } n   int avg = sum / n; n   vector<tuple<int, int, int>> ops; n   auto move = [&](int i, int j, int x) { n     assert(a[i] >= x * i); n     ops.emplace_back(i, j, x); n     a[j] += x * i; n     a[i] -= x * i; n   }; n   for (int i = 2; i <= n; i++) { n     int x = (i - a[i] % i) % i; n     if (x > 0) { n       move(1, i, x); n     } n     assert(a[i] % i == 0); n     move(i, 1, a[i] / i); n   } n   for (int i = 2; i <= n; i++) { n     move(1, i, avg); n   } n   cout << ops.size() <<   n ; n   for (auto x : ops) { n     cout << get<0>(x) <<     << get<1>(x) <<     << get<2>(x) <<   n ; n   } n } n int main() { n   ios::sync_with_stdio(false), cin.tie(nullptr); n   int t = 1; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1e9 + 7; n const int MN = 1e6 + 6; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cout << fixed << setprecision(10); n   long long n; n   cin >> n; n   long long p_x = 0, p_y = 0; n   long long res = 1; n   for (long long i = 0; i < n; ++i) { n     long long n_x, n_y; n     cin >> n_x >> n_y; n     if (p_x == n_x && p_y == n_y) continue; n     long long a = max(p_x, p_y); n     long long b = min(n_x, n_y); n     if (p_x == p_y) { n       a++; n     } n     if (a <= b) res += b - a + 1; n     p_x = n_x; n     p_y = n_y; n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, a, i, j, mid, cnt = 0; n   cin >> n; n   for (i = 0; i < n; i++) { n     for (j = 0; j < n; j++) { n       cin >> a; n       if (i == j) cnt = cnt + a; n       if (i + j == n - 1) cnt = cnt + a; n       if (i == n / 2) cnt = cnt + a; n       if (j == n / 2) cnt = cnt + a; n       if (i == n / 2 && j == n / 2) mid = a; n     } n   } n   cout << cnt - (3 * mid) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   int i = n, j = n; n   vector<int> a(2 * n + 1), b(2 * n + 1); n   long long s = 0, x = 1, y = a[n] = b[n] = 1; n   while (n--) { n     int v; n     cin >> v; n     if (v < m) n       x += a[++i]++, y += b[++j]++; n     else if (v == m) n       x += a[++i]++, y -= b[j], ++b[--j]; n     else n       x -= a[i], ++a[--i], y -= b[j], ++b[--j]; n     s += x - y; n   } n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T abs(T x) { n   return x > 0 ? x : -x; n } n int n; n int m; n int mask[500][500][17]; n int x[500], y[500], X[500], Y[500]; n double xx[500], yy[500], XX[500], YY[500]; n double vect(double x1, double y8687969, double x2, double y2) { n   return x1 * y2 - x2 * y8687969; n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) scanf( %d%d , &x[i], &y[i]); n   for (int i = 0; i < m; i++) scanf( %d%d , &X[i], &Y[i]); n   double *cx, *cy, *CX, *CY; n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j < n; j++) { n       xx[j] = x[j] - x[i], yy[j] = y[j] - y[i]; n     } n     for (int j = 0; j < m; j++) { n       XX[j] = X[j] - x[i]; n       YY[j] = Y[j] - y[i]; n     } n     cx = xx + i; n     cy = yy + i; n     for (int j = i + 1; j < n; j++) { n       cx++; n       cy++; n       CX = XX; n       CY = YY; n       int *ap = mask[i][j], *ar = mask[j][i]; n       int b = 0; n       for (int k = 0; k < m; k++, CX++, CY++) { n         if ((*cx) * (*CY) - (*cy) * (*CX) > 0) n           (*ap) |= (1 << b); n         else n           (*ar) |= (1 << b); n         b++; n         if (b == 30) { n           ap++; n           ar++; n           b = 0; n         } n       } n     } n   } n   int ans = 0; n   double *jx, *jy, *kx, *ky; n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j < n; j++) { n       xx[j] = x[j] - x[i]; n       yy[j] = y[j] - y[i]; n     } n     jx = xx + i; n     jy = yy + i; n     for (int j = i + 1; j < n; j++) { n       jx++; n       jy++; n       kx = jx; n       ky = jy; n       for (int k = j + 1; k < n; k++) { n         kx++; n         ky++; n         if ((*jx) * (*ky) - (*jy) * (*kx) > 0) { n           ans++; n           for (int l = 0; l < 17; l++) n             if (mask[i][j][l] & mask[j][k][l] & mask[k][i][l]) { n               ans--; n               break; n             } n         } else { n           ans++; n           for (int l = 0; l < 17; l++) n             if (mask[i][k][l] & mask[k][j][l] & mask[j][i][l]) { n               ans--; n               break; n             } n         } n       } n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, x; n   int A[200010] = {0}, L[200010] = {0}, R[200010] = {0}; n   scanf( %d%d%d , &n, &k, &x); n   for (int i = 1; i <= n; i++) { n     scanf( %d , A + i); n   } n   sort(A + 1, A + 1 + n); n   for (int i = 1; i <= n; i++) { n     L[i] = A[i] | L[i - 1]; n   } n   for (int i = n; i >= 1; i--) { n     R[i] = A[i] | R[i + 1]; n   } n   long long ret = 0, m = 1; n   for (int i = 1; i <= k; i++) { n     m *= x; n   } n   for (int i = 1; i <= n; i++) { n     long long ans = A[i] * m | L[i - 1] | R[i + 1]; n     if (ans > ret) { n       ret = ans; n     } n   } n   printf( %I64d n , ret); n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n string s; n int main() { n   cin >> n >> k >> s; n   int del = (n - k) / 2; n   stack<int> st; n   for (char ch : s) { n     if (ch ==  ( ) { n       if (del) { n         st.push(1); n         del--; n       } else { n         st.push(0); n         putchar( ( ); n       } n     } else { n       int v = st.top(); n       st.pop(); n       if (v == 0) putchar( ) ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 4; n int n, ans, ar[maxn], flag[maxn], dp[maxn]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> ar[i]; n   } n   for (int i = 0; i < maxn; i++) dp[i] = 1; n   for (int i = n - 1; i >= 0; i--) { n     int mx = 0; n     for (int j = 2 * ar[i]; j < maxn; j += ar[i]) { n       if (flag[j]) mx = max(dp[j], mx); n     } n     dp[ar[i]] = mx + 1; n     flag[ar[i]] = 1; n     ans = max(ans, mx + 1); n   } n   cout << ans; n } n