#include <bits/stdc++.h> n using namespace std; n const int N = 500010; n struct E { n   int u, v, w, I; n } e[N]; n int n, m, F[N], T[N], q, k, a[N], A[N], V, d, L[N], C[N]; n vector<int> G[N]; n bool M(E a, E b) { return a.w < b.w; } n int P(int x) { return x == A[x] ? x : A[x] = P(A[x]); } n void D(int b, int x) { n   if (L[x] == b) return; n   L[x] = b; n   V++; n   d += G[x].size(); n   for (int J = 0; J < G[x].size(); J++) D(b, G[x][J]); n } n bool K(int b, int x) { n   V = d = 0; n   D(b, x); n   return d == 2 * (V - 1); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     scanf( %d%d%d , &e[i].u, &e[i].v, &e[i].w); n     e[i].I = i; n     F[i] = e[i].u; n     T[i] = e[i].v; n   } n   for (int i = 1; i <= n; i++) A[i] = i; n   sort(e + 1, e + m + 1, M); n   for (int i = 1; i <= m; i++) { n     int o = i; n     while (e[o].w == e[i].w && o <= m) { n       int u = P(e[o].u), v = P(e[o].v); n       F[e[o].I] = u; n       T[e[o].I] = v; n       C[e[o].I] = u != v; n       o++; n     } n     for (; i < o; i++) A[P(e[i].u)] = P(e[i].v); n     i--; n   } n   scanf( %d , &q); n   for (int c = 1; c <= q; c++) { n     scanf( %d , &k); n     bool Y = 1; n     for (int i = 1; i <= k; i++) { n       scanf( %d , &a[i]); n       if (!C[a[i]]) Y = 0; n       G[F[a[i]]].clear(); n       G[T[a[i]]].clear(); n     } n     for (int i = 1; i <= k; i++) n       G[F[a[i]]].push_back(T[a[i]]), G[T[a[i]]].push_back(F[a[i]]); n     for (int i = 1; i <= k; i++) { n       int x = F[a[i]], y = T[a[i]]; n       if (L[x] != c) Y &= K(c, x); n       if (L[y] != c) Y &= K(c, y); n     } n     puts(Y ?  YES  :  NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, const char* argv[]) { n   int x1, x2, y1, y2, dx, dy, px, py; n   cin >> x1 >> y1 >> x2 >> y2 >> px >> py; n   dx = abs(x2 - x1); n   dy = abs(y2 - y1); n   if (dx % px != 0 || dy % py != 0) { n     cout <<  NO ; n     exit(0); n   } n   int a = dx / px; n   int b = dy / py; n   if (a % 2 == b % 2) { n     cout <<  YES ; n   } else { n     cout <<  NO ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int a[100005]; n int p[100005]; n long long size[100005]; n struct edge { n   int u, v, w; n   edge(int u = 0, int v = 0, int w = 0) : u(u), v(v), w(w) {} n   bool operator<(const edge &e1) const { return w > e1.w; } n } eList[100005]; n int findR(int x) { n   if (p[x] == x) return x; n   return p[x] = findR(p[x]); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   int u, v; n   for (int i = 1; i <= m; i++) { n     scanf( %d%d , &u, &v); n     eList[i] = edge(u, v, min(a[u], a[v])); n   } n   for (int i = 1; i <= n; i++) { n     p[i] = i; n     size[i] = 1; n   } n   sort(eList + 1, eList + m + 1); n   long long ans = 0; n   int x, y; n   for (int i = 1; i <= m; i++) { n     u = eList[i].u; n     v = eList[i].v; n     x = findR(u); n     y = findR(v); n     if (x != y) { n       ans += eList[i].w * (size[x] * size[y]); n       p[x] = y; n       size[y] += size[x]; n     } n   } n   printf( %.6lf , ans * 2.0 / n / (n - 1)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, p; n set<int> ss; n int idx[500500]; n char str[500500], op[500500]; n int main() { n   cin >> n >> m >> p; n   scanf( %s%s , str + 1, op + 1); n   stack<int> s; n   ss.insert(0); n   for (int i = 1; i <= n; i++) { n     ss.insert(i); n     if (str[i] ==  ( ) n       s.push(i); n     else n       idx[s.top()] = i, idx[i] = s.top(), s.pop(); n   } n   for (int i = 1; i <= m; i++) { n     if (op[i] ==  R ) n       p = *ss.upper_bound(p); n     else if (op[i] ==  L ) n       p = *prev(ss.lower_bound(p)); n     else { n       auto it = ss.lower_bound(p); n       int from = *it; n       int to = idx[from]; n       int val; n       do { n         val = *it; n         auto nxt = it; n         if (from < to) n           nxt++; n         else n           nxt--; n         ss.erase(it); n         it = nxt; n       } while (val != to); n       if (from > to) it++; n       if (it == ss.end()) it--; n       p = *it; n     } n   } n   for (auto it : ss) n     if (it) printf( %c , str[it]); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 1e5 + 10; n const long long INF = 1e18; n int n, m, h[MAXN], a[MAXN], c[MAXN]; n double x, ans[MAXN]; n vector<pair<int, int>> g[MAXN]; n vector<int> going; n bool visited[MAXN], b, res, f; n void dfs(int v, int hi, int p) { n   visited[v] = true; n   going.push_back(v); n   h[v] = hi; n   for (auto u : g[v]) { n     if (!visited[u.first]) { n       a[u.first] = u.second - a[v]; n       dfs(u.first, hi + 1, v); n     } else if (u.first != p) { n       if ((h[v] & 1) == (h[u.first] & 1)) { n         double z = double(a[v] - (u.second - a[u.first])) / 2; n         if (!(h[v] & 1)) { n           z *= -1; n         } n         if (!b) { n           b = true; n           x = z; n         } else if (z != x) { n           res = false; n         } n       } else { n         if (u.second - a[u.first] != a[v]) { n           res = false; n         } n       } n     } n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int u, v, c; n     cin >> u >> v >> c; n     g[u].push_back({v, c}); n     g[v].push_back({u, c}); n   } n   res = true; n   for (int i = 1; i <= n; i++) { n     if (!visited[i]) { n       b = false; n       going.clear(); n       dfs(i, 0, 0); n       if (res) { n         if (!b) { n           for (int j = 0; j < going.size(); j++) { n             if (h[going[j]] & 1) { n               c[j] = a[going[j]]; n             } else { n               c[j] = -a[going[j]]; n             } n           } n           sort(c, c + going.size()); n           x = c[going.size() / 2]; n         } n         for (auto j : going) { n           if (h[j] & 1) { n             ans[j] = double(a[j]) - x; n           } else { n             ans[j] = double(a[j]) + x; n           } n         } n       } else { n         cout <<  NO ; n         return 0; n       } n     } n   } n   cout <<  YES  <<   n ; n   for (int i = 1; i <= n; i++) { n     if (ceil(ans[i]) != ans[i]) { n       cout << fixed << setprecision(1); n     } n     cout << ans[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1e9 + 7; n void solve() { n   int n, m, k; n   cin >> n >> m >> k; n   vector<int> A(n); n   for (int i = 0; i < n; ++i) { n     cin >> A[i]; n   } n   int x = min(k, m - 1); n   int y = m - 1 - x; n   vector<int> b; n   for (int i = 0; i + n - m < n; ++i) { n     b.push_back(max({A[i], A[i + n - m]})); n   } n   deque<int> dq; n   for (int i = 0; i <= y; ++i) { n     while (!dq.empty() && b[dq.back()] >= b[i]) { n       dq.pop_back(); n     } n     dq.push_back(i); n   } n   int ans = b[dq.front()]; n   for (int i = y + 1; i <= m - 1; ++i) { n     while (!dq.empty() && b[dq.back()] >= b[i]) { n       dq.pop_back(); n     } n     while (!dq.empty() && dq.front() <= i - (y + 1)) { n       dq.pop_front(); n     } n     dq.push_back(i); n     ans = max(ans, b[dq.front()]); n   } n   cout << ans <<   n ; 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 namespace std; n const int N = 2e3 + 10, INF = 1e9 + 7; n int r[N][N], n, a[N], o[N], t[N]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   for (int i = 1; i <= n; i++) { n     o[i] = o[i - 1]; n     if (a[i] == 1) o[i]++; n   } n   for (int i = n; i >= 0; i--) { n     t[i] = t[i + 1]; n     if (a[i] == 2) t[i]++; n   } n   for (int i = 1; i <= n; i++) { n     r[i][i] = 1; n     for (int j = i + 1; j <= n; j++) { n       r[i][j] = r[i][j - 1]; n       if (a[j] == 1) n         r[i][j]++; n       else if (t[i - 1] - t[j + 1] > r[i][j]) n         r[i][j] = t[i - 1] - t[j + 1]; n     } n   } n   int MAX = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = i; j <= n; j++) { n       MAX = max(o[i - 1] + r[i][j] + t[j + 1], MAX); n     } n   } n   cout << MAX <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int qq = 1; n   cin >> qq; n   for (int qqq = 0; qqq < qq; qqq++) { n     int n, first, v; n     cin >> n >> first; n     int maxx = 0; n     int maxxd = 0; n     for (int i = 0; i < n; i++) { n       cin >> v; n       maxx = max(maxx, v); n       if (v <= first) { n         maxxd = max(maxxd, v); n       } n     } n     if (maxxd == 0) n       cout << 2 <<   n ; n     else if (maxx == maxxd) { n       cout << first / maxx + (first % maxx > 0) <<   n ; n     } else if (maxxd == first) { n       cout << 1 <<   n ; n     } else n       cout << 2 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   ; n   long long ans = 0; n   int arr[n]; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   sort(arr, arr + n); n   for (int i = 0; i < n; i++) { n     ans += abs(i + 1 - arr[i]); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int fa[100010]; n int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } n bool merge(int x, int y) { n   int f1 = find(x), f2 = find(y); n   if (f1 == f2) return false; n   fa[f2] = f1; n   return true; n } n int main() { n   int n, k; n   scanf( %d %d , &n, &k); n   int ans = 0; n   for (int i = 1; i <= n; i++) fa[i] = i; n   for (int i = 1; i <= k; i++) { n     int u, v; n     scanf( %d %d , &u, &v); n     ans += merge(u, v); n   } n   printf( %d n , k - ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline void open(const char *s) {} n inline int rd() { n   static int x, f; n   x = 0; n   f = 1; n   char ch = getchar(); n   for (; ch <  0  || ch >  9 ; ch = getchar()) n     if (ch ==  - ) f = -1; n   for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ; n   return f > 0 ? x : -x; n } n const int N = 5010; n int n; n bool f[N][N]; n char s[N], ans[N]; n int main() { n   open( hh ); n   scanf( %s , s + 1); n   n = strlen(s + 1); n   int m = -1; n   while ((1 << (m + 1)) <= n) ++m; n   int Max = (1 << m) - 1, nn = n - Max; n   memset(f[0], 1, sizeof f[0]); n   for (int i = 1; i <= nn; i++) { n     char mn =  z  + 1; n     for (int j = 0; j <= Max; j++) f[i][j] = f[i - 1][j]; n     for (int j = 0; j <= Max; j++) n       if (f[i][j]) mn = min(mn, s[i + j]); n     for (int j = 0; j <= Max; j++) n       if (mn != s[i + j]) f[i][j] = 0; n     for (int j = 0; j <= Max; j++) n       for (int k = 0; k <= m; k++) n         if (j >> k & 1) f[i][j] |= f[i][j ^ (1 << k)]; n     ans[i] = mn; n   } n   printf( %s , ans + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct edge { n   int to, cost; n   edge(int to = 0, int cost = 0) : to(to), cost(cost) {} n }; n vector<edge> vec[100005]; n long long int F[100005], G[100005]; n int nd[100005]; n int n; n long long int mpow(long long int m, long long int t) { n   if (t == 0) return 1LL; n   long long int ret = mpow(m * m % 1000000007, t / 2); n   if (t % 2 == 1) ret = ret * m % 1000000007; n   return ret; n } n long long int inv(long long int m) { return mpow(m, 1000000007 - 2); } n void dfs(int v = 0, int p = -1) { n   if (vec[v].size() == 1) { n     F[v] = G[v] = 0; n     return; n   } n   long long int sumG = 0, sumF = vec[v].size(); n   for (int i = 0; i < vec[v].size(); i++) { n     edge e = vec[v][i]; n     sumG += e.cost; n     if (sumG >= 1000000007) sumG -= 1000000007; n     if (e.to != p) { n       dfs(e.to, v); n       sumG += G[e.to]; n       if (sumG >= 1000000007) sumG -= 1000000007; n       sumF -= F[e.to]; n       if (sumF < 0) sumF += 1000000007; n     } n   } n   long long int g = inv(sumF); n   F[v] = g; n   G[v] = g * sumG % 1000000007; n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n - 1; i++) { n     int a, b, c; n     scanf( %d %d %d , &a, &b, &c); n     vec[a].push_back(edge(b, c)); n     vec[b].push_back(edge(a, c)); n   } n   dfs(); n   printf( %lld n , G[0]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = LLONG_MAX - 1e10; n const long long maxn = 1e6 + 5; n const long long mo_num = 1e9 + 7; n long long n, m, a[maxn], b[maxn], ans; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   for (long long i = 1; i <= 4; i++) cin >> a[i]; n   long long key = 0; n   if (a[1] == a[4]) { n     if (!a[3]) n       key = 1; n     else if (a[1] > 0) n       key = 1; n   } n   cout << key ? 1 : 0; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     int x; n     scanf( %d , &x); n     bool found = 0; n     for (int n = 1; n <= 200000; n++) { n       int lo = 1, hi = n; n       bool done = 0; n       while (lo <= hi) { n         int m = lo + hi >> 1; n         long long val = 1ll * n * n - 1ll * (n / m) * (n / m); n         if (val == x) { n           done = 1; n           printf( %d %d n , n, m); n           break; n         } n         if (val < x) lo = m + 1; n         if (val > x) hi = m - 1; n       } n       if (done) { n         found = 1; n         break; n       } n     } n     if (!found) puts( -1 ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 100; n int n, h, l, r, dp[2222][2222], a[2222]; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> h >> l >> r; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < h; i++) n     for (int j = 0; j <= n; j++) dp[j][i] = -1e9; n   dp[0][0] = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < h; j++) { n       int x = j + a[i]; n       if (x >= h) x -= h; n       dp[i + 1][x] = max(dp[i + 1][x], dp[i][j] + (l <= x && x <= r)); n       int y = j + a[i] - 1; n       if (y >= h) y -= h; n       dp[i + 1][y] = max(dp[i + 1][y], dp[i][j] + (l <= y && y <= r)); n     } n   } n   cout << *max_element(dp[n], dp[n] + h); n   cerr <<   nTime elapsed:   << 1.0 * clock() / CLOCKS_PER_SEC <<   s. n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int max_n = 1e3 + 5; n const int max_p = 1e3 + 5; n const int max_k = 50 + 5; n bool a[max_n], b[max_n]; n int dp[2][max_p][max_k][max_k]; n inline void check_max(int &x, int y) { x = max(x, y); } n int main() { n   int n, p, k; n   scanf( %d%d%d , &n, &p, &k); n   int r; n   scanf( %d , &r); n   for (int i = 1; i <= r; ++i) { n     int x; n     scanf( %d , &x); n     a[x] = true; n   } n   int s; n   scanf( %d , &s); n   for (int i = 1; i <= s; ++i) { n     int x; n     scanf( %d , &x); n     b[x] = true; n   } n   if (p >= 2 * ((n + k - 1) / k)) { n     int ans = 0; n     for (int i = 1; i <= n; ++i) ans += a[i] | b[i]; n     printf( %d n , ans); n     return 0; n   } n   for (int j = 0; j <= p; ++j) n     for (int l = 0; l < k; ++l) n       for (int r = 0; r < k; ++r) dp[0][j][l][r] = -1e9; n   dp[0][p][0][0] = 0; n   for (int i = 1; i <= n; ++i) { n     int y = i & 1, x = y ^ 1; n     for (int j = 0; j <= p; ++j) n       for (int l = 0; l < k; ++l) n         for (int r = 0; r < k; ++r) dp[y][j][l][r] = -1e9; n     for (int j = 0; j <= p; ++j) n       for (int l = 0; l < k; ++l) n         for (int r = 0; r < k; ++r) { n           if (dp[x][j][l][r] >= 0) { n             check_max(dp[y][j][max(l - 1, 0)][max(r - 1, 0)], n                       dp[x][j][l][r] + ((l > 0 && a[i]) || (r > 0 && b[i]))); n             if (j > 0) { n               if (a[i]) n                 check_max(dp[y][j - 1][k - 1][max(r - 1, 0)], n                           dp[x][j][l][r] + 1); n               if (b[i]) n                 check_max(dp[y][j - 1][max(l - 1, 0)][k - 1], n                           dp[x][j][l][r] + 1); n             } n           } n         } n   } n   int x = n & 1, ans = 0; n   for (int j = 0; j <= p; ++j) n     for (int l = 0; l < k; ++l) n       for (int r = 0; r < k; ++r) ans = max(ans, dp[x][j][l][r]); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long calc(long long n, long long k) { n   long long a = 1, b = 1, c; n   for (long long i = 1; i <= k; i++) a = a * (n - i + 1), b = b * i; n   if (k == 4) n     c = 9; n   else if (k == 3) n     c = 2; n   else if (k == 2) n     c = 1; n   else n     c = 0; n   return c * a / b; n } n int main() { n   long long n, k; n   cin >> n >> k; n   long long res = 0; n   while (k) res += calc(n, k--); n   cout << res + 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long x = 0; n   char zf = 1; n   char ch = getchar(); n   while (ch !=  -  && !isdigit(ch)) ch = getchar(); n   if (ch ==  - ) zf = -1, ch = getchar(); n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar(); n   return x * zf; n } n void write(long long y) { n   if (y < 0) putchar( - ), y = -y; n   if (y > 9) write(y / 10); n   putchar(y % 10 + 48); n } n void writeln(const long long y) { n   write(y); n   putchar(  n ); n } n int i, j, k, m, n, cnt; n const double PI = acos(-1.0); n struct node { n   int x, y; n } a[3030]; n double b[5030]; n int main() { n   n = read(); n   for (register int i = 1; i <= n; i++) a[i].x = read(), a[i].y = read(); n   unsigned long long ans = 0; n   for (register int i = 1; i <= n; i++) { n     cnt = 0; n     for (register int j = 1; j <= n; j++) n       if (i != j) b[++cnt] = atan2(a[j].x - a[i].x, a[j].y - a[i].y); n     sort(b + 1, b + cnt + 1); n     for (register int i = cnt + 1; i <= 2 * cnt; i++) n       b[i] = b[i - cnt] + PI * 2; n     for (register int j = k = 1; j <= cnt; j++) { n       if (k < j) k = j; n       while (k < cnt * 2 && b[k + 1] - b[j] < PI) k++; n       int sum = k - j, sum2 = cnt - sum - 1; n       ans += (unsigned long long)sum * (sum - 1) * sum2 * (sum2 - 1) / 4; n     } n   } n   cout << ans / 2; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n ostream &operator<<(ostream &str, vector<T> &a) { n   for (auto &i : a) { n     str << i <<    ; n   } n   return str; n } n template <class T> n istream &operator>>(istream &str, vector<T> &a) { n   for (auto &i : a) { n     str >> i; n   } n   return str; n } n template <class T> n ostream &operator<<(ostream &str, pair<T, T> &a) { n   str << a.first <<     << a.second; n   return str; n } n template <class T> n istream &operator>>(istream &str, pair<T, T> &a) { n   str >> a.first >> a.second; n   return str; n } n void solve(); n signed main() { n   srand(time(0)); n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cout.setf(ios::fixed); n   cout.precision(6); n   solve(); n   return 0; n } n const long long MOD = 998244353, MAXN = 5e5 + 10, INF = 1e18 + 10, BASE = 37; n long long bin_pow(long long a, long long n) { n   if (n == 0) { n     return 1; n   } n   if (n & 1) { n     return a * bin_pow(a, n - 1) % MOD; n   } else { n     long long tmp = bin_pow(a, n / 2); n     return tmp * tmp % MOD; n   } n } n void solve() { n   long long n; n   cin >> n; n   vector<long long> c(n); n   cin >> c; n   sort((c).rbegin(), (c).rend()); n   long long ans = 0; n   for (long long i = 0; i < n; ++i) { n     ans = (ans + i * c[i] % MOD) % MOD; n   } n   cout << ans * bin_pow(n, MOD - 2) % MOD <<    ; n   vector<long long> ps(n); n   ps[0] = c[0]; n   for (long long i = 1; i < n; ++i) { n     ps[i] = (ps[i - 1] + c[i]) % MOD; n   } n   for (long long k = 2; k <= n; ++k) { n     ans = 0; n     for (long long i = k - 1; i <= n - 1; i += k) { n       ans = (ans + n              ((i / k) * (ps[i] - (i - k == -1 ? 0 : ps[i - k]) + MOD)) % MOD) % n             MOD; n     } n     if (n % k != 0) { n       ans = (ans + ((n - 1) / k) * n                        (ps[n - 1] - n                         (n - 1 - n % k == -1 ? 0 : ps[n - 1 - n % k]) + MOD) % n                        MOD) % n             MOD; n     } n     cout << ans * bin_pow(n, MOD - 2) % MOD <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC optimize( -ffloat-store ) n #pragma GCC optimize( -fno-defer-pop ) n long long int power(long long int a, long long int b, long long int m) { n   if (b == 0) return 1; n   if (b == 1) return a % m; n   long long int t = power(a, b / 2, m) % m; n   t = (t * t) % m; n   if (b & 1) t = ((t % m) * (a % m)) % m; n   return t; n } n long long int modInverse(long long int a, long long int m) { n   return power(a, m - 2, m); n } n long long int solve(long long int n) { n   long long int a, b, mid, an = -1, k, l; n   a = 1; n   b = 1e9; n   while (b >= a) { n     mid = (a + b) / 2; n     k = mid; n     l = 0; n     while (k > 0) { n       l += (k / 5); n       k = k / 5; n     } n     if (l == n) { n       an = mid; n       b = mid - 1; n     } else if (l > n) { n       b = mid - 1; n     } else { n       a = mid + 1; n     } n   } n   return an; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int i, j, k, l, n; n   cin >> n; n   k = solve(n); n   if (k == -1) { n     cout <<  0  n          <<   n ; n   } else { n     cout <<  5 n ; n     for (i = k; i < k + 5; i++) { n       cout << i <<    ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int nn = 115; n const double PI = 2 * acos(0); n int main() { n   int n; n   double r; n   double ans; n   cin >> n >> r; n   double x = (PI * (180 - (360.0 / n)) / 2.0) / 180.0; n   double L = 0, R = 1e5; n   while (L <= R) { n     double mid = (L + R) / 2.0; n     if (fabs(cos(x) * (mid + r) - mid) < 1e-9) { n       ans = mid; n       break; n     } else if (cos(x) * (mid + r) > (mid)) { n       L = mid; n     } else { n       R = mid; n     } n   } n   printf( %.6f n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, i, o = 0; n   cin >> n; n   long long int a[n]; n   for (i = 0; i < n; ++i) { n     cin >> a[i]; n     if (a[i] & 1) o++; n   } n   cout << min(o, n - o); n } n


