#include <bits/stdc++.h> n using namespace std; n const int MAXN = int(1e5 + 5); n int n, A, cf, cm; n int a[MAXN], tmp1[MAXN], tmp2[MAXN]; n long long s[MAXN], m; n int _max = 0, _min = int(1e9); n bool cmp(int x, int y) { return a[x] < a[y]; } n int main() { n   cin >> n >> A >> cf >> cm >> m; n   for (int i = 0; i < n; i++) tmp1[i] = i, cin >> a[i]; n   if (!cm && !cf) { n     puts( 0 ); n     for (int i = 0; i < n; i++) cout << a[i] <<    ; n     return 0; n   } n   sort(tmp1, tmp1 + n, cmp); n   sort(a, a + n); n   for (int i = 0; i < n; i++) { n     s[i] = a[i]; n     i ? s[i] += s[i - 1] : 0; n   } n   long long ret, ans = 0; n   a[n] = A; n   for (int i = n; i >= 0; i--) { n     ret = m - (1ll * A * (n - i) - (s[n - 1] - (i ? s[i - 1] : 0))); n     if (ret < 0) break; n     if (!cm) { n       ans = 1ll * (n - i) * cf; n       _max = n - i; n       _min = 0; n       continue; n     } n     long long l = a[0], r = A, mid; n     while (l < r) { n       mid = r - ((r - l) >> 1); n       int k = upper_bound(a, a + n, mid) - a; n       k = min(k, i); n       if (ret >= 1ll * k * mid - (k ? s[k - 1] : 0)) n         l = mid; n       else n         r = mid - 1; n     } n     long long force = 1ll * (n - i) * cf + 1ll * l * cm; n     if (force > ans) { n       ans = force; n       _max = n - i; n       _min = l; n     } n   } n   cout << ans << endl; n   for (int i = 0; i < n - _max; i++) tmp2[tmp1[i]] = max(_min, a[i]); n   for (int i = n - _max; i < n; i++) tmp2[tmp1[i]] = A; n   for (int i = 0; i < n; i++) cout << tmp2[i] <<    ; n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n double v1, v2, l; n int main() { n   scanf( %d%lf%lf%lf%d , &n, &l, &v1, &v2, &k); n   int T = n / k; n   if (n % k) T++; n   printf( %.7lf n , (2 * T - 2 + (v1 + v2) / v1 - v2 / v1 + v1 / v2) * l / n                         ((2 * T - 2) * v1 + v1 + v2)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool ans[310000]; n struct Query { n   int x1, y1, x2, y2, id; n } querys[310000]; n bool operator<(Query a, Query b) { return a.x2 < b.x2; } n struct Point { n   int x, y; n } points[310000]; n bool operator<(Point a, Point b) { return a.x < b.x; } n int minv[310000 << 2]; n void pushup(int o) { minv[o] = min(minv[((o) << 1)], minv[((o) << 1 | 1)]); } n void update(int o, int L, int R, int x, int val) { n   if (L == R) { n     minv[o] = val; n     return; n   } n   int M = (L + R) >> 1; n   if (x <= M) n     update(((o) << 1), L, M, x, val); n   else n     update(((o) << 1 | 1), M + 1, R, x, val); n   pushup(o); n } n int query(int o, int L, int R, int ql, int qr) { n   if (ql <= L && R <= qr) return minv[o]; n   int M = (L + R) >> 1; n   int ans = 0x3f3f3f3f; n   if (ql <= M) ans = min(ans, query(((o) << 1), L, M, ql, qr)); n   if (qr > M) ans = min(ans, query(((o) << 1 | 1), M + 1, R, ql, qr)); n   return ans; n } n int main() { n   int n, m, t, q; n   scanf( %d%d%d%d , &n, &m, &t, &q); n   for (int i = 1; i <= t; i++) scanf( %d%d , &points[i].x, &points[i].y); n   for (int i = 1; i <= q; i++) n     scanf( %d%d%d%d , &querys[i].x1, &querys[i].y1, &querys[i].x2, n           &querys[i].y2), n         querys[i].id = i; n   sort(points + 1, points + t + 1); n   sort(querys + 1, querys + q + 1); n   for (int i = 1, j = 1; i <= q; i++) { n     while (j <= t && points[j].x <= querys[i].x2) { n       update(1, 1, m, points[j].y, points[j].x); n       j++; n     } n     ans[querys[i].id] |= n         query(1, 1, m, querys[i].y1, querys[i].y2) >= querys[i].x1; n   } n   swap(n, m); n   for (int i = 1; i <= t; i++) swap(points[i].x, points[i].y); n   for (int i = 1; i <= q; i++) { n     swap(querys[i].x1, querys[i].y1); n     swap(querys[i].x2, querys[i].y2); n   } n   sort(points + 1, points + t + 1); n   sort(querys + 1, querys + q + 1); n   memset(minv, 0, sizeof(minv)); n   for (int i = 1, j = 1; i <= q; i++) { n     while (j <= t && points[j].x <= querys[i].x2) { n       update(1, 1, m, points[j].y, points[j].x); n       j++; n     } n     ans[querys[i].id] |= n         query(1, 1, m, querys[i].y1, querys[i].y2) >= querys[i].x1; n   } n   for (int i = 1; i <= q; i++) { n     if (ans[i]) n       printf( YES n ); n     else n       printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int x = n / 2, y = (n / 2) + 1, prime1 = 0, prime2 = 0; n   if (n % 2 == 0) { n     x = (n / 2); n     y = n / 2; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 2; j < x; j++) { n       if (x % j == 0) { n         prime1++; n         break; n       } else if (j == x - 1) { n         prime1 = 0; n         break; n       } n     } n     for (int j = 2; j < y; j++) { n       if (y % j == 0) { n         prime2++; n         break; n       } else if (j == y - 1) { n         prime1 = 0; n         prime2 = 0; n       } n     } n     if (prime1 >= 1 && prime2 >= 1) n       break; n     else { n       x--; n       y++; n     } n   } n   cout << x <<     << y; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e5 + 5, inf = 1e9 + 7; n long long n, k, f[30]; n string s, t, r; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long i, j, a, b, ans = 0; n   cin >> s >> t; n   r = s; n   sort(r.begin(), r.end(), greater<long long>()); n   if (r <= t) return cout << -1, 0; n   n = s.size(); n   for (i = 0; i < n; i++) f[s[i] -  a ]++; n   k = t.size(); n   for (i = 0; i < min(k, n); i++) { n     if (f[t[i] -  a ]) { n       s[i] = t[i], f[t[i] -  a ]--; n     } else { n       for (j = t[i] -  a ; j < 26; j++) n         if (f[j]) { n           s[i] = char(j +  a ); n           f[j]--; n           i++; n           for (j = 0; j < 26; j++) { n             while (f[j]--) s[i] = char(j +  a ), i++; n           } n           cout << s; n           return 0; n         } n       for (j = 25; j >= 0; j--) { n         while (f[j]--) s[i] = char(j +  a ), i++; n       } n       next_permutation(s.begin(), s.end()); n       cout << s; n       return 0; n     } n   } n   if (i == n) next_permutation(s.begin(), s.end()); n   for (j = 0; j < 26; j++) { n     while (f[j]--) s[i] = char(j +  a ), i++; n   } n   cout << s; n } n


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


#include <bits/stdc++.h> n using namespace std; n const double Pi = acos(-1.0); n const int INF = 1 << 29; n const int MAXN = 505; n int n; n int M[MAXN][MAXN]; n int R[MAXN]; n long long A[MAXN]; n int main(int argc, char** argv) { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       scanf( %d , &M[i][j]); n     } n   } n   for (int i = 0; i < n; i++) { n     scanf( %d , &R[n - i - 1]); n     R[n - i - 1]--; n   } n   for (int k = 0; k < n; k++) { n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < n; j++) { n         M[R[i]][R[j]] = min(M[R[i]][R[j]], M[R[i]][R[k]] + M[R[k]][R[j]]); n       } n     } n     for (int i = 0; i <= k; i++) { n       for (int j = 0; j <= k; j++) { n         A[n - k - 1] += M[R[i]][R[j]]; n       } n     } n   } n   for (int i = 0; i < n; i++) { n     printf( %I64d  , A[i]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100005; n const long long INF = 2000000000LL; n long long res[MAXN], xx[MAXN << 1], cnt[MAXN << 1], la[MAXN << 1]; n struct Event { n   long long l, r, y, v; n   Event() {} n   Event(long long _l, long long _r, long long _y, long long _v) n       : l(_l), r(_r), y(_y), v(_v) {} n   bool operator<(const Event &t) const { return y < t.y; } n } e[MAXN << 1]; n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   int tot = 0; n   xx[tot++] = -INF; n   for (int i = 0; i < n; i++) { n     long long x, y; n     scanf( %I64d%I64d , &x, &y); n     xx[tot++] = x; n     xx[tot++] = x + k; n     e[i << 1] = Event(x, x + k, y, 1); n     e[i << 1 | 1] = Event(x, x + k, y + k, -1); n   } n   sort(xx, xx + tot); n   tot = unique(xx, xx + tot) - xx; n   sort(e, e + 2 * n); n   for (int i = 0; i < tot; i++) la[i] = -INF; n   for (int i = 0; i < 2 * n; i++) { n     int l = upper_bound(xx, xx + tot, e[i].l) - xx; n     int r = lower_bound(xx, xx + tot, e[i].r) - xx; n     for (int j = l; j <= r; j++) { n       res[cnt[j]] += (xx[j] - xx[j - 1]) * (e[i].y - la[j]); n       cnt[j] += e[i].v; n       la[j] = e[i].y; n     } n   } n   for (int i = 1; i <= n; i++) printf( %I64d  , res[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n; n long long l, val[205], cst[205]; n char s[205]; n long long ch[205][26], fail[205], cnt = 1; n void Insert(char *s, long long w) { n   long long len = strlen(s), r = 0; n   for (long long i = 0; i < len; i++) { n     long long val = s[i] -  a ; n     if (!ch[r][val]) ch[r][val] = cnt++; n     r = ch[r][val]; n   } n   val[r] += w; n } n long long Q[205], L, R; n void build(long long r) { n   Q[L = 0] = r, R = 1; n   long long p, c; n   for (; L < R;) { n     r = Q[L++]; n     for (long long i = 0; i < 26; i++) n       if (c = ch[r][i]) { n         Q[R++] = c; n         for (p = fail[r]; p != 0 && ch[p][i] == 0; p = fail[p]) n           ; n         long long tmp = ch[p][i]; n         if (tmp && tmp != c) n           fail[c] = tmp; n         else n           fail[c] = 0; n         val[c] += val[fail[c]]; n       } else { n         for (p = fail[r]; p != 0 && ch[p][i] == 0; p = fail[p]) n           ; n         long long tmp = ch[p][i]; n         if (tmp) n           ch[r][i] = tmp; n         else n           ch[r][i] = 0; n       } n   } n } n long long dp[205][205], dp2[205][205], dp3[205][205], A[205][205], B[205][205]; n void solve(long long a[205][205], long long b[205][205], n            long long c[205][205]) { n   memcpy(A, a, sizeof A), memcpy(B, b, sizeof B); n   for (long long k = 0; k < cnt; k++) n     for (long long i = 0; i < cnt; i++) n       for (long long j = 0; j < cnt; j++) n         if (A[i][k] != -0x3f3f3f3f3f3f3f3fll && n             B[k][j] != -0x3f3f3f3f3f3f3f3fll) n           c[i][j] = max(c[i][j], A[i][k] + B[k][j]); n } n int main() { n   scanf( %lld%lld , &n, &l); n   for (long long i = 1; i <= n; i++) scanf( %lld , &cst[i]); n   fail[0] = -1; n   for (long long i = 1; i <= n; i++) { n     scanf( %s , s); n     Insert(s, cst[i]); n   } n   build(0); n   for (long long i = 0; i < cnt; i++) n     for (long long j = 0; j < cnt; j++) n       dp[i][j] = dp2[i][j] = -0x3f3f3f3f3f3f3f3fll; n   for (long long i = 0; i < cnt; i++) dp[i][i] = dp2[i][i] = 0; n   for (long long i = 0; i < cnt; i++) n     for (long long j = 0; j < 26; j++) dp[i][ch[i][j]] = val[ch[i][j]]; n   for (; l; l >>= 1, solve(dp, dp, dp)) n     if (l & 1) solve(dp, dp2, dp2); n   printf( %lld n , *max_element(dp2[0], dp2[0] + cnt + 1)); n } n


