#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline void read(T& t) { n   T f = 1; n   char ch = getchar(); n   t = 0; n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -f; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) t = t * 10 + ch -  0 , ch = getchar(); n   t *= f; n } n template <typename T, typename... Args> n inline void read(T& t, Args&... args) { n   read(t); n   read(args...); n } n int t, T, n, m; n int n1 = 1e9, n2 = -1e9; n int l[100005], r[100005]; n char ans[100005]; n inline bool pd(int i, int x) { return l[i] <= x && x <= r[i]; } n vector<int> edge[100005]; n bool dfs(int now) { n   for (int i = 0; i < edge[now].size(); i++) n     if (ans[edge[now][i]] == 0) { n       ans[edge[now][i]] = 3 - ans[now]; n       if (dfs(edge[now][i]) == 0) return 0; n     } else if (ans[edge[now][i]] == ans[now]) n       return 0; n   return 1; n } n int main() { n   read(t, T, n, m); n   for (int i = 1; i <= n; i++) n     read(l[i], r[i]), n1 = min(n1, r[i]), n2 = max(n2, l[i]); n   if (n1 + n2 < t) n2 = t - n1; n   if (n1 + n2 > T) n1 = T - n2; n   if (n1 < 0 || n2 < 0) return printf( IMPOSSIBLE n ), 0; n   for (int i = 1; i <= n; i++) { n     if (pd(i, n1) == 0 && pd(i, n2) == 0) return printf( IMPOSSIBLE n ), 0; n     if (pd(i, n1) == 1 && pd(i, n2) == 0) ans[i] = 1; n     if (pd(i, n1) == 0 && pd(i, n2) == 1) ans[i] = 2; n   } n   for (int i = 1, x, y; i <= m; i++) { n     read(x, y); n     edge[x].push_back(y); n     edge[y].push_back(x); n   } n   for (int i = 1; i <= n; i++) n     if (ans[i]) n       if (dfs(i) == 0) return printf( IMPOSSIBLE n ), 0; n   for (int i = 1; i <= n; i++) n     if (ans[i] == 0) { n       ans[i] = 1; n       if (dfs(i) == 0) return printf( IMPOSSIBLE n ), 0; n     } n   printf( POSSIBLE n%d %d n , n1, n2); n   for (int i = 1; i <= n; i++) ans[i] +=  0 ; n   printf( %s n , ans + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class _T> n inline _T sqr(const _T &first) { n   return first * first; n } n template <class _T> n inline string tostr(const _T &a) { n   ostringstream os(  ); n   os << a; n   return os.str(); n } n const long double PI = 3.1415926535897932384626433832795L; n const long double EPS = 1e-9; n char TEMPORARY_CHAR; n const int INF = 1e9; n inline void fft(vector<complex<long double> > &a, bool invert) { n   int n = (int)a.size(); n   for (int i = 1, j = 0; i < n; ++i) { n     int bit = n >> 1; n     for (; j >= bit; bit >>= 1) j -= bit; n     j += bit; n     if (i < j) swap(a[i], a[j]); n   } n   for (int len = 2; len <= n; len <<= 1) { n     long double ang = 2 * PI / len * (invert ? -1 : 1); n     complex<long double> wlen(cos(ang), sin(ang)); n     for (int i = 0; i < n; i += len) { n       complex<long double> w(1); n       for (int j = 0; j < len / 2; ++j) { n         complex<long double> u = a[i + j], v = a[i + j + len / 2] * w; n         a[i + j] = u + v; n         a[i + j + len / 2] = u - v; n         w *= wlen; n       } n     } n   } n   if (invert) n     for (int i = 0; i < n; ++i) a[i] /= n; n } n inline void input(int &a) { n   a = 0; n   while (((TEMPORARY_CHAR = getchar()) >  9  || TEMPORARY_CHAR <  0 ) && n          (TEMPORARY_CHAR !=  - )) { n   } n   char neg = 0; n   if (TEMPORARY_CHAR ==  - ) { n     neg = 1; n     TEMPORARY_CHAR = getchar(); n   } n   while (TEMPORARY_CHAR <=  9  && TEMPORARY_CHAR >=  0 ) { n     a = (a << 3) + (a << 1) + TEMPORARY_CHAR -  0 ; n     TEMPORARY_CHAR = getchar(); n   } n   if (neg) a = -a; n } n inline void out(long long a) { n   if (!a) putchar( 0 ); n   if (a < 0) { n     putchar( - ); n     a = -a; n   } n   char s[20]; n   int i; n   for (i = 0; a; ++i) { n     s[i] =  0  + a % 10; n     a /= 10; n   } n   for (int j = (i)-1; j >= 0; j--) putchar(s[j]); n } n inline int nxt() { n   int(ret); n   input((ret)); n   ; n   return ret; n } n struct lnum { n   vector<int> a; n   int base; n   lnum(int num = 0, int base = 1000000000) : base(base) { n     if (!num) a.resize(1); n     while (num) { n       a.push_back(num % base); n       num /= base; n     } n   } n   inline int len() const { return a.size(); } n   lnum &operator=(const lnum &l) { n     if (this != &l) { n       a = l.a; n       base = l.base; n     } n     return *this; n   } n   inline friend lnum operator+(const lnum &l, const lnum &r) { n     lnum ret(0, l.base); n     int base = l.base; n     int ln = l.len(), rn = r.len(); n     int n = max(ln, rn); n     ret.a.resize(n); n     int o = 0; n     for (int i = 0; i < n; ++i) { n       int s = o; n       if (i < ln) s += l.a[i]; n       if (i < rn) s += r.a[i]; n       o = s >= base; n       if (o) s -= base; n       ret.a[i] = s; n     } n     if (o) ret.a.push_back(1); n     return ret; n   } n   inline friend lnum operator-(const lnum &l, const lnum &r) { n     lnum ret(0, l.base); n     int base = l.base; n     int n = l.len(); n     int rn = r.len(); n     ret.a.resize(n); n     int o = 0; n     for (int i = 0; i < n; ++i) { n       int s = l.a[i] - o; n       if (i < rn) s -= r.a[i]; n       o = s < 0; n       if (o) s += base; n       ret.a[i] = s; n     } n     if (ret.len() > 1 && !ret.a.back()) ret.a.pop_back(); n     return ret; n   } n   inline friend lnum operator*(const lnum &l, const lnum &r) { n     lnum ret(0, l.base); n     int base = l.base; n     if (l.len() * r.len() > 1000000) { n       vector<complex<long double> > fa(l.a.begin(), l.a.end()), n           fb(r.a.begin(), r.a.end()); n       int n = 1; n       while (n < max(l.len(), r.len())) n <<= 1; n       n <<= 1; n       fa.resize(n), fb.resize(n); n       fft(fa, false), fft(fb, false); n       for (int i = 0; i < n; ++i) fa[i] *= fb[i]; n       fft(fa, true); n       ret.a.resize(n); n       for (int i = 0; i < n; ++i) ret.a[i] = int(fa[i].real() + 0.5); n       int carry = 0; n       for (int i = 0; i < n; ++i) { n         ret.a[i] += carry; n         carry = ret.a[i] / base; n         ret.a[i] %= base; n       } n     } else { n       ret.a.resize(l.len() + r.len()); n       for (int i = 0; i < l.len(); ++i) n         for (int j = 0, carry = 0; j < r.len() || carry; ++j) { n           long long cur = ret.a[i + j] + n                           (long long)l.a[i] * (j < r.len() ? r.a[j] : 0) + n                           carry; n           ret.a[i + j] = cur % base; n           carry = cur / base; n         } n     } n     while (ret.len() > 1 && !ret.a.back()) ret.a.pop_back(); n     return ret; n   } n   inline friend lnum operator/(const lnum &l, const int &r) { n     lnum ret(0, l.base); n     ret.a.resize(l.len()); n     int carry = 0; n     for (int i = l.len() - 1; i >= 0; --i) { n       long long cur = l.a[i] + (long long)carry * l.base; n       ret.a[i] = cur / r; n       carry = cur % r; n     } n     while (ret.len() > 1 && ret.a.back() == 0) ret.a.pop_back(); n     return ret; n   } n   inline friend bool operator<(const lnum &l, const lnum &r) { n     if (l.len() < r.len()) return true; n     if (l.len() > r.len()) return false; n     int n = l.len(); n     for (int i = n - 1; i >= 0; --i) { n       if (l.a[i] < r.a[i]) return true; n       if (l.a[i] > r.a[i]) return false; n     } n     return false; n   } n   inline friend bool operator>(const lnum &l, const lnum &r) { return r < l; } n   inline friend bool operator==(const lnum &l, const lnum &r) { n     if (l.len() != r.len()) return false; n     int n = l.len(); n     for (int i = n - 1; i; --i) { n       if (l.a[i] != r.a[i]) return false; n     } n     return true; n   } n   inline friend bool operator!=(const lnum &l, const lnum &r) { n     return !(l == r); n   } n   inline void print() { n     if (base == 1000000000) { n       printf( %d , a.back()); n       for (int i = a.size() - 2; i >= 0; --i) printf( %09d , a[i]); n     } else { n       for (int i = a.size() - 1; i >= 0; --i) printf( %d , a[i]); n     } n   } n }; n int main() { n   string s; n   cin >> s; n   int n = s.length(); n   int ans[n][n]; n   memset((ans), 0, sizeof(ans)); n   for (int i = 0; i < n; ++i) n     for (int j = i; j < n; ++j) n       for (int k = 0; k < (j - i + 1) / 2; ++k) n         if (s[i + k] != s[j - k]) ++ans[i][j]; n   int(k); n   input((k)); n   ; n   int dp[n + 1][k + 1]; n   int p[n + 1][k + 1]; n   for (int i = 0; i <= n; ++i) n     for (int j = 0; j <= k; ++j) dp[i][j] = 1e9; n   dp[0][0] = 0; n   for (int i = 0; i < n; ++i) n     for (int j = 1; j <= k; ++j) n       for (int l = 0; l <= i; ++l) n         if (dp[i + 1][j] > dp[l][j - 1] + ans[l][i]) { n           dp[i + 1][j] = dp[l][j - 1] + ans[l][i]; n           p[i + 1][j] = l; n         } n   int best = 1; n   for (int i = 1; i <= k; ++i) n     if (dp[n][i] < dp[n][best]) best = i; n   cout << dp[n][best] << endl; n   vector<string> t; n   int cur = n; n   while (best) { n     t.push_back(s.substr(p[cur][best], cur - p[cur][best])); n     cur = p[cur][best]; n     --best; n   } n   reverse((t).begin(), (t).end()); n   for (int i = 0; i < t.size(); ++i) { n     if (i) cout <<  + ; n     for (int j = 0; j < t[i].length(); ++j) n       if (t[i][j] != t[i][t[i].length() - 1 - j]) n         t[i][j] = t[i][t[i].length() - 1 - j]; n     cout << t[i]; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n int n, m; n int cnt1[N], cnt2[N]; n struct Fenwick_tree { n   vector<long long> t; n   int n; n   void init(int _n) { n     n = _n; n     t.assign(n + 1, 0); n   } n   void add(int r, int x) { n     for (; r <= n; r = (r | (r + 1))) t[r] += 1LL * x; n   } n   long long get_sum(int r) { n     long long res = 0LL; n     for (; r >= 0; r = (r & (r + 1)) - 1) res += t[r]; n     return res; n   } n   long long get_sum(int l, int r) { n     if (r < l) return 0LL; n     return get_sum(r) - get_sum(l - 1); n   } n }; n Fenwick_tree t1, t2; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> m; n   t1.init(n); n   t2.init(n); n   long long free = 1LL * n * n; n   for (int i = 0; i < m; ++i) { n     int x, y; n     cin >> x >> y; n     if (cnt2[y] == 0) n       free -= (n - 1 - t1.get_sum(1, x - 1) - t1.get_sum(x + 1, n)); n     if (cnt1[x] == 0) n       free -= (n - 1 - t2.get_sum(1, y - 1) - t2.get_sum(y + 1, n)); n     if (cnt1[x] == 0 && cnt2[y] == 0) free--; n     cnt1[x] = cnt2[y] = true; n     if (t1.get_sum(x, x) == 0) t1.add(x, 1); n     if (t2.get_sum(y, y) == 0) t2.add(y, 1); n     cout << free <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int NMAX = 200010, ALPHA = 30; n int N; n long long Sum[ALPHA]; n double Ans; n char A[NMAX], B[NMAX]; n int main() { n   scanf( %i n , &N); n   gets(A + 1); n   gets(B + 1); n   long long Posib = (1LL * N * (N + 1) * (2 * N + 1)) / 6; n   for (int i = N; i; --i) { n     int C = B[i] -  A  + 1; n     Sum[C] += N - i + 1; n     C = A[i] -  A  + 1; n     Ans += (1LL * i * Sum[C]) / (1.0 * Posib); n   } n   for (int i = 0; i < ALPHA; ++i) Sum[i] = 0; n   for (int i = N; i; --i) { n     int C = B[i] -  A  + 1; n     Ans += (1LL * i * Sum[C]) / (1.0 * Posib); n     C = A[i] -  A  + 1; n     Sum[C] += N - i + 1; n   } n   printf( %.9f n , 1.0 * Ans); n } n