#include <bits/stdc++.h> n using namespace std; n int count(string &s) { n   int p = 0; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  1 ) p++; n   } n   return p; n } n int main() { n   string a, b; n   cin >> a >> b; n   int x, y; n   x = count(a); n   y = count(b); n   if (x >= y || (x + 1 == y && x % 2 == 1)) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int n = s.length(); n   bool sign = false; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  a  && !sign) continue; n     if (s[i] ==  a  && sign) break; n     s[i]--; n     sign = true; n   } n   if (!sign) s[n - 1] =  z ; n   cout << s <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int q, n, a[200000 + 5], cnt[200000 + 5]; n int main() { n   scanf( %d , &q); n   for (; q--;) { n     memset(cnt, 0, sizeof(cnt)); n     int sum1 = 0, sum2 = 0, tot = 0, m = 0; n     scanf( %d , &n); n     for (int i = 1; i <= n; i++) { n       scanf( %d , &a[i]); n       cnt[a[i]]++; n       m = max(a[i], m); n     } n     if (m % 30 == 0 && cnt[m / 2] && cnt[m / 3] && cnt[m / 5]) n       sum1 = m / 30 * 31; n     for (int i = 200000; i >= 1; i--) n       if (cnt[i]) { n         for (int j = i - 1; j >= 1; j--) n           if (i % j == 0) cnt[j] = 0; n         tot++; n         sum2 += i; n         if (tot == 3) break; n       } n     printf( %d n , max(sum1, sum2)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T sqr(T x) { n   return x * x; n } n template <class T> n inline T parse(const string &s) { n   T x; n   stringstream ss(s); n   ss >> x; n   return x; n } n const double EPS = 1e-12; n const int INF = 1000 * 1000 * 1000; n const long long LINF = INF * 1ll * INF; n const double DINF = 1e200; n const double PI = 3.1415926535897932384626433832795l; n int gcd(int a, int b) { return a ? gcd(b % a, a) : b; } n long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; } n long long gcdex(long long a, long long b, long long &x, long long &y) { n   if (!a) { n     x = 0, y = 1; n     return b; n   } n   long long k = b / a; n   long long g = gcdex(b - k * a, a, y, x); n   x -= k * y; n   return g; n } n long long inv(long long a, long long m) { n   assert(m > 1); n   long long x, y, g; n   g = gcdex(a, m, x, y); n   return (x % (m / g) + m / g) % m / g; n } n long long crt(long long a1, long long m1, long long a2, long long m2) { n   long long a = (a2 - a1 % m2 + m2) % m2; n   long long x, y, g; n   g = gcdex(m1, m2, x, y); n   if (a % g) return -1; n   long long m = m1 / g * m2; n   assert(x + m2 >= 0); n   x = a / g * (x + m2) % m2; n   long long r = (a1 + x * m1) % m; n   assert(r % m1 == a1 && r % m2 == a2); n   return r; n } n long long powmod(long long a, long long p, long long m) { n   assert(p >= 0); n   long long r = 1; n   while (p) { n     if (p & 1) r = r * a % m; n     p >>= 1; n     a = a * a % m; n   } n   return r; n } n bool isprime(long long a) { n   if (a <= 1) return false; n   for (long long i = 2; i * i <= a; ++i) { n     if (a % i == 0) return false; n   } n   return true; n } n long long sqrtup(long long a) { n   if (!a) return 0; n   long long x = max(0ll, (long long)sqrt((double)a)); n   while (x * x >= a) --x; n   while ((x + 1) * (x + 1) < a) ++x; n   return x + 1; n } n long long isqrt(long long a) { n   if (a <= 0) { n     assert(!a); n     return 0; n   } n   long long x = (long long)sqrt((double)a); n   while (sqr(x + 1) <= a) ++x; n   while (x * x > a) --x; n   return x; n } n long long sgn(long long x) { return x < 0 ? -1 : x > 0 ? 1 : 0; } n template <class T> n ostream &operator<<(ostream &s, const vector<T> &v); n template <class A, class B> n ostream &operator<<(ostream &s, const pair<A, B> &p); n template <class K, class V> n ostream &operator<<(ostream &s, const map<K, V> &m); n template <class T> n ostream &operator<<(ostream &s, const set<T> &m); n template <class T, size_t N> n ostream &operator<<(ostream &s, const array<T, N> &a); n template <class... T> n ostream &operator<<(ostream &s, const tuple<T...> &t); n template <class T> n ostream &operator<<(ostream &s, const vector<T> &v) { n   s <<  [ ; n   for (int i = 0; i < (((int)(v).size())); ++i) { n     if (i) s <<  , ; n     s << v[i]; n   } n   s <<  ] ; n   return s; n } n template <class A, class B> n ostream &operator<<(ostream &s, const pair<A, B> &p) { n   s <<  (  << p.first <<  ,  << p.second <<  ) ; n   return s; n } n template <class K, class V> n ostream &operator<<(ostream &s, const map<K, V> &m) { n   s <<  { ; n   bool f = false; n   for (const auto &it : m) { n     if (f) s <<  , ; n     f = true; n     s << it.first <<  :   << it.second; n   } n   s <<  } ; n   return s; n } n template <class T> n ostream &operator<<(ostream &s, const set<T> &m) { n   s <<  { ; n   bool f = false; n   for (const auto &it : m) { n     if (f) s <<  , ; n     f = true; n     s << it; n   } n   s <<  } ; n   return s; n } n template <class T> n ostream &operator<<(ostream &s, const multiset<T> &m) { n   s <<  { ; n   bool f = false; n   for (const auto &it : m) { n     if (f) s <<  , ; n     f = true; n     s << it; n   } n   s <<  } ; n   return s; n } n template <class T, class V, class C> n ostream &operator<<(ostream &s, const priority_queue<T, V, C> &q) { n   auto a = q; n   s <<  { ; n   bool f = false; n   while (!a.empty()) { n     if (f) s <<  , ; n     f = true; n     s << a.top(); n     a.pop(); n   } n   return s <<  } ; n } n template <class T, size_t N> n ostream &operator<<(ostream &s, const array<T, N> &a) { n   s <<  [ ; n   for (int i = 0; i < (((int)(a).size())); ++i) { n     if (i) s <<  , ; n     s << a[i]; n   } n   s <<  ] ; n   return s; n } n template <class T> n ostream &operator<<(ostream &s, const deque<T> &a) { n   s <<  [ ; n   for (int i = 0; i < (((int)(a).size())); ++i) { n     if (i) s <<  , ; n     s << a[i]; n   } n   s <<  ] ; n   return s; n } n template <size_t n, class... T> n struct put1 { n   static ostream &put(ostream &s, const tuple<T...> &t) { n     s << get<sizeof...(T) - n>(t); n     if (n > 1) s <<  , ; n     return put1<n - 1, T...>::put(s, t); n   } n }; n template <class... T> n struct put1<0, T...> { n   static ostream &put(ostream &s, const tuple<T...> &t) { return s; } n }; n template <class... T> n ostream &operator<<(ostream &s, const tuple<T...> &t) { n   s <<  ( ; n   put1<sizeof...(T), T...>::put(s, t); n   s <<  ) ; n   return s; n } n ostream &put3(ostream &s, const char *, bool) { return s; } n template <class U, class... T> n ostream &put3(ostream &s, const char *f, bool fs, U &&u, T &&...t) { n   while (*f ==    ) ++f; n   if (!fs) s <<  ,  ; n   auto nf = f; n   int d = 0; n   while (*nf && (*nf !=  ,  || d)) { n     if (*nf ==  ( ) n       ++d; n     else if (*nf ==  ) ) n       --d; n     ++nf; n   } n   auto nf2 = nf; n   while (nf2 > f && *(nf2 - 1) ==    ) --nf; n   fs = *f ==    ; n   if (!fs) { n     s.write(f, nf2 - f); n     s <<  = ; n   }; n   s << u; n   if (fs) s <<    ; n   if (*nf) ++nf; n   return put3(s, nf, fs, forward<T>(t)...); n } n vector<pair<string, string>> solve() { n   vector<pair<string, string>> R; n   R.push_back(make_pair( init carry ,  ddd0uuu )); n   const int L = 40; n   for (int i = 0; i < (L); ++i) { n     string andup =  uu10dtr0uel10dddttrudtedddl ; n     string xordown =  d10utled0r0uduuutt1ludtru ; n     string stepdown =  d10ut ; n     R.push_back(make_pair( pad up ,  uuued0sdt0uudtddd )); n     R.push_back(make_pair( pad down ,  ddeu0sut0ddutuu )); n     R.push_back(make_pair( x and y , andup)); n     R.push_back(make_pair( x xor y , xordown)); n     R.push_back(make_pair( xy xor c ,  ddd  + xordown)); n     R.push_back(make_pair( xy and c , andup)); n     R.push_back(make_pair( not1 ,  uuuu01dt )); n     R.push_back(make_pair( not2 ,  u01ut )); n     R.push_back(make_pair( carry and ,  d  + andup)); n     R.push_back(make_pair( carry not ,  uu01ut )); n     R.push_back(make_pair( 6 steps down ,   )); n     for (int j = 0; j < (6); ++j) R.back().second += stepdown; n     R.push_back(make_pair( carry left ,  l10rtuuu )); n   } n   R.push_back(make_pair( go to ans ,  rddddd )); n   R.push_back(make_pair( unpad ,   )); n   for (int i = 0; i < (L); ++i) R.back().second +=  rlt ; n   return R; n } n string concat(const vector<pair<string, string>> &S) { n   string r; n   for (auto &p : S) r += p.second; n   return r; n } n map<pair<int, int>, char> A; n void putnum(int a, int x, int y) { n   while (a) { n     A[make_pair(x, y)] =  0  + a % 2; n     a /= 2; n     --x; n   } n } n string bin(int a) { n   string r; n   while (a) { n     r += (char)( 0  + a % 2); n     a /= 2; n   } n   reverse((r).begin(), (r).end()); n   return r; n } n string readout(int x, int y) { n   string r; n   while (A.count(make_pair(x, y))) { n     r += A.at(make_pair(x, y)); n     ++x; n   } n   return r; n } n string sim(const vector<pair<string, string>> &S) { n   vector<pair<char, char>> st; n   int x = 0, y = 0; n   for (auto &sub : S) { n     for (char c : sub.second) { n       if (c ==  t ) { n         if (A.count(make_pair(x, y))) { n           int cnt = A.at(make_pair(x, y)) -  0  + 1; n           for (int qq = 0; qq < (cnt); ++qq) { n             if (st.empty()) break; n             c = st.back().first; n             char pr = st.back().second; n             st.pop_back(); n             if (c ==  0  || c ==  1  || c ==  e ) { n               if (!pr) n                 A.erase(make_pair(x, y)); n               else n                 A[make_pair(x, y)] = pr; n               continue; n             } n             if (c ==  l ) n               ++x; n             else if (c ==  r ) n               --x; n             else if (c ==  u ) n               --y; n             else if (c ==  d ) n               ++y; n             else n               assert(c ==  s ); n           } n         } n       } else { n         st.push_back(make_pair(c,  - )); n         if (c ==  0  || c ==  1  || c ==  e ) { n           st.back().second = A[make_pair(x, y)]; n           if (c ==  e ) n             A.erase(make_pair(x, y)); n           else n             A[make_pair(x, y)] = c; n         } else if (c ==  l ) n           --x; n         else if (c ==  r ) n           ++x; n         else if (c ==  u ) n           ++y; n         else if (c ==  d ) n           --y; n         else n           assert(c ==  s ); n       } n     } n   } n   return readout(x, y); n } n void test() { n   auto S = solve(); n   for (int s = 2; s <= 100; ++s) { n     for (int a = 1; a < s; ++a) { n       A.clear(); n       putnum(a, 0, 0); n       putnum(s - a, 0, 1); n       string r = sim(S); n       string b = bin(s); n       if (r != b) { n         do { n         } while (false); n         return; n       } n     } n   } n   do { n   } while (false); n } n int main(int argc, char **argv) { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.precision(20); n   srand(time(0)); n   cout << concat(solve()); n   return 0; n } n