#include <bits/stdc++.h> n int main() { n   int t, n, a, b, c, x, z = 0, e = 0, r = 0, o = 0, n1 = 0; n   char s[100000]; n   scanf( %d , &n); n   scanf( %s , &s); n   for (x = 0; x < n; x++) { n     if (s[x] ==  z ) n       z++; n     else if (s[x] ==  e ) n       e++; n     else if (s[x] ==  r ) n       r++; n     else if (s[x] ==  o ) n       o++; n     else if (s[x] ==  n ) n       n1++; n   } n   if (n1 <= o && n1 <= e) { n     for (x = 0; x < n1; x++) printf( 1  ); n     o -= n1; n     e -= n1; n     a = (o > e) ? e : o; n     b = (z > r) ? r : z; n     c = (a > b) ? b : a; n     for (x = 0; x < c; x++) printf( 0  ); n   } else { n     t = (o > e) ? e : o; n     for (x = 0; x < t; x++) printf( 1  ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[20002][11] = {0}; n int b[20002] = {0}; n int c[11] = {0}; n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) scanf( %d , &a[i][j]); n   for (int i = 0; i < k; i++) { n     int x, y; n     cin >> x >> y; n     c[y - 1]++; n     b[x - 1] -= a[x - 1][y - 1]; n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       b[i] += c[j] * a[i][j]; n     } n     cout << b[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 2e5, mod = 1e9 + 7; n vector<char> s; n long long X; n void paste(long long p, long long l, long long cnt) { n   if (s.size() > X + 3 || l == 0) return; n   for (long long i = 0; i < cnt; ++i) n     for (long long j = 0; j < l; ++j) n       if (s.size() > X + 3) n         return; n       else n         s.push_back(s[p + j]); n } n long long md(long long a) { n   if (a < 0) n     return (a + mod * 2) % mod; n   else n     return a % mod; n } n void solve() { n   long long x; n   cin >> x; n   X = x; n   string str; n   cin >> str; n   s = vector<char>(str.begin(), str.end()); n   long long p = 0; n   long long cl = s.size(); n   while (p < x) { n     ++p; n     long long num = s[p - 1] -  0 ; n     paste(p, s.size() - p, num - 1); n     cl = (cl + (num - 1) * md(cl - p)) % mod; n   } n   cout << cl << endl; n   return; n } n signed main() { n   ios::sync_with_stdio(false); n   long long t; n   cin >> t; n   for (long long i = 0; i < t; ++i) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using seg = pair<int, int>; n using ll = long long; n seg intersect(seg a, seg b) { n   seg ret = {max(a.first, b.first), min(a.second, b.second)}; n   if (ret.first > ret.second) return {-1, -1}; n   return ret; n } n inline int len(const seg& a) { return a.second - a.first; } n const int inf = 1234567890; n struct node { n   int l, r; n   seg x; n   node() {} n   node(int _l, int _r) : l(_l), r(_r), x(0, inf) {} n   node(int _l, int _r, const seg& _x) : node(_l, _r) { x = _x; } n   node(node a, node b) : node(a.l, b.r) { x = intersect(a.x, b.x); } n   void update(const seg& v) { x = v; } n }; n struct segment_tree { n   int n; n   vector<node> arr; n   segment_tree(const vector<seg>& a) : n(a.size()), arr(4 * n) { n     mk(a, 0, 0, n - 1); n   } n   node mk(const vector<seg>& a, int i, int l, int r) { n     int m = (l + r) / 2; n     return arr[i] = l > r    ? node(l, r) n                     : l == r ? node(l, r, a[l]) n                              : node(mk(a, 2 * i + 1, l, m), n                                     mk(a, 2 * i + 2, m + 1, r)); n   } n   node update(int at, seg v, int i = 0) { n     int hl = arr[i].l, hr = arr[i].r; n     if (at < hl || hr < at) return arr[i]; n     if (hl == at && at == hr) { n       arr[i].update(v); n       return arr[i]; n     } n     return arr[i] = node(update(at, v, 2 * i + 1), update(at, v, 2 * i + 2)); n   } n   node query(int l, int r, int i = 0) { n     int hl = arr[i].l, hr = arr[i].r; n     if (r < hl || hr < l) return node(hl, hr); n     if (l <= hl && hr <= r) return arr[i]; n     return node(query(l, r, 2 * i + 1), query(l, r, 2 * i + 2)); n   } n }; n int main() { n   ios::sync_with_stdio(false), cin.tie(nullptr); n   int n; n   cin >> n; n   vector<seg> a(n); n   for (int i = 0; i < n; ++i) { n     cin >> a[i].first >> a[i].second; n   } n   segment_tree st(a); n   int mx = 0; n   for (int i = 0; i < n; ++i) { n     st.update(i, seg(0, inf)); n     mx = max(mx, len(st.query(0, n - 1).x)); n     st.update(i, a[i]); n   } n   cout << mx <<   n ; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n struct segment_tree { n   int val[200005 << 2]; n   inline void update(int l, int r, int k, int x, int w) { n     if (l == r) { n       val[k] = w; n       return; n     } n     int mid = l + r >> 1; n     if (x <= mid) n       update(l, mid, k << 1, x, w); n     else n       update(mid + 1, r, k << 1 | 1, x, w); n     val[k] = max(val[k << 1], val[k << 1 | 1]); n   } n   inline int query(int l, int r, int k, int L, int R) { n     if (L <= l && r <= R) return val[k]; n     int mid = l + r >> 1, ans = 0; n     if (L <= mid) ans = max(ans, query(l, mid, k << 1, L, R)); n     if (mid < R) ans = max(ans, query(mid + 1, r, k << 1 | 1, L, R)); n     return ans; n   } n } sgt; n int p[200005], pos[200005], a[200005], lg2[200005]; n int lastp[200005], pre[200005][20]; n char str[200005]; n int main() { n   int n, m, q; n   scanf( %d%d%d , &n, &m, &q); n   lg2[1] = 0; n   for (int i = 2; i <= m; i++) lg2[i] = lg2[i >> 1] + 1; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &p[i]); n     pos[p[i]] = i; n   } n   p[n + 1] = p[1], p[0] = p[n]; n   for (int i = 1; i <= m; i++) { n     scanf( %d , &a[i]); n     pre[i][0] = lastp[p[pos[a[i]] - 1]]; n     for (int k = 1; k <= lg2[i]; k++) pre[i][k] = pre[pre[i][k - 1]][k - 1]; n     lastp[a[i]] = i; n   } n   for (int i = 1; i <= m; i++) { n     int x = i, k = n - 1; n     while (k) { n       x = pre[x][lg2[k]]; n       k -= 1 << lg2[k]; n     } n     if (x) sgt.update(1, m, 1, i, x); n   } n   for (int i = 1; i <= q; i++) { n     int l, r; n     scanf( %d%d , &l, &r); n     int t = sgt.query(1, m, 1, l, r); n     if (t >= l) n       str[i] =  1 ; n     else n       str[i] =  0 ; n   } n   str[q + 1] =   0 ; n   puts(str + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const double PI = acos(-1.0); n const int N = 1e5 + 5; n int n; n map<string, set<string> > m; n map<string, set<string> > m2; n set<string> host; n vector<set<string> > res; n int main(void) { n   ios_base::sync_with_stdio(false); n   cin >> n; n   while (n--) { n     string s; n     cin >> s; n     host.insert(s); n     string s1 =   , s2 =   ; n     int count = 0; n     for (int i = 0; i < (int)s.size(); i++) { n       if (s[i] ==  / ) count++; n       if (count < 3) { n         s1 += s[i]; n       } else { n         s2 += s[i]; n       } n     } n     s1 +=    ; n     s2 +=    ; n     m[s1].insert(s2); n   } n   for (map<string, set<string> >::iterator it = m.begin(); it != m.end(); n        it++) { n     string str =   ; n     for (set<string>::iterator itt = (it->second).begin(); n          itt != (it->second).end(); itt++) { n       str += (*itt); n     } n     m2[str].insert(it->first); n   } n   for (map<string, set<string> >::iterator it = m2.begin(); it != m2.end(); n        it++) { n     if ((it->second).size() > 1) { n       res.push_back(it->second); n     } n   } n   cout << res.size() << endl; n   for (int i = 0; i < (int)res.size(); i++) { n     for (set<string>::iterator it = res[i].begin(); it != res[i].end(); it++) { n       cout << (*it) <<    ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n struct Block { n   vector<array<int, 3>> events; n   int pop_before; n   vector<int> stack_after; n   void add_event(array<int, 3> v) { n     events.insert(upper_bound(events.begin(), events.end(), v), v); n     sort(events.begin(), events.end()); n     pop_before = 0; n     stack_after.clear(); n     for (auto [p, t, x] : events) { n       if (t) n         stack_after.push_back(x); n       else { n         if (stack_after.size()) n           stack_after.pop_back(); n         else n           ++pop_before; n       } n     } n   } n }; n int main() { n   cin.tie(0)->sync_with_stdio(0); n   int q; n   cin >> q; n   int R = (int)sqrt(q); n   int B = (q + R - 1) / R; n   vector<Block> blocks(B); n   for (int qq = 0; qq < q; ++qq) { n     int p, t, x = 0; n     cin >> p >> t; n     --p; n     if (t == 1) cin >> x; n     blocks[p / R].add_event({p, t, x}); n     vector<array<int, 2>> remaining; n     for (int i = 0; i < B; ++i) { n       int to_pop = blocks[i].pop_before; n       while (to_pop && remaining.size()) { n         int pop_here = min(remaining.back()[0], to_pop); n         to_pop -= pop_here; n         remaining.back()[0] -= pop_here; n         if (remaining.back()[0] == 0) remaining.pop_back(); n       } n       if (blocks[i].stack_after.size()) n         remaining.push_back({(int)blocks[i].stack_after.size(), i}); n     } n     if (remaining.size()) { n       cout << blocks[remaining.back()[1]].stack_after[remaining.back()[0] - 1] n            <<   n ; n     } else n       cout <<  -1 n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000000007; n const int N = 700, COLOR = 3; n int n; n char s[N + 1]; n int mch[N + 1]; n int dp[N + 2][N + 1][COLOR][COLOR]; n int main() { n   scanf( %s , s + 1); n   n = strlen(s + 1); n   stack<int> stk; n   for (int i = 1; i <= n; i++) n     if (s[i] ==  ( ) n       stk.push(i); n     else n       mch[stk.top()] = i, stk.pop(); n   for (int i = n - 1; i; i--) n     for (int j = i + 1; j <= n; j++) n       for (int k = 0; k <= 2; k++) n         for (int o = 0; o <= 2; o++) n           if (mch[i] == j) { n             if (!!k + !!o != 1) continue; n             if (i + 1 == j) { n               dp[i][j][k][o] = 1; n               continue; n             } n             for (int p = 0; p <= 2; p++) n               for (int q = 0; q <= 2; q++) n                 if (!(k && k == p || o && o == q)) n                   (dp[i][j][k][o] += dp[i + 1][j - 1][p][q]) %= mod; n           } else { n             if (!mch[i] || mch[i] > j) continue; n             if (k) n               dp[i][j][k][o] = n                   dp[i][mch[i]][k][0] * n                   (1ll * dp[mch[i] + 1][j][0][o] + dp[mch[i] + 1][j][1][o] + n                    dp[mch[i] + 1][j][2][o]) % n                   mod; n             else n               dp[i][j][k][o] = n                   (1ll * dp[i][mch[i]][k][1] * n                        (dp[mch[i] + 1][j][0][o] + dp[mch[i] + 1][j][2][o]) % n                        mod + n                    1ll * dp[i][mch[i]][k][2] * n                        (dp[mch[i] + 1][j][0][o] + dp[mch[i] + 1][j][1][o]) % n                        mod) % n                   mod; n           } n   int ans = 0; n   for (int i = 0; i <= 2; i++) n     for (int j = 0; j <= 2; j++) (ans += dp[1][n][i][j]) %= mod; n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int64_t n, i; n   cin >> n; n   string s; n   cin >> s; n   string ans =   ; n   ans = ans + s[0]; n   bool st = true; n   if ((n - 1) & 1) { n     st = false; n   } n   for (i = 1; i < n; i++) { n     if (st) { n       ans = s[i] + ans; n       st = false; n     } else { n       ans = ans + s[i]; n       st = true; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int req_amount; n   std::cin >> req_amount; n   while (req_amount--) { n     std::string s; n     std::cin >> s; n     int counter = 0; n     for (const auto c : s) { n       counter -= ((c ==  B ) ? -1 : 1); n     } n     std::cout << ((counter == 0) ?  YES  :  NO ) << std::endl; 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 > 0) { n     T--; n     string a, b; n     int d; n     cin >> a >> b; n     for (int i = 0; i < b.length(); i++) n       if (b[b.size() - i - 1] ==  1 ) { n         d = i; n         break; n       } n     for (int i = d; i <= a.size() - 1; i++) { n       if (a[a.size() - i - 1] ==  1 ) { n         cout << i - d << endl; n         d = 100005; n         break; n       } n     } n     if (d != 100005) { n       cout << a.size() - b.size() << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int N = 1005; n int n, s; n struct Parcel { n   int l, r, w, s, v, id; n } a[N]; n vector<Parcel> p[N]; n ll dp[N][N]; n ll dfs(int pos, int r) { n   if (dp[pos][r] != -1) return dp[pos][r]; n   ll &ret = dp[pos][r]; n   ret = 0; n   vector<ll> f(a[pos].r + 1); n   for (int i = a[pos].l; i <= a[pos].r; i++) { n     if (i) f[i] = f[i - 1]; n     for (auto &j : p[i]) n       if (j.l >= a[pos].l && j.w <= r && j.id != pos) n         f[i] = max(f[i], f[j.l] + j.v + dfs(j.id, min(j.s, r - j.w))); n   } n   return ret = f[a[pos].r]; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> s; n   for (int i = 1; i <= n; i++) n     cin >> a[i].l >> a[i].r >> a[i].w >> a[i].s >> a[i].v, n         a[i].id = i, p[a[i].r].push_back(a[i]); n   a[0].l = 0; n   a[0].r = 2 * n; n   memset(dp, -1, sizeof(dp)); n   cout << dfs(0, s) << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int N = 50; n std::vector<int> *graph[N][N], *igraph[N][N]; n std::vector<int> expand(std::vector<int> *graph[N][N], std::vector<int> queue, n                         int max) { n   for (int t = 0; t + 1 < (int)queue.size() && (int)queue.size() <= max; ++t) { n     int u = queue[t]; n     int v = queue[t + 1]; n     if (graph[u][v] == NULL) { n       return std::vector<int>(); n     } else { n       for (int w : *graph[u][v]) { n         queue.push_back(w); n       } n     } n   } n   return queue; n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   memset(graph, 0, sizeof(graph)); n   for (int i = 0; i < m; ++i) { n     int x, y, k; n     scanf( %d%d%d , &x, &y, &k); n     x--; n     y--; n     std::vector<int> seq; n     while (k--) { n       int v; n       scanf( %d , &v); n       seq.push_back(--v); n     } n     graph[x][y] = new std::vector<int>(seq); n     std::reverse(seq.begin(), seq.end()); n     igraph[y][x] = new std::vector<int>(seq); n   } n   bool found = false; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < n; ++j) { n       if (graph[i][j] != NULL) { n         std::vector<int> seq = *graph[i][j]; n         for (int k = 1; k < (int)seq.size(); ++k) { n           if (seq[k - 1] == i && seq[k] == j) { n             std::vector<int> fw = expand( n                 graph, std::vector<int>(seq.begin() + k, seq.end()), 2 * n); n             std::vector<int> iseq(seq.begin(), seq.begin() + k); n             std::reverse(iseq.begin(), iseq.end()); n             std::vector<int> bw = expand(igraph, iseq, 2 * n); n             if (!fw.empty() && !bw.empty()) { n               std::reverse(bw.begin(), bw.end()); n               for (int t : fw) { n                 bw.push_back(t); n               } n               if ((int)bw.size() <= 2 * n && !found) { n                 found = true; n                 printf( %d n , (int)bw.size()); n                 for (int i = 0; i < (int)bw.size(); ++i) { n                   printf( %d%c , bw[i] + 1,    n [i == (int)bw.size() - 1]); n                 } n               } n             } n           } n         } n       } n     } n   } n   if (!found) { n     puts( 0 ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = 3.1415926535897; n int m, n, dp[5005][5005], ans; n char yy[5005], sy[5005]; n signed main() { n   std::ios::sync_with_stdio(0); n   std::cin.tie(0); n   cin >> m >> n >> yy >> sy; n   for (int i = 0; i < m; ++i) n     for (int j = 0; j < n; ++j) { n       if (yy[i] == sy[j]) n         dp[i + 1][j + 1] = dp[i][j] + 2; n       else n         dp[i + 1][j + 1] = max(max(dp[i + 1][j], dp[i][j + 1]) - 1, 0); n       ans = max(ans, dp[i + 1][j + 1]); n     } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int x, y, z, a, b, c; n   scanf( %d %d %d , &x, &y, &z); n   scanf( %d %d %d , &a, &b, &c); n   if (x == a || y == b || z == c) n     printf( YES n ); n   else n     printf( NO n ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     string s; n     cin >> s; n     unordered_set<char> st; n     for (int i = 0; i < s.length(); i++) { n       if (s[i] != s[i + 1]) { n         st.insert(s[i]); n       } else { n         i++; n       } n     } n     vector<char> v; n     for (auto i : st) { n       v.push_back(i); n     } n     sort(v.begin(), v.end()); n     for (auto i = v.begin(); i != v.end(); i++) { n       cout << *i; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 61; n const int K = 22222; n const int M = K + K + 5; n int n, m; n int a[N], b[N]; n long long m1[M], m2[M]; n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 0; i < n; i++) scanf( %d , &a[i]); n   for (int i = 0; i < m; i++) scanf( %d , &b[i]); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       m1[a[i] + b[j] + K] |= 1LL << i; n       m2[a[i] + b[j] + K] |= 1LL << j; n     } n   } n   int ans = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       for (int p = 0; p < n; p++) { n         for (int q = 0; q < m; q++) { n           int x = a[i] + b[j] + K; n           int y = a[p] + b[q] + K; n           int res1 = __builtin_popcountll(m1[x]) + __builtin_popcountll(m1[y]) - n                      __builtin_popcountll(m1[x] & m1[y]); n           int res2 = __builtin_popcountll(m2[x]) + __builtin_popcountll(m2[y]) - n                      __builtin_popcountll(m2[x] & m2[y]); n           ans = max(ans, res1 + res2); n         } n       } n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<int, int> mp; n int n, ans[100001][4], cnt = 0; n pair<int, int> t[4]; n priority_queue<pair<int, int> > q; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     ++mp[x]; n   } n   for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) { n     q.push({it->second, it->first}); n   } n   while (q.size() >= 3) { n     ++cnt; n     for (int i = 1; i <= 3; i++) { n       t[i] = q.top(); n       q.pop(); n       ans[cnt][i] = t[i].second; n     } n     for (int i = 1; i <= 3; i++) { n       t[i].first--; n       if (t[i].first) { n         q.push(t[i]); n       } n     } n   } n   cout << cnt <<   n ; n   for (int i = 1; i <= cnt; i++) { n     sort(ans[i] + 1, ans[i] + 4); n     cout << ans[i][3] <<     << ans[i][2] <<     << ans[i][1] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void qmax(int &x, int y) { n   if (x < y) x = y; n } n void qmin(int &x, int y) { n   if (x > y) x = y; n } n inline long long read() { n   char s; n   long long k = 0, base = 1; n   while ((s = getchar()) !=  -  && s != EOF && !(isdigit(s))) n     ; n   if (s == EOF) exit(0); n   if (s ==  - ) base = -1, s = getchar(); n   while (isdigit(s)) { n     k = k * 10 + (s ^  0 ); n     s = getchar(); n   } n   return k * base; n } n inline void write(int x) { n   static char cnt, num[15]; n   cnt = 0; n   if (!x) { n     printf( 0 ); n     return; n   } n   for (; x; x /= 10) num[++cnt] = x % 10; n   for (; cnt; putchar(num[cnt--] + 48)) n     ; n } n const int maxn = 1e5 + 100; n int a[maxn]; n int n, l, r, l1, r1, la, ra; n int q(int x) { n   printf( ? %d n , x); n   fflush(stdout); n   int y; n   scanf( %d , &y); n   return y; n } n void ret(int x) { n   printf( ! %d n , x); n   fflush(stdout); n   exit(0); n } n int main() { n   n = read(); n   if ((n / 2) % 2 == 1) { n     ret(-1); n     return 0; n   } n   memset(a, 0x3f3f3f3f, sizeof(a)); n   l = 1, r = n / 2; n   la = q(l); n   ra = q(n / 2 + l); n   if (la == ra) { n     ret(l); n     return 0; n   } n   int mdl, mdr, mda, mdb; n   while (l <= r) { n     mdl = (l + r) / 2; n     mdr = mdl + n / 2; n     mda = q(mdl); n     mdb = q(mdr); n     if (mda == mdb) { n       ret(mdl); n       return 0; n     } n     if ((la < ra) ^ (mda < mdb)) n       r = mdl - 1; n     else n       l = mdl + 1; n   } n   ret(-1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, sx, sy, ex, ey, a, b; n vector<pair<int, long long>> node[100001]; n vector<pair<long long, int>> X, Y; n vector<long long> dist; n vector<bool> done; n int mulMod(long long, long long); n int addMod(int, int); n void readArray(int *, int); n void printArray(int *, int); n void addEdgesFromStart() { n   for (int i = 0; i < m; i++) { n     long long w = min(abs(sx - X[i].first), abs(sy - Y[i].first)); n     node[0].push_back({X[i].second, w}); n   } n } n void addEdgesToEnd() { n   for (int i = 0; i < m; i++) { n     long long w = abs(ex - X[i].first) + abs(ey - Y[i].first); n     node[X[i].second].push_back({m + 1, w}); n   } n   long long w = abs(ex - sx) + abs(ey - sy); n   node[0].push_back({m + 1, w}); n } n void addEdges(vector<pair<long long, int>> &coord) { n   for (int i = 1; i < coord.size(); i++) { n     int id1 = coord[i - 1].second, id2 = coord[i].second; n     long long w = coord[i].first - coord[i - 1].first; n     node[id1].push_back({id2, w}); n     node[id2].push_back({id1, w}); n   } n } n struct comp { n   bool operator()(const pair<long long, int> &x, n                   const pair<long long, int> &y) { n     return (x.first > y.first); n   } n }; n int main() { n   cin >> n >> m; n   cin >> sx >> sy >> ex >> ey; n   for (int i = 1; i <= m; i++) { n     cin >> a >> b; n     X.push_back({a, i}); n     Y.push_back({b, i}); n   } n   addEdgesFromStart(); n   addEdgesToEnd(); n   sort(X.begin(), X.end()); n   sort(Y.begin(), Y.end()); n   addEdges(X); n   addEdges(Y); n   priority_queue<pair<long long, int>, vector<pair<long long, int>>, comp> pq; n   dist.resize(m + 2, LONG_MAX); n   done.resize(m + 2, false); n   dist[0] = 0; n   pq.push({dist[0], 0}); n   while (!pq.empty()) { n     pair<long long, int> curr = pq.top(); n     pq.pop(); n     if (curr.second == m + 1) { n       dist[m + 1] = curr.first; n       break; n     } n     if (done[curr.second]) continue; n     int id = curr.second; n     long long w = curr.first; n     done[id] = true; n     dist[id] = w; n     for (auto edge : node[id]) n       if (dist[edge.first] > w + edge.second) n         pq.push({w + edge.second, edge.first}); n   } n   cout << dist[m + 1] << endl; n   return 0; n } n int mulMod(long long a, long long b) { n   a *= b; n   a %= 1000000007; n   return (int)a; n } n int addMod(int a, int b) { n   long long c = a + b; n   if (c >= 1000000007) { n     c -= 1000000007; n   } n   return (int)c; n } n void readArray(int *nums, int n) { n   for (int i = 0; i < n; i++) cin >> nums[i]; n } n void printArray(int *nums, int n) { n   for (int i = 0; i < n; i++) cout << nums[i] <<    ; n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6; n long long int x[maxn]; n long long int sum, ans; n map<long long int, long long int> table[27]; n string s; n int main() { n   for (int i = 1; i <= 26; i++) cin >> x[i]; n   cin >> s; n   for (int i = 0; i < s.size(); i++) { n     ans += table[s[i] -  a  + 1][sum]; n     sum += x[s[i] -  a  + 1]; n     table[s[i] -  a  + 1][sum]++; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1e9 + 7; n signed main() { n   long long n; n   cin >> n; n   vector<long long> a(n); n   vector<long long> ruio(n + 1, 0); n   vector<long long> ruit(n + 1, 0); n   long long ro = 0; n   long long rt = 0; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] == 1) { n       ro++; n     } else { n       rt++; n     } n     ruio[i + 1] = ro; n     ruit[i + 1] = rt; n   } n   long long ans = rt; n   for (long long i = 0; i < n; i++) { n     long long ltmp = 0; n     for (long long j = 0; j < i; j++) { n       ltmp = max(ltmp, ruio[j] + (ruit[i + 1] - ruit[j])); n     } n     long long rtmp = 0; n     for (long long j = i; j < n; j++) { n       rtmp = max(rtmp, (ruio[j + 1] - ruio[i]) + (ruit[n] - ruit[j])); n     } n     ans = max(ans, ltmp + rtmp); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double r, x1, y1, x2, y2; n   cin >> r >> x1 >> y1 >> x2 >> y2; n   double distance = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); n   if (distance == 0) { n     cout << 0; n     return 0; n   } n   if (distance <= 2 * r) { n     cout << 1; n     return 0; n   } n   double midDistance = distance - (2 * r); n   double x = midDistance / (2 * r); n   int y = x; n   int z = ceil(x); n   if ((z - y) == 0) { n     cout << y + 1; n     return 0; n   } else { n     cout << y + 2; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 5; n int T, n, m, a[N], b[N], cnt, res[N << 1], v[N << 1], t, c[N << 1], pr[N], n     sf[N], p[N]; n long long ans; n void add(int x, int y) { n   for (int i = x; i; i -= i & (-i)) c[i] += y; n } n int query(int x) { n   int ans = 0; n   for (int i = x; i <= t; i += i & (-i)) ans += c[i]; n   return ans; n } n void solve(int l, int r, int nl, int nr) { n   if (l > r || nl > nr) return; n   int mid = (l + r) / 2, ans = 1e9; n   pr[nl - 1] = sf[nr + 1] = 0; n   for (int i = nl; i <= nr; i++) pr[i] = pr[i - 1] + (a[i] > b[mid]); n   for (int i = nr; i >= nl; i--) sf[i] = sf[i + 1] + (a[i] < b[mid]); n   for (int i = nl; i <= nr; i++) n     if (ans > pr[i - 1] + sf[i]) ans = pr[i - 1] + sf[i], p[mid] = i; n   solve(l, mid - 1, nl, p[mid]), solve(mid + 1, r, p[mid], nr); n } n signed main() { n   scanf( %d , &T); n   while (T--) { n     scanf( %d%d , &n, &m), cnt = ans = 0; n     for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n     for (int i = 1; i <= m; i++) scanf( %d , &b[i]); n     sort(b + 1, b + 1 + m), solve(1, m + 1, 1, n + 1); n     for (int i = 1, j = 1; i <= n + 1; i++) { n       while (j <= m && p[j] <= i) res[++cnt] = b[j], j++; n       if (i <= n) res[++cnt] = a[i]; n     } n     for (int i = 1; i <= cnt; i++) v[i] = res[i]; n     sort(v + 1, v + 1 + cnt), t = unique(v + 1, v + 1 + cnt) - v - 1, n                               fill(c + 1, c + 1 + t, 0); n     for (int i = 1; i <= cnt; i++) { n       res[i] = lower_bound(v + 1, v + 1 + t, res[i]) - v; n       ans += query(res[i] + 1), add(res[i], 1); n     } n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353; n long long fact[200005]; n long long factinv[200005]; n long long lgput(long long a, long long exp) { n   long long rz = 1; n   while (exp) { n     if (exp & 1LL) { n       --exp; n       rz = (rz * 1LL * a) % mod; n     } else { n       exp >>= 1LL; n       a = (a * 1LL * a) % mod; n     } n   } n   return rz; n } n long long comb(long long a, long long b) { n   return ((fact[a] * factinv[b]) % mod * factinv[a - b]) % mod; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long k, mxc = 0, n, m, a, b, i, j = 0, t; n   cin >> n >> k; n   fact[0] = fact[1] = 1; n   for (i = 2; i <= n; ++i) fact[i] = (fact[i - 1] * i) % mod; n   for (i = 1; i <= n; ++i) factinv[i] = lgput(fact[i], mod - 2); n   factinv[0] = factinv[1]; n   if (k >= n) { n     cout << 0; n     return 0; n   } n   long long rz = 0; n   k = n - k; n   for (i = 0; i <= k; ++i) { n     if (i & 1) { n       rz = (rz + mod - comb(k, i) * lgput(k - i, n)) % mod; n     } else { n       rz = (rz + comb(k, i) * lgput(k - i, n)) % mod; n     } n   } n   rz = (rz * comb(n, n - k)) % mod; n   if (k != n) n     cout << (rz * 2LL) % mod; n   else n     cout << rz; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2 * 1000 * 100 + 10; n int to[N], nxt[N], idx[N], tot; n int rnk[N], sz[N]; n bool visited[N]; n int minsz, center; n void add_edge(int u, int v) { n   ++tot; n   to[tot] = v; n   nxt[tot] = idx[u]; n   idx[u] = tot; n } n int compute_size(int node, int parent) { n   int s = 1; n   for (int i = idx[node]; i != 0; i = nxt[i]) { n     if (!visited[to[i]] && parent != to[i]) { n       s += compute_size(to[i], node); n     } n   } n   return sz[node] = s; n } n void compute_center(int node, int parent, int totsz) { n   int upsz = totsz - sz[node]; n   int dnsz = -1; n   for (int i = idx[node]; i != 0; i = nxt[i]) { n     if (!visited[to[i]] && parent != to[i]) { n       compute_center(to[i], node, totsz); n       dnsz = max(dnsz, sz[to[i]]); n     } n   } n   if (max(upsz, dnsz) < minsz) { n     minsz = max(upsz, dnsz); n     center = node; n   } n } n void dfs(int node, int depth) { n   int totsz = compute_size(node, 0); n   minsz = INT_MAX; n   compute_center(node, 0, totsz); n   int c = center; n   rnk[c] = depth; n   visited[c] = true; n   for (int i = idx[c]; i != 0; i = nxt[i]) { n     if (!visited[to[i]]) { n       dfs(to[i], depth + 1); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   tot = 0; n   memset(nxt, 0, sizeof(nxt)); n   memset(idx, 0, sizeof(idx)); n   memset(visited, false, sizeof(visited)); n   int n; n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     int u, v; n     cin >> u >> v; n     add_edge(u, v); n     add_edge(v, u); n   } n   dfs(1, 0); n   for (int i = 1; i <= n; i++) { n     cout << static_cast<char>(rnk[i] +  A ) <<    ; n   } n   cout << endl; 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, m; n     cin >> n >> m; n     long long int a[n + 1][m + 1], i, j, p = 0; n     for (i = 1; i <= n; i++) { n       for (j = 1; j <= m; j++) { n         cin >> a[i][j]; n       } n     } n     for (i = 1; i <= n; i++) { n       for (j = 1; j <= m; j++) { n         int d = 4; n         if (i == 1) { n           d--; n         } n         if (j == 1) { n           d--; n         } n         if (i == n) { n           d--; n         } n         if (j == m) { n           d--; n         } n         if (a[i][j] <= d) { n           a[i][j] = d; n         } else { n           p = 1; n         } n       } n     } n     if (p == 1) { n       cout <<  NO  << endl; n     } else { n       cout <<  YES  << endl; n       for (i = 1; i <= n; i++) { n         for (j = 1; j <= m; j++) { n           cout << a[i][j] <<    ; n         } n         cout << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct data { n   int a, b, c, d; n   data() {} n   data(int a, int b, int c, int d) : a(a), b(b), c(c), d(d) {} n }; n const int MAX = 100500; n data info[MAX]; n int main() { n   std::ios_base::sync_with_stdio(false); n   int n, k; n   cin >> n >> k; n   info[0] = data(1, 2, 3, 5); n   int mx; n   for (int i = 1; i < n; i++) { n     info[i] = data(info[i - 1].a + 6, info[i - 1].b + 6, info[i - 1].c + 6, n                    info[i - 1].d + 6); n   } n   mx = info[n - 1].d * k; n   cout << mx <<   n ; n   for (int i = 0; i < n; i++) { n     cout << info[i].a * k <<     << info[i].b * k <<     << info[i].c * k <<     n          << info[i].d * k <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[500005]; n long long add[500005]; n int main() { n   int i, j, n, x, y, z, m; n   long long sum; n   scanf( %d , &n); n   sum = 0; n   a[0] = 0; n   m = 1; n   for (i = 0; i < n; i++) { n     scanf( %d , &x); n     if (x == 1) { n       scanf( %d%d , &y, &z); n       sum += y * z; n       add[y - 1] += z; n       printf( %lf n , sum * 1.0 / m); n     } n     if (x == 2) { n       scanf( %d , &y); n       a[m++] = y; n       add[m - 1] = 0; n       sum += y; n       printf( %lf n , sum * 1.0 / m); n     } n     if (x == 3) { n       sum -= a[m - 1]; n       sum -= add[m - 1]; n       a[m - 1] = 0; n       add[m - 2] += add[m - 1]; n       add[m - 1] = 0; n       m--; n       printf( %lf n , sum * 1.0 / m); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n const int N = 1100; n int n; n vector<int> g[N]; n int ed[N][3]; n int ans[10 * N][3]; n int ansSz; n void addAns(int v, int u, int x) { n   ans[ansSz][0] = v + 1; n   ans[ansSz][1] = u + 1; n   ans[ansSz][2] = x; n   ansSz++; n } n int getLeaf(int v, int par, int u) { n   if (v == u) return -1; n   if ((int)g[v].size() == 1) return v; n   int res = -2; n   for (int w : g[v]) { n     if (w == par) continue; n     int z = getLeaf(w, v, u); n     if (z == -1) return -1; n     res = z; n   } n   return res; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     int v, u, w; n     scanf( %d%d%d , &v, &u, &w); n     v--; n     u--; n     ed[i][0] = v; n     ed[i][1] = u; n     ed[i][2] = w; n     g[v].push_back(u); n     g[u].push_back(v); n   } n   for (int v = 0; v < n; v++) { n     if ((int)g[v].size() == 2) { n       printf( NO n ); n       return 0; n     } n   } n   for (int i = 1; i < n; i++) { n     int v = ed[i][0], u = ed[i][1], x = ed[i][2] / 2; n     vector<int> vv, uu; n     if ((int)g[v].size() == 1) { n       vv.push_back(v); n     } else { n       for (int w : g[v]) { n         int z = getLeaf(w, v, u); n         if (z != -1) vv.push_back(z); n         if ((int)vv.size() == 2) break; n       } n     } n     if ((int)g[u].size() == 1) { n       uu.push_back(u); n     } else { n       for (int w : g[u]) { n         int z = getLeaf(w, u, v); n         if (z != -1) uu.push_back(z); n         if ((int)uu.size() == 2) break; n       } n     } n     if ((int)uu.size() == 1) swap(vv, uu); n     if ((int)uu.size() == 1) { n       addAns(vv[0], uu[0], 2 * x); n     } else if ((int)vv.size() == 1) { n       addAns(vv[0], uu[0], x); n       addAns(vv[0], uu[1], x); n       addAns(uu[0], uu[1], -x); n     } else { n       addAns(vv[0], uu[0], x); n       addAns(vv[1], uu[1], x); n       addAns(vv[0], vv[1], -x); n       addAns(uu[0], uu[1], -x); n     } n   } n   printf( YES n ); n   printf( %d n , ansSz); n   for (int i = 0; i < ansSz; i++) n     printf( %d %d %d n , ans[i][0], ans[i][1], ans[i][2]); n   return 0; n } n


