#include <bits/stdc++.h> n using namespace std; n inline void read(int &x) { n   x = 0; n   char c = getchar(); n   int f = 1; n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (isdigit(c)) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   x *= f; n } n const int N = 303000; n int n, m, head[N], to[N], nxt[N], val[N], edgenum = 1; n inline void add(int u, int v, int w) { n   to[++edgenum] = v; n   val[edgenum] = w; n   nxt[edgenum] = head[u]; n   head[u] = edgenum; n } n struct Gauss { n   int v[32]; n   inline void add(int x) { n     for (int i = 30; i >= 0; i--) n       if ((x >> i) & 1) n         if (!v[i]) { n           v[i] = x; n           break; n         } else n           x ^= v[i]; n   } n   inline int query(int x) { n     for (int i = 30; i >= 0; i--) x = (x ^ v[i]) < x ? x ^ v[i] : x; n     return x; n   } n } gauss; n int vis[N], tree[N], v[N]; n inline void dfs(int u, int Val) { n   vis[u] = 1; n   v[u] = Val; n   for (int i = head[u]; i != 0; i = nxt[i]) n     if (!vis[to[i]]) { n       tree[i >> 1] = 1; n       dfs(to[i], Val ^ val[i]); n     } else if (!tree[i >> 1]) { n       gauss.add(v[to[i]] ^ v[u] ^ val[i]); n     } n } n int main() { n   read(n); n   read(m); n   for (int i = 1; i <= m; i++) { n     int a, b, c; n     read(a); n     read(b); n     read(c); n     add(a, b, c); n     add(b, a, c); n   } n   dfs(1, 0); n   printf( %d , gauss.query(v[n])); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<long long, long long> > points; n vector<pair<long long, pair<long long, long long> > > areas; n map<long long, vector<long long> > pm; n int main() { n   int n, m, k; n   scanf( %i%i%i , &n, &m, &k); n   for (int i = 0; i < n; i++) { n     int x, y; n     scanf( %i%i , &x, &y); n     points.push_back(pair<long long, long long>(x, y)); n   } n   for (int i = 0; i < m; i++) { n     int c1, c2, r; n     scanf( %i%i%i , &r, &c1, &c2); n     areas.push_back(pair<long long, pair<long long, long long> >( n         r, pair<long long, long long>(c1, c2))); n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if ((points[i].first - areas[j].second.first) * n                   (points[i].first - areas[j].second.first) + n               (points[i].second - areas[j].second.second) * n                   (points[i].second - areas[j].second.second) < n           areas[j].first * areas[j].first) { n         pm[i].push_back(j); n       } n     } n     sort(pm[i].begin(), pm[i].end()); n   } n   for (int i = 0; i < k; i++) { n     int a, b; n     scanf( %i%i , &a, &b); n     a -= 1; n     b -= 1; n     vector<long long> tmp1 = pm[a]; n     vector<long long> tmp2 = pm[b]; n     int p = 0; n     int cnt = 0; n     for (int i = 0; i < tmp1.size(); i++) { n       while (p < tmp2.size() && tmp2[p] < tmp1[i]) { n         cnt++; n         p++; n       } n       if (p == tmp2.size() || tmp2[p] != tmp1[i]) { n         cnt++; n       } n       if (p != tmp2.size() && tmp2[p] == tmp1[i]) { n         p++; n       } n     } n     printf( %i n , cnt + (tmp2.size() - p)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int arr[5010], n; n int solve(int l, int r, int h) { n   int i, j, k; n   if (l > r) return 0; n   int ans = 0, val = 1000000007; n   for (i = l; i <= r; i++) val = min(val, arr[i]); n   int pos = l - 1; n   ans = val - h; n   for (i = l; i <= r; i++) { n     if (arr[i] == val) { n       ans += solve(pos + 1, i - 1, val); n       pos = i; n     } n   } n   ans += solve(pos + 1, r, val); n   return min(r - l + 1, ans); n } n int main(void) { n   int i, k; n   scanf( %d , &n); n   for (i = 1; i <= n; i++) scanf( %d , &arr[i]); n   k = solve(1, n, 0); n   printf( %d  , k); n   printf(  n ); n   ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, u, r; n vector<int> a, b, k, p; n long long s, current; n int lastChoice; n void input(); n void solve(); n void go(int k); n int main() { n   input(); n   solve(); n } n void input() { n   cin >> n >> u >> r; n   a.resize(n); n   b.resize(n); n   k.resize(n); n   p.resize(n); n   int val; n   for (int i = 0; i <= n - 1; ++i) { n     cin >> val; n     a[i] = val; n   } n   for (int i = 0; i <= n - 1; ++i) { n     cin >> val; n     b[i] = val; n   } n   for (int i = 0; i <= n - 1; ++i) { n     cin >> val; n     k[i] = val; n   } n   for (int i = 0; i <= n - 1; ++i) { n     cin >> val; n     p[i] = val - 1; n   } n } n void solve() { n   s = (long long)(-1e12); n   lastChoice = 1; n   go(1); n   cout << s; n } n void go(int x) { n   if ((x - 1) % 2 == u % 2) { n     long long sum = 0; n     for (int i = 0; i <= n - 1; ++i) sum += a[i] * k[i]; n     s = max(s, sum); n   } n   if (x >= u + 1) { n     return; n   } n   vector<int> _a(n); n   int _lastChoice = lastChoice; n   for (int i = 0; i <= n - 1; ++i) _a[i] = a[i]; n   lastChoice = 1; n   for (int i = 0; i <= n - 1; ++i) { n     a[i] = _a[p[i]] + r; n   } n   go(x + 1); n   for (int i = 0; i <= n - 1; ++i) a[i] = _a[i]; n   lastChoice = _lastChoice; n   if (lastChoice == 0) { n     return; n   } else { n     _lastChoice = lastChoice; n     for (int i = 0; i <= n - 1; ++i) _a[i] = a[i]; n     lastChoice = 0; n     for (int i = 0; i <= n - 1; ++i) { n       a[i] = (_a[i] ^ b[i]); n     } n     go(x + 1); n     lastChoice = _lastChoice; n     for (int i = 0; i <= n - 1; ++i) a[i] = _a[i]; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int ans[3][1010], dp[3][1010][55][55]; n int n, p, k, r, s, x; n int teto(int a, int b) { return (a + b - 1) / b; } n int main() { n   while (scanf( %d %d %d , &n, &p, &k) != EOF) { n     memset(ans, 0, sizeof(ans)); n     scanf( %d , &r); n     for (int i = 0; i < r; i++) { n       scanf( %d , &x); n       x--; n       ans[0][x] = 1; n     } n     scanf( %d , &s); n     for (int i = 0; i < s; i++) { n       scanf( %d , &x); n       x--; n       ans[1][x] = 1; n     } n     if (p >= 2 * teto(n, k)) { n       int cnt = 0; n       for (int i = 0; i < n; i++) { n         if (ans[0][i] == 1 || ans[1][i] == 1) { n           cnt++; n         } n       } n       printf( %d n , cnt); n       continue; n     } n     int A = min(n, k), B = min(n, k); n     for (int pos = n; pos >= 0; pos--) { n       int pos1 = pos % 2, pos2 = (pos + 1) % 2; n       for (int used = 0; used <= p; used++) { n         for (int a = 0; a <= A; a++) { n           for (int b = 0; b <= B; b++) { n             if (pos == n) { n               dp[pos1][used][a][b] = 0; n             } else { n               int max_ = n                   dp[pos2][used][max(a - 1, 0)][max(b - 1, 0)] + n                   max((a >= 1) * (ans[0][pos]), (b >= 1) * (ans[1][pos])); n               if (used + 1 <= p) { n                 max_ = n                     max(max_, dp[pos2][used + 1][k - 1][max(0, b - 1)] + n                                   max(ans[0][pos], (b >= 1) * (ans[1][pos]))); n                 max_ = n                     max(max_, dp[pos2][used + 1][max(a - 1, 0)][k - 1] + n                                   max((a >= 1) * (ans[0][pos]), ans[1][pos])); n               } n               if (used + 2 <= p) { n                 max_ = max(max_, dp[pos2][used + 2][k - 1][k - 1]); n               } n               dp[pos1][used][a][b] = max_; n             } n           } n         } n       } n     } n     printf( %d n , dp[0][0][0][0]); n   } n   return 0; n } n


