#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 2e5 + 10; n int a[MAX_N]; n vector<pair<int, int>> scanCuts[2][MAX_N]; n pair<int, int> cuts[MAX_N]; n int tree[2 * MAX_N], d[2 * MAX_N]; n void push(int i) { n   d[2 * i + 1] += d[i]; n   d[2 * i + 2] += d[i]; n   tree[2 * i + 1] += d[i]; n   tree[2 * i + 2] += d[i]; n   d[i] = 0; n } n void pull(int i) { n   tree[i] = min(tree[2 * i + 1], tree[2 * i + 2]); n   tree[i] += d[i]; n } n void build(int i, int l, int r) { n   if (r - l == 1) { n     tree[i] = a[l]; n     return; n   } n   int mid = (l + r) / 2; n   build(2 * i + 1, l, mid); n   build(2 * i + 2, mid, r); n   pull(i); n } n void add(int l, int r, int x, int i, int cl, int cr) { n   if (r <= cl || cr <= l) return; n   if (l <= cl && cr <= r) { n     tree[i] += x; n     d[i] += x; n     return; n   } n   int mid = (cl + cr) / 2; n   add(l, r, x, 2 * i + 1, cl, mid); n   add(l, r, x, 2 * i + 2, mid, cr); n   pull(i); n } n int get(int l, int r, int i, int cl, int cr) { n   if (r <= cl || cr <= l) return +1e9; n   if (l <= cl && cr <= r) return tree[i]; n   int mid = (cl + cr) / 2; n   push(i); n   return min(get(l, r, 2 * i + 1, cl, mid), get(l, r, 2 * i + 2, mid, cr)); n } n void print(int i, int cl, int cr) { n   cout << i <<   (  << cl <<  ;   << cr <<  ) ->   << tree[i] <<     << d[i] n        <<   n ; n   if (cr - cl == 1) return; n   int mid = (cl + cr) / 2; n   print(2 * i + 1, cl, mid); n   print(2 * i + 2, mid, cr); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n, q; n   cin >> n >> q; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   build(0, 0, n); n   set<int> bestAns; n   set<int> currAns; n   for (int i = 0; i < q; ++i) { n     cin >> cuts[i].first >> cuts[i].second; n     --cuts[i].first; n     currAns.insert(i); n     add(cuts[i].first, cuts[i].second, -1, 0, 0, n); n     scanCuts[0][cuts[i].first].push_back({cuts[i].second, i}); n     scanCuts[1][cuts[i].second].push_back({cuts[i].first, i}); n   } n   int ans = 0; n   for (int i = 0; i < n; ++i) { n     for (auto u : scanCuts[0][i]) { n       add(i, u.first, 1, 0, 0, n); n       currAns.erase(u.second); n     } n     for (auto u : scanCuts[1][i]) { n       add(u.first, i, -1, 0, 0, n); n       currAns.insert(u.second); n     } n     int lans = get(i, i + 1, 0, 0, n) - get(0, n, 0, 0, n); n     if (lans > ans) { n       ans = lans; n       bestAns = currAns; n     } n   } n   cout << ans <<   n ; n   cout << bestAns.size() <<   n ; n   for (int u : bestAns) cout << u + 1 <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool isprime(long long n) { n   if (n == 1) return false; n   if (n == 2) return true; n   for (long long i = 2; i <= sqrt(n); i++) { n     if (n % i == 0) { n       return false; n     } n   } n   return true; n } n long long poww(long long b, long long e) { n   if (e == 0) n     return 1; n   else if (e % 2 == 0) { n     long long a = pow(b, e / 2); n     return a * a; n   } else { n     long long a = pow(b, e / 2); n     return b * a * a; n   } n } n long long powm(long long x, long long y, long long m = 1000000007) { n   x = x % m; n   long long res = 1; n   while (y) { n     if (y & 1) res = res * x; n     res %= m; n     y = y >> 1; n     x = x * x; n     x %= m; n   } n   return res; n } n long long modInverse(long long a, long long m = 1000000007) { n   return powm(a, m - 2, m); n } n void print(vector<long long> v) { n   for (long long i = 0; i < v.size(); i++) { n     cout << v[i] <<    ; n   } n } n void print(long long arr[]) { n   long long size = *(&arr + 1) - arr; n   for (long long i = 0; i < size; i++) { n     cout << arr[i] <<    ; n   } n } n string to_bin(long long n) { n   string res =   ; n   long long i = 0; n   while (n > 0) { n     if (n % 2 == 1) { n       res = res +  1 ; n     } else { n       res = res +  0 ; n     } n     n /= 2; n     i++; n   } n   reverse(res.begin(), res.end()); n   return res; n } n long long to_dec(string second) { n   long long n = second.size(), ans = 0, temp = 1; n   for (long long i = n - 1; i >= 0; i--) { n     long long x = second[i] -  0 ; n     ans += x * temp; n     temp *= 2; n   } n   return ans; n } n void result(bool first) { n   if (first) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n } n void solve() { n   long long a, b, p; n   cin >> a >> b >> p; n   string second; n   cin >> second; n   reverse(second.begin(), second.end()); n   long long n = second.length(); n   long long ind = 1; n   long long maxi; n   for (long long i = 1; i < n; i++) { n     char ch = second[i]; n     if (second[i] ==  B ) { n       if (p >= b) { n         p -= b; n         if (i != n - 1) { n           while (second[i + 1] ==  B ) { n             i++; n           } n         } n         ind = i + 1; n       } else n         break; n     } else if (second[i] ==  A ) { n       if (p >= a) { n         p -= a; n         if (i != n - 1) { n           while (second[i + 1] ==  A ) { n             i++; n           } n         } n         ind = i + 1; n       } else n         break; n     } n   } n   long long ans = n - ind + 1; n   cout << ans << endl; n } n int32_t main() { n   ios_base::sync_with_stdio(); n   cin.tie(0); n   cout.tie(0); n   long long tests; n   cin >> tests; n   while (tests--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int C = 10005, N = 1005; n int n, w, b, x, c[N], cost[N]; n long long dp[2][C]; n template <class T> n void maxz(T &a, T b) { n   if (a < b) a = b; n } n int main() { n   int i, j, k, ub; n   long long mn; n   scanf( %d%d%d%d , &n, &w, &b, &x); n   for (i = 1; i <= n; i++) scanf( %d , c + i); n   for (i = 1; i <= n; i++) scanf( %d , cost + i); n   memset(dp[0], -1, sizeof(dp[0])); n   ub = 1; n   dp[0][0] = w; n   for (i = 1; i <= n; i++) { n     memset(dp[i & 1], -1, sizeof(dp[0])); n     for (j = 0; j < ub; j++) n       if (dp[~i & 1][j] >= 0) { n         mn = min(dp[~i & 1][j] + x, w + (long long)b * j); n         for (k = 0; k <= c[i] && mn >= 0; k++) { n           maxz(dp[i & 1][j + k], mn); n           mn -= cost[i]; n         } n         maxz(ub, j + k); n       } n   } n   printf( %d , ub - 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int r = 2, g = 5, b = 8, n, k; n int h, j, p; n int main() { n   cin >> n >> k; n   h = r * n; n   j = g * n; n   p = b * n; n   h = (h + k - 1) / k; n   j = (j + k - 1) / k; n   p = (p + k - 1) / k; n   cout << p + j + h; n } n


#include <bits/stdc++.h> n int sw, sw1, sw2; n int main() { n   char a[1000]; n   scanf( %s , a); n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     char b[10]; n     scanf( %s , b); n     if (b[0] == a[0] && b[1] == a[1]) sw = 1; n     if (b[1] == a[0]) sw1 = 1; n     if (b[0] == a[1]) sw2 = 1; n   } n   if (sw == 1 || sw1 == 1 && sw2 == 1) n     printf( YES ); n   else n     printf( NO ); n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<long long>> dp(10, vector<long long>(1000005, 0)); n long long g(long long n) { n   if (n < 10) return n; n   long long ans = 1; n   while (n) { n     if (n % 10) ans *= (n % 10); n     n /= 10; n   } n   return g(ans); n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   for (long long i = 1; i <= 1000000; i++) dp[g(i)][i]++; n   for (long long i = 0; i < 10; i++) { n     for (long long j = 2; j <= 1000000; j++) { n       dp[i][j] += dp[i][j - 1]; n     } n   } n   long long t; n   cin >> t; n   while (t--) { n     long long l, r, k; n     cin >> l >> r >> k; n     cout << dp[k][r] - dp[k][l - 1] <<   n ; n   } n } n


#include <bits/stdc++.h> n const int MOD = 1e9; n const int N = 100003; n using namespace std; n vector<int> ans; n int main() { n   int n; n   cin >> n; n   int p, q; n   p = q = 0; n   for (int i = 0; i < n; i++) { n     char c; n     int x, y; n     cin >> c; n     scanf( %d , &x); n     scanf( %d , &y); n     if (x > y) swap(x, y); n     if (c ==  + ) n       p = max(p, x), q = max(q, y); n     else if (p <= x && q <= y) n       cout <<  YES ; n     else n       cout <<  NO ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 1e5 + 69; n const int inf = 1e9 + 5; n const long long mod = 1e9 + 7; n const long double eps = 1e-10; n vector<int> v[MX]; n int par[24][MX]; n int depth[MX]; n void dfs(int x, int p) { n   for (auto g : v[x]) { n     if (g == p) { n       continue; n     } n     depth[g] = depth[x] + 1; n     dfs(g, x); n     par[0][g] = x; n   } n } n int lca(int x, int y) { n   if (depth[x] > depth[y]) swap(x, y); n   int i = 22; n   while (depth[x] < depth[y]) { n     if (depth[par[i][y]] >= depth[x]) { n       y = par[i][y]; n     } n     i--; n   } n   for (int i = 22; i >= 0; i--) { n     if (par[i][x] != par[i][y]) { n       x = par[i][x]; n       y = par[i][y]; n     } n   } n   if (x != y) { n     x = par[0][x]; n     y = par[0][y]; n   } n   return x; n } n int dis(int a, int b) { return (depth[a] + depth[b] - 2 * depth[lca(a, b)]); } n int cal(int a, int b, int c) { n   int ret = 0; n   int q1 = lca(a, b); n   int q2 = lca(a, c); n   int q3 = lca(b, c); n   if (depth[q1] >= max(depth[q2], depth[q3])) { n     ret = dis(lca(a, b), c); n   } else { n     ret = dis((depth[q2] >= depth[q3] ? q2 : q3), c); n   } n   return ret; n } n int main() { n   depth[0] = -1; n   int n, q; n   cin >> n >> q; n   for (int i = 2; i <= n; i++) { n     int b; n     scanf( %d , &b); n     v[i].push_back(b); n     v[b].push_back(i); n   } n   dfs(1, -1); n   for (int i = 1; i < 23; i++) { n     for (int j = 1; j <= n; j++) { n       par[i][j] = par[i - 1][par[i - 1][j]]; n     } n   } n   while (q--) { n     int ans = 0; n     int a, b, c; n     scanf( %d%d%d , &a, &b, &c); n     ans = max(cal(a, b, c), max(cal(a, c, b), cal(b, c, a))); n     printf( %d n , ans + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<vector<int>> g(n); n   vector<pair<int, int>> e(n - 1); n   for (int i = 0; i < n - 1; ++i) { n     int u, v; n     cin >> u >> v; n     --u; n     --v; n     g[u].push_back(v); n     g[v].push_back(u); n     e[i] = make_pair(u, v); n   } n   vector<int> col(n); n   for (int &i : col) { n     cin >> i; n   } n   int diff = 0; n   for (auto i : e) { n     if (col[i.first] != col[i.second]) { n       ++diff; n     } n   } n   for (int i = 0; i < n; ++i) { n     int ctr = 0; n     for (int j : g[i]) { n       if (col[i] != col[j]) { n         ++ctr; n       } n     } n     if (ctr == diff) { n       cout <<  YES n  << i + 1; n       return 0; n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n bool chkmax(T &x, T y) { n   return x < y ? x = y, true : false; n } n template <typename T> n bool chkmin(T &x, T y) { n   return x > y ? x = y, true : false; n } n int readint() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n int n, k; n int a[20]; n bitset<2001> d[66000]; n multiset<pair<int, int> > s; n void solve(int now, int cs, int r) { n   if (!now) return; n   while (cs <= 2000) { n     for (int i = 1; i <= n; i++) { n       if (((now >> (i - 1)) & 1) && cs >= a[i] && n           d[now ^ (1 << (i - 1))][cs - a[i]]) { n         s.insert(make_pair(-r, a[i])); n         solve(now ^ (1 << (i - 1)), cs - a[i], r); n         return; n       } n     } n     cs = cs * k, r++; n   } n   assert(0); n } n int main() { n   n = readint(); n   k = readint(); n   for (int i = 1; i <= n; i++) a[i] = readint(); n   d[0][0] = 1; n   for (int i = 1; i < (1 << n); i++) { n     for (int j = 1; j <= n; j++) n       if ((i >> (j - 1)) & 1) d[i] |= d[i ^ (1 << (j - 1))] << a[j]; n     for (int j = 2000 / k; j >= 1; j--) n       if (d[i][j * k]) d[i][j] = 1; n   } n   if (!d[(1 << n) - 1][1]) return printf( NO n ), 0; n   printf( YES n ); n   solve((1 << n) - 1, 1, 0); n   while (s.size() > 1) { n     auto it1 = s.begin(), it2 = it1; n     it2++; n     assert(it1->first == it2->first); n     printf( %d %d n , it1->second, it2->second); n     int tmp = it1->second + it2->second, dep = -it1->first; n     while (tmp % k == 0) tmp /= k, dep--; n     s.erase(it1); n     s.erase(it2); n     s.insert(make_pair(-dep, tmp)); n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   long long int a, b; n   scanf( %lld%lld , &a, &b); n   if (a > b) { n     printf( %lld %lld , b, (a - b) / 2); n   } else { n     printf( %lld %lld , a, (b - a) / 2); n   } n } n