#include <bits/stdc++.h> n constexpr int MAXN = 1e5 + 5; n using namespace std; n int tot, n, cnt; n unordered_map<int, int> Map; n vector<int> vec; n vector<pair<string, int>> opt; n string s; n inline void discretization() { n   sort(vec.begin(), vec.end()); n   cnt = unique(vec.begin(), vec.end()) - vec.begin(); n   for (int i = 0; i < cnt; i++) Map[vec[i]] = i; n } n struct Node { n   Node *lson, *rson; n   int cnt, l, r; n   long long sum[5]; n } Tree[MAXN << 1]; n inline Node *newNode(Node *&root) { return root = &Tree[++tot]; } n inline void update(Node *root) { n   root->cnt = root->lson->cnt + root->rson->cnt; n   for (int i = 0; i < 5; i++) n     root->sum[i] = root->lson->sum[i] + n                    root->rson->sum[((i - root->lson->cnt) % 5 + 5) % 5]; n } n inline void build(int L, int R, Node *root) { n   root->l = L, root->r = R; n   if (L == R) return; n   int mid = (L + R) >> 1; n   build(L, mid, newNode(root->lson)), build(mid + 1, R, newNode(root->rson)); n } n inline void modify(int pos, int val, Node *root) { n   if (root->l == pos && root->r == pos) { n     root->cnt += val, root->sum[1] += val * vec[pos]; n     return; n   } n   int mid = (root->l + root->r) >> 1; n   if (pos <= mid) modify(pos, val, root->lson); n   if (pos > mid) modify(pos, val, root->rson); n   update(root); n } n int main() { n   std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n; n   for (int i = 1, x; i <= n; i++) { n     cin >> s; n     if (s ==  add ) n       cin >> x, opt.push_back({s, x}), vec.push_back(x); n     else if (s ==  del ) n       cin >> x, opt.push_back({s, x}); n     else n       opt.push_back({s, 0}); n   } n   discretization(), build(0, cnt, Tree); n   for (auto i : opt) { n     if (i.first ==  add ) n       modify(Map[i.second], 1, Tree); n     else if (i.first ==  del ) n       modify(Map[i.second], -1, Tree); n     else n       cout << Tree->sum[3] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n void add(int &a, int b) { n   a += b; n   if (a >= mod) a -= mod; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   vector<int> dp(20002), pre(20002, 0); n   int zero = 10000; n   int ans = 0; n   for (int i = 1; i <= n; ++i) { n     int x; n     cin >> x; n     ++pre[zero]; n     for (int j = 0; j <= zero << 1; ++j) { n       if (j >= x) add(dp[j], pre[j - x]); n       if (j + x <= zero * 2) add(dp[j], pre[j + x]); n     } n     add(ans, dp[zero]); n     if (i == n) continue; n     pre = dp; n     memset(&dp[0], 0, sizeof dp[0] * dp.size()); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n map<int, int> m; n string s; n long long ans; n bool flag; n void solve() { n   cin >> n; n   cin >> k; n   vector<int> a(n); n   int maxi = 0; n   for (auto i = 0; i < n; i++) cin >> a[i]; n   ; n   for (auto i = 0; i < n; i++) { n     maxi = max(maxi, a[i]); n     m[a[i]]++; n     if (m[a[i]] >= k) { n       cout << 0; n       return; n     } n   } n   long long ans = INT_MAX; n   for (auto x = 1; x < 200000; x++) { n     queue<int> q; n     q.push(x); n     long long an = 0; n     int mul = 0; n     int K = 0; n     while (!q.empty() && K < k) { n       int N = q.size(); n       while (N-- && K < k) { n         int y = q.front(); n         q.pop(); n         int count = m[y]; n         if ((y * 2 - 1) < maxi) { n           q.push(y * 2); n           q.push(y * 2 + 1); n         } n         if (count > (k - K)) count = (k - K); n         an += count * mul; n         K += count; n       } n       mul++; n     } n     if (K == k) ans = min(an, ans); n   } n   cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n const int S = 400004; n int last, tr[S][26], fail[S], len[S], tot = 0, eg = 1, h[S], nx[S << 1], n                                       v[S << 1], e[S]; n char c[S]; n void insert(int &last, char c) { n   c -=  a ; n   int p = last, now = ++tot; n   len[now] = len[last] + 1; n   while (p != -1 && !tr[p][c]) { n     tr[p][c] = now; n     p = fail[p]; n   } n   if (p == -1) n     fail[now] = 0; n   else { n     int q = tr[p][c]; n     if (len[p] + 1 == len[q]) n       fail[now] = q; n     else { n       int w = ++tot; n       len[w] = len[p] + 1; n       fail[w] = fail[q]; n       for (int i = 0; i < 26; ++i) tr[w][i] = tr[q][i]; n       fail[q] = fail[now] = w; n       while (p != -1 && tr[p][c] == q) { n         tr[p][c] = w; n         p = fail[p]; n       } n     } n   } n   last = now; n } n inline void egadd(int uu, int vv) { n   nx[++eg] = h[uu]; n   h[uu] = eg; n   v[eg] = vv; n } n long long res = 0; n void dfs(int x) { n   for (int i = h[x]; i; i = nx[i]) { n     dfs(v[i]); n     e[x] += e[v[i]]; n   } n   res += (len[x] - len[fail[x]]) * 1ll * e[x] * e[x]; n } n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     tot = last = 0; n     fail[0] = -1; n     res = 0; n     scanf( %s , c + 1); n     for (int i = 1; c[i]; ++i) insert(last, c[i]); n     int p = 0; n     for (int i = 1; c[i]; ++i) { n       p = tr[p][c[i] -  a ]; n       e[p] = 1; n     } n     for (int i = 1; i <= tot; ++i) egadd(fail[i], i); n     dfs(0); n     printf( %lld n , res); n     for (int i = 0; i <= tot; ++i) { n       fail[i] = len[i] = 0; n       h[i] = 0; n       e[i] = 0; n       for (int j = 0; j < 26; ++j) tr[i][j] = 0; n     } n     eg = 1; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000 + 3; n void read(int &x) { n   char ch; n   bool flag = 0; n   for (ch = getchar(); !isdigit(ch) && ((flag |= (ch ==  - )) || 1); n        ch = getchar()) n     ; n   for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar()) n     ; n   x *= 1 - 2 * flag; n } n string fuck[maxn]; n int edge[105][105]; n map<string, int> cou; n int a[105], b[105]; n int out = -1; n vector<string> output; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) { n     string tmp; n     cin >> tmp; n     fuck[i] = tmp; n     cou[tmp] = i; n   } n   for (int i = 0; i < m; i++) { n     string c, d; n     cin >> c >> d; n     edge[cou[c]][cou[d]] = 1; n     edge[cou[d]][cou[c]] = 1; n   } n   int aa[50]; n   for (int i = 0; i < (1 << n); i++) { n     memset(aa, 0, sizeof(aa)); n     int top = 0; n     for (int j = 0; j < n; j++) { n       if (i & (1 << j)) { n         aa[j] = 1; n         top++; n       } n     } n     bool f = 1; n     for (int j = 0; j < n; j++) { n       for (int k = j + 1; k < n; k++) { n         if (aa[j] && aa[k] && edge[j][k]) { n           f = 0; n           break; n         } n       } n     } n     if (!f) continue; n     if (top > out) { n       out = top; n       output.clear(); n       for (int j = 0; j < n; j++) { n         if (aa[j]) output.push_back(fuck[j]); n       } n     } n   } n   cout << output.size() << endl; n   sort(output.begin(), output.begin() + out); n   for (int i = 0; i < output.size(); i++) cout << output[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 10000000; n int main() { n   int n; n   string s; n   scanf( %d , &n); n   cin >> s; n   for (int i = 0; i < s.size(); i++) { n     for (int j = 1; j < 25; j++) { n       if (i + j * 4 < 100) { n         if (s[i] ==  *  && s[i + j] ==  *  && s[i + j * 2] ==  *  && n             s[i + j * 3] ==  *  && s[i + j * 4] ==  * ) { n           printf( yes ); n           return 0; n         } n       } n     } n   } n   printf( no ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void print_array(T* arr, int num) { n   for (int(i) = (0); (i) < (num); (i)++) cout << arr[i] <<    ; n   cout <<   n ; n } n template <typename T> n void print_vector(vector<T> vec) { n   for (int(i) = (0); (i) < (vec.size()); (i)++) cout << vec[i] <<    ; n   cout <<   n ; n } n void setIO() {} n int n, x, p0[5010], b0[5010], arr[5010], b[5010], p[5010]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   setIO(); n   cin >> n; n   for (int(i) = (0); (i) < (n); (i)++) { n     cout <<  ?   << 0 <<     << i <<   n ; n     cout.flush(); n     cin >> p0[i]; n   } n   for (int(i) = (0); (i) < (n); (i)++) { n     cout <<  ?   << i <<     << 0 <<   n ; n     cout.flush(); n     cin >> b0[i]; n   } n   int ans = 0; n   bitset<5010> chk; n   for (int(i) = (0); (i) < (n); (i)++) { n     chk.reset(); n     int found = 1; n     for (int(j) = (0); (j) < (n); (j)++) { n       p[j] = b0[j] ^ i; n       if (p[j] >= n || chk[p[j]]) { n         found = 0; n         break; n       } n       chk[p[j]] = 1; n     } n     if (!found) continue; n     for (int(j) = (0); (j) < (n); (j)++) b[p[j]] = j; n     for (int(j) = (0); (j) < (n); (j)++) { n       if (p0[j] != (p[0] ^ b[j]) || b0[j] != (p[j] ^ b[0])) { n         found = 0; n         break; n       } n     } n     if (found) { n       ans++; n       if (ans == 1) n         for (int(j) = (0); (j) < (n); (j)++) arr[j] = p[j]; n     } n   } n   cout <<  !  <<   n  << ans <<   n ; n   for (int(i) = (0); (i) < (n); (i)++) cout << arr[i] <<    ; n   cout.flush(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   double L, v1, v2; n   cin >> n >> L >> v1 >> v2 >> k; n   double p = 2 * (n / k - (n % k == 0)) + 1; n   printf( %.10f , double(L * (p * v2 + v1)) / double(v2 * (p * v1 + v2))); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int tt; n   cin >> tt; n   while (tt--) { n     int k; n     cin >> k; n     string s, a, b; n     cin >> s >> a >> b; n     int n = (int)(s).size(); n     vector<int> x; n     vector<int> p(k, -1); n     bool goodx = true; n     for (int i = 0; i < n; ++i) { n       int c = s[i] -  a ; n       if (p[c] != -1) { n         if (p[c] < a[i] -  a ) { n           goodx = false; n           break; n         } else if (p[c] == a[i] -  a ) { n           continue; n         } else { n           goodx = true; n           break; n         } n       } n       p[c] = a[i] -  a ; n       x.push_back(i); n     } n     bool found = false; n     for (int u = 0; u <= (int)(x).size(); ++u) { n       if (u == (int)(x).size() && !goodx) { n         continue; n       } n       p.assign(k, -1); n       vector<bool> occ(k, false); n       bool ok = true; n       for (int i = 0; i < u; ++i) { n         if (occ[a[x[i]] -  a ]) { n           ok = false; n           break; n         } n         occ[a[x[i]] -  a ] = true; n         p[s[x[i]] -  a ] = a[x[i]] -  a ; n       } n       if (u < (int)(x).size()) { n         int pos = a[x[u]] -  a  + 1; n         while (pos < k && occ[pos]) { n           ++pos; n         } n         if (pos == k) { n           ok = false; n         } else { n           p[s[x[u]] -  a ] = pos; n           occ[pos] = true; n         } n       } n       if (!ok) { n         continue; n       } n       int pos = 0; n       for (int i = 0; i < n; ++i) { n         if (p[s[i] -  a ] != -1) { n           continue; n         } n         while (occ[pos]) { n           ++pos; n         } n         p[s[i] -  a ] = pos; n         occ[pos] = true; n       } n       string res =   ; n       for (int i = 0; i < n; ++i) { n         res += char(p[s[i] -  a ] +  a ); n       } n       if (res > b) { n         continue; n       } n       found = true; n       cout <<  YES n ; n       for (int i = 0; i < k; ++i) { n         if (p[i] != -1) { n           continue; n         } n         while (occ[pos]) { n           ++pos; n         } n         p[i] = pos; n         occ[pos] = true; n       } n       for (int i = 0; i < k; ++i) { n         cout << char(p[i] +  a ); n       } n       cout <<   n ; n       break; n     } n     if (!found) { n       cout <<  NO n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct Point { n   long long x, y; n   int id; n }; n long long judge(Point p0, Point p1, Point p2) { n   return (p1.x - p0.x) * (p2.y - p1.y) - (p2.x - p1.x) * (p1.y - p0.y); n } n long long cmp(Point a, Point b) { n   if (a.x == b.x) return a.y < b.y; n   return a.x < b.x; n } n Point s[100005]; n int main() { n   int n; n   while (~scanf( %d , &n)) { n     for (int i = 1; i <= n; i++) n       scanf( %lld%lld , &s[i].x, &s[i].y), s[i].id = i; n     sort(s + 1, s + 1 + n, cmp); n     int flag, ans; n     int a = 0, b = 0, c = 0; n     for (int i = 3; i <= n; i++) { n       flag = 0, ans = 0; n       if (judge(s[1], s[2], s[i]) == 0) ans++; n       if (ans == 0) { n         a = s[1].id, b = s[2].id, c = s[i].id; n         flag = 1; n         break; n       } n     } n     printf( %d %d %d n , a, b, c); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int clique_size(vector<int> *graph, vector<int> &govs, int *visited, n                 int starting) { n   visited[starting] = 1; n   int size = 1; n   for (int i = 0; i < graph[starting].size(); i++) { n     if (!visited[graph[starting][i]]) { n       size += clique_size(graph, govs, visited, graph[starting][i]); n     } n   } n   return size; n } n int main(int argc, char *argv[]) { n   vector<int> graph[1001]; n   vector<int> govs; n   int visited[1001] = {0}; n   int n, m, k; n   cin >> n >> m >> k; n   for (int i = 0; i < k; i++) { n     int c; n     cin >> c; n     govs.push_back(c); n   } n   for (int i = 0; i < m; i++) { n     int u, v; n     cin >> u >> v; n     graph[u].push_back(v); n     graph[v].push_back(u); n   } n   int connected_points = 0; n   int max_state_size = 0; n   int answer = 0; n   for (int i = 0; i < k; i++) { n     int count = clique_size(graph, govs, visited, govs[i]); n     connected_points += count; n     max_state_size = (count > max_state_size) ? count : max_state_size; n     answer += count * (count - 1) / 2; n   } n   int remaining = n - connected_points; n   answer -= max_state_size * (max_state_size - 1) / 2; n   max_state_size += remaining; n   answer += max_state_size * (max_state_size - 1) / 2; n   cout << answer - m <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long s = 0; n   bool f = 0; n   char ch =    ; n   while (!isdigit(ch)) { n     f |= (ch ==  - ); n     ch = getchar(); n   } n   while (isdigit(ch)) { n     s = (s << 3) + (s << 1) + (ch ^ 48); n     ch = getchar(); n   } n   return (f) ? (-s) : (s); n } n inline void write(long long x) { n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   if (x < 10) { n     putchar(x +  0 ); n     return; n   } n   write(x / 10); n   putchar((x % 10) +  0 ); n   return; n } n const int N = 100005; n int n, Num, a[N]; n struct Zidianshu { n   int Trie[N * 25][25], cnt; n   int End[N * 25]; n   inline void Init() { cnt = 0; } n   inline void Insert(int Num) { n     int i, Root = 0; n     for (i = 0; i <= 23; i++) { n       int oo = (Num & (1 << i)) >> i; n       if (!Trie[Root][oo]) Trie[Root][oo] = ++cnt; n       Root = Trie[Root][oo]; n     } n     End[Root]++; n   } n   inline int Query(int Num, int Want) { n     int i, Root = 0; n     for (i = 0; i <= 23; i++) { n       int oo = ((Want & (1 << i)) >> i) ^ ((Num & (1 << i)) >> i); n       if (!Trie[Root][oo]) return 0; n       Root = Trie[Root][oo]; n     } n     return End[Root]; n   } n } Trie; n int main() { n   Trie.Init(); n   int i; n   long long ans = 0; n   n = read(); n   Num = read(); n   for (i = 1; i <= n; i++) { n     a[i] = read(); n     ans += 1ll * Trie.Query(a[i], Num); n     Trie.Insert(a[i]); n   } n   write(ans), putchar(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e9; n long long sum(long long l, long long r) { return (l + r) * (r - l + 1) / 2; } n int main() { n   long long n, H; n   cin >> n >> H; n   long long l = H, r = 2e9, ans = -1; n   while (l <= r) { n     long long mid = (l + r) >> 1; n     if (n >= sum(H, mid) + sum(1, mid) - mid) n       ans = mid, l = mid + 1; n     else n       r = mid - 1; n   } n   if (ans != -1) { n     cout << 2 * ans - H + n                 ((n - sum(H, ans) - sum(1, ans) + ans) + ans - 1) / ans n          << endl; n   } else { n     l = 1, r = min(H, N); n     while (l <= r) { n       long long mid = (l + r) >> 1; n       if (n >= sum(1, mid)) n         ans = mid, l = mid + 1; n       else n         r = mid - 1; n     } n     cout << ans + (n - sum(1, ans) + ans - 1) / ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d n , &n); n   string str; n   getline(cin, str); n   int ans = 0; n   int subans = 0; n   for (int i = 0; i < n; i++) { n     if (str[i] !=    ) { n       int ascii = (int)str[i]; n       if (ascii >= 65 && ascii <= 90) { n         subans++; n       } n       ans = max(ans, subans); n     } else { n       subans = 0; n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long s, x; n string S, X; n long long dp[64][2]; n long long d__p(int i, int st) { n   if (i == S.size() && st) n     return 0; n   else if (i == S.size()) n     return 1; n   long long &res = dp[i][st]; n   if (res != -1) return res; n   res = 0; n   int x = S[i] -  0 ; n   int y = X[i] -  0 ; n   for (int a = 0; a <= 1; a++) { n     for (int b = 0; b <= 1; b++) { n       int remember = (a + b + st) > 1; n       int Sum = a + b + st; n       Sum %= 2; n       int Xor = a ^ b; n       if (Sum != x || Xor != y) continue; n       res += d__p(i + 1, remember); n     } n   } n   return res; n } n int main() { n   cin >> s >> x; n   for (int i = 63; i >= 0; i--) { n     if (s & (1LL << i)) n       S +=  1 ; n     else n       S +=  0 ; n     if (x & (1LL << i)) n       X +=  1 ; n     else n       X +=  0 ; n   } n   reverse(S.begin(), S.end()); n   reverse(X.begin(), X.end()); n   memset(dp, -1, sizeof dp); n   cout << d__p(0, 0) - 2 * (s == x); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class DREAD { n   friend int fread(); n   static const int buff_max = 20000000 + 10; n   char buf[buff_max], *pt; n  n  public: n   void clear() { n     for (; isspace(*pt); ++pt) n       ; n   } n   void Init() { n     buf[fread(buf, 1, buff_max, stdin)] = EOF; n     pt = buf; n   } n   bool eoln() { return *pt ==   n ; } n   inline bool eof() { return *pt == EOF; } n   int Int() { n     bool pos = 1; n     int res = 0; n     for (; !isdigit(*pt) && *pt !=  -  && !eof(); ++pt) n       ; n     if (*pt ==  - ) pos = 0, ++pt; n     for (; isdigit(*pt); ++pt) res = res * 10 + (*pt -  0 ); n     return pos ? res : -res; n   } n } READ; n const int N_MAX = 5000 + 10; n int N, M, seq[N_MAX], bad[N_MAX]; n namespace Nwork { n int gcd[N_MAX]; n int GCD(int a, int b) { return b ? GCD(b, a % b) : a; } n int p[N_MAX], e[N_MAX], cnt; n int exist(int p) { return *lower_bound(bad + 1, bad + M + 1, p) == p ? -1 : 1; } n int calc(int x) { n   cnt = 0; n   for (int i = 2, k = int(sqrt(x)); i <= k; ++i) { n     if (x == 1) break; n     if (x % i == 0) { n       p[++cnt] = i; n       for (e[cnt] = 0; x % i == 0; x /= i) ++e[cnt]; n     } n   } n   if (x != 1) p[++cnt] = x, e[cnt] = 1; n   int ret = 0; n   for (int i = 1; i <= cnt; ++i) ret += exist(p[i]) * e[i]; n   return ret; n } n void main() { n   gcd[1] = seq[1]; n   for (int i = 2; i <= N; ++i) gcd[i] = GCD(gcd[i - 1], seq[i]); n   sort(bad + 1, bad + M + 1); n   for (int r = N; r >= 1; --r) n     if (calc(gcd[r]) < 0) n       for (int i = 1; i <= r; ++i) { n         seq[i] /= gcd[r]; n         gcd[i] /= gcd[r]; n       } n   int ret = 0; n   for (int i = 1; i <= N; ++i) ret += calc(seq[i]); n   printf( %d n , ret); n } n }  // namespace Nwork n namespace Ninit { n void init() { n   N = READ.Int(), M = READ.Int(); n   for (int i = 1; i <= N; ++i) seq[i] = READ.Int(); n   for (int i = 1; i <= M; ++i) bad[i] = READ.Int(); n } n }  // namespace Ninit n int main() { n   READ.Init(); n   Ninit::init(); n   Nwork::main(); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n enum { MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009 }; n template <typename T> n ostream &operator<<(ostream &cout, vector<T> &a) { n   for (size_t i = 0; i < a.size(); ++i) cout << a[i] <<    ; n   return cout; n } n template <typename T> n ostream &operator<<(ostream &cout, vector<vector<T> > &a) { n   for (size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; n   return cout; n } n int p[256]; n inline bool eq(int a, int b) { return p[a] == p[b]; } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   for (int i = 0; i < sizeof(p) / sizeof(*p); ++i) { n     p[i] = i; n   } n   p[ 1 ] = p[ i ] = p[ l ]; n   p[ 0 ] = p[ o ]; n   for (int i =  A ; i <=  Z ; ++i) { n     p[i] = p[i -  A  +  a ]; n   } n   string s; n   cin >> s; n   int n; n   cin >> n; n   string a; n   for (int i = 0; i < n; ++i) { n     cin >> a; n     if (a.size() != s.size()) { n       continue; n     } n     bool bad = 1; n     for (int j = 0; j < a.size(); ++j) { n       if (!eq(a[j], s[j])) { n         bad = 0; n         break; n       } n     } n     if (bad) { n       cout <<  No  <<   n ; n       return 0; n     } n   } n   cout <<  Yes  <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const double err = 1e-12; n const double PI = 3.141592653589793; n const int N = 1e5 + 5; n int n; n vector<int> res; n void solve() { n   cin >> n; n   if (n & 1) { n     cout << 1 <<    ; n     n--; n     for (int i = 2; i <= n; i += 2) cout << i + 1 <<     << i <<    ; n     cout << endl; n   } else { n     cout << n <<    ; n     n--; n     for (int i = 2; i <= (n - 1); i += 2) cout << i + 1 <<     << i <<    ; n     cout << 1 << endl; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int maxn = 55; n long long f[maxn][maxn][maxn][maxn]; n long long pw[maxn]; n int c[maxn]; n void init() { n   f[0][0][0][0] = 1; n   pw[0] = 1; n   for (int i = 1; i < maxn; i++) pw[i] = (pw[i - 1] * 2ll) % mod; n } n long long cal(int x, bool xx) { return x ? pw[x - 1] : xx; } n void cal_ans(int ew, int ow, int eb, int ob, int now, long long& ret) { n   if (now != 0 && ew) n     (ret += f[ew - 1][ow][eb][ob] * pw[ew + ow - 1 + eb] % mod * cal(ob, 0) % n             mod) %= mod; n   if (now != 0 && ow) n     (ret += f[ew][ow - 1][eb][ob] * pw[ew + ow - 1 + eb] % mod * cal(ob, 1) % n             mod) %= mod; n   if (now != 1 && eb) n     (ret += f[ew][ow][eb - 1][ob] * pw[eb + ob - 1 + ew] % mod * cal(ow, 0) % n             mod) %= mod; n   if (now != 1 && ob) n     (ret += f[ew][ow][eb][ob - 1] * pw[eb + ob - 1 + ew] % mod * cal(ow, 1) % n             mod) %= mod; n } n int main(int argc, const char** argv) { n   init(); n   int n, p; n   cin >> n >> p; n   for (int i = 1; i <= n; i++) scanf( %d , c + i); n   long long ans = 0; n   for (int i = 1; i <= n; i++) n     for (int ew = 0; ew <= i; ew++) n       for (int ow = 0; ow + ew <= i; ow++) n         for (int eb = 0; ow + ew + eb <= i; eb++) { n           int ob = i - ow - ew - eb; n           cal_ans(ew, ow, eb, ob, c[i], f[ew][ow][eb][ob]); n           if (i == n && ((ow + ob) & 1) == p) (ans += f[ew][ow][eb][ob]) %= mod; n         } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 6; n vector<int> G[N]; n int d[N]; n void dfs(int u, int f, int dep) { n   d[u] = dep; n   for (int i = 0, iend = G[u].size(); i < iend; ++i) { n     int v = G[u][i]; n     if (v != f) dfs(v, u, dep + 1); n   } n } n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     int n, a, b, da, db; n     scanf( %d%d%d%d%d , &n, &a, &b, &da, &db); n     for (int i = 1; i <= n; ++i) G[i].clear(); n     for (int i = 1; i <= n - 1; ++i) { n       int u, v; n       scanf( %d%d , &u, &v); n       G[u].push_back(v), G[v].push_back(u); n     } n     if (2 * da >= db) { n       puts( Alice ); n       continue; n     } n     dfs(1, 0, 0); n     int u = 0; n     for (int i = 1; i <= n; ++i) n       if (d[i] > d[u]) u = i; n     dfs(u, 0, 0); n     int mx = 0; n     for (int i = 1; i <= n; ++i) mx = max(mx, d[i]); n     if (da >= (mx + 1) / 2) { n       puts( Alice ); n       continue; n     } n     dfs(a, 0, 0); n     puts(da >= d[b] ?  Alice  :  Bob ); n   } n   return 0; n } n