#include <bits/stdc++.h> n const int N = 1e2 + 9; n using namespace std; n int n, m; n int mp[N][N]; n int main() { n   scanf( %d%d , &n, &m); n   puts( YES ); n   memset(mp, 0, sizeof mp); n   if (m <= n - 2) { n     int mid = (n + 1) / 2; n     if (m & 1) { n       mp[2][mid] = 1; n     } n     for (int i = 1; i <= m / 2; i++) { n       mp[2][mid - i] = mp[2][mid + i] = 1; n     } n   } else { n     for (int i = 2; i < n; i++) { n       mp[2][i] = 1; n     } n     m -= n - 2; n     int mid = (n + 1) / 2; n     if (m & 1) { n       mp[3][mid] = 1; n     } n     for (int i = 1; i <= m / 2; i++) { n       mp[3][mid - i] = mp[3][mid + i] = 1; n     } n   } n   for (int i = 1; i <= 4; i++) { n     for (int j = 1; j <= n; j++) { n       if (mp[i][j] == 1) n         printf( # ); n       else n         printf( . ); n     } n     puts(  ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e9; n const long long MOD = 1e9 + 7; n const long long maxn = 2e5 + 7; n const long long maxm = 2e5 + 7; n int n; n bool isPrime(int a) { n   for (int i = 2; i <= sqrt(a); i++) { n     if (a % i == 0) { n       return 0; n     } n   } n   return 1; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   cin >> n; n   for (int m = 1;; m++) { n     if (!isPrime(n * m + 1)) { n       cout << m << endl; n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using pii = pair<int, int>; n using pll = pair<ll, ll>; n using ld = long double; n const int MN = 5e5 + 5, MM = 1e6 + 3; n vector<int> bs; n struct Lady { n   int a, b, c; n } ladies[MN]; n int bit[MN]; n int n; n void update(int i, int v) { n   for (i = MN - i; i < MN; i += i & -i) bit[i] = max(bit[i], v); n } n int query(int i) { n   int ret = 0; n   for (i = MN - i; i; i ^= i & -i) ret = max(ret, bit[i]); n   return ret; n } n void getb(int &b) { n   b = lower_bound((bs).begin(), (bs).end(), b) - bs.begin() + 1; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &ladies[i].a); n   for (int i = 1; i <= n; i++) n     scanf( %d , &ladies[i].b), bs.push_back(ladies[i].b); n   for (int i = 1; i <= n; i++) scanf( %d , &ladies[i].c); n   sort((bs).begin(), (bs).end()); n   for (Lady &l : ladies) getb(l.b); n   sort(ladies + 1, ladies + 1 + n, [](Lady a, Lady b) { return a.a > b.a; }); n   vector<Lady> toadd; n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     if (ladies[i].a != ladies[i - 1].a) { n       for (Lady &l : toadd) update(l.b, l.c); n       toadd.clear(); n     } n     toadd.push_back(ladies[i]); n     ans += query(ladies[i].b + 1) > ladies[i].c; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<double, double> > a; n pair<double, double> cur; n double r; n void findmax(pair<double, double> p) { n   double y = n       sqrt(2 * r * 2 * r - abs(p.first - cur.first) * abs(p.first - cur.first)); n   y += p.second; n   cur.second = max(cur.second, y); n } n void doit(double x) { n   for (double k = 0; k < a.size(); k++) { n     if (abs(x - a[k].first) <= 2 * r) findmax(a[k]); n   } n   a.push_back(cur); n } n int main() { n   double x, n; n   cin >> n >> r; n   for (double k = 0; k < n; k++) { n     cin >> x; n     cur.first = x; n     cur.second = r; n     doit(x); n   } n   for (double k = 0; k < a.size(); k++) n     cout << setprecision(17) << a[k].second <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   int b[100]; n   for (int i = 0; i < 100; i++) b[i] = 0; n   int x; n   for (int i = 0; i < n; i++) { n     cin >> x; n     b[x - 1] += 1; n   } n   x = b[0]; n   for (int i = 0; i < 100; i++) { n     if (b[i] > x) { n       x = b[i]; n     } n   } n   if (x % k == 0) n     x = x / k; n   else n     x = x / k + 1; n   x = x * k; n   k = 0; n   for (int i = 0; i < 100; i++) n     if (b[i]) { n       k += x - b[i]; n     } n   cout << k; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int point, w; n } p[30][30]; n int n, m; n int s[30][30], w[30][30], Min[30], f[3000000]; n int Get() { n   char c = getchar(); n   while (!isalpha(c)) c = getchar(); n   return c; n } n void init(int x, int y) { n   int t1 = 0, t2 = 0, mx = 0; n   for (int i = 1; i <= n; i++) n     if (s[i][y] == s[x][y]) { n       t1 |= 1 << (i - 1); n       t2 += w[i][y]; n       mx = max(mx, w[i][y]); n     } n   p[x][y] = (node){t1, t2 - mx}; n } n int Getlow(int x) { n   int ss[200]; n   int num = 0; n   if (x == 0) return 1; n   while (x) { n     ss[++num] = x % 2; n     x /= 2; n   } n   ss[++num] = 0; n   for (int i = 1; i <= num; i++) n     if (ss[i] == 0) return i; n } n int main() { n   for (int i = 1; i <= 29; i++) Min[i] = 19240012; n   for (int i = 1; i <= 3000000 - 1; i++) f[i] = 30000000; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) s[i][j] = Get(); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       cin >> w[i][j]; n       Min[i] = min(Min[i], w[i][j]); n     } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) init(i, j); n   f[0] = 0; n   for (int i = 0; i < (1 << n); i++) { n     int p_ = Getlow(i); n     f[i | (1 << (p_ - 1))] = min(f[i | (1 << (p_ - 1))], f[i] + Min[p_]); n     for (int j = 1; j <= m; j++) n       f[i | p[p_][j].point] = min(f[i | p[p_][j].point], f[i] + p[p_][j].w); n   } n   cout << f[(1 << n) - 1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   int ctra = 0; n   int ctrb = 0; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  A ) { n       ctra++; n     } else { n       ctrb++; n     } n   } n   if (ctra > ctrb) { n     cout <<  Anton ; n   } else if (ctra < ctrb) { n     cout <<  Danik ; n   } else { n     cout <<  Friendship ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, x, y, z; n   cin >> a >> b >> c; n   cin >> x >> y >> z; n   a -= x; n   b -= y; n   c -= z; n   if (a >= 0) a /= 2; n   if (b >= 0) b /= 2; n   if (c >= 0) c /= 2; n   if (a + b + c >= 0) n     cout <<  Yes  << endl; n   else n     cout <<  No  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, tot, Trie[2000000 + 5][2], Num[2000000 + 5]; n long long x; n char s[9], ch[20]; n int main() { n   for (scanf( %d , &n); n; n--) { n     scanf( %s , s); n     if (s[0] ==  ? ) { n       scanf( %s , ch); n       int len = strlen(ch), u = 0, ans; n       for (int i = 1; i <= 19; i++) { n         int j = 0; n         if (i <= len) { n           j = ch[len - i] -  0 ; n           ch[len - i] =   0 ; n         } n         if (!Trie[u][j]) { n           u = -1; n           break; n         } n         u = Trie[u][j]; n       } n       if (!~u) n         ans = 0; n       else n         ans = Num[u]; n       printf( %d n , ans); n     } else { n       scanf( %I64d , &x); n       for (int i = 0, u = 0; i <= 18 || x; i++, x /= 10) { n         int j = (x % 10) & 1; n         if (!Trie[u][j]) Trie[u][j] = ++tot; n         u = Trie[u][j]; n         Num[u] += (s[0] ==  +  ? 1 : -1); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int p[300100], l[300100]; n vector<int> e[300100]; n int f(int x) { n   while (x != p[x]) { n     x = p[x] = p[p[x]]; n   } n   return x; n } n pair<int, int> L(int x, int p) { n   int lon = 0, h1 = 0, h2 = 0, S = e[x].size(); n   pair<int, int> R; n   for (int i = 0; i < S; i++) { n     if (p == e[x][i]) continue; n     R = L(e[x][i], x); n     if (R.first > h1) { n       h2 = max(h1, h2); n       h1 = R.first; n     } else if (R.first > h2) { n       h2 = R.first; n     } n     if (R.second > lon) lon = R.second; n   } n   lon = max(h1 + h2, lon); n   return pair<int, int>(h1 + 1, lon); n } n int main() { n   stringstream ss; n   memset(l, 0, sizeof(l)); n   int n, m, q; n   scanf( %d %d %d , &n, &m, &q); n   for (int i = 0; i < n; i++) p[i] = i; n   int a, b; n   for (int i = 0; i < m; i++) { n     scanf( %d %d , &a, &b); n     a--; n     b--; n     e[a].push_back(b); n     e[b].push_back(a); n   } n   bitset<300100> B; n   queue<int> Q; n   for (int i = 0; i < n; i++) { n     if (!B.test(i)) { n       B.set(i); n       Q.push(i); n       while (!Q.empty()) { n         int x = Q.front(); n         Q.pop(); n         for (int j = 0; j < e[x].size(); j++) { n           if (!B.test(e[x][j])) { n             B.set(e[x][j]); n             Q.push(e[x][j]); n             p[e[x][j]] = i; n           } n         } n       } n       l[i] = L(i, i).second; n     } n   } n   int c, x, y; n   for (int i = 0; i < q; i++) { n     scanf( %d , &c); n     if (c == 2) { n       scanf( %d %d , &x, &y); n       x--; n       y--; n       x = f(x); n       y = f(y); n       if (x != y) { n         int m = max(l[x], l[y]); n         l[x] = max(m, (l[x] + 1) / 2 + (l[y] + 1) / 2 + 1); n         p[y] = x; n       } n     } else if (c == 1) { n       scanf( %d , &x); n       x--; n       printf( %d n , l[f(x)]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O2 ) n using namespace std; n const int MAX = 3e5 + 5; n const long long MAX2 = 11; n const long long MOD = 1000000007; n const long long MOD2 = 1000005329; n const long long INF = 2e18; n const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0}; n const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0}; n const double pi = acos(-1); n const double EPS = 1e-9; n const int block = 555; n int n; n long long a, b, c, mx, ans, nw; n string s[MAX]; n int main() { n   cout << fixed << setprecision(10); n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (long long i = 1; i <= n; ++i) cin >> s[i]; n   for (char tgt =  a ; tgt <=  z ; ++tgt) { n     nw = 0; n     for (long long i = 1; i <= n; ++i) { n       a = b = c = mx = 0; n       reverse(s[i].begin(), s[i].end()); n       for (char j : s[i]) { n         if (j != tgt) break; n         ++a; n       } n       reverse(s[i].begin(), s[i].end()); n       for (char j : s[i]) { n         if (j != tgt) break; n         ++b; n       } n       for (char j : s[i]) { n         if (j != tgt) n           c = 0; n         else n           ++c, mx = max(c, mx); n       } n       if (mx == s[i].size()) n         nw = min(MOD, nw + (nw + 1) * mx); n       else n         nw = max(nw ? a + b + 1 : 0, mx); n     } n     ans = max(ans, nw); n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     map<string, int> m; n     int ans = 0; n     vector<string> a, b; n     for (int i = 0; i < n; i++) { n       string s; n       cin >> s; n       if (m[s] != 0) ans++; n       m[s]++; n       b.push_back(s); n     } n     for (int i = 0; i < n; i++) { n       string s; n       s = b[i]; n       if (m[s] != 1) { n         m[s]--; n         while (true) { n           if (s[3] ==  9 ) n             s[3] =  0 ; n           else n             s[3] = ((int)s[3] + 1); n           if (m[s] == 0) { n             m[s]++; n             a.push_back(s); n             break; n           } n         } n       } else { n         a.push_back(s); n       } n     } n     cout << ans << endl; n     for (int i = 0; i < a.size(); i++) { n       cout << a[i] << endl; n     } n   } n   return 0; n } n