#include <bits/stdc++.h> n const int N = 25, Mod = 1e6 + 3; n const int n = 11; n int y[N], k, inv[Mod + 2]; n int fm[] = {404910, 950915, 220896, 410947, 30845, 962989, n             30845,  410947, 220896, 950915, 404910}; n inline int po(int x, int y) { n   int r = 1; n   while (y) { n     if (y & 1) r = 1ll * r * x % Mod; n     x = 1ll * x * x % Mod, y >>= 1; n   } n   return r; n } n int judge(int k) { n   int ans = 0, base = 1; n   for (int i = 1; i <= n; ++i) n     if (k != i) base = 1ll * base * (k - i) % Mod; n   if (1 <= k && k <= 11) n     return (1ll * base * fm[k - 1] % Mod * y[k] % Mod + Mod) % Mod; n   base = (base + Mod) % Mod; n   for (int i = 1; i <= n; ++i) n     ans = (ans + 1ll * base * inv[(k - i + Mod) % Mod] % Mod * fm[i - 1] % Mod * n                      y[i] % Mod) % n           Mod; n   return ans; n } n int main() { n   for (int i = 1; i <= n; ++i) { n     printf( ? %d n , i); n     fflush(stdout); n     scanf( %d , &y[i]); n   } n   inv[0] = inv[1] = 1; n   for (int i = 2; i < Mod; ++i) n     inv[i] = 1ll * (Mod - Mod / i) * inv[Mod % i] % Mod; n   for (int k = 0; k < Mod; ++k) n     if (!judge(k)) { n       printf( ! %d n , k); n       fflush(stdout); n       return 0; n     } n   printf( ! -1 n ); n   fflush(stdout); n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:256000000 ) n #pragma warning(disable : 4996 4018) n using namespace std; n long long n, k, p; n int main() { n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   cin >> n >> k >> p; n   if ((n & 1) && k) { n     n--; n     k--; n   } n   while (p--) { n     long long nm; n     cin >> nm; n     if (nm > n) { n       cout <<  X ; n       continue; n     } n     if (!k) { n       cout <<  . ; n       continue; n     } n     if (nm & 1) { n       if (k > n / 2) { n         long long rest = k - n / 2; n         long long nd = n / 2; n         long long val = nd - (nm / 2.0) + 1; n         if (val <= rest) n           cout <<  X ; n         else n           cout <<  . ; n       } else n         cout <<  . ; n     } else { n       long long nd = n / 2; n       long long val = nd - (nm / 2) + 1; n       if (val <= k) n         cout <<  X ; n       else n         cout <<  . ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 3e5 + 5; n long long n, q, a[maxn], c[maxn]; n long long read() { n   long long res = 0, f = 1; n   char ch; n   do { n     ch = getchar(); n     if (ch ==  - ) f = -1; n   } while (!isdigit(ch)); n   do { n     res = res * 10 + ch -  0 ; n     ch = getchar(); n   } while (isdigit(ch)); n   return res * f; n } n long long check(long long x) { n   if (!x) return 0; n   return x > 0 ? 1 : -1; n } n struct SegmentTree { n   long long mxlen[maxn << 2], lmost[maxn << 2], ltype[maxn << 2], n       rmost[maxn << 2], rtype[maxn << 2], len[maxn << 2]; n   void pushup(long long rt, long long l, long long r) { n     long long ls = rt << 1, rs = rt << 1 | 1, mx = max(mxlen[ls], mxlen[rs]), n               mid = (l + r) >> 1; n     ltype[rt] = ltype[ls]; n     rtype[rt] = rtype[rs]; n     mx = max(mx, lmost[ls]); n     mx = max(mx, rmost[rs]); n     if (rtype[ls] && ltype[rs] && rtype[ls] >= ltype[rs]) { n       mx = max(mx, rmost[ls] + lmost[rs]); n       if (lmost[ls] == len[ls]) n         lmost[rt] = lmost[ls] + lmost[rs]; n       else n         lmost[rt] = lmost[ls]; n       if (rmost[rs] == len[rs]) n         rmost[rt] = rmost[ls] + rmost[rs]; n       else n         rmost[rt] = rmost[rs]; n     } else n       lmost[rt] = lmost[ls], rmost[rt] = rmost[rs]; n     mxlen[rt] = mx; n   } n   void build(long long rt, long long l, long long r) { n     len[rt] = r - l + 1; n     if (l == r) { n       ltype[rt] = rtype[rt] = lmost[rt] = rmost[rt] = 0; n       if (a[l]) mxlen[rt] = 1; n       if (a[l] > 0) { n         ltype[rt] = 1; n         lmost[rt] = 1; n         rtype[rt] = 1; n         rmost[rt] = 1; n       } else if (a[l] < 0) { n         ltype[rt] = -1; n         lmost[rt] = 1; n         rtype[rt] = -1; n         rmost[rt] = 1; n       } n       return; n     } n     long long mid = (l + r) >> 1; n     build(rt << 1, l, mid); n     build(rt << 1 | 1, mid + 1, r); n     pushup(rt, l, r); n   } n   void update(long long rt, long long l, long long r, long long x, n               long long val) { n     if (l == r) { n       a[l] += val; n       ltype[rt] = rtype[rt] = lmost[rt] = rmost[rt] = 0; n       if (a[l]) mxlen[rt] = 1; n       if (a[l] > 0) { n         ltype[rt] = 1; n         lmost[rt] = 1; n         rtype[rt] = 1; n         rmost[rt] = 1; n       } else if (a[l] < 0) { n         ltype[rt] = -1; n         lmost[rt] = 1; n         rtype[rt] = -1; n         rmost[rt] = 1; n       } n       return; n     } n     long long mid = (l + r) >> 1; n     if (x <= mid) n       update(rt << 1, l, mid, x, val); n     else n       update(rt << 1 | 1, mid + 1, r, x, val); n     pushup(rt, l, r); n   } n } T; n signed main() { n   n = read(); n   for (long long i = (1); i <= (n); ++i) c[i] = read(); n   if (n == 1) { n     q = read(); n     while (q--) { n       long long l = read(), r = read(), x = read(); n       puts( 1 ); n     } n     return 0; n   } n   for (long long i = (1); i <= (n - 1); ++i) a[i] = c[i + 1] - c[i]; n   T.build(1, 1, n - 1); n   q = read(); n   while (q--) { n     long long l = read(), r = read(), x = read(); n     if (l - 1 >= 1) T.update(1, 1, n - 1, l - 1, x); n     if (r + 1 <= n) T.update(1, 1, n - 1, r, -x); n     printf( %d n , T.mxlen[1] + 1); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000 * 100 * 2 + 152; n long long n, m, x, y, z, q, mark[maxn], k = 1, par1[maxn], sum[maxn], h[maxn]; n pair<long long, long long> par[17][maxn]; n vector<pair<long long, long long> > v[maxn]; n pair<long long, pair<long long, long long> > edg[maxn]; n void dfs(int x) { n   mark[x] = k; n   for (int i = 0; i < v[x].size(); i++) n     if (!mark[v[x][i].first]) { n       sum[k] += v[x][i].second; n       par[0][v[x][i].first] = make_pair(x, v[x][i].second); n       h[v[x][i].first] = h[x] + 1; n       dfs(v[x][i].first); n     } n } n int find_par(int x) { n   if (x == par1[x]) return x; n   return par1[x] = find_par(par1[x]); n } n long long LCA(int x, int y) { n   if (h[x] > h[y]) swap(x, y); n   long long fa = h[y] - h[x], jack = 0, MAX = 0; n   for (int i = 0; i < 17; i++) n     if ((1 << i) & fa) { n       MAX = max(MAX, par[i][y].second); n       y = par[i][y].first; n     } n   for (int i = 16; i >= 0; i--) n     if (par[i][x].first != par[i][y].first) { n       MAX = max(MAX, max(par[i][x].second, par[i][y].second)); n       x = par[i][x].first; n       y = par[i][y].first; n     } n   if (x != y) MAX = max(MAX, max(par[0][x].second, par[0][y].second)); n   return MAX; n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < m; i++) n     cin >> edg[i].second.first >> edg[i].second.second >> edg[i].first; n   for (int i = 1; i <= n; i++) par1[i] = i; n   sort(edg, edg + m); n   for (int i = 0; i < m; i++) { n     int x = find_par(edg[i].second.first), y = find_par(edg[i].second.second); n     if (x == y) continue; n     v[edg[i].second.first].push_back( n         make_pair(edg[i].second.second, edg[i].first)); n     v[edg[i].second.second].push_back( n         make_pair(edg[i].second.first, edg[i].first)); n     par1[x] = y; n   } n   for (int i = 1; i <= n; i++) n     if (!mark[i]) { n       dfs(i); n       k++; n     } n   for (int i = 1; i < 17; i++) n     for (int j = 1; j <= n; j++) n       par[i][j] = make_pair( n           par[i - 1][par[i - 1][j].first].first, n           max(par[i - 1][j].second, par[i - 1][par[i - 1][j].first].second)); n   cin >> q; n   while (q--) { n     cin >> x >> y; n     if (k > 3 || (k == 3 && mark[x] == mark[y])) { n       cout << -1 << endl; n       continue; n     } n     if (k == 3) { n       cout << sum[1] + sum[2] << endl; n       continue; n     } n     long long jack = LCA(x, y); n     cout << sum[1] - jack << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e4 + 5, inf = 0x3f3f3f3f; n int n, front, x, ans = -inf, nxt; n vector<int> interact(int _) { n   printf( ? %d n , _); n   fflush(stdout); n   int a, b; n   scanf( %d%d , &a, &b); n   return vector<int>({a, b}); n } n void give(int _) { n   printf( ! %d n , _); n   fflush(stdout); n } n int seed, seed2; n void srand(int x, int y) { n   seed = x; n   seed2 = y; n } n int frand() { return (seed *= 19260817) += ((seed2 += 114514) ^= 1919810); } n int rand() { n   int res = frand(); n   while (res <= 0) res += n; n   return res; n } n int main() { n   srand(998244353, 1000000007); n   scanf( %d%d%d , &n, &front, &x); n   nxt = front; n   for (int(i) = (1); (i) <= (min(n, 1000) - 1); (i)++) { n     int pos = rand() % n + 1; n     vector<int> res = interact(pos); n     if (res[0] <= x && res[0] > ans) nxt = res[1], ans = res[0]; n   } n   if (ans == x) return give(x), 0; n   for (int(i) = (1); (i) <= (1000); (i)++) { n     if (nxt == -1) break; n     vector<int> res = interact(nxt); n     if (res[0] >= x) return give(res[0]), 0; n     ans = res[0]; n     nxt = res[1]; n   } n   give(ans >= x ? ans : -1); n   return 0; n   int lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n   lll = 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool cmp(pair<int, int> p1, pair<int, int> p2) { return p2.second < p1.second; } n vector<pair<int, int> > k; n vector<pair<int, int> > c; n vector<pair<int, int> > ans; n int main() { n   int n, v; n   int t, p; n   cin >> n >> v; n   for (int i = 0; i < n; i++) { n     cin >> t >> p; n     if (t == 1) { n       k.push_back(make_pair(i + 1, p)); n     } else { n       c.push_back(make_pair(i + 1, p)); n     } n   } n   sort(k.begin(), k.end(), cmp); n   sort(c.begin(), c.end(), cmp); n   int cur = 0; n   while (v > 1 && cur < c.size()) { n     ans.push_back(c[cur]); n     v -= 2; n     cur++; n   } n   int last = ans.size() - 1; n   int nowk = 0; n   while (v > 0 && nowk < k.size()) { n     ans.push_back(k[nowk]); n     v -= 1; n     nowk++; n   } n   for (; nowk < k.size() - 1 && last >= 0; nowk += 2) { n     if (k[nowk].second + k[nowk + 1].second > ans[last].second) { n       ans.erase(ans.begin() + last); n       ans.push_back(k[nowk]); n       ans.push_back(k[nowk + 1]); n       last--; n     } n   } n   if (last >= 0 && nowk == k.size() - 1) { n     if (k[nowk].second > ans[last].second) { n       ans.erase(ans.begin() + last); n       ans.push_back(k[nowk]); n       last--; n     } n   } n   if (ans.size() > 0) { n     int tot = 0; n     for (int i = 0; i < ans.size(); i++) tot += ans[i].second; n     cout << tot << endl << ans[0].first << endl; n     for (int i = 1; i < ans.size(); i++) cout << ans[i].first <<    ; n     cout << endl; n   } else { n     cout <<  0  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 6e5 + 5; n const long long mod = 10000000000000007; n const long long nary = 9; n long long a; n int ans[100], n; n int main() { n   while (scanf( %d%I64d , &n, &a) != EOF) { n     n = 0; n     while (a > 0) { n       int d = (int)(a % 10); n       a /= (long long)10; n       if (d == 9) { n         d -= 2; n         ans[++n] = 3; n         ans[++n] = 3; n         ans[++n] = 2; n       } n       if (d == 8) { n         d--; n         ans[++n] = 2; n         ans[++n] = 2; n         ans[++n] = 2; n       } n       if (d == 6) { n         d--; n         ans[++n] = 3; n       } n       if (d == 4) { n         d--; n         ans[++n] = 2; n         ans[++n] = 2; n       } n       if (d > 1) ans[++n] = d; n     } n     sort(ans + 1, ans + n + 1); n     for (int i = n; i > 0; i--) printf( %d , ans[i]); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool square(long long g) { n   long long k = sqrt(g); n   return k * k == g; n } n int main() { n   int i, q, k; n   long long l, r, val; n   set<long long> s; n   for (i = 2; i <= 1000000; i++) { n     int op = 18.0 / log10(i); n     val = 1LL * i * i; n     for (k = 3; k <= op; k++) { n       val *= i; n       if (!square(val)) s.insert(val); n     } n   } n   vector<long long> v(s.begin(), s.end()); n   cin >> q; n   for (i = 0; i < q; i++) { n     cin >> l >> r; n     long long a = floor(sqrtl(r)); n     long long b = ceil(sqrtl(l)); n     long long res = n         upper_bound(v.begin(), v.end(), r) - lower_bound(v.begin(), v.end(), l); n     long long res1 = a - b + 1; n     cout << res + res1 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[5001], n; n int dfs(int l, int r) { n   int Min = a[l], ans = 0; n   for (int i = l + 1; i <= r; i++) Min = min(Min, a[i]); n   ans = Min; n   for (int i = l; i <= r; i++) a[i] -= Min; n   for (int i = l; i <= r; i++) n     if (a[i]) { n       int tmp = i + 1; n       while (tmp <= r && a[tmp]) ++tmp; n       ans += dfs(i, tmp - 1); n       i = tmp - 1; n     } n   return min(ans, r - l + 1); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   printf( %d n , dfs(1, n)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N; n double A[100001]; n double dp[100001]; n int main() { n   scanf( %d , &N); n   for (int i = 1; i <= N; i++) scanf( %lf , A + i); n   double ans = 0.0; n   for (int i = 1; i <= N; i++) n     ans += A[i] + 2 * (dp[i] = (dp[i - 1] + A[i - 1]) * A[i]); n   printf( %.9f n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e3 + 10, M = 2e5 + 10; n struct upd { n   int r, s, t, id; n } t; n vector<upd> v[M]; n struct edge { n   int x, y; n } e[M]; n int ans[M], n, m, qi, f[N][N]; n signed main() { n   int x; n   scanf( %d %d %d , &n, &m, &qi); n   for (register int i = (1); i <= (m); ++i) scanf( %d %d , &e[i].x, &e[i].y); n   for (register int i = (1); i <= (qi); ++i) n     scanf( %d %d %d %d , &x, &t.r, &t.s, &t.t), t.id = i, v[x].push_back(t); n   int p = qi; n   memset(f, 0x3f, sizeof(f)); n   for (register int i = (m); i >= (1); --i) { n     int x = e[i].x, y = e[i].y; n     f[x][y] = f[y][x] = i; n     for (register int j = (1); j <= (n); ++j) n       f[x][j] = min(f[x][j], f[y][j]), f[y][j] = min(f[y][j], f[x][j]); n     int l = v[i].size() - 1; n     for (register int j = (0); j <= (l); ++j) n       ans[v[i][j].id] = (f[v[i][j].s][v[i][j].t] <= v[i][j].r); n   } n   for (register int i = (1); i <= (qi); ++i) printf(ans[i] ?  Yes n  :  No n ); n   return 0; n } n