#include<bits/stdc++.h> n #define int long long n #define f first n #define s second n #define N 1010 n #define M 1010 n #define MOD 998244353 n #define oo 1e18 n using namespace std; n typedef pair<int,int> ii; n int v[N][N], estado[N]; n set<int>freq[N][N]; n int n; n void eraseLine(int line, queue<int>&unique) { n     for(int c=0; c<n; c++) { n         int val = v[line][c]; n         freq[c][val].erase(line); n         if(freq[c][val].size() == 1) { n             int line = *freq[c][val].begin(); n             unique.push(line); n             freq[c][val].clear(); n         } n     } n } n int32_t main() { n     int t; cin >> t; n     while(t--) { n         cin >> n; n         for(int l=0; l<2*n; l++) { n             estado[l] = 0; n             for(int i=0; i<=n; i++) { n                 freq[l][i].clear(); n             } n         } n          n         for(int l=0; l<2*n; l++) { n             for(int c=0; c<n; c++) { n                 cin >> v[l][c]; n                 freq[c][v[l][c]].insert(l); n             } n         } n         queue<int>unique; n         for(int c=0; c<n; c++) { n             for(int i=1; i<=n; i++) { n                 if(freq[c][i].size() == 1) { n                     int line = *freq[c][i].begin(); n                     unique.push(line); n                     freq[c][i].clear(); n                 } n             } n         } n  n         int quantityAnswers = 1; n         vector<int>example; n  n         while(example.size() != n) { n             int choosenLine = -1; n             if(unique.size()) { n                 choosenLine = unique.front(); n                 unique.pop(); n                 if(estado[choosenLine]) continue; n             } else { n                 quantityAnswers *= 2; n                 quantityAnswers %= MOD; n                  n                 choosenLine = -1; n                 for(int l=0; l<=2*n; l++) { n                     if(estado[l]) continue; n                     choosenLine = l; n                     break; n                 } n             } n  n             estado[choosenLine] = 2; n             example.push_back(choosenLine); n             for(int curLine=0; curLine<2*n; curLine++) { n                 if(estado[curLine]) continue; n                 for(int c=0; c<n; c++) { n                     if(v[choosenLine][c] == v[curLine][c]) { n                         estado[curLine] = 1; n                         break; n                     } n                 } n  n                 if(estado[curLine]) { n                     eraseLine(curLine, unique); n                 } n             } n             eraseLine(choosenLine, unique); n         } n  n         sort(example.begin(), example.end()); n         cout << quantityAnswers << endl; n         for(int val:example) cout << val + 1 <<    ; n         cout << endl; n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using ii = pair<ll, ll>; n using vi = vector<ll>; n using vb = vector<bool>; n using vvi = vector<vi>; n using vii = vector<ii>; n using vvii = vector<vii>; n constexpr int INF = 2000000000; n constexpr ll LLINF = 9000000000000000000; n struct abc { n   ll a, b, c; n }; n ll remove_from_front(map<ll, ll> &pareto, ll a, ll b, ll ma, ll mb) { n   auto ait = pareto.find(a); n   pareto.erase(ait); n   auto it = pareto.lower_bound(a); n   mb = max(mb, it->second); n   --it; n   ma = max(ma, it->first); n   return max(0LL, a - ma) * max(0LL, b - mb); n } n ll insert_in_front(map<ll, ll> &pareto, ll a, ll b, ll ma, ll mb) { n   ll ret = 0LL; n   while (true) { n     auto it = pareto.lower_bound(a); n     if (it->second >= b) return 0LL; n     while (it->first > a) --it; n     if (it->second > b) break; n     ll ra = it->first, rb = it->second; n     ret += remove_from_front(pareto, ra, rb, ma, mb); n   } n   auto it = pareto.lower_bound(a); n   mb = max(mb, it->second); n   --it; n   ma = max(ma, it->first); n   ret -= max(0LL, a - ma) * max(0LL, b - mb); n   pareto.insert({a, b}); n   return ret; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   ll p, q, r; n   cin >> n >> p >> q >> r; n   vector<abc> vs(n, {0, 0, 0}); n   for (abc &v : vs) cin >> v.a >> v.b >> v.c; n   sort(vs.begin(), vs.end(), n        [](const abc &l, const abc &r) { return l.c < r.c; }); n   vi amax(n, 0LL), bmax(n, 0LL); n   amax.back() = vs.back().a; n   bmax.back() = vs.back().b; n   for (int i = n - 2; i >= 0; --i) n     amax[i] = max(amax[i + 1], vs[i].a), bmax[i] = max(bmax[i + 1], vs[i].b); n   ll cur = (p - amax[0]) * (q - bmax[0]), ans = 0LL; n   map<ll, ll> pareto; n   pareto.insert({0LL, q + 1LL}); n   pareto.insert({p + 1LL, 0LL}); n   int i = 0; n   for (ll c = 1LL; c <= r; ++c) { n     ans += cur; n     for (; i < n && vs[i].c == c; ++i) { n       ll ai = vs[i].a, bi = vs[i].b; n       cur += insert_in_front(pareto, ai, bi, amax[i], bmax[i]); n       ll af = amax[i], bf = bmax[i]; n       ll at = (i + 1 < n ? amax[i + 1] : 0LL), n          bt = (i + 1 < n ? bmax[i + 1] : 0LL); n       if (af == at && bf == bt) continue; n       auto it = pareto.lower_bound(af); n       while (it->first > at) { n         auto it2 = it; n         --it2; n         ll h = it->second; n         cur += (min(af, it->first) - max(at, it2->first)) * (q - max(h, bf)); n         it = it2; n       } n       ll l = 0LL, r = p; n       while (l < r) { n         ll m = (l + r + 1) / 2LL; n         auto it = pareto.lower_bound(m); n         if (it->second > bf) n           l = m; n         else n           r = m - 1; n       } n       it = pareto.lower_bound(l); n       while (it->second > bt) { n         auto it2 = it; n         ++it2; n         ll h = it->first; n         cur += (min(bf, it->second) - max(bt, it2->second)) * (p - max(h, at)); n         it = it2; n       } n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n; n   std::cin >> n; n   int a[n][n]; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) std::cin >> a[i][j]; n   int sum = 0; n   int l = (n - 1) / 2, j = n - 1; n   for (int i = 0; i < n; i++) { n     sum = sum + a[i][l] + a[l][i] + a[i][i] + a[i][j--]; n   } n   sum = sum - 3 * a[l][l]; n   std::cout << sum; n } n