#include <bits/stdc++.h> n int main() { n   int a, b, c, ab = -1, min; n   scanf( %d %d %d , &a, &b, &c); n   min = b; n   if (a < b) min = a; n   for (int i = 0; i <= min; i++) { n     if (b + a - 2 * i == c) { n       ab = i; n       break; n     } n   } n   if (ab == -1) n     printf( Impossible ); n   else n     printf( %d %d %d , ab, b - ab, a - ab); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9; n set<int> fang[400001]; n map<int, int> cishu[400001]; n int n, m, q, to1[400001], Nxt[400001], first1[400001], dfn[400001], low[400001]; n int to[500001], nxt[500001], first[500001], cnt, e1, x2, fa[400001]; n int sum, tot = 0, ss[400001], heavy[400001], siz[400001], seg[1000001]; n int pos[400001], top[400001], deep[400001], h = 0, Stack[400001 * 10]; n char ch; n void Build(int x, int y) { n   to1[cnt] = y; n   Nxt[cnt] = first1[x]; n   first1[x] = cnt++; n } n void insert(int x, int y) { n   to[e1] = y; n   nxt[e1] = first[x]; n   first[x] = e1++; n } n void tarjan(int x) { n   dfn[x] = low[x] = ++tot; n   Stack[++h] = x; n   for (int i = first1[x]; i != -1; i = Nxt[i]) n     if (!dfn[to1[i]]) { n       tarjan(to1[i]); n       low[x] = min(low[x], low[to1[i]]); n       if (dfn[x] <= low[to1[i]]) { n         int z; n         sum++; n         do { n           z = Stack[h--]; n           insert(sum, z); n           insert(z, sum); n         } while (z != to1[i]); n         insert(sum, x); n         insert(x, sum); n       } n     } else n       low[x] = min(low[x], dfn[to1[i]]); n } n void dfs(int o, int p) { n   siz[o] = 1; n   deep[o] = deep[p] + 1; n   fa[o] = p; n   for (int i = first[o]; i != -1; i = nxt[i]) n     if (to[i] != p) { n       dfs(to[i], o); n       siz[o] += siz[to[i]]; n       if (siz[to[i]] > siz[heavy[o]]) heavy[o] = to[i]; n     } n } n void dfs1(int o, int p) { n   pos[o] = ++x2; n   if (heavy[o] > 0) { n     top[heavy[o]] = top[o]; n     dfs1(heavy[o], o); n     for (int i = first[o]; i != -1; i = nxt[i]) n       if ((to[i] != p) && (to[i] != heavy[o])) { n         top[to[i]] = to[i]; n         dfs1(to[i], o); n       } n   } n } n void put(int o, int p, int q, int r, int s) { n   if ((o == q) && (p == q)) { n     seg[r] = s; n     return; n   } n   int mid = (o + p) / 2; n   if (q <= mid) { n     put(o, mid, q, r * 2, s); n     seg[r] = min(seg[r * 2 + 1], seg[r * 2]); n   } else { n     put(mid + 1, p, q, r * 2 + 1, s); n     seg[r] = min(seg[r * 2], seg[r * 2 + 1]); n   } n } n int get(int o, int p, int q, int r, int s) { n   if ((o == q) && (p == r)) return seg[s]; n   int mid = (o + p) / 2; n   if (r <= mid) n     return get(o, mid, q, r, s * 2); n   else if (q > mid) n     return get(mid + 1, p, q, r, s * 2 + 1); n   else n     return min(get(o, mid, q, mid, s * 2), n                get(mid + 1, p, mid + 1, r, s * 2 + 1)); n } n int gettree(int o, int p) { n   int yu = INF; n   while (top[o] != top[p]) { n     if (deep[top[o]] < deep[top[p]]) { n       int t = o; n       o = p; n       p = t; n     } n     yu = min(yu, get(1, sum, pos[top[o]], pos[o], 1)); n     o = fa[top[o]]; n   } n   if (deep[o] > deep[p]) { n     int t = o; n     o = p; n     p = t; n   } n   yu = min(yu, get(1, sum, pos[o], pos[p], 1)); n   if (o > n) yu = min(yu, ss[fa[o]]); n   return yu; n } n int main() { n   memset(first1, -1, sizeof(first1)); n   memset(first, -1, sizeof(first)); n   scanf( %d%d%d , &n, &m, &q); n   sum = n; n   for (int i = 1; i <= n; i++) scanf( %d , &ss[i]); n   for (int i = 1; i <= m; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     Build(x, y); n     Build(y, x); n   } n   for (int i = 1; i <= n; i++) n     if (!dfn[i]) tarjan(i); n   deep[0] = 0; n   dfs(1, 0); n   top[1] = 1; n   dfs1(1, 0); n   for (int i = 1; i <= n; i++) n     if (fa[i] > 0) { n       fang[fa[i]].insert(ss[i]); n       if (!cishu[fa[i]].count(ss[i])) cishu[fa[i]][ss[i]] = 0; n       cishu[fa[i]][ss[i]]++; n     } n   for (int i = n + 1; i <= sum; i++) ss[i] = *fang[i].begin(); n   for (int i = 0; i <= 1000000; i++) seg[i] = INF + 1; n   for (int i = 1; i <= sum; i++) put(1, sum, pos[i], 1, ss[i]); n   for (int i = 1; i <= q; i++) { n     int x, y; n     getchar(); n     scanf( %c%d%d , &ch, &x, &y); n     if (ch ==  C ) { n       if (fa[x] > 0) { n         cishu[fa[x]][ss[x]]--; n         if (cishu[fa[x]][ss[x]] == 0) fang[fa[x]].erase(ss[x]); n         if (!cishu[fa[x]].count(y)) cishu[fa[x]][y] = 0; n         cishu[fa[x]][y]++; n         fang[fa[x]].insert(y); n         put(1, sum, pos[fa[x]], 1, (*fang[fa[x]].begin())); n       } n       put(1, sum, pos[x], 1, y); n       ss[x] = y; n     } else n       cout << gettree(x, y) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ull = unsigned long long; n using ld = long double; n using pii = pair<int, int>; n using pll = pair<ll, ll>; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, b, d; n   cin >> n >> b >> d; n   int cur = 0, cnt = 0; n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     if (a > b) continue; n     cur += a; n     if (cur > d) { n       cnt++; n       cur = 0; n     } n   } n   if (cur > d) cnt++; n   cout << cnt << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = (int)1e9 + 7; n const int N = (int)1e5 + 10; n struct qq { n   int l, r, i, w; n }; n int t[4 * N], ans[2 * N]; n pair<int, int> p[2 * N]; n vector<qq> qx[N], qy[N]; n void upd(int pos, int val, int v = 1, int l = 1, int r = N - 10) { n   if (l == r) { n     t[v] = val; n     return; n   } n   int m = (l + r) >> 1; n   if (pos <= m) { n     upd(pos, val, v + v, l, m); n   } else { n     upd(pos, val, v + v + 1, m + 1, r); n   } n   t[v] = min(t[v + v], t[v + v + 1]); n } n int get(int l, int r, int v = 1, int tl = 1, int tr = N - 10) { n   if (l > r || tr < l || tl > r) { n     return inf; n   } n   if (l <= tl && tr <= r) { n     return t[v]; n   } n   int tm = (tl + tr) >> 1; n   return min(get(l, r, v + v, tl, tm), get(l, r, v + v + 1, tm + 1, tr)); n } n inline bool cmp(pair<int, int> f, pair<int, int> s) { n   return f.second < s.second || (f.second == s.second && f.first < s.first); n } n int main() { n   int n, m, k, q; n   scanf( %d %d %d %d , &n, &m, &k, &q); n   for (int i = 1; i <= k; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     p[i] = {x, y}; n   } n   for (int i = 1; i <= q; i++) { n     int ax, ay, bx, by; n     scanf( %d %d %d %d , &ax, &ay, &bx, &by); n     qx[bx].emplace_back(qq({ay, by, i, ax})); n     qy[by].emplace_back(qq({ax, bx, i, ay})); n   } n   sort(p + 1, p + k + 1); n   int ptr = 1; n   for (int i = 1; i < N; i++) { n     while (ptr <= k && p[ptr].first == i) { n       upd(p[ptr].second, i); n       ptr++; n     } n     for (auto j : qx[i]) { n       ans[j.i] |= ((get(j.l, j.r) >= j.w) ? 1 : 0); n     } n   } n   memset(t, 0, sizeof(t)); n   ptr = 1; n   sort(p + 1, p + k + 1, cmp); n   for (int i = 1; i < N; i++) { n     while (ptr <= k && p[ptr].second == i) { n       upd(p[ptr].first, i); n       ptr++; n     } n     for (auto j : qy[i]) { n       ans[j.i] |= ((get(j.l, j.r) >= j.w) ? 1 : 0); n     } n   } n   for (int i = 1; i <= q; i++) { n     if (ans[i] == 1) n       puts( YES ); n     else n       puts( NO ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 3e5 + 10, N2 = 2e5, delta = 10499, mod = 1e9 + 7, n                     oo = 1e18, LOG = 20, SQ = 300; n const long double PI = 3.141592653589793; n pair<pair<long long int, long long int>, long long int> p[N]; n int32_t main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   long long int t; n   cin >> t; n   while (t--) { n     long long int n; n     cin >> n; n     for (long long int i = 0; i < 2 * n - 1; i++) { n       long long int x, y; n       cin >> x >> y; n       p[i] = {{x, y}, i}; n     } n     cout <<  YES n ; n     sort(p, p + 2 * n - 1); n     for (long long int i = 0; i < 2 * n - 2; i += 2) { n       if (p[i].first.second < p[i + 1].first.second) n         cout << p[i + 1].second + 1 <<    ; n       else n         cout << p[i].second + 1 <<    ; n     } n     cout << p[2 * n - 2].second + 1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   fixed(cout); n   cout << setprecision(10); n   ; n   long long int n, h; n   cin >> n >> h; n   for (int i = 1; i <= n - 1; i++) { n     double x = (h * h * i) / double(n); n     x = sqrt(x); n     if (i == n) break; n     cout << x <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int tipo[100000 + 5]; n int main() { n   int n, x, y, z, m; n   cin >> n >> m; n   memset(tipo, -1, sizeof(tipo)); n   for (int i = 0; i < m; ++i) { n     cin >> x >> y >> z; n     x--, y--, z--; n     bool enc = 0; n     if (tipo[x] != -1) { n       enc = 1; n       tipo[y] = (tipo[x] + 1) % 3; n       tipo[z] = (tipo[x] + 2) % 3; n     } else if (tipo[y] != -1) { n       enc = 1; n       tipo[x] = (tipo[y] + 1) % 3; n       tipo[z] = (tipo[y] + 2) % 3; n     } else if (tipo[z] != -1) { n       enc = 1; n       tipo[x] = (tipo[z] + 1) % 3; n       tipo[y] = (tipo[z] + 2) % 3; n     } n     if (enc == 0) { n       tipo[x] = 0, tipo[y] = 1, tipo[z] = 2; n     } n   } n   for (int i = 0; i < n; ++i) { n     if (i == 0) n       cout << tipo[i] + 1; n     else n       cout <<     << tipo[i] + 1; n   } n   puts(  ); n } n