#include <bits/stdc++.h> n using uint = unsigned int; n using cat = long long; n using dbl = long double; n constexpr dbl pi = 3.14159265358979323846; n using namespace std; n cat pw(cat a, cat e, cat mod) { n   if (e <= 0) return 1; n   cat x = pw(a, e / 2, mod); n   x = x * x % mod; n   return (e & 1) ? x * a % mod : x; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cout << fixed << setprecision(10); n   int N; n   cin >> N; n   vector<int> A(N); n   int S = 0; n   for (int i = 0; i < N; i++) { n     cin >> A[i]; n     S += A[i]; n   } n   if (S == 1) { n     cout <<  0 n ; n     return 0; n   } n   cat mod = 998244353; n   vector<cat> inv(S + 1, 1); n   for (int i = 1; i <= S; i++) { n     if (i > 2 && i % 2 == 0) n       inv[i] = inv[i / 2] * inv[2] % mod; n     else if (i > 3 && i % 3 == 0) n       inv[i] = inv[i / 3] * inv[3] % mod; n     else n       inv[i] = pw(i, mod - 2, mod); n   } n   cat iN = pw(N - 1, mod - 2, mod); n   vector<cat> E(S + 1, 0), E_lf_c(S + 1, 0), E_lf_a(S + 1, 0); n   E_lf_a[1] = 1; n   for (int i = 1; i < S; i++) { n     cat c1 = i * iN % mod; n     cat c2 = S - i + c1; n     E_lf_a[i + 1] = n         (c2 * E_lf_a[i] - c1 * E_lf_a[i - 1]) % mod * inv[S - i] % mod; n     E_lf_c[i + 1] = n         (c2 * E_lf_c[i] - c1 * E_lf_c[i - 1] - S) % mod * inv[S - i] % mod; n   } n   E[1] = (N - 1 + E_lf_c[S - 1] - E_lf_c[S]) * n          pw(E_lf_a[S] - E_lf_a[S - 1], mod - 2, mod) % mod; n   for (int i = 2; i <= S; i++) E[i] = (E[1] * E_lf_a[i] + E_lf_c[i]) % mod; n   cat E_cyc = E[S]; n   cat ans = 0; n   for (int i = 0; i < N; i++) ans += E[S - A[i]]; n   ans = (ans - (N - 1) * E_cyc) % mod * pw(N, mod - 2, mod) % mod; n   if (ans < 0) ans += mod; n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void print(vector<T>& v) { n   for (int i = 0; i < v.size(); i++) { n     cout << v[i] <<    ; n   } n   cout <<   n ; n } n vector<int> z_function(string s) { n   int n = (int)s.length(); n   vector<int> z(n); n   for (int i = 1, l = 0, r = 0; i < n; ++i) { n     if (i <= r) z[i] = min(r - i + 1, z[i - l]); n     while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i]; n     if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1; n   } n   return z; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   string s; n   cin >> s; n   int n = s.length(); n   int q; n   cin >> q; n   string sr = s; n   reverse(sr.begin(), sr.end()); n   vector<int> v(n, n + 1); n   while (q--) { n     string t; n     cin >> t; n     int l = t.length(); n     for (int i = 0; i < n; i++) { n       if (i + l > n) break; n       if (s.substr(i, l) == t) { n         v[i + l - 1] = min(v[i + l - 1], l); n       } n     } n   } n   int maxlen = (v[0] == 1) ? 0 : 1; n   int index = 0; n   int ans = maxlen; n   for (int i = 1; i < n; i++) { n     int len = min(v[i] - 1, ans + 1); n     if (len > maxlen) { n       maxlen = len; n       index = i - len + 1; n     } n     ans = len; n   } n   cout << maxlen <<     << index <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAX = 100010; n const long long MOD = 1000000007; n const long long INF = (long long)1e9; n const long long LLINF = 0x3f3f3f3f3f3f3f3f; n const long double EPS = 1e-7; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long n, m; n   cin >> n; n   long long somaa0 = 0, somab0 = 0; n   vector<long long> a(n); n   for (long long i = 0; i < (long long)n; i++) { n     cin >> a[i]; n     somaa0 += a[i]; n   } n   cin >> m; n   vector<long long> b(m); n   for (long long i = 0; i < (long long)m; i++) { n     cin >> b[i]; n     somab0 += b[i]; n   } n   vector<pair<long long, long long> > res; n   long long melhor = abs(somaa0 - somab0); n   set<long long> setb; n   for (long long i = 0; i < (long long)m; i++) { n     for (long long j = i + 1; j <= m - 1; j++) { n       setb.insert(2 * b[i] + 2 * b[j]); n     } n   } n   for (long long i = 0; i < (long long)n; i++) { n     for (long long j = 0; j < (long long)m; j++) { n       long long somaa1 = somaa0 - a[i] + b[j]; n       long long somab1 = somab0 + a[i] - b[j]; n       if (abs(somaa1 - somab1) < melhor) { n         melhor = abs(somaa1 - somab1); n         res.clear(); n         res.push_back(make_pair(i, j)); n       } n     } n   } n   bool win2 = false; n   for (long long i = 0; i < a.size(); i++) { n     for (long long j = i + 1; j < a.size(); j++) { n       long long somaa2 = somaa0 - a[i] - a[j]; n       long long somab2 = somab0 + a[i] + a[j]; n       long long m = somab2 - somaa2; n       auto it = setb.lower_bound(m); n       if (it != setb.end()) { n         long long val = *it; n         if (abs(val + somaa2 - somab2) < melhor) { n           melhor = abs(val + somaa2 - somab2); n           win2 = true; n           res.clear(); n           res.push_back(make_pair(i, j)); n         } n       } n       if (it != setb.begin()) { n         auto it2 = prev(it); n         long long val = *it2; n         if (abs(val + somaa2 - somab2) < melhor) { n           melhor = abs(val + somaa2 - somab2); n           win2 = true; n           res.clear(); n           res.push_back(make_pair(i, j)); n         } n       } n     } n   } n   if (win2) { n     long long ia = res[0].first, ja = res[0].second; n     long long somaa2 = somaa0 - a[ia] - a[ja]; n     long long somab2 = somab0 + a[ia] + a[ja]; n     for (long long i = 0; i < (long long)m; i++) { n       for (long long j = i + 1; j <= m - 1; j++) { n         if (abs(somaa2 + 2 * b[i] + 2 * b[j] - somab2) <= melhor) { n           res.clear(); n           res.push_back(make_pair(ia, i)); n           res.push_back(make_pair(ja, j)); n         } n       } n     } n   } n   cout << melhor <<   n ; n   cout << res.size() <<   n ; n   for (auto val : res) { n     cout << val.first + 1 <<     << val.second + 1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n struct cmp { n   bool operator()(const pair<ll, ll>& a, const pair<ll, ll>& b) { n     return abs(a.first - a.second) > abs(b.first - b.second); n   } n }; n int main() { n   ll n; n   cin >> n; n   vector<pair<ll, ll>> v(n); n   multiset<pair<ll, ll>, cmp> s; n   for (int i = 0; i < n; i++) { n     cin >> v[i].first >> v[i].second; n     s.insert(v[i]); n   } n   int l = 0; n   int r = n - 1; n   ll ans = 0; n   for (int i = 0; i < n; i++) { n     pair<ll, ll> cur = *s.begin(); n     s.erase(s.begin()); n     if (cur.first <= cur.second) { n       ans += cur.first * r + cur.second * (n - 1 - r); n       r--; n     } else { n       ans += cur.first * l + cur.second * (n - 1 - l); n       l++; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 404; n int n, m; n vector<int> g[maxn]; n vector<int> q, G; n int dis[maxn][maxn]; n long double p[maxn], P; n pair<long double, int> mxp[maxn]; n long double ans; n void bfs(int s) { n   dis[s][s] = 0; n   q.resize(0); n   q.push_back(s); n   for (int v, i = 0; i < q.size(); i++) { n     v = q[i]; n     for (int u : g[v]) n       if (dis[s][v] + 1 < dis[s][u]) { n         dis[s][u] = dis[s][v] + 1; n         q.push_back(u); n       } n   } n } n long double f(int v) { n   long double ret = 0; n   for (int d = 0; d < n; d++) { n     G.resize(0); n     for (int i = 0; i < n; i++) p[i] = 0; n     for (int i = 0; i < n; i++) n       if (dis[v][i] == d) { n         for (int j : g[i]) { n           if (p[j] == 0) G.push_back(j); n           p[j] += P / g[i].size(); n         } n       } n     if (!G.size()) break; n     for (int i = 0; i < n; i++) mxp[i] = {0, -1}; n     long double X = P, x; n     for (int u = 0; u < n; u++) { n       x = 0; n       for (int c : G) { n         if (mxp[dis[u][c]].second == u) x -= mxp[dis[u][c]].first; n         if (mxp[dis[u][c]].second != u or mxp[dis[u][c]].first < p[c]) n           mxp[dis[u][c]] = {p[c], u}; n         if (mxp[dis[u][c]].second == u) x += mxp[dis[u][c]].first; n       } n       X = max(X, x); n     } n     ret += X; n   } n   return ret; n } n int main() { n   memset(dis, 127, sizeof dis); n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m; n   for (int v, u, i = 0; i < m; i++) { n     cin >> v >> u; n     v--, u--; n     g[v].push_back(u); n     g[u].push_back(v); n   } n   for (int i = 0; i < n; i++) bfs(i); n   P = 1.0 / n; n   for (int i = 0; i < n; i++) { n     ans = max(ans, f(i)); n   } n   cout << setprecision(15) << fixed << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e3 + 5; n const int inf = 6969696; n int dp[N][N]; n int a[N]; n int e[N]; n int n, k; n int go(int pos, int left) { n   if (left < 0) return -inf; n   if (pos == n) return 0; n   int &cur = dp[pos][left]; n   if (cur != -1) return cur; n   cur = go(pos + 1, left); n   cur = max(cur, e[pos] - pos + go(e[pos], left - 1)); n   return cur; n } n int main() { n   scanf( %d %d , &n, &k); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   sort(a, a + n); n   int i = 0, ptr = 0; n   while (i < n) { n     while (ptr < n and a[ptr] <= a[i] + 5) ptr++; n     e[i] = ptr; n     i++; n   } n   memset(dp, -1, sizeof dp); n   printf( %d n , go(0, k)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string s =  abcd ; n   string ans =   ; n   int m = n / 4; n   for (int i = 0; i < m; i++) { n     ans += s; n   } n   int z = n % 4; n   for (int i = 0; i < z; i++) { n     ans += s[i]; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = (1LL << 30) - 1; n const long long int LINF = (1LL << 62) - 1; n const int NMAX = (1e5) + 5; n int N, M; n int pile[NMAX]; n bool check(long long int time) { n   int i, k; n   long long int curr; n   int P[NMAX]; n   memcpy(P, pile, sizeof(pile)); n   for (i = N, k = 1; k <= M; k++) { n     while (P[i] == 0 && i >= 1) i--; n     if (i == 0) return 1; n     curr = i; n     while (curr < time) { n       if (curr + P[i] <= time) { n         curr += P[i]; n         P[i] = 0; n       } else { n         P[i] -= time - curr; n         curr = time; n       } n       while (P[i] == 0 && i >= 1) i--; n       if (i == 0) return 1; n     } n   } n   return 0; n } n int main() { n   int i; n   long long int lo = 0, hi = 0, mi; n   long long int sol; n   cin.sync_with_stdio(false); n   scanf( %d%d , &N, &M); n   hi += N; n   for (i = 1; i <= N; i++) { n     scanf( %d , &pile[i]); n     hi += pile[i]; n   } n   sol = hi; n   while (lo <= hi) { n     mi = (lo + hi) / 2; n     if (check(mi)) { n       sol = min(sol, mi); n       hi = mi - 1; n     } else n       lo = mi + 1; n   } n   printf( %lld n , sol); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long lis(long long arr[], long long n) { n   long long lis[n]; n   lis[0] = 1; n   for (long long i = 1; i < n; i++) { n     lis[i] = 1; n     for (long long j = 0; j < i; j++) n       if (arr[i] >= arr[j] && lis[i] < lis[j] + 1) lis[i] = lis[j] + 1; n   } n   return *max_element(lis, lis + n); n } n void solve() { n   long long n, m; n   cin >> n >> m; n   long long a[n]; n   double d[n]; n   for (long long i = 0; i < (n); ++i) cin >> a[i] >> d[i]; n   cout << n - lis(a, n); n } n signed main() { n   std::ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t; n   t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n constexpr int kN = int(1E7 + 10); n vector<long long int> prime; n int l[kN], mu[kN], s[kN]; n long long int n; n void pre() { n   mu[1] = 1; n   for (int i = 2; i <= n; i++) { n     if (l[i] == 0) { n       mu[i] = -1; n       prime.push_back(l[i] = i); n     } n     for (int j : prime) { n       if (i * j > n) break; n       l[i * j] = min(l[i], j); n       if (i % j == 0) { n         mu[i * j] = 0; n         break; n       } else n         mu[i * j] = -mu[i]; n     } n   } n   for (int i = 2; i <= n; i++) s[l[i]]++; n   for (int i = 3; i <= n; i++) s[i] += s[i - 1]; n   return; n } n int main() { n   long long int ans = 0, one = 0, two = 0, three = 0, zero = 0, cnt = 1; n   scanf( %lld , &n); n   pre(); n   for (int k = 1; k <= n; k++) one += mu[k] * (n / k) * (n / k); n   one = n * (n - 1) / 2 - (one >> 1); n   for (long long int i : prime) n     if (i * i < n) n       continue; n     else if ((i << 1) > n) n       cnt++; n     else if (i > n / i) n       three += s[i - 1] - s[n / i]; n   zero = (((n - 1) + (n - cnt)) * cnt) >> 1; n   two = n * (n - 1) / 2 - zero - one - three; n   ans = one + two * 2 + three * 3; n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, mx = -1, n; n   cin >> n; n   while (n--) { n     cin >> x; n     mx = max(x, mx); n   } n   if (mx <= 25) n     cout <<  0 n ; n   else n     cout << mx - 25 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxVal = 200005; n int arr[maxVal]; n int tree[4 * maxVal]; n void build(int node, int start, int endd, int k) { n   if (start == endd) { n     if (arr[start] >= k) n       tree[node] = 1; n     else n       tree[node] = 0; n   } else { n     int mid = (start + endd) / 2; n     build(2 * node, start, mid, k); n     build(2 * node + 1, mid + 1, endd, k); n     tree[node] = tree[2 * node] + tree[2 * node + 1]; n   } n } n int query(int node, int start, int endd, int l, int r) { n   if (start > r || endd < l) { n     return 0; n   } else if (l <= start && endd <= r) { n     return tree[node]; n   } else { n     int mid = (start + endd) / 2; n     int a1 = query(2 * node, start, mid, l, r); n     int a2 = query(2 * node + 1, mid + 1, endd, l, r); n     return a1 + a2; n   } n } n int main() { n   int n, m, k; n   cin >> n >> k >> m; n   int a, b; n   for (int i = 0; i < n; i++) { n     cin >> a >> b; n     arr[a]++; n     arr[b + 1]--; n   } n   for (int i = 1; i < maxVal; i++) { n     arr[i] = arr[i] + arr[i - 1]; n   } n   build(1, 0, maxVal, k); n   for (int i = 0; i < m; i++) { n     cin >> a >> b; n     cout << query(1, 0, maxVal, a, b) << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 5; n const long long p = 1e9 + 7; n int par[MAXN][2], size[MAXN][2], dist[MAXN][2], val[MAXN][2]; n int groups, n, k; n pair<int, int> find(int e, int x) { n   if (par[x][e] == x) { n     return pair<int, int>(x, 0); n   } n   pair<int, int> t = find(e, par[x][e]); n   t.second += dist[x][e]; n   t.second %= 2; n   dist[x][e] = t.second; n   par[x][e] = t.first; n   return t; n } n bool assign(int e, int x, int v) { n   find(e, x); n   if (val[par[x][e]][e] == -1) { n     val[par[x][e]][e] = (dist[x][e] + v) % 2; n     --groups; n     return true; n   } n   if (val[par[x][e]][e] != (dist[x][e] + v) % 2) return false; n   return true; n } n bool addedge(int e, int x, int y, int v) { n   find(e, x); n   find(e, y); n   if (par[x][e] == par[y][e]) return ((dist[x][e] + dist[y][e] + v) % 2 == 0); n   v = (dist[x][e] + dist[y][e] + v) % 2; n   x = par[x][e]; n   y = par[y][e]; n   if (size[x][e] > size[y][e]) swap(x, y); n   par[x][e] = y; n   dist[x][e] = v; n   size[y][e] += size[x][e]; n   if (val[y][e] != -1 && val[x][e] != -1) { n     if ((val[x][e] + val[y][e] + v) % 2 != 0) return false; n     return true; n   } n   if (val[x][e] != -1) { n     val[y][e] = (val[x][e] + v) % 2; n     --groups; n     return true; n   } n   --groups; n   return true; n } n int main() { n   cin >> n >> k; n   groups = 2 * n - 1; n   for (int i = 0; i < MAXN; ++i) { n     par[i][0] = par[i][1] = i; n     size[i][0] = size[i][1] = 1; n     dist[i][0] = dist[i][1] = 0; n     val[i][0] = val[i][1] = -1; n   } n   for (int i = 0; i < k; ++i) { n     int x, y, v; n     char j; n     cin >> x >> y >> j; n     v = (j ==  o ); n     x--; n     y--; n     if (abs(x - y) <= 1) { n       if (!assign((x + y) % 2, min(x, y), v)) { n         cout <<  0  << endl; n         return 0; n       } n     } else { n       if (x > y) swap(x, y); n       if (!addedge((x + y) % 2, (y - x - (x + y) % 2) / 2 - 1, n                    (y - x - (x + y) % 2) / 2 + x, v)) { n         cout <<  0  << endl; n         return 0; n       } n     } n   } n   for (int i = 0; i < n / 2; ++i) { n     if (!addedge(0, i, n - 1 - i, 0)) { n       cout <<  0  << endl; n       return 0; n     } n   } n   for (int i = 0; i < (n - 1) / 2; ++i) { n     if (!addedge(1, i, n - 2 - i, 0)) { n       cout <<  0  << endl; n       return 0; n     } n   } n   long long prod = 1; n   for (int i = 0; i < groups; ++i) { n     prod *= 2; n     prod %= p; n   } n   cout << prod << endl; n } n


