#include <bits/stdc++.h> n using namespace std; n const int INF = 1000 * 1000 * 1000; n const double PI = acos(-1.0); n const int MAX = 150005; n int n, len, h; n pair<int, int> a[MAX]; n int b[MAX]; n pair<int, int> T[MAX * 8]; n int lazy[MAX * 8]; n bool pzdc[MAX]; n void push(int v) { n   T[v].first += lazy[v]; n   lazy[v * 2] += lazy[v]; n   lazy[v * 2 + 1] += lazy[v]; n   lazy[v] = 0; n } n void upd(int v, int tl, int tr, int l, int r, int delta) { n   push(v); n   if (l > r) return; n   if (tl == l && tr == r) { n     lazy[v] += delta; n     push(v); n     return; n   } n   int tm = (tl + tr) / 2; n   upd(v * 2, tl, tm, l, min(r, tm), delta); n   upd(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, delta); n   T[v] = min(T[v * 2], T[v * 2 + 1]); n } n void build(int v, int tl, int tr) { n   if (tl == tr) { n     T[v].second = tl; n     return; n   } n   int tm = (tl + tr) / 2; n   build(v * 2, tl, tm); n   build(v * 2 + 1, tm + 1, tr); n   T[v] = min(T[v * 2], T[v * 2 + 1]); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> len >> h; n   build(1, 0, n - len); n   for (int i = 0; i < len; i++) cin >> b[i]; n   sort(b, b + len); n   for (int i = 0; i < n; i++) { n     cin >> a[i].first; n     a[i].second = i; n   } n   sort(a, a + n); n   int ptr = n - 1; n   for (int i = 0; i < len; i++) { n     while (ptr >= 0 && a[ptr].first + b[i] >= h) { n       upd(1, 0, n - len, max(0, a[ptr].second - len + 1), n           min(n - len, a[ptr].second), 1); n       ptr--; n     } n     while (T[1].first <= i) { n       pzdc[T[1].second] = 1; n       upd(1, 0, n - len, T[1].second, T[1].second, INF); n     } n   } n   int ans = 0; n   for (int i = 0; i < n - len + 1; i++) ans += !pzdc[i]; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> a; n int main(int argc, char *argv[]) { n   int n; n   cin >> n; n   if (n == 1) { n     cout << 1; n     return 0; n   } n   if (n == 2) { n     cout << 1 <<     << 2; n     return 0; n   } n   if (n == 3) { n     cout << 1 <<     << 1 <<     << 3; n     return 0; n   } n   int so = 1, ts = 2, ss = n, luu = 1; n   while (ss > 2) { n     int m = n / ts; n     m = ss - m; n     for (int i = 1; i <= m; i++) cout << luu <<    ; n     ss = ss - m; n     if (ss == 1) { n       cout << ts; n       return 0; n     } n     if (ss == 2) { n       cout << ts <<     << ts * 2; n       return 0; n     } n     if (ss == 3) { n       cout << ts <<     << ts <<     << ts * 3; n       return 0; n     } n     luu = ts; n     ts = ts * 2; n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int> > T; n vector<vector<int> > T2; n set<int> att; n bool keep[123456 + 5]; n bool hasa(int from, int v) { n   keep[v] = false; n   if (att.find(v) != att.end()) keep[v] = 1; n   for (int i = 0; i < T[v].size(); ++i) { n     if (T[v][i] != from) keep[v] |= hasa(v, T[v][i]); n   } n   return keep[v]; n } n map<pair<int, int>, long long> dp[2]; n long long get(bool back, int from, int v) { n   pair<int, int> state(from, v); n   if (dp[back].find(state) == dp[back].end()) { n     long long ans = 0; n     for (int i = 0; i < T2[v].size(); ++i) { n       int u = T2[v][i]; n       if (u == from) continue; n       ans += 2 + get(true, v, u); n     } n     long long a2 = ans; n     if (!back) { n       for (int k = 0; k < T2[v].size(); ++k) { n         int u = T2[v][k]; n         if (u == from) continue; n         a2 = min(a2, ans - 2 - get(true, v, u) + 1 + get(false, v, u)); n       } n     } n     dp[back][state] = a2; n   } n   return dp[back][state]; n } n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i <= n; ++i) { n     T.push_back(vector<int>()); n     T2.push_back(vector<int>()); n   } n   for (int i = 1; i < n; ++i) { n     int a, b; n     cin >> a >> b; n     T[a].push_back(b); n     T[b].push_back(a); n   } n   for (int i = 0; i < m; ++i) { n     int a; n     cin >> a; n     att.insert(a); n   } n   fill(keep, keep + n, false); n   hasa(-1, *att.begin()); n   for (int i = 1; i <= n; ++i) { n     for (int j = 0; j < T[i].size(); ++j) { n       int u = T[i][j]; n       if (keep[i] && keep[u]) T2[i].push_back(u); n     } n   } n   long long vert = -1, mn = 0x7fffffffffffffff; n   for (int i = 1; i <= n; ++i) { n     if (keep[i]) { n       long long score = get(false, -1, i); n       if (score < mn) { n         vert = i; n         mn = score; n       } n     } n   } n   cout << vert <<   n  << mn <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5e5 + 5; n const long long inf = 0x3f3f3f3f3f; n long long a[1010][1010]; n long long n, k; n int main() { n   cin >> n >> k; n   long long cnt = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = n; j >= k; j--) { n       a[i][j] = n * n - cnt; n       cnt++; n     } n   } n   long long fcnt = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j < k; j++) { n       fcnt++; n       a[i][j] = fcnt; n     } n   } n   long long sum = 0; n   for (int i = 1; i <= n; i++) sum += a[i][k]; n   cout << sum << endl; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       cout << a[i][j] <<    ; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   string s; n   cin >> s; n   long long n = s.size(); n   long long an = 0; n   for (long long i = 0; i < n; i++) { n     long long r = INT_MAX; n     for (long long j = i; j <= min((long long)(i + 9), n - 1); j++) { n       for (long long k = 1; k <= 8; k++) { n         if (j + 2 * k < n) { n           if (s[j] == s[j + k] and s[j] == s[j + 2 * k]) { n             r = min(r, j + 2 * k); n           } n         } n       } n     } n     if (r != INT_MAX) an = an + n - r; n   } n   cout << an << endl; n } n


#include <bits/stdc++.h> n using namespace std; n bool cmp(string s1, string s2) { return (s1 + s2) < (s2 + s1); } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, n       v, w, x, y, z; n   cin >> n; n   vector<string> v1; n   string s1; n   for (i = 0; i < n; i++) { n     cin >> s1; n     v1.push_back(s1); n   } n   sort(v1.begin(), v1.end(), cmp); n   for (i = 0; i < n; i++) cout << v1[i]; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math ) n using namespace std; n const int N = 3e5 + 100; n set<pair<int, int> > s[N]; n int a[N]; n int nxt[N]; n int dp[N]; n int mol[N]; n int n; n void add(long long int v, long long int u) { n   long long int m = mol[u]; n   if (m != n + 2) s[m].insert({a[v], v}); n   mol[v] = mol[u]; n } n int tt; n void Main(long long int oo) { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     nxt[i] = n + 2; n     s[i].clear(); n     dp[i] = 0; n   } n   s[n + 1].clear(); n   s[n + 2].clear(); n   a[n + 1] = -1; n   a[n + 2] = -1; n   dp[n + 2] = 0; n   dp[n + 1] = 0; n   nxt[n + 2] = n + 2; n   mol[n + 2] = n + 2; n   nxt[n + 1] = n + 1; n   for (int i = 1; i <= n + 1; i++) { n     mol[i] = n + 1; n   } n   vector<int> pashm; n   for (int i = n; i; i--) { n     if (a[i] == a[i + 1]) { n       nxt[i] = i + 2; n       add(i, i + 2); n     } else { n       long long int z = mol[nxt[i + 1]]; n       if (z == n + 3) z = n + 2; n       auto y = s[z].lower_bound({a[i], 0}); n       if (y != s[z].end() && y->first == a[i]) { n         long long int p = y->second; n         nxt[i] = p + 1; n         add(i, p + 1); n       } else { n         mol[i] = i; n         nxt[i] = n + 2; n         add(i, i); n       } n     } n   } n   long long int ans = 0; n   for (int i = n; i; i--) { n     if (nxt[i] != n + 2) { n       dp[i] = 1 + dp[nxt[i]]; n     } n     ans += dp[i]; n   } n   cout << ans <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> tt; n   for (int i = 1; i <= tt; i++) Main(i); n } n