#include <bits/stdc++.h> n using namespace std; n int vis[10] = {0}; n int main() { n   int c = 0, n = 0, i, flag = 0; n   long long ans = 1; n   string s; n   cin >> s; n   for (i = 0; i < s.size(); i++) { n     if (s[i] ==  ? ) { n       if (i == 0) flag = 1; n       c++; n     } n     if (s[i] >=  A  && s[i] <=  J ) { n       if (i == 0) flag = 1; n       vis[s[i] -  A ] = 1; n     } n   } n   for (i = 0; i < 10; i++) n     if (vis[i]) n++; n   for (i = 0; i < n; i++) ans *= 10 - i; n   if (flag) { n     ans *= 9; n     if (ans % 10 == 0) { n       ans /= 10; n       flag = 0; n     } n   } n   cout << ans; n   for (i = flag; i < c; i++) cout << 0; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n void c_p_c() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n int32_t main() { n   c_p_c(); n   long long t; n   cin >> t; n   while (t--) { n     long long n, r; n     cin >> n >> r; n     long long k = r; n     r = min(n - 1, r); n     long long ans = r * (r + 1) / 2; n     if (k > r) ans++; n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200000 + 10; n const int inf = 0x3f3f3f3f; n vector<int> ve[maxn]; n int a[maxn], c[maxn]; n struct node { n   int pos, val; n } nod[maxn]; n bool cmp(node a, node b) { return a.val < b.val; } n bool cmp1(int x, int y) { return nod[a[x]].val > nod[a[y]].val; } n int main() { n   int n, q, k, x, y; n   scanf( %d , &n); n   for (int i = 0; i <= n; i++) { n     ve[i].clear(); n     nod[i].val = 0; n     nod[i].pos = 0; n   } n   for (int i = 0; i < n; i++) { n     scanf( %d%d , &x, &y); n     ve[x].push_back(y); n     nod[x].pos = x; n     nod[x].val = max(nod[x].val, y); n   } n   sort(nod + 1, nod + 1 + n, cmp); n   for (int i = 1; i <= n; i++) a[nod[i].pos] = i; n   scanf( %d , &q); n   int ans, res; n   while (q--) { n     int max1 = nod[n].val, pos1 = nod[n].pos; n     int max2 = nod[n - 1].val, pos2 = nod[n - 1].pos, s, j = n - 2; n     scanf( %d , &k); n     for (int i = 0; i < k; i++) scanf( %d , &c[i]); n     sort(c, c + k, cmp1); n     for (int i = 0; i < k; i++) { n       if (c[i] == pos1) { n         max1 = max2; n         pos1 = pos2; n         max2 = nod[j].val; n         pos2 = nod[j--].pos; n       } else if (c[i] == pos2) { n         max2 = nod[j].val; n         pos2 = nod[j--].pos; n       } n     } n     if (max1 == 0) n       ans = 0, res = 0; n     else { n       int l = 0, r = ve[pos1].size(), mid; n       while (l < r) { n         mid = l + (r - l) / 2; n         if (max2 <= ve[pos1][mid]) n           r = mid; n         else n           l = mid + 1; n       } n       ans = pos1; n       res = ve[pos1][l]; n     } n     printf( %d %d n , ans, res); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int mod_expo(long long int x, long long int y) { n   long long int res = 1; n   while (y > 0) { n     if (y & 1) res = (res * x) % 1000000007; n     y = y >> 1; n     x = (x * x) % 1000000007; n   } n   return res; n } n int main() { n   long long int t; n   cin >> t; n   while (t--) { n     map<long long int, long long int> right; n     long long int n; n     cin >> n; n     long long int ar[2 * n + 4]; n     long long int dp[2 * n + 3]; n     for (long long int i = 0; i < 2 * n; i++) { n       cin >> ar[i]; n     } n     long long int count = 0; n     for (long long int i = 0; i < n; i++) { n       if (ar[i] == 1) n         count++; n       else { n         count--; n       } n       dp[i] = count; n     } n     count = 0; n     for (long long int i = 2 * n - 1; i >= n; i--) { n       if (ar[i] == 1) n         count--; n       else { n         count++; n       } n       dp[i] = count; n       right[count] = i; n     } n     long long int mini = 2 * n; n     for (long long int i = 0; i < 2 * n; i++) { n       if (dp[i] == 0) { n         if (i < n && mini > (2 * n - i - 1)) n           mini = 2 * n - i - 1; n         else if (i >= n && mini > (i)) n           mini = i; n       } n     } n     for (long long int i = n - 1; i >= 0; i--) { n       long long int p = dp[i]; n       long long int k = right[p]; n       if (k > 0 && mini > (k - i - 1)) mini = k - i - 1; n     } n     cout << mini << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   unsigned long long A, B; n   cin >> A >> B; n   if (A < B) { n     puts( -1 ); n     return 0; n   } n   if ((A - B) % 2 != 0) { n     puts( -1 ); n     return 0; n   } n   unsigned long long C = (A - B) / 2; n   unsigned long long X = 0, Y = 0; n   for (unsigned long long bit = 1ULL << 63; bit >= 1; bit >>= 1) { n     bool dif = (B & bit); n     bool allHas = (C & bit); n     if (allHas && dif) { n       puts( -1 ); n       return 0; n     } n     if (allHas) { n       X |= bit; n       Y |= bit; n     } n     if (dif) { n       Y |= bit; n     } n   } n   cout << X <<     << Y << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = (int)1e4 + 10; n int n, w, b, x; n long long dp[1005][maxN]; n int c[maxN]; n int cost[maxN]; n int main() { n   cin >> n >> w >> b >> x; n   for (int i = 1; i <= n; i++) cin >> c[i]; n   for (int i = 1; i <= n; i++) cin >> cost[i]; n   memset(dp, -1, sizeof dp); n   dp[0][0] = w; n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < maxN; j++) { n       long long cur_bal = dp[i - 1][j]; n       if (cur_bal == -1) continue; n       for (int k = 0; k <= c[i]; k++) { n         if (1LL * k * cost[i] > cur_bal) continue; n         dp[i][j + k] = max(min(cur_bal - (1LL * k * cost[i]) + x, n                                1LL * w + (1LL * b * (j + k))), n                            dp[i][j + k]); n       } n     } n   } n   for (int i = maxN - 1; i >= 0; i--) { n     if (dp[n][i] != -1) { n       cout << i; n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int T, n, b[100010], mp[100010], hah[100010]; n struct qwq { n   int v, id; n } a[100010]; n bool cmp(qwq x, qwq y) { return x.v < y.v; } n int main() { n   scanf( %d , &T); n   while (T--) { n     scanf( %d , &n); n     for (int i = 1; i <= n; i++) n       scanf( %d , &a[i].v), mp[a[i].v] = i, b[i] = a[i].v, hah[i] = 0; n     sort(a + 1, a + n + 1, cmp); n     bool flag = true; n     for (int i = 1; i <= n;) { n       int now = mp[i], js = i; n       hah[now] = 1; n       for (int j = now + 1; j <= n; j++) { n         if (hah[j]) { n           break; n         } n         if (b[j] != b[j - 1] + 1) { n           flag = false; n           break; n         } else { n           hah[j] = 1; n           js++; n         } n       } n       if (!flag) { n         break; n       } n       i = js + 1; n     } n     if (flag) n       printf( YES n ); n     else n       printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T, class U> n struct SegmentTree { n   struct Node { n     bool hasCarry = 0; n     int b = 0, e = 0; n     U carry = U(); n     T val = T(); n     Node() {} n     void join(const Node &l, const Node &r) { n       val = l.val + r.val; n       b = l.b; n       e = r.e; n     } n     void update(const U &u) { n       carry += u; n       u.update(val, b, e); n       hasCarry = 1; n     } n     void pushDown(Node &l, Node &r) { n       if (!hasCarry) return; n       l.update(carry); n       r.update(carry); n       carry = U(); n       hasCarry = 0; n     } n   }; n   vector<Node> V; n   int N; n   SegmentTree(int N) : V(4 * N), N(N) {} n   template <class I> n   void create(const vector<I> &VEC, int n = 1, int b = 0, int e = -1) { n     if (e == -1) e = N - 1; n     if (b == e) { n       V[n].val = T(VEC[b]), V[n].b = b, V[n].e = e; n     } else { n       int m = (b + e) / 2; n       create(VEC, 2 * n, b, m); n       create(VEC, 2 * n + 1, m + 1, e); n       V[n].join(V[2 * n], V[2 * n + 1]); n     } n   } n   T query(int i, int j, int n = 1, int b = 0, int e = -1) { n     if (e == -1) e = N - 1; n     if (i <= b && e <= j) n       return V[n].val; n     else { n       V[n].pushDown(V[2 * n], V[2 * n + 1]); n       int m = (b + e) / 2; n       if (i > m) return query(i, j, 2 * n + 1, m + 1, e); n       if (j <= m) return query(i, j, 2 * n, b, m); n       return query(i, j, 2 * n, b, m) + query(i, j, 2 * n + 1, m + 1, e); n     } n   } n   void update(int i, int j, const U &v, int n = 1, int b = 0, int e = -1) { n     if (e == -1) e = N - 1; n     if (i <= b && e <= j) n       V[n].update(v); n     else if (i > e || j < b) n       return; n     else { n       V[n].pushDown(V[2 * n], V[2 * n + 1]); n       int m = (b + e) / 2; n       update(i, j, v, 2 * n, b, m); n       update(i, j, v, 2 * n + 1, m + 1, e); n       V[n].join(V[2 * n], V[2 * n + 1]); n     } n   } n   int findOkPrefix(int i, const function<bool(T)> &isOk) { n     vector<int> stk; n     stk.reserve(20); n     stk.push_back(1); n     T acum; n     int sz = 0; n     while (stk.size()) { n       int t = stk.back(); n       stk.pop_back(); n       Node &n = V[t]; n       if (n.e < i) continue; n       T newAcum = sz == 0 ? n.val : (acum + n.val); n       if (i <= n.b) { n         if (isOk(newAcum)) { n           sz += n.e - n.b + 1; n           acum = newAcum; n         } else { n           if (n.b == n.e) return sz; n           V[t].pushDown(V[t << 1], V[t << 1 | 1]); n           stk.push_back(2 * t + 1); n           stk.push_back(2 * t); n         } n       } else { n         V[t].pushDown(V[t << 1], V[t << 1 | 1]); n         stk.push_back(2 * t + 1); n         stk.push_back(2 * t); n       } n     } n   } n }; n struct RRange { n   int tL, tR, sz; n   RRange(int v = 0) : tR(v), tL(v), sz(1) {} n   RRange operator+(const RRange &m) const { n     RRange r; n     r.sz = sz + m.sz; n     r.tL = max(tL, m.tL - sz); n     r.tR = max(tR - m.sz, m.tR); n     return r; n   } n   friend ostream &operator<<(ostream &os, const RRange &range) { n     os <<  (  << range.tL <<  ,  << range.tR <<  ) ; n     return os; n   } n   void normalize(int N) { n     if (tL + tR + 1 >= N) { n       tL = 0; n       tR = N - 1; n     } n     sz = 1; n   } n   int size() { return tL + tR + 1; } n }; n struct Void { n   void update(RRange &m, int b, int e) const {} n   void operator+=(const Void &s) {} n }; n int main() { n   int N; n   cin >> N; n   vector<RRange> V(N); n   for (int i = 0; i < N; ++i) { n     int n; n     cin >> n; n     V[i] = RRange(n); n     V[i].normalize(N); n   } n   vector<vector<RRange>> T(20, vector<RRange>(N)); n   vector<SegmentTree<RRange, Void>> STS; n   T[0] = V; n   auto fn = [](int i, int j, SegmentTree<RRange, Void> &ST, int N) { n     RRange r = ST.query(max(i, 0), min(j, N - 1)); n     if (i < 0) r = ST.query(N + i, N - 1) + r; n     if (j >= N) r = r + ST.query(0, j % N); n     return r; n   }; n   for (int i = 1; i < 20; ++i) { n     STS.push_back(SegmentTree<RRange, Void>(N)); n     STS.back().create(T[i - 1]); n     auto &ST = STS.back(); n     for (int j = 0; j < N; ++j) { n       T[i][j] = fn(j - T[i - 1][j].tL, j + T[i - 1][j].tR, ST, N); n       T[i][j].tL += T[i - 1][j].tL; n       T[i][j].tR += T[i - 1][j].tR; n       T[i][j].normalize(N); n     } n   } n   for (int i = 0; i < N; ++i) { n     RRange mx(0); n     int ans = 0; n     for (int j = STS.size() - 1; j >= 0; --j) { n       RRange t = fn(i - mx.tL, i + mx.tR, STS[j], N); n       t.tL += mx.tL; n       t.tR += mx.tR; n       t.normalize(N); n       if (t.size() < N) { n         mx = t; n         ans |= 1 << j; n       } n     } n     if (mx.size() < N) ans++; n     cout << ans <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int p = 1000003; n const int n = 10; n int inv[1000005], a[15][15], ans[15]; n int read() { n   char c = getchar(); n   int x = 0, f = 1; n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   return x * f; n } n int calc(int x) { n   int res = 0; n   for (int i = n; i >= 0; i--) res = (1LL * res * x + ans[i]) % p; n   return res; n } n int main() { n   inv[1] = 1; n   for (int i = 2; i < p; i++) inv[i] = 1LL * (p - p / i) * inv[p % i] % p; n   printf( ? 0 n ); n   fflush(stdout); n   ans[0] = read(); n   for (int i = 1; i <= n; i++) { n     printf( ? %d n , i); n     fflush(stdout); n     a[i][0] = 1; n     for (int j = 1; j <= n; j++) a[i][j] = a[i][j - 1] * i % p; n     a[i][n + 1] = (read() + p - ans[0]) % p; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = i + 1; j <= n; j++) { n       int t = 1LL * a[j][i] * inv[a[i][i]] % p; n       for (int k = i + 1; k <= n + 1; k++) n         a[j][k] = (a[j][k] + p - 1LL * a[i][k] * t % p) % p; n       a[j][i] = 0; n     } n   } n   for (int i = n; i >= 1; i--) { n     int res = a[i][n + 1]; n     for (int j = i + 1; j <= n; j++) n       res = (res + p - 1LL * a[i][j] * ans[j] % p) % p; n     ans[i] = 1LL * res * inv[a[i][i]] % p; n   } n   for (int i = 0; i < p; i++) { n     if (calc(i) == 0) { n       printf( ! %d n , i); n       fflush(stdout); n       exit(0); n     } n   } n   printf( ! -1 n ); n   fflush(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000 + 10; n int n, d[MAXN], id[MAXN]; n bool b[MAXN][MAXN]; n bool cmp(int a, int b) { n   if (d[a] > d[b]) return true; n   if (d[a] < d[b]) return false; n   return a < b; n } n int main() { n   scanf( %d , &n); n   if (n == 4) puts( -1 ), exit(0); n   b[3][1] = b[1][2] = b[2][3] = 1; n   d[1] = d[2] = d[3] = 1; n   for (int i = 4; i <= n; ++i) { n     for (int j = 1; j < i; ++j) id[j] = j; n     sort(id + 1, id + i, cmp); n     for (int j = 1; j <= i / 2; ++j) b[id[j]][i] = 1, ++d[i]; n     for (int j = i / 2 + 1; j < i; ++j) b[i][id[j]] = 1, ++d[id[j]]; n   } n   for (int i = 1; i <= n; ++i, puts(  )) n     for (int j = 1; j <= n; ++j) printf( %d  , b[i][j]); n   fclose(stdin); n   fclose(stdout); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n inline int read() { n   int f = 1, x = 0; n   char ch; n   do { n     ch = getchar(); n     if (ch ==  - ) f = -1LL; n   } while (ch <  0  || ch >  9 ); n   do { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } while (ch >=  0  && ch <=  9 ); n   return f * x; n } n template <class T> n inline void chmax(T &a, T b) { n   if (a < b) a = b; n } n template <class T> n inline void chmin(T &a, T b) { n   if (a > b) a = b; n } n inline void swap(int &a, int &b) { n   int c = a; n   a = b; n   b = c; n } n using namespace std; n const int N = 4e5 + 10; n set<int> seg[N << 2]; n int mx[N << 2], mn[N << 2]; n struct node { n   int x1, y1, x2, y2; n } a[N]; n inline void show(node a) { printf( %d %d %d %d n , a.x1, a.y1, a.x2, a.y2); } n vector<int> ins[N], era[N]; n int n, px[N << 1], py[N << 1], totx, toty, lenx, leny, ok[N]; n inline void upd(int cur) { n   int mxp; n   if (seg[cur].size()) { n     mxp = *(--seg[cur].end()); n   } else { n     mxp = -1; n   } n   int mxt = max(mx[cur << 1], mx[cur << 1 | 1]); n   int mnt = min(mn[cur << 1], mn[cur << 1 | 1]); n   if (mxp > mxt) { n     if (ok[mxp] || mxp < mnt) { n       mx[cur] = -1; n     } else { n       mx[cur] = mxp; n     } n   } else { n     mx[cur] = mxt; n   } n   mn[cur] = max(mxp, mnt); n } n inline void cover(int cur, int L, int R, int l, int r, int id, int fl) { n   if (l > r) return; n   if (l <= L && r >= R) { n     if (fl == 1) { n       seg[cur].insert(id); n     } else if (fl == -1) { n       seg[cur].erase(id); n     } n     upd(cur); n     return; n   } n   int mid = (L + R) >> 1; n   if (l <= mid) cover(cur << 1, L, mid, l, r, id, fl); n   if (r > mid) cover(cur << 1 | 1, mid + 1, R, l, r, id, fl); n   upd(cur); n } n inline void norx(int &x) { n   x = (int)(lower_bound(px + 1, px + lenx + 1, x) - px); n } n inline void nory(int &x) { n   x = (int)(lower_bound(py + 1, py + leny + 1, x) - py); n } n int main() { n   memset(mx, -1, sizeof(mx)); n   n = read(); n   for (int i = (1); i <= (n); ++i) n     a[i].x1 = read(), a[i].y1 = read(), a[i].x2 = read(), a[i].y2 = read(); n   for (int i = (1); i <= (n); ++i) { n     px[++totx] = a[i].x1; n     px[++totx] = a[i].x2; n     py[++toty] = a[i].y1; n     py[++toty] = a[i].y2; n   } n   sort(px + 1, px + totx + 1); n   sort(py + 1, py + toty + 1); n   lenx = (int)(unique(px + 1, px + totx + 1) - px - 1); n   leny = (int)(unique(py + 1, py + toty + 1) - py - 1); n   for (int i = (1); i <= (n); ++i) { n     norx(a[i].x1); n     norx(a[i].x2); n     nory(a[i].y1); n     nory(a[i].y2); n   } n   for (int i = (1); i <= (n); ++i) { n     ins[a[i].x1].push_back(i); n     era[a[i].x2].push_back(i); n   } n   for (int t = (1); t <= (lenx); ++t) { n     for (auto cur : ins[t]) { n       cover(1, 1, leny, a[cur].y1, a[cur].y2 - 1, cur, 1); n     } n     for (auto cur : era[t]) { n       cover(1, 1, leny, a[cur].y1, a[cur].y2 - 1, cur, -1); n     } n     while (~mx[1]) { n       ok[mx[1]] = 1; n       cover(1, 1, leny, a[mx[1]].y1, a[mx[1]].y2 - 1, mx[1], 0); n     } n   } n   int ans = 1; n   for (int i = (1); i <= (n); ++i) n     if (ok[i]) ++ans; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n int q, t, l, r, x, last; n std::map<int, int> dsu, val; n int root(int x) { n   int cur = dsu[x]; n   if (cur < 0) n     return x; n   else { n     dsu[x] = root(dsu[x]); n     val[x] ^= val[cur]; n     return dsu[x]; n   } n } n void connect(int x, int y, int v) { n   int a = root(x), b = root(y); n   if (a != b) { n     if (dsu[a] > dsu[b]) std::swap(a, b); n     dsu[a] += dsu[b]; n     dsu[b] = a; n     val[b] = v ^ val[x] ^ val[y]; n   } n } n int main() { n   std::cin >> q; n   while (q--) { n     std::cin >> t >> l >> r; n     if ((l ^= last) > (r ^= last)) std::swap(l, r); n     if (!dsu.count(l)) dsu[l] = -1; n     if (!dsu.count(++r)) dsu[r] = -1; n     if (t == 1) { n       std::cin >> x; n       connect(l, r, x ^= last); n     } else if (root(l) == root(r)) n       std::cout << (last = val[l] ^ val[r]) <<   n ; n     else n       std::cout << -(last = 1) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long pl, pr, vl, vr; n int k; n long long Inter(long long x1, long long x2, long long y1, long long y2) { n   long long a = max(x1, y1); n   long long b = min(x2, y2); n   if (a > b) n     return 0.0; n   else n     return b - a + 1; n } n long long GetProb(long long x1, long long x2, long long y1, long long y2) { n   return Inter(x1, x2, pl, pr) * Inter(y1, y2, vl, vr) + n          Inter(x1, x2, vl, vr) * Inter(y1, y2, pl, pr); n } n int main() { n   cin >> pl >> pr >> vl >> vr >> k; n   vector<long long> numbers; n   numbers.push_back(0); n   int a = 0; n   for (int i = 0; i < 9; i++) { n     int b = numbers.size(); n     for (int j = a; j < b; j++) { n       numbers.push_back(numbers[j] * 10 + 4); n       numbers.push_back(numbers[j] * 10 + 7); n     } n     a = b; n   } n   numbers.push_back(1000000000); n   long long P = (pr - pl + 1) * (vr - vl + 1); n   long long gP = 0; n   int l = 1; n   int r = k; n   while (1) { n     gP += n         GetProb(numbers[l - 1] + 1, numbers[l], numbers[r], numbers[r + 1] - 1); n     l++; n     r++; n     if (r + 1 >= numbers.size()) break; n   } n   l = 1; n   r = k + 1; n   while (1) { n     l++; n     r++; n     if (r + 1 >= numbers.size()) break; n   } n   l = 1; n   if (k == 1) n     while (1) { n       gP -= GetProb(numbers[l], numbers[l], numbers[l], numbers[l]) / 2; n       l++; n       if (l + 1 >= numbers.size()) break; n     } n   printf( %.15f , (long double)gP / P); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 205; n int a[maxn]; n int main() { n   ios::sync_with_stdio(false); n   int n, k; n   scanf( %d %d , &n, &k); n   int m = n + n + 1; n   for (int i = 0; i < m; ++i) scanf( %d , &a[i]); n   for (int i = 1; k && i < m; i += 2) { n     if (a[i] > max(a[i - 1], a[i + 1]) + 1) { n       --a[i]; n       --k; n     } n   } n   for (int i = 0; i < m; ++i) printf( %d  , a[i]); n   putchar(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[10][300]; n int s[10][10]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < int(n); ++i) n     for (int j = 0; j < int(m); ++j) cin >> s[i][j]; n   int *cur = dp[0], *next = dp[1]; n   for (int i = n - 1; i >= 0; --i) { n     for (int j = m - 1; j >= 0; --j) { n       for (int used = 0; used < int(1 << m); ++used) { n         if (used & (1 << j)) { n           next[used] = cur[used & ~(1 << j)]; n         } else { n           int best = 0; n           if (j + 1 < m && !(used & (1 << (j + 1)))) n             best = max(best, n                        cur[used | (1 << (j + 1))] + (s[i][j] == s[i][j + 1])); n           if (i + 1 < n) n             best = max(best, cur[used | (1 << j)] + (s[i][j] == s[i + 1][j])); n           next[used] = best; n         } n       } n       swap(cur, next); n     } n   } n   cout << n * m / 2 - cur[0] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[100001], flag[100001]; n vector<pair<long long, long long> > ans; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long n, sum = 0; n   cin >> n; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     sum += a[i]; n   } n   sum /= n / 2; n   for (long long i = 0; i < n; i++) { n     if (flag[i] == 0) n       for (long long j = i + 1; j < n; j++) { n         if (flag[j] == 0 && ((a[i] + a[j]) == sum)) { n           flag[j] = 1; n           flag[i] = 1; n           ans.push_back(make_pair(i + 1, j + 1)); n           break; n         } n       } n   } n   for (auto i : ans) { n     cout << i.first <<     << i.second << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n long long f(const string& s) { n   long long res = 0; n   for (int i = 0; i + 1 < s.size(); ++i) { n     if (s[i] != s[i + 1]) { n       res += (m - 1) * (n - i - 1); n     } n   } n   return res; n } n long long g(const string& s) { n   long long res = 0; n   for (int i = 0; i + 1 < s.size(); ++i) n     if (s[i] != s[i + 1]) { n       int j = i + 1; n       while (j + 1 < s.size() && s[j + 1] == s[j - 1]) ++j; n       long long l = j - i + 1; n       res += l * (l - 1) / 2; n       i = j - 1; n     } n   return res; n } n int main() { n   string s; n   cin >> n >> m >> s; n   long long res = n * (m - 1) + f(s); n   reverse(s.begin(), s.end()); n   res += f(s) - g(s); n   cout << res << endl; n   return 0; n } n