#include <bits/stdc++.h> n const double eps = (1e-5); n using namespace std; n int dcmp(long double a, long double b) { n   return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1; n } n long long getBit(long long num, int idx) { return ((num >> idx) & 1ll) == 1; } n int setBit1(int num, int idx) { return num | (1 << idx); } n long long setBit0(long long num, int idx) { return num & ~(1ll << idx); } n long long flipBit(long long num, int idx) { return num ^ (1ll << idx); } n void M() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n int countNumBit1(int mask) { n   int ret = 0; n   while (mask) { n     mask &= (mask - 1); n     ++ret; n   } n   return ret; n } n int arr[3009], E[4500009]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   int cnt = 0; n   while (1) { n     int fl = 0; n     for (int i = 0; i < n; i++) { n       if (i + 1 < n && arr[i] > arr[i + 1]) n         swap(arr[i], arr[i + 1]), cnt++, fl = 1; n     } n     if (!fl) break; n   } n   E[1] = 1; n   for (int i = 2; i <= cnt; i++) E[i] = 4 + E[i - 2]; n   cout << fixed << setprecision(9) << (double)E[cnt] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 100; n const long long INF = 1e18; n struct node { n   long long d, f, t, c; n } a[N]; n long long b[N]; n long long dp[1000006], dp1[1000005]; n bool cmp(node p, node q) { return p.d < q.d; } n int main() { n   int n, m, k; n   long long x = 1000000, y = -1; n   cin >> n >> m >> k; n   for (int i = 1; i <= m; i++) { n     scanf( %lld%lld%lld%lld , &a[i].d, &a[i].f, &a[i].t, &a[i].c); n   } n   sort(a + 1, a + 1 + m, cmp); n   for (int i = 1; i <= 1000001; i++) b[i] = -1, dp[i] = INF; n   long long sum = 0, s = 0; n   for (int i = 1; i <= m; i++) { n     if (a[i].f == 0) continue; n     if (b[a[i].f] == -1) { n       s++; n       b[a[i].f] = a[i].c; n       sum += a[i].c; n     } else { n       if (b[a[i].f] > a[i].c) { n         sum -= b[a[i].f]; n         sum += a[i].c; n         b[a[i].f] = a[i].c; n       } n     } n     if (s == n) { n       dp[a[i].d] = sum; n       x = min(x, a[i].d); n     } n   } n   for (int i = 1; i <= 1000001; i++) b[i] = -1, dp1[i] = INF; n   sum = 0; n   s = 0; n   for (int i = m; i >= 1; i--) { n     if (a[i].t == 0) continue; n     if (b[a[i].t] == -1) { n       s++; n       b[a[i].t] = a[i].c; n       sum += a[i].c; n     } else { n       if (b[a[i].t] > a[i].c) { n         sum -= b[a[i].t]; n         sum += a[i].c; n         b[a[i].t] = a[i].c; n       } n     } n     if (s == n) { n       dp1[a[i].d] = sum; n       y = max(y, a[i].d); n     } n   } n   for (int i = x + 1; i <= 1000000; i++) dp[i] = min(dp[i - 1], dp[i]); n   for (int i = y - 1; i >= 1; i--) dp1[i] = min(dp1[i + 1], dp1[i]); n   long long ans = INF; n   for (int i = 1; i <= 1000000 - k - 1; i++) { n     if (dp[i] == INF || dp1[i + k + 1] == INF) continue; n     if (ans > dp[i] + dp1[i + k + 1]) { n       ans = dp[i] + dp1[i + k + 1]; n     } n   } n   if (ans == INF) n     cout << -1 << endl; n   else n     cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long sum[4]; n int main(void) { n   long long n, a, b, c, d, min_value = 1e14, max_value = 0, flag = 0; n   scanf( %lld %lld %lld %lld %lld , &n, &a, &b, &c, &d); n   sum[0] = a + b; n   sum[1] = b + d; n   sum[2] = c + d; n   sum[3] = a + c; n   for (int i = 0; i < 4; i++) { n     min_value = min(min_value, sum[i]); n     max_value = max(max_value, sum[i]); n   } n   if (max_value - min_value > n) flag = 1; n   if (flag == 1) n     printf( 0 ); n   else n     printf( %lld , n * (n - (max_value - min_value))); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long md = 1e9 + 7; n const long long MX = 2e5 + 5; n const long long INF = 1e18; n const long double PI = 4 * atan((long double)1); n long long power(long long a, long long n) { n   long long res = 1; n   while (n) { n     if (n % 2) res *= a; n     a *= a; n     n /= 2; n   } n   return res; n } n long long abst(long long a) { return ((a < 0) ? (-1 * a) : (a)); } n long long froot(long long x, long long* root) { n   if (x == root[x]) n     return x; n   else n     root[x] = froot(root[x], root); n } n int32_t main() { n   long long n; n   cin >> n; n   long long arr[n + 1], root[n + 1], cnt[n + 1]; n   for (long long i = 1; i <= n; i++) { n     cnt[i] = 1; n     root[i] = i; n   } n   for (long long i = 1; i <= n; i++) { n     cin >> arr[i]; n     long long x = froot(i, root); n     long long y = froot(arr[i], root); n     if (x < y) { n       root[y] = x; n       cnt[x] += cnt[y]; n     } else if (y < x) { n       root[x] = y; n       cnt[y] += cnt[x]; n     } n   } n   map<long long, long long> mp; n   long long max1 = -1, max2 = -1, rm1 = -1, rm2 = -1; n   for (long long i = 1; i <= n; i++) { n     long long x = froot(i, root); n     if (mp[x] == 0) { n       mp[x]++; n       if (cnt[x] >= max1) { n         max2 = max1; n         rm2 = rm1; n         max1 = cnt[x]; n         rm1 = x; n       } else if (cnt[x] > max2) { n         max2 = cnt[x]; n         rm2 = x; n       } n     } n   } n   if (rm2 == -1) { n     long long res; n     long long x = froot(1, root); n     x = cnt[x]; n     res = power(x, 2); n     cout << res <<   n ; n   } else { n     long long res = 0; n     root[rm2] = rm1; n     cnt[rm1] += cnt[rm2]; n     map<long long, long long> mp1; n     for (long long i = 1; i <= n; i++) { n       long long x = froot(i, root); n       if (mp1[x] == 0) { n         mp1[x]++; n         long long p = cnt[x]; n         res += power(p, 2); n       } n     } n     cout << res <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 710; n int n; n struct Tbig { n   static const int bit = 10000; n   int n, a[30]; n   Tbig(int x = 0) { n     memset(a, 0, sizeof a); n     for (n = 0; x; x /= bit) a[n++] = x % bit; n     !n ? n = 1 : 0; n   } n   Tbig operator*(const Tbig &b) const { n     int i, j; n     Tbig c; n     c.n = n + b.n; n     for (i = 0; i < n; ++i) n       for (j = 0; j < b.n; ++j) { n         c.a[i + j] += a[i] * b.a[j]; n         c.a[i + j + 1] += c.a[i + j] / bit, c.a[i + j] %= bit; n       } n     for (; c.n > 0 && !c.a[c.n]; --c.n) n       ; n     ++c.n; n     return c; n   } n   bool operator<(const Tbig &b) const { n     int i; n     if (n != b.n) return n < b.n; n     for (i = n - 1; i >= 0; --i) n       if (a[i] != b.a[i]) return a[i] < b.a[i]; n     return false; n   } n   void print() { n     int i; n     printf( %d , a[n - 1]); n     for (i = n - 2; i >= 0; --i) printf( %04d , a[i]); n     printf(  n ); n   } n }; n struct Talt { n   int tot; n   struct Tsqy { n     int s; n     Tsqy *l; n     inline void set(Tsqy *_l, int _s) { l = _l, s = _s; } n   } * pos[maxn], buf[maxn * 2]; n   inline void add(int a, int b) { n     buf[++tot].set(pos[a], b), pos[a] = buf + tot; n     buf[++tot].set(pos[b], a), pos[b] = buf + tot; n   } n } alt; n namespace Ninit { n void init() { n   int i, a1, a2; n   scanf( %d , &n); n   for (i = 1; i < n; ++i) { n     scanf( %d%d , &a1, &a2), alt.add(a1, a2); n   } n } n }  // namespace Ninit n namespace Nsolve { n Tbig F[maxn][maxn], G[maxn], F_xi; n int S[maxn]; n void dfs(int x, int f) { n   Talt::Tsqy *p; n   int i, j; n   S[x] = 1, F[x][1] = 1; n   for (p = alt.pos[x]; p; p = p->l) n     if (p->s != f) { n       dfs(p->s, x), S[x] += S[p->s]; n       for (i = S[x]; i >= 1; --i) { n         F_xi = F[x][i]; n         for (j = min(S[p->s], i - 1); j > 0 && i - j <= S[x] - S[p->s]; --j) n           F[x][i] = max(F[x][i], F[x][i - j] * F[p->s][j]); n         F[x][i] = max(F[x][i], F_xi * G[p->s]); n       } n     } n   for (i = 1; i <= S[x]; ++i) G[x] = max(G[x], F[x][i] * i); n } n void solve() { n   dfs(1, 0); n   G[1].print(); n } n }  // namespace Nsolve n int main() { n   Ninit::init(); n   Nsolve::solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int size1; n   string s; n   vector<int> v; n   int arr[200]; n   cin >> size1 >> s; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  * ) v.push_back(i + 1); n   } n   for (int i = 0; i < v.size(); i++) { n     for (int count1 = 1; count1 <= 100; count1++) { n       int n = v[i] + count1; n       int counttimes = 0; n       for (int l = i + 1; l < v.size(); l++) { n         if (counttimes == 4) { n           cout <<  yes ; n           return 0; n         } n         if (n == v[l]) { n           n = v[l] + count1; n           counttimes++; n         } n         if (v[l] > n) break; n       } n       if (counttimes == 4) { n         cout <<  yes ; n         return 0; n       } n     } n   } n   cout <<  no ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 1e5; n long long int t[N]; n string s; n long long int n, k; n bool chek(long long int x) { n   for (long long int i = 0; i < n; i++) { n     if (!(s[i] -  0 )) { n       long long int en = i + x; n       long long int st = i - x; n       en = min(en, n - 1); n       st = max((long long int)0, st); n       long long int cur = t[en] - (st ? t[st - 1] : 0) - 1; n       if (cur >= k) return true; n     } n   } n   return false; n } n int32_t main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n >> k; n   cin >> s; n   long long int x = 0; n   for (long long int i = 0; i < s.size(); i++) { n     if (!(s[i] -  0 )) x++; n     t[i] = x; n   } n   long long int l = -1, r = n + 1; n   while (r - l > 1) { n     long long int mid = (r + l) / 2; n     if (chek(mid)) n       r = mid; n     else n       l = mid; n   } n   cout << r; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, c, d, n, m; n string s, v; n int main() { n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     cin >> a >> b; n   } n   for (int i = 1; i <= n; i++) { n     if (i % 2 == 1) { n       cout << 1; n     } else { n       cout << 0; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, i, j, k, x, y, w, m, Q, used[100500], start; n pair<pair<int, int>, int> a[100500]; n vector<pair<int, int> > g[100500]; n vector<int> f[100500]; n long long d[100500]; n long long hea[200500]; n int new_w[100500], new_d[100500]; n int hea2[200500]; n int st[100500], sz[100500], cur_pos[100500]; n pair<int, int> G[100500]; n int heapSize; n void add(pair<long long, int> value) { n   hea[heapSize++] = value.first; n   int i = heapSize - 1; n   hea2[i] = value.second; n   int parent = ((i - 1) >> 1); n   while (i > 0 && hea[parent] < hea[i]) { n     swap(hea[i], hea[parent]); n     swap(hea2[i], hea2[parent]); n     i = parent; n     parent = ((i - 1) >> 1); n   } n } n void heapify(int i) { n   int largestChild; n   for (;;) { n     largestChild = i; n     if (hea[2 * i + 1] > hea[largestChild]) { n       largestChild = 2 * i + 1; n     } n     if (hea[2 * i + 2] > hea[largestChild]) { n       largestChild = 2 * i + 2; n     } n     if (largestChild == i) { n       break; n     } n     swap(hea[i], hea[largestChild]); n     swap(hea2[i], hea2[largestChild]); n     i = largestChild; n   } n } n pair<long long, int> getMax() { n   pair<int, int> result = make_pair(hea[0], hea2[0]); n   heapSize--; n   hea[0] = hea[heapSize]; n   hea2[0] = hea2[heapSize]; n   hea[heapSize] = -(long long)1e+18; n   heapify(0); n   return result; n } n inline unsigned int readUInt() { n   int c = getc(stdin); n   unsigned int x = 0; n   while (c <= 32) c = getc(stdin); n   while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getc(stdin); n   return x; n } n int main() { n   cin >> n >> m >> Q; n   for (i = 0; i <= 200000; i++) hea[i] = -(long long)1e+18; n   for (i = 0; i < m; i++) { n     int x, y, z; n     x = readUInt(); n     y = readUInt(); n     z = readUInt(); n     a[i] = make_pair(make_pair(x, y), z); n   } n   int s = 1; n   for (i = 0; i < m; i++) { n     g[a[i].first.first].push_back(make_pair(a[i].first.second, a[i].second)); n   } n   st[1] = 0; n   sz[1] = g[1].size(); n   for (i = 2; i <= n; i++) { n     st[i] = st[i - 1] + g[i - 1].size(); n     sz[i] = g[i].size(); n   } n   for (i = 1; i <= n; i++) d[i] = (long long)1e+18; n   d[s] = 0; n   for (i = 0; i < heapSize; i++) hea[i] = -(long long)1e+18; n   heapSize = 0; n   add(make_pair(0, s)); n   while (heapSize) { n     pair<int, int> tmp = getMax(); n     int v = tmp.second; n     long long cur_d = -tmp.first; n     if (cur_d > d[v]) continue; n     for (size_t j = 0; j < g[v].size(); ++j) { n       int to = g[v][j].first; n       long long len = g[v][j].second; n       if (d[v] + len < d[to]) { n         d[to] = d[v] + len; n         add(make_pair(-d[to], to)); n       } n     } n   } n   for (i = 0; i < m; i++) n     new_w[i] = min(100000000LL, n                    a[i].second + d[a[i].first.first] - d[a[i].first.second]); n   for (int ii = 0; ii < Q; ii++) { n     int test; n     cin >> test; n     if (test == 1) { n       int t; n       cin >> t; n       if (d[t] == (long long)1e+18) n         cout << -1 << endl; n       else n         cout << d[t] << endl; n     } else { n       cin >> x; n       for (i = 0; i < x; i++) { n         int y = readUInt(); n         new_w[y - 1]++; n         a[y - 1].second++; n       } n       for (i = 1; i <= n; i++) cur_pos[i] = st[i]; n       for (i = 0; i < m; i++) { n         G[cur_pos[a[i].first.first]++] = make_pair(a[i].first.second, new_w[i]); n       } n       for (i = 0; i <= n; i++) { n         f[i].clear(); n         new_d[i] = (int)1e+9; n       } n       f[0].push_back(1); n       new_d[1] = 0; n       for (i = 0; i < n; i++) { n         for (j = 0; j < f[i].size(); j++) { n           int v = f[i][j]; n           if (new_d[v] == i) { n             for (k = st[v]; k < st[v] + sz[v]; k++) { n               int to = G[k].first; n               int val = G[k].second; n               if (new_d[to] > i + val) { n                 new_d[to] = min(100000000, i + val); n                 if (new_d[to] <= n) f[new_d[to]].push_back(to); n               } n             } n           } n         } n       } n       for (i = 1; i <= n; i++) { n         d[i] += new_d[i]; n         if (d[i] > (long long)1e+18) d[i] = (long long)1e+18; n       } n       for (i = 0; i < m; i++) n         new_w[i] = min(100000000LL, a[i].second + d[a[i].first.first] - n                                         d[a[i].first.second]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, arr[100010], mn = 1000000000, st, ans = 1000000000; n bool b; n int main() { n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> arr[i]; n     mn = min(mn, arr[i]); n   } n   for (int i = 0; i < n; ++i) { n     if (arr[i] == mn && !b) { n       st = i; n       b = 1; n     } else if (arr[i] == mn) { n       ans = min(ans, i - st); n       st = i; n     } n   } n   cout << ans; 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 a[n]; n   for (int i = 0; i < n; i++) a[i] = i + 1; n   int cnt = (n / 2) * (n / 2); n   if (n % 2 == 0) cnt -= n / 2; n   if (cnt < m) { n     cout << -1; n     return 0; n   } n   int idx = n - 1; n   while (m < cnt) { n     if (cnt - (idx / 2) <= m) { n       a[idx] += 2 * (cnt - m); n       break; n     } else { n       cnt -= idx / 2; n       if (idx + 1 == n) n         a[idx] = 1000 * 1000 * 1000; n       else n         a[idx] = a[idx + 1] - 2 * n; n     } n     idx--; n   } n   for (int i = 0; i < n; i++) cout << a[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, nn[5], ma; n string s; n long long ans = 1; n int main() { n   cin >> n >> s; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  A ) nn[0]++; n     if (s[i] ==  C ) nn[1]++; n     if (s[i] ==  G ) nn[2]++; n     if (s[i] ==  T ) nn[3]++; n   } n   for (int i = 0; i < 4; i++) ma = max(ma, nn[i]); n   int ct = 0; n   for (int i = 0; i < 4; i++) { n     if (nn[i] == ma) ct++; n   } n   for (int i = 0; i < n; i++) { n     ans *= ct; n     ans %= 1000000007; n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 5; n long long t, n, a[maxn]; n int main() { n   scanf( %d , &t); n   while (t--) { n     long long maxx = -1e18, ans = 0; n     cin >> n; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n       if (a[i] > maxx) maxx = a[i]; n     } n     for (int i = 0; i < n; i++) { n       if (maxx == a[i]) { n         if (i == 0 && a[0] > a[1]) { n           ans = 1; n           break; n         } else if (i == n - 1 && a[n - 1] > a[n - 2]) { n           ans = n; n           break; n         } else if (((i != 0) && a[i] > a[i - 1]) || n                    (i != n - 1 && a[i] > a[i + 1])) { n           ans = i + 1; n           break; n         } n       } n     } n     if (ans == 0) n       cout << -1 << endl; n     else n       cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 5; n char s[MAXN]; n int main() { n   int m; n   scanf( %d , &m); n   scanf( %s , s); n   int n = strlen(s); n   priority_queue<int, vector<int>, greater<int> > Q; n   for (int k = 0; k < 26; k++) { n     while (!Q.empty()) Q.pop(); n     bool flag; n     for (int i = 0; i <= n - 1; i++) { n       flag = 0; n       int tmp = 0; n       for (int j = i; j <= i + m - 1 && j < n; j++) { n         if (s[j] -  a  < k) Q.push(s[j]), flag = 1, tmp = j; n       } n       if (i > n - m) { n         flag = 1; n         break; n       } n       if (!flag) { n         for (int j = i + m - 1; j >= i; j--) { n           if (s[j] -  a  == k) { n             Q.push(s[j]), flag = 1; n             tmp = j; n             break; n           } n         } n         if (!flag) break; n       } n       i = tmp; n     } n     if (flag) { n       while (!Q.empty()) { n         printf( %c , Q.top()); n         Q.pop(); n       } n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const double PI = acos(-1); n long long power(long long x, long long y) { n   if (y == 0) n     return 1; n   else if (y == 1) n     return x; n   long long r = power(x, y / 2); n   if (y % 2 == 0) n     return (r * r); n   else n     return (r * r * x); n } n bool primechecker(long long i) { n   bool valid = true; n   for (int j = 2; j <= sqrt(i); j++) { n     if (i % j == 0) { n       valid = false; n       break; n     } n   } n   if (valid && i != 1) n     return true; n   else n     return false; n } n vector<bool> prime(10000001, true); n void sieveprime() { n   prime[0] = false; n   prime[1] = false; n   for (int i = 2; i < prime.size(); i++) { n     if (prime[i] == true) { n       for (int j = i + i; j <= 10000000; j += i) prime[j] = false; n     } n   } n   return; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     long long a, b; n     cin >> a >> b; n     cout << (a ^ b) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 205; n int n, siz[N], s[N][N], ori[N][N], tot[N], pos[N]; n vector<int> ans; n int read() { n   int x = 0, f = 1; n   char s; n   while ((s = getchar()) >  9  || s <  0 ) n     if (s ==  - ) f = -1; n   while (s >=  0  && s <=  9 ) n     x = (x << 1) + (x << 3) + (s ^ 48), s = getchar(); n   return x * f; n } n bool ok() { n   for (int i = 1; i <= n; ++i) n     if (tot[i]) return 0; n   return 1; n } n bool check() { n   int maxx; n   for (int i = 1; i <= n; ++i) pos[ans[n - i]] = i; n   for (int i = 1; i < n; ++i) { n     maxx = 0; n     for (int j = 1; j <= n; ++j) tot[j] = 0; n     for (int j = 1; j <= siz[i]; ++j) n       maxx = max(maxx, pos[ori[i][j]]), ++tot[ori[i][j]]; n     if (maxx - siz[i] + 1 < 1) return 0; n     for (int j = maxx; j >= maxx - siz[i] + 1; --j) n       if (!tot[ans[n - j]]) return 0; n   } n   return 1; n } n int main() { n   int x, sum; n   bool flag; n   for (int T = read(); T; --T) { n     n = read(); n     for (int i = 1; i < n; ++i) { n       siz[i] = read(); n       for (int j = 1; j <= siz[i]; ++j) ori[i][j] = read(); n     } n     for (int num = 1; num <= n; ++num) { n       ans.clear(); n       flag = 0; n       for (int i = 1; i < n; ++i) { n         for (int j = 1; j <= siz[i]; ++j) { n           s[i][j] = ori[i][j]; n           if (s[i][j] == num) s[i][j] = 0; n         } n       } n       while (233) { n         sum = 0; n         for (int i = 0; i <= n; ++i) tot[i] = 0; n         for (int i = 1; i < n; ++i) n           for (int j = 1; j <= siz[i]; ++j) ++tot[s[i][j]]; n         for (int i = 1; i <= n; ++i) n           if (tot[i] == 1) ++sum, x = i; n         if (ok()) break; n         if (sum != 1) { n           flag = 1; n           break; n         } n         ans.push_back(x); n         bool f; n         for (int i = 1; i < n; ++i) { n           f = 0; n           for (int j = 1; j <= siz[i]; ++j) n             if (s[i][j] == x) { n               f = 1; n               break; n             } n           if (f) n             for (int j = 1; j <= siz[i]; ++j) s[i][j] = 0; n         } n       } n       if (!flag) { n         ans.push_back(num); n         if (check()) break; n       } n     } n     for (int i = ans.size() - 1; ~i; --i) printf( %d  , ans[i]); n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n inline void DoNothing() {} n template <typename T> n inline T Abs(const T a) { n   return a < 0 ? -a : a; n } n template <typename T> n inline T Min(const T a, const T b) { n   return a < b ? a : b; n } n template <typename T> n inline T Max(const T a, const T b) { n   return a > b ? a : b; n } n static const long double eps = 1.0e-07; n template <typename T> n inline T IsEqual(const T a, const T b) { n   return Abs(a - b) < eps; n } n template <typename T> n inline T IsGreater(const T a, const T b) { n   return a > b + eps; n } n template <typename T> n inline T IsLess(const T a, const T b) { n   return a + eps < b; n } n template <typename T> n inline void Print(const T& val) { n   std::cout << val <<    ; n } n template <typename T> n inline std::string ToStr(const T& val) { n   std::ostringstream ostr; n   ostr << val; n   return ostr.str(); n } n template <typename T> n inline bool FromStr(const std::string& str, T& val) { n   std::istringstream istr(str); n   istr >> val; n   return !!istr; n } n struct Rand { n   unsigned long z_, w_; n   unsigned long get32() { n     z_ = 36969 * (z_ & 65535) + (z_ >> 16); n     w_ = 18000 * (w_ & 65535) + (w_ >> 16); n     return (z_ << 16) + (w_ & 65535); n   } n   void Reset() { n     z_ = 1; n     w_ = 1; n   } n   Rand() { Reset(); } n }; n template <typename T> n inline std::vector<std::vector<T> > CreateVector2d(const size_t rowCnt, n                                                    const size_t colCnt) { n   return std::vector<std::vector<T> >(rowCnt, std::vector<T>(colCnt)); n } n void Prepare(); n class StopWatchEx { n  public: n   StopWatchEx(); n   ~StopWatchEx(); n  n  private: n   struct Data; n   Data* pData; n }; n inline double CalcRk(const double rb, const double rs, size_t k) { n   const double i_ds = 1 / (2 * rs); n   const double i_db = 1 / (2 * rb); n   const double i_d = i_ds - i_db; n   const double i_xc = i_db + i_d / 2; n   const double i_yc = i_d * (double)(k); n   const double i_c = sqrt(i_yc * i_yc + i_xc * i_xc); n   const double z1 = 1 / (i_c - i_d / 2); n   const double z2 = 1 / (i_c + i_d / 2); n   const double rk = (z1 - z2) / 2; n   return rk; n } n bool Solve(bool bCheckInputStream = false) { n   size_t n; n   std::cin >> n; n   if (bCheckInputStream && !std::cin) { n     return false; n   } n   StopWatchEx _sw; n   for (size_t i = 0; i < n; i++) { n     size_t rb, rs, k; n     std::cin >> rb >> rs >> k; n     const double rk = CalcRk((double)rb, (double)rs, k); n     std::cout << std::setprecision(8) << std::setw(12) << rk << std::endl; n   } n   return true; n } n int main() { n   Prepare(); n   Solve(); n } n struct StopWatchEx::Data {}; n StopWatchEx::StopWatchEx() {} n StopWatchEx::~StopWatchEx() {} n void Prepare() {} n