#include <bits/stdc++.h> n using namespace std; n template <class n, class second> n ostream &operator<<(ostream &p, pair<n, second> x) { n   return p <<  <  << x.first <<  ,   << x.second <<  > ; n } n template <class n> n auto operator<<(ostream &p, n y) -> n     typename enable_if<!is_same<n, string>::value, n                        decltype(y.begin(), p)>::type { n   int o = 0; n   p <<  { ; n   for (auto c : y) { n     if (o++) p <<  ,  ; n     p << c; n   } n   return p <<  } ; n } n void dor() { cerr << endl; } n template <class n, class... second> n void dor(n p, second... y) { n   cerr << p <<    ; n   dor(y...); n } n template <class n, class second> n void mini(n &p, second y) { n   if (p > y) p = y; n } n template <class n, class second> n void maxi(n &p, second y) { n   if (p < y) p = y; n } n const int M = 1024 * 256; n int n, k, x; n int in[M]; n int main() { n   scanf( %d%d , &n, &k); n   for (int i = (2); i <= (int)(n); ++i) { n     int a, b; n     scanf( %d%d , &a, &b); n     in[a]++; n     in[b]++; n   } n   for (int i = (1); i <= (int)(n); ++i) { n     if (in[i] == 1) { n       x++; n     } n   } n   printf( %.9Lf n , (long double)(k * 2) / x); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e9 + 5; n const long long INF = 1e18 + 5; n const long long maxn = 5e5 + 5; n long long n = 1000000007, d[151111], mx = -1000000001; n long long a[1511111], ok[100005], sum, cnt, rg[555555], v[555555]; n long long bi(long long x, long long y) { n   if (y == 0) return 1ll; n   if (y == 1) return x; n   long long z = bi(x, y / 2); n   z = z * z % n; n   if (y & 1) z = z * x % n; n   return z % n; n } n bool ch(string a, string b) { return a > b; } n map<string, long long> mm; n map<pair<string, string>, long long> ma; n long long first(long long m) { n   long long ans = m; n   for (long long i = 2; i * i <= m; i++) { n     if (m % i == 0) { n       while (m % i == 0) m /= i; n       ans -= ans / i; n     } n   } n   if (m > 1) ans -= ans / m; n   return ans; n } n long long dp[555555][55], b[55][55]; n int main() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(NULL); n   long long m; n   cin >> m; n   while (m--) { n     long long l, r, x; n     cin >> l >> r; n     x = l; n     for (long long i = 0; i <= 60; i++) { n       if ((x | (1ll << i)) <= r) { n         x |= (1ll << i); n       } n     } n     cout << x << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t = 1; n   cin >> t; n   while (t--) { n     long long int n; n     cin >> n; n     cout << n <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:102400000,102400000 ) n const int N = 2000005; n long long n, A, B, x, y; n int p[N]; n int main() { n   scanf( %lld%lld%lld , &n, &A, &B); n   y = -1; n   for (; x * A <= n; ++x) { n     long long tmp = n - x * A; n     if (tmp / B * B == tmp) { n       y = tmp / B; n       break; n     } n   } n   if (y == -1) return 0 * printf( -1 n ); n   int i = 1; n   while (x--) { n     int ti = i; n     p[ti + A - 1] = i; n     for (int ci = 1; ci <= A; ++ci) { n       if (ci < A) p[i] = i + 1; n       ++i; n     } n   } n   while (y--) { n     int ti = i; n     p[ti + B - 1] = i; n     for (int ci = 1; ci <= B; ++ci) { n       if (ci < B) p[i] = i + 1; n       ++i; n     } n   } n   for (int i = 1; i <= n; ++i) printf( %d  , p[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class c> n struct rge { n   c b, e; n }; n template <class c> n rge<c> range(c i, c j) { n   return rge<c>{i, j}; n } n template <class c> n auto dud(c* x) -> decltype(cerr << *x, 0); n template <class c> n char dud(...); n struct debug { n   template <class c> n   debug& operator<<(const c&) { n     return *this; n   } n }; n void test_case() { n   int n; n   scanf( %d , &n); n   vector<int> a(n); n   const int INF = 1e9 + 5; n   long long L = 1, R = INF; n   set<long long> s; n   long long offset = 0; n   int dp = 0; n   for (int i = 0; i < n; ++i) { n     scanf( %d , &a[i]); n     if (i % 2 == 1) { n       int diff = a[i] - a[i - 1]; n       L += diff; n       R += diff; n       offset += diff; n     } n     L = max(L, 1LL); n     R = min(R, a[i] - 1LL); n     while (!s.empty() && *s.begin() + offset < 1) { n       s.erase(s.begin()); n     } n     while (!s.empty() && *s.rbegin() + offset >= a[i]) { n       s.erase(prev(s.end())); n     } n     if (L <= R || !s.empty()) { n       if (i != 0) { n         dp++; n       } n       if (a[i] % 2 == 0) { n         if ((L <= a[i] / 2 && a[i] / 2 <= R) || s.count(a[i] / 2 - offset)) { n           dp++; n           L = R = a[i] / 2; n           s.clear(); n         } else { n           s.insert(a[i] / 2 - offset); n         } n       } n     } else { n       L = 1; n       R = a[i] - 1; n       if (a[i] % 2 == 0) { n         L = R = a[i] / 2; n         dp++; n       } n     } n   } n   debug() <<   [  n           <<  dp  n               :   n           << (dp) <<  ]  ; n   printf( %d n , 2 * n - dp); n } n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     test_case(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct kmp { n   vector<int> lps; n   string pattern; n   void compute_lps() { n     int lptr = 0, rptr = 1; n     lps[0] = 0; n     while (rptr < lps.size()) { n       while (lptr != 0 && pattern[lptr] != pattern[rptr]) lptr = lps[lptr - 1]; n       if (pattern[lptr] == pattern[rptr]) lptr++; n       lps[rptr] = lptr; n       rptr++; n     } n   } n   kmp(string& s) { n     pattern = s; n     lps.resize(s.size()); n     compute_lps(); n   } n   void search(string& s) { n     vector<int> hits; n     int lptr = 0, rptr = 0; n     while (rptr < s.size()) { n       while (lptr != 0 && pattern[lptr] != s[rptr]) lptr = lps[lptr - 1]; n       if (pattern[lptr] == s[rptr]) lptr++; n       rptr++; n       if (lptr == pattern.size()) { n         hits.push_back(rptr - pattern.size()); n         lptr = lps[lptr - 1]; n       } n     } n   } n }; n long long mod = 1e9 + 7; n long long add(long long a, long long b) { return (a + b) % mod; } n long long sub(long long a, long long b) { return ((a - b) % mod + mod) % mod; } n long long mul(long long a, long long b) { return (a * b) % mod; } n const int maxn = 205; n long long dp[maxn][maxn][maxn][2], ans; n int n; n string s; n int getmaxlen(kmp& KMP, char t, int mptr) { n   if (mptr == s.size()) mptr = KMP.lps[mptr - 1]; n   while (s[mptr] != t && mptr != 0) mptr = KMP.lps[mptr - 1]; n   if (s[mptr] == t) mptr++; n   return mptr; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   cin >> n >> s; n   dp[0][0][0][0] = 1; n   kmp KMP(s); n   for (int i = 0; i < (2 * n); i++) { n     for (int j = 0; j <= n; j++) { n       for (int k = 0; k < (2 * n) && k <= s.size(); k++) { n         for (int l = 0; l < 2; l++) { n           if (dp[i][j][k][l] == 0) continue; n           int mptr = getmaxlen(KMP,  ( , k); n           int matched = l; n           if (mptr == s.size()) matched = 1; n           dp[i + 1][j + 1][mptr][matched] = n               add(dp[i + 1][j + 1][mptr][matched], dp[i][j][k][l]); n           if (j != 0) { n             mptr = getmaxlen(KMP,  ) , k); n             matched = l; n             if (mptr == s.size()) matched = 1; n             dp[i + 1][j - 1][mptr][matched] = n                 add(dp[i + 1][j - 1][mptr][matched], dp[i][j][k][l]); n           } n         } n       } n     } n   } n   for (int i = 0; i <= s.size(); i++) ans = add(ans, dp[2 * n][0][i][1]); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 5; n const long double INF = 1e100; n const long double eps = 1e-12; n template <typename T> n void chkmax(T &x, T y) { n   x = max(x, y); n } n template <typename T> n void chkmin(T &x, T y) { n   x = min(x, y); n } n template <typename T> n void read(T &x) { n   x = 0; n   int f = 1; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = -f; n   for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ; n   x *= f; n } n template <typename T> n void write(T x) { n   if (x < 0) x = -x, putchar( - ); n   if (x > 9) write(x / 10); n   putchar(x % 10 +  0 ); n } n template <typename T> n void writeln(T x) { n   write(x); n   puts(  ); n } n int n, p, q; n long double a[MAXN], b[MAXN]; n long double check(long double x) { n   long double y = 1; n   for (int i = 1; i <= n; i++) chkmin(y, (1.0 - x * a[i]) / b[i]); n   return x * p + y * q; n } n int main() { n   read(n), read(p), read(q); n   long double l = 0, r = INF; n   for (int i = 1; i <= n; i++) { n     read(a[i]), read(b[i]); n     chkmin(r, 1.0 / a[i]); n   } n   while (l + eps < r) { n     long double ml = (2 * l + r) / 3, mr = (l + 2 * r) / 3; n     if (check(ml) > check(mr)) n       r = mr; n     else n       l = ml; n   } n   printf( %.10Lf n , check((l + r) / 2)); n   return 0; n } n


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


// In the name of Allah. n // We re nothing and you re everything. n // Ya Ali! n  n #include <bits/stdc++.h> n  n using namespace std; n typedef long long ll; n const int MAX_N = 1e5 + 14, MAX_K = 40; n int n, k; n  n struct XorKeeper { n     int a[MAX_K]{}; n  n     XorKeeper operator^(const XorKeeper &o) { n         XorKeeper ret; n         for (int i = 0; i < 2 * k; ++i) { n             ret.a[i] = a[i] ^ o.a[i]; n         } n         return ret; n     } n  n     XorKeeper &operator^=(const XorKeeper &o) { n         return *this = *this ^ o; n     } n  n     XorKeeper next() const { n         XorKeeper ret = *this; n         rotate(ret.a, ret.a + 2 * k - 1, ret.a + 2 * k); n         return ret; n     } n  n     int get_ans() { n         return accumulate(a + k, a + 2 * k, 0, [](int x, int y) { return x ^ y; }); n     } n } down[MAX_N], up[MAX_N]; n  n vector<int> g[MAX_N]; n int a[MAX_N]; n  n void dfs_down(int v = 0, int p = -1) { n     down[v].a[0] = a[v]; n     for (auto u : g[v]) n         if (u != p) { n             dfs_down(u, v); n             down[v] ^= down[u].next(); n         } n } n  n void dfs_up(int v = 0, int p = -1) { n     for (auto u : g[v]) n         if (u != p) { n             up[u] = (up[v] ^ down[v] ^ down[u].next()).next(); n             dfs_up(u, v); n         } n } n  n int main() { n     ios::sync_with_stdio(0), cin.tie(0); n     cin >> n >> k; n     for (int i = 0; i < n - 1; ++i) { n         int v, u; n         cin >> v >> u; n         v--, u--; n         g[v].push_back(u); n         g[u].push_back(v); n     } n     for (int i = 0; i < n; ++i) { n         cin >> a[i]; n     } n     dfs_down(); n     dfs_up(); n     for (int i = 0; i < n; ++i) { n         cout << bool(down[i].get_ans() ^ up[i].get_ans()) <<    ; n     } n     cout <<   n ; n }


#include <bits/stdc++.h> n using namespace std; n namespace hjt { n template <typename A, typename B> n std::ostream &operator<<(std::ostream &o, const std::pair<A, B> &x) { n   return o <<  (  << x.first <<  ,  << x.second <<  ) ; n } n }  // namespace hjt n using namespace hjt; n const double eps = 1e-7; n const double PI = acos(-1); n const int MOD = 998244353; n const int INF = 0x3f3f3f3f; n const int N = 3e5 + 7; n int n; n int a[N], b[N], dp[N]; n pair<int, int> path[N]; n set<int> st; n vector<int> ans; n void update(int &x, int y) { n   if (x == -1 || y < x) x = y; n } n inline void solve() { n   cin >> n; n   for (int i = 1; i <= n; ++i) cin >> a[i]; n   for (int i = 1; i <= n; ++i) cin >> b[i]; n   st.clear(); n   for (int i = 0; i <= n + 1; ++i) { n     dp[i] = -1; n     st.insert(i); n   } n   queue<int> q; n   dp[n] = 0; n   q.push(n); n   while (q.size()) { n     int u = q.front(); n     q.pop(); n     while (true) { n       int x = *st.lower_bound(u - a[u]); n       if (x > u) break; n       st.erase(x); n       int v = x + b[x]; n       if (dp[v] == -1 || dp[u] + 1 < dp[v]) { n         dp[v] = dp[u] + 1; n         path[v] = {u, x}; n         q.push(v); n       } n     } n   } n   if (dp[0] == -1) { n     cout <<  -1 n ; n     return; n   } n   ans.clear(); n   for (int i = 0; i != n; i = path[i].first) { n     ans.emplace_back(path[i].second); n   } n   reverse(ans.begin(), ans.end()); n   cout << ans.size() <<   n ; n   for (int &i : ans) cout << i <<    ; n   cout <<   n ; n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int T = 1; n   for (int t = 1; t <= T; ++t) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, i, s, f, h, co = 0, sum, savesum, res, re, savere; n   cin >> n; n   long long a[n + 1]; n   for (i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   cin >> s >> f; n   h = f - s; n   queue<long long> qu; n   i = 1; n   sum = 0; n   savesum = 0; n   res = 1; n   for (i = 1; i <= h; i++) { n     qu.push(a[i]); n     sum += a[i]; n     savesum = sum; n   } n   re = s; n   savere = s; n   for (i = h + 1; i <= n; i++) { n     sum += a[i] - qu.front(); n     qu.pop(); n     qu.push(a[i]); n     if (sum > savesum) { n       res = i - h + 1; n       savesum = sum; n       re = s - res + 1; n       if (re < 1) re += n; n       savere = re; n     } else if (sum == savesum) { n       res = i - h + 1; n       savesum = sum; n       re = s - res + 1; n       if (re < 1) re += n; n       if (savere > re) savere = re; n     } n   } n   for (i = 1; i <= h; i++) { n     sum += a[i] - qu.front(); n     qu.pop(); n     qu.push(a[i]); n     if (sum > savesum) { n       savesum = sum; n       res = n - h + 1 + i; n       re = s - res + 1; n       if (re < 1) re += n; n       savere = re; n     } else if (sum == savesum) { n       res = n - h + 1 + i; n       re = s - res + 1; n       if (re < 1) re += n; n       if (savere > re) savere = re; n     } n   } n   cout << savere; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int>> tr; n int n; n int mx_bits = 40; n int ind = 0; n long long xor_sum = 0; n long long ans; n vector<long long> v; n void insert_tr(long long num) { n   int node = 0; n   for (int i = (int)mx_bits; i >= (int)0; --i) { n     bool bit = ((num >> i) & 1) > 0; n     if (tr[node][bit] == -1) { n       tr.push_back(vector<int>(2, -1)); n       ++ind; n       tr[node][bit] = ind; n     } n     node = tr[node][bit]; n   } n } n long long query_tr(long long num) { n   long long ret = 0; n   int node = 0; n   long long val = 1; n   for (int i = (int)mx_bits; i >= (int)0; --i) { n     bool bit = ((num >> i) & 1) > 0; n     if (tr[node][1 - bit] != -1) { n       ret += val << i; n       node = tr[node][1 - bit]; n     } else n       node = tr[node][bit]; n   } n   return ret; n } n void solve() { n   ans = xor_sum; n   long long cur = 0; n   insert_tr(cur); n   for (int i = (int)0; i < (int)n; ++i) { n     cur ^= v[i]; n     insert_tr(cur); n     long long ret = query_tr(xor_sum ^ cur); n     ans = max(ans, ret); n   } n   cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   tr.push_back(vector<int>(2, -1)); n   cin >> n; n   v.resize(n); n   for (int i = (int)0; i < (int)n; ++i) { n     cin >> v[i]; n     xor_sum = xor_sum ^ v[i]; n   } n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using uiII = unsigned int long long; n using II = int long long; n using namespace std; n const II N = 0x3f3f3f3f3f3f3f; n int main() { n   vector<pair<II, II>> v; n   vector<pair<II, II>>::iterator it; n   v.reserve(1000000); n   II t, n, l, r, i(0); n   for (cin >> t; i < t; i++) { n     cin >> n; n     v.push_back(make_pair(1, n)); n     bool x[2000][2000]{false}; n     for (II i = 0; i < n; i++) { n       cin >> l >> r; n       x[l][r] = true; n     } n     bool f = false; n     for (II i = 0; i < v.size(); i++) { n       for (II j = v[i].first; j <= v[i].second; j++) { n         if (v[i].first == v[i].second) { n           cout << v[i].first <<     << v[i].second <<     << v[i].first << endl; n         } n         if (j - v[i].first == 0) { n           if (v[i].second - v[i].first >= 2) { n             if (x[j + 1][v[i].second] == true) { n               cout << v[i].first <<     << v[i].second <<     << j << endl; n               v.push_back(make_pair(j + 1, v[i].second)); n             } n             continue; n           } n           if (v[i].second - v[i].first == 1) { n             if (x[v[i].second][v[i].second] == true) { n               cout << v[i].first <<     << v[i].second <<     << j << endl; n               v.push_back(make_pair(v[i].second, v[i].second)); n             } n             continue; n           } n         } n         if (j - v[i].second == 0) { n           if (j - v[i].first >= 2) { n             if (x[v[i].first][v[i].second - 1] == true) { n               cout << v[i].first <<     << v[i].second <<     << j << endl; n               v.push_back(make_pair(v[i].first, v[i].second - 1)); n             } n             continue; n           } n           if (j - v[i].first == 1) { n             if (x[v[i].first][v[i].first] == true) { n               cout << v[i].first <<     << v[i].second <<     << j << endl; n               v.push_back(make_pair(v[i].first, v[i].first)); n             } n             continue; n           } n         } n         if (j != v[i].first && j != v[i].second) { n           if (j - v[i].first == 1) { n             if (x[v[i].first][v[i].first] == true) { n               if (x[j + 1][v[i].second] == true) { n                 cout << v[i].first <<     << v[i].second <<     << j << endl; n                 v.push_back(make_pair(v[i].first, v[i].first)); n                 v.push_back(make_pair(j + 1, v[i].second)); n                 break; n               } n             } n             continue; n           } n           if (v[i].second - j == 1) { n             if (x[v[i].first][j - 1] == true) { n               if (x[v[i].second][v[i].second] == true) { n                 cout << v[i].first <<     << v[i].second <<     << j << endl; n                 v.push_back(make_pair(v[i].second, v[i].second)); n                 v.push_back(make_pair(v[i].first, j - 1)); n                 break; n               } n             } n             continue; n           } else { n             if (x[v[i].first][j - 1] == true) { n               if (x[j + 1][v[i].second] == true) { n                 cout << v[i].first <<     << v[i].second <<     << j << endl; n                 v.push_back(make_pair(v[i].first, j - 1)); n                 v.push_back(make_pair(j + 1, v[i].second)); n                 break; n               } n             } n             continue; n           } n         } n       } n     } n     v.clear(); n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000000; n const int MAXN = 30005; n int lst[MAXN], N; n bool ok(vector<int> &v) { n   if ((int)v.size() <= 2) return true; n   for (int i = (int)v.size() - 2; i >= max(1, (int)v.size() - 5); i--) n     if (v[i + 1] - v[i] != v[1] - v[0]) return false; n   return true; n } n bool check(vector<int> &a, vector<int> &b, int n) { n   if ((int)a.size() < 2) { n     b.push_back(lst[n]); n     if (!ok(b)) { n       b.erase(b.end() - 1); n       a.push_back(lst[n]); n     } n   } else if ((int)b.size() < 2) { n     a.push_back(lst[n]); n     if (!ok(a)) { n       a.erase(a.end() - 1); n       b.push_back(lst[n]); n     } n   } else { n     a.push_back(lst[n]); n     if (!ok(a)) { n       a.erase(a.end() - 1); n       b.push_back(lst[n]); n     } n   } n   return ok(a) && ok(b); n } n int main() { n   cin >> N; n   for (int i = 0; i < N; i++) cin >> lst[i]; n   int sz = min(6, N); n   vector<int> x, y; n   for (int mask = 0; mask < (1 << sz); mask++) { n     vector<int> a, b; n     for (int i = 0; i < sz; i++) { n       if (mask & (1 << i)) n         a.push_back(lst[i]); n       else n         b.push_back(lst[i]); n     } n     if (!ok(a) || !ok(b)) continue; n     bool k = true; n     for (int i = sz; i < N; i++) { n       if (!check(a, b, i)) { n         k = false; n         break; n       } n     } n     if (k) { n       x = a, y = b; n       break; n     } n   } n   if ((int)x.size() == 0 && (int)y.size() > 0) { n     x.push_back(y[(int)y.size() - 1]); n     y.erase(y.end() - 1); n   } else if ((int)y.size() == 0 && (int)x.size() > 0) { n     y.push_back(x[(int)x.size() - 1]); n     x.erase(x.end() - 1); n   } n   if ((int)x.size() == 0 && (int)y.size() == 0) { n     cout <<  No solution  << endl; n     return 0; n   } n   for (int i = 0; i < (int)x.size(); i++) cout << x[i] <<    ; n   cout << endl; n   for (int i = 0; i < (int)y.size(); i++) cout << y[i] <<    ; n   cout << endl; n } n