/*mjytxdy!*/ n #include <bits/stdc++.h> n using namespace std; n #define pb push_back n #define fi first n #define se second n #define all(x) x.begin(),x.end() n #define SZ(x) ((int)x.size()) n #define pii pair<int,int> n #define pil pair<int,ll> n #define pli pair<ll,int> n #define pll pair<ll,ll> n #define inl inline n #define rep(i,l,r) for(int i=(l);i<=(r);i++) n #define per(i,r,l) for(int i=(r);i>=(l);i--) n #define trv(i,u) for(int i=head[u];i;i=e[i].next) n #define lb(x) ((x)&(-(x))) n #define debug(x) cout<<#x : <<x<<  n  n #define myput puts( QaQ ) n #define file(x) freopen(#x .in , r ,stdin),freopen(#x .out , w ,stdout); n typedef long long ll; n template<class T>inl bool ylmin(T &a,T b){return a<b?0:(a=b,1);} n template<class T>inl bool ylmax(T &a,T b){return a>b?0:(a=b,1);} n template<class T>inl T abs(T x){return x<0?-x:x;} n inl char read(){ n  static const int IO_LEN=1024*1024; n  static char buf[IO_LEN],*ioh,*iot; n  if(ioh==iot){ n   iot=(ioh=buf)+fread(buf,1,IO_LEN,stdin); n   if(ioh==iot) return -1; n  } n  return *ioh++; n } n template<class T>inl void read(T &x){ n  static int iosig;static char ioc; n  for(iosig=0,ioc=read();!isdigit(ioc);ioc=read()) if(ioc== - ) iosig=1; n  for(x=0;isdigit(ioc);ioc=read())x=(x<<1)+(x<<3)+(ioc^ 0 ); n  if(iosig) x=-x; n } n const int MAXN = 1e5 + 10; n struct Node{ n  int x,y; n }a[MAXN]; n int n,m; n vector<int> S,T,Set; n map<pii,bool> Map; n inl bool cmp(Node a,Node b){ n  return a.x-a.y>b.x-b.y; n } n struct Segment{ n  #define ls rt<<1 n  #define rs rt<<1|1 n  pii Min[MAXN<<2]; n  int tag; n  inl void pushup(int rt){ n   Min[rt]=min(Min[ls],Min[rs]); n  } n  inl pii query(int rt,int l,int r,int L,int R){ n   if(L>R) return {2e9,-1}; n   if(l>=L && r<=R) return Min[rt];  n   int mid=l+r>>1; n   if(R<=mid) return query(ls,l,mid,L,R); n   else if(L>mid) return query(rs,mid+1,r,L,R); n   else return min(query(ls,l,mid,L,R),query(rs,mid+1,r,L,R)); n  } n  inl void update(int rt,int l,int r,int pos) { n   if(l==r) return Min[rt]={2e9,-1},void(); n   int mid=l+r>>1; n   if(pos<=mid) update(ls,l,mid,pos); n   else update(rs,mid+1,r,pos); n   pushup(rt); n  } n  inl void build(int rt,int l,int r,int opt){ n   if(l==r) { n    Min[rt]={opt?a[l].y:a[l].x,l}; n    return ; n   } n   int mid=l+r>>1; n   build(ls,l,mid,opt),build(rs,mid+1,r,opt); n   pushup(rt); n  } n  #undef ls n  #undef rs n }t[2]; n int main(){ n  //freopen( in.txt , r ,stdin); n  read(n),read(m); n  rep(i,1,n) read(a[i].x),read(a[i].y),Map[{a[i].x,a[i].y}]=1; n  sort(a+1,a+n+1,cmp); n  per(i,n,1) Set.push_back(a[i].x-a[i].y); n  t[0].build(1,1,n,0),t[1].build(1,1,n,1); n  int delta=0;S.push_back(-1),T.push_back(-1); n  rep(i,1,n) { n   int pos=n-(lower_bound(all(Set),delta)-Set.begin())+1; n   pii lans=t[0].query(1,1,n,1,pos-1),rans=t[1].query(1,1,n,pos,n); n   lans.fi-=t[0].tag,rans.fi-=t[1].tag; n   pii Min=min(lans,rans); n   int id=Min.se; n   if(a[id].x-a[id].y==delta) { n    if(S.back()!=a[id].x && T.back()!=a[id].y) { n     t[0].tag++,S.push_back(a[id].x); n     t[1].tag++,T.push_back(a[id].y); n    } n   } else if(a[id].x-a[id].y>delta) { n    if(S.back()!=a[id].x) delta++,t[0].tag++,S.push_back(a[id].x); n   } else if(a[id].x-a[id].y<delta) { n    if(T.back()!=a[id].y) delta--,t[1].tag++,T.push_back(a[id].y); n   } n   t[0].update(1,1,n,id);t[1].update(1,1,n,id); n   } n   rep(i,1,m) { n    int x,y; n    read(x),read(y); n    if(Map[{x,y}]) {puts( LOSE );continue;} n    if(binary_search(all(S),x) || binary_search(all(T),y)) {puts( WIN );continue;} n   x-=lower_bound(all(S),x)-S.begin(); n    y-=lower_bound(all(T),y)-T.begin(); n    puts(x==y? LOSE : WIN ); n  } n  return 0; n }