#include <bits/stdc++.h> n using namespace std; n int sumb[64]; n int xorb[64]; n long long s, r; n int maxx = 0; n void bits() { n   int i = 0; n   long long bf = s; n   while (bf) { n     sumb[i] = bf % 2; n     ++i; n     bf /= 2; n   } n   maxx = i; n   bf = r; n   i = 0; n   while (bf) { n     xorb[i] = bf % 2; n     ++i; n     bf /= 2; n     maxx = max(maxx, i); n   } n } n long long ansv[2][65][2][2]; n bool ch[2][65][2][2]; n long long calc(int ost, int pos, int f1, int f2) { n   if (ch[ost][pos][f1][f2]) { n     return ansv[ost][pos][f1][f2]; n   } n   ch[ost][pos][f1][f2] = 1; n   if (pos >= 64) { n     if (ost == 0 && f1 == f2 && f2 == 1) { n       return 1; n     } else { n       return 0; n     } n   } n   long long ans = 0; n   for (long long(x1) = 0; (x1) < (2); ++(x1)) { n     for (long long(x2) = 0; (x2) < (2); ++(x2)) { n       long long p; n       if ((x1 + x2 + ost) % 2 == sumb[pos] && n           ((x1 == x2 && 0 == xorb[pos]) || (x1 != x2 && 1 == xorb[pos]))) { n         p = calc(((x1 + x2 + ost) > 1), pos + 1, (x1 != 0) || f1, n                  (x2 != 0) || f2); n         ans += p; n       } n     } n   } n   return ansv[ost][pos][f1][f2] = ans; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> s >> r; n   bits(); n   cout << calc(0, 0, 0, 0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long add(long long a, long long b) { n   return ((a % 1000000007LL) + (b % 1000000007LL)) % 1000000007LL; n } n inline long long mul(long long a, long long b) { n   return ((a % 1000000007LL) * (b % 1000000007LL)) % 1000000007LL; n } n inline long long sub(long long a, long long b) { n   return ((a % 1000000007LL) - (b % 1000000007LL) + 1000000007LL) % n          1000000007LL; n } n long long dp[1001][2001]; n long long findAns(long long i, long long j, long long n, long long k, n                   long long a[], long long key[], long long p) { n   if (i == n) { n     return 0; n   } n   if (j >= k) { n     return -1000000000000000000LL; n   } n   if (dp[i][j] != -1) { n     return dp[i][j]; n   } n   long long ret; n   long long ret1 = findAns(i, j + 1, n, k, a, key, p); n   long long ret2 = findAns(i + 1, j + 1, n, k, a, key, p); n   if (ret1 == -1000000000000000000LL && ret2 == -1000000000000000000LL) { n     ret = -1000000000000000000LL; n   } else if (ret1 == -1000000000000000000LL) { n     ret = max(abs(a[i] - key[j]) + abs(key[j] - p), ret2); n   } else if (ret2 == -1000000000000000000LL) { n     ret = ret1; n   } else { n     ret = min(ret1, max(abs(a[i] - key[j]) + abs(key[j] - p), ret2)); n   } n   return dp[i][j] = ret; n } n void Flash() { n   long long n, k, p; n   cin >> n >> k >> p; n   long long a[n]; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n   } n   long long key[k]; n   for (long long i = 0; i < k; i++) { n     cin >> key[i]; n   } n   sort(a, a + n), sort(key, key + k); n   memset(dp, -1, sizeof(dp)); n   long long ans = findAns(0, 0, n, k, a, key, p); n   cout << ans <<   n ; n } n int main(int argc, char const *argv[]) { n   ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); n   ; n   long long t = 1; n   for (long long i = 1; i <= t; i++) { n     Flash(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000007; n int v[N]; n vector<int> pos[N]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> v[i]; n     pos[v[i]].push_back(i); n   } n   for (int i = 0; i < N; ++i) { n     reverse(pos[i].begin(), pos[i].end()); n   } n   set<int> s; n   long long cnt = 0; n   for (int i = 0; i < n; ++i) { n     s.insert(v[i]); n     cnt += s.size(); n   } n   long long ans = 2ll * cnt; n   long long cur = 0; n   for (int l = 0; l < n; ++l) { n     int x = v[l]; n     pos[x].pop_back(); n     int j = n; n     if (pos[x].size()) j = pos[x].back(); n     cnt -= 1; n     cnt -= (j - l - 1); n     ans += 2ll * cnt; n   } n   ans -= n; n   cout << fixed << setprecision(10) n        << (ans / (1.0 * ((long long)n * (long long)n))) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   int n, m; n   cin >> n >> m; n   vector<string> xs(n); n   for (int i = 0; i < n; i++) cin >> xs[i]; n   int cur = 0; n   int curB = 0; n   set<int> ans; n   for (int i = 0; i < xs.size() - 1; i++) { n     int j = 0; n     while (j < xs[i].size()) { n       if (xs[i][j] != xs[i + 1][j] && !ans.count(j)) { n         break; n       } n       j++; n     } n     if (j < m && xs[i][j] > xs[i + 1][j]) { n       ans.insert(j); n       i = -1; n     } n   } n   cout << ans.size(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int num = 200001; n long long a[401]; n int main() { n   int t, n; n   cin >> t; n   int str, cur; n   int fl = 0; n   while (t--) { n     cin >> n; n     for (int i = 0; i < n; i++) cin >> a[i]; n     for (int i = 0; i < n; i++) a[n + i] = a[i]; n     cur = 2 * n; n     int first = 1; n     for (int i = 0; i < cur; i++) { n       if (a[i] == first) { n         first++; n       } else { n         first = 1; n       } n       if (first == n) { n         fl = 1; n         break; n       } n     } n     first = n; n     for (int i = 0; i < cur; i++) { n       if (a[i] == first) n         first--; n       else n         first = n; n       if (first == 1) { n         fl = 1; n         break; n       } n     } n     if (fl) n       cout <<  YES n ; n     else n       cout <<  NO n ; n     fl = 0; n     for (int i = 0; i < cur; i++) a[i] = 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int pw = 1 << 17; n const int maxn = 1e5 + 20; n int ans[maxn]; n void work() { n   int n, x; n   cin >> n >> x; n   if (n == 1) { n     printf( YES n ); n     cout << x << endl; n     return; n   } else if (n == 2 && x == 0) { n     printf( NO n ); n     return; n   } n   printf( YES n ); n   int t = x; n   for (int i = 0; i < n; ++i) ans[i] = i; n   for (int i = 0; i < n - 1; ++i) { n     t ^= ans[i]; n   } n   if (t <= n - 2) { n     ans[t] ^= pw; n     if (t == n - 2) n       ans[t - 1] ^= pw; n     else if (t == 0) n       ans[t + 1] ^= pw; n     else n       ans[t + 1] ^= pw; n   } n   ans[n - 1] = t; n   int res = 0; n   for (int i = 0; i < n; ++i) { n     printf( %d  , ans[i]); n     res ^= ans[i]; n   } n } n int main() { n   work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   set<int> st; n   int x; n   int sz = 0; n   for (int i = 0; i < n; i++) { n     cin >> x; n     if (sz > 3) continue; n     if (st.find(x) == st.end()) { n       sz++; n       st.insert(x); n     } n   } n   if (sz > 3) n     cout <<  NO  << endl; n   else if (sz < 3) n     cout <<  YES  << endl; n   else { n     auto it = st.begin(); n     int a, b, c; n     a = *it; n     it++; n     b = *it; n     it++; n     c = *it; n     if (b - a == c - b) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char a[105]; n char temp[105]; n int main() { n   int n; n   scanf( %d%*c , &n); n   while (n--) { n     int cnt = 0; n     bool flag = false; n     bool first = false; n     gets(a); n     int len = strlen(a); n     for (int i = len - 5; i <= len; i++) temp[cnt++] = a[i]; n     if (strncmp(a,  miao. , 5) == 0) first = true; n     if (strcmp(temp,  lala. ) == 0) flag = true; n     if (first && !flag) n       printf( Rainbow s n ); n     else if (!first && flag) n       printf( Freda s n ); n     else n       printf( OMG>.< I don t know! n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int X = 100000 + 5; n long long C[1005][1005]; n long long n, m; n long long iis, ii, jjs, jj, cc; n void calc() { n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cc += C[i][j]; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       ii += C[i][j] * (i * 4 + 2); n       iis += (i * 4 + 2) * (i * 4 + 2) * C[i][j]; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       jj += C[i][j] * (j * 4 + 2); n       jjs += (j * 4 + 2) * (j * 4 + 2) * C[i][j]; n     } n   } n } n long long dist(long long x, long long y) { n   x *= 4; n   y *= 4; n   long long s = iis + x * x * cc - 2 * x * ii + jjs + y * y * cc - 2 * y * jj; n   return s; n } n long long foo(long long x, long long& z) { n   long long lo = 0, hi = m, mm = LLONG_MAX; n   while (lo + 2 < hi) { n     long long ml = lo + (hi - lo) / 3, mr = hi - (hi - lo) / 3; n     long long l = dist(x, ml), r = dist(x, mr); n     if (l <= r) n       hi = mr; n     else n       lo = ml; n   } n   for (int i = 0; i <= 2; i++) { n     long long cc = dist(x, lo + i); n     if (cc < mm) { n       mm = cc; n       z = lo + i; n     } n   } n   return mm; n } n void MAIN() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> C[i][j]; n     } n   } n   calc(); n   long long mm = LLONG_MAX, xx = -1, yy = -1; n   for (int i = 0; i <= n; i++) { n     for (int j = 0; j <= m; j++) { n       long long z = dist(i, j); n       if (z < mm) { n         mm = z; n         xx = i; n         yy = j; n       } n     } n   } n   cout << mm <<   n  << xx <<     << yy; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout << setprecision(12); n   MAIN(); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int n, q, adj[4][200123]; n int vis[4][200123]; n void show() { n   for (int i = 1; i <= 2; ++i) { n     for (int j = 1; j <= n; ++j) { n       cout << adj[i][j] <<    ; n     } n     cout << endl; n   } n } n int dfs(int i, int j, char v) { n   if (i == 2 and (j == (n + 1))) return 1; n   if (i <= 0 or i > 2 or j <= 0 or j > n) return 0; n   if (vis[i][j]) return 0; n   vis[i][j] = 1; n   if ((adj[i][j] == 1 or adj[i][j] == 2) and (v ==  e )) { n     return dfs(i, j + 1,  e ); n   } else if (adj[i][j] == 1 or adj[i][j] == 2) { n     return 0; n   } n   if (v ==  e ) { n     return dfs(i + 1, j,  c ) or dfs(i - 1, j,  b ); n   } else if (v ==  c ) { n     return dfs(i, j + 1,  e ); n   } else if (v ==  b ) { n     return dfs(i, j + 1,  e ); n   } n   return 0; n } n int main() { n   ios_base::sync_with_stdio(0); n   char c; n   string s; n   cin >> q; n   while (q--) { n     cin >> n; n     cin >> s; n     for (int i = 0; i < n; ++i) { n       adj[1][i + 1] = s[i] -  0 ; n     } n     cin >> s; n     for (int i = 0; i < n; ++i) { n       adj[2][i + 1] = s[i] -  0 ; n     } n     cout << (dfs(1, 1,  e ) ?  YES n  :  NO n ); n     for (int i = 1; i <= 2; ++i) { n       for (int j = 1; j <= n; ++j) { n         vis[i][j] = 0; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef struct edge { n   int a; n   int b; n   int c; n }; n int n, m; n edge roads[10000]; n vector<int> out[200]; n double matrix[200][200]; n double const eps = 1e-10; n double val[200]; n bool isZero(double r) { return r < eps && r > -eps; } n void flip(int r1, int r2) { n   for (int i = 1; i <= n; i++) { n     double fill = matrix[r1][i]; n     matrix[r1][i] = matrix[r2][i]; n     matrix[r2][i] = fill; n   } n } n void scale(int r1, double c) { n   for (int i = 1; i <= n; i++) { n     matrix[r1][i] *= c; n   } n } n void add(int r1, int r2, double c) { n   for (int i = 1; i <= n; i++) { n     matrix[r1][i] += matrix[r2][i] * c; n   } n } n void solve_system() { n   for (int cur = 2; cur <= n - 1; cur++) { n     int i; n     for (i = cur; i <= n - 1; i++) { n       if (!isZero(matrix[i][cur])) { n         swap(i, cur); n         break; n       } n     } n     if (i == n) continue; n     scale(cur, 1 / matrix[cur][cur]); n     for (int j = cur + 1; j <= n - 1; j++) { n       if (!isZero(matrix[j][cur])) { n         add(j, cur, -matrix[j][cur]); n       } n     } n   } n   for (int cur = n - 1; cur >= 2; cur--) { n     if (isZero(matrix[cur][cur])) n       continue; n     else { n       val[cur] = -matrix[cur][1]; n     } n     for (int j = cur - 1; j >= 2; j--) { n       add(j, cur, -matrix[j][cur]); n     } n   } n } n void set_up() { n   for (int i = 0; i < 200; i++) { n     val[i] = 0; n     for (int j = 0; j < 200; j++) { n       matrix[i][j] = 0; n     } n   } n   val[1] = 1; n   for (int i = 2; i <= n - 1; i++) { n     matrix[i][i] = out[i].size(); n     for (int j = 0; j < out[i].size(); j++) { n       matrix[i][out[i][j]] -= 1; n     } n   } n } n void print_mat() { n   for (int i = 2; i <= n - 1; i++) { n     for (int j = 1; j <= n; j++) { n       printf( %f  , matrix[i][j]); n     } n     printf(  n ); n   } n } n int main() { n   scanf( %d , &n); n   scanf( %d , &m); n   for (int i = 0; i < m; i++) { n     scanf( %d %d %d , &roads[i].a, &roads[i].b, &roads[i].c); n     out[roads[i].a].push_back(roads[i].b); n     out[roads[i].b].push_back(roads[i].a); n   } n   set_up(); n   solve_system(); n   double scale = 1e10; n   for (int i = 0; i < m; i++) { n     double dif = val[roads[i].a] - val[roads[i].b]; n     if (isZero(dif)) n       continue; n     else { n       scale = min(scale, abs(roads[i].c / dif)); n     } n   } n   double total = 0; n   for (int i = 0; i < out[1].size(); i++) { n     total += val[1] - val[out[1][i]]; n   } n   printf( %.10f n , total * scale); n   for (int i = 0; i < m; i++) { n     double dif = val[roads[i].a] - val[roads[i].b]; n     printf( %.10f n , scale * dif); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long a[1000005]; n int main() { n   int n; n   cin >> n; n   multiset<long long> s; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     s.insert(a[i]); n   } n   long long ans = 1e9; n   for (int i = 1; i <= n; i++) { n     s.erase(s.find(a[i])); n     long long mi = *s.begin(); n     auto it = s.end(); n     it--; n     long long ma = *it; n     ans = min(ans, ma - mi); n     s.insert(a[i]); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC target( avx,avx2,fma ) n #pragma GCC optimization( O8 ) n #pragma GCC optimization( unroll-loops ) n using namespace std; n const long long int N = 60 + 5, mod = 1e9 + 7, inf = 1e12, maxq = 5e5 + 30, n                     maxm = 1e3 + 30; n const long double eps = 0.0000001; n long long int poww(long long int a, long long int b) { n   return (!b ? 1 n              : (b & 1 ? a * poww(a * a % mod, b / 2) % mod n                       : poww(a * a % mod, b / 2) % mod)); n } n int mat[N][N][N]; n int dp[maxm][N][N]; n int d[N][N][N][N]; n int n, m, r; n int main() { n   ios ::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   memset(d, 63, sizeof d); n   cin >> n >> m >> r; n   for (int i = 1; i < m + 1; i++) n     for (int j = 1; j < n + 1; j++) n       for (int k = 1; k < n + 1; k++) cin >> mat[i][j][k]; n   for (int i = 1; i < n + 1; i++) n     for (int j = 1; j < n + 1; j++) n       for (int k = 1; k < m + 1; k++) d[0][i][j][k] = mat[k][i][j]; n   for (int k = 1; k < n + 1; k++) n     for (int i = 1; i < n + 1; i++) n       for (int j = 1; j < n + 1; j++) { n         if (i != j) { n           for (int x = 1; x < m + 1; x++) { n             d[k][i][j][x] = n                 min(d[k - 1][i][j][x], d[k - 1][i][k][x] + d[k - 1][k][j][x]); n           } n         } n       } n   for (int i = 1; i < n + 1; i++) n     for (int j = 1; j < n + 1; j++) { n       if (i != j) { n         for (int k = 1; k < m + 1; k++) { n           if (k > 1) { n             if (dp[0][i][j] > d[n][i][j][k]) dp[0][i][j] = d[n][i][j][k]; n           } else n             dp[0][i][j] = d[n][i][j][k]; n         } n       } else n         dp[0][i][j] = 0; n     } n   for (int k = 1; k < 1001; k++) { n     for (int i = 1; i < n + 1; i++) { n       for (int j = 1; j < n + 1; j++) { n         dp[k][i][j] = dp[k - 1][i][j]; n         if (i == j) continue; n         for (int y = 1; y < n + 1; y++) n           if (dp[k - 1][i][y] + dp[0][y][j] < dp[k][i][j]) n             dp[k][i][j] = dp[k - 1][i][y] + dp[0][y][j]; n       } n     } n   } n   int x, y, z; n   for (int i = 0; i < r; i++) { n     cin >> x >> y >> z; n     cout << dp[z][x][y] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, odd, up, down; n   odd = up = down = 0; n   cin >> n; n   int a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] % 2 != 0) odd++; n   } n   for (int i = 0; i < n; i++) { n     if (a[i] % 2 == 0) n       cout << a[i] / 2 << endl; n     else { n       int x; n       if (up < odd / 2) { n         if (a[i] > 0) n           cout << (a[i] / 2 + 1) << endl; n         else n           cout << (a[i] / 2) << endl; n         up++; n       } else { n         if (a[i] > 0) n           cout << (a[i] / 2) << endl; n         else n           cout << (a[i] / 2 - 1) << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 500005; n int n, K, a[N]; n long long checkl(int x) { n   long long sum = 0; n   for (int i = 0; i < n; ++i) { n     sum += max(0, x - a[i]); n   } n   return sum; n } n long long checkr(int x) { n   long long sum = 0; n   for (int i = 0; i < n; ++i) { n     sum += max(0, a[i] - x); n   } n   return sum; n } n int main() { n   scanf( %d%d , &n, &K); n   long long sum = 0; n   for (int i = 0; i < n; ++i) { n     scanf( %d , &a[i]); n     sum += a[i]; n   } n   sort(a, a + n); n   int l = 0, r = 1e9; n   while (l < r) { n     int m = l + r + 1 >> 1; n     if (checkl(m) <= K) { n       l = m; n     } else { n       r = m - 1; n     } n   } n   int L = l; n   l = 0, r = 1e9; n   while (l < r) { n     int m = l + r >> 1; n     if (checkr(m) <= K) { n       r = m; n     } else { n       l = m + 1; n     } n   } n   int R = r; n   printf( %d n , max(R - L, sum % n == 0 ? 0 : 1)); n } n


