#include <bits/stdc++.h> n using namespace std; n inline int ni() { n   int a; n   scanf( %d , &a); n   return a; n } n inline double nf() { n   double a; n   scanf( %lf , &a); n   return a; n } n template <class T> n void out(T a, T b) { n   bool first = true; n   for (T i = a; i != b; i++) { n     if (!first) printf(   ); n     first = false; n     cout << *i; n   } n   puts(  ); n } n template <class T> n void outl(T a, T b) { n   for (T i = a; i != b; i++) cout << *i <<   n ; n } n const int MAXN = 5010; n int gcd(int x, int y) { n   while (x) { n     y %= x; n     swap(x, y); n   } n   return y; n } n int n, m; n int a[MAXN], b[MAXN], g[MAXN]; n long long d[MAXN]; n long long balance[MAXN], gb[MAXN]; n int main() { n   n = ni(); n   m = ni(); n   for (int i = 0; i < (int)(n); i++) a[i] = ni(); n   for (int i = 0; i < (int)(m); i++) b[i] = ni(); n   sort(b, b + m); n   g[0] = a[0]; n   for (int i = 1; i < n; i++) g[i] = gcd(g[i - 1], a[i]); n   for (int i = 0; i < (int)(n); i++) { n     int c = a[i]; n     for (int j = 2; j * j <= c; j++) { n       if (c % j) continue; n       bool flag = binary_search(b, b + m, j); n       while (c % j == 0) { n         if (flag) n           balance[i]--; n         else n           balance[i]++; n         c /= j; n       } n     } n     if (c != 1) { n       bool flag = binary_search(b, b + m, c); n       if (flag) n         balance[i]--; n       else n         balance[i]++; n     } n   } n   for (int i = 0; i < (int)(n); i++) { n     int c = g[i]; n     for (int j = 2; j * j <= c; j++) { n       if (c % j) continue; n       bool flag = binary_search(b, b + m, j); n       while (c % j == 0) { n         if (flag) n           gb[i]--; n         else n           gb[i]++; n         c /= j; n       } n     } n     if (c != 1) { n       bool flag = binary_search(b, b + m, c); n       if (flag) n         gb[i]--; n       else n         gb[i]++; n     } n   } n   for (int i = n - 1; i >= 0; i--) { n     d[i] = -(1LL << 60); n     long long sum = 0; n     for (int j = i; j < n; j++) { n       sum += balance[j]; n       d[i] = max(d[i], d[j + 1] + sum - ((j - i + 1) * 1LL) * gb[j]); n     } n     d[i] = max(d[i], sum); n   } n   cout << d[0] << endl; n } n