#include <bits/stdc++.h> n using std::bitset; n using std::cerr; n using std::cin; n using std::complex; n using std::cout; n using std::deque; n using std::endl; n using std::ios_base; n using std::iterator; n using std::map; n using std::max; n using std::max_element; n using std::min; n using std::min_element; n using std::multimap; n using std::multiset; n using std::pair; n using std::queue; n using std::reverse; n using std::set; n using std::sort; n using std::stable_sort; n using std::stack; n using std::string; n using std::swap; n using std::unique; n using std::vector; n namespace MySpace { n struct Small_Segment_Tree { n   vector<int> a; n   int l, r; n  n  private: n   int __summ(int L, int R, int l, int r, int v) { n     if (L <= l && r <= R) return a[v]; n     if (R <= l || r <= L) return 0; n     int m = (l + r) / 2; n     return __summ(L, R, l, m, 2 * v + 1) + __summ(L, R, m, r, 2 * v + 2); n   } n   void __set(int P, int l, int r, int v, int V) { n     if (l + 1 == r) { n       a[v] = V; n       return; n     } n     int m = (l + r) / 2; n     if (P < m) { n       __set(P, l, m, 2 * v + 1, V); n       a[v] = a[2 * v + 1] + a[2 * v + 2]; n     } else { n       __set(P, m, r, 2 * v + 2, V); n       a[v] = a[2 * v + 1] + a[2 * v + 2]; n     } n   } n  n  public: n   int Summ(int L, int R) { n     if (R < L) return 0; n     return __summ(L, R + 1, l, r, 0); n   } n   void Set(int P, int V) { __set(P, l, r, 0, V); } n   Small_Segment_Tree(int _n) { n     a.resize(4 * _n); n     l = 0, r = _n; n   } n }; n long long inq(long long x, long long q, long long MOD) { n   if (q == 0) return 1; n   long long l = inq(x, q / 2, MOD); n   if (q % 2) return l * l % MOD * x % MOD; n   return l * l % MOD; n } n };  // namespace MySpace n using namespace MySpace; n long long n, m; n long long a[500000]; n int main() { n   ios_base::sync_with_stdio(); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = n; i < 2 * n; i++) cin >> a[i]; n   sort(a, a + 2 * n); n   long long s1 = 0, s2 = 0; n   for (int i = 0; i < n; i++) s1 += a[i]; n   for (int i = n; i < 2 * n; i++) s2 += a[i]; n   if (s1 == s2) { n     cout << -1; n     return 0; n   } n   for (int i = 0; i < 2 * n; i++) cout << a[i] <<    ; n } n


#include <bits/stdc++.h> n struct event { n   int t, time, L, R, idx; n   event() {} n   event(int t, int time, int L, int R, int idx) n       : t(t), time(time), L(L), R(R), idx(idx) {} n   bool operator<(const event& a) const { n     return (time < a.time || (time == a.time && t < a.t)); n   } n } e[200005 * 23]; n int n, m, i, j, ai, place[200005], L, R, en, idx, ans[200005], fw[200005]; n void modify(int j) { n   for (; j <= n; j = (j | (j - 1)) + 1) ++fw[j]; n } n int query(int j) { n   int rt = 0; n   for (; j; j &= (j - 1)) rt += fw[j]; n   return rt; n } n int main(int argc, char* const argv[]) { n   scanf( %d%d , &n, &m); n   for (i = 1; i <= n; i++) { n     scanf( %d , &ai); n     place[ai] = i; n   } n   for (i = 1; i <= m; i++) { n     scanf( %d%d , &L, &R); n     e[++en] = event(2, R, L, R, i); n     e[++en] = event(2, L - 1, L, R, -i); n   } n   for (i = 1; i <= n; i++) { n     j = i; n     while (j <= n) { n       e[++en] = event(1, place[i], place[j], 0, 0); n       j += i; n     } n   } n   std::sort(e + 1, e + en + 1); n   for (i = 1; i <= en; i++) n     if (e[i].t == 1) n       modify(e[i].L); n     else { n       idx = abs(e[i].idx); n       ans[idx] += (query(e[i].R) - query(e[i].L - 1)) * (e[i].idx / idx); n     } n   for (i = 1; i <= m; i++) printf( %d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n const int inf = 0x7FFFFFFF; n using namespace std; n int dep[2014], shortcut[20][2014]; n struct Edge { n   int u, v, w; n   bool operator<(const Edge &A) const { return w < A.w; } n } E[4000005]; n int mp[2014][2014]; n int fa[2014], d[2014]; n int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } n vector<int> G[2014], Q; n int get_lca(int a, int b) { n   if (dep[a] < dep[b]) swap(a, b); n   for (int i = 20 - 1; i >= 0; i--) { n     if (dep[a] - dep[b] >> i & 1) { n       a = shortcut[i][a]; n     } n   } n   if (a == b) return a; n   for (int i = 20 - 1; i >= 0; i--) { n     if (shortcut[i][a] != shortcut[i][b]) { n       a = shortcut[i][a]; n       b = shortcut[i][b]; n     } n   } n   return shortcut[0][a]; n } n int main() { n   int N; n   scanf( %d , &N); n   for (int i = 1; i <= N; i++) n     for (int j = 1; j <= N; j++) scanf( %d , &mp[i][j]); n   int tot = 0; n   for (int i = 1; i <= N; i++) n     for (int j = i + 1; j <= N; j++) { n       E[tot].u = i; n       E[tot].v = j; n       E[tot].w = mp[i][j]; n       tot++; n     } n   sort(E, E + tot); n   for (int i = 1; i <= N; i++) fa[i] = i; n   for (int i = 0; i < tot; i++) { n     int u = E[i].u; n     int v = E[i].v; n     if (find(u) != find(v)) { n       fa[find(u)] = find(v); n       G[u].push_back(v); n       G[u].push_back(E[i].w); n       G[v].push_back(u); n       G[v].push_back(E[i].w); n     } n   } n   int *parent = shortcut[0]; n   d[1] = 0; n   parent[1] = -1; n   dep[1] = 0; n   Q.push_back(1); n   for (int head = 0; head < int(Q.size()); head++) { n     int u = Q[head]; n     for (int i = 0; i < int(G[u].size()); i += 2) { n       int v = G[u][i]; n       int w = G[u][i + 1]; n       if (v != parent[u]) { n         parent[v] = u; n         dep[v] = dep[u] + 1; n         d[v] = d[u] + w; n         Q.push_back(v); n       } n     } n   } n   for (int i = 1; i < 20; i++) { n     for (int j = 1; j <= N; j++) { n       int &res = shortcut[i][j]; n       res = shortcut[i - 1][j]; n       if (~res) { n         res = shortcut[i - 1][res]; n       } n     } n   } n   bool ok = true; n   int num = 0; n   for (int i = 1; i <= N; i++) n     if (fa[i] == i) num++; n   if (num > 1) ok = false; n   for (int u = 1; ok && u <= N; u++) { n     if (mp[u][u] != 0) ok = false; n     for (int v = u + 1; ok && v <= N; v++) { n       if (mp[u][v] != mp[v][u]) ok = false; n       if (mp[u][v] == 0) ok = false; n       int mid = get_lca(u, v); n       if (d[u] + d[v] - d[mid] * 2 != mp[u][v]) ok = false; n     } n   } n   puts(ok ?  YES  :  NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e18; n const long long mod = 1e9 + 7; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long q; n   cin >> q; n   ; n   for (long long i = (1); i <= (q); i++) { n     long long n; n     cin >> n; n     ; n     long long r; n     cin >> r; n     ; n     set<long long, greater<long long>> s; n     for (long long i = (1); i <= (n); i++) { n       long long x; n       cin >> x; n       ; n       s.insert(x); n     } n     long long k = 0, st = 0; n     for (long long j : s) { n       if (j - r * k <= 0) { n         cout << k <<   n ; n         st = 1; n         break; n       } n       k++; n     } n     if (!st) cout << k <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int mx = 2e5 + 10; n long long x[mx], y[mx]; n ifstream fin( input.txt ); n ofstream fout( output.txt ); n long long sum[5]; n int main() { n   string b; n   cin >> b; n   int x = 0, y = 0; n   for (int i = 0; i < b.size(); i++) { n     if (b[i] ==  x ) n       x++; n     else n       y++; n   } n   if (x > y) { n     for (int i = 1; i <= x - y; i++) cout <<  x ; n     return 0; n   } n   for (int i = 1; i <= y - x; i++) cout <<  y ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10; n const int M = 1e9 + 7; n const int MOD = 998244353; n const double PI = 3.141592653589793238460; n const int bs = 1e9 + 7; n unsigned long long power(unsigned long long a, unsigned long long b) { n   unsigned long long res = 1; n   if (a == 0) return 0; n   if (a == 1) return 1; n   for (; b > 0; b >>= 1) { n     if (b & 1) res = (res * a); n     if (res > MOD) res %= MOD; n     a = (a * a); n     if (a > MOD) a = a % MOD; n   } n   return res; n } n bool isPrime[1000001]; n vector<unsigned long long> prime; n void seive(int limit) { n   isPrime[0] = isPrime[1] = 1; n   for (int i = 2; i * i <= limit; i++) { n     if (!isPrime[i]) n       for (int j = i * i; j <= limit; j += i) { n         isPrime[j] = 1; n       } n   } n   for (int i = 2; i <= limit; i++) n     if (!isPrime[i]) prime.push_back(i); n } n map<string, int> m; n unsigned long long parent[100100], sz[100100]; n vector<pair<unsigned long long, unsigned long long>> v[100010]; n vector<pair<pair<unsigned long long, unsigned long long>, n             pair<unsigned long long, unsigned long long>>> n     rem; n int visited[100010], valid[100010], cum[100110]; n int n, q1, q2; n int finds(int i) { n   while (parent[i] != i) i = parent[i]; n   return i; n } n int unions(int x, int y) { n   int xr = finds(x); n   int yr = finds(y); n   if (xr == yr) return 0; n   if (sz[xr] > sz[yr]) n     parent[yr] = xr; n   else if (sz[xr] < sz[yr]) n     parent[xr] = yr; n   else { n     sz[yr]++; n     parent[xr] = yr; n   } n   return 1; n } n void dfs(int node, int pnode, int x) { n   cum[node] = x; n   visited[node] = 1; n   for (int i = 0; i < v[node].size(); i++) { n     if (!visited[v[node][i].first]) n       dfs(v[node][i].first, node, x ^ (v[node][i].second)); n   } n } n void process() { n   for (int i = 0; i < n; i++) n     if (!visited[i]) dfs(i, i, 0); n   for (int i = 0; i < rem.size(); i++) { n     int x = rem[i].first.first, y = rem[i].first.second; n     int idx = rem[i].second.first, t = rem[i].second.second; n     if (cum[x] ^ cum[y] != t) n       valid[idx] = 0; n     else n       valid[idx] = 1; n   } n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0); n   int tt = 1; n   while (tt--) { n     cin >> n >> q1 >> q2; n     for (int i = 0; i < n; i++) { n       string s; n       cin >> s; n       m[s] = i; n       parent[i] = i; n       sz[i] = 0; n     } n     for (int i = 0; i < q1; i++) { n       int t; n       cin >> t; n       string a, b; n       cin >> a >> b; n       int x = m[a], y = m[b]; n       if (unions(x, y)) { n         v[x].push_back({y, t - 1}); n         v[y].push_back({x, t - 1}); n         valid[i] = 1; n       } else n         rem.push_back({{x, y}, {i, t - 1}}); n     } n     process(); n     for (int i = 0; i < q1; i++) { n       if (valid[i]) n         cout <<  YES  n              <<   n ; n       else n         cout <<  NO  n              <<   n ; n     } n     for (int i = 0; i < q2; i++) { n       string a, b; n       cin >> a >> b; n       int x = m[a], y = m[b]; n       if (finds(x) != finds(y)) n         cout << 3 <<   n ; n       else n         cout << (cum[x] ^ cum[y]) + 1 <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long n, m; n   cin >> n >> m; n   if (n > 26) n     cout << m; n   else { n     n = pow(2, n); n     cout << m % n; n   } n   return 0; n } n