#include <bits/stdc++.h> n using namespace std; n int prior(string a) { n   if (a ==  rat ) { n     return 0; n   } else if (a ==  woman  || a ==  child ) { n     return 1; n   } else if (a ==  man ) { n     return 2; n   } else n     return 3; n } n int main() { n   int n, i, j; n   int k[4] = {0}; n   string b[4][100]; n   cin >> n; n   string a[100][2]; n   for (i = 0; i < n; i++) { n     cin >> a[i][0] >> a[i][1]; n   } n   for (i = 0; i < n; i++) { n     b[prior(a[i][1])][k[prior(a[i][1])]] = a[i][0]; n     k[prior(a[i][1])]++; n   } n   for (i = 0; i < 4; i++) { n     for (j = 0; j < k[i]; j++) { n       cout << b[i][j] << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, k1, k2; n   cin >> n >> m >> k1 >> k2; n   if (n > m) { n     cout <<  First  << endl; n   } else { n     cout <<  Second  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char const *argv[]) { n   int n; n   cin >> n; n   getchar(); n   string s; n   cin >> s; n   int ans = 1000000; n   string cnt =   ; n   for (int i = 0; i < n; ++i) { n     cnt += s[i]; n     string s1 = cnt; n     string s2 = s.substr(i + 1, i + 1); n     if (s1 == s2) { n       int x = (n - 2 * (i + 1)) + 1 + i + 1; n       if (ans > x) { n         ans = x; n       } n     } n   } n   printf( %d n , min(ans, n)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   vector<int> a(n); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   long long ans = 0; n   for (int rep = 0; rep < 2; rep++) { n     for (int r = 2; r < n; r++) { n       long long sum = a[r - 1]; n       for (int l = r - 2; l >= 0; l--) { n         if (a[l] < a[r] && sum == (a[l] ^ a[r])) { n           ans++; n         } n         sum += a[l]; n         if (__builtin_clzll(sum) < __builtin_clzll(a[r])) { n           break; n         } n       } n     } n     if (rep == 0) { n       reverse(a.begin(), a.end()); n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n  n using namespace std; n  n int main() n { n     int t; n     cin>>t; n     while(t--) n     { n         int n; n         cin>>n; n         int a[n],b[n],sum=0,sum2=0; n         vector<int>v1; n         vector<int>v2; n         for(int i=0;i<n;i++) n         { n             cin>>a[i]; n             sum+=a[i]; n         } n         for(int i=0;i<n;i++) n         { n             cin>>b[i]; n             sum2+=b[i]; n         } n         if(sum==sum2){ n         for(int i=0;i<n;i++) n         { n             if(a[i]>b[i]) n             { n                 for(int j=0;j<a[i]-b[i];j++) n                     v1.push_back(i+1); n             } n             if(b[i]>a[i]) n             { n                 for(int j=0;j<b[i]-a[i];j++) n                     v2.push_back(i+1); n             } n         } n         cout<<v1.size()<<endl; n         for(int i=0;i<v1.size();i++) n             cout<<v1[i]<<   <<v2[i]<<endl; n         } n         else n             cout<< -1 <<endl; n     } n } n