#define _CRT_SECURE_NO_WARNINGS  n #include <bits/stdc++.h> n using namespace std; n typedef long long ll; n typedef unsigned long long ull; n #define all(x) x.begin(), x.end() n #define rall(x) x.rbegin(), x.rend() n //#define endl   n  n #define boostIO() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); n ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); } n  n ll mod = 998244353; n  n ll binpow(ll a, ll n) { n  ll res = 1; n  while (n) { n   if (n & 1) n    res = (1LL * res * a) % mod; n   a = (1LL * a * a) % mod; n  n   n >>= 1; n  } n  return res; n } n  n signed main() { n  int q = 1; n  //cin >> q; n  while (q--) { n   int n; n   cin >> n; n   vector<ll> dp(n + 3, 0); n   dp[1] = 1, dp[2] = 1; n   for (int i = 3; i <= n; ++i) { n    dp[i] = dp[i - 1] + dp[i - 2]; n    if (dp[i] >= mod) dp[i] -= mod; n   } n   cout << (dp[n] * binpow(binpow(2, n), mod - 2)) % mod; n  } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100; n int n, k[N]; n double p[N], p_log[N], p_log_1[N]; n priority_queue<pair<double, int>> s; n inline double P(int i, int k) { n   double x = pow(p[i], k); n   if (x > 1e-6) return log(1 - x); n   x = -x; n   return x - x * x / 2 + x * x * x / 3; n } n void add(int i) { s.push(make_pair(P(i, k[i] + 1) - P(i, k[i]), i)); } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   cin >> n; n   if (n == 1) { n     puts( 1 ); n     return 0; n   } n   for (int i = 0; i < (int)(n); i++) { n     int a; n     cin >> a; n     p[i] = 1 - a * 1e-2; n     p_log[i] = log(p[i]); n     p_log_1[i] = log(1 - p[i]); n   } n   double sum = 0; n   int cnt = n; n   for (int i = 0; i < (int)(n); i++) sum += P(i, k[i] = 1); n   double res = exp(sum) * cnt; n   for (int i = 0; i < (int)(n); i++) add(i); n   while (cnt <= 1e6) { n     cnt++; n     int i = s.top().second; n     s.pop(); n     sum -= P(i, k[i]); n     double x = cnt * exp(sum + p_log[i] * k[i]) * (1 - p[i]); n     res += x; n     sum += P(i, ++k[i]); n     add(i); n   } n   printf( %.15f n , (double)res); n   fprintf(stderr,  time = %.2f, cnt = %d n , 1. * clock() / CLOCKS_PER_SEC, n           cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long read() { n   long long x = 0, f = 1; n   char ch; n   while (!isdigit(ch = getchar())) (ch ==  - ) && (f = -f); n   for (x = ch ^ 48; isdigit(ch = getchar()); n        x = (x << 3) + (x << 1) + (ch ^ 48)) n     ; n   return x * f; n } n const long long N = 2e5 + 66; n long long n, m, k, A, B, C, AB, tmp1, tmp2, a[N], b[N], tag[N], taga[N], n     tagb[N], tagab[N]; n long long n1[N], n2[N], n3[N]; n long long suma[N], sumb[N], sumc[N], sum, ans; n bool visa[N], visb[N]; n struct seg { n   long long a, b, c; n } tr[N << 2]; n void up(long long o) { n   tr[o].a = tr[(o << 1 | 1)].a; n   tr[o].b = tr[(o << 1 | 1)].b; n   tr[o].c = tr[(o << 1 | 1)].c; n } n void build(long long o, long long l, long long r) { n   if (l == r) { n     tr[o].a = n1[l]; n     tr[o].b = n2[l]; n     tr[o].c = n3[l]; n     return; n   } n   build((o << 1), l, ((l + r) >> 1)); n   build((o << 1 | 1), ((l + r) >> 1) + 1, r); n   up(o); n } n long long query(long long o, long long l, long long r, long long a) { n   if (l == r) n     return suma[max(tr[o].a, a)] + sumb[max(tr[o].b, a)] + sumc[tr[o].c] - n            b[l] * (max(tr[o].a, a) + max(tr[o].b, a) + tr[o].c + k - a - m); n   long long t = n       max(tr[(o << 1)].a, a) + max(tr[(o << 1)].b, a) + tr[(o << 1)].c + k - a; n   if (t >= m) n     return query((o << 1), l, ((l + r) >> 1), a); n   else n     return query((o << 1 | 1), ((l + r) >> 1) + 1, r, a); n } n signed main() { n   n = read(); n   m = read(); n   k = read(); n   for (long long i = 1; i <= n; i++) a[i] = read(), b[i] = a[i]; n   sort(b + 1, b + 1 + n); n   long long cur = unique(b + 1, b + 1 + n) - b - 1; n   for (long long i = 1; i <= n; i++) n     a[i] = lower_bound(b + 1, b + 1 + cur, a[i]) - b; n   tmp1 = read(); n   for (long long i = 1; i <= tmp1; i++) visa[read()] = 1; n   tmp2 = read(); n   for (long long i = 1; i <= tmp2; i++) visb[read()] = 1; n   for (long long i = 1; i <= n; i++) { n     if (visa[i] && visb[i]) n       tagab[++AB] = b[a[i]]; n     else if (visa[i]) n       taga[++A] = b[a[i]], n1[a[i]]++; n     else if (visb[i]) n       tagb[++B] = b[a[i]], n2[a[i]]++; n     else n       tag[++C] = b[a[i]], n3[a[i]]++; n   } n   if (k > m || (AB + A < k) || (AB + B < k)) { n     puts( -1 ); n     return 0; n   } n   sort(tagab + 1, tagab + 1 + AB); n   sort(taga + 1, taga + 1 + A); n   sort(tagb + 1, tagb + 1 + B); n   sort(tag + 1, tag + 1 + C); n   for (long long i = 1; i <= cur; i++) n     n1[i] += n1[i - 1], n2[i] += n2[i - 1], n3[i] += n3[i - 1]; n   for (long long i = 1; i <= A; i++) suma[i] = suma[i - 1] + taga[i]; n   for (long long i = 1; i <= B; i++) sumb[i] = sumb[i - 1] + tagb[i]; n   for (long long i = 1; i <= C; i++) sumc[i] = sumc[i - 1] + tag[i]; n   build(1, 0, cur); n   sum = 0; n   ans = 1ll << 60; n   for (long long i = 0, tmp; i <= min(AB, m); i++) { n     sum += tagab[i]; n     if (min(A, B) >= k - i && 2 * k - i <= m && i + A + B + C >= m) n       ans = min(ans, sum + (tmp = query(1, 0, cur, k - i))); n   } n   if (ans == (1ll << 60)) n     puts( -1 ); n   else n     printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n struct node { n   int x, index; n } a[1010]; n bool cmp(node x, node y) { n   if (x.x != y.x) n     return x.x > y.x; n   else n     return x.index > y.index; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i].x); n     a[i].index = i; n   } n   sort(a + 1, a + n + 1, cmp); n   int SUM = 0; n   for (int i = 1; i <= n; i++) { n     SUM += ((i - 1) * a[i].x + 1); n   } n   printf( %d n , SUM); n   for (int i = 1; i <= n; i++) { n     printf( %d  , a[i].index); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     long long int n, a, b, x, y; n     cin >> n; n     x = 1 + (n - 1) / 3; n     long long int sum = 0, k = 1; n     while (sum < x) { n       sum += k; n       k <<= 2; n     } n     k >>= 2; n     sum -= k; n     y = a = (x - sum - 1 + k); n     int c[] = {0, 2, 3, 1}; n     k = 1, b = 0; n     while (y) { n       b += c[y % 4] * k; n       k <<= 2; n       y >>= 2; n     } n     x = a ^ b; n     if (n % 3 == 1) { n       cout << a << endl; n     } else if (n % 3 == 2) { n       cout << b << endl; n     } else n       cout << x << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math ) n #pragma GCC target(   n      sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native ) n using namespace std; n namespace _c { n const double pi = acos(-1.0); n namespace min { n const int i8 = -128; n const int i16 = -32768; n const int i = -2147483647 - 1; n const long long l = -9223372036854775807LL - 1; n }  // namespace min n namespace max { n const int i8 = 127; n const int i16 = 32767; n const int i = 2147483647; n const long long l = 9223372036854775807LL; n }  // namespace max n }  // namespace _c n namespace _f { n template <typename T> n inline const T gcd(T m, T n) { n   while (n != 0) { n     T t = m % n; n     m = n; n     n = t; n   } n   return m; n } n template <typename T> n inline const T max(const T &a, const T &b) { n   return a > b ? a : b; n } n template <typename T> n inline const T min(const T &a, const T &b) { n   return a < b ? a : b; n } n template <typename T> n inline const T abs(const T &a) { n   return a > 0 ? a : -a; n } n }  // namespace _f n namespace io { n template <typename T> n inline void read(T &t) { n   register T res = 0, neg = 1; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) { n     if (c ==  - ) { n       neg = -1; n     } n   } n   for (; isdigit(c); c = getchar()) { n     res = res * 10 + c -  0 ; n   } n   t = res * neg; n } n inline int in() { n   register int T; n   read(T); n   return T; n } n inline long long in_ll() { n   register long long T; n   read(T); n   return T; n } n }  // namespace io n int n; n double a[110], ans; n int main() { n   scanf( %d , &n); n   for (int i = 0; i <= n; i++) { n     scanf( %lf , a + i); n   } n   if (~n & 1) { n     ans = a[n / 2]; n   } n   for (int i = 0; i * 2 <= n; i++) { n     for (int j = n; j > n / 2; j--) { n       ans = _f::max(ans, n                     ((n - 2 * i) * a[j] + (2 * j - n) * a[i]) / (2 * (j - i))); n     } n   } n   printf( %.9lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 100005; n const int INF = 1 << 30; n int n, m, D; n int a[MAX]; n vector<int> v[MAX]; n int down[MAX]; n inline void Down(int x, int fa) { n   int res = -1; n   for (int i = 0; i < v[x].size(); i++) { n     int next = v[x][i]; n     if (next == fa) continue; n     Down(next, x); n     res = max(res, down[next]); n   } n   if (res != -1) down[x] = max(down[x], res + 1); n } n int up[MAX]; n inline void Up(int x, int fa) { n   int max1 = -1, max2 = -1; n   for (int i = 0; i < v[x].size(); i++) { n     int next = v[x][i]; n     if (next == fa) continue; n     if (down[next] > max1) n       max2 = max1, max1 = down[next]; n     else if (down[next] > max2) n       max2 = down[next]; n   } n   int res = -1; n   for (int i = 0; i < v[x].size(); i++) { n     int next = v[x][i]; n     if (next == fa) continue; n     if (up[x] != -1) up[next] = max(up[next], up[x] + 1); n     int val = (down[next] == max1 ? max2 : max1); n     if (val != -1) up[next] = max(up[next], val + 2); n     Up(next, x); n   } n } n int main() { n   scanf( %d%d%d , &n, &m, &D); n   for (int i = 1; i <= m; i++) scanf( %d , &a[i]); n   for (int i = 1; i < n; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     v[x].push_back(y); n     v[y].push_back(x); n   } n   memset(down, -1, sizeof(down)); n   memset(up, -1, sizeof(up)); n   for (int i = 1; i <= m; i++) down[a[i]] = up[a[i]] = 0; n   Down(1, 0); n   Up(1, 0); n   int ans = 0; n   for (int i = 1; i <= n; i++) n     if (up[i] <= D && down[i] <= D) ans++; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a, b, c, d; n double Max(double x, double y, double d) { n   double temp = (x - d) * (y + d); n   temp = max((x - d) * (y - d), temp); n   temp = max((x + d) * (y - d), temp); n   temp = max((x + d) * (y + d), temp); n   return temp; n } n double Min(double x, double y, double d) { n   double temp = (x - d) * (y - d); n   temp = min((x - d) * (y + d), temp); n   temp = min((x + d) * (y - d), temp); n   temp = min((x + d) * (y + d), temp); n   return temp; n } n bool check(double x) { n   double l1 = Min(a, d, x); n   double r1 = Max(a, d, x); n   double l2 = Min(b, c, x); n   double r2 = Max(b, c, x); n   if (l1 <= r2 && r1 >= l2) return true; n   return false; n } n int main() { n   while (~scanf( %d %d %d %d , &a, &b, &c, &d)) { n     double r = max(max(abs(a), abs(b)), max(abs(c), abs(d))); n     double l = 0.0; n     int num = 1000000; n     while (num--) { n       double mid = (l + r) / 2.0; n       if (check(mid)) n         r = mid; n       else n         l = mid; n     } n     printf( %.11lf n , l); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int p = 1000000007; n long long quick_mod(long long a, long long b) { n   long long ans = 1; n   a %= p; n   while (b) { n     if (b & 1) { n       ans = ans * a % p; n       b--; n     } n     b >>= 1; n     a = a * a % p; n   } n   return ans; n } n long long C(long long n, long long m) { n   if (m > n) return 0; n   long long ans = 1; n   for (int i = 1; i <= m; i++) { n     long long a = (n + i - m) % p; n     long long b = i % p; n     ans = ans * (a * quick_mod(b, p - 2) % p) % p; n   } n   return ans; n } n long long Lucas(long long n, long long m) { n   if (m == 0) return 1; n   return C(n % p, m % p) * Lucas(n / p, m / p) % p; n } n int main() { n   long long ans = 1; n   int n, cnt, x; n   scanf( %d%d , &n, &cnt); n   for (int i = 2; i <= n; i++) { n     scanf( %d , &x); n     long long t = C(cnt + x - 1, x - 1) % p; n     ans = ans * t % p; n     cnt += x; n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   int cnt = 0, rem = m; n   int arr[10000]; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   for (int i = 0; i < n; i++) { n     if (rem >= arr[i]) n       rem -= arr[i]; n     else { n       cnt++; n       rem = m; n       rem -= arr[i]; n     } n   } n   cout << cnt + 1; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[200500]; n long long res[200500]; n long long n; n bool check(long long x) { n   for (long long i = 0; i < n; i++) { n     res[i] = 0; n   } n   for (long long i = n - 1; i >= 2; i--) { n     long long f = (a[i] + res[i]) - x; n     if (f < 0) { n       return false; n     } n     long long k = min((f / 3), (a[i] / 3)); n     res[i - 1] += k; n     res[i - 2] += 2 * k; n   } n   if (a[0] + res[0] < x) { n     return false; n   } n   if (a[1] + res[1] < x) { n     return false; n   } n   return true; n } n signed main() { n   long long t; n   cin >> t; n   while (t--) { n     cin >> n; n     for (long long i = 0; i < n; i++) { n       cin >> a[i]; n     } n     long long l = 0, r = 2000000000; n     while (r - l > 1) { n       long long mid = (l + r) / 2; n       if (check(mid)) { n         l = mid; n       } else { n         r = mid; n       } n     } n     cout << l <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5; n int l = 0; n int r = 0; n int res = 0; n int f[maxn + 11][55]; n int a[maxn + 11]; n int cnt[maxn + 11]; n void add(int x) { n   if (!cnt[a[x]]) res++; n   cnt[a[x]]++; n } n void del(int x) { n   cnt[a[x]]--; n   if (!cnt[a[x]]) res--; n } n int calc(int L, int R) { n   while (r < R) add(++r); n   while (r > R) del(r--); n   while (l > L) add(--l); n   while (l < L) del(l++); n   return res; n } n void solve(int k, int l, int r, int al, int ar) { n   int mid = (l + r) >> 1; n   if (l > r || al > ar) return; n   int ind = 0; n   for (int i = al; i <= min(ar, mid - 1); i++) { n     if (f[i][k - 1] + calc(i + 1, mid) > f[mid][k]) { n       f[mid][k] = f[i][k - 1] + calc(i + 1, mid); n       ind = i; n     } n   } n   solve(k, l, mid - 1, al, ind); n   solve(k, mid + 1, r, ind, ar); n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int n, k; n   cin >> n >> k; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= k; i++) solve(i, 1, n, 0, n); n   cout << f[n][k] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[100][3]; n   int n = 0; n   cin >> n; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < 3; j++) { n       cin >> a[i][j]; n     } n   } n   int s = 1; n   int m = 0; n   int f = 0; n   int cou = 0; n   int back = 0; n   for (int k = 0; k < n; k++) { n     if (a[k][0] == s && a[k][1] != back) { n       back = s; n       s = a[k][1]; n       m += a[k][2]; n       cou++; n       k = -1; n     } n     if (k == n - 1) { n       for (int k2 = 0; k2 < n; k2++) { n         if (a[k2][1] == s && a[k2][0] != back) { n           back = s; n           s = a[k2][0]; n           f += a[k2][2]; n           cou++; n           k = -1; n           k2 = n; n         } n       } n     } n     if (cou == n) { n       k = n; n     } n   } n   if (m > f) n     cout << f << endl; n   else n     cout << m << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int power(long long int first, long long int n) { n   if (n == 0) n     return 1; n   else if (n % 2 == 0) { n     long long int second = power(first, n / 2); n     return second * second; n   } else n     return first * power(first, n - 1); n } n int strTOint(string s) { n   stringstream ss; n   int first; n   ss << s; n   ss >> first; n   return first; n } n double geo_dist(int a, int b, int c, int d) { n   double dd = (double)(a - c) * (a - c) + (b - d) * (b - d); n   double r = sqrt(dd) + 1e-9; n   return r; n } n long long int bigmod(long long int a, long long int p, long long int m) { n   if (p == 0) return 1 % m; n   if (p % 2 == 0) { n     long long int second = bigmod(a, p / 2, m); n     return (second * second) % m; n   } else { n     return (a * bigmod(a, p - 1, m)) % m; n   } n } n long long int first, second, d, g; n void ext_gcd(long long int a, long long int b) { n   if (b == 0) { n     first = 1; n     second = 0; n     d = a; n     return; n   } n   ext_gcd(b, a % b); n   long long int x1 = second; n   long long int y1 = first - (a / b) * second; n   first = x1; n   second = y1; n } n long long int modInv(long long int a, long long int m) { n   ext_gcd(a, m); n   first %= m; n   if (first < 0) first += m; n   return first; n } n int fx[] = {0, 0, -1, 1, -1, 1, 1, -1}; n int fy[] = {1, -1, 0, 0, 1, 1, -1, -1}; n map<string, int> mp; n vector<pair<int, int> > adj[1000]; n vector<int> v; n int main() { n   long long int n, m; n   cin >> n >> m; n   long long int a, b, c, d, e, a1, b1, c1, d1, e1; n   long long int sum = 0; n   int j = 0; n   a = n / 5; n   a1 = m / 5; n   a *= a1; n   sum += a; n   for (int i = 1; i <= 4; i++) { n     j = 5 - i; n     j %= 5; n     a = n / 5; n     if (n % 5 >= i) a++; n     a1 = m / 5; n     if (m % 5 >= j) a1++; n     a *= a1; n     sum += a; n   } n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int n, m, m1, arr[9] = {0}, num = 0, num1 = 0; n   cin >> n >> m, m1 = m; n   if (n == 1 && m == 0) n     cout <<  0 0 ; n   else if (9 * n < m || m == 0) n     cout <<  -1 -1 ; n   else { n     num1 = 1; n     while (m - (num1) > (n - 1) * 9) num1++; n     cout << num1; n     num += num1; n     num1 = 0; n     for (int i = 1; i < n; i++) { n       while (m - (num1 + num) > (n - (i + 1)) * 9) num1++; n       cout << num1; n       num += num1; n       num1 = 0; n     } n     num = 0; n     cout <<    ; n     for (int i = 8; i >= 0; i--) { n       arr[i] = m1 / (i + 1); n       m1 %= (i + 1); n       num += arr[i]; n     } n     for (int i = 8; i >= 0; i--) n       while (arr[i]--) cout << i + 1; n     while (num < n) cout <<  0 , num++; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace rel_ops; n using ll = int64_t; n using Pii = pair<int, int>; n using ull = uint64_t; n using Vi = vector<int>; n void run(); n int main() { n   cin.sync_with_stdio(0); n   cin.tie(0); n   cout << fixed << setprecision(10); n   run(); n   return 0; n } n int uplg(int n) { return 32 - __builtin_clz(n); } n int uplg(ll n) { return 64 - __builtin_clzll(n); } n struct Vert { n   int ver{-1}; n   int defPar{-1}, par; n   bool defBlocked{1}, blocked; n }; n int hei, wid, nQuestions; n vector<Vert> G; n set<Pii> permEdges, tempEdges; n int currentVer = 1; n void update(int i) { n   if (G[i].ver != currentVer) { n     G[i].ver = currentVer; n     G[i].par = G[i].defPar; n     G[i].blocked = G[i].defBlocked; n   } n } n int find(int i) { n   update(i); n   if (G[i].par == -1) return i; n   return G[i].par = find(G[i].par); n } n int join(int i, int j) { n   i = find(i); n   j = find(j); n   if (i == j) return i; n   if (rand() % 2) swap(i, j); n   return G[i].par = j; n } n int ind(int first, int second) { return first * wid + second; } n Vert& vert(int i) { n   update(i); n   return G[i]; n } n Vert& vert(int first, int second) { return vert(ind(first, second)); } n void eachNeigh(int i, int j, function<void(int, int)> func) { n   for (int dx = (-1); dx < (2); dx++) n     for (int dy = (-1); dy < (2); dy++) n       if (dx != 0 || dy != 0) { n         int first = i + dx, second = j + dy; n         if (first >= 0 && second >= 0 && first < hei && second < wid) { n           func(first, second); n         } n       } n } n void addEdges(int i, int j) { n   assert(vert(i, j).blocked); n   eachNeigh(i, j, [&](int first, int second) { n     if (vert(first, second).blocked) return; n     eachNeigh(first, second, [&](int a, int b) { n       if (vert(a, b).blocked) { n         int p1 = find(ind(i, j)), p2 = find(ind(a, b)); n         tempEdges.insert({p1, p2}); n         tempEdges.insert({p2, p1}); n       } n     }); n   }); n } n void query() { n   int k; n   cin >> k; n   vector<Pii> toBlock(k); n   for (auto& p : (toBlock)) cin >> p.first >> p.second; n   Vi toCheck; n   currentVer++; n   tempEdges.clear(); n   for (auto& p : (toBlock)) { n     vert(p.first, p.second).blocked = 1; n     toCheck.push_back(find(ind(p.first, p.second))); n     eachNeigh(p.first, p.second, [&](int i, int j) { n       if (vert(i, j).blocked) { n         toCheck.push_back(find(ind(i, j))); n         join(ind(i, j), ind(p.first, p.second)); n       } n     }); n     addEdges(p.first, p.second); n     toCheck.push_back(find(ind(p.first, p.second))); n     eachNeigh(p.first, p.second, [&](int i, int j) { n       if (vert(i, j).blocked) { n         toCheck.push_back(find(ind(i, j))); n       } n     }); n   } n   int top = find(ind(0, 3)), bottom = find(ind(3, 0)); n   toCheck.push_back(top); n   toCheck.push_back(bottom); n   for (auto& i : (toCheck)) n     if (find(i) == top) { n       for (auto& j : (toCheck)) n         if (find(j) == bottom) { n           if (permEdges.count({i, j}) || tempEdges.count({i, j})) { n             cout <<  NO  << endl; n             return; n           } n         } n     } n   cout <<  YES  << endl; n } n void run() { n   cin >> hei >> wid >> nQuestions; n   hei += 2; n   wid += 2; n   G.resize(hei * wid); n   for (int i = (0); i < (3); i++) { n     vert(i, 0).defBlocked = vert(0, i).defBlocked = 0; n     vert(hei - i - 1, wid - 1).defBlocked = n         vert(hei - 1, wid - i - 1).defBlocked = 0; n   } n   for (int i = (1); i < (hei - 1); i++) { n     string tmp; n     cin >> tmp; n     for (int j = (1); j < (wid - 1); j++) n       vert(i, j).defBlocked = (tmp[j - 1] ==  # ); n   } n   for (int first = (0); first < (hei); first++) n     for (int second = (0); second < (wid); second++) { n       auto& cur = vert(first, second); n       if (!cur.defBlocked) continue; n       eachNeigh(first, second, [&](int i, int j) { n         if (vert(i, j).defBlocked) { n           join(ind(first, second), ind(i, j)); n         } n       }); n     } n   for (auto& v : (G)) v.defPar = v.par; n   currentVer++; n   for (int i = (0); i < (hei); i++) n     for (int j = (0); j < (wid); j++) { n       auto& cur = vert(i, j); n       if (cur.defBlocked) addEdges(i, j); n     } n   swap(tempEdges, permEdges); n   while (nQuestions--) query(); n } n