#include <bits/stdc++.h> n const long long INFLL = 1e18; n using namespace std; n const int MAXN = 2 * 100000; n const int INF = 1000 * 1000 * 1000; n int a[MAXN + 1], used[MAXN + 10]; n int main() { n   int n; n   scanf( %d , &n); n   int ans = 1; n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     if (used[a[i]]) { n       ans++; n     } n     used[a[i]] = 1; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int>> segT; n vector<int> lazy; n long long n, m, l, r; n string s; n void buildT(int ss, int se, int si) { n   if (ss == se) { n     if (s[ss] ==  4 ) n       segT[si][0] = 1; n     else n       segT[si][1] = 1; n     segT[si][2] = 1; n     segT[si][3] = 1; n     return; n   } n   int mid = (ss + se) / 2; n   buildT(ss, mid, 2 * si + 1); n   buildT(mid + 1, se, 2 * si + 2); n   segT[si][0] = segT[2 * si + 1][0] + segT[2 * si + 2][0]; n   segT[si][1] = segT[2 * si + 1][1] + segT[2 * si + 2][1]; n   segT[si][2] = max(segT[2 * si + 1][2] + segT[2 * si + 2][1], n                     segT[2 * si + 1][0] + segT[2 * si + 2][2]); n   segT[si][3] = max(segT[2 * si + 1][3] + segT[2 * si + 2][0], n                     segT[2 * si + 1][1] + segT[2 * si + 2][3]); n } n void upd(int ss, int se, int si) { n   if (lazy[si] == 1) { n     swap(segT[si][0], segT[si][1]); n     swap(segT[si][2], segT[si][3]); n     if (ss != se) { n       lazy[2 * si + 1] ^= 1; n       lazy[2 * si + 2] ^= 1; n     } n     lazy[si] = 0; n   } n   if (r < ss || l > se) return; n   if (ss >= l && se <= r) { n     swap(segT[si][0], segT[si][1]); n     swap(segT[si][2], segT[si][3]); n     if (ss != se) { n       lazy[2 * si + 1] ^= 1; n       lazy[2 * si + 2] ^= 1; n     } n     return; n   } n   int mid = (ss + se) / 2; n   upd(ss, mid, 2 * si + 1); n   upd(mid + 1, se, 2 * si + 2); n   segT[si][0] = segT[2 * si + 1][0] + segT[2 * si + 2][0]; n   segT[si][1] = segT[2 * si + 1][1] + segT[2 * si + 2][1]; n   segT[si][2] = max(segT[2 * si + 1][2] + segT[2 * si + 2][1], n                     segT[2 * si + 1][0] + segT[2 * si + 2][2]); n   segT[si][3] = max(segT[2 * si + 1][3] + segT[2 * si + 2][0], n                     segT[2 * si + 1][1] + segT[2 * si + 2][3]); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int i, j; n   cin >> n >> m; n   cin >> s; n   long long lim = 2 * pow(2, ceil(log(n) / log(2.0))) + 2; n   vector<int> temp(lim, 0); n   vector<vector<int>> temp2(lim, vector<int>(4, 0)); n   segT = temp2; n   lazy = temp; n   buildT(0, n - 1, 0); n   string typ; n   for (i = 0; i < m; i++) { n     cin >> typ; n     if (typ.compare( switch ) == 0) { n       cin >> l >> r; n       l -= 1; n       r -= 1; n       upd(0, n - 1, 0); n     } else { n       if (lazy[0] == 1) n         cout << segT[0][3] << endl; n       else n         cout << segT[0][2] << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace ::std; n int main() { n   long long int temp, q, v1, v2, t, d, i, sum = 0; n   cin >> v1 >> v2 >> t >> d; n   long long int a[t]; n   sum = d * (t - 1); n   i = 0; n   temp = 0; n   bool ff = false; n   while (1) { n     if (!ff) { n       i += v1; n       a[temp] = i; n       temp++; n       ff = true; n       continue; n     } else if (i + d - sum + d <= v2) { n       i += d; n       sum -= d; n       a[temp] = i; n     } else { n       for (long long int k = d - 1; k >= -d; k--) { n         if (i + k - sum + d <= v2) { n           i += k; n           sum -= d; n           a[temp] = i; n           break; n         } n       } n     } n     temp++; n     if (temp == t) break; n   } n   long long int s = 0; n   for (long long int j = 0; j < t; j++) s += a[j]; n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e6 + 1e5, inf = 3e18, mod = 1e9 + 7; n long long tc, n, m, q, a, b, c, d, i, j, k; n long long A[N]; n vector<long long> vec; n string s; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> tc; n   while (tc--) { n     cin >> n >> m; n     long long flag1 = 0, flag2 = 0; n     for (i = 2; i < n + 2; i++) { n       cin >> A[i]; n       if (A[i] == m) flag1 = 1; n       if (A[i] >= m && (A[i - 1] >= m || A[i - 2] >= m)) flag2 = 1; n     } n     if (flag1 && flag2 || (n == 1 && A[2] == m)) n       cout <<  yes n ; n     else n       cout <<  no n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 2e5 + 5; n void solve() { n   long long int n; n   cin >> n; n   double ans, pi = 3.14159265358979323846; n   double rad = (2.0 * sin(pi / (2.0 * (double)n))); n   ans = (cos(pi / (4.0 * n))) / sin(pi / (2.0 * (double)n)); n   cout << fixed << setprecision(15) << ans <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); n   long long int t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, l[10], r[10], t = 1; n   double ans = 0, o = 1; n   cin >> n; n   for (int i = 0; i < n; i++) { n     t *= 2; n     cin >> l[i] >> r[i]; n     o *= r[i] - l[i] + 1; n   } n   if (n == 1) { n     cout << setprecision(10) << fixed << (r[0] + l[0]) / 2.0 << endl; n     return 0; n   } n   for (int i = 1; i <= 10000; i++) { n     for (int g = 0; g < n; g++) { n       if (r[g] <= i) continue; n       for (int j = 1; j < t; j++) { n         int a[10] = {}, t2 = j, o = 0; n         while (t2) { n           a[o++] = t2 % 2; n           t2 /= 2; n         } n         if (a[g]) continue; n         double k = 1; n         bool ch = 0; n         for (int h = 0; h < n; h++) { n           if (h == g) continue; n           if (a[h] && (r[h] < i || l[h] > i)) { n             ch = 1; n             h = n; n           } n           if (!a[h] && l[h] >= i) { n             ch = 1; n             h = n; n           } n           if (!a[h]) k *= min(i - 1, r[h]) - l[h] + 1; n         } n         if (ch) continue; n         k *= r[g] - max(i + 1, l[g]) + 1; n         ans += k * i; n       } n     } n   } n   for (int i = 1; i <= 10000; i++) { n     for (int j = 1; j < t; j++) { n       int a[10] = {}, t2 = j, o = 0, d = 0; n       while (t2) { n         a[o++] = t2 % 2; n         if (a[o - 1]) d++; n         t2 /= 2; n       } n       double k = 1; n       if (d == 1) continue; n       bool ch = 0; n       for (int h = 0; h < n; h++) { n         if (a[h] && (r[h] < i || l[h] > i)) { n           ch = 1; n           h = n; n         } n         if (!a[h] && l[h] >= i) { n           ch = 1; n           h = n; n         } n         if (!a[h]) k *= min(i - 1, r[h]) - l[h] + 1; n       } n       if (ch) continue; n       ans += k * i; n     } n   } n   cout << setprecision(10) << fixed << ans / o << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n template <class T> n inline T read() { n   T x = 0, f = 1; n   char s = getchar(); n   while (s <  0  || s >  9 ) { n     if (s ==  - ) f = -1; n     s = getchar(); n   }; n   while (s >=  0  && s <=  9 ) { n     x = (x << 3) + (x << 1) + s - 48; n     s = getchar(); n   }; n   return x * f; n } n template <typename T> n inline void wri(T x) { n   if (x < 0) { n     x = -x; n     putchar( - ); n   }; n   if (x / 10) wri(x / 10); n   putchar(x % 10 + 48); n } n template <typename T> n inline void print(T x, char s) { n   wri(x); n   putchar(s); n } n struct node { n   int l, r, val, add; n } e[800010]; n int a[200010], ans[200010]; n void build_tree(int node, int start, int end) { n   e[node].l = start, e[node].r = end; n   if (start == end) { n     e[node].add = 0; n     e[node].val = a[start]; n     return; n   } n   int mid = (start + end) >> 1; n   build_tree(node << 1, start, mid), build_tree(node << 1 | 1, mid + 1, end); n } n void update(int x, int q, int val) { n   if (e[x].l == q && e[x].r == q) { n     e[x].val = val, e[x].add = 0; n     return; n   } n   int mid = (e[x].l + e[x].r) >> 1; n   e[x << 1].add = max(e[x << 1].add, e[x].add); n   e[x << 1 | 1].add = max(e[x << 1 | 1].add, e[x].add); n   e[x].add = 0; n   if (q <= mid) n     update(x << 1, q, val); n   else n     update(x << 1 | 1, q, val); n } n void query(int x) { n   if (e[x].l == e[x].r) { n     ans[e[x].l] = max(e[x].val, e[x].add); n     return; n   } n   e[x << 1].add = max(e[x << 1].add, e[x].add); n   e[x << 1 | 1].add = max(e[x << 1 | 1].add, e[x].add); n   query(x << 1), query(x << 1 | 1); n } n int main() { n   int n; n   n = read<int>(); n   for (register int i = (1); i < (n + 1); i++) a[i] = read<int>(); n   build_tree(1, 1, n); n   int q; n   q = read<int>(); n   while (q--) { n     int x, y, z; n     x = read<int>(); n     if (x == 1) { n       y = read<int>(), z = read<int>(); n       update(1, y, z); n     } else n       y = read<int>(), e[1].add = max(e[1].add, y); n   } n   query(1); n   for (register int i = (1); i < (n + 1); i++) print(ans[i],    ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   string cnv; n   cnv.reserve(62); n   for (char i =  a ; i <=  z ; ++i) { n     cnv.push_back(i); n   } n   for (char i =  A ; i <=  Z ; ++i) { n     cnv.push_back(i); n   } n   for (char i =  0 ; i <=  9 ; ++i) { n     cnv.push_back(i); n   } n   for (int i = 0; i < t; ++i) { n     int n, m, k; n     cin >> n >> m >> k; n     vector<string> mas(n); n     int cnt = 0; n     for (int j = 0; j < n; ++j) { n       cin >> mas[j]; n       for (char c : mas[j]) { n         cnt += (c ==  R ); n       } n     } n     int cur = 0; n     int perc = cnt / k; n     int bigger = cnt % k; n     int curcnt = 0; n     for (int i = 0; i < n; ++i) { n       if (i & 1) { n         for (int j = 0; j < m; ++j) { n           if (mas[i][j] ==  R  && curcnt == perc + (cur < bigger)) { n             ++cur; n             curcnt = 0; n           } n           if (mas[i][j] ==  R ) ++curcnt; n           mas[i][j] = cnv[cur]; n         } n       } else { n         for (int j = m - 1; j >= 0; --j) { n           if (mas[i][j] ==  R  && curcnt == perc + (cur < bigger)) { n             ++cur; n             curcnt = 0; n           } n           if (mas[i][j] ==  R ) ++curcnt; n           mas[i][j] = cnv[cur]; n         } n       } n     } n     for (int i = 0; i < n; ++i) { n       cout << mas[i] <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, l[50 + 1]; n void Answer() { n   int j = 1, s = n; n   for (int i = 1; i <= k; i++) { n     if (i > s) s += n - (++j) + 1; n     cout << j <<    ; n     for (int u = n - 1; u > n - j; u--) cout << l[u] <<    ; n     cout << l[s - i] << endl; n   } n } n int main() { n   cin >> n >> k; n   for (int i = 0; i < n; i++) cin >> l[i]; n   sort(l, l + n); n   Answer(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n inline void smin(T &a, U b) { n   if (a > b) a = b; n } n template <typename T, typename U> n inline void smax(T &a, U b) { n   if (a < b) a = b; n } n int power(int a, int b, int m, int ans = 1) { n   for (; b; b >>= 1, a = 1LL * a * a % m) n     if (b & 1) ans = 1LL * ans * a % m; n   return ans; n } n char s[500010]; n int l[12], r[12]; n int sz, ed; n int cnt[500010], ord[500010 << 1]; n struct node { n   int deep, fail, cnt, nxt[30], val[12]; n   void clear() { n     memset(nxt, -1, sizeof nxt); n     memset(val, 0, sizeof val); n     deep = fail = cnt = 0; n   } n } mem[500010 << 1]; n struct automaton { n   void init() { n     for (int i = 0; i < 26; i++) mem[0].nxt[i] = 1; n     mem[0].deep = -1; n     mem[1].clear(); n     mem[1].cnt = 1; n     sz = 2, ed = 1; n   } n   void insert(int c, int id) { n     if (~mem[ed].nxt[c]) { n       int p1 = mem[ed].nxt[c]; n       if (mem[p1].deep == mem[ed].deep + 1) { n         mem[p1].val[id]++; n         ed = p1; n         return; n       } n       int p2 = sz++; n       mem[p2] = mem[p1]; n       mem[p2].deep = mem[ed].deep + 1; n       mem[p2].cnt = 0; n       for (int i = 0; i < 12; i++) mem[p2].val[i] = 0; n       mem[p2].val[id] = 1; n       mem[p1].fail = p2; n       while (mem[ed].nxt[c] == p1) { n         mem[ed].nxt[c] = p2; n         mem[p1].cnt -= mem[ed].cnt; n         mem[p2].cnt += mem[ed].cnt; n         ed = mem[ed].fail; n       } n       ed = p2; n       return; n     } n     int p = sz++; n     mem[p].clear(); n     mem[p].deep = mem[ed].deep + 1; n     mem[p].val[id] = 1; n     while (mem[ed].nxt[c] == -1) { n       mem[ed].nxt[c] = p; n       mem[p].cnt += mem[ed].cnt; n       ed = mem[ed].fail; n     } n     int p1 = mem[ed].nxt[c]; n     if (mem[p1].deep == mem[ed].deep + 1) n       mem[p].fail = p1; n     else { n       int p2 = sz++; n       mem[p2] = mem[p1]; n       mem[p2].deep = mem[ed].deep + 1; n       mem[p2].cnt = 0; n       for (int i = 0; i < 12; i++) mem[p2].val[i] = 0; n       mem[p].fail = mem[p1].fail = p2; n       while (mem[ed].nxt[c] == p1) { n         mem[ed].nxt[c] = p2; n         mem[p1].cnt -= mem[ed].cnt; n         mem[p2].cnt += mem[ed].cnt; n         ed = mem[ed].fail; n       } n     } n     ed = p; n   } n   void build(int n) { n     memset(cnt, 0, sizeof cnt); n     for (int i = 1; i < sz; i++) cnt[mem[i].deep]++; n     for (int i = 1; i < 500010; i++) cnt[i] += cnt[i - 1]; n     for (int i = 1; i < sz; i++) ord[--cnt[mem[i].deep]] = i; n     for (int i = sz - 2; i >= 0; i--) { n       int cur = ord[i], prv = mem[cur].fail; n       for (int j = 0; j <= n; j++) mem[prv].val[j] += mem[cur].val[j]; n     } n     long long ans = 0; n     for (int i = 2; i < sz; i++) n       if (mem[i].val[n]) { n         int ok = 1; n         for (int j = 0; j < n; j++) n           if (mem[i].val[j] < l[j] || mem[i].val[j] > r[j]) { n             ok = 0; n             break; n           } n         if (ok) ans += mem[i].cnt; n       } n     printf( %I64d n , ans); n   } n } sam; n int main() { n   int n; n   scanf( %s %d , s, &n); n   sam.init(); n   int len = strlen(s); n   for (int i = 0; i < len; i++) sam.insert(s[i] -  a , n); n   for (int i = 0; i < n; i++) { n     scanf( %s %d %d , s, l + i, r + i); n     ed = 1; n     len = strlen(s); n     for (int j = 0; j < len; j++) sam.insert(s[j] -  a , i); n   } n   sam.build(n); n } n