#include <bits/stdc++.h> n const int INF = 0x7fffffff; n const long long int LNF = 0x7fffffffffffffff; n using namespace std; n int ac[26], az[26]; n char aa[105], bb[105]; n int main() { n   int i, k, nn, kk = 0, len1, len2, s; n   scanf( %d , &nn); n   getchar(); n   while (kk < nn) { n     gets(aa); n     gets(bb); n     len1 = strlen(aa); n     len2 = strlen(bb); n     memset(az, 0, sizeof(az)); n     k = 0; n     while (k < len1) { n       az[aa[k] -  a ]++; n       k++; n     } n     k = 0; n     s = 1; n     while (k + len1 <= len2) { n       memset(ac, 0, sizeof(ac)); n       i = 0; n       while (i < len1) { n         ac[bb[k + i] -  a ]++; n         i++; n       } n       i = 0; n       s = 0; n       while (i < 26) { n         if (ac[i] != az[i]) { n           s = 1; n           break; n         } n         i++; n       } n       if (s == 0) { n         break; n       } n       k++; n     } n     if (s == 0) { n       printf( YES n ); n     } else { n       printf( NO n ); n     } n     kk++; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops ) n #pragma GCC target(   n      sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma,tune=native ) n using namespace std; n const long long inf = 1e9 + 5; n struct Node { n   Node *l = 0, *r = 0; n   long long lo, hi, mset = inf, madd = 0, val = 0, smol = inf; n   Node(int lo, int hi) : lo(lo), hi(hi) {} n   Node(vector<long long>& v, int lo, int hi) : lo(lo), hi(hi) { n     if (lo + 1 < hi) { n       int mid = lo + (hi - lo) / 2; n       l = new Node(v, lo, mid); n       r = new Node(v, mid, hi); n       val = l->val + r->val; n       smol = min(l->smol, r->smol); n     } else n       val = v[lo], smol = v[lo]; n   } n   long long query(int L, int R) { n     if (R <= lo || hi <= L) return 0; n     if (L <= lo && hi <= R) return val; n     push(); n     return l->query(L, R) + r->query(L, R); n   } n   int find(long long v) { n     if (smol > v) return hi; n     if (lo + 1 == hi) return lo; n     if (mset <= v) return lo; n     if (l->smol <= v) return l->find(v); n     return r->find(v); n   } n   void set(int L, int R, int x) { n     if (R <= lo || hi <= L) return; n     if (L <= lo && hi <= R) n       mset = x, val = (hi - lo) * x, smol = x, madd = 0; n     else { n       push(), l->set(L, R, x), r->set(L, R, x); n       val = l->val + r->val; n       smol = min(l->smol, r->smol); n     } n   } n   void push() { n     if (!l) { n       int mid = lo + (hi - lo) / 2; n       l = new Node(lo, mid); n       r = new Node(mid, hi); n     } n     if (mset != inf) l->set(lo, hi, mset), r->set(lo, hi, mset), mset = inf; n   } n }; n int n, q; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> q; n   vector<long long> l(n, 0); n   for (int i = 0; i < n; i++) { n     long long v; n     cin >> v; n     l[i] = v; n   } n   Node seg = Node(l, 0, n); n   for (int it = 0; it < q; it++) { n     long long y; n     int t, x; n     cin >> t >> x >> y; n     x -= 1; n     if (t == 1) { n       int left = seg.find(y); n       if (x + 1 > left) { n         seg.set(left, x + 1, y); n       } n     } else { n       int out = 0; n       x = max(x, seg.find(y)); n       while (x < n) { n         long long dist = y / seg.query(x, x + 1); n         int lo = min((long long)n - 1, x + dist - 1); n         y -= seg.query(x, lo + 1); n         out += (lo - x + 1); n         x = max(lo + 1, seg.find(y)); n       } n       cout << out <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n double EPS = 1e-9; n int conversion(string p) { n   int o; n   o = atoi(p.c_str()); n   return o; n } n string toString(int h) { n   stringstream ss; n   ss << h; n   return ss.str(); n } n long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } n long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); } n long long toi(string p) { n   long long x; n   istringstream in(p); n   in >> x; n   return x; n } n long long square(long long n) { return n * n; } n long long fastexp(long long base, long long power) { n   if (power == 0) n     return 1LL; n   else if (power % 2 == 0) n     return square(fastexp(base, power / 2)); n   else n     return base * (fastexp(base, power - 1)); n } n bool is_prime(int n) { n   for (int i = 2; i * i <= n; i++) n     if (n % i == 0) return 0; n   return 1; n } n int logba(int a, int b) { return log(a) / log(b); } n int rd(double d) { n   int x = (int)((double)d + 0.5); n   return x; n } n vector<pair<int, int> > W, B, Q; n char lab[8][8]; n bool go(int x, int y, int id) { n   if (id == 0) { n     for (int i = x - 1; i >= 0; i--) { n       if (lab[i][y] !=  . ) return false; n     } n   } else { n     for (int i = x + 1; i < 8; i++) { n       if (lab[i][y] !=  . ) return false; n     } n   } n   return true; n } n int main() { n   int res = 0, x, y; n   for (int i = 0; i < 8; i++) { n     for (int j = 0; j < 8; j++) { n       cin >> lab[i][j]; n       if (lab[i][j] ==  W ) W.push_back(make_pair(i, j)); n       if (lab[i][j] ==  B ) B.push_back(make_pair(i, j)); n     } n   } n   for (int i = 0; i < W.size(); i++) { n     x = W[i].first; n     y = W[i].second; n     if (go(x, y, 0)) Q.push_back(make_pair(x, 0)); n   } n   for (int i = 0; i < B.size(); i++) { n     x = B[i].first; n     y = B[i].second; n     if (go(x, y, 1)) Q.push_back(make_pair(7 - x, 1)); n   } n   sort(Q.begin(), Q.end()); n   if (Q[0].second == 0) n     cout <<  A  << endl; n   else n     cout <<  B  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 2e9; n const long long LINF = 2e16; n const int magic = 348; n const int MOD = 1e9 + 7; n const double eps = 1e-10; n const double pi = acos(-1); n struct fastio { n   static const int S = 1e7; n   char rbuf[S + 48], wbuf[S + 48]; n   int rpos, wpos, len; n   fastio() { rpos = len = wpos = 0; } n   inline char Getchar() { n     if (rpos == len) rpos = 0, len = fread(rbuf, 1, S, stdin); n     if (!len) return EOF; n     return rbuf[rpos++]; n   } n   template <class T> n   inline void Get(T &first) { n     char ch; n     bool f; n     T res; n     while (!isdigit(ch = Getchar()) && ch !=  - ) { n     } n     if (ch ==  - ) n       f = false, res = 0; n     else n       f = true, res = ch -  0 ; n     while (isdigit(ch = Getchar())) res = res * 10 + ch -  0 ; n     first = (f ? res : -res); n   } n   inline void getstring(char *s) { n     char ch; n     while ((ch = Getchar()) <= 32) { n     } n     for (; ch > 32; ch = Getchar()) *s++ = ch; n     *s =   0 ; n   } n   inline void flush() { n     fwrite(wbuf, 1, wpos, stdout); n     fflush(stdout); n     wpos = 0; n   } n   inline void Writechar(char ch) { n     if (wpos == S) flush(); n     wbuf[wpos++] = ch; n   } n   template <class T> n   inline void Print(T first, char ch) { n     char s[20]; n     int pt = 0; n     if (first == 0) n       s[++pt] =  0 ; n     else { n       if (first < 0) Writechar( - ), first = -first; n       while (first) s[++pt] =  0  + first % 10, first /= 10; n     } n     while (pt) Writechar(s[pt--]); n     Writechar(ch); n   } n   inline void printstring(char *s) { n     int pt = 1; n     while (s[pt] !=   0 ) Writechar(s[pt++]); n   } n } io; n template <typename T> n inline void check_max(T &first, T cmp) { n   first = max(first, cmp); n } n template <typename T> n inline void check_min(T &first, T cmp) { n   first = min(first, cmp); n } n template <typename T> n inline T myabs(T first) { n   return first >= 0 ? first : -first; n } n const int MAXN = 1e5; n inline int add(int first) { n   if (first >= MOD) first -= MOD; n   return first; n } n inline int sub(int first) { n   if (first < 0) first += MOD; n   return first; n } n inline int quick_pow(int first, int second) { n   int res = 1; n   while (second) { n     if (second & 1) res = (1ll * res * first) % MOD, second--; n     first = (1ll * first * first) % MOD; n     second >>= 1; n   } n   return res; n } n int inv[MAXN + 48], fac[MAXN + 48]; n inline void init_inv() { n   fac[0] = 1; n   for (register int i = 1; i <= MAXN; i++) n     fac[i] = (1ll * fac[i - 1] * i) % MOD; n   inv[MAXN] = quick_pow(fac[MAXN], MOD - 2); n   for (register int i = MAXN - 1; i >= 0; i--) n     inv[i] = (1ll * inv[i + 1] * (i + 1)) % MOD; n } n inline int C(int first, int second) { n   if (first < second || first < 0 || second < 0) return 0; n   return 1ll * fac[first] * inv[second] % MOD * inv[first - second] % MOD; n } n inline int split(int first, int second) { n   if (!second) { n     return first == 0; n   } n   return C(first + second - 1, second - 1); n } n inline int calc(int c[2][2]) { n   if (c[0][1] - c[1][0] < 0 || c[0][1] - c[1][0] > 1) return 0; n   return 1ll * split(c[0][0], c[1][0] + 1) * split(c[1][1], c[0][1]) % MOD; n } n int c[2][2], cc[2][2], n; n char A[MAXN + 48], B[MAXN + 48]; n inline int solve(int c[2][2], char *s) { n   int len = strlen(s + 1); n   if (len == 1 && s[1] ==  0 ) return 0; n   if (len < n) return 0; n   if (len > n) n     for (register int i = n; i >= 1; i--) s[i] =  1 ; n   char last =  1 ; n   int res = 0, i; n   for (i = n - 1; i >= 1; i--) n     if (s[i] ==  1 ) { n       if (c[last -  0 ][0]) { n         c[last -  0 ][0]--; n         res = add(res + calc(c)); n         c[last -  0 ][0]++; n       } n       if (!c[last -  0 ][1]) break; n       c[last -  0 ][1]--; n       last =  1 ; n     } else { n       if (!c[last -  0 ][0]) break; n       c[last -  0 ][0]--; n       last =  0 ; n     } n   if (!i) res = add(res + 1); n   return res; n } n inline void Minus() { n   int len = strlen(A + 1), pt = 1; n   while (A[pt] ==  0 ) A[pt] =  1 , pt++; n   A[pt] =  0 ; n   while (len >= 1 && A[len] ==  0 ) len--; n   if (!len) len++; n   A[len + 1] =   0 ; n } n int main() { n   init_inv(); n   io.getstring(A + 1); n   io.getstring(B + 1); n   int lena = strlen(A + 1), lenb = strlen(B + 1); n   reverse(A + 1, A + lena + 1); n   reverse(B + 1, B + lenb + 1); n   io.Get(c[0][0]); n   io.Get(c[0][1]); n   io.Get(c[1][0]); n   io.Get(c[1][1]); n   Minus(); n   n = c[0][0] + c[0][1] + c[1][0] + c[1][1] + 1; n   for (register int i = 0; i <= 1; i++) n     for (register int j = 0; j <= 1; j++) cc[i][j] = c[i][j]; n   int resb = solve(c, B), resa = solve(cc, A); n   io.Print(sub(resb - resa),   n ); n   io.flush(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int TOUR = 1 << 18, MOD = 1e9 + 7; n int Add(int a, int b) { n   a += b; n   if (a >= MOD) a -= MOD; n   return a; n } n int Sub(int a, int b) { n   a -= b; n   if (a < 0) a += MOD; n   return a; n } n int Mul(int a, int b) { return (int)(((long long)a * b) % MOD); } n int Inverz(int x) { n   int ret = 1; n   for (int e = MOD - 2; e; e /= 2, x = Mul(x, x)) n     if (e & 1) ret = Mul(ret, x); n   return ret; n } n int Div(int a, int b) { return Mul(a, Inverz(b)); } n struct node { n   int sum, mul, prop; n }; n struct tour { n   node t[2 * TOUR]; n   tour() { n     for (int i = 0; i < 2 * TOUR; i++) { n       t[i].sum = 0; n       t[i].mul = t[i].prop = 1; n     } n   } n   void propagiraj(int x) { n     for (int i = 2 * x; i <= 2 * x + 1; i++) { n       t[i].sum = Mul(t[i].sum, t[x].prop); n       t[i].mul = Mul(t[i].mul, t[x].prop); n       t[i].prop = Mul(t[i].prop, t[x].prop); n     } n     t[x].prop = 1; n   } n   void stavi_sum(int pos, int lo, int hi, int ind, int val) { n     if (lo >= ind + 1 || hi <= ind) return; n     if (lo == ind && hi == ind + 1) { n       t[pos].sum = Mul(t[pos].mul, val); n       return; n     } n     propagiraj(pos); n     stavi_sum(2 * pos + 0, lo, (lo + hi) / 2, ind, val); n     stavi_sum(2 * pos + 1, (lo + hi) / 2, hi, ind, val); n     t[pos].sum = Add(t[2 * pos].sum, t[2 * pos + 1].sum); n   } n   void stavi_sum(int pos, int val) { stavi_sum(1, 0, TOUR, pos, val); } n   void stavi_mul(int pos, int lo, int hi, int begin, int end, int val) { n     if (lo >= end || hi <= begin) return; n     if (lo >= begin && hi <= end) { n       t[pos].sum = Mul(t[pos].sum, val); n       t[pos].mul = Mul(t[pos].mul, val); n       t[pos].prop = Mul(t[pos].prop, val); n       return; n     } n     propagiraj(pos); n     stavi_mul(2 * pos + 0, lo, (lo + hi) / 2, begin, end, val); n     stavi_mul(2 * pos + 1, (lo + hi) / 2, hi, begin, end, val); n     t[pos].sum = Add(t[2 * pos].sum, t[2 * pos + 1].sum); n   } n   void stavi_mul(int begin, int end, int val) { n     stavi_mul(1, 0, TOUR, begin, end, val); n   } n   int query_sum(int pos, int lo, int hi, int begin, int end) { n     if (lo >= end || hi <= begin) return 0; n     if (lo >= begin && hi <= end) return t[pos].sum; n     propagiraj(pos); n     return Add(query_sum(2 * pos + 0, lo, (lo + hi) / 2, begin, end), n                query_sum(2 * pos + 1, (lo + hi) / 2, hi, begin, end)); n   } n   int query_sum(int begin, int end) { n     return query_sum(1, 0, TOUR, begin, end); n   } n   int query_mul(int pos, int lo, int hi, int ind) { n     if (lo >= ind + 1 || hi <= ind) return 0; n     if (lo == ind && hi == ind + 1) return t[pos].mul; n     propagiraj(pos); n     return Add(query_mul(2 * pos + 0, lo, (lo + hi) / 2, ind), n                query_mul(2 * pos + 1, (lo + hi) / 2, hi, ind)); n   } n   int query_mul(int ind) { return query_mul(1, 0, TOUR, ind); } n } T; n vector<int> V[TOUR]; n pair<int, int> ev[TOUR]; n int disc[TOUR], fin[TOUR], vr = 1; n int pocval[TOUR], par[TOUR]; n int brdjec[TOUR]; n void Dfs(int node) { n   disc[node] = vr++; n   for (int i = 0; i < (int)V[node].size(); i++) Dfs(V[node][i]); n   fin[node] = vr; n } n void Dodaj(int node) { n   int p = par[node]; n   T.stavi_mul(disc[p], fin[p], Mul(Inverz(brdjec[p]), brdjec[p] + 1)); n   T.stavi_sum(disc[node], pocval[node]); n   brdjec[p]++; n } n int Query(int node) { n   int ret = T.query_sum(disc[node], fin[node]); n   if (node) ret = Div(ret, T.query_mul(disc[par[node]])); n   return ret; n } n int main() { n   int brq, brcv = 1; n   scanf( %d%d , &pocval[0], &brq); n   for (int i = 0; i < brq; i++) { n     int st; n     scanf( %d , &st); n     if (st == 2) { n       int tmp; n       scanf( %d , &tmp); n       tmp--; n       ev[i] = pair<int, int>(st, tmp); n     } else { n       scanf( %d%d , &par[brcv], &pocval[brcv]); n       par[brcv]--; n       V[par[brcv]].push_back(brcv); n       ev[i] = pair<int, int>(st, brcv++); n     } n   } n   Dfs(0); n   T.stavi_sum(disc[0], pocval[0]); n   for (int i = 0; i < brcv; i++) brdjec[i] = 1; n   for (int i = 0; i < brq; i++) { n     if (ev[i].first == 1) n       Dodaj(ev[i].second); n     else n       printf( %d n , Query(ev[i].second)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1 << 16; n int n, m; n int d[2][N]; n int get_n(int x, int n) { n   int tmp = 3 << (n * 2); n   tmp = x & tmp; n   tmp >>= n * 2; n   return tmp; n } n int set_n(int x, int n, int y) { n   int tmp = 3 << (n * 2); n   x = x & (~tmp); n   y <<= (n * 2); n   x |= y; n   return x; n } n void update(int &x, int y) { n   if (x == -1 || x < y) x = y; n } n int solve() { n   int i, j, k; n   int t = 0; n   memset(d, -1, sizeof(d)); n   d[0][0] = 0; n   int tot = 1 << (n * 2 + 2); n   for (i = 0; i < m; ++i) { n     for (j = 0; j < n; ++j) { n       memset(d[1 - t], -1, sizeof(d[1 - t])); n       for (k = 0; k < tot; ++k) { n         if (d[t][k] == -1) continue; n         int t0 = get_n(k, j); n         int t1 = get_n(k, j + 1); n         int st = set_n(k, j, 1); n         st = set_n(st, j + 1, 1); n         update(d[1 - t][st], d[t][k]); n         if (t0 > 0) { n           st = set_n(k, j - 1, 2); n           st = set_n(st, j, 0); n           st = set_n(st, j + 1, 0); n           update(d[1 - t][st], d[t][k] + 1); n           if (t0 == 1) { n             st = set_n(k, j - 1, 0); n             st = set_n(st, j, 2); n             st = set_n(st, j + 1, 2); n             update(d[1 - t][st], d[t][k] + 1); n           } n         } n         if (t1 > 0) { n           st = set_n(k, j, 0); n           st = set_n(st, j + 1, 0); n           update(d[1 - t][st], d[t][k] + 1); n           if (t1 == 1) { n             st = set_n(k, j, 2); n             st = set_n(st, j + 1, 2); n             update(d[1 - t][st], d[t][k] + 1); n           } n         } n         if (t0 == 1 && t1 == 1) { n           st = set_n(k, j - 1, 0); n           st = set_n(st, j, 2); n           st = set_n(st, j + 1, 2); n           update(d[1 - t][st], d[t][k] + 2); n         } n       } n       t = 1 - t; n     } n     memset(d[1 - t], -1, sizeof(d[1 - t])); n     for (k = 0; k < tot; ++k) { n       int st = set_n(k, n, 0); n       st <<= 2; n       update(d[1 - t][st], d[t][k]); n     } n     t = 1 - t; n   } n   int ans = -1; n   for (k = 0; k < tot; ++k) { n     update(ans, d[t][k]); n   } n   return ans; n } n int main() { n   int i, j, k, t, nc = 0; n   while (scanf( %d%d , &n, &m) != EOF) { n     if (n > m) swap(n, m); n     int ans = solve(); n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int> > g; n vector<long double> ans; n vector<int> sum; n void dfs0(int x) { n   sum[x] = 1; n   for (int to : g[x]) { n     dfs0(to); n     sum[x] += sum[to]; n   } n } n void dfs(int x, long double f) { n   ans[x] = f; n   int s = sum[x] - 1; n   for (int to : g[x]) { n     dfs(to, ((s - sum[to]) / 2.0) + f + 1.0); n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   int n; n   cin >> n; n   g.resize(n); n   ans.resize(n); n   sum.resize(n); n   for (int i = 1; i < n; i++) { n     int p; n     cin >> p; n     p--; n     g[p].push_back(i); n   } n   dfs0(0); n   dfs(0, 1.0); n   cout << fixed << setprecision(8); n   for (long double x : ans) cout << x <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n long long k; n long long f(int a[], int l, int r) { n   long long m = 0; n   for (int i = 0; i < n; i++) n     if (a[i] < l) n       m += l - a[i]; n     else if (a[i] > r) n       m += a[i] - r; n   return m; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL); n   cin >> n >> k; n   int a[n]; n   for (int& i : a) cin >> i; n   int l = 0, r = 1e9; n   while (l <= r) { n     int m = (l + r) / 2; n     int lt = 0, rt = 1e9; n     while (rt - lt > 1) { n       int mt = (lt + rt) / 2; n       if (f(a, mt, mt + m) < f(a, mt + 1, mt + 1 + m)) n         rt = mt; n       else n         lt = mt; n     } n     if (f(a, rt, rt + m) <= k) n       r = m - 1; n     else n       l = m + 1; n   } n   cout << l <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n struct tree { n   int C; n   int root; n   int number_of_branches; n   int *branches; n }; n int main() { n   int c, p, n, i, j, r = 0; n   int start, D[100000] = {0}, k = 0; n   struct tree A[100000]; n   cin >> n; n   for (i = 0; i < n; i++) { n     A[i].branches = new int[1]; n     A[i].number_of_branches = 0; n   } n   for (i = 0; i < n; i++) { n     cin >> p >> c; n     if (p == -1) { n       start = i; n     } else { n       A[i].C = c; n       A[i].root = p - 1; n       A[p - 1].branches[A[p - 1].number_of_branches] = i; n       A[p - 1].number_of_branches++; n       A[p - 1].branches = n           (int *)realloc(A[p - 1].branches, n                          (A[p - 1].number_of_branches) * sizeof(struct tree)); n     } n   } n   for (i = 0; i < n; i++) { n     if (A[i].C == 1) { n       k = 0; n       for (j = 0; j < A[i].number_of_branches; j++) { n         if (A[A[i].branches[j]].C == 1) { n           k++; n         } n       } n       if ((k == A[i].number_of_branches) || n           (k == 0 && k == A[i].number_of_branches)) { n         cout << i + 1 <<    ; n         r = 1; n       } n     } n   } n   if (r == 0) { n     cout << -1; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 2e5 + 5; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cout << name <<   :   << arg1 <<   n ; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cout.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n long long int n, k; n long long int a[N]; n long long int month[2 * N]; n long long int sum(long long int days) { return (days * (days + 1) / 2); } n void solve() { n   cin >> n >> k; n   for (long long int i = 0; i < n; i++) { n     cin >> a[i]; n     month[i] = a[i]; n     month[n + i] = a[i]; n   } n   long long int j = 0; n   long long int hugs = 0, days = 0, best = 0; n   for (long long int i = 0; i < 2 * n; i++) { n     hugs += sum(month[i]); n     days += month[i]; n     while (days > k) { n       days -= month[j]; n       hugs -= sum(month[j]); n       j++; n     } n     long long int curr = hugs; n     if (j > 0) { n       long long int skips = month[j - 1] + days - k; n       curr += sum(month[j - 1]) - sum(skips); n     } n     best = max(best, curr); n   } n   cout << best <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n #define ll long long n #define ld long double n #define pb push_back n #define VI vector<int> n #define VL vector<ll> n #define MX vector<VI > n #define all(x) x.begin(), x.end() n #define IOS cin.tie(0)->sync_with_stdio(0) n  n using namespace std; n  n ll gcd(ll a, ll b){ n  if(!b) return a; n  return gcd(b, a%b); n } n  n int main(){ n  n  int n, m; n  cin >> n >> m; n  n  VL a(n), b(m); n  for(ll &i : a) cin >> i; n  for(ll &i : b) cin >> i; n  n  sort(all(a)); n  n  ll t = 0; n  for(int i=1; i<n; i++) t = gcd(a[i]-a[i-1], t); n  n  for(ll &i : b) cout << gcd(i+a[0], t) <<    ; n  cout <<   n ; n  n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int toInt(string s) { n   int v; n   istringstream sin(s); n   sin >> v; n   return v; n } n template <class T> n inline string toString(T x) { n   ostringstream sout; n   sout << x; n   return sout.str(); n } n inline int readInt() { n   int x; n   scanf( %d , &x); n   return x; n } n int a[55]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < (int)n; ++i) scanf( %d , &a[i]); n   sort(a, a + n); n   if (a[0] == a[n / 2]) n     printf( Bob n ); n   else n     printf( Alice n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-9; n const int INF = 0x7fffffff; n const double PI = acos(-1.0); n const int MAX = 100005; n const int MOD = 1000000007; n inline bool isEq(double a, double b) { return abs(a - b) < EPS; } n inline bool isEq(double a, double b, double eps) { return abs(a - b) < eps; } n inline double toRad(double deg) { return deg * PI / 180; } n inline double toDeg(double rad) { return rad * 180 / PI; } n class Timer { n   clock_t start; n   string name; n  n  public: n   Timer() { n     name =   ; n     start = clock(); n   } n   Timer(string s) { n     name = s; n     start = clock(); n   } n   ~Timer() { n     fprintf(stderr,  %s: %.3gs n , name.c_str(), n             1.0 * (clock() - start) / CLOCKS_PER_SEC); n   } n }; n double cross(complex<double> &a, complex<double> &b) { n   return imag((conj(a) * b)); n } n double perpendicularDist(double x1, double y1, double x2, double y2, double x3, n                          double y3) { n   complex<double> A = complex<double>(x2 - x1, y2 - y1); n   complex<double> B = complex<double>(x3 - x1, y3 - y1); n   return cross(A, B) / abs(A); n } n double getYaxiyIntersection(complex<double> start, complex<double> a) { n   double lo = 0, hi = 1000000000, dist = 0; n   int cnt = 300; n   a = a / abs(a); n   complex<double> en; n   while (cnt--) { n     dist = (lo + hi) / 2; n     en = start + a * dist; n     if (start.real() * en.real() > 0) n       lo = dist; n     else n       hi = dist; n   } n   return en.imag(); n } n int main(int argc, char *argv[]) { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   double y1, y2, yw, xb, yb, r; n   cin >> y1 >> y2 >> yw >> xb >> yb >> r; n   double lowxw = 0, highxw = xb, xw, y, rxb; n   int cnt = 300; n   double yweff = yw - r; n   bool found = false; n   complex<double> A; n   while (cnt--) { n     xw = (lowxw + highxw) / 2; n     rxb = xw - (xb - xw); n     A = complex<double>(xw - rxb, yweff - yb); n     if (rxb > 0) A = -A; n     y = getYaxiyIntersection(complex<double>(rxb, yb), A); n     if (y - r >= y1 && y2 >= y + r && n         perpendicularDist(0, y, xw, yweff, 0, y2) >= r) { n       found = true; n       break; n     } else { n       if (y - r < y1) n         highxw = xw; n       else n         lowxw = xw; n     } n   } n   if (found) n     cout << fixed << setprecision(10) << xw << endl; n   else n     cout <<  -1  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long i, n, m, a[200000], q, l, p, k, c[200000], b[200000], j, ans; n string s[200000], ss, s1; n int main() { n   ios_base::sync_with_stdio(0); n   ans = 1000000007; n   cin >> n; n   for (i = 1; i <= n; i++) cin >> a[i]; n   sort(a + 1, a + 1 + n); n   for (i = 1; i <= n / 2; i++) { n     ans = min(ans, a[n / 2 + i] - a[i]); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   vector<int> a(n); n   for (int &i : a) { n     cin >> i; n   } n   vector<vector<bool> > match(n + 1, vector<bool>(n + 1, false)); n   for (int i = 0, x, y; i < m; i++) { n     cin >> x >> y; n     x--; n     y--; n     match[x][y] = true; n     match[y][x] = true; n   } n   int ans = INT_MAX; n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j < n; j++) { n       for (int z = j + 1; z < n; z++) { n         if (match[i][j] && match[j][z] && match[z][i]) { n           ans = min(ans, a[i] + a[j] + a[z]); n         } n       } n     } n   } n   if (ans == INT_MAX) ans = -1; n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, x, ans; n priority_queue<long long> q; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> x; n     q.push(x); n     if (q.top() > x) { n       ans += q.top() - x; n       q.pop(); n       q.push(x); n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int *p = new int[100010]; n   fill(p, p + 100010, -1000000000); n   for (int i = 0; i < n; ++i) { n     int x, y; n     int res = 0; n     scanf( %d%d , &x, &y); n     int q = (int)sqrt((double)x); n     for (int j = 1; j <= q; ++j) { n       if (x % j == 0) { n         if (p[j] < i - y) ++res; n         p[j] = i; n         if (p[x / j] < i - y) ++res; n         p[x / j] = i; n       } n     } n     cout << res << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int power(long long int x, long long int y) { n   if (y == 0) return 1; n   long long int d = power(x, y / 2) % 1000000007; n   if (y % 2 == 0) n     return (d * d) % 1000000007; n   else n     return (((x * d) % 1000000007) * d) % 1000000007; n } n long long int divmod(long long int num, long long int den) { n   return (num * (power(den, 1000000007 - 2))) % 1000000007; n } n int mobius[100001]; n int mob(int x) { n   int cnt = 0; n   for (int i = 2; i * i <= x; i++) { n     if (x % i == 0) { n       x = x / i; n       cnt++; n     } n     if (x % i == 0) { n       return 0; n     } n   } n   if (x > 1) { n     cnt++; n   } n   if (cnt & 1) return -1; n   return 1; n } n long long int nmod(long long int x) { n   return (x % 1000000007 + 1000000007) % 1000000007; n } n long long int fact[100001]; n long long int ncr(long long int n, long long int r) { n   long long int num = fact[n]; n   long long int den = fact[r] * fact[n - r]; n   den %= 1000000007; n   return divmod(num, den); n } n long long int calc(long long int n, long long int k, long long int x) { n   n = n / x; n   n = n - k; n   if (n < 0) return 0; n   if (n == 0) return 1; n   return ncr(n + k - 1, k - 1); n } n void solve() { n   int n, k; n   scanf( %d , &n); n   scanf( %d , &k); n   vector<int> f; n   for (int i = 1; i * i <= n; i++) { n     if (i * i == n) { n       f.push_back(i); n       break; n     } n     if (n % i == 0) { n       f.push_back(i); n       f.push_back(n / i); n     } n   } n   long long int ans = 0; n   for (int i = 0; i < f.size(); i++) { n     if (mobius[f[i]] == 0) continue; n     ans = ans + mobius[f[i]] * calc(n, k, f[i]); n   } n   ans = nmod(ans); n   printf( %lld n , ans); n } n int main() { n   fact[0] = 1; n   for (int i = 1; i <= 100000; i++) fact[i] = (i * fact[i - 1]) % 1000000007; n   mobius[1] = 1; n   for (int i = 2; i <= 100000; i++) { n     mobius[i] = mob(i); n   } n   int q; n   scanf( %d , &q); n   for (int i = 0; i < q; i++) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int x = 0, f = 1, 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 << 1) + (x << 3) + (ch -  0 ); n     ch = getchar(); n   } n   return f * x; n } n const int maxn = 1e5 + 10, mod = 1e9 + 7, limit = 1e7; n int n, num[2][maxn], k[2]; n int f[2][maxn], cnt[2][maxn], ans[2][maxn]; n queue<pair<int, int> > q; n int main() { n   n = read(); n   memset(ans, 127, sizeof(ans)); n   k[0] = read(); n   for (int i = 1; i <= k[0]; i++) num[0][i - 1] = read(); n   k[1] = read(); n   for (int i = 1; i <= k[1]; i++) num[1][i - 1] = read(); n   ans[0][0] = ans[1][0] = 0; n   q.push(make_pair(0, 0)); n   q.push(make_pair(1, 0)); n   while (q.size()) { n     while (q.size()) { n       int x = q.front().first, y = q.front().second; n       q.pop(); n       for (int i = 0; i < k[x ^ 1]; i++) { n         int x1 = x ^ 1, y1 = (y - num[x1][i] + n) % n; n         if (!ans[x1][y1] || ans[x1][y1] == 1) continue; n         ans[x1][y1] = 1; n         for (int j = 0; j < k[x]; j++) { n           int y2 = (y1 - num[x][j] + n) % n; n           ++cnt[x][y2]; n         } n       } n     } n     for (int i = 0; i < 2; i++) n       for (int j = 0; j < n; j++) { n         if (!ans[i][j] || ans[i][j] == 1) continue; n         if (cnt[i][j] == k[i]) { n           ans[i][j] = 0; n           q.push(make_pair(i, j)); n         } n       } n   } n   for (int i = 0; i < 2; i++) { n     for (int j = 1; j < n; j++) { n       if (ans[i][j] == 0) n         printf( Lose  ); n       else if (ans[i][j] == 1) n         printf( Win  ); n       else n         printf( Loop  ); n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a, b; n   while (cin >> n) { n     stack<int> st; n     bool ov = true; n     int ovs = 0; n     int res = 0; n     int spd = 0; n     for (int i = 0; i < n; i++) { n       scanf( %d , &(a)); n       if (a == 1) { n         scanf( %d , &(b)); n         spd = b; n       } else if (a == 2) { n         res += ovs; n         ovs = 0; n       } else if (a == 3) { n         scanf( %d , &(b)); n         st.push(b); n       } else if (a == 4) { n         ovs = 0; n       } else if (a == 5) { n         while (!st.empty()) st.pop(); n       } else if (a == 6) { n         ovs++; n       } n       while (!st.empty() && st.top() < spd) { n         st.pop(); n         res++; n       } n     } n     cout << res << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using db = double; n using str = string; n using pi = pair<int, int>; n using pl = pair<ll, ll>; n using pd = pair<db, db>; n using vi = vector<int>; n using vb = vector<bool>; n using vl = vector<ll>; n using vd = vector<db>; n using vs = vector<str>; n using vpi = vector<pi>; n using vpl = vector<pl>; n using vpd = vector<pd>; n template <class T> n using V = vector<T>; n template <class T, size_t SZ> n using AR = array<T, SZ>; n const int MOD = 1e9 + 7; n const int MX = 2e5 + 5; n const ll INF = 1e18; n const ld PI = acos((ld)-1); n const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1}; n mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); n constexpr int pct(int x) { return __builtin_popcount(x); } n constexpr int bits(int x) { return 31 - __builtin_clz(x); } n ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } n ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); } n template <class T> n bool ckmin(T& a, const T& b) { n   return b < a ? a = b, 1 : 0; n } n template <class T> n bool ckmax(T& a, const T& b) { n   return a < b ? a = b, 1 : 0; n } n template <class T, class U> n T fstTrue(T lo, T hi, U first) { n   hi++; n   assert(lo <= hi); n   while (lo < hi) { n     T mid = lo + (hi - lo) / 2; n     first(mid) ? hi = mid : lo = mid + 1; n   } n   return lo; n } n template <class T, class U> n T lstTrue(T lo, T hi, U first) { n   lo--; n   assert(lo <= hi); n   while (lo < hi) { n     T mid = lo + (hi - lo + 1) / 2; n     first(mid) ? lo = mid : hi = mid - 1; n   } n   return lo; n } n template <class T> n void remDup(vector<T>& v) { n   sort(begin(v), end(v)); n   v.erase(unique(begin(v), end(v)), end(v)); n } n template <class T, class U> n void erase(T& t, const U& u) { n   auto it = t.find(u); n   assert(it != end(t)); n   t.erase(u); n } n template <class T> n void re(complex<T>& c); n template <class T, class U> n void re(pair<T, U>& p); n template <class T> n void re(vector<T>& v); n template <class T, size_t SZ> n void re(AR<T, SZ>& a); n template <class T> n void re(T& x) { n   cin >> x; n } n void re(db& d) { n   str t; n   re(t); n   d = stod(t); n } n void re(ld& d) { n   str t; n   re(t); n   d = stold(t); n } n template <class T, class... U> n void re(T& t, U&... u) { n   re(t); n   re(u...); n } n template <class T> n void re(complex<T>& c) { n   T a, b; n   re(a, b); n   c = {a, b}; n } n template <class T, class U> n void re(pair<T, U>& p) { n   re(p.first, p.second); n } n template <class T> n void re(vector<T>& x) { n   for (auto& a : x) re(a); n } n template <class T, size_t SZ> n void re(AR<T, SZ>& x) { n   for (auto& a : x) re(a); n } n str to_string(char c) { return str(1, c); } n str to_string(const char* second) { return (str)second; } n str to_string(str second) { return second; } n str to_string(bool b) { return to_string((int)b); } n template <class T> n str to_string(complex<T> c) { n   stringstream ss; n   ss << c; n   return ss.str(); n } n str to_string(vector<bool> v) { n   str res =  { ; n   for (int i = (0); i < ((int)(v).size()); ++i) res += char( 0  + v[i]); n   res +=  } ; n   return res; n } n template <size_t SZ> n str to_string(bitset<SZ> b) { n   str res =   ; n   for (int i = (0); i < (SZ); ++i) res += char( 0  + b[i]); n   return res; n } n template <class T, class U> n str to_string(pair<T, U> p); n template <class T> n str to_string(T v) { n   bool fst = 1; n   str res =   ; n   for (const auto& x : v) { n     if (!fst) res +=    ; n     fst = 0; n     res += to_string(x); n   } n   return res; n } n template <class T, class U> n str to_string(pair<T, U> p) { n   return to_string(p.first) +     + to_string(p.second); n } n template <class T> n void pr(T x) { n   cout << to_string(x); n } n template <class T, class... U> n void pr(const T& t, const U&... u) { n   pr(t); n   pr(u...); n } n void ps() { pr(  n ); } n template <class T, class... U> n void ps(const T& t, const U&... u) { n   pr(t); n   if (sizeof...(u)) pr(   ); n   ps(u...); n } n void DBG() { cerr <<  ]  << endl; } n template <class T, class... U> n void DBG(const T& t, const U&... u) { n   cerr << to_string(t); n   if (sizeof...(u)) cerr <<  ,  ; n   DBG(u...); n } n void setIn(str second) { freopen(second.c_str(),  r , stdin); } n void setOut(str second) { freopen(second.c_str(),  w , stdout); } n void unsyncIO() { cin.tie(0)->sync_with_stdio(0); } n void setIO(str second =   ) { n   unsyncIO(); n   if ((int)(second).size()) { n     setIn(second +  .in ), setOut(second +  .out ); n   } n } n int main() { n   setIO(); n   int l; n   cin >> l; n   ll num = 0; n   vl v; n   v.push_back(1); n   for (int a = (0); a < (l); ++a) { n     string second; n     cin >> second; n     if (second ==  add ) { n       num += v.back(); n       if (num > 4294967295) { n         cout <<  OVERFLOW!!!  << endl; n         return 0; n       } n     } else if (second ==  for ) { n       int k; n       cin >> k; n       v.push_back(min(4294967296LL, k * v.back())); n     } else n       v.pop_back(); n   } n   cout << num << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int cmax = 1e5 + 8; n int n; n int cnt[cmax]; n vector<pair<int, int> > l(cmax); n long long psum[cmax]; n int d[202]; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> l[i].first, cnt[l[i].first]++; n   for (int i = 1; i <= n; i++) cin >> l[i].second; n   sort(l.begin() + 1, l.begin() + n + 1); n   for (int i = 1; i <= n; i++) psum[i] = psum[i - 1] + l[i].second; n   long long ans = 284488937875784; n   for (int i = 1; i <= n; i++) { n     int p = i; n     while (i < n and l[i].first == l[i + 1].first) i++; n     long long t = psum[n] - psum[i]; n     int x = max(0, i - 2 * cnt[l[i].first] + 1); n     for (int j = 1; j <= 200 and x > 0; j++) { n       int u = min(x, d[j]); n       x -= u; n       t += (long long)u * j; n     } n     ans = min(ans, t); n     for (int k = p; k <= i; k++) d[l[k].second]++; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using i64 = long long; n int n, p[666][666], quad[666]; n bool alive[666]; n i64 x[666], y[666], px[666], py[666]; n int gopos[666][666], goneg[666][666], f[666], id[666]; n i64 dp[666][666][4], ans; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %lld%lld , &x[i], &y[i]); n   } n   for (int i = 1; i <= n; i++) { n     auto getquad = [&](int px, int py) { n       if (px == 0 && py == 0) return 0; n       if (py < 0 || (py == 0 && px < 0)) return 1; n       return 2; n     }; n     for (int j = 1; j <= n; j++) { n       px[j] = x[j] - x[i]; n       py[j] = y[j] - y[i]; n       p[i][j] = j; n       quad[j] = getquad(px[j], py[j]); n     } n     for (int j = 1; j <= n; j++) { n       px[j + n] = x[i] - x[j]; n       py[j + n] = y[i] - y[j]; n       p[i][j + n] = j + n; n       quad[j + n] = getquad(px[j + n], py[j + n]); n     } n     sort(p[i] + 1, p[i] + 2 * n + 1, [&](int a, int b) { n       return quad[a] != quad[b] ? quad[a] < quad[b] n                                 : (px[a] * py[b] < px[b] * py[a]); n     }); n     for (int j = 1; j <= 2 * n; j++) n       if (p[i][j] > n) p[i][j] = n - p[i][j]; n   } n   for (int i = 1; i <= n; i++) { n     int m = 0; n     for (int j = 1; j <= n; j++) { n       if (y[j] > y[i] || (y[j] == y[i] && x[j] >= x[i])) n         alive[j] = 1; n       else n         alive[j] = 0; n       px[j] = x[j] - x[i]; n       py[j] = y[j] - y[i]; n       if (alive[j] && j != i) { n         f[++m] = j; n       } n     } n     sort(f + 1, f + m + 1, n          [&](int a, int b) { return px[a] * py[b] < px[b] * py[a]; }); n     f[0] = i; n     for (int i = 0; i <= m; i++) id[f[i]] = i; n     memset(gopos, -1, sizeof(gopos)); n     memset(goneg, -1, sizeof(goneg)); n     for (int i = 0; i <= m; i++) { n       int nxtpos = -1; n       for (int j = 4 * n; j >= 1; j--) { n         int aj = (j - 1) % (2 * n) + 1; n         int u = p[f[i]][aj]; n         if (u > 0 && alive[u] && nxtpos >= 0) { n           gopos[i][id[u]] = nxtpos; n         } n         if (u < 0 && alive[-u] && nxtpos >= 0) { n           goneg[i][id[-u]] = nxtpos; n         } n         if (u > 0 && alive[u] && u != f[i]) { n           nxtpos = id[u]; n         } n       } n     } n     memset(dp, 0, sizeof(dp)); n     dp[0][1][0] = 1; n     for (int i = 0; i <= m; i++) { n       int u = goneg[i][0]; n       for (int j = 0; j < m - 1; j++) { n         int v = gopos[i][u]; n         for (int k = 0; k <= 3; k++) { n           dp[i][v][k] += dp[i][u][k]; n         } n         u = v; n       } n       for (int j = i + 1; j <= m; j++) { n         ans += dp[i][j][3]; n         int nxt = goneg[j][i]; n         if (nxt > j) { n           for (int k = 0; k <= 2; k++) { n             dp[j][nxt][k + 1] += dp[i][j][k]; n           } n         } n       } n     } n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n typename T::value_type arr_sum(const T& v, int n) { n   typename T::value_type sum = 0; n   for (int i = 0; i < n; ++i) sum += v[i]; n   return sum; n } n struct Sync_stdio { n   Sync_stdio() { n     cin.tie(NULL); n     ios_base::sync_with_stdio(false); n   } n } _sync_stdio; n int main() { n   int n, m; n   cin >> n >> m; n   vector<int> left; n   vector<int> right(n); n   for (int i = 0; i < n; ++i) { n     int t; n     cin >> t; n     left.push_back(t); n   } n   sort(left.begin(), left.end()); n   for (int i = 0, j = n / 2; i < n; ++i, j = (j + 1) % n) { n     right[i] = left[j]; n   } n   int res = 0; n   for (int i = 0; i < n; ++i) { n     if (left[i] == right[i]) { n       ++res; n     } n   } n   cout << n - res <<   n ; n   for (int i = 0; i < n; ++i) { n     cout << left[i] <<     << right[i] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1e9 + 7; n long long min(long long a, long long b) { return (a < b) ? a : b; } n long long max(long long a, long long b) { return (a > b) ? a : b; } n long long fp(long long a, long long b) { n   if (b == 0) return 1; n   long long x = fp(a, b / 2); n   x = (x * x) % mod; n   if (b & 1) x = (x * a) % mod; n   return x; n } n const long long N = 2000; n long long bit[4 * N]; n void update(long long id, long long l, long long r, long long point, n             long long val) { n   if (point < l || point > r) return; n   if (l == r) { n     bit[id] += val; n     return; n   } n   long long mid = (l + r) / 2; n   update(2 * id, l, mid, point, val); n   update(2 * id + 1, mid + 1, r, point, val); n   bit[id] = bit[2 * id] + bit[2 * id + 1]; n } n long long get(long long id, long long l, long long r, long long point) { n   if (point < l) { n     return 0; n   } n   if (r <= point) { n     return bit[id]; n   } n   long long mid = (l + r) / 2; n   return get(2 * id, l, mid, point) + get(2 * id + 1, mid + 1, r, point); n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long n; n   cin >> n; n   long long a[n + 1]; n   for (long long i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   map<long long, vector<array<long long, 2>>> mp; n   for (long long i = 1; i <= n; i++) { n     long long sm = 0; n     for (long long j = i; j <= n; j++) { n       sm += a[j]; n       mp[sm].push_back({i, j}); n     } n   } n   vector<array<long long, 2>> ans; n   for (auto i : mp) { n     vector<array<long long, 2>> tmp; n     sort(i.second.begin(), i.second.end()); n     for (long long j = 0; j < i.second.size(); j++) { n       update(1, 1, n, i.second[j][1], 1); n     } n     long long st = 1; n     for (long long j = 0; j < i.second.size(); j++) { n       update(1, 1, n, i.second[j][1], -1); n       if (i.second[j][0] < st) continue; n       if (i.second[j][0] == i.second[j][1]) { n         tmp.push_back(i.second[j]); n         st = i.second[j][1] + 1; n       } else { n         long long x = n             get(1, 1, n, i.second[j][1] - 1) - get(1, 1, n, i.second[j][0]); n         if (x > 0) { n           continue; n         } else { n           tmp.push_back(i.second[j]); n           st = i.second[j][1] + 1; n         } n       } n     } n     if (tmp.size() > ans.size()) ans = tmp; n   } n   cout << ans.size() <<   n ; n   for (auto i : ans) cout << i[0] <<     << i[1] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int ans = 1, n, k, i; n   cin >> n >> k; n   cout << (n / k + 1) * k; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::cout << std::setprecision(6) << std::fixed; n   double tux; n   cin >> tux; n   double foo = 0, bar = 0, baz = 0, quz = 1; n   for (; tux != 0.0; tux--) { n     double pur; n     cin >> pur; n     foo = foo + pur; n     bar = bar + 1; n     if ((foo * quz) >= (bar * baz)) { n       baz = foo; n       quz = bar; n     } n   } n   cout << (double)(baz / quz); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a, d, t, v; n double tim[200000]; n double jisuan(double a, double vmax, double s) { n   double t = (vmax) / a; n   if (0.5 * a * t * t > s) n     return sqrt(s * 2 / a); n   else n     return t + (s - 0.5 * a * t * t) / vmax; n } n int main() { n   scanf( %d%d%d , &n, &a, &d); n   scanf( %d%d , &t, &v); n   tim[1] = t + jisuan(a, v, d); n   for (int i = 2; i <= n; ++i) { n     scanf( %d%d , &t, &v); n     tim[i] = t + jisuan(a, v, d); n     if (tim[i] < tim[i - 1]) tim[i] = tim[i - 1]; n   } n   for (int i = 1; i <= n; ++i) printf( %.10lf n , tim[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = (int)2e5 + 7; n vector<int> G[MAXN]; n int pic[1007][1007], vis[MAXN], siz[MAXN]; n unordered_map<int, int> mp; n int tot, val[MAXN]; n int fa[MAXN], sz; n int findfa(int x) { n   if (x == fa[x]) return x; n   return fa[x] = findfa(fa[x]); n } n void unite(int x, int y, bool flag = 1) { n   int u = findfa(x), v = findfa(y); n   if (u == v) return; n   fa[u] = v; n   if (flag) siz[v] += siz[u]; n   sz++; n } n int main() { n   int N, M; n   scanf( %d %d , &N, &M); n   for (int i = (int)1; i <= (int)N; i++) fa[i] = i, siz[i] = 1; n   for (int i = (int)1; i <= (int)M; i++) { n     int u, v; n     scanf( %d %d , &u, &v); n     G[u].push_back(v); n     G[v].push_back(u); n   } n   int mn = 1e9, id = 0; n   for (int i = (int)1; i <= (int)N; i++) { n     if (G[i].size() < mn) { n       mn = G[i].size(); n       id = i; n     } n   } n   for (int v : G[id]) vis[v] = 1; n   vis[id] = 1; n   for (int i = (int)1; i <= (int)N; i++) n     if (vis[i] == 0) unite(id, i); n   for (int i = (int)1; i <= (int)N; i++) { n     if (findfa(i) == i) { n       mp[i] = ++tot; n       val[tot] = i; n     } n   } n   for (int u = (int)1; u <= (int)N; u++) { n     for (int v : G[u]) { n       int f1 = mp[findfa(u)]; n       int f2 = mp[findfa(v)]; n       if (f1 == f2) continue; n       pic[f1][f2]++; n     } n   } n   for (int i = (int)1; i <= (int)tot; i++) { n     for (int j = (int)i + 1; j <= (int)tot; j++) { n       if (1LL * siz[val[i]] * siz[val[j]] != pic[i][j]) { n         unite(val[i], val[j], 0); n       } n     } n   } n   int ans = N - sz - 1; n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, k; n   cin >> n >> k; n   long long int i, a[n]; n   for (i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   if (a[0] == a[n - 1] && a[0] == 0) { n     while (k--) cout << 0 << endl; n   } n   long long int b[n], ct = 0; n   for (i = 0; i < n; i++) { n     while (i < n && a[i] == a[i + 1]) i++; n     b[ct++] = a[i]; n   } n   i = 0; n   long long int cnt = 0; n   while (k--) { n     while (b[i] == 0) i++; n     if (i >= ct) n       cout << 0 << endl; n     else n       cout << b[i] - cnt << endl; n     cnt = b[i]; n     i++; n   } n } n