#include <bits/stdc++.h> n using namespace std; n struct EDGE { n   int to, next, w; n } e[400010]; n int head[200010], top; n void add(int u, int v, int w) { n   e[top].to = v; n   e[top].next = head[u]; n   e[top].w = w; n   head[u] = top++; n } n vector<int> vv; n int vis[200010], tmpp = -1; n long long in_max; n int fa[200010], id[400010]; n long long dep[200010]; n long long l[400010], r[400010], wl[400010], idtop, val[400010]; n vector<int> o; n void dfs(int x, int fa) { n   if (vis[x]) { n     tmpp = x; n     throw  w23c3c3 ; n   } n   vis[x] = 1; n   vv.push_back(x); n   int i; n   for (i = head[x]; ~i; i = e[i].next) { n     if (e[i].to == fa) continue; n     o.push_back(e[i].w); n     dfs(e[i].to, x); n     o.pop_back(); n   } n   vv.pop_back(); n } n void dfs1(int x) { n   int i; n   long long max_ = 0, se = 0, tmp; n   for (i = head[x]; ~i; i = e[i].next) { n     if (vis[e[i].to] || e[i].to == fa[x]) continue; n     fa[e[i].to] = x; n     dfs1(e[i].to); n     tmp = dep[e[i].to] + e[i].w; n     if (tmp > max_) { n       se = max_; n       max_ = tmp; n     } else { n       if (tmp > se) { n         se = tmp; n       } n     } n   } n   in_max = max(in_max, max_ + se); n   dep[x] = max_; n } n struct __ { n   int id; n   long long val; n   bool operator<(const __ &ob) const { n     if (val != ob.val) return val > ob.val; n     return id < ob.id; n   } n }; n multiset<__> L, R; n int main() { n   memset(head, 255, sizeof(head)); n   int n; n   scanf( %d , &n); n   int i; n   int u, v, w; n   for (i = 1; i <= n; i++) { n     scanf( %d%d%d , &u, &v, &w); n     add(u, v, w); n     add(v, u, w); n   } n   int tmp; n   try { n     dfs(1, 0); n   } catch (...) { n   } n   tmp = tmpp; n   memset(vis, 0, sizeof(vis)); n   int len = 1; n   wl[idtop] = o.back(); n   o.pop_back(); n   id[idtop++] = tmp; n   vis[tmp] = 1; n   while (1) { n     if (vv.back() == tmp) break; n     len++; n     wl[idtop] = o.back(); n     o.pop_back(); n     id[idtop++] = vv.back(); n     vv.pop_back(); n     vis[id[idtop - 1]] = 1; n   } n   vv.clear(); n   for (i = 1; i <= n; i++) { n     if (vis[i]) { n       dfs1(i); n     } n   } n   for (i = 0; i < len; i++) { n     val[i] = dep[id[i]]; n   } n   for (i = 0; i < len; i++) { n     id[i + len] = id[i]; n     wl[i + len] = wl[i]; n     val[i + len] = val[i]; n   } n   l[0] = r[0] = val[0]; n   for (i = 1; i < (len << 1) - 1; i++) { n     l[i] = l[i - 1] - val[i - 1] - wl[i - 1] + val[i]; n     r[i] = r[i - 1] - val[i - 1] + wl[i - 1] + val[i]; n   } n   long long ans = 998244353998244347; n   for (i = 0; i < len - 1; i++) { n     L.insert((__){id[i], l[i]}); n     R.insert((__){id[i], r[i]}); n   } n   __ tmpl1, tmpl2, tmpr1, tmpr2; n   for (i = len - 1; i + 1 < len << 1; i++) { n     L.insert((__){id[i], l[i]}); n     R.insert((__){id[i], r[i]}); n     tmpl1 = *L.begin(); n     tmpl2 = *++L.begin(); n     tmpr1 = *R.begin(); n     tmpr2 = *++R.begin(); n     if (tmpl1.id != tmpr1.id) { n       ans = min(ans, max(in_max, tmpl1.val + tmpr1.val)); n     } else { n       ans = min(ans, n                 max(in_max, max(tmpl1.val + tmpr2.val, tmpl2.val + tmpr1.val))); n     } n     L.erase(L.lower_bound((__){id[i - (len - 1)], l[i - (len - 1)]})); n     R.erase(R.lower_bound((__){id[i - (len - 1)], r[i - (len - 1)]})); n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long v[2][200005]; n long long c[2][200005]; n int n, k, a, b, q, e, day, ord; n const int maxn = 200005; n void add(int i, int value, int z) { n   for (; i < maxn; i += (i + 1) & -(i + 1)) v[z][i] += value; n } n long long get(int i, int z) { n   long long res = 0; n   for (; i >= 0; i -= (i + 1) & -(i + 1)) res += v[z][i]; n   return res; n } n long long g = 0; n int main() { n   scanf( %d%d%d%d%d , &n, &k, &a, &b, &q); n   while (q--) { n     scanf( %d , &e); n     if (e == 1) { n       scanf( %d %d , &day, &ord); n       long long ord1 = ord, ord2 = ord; n       if (c[0][day] <= b) { n         long long need = (long long)b - c[0][day]; n         if (need <= ord1) { n           ord1 = need; n           c[0][day] = b; n         } else n           c[0][day] += (long long)ord1; n         add(day, ord1, 0); n       } n       if (c[1][day] <= a) { n         long long need = (long long)a - c[1][day]; n         if (need <= ord2) { n           ord2 = need; n           c[1][day] = a; n         } else n           c[1][day] += ord2; n         add(day, ord2, 1); n       } n     } else { n       scanf( %d , &day); n       g = 0; n       if (day - 1) g = get(day - 1, 0); n       g += (long long)(get(200004, 1) - get(day + k - 1, 1)); n       printf( %I64d n , g); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1 << 18; n const int inf = 1e9; n int a[N], b[N], c[N], d[N]; n int dp[19][N]; n bool pr[19][N]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     b[i] = (a[i] % N + N) % N; n   } n   dp[0][0] = 0; n   for (int i = 1; i <= 18; i++) { n     int mod = 1 << i, _mod = 1 << i - 1; n     for (int j = 1; j <= n; j++) { n       c[j] = b[j] % mod; n       d[j] = b[j] % _mod; n     } n     int L = _mod, R = -1; n     for (int j = 1; j <= n; j++) n       if (d[j] != c[j]) L = min(L, d[j]); n     for (int j = 1; j <= n; j++) n       if (d[j] == c[j]) R = max(R, d[j]); n     for (int s = 0; s < mod; s++) dp[i][s] = inf, pr[i][s] = 1; n     for (int s = 0; s < _mod; s++) { n       if (dp[i - 1][s] < inf) { n         for (int j = 0; j < 2; j++) { n           int t = s + (_mod * j); n           if (dp[i - 1][s] + 1 < dp[i][t]) { n             dp[i][t] = dp[i - 1][s] + 1; n           } n           if (s == 0) { n             if (j == 0 && L == _mod) { n               if (dp[i - 1][s] < dp[i][t]) { n                 dp[i][t] = dp[i - 1][s]; n                 pr[i][t] = 0; n               } n             } n           } else if (R < s && s <= L) { n             if (j) { n               if (dp[i - 1][s] < dp[i][t]) { n                 dp[i][t] = dp[i - 1][s]; n                 pr[i][t] = 0; n               } n             } n           } n         } n       } n     } n   } n   int L = 1 << 18, R = -1; n   for (int i = 1; i <= n; i++) { n     if (a[i] < 0) n       L = min(L, b[i]); n     else n       R = max(R, b[i]); n   } n   int s = -1; n   for (int t = 0; t < 1 << 18; t++) { n     if (t == 0 && L != (1 << 18)) continue; n     if (t && t > L) continue; n     if (t && t <= R) continue; n     if (s == -1 || dp[18][t] < dp[18][s]) s = t; n   } n   int ret = dp[18][s]; n   vector<int> ans; n   for (int i = 18; i > 0; i--) { n     int x = 1 << i - 1; n     if (s && s <= x) { n       ans.push_back(-x); n     } else { n       if (pr[i][s]) ans.push_back(x); n     } n     s %= x; n   } n   assert(ans.size() == ret); n   reverse(ans.begin(), ans.end()); n   cout << ans.size() << endl; n   for (int x : ans) printf( %d  , x); n   puts(  ); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n string s; n int main() { n   cin >> s; n   long long n = s.size(); n   long long b = n / 2; n   if (n % 2) { n     while (1) { n       if (s[b] ==  A ) break; n       if (s[b] ==  H ) break; n       if (s[b] ==  I ) break; n       if (s[b] ==  M ) break; n       if (s[b] ==  U ) break; n       if (s[b] ==  T ) break; n       if (s[b] ==  O ) break; n       if (s[b] ==  I ) break; n       if (s[b] ==  W ) break; n       if (s[b] ==  V ) break; n       if (s[b] ==  Y ) break; n       if (s[b] ==  X ) break; n       cout <<  NO  << endl; n       return 0; n     } n   } n   for (int i = 0; i < n; i++) { n     if (s[i] ==  A ) { n       continue; n     } else if (s[i] ==  W ) { n       continue; n     } else if (s[i] ==  T ) { n       continue; n     } else if (s[i] ==  Y ) { n       continue; n     } else if (s[i] ==  U ) { n       continue; n     } else if (s[i] ==  I ) { n       continue; n     } else if (s[i] ==  O ) { n       continue; n     } else if (s[i] ==  H ) { n       continue; n     } else if (s[i] ==  X ) { n       continue; n     } else if (s[i] ==  V ) { n       continue; n     } else if (s[i] ==  M ) { n       continue; n     } else { n       cout <<  NO  << endl; n       return 0; n     } n   } n   for (int i = 0; i < n / 2; i++) { n     if (s[i] != s[n - i - 1]) { n       cout <<  NO  << endl; n       return 0; n     } n   } n   cout <<  YES  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100000; n long long n, ans; n int main() { n   while (~scanf( %lld , &n)) { n     n--; n     int l = 0; n     for (int i = 0; i < 50; i++) n       if ((1ll << i) & n) l = i; n     ans = n / 2 + n % 2; n     int f = l; n     for (; f > 0; f--) { n       if ((1ll << f) & n) { n         int k = f; n         ans += (1ll << f); n         for (int i = 1; i < k; i++) { n           ans += (1ll << i) * (1ll << (k - 1 - i)); n         } n       } n     } n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, ans = 0; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) { n       int x; n       cin >> x; n       if (i == j || (i + j) == (n + 1) || i == (n + 1) / 2 || j == (n + 1) / 2) n         ans += x; n     } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 105; n int M127; n string s; n int S, k, n; n int e[N][N]; n int f[N][N][N]; n int conv(char c) { return c -  a  + 1; } n int main() { n   cin >> s; n   S = s.size(); n   s =     + s; n   memset(f, -127, sizeof(f)); n   M127 = f[0][0][0]; n   k = ({ n     long long first = 0; n     int c = getchar(), n = 0; n     for (; !isdigit(c); c = getchar()) n = (c ==  - ); n     for (; isdigit(c); c = getchar()) first = first * 10 + c -  0 ; n     n ? -first : first; n   }); n   n = ({ n     long long first = 0; n     int c = getchar(), n = 0; n     for (; !isdigit(c); c = getchar()) n = (c ==  - ); n     for (; isdigit(c); c = getchar()) first = first * 10 + c -  0 ; n     n ? -first : first; n   }); n   for (int i(1); i <= n; i++) n     e[conv(({ n       char c = getchar(); n       while (c ==     || c ==   n ) c = getchar(); n       c; n     }))][conv(({ n       char c = getchar(); n       while (c ==     || c ==   n ) c = getchar(); n       c; n     }))] = ({ n       long long first = 0; n       int c = getchar(), n = 0; n       for (; !isdigit(c); c = getchar()) n = (c ==  - ); n       for (; isdigit(c); c = getchar()) first = first * 10 + c -  0 ; n       n ? -first : first; n     }); n   for (int i(1); i <= 26; i++) f[1][i][i != conv(s[1])] = 0; n   for (int i(2); i <= S; i++) n     for (int j(1); j <= 26; j++) n       for (int kk(0); kk <= k; kk++) { n         int ok = j != conv(s[i]); n         if (kk < ok) continue; n         for (int j2(1); j2 <= 26; j2++) n           if (f[i - 1][j2][kk - ok] != M127) n             f[i][j][kk] = max(f[i - 1][j2][kk - ok] + e[j2][j], f[i][j][kk]); n       } n   int res = M127; n   for (int j(1); j <= 26; j++) n     for (int kk(0); kk <= k; kk++) res = max(res, f[S][j][kk]); n   cout << res; n } n