#include <bits/stdc++.h> n using namespace std; n double cal(int n, int *a, double x) { n   double ret = 0, t1 = 0, t2 = 0; n   for (int i = 0; i < n; i++) { n     t1 += a[i] - x; n     t2 += a[i] - x; n     t1 = max(0., t1); n     t2 = min(0., t2); n     ret = max(ret, t1); n     ret = max(ret, -t2); n   } n   return ret; n } n int main() { n   int n; n   scanf( %d , &n); n   static int a[200000]; n   for (int i = 0; i < n; i++) { n     scanf( %d , a + i); n   } n   double l = -10001, r = 10001, ans; n   for (int t = 0; t < 100; t++) { n     double d1 = (2 * l + r) / 3, d2 = (l + 2 * r) / 3; n     double e1 = cal(n, a, d1), e2 = cal(n, a, d2); n     if (e1 <= e2) { n       r = d2; n       ans = e1; n     } else { n       l = d1; n       ans = e2; n     } n   } n   printf( %.9lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1005; n char g[N][N]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     long double h, c, t; n     cin >> h >> c >> t; n     if (t >= h) { n       cout <<  1 n ; n       continue; n     } n     if ((h + c) / 2 >= t) { n       cout <<  2 n ; n       continue; n     } n     int x = 0; n     x = (h - t) / (2 * t - h - c); n     long double curd = 100000000.0; n     int res = -1; n     for (int i = max(0, x - 50); i <= x + 50; ++i) { n       long double xx = (i + 1) * h + i * c; n       xx = 1.0 * xx / (2 * i + 1); n       xx = abs(xx - t); n       if (xx < curd) { n         curd = xx; n         res = i; n       } n     } n     cout << 2 * res + 1 <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int Day12[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; n int prime100[] = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29, 31, 37,  41, 43, n                   47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103}; n template <typename T> n inline bool isLeap(T y) { n   return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false); n } n template <typename T> n inline T GCD(T a, T b) { n   a = abs(a); n   b = abs(b); n   if (a < b) swap(a, b); n   while (b) { n     a = a % b; n     swap(a, b); n   } n   return a; n } n template <typename T> n inline T LCM(T x, T y) { n   T tp = GCD(x, y); n   if ((x / tp) * 1. * y > 9e18) return 9e18; n   return (x / tp) * y; n } n template <typename T> n inline T BIGMOD(T A, T B, T M = 1000000007) { n   T ret = 1; n   while (B) { n     if (B & 1) ret = (ret * A) % M; n     A = (A * A) % M; n     B = B >> 1; n   } n   return ret; n } n template <typename T> n inline T BigMod(T A, T B, T M) { n   T ret = 1; n   while (B) { n     if (B & 1) ret = (ret * A) % M; n     A = (A * A) % M; n     B = B >> 1; n   } n   return ret; n } n long long int MySqrt(long long int n) { n   long long int p = sqrt(n); n   if ((p + 1) * (p + 1) <= n) n     return p + 1; n   else if (p * p <= n) n     return p; n   else n     return p - 1; n } n long long int MyPow(long long int x, long long int n) { n   if (n == 0) n     return 1; n   else if (n % 2 == 0) n     return MyPow(x * x, n / 2); n   else n     return x * MyPow(x * x, ((n - 1) / 2)); n } n long long int modInverse(long long int n) { n   return BIGMOD(n, (long long int)1000000007 - 2) % 1000000007; n } n void solve() { n   long long int ans = 1, n; n   cin >> n; n   if (n % 2 == 1) n     printf( 0 n ); n   else { n     n /= 2; n     for (int i = 1; i <= n; i++) ans *= 2; n     printf( %lld n , ans); n   } n } n char arr[505][505]; n int Left[505][505]; n int Right[505][505]; n int Up[505][505]; n int Low[505][505]; n void Now() { n   int n, m, cnt = 0; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> arr[i][j]; n       if (arr[i][j] ==  * ) cnt++; n     } n   } n   for (int i = 1; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (arr[i - 1][j] ==  * ) Up[i][j] += 1 + Up[i - 1][j]; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 1; j < m; j++) { n       if (arr[i][j - 1] ==  * ) Left[i][j] += 1 + Left[i][j - 1]; n     } n   } n   for (int i = n - 1; i >= 0; i--) { n     for (int j = m - 2; j >= 0; j--) { n       if (arr[i][j + 1] ==  * ) Right[i][j] += 1 + Right[i][j + 1]; n     } n   } n   for (int i = n - 2; i >= 0; i--) { n     for (int j = m - 1; j >= 0; j--) { n       if (arr[i + 1][j] ==  * ) Low[i][j] += 1 + Low[i + 1][j]; n     } n   } n   for (int i = 1; i < n - 1; i++) { n     for (int j = 1; j < m - 1; j++) { n       if (Left[i][j] > 0 && Up[i][j] > 0 && Right[i][j] > 0 && Low[i][j] > 0 && n           arr[i][j] ==  * ) { n         if (Left[i][j] + Up[i][j] + Right[i][j] + Low[i][j] + 1 == cnt) { n           printf( YES n ); n           exit(0); n         } n       } n     } n   } n   printf( NO n ); n } n int main() { solve(); } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n, m; n   int x, y; n   int z = 1; n   cin >> n >> m; n   cin >> x >> y; n   cout << x <<     << y <<   n ; n   cout << 1 <<     << y <<   n ; n   for (int i = 1; i <= n; i++) { n     vector<pair<int, int>> v; n     for (int j = 1; j <= m; j++) { n       if ((i == x && j == y) || (i == 1 && j == y)) continue; n       v.push_back({i, j}); n     } n     if (z) { n       reverse(v.begin(), v.end()); n     } n     for (auto it : v) { n       cout << it.first <<     << it.second <<   n ; n     } n     z ^= 1; n   } n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n int n, q, a[N], node[4 * N]; n vector<int> pos[N]; n void init(int i, int l, int r) { n   if (l == r) { n     node[i] = (a[l] == 0 ? 1e9 : a[l]); n     return; n   } n   int m = (l + r) >> 1; n   init(i << 1, l, m); n   init(i << 1 | 1, m + 1, r); n   node[i] = min(node[i << 1], node[i << 1 | 1]); n } n int get(int i, int l, int r, int a, int b) { n   if (l > r || a > r || b < l) return (int)1e9; n   if (a <= l && r <= b) return node[i]; n   int m = (l + r) >> 1; n   return min(get(i << 1, l, m, a, b), get(i << 1 | 1, m + 1, r, a, b)); n } n int main() { n   scanf( %d %d , &n, &q); n   bool f = false; n   bool zero = false; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     if (a[i] == q) f = true; n     if (a[i]) n       pos[a[i]].push_back(i); n     else n       zero = true; n   } n   if (!f && !zero) return !printf( NO ); n   init(1, 1, n); n   for (int i = 1; i <= q; i++) { n     if (pos[i].size() > 0) { n       if (get(1, 1, n, pos[i][0], pos[i][pos[i].size() - 1]) < i) n         return !printf( NO ); n     } n   } n   puts( YES ); n   int l = 1; n   while (l <= n) { n     while (l <= n && a[l]) l++; n     int r = l; n     while (r <= n && !a[r]) r++; n     if (l > 1) { n       for (int j = l; j < r; j++) a[j] = f ? a[l - 1] : q; n       if (!f) f = true; n     } else if (r <= n) { n       for (int j = l; j < r; j++) a[j] = f ? a[r] : q; n       if (!f) f = true; n     } else n       for (int j = l; j < r; j++) a[j] = q; n     l = r; n   } n   for (int i = 1; i <= n; i++) printf( %d  , a[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline void ckmax(T& x, T y) { n   x = (y > x ? y : x); n } n template <typename T> n inline void ckmin(T& x, T y) { n   x = (y < x ? y : x); n } n namespace Fread { n const int SIZE = 1 << 21; n char buf[SIZE], *S, *T; n inline char getchar() { n   if (S == T) { n     T = (S = buf) + fread(buf, 1, SIZE, stdin); n     if (S == T) return   n ; n   } n   return *S++; n } n }  // namespace Fread n namespace Fwrite { n const int SIZE = 1 << 21; n char buf[SIZE], *S = buf, *T = buf + SIZE; n inline void flush() { n   fwrite(buf, 1, S - buf, stdout); n   S = buf; n } n inline void putchar(char c) { n   *S++ = c; n   if (S == T) flush(); n } n struct NTR { n   ~NTR() { flush(); } n } ztr; n }  // namespace Fwrite n namespace Fastio { n struct Reader { n   template <typename T> n   Reader& operator>>(T& x) { n     char c = Fread ::getchar(); n     T f = 1; n     while (c <  0  || c >  9 ) { n       if (c ==  - ) f = -1; n       c = Fread ::getchar(); n     } n     x = 0; n     while (c >=  0  && c <=  9 ) { n       x = x * 10 + (c -  0 ); n       c = Fread ::getchar(); n     } n     x *= f; n     return *this; n   } n   Reader& operator>>(char& c) { n     c = Fread ::getchar(); n     while (c ==   n  || c ==    ) c = Fread ::getchar(); n     return *this; n   } n   Reader& operator>>(char* str) { n     int len = 0; n     char c = Fread ::getchar(); n     while (c ==   n  || c ==    ) c = Fread ::getchar(); n     while (c !=   n  && c !=    ) { n       str[len++] = c; n       c = Fread ::getchar(); n     } n     str[len] =   0 ; n     return *this; n   } n   Reader() {} n } cin; n const char endl =   n ; n struct Writer { n   template <typename T> n   Writer& operator<<(T x) { n     if (x == 0) { n       Fwrite ::putchar( 0 ); n       return *this; n     } n     if (x < 0) { n       Fwrite ::putchar( - ); n       x = -x; n     } n     static int sta[45]; n     int top = 0; n     while (x) { n       sta[++top] = x % 10; n       x /= 10; n     } n     while (top) { n       Fwrite ::putchar(sta[top] +  0 ); n       --top; n     } n     return *this; n   } n   Writer& operator<<(char c) { n     Fwrite ::putchar(c); n     return *this; n   } n   Writer& operator<<(char* str) { n     int cur = 0; n     while (str[cur]) Fwrite ::putchar(str[cur++]); n     return *this; n   } n   Writer& operator<<(const char* str) { n     int cur = 0; n     while (str[cur]) Fwrite ::putchar(str[cur++]); n     return *this; n   } n   Writer() {} n } cout; n }  // namespace Fastio n const int MAXN = 1000, MAXM = 3e4; n const int INF = 2e9 + 233; n int n, m, s, t; n struct EDGE { n   int nxt, to, w, id; n } edge[MAXM * 2 + 5]; n int head[MAXN + 5], tot; n inline void add_edge(int u, int v, int w, int id) { n   edge[++tot].nxt = head[u]; n   edge[tot].to = v; n   edge[tot].w = w; n   edge[tot].id = id; n   head[u] = tot; n } n pair<int, pair<int, int> > ans; n int dfn[MAXN + 5], ofn[MAXN + 5], cnt_dfn; n int fa[MAXN + 5], fw[MAXN + 5], fid[MAXN + 5]; n int num[MAXN + 5]; n long long sum[MAXN + 5], sumid[MAXN + 5]; n unsigned long long sumhash[MAXN + 5]; n map<unsigned long long, bool> vis; n int id[MAXN + 5], lca[MAXN + 5]; n set<pair<int, int> > S[MAXN + 5]; n vector<pair<int, int> > to_del[MAXN + 5]; n int an[MAXN + 5][10], dep[MAXN + 5]; n int get_lca(int u, int v) { n   if (dep[u] < dep[v]) swap(u, v); n   for (int i = 9; i >= 0; --i) { n     if (dep[an[u][i]] >= dep[v]) { n       u = an[u][i]; n     } n   } n   if (u == v) return u; n   for (int i = 9; i >= 0; --i) { n     if (an[u][i] != an[v][i]) { n       u = an[u][i]; n       v = an[v][i]; n     } n   } n   return an[u][0]; n } n int l(int id) { n   int x = edge[id * 2].to; n   int y = edge[id * 2 - 1].to; n   if (dfn[x] < dfn[y]) swap(x, y); n   return x; n } n void dfs(int u) { n   dfn[u] = ++cnt_dfn; n   an[u][0] = fa[u]; n   dep[u] = dep[fa[u]] + 1; n   for (int i = 1; i <= 9; ++i) { n     an[u][i] = an[an[u][i - 1]][i - 1]; n   } n   for (int i = head[u]; i; i = edge[i].nxt) { n     int v = edge[i].to; n     if (edge[i].id == fid[u]) continue; n     if (!dfn[v]) { n       fa[v] = u; n       fw[v] = edge[i].w; n       fid[v] = edge[i].id; n       dfs(v); n       num[u] += num[v]; n       sum[u] += sum[v]; n       sumid[u] += sumid[v]; n       sumhash[u] += sumhash[v]; n       if (((int)(S[id[u]]).size()) < ((int)(S[id[v]]).size())) { n         swap(id[u], id[v]); n       } n       for (set<pair<int, int> >::iterator it = S[id[v]].begin(); n            it != S[id[v]].end(); ++it) { n         S[id[u]].insert(*it); n       } n     } else if (dfn[v] < dfn[u]) { n       num[u]++; n       num[v]--; n       sum[u] += edge[i].w; n       sum[v] -= edge[i].w; n       sumid[u] += edge[i].id; n       sumid[v] -= edge[i].id; n       S[id[u]].insert(make_pair(dfn[u], edge[i].id)); n       to_del[v].push_back(make_pair(dfn[u], edge[i].id)); n       unsigned long long hashw = n           (((unsigned long long)rand() << 30) ^ (rand() << 15) ^ rand()); n       while (vis[hashw]) { n         hashw = (((unsigned long long)rand() << 30) ^ (rand() << 15) ^ rand()); n       } n       vis[hashw] = 1; n       sumhash[u] += hashw; n       sumhash[v] -= hashw; n     } n   } n   for (int i = 0; i < ((int)(to_del[u]).size()); ++i) { n     S[id[u]].erase(to_del[u][i]); n   } n   assert(((int)(S[id[u]]).size()) == num[u]); n   if (num[u] >= 2) { n     lca[u] = get_lca(l(S[id[u]].begin()->second), l(S[id[u]].rbegin()->second)); n   } n   ofn[u] = cnt_dfn; n } n int main() { n   srand((unsigned long long)time(0) ^ (unsigned long long)(new char)); n   Fastio ::cin >> n >> m; n   Fastio ::cin >> s >> t; n   for (int i = 1; i <= m; ++i) { n     int u, v, w; n     Fastio ::cin >> u >> v >> w; n     add_edge(u, v, w, i); n     add_edge(v, u, w, i); n   } n   for (int i = 1; i <= n; ++i) { n     id[i] = i; n   } n   ans = make_pair(INF, make_pair(INF, INF)); n   dfs(s); n   if (!dfn[t]) { n     Fastio ::cout << 0 << Fastio ::endl; n     Fastio ::cout << 0 << Fastio ::endl; n     Fastio ::cout << Fastio ::endl; n     return 0; n   } n   for (int u = t; u != s; u = fa[u]) { n     if (num[u] == 0) { n       ckmin(ans, make_pair(fw[u], make_pair(fid[u], 0))); n     } else if (num[u] == 1) { n       ckmin(ans, n             make_pair(fw[u] + (int)sum[u], make_pair(fid[u], (int)sumid[u]))); n       int x = l(sumid[u]); n       for (int v = x; v != u; v = fa[v]) { n         if (num[v] == 1) { n           if (dfn[get_lca(t, x)] < dfn[v]) { n             ckmin(ans, make_pair(fw[u] + fw[v], make_pair(fid[u], fid[v]))); n           } n         } n       } n     } else { n       int x = lca[u]; n       for (int v = x; v != u; v = fa[v]) { n         if (num[u] == num[v] && sum[u] == sum[v] && sumid[u] == sumid[v] && n             sumhash[u] == sumhash[v]) { n           if (dfn[get_lca(t, x)] < dfn[v]) { n             ckmin(ans, make_pair(fw[u] + fw[v], make_pair(fid[u], fid[v]))); n           } n         } n       } n     } n   } n   if (ans.first == INF) { n     Fastio ::cout << -1 << Fastio ::endl; n     return 0; n   } n   Fastio ::cout << ans.first << Fastio ::endl; n   if (ans.second.second == 0) { n     Fastio ::cout << 1 << Fastio ::endl; n     Fastio ::cout << ans.second.first << Fastio ::endl; n   } else { n     Fastio ::cout << 2 << Fastio ::endl; n     Fastio ::cout << ans.second.first <<     << ans.second.second n                   << Fastio ::endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   long long a, f, sec, t = 0, h = 0; n   cin >> a; n   vector<long long> par; n   vector<long long> m; n   for (int i = 0; i < s.length(); i++) { n     if (s[i - 1] == s[i]) { n       h++; n     } n     par.push_back(h); n   } n   for (int i = 0; i < a; i++) { n     cin >> f >> sec; n     m.push_back(par[sec - 1] - par[f - 1]); n   } n   for (int i = 0; i < a; i++) { n     cout << m[i] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long dp[2]; n void solve() { n   long long n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     dp[i % 2] = dp[i % 2] + dp[!(i % 2)] + 1; n     if (dp[i % 2] > 1000000007) dp[i % 2] %= 1000000007; n   } n   cout << (dp[0] + dp[1] + 1000000007) % (1000000007); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, t; n   cin >> n >> t; n   int* time = new int[n]; n   for (int i = 0; i < n; i++) { n     cin >> time[i]; n   } n   int sum = 0, count = 0; n   int ans = INT_MIN; n   for (int i = 0; i < n; i++) { n     if (sum + time[i] <= t) { n       sum += time[i]; n       count++; n     } else { n       sum = sum - time[i - count] + time[i]; n     } n     ans = max(ans, count); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n vector<int> a; n int was[100100]; n int t[100100]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 1; i <= 2 * n; i++) { n     int x; n     cin >> x; n     a.push_back(x); n   } n   vector<int> ans; n   int cnt = 0; n   for (int i = 0; i < 2 * n; i++) { n     if (!was[a[i]]) { n       t[a[i]] = i; n       ans.push_back(a[i]); n       was[a[i]] = true; n     } else { n       was[a[i]] = true; n       cnt += i - t[a[i]] - 1; n       ans.insert(ans.begin() + t[a[i]] + 1, a[i]); n       for (int j = 0; j < ans.size(); j++) { n         t[ans[j]] = j; n       } n     } n   } n   cout << cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> tab[100100], ans; n int n, ls[10]; n bool used[100100]; n bool chek(int a, int b) { n   for (int i = 0; i < 4; i++) n     if (tab[a][i] == b) return true; n   return false; n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n + n; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     if (a == b) { n       puts( -1 ); n       return 0; n     } n     tab[a].push_back(b); n     tab[b].push_back(a); n   } n   for (int i = 1; i <= n; i++) { n     if (tab[i].size() != 4) { n       puts( -1 ); n       return 0; n     } n   } n   if (n <= 10) { n     int ar[30] = {}; n     for (int i = 0; i < n; i++) ar[i] = i + 1; n     do { n       ar[n] = ar[0]; n       ar[n + 1] = ar[1]; n       bool ok = true; n       for (int i = 0; i < n; i++) { n         if (!chek(ar[i], ar[i + 1]) || !chek(ar[i], ar[i + 2])) { n           ok = false; n           break; n         } n       } n       if (ok) { n         for (int i = 0; i < n; i++) n           printf( %d%c , ar[i], i == n - 1 ?   n  :    ); n         return 0; n       } n     } while (std::next_permutation(ar, ar + n)); n     puts( -1 ); n     return 0; n   } n   int start = 1, pre = -1; n   while (!used[start]) { n     used[start] = true; n     ans.push_back(start); n     int nxt = start; n     for (int i = 0; i < 4; i++) { n       int cnt = 0; n       for (int j = 0; j < 4; j++) n         if (chek(tab[start][i], tab[start][j])) cnt++; n       if (cnt == 2 && tab[start][i] != pre) { n         nxt = tab[start][i]; n         break; n       } n     } n     if (nxt == start) { n       puts( -1 ); n       return 0; n     } n     pre = start; n     start = nxt; n   } n   if ((int)ans.size() < n) { n     puts( -1 ); n     return 0; n   } n   ans.push_back(ans[0]); n   ans.push_back(ans[1]); n   for (int i = 0; i < n; i++) { n     if (!chek(ans[i], ans[i + 1]) || !chek(ans[i], ans[i + 2])) { n       puts( -1 ); n       return 0; n     } n   } n   for (int i = 0; i < n; i++) printf( %d%c , ans[i], i == n - 1 ?   n  :    ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, q, sum, x; n int main(void) { n   scanf( %lld%lld , &n, &q); n   while (q--) { n     scanf( %lld , &x); n     while (x % 2 == 0) { n       sum = (x + 1) / 2 + 1, sum = n - sum, x += sum + 1; n     } n     printf( %lld n , x / 2 + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<pair<int, int> > s[2]; n bool eq(pair<int, int> a, pair<int, int> b) { n   return (a.first == b.first && a.second == b.second); n } n int main() { n   int n, m, i, a, b, j; n   scanf( %d%d , &n, &m); n   for (i = 0; i < n; i++) { n     scanf( %d%d , &a, &b); n     if (b < a) swap(a, b); n     s[0].insert(make_pair(a, b)); n   } n   for (i = 0; i < m; i++) { n     scanf( %d%d , &a, &b); n     if (b < a) swap(a, b); n     s[1].insert(make_pair(a, b)); n   } n   set<int> ans; n   for (auto i : s[0]) n     for (auto j : s[1]) { n       if (i.first == j.first && i.second == j.second) n         continue; n       else if (i.first != j.first && i.first != j.second && n                i.second != j.first && i.second != j.second) n         continue; n       else if (i.first == j.first) { n         for (auto k : s[0]) { n           if (eq(k, j)) continue; n           if (k.first == j.second || k.second == j.second) n             return !printf( -1 n ); n         } n         for (auto k : s[1]) { n           if (eq(k, i)) continue; n           if (k.first == i.second || k.second == i.second) n             return !printf( -1 n ); n         } n         ans.insert(i.first); n       } else if (i.first == j.second) { n         for (auto k : s[0]) { n           if (eq(k, j)) continue; n           if (k.first == j.first || k.second == j.first) return !printf( -1 n ); n         } n         for (auto k : s[1]) { n           if (eq(k, i)) continue; n           if (k.first == i.second || k.second == i.second) n             return !printf( -1 n ); n         } n         ans.insert(i.first); n       } else if (i.second == j.second) { n         for (auto k : s[0]) { n           if (eq(k, j)) continue; n           if (k.first == j.first || k.second == j.first) return !printf( -1 n ); n         } n         for (auto k : s[1]) { n           if (eq(k, i)) continue; n           if (k.first == i.first || k.second == i.first) return !printf( -1 n ); n         } n         ans.insert(i.second); n       } else if (i.second == j.first) { n         for (auto k : s[0]) { n           if (eq(k, j)) continue; n           if (k.first == j.second || k.second == j.second) n             return !printf( -1 n ); n         } n         for (auto k : s[1]) { n           if (eq(k, i)) continue; n           if (k.first == i.first || k.second == i.first) return !printf( -1 n ); n         } n         ans.insert(i.second); n       } n     } n   if ((int)ans.size() > 1) return !printf( 0 n ); n   cout << *ans.begin() << endl; n } n