#include <bits/stdc++.h> n using namespace std; n int piles[105]; n int main() { n   int n; n   cin >> n; n   vector<int> A(n); n   for (int i = 0; i < n; ++i) cin >> A[i]; n   sort(A.begin(), A.end()); n   for (int i = 0; i < n; ++i) { n     bool flag = false; n     for (int j = 0; j <= A[i]; ++j) n       if (piles[j]) { n         --piles[j]; n         ++piles[j + 1]; n         flag = true; n         break; n       } n     if (!flag) piles[1] += 1; n   } n   int cnt = 0; n   for (int i = 1; i < 105; ++i) cnt += piles[i]; n   cout << cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 10005; n long long int p[N], s[N], n, c; n long long int dp[2][N]; n int main() { n   cin >> n >> c; n   for (int i = 0; i < n; i++) cin >> p[i]; n   for (int i = 0; i < n; i++) cin >> s[i]; n   dp[0][0] = p[0]; n   dp[0][1] = s[0]; n   int row = 1; n   for (int i = 1; i < n; i++) { n     for (int j = 0; j <= i + 1; j++) { n       dp[row][j] = (long long)(1e18); n       if (j != i + 1) dp[row][j] = dp[1 - row][j] + j * c + p[i]; n       if (j != 0) dp[row][j] = min(dp[row][j], dp[1 - row][j - 1] + s[i]); n     } n     row = 1 - row; n   } n   row = 1 - row; n   long long ansa = (long long)(1e18); n   for (int j = 0; j <= n; j++) ansa = min(ansa, dp[row][j]); n   cout << ansa << endl; n   return 0; n } n