#include <bits/stdc++.h> n using namespace std; n class C_ {}; n template <typename T> n C_& operator<<(C_& __m, const T& __s) { n   if (!1) cerr <<   E[91m  << __s <<   E[0m ; n   return __m; n } n C_ merr; n struct __s { n   __s() { n     if (1) { n       ios_base::Init i; n       cin.sync_with_stdio(0); n       cin.tie(0); n     } n   } n   ~__s() { n     merr <<  Execution time:   << (double)clock() / CLOCKS_PER_SEC <<   s. n ; n   } n } __S; n char A[2222][2222]; n bool u[2222][2222]; n int n, m; n bool check(int x, int y) { n   int i = x, j = y; n   int cnt = 0; n   if (!(0 <= x && x < n) || !(0 <= y && y < m) || A[x][y] !=  . ) return false; n   cnt += (i == 0 || A[i - 1][j] !=  . ); n   cnt += (j == 0 || A[i][j - 1] !=  . ); n   cnt += (i == n - 1 || A[i + 1][j] !=  . ); n   cnt += (j == m - 1 || A[i][j + 1] !=  . ); n   return !u[i][j] && cnt == 3; n } n void add(queue<pair<int, int> >& Q, int x, int y) { n   if (check(x, y)) { n     Q.push(make_pair(x, y)); n     u[x][y] = 1; n   } n } n int main() { n   int left = 0; n   queue<pair<int, int> > Q; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     for (int j = 0; j < m; j++) { n       A[i][j] = s[j]; n       if (A[i][j] ==  . ) { n         left++; n       } n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (A[i][j] !=  . ) continue; n       add(Q, i, j); n     } n   } n   while (Q.size()) { n     int x = Q.front().first, y = Q.front().second; n     Q.pop(); n     if (A[x][y] !=  . ) continue; n     if (x != n - 1 && A[x + 1][y] ==  . ) { n       A[x][y] =  ^ ; n       A[x + 1][y] =  v ; n       left -= 2; n       add(Q, x - 1, y); n       add(Q, x, y - 1); n       add(Q, x, y + 1); n       add(Q, x + 1, y - 1); n       add(Q, x + 1, y + 1); n       add(Q, x + 2, y); n     } else if (x != 0 && A[x - 1][y] ==  . ) { n       A[x - 1][y] =  ^ ; n       A[x][y] =  v ; n       left -= 2; n       add(Q, x - 2, y); n       add(Q, x, y - 1); n       add(Q, x, y + 1); n       add(Q, x - 1, y - 1); n       add(Q, x - 1, y + 1); n       add(Q, x + 1, y); n     } else if (y != m - 1 && A[x][y + 1] ==  . ) { n       A[x][y] =  < ; n       A[x][y + 1] =  > ; n       left -= 2; n       add(Q, x, y - 1); n       add(Q, x - 1, y); n       add(Q, x - 1, y + 1); n       add(Q, x + 1, y); n       add(Q, x + 1, y + 1); n       add(Q, x + 2, y); n     } else if (y != 0 && A[x][y - 1] ==  . ) { n       A[x][y - 1] =  < ; n       A[x][y] =  > ; n       left -= 2; n       add(Q, x, y - 2); n       add(Q, x - 1, y); n       add(Q, x - 1, y - 1); n       add(Q, x + 1, y); n       add(Q, x + 1, y - 1); n       add(Q, x + 2, y); n     } n     for (int dx = -3; dx <= 3; dx++) { n       for (int dy = -3; dy <= 3; dy++) { n         add(Q, x + dx, y + dy); n       } n     } n   } n   if (left != 0) { n     cout <<  Not unique  <<   n ; n     return 0; n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cout << A[i][j]; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 500005; n int n, m, h[N], mn[N], par[N], t, num, op, uo, ra; n vector<int> adj[N]; n set<int> answer, qtr; n bool finish, q[N], vis[N]; n struct edge { n   int u, v; n } ed[N]; n void output() { n   if ((int)answer.size() == n) { n     cout <<  NO  <<   n ; n     finish = true; n     return; n   } n   cout <<  YES  <<   n  << n - answer.size() <<   n ; n   for (int i = 0; i < n; i++) n     if (!answer.count(i)) cout << i + 1 <<    ; n   cout <<   n ; n   finish = true; n } n void haveDeg3() { n   for (int i = 0; i < n && !finish; i++) n     if (!(adj[i].size() % 3)) answer.insert(i), output(); n } n void oneEdge() { n   for (int i = 0; i < m; i++) { n     if (adj[ed[i].v].size() % 3 == 1 && adj[ed[i].u].size() % 3 == 1) { n       answer.insert(ed[i].u), answer.insert(ed[i].v), output(); n       return; n     } n   } n } n void check(int x) { n   vector<int> po; n   for (auto v : adj[x]) n     if (adj[v].size() % 3 == 1) { n       q[x] = true; n       po.push_back(v); n     } n   if (po.size() > 1) { n     answer.insert(po[0]), answer.insert(po[1]), answer.insert(x), output(); n     return; n   } n } n void Vgraph() { n   for (int i = 0; i < n && !finish; i++) n     if (adj[i].size() % 3 == 2) check(i); n } n void findCycle(int x) { n   vis[x] = true; n   for (auto v : adj[x]) n     if (adj[v].size() % 3 == 2 && v != par[x]) { n       if (!vis[v]) n         h[v] = h[x] + 1, mn[v] = h[v], par[v] = x; n       else { n         if (mn[x] != h[x]) n           mn[x] = max(mn[x], h[v]); n         else n           mn[x] = min(mn[x], h[v]); n       } n     } n   if (mn[x] < h[x] - 1) { n     int z = mn[x]; n     while (h[x] != z) { n       answer.insert(x), x = par[x]; n     } n     answer.insert(x), output(); n     return; n   } n   for (auto v : adj[x]) n     if (!vis[v] && !finish && adj[v].size() % 3 == 2) { n       findCycle(v); n     } n } n void cycle() { n   for (int i = 0; i < n && !finish; i++) n     if (adj[i].size() % 3 == 2 && !vis[i]) { n       findCycle(i); n     } n } n void dfs(int x) { n   if (finish) return; n   vis[x] = true; n   if (q[x]) { n     if (!qtr.count(x)) { n       for (auto v : adj[x]) n         if (adj[v].size() % 3 == 1) answer.insert(v); n       while (x != op) answer.insert(x), x = par[x]; n       answer.insert(op); n       output(); n     } else if (par[x] != op) { n       vis[x] = false; n       return; n     } n   } n   for (auto v : adj[x]) n     if (!vis[v] && adj[v].size() % 3 == 2) par[v] = x, dfs(v); n } n void dfsqt(int x) { n   if (finish) return; n   vis[x] = true; n   if (q[x] && par[x] != op) { n     num++; n     while (x != op) { n       for (auto v : adj[x]) vis[v] = true; n       answer.insert(x), x = par[x]; n     } n     if (num > 1) { n       answer.insert(x); n       output(); n     } n     dfsqt(op); n   } n   for (auto v : adj[x]) n     if (!vis[v] && adj[v].size() % 3 == 2) par[v] = x, dfsqt(v); n } n void another() { n   num = 0; n   for (int i = 0; i < n; i++) par[i] = 0, vis[i] = false; n   for (int i = 0; i < n && !finish; i++) n     if (adj[i].size() % 3 == 1) { n       qtr.clear(); n       for (auto v : adj[i]) qtr.insert(v); n       dfs(op = i); n       if (!finish) { n         for (int i = 0; i < n; i++) par[i] = 0, vis[i] = false; n         dfsqt(op); n       } n       return; n     } n } n void readInput() { n   answer.clear(); n   finish = false; n   cin >> n >> m; n   for (int i = 0; i < n; i++) n     adj[i].clear(), h[i] = mn[i] = par[i] = 0, vis[i] = q[i] = false; n   for (int i = 0; i < m; i++) { n     int x, y; n     cin >> x >> y; n     ed[i].u = --x, ed[i].v = --y; n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n } n void solve() { n   haveDeg3(); n   if (finish) return; n   oneEdge(); n   if (finish) return; n   Vgraph(); n   if (finish) return; n   cycle(); n   if (finish) return; n   another(); n   if (finish) return; n   cout <<  NO n ; n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> t; n   while (t--) readInput(), solve(); n   return 0; 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   int t; n   cin >> t; n   while (t--) { n     int n, k; n     cin >> n >> k; n     int arr[n], brr[n]; n     for (int i = 0; i < n; i++) { n       cin >> arr[i]; n     } n     sort(arr, arr + n, greater<int>()); n     for (int j = 0; j < n; j++) { n       cin >> brr[j]; n     } n     sort(brr, brr + n, greater<int>()); n     int ans = 0; n     int i = 0, j = 0; n     int cnt = n; n     while (cnt--) { n       if (arr[i] >= brr[j]) n         ans += arr[i], i += 1; n       else if (k > 0) n         ans += brr[j], j += 1, k -= 1; n       else n         ans += arr[i], i += 1; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n, c0, c1, h; n   cin >> n >> c0 >> c1 >> h; n   string s; n   cin >> s; n   int ans = 0; n   for (char ch : s) { n     if (ch ==  0 ) { n       ans += min(c0, c1 + h); n     } else { n       ans += min(c1, c0 + h); n     } n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int tc = 1; n   cin >> tc; n   while (tc--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> AL[100005]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n - 1; i++) { n     int u, v; n     scanf( %d , &u); n     scanf( %d , &v); n     AL[u].push_back(v); n     AL[v].push_back(u); n   } n   long long int l = 0; n   int fl = 0; n   for (int i = 1; i <= n; i++) { n     if (AL[i].size() == 2) { n       fl = 1; n     } n   } n   if (fl == 0) { n     printf( YES n ); n   } else { n     printf( NO n ); n   } n   return 0; n } n