#include <bits/stdc++.h> n using namespace std; n long long ans, p, s; n int N; n struct node { n   int a[2]; n   node *L, *R; n   node() { n     a[0] = a[1] = 0; n     L = R = NULL; n   } n   void add() { n     if (L == NULL) L = new node(); n     if (R == NULL) R = new node(); n   } n }; n void update(node *no, long long x, int h, int inc) { n   no->add(); n   if (h < 0) return; n   if (!(x & (1LL << h))) n     no->a[0]++, update(no->L, x, h - 1, inc); n   else n     no->a[1]++, update(no->R, x, h - 1, inc); n } n long long query(node *no, long long x, int h) { n   if (h < 0) return 0; n   no->add(); n   if (!(x & (1LL << h)) && no->a[1]) return (1LL << h) + query(no->R, x, h - 1); n   if ((x & (1LL << h)) && no->a[0]) return (1LL << h) + query(no->L, x, h - 1); n   if (no->a[0]) return query(no->L, x, h - 1); n   if (no->a[1]) return query(no->R, x, h - 1); n   return 0LL; n } n int main(int argc, char **argv) { n   node *no; n   no = new node(); n   scanf( %d , &N); n   vector<long long> a(N); n   for (auto &x : a) scanf( %I64d , &x); n   update(no, s, 42, 1); n   for (int i = (N - 1); i >= (0); i--) { n     s ^= a[i]; n     ans = max(ans, s); n     update(no, s, 42, 1); n   } n   for (int i = (0); i < (N); i++) { n     p ^= a[i]; n     s ^= a[i]; n     update(no, s, 42, -1); n     ans = max(ans, query(no, p, 42)); n     ans = max(ans, p); n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long fn(long long x) { n   long long ret = (x * (x + 1)) / 2; n   if (x < 0) ret = 0; n   return ret; n } n long long fn(long long R, long long K1, long long K2) { n   long long ret = 0; n   K1 = min(K1, R - 1); n   K2 = min(K2, R); n   if (R - K1 >= K2) return ((K1 + 1) * K2); n   ret -= fn(R - K1 - 1); n   ret += fn(K2); n   ret += (R - K2) * K2; n   return ret; n } n long long N, X, Y, C; n long long bin(long long start, long long end) { n   if (start > end) return start; n   long long mid = (start + end) / 2; n   long long ret = 1, foo = 0; n   foo = fn(mid, N - X, N - Y); n   ret += foo; n   foo = fn(mid, N - Y, X - 1); n   ret += foo; n   foo = fn(mid, X - 1, Y - 1); n   ret += foo; n   foo = fn(mid, Y - 1, N - X); n   ret += foo; n   if (ret >= C) n     return bin(start, mid - 1); n   else n     return bin(mid + 1, end); n } n inline void ReadInput(void) { n   scanf( %lld , &N); n   scanf( %lld , &X); n   scanf( %lld , &Y); n   scanf( %lld , &C); n } n inline void solve(void) { n   if (C == 1) n     cout << 0 << endl; n   else n     cout << bin(1, 2 * N) << endl; n } n inline void Refresh(void) {} n int main() { n   ReadInput(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN(2e5 + 10); n typedef int i_N[maxN]; n int N, K; n namespace graph { n i_N A, P, is_us, Cus, deg; n pair<int, int> edge[maxN]; n vector<int> adj[maxN], node[maxN]; n void link(const int u, const int v) { adj[u].push_back(v); } n void dfs(const int u) { n   for (int i = 0; i < (int)adj[u].size(); i++) { n     const int v(adj[u][i]); n     if (P[v]) continue; n     P[v] = u; n     dfs(v); n     Cus[u] += Cus[v]; n   } n   Cus[u] += is_us[u]; n } n }  // namespace graph n int main() { n   ios_base::sync_with_stdio(0); n   { n     using namespace graph; n     cin >> N >> K; n     for (int i = 0; i < K * 2; i++) cin >> A[i], is_us[A[i]] = 1; n     for (int i = 0; i < N - 1; i++) { n       int u, v; n       cin >> u >> v; n       edge[i] = pair<int, int>(u, v); n       link(u, v); n       link(v, u); n     } n   } n   { n     using namespace graph; n     P[1] = -1; n     dfs(1); n   } n   { n     using namespace graph; n     for (int i = 0; i < N - 1; i++) { n       const int v(P[edge[i].first] == edge[i].second ? edge[i].first n                                                      : edge[i].second); n       const int u(P[v]); n       if (Cus[v] && 2 * K - Cus[v]) deg[u]++, deg[v]++; n     } n     long long ans(0); n     queue<int> bfs_node; n     for (int u = 1; u <= N; u++) n       if (deg[u] == 1) node[1].push_back(u); n     for (int i = 1; i <= 2 * K; i++) { n       for (int j = 0; j < (int)node[i].size(); j++) { n         const int u(node[i][j]); n         deg[u] = 0; n         for (int k = 0; k < (int)adj[u].size(); k++) { n           const int v(adj[u][k]); n           if (!deg[v]) continue; n           ans += is_us[u]; n           deg[v]--; n           is_us[v] += is_us[u]; n           if (deg[v] == 1) node[is_us[v]].push_back(v); n         } n       } n     } n     cout << ans; n   } n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const ll mod = 1e18 + 7; n void solve() { n   int n, k; n   cin >> n >> k; n   string s; n   cin >> s; n   for (int i = 0; i < k; i++) { n     int z = 0, one = 0, j = i + k; n     for (j; j < n; j += k) { n       if (s[j] ==  1 ) n         one++; n       else if (s[j] ==  0 ) n         z++; n     } n     if (one > 0 && z > 0) { n       cout <<  NO n ; n       return; n     } n     if ((one > 0 && s[i] ==  0 ) || (z > 0 && s[i] ==  1 )) { n       cout <<  NO n ; n       return; n     } n     if (one > 0) { n       j = i; n       for (j; j < n; j += k) { n         s[j] =  1 ; n       } n     } else if (z > 0) { n       j = i; n       for (j; j < n; j += k) { n         s[j] =  0 ; n       } n     } n   } n   int z = 0, one = 0; n   for (int i = 0; i < k; i++) { n     if (s[i] ==  0 ) n       z++; n     else if (s[i] ==  1 ) n       one++; n   } n   if (one > k / 2 || z > k / 2) { n     cout <<  NO n ; n   } else n     cout <<  YES n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   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 const int N = 520; n long long gi() { n   long long x = 0, o = 1; n   char ch = getchar(); n   while (!isdigit(ch) && ch !=  - ) ch = getchar(); n   if (ch ==  - ) o = -1, ch = getchar(); n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar(); n   return x * o; n } n int k, n, t, x[N], y[N]; n long long a[N][N], b[N][N]; n int main() { n   cin >> k; n   n = 1 << k; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) a[i][j] = gi(); n   cin >> t; n   for (int i = 1; i <= t; i++) x[i] = gi(), y[i] = gi(); n   for (int i = t; i; i--) n     x[i] = (x[i] - x[1] + n) % n, y[i] = (y[i] - y[1] + n) % n; n   for (int i = 1; i <= k; i++) { n     for (int j = 0; j < n; j++) n       for (int k = 0; k < n; k++) n         for (int l = 1; l <= t; l++) n           b[j][k] ^= a[(j - x[l] + n) % n][(k - y[l] + n) % n]; n     memcpy(a, b, sizeof(b)); n     memset(b, 0, sizeof(b)); n     for (int j = 1; j <= t; j++) x[j] = x[j] * 2 % n, y[j] = y[j] * 2 % n; n   } n   int ans = 0; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) n       if (a[i][j]) ++ans; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long x = 0; n   bool f = false; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = true; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = (x << 3) + (x << 1) + (c ^  0 ); n     c = getchar(); n   } n   return f ? -x : x; n } n inline void write(long long x) { n   if (x < 0) putchar( - ), x = -x; n   if (x > 9) write(x / 10); n   putchar(x % 10 +  0 ); n } n long long n, k, a[101], b[101][101], ans, cnt1, cnt2; n signed main() { n   n = read(); n   k = read(); n   for (register long long i = 0; i < n; ++i) n     a[i] = read(), b[i / k][i % k] = a[i]; n   for (register long long i = 0; i < k; ++i) { n     cnt1 = cnt2 = 0; n     for (register long long j = 0; j < n / k; ++j) n       b[j][i] == 1 ? ++cnt1 : ++cnt2; n     ans += min(cnt1, cnt2); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int pointer; n vector<long long> M; n vector<long long> B; n bool bad(int l1, int l2, int l3) { n   double x_12 = double(B[l2] - B[l1]) / double(M[l1] - M[l2]); n   double x_13 = double(B[l3] - B[l1]) / double(M[l1] - M[l3]); n   return x_13 < x_12; n } n void add(long long m, long long b) { n   M.push_back(m); n   B.push_back(b); n   while (M.size() >= 3 && bad(M.size() - 3, M.size() - 2, M.size() - 1)) { n     M.erase(M.end() - 2); n     B.erase(B.end() - 2); n   } n } n long long query(long long x) { n   if (pointer > M.size()) pointer = M.size() - 1; n   while (pointer < M.size() - 1 && n          M[pointer + 1] * x + B[pointer + 1] < M[pointer] * x + B[pointer]) n     pointer++; n   return M[pointer] * x + B[pointer]; n } n int main() { n   long long int a[100123]; n   long long int b[100123]; n   int n; n   scanf(  %d , &n); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (int i = 0; i < n; i++) { n     cin >> b[i]; n   } n   long long int cost = 0; n   add(b[0], 0); n   pointer = 0; n   for (int i = 0; i < n; i++) { n     cost = query(a[i]); n     if (i < n) add(b[i], cost); n   } n   cout << cost << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, c = 0, j, x = 0, n; n   cin >> n; n   string s; n   vector<string> ar; n   for (i = 0; i < n; i++) { n     cin >> s; n     ar.push_back(s); n   } n   for (i = 0; i < ar[0].length(); i++) { n     for (j = 0; j < n - 1; j++) { n       if (ar[j][i] != ar[j + 1][i]) { n         x = 1; n         break; n       } n     } n     if (x == 0) n       c++; n     else n       break; n   } n   cout << c; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = (int)((1e5) + 100); n int gcd(int a, int b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n int max(int a, int b) { n   if (a > b) n     return a; n   else n     return b; n } n int min(int a, int b) { n   if (a < b) n     return a; n   else n     return b; n } n void pr(int x) { cout << x; } n void prl(int x) { cout << x <<   n ; } n template <class T> n bool ckmin(T& a, const T& b) { n   return b < a ? a = b, 1 : 0; n } n template <class T> n bool ckmax(T& a, const T& b) { n   return a < b ? a = b, 1 : 0; n } n const int N = 200 * 1000 + 11; n void solve() { n   int q; n   cin >> q; n   std::vector<int> v(N); n   int left = 0, right = 0; n   for (int i = 0; i < q; ++i) { n     string x; n     cin >> x; n     int id; n     cin >> id; n     if (i == 0) { n       v[id] = left; n       left--; n       right++; n     } else { n       if (x ==  L ) { n         v[id] = left; n         left--; n       } else if (x ==  R ) { n         v[id] = right; n         right++; n       } else { n         cout << min(abs(v[id] - left), abs(v[id] - right)) - 1 <<   n ; n       } n     } n   } n } n signed main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n map<pair<int, long long>, int> dp; n int n, s[1000010]; n int calc(pair<int, long long> u) { n   if (dp.count(u) > 0) return dp[u]; n   if (u.first == 0) return dp[u] = 0; n   vector<bool> g(61); n   for (int i = 1; i <= u.first; ++i) { n     if (u.second & (1ll << i)) continue; n     g[calc({u.first - i, u.second | (1ll << i)})] = true; n   } n   int x = 0; n   while (g[x]) ++x; n   return dp[u] = x; n } n int main() { n   scanf( %d , &n); n   int ans = 0; n   for (int i = 0; i < n; ++i) { n     scanf( %d , &s[i]); n     ans = ans ^ calc({s[i], 0}); n   } n   printf( %s n , ans != 0 ?  NO  :  YES ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int r[8192]; n vector<int> g[8192]; n int ans[8192] = { n     0, n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   ans[0] = 1; n   for (int i = 0; i < 8192; i++) { n     g[i].push_back(0); n   } n   for (int i = 0; i < 8192; i++) { n     r[i] = 8192; n   } n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     for (const auto& key : g[x]) { n       int to = (key ^ x); n       ans[to] = 1; n       while (r[to] > x) { n         r[to]--; n         if (r[to] != x) g[r[to]].push_back(to); n       } n     } n     g[x].clear(); n   } n   int cnt = 0; n   for (int i = 0; i < 8192; i++) { n     cnt += ans[i]; n   } n   cout << cnt <<   n ; n   for (int i = 0; i < 8192; i++) { n     if (ans[i]) cout << i <<    ; n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int h = 0; n   int start = 0; n   map<int, int> m; n   set<int> hash; n   for (int i = 0; i < s.size(); ++i) { n     int index = i; n     if (s[i] ==  > ) { n       for (int i = 0; i < 2 * h; ++i) { n         cout <<    ; n       } n       cout << s.substr(start, index - start + 1) << endl; n       hash.insert(index - 1); n       if (s[index - 2] !=  / ) { n         ++h; n       } n       start = index + 1; n     } else if (s[i] ==  / ) { n       --h; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, d; n   while (scanf( %d%d%d%d , &a, &b, &c, &d) != EOF) { n     if (d > 2 * c || d >= b || c > 2 * d) { n       printf( -1 n ); n     } else { n       printf( %d n%d n%d n , 2 * a, 2 * b, max(c, d)); n     } n   } n   return 0; n } n