#include <bits/stdc++.h> n std::set<int> s; n std::vector<bool> wh; n bool push(int n) { n   for (int it = 1; it < 32; ++it) { n     if (!wh[n >> it]) { n       s.erase(n); n       wh[n] = false; n       s.insert(n >> it); n       wh[n >> it] = true; n       return true; n     } n   } n   return false; n } n void solution() { n   int n, temp; n   scanf( %d , &n); n   wh.resize(1000000001, false); n   wh[0] = true; n   while (n-- > 0) { n     scanf( %d , &temp); n     s.insert(temp); n     wh[temp] = true; n   } n   while (push(*(s.rbegin()))) n     ; n   for (auto it : s) { n     printf( %d  , it); n   } n } n int main() { n   solution(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char buf[1000000]; n vector<vector<int> > g; n vector<bool> used; n vector<long long> border, space, w, h; n vector<int> tp; n void dfs(int v) { n   used[v] = true; n   for (int i = (0); i < (int((g[v]).size())); ++i) n     if (!used[g[v][i]]) dfs(g[v][i]); n   if (tp[v] == 0) { n     long long W = 0, H = 0; n     for (int i = (0); i < (int((g[v]).size())); ++i) { n       W += w[g[v][i]]; n       H = max(H, h[g[v][i]]); n     } n     if (int((g[v]).size()) == 0) return; n     W += (int((g[v]).size()) - 1) * space[v] + 2 * border[v]; n     H += 2 * border[v]; n     w[v] = W; n     h[v] = H; n     return; n   } n   if (tp[v] == 1) { n     long long W = 0, H = 0; n     for (int i = (0); i < (int((g[v]).size())); ++i) { n       H += h[g[v][i]]; n       W = max(W, w[g[v][i]]); n     } n     if (int((g[v]).size()) == 0) return; n     H += (int((g[v]).size()) - 1) * space[v] + 2 * border[v]; n     W += 2 * border[v]; n     w[v] = W; n     h[v] = H; n     return; n   } n } n int main() { n   g.resize(110); n   map<string, int> M; n   int it = 0; n   int n; n   cin >> n; n   vector<string> names; n   for (int i = (0); i < (n); ++i) { n     string s; n     scanf( %s , buf); n     s = buf; n     if (s ==  HBox ) { n       scanf( %s , buf); n       s = buf; n       M[s] = it; n       names.push_back(s); n       tp.push_back(0); n       w.push_back(0); n       h.push_back(0); n       border.push_back(0); n       space.push_back(0); n       it++; n       continue; n     } n     if (s ==  VBox ) { n       scanf( %s , buf); n       s = buf; n       M[s] = it; n       names.push_back(s); n       tp.push_back(1); n       w.push_back(0); n       h.push_back(0); n       border.push_back(0); n       space.push_back(0); n       it++; n       continue; n     } n     if (s ==  Widget ) { n       scanf( %s , buf); n       s = buf; n       string nm =   ; n       int j = 0; n       while (s[j] !=  ( ) { n         nm.push_back(s[j]); n         j++; n       } n       M[nm] = it; n       names.push_back(nm); n       long long W, H; n       W = H = 0; n       j++; n       while (s[j] !=  , ) { n         W = W * 10 + (s[j] -  0 ); n         j++; n       } n       j++; n       while (s[j] !=  ) ) { n         H = H * 10 + (s[j] -  0 ); n         j++; n       } n       tp.push_back(2); n       w.push_back(W); n       h.push_back(H); n       border.push_back(0); n       space.push_back(0); n       it++; n       continue; n     } n     for (int j = (0); j < (int((s).size())); ++j) n       if (s[j] ==  ,  || s[j] ==  (  || s[j] ==  .  || s[j] ==  ) ) s[j] =    ; n     stringstream sin; n     sin << s; n     vector<string> q; n     while (sin >> s) q.push_back(s); n     if (q[1] ==  pack ) { n       g[M[q[0]]].push_back(M[q[2]]); n     } else { n       long long t = 0; n       for (int j = (0); j < (int((q[2]).size())); ++j) n         t = t * 10 + (q[2][j] -  0 ); n       if (q[1] ==  set_border ) n         border[M[q[0]]] = t; n       else n         space[M[q[0]]] = t; n     } n   } n   used.resize(it, false); n   for (int i = (0); i < (it); ++i) { n     if (!used[i]) dfs(i); n   } n   vector<pair<string, int> > res; n   for (int i = (0); i < (it); ++i) res.push_back(make_pair(names[i], i)); n   sort((res).begin(), (res).end()); n   for (int i = (0); i < (it); ++i) { n     int j = res[i].second; n     cout << names[j] <<     << w[j] <<     << h[j] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int Array[10005]; n int main() { n   int N, m, i, j, l, r, x, Count; n   scanf( %d%d , &N, &m); n   for (i = 1; i <= N; i++) scanf( %d , Array + i); n   for (i = 1; i <= m; i++) { n     Count = 0; n     scanf( %d%d%d , &l, &r, &x); n     for (j = l; j <= r; j++) { n       if (Array[j] < Array[x]) Count++; n     } n     if (Count == x - l) n       puts( Yes ); n     else n       puts( No ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 105; n const int MOD = 1e6 + 3; n struct matrix { n   int val[M][M]; n   int n; n   matrix(int nn, int x = 0) { n     n = nn; n     for (int i = 0; i < n; i++) n       for (int j = 0; j < n; j++) n         if (i != j) n           val[i][j] = 0; n         else n           val[i][j] = x; n   } n   int* operator[](int x) { return val[x]; } n   matrix operator*(matrix b) { n     matrix ans(n, 0); n     for (int i = 0; i < n; i++) n       for (int j = 0; j < n; j++) n         for (int k = 0; k < n; k++) n           ans[i][k] += 1LL * val[i][j] * b[j][k] % MOD, ans[i][k] %= MOD; n     return ans; n   } n }; n matrix operator^(matrix a, long long b) { n   matrix ans(a.n, 1); n   while (b) { n     if (b & 1) ans = ans * a; n     a = a * a; n     b >>= 1; n   } n   return ans; n } n int main() { n   long long n; n   int w, h; n   cin >> n >> w >> h; n   matrix mat(w + 1, 0); n   for (int i = 0; i < w; i++) mat[i][i + 1] = 1; n   int k = 1; n   for (int i = w; i >= 0; i--) { n     mat[w][i] = k; n     k = 1LL * k * h % MOD; n   } n   mat = mat ^ n; n   cout << (mat[w][w - 1] + mat[w][w]) % MOD <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct re { n   int x, y; n }; n int n, K, f[2001][2001]; n char mp[2001][2001]; n vector<re> A, B, zy[4001]; n string Ans; n void upd(int &x, int y) { n   if (y <= K) { n     if (x == -1) x = y; n     if (y < x) x = y; n   } n } n int main() { n   scanf( %d%d , &n, &K); n   for (int i = 1; i <= n; ++i) scanf( %s , mp[i] + 1); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) { n       f[i][j] = -1; n       zy[i + j - 1].push_back((re){i, j}); n     } n   if (mp[1][1] ==  a ) { n     Ans.push_back( a ); n     A.push_back((re){1, 1}); n     f[1][1] = 0; n   } else { n     if (K >= 1) { n       Ans.push_back( a ); n       A.push_back((re){1, 1}); n       f[1][1] = 1; n     } else { n       Ans.push_back(mp[1][1]); n       A.push_back((re){1, 1}); n       f[1][1] = 0; n     } n   } n   for (int i = 2; i <= 2 * n - 1; ++i) { n     char Min =  z ; n     for (auto u : A) { n       if (f[u.x][u.y] + 1 <= K) Min =  a ; n       if (u.x + 1 <= n) Min = min(Min, mp[u.x + 1][u.y]); n       if (u.y + 1 <= n) Min = min(Min, mp[u.x][u.y + 1]); n     } n     Ans.push_back(Min); n     for (auto u : A) { n       if (u.x + 1 <= n) { n         upd(f[u.x + 1][u.y], f[u.x][u.y] + (mp[u.x + 1][u.y] != Min)); n       } n       if (u.y + 1 <= n) { n         upd(f[u.x][u.y + 1], f[u.x][u.y] + (mp[u.x][u.y + 1] != Min)); n       } n     } n     for (auto u : zy[i]) n       if (f[u.x][u.y] != -1) B.push_back(u); n     swap(A, B); n     B.clear(); n   } n   printf( %s n , Ans.c_str()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mxn = 1e5 + 100; n int a[mxn], b[mxn], c[mxn]; n set<int> mp; n void add(int x) { n   if (c[x] == 0) n     mp.insert(b[x]); n   else if (c[x] == 1) n     mp.erase(b[x]); n   c[x]++; n } n void remove(int x) { n   if (c[x] == 2) n     mp.insert(b[x]); n   else if (c[x] == 1) n     mp.erase(b[x]); n   c[x]--; n } n int main() { n   int n, k, m; n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %d , a + i), b[i - 1] = a[i]; n   sort(b, b + n), m = unique(b, b + n) - b; n   for (int i = 1; i <= n; i++) { n     a[i] = lower_bound(b, b + m, a[i]) - b; n     add(a[i]); n     if (i >= k) { n       if (mp.empty()) n         puts( Nothing ); n       else n         printf( %d n , *mp.rbegin()); n       remove(a[i - k + 1]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   long long n; n   cin >> t; n   while (t--) { n     cin >> n; n     if (n % 2) { n       if ((n / 2) & 1) { n         cout << n + 1 << endl; n       } else { n         cout << 2 * n + 1 << endl; n       } n     } else { n       cout << 4 * n + 1 << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   char c = getchar(); n   long long f = 1, x = 0; n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = (x << 1) + (x << 3) + (c ^  0 ); n     c = getchar(); n   } n   return x * f; n } n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n char s[3]; n char b[3]; n int main() { n   scanf( %s , s + 1); n   long long flag = 0; n   long long ff = 0, f = 0, fff = 0; n   long long n = read(); n   for (int i = 1; i <= n; i++) { n     memset(b,   0 , sizeof(b)); n     scanf( %s , b + 1); n     if (b[1] == s[1] && b[2] == s[2]) { n       fff = 1; n     } n     if (b[1] == s[2] && b[2] == s[1]) { n       flag = 1; n     } n     if (b[2] == s[1]) { n       f = 1; n     } n     if (b[1] == s[2]) { n       ff = 1; n     } n   } n   if (flag != 0 || ff + f == 2 || fff == 1) { n     printf( YES n ); n   } else { n     printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = (1LL << 60) - 1; n int dx[] = {-1, 1, 0, 0}; n int dy[] = {0, 0, -1, 1}; n void solve() { n   long long n, x, y, k, c = 0; n   cin >> n >> x >> y; n   for (long long i = 0; i < n; i++) { n     cin >> k; n     if (k <= x) c++; n   } n   if (x > y) n     cout << n <<   n ; n   else n     cout << (c + 1) / 2 <<   n ; n } n int main() { n   ios::sync_with_stdio(0); n   cout.tie(0); n   ; n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cin.tie(NULL); n   cout.tie(NULL); n   ios_base::sync_with_stdio(false); n   int arr[4]; n   for (int i = 0; i < 4; i++) cin >> arr[i]; n   int a, b; n   cin >> a >> b; n   sort(arr, arr + 4); n   if (arr[0] > b) n     cout << b - a + 1 << endl; n   else if (arr[0] > a) n     cout << arr[0] - a << endl; n   else n     cout << 0 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int ans = -1; n   int n, dol, cent, s, i; n   cin >> n >> s; n   for (i = 0; i < n; i++) { n     cin >> dol >> cent; n     if (s > dol && cent != 0 && 100 - cent > ans) ans = 100 - cent; n     if (s >= dol && cent == 0 && ans == -1) ans = 0; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int tree[270000 * 4]; n int t; n char opt; n void insert(long long x) { n   if (x == 0) { n     ++tree[2]; n     return; n   } n   int num = x % 10; n   x /= 10; n   num = (num % 2 == 0 ? 0 : 1); n   int root = (num == 0 ? 2 : 3); n   ++tree[root]; n   while (x) { n     num = x % 10; n     x /= 10; n     num = (num % 2 == 0 ? 0 : 1); n     root = (num == 0 ? root * 2 : root * 2 + 1); n     ++tree[root]; n   } n } n void erase(long long x) { n   if (x == 0) { n     --tree[2]; n     return; n   } n   int num = x % 10; n   x /= 10; n   num = (num % 2 == 0 ? 0 : 1); n   int root = (num == 0 ? 2 : 3); n   --tree[root]; n   while (x) { n     num = x % 10; n     x /= 10; n     num = (num % 2 == 0 ? 0 : 1); n     root = (num == 0 ? root * 2 : root * 2 + 1); n     --tree[root]; n   } n } n void query(string s) { n   stack<int> stk; n   int lens = s.length(), beg = 0; n   for (int i = 0; i < lens; ++i) n     if (s[i] !=  0  || i == lens - 1) { n       beg = i; n       break; n     } n   for (int i = beg; i < lens; ++i) stk.push(s[i] -  0 ); n   int now = stk.top(); n   stk.pop(); n   int root = (now == 0 ? 2 : 3); n   int ans = tree[root]; n   while (!stk.empty()) { n     now = stk.top(); n     stk.pop(); n     root = (now == 0 ? root * 2 : root * 2 + 1); n     ans = min(tree[root], ans); n   } n   while (beg) { n     root *= 2; n     ans -= tree[root + 1]; n     --beg; n   } n   while (tree[root * 2] || tree[root * 2 + 1]) { n     root *= 2; n     ans -= tree[root + 1]; n   } n   cout << ans << endl; n } n int main() { n   cin >> t; n   for (int i = 1; i <= t; ++i) { n     cin >> opt; n     if (opt ==  + ) { n       long long x; n       cin >> x; n       insert(x); n     } else if (opt ==  - ) { n       long long x; n       cin >> x; n       erase(x); n     } else { n       string s; n       cin >> s; n       query(s); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long ans, tot, n; n long long a[105]; n void update(long long d) { n   long long sum = 0; n   for (int i = 1; i <= n; i++) sum += (a[i] - 1) / d + 1; n   if (sum * d <= tot) ans = max(ans, d); n } n int main() { n   long long k; n   scanf( %lld %lld , &n, &k); n   for (int i = 1; i <= n; i++) { n     scanf( %lld , &a[i]); n     tot += a[i]; n   } n   tot += k; n   for (long long i = 1; i * i <= tot - 1; i++) { n     update(i); n     update(tot / i); n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:1108864220 ) n using namespace std; n const int MOD = 1000000007; n const int INF = 1000000000; n const double EPS = 1e-9; n const int HASH_POW = 29; n const long double PI = acos(-1.0); n mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); n long long nextLong(long long l, long long r) { n   uniform_int_distribution<long long> foo(l, r); n   return foo(rnd); n } n double nextDouble(double l, double r) { n   uniform_real_distribution<double> foo(l, r); n   return foo(rnd); n } n double workTime() { return double(clock()) / CLOCKS_PER_SEC; } n void myReturn(int code = 0) { exit(code); } n int n; n long long goal = 0; n vector<int> p[15]; n vector<long long> sum; n unordered_map<int, pair<int, int> > pos; n pair<int, int> cycles[1 << 15]; n bool dp[1 << 15]; n int par[1 << 15]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   scanf( %d , &n); n   sum.resize(n); n   for (int i = 0; i < n; ++i) { n     int s; n     scanf( %d , &s); n     p[i].resize(s); n     sum[i] = 0; n     for (int j = 0; j < s; ++j) { n       scanf( %d , &p[i][j]); n       goal += p[i][j]; n       sum[i] += p[i][j]; n       pos[p[i][j]] = {i, j}; n     } n   } n   if (goal % n != 0) { n     printf( No n ); n     myReturn(); n   } else { n     goal /= n; n   } n   for (int i = 0; i < (1 << n); ++i) { n     cycles[i] = {-1, -1}; n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < p[i].size(); ++j) { n       int msk = 0, row = i, col = j; n       bool good = true; n       while (true) { n         if (msk & (1 << row)) { n           if (row != i) { n             good = false; n           } else if (col != j) { n             good = false; n           } n           break; n         } n         msk |= (1 << row); n         long long val = goal - sum[row] + p[row][col]; n         if (abs(val) > 1000000000) { n           good = false; n           break; n         } n         int key = (int)val; n         if (pos.find(key) == pos.end()) { n           good = false; n           break; n         } n         if (pos[key].first == row && pos[key].second != col) { n           good = false; n           break; n         } n         row = pos[key].first, col = pos[key].second; n       } n       if (good) { n         cycles[msk] = {i, j}; n       } n     } n   } n   dp[0] = true; n   for (int i = 1; i < (1 << n); ++i) { n     for (int s = i; s > 0; s = ((s - 1) & i)) { n       if (cycles[s].first != -1 && dp[i ^ s]) { n         dp[i] = true; n         par[i] = s; n       } n     } n   } n   if (!dp[(1 << n) - 1]) { n     printf( No n ); n     myReturn(); n   } n   vector<pair<int, int> > ans(n, {-1, -1}); n   int q = (1 << n) - 1; n   while (q != 0) { n     int s = par[q]; n     q ^= s; n     int msk = 0, row = cycles[s].first, col = cycles[s].second; n     while (true) { n       if (msk & (1 << row)) { n         break; n       } n       msk |= (1 << row); n       long long val = goal - sum[row] + p[row][col]; n       int key = (int)val; n       ans[pos[key].first] = {p[pos[key].first][pos[key].second], row + 1}; n       row = pos[key].first, col = pos[key].second; n     } n   } n   printf( Yes n ); n   for (int i = 0; i < n; ++i) { n     printf( %d %d n , ans[i].first, ans[i].second); n   } n   myReturn(); n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const int N = 2100; n int a[N][N], b[N][N], d[N][N]; n int c[N], n, tag = -1, res[N]; n void print() { n   cout << -1; n   exit(0); n } n int cnt = 0; n void solve(int id, int T) { n   if (T) { n     for (int i = 1; i <= n; i++) { n       if (i == tag) continue; n       if (d[i][id] != c[i]) res[i]++; n     } n   } else { n     for (int i = 1; i <= n; i++) { n       if (i == tag) continue; n       if (d[i][id] != 0) res[i]++; n     } n   } n } n int main() { n   std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n; n   char ch; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) cin >> ch, a[i][j] = ch -  0 ; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) cin >> ch, b[i][j] = ch -  0 ; n   for (int i = 1; i <= n; i++) cin >> ch, c[i] = ch -  0 ; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) d[i][j] = a[i][j] ^ b[i][j]; n   for (int i = 1; i <= n; i++) n     if (c[i]) tag = i; n   if (tag == -1) { n     bool f = 0; n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= n; j++) n         if (d[i][j]) f = 1; n     if (f) print(); n   } n   for (int i = 1; i <= n; i++) n     if (d[tag][i]) cnt++; n   for (int i = 1; i <= n; i++) solve(i, d[tag][i]); n   for (int i = 1; i <= n; i++) { n     if (res[i]) { n       cnt++; n       for (int j = 1; j <= n; j++) d[i][j] ^= c[j]; n     } n   } n   for (int j = 1; j <= n; j++) { n     int C = 0; n     bool f = 0; n     for (int i = 1; i <= n; i++) { n       if ((d[i][j] && c[i] == 0) || (!d[i][j] && c[i])) f = 1; n       if (d[i][j]) C++; n     } n     if (C && f) print(); n   } n   cout << cnt <<   n ; n   for (int i = 1; i <= n; i++) n     if (res[i]) cout <<  row   << i - 1 <<   n ; n   for (int i = 1; i <= n; i++) n     if (d[tag][i]) cout <<  col   << i - 1 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int cambio; n   cin >> cambio; n   vector<int> hansel; n   int madera = 0; n   int piedra = 0; n   int ladrillo; n   for (int i = 0; cambio > i; i++) { n     int gretel; n     cin >> gretel; n     piedra = piedra + gretel; n     hansel.push_back(gretel); n   } n   sort(hansel.begin(), hansel.end()); n   for (int i = 0; i < cambio; i++) { n     madera = madera + hansel[i]; n     piedra = piedra - hansel[i]; n     if (madera >= piedra) { n       ladrillo = cambio - i; n       break; n     } n   } n   cout << ladrillo; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int mod(int a, int k) { return (a % k + k) % k; } n int main() { n   int n, k, v; n   cin >> n >> k >> v; n   vector<int> a(1 + n, 0); n   int ss = 0; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     ss += a[i]; n   } n   if (ss < v) { n     cout <<  NO n ; n     return 0; n   } n   int target = v % k; n   vector<vector<pair<int, int>>> dp(1 + n, vector<pair<int, int>>(k, {0, 0})); n   dp[0][0] = {-1, 0}; n   for (int i = 1; i <= n; ++i) { n     for (int j = 0; j < k; ++j) { n       auto var1 = dp[i - 1][mod(j - a[i], k)]; n       auto var2 = dp[i - 1][j]; n       if (var1.first && var2.first) { n         if (var1.second + a[i] % k > var2.second) { n           dp[i][j] = {2, var1.second + a[i] % k}; n         } else { n           dp[i][j] = {1, var2.second}; n         } n       } else if (var1.first) { n         dp[i][j] = {2, var1.second + a[i] % k}; n       } else if (var2.first) { n         dp[i][j] = {1, var2.second}; n       } n     } n   } n   if (dp[n][target].first == 0) { n     cout <<  NO n ; n     return 0; n   } n   if (n == 1 && a[1] != v) { n     cout <<  NO n ; n     return 0; n   } n   cout <<  YES n ; n   int x = -1; n   int y = -1; n   int curr = n; n   int rem1 = target; n   while (curr > 0) { n     if (dp[curr][rem1].first == 2) { n       if (x == -1) { n         x = curr; n         rem1 = mod(rem1 - a[curr], k); n       } else { n         if (a[curr] > 0) { n           cout << (a[curr] - 1) / k + 1 <<     << curr <<     << x <<   n ; n         } n         a[x] += a[curr]; n         rem1 = mod(rem1 - a[curr], k); n         a[curr] = 0; n       } n     } else { n       if (y == -1) { n         y = curr; n       } else { n         if (a[curr] > 0) { n           cout << (a[curr] - 1) / k + 1 <<     << curr <<     << y <<   n ; n         } n         a[y] += a[curr]; n         a[curr] = 0; n       } n     } n     --curr; n   } n   if (y == -1) { n     if (x == 1) { n       y = 2; n     } else { n       y = 1; n     } n   } n   if (x == -1) { n     if (y == 1) { n       x = 2; n     } else { n       x = 1; n     } n   } n   if (x != -1) { n     if (a[x] < v) { n       cout << (v - a[x]) / k <<     << y <<     << x <<   n ; n     } else if (a[x] > v) { n       cout << (a[x] - v) / k <<     << x <<     << y <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, k; n   cin >> n >> k; n   long long l = 1, u = n, mid; n   while (l <= u) { n     mid = (l + u) / 2; n     long long sum = (mid * (mid + 1)) / 2; n     sum = sum - (n - mid); n     if (sum == k) { n       cout << n - mid << endl; n       break; n     } else if (sum < k) { n       l = mid + 1; n     } else n       u = mid - 1; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t; n   cin >> t; n   while (t--) { n     long long n, k; n     cin >> n >> k; n     long long arr[n]; n     for (long long i = 0; i < n; i++) cin >> arr[i]; n     long long x = 0; n     vector<long long> v; n     map<long long, long long> mp; n     for (long long i = 0; i < n; i++) { n       if (mp.find(arr[i]) == mp.end()) { n         v.push_back(arr[i]); n         mp[arr[i]] = 1; n         x++; n       } n     } n     if (x > k) n       cout << -1 << endl; n     else { n       long long x = 0; n       while (v.size() < k) { n         v.push_back(v[x]); n         x++; n       } n       vector<long long> w; n       long long j = 0, l = 0; n       while (j < n) { n         if (arr[j] == v[l]) { n           w.push_back(arr[j]); n           j++; n           l++; n         } else { n           w.push_back(v[l]); n           l++; n         } n         l %= v.size(); n       } n       cout << w.size() << endl; n       for (long long i = 0; i < w.size(); i++) cout << w[i] <<    ; n       cout << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   int m = (n << 1) - 1; n   vector<int> a(m); n   int first = -1; n   for (int i = 0; i < m; ++i) { n     scanf( %d , &a[i]); n     --a[i]; n     if (!~first && ~a[i]) { n       first = i; n     } n   } n   if (!~first) { n     puts( yes ); n     printf( 1 ); n     for (int i = 1; i < n; ++i) { n       printf(  %d 1 , i + 1); n     } n     putchar(10); n     return 0; n   } n   if (first) { n     vector<int> temp; n     for (int i = first; i < m; ++i) { n       temp.push_back(a[i]); n     } n     for (int i = 0; i < first; ++i) { n       temp.push_back(a[i]); n     } n     a = temp; n   } n   if (~a.back() && a.back() != a[0]) { n     puts( no ); n     return 0; n   } n   a.back() = a[0]; n   vector<int> free, parity(n, -1); n   for (int i = 0; i < m; ++i) { n     if (~a[i]) { n       if (~parity[a[i]]) { n         if (parity[a[i]] != (i & 1)) { n           puts( no ); n           return 0; n         } n       } else { n         parity[a[i]] = i & 1; n       } n     } n   } n   for (int i = 0; i < n; ++i) { n     if (!~parity[i]) { n       free.push_back(i); n     } n   } n   vector<int> prev(m), next(m); n   for (int i = 0; i < m; ++i) { n     prev[i] = i - 1; n     next[i] = i + 1; n   } n   auto erase = [&](int x) { n     if (next[x] != m) { n       prev[next[x]] = prev[x]; n     } n     if (~prev[x]) { n       next[prev[x]] = next[x]; n     } n   }; n   auto solve = [&](int l, int r) { n     for (int i = next[l]; i < r;) { n       if (~a[i] && ~a[next[i]] && !~a[prev[i]]) { n         a[prev[i]] = a[next[i]]; n         erase(i); n         erase(next[i]); n         i = prev[i]; n         if (i > l) { n           i = prev[i]; n         } n         if (i == l) { n           i = next[i]; n         } n       } else if (~a[i] && ~a[prev[i]] && !~a[next[i]]) { n         a[next[i]] = a[prev[i]]; n         erase(i); n         erase(next[i]); n         i = prev[i]; n         if (i == l) { n           i = next[i]; n         } n       } else { n         i = next[i]; n       } n     } n     for (int i = next[l]; i < r; i = next[i]) { n       erase(i); n     } n     erase(r); n   }; n   vector<bool> not_first(n), ban(n); n   for (int i = 0; i < m; ++i) { n     if (~a[i]) { n       if (not_first[a[i]]) { n         if (ban[a[i]]) { n           puts( no ); n           return 0; n         } n         int left = prev[i], right = i, numbers = 1, total = 1; n         while (a[left] != a[right]) { n           if (~a[left]) { n             ban[a[left]] = true; n             ++numbers; n           } n           ++total; n           left = prev[left]; n         } n         int need = (total >> 1) + 1 - numbers; n         if (need < 0) { n           puts( no ); n           return 0; n         } n         for (int j = left; j < right; j = next[j]) { n           if (!~a[j] && need) { n             if (free.empty()) { n               puts( no ); n               return 0; n             } else { n               a[j] = free.back(); n               --need; n               free.pop_back(); n             } n           } n         } n         solve(left, right); n       } else { n         not_first[a[i]] = true; n       } n     } n   } n   puts( yes ); n   if (first) { n     vector<int> temp; n     for (int i = m - 1 - first; i < m - 1; ++i) { n       temp.push_back(a[i]); n     } n     for (int i = 0; i < m - 1 - first; ++i) { n       temp.push_back(a[i]); n     } n     temp.push_back(a[m - 1 - first]); n     a = temp; n   } n   for (int i = 0; i < m; ++i) { n     printf( %d%c , a[i] + 1, i == m - 1 ?   n  :    ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int answer(); n int main() { n   long long t; n   t = 1; n   while (t--) { n     answer(); n   } n   return 0; n } n int answer() { n   string k; n   cin >> k; n   int sup[10] = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2}; n   if (k.size() > 1) { n     cout << sup[k[0] -  0 ] * sup[k[1] -  0 ] << endl; n   } else { n     cout << sup[k[0] -  0 ] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   double n, m; n   scanf( %lf %lf , &m, &n); n   double ans = 0; n   for (int i = 1; i <= m; i++) { n     ans += pow(i / m, n); n   } n   ans = m - ans + 1; n   printf( %.10lf , ans); n   return 0; n } n