#include <bits/stdc++.h> n const int mxn = 1 << 19, mod = 998244353; n inline int qpow(int x, int n) { n   int ans = 1; n   for (; n; n >>= 1, x = 1LL * x * x % mod) n     if (n & 1) ans = 1LL * ans * x % mod; n   return ans; n } n int r[mxn], w[mxn]; n void fft_init(int n) { n   for (int i = 1; i < n - 1; ++i) r[i] = r[i >> 1] >> 1 | (i & 1 ? n >> 1 : 0); n   for (int h = 1; h < n; h <<= 1) { n     int temp = qpow(3, (mod - 1) / (h << 1)); n     for (int i = 0; i < (int)(h); ++i) n       w[h + i] = i ? 1LL * temp * w[h + i - 1] % mod : 1; n   } n } n void fft(int a[], int n, bool flag = false) { n   fft_init(n); n   for (int i = 1; i < n - 1; ++i) n     if (i < r[i]) std::swap(a[i], a[r[i]]); n   for (int h = 1; h < n; h <<= 1) n     for (int i = 0; i < n; i += h << 1) n       for (int j = 0; j < h; ++j) { n         int v = 1LL * a[i + h + j] * w[h + j] % mod; n         a[i + h + j] = a[i + j] - v >= 0 ? a[i + j] - v : a[i + j] + mod - v; n         a[i + j] = a[i + j] + v < mod ? a[i + j] + v : a[i + j] + v - mod; n       } n   if (flag) { n     std::reverse(a + 1, a + n); n     int in = qpow(n, mod - 2); n     for (int i = 0; i < (int)(n); ++i) a[i] = 1LL * a[i] * in % mod; n   } n } n struct poly : std::vector<int> { n   poly(int n, int x = 0) { assign(n, x); } n   poly(std::initializer_list<int> l) { n     clear(); n     for (int x : l) push_back(x); n   } n   friend inline poly operator*(const poly &a, const poly &b) { n     int sz = 1; n     while (sz < (int)a.size() + (int)b.size() - 1) sz <<= 1; n     static int A[mxn], B[mxn]; n     for (int i = 0; i < (int)(sz); ++i) A[i] = i < (int)a.size() ? a[i] : 0; n     for (int i = 0; i < (int)(sz); ++i) B[i] = i < (int)b.size() ? b[i] : 0; n     fft(A, sz), fft(B, sz); n     for (int i = 0; i < (int)(sz); ++i) A[i] = 1LL * A[i] * B[i] % mod; n     fft(A, sz, true); n     poly c(a.size() + b.size() - 1); n     for (int i = 0; i < (int)(c.size()); ++i) c[i] = A[i]; n     return c; n   } n }; n int n; n int deg[mxn]; n int fac[mxn]; n poly calc(int l, int r) { n   if (l + 1 == r) return {1, deg[l]}; n   int m = (l + r) >> 1; n   return calc(l, m) * calc(m, r); n } n int main() { n   for (int i = 0; i < (int)(mxn); ++i) n     fac[i] = i ? 1LL * i * fac[i - 1] % mod : 1; n   scanf( %d , &n); n   for (int i = 0; i < (int)(n - 1); ++i) { n     int u, v; n     scanf( %d %d , &u, &v); n     --u, --v; n     ++deg[u]; n     ++deg[v]; n   } n   for (int i = 0; i < (int)(n); ++i) n     if (i) --deg[i]; n   poly p = calc(0, n); n   int ans = 0; n   for (int i = 0; i < (int)(p.size()); ++i) { n     int cur = 1LL * p[i] * fac[n - i] % mod; n     if (i & 1) n       ans = (ans + mod - cur) % mod; n     else n       ans = (ans + cur) % mod; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 40; n long long int dp[maxn][maxn], P[maxn], par[maxn][maxn]; n string s; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   P[0] = 1; n   for (int i = 1; i < maxn; i++) P[i] = P[i - 1] * 10; n   cin >> s >> s; n   for (int i = ((int)(s).size()) - 1; i >= 0; i--) { n     for (int j = 0; j <= ((int)(s).size()) - i; j++) { n       long long int pnt1, pnt2; n       if (j == 0) n         dp[i][j] = dp[i + 1][j] + (s[i] -  0 ) * P[((int)(s).size()) - i - 1], n         par[i][j] = j; n       else if (j == ((int)(s).size()) - i) n         dp[i][j] = dp[i + 1][j - 1] + (s[i] -  0 ) * P[j - 1], n         par[i][j] = j - 1; n       else if ((pnt1 = dp[i + 1][j - 1] + (s[i] -  0 ) * P[j - 1]) > n                (pnt2 = dp[i + 1][j] + n                        (s[i] -  0 ) * P[((int)(s).size()) - i - j - 1])) n         dp[i][j] = pnt1, par[i][j] = j - 1; n       else n         dp[i][j] = pnt2, par[i][j] = j; n     } n   } n   int row = 0, col = ((int)(s).size()) / 2; n   while (row < ((int)(s).size())) { n     if (par[row][col] == col) n       cout <<  H ; n     else n       cout <<  M ; n     col = par[row][col]; n     row++; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n int b[5005], cnt, pr[800], f[800][5001], n, at[5005], sum[800][5001]; n long long ans; n int ss[5005], tmp[5005], sa, st; n int main() { n   for (int i = 2; i <= 5000; i++) { n     if (b[i]) continue; n     for (int j = 2; j * i <= 5000; j++) b[i * j] = 1; n   } n   for (int i = 2; i <= 5000; i++) n     if (b[i] == 0) pr[++cnt] = i; n   for (int i = 1; i <= cnt; i++) { n     for (int j = 1; j <= 5000; j++) { n       if (j >= pr[i]) f[i][j] = j / pr[i] + f[i][j / pr[i]]; n       sum[i][j] = sum[i - 1][j] + f[i][j]; n     } n   } n   scanf( %d , &n); n   for (int i = 1, x; i <= n; i++) { n     scanf( %d , &x); n     if (x == 0) x = 1; n     ++at[x]; n     ans += sum[cnt][x]; n   } n   for (int i = 1; i <= 5000; i++) n     if (at[i]) ss[++sa] = i; n   for (int i = cnt; i >= 1;) { n     int s = 0, minn = 0x7fffffff; n     st = 0; n     for (int j = 1, a; j <= sa; j++) { n       a = ss[j]; n       if (f[i][a]) s += at[a], minn = min(minn, f[i][a]); n     } n     if (s > n - s) { n       ans -= 1ll * minn * (s - n + s); n       for (int j = 1, a; j <= sa; j++) { n         a = ss[j]; n         if (f[i][a]) f[i][a] -= minn, tmp[++st] = a; n       } n       for (int i = 1; i <= st; i++) ss[i] = tmp[i]; n       sa = st; n     } else if (n - s > s) { n       for (int j = 1, a; j <= sa; j++) { n         a = ss[j]; n         if (!f[i][a]) tmp[++st] = a; n       } n       for (int i = 1; i <= st; i++) ss[i] = tmp[i]; n       sa = st; n       --i; n     } else { n       break; n     } n   } n   printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long M = 200100; n long long b[M]; n long long fre[M]; n int main() { n   long long n; n   cin >> n; n   vector<long long> a(n); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     b[a[i]]++; n     fre[b[a[i]]]++; n   } n   long long q; n   cin >> q; n   while (q--) { n     char s; n     long long x; n     cin >> s >> x; n     if (s ==  + ) { n       b[x]++; n       fre[b[x]]++; n     } else { n       assert(b[x] > 0); n       fre[b[x]]--; n       b[x]--; n     } n     if ((fre[8] > 0) || (fre[4] >= 2) || (fre[2] >= 2 && fre[6] > 0) || n         (fre[2] >= 3 && fre[4] > 0)) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n #define int long long int n const int INF = 1e9 + 7; n using namespace std; n const int m = 1e9 + 7; n  n signed main() n { n  ios_base::sync_with_stdio(false); n  cin.tie(0); n  int t; n  cin >> t; n  while (t--) n  { n   int n; n   cin >> n; n   string a[n], b[n]; n   for (int i = 0; i < n; i++) n    cin >> a[i]; n   for (int i = 0; i < n; i++) n    cin >> b[i]; n   for (int j = 0; j < n; j++) n   { n    if (a[0][j] != b[0][j]) n    { n     for (int i = 0; i < n; i++) n     { n      a[i][j] ^= 1; n     } n    } n   } n   for (int i = 1; i < n; i++) n   { n    for (int j = 1; j < n; j++) n    { n     if (a[i][j] != b[i][j]) n     { n      for (int j = 0; j < n; j++) n       a[i][j] ^= 1; n     } n    } n   } n   bool ans = true; n   for (int i = 0; i < n; i++) n   { n    for (int j = 0; j < n; j++) n     if (a[i][j] != b[i][j]) n     { n      ans = false; n      break; n     } n    if (ans == false) n     break; n   } n   if (ans) n    cout <<  YES n ; n   else n    cout <<  NO n ; n  } n  n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int maxlen = 81; n char s[maxlen]; n int base; n long long int greedy(int r) { n   if (!r) return 0; n   int l = r; n   long long val = 0, t = 1; n   for (int i = r; i >= 1 && t < base; --i, t *= 10) n     if (val + (s[i] -  0 ) * t < base) { n       val += (s[i] -  0 ) * t; n       if (s[i] !=  0 ) l = i; n     } else n       break; n   return greedy(l - 1) * base + val; n } n int main() { n   scanf( %d%s , &base, s + 1); n   cout << greedy(strlen(s + 1)) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 100000; n long long l[MX], a[MX + 1], mn[MX + 1]; n char s[MX + 1]; n int main() { n   int n; n   ignore = scanf( %d , &n); n   for (int i = 0; i < n; i++) ignore = scanf( %lld , l + i); n   ignore = scanf( %s , s); n   long long e = 0, ans = 0; n   for (int i = 0, p = 5; i < n; i++) { n     a[i] = e; n     if (s[i] ==  G ) { n       ans += 5 * l[i]; n       e += l[i]; n     } else if (s[i] ==  W ) { n       ans += 3 * l[i]; n       e += l[i]; n       p = 3; n     } else { n       long long f = min(l[i], e); n       ans += l[i] + (l[i] - f) * p; n       e -= f; n     } n     a[i + 1] = e; n   } n   auto opt = [&](char c, int t) { n     mn[n] = a[n]; n     for (int i = n - 1; i >= 0; i--) mn[i] = min(mn[i + 1], a[i]); n     long long delta = 0; n     for (int i = 0; i < n; i++) { n       if (s[i] == c) { n         long long x = min(mn[i + 1] - delta, 2 * l[i]); n         ans -= x * (t - 1) / 2; n         delta += x; n       } n       a[i + 1] -= delta; n     } n   }; n   opt( G , 5); n   opt( W , 3); n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long ax, ay, bx, by, tx, ty; n int n; n long long x[110000]; n long long y[110000]; n long double solve(int cnt) { n   long double res = 0; n   int p = 0; n   long double v = sqrt((x[0] - ax) * (x[0] - ax) + (y[0] - ay) * (y[0] - ay)) - n                   sqrt((x[0] - tx) * (x[0] - tx) + (y[0] - ty) * (y[0] - ty)); n   for (int i = 1; i < n; ++i) { n     long double cur = n         sqrt((x[i] - ax) * (x[i] - ax) + (y[i] - ay) * (y[i] - ay)) - n         sqrt((x[i] - tx) * (x[i] - tx) + (y[i] - ty) * (y[i] - ty)); n     if (cur < v) v = cur, p = i; n   } n   res += v; n   if (cnt == 1) return res; n   int q = 0; n   v = sqrt((x[0] - bx) * (x[0] - bx) + (y[0] - by) * (y[0] - by)) - n       sqrt((x[0] - tx) * (x[0] - tx) + (y[0] - ty) * (y[0] - ty)); n   for (int i = 1; i < n; ++i) { n     if (i == p) continue; n     long double cur = n         sqrt((x[i] - bx) * (x[i] - bx) + (y[i] - by) * (y[i] - by)) - n         sqrt((x[i] - tx) * (x[i] - tx) + (y[i] - ty) * (y[i] - ty)); n     if (cur < v || p == q) v = cur, q = i; n   } n   res += v; n   return res; n } n int main() { n   ios::sync_with_stdio(0); n   cin >> ax >> ay >> bx >> by >> tx >> ty; n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> x[i] >> y[i]; n   if (n == 1) { n     long double v = sqrt((x[0] - tx) * (x[0] - tx) + (y[0] - ty) * (y[0] - ty)); n     cout << setprecision(10) << fixed n          << min(sqrt((x[0] - ax) * (x[0] - ax) + (y[0] - ay) * (y[0] - ay)), n                 sqrt((x[0] - bx) * (x[0] - bx) + (y[0] - by) * (y[0] - by))) + n                 v n          <<   n ; n     return 0; n   } n   long double ans = 0; n   for (int i = 0; i < n; ++i) n     ans += 2.0 * sqrt((x[i] - tx) * (x[i] - tx) + (y[i] - ty) * (y[i] - ty)); n   long double res = ans + solve(1); n   res = min(res, ans + solve(2)); n   swap(ax, bx); n   swap(ay, by); n   res = min(res, ans + solve(1)); n   res = min(res, ans + solve(2)); n   cout << setprecision(10) << fixed << res <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b; n   cin >> a >> b; n   int result = a; n   int temp = 0; n   while ((a + temp) >= b) { n     int t1 = temp; n     result += (a + temp) / b; n     temp = (a + temp) % b; n     a = (a + t1) / b; n   } n   cout << result << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100000 + 10; n struct node { n   int x, h; n   int num; n   int ans; n }; n node a[maxn]; n int ans[maxn]; n stack<int> s; n int n; n void init() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     a[i].num = i; n     cin >> a[i].x >> a[i].h; n   } n } n bool cmp1(const node &a, const node &b) { return a.x < b.x; } n bool cmp2(const node &a, const node &b) { return a.num < b.num; } n void solve() { n   s.push(n); n   a[n].ans = 1; n   for (int i = n - 1; i >= 1; i--) { n     int j = i; n     while (!s.empty() && a[i].x + a[i].h > a[s.top()].x) { n       j = s.top(); n       s.pop(); n     } n     s.push(i); n     if (j == i) n       a[i].ans = 1; n     else n       a[i].ans = j - i + a[j].ans; n   } n   sort(a + 1, a + 1 + n, cmp2); n   for (int i = 1; i < n; i++) cout << a[i].ans <<    ; n   cout << a[n].ans << endl; n } n int main() { n   init(); n   sort(a + 1, a + 1 + n, cmp1); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100000 + 50; n const int X = 1024; n int n, k, x; n int arr[N]; n int freq[X], freq2[X]; n inline void brute() { n   int seen_till = 0; n   for (int i = 0; i < X; i++) { n     if (freq[i] != 0) { n       if (!seen_till) { n         int dec = (freq[i] + 1) / 2; n         freq2[i ^ x] += dec; n         freq2[i] += (freq[i] - dec); n       } else { n         int dec = (freq[i]) / 2; n         freq2[i ^ x] += dec; n         freq2[i] += (freq[i] - dec); n       } n     } n     seen_till += freq[i]; n     seen_till %= 2; n   } n   for (int i = 0; i < X; i++) { n     freq[i] = freq2[i]; n   } n   memset(freq2, 0, sizeof freq2); n } n int main() { n   ios ::sync_with_stdio(false); n   cin >> n >> k >> x; n   for (int i = 1; i <= n; i++) { n     cin >> arr[i]; n     freq[arr[i]]++; n   } n   while (k--) { n     brute(); n   } n   int mn = 1e9, mx = -1; n   for (int i = 0; i < X; i++) { n     if (freq[i] != 0) { n       if (i < mn) mn = i; n       if (i > mx) mx = i; n     } n   } n   cout << mx <<     << mn << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, OO = 1e8; n int dp[100001]; n int solve(int x) { n   if (x <= 0 || x > 1e5) return OO; n   if (x == m) return 0; n   int &ret = dp[x]; n   if (ret != -1) return ret; n   ret = OO; n   if (x > m) n     ret = min(ret, 1 + solve(x - 1)); n   else { n     ret = min(ret, 1 + solve(x * 2)); n     ret = min(ret, 1 + solve(x - 1)); n   } n   return ret; n } n int main() { n   cin >> n >> m; n   memset(dp, -1, sizeof(dp)); n   cout << solve(n) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353; n vector<int> *mapo; n long long Montgomery(long long a, long long b) { n   long long ans = 1; n   a = a % mod; n   while (b > 0) { n     if (b & 1) ans = ans * a % mod; n     b >>= 1; n     a = a * a % mod; n   } n   return ans; n } n bool inQueue[size_t(3e5 + 10)]; n int status[size_t(3e5 + 10)]; n long long dfs_detect_possibility(int, int); n int main() { n   int t; n   scanf( %d , &t); n   for (int i = 0; i < t; ++i) { n     int n, m; n     scanf( %d%d , &n, &m); n     fill(inQueue, inQueue + n + 2, false); n     fill(status, status + n + 2, -1); n     vector<int> links[n + 1]; n     mapo = links; n     for (int j = 0; j < m; ++j) { n       int t1, t2; n       scanf( %d%d , &t1, &t2); n       links[t1].push_back(t2); n       links[t2].push_back(t1); n     } n     long long ans = 1; n     for (int j = 1; j <= n; j++) { n       if (inQueue[j]) continue; n       ans = ans * dfs_detect_possibility(n, j) % mod; n     } n     cout << ans << endl; n   } n   return 0; n } n long long dfs_detect_possibility(int n, int st) { n   int same = 1; n   status[st] = 1; n   queue<int> q; n   q.push(st); n   inQueue[st] = true; n   long long dans = 1; n   int cnt = 1; n   while (!q.empty()) { n     int poi = q.front(); n     q.pop(); n     for (int &i : mapo[poi]) { n       if (status[i] == status[poi]) { n         return 0; n       } else if (status[i] == -1) { n         cnt++; n         if (status[poi] == 1) n           status[i] = 0; n         else { n           status[i] = 1; n           same++; n         } n         q.push(i); n         inQueue[i] = true; n       } n     } n   } n   dans = Montgomery(2, same) + Montgomery(2, cnt - same); n   return dans % mod; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, y, x1, y1, a, b, c, d, e; n   cin >> x >> y >> x1 >> y1; n   a = x1 - x; n   b = y1 - y; n   { n     if (a < 0) { n       c = (-1) * a; n     } else n       c = a; n   } n   { n     if (b < 0) { n       d = (-1) * b; n     } else n       d = b; n   } n   e = max(d, c); n   cout << e; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int infint = 1e9; n const long long inf = 1e18; n const int MOD = (int)1e9 + 7; n const int MAXN = (int)3e5 + 7; n const int LOG = 17; n int a[MAXN], n, IL[MAXN], IR[MAXN], Lp, Rp, ans, L, R; n pair<int, int> G, seg[LOG][2 * MAXN]; n pair<int, int> operator*(const pair<int, int> &a, pair<int, int> b) { n   return {min(a.first, b.first), max(a.second, b.second)}; n } n void update(int BASE, int idx, int x, int y) { n   for (seg[BASE][idx += 3 * n] = {x, y}; idx > 1; idx >>= 1) n     seg[BASE][idx >> 1] = seg[BASE][idx] * seg[BASE][idx ^ 1]; n } n pair<int, int> get(int BASE, int l, int r) { n   pair<int, int> res = {3 * n, 0}; n   for (l += 3 * n, r += 3 * n; l < r; l >>= 1, r >>= 1) { n     if (l & 1) res = res * seg[BASE][l++]; n     if (r & 1) res = res * seg[BASE][--r]; n   } n   return res; n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , &a[i]); n   for (int i = n; i < 3 * n; i++) a[i] = a[i % n]; n   for (int i = 0; i < LOG; i++) n     for (int j = 0; j < MAXN; j++) seg[i][j] = {3 * n, 0}; n   for (int i = 0; i < 3 * n; i++) { n     update(0, i, max(0, i - a[i]), min(i + a[i], 3 * n - 1)); n     IL[i] = max(0, i - a[i]), IR[i] = min(i + a[i], 3 * n - 1); n   } n   for (int i = 1; i < LOG; i++) { n     for (int j = 0; j < 3 * n; j++) { n       G = get(i - 1, IL[j], IR[j] + 1); n       Lp = G.first, Rp = G.second; n       IL[j] = Lp, IR[j] = Rp; n       update(i, j, Lp, Rp); n     } n   } n   if (n == 1) return cout << 0, 0; n   for (int j = n; j < 2 * n; j++) { n     ans = 0, L = j, R = j; n     for (int lg = 16; lg >= 0; lg--) { n       G = get(lg, L, R + 1); n       if (G.second - G.first + 1 < n) { n         ans += (1 << lg); n         Lp = G.first, Rp = G.second; n         L = Lp, R = Rp; n       } n     } n     printf( %d  , ans + 1); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, n; n   double res, t = 1e99; n   cin >> a >> b >> n; n   int x, y, v; n   int i; n   for (i = 0; i < n; i++) { n     cin >> x >> y >> v; n     res = hypot(x - a + 0., y - b + 0.) / v; n     t = min(t, res); n   } n   printf( %.10f n , t); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n /* * * *   * * *    * * * */ n #define mp make_pair n typedef long long ll; n typedef long double ld; n typedef pair<int, int> pii; n /* * * *   * * *    * * * */ n /* * n  * n  * Too many mind, no mind. n  * n  * */ n bool can(int med, int k, vector <int> &a) { n  int n = a.size(); n  vector <int> pre(n), mn(n); n  for (int i = 0; i < n; ++i) pre[i] = a[i] < med ? -1 : 1; n  mn[0] = pre[0]; n  for (int i = 1; i < k; ++i) { n   pre[i] += pre[i - 1]; n   mn[i] = min(pre[i], mn[i - 1]); n  } n  if (pre[k - 1] > 0) return 1; n  for (int i = k; i < n; ++i) { n   pre[i] += pre[i - 1]; n   mn[i] = min(pre[i], mn[i - 1]); n   if (mn[i - k] <= pre[i] - 1 || pre[i] > 0) return 1; n  } n  return 0; n } n int main(){ n  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n  //freopen( input.txt ,  r , stdin); n  //freopen( output.txt ,  w , stdout); n  int n, k; cin >> n >> k; n  vector <int> a(n); n  for (int i = 0; i < n; ++i) cin >> a[i]; n  int lo = 1, hi = n; n  while (lo < hi) { n   int mid = lo + (hi - lo + 1) / 2; n   if (can(mid, k, a)) lo = mid; n   else hi = mid - 1; n  } n  cout << lo <<   n ; n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 22; n int cache[1 << N]; n int next_element[1 << N]; n int already_done(const vector<int>& adj); n int memo(int set, const vector<int>& adj); n int main() { n   int n, m; n   cin >> n >> m; n   vector<int> adj(n); n   for (int i = 0; i < m; i++) { n     int u, v; n     cin >> u >> v; n     u--; n     v--; n     adj[u] |= 1 << v; n     adj[v] |= 1 << u; n   } n   for (int i = 0; i < n; i++) adj[i] |= 1 << i; n   if (already_done(adj)) { n     cout <<  0 n ; n     return 0; n   } n   cout << memo(0, adj) <<   n ; n   int set = 0; n   while (cache[set]) { n     cout << next_element[set] + 1 <<    ; n     int n = next_element[set]; n     set = set | (1 << n) | adj[n]; n   } n } n int already_done(const vector<int>& adj) { n   int all = (1 << adj.size()) - 1; n   for (int i = 0; i < adj.size(); i++) n     if (adj[i] != all) { n       return false; n     } n   return true; n } n int memo(int set, const vector<int>& adj) { n   if (cache[set]) return cache[set]; n   int& ret = cache[set] = adj.size(); n   if (set == (1 << adj.size()) - 1) return ret = 0; n   for (int i = 0; i < adj.size(); i++) n     if ((set & (1 << i)) && (set | adj[i]) != set || set == 0) { n       int next_set = set | (1 << i) | adj[i]; n       int now = 1 + memo(next_set, adj); n       if (now < ret) { n         ret = now; n         next_element[set] = i; n       } n     } n   return ret; n } n