#include <bits/stdc++.h> n using namespace std; n long long int MOD = 1000000007; n void solve() { n   int p, f; n   cin >> p >> f; n   if (f > p) swap(p, f); n   int cs, cw; n   cin >> cs >> cw; n   int s, w; n   cin >> s >> w; n   if (w > s) { n     swap(w, s); n     swap(cs, cw); n   } n   int maxv = 0; n   for (int x = 0; x <= min(cw, f / w); x++) { n     int curr = x; n     int fr = f - x * w; n     int pr = p; n     int csr = cs; n     int cwr = cw - x; n     int t = min(csr, fr / s); n     curr += t; n     csr -= t; n     curr += min(cwr, pr / w); n     pr -= min(cwr, pr / w) * w; n     curr += min(csr, pr / s); n     maxv = max(maxv, curr); n   } n   cout << maxv << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int tt = 1; n   cin >> tt; n   for (int ttt = 1; ttt <= tt; ttt++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t, n, m, l, a[100001], i, check, p, d; n bool b[100001]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m >> l; n   t = 0; n   fill(b + 1, b + 1 + n, false); n   for (i = 1; i <= n; i++) { n     cin >> a[i]; n     if (a[i] > l) { n       if (i - 1 == 0 || (i - 1 > 0 && b[i - 1] == false)) t++; n       b[i] = true; n     } n   } n   for (i = 1; i <= m; i++) { n     cin >> check; n     if (check == 0) n       cout << t <<   n ; n     else { n       cin >> p >> d; n       a[p] += d; n       if (a[p] > l && b[p] == false) { n         if (p > 1 && p < n) { n           if (b[p - 1] == true && b[p + 1] == true) { n             if (t > 1) t--; n           } else if (b[p - 1] == false && b[p + 1] == false) { n             if (t < n) t++; n           } n         } else if (p == 1) { n           if (b[p + 1] == false) { n             if (t < n) t++; n           } n         } else if (p == n) { n           if (b[p - 1] == false) { n             if (t < n) t++; n           } n         } n         b[p] = true; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n const double eps = 1e-6; n vector<int> mp[105], ans; n char s[105][105]; n int len[105], tmp[30]; n queue<int> q; n bool solve(int x, int y) { n   for (int i = 0; i < len[x] && i < len[y]; i++) { n     if (s[x][i] != s[y][i]) { n       mp[s[x][i] -  a ].push_back(s[y][i] -  a ); n       tmp[s[y][i] -  a ]++; n       return true; n     } n   } n   if (len[x] > len[y]) return false; n } n bool ok() { n   for (int i = 0; i < 26; i++) n     if (tmp[i] == 0) { n       ans.push_back(i); n       q.push(i); n     } n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (int i = 0; i < mp[u].size(); i++) { n       int v = mp[u][i]; n       tmp[v]--; n       if (tmp[v] == 0) { n         q.push(v); n         ans.push_back(v); n       } n     } n   } n   return ans.size() == 26; n } n int main() { n   int n; n   while (~scanf( %d , &n)) { n     for (int i = 1; i <= n; i++) { n       scanf( %s , s[i]); n       len[i] = strlen(s[i]); n     } n     bool flag = 0; n     for (int i = 1; i <= n; i++) n       for (int j = i + 1; j <= n; j++) n         if (!solve(i, j)) flag = 1; n     if ((!flag) && ok()) { n       for (int i = 0; i < 26; i++) printf( %c , ans[i] +  a ); n       printf(  n ); n     } else n       printf( Impossible n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double a, b, c, delta, x1, x2; n   cin >> a >> b >> c; n   delta = b * b - 4.0 * a * c; n   delta = sqrt(delta); n   x1 = (-b + delta) / (2.0 * a); n   x2 = (-b - delta) / (2.0 * a); n   if (x1 < x2) swap(x1, x2); n   cout << fixed << setprecision(8) << x1 << endl n        << fixed << setprecision(8) << x2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n unsigned long long gcd(unsigned long long a, unsigned long long b) { n   if (b == 0) { n     return a; n   } n   return gcd(b, a % b); n } n int main() { n   unsigned long long n, m, k; n   cin >> n >> m >> k; n   unsigned long long h = 2 * n * m; n   if (h % k == 0) { n     cout <<  YES  << endl; n     bool isKEven = false; n     if (k % 2 == 0) { n       isKEven = true; n       k /= 2; n     } n     int y1 = 0, x2 = 0, x3 = 0, y3 = 0; n     unsigned long long gx = gcd(n, k); n     k /= gx; n     unsigned long long x1 = n / gx; n     unsigned long long gy = gcd(m, k); n     k /= gy; n     unsigned long long y2 = m / gy; n     if (!isKEven) { n       if (x1 < n) { n         x1 *= 2; n       } else { n         y2 *= 2; n       } n     } n     cout << x1 <<     << y1 << endl; n     cout << x2 <<     << y2 << endl; n     cout << x3 <<     << y3 << endl; n   } else { n     cout <<  NO ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   int c[n]; n   memset(c, 0, sizeof(c)); n   while (m--) { n     int x, y = 0, p = 0; n     for (int i = 0; i < n; i++) { n       scanf( %d , &x); n       if (x > y) { n         y = x; n         p = i; n       } n     } n     c[p]++; n   } n   int y = 0, p; n   for (int i = 0; i < n; i++) { n     if (c[i] > y) { n       y = c[i]; n       p = i; n     } n   } n   printf( %d , p + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp(int a, int b, int row) { n   if (row == 1 && a < 3 && b >= 3) { n     return -1; n   } n   if (row == 0 && a < 3 && b >= 3) { n     return 0; n   } n   if (row == 1 && a < 3 && b < 3) { n     return 1; n   } n   if (row == 0 && a < 3 && b < 3) { n     return 0; n   } n   if (row == 1 && a >= 3 && b >= 3) { n     return 0; n   } n   if (row == 0 && a >= 3 && b >= 3) { n     return 1; n   } n   if (row == 1 && a >= 3 && b < 3) { n     return 1; n   } n   if (row == 0 && a >= 3 && b < 3) { n     return -1; n   } else { n     return -1; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     string arr, brr; n     cin >> arr; n     cin >> brr; n     int x = dp(arr[0] -  0 , brr[0] -  0 , 0); n     for (int i = 1; i < n; i++) { n       x = dp(arr[i] -  0 , brr[i] -  0 , x); n       if (x == -1) { n         break; n       } n     } n     if (x != 1) { n       cout <<  NO  <<   n ; n     } else { n       cout <<  YES  <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1 << 30; n const long long linf = 1LL << 62; n const int mod = 1e9 + 7; n const int MAX = 510000; n const int V = 100005; n struct UnionFind { n   vector<long long> p; n   vector<long long> rank; n   vector<long long> cnt; n   UnionFind(long long n) { n     rank.resize(n, 0); n     p.resize(n, 0); n     cnt.resize(n, 1); n     for (long long i = 0; i < (n); i++) { n       p[i] = i; n       rank[i] = 0; n       cnt[i] = 1; n     } n   } n   long long find(long long x) { n     if (x != p[x]) p[x] = find(p[x]); n     return p[x]; n   } n   bool same(long long x, long long y) { return find(x) == find(y); } n   void unite(long long x, long long y) { n     x = find(x); n     y = find(y); n     if (x == y) return; n     if (rank[x] > rank[y]) { n       p[y] = x; n       cnt[x] += cnt[y]; n     } else { n       p[x] = y; n       cnt[y] += cnt[x]; n       if (rank[x] == rank[y]) rank[y]++; n     } n   } n   long long getcnt(long long x) { return cnt[find(x)]; } n }; n int main() { n   long long q; n   cin >> q; n   while (q--) { n     long long n; n     cin >> n; n     UnionFind uf(n); n     for (long long i = 0; i < (n); i++) { n       long long a; n       cin >> a; n       a--; n       uf.unite(i, a); n     } n     for (long long i = 0; i < (n); i++) cout << uf.getcnt(i) <<    ; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int fx[] = {+1, -1, +0, +0}, fy[] = {+0, +0, +1, -1}; n const long long mod = 1e9 + 7, INF = 1e18, mx = 1e6; n int Case = 1, cas = 0; n string S; n struct exo { n   int Open, Close, SubLen; n   exo() {} n   exo(int a, int b, int c) { Open = a, Close = b, SubLen = c; } n } tree[3 * mx + 5]; n exo Combine(exo p, exo q) { n   int mn = min(p.Open, q.Close); n   int a = p.Open + q.Open - mn; n   int b = p.Close + q.Close - mn; n   int c = p.SubLen + q.SubLen + 2 * mn; n   return exo(a, b, c); n } n void build(int node, int L, int R) { n   if (L > R) return; n   if (L == R) { n     if (S[L] ==  ( ) n       tree[node] = exo(1, 0, 0); n     else n       tree[node] = exo(0, 1, 0); n     return; n   } n   int mid = (L + R) >> 1; n   int Left = node << 1; n   int Right = Left | 1; n   build(Left, L, mid); n   build(Right, mid + 1, R); n   tree[node] = Combine(tree[Left], tree[Right]); n } n exo query(int node, int L, int R, int i, int j) { n   if (i > R || j < L) return exo(0, 0, 0); n   if (i <= L && R <= j) return tree[node]; n   int mid = (L + R) >> 1; n   int Left = node << 1; n   int Right = Left | 1; n   exo p = query(Left, L, mid, i, j); n   exo q = query(Right, mid + 1, R, i, j); n   return Combine(p, q); n } n int main() { n   ios_base ::sync_with_stdio(0), cin.tie(0); n   ; n   cin >> S; n   int n = S.size(); n   build(1, 0, n - 1); n   int Q; n   cin >> Q; n   while (Q--) { n     int L, R; n     cin >> L >> R; n     L--, R--; n     cout << query(1, 0, n - 1, L, R).SubLen << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, ans; n vector<int> v[100010]; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= m; ++i) { n     int x, y; n     scanf( %d%d , &x, &y); n     v[x].push_back(y); n     v[y].push_back(x); n   } n   for (int i = 1; i <= n; ++i) ans += v[i].size() % 2; n   ans /= 2; n   for (int i = 1; i <= n; ++i) { n     if (v[i].size() != 2) continue; n     int x = v[i][0], y = v[i][1]; n     if (x == y) { n       v[x].clear(); n       ++ans; n       continue; n     } n     v[x][v[x][1] == i] = y; n     v[y][v[y][1] == i] = x; n   } n   cout << ans <<     << m << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s =   , s1 =   , tmp; n   cin >> tmp; n   s += tmp; n   cin >> tmp; n   reverse(tmp.begin(), tmp.end()); n   s += tmp; n   cin >> tmp; n   s1 += tmp; n   cin >> tmp; n   reverse(tmp.begin(), tmp.end()); n   s1 += tmp; n   s.erase(s.find( X ), 1); n   s1.erase(s1.find( X ), 1); n   s += s; n   int i = 0; n   while (s[i] != s1[0]) i++; n   if (s.substr(i, 3) == s1) { n     cout <<  YES  << endl; n   } else { n     cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 150001; n int t[MAX_N]; n int main() { n   int n, k, q; n   cin >> n >> k >> q; n   for (int i = 0; i < n; ++i) { n     cin >> t[i]; n   } n   set<int> s; n   for (int i = 0; i < q; ++i) { n     int x, y; n     cin >> x >> y; n     if (x == 1) { n       s.insert(-t[y - 1]); n       if (s.size() > k) { n         auto it = s.begin(); n         for (int j = 0; j < k; ++j) it++; n         s.erase(it); n       } n     } else { n       cout << (s.find(-t[y - 1]) == s.end() ?  NO  :  YES ) << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int v, w; n } a[100005]; n bool cmp(node a, node b) { return a.v > b.v; } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d%d , &a[i].v, &a[i].w); n   sort(a, a + n, cmp); n   int ma = a[0].w; n   for (int i = 1; i < n; i++) { n     if (a[i].w > ma) { n       printf( Happy Alex n ); n       return 0; n     } n     ma = min(ma, a[i].w); n   } n   printf( Poor Alex n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long ll(long double x) { return x; } n int main() { n   int n; n   cin >> n; n   while (n--) { n     long long a, b; n     cin >> a >> b; n     if (ceil((2 * a - b) / 3.0) == floor((2 * a - b) / 3.0) and n         ceil((2 * b - a) / 3.0) == floor((2 * b - a) / 3.0) and n         ceil((2 * b - a) / 3.0) >= 0 and ((2 * a - b) / 3.0) >= 0) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool SR(int &x) { return scanf( %d , &x) == 1; } n bool SR(long long &x) { return scanf( %lld , &x) == 1; } n bool SR(double &x) { return scanf( %lf , &x) == 1; } n bool SR(char *s) { return scanf( %s , s) == 1; } n bool RI() { return true; } n template <typename I, typename... T> n bool RI(I &x, T &...tail) { n   return SR(x) && RI(tail...); n } n void SP(const int x) { printf( %d , x); } n void SP(const long long x) { printf( %lld , x); } n void SP(const double x) { printf( %.16lf , x); } n void SP(const char *s) { printf( %s , s); } n void PL() { puts(  ); } n template <typename I, typename... T> n void PL(const I x, const T... tail) { n   SP(x); n   if (sizeof...(tail)) putchar(   ); n   PL(tail...); n } n const int maxn = 1e2 + 2; n vector<bool> a[maxn]; n int n, m, k; n void read() { n   RI(n, m, k); n   for (int i = 0; i < int(n); i++) a[i].resize(m); n   for (int i = 0; i < int(n); i++) n     for (int j = 0; j < int(m); j++) { n       int x; n       RI(x); n       a[i][j] = (x == 1); n     } n } n void build() {} n int doo(const vector<bool> &v) { n   int ans = 0; n   for (int i = 0; i < int(n); i++) { n     int c[2] = {0, 0}; n     for (int j = 0; j < int(m); j++) c[v[j] ^ a[i][j]]++; n     ans += min(c[0], c[1]); n   } n   return ans; n } n void sol() { n   int ans = k + 1; n   if (n > 10) { n     for (int i = 0; i < int(n); i++) ans = min(ans, doo(a[i])); n   } else { n     vector<bool> c[maxn]; n     for (int i = 0; i < int(m); i++) c[i].resize(n); n     for (int i = 0; i < int(n); i++) n       for (int j = 0; j < int(m); j++) c[j][i] = a[i][j]; n     swap(n, m); n     for (int i = 0; i < int(n); i++) a[i] = c[i]; n     vector<bool> v(m); n     for (int i = 0; i < int((1 << m)); i++) { n       for (int j = 0; j < int(m); j++) v[j] = ((i >> j) & 1); n       ans = min(ans, doo(v)); n     } n   } n   if (ans <= k) n     PL(ans); n   else n     PL(-1); n } n int main() { n   read(); n   build(); n   sol(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int dx[] = {0, 0, 1, -1}; n const int dy[] = {1, -1, 0, 0}; n int s[505][505]; n queue<pair<int, int> > q; n char c[505][505]; n bitset<505> b[505]; n int main(void) { n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) cin >> (c[i] + 1); n   int x1, y1, first, second; n   cin >> first >> second >> x1 >> y1; n   s[first][second] = 1; n   q.push(make_pair(first, second)); n   while (q.size()) { n     int k = q.front().first, l = q.front().second; n     q.pop(); n     for (int p = 0; p < 4; ++p) { n       int f = k + dx[p]; n       int g = l + dy[p]; n       if ((c[f][g] ==  . ) && !s[f][g]) n         s[f][g] = s[k][l] + 1, q.push(make_pair(f, g)); n     } n   } n   int p = 0, g = 0; n   for (int l = 0; l < 4; ++l) n     p += c[x1 + dx[l]][y1 + dy[l]] ==  . , g |= s[x1 + dx[l]][y1 + dy[l]]; n   if (c[x1][y1] ==  X ) return cout << (g ?  YES  :  NO ) <<   n , 0; n   if (!s[x1][y1]) return cout <<  NO n , 0; n   if (p > 1 || (abs(first - x1) + abs(second - y1) == 1 && p >= 1)) n     return cout <<  YES n , 0; n   return cout <<  NO n , 0; n } n