#include <bits/stdc++.h> n const int INF_INT = 0x3f3f3f3f; n const long long INF_LL = 0x7f7f7f7f; n const int MOD = 1e9 + 7; n const double eps = 1e-10; n const double pi = acos(-1); n using namespace std; n int n; n int a[30]; n int vis[30]; n bool dfs(int root, int cnt, int son) { n   if (root == n + 1) return true; n   if (cnt + 1 == a[root]) { n     if (son != 1 && dfs(root + 1, 0, 0)) return true; n     return false; n   } n   int same = 0; n   for (int i = 1; i <= n; i++) { n     if (!vis[i] && cnt + a[i] < a[root] && a[i] != same) { n       same = a[i]; n       vis[i] = 1; n       if (dfs(root, cnt + a[i], son + 1)) return true; n       vis[i] = 0; n     } n   } n   return false; n } n int main(int argc, char const *argv[]) { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   sort(a + 1, a + 1 + n); n   memset(vis, 0, sizeof(vis)); n   if (a[n] != n) n     puts( NO ); n   else { n     if (dfs(1, 0, 0)) n       puts( YES ); n     else n       puts( NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int arrx[100]; n long long int arry[100]; n long long int arr[10000]; n map<long long int, bool> M; n void parr(long long int a[], long long int n); n int main() { n   long long int x, y, l, r, ss, siz, sizx, sizy, mulx, muly, start, ans, fin, n       ran, tempx, tempy, i, j, temp; n   bool fx, fy; n   scanf( %lld , &x); n   scanf( %lld , &y); n   scanf( %lld , &l); n   scanf( %lld , &r); n   sizx = 0; n   sizy = 0; n   mulx = 1; n   muly = 1; n   tempx = r / x; n   tempy = r / y; n   fx = 1; n   fy = 1; n   while (1) { n     if (fx) { n       arrx[sizx] = mulx; n       sizx++; n     } n     if (fy) { n       arry[sizy] = muly; n       sizy++; n     } n     if (mulx > tempx && muly > tempy) break; n     if (mulx <= tempx) { n       mulx = mulx * x; n     } else n       fx = 0; n     if (muly <= tempy) { n       muly = muly * y; n     } else n       fy = 0; n   } n   siz = 0; n   for (i = 0; i < sizx; i = i + 1) { n     temp = r - arrx[i]; n     for (j = 0; j < sizy; j = j + 1) { n       if (arry[j] > temp) break; n       ss = arrx[i] + arry[j]; n       if (ss < l) continue; n       if (M[ss]) continue; n       arr[siz] = ss; n       M[ss] = 1; n       siz++; n     } n   } n   sort(arr, arr + siz); n   start = l; n   ans = 0; n   for (i = 0; i < siz; i = i + 1) { n     fin = arr[i] - 1; n     ran = fin - start + 1; n     ans = max(ans, ran); n     start = arr[i] + 1; n   } n   ran = r - start + 1; n   ans = max(ans, ran); n   printf( %lld n , ans); n   return 0; n } n void parr(long long int a[], long long int n) { n   long long int i; n   for (i = 0; i < n; i = i + 1) { n     printf( %lld  , a[i]); n   } n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> adj[300010]; n bool vst[300010]; n int dp[300010][2]; n int root[300010]; n int cnt[300010]; n int dst[300010]; n int find_root(int u) { n   if (root[u] == u) return u; n   return root[u] = find_root(root[u]); n } n void reunion(int u, int v) { n   u = find_root(u); n   v = find_root(v); n   if (u == v) return; n   if (cnt[u] < cnt[v]) swap(u, v); n   cnt[u] += cnt[v]; n   root[v] = u; n   dst[u] = max(dst[u], (dst[u] + 1) / 2 + (dst[v] + 1) / 2 + 1); n   dst[u] = max(dst[u], dst[v]); n } n int val; n void dfs(int u, int fa = 0) { n   vst[u] = 1; n   for (int i = 0; i < adj[u].size(); i++) { n     int v = adj[u][i]; n     if (v == fa) continue; n     dfs(v, u); n   } n   vector<int> vt; n   for (int i = 0; i < adj[u].size(); i++) { n     int v = adj[u][i]; n     if (v == fa) continue; n     vt.push_back(dp[v][0]); n   } n   sort(vt.begin(), vt.end()); n   reverse(vt.begin(), vt.end()); n   if (vt.size()) dp[u][0] = vt[0] + 1; n   if (vt.size() > 1) dp[u][1] = vt[1] + 1; n   val = max(val, dp[u][0] + dp[u][1]); n } n int main() { n   int n, m, q; n   scanf( %d%d%d , &n, &m, &q); n   for (int i = 1; i <= n; i++) root[i] = i; n   for (int i = 1; i <= m; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     adj[u].push_back(v); n     adj[v].push_back(u); n     reunion(u, v); n   } n   for (int i = 1; i <= n; i++) { n     if (!vst[i]) { n       val = 0; n       dfs(i); n       int fa = find_root(i); n       dst[fa] = val; n     } n   } n   while (q--) { n     int ok; n     scanf( %d , &ok); n     if (ok == 2) { n       int u, v; n       scanf( %d%d , &u, &v); n       reunion(u, v); n     } else { n       int u; n       scanf( %d , &u); n       u = find_root(u); n       printf( %d n , dst[u]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double a, d; n double pre(double v) { n   if (d >= (v * v) / (2.0 * a)) { n     double x = v / a; n     double y = d - ((v * v) / (2.0 * a)); n     double out = x + (y / (v)); n     return out; n   } else { n     double out = sqrt((2.0 * d) / a); n     return out; n   } n } n int main() { n   int n; n   cin >> n >> a >> d; n   double arr[n][2]; n   double time[n]; n   for (int i = 0; i < n; i++) { n     scanf( %lf%lf , &arr[i][0], &arr[i][1]); n     double x = pre(arr[i][1]); n     time[i] = x + arr[i][0]; n     if (i != 0 && time[i] < time[i - 1]) { n       time[i] = time[i - 1]; n     } n     printf( %.6f n , time[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool sushu(long long n) { n   long long t = sqrt(n); n   for (long long i = 2; i <= t; i++) { n     if (n % i == 0) return false; n   } n   return true; n } n long long ret(long long n) { n   long long ne = 0; n   while (n != 0) { n     ne = ne * 10 + n % 10; n     n = n / 10; n   } n   return ne; n } n int main() { n   long long n, ans; n   long long a[11190]; n   long long i, num = 0; n   for (i = 13;; i++) { n     if (sushu(i) && sushu(ret(i)) && i != ret(i)) { n       a[num++] = i; n       if (num == 11184) break; n     } n   } n   while (cin >> n) { n     cout << a[n - 1] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void ckmx(int &x, int y) { x = max(x, y); } n const int N = 100050; n const int L = 17; n const int M = 2 * N; n int root, ls[M], rs[M], tsz, mx[M], lzy[M]; n void Build(int &c, int ss, int se, int a[]) { n   c = ++tsz; n   lzy[c] = 0; n   if (ss == se) { n     mx[c] = a[ss]; n     return; n   } n   int mid = ss + se >> 1; n   Build(ls[c], ss, mid, a); n   Build(rs[c], mid + 1, se, a); n   mx[c] = max(mx[ls[c]], mx[rs[c]]); n } n void Add(int c, int ss, int se, int qs, int qe, int f) { n   if (qs > qe || qs > se || ss > qe) return; n   if (qs <= ss && qe >= se) { n     lzy[c] += f; n     mx[c] += f; n     return; n   } n   int mid = ss + se >> 1; n   Add(ls[c], ss, mid, qs, qe, f); n   Add(rs[c], mid + 1, se, qs, qe, f); n   mx[c] = max(mx[ls[c]], mx[rs[c]]) + lzy[c]; n } n int Get(int c, int ss, int se, int qs, int qe) { n   if (qs > qe || qs > se || ss > qe) return -1e9; n   if (qs <= ss && qe >= se) return mx[c]; n   int mid = ss + se >> 1; n   return max(Get(ls[c], ss, mid, qs, qe), Get(rs[c], mid + 1, se, qs, qe)) + n          lzy[c]; n } n vector<int> E[N]; n int dep[N], par[N][L], lid[N], rid[N], tid, h[N], ans[N]; n void DFS(int u, int p) { n   par[u][0] = p; n   dep[u] = dep[p] + 1; n   lid[u] = ++tid; n   h[lid[u]] = dep[u]; n   for (int i = 1; i < L; i++) par[u][i] = par[par[u][i - 1]][i - 1]; n   for (int v : E[u]) n     if (v != p) DFS(v, u); n   rid[u] = tid; n } n int LCA(int u, int v) { n   if (dep[u] < dep[v]) swap(u, v); n   for (int i = L - 1; ~i; i--) n     if (dep[par[u][i]] >= dep[v]) u = par[u][i]; n   for (int i = L - 1; ~i; i--) n     if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i]; n   return u == v ? v : par[v][0]; n } n int Dist(int u, int v) { return dep[u] + dep[v] - 2 * dep[LCA(u, v)]; } n int Up(int u, int k) { n   for (int i = 0; i < L; i++) n     if (k >> i & 1) u = par[u][i]; n   return u; n } n struct Query { n   int id, l, r; n }; n vector<Query> Qs[N]; n void Solve(int u, int p) { n   Add(root, 1, tid, lid[u], rid[u], -2); n   for (Query Q : Qs[u]) ckmx(ans[Q.id], Get(root, 1, tid, Q.l, Q.r) + dep[u]); n   for (int v : E[u]) n     if (v != p) Solve(v, u); n   Add(root, 1, tid, lid[u], rid[u], 2); n } n int main() { n   int n, m; n   scanf( %i , &n); n   for (int i = 1, u, v; i < n; i++) n     scanf( %i %i , &u, &v), E[u].push_back(v), E[v].push_back(u); n   DFS(1, 0); n   Build(root, 1, n, h); n   scanf( %i , &m); n   for (int i = 1; i <= m; i++) { n     int u, v; n     scanf( %i %i , &u, &v); n     if (dep[u] < dep[v]) swap(u, v); n     int w = Up(u, (Dist(u, v) - 1) / 2); n     Qs[u].push_back((Query){i, lid[w], rid[w]}); n     Qs[v].push_back((Query){i, 1, lid[w] - 1}); n     Qs[v].push_back((Query){i, rid[w] + 1, n}); n   } n   Solve(1, 0); n   for (int i = 1; i <= m; i++) printf( %i n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 5, maxk = (1 << 20), inf = 1e9; n int dp[maxk][2]; n int ind[20]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, m, k; n   cin >> n >> m >> k; n   string a, b; n   cin >> a >> b; n   int c = 0, d = 0; n   for (int i = 0; i < k; i++) { n     if (a[i] ==  1 ) { n       c += (1 << i); n     } n     if (b[i] ==  1 ) { n       d += (1 << i); n     } n   } n   for (int i = 0; i < maxk; i++) { n     dp[i][0] = inf; n     dp[i][1] = -inf; n   } n   dp[c][0] = 0; n   dp[d][1] = 0; n   int x, y; n   int c1, d1; n   for (int i = 0; i < k; i++) { n     ind[i] = i; n   } n   for (int i = 0; i < n; i++) { n     cin >> x >> y; n     x--; n     y--; n     swap(ind[x], ind[y]); n     c1 = 0; n     d1 = 0; n     for (int j = 0; j < k; j++) { n       c1 += (1 << ind[j]) * (((1 << j) & c) > 0); n       d1 += (1 << ind[j]) * (((1 << j) & d) > 0); n     } n     if (dp[c1][0] == inf) { n       dp[c1][0] = i + 1; n     } n     dp[d1][1] = i + 1; n   } n   int uk = __builtin_popcount(c) + __builtin_popcount(d); n   int sol = 0; n   pair<int, int> range = {1, 1}; n   for (int i = (1 << k) - 1; i > -1; i--) { n     if (dp[i][1] - dp[i][0] >= m) { n       if (sol < k + __builtin_popcount(i) * 2 - uk) { n         sol = k + __builtin_popcount(i) * 2 - uk; n         range = {dp[i][0] + 1, dp[i][1]}; n       } n     } n     for (int j = 0; j < k; j++) { n       if (i & (1 << j)) { n         dp[i ^ (1 << j)][0] = min(dp[i ^ (1 << j)][0], dp[i][0]); n         dp[i ^ (1 << j)][1] = max(dp[i ^ (1 << j)][1], dp[i][1]); n       } n     } n   } n   cout << sol <<   n ; n   cout << range.first <<     << range.second <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int h, t; n vector<vector<int> > graph; n vector<int> lvl; n int edges[100005][2]; n int stat[100005]; n int check(int u, int v) { n   int len = h + t; n   int ht = 0; n   int tt = 0; n   stat[u] = -1; n   stat[v] = -1; n   int i = 0; n   while (ht < len) { n     int a = graph[u][i++]; n     if (a == -1) break; n     if (stat[a] == -1) continue; n     stat[a] = 1; n     ht++; n   } n   i = 0; n   while (tt < t) { n     int a = graph[v][i++]; n     if (a == -1) break; n     if (stat[a] == -1) continue; n     if (stat[a] == 1) { n       if (ht > h) n         ht--; n       else n         continue; n     } n     stat[a] = 2; n     tt++; n   } n   if (ht >= h && tt >= t) return 1; n   stat[u] = 0; n   stat[v] = 0; n   i = 0; n   while (ht > 0) { n     int a = graph[u][i++]; n     if (stat[a] == 1) { n       ht--; n       stat[a] = 0; n     } n   } n   i = 0; n   while (tt > 0) { n     int a = graph[v][i++]; n     if (stat[a] == 2) tt--; n     stat[a] = 0; n   } n   return 0; n } n void print(int n) { n   for (int i = 0; i <= n && h > 0; i++) { n     if (stat[i] == 1) { n       cout << i <<    ; n       h--; n     } n   } n   cout << endl; n   for (int i = 0; i <= n && t > 0; i++) { n     if (stat[i] == 2) { n       cout << i <<    ; n       t--; n     } n   } n } n int main() { n   int n, m; n   cin >> n >> m >> h >> t; n   for (int i = 0; i <= n; i++) { n     lvl.push_back(0); n     graph.push_back(vector<int>()); n   } n   for (int i = 0; i < m; i++) { n     int a, b; n     cin >> a >> b; n     graph[a].push_back(b); n     graph[b].push_back(a); n     edges[i][0] = a; n     edges[i][1] = b; n   } n   for (int i = 0; i <= n; i++) { n     graph[i].push_back(-1); n   } n   for (int i = 0; i < m; i++) { n     if (check(edges[i][0], edges[i][1])) { n       cout <<  YES  << endl; n       cout << edges[i][0] <<     << edges[i][1] << endl; n       print(n); n       return 0; n     } n     if (check(edges[i][1], edges[i][0])) { n       cout <<  YES  << endl; n       cout << edges[i][1] <<     << edges[i][0] << endl; n       print(n); n       return 0; n     } n   } n   cout <<  NO  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> adj[3010]; n pair<int, long long> dp[3010][3010], tmp[3010]; n int v[3010], sz[3010]; n void merge(int x, int y) { n   for (int i = 0; i < sz[x] + sz[y]; i++) tmp[i] = pair<int, long long>(-1, 0); n   for (int i = 0; i < sz[x]; i++) n     for (int j = 0; j < sz[y]; j++) { n       tmp[i + j] = max(tmp[i + j], n                        pair<int, long long>(dp[x][i].first + dp[y][j].first, n                                             dp[x][i].second + dp[y][j].second)); n       tmp[i + j + 1] = max( n           tmp[i + j + 1], pair<int, long long>(dp[x][i].first + dp[y][j].first + n                                                    (dp[y][j].second > 0), n                                                dp[x][i].second)); n     } n   sz[x] += sz[y]; n   for (int i = 0; i < sz[x]; i++) dp[x][i] = tmp[i]; n } n void dfs(int x, int p) { n   sz[x] = 1; n   dp[x][0] = pair<int, long long>(0, v[x]); n   for (int i = 0; i < adj[x].size(); i++) { n     int y = adj[x][i]; n     if (y == p) continue; n     dfs(y, x); n     merge(x, y); n   } n } n void solve() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) v[i] = 0, adj[i].clear(); n   for (int i = 1, x; i <= n; i++) { n     scanf( %d , &x); n     v[i] -= x; n   } n   for (int i = 1, x; i <= n; i++) { n     scanf( %d , &x); n     v[i] += x; n   } n   for (int i = 1, x, y; i < n; i++) { n     scanf( %d%d , &x, &y); n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   dfs(1, 0); n   cout << dp[1][m - 1].first + (dp[1][m - 1].second > 0) << endl; n } n int main() { n   int t; n   scanf( %d , &t); n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int abc; n inline int rd(int l, int r) { return rand() % (r - l + 1) + l; } n const int mxn = 2e5 + 3, mod = 998244353; n long long por(long long x, int y = mod - 2) { n   long long r = 1; n   for (; y; y >>= 1) { n     if (y & 1) r = r * x % mod; n     x = x * x % mod; n   } n   return r; n } n int n, a[mxn], m, R[mxn], N; n long long w[2][mxn]; n bool b[mxn]; n bool chk() { n   for (int i = 1; i <= n;) { n     int x = a[i], y = x; n     b[++m] = x > 1; n     while (y--) { n       if (a[i] != x) return 0; n       ++i; n     } n   } n   return 1; n } n struct VV { n   vector<long long> a[2][2]; n   void ii(int s) { n     a[0][0].resize(s), a[0][1].resize(s), a[1][0].resize(s), a[1][1].resize(s); n   } n }; n void ntt(vector<long long>& a, int n, bool tp = 0) { n   for (int i = 1; i < n; ++i) R[i] = R[i >> 1] >> 1, R[i] |= (i & 1) * (n >> 1); n   for (int i = 0; i < n; ++i) a[i] %= mod; n   for (int i = 0; i < n; ++i) n     if (i > R[i]) swap(a[i], a[R[i]]); n   for (int d = 1, t = N >> 1; d < n; d *= 2, t >>= 1) { n     for (int i = 0; i < n; i += d * 2) n       for (int j = 0; j < d; ++j) { n         long long x = a[i + j + d] * w[tp][t * j]; n         a[i + j + d] = (a[i + j] - x) % mod, a[i + j] = (a[i + j] + x) % mod; n       } n   } n   if (tp) { n     long long iv = por(n); n     for (int i = 0; i < n; ++i) a[i] = a[i] * iv % mod; n   } n } n vector<long long> d; n void NTT(vector<long long>& a, vector<long long>& b, vector<long long>& c, n          int t1, int t2) { n   for (int i = 0; i < n; ++i) d[i] = a[i] * b[i] % mod; n   ntt(d, n, 1); n   for (int i = 0; i < n; ++i) n     if (d[i]) c[i] += d[i] * (t1 + 1) * (t2 + 1), c[i - 1] += d[i] * 2; n   for (int i = 0; i < n; ++i) c[i] %= mod; n } n VV sol(int L, int R) { n   if (L == R) { n     VV r; n     r.ii(2); n     r.a[b[L]][b[L]][1] = 1; n     return r; n   } n   int md = (L + R) >> 1; n   VV v1 = sol(L, md), v2 = sol(md + 1, R), re; n   n = 1; n   while (n <= R - L + 1) n *= 2; n   v1.ii(n), v2.ii(n), re.ii(n), d.resize(n); n   for (int i1 = 0; i1 <= 1; ++i1) n     for (int i2 = 0; i2 <= 1; ++i2) n       for (int i3 = 0; i3 <= 1; ++i3) n         for (int i4 = 0; i4 <= 1; ++i4) { n           vector<long long>&h1 = v1.a[i1][i2], &h2 = v2.a[i3][i4]; n           h1[1] = (h1[1] + mod) % mod, h2[1] = (h2[1] + mod) % mod; n           assert(h1[0] == 0 && h2[0] == 0); n           assert(h1[1] >= 0 && h1[1] <= 1 && h2[1] >= 0 && h2[1] <= 1); n           if (i1 == i2 && i3 == i4) n             re.a[i1][i3][2] += h1[1] * h2[1], re.a[1][1][1] += h1[1] * h2[1]; n           if (i1 == i2) { n             if (h1[1]) n               for (int i = 2; i < n; ++i) { n                 if (h2[i]) n                   assert(i + 1 < n), re.a[i1][i4][i + 1] += (i3 + 1) * h2[i], n                       re.a[1][i4][i] += h2[i]; n               } n           } n           if (i3 == i4) { n             if (h2[1]) n               for (int i = 2; i < n; ++i) { n                 if (h1[i]) n                   assert(i + 1 < n), re.a[i1][i4][i + 1] += (i2 + 1) * h1[i], n                       re.a[i1][1][i] += h1[i]; n               } n           } n         } n   for (int i = 0; i <= 1; ++i) n     for (int j = 0; j <= 1; ++j) { n       vector<long long>& v = v1.a[i][j]; n       v[1] = 0; n       ntt(v, n); n     } n   for (int i = 0; i <= 1; ++i) n     for (int j = 0; j <= 1; ++j) { n       vector<long long>& v = v2.a[i][j]; n       v[1] = 0; n       ntt(v, n); n     } n   for (int i1 = 0; i1 <= 1; ++i1) n     for (int i2 = 0; i2 <= 1; ++i2) n       for (int i3 = 0; i3 <= 1; ++i3) n         for (int i4 = 0; i4 <= 1; ++i4) n           NTT(v1.a[i1][i2], v2.a[i3][i4], re.a[i1][i4], i2, i3); n   return re; n } n int main() { n   abc = scanf( %d , &n); n   for (int i = 1; i <= n; ++i) abc = scanf( %d , a + i); n   if (!chk()) return puts( 0 ), 0; n   N = 1; n   while (N <= m) N *= 2; n   assert(N < mxn && (mod - 1) % N == 0); n   w[0][0] = w[1][0] = 1, w[0][1] = por(3, (mod - 1) / N), n   w[1][1] = por(w[0][1]); n   for (int i = 2; i < N; ++i) n     w[0][i] = w[0][i - 1] * w[0][1] % mod, n     w[1][i] = w[1][i - 1] * w[1][1] % mod; n   VV re = sol(1, m); n   long long ans = 0; n   for (int i1 = 0; i1 <= 1; ++i1) n     for (int i2 = 0; i2 <= 1; ++i2) { n       vector<long long>& v = re.a[i1][i2]; n       long long jc = (m & 1) ? -1 : 1; n       for (int i = 1; i <= m; ++i) { n         jc *= -i, jc %= mod; n         if (i == 1) n           ans += v[i] * (i1 + 1) * jc % mod; n         else n           ans += v[i] * (i1 + 1) * (i2 + 1) * jc % mod; n       } n       ans %= mod; n     } n   printf( %lld n , (ans % mod + mod) % mod); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, x, y; n   cin >> n >> m; n   vector<pair<int, int>> v; n   for (int i = 0; i < m; i++) { n     cin >> x >> y; n     v.push_back({y, x}); n   } n   sort(v.begin(), v.end()); n   int ans = 0, counter = 0; n   for (int i = m - 1; i >= 0; i--) { n     if (counter + v[i].second <= n) { n       ans += v[i].first * v[i].second; n       counter += v[i].second; n     } else { n       ans += v[i].first * (n - counter); n       break; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int val[300005]; n long long num[300005]; n int main() { n   int n; n   scanf( %d , &n); n   long long s = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %d%lld , &val[i], &num[i]); n     s += val[i]; n   } n   long long ans = 0; n   for (int i = 61; i >= 0; i--) { n     long long s0 = 0, s1 = 0; n     for (int j = 1; j <= n; j++) n       if ((num[j] & (1LL << i)) && (num[j] >> i << i) == num[j]) { n         bool v = (val[j] > 0) ^ (s > 0); n         for (int k = 0; k < 62; k++) n           if ((num[j] & ans) & (1LL << k)) v ^= 1; n         if (v) n           s0 += abs(val[j]); n         else n           s1 += abs(val[j]); n       } n     if (s1 > s0) ans ^= (1LL << i); n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   cin >> n; n   while (n--) { n     cout << 1 <<    ; n   } n   cout << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using std::cin; n using std::cout; n const int N = 5054, mod = 1000000007; n int n, K; n int f[N]; n long long PowerMod(long long a, int n, long long c = 1) { n   for (; n; n >>= 1, a = a * a % mod) n     if (n & 1) c = c * a % mod; n   return c; n } n int main() { n   int i, j, x, in, ans = 0; n   std::ios::sync_with_stdio(false), cin.tie(NULL); n   cin >> n >> K, *f = 1, in = PowerMod(n, mod - 2); n   for (i = 0; i < n; ++i) { n     cin >> x; n     for (j = i + 1; j; --j) f[j] = ((long long)f[j] * x + mod - f[j - 1]) % mod; n     *f = (long long)*f * x % mod; n   } n   for (x = mod - 1, i = 1; i <= n && i <= K; ++i) n     x = x * (K - i + 1ll) % mod * in % mod, n     ans = (ans + (long long)x * f[i]) % mod; n   cout << ans <<   n ; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int seq[100050]; n int n; n int l[40], r[40]; n int dp[100050]; n bool chk() { n   for (int i = 1; i <= n; ++i) n     if (seq[i] != i) return false; n   return true; n } n void dfs(int dep) { n   if (chk()) { n     printf( %d n , dep); n     for (int i = dep; i >= 1; --i) printf( %d %d n , l[i], r[i]); n     exit(0); n   } n   if (dep == 3) return; n   for (int i = 1; i <= n - 1; ++i) { n     if (seq[i] != i && n         (abs(seq[i] - seq[i - 1]) != 1 || abs(seq[i] - seq[i + 1]) != 1)) { n       for (int j = i + 1; j <= n; ++j) n         if (seq[j] != j && n             (abs(seq[j] - seq[j + 1]) != 1 || abs(seq[j] - seq[j - 1]) != 1)) { n           l[dep + 1] = i; n           r[dep + 1] = j; n           reverse(seq + i, seq + j + 1); n           dfs(dep + 1); n           reverse(seq + i, seq + j + 1); n         } n     } n   } n } n int main() { n   seq[0] = -1; n   scanf( %d , &n); n   seq[n + 1] = -1; n   for (int i = 1; i <= n; ++i) scanf( %d , &seq[i]); n   dfs(0); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> Height(n); n   vector<int> count(n, 0); n   for (int i = 0; i < n; i++) { n     cin >> Height[i]; n   } n   int x = 0, after = 1, befor = 0; n   while (after < n && Height[x] >= Height[after]) { n     count[0]++; n     x++; n     after++; n   } n   for (int i = 1; i < n - 1; i++) { n     x = i, after = i + 1, befor = i - 1; n     while (befor >= 0 && Height[x] >= Height[befor]) { n       count[i]++; n       x--; n       befor--; n     } n     x = i; n     while (after < n && Height[x] >= Height[after]) { n       count[i]++; n       x++; n       after++; n     } n   } n   x = n - 1; n   befor = n - 2; n   while (befor >= 0 && Height[x] >= Height[befor]) { n     count[n - 1]++; n     x--; n     befor--; n   } n   sort(count.begin(), count.end()); n   cout << count[count.size() - 1] + 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   char ch = getchar(); n   int x = 0, fl = 1; n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) fl = -1; n   for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch -  0 ); n   return x * fl; n } n const int NN = 500000 + 17; n const int MM = 10000000 + 17; n void open() { n   freopen( a.in ,  r , stdin); n   freopen( a.out ,  w , stdout); n } n int n, maxx; n int pw[NN], miu[MM], pri[NN * 4], cnt; n int tax[MM], bs[MM], f[MM], has[MM]; n bool notp[MM]; n const int mod = 1e9 + 7; n int add(int x, int y) { return (x + y) % mod; } n int getmod(int x) { return (x + mod) % mod; } n void prework() { n   pw[0] = 1; n   for (int i = 1; i <= n; i++) pw[i] = add(pw[i - 1], pw[i - 1]); n   miu[1] = 1; n   for (int i = 2; i <= maxx; i++) { n     if (!notp[i]) { n       pri[++cnt] = i; n       miu[i] = -1; n     } n     for (int j = 1; j <= cnt && i * pri[j] <= maxx; j++) { n       notp[i * pri[j]] = true; n       if (i % pri[j] == 0) { n         miu[i * pri[j]] = 0; n         break; n       } n       miu[i * pri[j]] = -miu[i]; n     } n   } n } n int main() { n   n = read(); n   for (int i = 1; i <= n; i++) { n     int x = read(); n     maxx = max(maxx, x); n     tax[x]++; n   } n   prework(); n   for (int i = maxx; i; i--) n     for (int j = i; j <= maxx; j += i) { n       bs[i] += tax[j]; n     } n   for (int i = maxx; i; i--) { n     f[i] = (pw[bs[i]] - 1 + mod) % mod; n     for (int j = i + i; j <= maxx; j += i) { n       f[i] = (f[i] - f[j] + mod) % mod; n     } n   } n   for (int i = 1; i <= maxx; i++) n     for (int j = i; j <= maxx; j += i) { n       has[j] = add(has[j], 1LL * getmod(miu[i]) * bs[i] % mod); n     } n   int ans = 0; n   for (int i = 2; i <= maxx; i++) { n     ans = add(ans, 1LL * has[i] * f[i] % mod); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Segment { n   int x1, y1, x2, y2; n }; n struct Line { n   long long a, b, c; n }; n int n; n Segment seg[1005]; n map<pair<int, int>, int> intersectCount; n unordered_map<int, int> toSubtract; n int gcd(int a, int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long det(long long a11, long long a12, long long a21, long long a22) { n   return a11 * a22 - a12 * a21; n } n pair<int, int> intersectLines(const Line &l1, const Line &l2) { n   long long detS = det(l1.a, l1.b, l2.a, l2.b); n   if (detS == 0) return make_pair(0x3f3f3f3f, 0x3f3f3f3f); n   long long detX = det(l1.c, l1.b, l2.c, l2.b); n   long long detY = det(l1.a, l1.c, l2.a, l2.c); n   if (detX % detS || detY % detS) return make_pair(0x3f3f3f3f, 0x3f3f3f3f); n   return make_pair(detX / detS, detY / detS); n } n Line segmentToLine(const Segment &s) { n   Line l; n   l.a = s.y1 - s.y2; n   l.b = s.x2 - s.x1; n   l.c = l.a * s.x1 + l.b * s.y1; n   return l; n } n pair<int, int> intersectSegments(const Segment &s1, const Segment &s2) { n   return intersectLines(segmentToLine(s1), segmentToLine(s2)); n } n bool pointInSegment(const pair<int, int> &A, const Segment &s) { n   return min(s.x1, s.x2) <= A.first && A.first <= max(s.x1, s.x2) && n          min(s.y1, s.y2) <= A.second && A.second <= max(s.y1, s.y2); n } n int main() { n   ios::sync_with_stdio(0); n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> seg[i].x1 >> seg[i].y1 >> seg[i].x2 >> seg[i].y2; n   } n   long long sol = 0; n   for (int i = 1; i <= n; ++i) { n     sol += gcd(abs(seg[i].x1 - seg[i].x2), abs(seg[i].y1 - seg[i].y2)) + 1; n   } n   for (int i = 1; i <= n; ++i) { n     for (int j = i + 1; j <= n; ++j) { n       pair<int, int> A = intersectSegments(seg[i], seg[j]); n       if (A.first == 0x3f3f3f3f) continue; n       if (pointInSegment(A, seg[i]) && pointInSegment(A, seg[j])) { n         ++intersectCount[A]; n       } n     } n   } n   int S = 0; n   for (int i = 1; i <= n; ++i) { n     S += i; n     toSubtract[S] = i; n   } n   for (auto first : intersectCount) { n     assert(toSubtract.count(first.second)); n     sol -= toSubtract[first.second]; n   } n   cout << sol <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long C[1007][1007]; n int main() { n   long long n, m, k; n   memset(C, 0, sizeof(C)); n   C[0][0] = 1; n   for (long long i = 1; i <= 1000; i++) { n     C[i][0] = 1; n     for (long long j = 1; j <= i; j++) n       C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007; n   } n   while (cin >> n >> m >> k) { n     long long a = n - 2 * k - 1; n     long long b = m - 2 * k - 1; n     if (a < 0 || b < 0) n       cout << 0 << endl; n     else n       cout << (C[2 * k + a][a] * C[2 * k + b][b]) % 1000000007 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct _IO { n   _IO() { n     ios::sync_with_stdio(0); n     cin.tie(0); n   } n } _io; n using ll = long long; n using db = long double; n using pi = pair<int, int>; n using mi = map<int, int>; n const int N = 6e5 + 5, M = 1e9 + 7; n using vi = vector<int>; n ll ri() { n   ll x; n   cin >> x; n   return x; n } n void prl() { cout <<   n ; } n template <class T, class... U> n void prl(T x, U... y) { n   cout << x <<    , prl(y...); n } n template <class T, class U> n ostream &operator<<(ostream &out, pair<T, U> p) { n   out <<  (  << p.first <<  ,   << p.second <<  ) ; n   return out; n } n template <class T> n ostream &operator<<(ostream &out, vector<T> &v) { n   cout <<  { ; n   for (int i = (0); i < (v.size()); ++i) { n     if (i) cout <<  ,  ; n     cout << v[i]; n   } n   cout <<  } ; n   return out; n } n struct cp { n   db x, y; n   cp(db a = 0, db b = 0) : x(a), y(b) {} n   cp operator-(const cp &b) const { return cp(x - b.x, y - b.y); } n   cp operator+(const cp &b) const { return cp(x + b.x, y + b.y); } n   cp operator*(const cp &b) const { n     return cp(x * b.x - y * b.y, x * b.y + y * b.x); n   } n   cp operator/(const int &b) const { return cp(x / b, y / b); } n }; n const db PI = acos(-1); n int rev[N]; n void init(int n) { n   for (int i = 0, lim = __builtin_ctz(n); i < n; i++) n     rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (lim - 1)); n } n void fft(cp *a, int n, int f) { n   for (int i = 0; i < n; i++) n     if (i < rev[i]) swap(a[i], a[rev[i]]); n   for (int l = 2, m = 1; l <= n; m = l, l <<= 1) n     for (cp *p = a, wn(cos(2 * PI / l), sin(f * 2 * PI / l)); p != a + n; n          p += l) n       for (cp *q = p, w(1, 0); q != p + m; q++, w = w * wn) { n         cp t = *(q + m) * w; n         *(q + m) = *q - t; n         *q = *q + t; n       } n   if (f == -1) n     for (int i = 0; i < n; i++) a[i] = a[i] / n; n } n cp a[N]; n signed main() { n   int n = ri(), m = ri(), k = ri(); n   string s, t, p =  ATCG ; n   cin >> s >> t; n   int len = 1; n   while (len < n + m) len *= 2; n   init(len); n   vi ans(len), sum(n + 1); n   for (int c = (0); c < (4); ++c) { n     memset(a, 0, sizeof a); n     for (int i = (0); i < (n); ++i) { n       if (s[i] == p[c]) { n         sum[i + 1] = 1; n       } else { n         sum[i + 1] = 0; n       } n       sum[i + 1] = sum[i] + sum[i + 1]; n     } n     for (int i = (0); i < (n); ++i) { n       if (sum[min(n, i + k + 1)] - sum[max(0, i - k)] >= 1) { n         a[i].x = 1; n       } n     } n     for (int i = (0); i < (m); ++i) { n       if (t[i] == p[c]) { n         a[m - i - 1].y = 1; n       } n     } n     fft(a, len, 1); n     for (int i = (0); i < (len); ++i) { n       a[i] = a[i] * a[i]; n     } n     fft(a, len, -1); n     for (int i = (0); i < (len); ++i) { n       ans[i] += (int)(a[i].y / 2 + 0.5); n     } n   } n   int cnt = 0; n   for (int i = (0); i < (n); ++i) n     if (ans[i] == m) ++cnt; n   prl(cnt); n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 200010, M = 2000010, INF = 0x3f3f3f3f; n inline long long max(long long x, long long y) { return x > y ? x : y; } n inline long long min(long long x, long long y) { return x < y ? x : y; } n inline void swap(long long &x, long long &y) { x ^= y ^= x ^= y; } n long long head[N], ver[M], Next[M], tot; n long long n, m, k, t, top, num, d[N], id[N], st[N], vis[N], size[N], f[N][20]; n vector<long long> v[N]; n bool cmp(long long x, long long y) { return id[x] < id[y]; } n void add(long long x, long long y) { n   ver[++tot] = y, Next[tot] = head[x], head[x] = tot; n } n void dfs(long long x, long long fa) { n   d[x] = d[fa] + 1; n   id[x] = ++num; n   for (long long i = head[x]; i; i = Next[i]) { n     long long y = ver[i]; n     if (y == fa) continue; n     f[y][0] = x; n     for (long long j = 1; j <= t; j++) f[y][j] = f[f[y][j - 1]][j - 1]; n     dfs(y, x); n   } n } n long long lca(long long x, long long y) { n   if (d[x] > d[y]) swap(x, y); n   for (long long i = t; i >= 0; i--) n     if (d[f[y][i]] >= d[x]) y = f[y][i]; n   if (x == y) return x; n   for (long long i = t; i >= 0; i--) n     if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i]; n   return f[x][0]; n } n long long dp(long long x, long long fa) { n   long long res = 0; n   size[x] = vis[x]; n   for (long long i = 0; i < (long long)v[x].size(); i++) n     if (v[x][i] != fa) res += dp(v[x][i], x); n   if (size[x]) { n     for (long long i = 0; i < (long long)v[x].size(); i++) n       if (v[x][i] != fa) res += (size[v[x][i]]); n   } else { n     long long cnt = 0; n     for (long long i = 0; i < (long long)v[x].size(); i++) n       if (v[x][i] != fa) cnt += (size[v[x][i]]); n     if (cnt == 1) n       size[x] = 1; n     else if (cnt > 1) n       res++; n   } n   return res; n } n int main() { n   scanf( %lld , &n); n   t = (long long)(log(n) / log(2)) + 1; n   for (long long i = 1; i < n; i++) { n     long long x, y; n     scanf( %lld%lld , &x, &y); n     add(x, y), add(y, x); n   } n   dfs(1, 0); n   scanf( %lld , &m); n   while (m--) { n     scanf( %lld , &k); n     top = 0; n     for (long long i = 1; i <= k; i++) { n       long long x; n       scanf( %lld , &x); n       st[++top] = x; n       vis[x] = 1; n     } n     long long flag = 0; n     for (long long i = 1; i <= top; i++) flag |= vis[f[st[i]][0]]; n     sort(st + 1, st + top + 1, cmp); n     for (long long i = 1; i < k; i++) { n       long long l = lca(st[i], st[i + 1]); n       if (l != st[i] && l != st[i + 1]) st[++top] = l; n     } n     st[++top] = 1; n     sort(st + 1, st + top + 1); n     top = unique(st + 1, st + top + 1) - st - 1; n     sort(st + 1, st + top + 1, cmp); n     for (long long i = 2; i <= top; i++) { n       long long l = lca(st[i - 1], st[i]); n       v[l].push_back(st[i]); n     } n     if (flag) n       puts( -1 ); n     else n       printf( %lld n , dp(st[1], 0)); n     for (long long i = 1; i <= top; i++) v[st[i]].clear(); n     for (long long i = 1; i <= top; i++) vis[st[i]] = 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int tot[100100]; n int maxd = 0; n vector<vector<int> > g; n void dfs(int v, int d, int p) { n   maxd = ((maxd < d) ? (d) : (maxd)); n   tot[d]++; n   for (int i = (0); i < (g[v].size()); ++i) { n     int to = g[v][i]; n     if (to != p) { n       dfs(to, d + 1, v); n     } n   } n } n int use[100100]; n inline bool check(int k, int w) { n   int l = 1, r = 1; n   int sum = tot[l]; n   while (sum < k) { n     r++; n     sum += tot[r]; n   } n   long long price = 0; n   int need = k; n   for (int i = r; i >= l; --i) { n     int v = ((need < tot[i]) ? (need) : (tot[i])); n     use[i] = v; n     price += v * 1ll * (r - i); n     need -= v; n   } n   if (price <= w) return true; n   while (1) { n     if (r == maxd) break; n     sum += tot[r + 1]; n     while (1) { n       if (l == r) break; n       if (sum - tot[l] >= k) { n         price -= (r - l) * 1ll * use[l]; n         sum -= tot[l]; n         l++; n       } else { n         int v = k - (sum - tot[l]); n         price -= (r - l) * 1ll * (use[l] - v); n         use[l] = v; n         break; n       } n     } n     r++; n     use[r] = ((tot[r] < k) ? (tot[r]) : (k)); n     price += k - use[r]; n     if (price <= w) return true; n   } n   return false; n } n int main() { n   int n, k, p; n   scanf( %d%d%d , &n, &k, &p); n   g.resize(n); n   for (int i = (0); i < (n - 1); ++i) { n     int v1, v2; n     scanf( %d%d , &v1, &v2); n     v1--; n     v2--; n     g[v1].push_back(v2); n     g[v2].push_back(v1); n   } n   dfs(0, 0, -1); n   int res = 0; n   int le = 1, ri = ((n - 1 < k) ? (n - 1) : (k)); n   while (le <= ri) { n     int m = (le + ri) / 2; n     if (check(m, p)) { n       res = m; n       le = m + 1; n     } else { n       ri = m - 1; n     } n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t; n   cin >> t; n   while (t--) { n     long long n, e = 0, o = 0; n     long long i, j; n     long long ans = 0; n     string str; n     cin >> str; n     for (i = 0; i < str.size(); i++) { n       if (str[i] ==  0 ) n         e++; n       else n         o++; n     } n     ans = min(o, e); n     if (ans % 2 == 1) n       cout <<  DA  << endl; n     else n       cout <<  NET  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class B_808 { n  public: n   int main() { n     int n, k, a[200005]; n     double ans = 0.0, sum = 0.0; n     cin >> n >> k; n     for (int i = 0; i < n; i++) cin >> a[i]; n     for (int i = 0; i < k; i++) sum += a[i]; n     ans += sum / ((double)n - k + 1); n     for (int i = k; i < n; i++) { n       sum += a[i] - a[i - k]; n       ans += sum / ((double)n - k + 1); n     } n     cout << std::fixed; n     cout << std::setprecision(6) << ans << endl; n     return 0; n   } n }; n class C_43 { n  public: n   int main() { n     int n, a, ans = 0, m[3] = {0}; n     cin >> n; n     for (int i = 0; i < n; i++) { n       cin >> a; n       m[a % 3]++; n     } n     ans += m[0] / 2; n     ans += min(m[1], m[2]); n     cout << ans << endl; n     return 0; n   } n }; n class B_814 { n  private: n   int n, a[1004], b[1004]; n   bool isValid() { n     int d = 0; n     for (int i = 0; i < n; i++) { n       if (a[i] != b[i]) d++; n     } n     return d == 1; n   } n  n  public: n   int main() { n     int missing, rep = 0; n     set<int> s; n     cin >> n; n     for (int i = 0; i < n; i++) cin >> a[i]; n     for (int i = 0; i < n; i++) cin >> b[i]; n     for (int i = 1; i <= n; i++) s.insert(i); n     for (int i = 0; i < n; i++) { n       if (s.find(a[i]) != s.end()) { n         s.erase(a[i]); n       } else { n         rep = a[i]; n       } n     } n     missing = *s.begin(); n     for (int i = 0; i < n; i++) { n       if (a[i] == rep) { n         a[i] = missing; n         if (isValid()) { n           break; n         } else { n           a[i] = rep; n         } n       } n     } n     for (int i = 0; i < n; i++) cout << a[i] << (i == n - 1 ?   n  :    ); n     return 0; n   } n }; n class C_628 { n  public: n   int main() { n     int n, k; n     string s; n     cin >> n >> k; n     cin >> s; n     string output = s; n     for (int i = 0; i < n && k > 0; i++) { n       if (abs( a  - s[i]) >= abs( z  - s[i])) { n         if (abs( a  - s[i]) < k) { n           output[i] =  a ; n           k -= abs( a  - s[i]); n         } else { n           output[i] = s[i] - k; n           k = 0; n         } n       } else { n         if (abs( z  - s[i]) < k) { n           output[i] =  z ; n           k -= abs( z  - s[i]); n         } else { n           output[i] = s[i] + k; n           k = 0; n         } n       } n     } n     if (k == 0) { n       cout << output; n     } else { n       cout <<  -1 ; n     } n     return 0; n   } n }; n class D_182 { n  private: n   bool verify(string &d, string &s) { n     int n = (int)d.length(); n     for (int i = 0; i < s.length(); i++) { n       if (d[i % n] != s[i]) { n         return false; n       } n     } n     return true; n   } n  n  public: n   int main() { n     string s1, s2, d; n     cin >> s1 >> s2; n     set<string> divisors; n     int ans = 0; n     int n = (int)s1.size(); n     for (int i = 1; i * i <= n; i++) { n       if (n % i == 0) { n         d = s1.substr(0, i); n         if (verify(d, s1)) { n           divisors.insert(d); n         } n         d = s1.substr(0, n / i); n         if (verify(d, s1)) { n           divisors.insert(d); n         } n       } n     } n     n = (int)s2.size(); n     for (int i = 1; i * i <= n; i++) { n       if (n % i == 0) { n         d = s2.substr(0, i); n         if (verify(d, s2) && divisors.find(d) != divisors.end()) { n           ans++; n         } n         if (i * i == n) continue; n         d = s2.substr(0, n / i); n         if (verify(d, s2) && divisors.find(d) != divisors.end()) { n           ans++; n         } n       } n     } n     cout << ans; n     return 0; n   } n }; n int main(int argc, const char *argv[]) { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   D_182().main(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n const int maxm = 1e5 + 5; n const long double eps = 1e-14; n const long double eps2 = 1e-9; n const long double INF = 1 << 30; n inline int dcmp(const long double& x) { n   return fabs(x) < eps ? 0 : (x < 0 ? -1 : 1); n } n pair<long double, long double> operator+( n     const pair<long double, long double>& a, n     const pair<long double, long double>& b) { n   return {a.first + b.first, a.second + b.second}; n } n pair<long double, long double> operator-( n     const pair<long double, long double>& a, n     const pair<long double, long double>& b) { n   return {a.first - b.first, a.second - b.second}; n } n pair<long double, long double> operator*( n     const pair<long double, long double>& a, const long double& b) { n   return {a.first * b, a.second * b}; n } n long double dot(const pair<long double, long double>& a, n                 const pair<long double, long double>& b) { n   return a.first * b.first + a.second * b.second; n } n long double cross(const pair<long double, long double>& a, n                   const pair<long double, long double>& b) { n   return a.first * b.second - a.second * b.first; n } n long double abs(const pair<long double, long double>& a) { n   return sqrt(dot(a, a)); n } n long double interPnt(pair<long double, long double> p1, n                      pair<long double, long double> p2, n                      pair<long double, long double> q1, n                      pair<long double, long double> q2) { n   pair<long double, long double> d = p2 - p1, e = q2 - q1; n   long double crs = cross(d, e); n   if (abs(crs) < eps) { n     long double c2 = cross(d, q1 - p1); n     if (abs(c2) > eps) return INF; n     long double da2 = dot(d, d); n     long double f1 = dot(d, q1 - p1) / da2; n     long double f2 = dot(d, q2 - p1) / da2; n     if (f1 < -eps and f2 < -eps) return INF; n     if (f1 > 1 + eps and f2 > 1 + eps) return INF; n     long double f = max(0.l, min(f1, f2)); n     return (p1 + d * f).first; n   } n   assert(0); n } n template <typename T> n inline bool getmin(T& a, const T& b) { n   return dcmp(b - a) < 0 ? (a = b, true) : false; n } n template <typename T> n inline bool getmax(T& a, const T& b) { n   return dcmp(b - a) > 0 ? (a = b, true) : false; n } n struct Iron { n   int show, speed, st, ed; n   inline void read() { n     scanf( %d%d%d%d , &show, &speed, &st, &ed); n     st--, ed--; n   } n } iron[maxm]; n struct Iron2 { n   long double from, fromt, to, tot; n }; n struct Path { n   int id, from, to; n }; n struct Event { n   long double t; n   int segid; n   bool operator<(const Event& rhs) const { return dcmp(t - rhs.t) < 0; } n }; n int n, m; n vector<int> G[maxn], chain[maxn]; n int fa[maxn], dep[maxn], chainid[maxn], size[maxn]; n int pre[maxn], dfs_clock; n void dfs(int now) { n   vector<int>& vec = chain[chainid[now]]; n   for (int i = ((int)(vec.size())) - 1; i >= 0; i--) pre[vec[i]] = dfs_clock++; n   for (int i = 0; i < ((int)(vec.size())); i++) { n     int now = vec[i]; n     for (const int& to : G[now]) n       if ((!i || to != vec[i - 1]) && to != fa[now]) dfs(to); n   } n } n inline void make_HLD() { n   int first = 0, last = 0; n   int* q = new int[n]; n   q[last++] = 0; n   fa[0] = -1; n   dep[0] = 0; n   while (last - first > 0) { n     int now = q[first++]; n     for (const int& to : G[now]) n       if (to != fa[now]) { n         fa[to] = now; n         dep[to] = dep[now] + 1; n         q[last++] = to; n       } n   } n   for (int i = last - 1; i >= 0; i--) { n     int now = q[i], hs = -1; n     size[now] = 1; n     for (const int& to : G[now]) n       if (to != fa[now]) { n         size[now] += size[to]; n         if (hs < 0 || size[to] > size[hs]) hs = to; n       } n     if (hs < 0) n       chainid[now] = now; n     else n       chainid[now] = chainid[hs]; n     chain[chainid[now]].push_back(now); n   } n   dfs_clock = 0; n   delete[] q; n   dfs(0); n } n inline bool inrange(const long double& x, const long double& L, n                     const long double& R) { n   return dcmp(x - L) >= 0 && dcmp(x - R) <= 0; n } n inline long double getIntersectime(const Iron2& A, const Iron2& B) { n   const long double &x1 = A.from, &t1 = A.fromt, &x2 = A.to, &t2 = A.tot, n                     &x3 = B.from, &t3 = B.fromt, &x4 = B.to, &t4 = B.tot; n   long double deno = (x2 - x1) * (t4 - t3) - (t2 - t1) * (x4 - x3); n   long double nume = (x3 - x1) * (t2 - t1) * (t4 - t3) - n                      t3 * (t2 - t1) * (x4 - x3) + t1 * (t4 - t3) * (x2 - x1); n   long double ans; n   if (dcmp(deno) == 0) { n     return interPnt(make_pair(t1, x1), make_pair(t2, x2), make_pair(t3, x3), n                     make_pair(t4, x4)); n     if (dcmp((x4 - x3) / (t4 - t3) * (t1 - t3) + x3 - x1) == 0) n       ans = max(t1, t3); n     else n       ans = INF; n   } else n     ans = nume / deno; n   if (inrange(ans, max(t1, t3), min(t2, t4))) n     return ans; n   else n     return INF; n } n long double curtime; n vector<Iron2> vec; n struct cmp { n   inline long double getpos(const Iron2& I, const long double& t) const { n     return I.from + ((I.to - I.from) / (I.tot - I.fromt)) * (t - I.fromt); n   } n   bool operator()(const int& a, const int& b) const { n     long double d1 = dcmp(getpos(vec[a], curtime) - getpos(vec[b], curtime)), n                 d2 = dcmp(getpos(vec[a], curtime + 1) - n                           getpos(vec[b], curtime + 1)); n     return d1 < 0 || (d1 == 0 && d2 < 0) || (d1 == 0 && d2 == 0 && a < b); n   } n }; n vector<Iron2> Seg[maxn]; n inline long double solve_path(const int& nowSeg) { n   vec = Seg[nowSeg]; n   set<int, cmp> second; n   vector<Event> eve; n   for (int i = 0; i < ((int)(vec.size())); i++) n     eve.push_back((Event){vec[i].fromt, i << 1}), n         eve.push_back((Event){vec[i].tot, i << 1 | 1}); n   sort(eve.begin(), eve.end()); n   long double ans = INF; n   for (const Event& e : eve) { n     curtime = e.t; n     if (dcmp(curtime - ans) >= 0) break; n     int id = e.segid; n     if (!(id & 1)) { n       id /= 2; n       set<int>::iterator it = second.lower_bound(id); n       assert(second.find(id) == second.end()); n       if (it != second.end()) getmin(ans, getIntersectime(vec[id], vec[*it])); n       if (it != second.begin()) n         it--, getmin(ans, getIntersectime(vec[id], vec[*it])); n       second.insert(id); n     } else { n       id /= 2; n       set<int>::iterator it = second.lower_bound(id), itL = it, itR = it; n       assert((*it) == id); n       itR++; n       if (itL != second.begin() && itR != second.end()) { n         itL--; n         getmin(ans, getIntersectime(vec[*itL], vec[*itR])); n       } n       second.erase(it); n     } n   } n   return ans; n } n vector<Path> path, L, R; n inline void getPath(int a, int b) { n   L.clear(); n   R.clear(); n   while (chainid[a] != chainid[b]) { n     int atop = chain[chainid[a]].back(), btop = chain[chainid[b]].back(); n     if (dep[atop] > dep[btop]) n       L.push_back((Path){chainid[a], a, fa[atop]}), a = fa[atop]; n     else n       R.push_back((Path){chainid[b], fa[btop], b}), b = fa[btop]; n   } n   L.push_back((Path){chainid[a], a, b}); n   path.clear(); n   for (int i = 0; i < ((int)(L.size())); i++) path.push_back(L[i]); n   for (int i = ((int)(R.size())) - 1; i >= 0; i--) path.push_back(R[i]); n } n inline int PosOnPath(int id, int now) { n   if (chainid[now] != id) return 0; n   return pre[now] - pre[chain[id].back()] + 1; n } n inline long double solve_tree() { n   make_HLD(); n   for (int i = 0; i < m; i++) { n     getPath(iron[i].st, iron[i].ed); n     long double curt = iron[i].show, v = iron[i].speed; n     for (const Path& p : path) { n       int from = PosOnPath(p.id, p.from), to = PosOnPath(p.id, p.to); n       long double arrt = curt + abs(to - from) / v; n       long double cc = dcmp(arrt - curt) == 0 ? 0 : (to - from) / (arrt - curt); n       Seg[p.id].push_back( n           (Iron2){from - eps2 * cc, curt - eps2, to + eps2 * cc, arrt + eps2}); n       curt = arrt; n     } n   } n   long double res = INF; n   for (int i = 0; i < n; i++) getmin(res, solve_path(i)); n   return res; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0, a, b; i < n - 1; i++) { n     scanf( %d%d , &a, &b); n     a--, b--; n     G[a].push_back(b); n     G[b].push_back(a); n   } n   for (int i = 0; i < m; i++) iron[i].read(); n   long double ans = solve_tree(); n   if (dcmp(ans - INF) >= 0) n     printf( -1 n ); n   else n     printf( %.13f n , (double)ans); n } n


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


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n const int mod = 1e9 + 7; n const long long inf = 1e18; n int d, n, m, x[N], p[N], cur, r[N]; n long long ans = inf, carry; n pair<int, int> a[N]; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> d >> n >> m; n   for (int i = 1; i <= m; i++) cin >> a[i].first >> a[i].second; n   vector<int> st; n   sort(a + 1, a + m + 1); n   for (int i = 1; i <= m; i++) x[i] = a[i].first, p[i] = a[i].second; n   for (int i = m; i >= 0; i--) { n     r[i] = i; n     while (st.size() && p[st.back()] >= p[i]) { n       r[i] = r[st.back()]; n       st.pop_back(); n     } n     st.push_back(i); n   } n   for (int i = 0, j = 0; i <= m; i++) { n     if (cur < 0) { n       ans = inf; n       break; n     } n     while (j + 1 <= m && x[j + 1] - x[i] <= n) j++; n     if (n >= d - x[i]) { n       long long dist = d - x[i]; n       long long cost = carry; n       if (dist > cur) cost += 1ll * (dist - cur) * p[i]; n       ans = min(ans, cost); n     } n     if (j < r[i] + 1) { n       carry += 1ll * (n - cur) * p[i]; n       cur = n; n     } else { n       long long dist = x[r[i] + 1] - x[i]; n       if (dist > n) dist = n; n       if (dist > cur) { n         carry += 1ll * (dist - cur) * p[i]; n         cur = dist; n       } n     } n     cur -= (x[i + 1] - x[i]); n   } n   if (ans == inf) ans = -1; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> g[1000010]; n int n, k; n bool r[1000010]; n int s[1000010]; n int m[1000010]; n int main() { n   scanf( %d %d , &n, &k); n   for (int i = 0; i < k; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     g[x].push_back(y); n   } n   int v = 0; n   for (int i = 1; i <= n; i++) { n     if (r[i]) continue; n     s[v++] = i; n     r[i] = true; n     for (int j = 0; j < (int)g[i].size(); j++) r[g[i][j]] = true; n   } n   int sz = 0; n   for (int i = 1; i <= n; i++) r[i] = false; n   for (int i = v - 1; i >= 0; i--) { n     if (!r[s[i]]) { n       m[sz++] = s[i]; n       for (int j = 0; j < (int)g[s[i]].size(); j++) r[g[s[i]][j]] = true; n     } n   } n   printf( %d n , sz); n   for (int i = 0; i < sz; i++) printf( %d  , m[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e4 + 100; n int c[maxn], a[maxn]; n int main() { n   int n, m, l = 0, ans = 0; n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> c[i]; n   for (int i = 0; i < m; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) n     if (a[l] >= c[i]) { n       ans++; n       l++; n     } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   string s; n   cin >> s; n   int x = 0, y = 0, pos = 0, coin = 0; n   if (s[0] ==  R ) n     x++; n   else n     y++; n   if (y > x) pos = 2; n   if (x > y) pos = 1; n   for (int i = 1; i < s.length(); i++) { n     if (s[i] ==  R ) n       x++; n     else n       y++; n     int npos = 0; n     if (y > x) npos = 2; n     if (x > y) npos = 1; n     if (npos != 0 && npos != pos) { n       coin++; n       pos = npos; n     } n   } n   cout << coin; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int r, x, y, x1, y1; n   cin >> r >> x >> y >> x1 >> y1; n   double d; n   d = pow((((x - x1) * (x - x1)) + ((y - y1) * (y - y1))), 0.5); n   cout << ceil(d / (2 * r)) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t, n, min1, min2, a, b; n   cin >> t; n   while (t--) { n     cin >> n; n     long long arr1[n]; n     long long arr2[n]; n     for (long long c = 0; c < n; c++) { n       cin >> arr1[c]; n     } n     for (long long d = 0; d < n; d++) { n       cin >> arr2[d]; n     } n     min1 = arr1[0]; n     for (long long i = 0; i < n; i++) { n       if (min1 > arr1[i]) { n         min1 = arr1[i]; n       } n     } n     min2 = arr2[0]; n     for (long long j = 0; j < n; j++) { n       if (min2 > arr2[j]) { n         min2 = arr2[j]; n       } n     } n     long long count = 0; n     for (long long k = 0; k < n; k++) { n       a = arr1[k] - min1; n       b = arr2[k] - min2; n       if (a > b) { n         count = count + a; n       } else { n         count = count + b; n       } n     } n     cout << count << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200005; n int a[maxn]; n long long s[maxn], ss[maxn]; n pair<int, long long> que[maxn]; n int tot; n pair<int, long long> operator-(pair<int, long long> b, pair<int, long long> a) { n   pair<int, long long> c; n   c.first = b.first - a.first; n   c.second = b.second - a.second; n   return c; n } n bool operator>(pair<int, long long> b, pair<int, long long> a) { n   double x = 1.0 * a.second / a.first; n   double y = 1.0 * b.second / b.first; n   return x > y; n } n int main() { n   int i, j, n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[n - i + 1]); n   } n   for (i = 1; i <= n; i++) { n     s[i] = s[i - 1] + a[i]; n     ss[i] = ss[i - 1] + s[i]; n   } n   long long ans = 0; n   for (i = n; i >= 1; i--) { n     ans = max(ans, (long long)a[i]); n     while (tot > 1 && (que[tot - 1] - make_pair(i, ss[i])) > n                           (que[tot - 2] - que[tot - 1])) { n       tot--; n     } n     que[tot++] = make_pair(i, ss[i]); n     if (tot == 1) { n       continue; n     } n     int le = 0, ri = tot - 2; n     int mid; n     while (le <= ri) { n       mid = (le + ri) / 2; n       double x = (que[mid].second - que[mid + 1].second) * 1.0 / n                  (que[mid].first - que[mid + 1].first); n       if (x >= s[i - 1]) { n         ri = mid - 1; n       } else n         le = mid + 1; n     } n     ans = max(ans, n               que[le].second - ss[i - 1] - (que[le].first - i + 1) * s[i - 1]); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int row[] = {0, 1, 0, -1, -1, -1, 1, 1}; n int col[] = {1, 0, -1, 0, 1, -1, -1, 1}; n const long long N = 2e5 + 10; n const long long M = 1e18 + 7; n const long long H = 1e9 + 7; n const long long base = 131; n long long logx(long long a, long long bs) { return log(a) / log(bs); } n long long Max(long long a, long long b) { n   if (a > b) return a; n   return b; n } n long long Min(long long a, long long b) { n   if (a > b) return b; n   return a; n } n long long big_mul(long long a, long long b, long long m) { n   long long x = 0, y = a % m; n   while (b > 0) { n     if (b & 1) x = (x + y) % m; n     y = (2 * y) % m; n     b >>= 1; n   } n   return x % m; n } n long long big_mod(long long a, long long b, long long m) { n   long long x = 1, y = a % m; n   while (b > 0) { n     if (b & 1) x = (x * y) % m; n     y = (y * y) % m; n     b >>= 1; n   } n   return x % m; n } n long long Big_mod(long long a, long long b, long long m) { n   long long x = 1, y = a % m; n   while (b > 0) { n     if (b & 1) x = big_mul(x, y, m); n     y = big_mul(y, y, m); n     b >>= 1; n   } n   return x % m; n } n long long mod_inverse(long long a, long long m) { return big_mod(a, m - 2, m); } n long long GCD(long long a, long long b) { n   if (!a) return b; n   return GCD(b % a, a); n } n double l, r; n vector<double> vec1; n vector<double> vec2; n double fnct(double total, double value) { return total / value; } n bool possible(double x, double m) { n   double total = m + x; n   double need = fnct(total, vec1[0]); n   if (need > x) return false; n   x -= need; n   total = m + x; n   for (int i = 1; i < vec1.size(); i++) { n     need = fnct(total, vec2[i]); n     if (need > x) return false; n     x -= need; n     total = m + x; n     need = fnct(total, vec1[i]); n     if (need > x) return false; n     x -= need; n     total = m + x; n   } n   need = fnct(total, vec2[0]); n   if (need > x) return false; n   return true; n } n void bs(double m) { n   l = 0; n   r = (double)H; n   int cnt = 0; n   while (cnt++ <= 100) { n     double mid = (l + r) / 2.0; n     if (possible(mid, m) == true) n       r = mid; n     else n       l = mid; n   } n   if (l == H || r == H) n     cout <<  -1  << endl; n   else n     printf( %0.10lf n , l); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int n; n   cin >> n; n   double m; n   cin >> m; n   for (int i = 0; i < n; i++) { n     double a; n     cin >> a; n     vec1.push_back(a); n   } n   for (int i = 0; i < n; i++) { n     double a; n     cin >> a; n     vec2.push_back(a); n   } n   bs(m); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 11; n const long long MOD0 = 1e9 + 7; n const long long P0 = 37; n const long long MOD1 = 1e9 + 9; n const long long P1 = 49; n long long a[N], b[N]; n long long h1[2][N], h2[2][N], s[2][N]; n long long m, n; n map<int, bool> ans; n int getnext(int pos) { n   if (pos > a[n]) return 1e9; n   int l = 1, r = n; n   while (r - l > 1) { n     int mid = (l + r) / 2; n     if (a[mid] >= pos) n       r = mid; n     else n       l = mid; n   } n   if (a[l] >= pos) return l; n   return r; n } n int getprev(int pos) { n   if (pos < a[1]) return -1e9; n   int l = 1, r = n; n   while (r - l > 1) { n     int mid = (l + r) / 2; n     if (a[mid] <= pos) n       l = mid; n     else n       r = mid; n   } n   if (a[r] <= pos) return r; n   return l; n } n bool good0(int l, int r) { n   long long hash1 = h1[0][r] - h1[0][l - 1] + MOD0; n   hash1 *= s[0][n - r]; n   hash1 %= MOD0; n   long long hash2 = h2[0][l] - h2[0][r + 1] + MOD0; n   hash2 *= s[0][l]; n   hash2 %= MOD0; n   if (hash1 == hash2) return true; n   return false; n } n bool good1(int l, int r) { n   long long hash1 = h1[1][r] - h1[1][l - 1] + MOD1; n   hash1 *= s[1][n - r]; n   hash1 %= MOD1; n   long long hash2 = h2[1][l] - h2[1][r + 1] + MOD1; n   hash2 *= s[1][l]; n   hash2 %= MOD1; n   if (hash1 == hash2) return true; n   return false; n } n bool good(long long x, long long y) { n   if (x > y) return true; n   if (y < a[1]) return true; n   int l = getnext(x), r = getprev(y); n   if (l > r) return true; n   if (a[l] - x != y - a[r]) return false; n   if (l == r) return true; n   if (good1(l, r - 1) && good0(l, r - 1)) return true; n   return false; n } n bool good(long long p) { n   if (ans[p]) return false; n   ans[p] = 1; n   if (good(0, p) && good(p + 1, m - 1)) return true; n   return false; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   sort(a + 1, a + n + 1); n   for (int i = 1; i < n; i++) b[i] = a[i + 1] - a[i]; n   s[0][0] = 1; n   s[1][0] = 1; n   for (int i = 1; i <= n * 2; i++) { n     s[0][i] = (s[0][i - 1] * P0) % MOD0; n     s[1][i] = (s[1][i - 1] * P1) % MOD1; n   } n   for (int i = 1; i < n; i++) { n     h1[0][i] = (h1[0][i - 1] + b[i] * s[0][i]) % MOD0; n     h1[1][i] = (h1[1][i - 1] + b[i] * s[1][i]) % MOD1; n   } n   for (int i = n - 1; i >= 1; i--) { n     h2[0][i] = (h2[0][i + 1] + b[i] * s[0][n - i]) % MOD0; n     h2[1][i] = (h2[1][i + 1] + b[i] * s[1][n - i]) % MOD1; n   } n   vector<int> vv; n   for (int i = 1; i <= n; i++) { n     long long x = (a[1] + a[i]) % m; n     if (good(x)) vv.push_back(x); n   } n   sort(vv.begin(), vv.end()); n   cout << vv.size() << endl; n   for (int j = 0; j < vv.size(); j++) cout << vv[j] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   while (cin >> n) { n     vector<int> v; n     long long res, me = 0, mf = 0; n     for (int i = 0; i < n; i++) { n       int c; n       cin >> c; n       v.push_back(c); n     } n     long long res1 = 1000000 - v[0]; n     res = 1000007; n     v.push_back(1000000); n     for (int i = 0; i < v.size() - 1; i++) { n       me = v[i] - 1; n       mf = 1000000 - v[i + 1]; n       if (i == n - 1) { n         res = min(res, me); n         continue; n       } n       res = min(res, max(me, mf)); n     } n     cout << min(res, res1) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n int n, m, l, x, oo = 1000000007, c[100005], a[100005], b[100005]; n long long res = 1, ans; n long long Exp(long long x, long long y) { n   long long res = 1; n   for (; y; y >>= 1, x = x * x % oo) n     if (y & 1) res = res * x % oo; n   return res; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &x), c[x]++; n   for (int i = 100005 - 5; i; i--) c[i - 1] += c[i]; n   for (int i = 1; c[i]; i++) { n     m = l = 0, res = 1; n     for (int j = 1; j * j <= i; j++) n       if (i % j == 0) { n         a[m++] = j; n         if (j * j - i) b[l++] = i / j; n       } n     while (l--) a[m++] = b[l]; n     for (int j = 1; j < m; j++) res = res * Exp(j, c[a[j - 1]] - c[a[j]]) % oo; n     ans = (ans + res * (Exp(m, c[i]) - Exp(m - 1, c[i]))) % oo; n   } n   printf( %d n , (ans + oo) % oo); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double EXP = 1e-11; n const int maxn = 2e5 + 10; n int n; n double a[maxn]; n double a2[maxn]; n double Judge(double x) { n   double sum1 = 0.0, sum2 = 0.0, sum3 = 0.0; n   for (int i = 1; i <= n; i++) a2[i] = a[i] - x; n   for (int i = 1; i <= n; i++) { n     sum1 = max(sum1 + a2[i], a2[i]); n     sum3 = max(sum3, sum1); n   } n   for (int i = 1; i <= n; i++) a2[i] = a2[i] * (-1.0); n   for (int i = 1; i <= n; i++) { n     sum2 = max(sum2 + a2[i], a2[i]); n     sum3 = max(sum3, sum2); n   } n   return sum3; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %lf , &a[i]); n   double l = -40000.0, r = 40000.0; n   while (r - l > EXP) { n     double mid = (l + l + r) / 3.0; n     double mmid = (l + r + r) / 3.0; n     if (Judge(mid) >= Judge(mmid)) n       l = mid; n     else n       r = mmid; n   } n   printf( %.13lf n , min(Judge(l), Judge(r))); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n vector<bitset<7>> score; n vector<bitset<7>> bvec(10); n map<unsigned long, int> bmap; n bool flag = false; n long long ans = 0; n vector<string> anss; n int ccc = 0; n int ans_tab[2001][10][2001]; n bool valid(vector<bitset<7>>& s, int cur, int dig, int cnt) { n   if (ans_tab[cur][dig][cnt] != -1) return ans_tab[cur][dig][cnt]; n   ccc++; n   bool vld = (score[cur] & bvec[dig]).to_ulong() == score[cur].to_ulong(); n   if (vld) { n     int x = __builtin_popcount((char)(score[cur] ^ bvec[dig]).to_ulong()); n     if (cnt - x >= 0) { n       if (cur == n - 1 && cnt - x == 0) { n         flag = true; n         return ans_tab[cur][dig][cnt] = true; n       } else { n         for (int j = 9; j >= 0; j--) { n           if (ans_tab[cur][dig][cnt] = valid(s, cur + 1, j, cnt - x)) { n             return true; n           } n         } n       } n     } else { n       return ans_tab[cur][dig][cnt] = false; n     } n   } n   return ans_tab[cur][dig][cnt] = false; n } n void solve() { n   memset(ans_tab, -1, sizeof(ans_tab)); n   cin >> n >> k; n   string in; n   for (int i = 0; i < n; ++i) { n     cin >> in; n     score.emplace_back(in); n   } n   bvec = {bitset<7>( 1110111 ), bitset<7>( 0010010 ), bitset<7>( 1011101 ), n           bitset<7>( 1011011 ), bitset<7>( 0111010 ), bitset<7>( 1101011 ), n           bitset<7>( 1101111 ), bitset<7>( 1010010 ), bitset<7>( 1111111 ), n           bitset<7>( 1111011 )}; n   for (int i = 0; i < (int)bvec.size(); ++i) { n     bmap[bvec[i].to_ulong()] = i; n   } n   string test =   ; n   test =   ; n   int cc = k; n   for (int j = 9; j >= 0; --j) { n     valid(score, 0, j, cc); n   } n   if (flag) { n     for (int i = 0; i < n; ++i) { n       for (int j = 9; j >= 0; --j) { n         bool vld = (score[i] & bvec[j]).to_ulong() >= score[i].to_ulong(); n         if (vld) { n           int x = __builtin_popcount((char)(score[i] ^ bvec[j]).to_ulong()); n           if (cc - x >= 0) { n             if (ans_tab[i][j][cc]) { n               test += to_string(j); n               cc -= x; n               break; n             } n           } n         } n       } n     } n     cout << test << endl; n   } else n     cout << -1 << endl; n } n int main() { solve(); } n


#include <bits/stdc++.h> n using namespace std; n const int N = 110; n long long dp[N][N][N]; n char s[N]; n int a[N]; n long long f[N]; n void update(long long &x, long long y) { n   if (y == -1) return; n   if (x == -1 || x < y) x = y; n } n bool vis[N][N][N]; n long long dfs(int l, int r, int p) { n   if (l > r) return a[p]; n   if (vis[l][r][p]) return dp[l][r][p]; n   vis[l][r][p] = true; n   if (l == r) { n     return dp[l][r][p] = f[p + 1]; n   } n   dp[l][r][p] = dfs(l, r - 1, 0) + f[p + 1]; n   for (int k = l; k < r; k++) n     if (s[k] == s[r]) { n       update(dp[l][r][p], dfs(l, k, p + 1) + dfs(k + 1, r - 1, 0)); n     } n   return dp[l][r][p]; n } n int main() { n   int n; n   cin >> n; n   cin >> (s + 1); n   for (int i = 1; i <= n; i++) cin >> a[i]; n   f[0] = 0; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= i; j++) f[i] = max(f[i], f[i - j] + a[j]); n   memset(dp, -1, sizeof(dp)); n   cout << dfs(1, n, 0) << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n void test_case() { n   int n; n   cin >> n; n   vector<int> arr(n); n   for (int i = 0; i < n; i++) cin >> arr[i]; n   vector<int> l(n), r(n); n   l[0] = 1; n   for (int i = 1; i < n; i++) { n     if (arr[i] > arr[i - 1]) n       l[i] = l[i - 1] + 1; n     else n       l[i] = 1; n   } n   r[n - 1] = 1; n   for (int i = n - 2; i >= 0; i--) { n     if (arr[i] < arr[i + 1]) n       r[i] = r[i + 1] + 1; n     else n       r[i] = 1; n   } n   int ans = 1; n   for (int i = 0; i < n; i++) { n     if (i > 0 && i < n - 1 && arr[i + 1] >= arr[i - 1] + 2) { n       ans = max(ans, l[i - 1] + r[i + 1] + 1); n     } n     if (i > 0 && arr[i] <= arr[i - 1]) { n       ans = max(ans, 1 + l[i - 1]); n     } n     if (i < n - 1 && arr[i] >= arr[i + 1]) { n       ans = max(ans, 1 + r[i + 1]); n     } n   } n   ans = max(ans, l[n - 1]); n   ans = max(ans, r[0]); n   cout << ans << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int t = 1; n   while (t--) test_case(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n int sq[504][504], sum[504][504], dp[2][504][504]; n int main() { n   int n, m; n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n >> m; n   for (int i = 1; i < n + 1; ++i) n     for (int j = 1; j < m + 1; ++j) cin >> sq[i][j]; n   for (int i = 1; i < n + 1; ++i) n     for (int j = 1; j < m + 1; ++j) n       sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + sq[i][j]; n   int mx = -1000000000; n   for (int i = 1; i < n + 1; ++i) { n     for (int j = 1; j < m + 1; ++j) { n       int n = i % 2, p = (i - 1) % 2, n           len = min(2 * ((i - 1) / 2) + 1, 2 * ((j - 1) / 2) + 1); n       dp[n][j][1] = sq[i][j]; n       for (int k = 3; k <= len; k += 2) { n         dp[n][j][k] = sum[i][j] - sum[i - k][j] - sum[i][j - k] + n                       sum[i - k][j - k] - dp[p][j - 1][k - 2] - n                       sq[i - k + 2][j - k + 1]; n         mx = max(dp[n][j][k], mx); n       } n     } n   } n   cout << mx <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, k; n   scanf( %lld , &n); n   scanf( %lld , &k); n   long long int i, j; n   long long int val = 0, val1 = 0, val2 = 1; n   for (i = 1; i < k; i++) { n     val = (val * 10) + 9; n     val2 = val2 * 10; n   } n   val1 = (val * 10) + 9; n   long long int arr[n + 5]; n   long long int brr[n + 5]; n   long long int m = n / k; n   for (i = 0; i < m; i++) { n     scanf( %lld , &arr[i]); n   } n   for (i = 0; i < m; i++) { n     scanf( %lld , &brr[i]); n   } n   long long int tot = 1; n   long long int mod = 1e9 + 7; n   for (i = 0; i < m; i++) { n     long long int t1 = val1 / arr[i]; n     if (brr[i] != 0) t1++; n     long long int t2 = (brr[i] * val2) + val; n     long long int t3 = t2 / arr[i]; n     long long int t4 = (max(0LL, brr[i] * val2 - 1)) / arr[i]; n     t3 = t3 - t4; n     long long int t5 = t1 - t3; n     tot *= t5; n     tot %= mod; n   } n   cout << tot <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename _Tp, typename _Up> n bool maximize(_Tp &__a, _Up __b) { n   if (__a < __b) { n     __a = __b; n     return true; n   } n   return false; n } n template <typename _Tp, typename _Up> n bool minimize(_Tp &__a, _Up __b) { n   if (__a > __b) { n     __a = __b; n     return true; n   } n   return false; n } n const long long siz = 2e5 + 2; n const long long SIZ = 1e6 + 2; n const long long mod = 1e9 + 7; n const long long maxx = 2e9; n const long long MAXX = 1e18; n const string file =  3 ; n struct fenwick_tree { n   long long n; n   vector<long long> fwt; n   fenwick_tree(long long n) : n(n) { fwt.assign(n + 1, 0); } n   void pos_update(long long pos, long long val) { n     assert(1 <= pos && pos <= n); n     for (long long i = pos; i <= n; i += i & (-i)) { n       fwt[i] += val; n     } n   } n   long long pre_sum(long long pos) { n     assert(0 <= pos && pos <= n + 1); n     long long res = 0; n     for (long long i = pos; i > 0; i -= i & (-i)) { n       res += fwt[i]; n     } n     return res; n   } n   long long suf_sum(long long pos) { return (pre_sum(n) - pre_sum(pos - 1)); } n   long long range_sum(long long lt, long long rt) { n     if (lt > rt) { n       return 0; n     } n     return (pre_sum(rt) - pre_sum(lt - 1)); n   } n }; n long long ans[siz]; n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   vector<pair<pair<long long, long long>, long long> > hold; n   for (long long i = 1; i <= n; i++) { n     long long l, r; n     cin >> l >> r; n     hold.push_back(pair<pair<long long, long long>, long long>( n         pair<long long, long long>(l, r), i)); n   } n   vector<long long> rar; n   for (auto x : hold) { n     rar.push_back(x.first.first); n     rar.push_back(x.first.second); n   } n   sort((rar).begin(), (rar).end()); n   rar.resize(unique((rar).begin(), (rar).end()) - rar.begin()); n   for (auto &x : hold) { n     long long &l = x.first.first, &r = x.first.second; n     l = lower_bound((rar).begin(), (rar).end(), l) - rar.begin() + 1; n     r = lower_bound((rar).begin(), (rar).end(), r) - rar.begin() + 1; n   } n   sort((hold).begin(), (hold).end(), n        [](const pair<pair<long long, long long>, long long> &x, n           const pair<pair<long long, long long>, long long> &y) { n          return (x.first.first > y.first.first); n        }); n   fenwick_tree fen(2 * n); n   for (auto x : hold) { n     long long l = x.first.first, r = x.first.second, i = x.second; n     ans[i] = fen.pre_sum(r); n     fen.pos_update(r, 1); n   } n   for (long long i = 1; i <= n; i++) { n     cout << ans[i] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long first, second, cycle_s, cycle_len, l; n int n, m, d, cnt[2][1000005][26]; n string A, B; n int gcd(int first, int second) { n   if (!second) return first; n   return gcd(second, first % second); n } n int main() { n   cin >> first >> second >> A >> B; n   n = A.size(); n   m = B.size(); n   d = gcd(n, m); n   int i, j; n   for (i = 0; i < n; i += d) n     for (j = 0; j < d; j++) cnt[0][j][A[i + j] -  a ]++; n   for (i = 0; i < m; i += d) n     for (j = 0; j < d; j++) cnt[1][j][B[i + j] -  a ]++; n   for (j = 0; j < d; j++) n     for (i = 0; i < 26; i++) cycle_s += (long long)cnt[0][j][i] * cnt[1][j][i]; n   cycle_len = (long long)m * n / d; n   l = n * first; n   cout << l - l / cycle_len * cycle_s <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int64_t MOD = 1e9 + 7; n void add(int64_t& a, int64_t b) { a = (a + b) % MOD; } n int nth_bit(int64_t num, int n) { return (num >> n) & 1; } n const int SZ = 14 * 16; n void matmul(int64_t A[SZ][SZ], int64_t B[SZ][SZ]) { n   int64_t ret[SZ][SZ] = {0}; n   for (int i = 0; i < SZ; i++) n     for (int j = 0; j < SZ; j++) n       for (int k = 0; k < SZ; k++) add(ret[i][j], A[i][k] * B[k][j]); n   for (int i = 0; i < SZ; i++) n     for (int j = 0; j < SZ; j++) A[i][j] = ret[i][j]; n } n int main() { n   int N, K, M; n   cin >> N >> K >> M; n   static int64_t A[SZ][SZ]; n   for (int j = 0; j <= K; j++) n     for (int bits = 0; bits < 16; bits++) { n       int pos = 1; n       for (int k = 0; k < M; k++) n         if (nth_bit(bits, k)) pos++; n       add(A[(j + 1) * 16 + (bits << 1) % 16 + 1][j * 16 + bits], pos); n       add(A[j * 16 + (bits << 1) % 16][j * 16 + bits], 1); n     } n   static int64_t B[SZ][SZ]; n   for (int i = 0; i < SZ; i++) B[i][i] = 1; n   while (N > 0) { n     if (N % 2) matmul(B, A); n     matmul(A, A); n     N /= 2; n   } n   int64_t ans = 0; n   for (int bits = 0; bits < 16; bits++) add(ans, B[K * 16 + bits][0]); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double ans = 0.0000; n void bfs(); n list<int> arr[100005]; n int visited[100005], dep[100005]; n int main() { n   int n, i, start, end; n   cin >> n; n   n--; n   while (n--) { n     cin >> start; n     cin >> end; n     arr[start].push_back(end); n     arr[end].push_back(start); n   } n   bfs(); n   cout.precision(7); n   cout << fixed << ans; n   return 0; n } n void bfs() { n   int node; n   dep[1] = 1; n   queue<int> qu; n   list<int>::iterator iter = arr[1].begin(); n   node = 1; n   visited[1] = 1; n   qu.push(1); n   while (!qu.empty()) { n     for (iter = arr[node].begin(); iter != arr[node].end(); ++iter) { n       if (!visited[*iter]) { n         qu.push(*iter); n         visited[*iter] = 1; n         dep[*iter] = dep[node] + 1; n       } n     } n     int k = qu.front(); n     qu.pop(); n     node = qu.front(); n     ans += 1 / (double)dep[k]; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 10; n map<pair<int, int>, int> weight; n vector<int> edges[MAXN]; n bool visited[MAXN]; n long long int maximum; n void dfs(int v, long long int sum) { n   visited[v] = true; n   maximum = max(maximum, sum); n   for (int i : edges[v]) { n     if (!visited[i]) dfs(i, sum + weight[make_pair(v, i)]); n   } n   return; n } n int main() { n   long long int n, a, b, c, sum_of_edges = 0; n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     cin >> a >> b >> c; n     sum_of_edges += c; n     a--; n     b--; n     edges[a].push_back(b); n     edges[b].push_back(a); n     weight[make_pair(a, b)] = c; n     weight[make_pair(b, a)] = c; n   } n   dfs(0, 0); n   sum_of_edges *= 2; n   sum_of_edges -= maximum; n   cout << sum_of_edges << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5e5 + 5; n int c[maxn]; n int p[64], q[64]; n int l[maxn]; n int ans[maxn]; n vector<int> g[maxn]; n int main() { n   ios_base::sync_with_stdio(0); n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> c[i]; n   int Q; n   cin >> Q; n   for (int i = 1; i <= Q; i++) { n     int r; n     cin >> l[i] >> r; n     g[r].push_back(i); n   } n   for (int i = 1; i <= n; i++) { n     int r = i, x = c[i]; n     for (int j = 30; j >= 0; j--) { n       if (x >> j & 1) { n         if (!p[j]) { n           p[j] = x; n           q[j] = r; n           break; n         } n         if (q[j] < r) { n           swap(p[j], x); n           swap(q[j], r); n         } n         x ^= p[j]; n       } n     } n     for (int k = 0; k < g[i].size(); k++) { n       int now = g[i][k]; n       for (int j = 30; j >= 0; j--) { n         if (q[j] >= l[now]) ans[now] = max(ans[now], ans[now] ^ p[j]); n       } n     } n   } n   for (int i = 1; i <= Q; i++) cout << ans[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char puzzel[600]; n   vector<string> Puz; n   int m, n; n   int stp; n   int len = 0, judge = 0; n   int prevstp; n   int prevlen; n   int minv = 1000; n   int maxv = -9; n   int flag = 0; n   scanf( %d%d , &m, &n); n   for (int i = 0; i < m; i++) { n     scanf( %s , puzzel); n     Puz.push_back(puzzel); n   } n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < n; j++) { n       if (Puz[i][j] ==  X ) { n         stp = j; n         len++; n         for (int k = j; k < n - 1; k++) { n           if (Puz[i][k + 1] ==  X ) { n             len++; n           } else { n             break; n           } n         } n         if (flag == 0) { n           flag = 1; n           prevlen = len; n           prevstp = stp; n           len = 0; n         } else { n           if (prevstp == stp && prevlen == len) { n             prevstp = stp; n             prevlen = len; n             len = 0; n           } else { n             judge = 1; n           } n         } n         break; n       } n     } n   } n   if (judge == 1) { n     printf( NO n ); n   } else if (flag == 1) { n     printf( YES n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double const eps = 1e-6; n double const pi = 3.1415926535; n long long const mod = 1e9 + 7; n int a[20]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < (1 << n); i++) { n     int x = 0; n     for (int j = 0; j < n; j++) { n       if (i & (1 << j)) n         x += a[j]; n       else n         x -= a[j]; n     } n     if (x % 360 == 0) { n       cout <<  YES  << endl; n       return 0; n     } n   } n   cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> res; n int main() { n   cin.tie(0); n   cout.tie(0); n   ios::sync_with_stdio(0); n   long long n, f = 0, m; n   cin >> n; n   m = n; n   for (int i = 2; i <= sqrt(m); i++) { n     if (n % i == 0) { n       while (n % i == 0) { n         res.push_back(i); n         n /= i; n         if (res.size() == 3) { n           f = 1; n           break; n         } n       } n     } n   } n   if (res.size() == 2) { n     if (m == res[0] * res[1]) n       cout << 2; n     else n       cout << 1 << endl << res[0] * res[1]; n     return 0; n   } n   if (f) { n     cout << 1 << endl << (res[0] * res[1]); n     return 0; n   } n   if (res.empty()) n     cout << 1 << endl << 0; n   else n     cout << 2; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const int _inf = 0xc0c0c0c0; n const long long INF = 0x3f3f3f3f3f3f3f3f; n const long long _INF = 0xc0c0c0c0c0c0c0c0; n const long long mod = (int)1e9 + 7; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long ksm(long long a, long long b, long long mod) { n   int ans = 1; n   while (b) { n     if (b & 1) ans = (ans * a) % mod; n     a = (a * a) % mod; n     b >>= 1; n   } n   return ans; n } n long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); } n void exgcd(long long a, long long b, long long &x, long long &y, long long &d) { n   if (!b) { n     d = a; n     x = 1; n     y = 0; n   } else { n     exgcd(b, a % b, y, x, d); n     y -= x * (a / b); n   } n } n int arr[55], num[55]; n int main() { n   int n; n   long long d, tmp = 0; n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &arr[i]); n     num[arr[i]]++; n   } n   sort(arr + 1, arr + 1 + n); n   if (num[arr[1]] <= n / 2) n     printf( Alice n ); n   else n     printf( Bob n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n short k, r, m = 10; n int main() { n   cin >> k >> r; n   for (int i = 10; i > 0; --i) { n     if ((i * k) % 10 == 0 || (i * k - r) % 10 == 0) { n       m = i; n     } n   } n   cout << m; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int num[10]; n char s[100010]; n int main() { n   scanf( %d , &n); n   scanf( %s , s); n   for (int i = 0; i < n; i++) { n     if (s[i] ==  L ) { n       for (int j = 0; j < 10; j++) { n         if (num[j] == 0) { n           num[j] = 1; n           break; n         } n       } n     } else if (s[i] ==  R ) { n       for (int j = 9; j >= 0; j--) { n         if (num[j] == 0) { n           num[j] = 1; n           break; n         } n       } n     } else if (s[i] >=  0  && s[i] <=  9 ) { n       num[s[i] -  0 ] = 0; n     } n   } n   for (int i = 0; i < 10; i++) { n     printf( %d , num[i]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int a, b, n, s; n     cin >> a >> b >> n >> s; n     if ((min(s / n, a) * n + b) >= s) { n       cout <<  YES  << endl; n     } else { n       cout <<  NO  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   int l[m], r[m]; n   for (int i = 1; i <= m; i++) { n     scanf( %d %d , &l[i], &r[i]); n   } n   for (int i = 1; i <= n; i++) { n     if (i % 2 == 1) n       printf( 1 ); n     else n       printf( 0 ); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<int> numeros; n   string str4 =  2 * 3 = 6 n6 * 4 = 24 n24 * 1 = 24 ; n   string str5 =  3 - 1 = 2 n2 + 2 = 4 n4 * 5 = 20 n20 + 4 = 24 ; n   int n; n   scanf( %d , &n); n   if (n < 4) n     printf( NO ); n   else { n     printf( YES n ); n     if (n % 2 != 0) { n       cout << str5; n       for (int i = 6; i <= n; i += 2) { n         printf(  n%d - %d = 1 , (i + 1), i); n       } n       for (int i = 0; i < ((n - 5) / 2) - 1; i++) { n         printf(  n1 * 1 = 1 ); n       } n       if (n > 5) printf(  n24 * 1 = 24 ); n     } else if (n % 2 == 0) { n       cout << str4; n       for (int i = 5; i <= n; i += 2) { n         printf(  n%d - %d = 1 , (i + 1), i); n       } n       for (int i = 0; i < ((n - 4) / 2) - 1; i++) { n         printf(  n1 * 1 = 1 ); n       } n       if (n > 4) printf(  n24 * 1 = 24 ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void scanint(int &x) { n   register int c = getchar(); n   x = 0; n   int neg = 0; n   for (; ((c < 48 || c > 57) && c !=  - ); c = getchar()) n     ; n   if (c ==  - ) { n     neg = 1; n     c = getchar(); n   } n   for (; c > 47 && c < 58; c = getchar()) { n     x = (x << 1) + (x << 3) + c - 48; n   } n   if (neg) x = -x; n } n int cmp(int a, int b) { n   if (a > b) n     return a; n   else n     return b; n } n int main() { n   std::ios::sync_with_stdio(false); n   cin.tie(NULL); n   int n, m, i, j, k; n   cin >> n >> m; n   int a[n][3]; n   for (i = 0; i < n; i++) { n     for (j = 0; j < 3; j++) { n       a[i][j] = 55; n     } n   } n   for (i = 0; i < n; i++) { n     string s; n     cin >> s; n     for (j = 0; j < m; j++) { n       int ctr = 2; n       if (s[j] ==  #  || s[j] ==  *  || s[j] ==  & ) n         ctr = 0; n       else if (s[j] >=  0  && s[j] <=  9 ) n         ctr = 1; n       if (a[i][ctr] > min(j, m - j)) a[i][ctr] = min(j, m - j); n     } n   } n   int ans = 200; n   for (i = 0; i < n; i++) { n     for (j = 0; j < n; j++) { n       if (i == j) continue; n       for (k = 0; k < n; k++) { n         if (i == k || k == j) continue; n         ans = min(ans, a[i][0] + a[j][1] + a[k][2]); n       } n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n template <typename T> n inline void read(T &x) { n   char c; n   bool nega = 0; n   while ((!isdigit(c = getchar())) && (c !=  - )) n     ; n   if (c ==  - ) { n     nega = 1; n     c = getchar(); n   } n   x = c - 48; n   while (isdigit(c = getchar())) x = x * 10 + c - 48; n   if (nega) x = -x; n } n template <typename T> n inline void writep(T x) { n   if (x > 9) writep(x / 10); n   putchar(x % 10 + 48); n } n template <typename T> n inline void write(T x) { n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   writep(x); n   putchar(   ); n } n template <typename T> n inline void writeln(T x) { n   write(x); n   putchar(  n ); n } n using namespace std; n int u, v, l, r; n vector<pair<int, int> > ans; n map<pair<int, int>, bool> dd; n int main() { n   ios_base::sync_with_stdio(NULL); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> u >> v; n   int up = 1, down = u; n   l = 1, r = v; n   while (up <= down) { n     if (l == 1) { n       for (int i = (1); i <= (v); ++i) { n         ans.push_back(make_pair(up, l)); n         ++l; n         ans.push_back(make_pair(down, r)); n         --r; n       } n       ++up; n       --down; n       --l; n       ++r; n     } else { n       for (int i = (1); i <= (v); ++i) { n         ans.push_back(make_pair(up, l)); n         --l; n         ans.push_back(make_pair(down, r)); n         ++r; n       } n       ++up; n       --down; n       ++l; n       --r; n     } n   } n   for (auto v : ans) { n     if (dd[v]) continue; n     dd[v] = 1; n     cout << v.first <<     << v.second <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long modulo(long long base, long long exp, long long m); n int main() { n   int x; n   cin >> x; n   if (x <= 1) n     cout <<  -1 ; n   else { n     cout << x <<     << x; n   } n   return 0; n } n long long modulo(long long base, long long exp, long long m) { n   long long answer = 1; n   while (exp > 0) { n     if (exp % 2 == 1) answer = (answer * base) % m; n     exp = exp / 2; n     base = (base * base) % m; n   } n   return answer; n } n


#include <bits/stdc++.h> n using namespace std; n int n, i, last[28], tmp[28]; n long long ans[28]; n char s[300005]; n int main() { n   scanf( %s , s); n   for (i = 0; i <= 26; i++) last[i] = -1; n   int length = strlen(s); n   for (i = 0; i < length; i++) { n     last[s[i] -  a ] = i; n     for (int j = 0; j <= 26; j++) tmp[j] = last[j]; n     sort(tmp, tmp + 27); n     for (int j = 26; j; j--) ans[26 - j + 1] += tmp[j] - tmp[j - 1]; n   } n   for (i = 1; i <= 26; i++) n     if (!ans[i]) break; n   printf( %d n , i - 1); n   for (int j = 1; j < i; j++) printf( %I64d n , ans[j]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n = 5, sum = 0; n   while (n--) { n     int a; n     cin >> a; n     sum += a; n   } n   if (sum == 0) { n     cout << -1 << endl; n     return 0; n   } n   cout << (sum % 5 == 0 ? sum / 5 : -1) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000000; n struct debugger { n   template <typename T> n   debugger& operator,(const T& v) { n     cerr << v <<    ; n     return *this; n   } n } dbg; n char b[100][100]; n int n; n bool in(int x) { return x >= 0 && x < n; } n bool in(int x, int y) { return in(x) && in(y); } n char a[200][200]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < (n); i++) scanf( %s , b[i]); n   vector<pair<int, int> > ans; n   for (int dx = (-n + 1); dx <= (n - 1); dx++) { n     for (int dy = (-n + 1); dy <= (n - 1); dy++) { n       if (dx == 0 && dy == 0) { n         continue; n       } n       bool fail = false; n       for (int i = 0; i < (n); i++) { n         for (int j = 0; j < (n); j++) { n           if (b[i][j] ==  o  && in(i + dx, j + dy) && n               b[i + dx][j + dy] ==  . ) { n             fail = true; n           } n         } n       } n       if (!fail) { n         ans.emplace_back(dx, dy); n       } n     } n   } n   for (int i = 0; i < (n); i++) n     for (int j = 0; j < (n); j++) { n       if (b[i][j] ==  x ) { n         bool success = false; n         for (auto& p : ans) { n           if (in(i - p.first, j - p.second) && n               b[i - p.first][j - p.second] ==  o ) { n             success = true; n           } n         } n         if (!success) { n           puts( NO ); n           return 0; n         } n       } n     } n   puts( YES ); n   for (int i = 0; i < (2 * n - 1); i++) { n     for (int j = 0; j < (2 * n - 1); j++) { n       a[i][j] =  . ; n     } n   } n   a[n - 1][n - 1] =  o ; n   for (auto& p : ans) { n     a[n - 1 + p.first][n - 1 + p.second] =  x ; n   } n   for (int i = 0; i < (2 * n - 1); i++) { n     puts(a[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 10, maxm = 2e6 + 10; n const long long INF = 0x3f3f3f3f, mod = 1e9 + 7; n int casn, n, m, k; n namespace graph { n vector<int> g[maxn]; n int all, sz[maxn], root, maxt; n bool vis[maxn]; n int dfs_root(int now, int fa) { n   int cnt = 1; n   for (auto to : g[now]) { n     if (to == fa || vis[to]) continue; n     cnt += dfs_root(to, now); n   } n   int tmp = max(cnt - 1, all - cnt); n   if (maxt > tmp) maxt = tmp, root = now; n   return sz[now] = cnt; n } n int ans[maxn]; n void dfs_col(int now, int fa, int c) { n   ans[now] = c; n   for (auto to : g[now]) n     if (to != fa && !vis[to]) dfs_col(to, now, c); n } n void dfs_dv(int now, int d = 0) { n   vis[now] = 1; n   dfs_col(now, now, d); n   for (auto to : g[now]) { n     if (vis[to]) continue; n     maxt = root = n + 1; n     all = sz[to]; n     dfs_root(to, now); n     dfs_dv(root, d + 1); n   } n } n void solve(int n) { n   all = maxt = root = n + 1; n   dfs_root(1, 1); n   all -= maxt; n   dfs_dv(root); n } n }  // namespace graph n using namespace graph; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 2; i <= n; ++i) { n     int a, b; n     cin >> a >> b; n     g[a].push_back(b); n     g[b].push_back(a); n   } n   solve(n); n   for (int i = 1; i <= n; ++i) cout << char(ans[i] +  A ) <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)1e5 + 113; n const double eps = 1e-7; n struct pt { n   long double x, y; n   int ind; n   pt(long double x = 0, long double y = 0, int ind = 0) n       : x(x), y(y), ind(ind) {} n }; n long double dist(pt a, pt b) { n   return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); n } n int n; n pt a, b, t, rat[N]; n pt mnA[2], mnB[2]; n int used[N]; n long double ans = 1000000000000, newAns; n bool cnt1(pt x, pt y) { n   long double toX = sqrt(dist(a, x)) + sqrt(dist(t, y)); n   long double toY = sqrt(dist(a, y)) + sqrt(dist(t, x)); n   return (toX - toY < eps); n } n bool cnt2(pt x, pt y) { n   long double toX = sqrt(dist(b, x)) + sqrt(dist(t, y)); n   long double toY = sqrt(dist(b, y)) + sqrt(dist(t, x)); n   return (toX - toY < eps); n } n int main() { n   cout.precision(30); n   cin >> a.x >> a.y >> b.x >> b.y >> t.x >> t.y; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> rat[i].x >> rat[i].y; n     rat[i].ind = i; n   } n   sort(rat + 1, rat + n + 1, cnt1); n   mnA[0] = rat[1]; n   mnA[1] = rat[2]; n   sort(rat + 1, rat + n + 1, cnt2); n   mnB[0] = rat[1]; n   mnB[1] = rat[2]; n   if (n == 1) { n     ans = min(sqrt(dist(a, rat[1])), sqrt(dist(b, rat[1]))) + n           sqrt(dist(rat[1], t)); n     cout << ans; n     return 0; n   } n   ans = sqrt(dist(a, mnA[0])) + sqrt(dist(mnA[0], t)); n   used[mnA[0].ind] = 1; n   for (int i = 1; i <= n; i++) { n     if (used[rat[i].ind]) continue; n     ans += 2 * sqrt(dist(t, rat[i])); n   } n   memset(used, 0, sizeof(used)); n   newAns = sqrt(dist(b, mnB[0])) + sqrt(dist(mnB[0], t)); n   used[mnB[0].ind] = 1; n   for (int i = 1; i <= n; i++) { n     if (used[rat[i].ind]) continue; n     newAns += 2 * sqrt(dist(t, rat[i])); n   } n   ans = min(ans, newAns); n   memset(used, 0, sizeof(used)); n   newAns = sqrt(dist(a, mnA[0])) + sqrt(dist(mnA[0], t)); n   used[mnA[0].ind] = 1; n   if (used[mnB[0].ind]) { n     newAns += sqrt(dist(b, mnB[1])) + sqrt(dist(mnB[1], t)); n     used[mnB[1].ind] = 1; n   } else { n     newAns += sqrt(dist(b, mnB[0])) + sqrt(dist(mnB[0], t)); n     used[mnB[0].ind] = 1; n   } n   for (int i = 1; i <= n; i++) { n     if (used[rat[i].ind]) continue; n     newAns += 2 * sqrt(dist(t, rat[i])); n   } n   ans = min(ans, newAns); n   memset(used, 0, sizeof(used)); n   newAns = sqrt(dist(b, mnB[0])) + sqrt(dist(mnB[0], t)); n   used[mnB[0].ind] = 1; n   if (used[mnA[0].ind]) { n     newAns += sqrt(dist(a, mnA[1])) + sqrt(dist(mnA[1], t)); n     used[mnA[1].ind] = 1; n   } else { n     newAns += sqrt(dist(a, mnA[0])) + sqrt(dist(mnA[0], t)); n     used[mnA[0].ind] = 1; n   } n   for (int i = 1; i <= n; i++) { n     if (used[rat[i].ind]) continue; n     newAns += 2 * sqrt(dist(t, rat[i])); n   } n   ans = min(ans, newAns); n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, i, j, l, r, poss_rn, poss_rm, poss_n, poss_m, k, ans1, ans2; n priority_queue<tuple<long long, int, int>> pq; n map<pair<int, int>, bool> um; n long long f(int x, int y) { n   long long a, b; n   if (x == poss_rn) n     a = poss_n; n   else n     a = 2; n   if (y == poss_rm) n     b = poss_m; n   else n     b = 2; n   return a * b; n } n int main() { n   cin >> n >> m >> r >> k; n   if (n > m) swap(n, m); n   poss_rn = min(r, n - r + 1); n   poss_rm = min(r, m - r + 1); n   ans2 = (n - r + 1) * (m - r + 1); n   poss_n = n - 2 * (poss_rn - 1); n   poss_m = m - 2 * (poss_rm - 1); n   r++; n   pq.push(make_tuple(poss_rn * poss_rm, poss_rn, poss_rm)); n   um[{poss_rn, poss_rm}] = true; n   while (k) { n     tie(m, i, j) = pq.top(); n     pq.pop(); n     l = f(i, j); n     if (l != 0) { n       if (k <= l) { n         ans1 += k * m; n         k = 0; n       } else { n         ans1 += l * m; n         k -= l; n       } n     } n     if (i != 1 && um[{i - 1, j}] == false) { n       um[{i - 1, j}] = true; n       pq.push(make_tuple((i - 1) * j, i - 1, j)); n     } n     if (j != 1 && um[{i, j - 1}] == false) { n       --j; n       pq.push(make_tuple(i * j, i, j)); n       um[{i, j}] = true; n     } n   } n   printf( %.9f , (double)ans1 / (double)ans2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a = 1, b = 1; n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     a = a * 27 % 1000000007; n     b = b * 7 % 1000000007; n   } n   cout << (a + 1000000007 - b) % 1000000007; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MXN = 2000010; n int N, M; n int A[MXN], B[MXN], T[32] = {}; n void init() { n   scanf( %d%d , &N, &M); n   for (int i = 1; i <= N; i++) scanf( %d , A + i); n   for (int i = 1; i <= M; i++) scanf( %d , B + i), T[B[i]]++; n } n namespace solve { n long long answer = 0; n int sat[MXN], m = 0, p = 1; n void solve() { n   for (int b = 30; b >= 0; b--) { n     for (int i = 1; i <= N; i++) { n       int x = min(T[b], A[i] >> b); n       A[i] -= x << b; n       T[b] -= x; n       for (int i = 0; i < x; i++) sat[++m] = b; n     } n     while (T[b] && p <= m && sat[p] > b) { n       A[++N] = 1 << sat[p++]; n       int x = min(T[b], A[N] >> b); n       A[N] -= x << b; n       T[b] -= x; n       for (int i = 0; i < x; i++) sat[++m] = b; n     } n   } n   cout << m - p + 1 << endl; n } n }  // namespace solve n int main() { n   init(); n   solve::solve(); n   return 0; n } n