#include <bits/stdc++.h> n using namespace std; n using LL = long long; n const LL INF = 2000000000000000000L; n struct Event { n   char c; n   LL v; n   int pos; n }; n void Dfs(int pos, vector<vector<pair<LL, int>>>& edge, vector<bool>& parallel, n          vector<LL>& ans) { n   if (edge[pos].size() == 0) { n     ans[pos] = 1; n     return; n   } n   if (parallel[pos]) { n     for (auto [vv, j] : edge[pos]) { n       Dfs(j, edge, parallel, ans); n     } n   } else { n     int j = 0; n     for (int i = 0; i < edge[pos].size(); ++i) { n       if (edge[pos][i].first < edge[pos][j].first) j = i; n     } n     Dfs(edge[pos][j].second, edge, parallel, ans); n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int times; n   cin >> times; n   while (times--) { n     int n; n     cin >> n; n     string ss; n     getline(cin, ss); n     string s; n     for (char c : ss) { n       if (c ==    ) continue; n       s.push_back(c); n     } n     vector<vector<pair<LL, int>>> edge(s.size()); n     vector<bool> sign(s.size()); n     stack<Event> st; n     for (int i = 0; i < s.size(); ++i) { n       if (s[i] ==  ) ) { n         vector<pair<LL, int>> x; n         bool parallel = false; n         int j = i; n         while (true) { n           Event e = st.top(); n           st.pop(); n           if (e.c ==  ( ) { n             j = e.pos; n             break; n           } n           if (e.c ==  P ) parallel = true; n           if (e.c ==  S ) parallel = false; n           if (e.c ==  * ) { n             x.push_back({e.v, e.pos}); n           } n         } n         sign[j] = parallel; n         for (int i = 0; i < x.size(); ++i) { n           edge[j].push_back(x[i]); n         } n         if (parallel) { n           LL ans = 0; n           for (auto [a, b] : x) ans += a; n           st.push({ * , ans, j}); n         } else { n           LL ans = INF; n           for (auto [a, b] : x) ans = min(ans, a); n           st.push({ * , ans, j}); n         } n       } else { n         st.push({s[i], 1, i}); n       } n     } n     vector<LL> ans(s.size()); n     Dfs(0, edge, sign, ans); n     cout <<  REVOLTING  ; n     for (int i = 0; i < s.size(); ++i) { n       if (s[i] ==  * ) cout << ans[i] * n * st.top().v <<    ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   int *arr = new int[n]; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   sort(arr, arr + n); n   reverse(arr, arr + n); n   cout << arr[k - 1]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int basecon(int n, int b); n int gcd(int a, int b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n int basecon(int n, int b) { n   int sum = 0; n   while (n) { n     sum = sum + (n % b); n     n = n / b; n   } n   return sum; n } n int main() { n   int n, sum = 0, y, g; n   cin >> n; n   y = n - 2; n   for (int i = 2; i < n; ++i) { n     sum = sum + basecon(n, i); n   } n   g = gcd(sum, y); n   sum = sum / g; n   y = y / g; n   cout << sum <<  /  << y << endl; n } n