#include <bits/stdc++.h> n using ll = long long; n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int t, n, x; n   cin >> t; n   int sum = 0; n   int cnt = 0; n   int item = 0; n   int s = 0; n   while (t--) { n     cin >> n >> x; n     cnt = 0; n     s = 0; n     for (int i = 0; i < n; ++i) { n       cin >> item; n       if (item == x) { n         ++cnt; n       } n       s += item; n       sum += (x - item); n     } n     if (cnt == n) { n       cout << 0 <<   n ; n     } else if (cnt > 0 or s == n * x or sum == 0) { n       cout << 1 <<   n ; n     } else { n       cout << 2 <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[9], aa[9]; n int c[9], cc[9]; n int n; n int ans; n void dfs(int u, int cnt, int self) { n   if (u == n) { n     ans = min(ans, cnt + (self > 1)); n     return; n   } n   dfs(u + 1, cnt + cc[u] + (c[u] != 1), self + 1); n   for (int i = u + 1; i < n; i++) n     if (aa[i] % a[u] == 0) { n       aa[i] /= a[u]; n       cc[i] -= c[u]; n       dfs(u + 1, cnt + cc[u] + (c[u] != 1), self); n       aa[i] *= a[u]; n       cc[i] += c[u]; n     } n } n int main() { n   int i, j; n   scanf( %d , &n); n   for (i = 0; i < n; i++) scanf( %I64d , &a[i]); n   sort(a, a + n); n   for (i = 0; i < n; i++) { n     long long x = a[i]; n     long long m = sqrt(x + 0.5); n     for (j = 2; j <= m; j++) n       while (x % j == 0) { n         c[i]++; n         x /= j; n       } n     if (x > 1) c[i]++; n     aa[i] = a[i]; n     cc[i] = c[i]; n   } n   ans = 1e9; n   dfs(0, 0, 0); n   printf( %d n , ans); n   return 0; n } n