#include<bits/stdc++.h> n #define ll long long n #define ull unsigned long long n  n #define  in(ar,n) for(int i=0;i<n;i++)cin>>ar[i]; n #define invec(ar,n)for(int i  =0 ; i<n;i++){int temp;cin>>temp;ar.push_back(temp);} n #define in2d(ar,n,m) for(int i=0;i<n;i++)for(int i=0;i<m;i++)cin>>ar[i] n #define out(ar,n)     for(int i=0;i<n;i++)     cout<<ar[i]<<   ;     cout<<endl; n #define swap(a,b)    int t = a;     a = b;     b = t; n #define print(val) cout<<val<<endl; n #define set(ar,n,val) for(int i=0;i<n;i++)ar[i]=val n #define for2d(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++) n #define minar(ar,n,mn) for(int i=0;i<n;i++)mn =min(mn,ar[i]) n #define maxar(ar,n,mx) for(int i=0;i<n;i++)mx =max(mx,ar[i]) n #define fori(i,a,b) for(ll i=a;i<b;++i) n #define all(ar) ar.begin(),ar.end() n using namespace std; n typedef pair<ll,ll> pll; n typedef pair<int,int> pii; n typedef vector<vector<int>> vvi; n const ll mod = 1e9 + 7; n  n int main(){ n     int t;cin>>t; n     while(t--){ n        int n;cin>>n; n        string s;cin>>s; n        vector<int> ar,ans; n        fori(i,0,n){ n            ar.push_back(s[i]- 0 ); n  n        } n         ans.push_back(1); n        int c = ar[0]+1; n  n        fori(i,1,n){ n            if(c==2){ n                if(ar[i]==1){ n                    ans.push_back(0); n                    c = 1; n                } n                else { n                    ans.push_back(1); n                    c = 1; n                } n            } n            else if(c==1){ n                if(ar[i]==1){ n                    ans.push_back(1); n                     c = 2; n                } n                else {ans.push_back(0);c = 0;} n            } n            else { n                if(ar[i]==0){ n                    ans.push_back(1); n                    c = 1; n                } n                else { n                    ans.push_back(1); n                    c = 2; n                } n            } n        } n        fori(i,0,n){ n            cout<<ans[i]; n        } n        cout<<endl; n     } n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, d, h, i, p, q, s; n   cin >> n >> d >> h; n   if (d > (2 * h)) { n     cout <<  -1 ; n   } else if ((d == 1) && (h == 1)) { n     if (n == 2) { n       cout <<  1 2 ; n     } else { n       cout <<  -1 ; n     } n   } else if ((d == h)) { n     for (i = 1; i <= h - 1; i++) { n       cout << i <<     << i + 1 << endl; n     } n     p = h + 2; n     for (i = h + 1; i <= n; i++) { n       cout << h <<     << i << endl; n     } n   } else { n     if (d > h) { n       for (i = 1; i <= h; i++) { n         cout << i <<     << i + 1 << endl; n       } n       cout <<  1   << h + 2 << endl; n       for (i = (h + 2); i <= d; i++) { n         cout << i <<     << i + 1 << endl; n       } n       for (i = (d + 2); i <= n; i++) { n         cout <<  1   << i << endl; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 25; n const int mo = 1000000007; n const int inf = (int)1e9; n inline int IN() { n   char ch; n   (ch = getchar()); n   int f = 0, x = 0; n   for (; ((ch) ==   n  || (ch) ==   r  || (ch) ==   t  || (ch) ==    ); n        (ch = getchar())) n     ; n   if (ch ==  - ) f = 1, (ch = getchar()); n   for (; !((ch) ==   n  || (ch) ==   r  || (ch) ==   t  || (ch) ==    ); n        (ch = getchar())) n     x = x * 10 + ch -  0 ; n   return (f) ? (-x) : (x); n } n int Pow(int x, int y, int p) { n   int A = 1; n   for (; y; y >>= 1, x = (long long)x * x % p) n     if (y & 1) A = (long long)A * x % p; n   return A; n } n int n, m, laba[N], labb[N], visa[N], visb[N], tim, mat[N], ans; n int w[N][N], a[N][N], b[N][N], c[N][N], tot_done; n bool extend(int x) { n   if (!x) return 1; n   visa[x] = tim; n   for (int i = (int)1; i <= (int)n; i++) { n     if (visb[i] != tim && laba[x] + labb[i] == w[x][i]) { n       visb[i] = tim; n       if (extend(mat[i])) { n         mat[i] = x; n         return 1; n       } n     } n   } n   return 0; n } n void change() { n   int delta = inf; n   for (int i = (int)1; i <= (int)n; i++) n     if (visa[i] == tim) n       for (int j = (int)1; j <= (int)n; j++) n         if (visb[j] != tim) { n           delta = min(delta, laba[i] + labb[j] - w[i][j]); n         } n   for (int i = (int)1; i <= (int)n; i++) n     if (visa[i] == tim) laba[i] -= delta; n   for (int i = (int)1; i <= (int)n; i++) n     if (visb[i] == tim) labb[i] += delta; n } n int KM() { n   for (int i = (int)1; i <= (int)n; i++) visa[i] = visb[i] = mat[i] = 0; n   for (int i = (int)1; i <= (int)n; i++) laba[i] = w[i][0], labb[i] = 0; n   tim = 0; n   for (int i = (int)1; i <= (int)n; i++) { n     for (;;) { n       ++tim; n       if (extend(i)) break; n       change(); n     } n   } n   int re = 0; n   for (int i = (int)1; i <= (int)n; i++) re += w[mat[i]][i]; n   return re; n } n void dfs(int x, int cnt) { n   int now = KM(); n   if (now <= ans) return; n   if (x == n) { n     ans = now; n     return; n   } n   ++tot_done; n   if (tot_done >= 1e5) return; n   ++x; n   if (m - cnt < n - x + 1) { n     for (int i = (int)0; i <= (int)n; i++) w[x][i] = a[x][i]; n     dfs(x, cnt); n   } n   if (cnt < m) { n     for (int i = (int)0; i <= (int)n; i++) w[x][i] = b[x][i]; n     dfs(x, cnt + 1); n   } n   for (int i = (int)0; i <= (int)n; i++) w[x][i] = c[x][i]; n } n int main() { n   scanf( %d , &n); n   m = n >> 1; n   for (int i = (int)1; i <= (int)n; i++) n     for (int j = (int)1; j <= (int)n; j++) { n       a[i][j] = IN(); n       a[i][0] = max(a[i][0], a[i][j]); n     } n   for (int i = (int)1; i <= (int)n; i++) n     for (int j = (int)1; j <= (int)n; j++) { n       b[i][j] = IN(); n       b[i][0] = max(b[i][0], b[i][j]); n     } n   for (int i = (int)1; i <= (int)n; i++) n     for (int j = (int)1; j <= (int)n; j++) { n       w[i][j] = c[i][j] = max(a[i][j], b[i][j]); n       w[i][0] = c[i][0] = max(w[i][0], c[i][j]); n     } n   dfs(0, 0); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e3 + 10, big = 1e18, mod = 1e9 + 7; n vector<long long> a[N], now, ans; n long long n, x, y, m, maxi; n bool vis[N], mp[N][N]; n void dfs(long long i) { n   vis[i] = 1, now.push_back(i); n   for (int j = 0; j < a[i].size(); j++) n     if (!vis[a[i][j]]) dfs(a[i][j]); n } n int main() { n   cin >> n; n   cin >> m; n   while (m--) { n     cin >> x >> y; n     a[x].push_back(y); n     a[y].push_back(x); n   } n   cin >> m; n   while (m--) { n     cin >> x >> y; n     mp[x][y] = mp[y][x] = 1; n   } n   for (int i = 1; i <= n; i++) n     if (!vis[i]) { n       now.clear(); n       dfs(i); n       bool check = 1; n       if (now.size() == 1) n         maxi = max(1LL, maxi); n       else { n         for (int j = 0; j < now.size() - 1; j++) n           for (int k = j + 1; k < now.size(); k++) n             if (mp[now[j]][now[k]]) check = 0; n         if (check) maxi = max((long long)now.size(), maxi); n       } n     } n   cout << maxi; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> V; n void initSet(int _size) { n   V.resize(_size); n   for (int i = int(0); i <= int(_size - 1); i++) V[i] = i; n } n int findSet(int i) { return (V[i] == i) ? i : (V[i] = findSet(V[i])); } n void unionSet(int i, int j) { V[findSet(i)] = findSet(j); } n bool isSameSet(int i, int j) { return findSet(i) == findSet(j); } n long long a, b, s, N, M, A, B, r[123450]; n int find(int node) { n   if (r[node]) return r[node] = find(r[node]); n   return node; n } n int main() { n   int N = 0; n   cin >> N >> M; n   s = 1; n   for (int i = 1; i <= M; ++i) { n     cin >> a >> b; n     A = find(a); n     B = find(b); n     if (A == B) { n       s = s * 2 % 1000000009; n     } else { n       r[B] = A; n     } n     if (s > 0) n       cout << s - 1 << endl; n     else n       cout << 1000000009 - 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 3e5 + 5; n const long long INF = 1e18; n const long long mod = 1e9 + 7; n void solve() { n   long long n, m, k; n   string s; n   cin >> n; n   map<int, int> F; n   while (true) { n     F[n] = 1; n     n = n + 1; n     while (n % 10 == 0) n /= 10; n     if (F.find(n) != F.end()) break; n   } n   cout << F.size(); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<int> s; n int a[200005]; n int b[200005], u[200005]; n int n, k; n int main() { n   int T; n   scanf( %d , &T); n   for (; T--;) { n     scanf( %d%d , &n, &k); n     for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n     for (int i = 1; i <= k; i++) scanf( %d , &b[i]); n     for (int i = 1; i <= n; i++) u[a[i]] = i; n     s.clear(); n     for (int i = 1; i <= k; i++) s.insert(b[i]); n     long long ans = 1; n     for (int i = 1; i <= k; i++) { n       int x = u[b[i]]; n       int now = 0; n       int y; n       if (x > 1) { n         y = x - 1; n         if (s.find(a[y]) == s.end()) now++; n       } n       if (x < n) { n         y = x + 1; n         if (s.find(a[y]) == s.end()) now++; n       } n       ans = ans * now % 998244353; n       s.erase(b[i]); n     } n     printf( %lld n , ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const string alf =  abcdefghijklmnopqrstuvwxyz ; n const int hashP = 239017; n const int N = 1e5 + 10; n const int MOD = 1e9 + 7; n const int MOD2 = 998244353; n const int INF = 1e9; n const long long oo = 9e18; n template <typename T> n bool umn(T &a, T b) { n   return (a > b ? (a = b, 1) : 0); n } n template <typename T> n bool umx(T &a, T b) { n   return (a < b ? (a = b, 1) : 0); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long tt; n   cin >> tt; n   while (tt--) { n     long long n; n     cin >> n; n     long long k = 2, sum = 1; n     while (1) { n       sum += k; n       k *= 2; n       if (!(n % sum)) { n         cout << n / sum <<   n ; n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long ans = 0; n   long long n; n   cin >> n; n   vector<long long> a(n), b(n), c(n); n   string s1, s2; n   cin >> s1 >> s2; n   for (long long i = 0; i < n; i++) { n     a[i] = (s1[i] ==  0  ? 0 : 1); n   } n   for (long long i = 0; i < n; i++) { n     b[i] = (s2[i] ==  0  ? 0 : 1); n     c[i] = a[i] ^ b[i]; n   } n   for (long long i = 1; i < n; i++) { n     if (c[i] == 1 && c[i - 1] == 1 && (a[i] != a[i - 1])) { n       ans += 1; n       c[i] = 0; n       c[i - 1] = 0; n     } n   } n   for (long long i = 0; i < n; i++) { n     if (c[i] == 1) { n       ans += 1; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   while (n <= 70000) { n     ++n; n     int x = n; n     int a[10] = {0}; n     for (int i = 0; i < 4; i++) { n       int m = x % 10; n       ++a[m]; n       x = x / 10; n     } n     int count = 0; n     for (int i = 0; i < 10; i++) { n       if (a[i] == 1) ++count; n     } n     if (count == 4) { n       cout << n; n       break; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline void read(int &x) { n   char ch; n   bool flag = false; n   for (ch = getchar(); !isdigit(ch); ch = getchar()) n     if (ch ==  - ) flag = true; n   for (x = 0; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar()) n     ; n   x = flag ? -x : x; n } n const int INF = 0x3f3f3f3f; n const int N = 1e6 + 7; n int a[N], l[N], r[N]; n int ll[N], rr[N]; n int main() { n   int n, x; n   cin >> n >> x; n   memset(l, 0x3f3f3f, sizeof(l)); n   memset(ll, 0x3f3f3f, sizeof(ll)); n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     l[a[i]] = min(i, l[a[i]]); n     r[a[i]] = i; n   } n   long long ans = 0; n   for (int i = 1; i <= x; i++) rr[i] = max(r[i], rr[i - 1]); n   for (int i = x; i >= 1; i--) ll[i] = min(l[i], ll[i + 1]); n   int d = x; n   while (ll[d] >= r[d - 1] && d >= 1) d--; n   for (int i = 0; i < x; i++) { n     if (i != 0 && l[i] < rr[i - 1]) break; n     while (d <= i + 1 || rr[i] > ll[d]) { n       d++; n     } n     ans += x - d + 2; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 10, maxk = 1e6 + 10; n int n, k, A[maxn], cnt[maxk], sum[maxk]; n int32_t main() { n   scanf( %d%d , &n, &k); n   for (int i = int(0); i < int(n); i++) { n     scanf( %d , A + i); n     cnt[A[i]]++; n   } n   sort(A, A + n); n   for (int i = int(1); i < int(maxk); i++) { n     sum[i] = sum[i - 1] + cnt[i - 1]; n   } n   int g, c = n, ans = 0; n   for (g = 1; g < maxk; g++) { n     c = 0; n     for (int j = g; j < maxk; j += g) { n       c += sum[min(maxk - 1, j + min(k + 1, g))] - sum[j]; n     } n     if (c >= n) ans = g; n   } n   printf( %d n , ans); n   return 0; n } n