#include<bits/stdc++.h> n #define pii pair<int,int> n #define fi first n #define sc second n #define pb push_back n #define ll long long n #define trav(v,x) for(auto v:x) n using namespace std; n const int N = 1e6 + 100; n const ll mod = 998244353; n  n int n, m, need; n int sa[N], rnk[N]; n ll fac[N], ifac[N]; n  n ll C(ll x, ll y) n {return 1LL * fac[x] * ifac[y] % mod * ifac[x - y] % mod;} n  n ll qpow(ll x, ll y = mod - 2) n { n     ll res = 1; n     while(y) n     { n         if(y & 1)res = res * x % mod; n         x = x * x % mod, y >>= 1; n     } n     return res; n } n  n signed main() n { n  ios::sync_with_stdio(0); n  cin.tie(0); n  cin >> n >> m; n  for(int i = 1; i <= n; i++) n         cin >> sa[i], ++sa[i], rnk[sa[i]] = i; n     need = 1; n     sa[n + 1] = 0; n     for(int i = 2; i <= n; i++) n     { n         int bf_ps = sa[i - 1], nw_ps = sa[i]; n         if(rnk[bf_ps + 1] < rnk[nw_ps + 1]); n         else ++need; n     } n     m -= need; n  //   cerr << !!  << m <<   n ; n     ll ans = 0; n     fac[0] = 1; n     for(int i = 1; i < N; i++)fac[i] = fac[i - 1] * i % mod; n     ifac[N - 1] = qpow(fac[N - 1]); n     for(int i = N - 2; i >= 0; i--)ifac[i] = ifac[i + 1] * (i + 1) % mod; n     for(ll x = 0; x <= m; x++) n         ans = (ans + C(x + n - 1, n - 1)) % mod; n     cout << ans  <<   n ; n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long g(long long n, long long m) { n   long long ans = 0; n   for (long long x = 1; x <= n; x++) { n     long long minY = 5 - (x % 5); n     if (minY <= m) ans += (m - minY) / 5 + 1; n   } n   return ans; n } n long long gs(long long n, long long m) { n   long long ans = 0; n   for (long long x = 1; x <= n; x++) { n     for (long long y = 1; y <= m; y++) { n       if ((x + y) % 5 == 0) ans++; n     } n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   long long n, m; n   cin >> n >> m; n   cout << g(n, m) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 101; n int N, Q, freq[11]; n char commands[MAXN], commands2[MAXN]; n void solve(int l, int r) { n   l--; n   r--; n   for (int i = 0; i < N; i++) commands2[i] = commands[i]; n   for (int i = 0; i < 10; i++) freq[i] = 0; n   int cur = l; n   int dir = 1; n   int prev; n   while (cur >= l && cur <= r) { n     if (commands2[cur] == 0) n       cur += dir; n     else if (commands2[cur] ==  > ) { n       prev = cur; n       dir = 1; n       cur += dir; n       while (cur >= l && cur <= r && commands2[cur] == 0) cur += dir; n       if (cur < l || cur > r) break; n       if (commands2[cur] ==  <  || commands2[cur] ==  > ) commands2[prev] = 0; n     } else if (commands2[cur] ==  < ) { n       prev = cur; n       dir = -1; n       cur += dir; n       while (cur >= l && cur <= r && commands2[cur] == 0) cur += dir; n       if (cur < l || cur > r) break; n       if (commands2[cur] ==  <  || commands2[cur] ==  > ) commands2[prev] = 0; n     } else { n       freq[commands2[cur] -  0 ]++; n       commands2[cur]--; n       if (commands2[cur] <  0 ) commands2[cur] = 0; n       cur += dir; n     } n   } n   for (int i = 0; i < 10; i++) { n     printf( %d , freq[i]); n     if (i == 9) n       printf(  n ); n     else n       printf(   ); n   } n } n int main() { n   scanf( %d %d , &N, &Q); n   scanf( %s , commands); n   for (int i = 0; i < Q; i++) { n     int L, R; n     scanf( %d %d , &L, &R); n     solve(L, R); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100; n int n, x, a; n int f[MAXN + 1]; n int main() { n   cin >> n >> x; n   memset(f, 0, sizeof f); n   for (int i = 0; i < n; i++) { n     cin >> a; n     f[a] = 1; n   } n   int ans = 0; n   for (int i = 0; i < x; i++) { n     if (f[i] == 0) ans++; n   } n   if (f[x] == 1) ans++; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int maxx = 2e5 + 7; n const int maxn = 1e9 + 7; n using namespace std; n inline int read() { n   int s = 0, w = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) w = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar(); n   return s * w; n } n long long n, h, l, r; n int dp[2005][2005], a[2006]; n int check(int op) { n   if (op <= r && op >= l) n     return 1; n   else n     return 0; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n >> h >> l >> r; n   memset(dp, -1, sizeof dp); n   dp[0][0] = 0; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < h; j++) { n       if (dp[i - 1][(j - a[i] + h) % h] < 0 && n           dp[i - 1][(j - a[i] + 1 + h) % h] < 0) n         continue; n       dp[i][j] = max(dp[i - 1][(j - a[i] + h) % h], n                      dp[i - 1][(j - a[i] + 1 + h) % h]) + n                  check(j); n     } n   } n   int ans = 0; n   for (int i = 0; i < h; i++) { n     ans = max(ans, dp[n][i]); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int ma = 35; n int n, m, mat[ma][ma]; n int main() { n   int t; n   scanf( %d , &t); n   int ans, one, zero; n   int sum, temp; n   int l, r; n   while (t--) { n     scanf( %d%d , &n, &m); n     one = zero = 0; n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= m; j++) { n         scanf( %d , &mat[i][j]); n         if (mat[i][j]) n           one++; n         else n           zero++; n       } n     ans = min(zero, one); n     zero = one = sum = 0; n     if (m > n) { n       l = 1, r = m; n       while (1) { n         temp = one = zero = 0; n         while ((1 + temp <= n) && (l - temp >= 1)) { n           if (mat[1 + temp][l - temp]) n             one++; n           else n             zero++; n           temp++; n         } n         temp--; n         if ((1 + temp == n) && (l - temp == r)) break; n         temp = 0; n         while ((n - temp >= 1) && (r + temp <= m)) { n           if (mat[n - temp][r + temp]) n             one++; n           else n             zero++; n           temp++; n         } n         sum += min(zero, one); n         if ((l + 1) == r + temp - 1) break; n         l++, r--; n       } n     } else { n       l = 1, r = n; n       while (1) { n         temp = one = zero = 0; n         while (l - temp >= 1 && 1 + temp <= m) { n           if (mat[l - temp][1 + temp]) n             one++; n           else n             zero++; n           temp++; n         } n         temp--; n         if (l - temp == r && 1 + temp == m) break; n         temp = 0; n         while (r + temp <= n && m - temp >= 1) { n           if (mat[r + temp][m - temp]) n             one++; n           else n             zero++; n           temp++; n         } n         sum += min(zero, one); n         if (l + 1 == r + temp - 1) break; n         l++, r--; n       } n     } n     printf( %d n , min(ans, sum)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n int freq[26]; n int main() { n   string s; n   cin >> s; n   int mx = -1; n   char g = s[0]; n   for (int i = 0; i < s.size(); i++) { n     freq[s[i] -  a ]++; n     if (s[i] >= g) { n       mx = max(mx, freq[s[i] -  a ]); n       g = s[i]; n     } n   } n   string d(freq[g -  a ], g); n   cout << d << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-8; n const double pi = acos(-1); n const int inf = 0x3f3f3f3f; n const long long INF = 0x3f3f3f3f3f3f3f3f; n const int N = 2e5 + 5; n int n, m; n char a[N], b[N]; n void solve() { n   scanf( %d , &n); n   scanf( %s , a + 1); n   scanf( %s , b + 1); n   int res = 0; n   for (int i = 1; i <= n; ++i) { n     if (b[i] ==  1 ) { n       if (a[i] ==  0  || a[i - 1] ==  1 ) n         ++res; n       else if (a[i + 1] ==  1 ) { n         a[i + 1] =  * ; n         ++res; n       } n     } n   } n   printf( %d n , res); n } n int main() { n   int t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int p, x, y; n queue<int> q; n int mmap[100000]; n bool check(int s) { n   int i = s / 50 % 475; n   for (int j = 0; j < 25; ++j) { n     i = (i * 96 + 42) % 475; n     if (26 + i == p) return true; n   } n   mmap[s] = 1; n   return false; n } n int main() { n   cin >> p >> x >> y; n   q.push(0); n   while (!q.empty()) { n     int n = q.front(); n     q.pop(); n     int s = x + n * 100; n     while (s >= y) { n       if (mmap[s]) { n         s -= 50; n         continue; n       } n       if (check(s)) { n         cout << n << endl; n         return 0; n       } n       s -= 50; n     } n     q.push(n + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     string s; n     cin >> s; n     int left0 = 0; n     for (int i = 0; i < n; i++) { n       if (s[i] ==  0 ) { n         left0 = i + 1; n       } else { n         break; n       } n     } n     int right1 = 0; n     for (int i = n - 1; i >= 0; i--) { n       if (s[i] ==  1 ) { n         right1 = right1 + 1; n       } else { n         break; n       } n     } n     for (int i = 0; i < left0; i++) { n       cout << 0; n     } n     if (left0 + right1 == n - 1 && (left0 != 0 || right1 != 0)) { n       cout << s[left0]; n     } else if (left0 + right1 != n) { n       cout << 0; n     } n     for (int i = 0; i < right1; i++) { n       cout << 1; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct no { n   long long i, h, m; n }; n long long dp[40][40][40]; n char str[40]; n no pre[40][40][40]; n long long pw[19]; n vector<char> ans; n int main() { n   long long n; n   scanf( %lld , &n); n   scanf( %s , str + 1); n   pw[0] = 1; n   for (long long i = 1; i < 19; i++) pw[i] = pw[i - 1] * 10LL; n   for (long long i = 0; i < 40; i++) n     for (long long j = 0; j < 40; j++) n       for (long long k = 0; k < 40; k++) dp[i][j][k] = -9999999999999LL; n   dp[0][0][0] = 0; n   pre[0][0][0] = {-1, -1, -1}; n   for (long long i = 1; i <= 2 * n; i++) { n     for (long long h = 0; h <= n; h++) { n       for (long long m = 0; m <= n; m++) { n         if (h) { n           if (dp[i - 1][h - 1][m] + pw[n - h] * (str[i] -  0 ) > dp[i][h][m]) { n             dp[i][h][m] = dp[i - 1][h - 1][m] + pw[n - h] * (str[i] -  0 ); n             pre[i][h][m] = {i - 1, h - 1, m}; n           } n         } n         if (m) { n           if (dp[i - 1][h][m - 1] + pw[n - m] * (str[i] -  0 ) > dp[i][h][m]) { n             dp[i][h][m] = dp[i - 1][h][m - 1] + pw[n - m] * (str[i] -  0 ); n             pre[i][h][m] = {i - 1, h, m - 1}; n           } n         } n       } n     } n   } n   no check = {-1, -1, -1}; n   no tren = {2 * n, n, n}; n   no pred = pre[tren.i][tren.h][tren.m]; n   while (pred.i != -1) { n     if (tren.h == pred.h) n       ans.push_back( M ); n     else n       ans.push_back( H ); n     tren = pred; n     pred = pre[tren.i][tren.h][tren.m]; n   } n   reverse(ans.begin(), ans.end()); n   for (long long i = 0; i < ans.size(); i++) printf( %c , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n long long a[5005]; n void input() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     int x; n     scanf( %d , &x); n     a[i + 1] = a[i] + x; n   } n } n void solve() { n   long long outx, outy, outz, ans; n   ans = outx = outy = outz = 0; n   for (int i = 0; i <= n; i++) { n     long long z = a[i], lft = i; n     for (int j = i; j <= n; j++) { n       if (a[j] < z) { n         lft = j, z = a[j]; n       } n       if (a[i] - a[lft] + a[j] > ans) { n         ans = a[i] - a[lft] + a[j]; n         outx = i, outz = j, outy = lft; n       } n     } n   } n   printf( %lld %lld %lld , outx, outy, outz); n } n int main() { n   input(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char s[18]; n   for (int i = 1; i <= 8; i++) { n     cin >> s; n     bool p = false; n     for (int j = 1; j < 8; j++) n       if (s[j] == s[j - 1]) { n         p = true; n         break; n       } n     if (p) { n       cout <<  NO ; n       return 0; n     } n   } n   cout <<  YES ; n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n #define inf 1999999999999999999 n #define mod 1000000007 n #define lb lower_bound n #define ub upper_bound n #define pb push_back n #define pf push_front n #define bn binary_search n #define pq priority_queue n #define int long long n #define pii pair<int,int> n #define mii map<int,int> n #define umii unordered_map<int,int> n #define um unordered_map n #define vi vector<int> n #define mii map<int,int> n #define si set<int> n #define ft first n #define sc second n #define gcd(a,b) __gcd(a,b) n #define lcm(a,b) a*(b/gcd(a,b)) n #define bp(a) __builtin_popcountll(a) n #define mmst(a,b) memset(a,b,sizeof(a)) n #define ld long double n void lc(){cout<<endl;} n int md(int n){return n%mod;} n void solve() n { n  int n; n  ld k; n  cin>>n>>k; n  //k=k*((ld)(sqrt(2))); n  pii p[n]; n  for(int i=0;i<n;i++) n  cin>>p[i].ft>>p[i].sc; n  for(int i=0;i<n;i++) n  { n   int mind=0; n   for(int j=0;j<n;j++) n   { n    if(i==j)continue; n    int dis=abs(p[i].ft-p[j].ft)+abs(p[i].sc-p[j].sc); n    mind=max(mind,dis); n   } n   if(mind<=k) n    { n     cout<< 1 ; n     return; n    } n  } n     cout<< -1 ; n   n } n signed main() n {  n  ios::sync_with_stdio(0); n  cin.tie(0); n  int t=1; n  cin>>t; n  while(t--) n  { n    solve(); n    lc(); n  } n }


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 3; n const long long OO = 0x3f3f3f3f3f3f3f3f; n long long n, a, b; n vector<int> primes, v; n long long mem[N][3]; n void fact(int num) { n   if (num % 2 == 0) primes.push_back(2); n   while (num % 2 == 0) num /= 2; n   for (int i = 3; i * i <= num; ++i) { n     if (num % i == 0) primes.push_back(i); n     while (num % i == 0) num /= i; n   } n   if (num > 1) primes.push_back(num); n } n long long solve(int idx, int typ, const int& gcd) { n   if (idx == n) return 0; n   long long& ret = mem[idx][typ]; n   if (~ret) return ret; n   ret = OO; n   if (typ < 2) { n     ret = min(ret, a + solve(idx + 1, 1, gcd)); n   } n   if (typ == 1) typ = 2; n   for (int i = -1; i <= 1; ++i) { n     if (((v[idx] + i) % gcd) == 0) n       ret = min(ret, (i == 0 ? 0 : b) + solve(idx + 1, typ, gcd)); n   } n   return ret; n } n int main() { n   cin >> n >> a >> b; n   v = vector<int>(n); n   for (auto& it : v) cin >> it; n   for (int i = -1; i <= 1; ++i) { n     fact(v[0] + i); n     fact(v[n - 1] + i); n   } n   set<int> st(primes.begin(), primes.end()); n   primes = vector<int>(st.begin(), st.end()); n   long long ans = OO; n   for (auto it : primes) { n     memset(mem, -1, sizeof mem); n     long long rt = solve(0, 0, it); n     ans = min(ans, rt); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 998244353; n int mx = (int)1e9; n char an; n void ask_query(int i, int j) { n   cout <<  ?   << i <<     << j << endl; n   cin >> an; n   if (an ==  e ) exit(0); n } n int solbin(int l, int r) { n   if (r == l + 1) return r; n   int mid = (l + r) / 2; n   ask_query(l, mid); n   if (an ==  x ) { n     return solbin(l, mid); n   } else { n     return solbin(mid, r); n   } n } n int sol(int shift, int en) { n   if (en == 2) { n     ask_query(shift, shift + 1); n     if (an ==  y ) { n       return shift + 2; n     } else { n       return shift + 1; n     } n   } n   an =  y ; n   int i = 0, j = 2; n   int it = 0; n   while (an !=  x  && 2 * j < en) { n     if (it != 0) { n       i = j; n       j = min(2 * j, en); n     } n     ask_query(shift + i, shift + j); n     it++; n   } n   if (2 * j >= en && an !=  x ) { n     i = j; n     j = en; n   } n   return solbin(shift + i, shift + j); n } n void solve() { n   string s; n   cin >> s; n   while (s ==  start ) { n     int ans = sol(0, mx); n     cout <<  !   << ans << endl; n     cin >> s; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t; n   t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n class Piece { n  public: n   int up[600]; n   int down[600]; n   vector<int> pcs; n   Piece() {} n } pieces[20]; n int x[600][600], w, h, p, u; n void readPhoto() { n   cin >> h >> w >> p; n   for (int i = 0; i < h; ++i) n     for (int j = 0; j < w; ++j) cin >> x[i][j]; n   h /= p; n } n void setPieces() { n   int st = 0; n   for (int i = 0; i < p; ++i) { n     pieces[i].pcs.push_back(i + 1); n     for (int j = 0; j < w; j++) { n       pieces[i].up[j] = x[st][j] + x[st + 1][j]; n       pieces[i].down[j] = x[st + h - 2][j] + x[st + h - 1][j]; n     } n     st += h; n   } n   u = p; n } n bool comp(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) { n   return a.first < b.first; n } n int calcDiff(int a, int b) { n   int diff = 0; n   for (int i = 0; i < w; ++i) n     diff += ((pieces[a].down[i] - pieces[b].up[i]) * n              (pieces[a].down[i] - pieces[b].up[i])); n   return diff; n } n void mrgPieces(int a, int b) { n   pieces[a].pcs.insert(pieces[a].pcs.end(), pieces[b].pcs.begin(), n                        pieces[b].pcs.end()); n   swap(pieces[a].down, pieces[b].down); n   swap(pieces[b], pieces[--u]); n } n void cmpPieces() { n   vector<pair<int, pair<int, int> > > v; n   for (int i = 0; i < u; ++i) n     for (int j = 0; j < u; ++j) n       if (i != j) { n         int diff = calcDiff(i, j); n         v.push_back(make_pair(diff, make_pair(i, j))); n       } n   sort(v.begin(), v.end(), comp); n   mrgPieces(v[0].second.first, v[0].second.second); n   v.clear(); n } n void cleanPieces() { n   for (int i = 0; i < 20; ++i) pieces[i].pcs.clear(); n } n int main() { n   ios_base::sync_with_stdio(false); n   int c; n   cin >> c; n   while (c--) { n     readPhoto(); n     setPieces(); n     while (u > 1) cmpPieces(); n     int tmpPrint[20]; n     int spx = 1; n     for (__typeof(pieces[0].pcs.begin()) it = pieces[0].pcs.begin(); n          it != pieces[0].pcs.end(); ++it) n       tmpPrint[*it - 1] = spx++; n     for (int i = 0; i < p; ++i) cout << tmpPrint[i] <<    ; n     cout << endl; n     cleanPieces(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool dp[5001][5001]; n vector<int> bits[10001]; n vector<pair<int, int> > cur; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   string s, ans; n   cin >> s; n   int n = s.size(); n   dp[0][0] = 1; n   cur.push_back(make_pair(0, 0)); n   int cnt = 0; n   while ((1 << cnt) < n) cnt++; n   cnt--; n   ans =   ; n   for (int i = 0; i < (1 << cnt); i++) n     for (int j = 0; j < cnt; j++) n       if ((i & (1 << j)) == 0) bits[i].push_back(j); n   int l = 1; n   int m = n; n   while (m > l) { n     m -= l; n     l *= 2; n   } n   while (ans.size() < m) { n     char min_chr =  z ; n     for (int i = 0; i < cur.size(); i++) { n       auto x = cur[i]; n       for (auto j : bits[x.second]) { n         if (dp[x.first + (1 << j)][x.second | (1 << j)] == 0) { n           cur.push_back(make_pair(x.first + (1 << j), x.second | (1 << j))); n           dp[x.first + (1 << j)][x.second | (1 << j)] = 1; n         } n       } n       min_chr = min(min_chr, s[x.first]); n     } n     ans.push_back(min_chr); n     vector<pair<int, int> > tmp; n     for (auto x : cur) { n       if (s[x.first] == min_chr) { n         dp[x.first + 1][x.second] = 1; n         tmp.push_back(make_pair(x.first + 1, x.second)); n       } n     } n     cur = tmp; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void __print(int x) { cerr << x; } n void __print(long x) { cerr << x; } n void __print(long long x) { cerr << x; } n void __print(unsigned x) { cerr << x; } n void __print(unsigned long x) { cerr << x; } n void __print(unsigned long long x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char *x) { cerr <<     << x <<    ; } n void __print(const string &x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V> &x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename T> n void __print(const T &x) { n   int f = 0; n   cerr <<  { ; n   for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n int n, m; n vector<int> me, a, nme; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m; n   int num; n   for (int i = 1; i <= n; i++) { n     cin >> num; n     me.push_back(num); n   } n   for (int i = 1; i <= m; i++) { n     cin >> num; n     a.push_back(num); n   } n   for (int i = 0; i < 30; i++) { n     for (int j = 0; j < me.size(); j++) { n       if (me[j] & (1 << i)) { n         nme.push_back((1 << i)); n       } n     } n   } n   sort(a.begin(), a.end()); n   int ans = 0; n   int cm = 0; n   for (int i = 0; i < nme.size(); i++) { n     while (cm < a.size() and nme[i] >= (1 << a[cm])) { n       nme[i] -= (1 << a[cm]); n       cm += 1; n       ans += 1; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, x; n bool isp(int n) { n   if (n == 1) return false; n   for (long long i = 2; i * i <= n; ++i) n     if (n % i == 0) return false; n   return true; n } n int mpow(long long x, int k) { n   long long ans = 1; n   while (k > 0) { n     if (k & 1) ans = (ans * x) % n; n     x = (x * x) % n; n     k /= 2; n   } n   return ans; n } n int main() { n   cin >> n >> x; n   ++n; n   if (!isp(n)) { n     cout <<  -1 ; n     return 0; n   } n   int m = n - 1; n   vector<int> p; n   for (int i = 2; i <= m; ++i) { n     if (m % i == 0) { n       p.push_back(i); n       while (m % i == 0) m /= i; n     } n   } n   if (m > 1) p.push_back(m); n   for (int y = x - 1; y > 0; --y) { n     bool ok = true; n     for (int i = 0; i < p.size(); ++i) { n       int k = (n - 1) / p[i]; n       if (mpow(y % n, k) == 1) { n         ok = false; n         break; n       } n     } n     if (ok) { n       cout << y; n       return 0; n     } n   } n   cout <<  -1 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 3e5 + 100; n const int oo = 1e9 + 7; n int N; n int H[MAXN]; n deque<int> dq; n int L[MAXN], R[MAXN], l[MAXN], r[MAXN]; n int d[MAXN]; n vector<int> G[MAXN]; n void Dijkstra(int u) { n   for (int i = (1), _b = (N + 1); i <= _b; ++i) d[i] = +oo; n   d[u] = 0; n   priority_queue<pair<int, int>, vector<pair<int, int>>, n                  greater<pair<int, int>>> n       pq; n   pq.push(pair<int, int>(0, u)); n   while (pq.size()) { n     int du = pq.top().first; n     int u = pq.top().second; n     pq.pop(); n     if (du != d[u]) continue; n     for (auto &v : G[u]) { n       if (d[v] > du + 1) { n         d[v] = du + 1; n         pq.push(pair<int, int>(d[v], v)); n       } n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> N; n   for (int i = (1), _b = (N); i <= _b; ++i) cin >> H[i]; n   dq.clear(); n   for (int i = (N), _a = (1); i >= _a; --i) { n     while (dq.size() && H[dq.front()] <= H[i]) dq.pop_front(); n     if (dq.size()) n       R[i] = dq.front() - 1; n     else n       R[i] = i; n     dq.push_front(i); n   } n   dq.clear(); n   for (int i = (1), _b = (N); i <= _b; ++i) { n     while (dq.size() && H[dq.front()] <= H[i]) dq.pop_front(); n     if (dq.size()) n       L[i] = dq.front() + 1; n     else n       L[i] = i; n     dq.push_front(i); n   } n   dq.clear(); n   for (int i = (1), _b = (N); i <= _b; ++i) { n     while (dq.size() && H[dq.front()] >= H[i]) dq.pop_front(); n     if (dq.size()) n       l[i] = dq.front() + 1; n     else n       l[i] = i; n     dq.push_front(i); n   } n   dq.clear(); n   for (int i = (N), _a = (1); i >= _a; --i) { n     while (dq.size() && H[dq.front()] >= H[i]) dq.pop_front(); n     if (dq.size()) n       r[i] = dq.front() - 1; n     else n       r[i] = i; n     dq.push_front(i); n   } n   for (int i = (1), _b = (N); i <= _b; ++i) G[i].push_back(i + 1); n   for (int i = (1), _b = (N); i <= _b; ++i) { n     if (H[i] < min(H[L[i] - 1], H[R[i] + 1])) { n       G[L[i] - 1].push_back(R[i] + 1); n     } n   } n   for (int i = (1), _b = (N); i <= _b; ++i) { n     if (max(H[l[i] - 1], H[r[i] + 1]) < H[i]) { n       G[l[i] - 1].push_back(r[i] + 1); n     } n   } n   Dijkstra(1); n   cout << d[N] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long MOD = 1000000007; n const long long INF = 1e12; n const long long N = 1e6 + 10; n vector<long long> G[100001]; n long long n, m, match[100001], dist[100001]; n bool bfs() { n   long long i, u, v, len; n   queue<long long> Q; n   for (i = 1; i <= n; i++) { n     if (match[i] == 0) { n       dist[i] = 0; n       Q.push(i); n     } else n       dist[i] = (1 << 28); n   } n   dist[0] = (1 << 28); n   while (!Q.empty()) { n     u = Q.front(); n     Q.pop(); n     if (u != 0) { n       len = G[u].size(); n       for (i = 0; i < len; i++) { n         v = G[u][i]; n         if (dist[match[v]] == (1 << 28)) { n           dist[match[v]] = dist[u] + 1; n           Q.push(match[v]); n         } n       } n     } n   } n   return (dist[0] != (1 << 28)); n } n bool dfs(long long u) { n   long long i, v, len; n   if (u != 0) { n     len = G[u].size(); n     for (i = 0; i < len; i++) { n       v = G[u][i]; n       if (dist[match[v]] == dist[u] + 1) { n         if (dfs(match[v])) { n           match[v] = u; n           match[u] = v; n           return true; n         } n       } n     } n     dist[u] = (1 << 28); n     return false; n   } n   return true; n } n long long hopcroft_karp() { n   long long matching = 0, i; n   while (bfs()) n     for (i = 1; i <= n; i++) n       if (match[i] == 0 && dfs(i)) matching++; n   return matching; n } n vector<pair<long long, pair<long long, long long>>> edges; n long long check(long long x) { n   for (long long i = 0; i <= 2 * n + 1; i++) { n     G[i].clear(); n     match[i] = 0; n     dist[i] = (1 << 28); n   } n   for (long long i = 0; i < (long long)edges.size() && edges[i].first <= x; n        i++) { n     long long u = edges[i].second.first, v = edges[i].second.second; n     G[u].push_back(v); n     G[v].push_back(u); n   } n   long long res = hopcroft_karp(); n   return n == res; n } n void solve() { n   long long V; n   cin >> n >> V; n   m = n; n   for (long long i = 0; i < V; i++) { n     long long d, u, v; n     cin >> u >> v >> d; n     edges.push_back({d, {u, v + n}}); n   } n   sort(edges.begin(), edges.end()); n   long long l = 1, h = 1e9 + 1; n   long long ans = h; n   while (l <= h) { n     long long mid = (l + h) / 2; n     if (check(mid)) { n       h = mid - 1; n       ans = mid; n     } else { n       l = mid + 1; n     } n   } n   if (ans == 1e9 + 1) n     cout << -1 <<   n ; n   else n     cout << ans; n } n signed main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   long long t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   double x, y; n } g[500]; n int main() { n   int i, j, k, n, m; n   scanf( %d , &n); n   for (i = 0; i < n; ++i) { n     scanf( %lf%lf , &g[i].x, &g[i].y); n   } n   double maxx = 0; n   double m1, m2; n   for (i = 0; i < n - 1; ++i) n     for (j = i + 1; j < n; ++j) { n       m1 = m2 = 0; n       for (k = 0; k < n; ++k) { n         if (i == k || j == k) continue; n         double temp = (g[i].x - g[k].x) * (g[j].y - g[k].y) - n                       (g[j].x - g[k].x) * (g[i].y - g[k].y); n         if (temp > 0) { n           if (temp > m1) m1 = temp; n         } else { n           if (temp < m2) m2 = temp; n         } n       } n       if (m1 != 0 && m2 != 0) n         if (maxx < m1 + abs(m2)) maxx = m1 + abs(m2); n     } n   printf( %lf , maxx / 2); n } n


#include <bits/stdc++.h> n using namespace std; n int mb[3], cd[3]; n int mn[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; n bool chk() { n   if (mb[1] > 12) return 0; n   int i, j, k, tm; n   tm = mn[mb[1]]; n   if (mb[1] == 2 && !(mb[2] & 3)) tm++; n   if (tm < mb[0]) return 0; n   for (i = mb[2]; i < cd[2]; i++) n     ; n   i -= (mb[2] + 1); n   int dy, m; n   if (mb[0] == 29 && mb[1] == 2 && (cd[2] & 3)) { n     dy = 1; n     m = 3; n   } else { n     dy = mb[0]; n     m = mb[1]; n   } n   if (cd[1] > m || (cd[1] == m && cd[0] >= dy)) i++; n   return i >= 18; n } n int main() { n   bool f = 0; n   scanf( %d.%d.%d %d.%d.%d , &cd[0], &cd[1], &cd[2], &mb[0], &mb[1], &mb[2]); n   sort(mb, mb + 3); n   do { n     if (chk()) { n       f = 1; n       break; n     } n   } while (next_permutation(mb, mb + 3)); n   if (f) n     puts( YES ); n   else n     puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3000000 + 11; n const int mod = 1e9 + 7; n const int MAXN = 3000000 + 5; n int n, m; n int c[MAXN]; n struct Node { n   int l, r; n } a[MAXN]; n int lowbit(int i) { return i & (-i); } n long long sum(int x) { n   long long sum = 0; n   while (x) { n     sum += c[x]; n     x -= lowbit(x); n   } n   return sum; n } n void add(int x, long long val) { n   while (x <= n) { n     c[x] += val; n     x += lowbit(x); n   } n } n int two_query(int x) { n   int l = 1, r = n; n   while (l < r) { n     int mid = (l + r) >> 1; n     if (sum(mid) >= x) { n       r = mid; n     } else n       l = mid + 1; n   } n   return l; n } n long long p[100]; n int lim; n void bz_init() { n   p[0] = 1; n   for (int i = 1; i < 30; i++) p[i] = p[i - 1] << 1; n   lim = log(n) / log(2) + 1; n } n int bz_query(int x) { n   int ans = 0, sum = 0; n   for (int j = lim; j >= 0; j--) { n     if (ans + p[j] <= n && sum + c[ans + p[j]] < x) { n       sum += c[ans + p[j]]; n       ans += p[j]; n     } n   } n   return ans + 1; n } n int f[N]; n char ans[N], s[N]; n int main() { n   scanf( %s , s + 1); n   scanf( %d%d , &n, &m); n   memset(c, 0, sizeof(c)); n   for (int i = 1; i <= n; i++) { n     add(i, 1); n   } n   for (int i = 1; i <= m; i++) { n     scanf( %d%d , &a[i].l, &a[i].r); n   } n   bz_init(); n   for (int now = n, i = m; i >= 1; i--) { n     for (int x = a[i].l + 1, j = 1; a[i].r < now && j <= a[i].r - a[i].l + 1; n          x += 2, j++, now--) { n       if (x > a[i].r) x = a[i].l; n       int pos = bz_query(a[i].r + 1); n       add(pos, -1); n       f[pos] = bz_query(x); n     } n   } n   for (int i = 1, j = 0; i <= n; i++) { n     if (f[i] != 0) n       ans[i] = ans[f[i]]; n     else n       ans[i] = s[++j]; n   } n   printf( %s , ans + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   char c = getchar(); n   int x = 0, f = 1; n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = -1; n   for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ; n   return x * f; n } n inline void chkmax(int &x, int y) { x = x > y ? x : y; } n const int MAXN = 1e5 + 5; n const int INF = 1e9; n int ch[MAXN][26], fail[MAXN]; n int N, M, cnt; n bool nd[MAXN]; n char s[MAXN], t[MAXN]; n vector<int> dp[MAXN]; n inline void build() { n   int p = 0; n   for (int i = 1; i <= M; i++) { n     int x = t[i] -  a ; n     ch[p][x] = ++cnt; n     p = ch[p][x]; n   } n   nd[p] = true; n   queue<int> Q; n   for (int i = 0; i < 26; i++) n     if (ch[0][i]) Q.push(ch[0][i]); n   while (!Q.empty()) { n     int x = Q.front(); n     Q.pop(); n     for (int i = 0; i < 26; i++) n       if (!ch[x][i]) n         ch[x][i] = ch[fail[x]][i]; n       else { n         int y = ch[x][i]; n         fail[y] = ch[fail[x]][i]; n         Q.push(y); n       } n   } n } n int main() { n   scanf( %s , s + 1); n   scanf( %s , t + 1); n   N = strlen(s + 1); n   M = strlen(t + 1); n   build(); n   for (int i = 0; i <= N; i++) { n     dp[i].resize(M + 1); n     for (int j = 0; j <= M; j++) dp[i][j] = -INF; n   } n   dp[0][0] = 0; n   for (int i = 0; i < N; i++) n     if (s[i + 1] !=  ? ) { n       int t = s[i + 1] -  a ; n       for (int j = 0; j <= M; j++) { n         int p = ch[j][t]; n         chkmax(dp[i + 1][p], dp[i][j] + nd[p]); n       } n     } else { n       for (int t = 0; t < 26; t++) n         for (int j = 0; j <= M; j++) { n           int p = ch[j][t]; n           chkmax(dp[i + 1][p], dp[i][j] + nd[p]); n         } n     } n   int ans = 0; n   for (int i = 0; i <= M; i++) chkmax(ans, dp[N][i]); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[4], i, n, x; n int main() { n   for (cin >> n, i = 0; i < n; ++i) n     cin >> x, --x, a[0] += !x, a[1] = max(a[0], a[1] + x), n                                a[2] = max(a[1], a[2] + !x), n                                a[3] = max(a[2], a[3] + x); n   cout << a[3] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int maxn, n, t, x; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int in1, in2; n     cin >> in1 >> in2; n     x -= in1 - t; n     if (x < 0) x = 0; n     x += in2; n     maxn = max(maxn, x); n     t = in1; n   } n   cout << t + x <<     << maxn; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10; n pair<int, long long> operator+(const pair<int, long long> &A, n                                const pair<int, long long> &B) { n   return {A.first + B.first, A.second + B.second}; n } n pair<int, long long> operator-(const pair<int, long long> &A, n                                const pair<int, long long> &B) { n   return {A.first - B.first, A.second - B.second}; n } n struct FenwickTree { n   pair<int, long long> fw[N]; n   void Update(int i, pair<int, long long> v) { n     for (i; i < N; i += i & -i) fw[i] = fw[i] + v; n   } n   pair<int, long long> Query(int i) { n     pair<int, long long> ans = {0, 0}; n     for (i; i > 0; i -= i & -i) ans = ans + fw[i]; n     return ans; n   } n   pair<int, long long> Query(int l, int r) { n     if (l > r) return {0, 0}; n     return Query(r) - Query(l - 1); n   } n } active_task; n int n, m; n int a[N], b[N]; n long long t; n vector<int> val[N]; n int find_index(int x, int r) { n   int l = 1, f = 0; n   while (l <= r) { n     int m = (l + r) >> 1; n     pair<int, long long> ret = active_task.Query(m); n     if (ret.first <= x) { n       f = m; n       l = m + 1; n     } else n       r = m - 1; n   } n   return f; n } n void Solve() { n   cin >> n >> m >> t; n   int number = m; n   pair<int, long long> ans = {t, 0}; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     b[i] = a[i]; n   } n   sort(b + 1, b + n + 1); n   int bSize = unique(b + 1, b + n + 1) - (b + 1); n   for (int i = 1; i <= n; ++i) val[a[i]].push_back(i); n   for (int i = 1; i <= bSize; ++i) { n     int value = b[i]; n     for (int idx : val[value]) { n       active_task.Update(idx, {1, a[idx]}); n     } n     int l = 1, r = n, f = -1; n     while (l <= r) { n       int m = (l + r) >> 1; n       pair<int, long long> ret1 = active_task.Query(m); n       int idx = find_index((ret1.first - 1) / number * number, m); n       pair<int, long long> ret2 = active_task.Query(idx); n       long long sum = ret2.second * 2LL + active_task.Query(idx + 1, m).second; n       if (sum <= t) { n         l = m + 1; n         f = m; n       } else n         r = m - 1; n     } n     if (f != -1) { n       pair<int, long long> ret = active_task.Query(f); n       if (ret.first > ans.second) ans = {value, ret.first}; n     } n   } n   cout << ans.second <<     << ans.first <<   n ; n   for (int i = 1; i <= n; ++i) n     active_task.Update(i, {-1, -a[i]}), val[a[i]].clear(); n } n int main() { n   int TC; n   cin >> TC; n   while (TC--) { n     Solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int compareAscending(const void *a, const void *b) { n   return (*(int *)a - *(int *)b); n } n int compareDecending(const void *a, const void *b) { n   return (*(int *)b - *(int *)a); n } n int compareFirst(const void *a, const void *b) { n   if (((pair<int, int> *)a)->first == ((pair<int, int> *)b)->first) n     return ((pair<int, int> *)a)->second - ((pair<int, int> *)b)->second; n   else n     return ((pair<int, int> *)a)->first - ((pair<int, int> *)b)->first; n } n int compareSecond(const void *a, const void *b) { n   if (((pair<int, int> *)a)->second == ((pair<int, int> *)b)->second) n     return ((pair<int, int> *)a)->first - ((pair<int, int> *)b)->first; n   else n     return ((pair<int, int> *)a)->second - ((pair<int, int> *)b)->second; n } n bool isPrime(int a) { n   if (a < 2) return false; n   if (a < 4) return true; n   if (a % 2 == 0) return false; n   int s = (int)sqrt(a); n   for (int i = 3; i <= s; i += 2) { n     if (a % i == 0) return false; n   } n   return true; n } n int bsearch(int *a, int value, int l, int r) { n   if (l == r) return l; n   if (l + 1 == r) return a[l] >= value ? l : r; n   int m = (l + r) / 2; n   if (a[m] >= value) n     return bsearch(a, value, l, m); n   else n     return bsearch(a, value, m + 1, r); n } n int main() { n   long long a, b, res = 0, t; n   scanf( %lld %lld , &a, &b); n   while (a != 0 && b != 0) { n     res += a / b; n     t = a % b; n     a = b; n     b = t; n   } n   printf( %lld , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n multimap<long long int, long long int> par; n char en =   n ; n long long int inf = pow(10, 14); n long long int mod = 1e9 + 7; n long long int parent[2][500005]; n long long int findRoot(long long int a, long long int which) { n   if (parent[which][a] == a) return a; n   parent[which][a] = findRoot(parent[which][a], which); n   return parent[which][a]; n } n void union1(long long int a, long long int b) { n   long long int root1 = findRoot(a, 0); n   long long int root2 = findRoot(b, 0); n   if (root1 == root2) return; n   long long int root11 = findRoot(a, 1); n   long long int root21 = findRoot(b, 1); n   if (root1 < root2) { n     parent[0][root1] = root2; n   } else { n     parent[0][root2] = root1; n   } n   if (root11 > root21) { n     parent[1][root11] = root21; n   } else { n     parent[1][root21] = root11; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int n, m, p; n   cin >> n >> m >> p; n   string s; n   cin >> s; n   char arr[500005]; n   for (long long int i = 1; i < n + 1; i += 1) { n     arr[i] = s[i - 1]; n     parent[0][i] = parent[1][i] = i; n   } n   bool visited[500005]; n   memset(visited, (false), sizeof(visited)); n   string s1; n   cin >> s1; n   long long int curr = p; n   for (long long int i = 0; i < s1.length(); i += 1) { n     if (s1[i] ==  R ) { n       if (visited[curr + 1]) n         curr = findRoot(curr + 1, 0) + 1; n       else n         curr++; n     } else if (s1[i] ==  L ) { n       if (visited[curr - 1]) n         curr = findRoot(curr - 1, 1) - 1; n       else n         curr--; n     } else { n       if (arr[curr] ==  ( ) { n         stack<char> st; n         while (curr <= n) { n           visited[curr] = true; n           if (visited[curr - 1]) union1(curr - 1, curr); n           if (visited[curr + 1]) union1(curr + 1, curr); n           if (arr[curr] ==  ( ) { n             st.push( ( ); n           } else { n             st.pop(); n           } n           if (st.empty()) { n             long long int temp; n             temp = findRoot(curr, 0) + 1; n             if (temp > n) { n               temp = findRoot(curr, 1) - 1; n             } n             curr = temp; n             break; n           } n           curr = findRoot(curr, 0) + 1; n         } n       } else { n         stack<char> st; n         while (curr >= 1) { n           visited[curr] = true; n           if (visited[curr - 1]) union1(curr - 1, curr); n           if (visited[curr + 1]) union1(curr + 1, curr); n           if (arr[curr] ==  ) ) { n             st.push( ) ); n           } else { n             st.pop(); n           } n           if (st.empty()) { n             long long int temp; n             temp = findRoot(curr, 0) + 1; n             if (temp > n) { n               temp = findRoot(curr, 1) - 1; n             } n             curr = temp; n             break; n           } n           curr = findRoot(curr, 1) - 1; n         } n       } n     } n   } n   for (long long int i = 1; i < n + 1; i += 1) { n     if (!visited[i]) cout << arr[i]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t, i = 0, j, k, x, y, z, count = 0, p, flag = 0, ans = 0, sum = 0, n                l, n, m, max1, min1, pos, tmp, q; n   t = 1; n   while (t--) { n     long long n, r; n     scanf( %lld%lld , &n, &r); n     long double x[1005], y[1005]; n     for (i = 0; i < n; i++) { n       scanf( %Lf , &x[i]); n     } n     for (i = 0; i < n; i++) { n       y[i] = -1.0 * 1000000000; n       for (j = 0; j < i; j++) { n         double p = abs(x[i] - x[j]); n         if (p <= 2 * r) { n           double q = y[j] + sqrtl(4 * r * r - p * p); n           if (q > y[i]) y[i] = q; n         } n       } n       if (y[i] == -1.0 * 1000000000) y[i] = 1.0 * r; n       printf( %.15Lf  , y[i]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2005; n const long double ep = 1e-10; n struct pnt { n   long double x, y; n   pnt() { x = y = 0; } n   pnt(long double xx, long double yy) { x = xx, y = yy; } n   pnt operator+(pnt a) { return pnt(x + a.x, y + a.y); } n   void in() { n     int xx, yy; n     cin >> xx >> yy; n     x = xx, y = yy; n   } n   long double operator^(const pnt &a) const { return x * a.y - y * a.x; } n   bool operator<(const pnt &a) const { return x != a.x ? x < a.x : y < a.y; } n   bool int_pnt(pnt &a) { n     int xx = x + (x > 0 ? 0.5 : -0.5), yy = y + (y > 0 ? 0.5 : -0.5); n     if (abs(x - xx) < ep && abs(y - yy) < ep) { n       a = pnt(xx, yy); n       return 1; n     } n     return 0; n   } n } p[N], M, MM; n vector<pnt> P; n int n; n map<pnt, int> h; n bool opp[N]; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     p[i].in(); n     M = M + p[i]; n     h[p[i]] = i; n   } n   M.x /= n, M.y /= n; n   MM.x = M.x * 2, MM.y = M.y * 2; n   for (int i = 1; i <= n; i++) n     if (!opp[i]) { n       pnt pp = pnt(MM.x - p[i].x, MM.y - p[i].y), qq; n       if (pp.int_pnt(qq) && h.count(qq)) { n         int t = h[qq]; n         opp[t] = 1; n         opp[i] = 1; n       } n     } n   for (int i = 1; i <= n; i++) n     if (!opp[i]) P.push_back(p[i]); n   if (P.empty()) n     puts( -1 ); n   else { n     pnt A = P[0]; n     int ans = 0; n     vector<pnt> D; n     for (auto x : P) { n       pnt AM = A + x; n       AM.x /= 2, AM.y /= 2; n       pnt d = pnt(M.x - AM.x, M.y - AM.y); n       vector<long double> pos, neg; n       for (auto y : P) { n         long double l = d ^ pnt(y.x - AM.x, y.y - AM.y); n         if (abs(l) < ep) continue; n         if (l < 0) n           neg.push_back(-l); n         else n           pos.push_back(l); n       } n       if (neg.size() != pos.size()) continue; n       sort(neg.begin(), neg.end()); n       sort(pos.begin(), pos.end()); n       bool flag = 0; n       for (int i = 0; i < pos.size(); i++) n         if (abs(pos[i] - neg[i]) > ep) flag = 1; n       if (!flag) D.push_back(d); n     } n     for (auto &x : D) { n       if (x.y < 0) x.y = -x.y, x.x = -x.x; n       if (x.y == 0 && x.x < 0) x.x = -x.x; n     } n     sort(D.begin(), D.end(), n          [](const pnt &x, const pnt &y) { return (x ^ y) > 0; }); n     int sz = D.size(); n     for (int i = 0, j; i < sz; i = j) { n       for (j = i; j < sz && (D[i] ^ D[j]) == 0; j++) n         ; n       ans++; n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n std::pair<long long, long long> go(long long m) { n   long long cur = 1; n   long long cur3 = 1; n   long long cur13 = 8; n   long long h = 0; n   long long num = 0; n   std::vector<long long> what; n   while (1) { n     while (h + cur3 >= cur13) { n       if (cur3 > m) break; n       cur++; n       cur3 = cur13; n       cur13 = (cur + 1) * (cur + 1) * (cur + 1); n     } n     if (h + cur3 > m) break; n     h += cur3; n     what.push_back(cur3); n     num++; n   } n   std::vector<long long> ch(num + 1, 0); n   long long sum = 0; n   for (int i = 0; i < num; i++) { n     sum += what[i]; n     ch[i + 1] = sum; n   } n   cur = 1; n   while (cur * cur * cur <= m) cur++; n   long long left = m; n   long long ans = 0; n   deque<long long> revans; n   for (int step = num - 1; step >= 0; step--) { n     cur++; n     while (1) { n       cur--; n       if (ch[step] + cur * cur * cur > left) continue; n       long long cum = ch[step] + cur * cur * cur; n       bool f = false; n       for (int i = 0; i < revans.size(); i++) { n         cum += revans[i] * revans[i] * revans[i]; n         long long ra3 = (revans[i] + 1) * (revans[i] + 1) * (revans[i] + 1); n         if (cum >= ra3) { n           f = true; n           break; n         } n       } n       if (!f) break; n     } n     revans.push_front(cur); n     cur3 = cur * cur * cur; n     left -= cur3; n     ans += cur3; n   } n   return make_pair(num, ans); n } n int main() { n   long long m; n   cin >> m; n   std::pair<long long, long long> x = go(m); n   cout << x.first <<     << x.second; n } n


#include<bits/stdc++.h> n using namespace std; n typedef long long int ll; n typedef unsigned long long int ull; n #define pii acos(-1) n #define sc(n) scanf( %d ,&n) n #define sc2(n,x) scanf( %d%d ,&n,&x) n #define pr(n) printf( %d ,n) n #define scl(n) scanf( %I64d ,&n) n #define scl2(n,m) scanf( %I64d%I64d ,&n,&m) n #define prl(n) printf( %I64d ,n) n #define loop(x,n) for(int i=x;i<n;i++) n #define mp make_pair n #define pb push_back n #define nl printf(  n ) n #define mod 998244353 n #define lv -100000000 n typedef pair<int,int> pi; n #define fastio           ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr) n using namespace std; n int a[300005],c[300005]; n int main() n { n     int t,n,k; n     cin>>t; n     while(t--) n     { n         cin>>n>>k; n         for(int i=0;i<n;i++) n         { n             cin>>a[i]; n         } n         for(int i=0;i<k;i++) n         { n             cin>>c[i]; n         } n         sort(a,a+n); n         ll ans=0; n         int l=0,flag=0; n         for(int i=n-1;i>=0;i--) n         { n             if(flag==0 && c[l]<=c[a[i]-1]&&l<k) n             { n                 ans+=c[l]; n                 l++; n                 //cout<< YES <<endl; n             } n             else n             { n                 flag++; n                 ans+=c[a[i]-1]; n             } n         } n         cout<<ans<<endl; n     } n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long int> v(26, 0); n long long int n, m; n bool myFun(string &a, string &s, long long int i, long long int j) { n   if (i >= n && j >= m) { n     return true; n   } n   if (j >= m) { n     return false; n   } n   if (i >= n) { n     while (j < m) { n       if (s[j] !=  * ) { n         return false; n       } n       j++; n     } n     return true; n   } n   if (a[i] == s[j]) { n     return myFun(a, s, i + 1, j + 1); n   } n   if (s[j] ==  ? ) { n     long long int temp = a[i] -  a ; n     if (v[temp]) { n       return myFun(a, s, i + 1, j + 1); n     } n     return false; n   } n   if (s[j] ==  * ) { n     long long int temp = a[i] -  a ; n     if (v[temp]) { n       return myFun(a, s, i, j + 1); n     } else { n       return (myFun(a, s, i + 1, j + 1) || myFun(a, s, i, j + 1)) || n              myFun(a, s, i + 1, j); n     } n   } n   return false; n } n int main() { n   string s; n   cin >> s; n   for (long long int i = 0; i < s.length(); i++) { n     long long int temp = s[i] -  a ; n     v[temp] = 1; n   } n   cin >> s; n   long long int k; n   cin >> k; n   for (long long int i = 0; i < k; i++) { n     string a; n     cin >> a; n     n = a.length(); n     m = s.length(); n     if (myFun(a, s, 0, 0)) { n       cout <<  YES  << endl; n     } else { n       cout <<  NO  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int a, b, c, d, e, f; n   scanf( %d , &a); n   e = 0; n   for (b = 1; b <= a; b++) { n     for (c = b; c <= a; c++) { n       f = b ^ c; n       d = 0 ^ f; n       if (b + c > d && d <= a && d >= c) { n         e++; n       } n     } n   } n   printf( %d n , e); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int *xi, *di, n; n   cin >> n; n   xi = new int[n]; n   di = new int[n]; n   for (int i = 0; i < n; i++) cin >> xi[i] >> di[i]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (xi[i] + di[i] == xi[j] && xi[j] + di[j] == xi[i] && j != i) { n         cout <<  YES ; n         return 0; n       } n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long fact[200005]; n long long extgcd(long long a, long long b, long long& x, long long& y) { n   long long d = a; n   if (b != 0LL) { n     d = extgcd(b, a % b, y, x); n     y -= (a / b) * x; n   } else { n     x = 1; n     y = 0; n   } n   return d; n } n long long mod_inverse(long long a, long long m) { n   long long x, y; n   extgcd(a, m, x, y); n   return (m + x % m) % m; n } n long long mod_fact(long long n, long long p, long long& e) { n   e = 0; n   if (n == 0) return 1; n   long long res = mod_fact(n / p, p, e); n   e += n / p; n   if (n / p % 2 != 0) { n     return res * (p - fact[n % p]) % p; n   } n   return res * fact[n % p] % p; n } n long long mod_comb(long long n, long long k, long long p) { n   if (n < 0 || k < 0 || n < k) return 0; n   long long e1, e2, e3; n   long long a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2), n             a3 = mod_fact(n - k, p, e3); n   if (e1 > e2 + e3) return 0; n   return a1 * mod_inverse(a2 * a3 % p, p) % p; n } n long long mod_pow(long long x, long long n) { n   long long ans = 1; n   while (n > 0) { n     if (n & 1) { n       ans = ans * x % 998244353LL; n     } n     x = x * x % 998244353LL; n     n >>= 1; n   } n   return ans; n } n int n; n long long k; n int h[200005]; n int main(void) { n   fact[0] = 1; n   for (long long i = 1; i <= 200000; i++) { n     fact[i] = fact[i - 1] * i % 998244353LL; n   } n   scanf( %d%lld , &n, &k); n   for (int i = 0; i < n; i++) { n     scanf( %d , &h[i]); n   } n   int cur = 0, nxt = 1; n   long long po = 1; n   int cnt = 0; n   for (int i = 0; i < n; i++) { n     int ans = h[i]; n     int cans = h[(i + 1) % n]; n     if (ans == cans) { n       po = po * k % 998244353LL; n     } else { n       cnt++; n     } n   } n   long long ans = 0; n   long long v1 = 1; n   for (int i = 0; i < cnt; i++) { n     int rest = cnt - i; n     long long v4 = mod_comb(cnt, i, 998244353LL); n     long long sum = 0; n     if (rest % 2 == 1) { n       if (i == cnt) { n         sum += v1 * mod_pow(2, rest - 1) % 998244353LL; n         sum %= 998244353LL; n       } else { n         sum += v1 * mod_pow(2, rest - 1) % 998244353LL; n         sum %= 998244353LL; n       } n     } else if (rest > 0) { n       long long v3 = mod_pow(2, rest - 1); n       long long v5 = mod_comb(rest - 1, rest / 2, 998244353LL); n       v3 = (v3 - v5 + 998244353LL) % 998244353LL; n       sum += v1 * v3 % 998244353LL; n       sum %= 998244353LL; n     } n     sum = sum * v4 % 998244353LL; n     ans += sum; n     ans %= 998244353LL; n     v1 = v1 * (k - 2LL) % 998244353LL; n   } n   ans = ans * po % 998244353LL; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k = 0, cl[105 * 35], link[105 * 35]; n vector<int> g[105 * 35]; n vector<pair<int, int> > has[105]; n bool dfs(int u) { n   for (int i = 0; i < g[u].size(); ++i) { n     int v = g[u][i]; n     if (!cl[v]) { n       cl[v] = 1; n       if (link[v] == 0 || dfs(link[v]) == true) { n         link[v] = u; n         return true; n       } n     } n   } n   return false; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) { n     int x; n     cin >> x; n     for (int j = 2; j <= sqrt(x); ++j) { n       if (x % j == 0) { n         while (x % j == 0) { n           x = x / j; n           has[i].push_back({j, ++k}); n         } n       } n     } n     if (x > 1) has[i].push_back({x, ++k}); n   } n   for (int i = 1; i <= m; ++i) { n     int u, v; n     cin >> u >> v; n     if (u % 2 == 0) swap(u, v); n     for (int j = 0; j < has[u].size(); ++j) n       for (int q = 0; q < has[v].size(); ++q) { n         if (has[u][j].first == has[v][q].first) { n           g[has[u][j].second].push_back(has[v][q].second); n         } n       } n   } n   int rs = 0; n   for (int j = 1; j <= k; ++j) { n     for (int i = 1; i <= k; ++i) cl[i] = 0; n     if (dfs(j)) ++rs; n   } n   cout << rs; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100005]; n int l[100005]; n int r[100005]; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   for (int i = 1; i <= n; i++) { n     l[i] = min(l[i - 1] + 1, a[i]); n   } n   for (int i = n; i >= 1; i--) { n     r[i] = min(r[i + 1] + 1, a[i]); n   } n   int ma = 0; n   for (int i = 1; i <= n; i++) { n     ma = max(ma, min(l[i], r[i])); n   } n   cout << ma << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   long long a, b; n   for (a = 0; a <= n / 1234567; a++) { n     for (b = 0; b * 123456 <= n - a * 1234567; b++) n       if ((n - (a * 1234567 + b * 123456)) % 1234 == 0) { n         cout <<  YES ; n         return 0; n       } n   } n   cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n long long rdtsc() { n   long long tmp; n   asm( rdtsc  :  =A (tmp)); n   return tmp; n } n inline int myrand() { return abs((rand() << 15) ^ rand()); } n inline int rnd(int x) { return myrand() % x; } n void precalc() {} n const int maxn = 1e4 + 10; n int n; n char s[maxn]; n bool read() { n   if (scanf( %s , s) < 1) { n     return false; n   } n   n = strlen(s); n   return true; n } n set<string> ans; n int dp[maxn][2]; n void solve() { n   ans.clear(); n   memset(dp, 0, sizeof(dp)); n   if (n >= 7) { n     dp[n - 2][0] = 1; n   } n   if (n >= 8) { n     dp[n - 3][1] = 1; n   } n   for (int i = n - 2; i >= 5; --i) { n     for (int it = 0; it < 2; ++it) { n       int len = it + 2; n       if (!dp[i][it]) { n         continue; n       } n       string cur = string(s + i, len); n       ans.insert(cur); n       for (int nit = 0; nit < 2; ++nit) { n         int nlen = nit + 2; n         if (i - nlen < 5) { n           break; n         } n         string t = string(s + (i - nlen), nlen); n         if (t != cur) { n           dp[i - nlen][nit] = 1; n         } n       } n     } n   } n   printf( %d n , ((int)(ans).size())); n   for (auto t : ans) { n     printf( %s n , t.c_str()); n   } n } n int main() { n   srand(rdtsc()); n   precalc(); n   while (true) { n     if (!read()) { n       break; n     } n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int L(int i) { return i << 1; } n inline int R(int i) { return (i << 1) | 1; } n inline long long max(long long a, long long b) { return a < b ? b : a; } n inline long long min(long long a, long long b) { return a < b ? a : b; } n inline int abs(int x) { return x < 0 ? -x : x; } n struct data { n   long long l, r; n } A[2][10100], tmp; n int top[2]; n long long B[33]; n void init() { n   int i; n   B[0] = 1; n   for (i = 1; i < 33; i++) B[i] = B[i - 1] << 1; n } n void dfs(long long l, long long r, int id, int n) { n   l = max(1, l); n   r = min(B[n] - 1, r); n   if (l <= r) { n     tmp.l = l, tmp.r = r; n     A[id][top[id]++] = tmp; n     if (!((l <= 1) && (r >= B[n - 1] - 1))) { n       dfs(l, r, id, n - 1); n       dfs(l - B[n - 1], r - B[n - 1], id, n - 1); n     } n   } n } n int main() { n   long long l1, r1, l2, r2, ret; n   int i, j; n   init(); n   while (cin >> l1 >> r1 >> l2 >> r2) { n     top[0] = top[1] = 0; n     dfs(l1, r1, 0, 30); n     dfs(l2, r2, 1, 30); n     ret = 0; n     for (i = 0; i < top[0]; i++) n       for (j = 0; j < top[1]; j++) n         ret = n             max(min(A[0][i].r, A[1][j].r) - max(A[0][i].l, A[1][j].l) + 1, ret); n     cout << ret << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a, b, n, i, j; n int f[5001]; n int dp[5001][5001]; n char s[5003]; n int main() { n   while (~scanf( %d%d%d , &n, &a, &b)) { n     scanf( %s , &s[1]); n     for (i = 1; i <= n; i++) f[i] = f[i - 1] + a; n     for (i = 1; i <= n; i++) { n       f[i] = min(f[i], f[i - 1] + a); n       for (j = 1; j < i; j++) { n         if (s[i] == s[j]) { n           dp[i][j] = dp[i - 1][j - 1] + 1; n         } else n           dp[i][j] = 0; n         if (j <= i - dp[i][j]) { n           f[i] = min(f[i], f[i - dp[i][j]] + b); n         } else { n           f[i] = min(f[i], f[j] + b); n         } n       } n     } n     printf( %d n , f[n]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int t[60], v[60]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &t[i]); n   for (int i = 1; i <= n; i++) scanf( %d , &v[i]); n   int nrOfStonesTakenAway = 0; n   for (int i = 1; i <= n; i++) { n     if (t[i] > v[i]) nrOfStonesTakenAway += (t[i] - v[i]); n   } n   for (int i = 1; i <= n; i++) n     if (t[i] < v[i]) { n       nrOfStonesTakenAway -= (v[i] - t[i]); n     } n   if (nrOfStonesTakenAway < 0) n     puts( No ); n   else n     puts( Yes ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, a, i, j, k, l; n   cin >> n >> a; n   long long arr[n + 2]; n   for (i = 1; i <= n; i++) { n     cin >> arr[i]; n   } n   long long pos; n   arr[n + 1] = a; n   sort(arr + 1, arr + n + 2); n   for (i = 1; i <= n + 1; i++) { n     if (arr[i] == a) { n       pos = i; n       break; n     } n   } n   long long dist, d1, d2, d3, d4; n   if (pos == 1 || pos == n + 1) { n     if (pos == 1) { n       cout << arr[n] - arr[pos] << endl; n       return 0; n     } n     if (pos == n + 1) { n       cout << arr[pos] - arr[2] << endl; n       return 0; n     } n   } else { n     d1 = 2 * (arr[pos] - arr[1]) + arr[n] - arr[pos]; n     d2 = arr[pos] - arr[1] + 2 * (arr[n] - arr[pos]); n     d3 = 2 * (arr[pos] - arr[2]) + arr[n + 1] - arr[pos]; n     d4 = arr[pos] - arr[2] + 2 * (arr[n + 1] - arr[pos]); n   } n   dist = min(min(d1, d2), min(d3, d4)); n   cout << dist << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:64000000 ) n using namespace std; n const double eps = 1e-9; n const double pi = acos(-1.0); n int main() { n   int n, s; n   cin >> n >> s; n   int res = -1; n   for (int i = 0; i < n; i++) { n     int x, y; n     cin >> x >> y; n     if (y == 0) { n       if (s >= x) { n         res = max(res, 0); n       } n     } else { n       if (s > x) { n         res = max(res, 100 - y); n       } n     } n   } n   cout << res << endl; n   return 0; n } n