#include <bits/stdc++.h> n using namespace std; n string s; n int n; n bool sogl(char x) { n   return x !=  a  && x !=  e  && x !=  i  && x !=  o  && x !=  u ; n } n int dp[3000], opt[3000]; n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> s; n   int n = s.size(); n   for (int i = 0; i < n; i++) { n     dp[i] = i + 1; n     opt[i] = i; n     for (int j = i; j >= 0; j--) { n       if (i - j + 1 >= 3 && sogl(s[j]) && sogl(s[j + 1]) && sogl(s[j + 2]) && n           (s[j] != s[j + 1] || s[j] != s[j + 2] || s[j + 1] != s[j + 2])) n         break; n       if ((j != 0 ? dp[j - 1] : 0) + 1 < dp[i]) { n         dp[i] = (j != 0 ? dp[j - 1] : 0) + 1; n         opt[i] = j; n       } n     } n   } n   vector<char> ans; n   int v = n - 1; n   while (v != -1) { n     int u = opt[v]; n     for (int i = v; i >= u; i--) ans.push_back(s[i]); n     ans.push_back(   ); n     v = u - 1; n   } n   ans.pop_back(); n   reverse(ans.begin(), ans.end()); n   for (char x : ans) cout << x; n } n


#include <bits/stdc++.h> n using namespace std; n int a[5][5]; n int b[] = {0, 1, 2, 3, 4}; n long long sol() { n   int p0 = b[0]; n   int p1 = b[1]; n   int p2 = b[2]; n   int p3 = b[3]; n   int p4 = b[4]; n   long long p = a[p0][p1] + a[p1][p0] + a[p2][p3] + a[p3][p2]; n   p += a[p1][p2] + a[p2][p1] + a[p3][p4] + a[p4][p3]; n   p += a[p2][p3] + a[p3][p2]; n   p += a[p3][p4] + a[p4][p3]; n   return p; n } n int main() { n   for (long long i = 0; i < 5; i++) n     for (long long j = 0; j < 5; j++) cin >> a[i][j]; n   long long m = 0; n   do { n     m = max(sol(), m); n   } while (next_permutation(b, b + 5)); n   cout << m; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e6 + 5; n const int mod = 1e9 + 7; n int n, k, m, dp[N], lst[300]; n char s[N]; n inline int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; } n inline int mul(int x, int y) { return (long long int)x * y % mod; } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n >> k >> (s + 1); n   m = strlen(s + 1); n   dp[0] = 1; n   for (int i = 1; i <= m; i++) { n     dp[i] = mul(dp[i - 1], 2); n     if (lst[s[i]] != 0) dp[i] = add(dp[i], mod - dp[lst[s[i]] - 1]); n     lst[s[i]] = i; n   } n   for (int i = m + 1; i <= n + m; i++) { n     dp[i] = mul(dp[i - 1], 2); n     int mn = 0; n     for (int j = 0; j < k; j++) { n       if (lst[mn +  a ] > lst[j +  a ]) mn = j; n     } n     if (lst[mn +  a ] != 0) dp[i] = add(dp[i], mod - dp[lst[mn +  a ] - 1]); n     lst[mn +  a ] = i; n   } n   cout << dp[n + m] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int r, c; n   cin >> r >> c; n   if (r == c and r == 1) return cout << 0, 0; n   if (r == 1) { n     for (int i = 0; i < c; i++) cout << 2 + i <<    ; n     return 0; n   } n   if (c == 1) { n     for (int i = 0; i < r; i++) cout << 2 + i <<    ; n     return 0; n   } n   int ans[r][c]; n   for (int i = 0; i < r; i++) n     for (int j = 0; j < c; j++) ans[i][j] = 1; n   int val = r + c; n   for (int i = 0; i < r; i++) { n     for (int j = 0; j < c; j++) ans[i][j] = val; n     val--; n   } n   for (int j = 0; j < c; j++) { n     for (int i = 0; i < r; i++) { n       ans[i][j] = ans[i][j] * val; n     } n     val--; n   } n   for (int i = 0; i < r; i++) { n     for (int j = 0; j < c; j++) cout << ans[i][j] <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[4]; n int cmp(int x, int y) { return x > y; } n int main() { n   int t; n   cin >> t; n   while (t--) { n     int ans = 0; n     cin >> a[0] >> a[1] >> a[2]; n     sort(a, a + 3, cmp); n     if (a[0]) { n       a[0]--; n       ans++; n     } n     if (a[1]) { n       a[1]--; n       ans++; n     } n     if (a[2]) { n       a[2]--; n       ans++; n     } n     if (a[0] && a[1]) { n       a[0]--, a[1]--; n       ans++; n     } n     if (a[0] && a[2]) { n       a[0]--, a[2]--; n       ans++; n     } n     if (a[1] && a[2]) { n       a[1]--, a[2]--; n       ans++; n     } n     if (a[0] && a[1] && a[2]) { n       ans++; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int a[s.length()]; n   int ans = -1; n   int n = s.length(); n   for (int i = 0; i < s.length(); i++) { n     a[i] = int(s[i]) - 48; n   } n   for (int i = 0; i < n; i++) { n     if (a[i] % 8 == 0) { n       ans = a[i]; n       break; n     } else n       for (int j = i + 1; j < n; j++) { n         if ((a[i] * 10 + a[j]) % 8 == 0) { n           ans = a[i] * 10 + a[j]; n           break; n         } else n           for (int k = j + 1; k < n; k++) { n             if ((100 * a[i] + 10 * a[j] + a[k]) % 8 == 0) { n               ans = 100 * a[i] + 10 * a[j] + a[k]; n               break; n             } n           } n       } n   } n   if (ans != -1) { n     cout <<  YES  << endl; n     cout << ans; n   } else n     cout <<  NO ; n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, a[3000000]; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> k; n   int mini = 2000000; n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     mini = min(mini, x); n     a[max(1, x - k)]++; n     a[x + 1]--; n   } n   for (int i = 1; i <= 1500000; i++) a[i] += a[i - 1]; n   for (int i = 1000000; i >= k + 1; i--) { n     int sum = 0; n     for (int j = 0; j <= 1000000; j += i) sum += a[j]; n     assert(sum <= n); n     if (sum == n) { n       cout << i << endl; n       return 0; n     } n   } n   cout << mini << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 3000000; n const int MAXM = 200000; n const int INF = 1000000010; n const long long int MOD = 1000000007; n const long long int P = 31; n const long double EPS = 1e-6; n int N, M, K; n char s[MAXN]; n long long int dp[26] = {0}; n int last_used[26]; n int main() { n   ios_base::sync_with_stdio(false); n   scanf( %d %d , &M, &K); n   scanf( %s , s); n   N = strlen(s); n   memset(last_used, -1, sizeof(last_used)); n   long long int tmp; n   for (int i = 0; i < N; i++) { n     tmp = 1; n     for (int j = 0; j < K; j++) { n       tmp = (tmp + dp[j]) % MOD; n     } n     dp[s[i] -  a ] = tmp; n     last_used[s[i] -  a ] = i; n   } n   int ptr; n   for (int i = 0; i < M; i++) { n     ptr = 0; n     tmp = 1; n     for (int j = 0; j < K; j++) { n       tmp = (tmp + dp[j]) % MOD; n       if (last_used[j] < last_used[ptr]) ptr = j; n     } n     dp[ptr] = tmp; n     last_used[ptr] = i + N; n   } n   tmp = 1; n   for (int i = 0; i < K; i++) tmp = (tmp + dp[i]) % MOD; n   printf( %I64d , tmp); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O2 ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n const long double eps = 1e-7; n const int inf = 1000000010; n const long long INF = 1000000000000001000LL; n const int mod = 1000000007; n const int MAXN = 300010, LOG = 19; n struct Data { n   long long w[2][2]; n } SP[MAXN][LOG]; n Data operator+(Data x, Data y) { n   Data out; n   for (int i = 0; i < 2; i++) n     for (int j = 0; j < 2; j++) n       out.w[i][j] = min(x.w[i][0] + y.w[0][j], x.w[i][1] + y.w[1][j]); n   return out; n } n long long n, m, k, u, v, x, y, t, a, b; n long long W[MAXN][2]; n int h[MAXN]; n int par[MAXN][LOG]; n Data D[MAXN]; n long long dist[MAXN]; n bool mark[MAXN]; n vector<pair<int, int>> G[MAXN]; n priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, n                greater<pair<long long, long long>>> n     pq; n void dfs(int node) { n   for (int i = 1; i < LOG; i++) { n     par[node][i] = par[par[node][i - 1]][i - 1]; n     SP[node][i] = SP[node][i - 1] + SP[par[node][i - 1]][i - 1]; n   } n   h[node] = h[par[node][0]] + 1; n   for (pair<int, int> p : G[node]) n     if (p.first != par[node][0]) { n       int v = p.first, i = p.second; n       par[v][0] = node; n       SP[v][0].w[0][0] = min(W[i][0], W[i][1] + dist[v] + dist[node]); n       SP[v][0].w[1][1] = min(W[i][1], W[i][0] + dist[v] + dist[node]); n       SP[v][0].w[0][1] = min(W[i][0] + dist[node], dist[v] + W[i][1]); n       SP[v][0].w[1][0] = min(W[i][1] + dist[node], dist[v] + W[i][0]); n       dfs(v); n     } n } n int LCA(int x, int y) { n   if (h[x] > h[y]) swap(x, y); n   for (int i = 0; i < LOG; i++) n     if ((h[y] - h[x]) & (1 << i)) y = par[y][i]; n   if (x == y) return x; n   for (int i = LOG - 1; i >= 0; i--) n     if (par[x][i] != par[y][i]) x = par[x][i], y = par[y][i]; n   return par[x][0]; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> x, pq.push({dist[i] = x, i}); n   for (int i = 1; i < n; i++) { n     cin >> u >> v >> W[i][1] >> W[i][0]; n     G[u].push_back({v, i}); n     G[v].push_back({u, i}); n   } n   while (!pq.empty()) { n     int v = pq.top().second; n     pq.pop(); n     if (mark[v]) continue; n     mark[v] = 1; n     for (pair<int, int> p : G[v]) n       if (!mark[p.first]) { n         long long w = W[p.second][0] + W[p.second][1]; n         if (dist[v] + w < dist[p.first]) n           pq.push({dist[p.first] = dist[v] + w, p.first}); n       } n   } n   for (int i = 1; i <= n; i++) D[i].w[0][1] = D[i].w[1][0] = dist[i]; n   dfs(1); n   cin >> m; n   while (m--) { n     cin >> x >> y; n     u = (x + 1) / 2; n     v = (y + 1) / 2; n     int lca = LCA(u, v); n     Data ans1 = D[u], ans2 = D[v]; n     for (int i = 0; i < LOG; i++) n       if ((h[lca] - h[u]) & (1 << i)) ans1 = ans1 + SP[u][i], u = par[u][i]; n     for (int i = 0; i < LOG; i++) n       if ((h[lca] - h[v]) & (1 << i)) ans2 = ans2 + SP[v][i], v = par[v][i]; n     swap(ans2.w[0][1], ans2.w[1][0]); n     Data ans = ans1 + ans2; n     cout << ans.w[x & 1][y & 1] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string solve() { n   int n; n   cin >> n; n   int a[n]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   if (n % 2 == 0) return  YES ; n   for (int i = 0; i < n - 1; i++) n     if (a[i] >= a[i + 1]) return  YES ; n   return  NO ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int t = 1; n   cin >> t; n   while (t--) { n     cout << solve() <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = int(1e9) + 7; n long long pom[2][2] = {{0, 1}, {1, 1}}; n void mulMat(long long *A, long long *B, int n) { n   long long res[2][2] = {{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         res[i][j] += (*(A + i * n + k)) * (*(B + k * n + j)); n         if (res[i][j] >= MOD) res[i][j] %= MOD; n       } n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) *(A + i * n + j) = res[i][j]; n } n void fastExp(long long pot, long long *T) { n   while (pot) { n     if (pot & 1) { n       mulMat(T, pom[0], 2); n     } n     mulMat(pom[0], pom[0], 2); n     pot >>= 1; n   } n   pom[0][0] = 0; n   pom[0][1] = 1; n   pom[1][0] = 1; n   pom[1][1] = 1; n } n struct Node { n   long long mat[2][2]; n   Node() { n     mat[0][0] = 1; n     mat[0][1] = 0; n     mat[1][0] = 0; n     mat[1][1] = 1; n   } n   Node(int pot) { n     mat[0][0] = 1; n     mat[0][1] = 0; n     mat[1][0] = 0; n     mat[1][1] = 1; n     fastExp(pot, mat[0]); n   } n }; n void zbrojiMat(long long *resMat, long long *op1, long long *op2) { n   for (int i = 0; i < 2; i++) n     for (int j = 0; j < 2; j++) { n       *(resMat + i * 2 + j) = (*(op1 + i * 2 + j) + *(op2 + i * 2 + j)); n       if (*(resMat + i * 2 + j) >= MOD) *(resMat + i * 2 + j) -= MOD; n     } n } n int n, m; n struct Node zeroe; n struct segTree { n   struct Node arr[1 << 18]; n   struct Node lazy[1 << 18]; n   int offset; n   struct Node neutralElem; n   void normalInit(int n) { n     for (offset = 1; offset < n; offset *= 2) n       ; n     for (int i = 0; i < 2 * offset; i++) { n       arr[i] = zeroe; n       lazy[i] = neutralElem; n     } n   } n   struct Node mergeValues(struct Node l, struct Node r) { n     struct Node n; n     zbrojiMat(n.mat[0], l.mat[0], r.mat[0]); n     return n; n   } n   segTree(int n) { normalInit(n); } n   segTree(int n, int *data) { n     normalInit(n); n     for (int i = offset; i < offset + n; i++) n       arr[i] = Node(*(data + i - offset)); n     for (int i = offset - 1; i >= 1; i--) n       arr[i] = mergeValues(arr[i * 2], arr[i * 2 + 1]); n   } n   void updateRange(int lo, int hi, long long *x) { n     update(1, 0, offset, lo, hi + 1, x); n   } n   struct Node query(int lo, int hi) { n     return q(1, 0, offset, lo, hi + 1); n   } n  n  private: n   void prop(int node) { n     mulMat(arr[node * 2].mat[0], lazy[node].mat[0], 2); n     mulMat(arr[node * 2 + 1].mat[0], lazy[node].mat[0], 2); n     mulMat(lazy[node * 2].mat[0], lazy[node].mat[0], 2); n     mulMat(lazy[node * 2 + 1].mat[0], lazy[node].mat[0], 2); n     lazy[node] = neutralElem; n   } n   void update(int node, int lo, int hi, int qlo, int qhi, long long *T) { n     if (lo >= qhi or hi <= qlo) return; n     if (lo >= qlo && hi <= qhi) { n       mulMat(arr[node].mat[0], T, 2); n       mulMat(lazy[node].mat[0], T, 2); n       return; n     } n     prop(node); n     int mid = (lo + hi) / 2; n     if (node < offset) { n       update(node * 2, lo, mid, qlo, qhi, T); n       update(node * 2 + 1, mid, hi, qlo, qhi, T); n       arr[node] = mergeValues(arr[node * 2], arr[node * 2 + 1]); n     } n   } n   struct Node q(int node, int lo, int hi, int qlo, int qhi) { n     if (lo >= qhi || hi <= qlo) return zeroe; n     if (lo >= qlo && hi <= qhi) return arr[node]; n     prop(node); n     int mid = (lo + hi) / 2; n     return mergeValues(q(node * 2, lo, mid, qlo, qhi), n                        q(node * 2 + 1, mid, hi, qlo, qhi)); n   } n }; n const int MAX = 100005; n int data[MAX]; n int main() { n   double start = clock(); n   zeroe.mat[0][0] = 0; n   zeroe.mat[1][1] = 0; n   cin >> n >> m; n   for (int i = 0; i < n; i++) scanf( %d , &data[i]); n   segTree *T = new segTree(n, data); n   if (n == 99395) n     ; n   for (int i = 0; i < m; i++) { n     int id; n     scanf( %d , &id); n     int l, r; n     scanf( %d%d , &l, &r); n     l--; n     r--; n     if (id == 1) { n       int x; n       scanf( %d , &x); n       long long Ti[2][2] = {{1, 0}, {0, 1}}; n       fastExp(x, Ti[0]); n       T->updateRange(l, r, Ti[0]); n     } else { n       printf( %d n , T->query(l, r).mat[0][1]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int mod = 1000000007; n void __print(long long int x) { cerr << x; } n void __print(unsigned x) { cerr << x; } n void __print(unsigned long x) { cerr << x; } n void __print(unsigned long long x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char *x) { cerr <<     << x <<    ; } n void __print(const string &x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename Th, typename V> n void __print(const pair<Th, V> &x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename Th> n void __print(const Th &x) { n   long long int f = 0; n   cerr <<  { ; n   for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename Th, typename... V> n void _print(Th t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n void binary_rock() { n   string a; n   cin >> a; n   long long int m; n   cin >> m; n   long long int i, j, k, l; n   vector<long long int> b(m); n   for (i = 0; i < m; i++) cin >> b[i]; n   vector<long long int> fre(26); n   for (i = 0; i < 26; i++) fre[i] = 0; n   long long int n = a.size(); n   for (i = 0; i < n; i++) { n     fre[a[i] -  a ]++; n   }; n   long long int pos = 25; n   string ans =   ; n   long long int nikal = 0; n   for (i = 0; i < m; i++) ans.push_back(( - )); n   ; n   ; n   while (1) { n     long long int zero = 0; n     vector<long long int> id; n     for (i = 0; i < m; i++) { n       if (b[i] == 0) id.push_back(i); n     } n     zero = id.size(); n     while (1) { n       if (fre[pos] >= zero) n         break; n       else { n         pos--; n       } n     } n     for (i = 0; i < zero; i++) { n       ans[id[i]] =  a  + pos; n     }; n     for (i = 0; i < zero; i++) { n       long long int x = id[i]; n       for (j = 0; j < m; j++) { n         if (b[j] == 0) continue; n         b[j] -= abs(x - j); n       } n     }; n     for (i = 0; i < zero; i++) { n       b[id[i]] = -1; n     } n     nikal += zero; n     if (nikal >= m) break; n     pos--; n   } n   cout << ans << endl; n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   clock_t t1 = clock(); n   long long int t = 1; n   cin >> t; n   while (t--) { n     binary_rock(); n   } n   clock_t t2 = clock(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n; n long long p[16]; n long long Count(long long n, int i) { n   long long ret = (i + 1LL) * (n / p[i]); n   n %= p[i]; n   if (n == 0) return ret; n   return ret + min(Count(n, i - 1), i + 1 + Count(p[i] - n, i - 1)); n } n int main() { n   p[0] = 1; n   for (int i = 0; i < 16; i++) p[i] = p[i - 1] * 10 + 1; n   cin >> n; n   cout << Count(n, 15); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[500010]; n int main() { n   int n; n   cin >> n; n   a[0] = 2; n   vector<pair<int, int> > cumcnt; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     if (a[i] == a[i - 1]) n       cumcnt.back().second++; n     else n       cumcnt.emplace_back(a[i], 1); n   } n   cumcnt.back().second++; n   int N = (int(cumcnt.size())); n   int st = 0; n   int ans = 0; n   for (int i = 0; i < N; i++) { n     if (i == N - 1) break; n     st += cumcnt[i].second; n     int j = i + 1, e = 0; n     while (j < N && cumcnt[j].second == 1) j++, e++; n     if (j < N) { n       int steps = (e + 1) / 2; n       ans = max(ans, steps); n       for (int make_pair = 0; make_pair < e; ++make_pair) { n         if (cumcnt[i].first == cumcnt[j].first) n           a[make_pair + st + 1] = cumcnt[i].first; n         else { n           if (make_pair < e / 2) n             a[make_pair + st + 1] = cumcnt[i].first; n           else n             a[make_pair + st + 1] = cumcnt[j].first; n         } n       } n     } n     st += e; n     i = j - 1; n   } n   cout << ans <<   n ; n   for (int i = 1; i <= n; ++i) { n     cout << a[i] <<    n [i == n]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100000 + 7; n vector<vector<int> > g, gr; n vector<char> used; n vector<int> order, component; n void dfs1(int v) { n   used[v] = true; n   for (size_t i = 0; i < g[v].size(); ++i) n     if (!used[g[v][i]]) dfs1(g[v][i]); n   order.push_back(v); n } n void dfs2(int v) { n   used[v] = true; n   component.push_back(v); n   for (size_t i = 0; i < gr[v].size(); ++i) n     if (!used[gr[v][i]]) dfs2(gr[v][i]); n } n int main() { n   int n, cost[MAXN]; n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> cost[i]; n   int m; n   cin >> m; n   g.resize(n); n   gr.resize(n); n   for (int i = 0; i < m; ++i) { n     int a, b; n     cin >> a >> b; n     --a; n     --b; n     g[a].push_back(b); n     gr[b].push_back(a); n   } n   used.assign(n, false); n   for (int i = 0; i < n; ++i) n     if (!used[i]) dfs1(i); n   used.assign(n, false); n   long long ficost = 0; n   long long fix = 1; n   for (int i = 0; i < n; ++i) { n     int v = order[n - 1 - i]; n     if (!used[v]) { n       dfs2(v); n       int curmin = INT_MAX; n       for (size_t j = 0; j < component.size(); ++j) n         curmin = min(curmin, cost[component[j]]); n       ficost += curmin; n       int curc = 0; n       for (size_t j = 0; j < component.size(); ++j) n         if (cost[component[j]] == curmin) ++curc; n       fix *= curc; n       fix %= 1000000000 + 7; n       component.clear(); n     } n   } n   cout << ficost <<     << fix << endl; n } n


#include <bits/stdc++.h> n using namespace std; n string s1, s2; n int main() { n   cin >> s1 >> s2; n   if (s1.length() != s2.length()) n     cout <<  NO ; n   else { n     int x = 0; n     int y = 0; n     for (int i = 0; i < s1.length(); i++) { n       if (s1[i] -  0  == 1) x++; n       if (s2[i] -  0  == 1) y++; n     } n     if (x == 0 && y == 0) n       cout <<  YES ; n     else if (x == 0 && y != 0) n       cout <<  NO ; n     else if (x != 0 && y == 0) n       cout <<  NO ; n     else if (x != 0 && y != 0) n       cout <<  YES ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1E18; n const int MAXN = 2000; n int l[MAXN]; n int r[MAXN]; n int a[MAXN]; n long long dp[MAXN]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, k; n   cin >> n >> k; n   bool poss = true; n   long long extra = 0; n   for (int i = 0; i < n; i++) { n     cin >> l[i] >> r[i] >> a[i]; n     if (i && l[i] > r[i - 1]) extra = 0; n     long long bullets = extra + a[i]; n     if (bullets > (long long)(r[i] - l[i] + 1) * k) { n       poss = false; n     } n     extra = max(0LL, bullets - (long long)(r[i] - l[i]) * k); n   } n   if (!poss) { n     cout <<  -1 n ; n     return 0; n   } n   dp[n - 1] = a[n - 1]; n   for (int i = n - 2; i >= 0; i--) { n     dp[i] = INF; n     extra = 0; n     long long totalUsed = 0; n     for (int j = i; j < n; j++) { n       totalUsed += a[j]; n       long long bullets = extra + a[j]; n       if (bullets > (long long)(r[j] - l[j] + 1) * k) break; n       extra = bullets % k; n       if (j < n - 1) { n         long long last = max(0LL, bullets - (long long)(r[j] - l[j]) * k); n         if (r[j] < l[j + 1] || !last) { n           if (extra) n             dp[i] = min(dp[i], totalUsed + (k - extra) + dp[j + 1]); n           else n             dp[i] = min(dp[i], totalUsed + dp[j + 1]); n         } n       } else { n         dp[i] = min(dp[i], totalUsed); n       } n     } n   } n   cout << dp[0] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string n; n int k; n int main() { n   cin >> n >> k; n   if (n[0] ==  0 ) { n     cout << 0 << endl; n     return 0; n   } n   int count = 0, c = 0; n   for (int i = n.size() - 1; i >= 0; i--) { n     count += (n[i] ==  0 ); n     c += (n[i] !=  0 ); n     if (count == k) { n       cout << c << endl; n       return 0; n     } n     if (i == 0) { n       for (auto m : n) n         if (m ==  0 ) { n           cout << n.size() - 1 << endl; n           return 0; n         } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n int n, m, tren, pos[N], cnt[N]; n vector<int> g[N]; n int dist(int a, int tr) { n   if (a > tr) n     return a - tr; n   else n     return n + a - tr; n } n bool cmp(int a, int b) { n   if (dist(a, tren) < dist(b, tren)) return true; n   return false; n } n int next(int i) { n   if (i < n) return i + 1; n   return 1; n } n int check(int i) { n   int num = 0, curr = i, time = 0; n   while (num < m) { n     if (cnt[curr]) { n       num += cnt[curr]; n       cnt[curr] = 0; n     } n     if (pos[curr] >= 0) { n       cnt[g[curr][pos[curr]]]++; n       pos[curr]--; n     } n     curr = next(curr); n     time++; n   } n   return time - 1; n } n int main() { n   scanf( %d , &n); n   scanf( %d , &m); n   for (int i = 1; i <= m; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     g[x].push_back(y); n   } n   for (int i = 1; i <= n; i++) { n     tren = i; n     sort(g[i].begin(), g[i].end(), cmp); n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       cnt[j] = 0; n       pos[j] = g[j].size() - 1; n     } n     printf( %d  , check(i)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int size = 100004; n char s[size][4]; n struct node { n   int l, r, cnt; n   long long sum[6]; n } tree[size * 4]; n int tmp[size], q[size]; n void pushup(int rt) { n   int i; n   for (i = 0; i < 5; ++i) n     tree[rt].sum[i] = n         tree[rt << 1].sum[i] + n         tree[rt << 1 | 1].sum[(i - tree[rt << 1].cnt % 5 + 5) % 5]; n   return; n } n void build(int rt, int l, int r) { n   int i, mid; n   tree[rt].l = l; n   tree[rt].r = r; n   tree[rt].cnt = 0; n   if (l == r) return; n   for (i = 0; i < 5; ++i) tree[rt].sum[i] = 0; n   mid = (l + r) >> 1; n   build(rt << 1, l, mid); n   build(rt << 1 | 1, mid + 1, r); n } n void update(int pos, int cnt, int rt, int add) { n   tree[rt].cnt += cnt; n   if (tree[rt].l == tree[rt].r) { n     tree[rt].sum[0] += (long long)add; n     return; n   } else { n     if (pos <= tree[rt << 1].r) n       update(pos, cnt, rt << 1, add); n     else n       update(pos, cnt, rt << 1 | 1, add); n     pushup(rt); n   } n } n int main() { n   int n, cnt, i, j, pos; n   while (scanf( %d , &n) != EOF) { n     cnt = 0; n     for (i = 0; i < n; ++i) { n       scanf( %s , s[i]); n       if (s[i][0] !=  s ) { n         scanf( %d , &q[i]); n         tmp[cnt++] = q[i]; n       } n     } n     if (cnt > 0) { n       sort(tmp, tmp + cnt); n       cnt = unique(tmp, tmp + cnt) - tmp; n       build(1, 1, cnt); n     } n     for (i = 0; i < n; ++i) { n       if (s[i][0] ==  s ) { n         cout << tree[1].sum[2] << endl; n       } else { n         pos = lower_bound(tmp, tmp + cnt, q[i]) - tmp; n         if (s[i][0] ==  a ) n           update(pos, 1, 1, q[i]); n         else n           update(pos, -1, 1, -q[i]); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int used[100]; n vector<vector<int>> g; n int cmp = 0; n vector<int> parent, rank1; n void make_set(int v) { n   parent[v] = v; n   rank1[v] = 0; n } n int find_set(int v) { n   if (v == parent[v]) return v; n   return parent[v] = find_set(parent[v]); n } n void union_sets(int a, int b) { n   a = find_set(a); n   b = find_set(b); n   if (a != b) { n     if (rank1[a] < rank1[b]) swap(a, b); n     parent[b] = a; n     if (rank1[a] == rank1[b]) ++rank1[a]; n   } n } n bool ok = 1; n void dfs(int v, int p = -1) { n   used[v] = 1; n   for (auto to : g[v]) { n     if (!used[to]) n       union_sets(v, to), dfs(to, v); n     else { n       if (to != p) ok = 0; n     } n   } n } n signed main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   int n, m; n   cin >> n >> m; n   parent.resize(n); n   rank1.resize(n); n   for (int i = 0; i < n; ++i) make_set(i); n   g.resize(n); n   bool ok1 = 1, ok2 = 1, ok3 = 1; n   bool ok4 = 1; n   if (m > n) ok1 = 0; n   for (int i = 0; i < m; ++i) { n     int a, b; n     cin >> a >> b; n     a--, b--; n     g[a].push_back(b); n     g[b].push_back(a); n     if (g[a].size() > 2 || g[b].size() > 2) { n       ok2 = 0; n     } n   } n   dfs(0); n   for (int i = 0; i < n; ++i) { n     if (!used[i]) ok3 = 0; n     if (g[i].size() != 2) ok4 = 0; n   } n   if (ok4 && ok3) { n     cout <<  YES  << endl << 0; n     return 0; n   } n   memset(used, 0, sizeof(used)); n   for (int i = 0; i < n; ++i) { n     if (!used[i]) dfs(i); n   } n   if (!(ok1 && ok2 && ok)) { n     cout <<  NO ; n     return 0; n   } n   vector<pair<int, int>> ans; n   vector<int> cur; n   vector<int> deg(n); n   for (int i = 0; i < n; ++i) { n     deg[i] = g[i].size(); n     if (deg[i] <= 1) cur.push_back(i); n   } n   for (int i = 0; i < n; ++i) { n     if (!used[i]) { n       dfs(i); n       cmp++; n     } n   } n   vector<int> nd; n   for (int i = 0; i < n; ++i) { n     for (int j = i + 1; j < n; ++j) { n       if (deg[i] >= 2 || deg[j] >= 2) continue; n       if (find_set(i) != find_set(j)) { n         ans.push_back({i, j}); n         deg[i]++; n         deg[j]++; n         union_sets(i, j); n       } n     } n   } n   for (int i = 0; i < n; ++i) { n     if (deg[i] <= 1) nd.push_back(i); n   } n   ans.push_back({nd[0], nd[nd.size() - 1]}); n   cout <<  YES n  << ans.size() <<   n ; n   for (auto u : ans) cout << u.first + 1 <<     << u.second + 1 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double m, n; n   long long int r, a, b, c, d, dist, sim; n   cin >> r >> a >> b >> c >> d; n   dist = (c - a) * (c - a) + (d - b) * (d - b); n   m = sqrt(dist); n   m = m / 2; n   c = m / r; n   m = m / r; n   if (m == c) n     cout << c; n   else n     cout << c + 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<int, bool> in; n int main() { n   int n, mx = 0, arr[200], ans = 0; n   char a[200]; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i] >> arr[i]; n     if (a[i] ==  + ) { n       in[arr[i]] = true; n       mx++; n     } else if (a[i] ==  - ) { n       if (in[arr[i]]) { n         mx--; n         in[arr[i]] = false; n       } else n         ans++; n     } n     ans = max(mx, ans); n   } n   cout << ans; n } n


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


#include <bits/stdc++.h> n using namespace std; n long sail(char ar[], long a, long m, long n) { n   for (int k = 0; k < a; k++) { n     if (m > 0) { n       if (ar[k] ==  E ) m--; n     } n     if (m < 0) { n       if (ar[k] ==  W ) m++; n     } n     if (n > 0) { n       if (ar[k] ==  N ) n--; n     } n     if (n < 0) { n       if (ar[k] ==  S ) n++; n     } n     if (n == 0 && m == 0) { n       return k + 1; n     } n   } n   return -1; n } n int main() { n   long a, b, c, d, e; n   cin >> a >> b >> c >> d >> e; n   char ar[100000]; n   for (int i = 0; i < a; i++) cin >> ar[i]; n   long m = d - b; n   long n = e - c; n   cout << sail(ar, a, m, n) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long int n, cnt = 0; n   cin >> n; n   for (long long i = 2; i <= sqrt(n); i++) { n     long long int temp[n]; n     if ((i * i * i) <= n) cnt++; n   } n   cout << cnt + 1 << endl; n } n void opti() { n   long long int n; n   cin >> n; n   set<int> a; n   for (int i = 1; i * i <= n; i++) { n     a.insert(i * i); n   } n   for (int i = 1; i * i * i <= n; i++) { n     a.insert(i * i * i); n   } n   cout << a.size() << endl; n } n int main() { n   int t; n   cin >> t; n   while (t--) opti(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a, b; n int main() { n   cin >> a >> b; n   cout << a + b << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <class a, class b> n pair<a, b> operator+(pair<a, b> x, pair<a, b> y) { n   return (pair<a, b>(x.first + y.first, x.second + y.second)); n } n template <class t> n ostream &operator<<(ostream &tout, const vector<t> &s) { n   tout <<  [ ; n   for (long long i = 0; i < s.size(); i++) n     if (i + 1 == s.size()) n       tout << s[i]; n     else n       tout << s[i] <<  , ; n   tout <<  ] ; n   return (tout); n } n template <class a, class b> n ostream &operator<<(ostream &tout, const pair<a, b> &c) { n   return (tout <<  (  << c.first <<  ,  << c.second <<  ) ); n } n const long long MAX_N = 200000 + 20; n const complex<double> change(1.42423, 1.31231); n pair<long long, long long> num[MAX_N]; n long long n, order[MAX_N], k; n bool df(long long a, long long b) { n   double x = (complex<double>(num[a].first, num[a].second) * change).real(); n   double y = (complex<double>(num[b].first, num[b].second) * change).real(); n   return (x < y); n } n pair<long long, long long> first[MAX_N], second[MAX_N]; n long long amount() { n   long long p1 = 1, p2 = 1, ans = 0; n   while (p1 <= n && p2 <= n) { n     if (first[p1] < second[p2]) { n       ans++; n       p1++; n       continue; n     } n     if (first[p1] > second[p2]) { n       ans++; n       p2++; n       continue; n     } n     p1++; n   } n   ans += (n + 1) * 2 - p1 - p2; n   return (ans); n } n int main() { n   cout << fixed; n   cout.precision(1); n   ios_base::sync_with_stdio(false); n   cin >> n >> k; n   if (k >= n) { n     cout << -1 << endl; n     return (0); n   } n   for (long long i = 1; i <= n; i++) { n     cin >> num[i].first >> num[i].second; n     num[i].first *= 2; n     num[i].second *= 2; n   } n   vector<pair<long long, long long> > candidates; n   for (long long i = 1; i <= n; i++) order[i] = i; n   sort(order + 1, order + n + 1, df); n   for (long long i = 1; i <= n && i <= 11; i++) n     for (long long j = n; j >= 1 && j >= n - 10; j--) n       if (i - 1 + n - j <= k) n         candidates.push_back(pair<long long, long long>( n             (num[order[i]].first + num[order[j]].first) / 2, n             (num[order[i]].second + num[order[j]].second) / 2)); n   vector<pair<long long, long long> > result; n   sort(candidates.begin(), candidates.end()); n   candidates.resize(unique(candidates.begin(), candidates.end()) - n                     candidates.begin()); n   for (long long i = 1; i <= n; i++) first[i] = num[i]; n   sort(first + 1, first + n + 1); n   for (long long i = 1; i <= n; i++) n     second[i] = pair<long long, long long>(-first[n - i + 1].first, n                                            -first[n - i + 1].second); n   for (long long i = 0; i < candidates.size(); i++) { n     if (i == 0) n       for (long long j = 1; j <= n; j++) { n         second[j].first += 2 * candidates[i].first; n         second[j].second += 2 * candidates[i].second; n       } n     else n       for (long long j = 1; j <= n; j++) { n         second[j].first += 2 * (candidates[i].first - candidates[i - 1].first); n         second[j].second += n             2 * (candidates[i].second - candidates[i - 1].second); n       } n     if (amount() <= n + k) result.push_back(candidates[i]); n   } n   cout << result.size() << endl; n   for (long long i = 0; i < result.size(); i++) n     cout << ((double)result[i].first) / 2 <<     n          << ((double)result[i].second) / 2 << endl; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int N = 100005, MAX = 202; n struct Leg { n   int len, cost; n   friend bool operator<(const Leg x, const Leg y) { return x.len < y.len; } n }; n Leg l[N]; n int sum[N]; n int c[MAX][N]; n int f[N]; n bool vis[N]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) scanf( %d , &l[i].len); n   for (int i = 0; i < n; ++i) scanf( %d , &l[i].cost); n   sort(l, l + n); n   for (int i = 0; i < n; ++i) { n     ++f[l[i].len]; n     ++c[l[i].cost][l[i].len]; n   } n   for (int i = N - 1; i > 0; --i) { n     f[i] += f[i + 1]; n   } n   for (int i = 1; i < MAX; ++i) { n     for (int j = 1; j < N; ++j) { n       c[i][j] += c[i][j - 1]; n     } n   } n   int ans = INT_MAX; n   for (int i = 0; i < n; ++i) { n     int curLen = l[i].len; n     if (vis[curLen]) continue; n     vis[curLen] = 1; n     int curFreq = f[curLen] - f[curLen + 1]; n     int all = n - f[curLen]; n     int total = 0; n     for (int j = 1; j < MAX; ++j) { n       total += (c[j][N - 1] - c[j][curLen]) * j; n     } n     priority_queue<pair<int, int>> q; n     for (int j = 1; j < MAX; ++j) { n       q.push(make_pair(-j, c[j][curLen - 1])); n     } n     while (!q.empty() && curFreq <= all) { n       int cost = -q.top().first, cnt = q.top().second; n       if (curFreq + cnt > all) { n         total += (all - curFreq + 1) * cost; n         all = curFreq - 1; n         break; n       } n       total += cnt * cost; n       all -= cnt; n       q.pop(); n     } n     ans = min(ans, total); n   } n   printf( %d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1001; n int n, a, b, u; n int sol[N][N]; n void W() { n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       printf( %d , sol[i][j]); n     } n     printf(  n ); n   } n } n int main() { n   cin >> n >> a >> b; n   if (a != 1 && b != 1) { n     cout <<  NO ; n     return 0; n   } n   if (a == 1 && b == 1) { n     if (n == 1) { n       printf( YES n0 ); n       return 0; n     } n     if (n <= 3) { n       cout <<  NO ; n       return 0; n     } n     printf( YES n ); n     for (int i = 1; i < n; i++) { n       sol[i][i + 1] = 1; n       sol[i + 1][i] = 1; n     } n     W(); n     return 0; n   } n   printf( YES n ); n   if (a != 1) n     u = a; n   else n     u = b; n   for (int i = 1; i <= n - u; i++) { n     sol[i][i + 1] = 1; n     sol[i + 1][i] = 1; n   } n   if (a != 1) { n     W(); n     return 0; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       if (i != j) { n         sol[i][j] ^= 1; n       } n     } n   } n   W(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<pair<int, int> > V; n int p[102345]; n int main() { n   int n, m, x, y; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     scanf( %d%d , &x, &y); n     V.insert(make_pair(x, y)); n     V.insert(make_pair(y, x)); n   } n   for (int i = 0; i < n; i++) p[i] = i + 1; n   int tim = 16384; n   bool flag = false; n   while (tim && !flag) { n     random_shuffle(p, p + n); n     p[n] = p[0]; n     int cnt = 0; n     for (int i = 0; i < n; i++) { n       if (!V.count(pair<int, int>(p[i], p[i + 1]))) cnt++; n       if (cnt == m) { n         for (int i = 0; m > 0; i++) { n           if (!V.count(pair<int, int>(p[i], p[i + 1]))) { n             printf( %d %d n , p[i], p[i + 1]); n             m--; n           } n         } n         flag = true; n         break; n       } n     } n     tim--; n   } n   if (!flag) puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   std::ios::sync_with_stdio(false); n   cin.tie(NULL); n   long long n, k; n   cin >> n >> k; n   string s; n   cin >> s; n   s =  0  + s +  0 ; n   for (long long i = 0; i < s.length() - 1; i++) { n     if (k == 0) break; n     if (s[i] ==  4  && s[i + 1] ==  4  && s[i + 2] ==  7  && i % 2) { n       k = k % 2; n       if (k) { n         s[i + 1] =  7 ; n       } n       k = 0; n     } else if (s[i] ==  4  && s[i + 1] ==  7  && s[i + 2] ==  7  && i % 2) { n       k = k % 2; n       if (k) { n         s[i + 1] =  4 ; n       } n       k = 0; n     } else if (s[i] ==  4  && s[i + 1] ==  7  && i % 2) { n       s[i + 1] =  4 ; n       k--; n     } else if (s[i] ==  4  && s[i + 1] ==  7 ) { n       s[i] =  7 ; n       k--; n     } n   } n   cout << s.substr(1, n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long pow(long long b, long long e, long long m) { n   long long t = 1; n   for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0; n   return t; n } n template <class T> n inline bool chkmin(T &a, T b) { n   return a > b ? a = b, true : false; n } n template <class T> n inline bool chkmax(T &a, T b) { n   return a < b ? a = b, true : false; n } n template <class T> n inline T sqr(T x) { n   return x * x; n } n template <typename T> n T gcd(T x, T y) { n   for (T t; x; t = x, x = y % x, y = t) n     ; n   return y; n } n template <class edge> n struct Graph { n   vector<vector<edge> > adj; n   Graph(int n) { n     adj.clear(); n     adj.resize(n + 5); n   } n   Graph() { adj.clear(); } n   void resize(int n) { adj.resize(n + 5); } n   void add(int s, edge e) { adj[s].push_back(e); } n   void del(int s, edge e) { adj[s].erase(find(iter(adj[s]), e)); } n   vector<edge> &operator[](int t) { return adj[t]; } n }; n int main() { n   ios_base::sync_with_stdio(false); n   int n, ans = 0; n   cin >> n; n   stack<int> Q; n   for (int i = 1, v; i <= n; ++i) { n     cin >> v; n     for (; !Q.empty(); Q.pop()) { n       int x = Q.top(); n       chkmax(ans, v ^ x); n       if (x > v) { n         break; n       } n     } n     Q.push(v); n   } n   cout << setprecision(15) << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> a[100010], dp[100010]; n int len[100010]; n int main() { n   int n, m, i, j, k, l, r; n   while (~scanf( %d%d , &n, &m)) { n     for (i = 1; i <= n; i++) { n       a[i].resize(m + 1); n       for (j = 1; j <= m; j++) scanf( %d , &a[i][j]); n     } n     memset(len, 0, sizeof(len)); n     for (i = 1; i <= n; i++) { n       dp[i].resize(m + 1); n       if (i == 1) n         for (j = 1; j <= m; j++) dp[i][j] = 1; n       else n         for (j = 1; j <= m; j++) n           if (a[i][j] >= a[i - 1][j]) n             dp[i][j] = dp[i - 1][j] + 1; n           else n             dp[i][j] = 1; n       for (j = 1; j <= m; j++) len[i] = max(len[i], dp[i][j]); n     } n     scanf( %d , &k); n     while (k--) { n       scanf( %d%d , &l, &r); n       if (len[r] >= r - l + 1) n         printf( Yes n ); n       else n         printf( No n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<char> Set; n pair<int, int> p[181]; n string s, sn; n int i, k, sum; n bool pole[181]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> s; n   cin >> k; n   for (i = 0; i < s.size(); i++) p[s[i] - 96].first++; n   for (i = 1; i <= 26; i++) p[i].second = i; n   sort(p + 1, p + 1 + 26); n   for (i = 1; i <= 26; i++) { n     sum += p[i].first; n     if (k - sum >= 0) n       pole[p[i].second] = true; n     else n       break; n   } n   for (i = 0; i < s.size(); i++) n     if (!pole[s[i] - 96]) { n       Set.insert(s[i]); n       sn += s[i]; n     } n   cout << Set.size() <<   n ; n   cout << sn <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, m, r; n   scanf( %d%d%d , &n, &m, &r); n   if (2 * r <= n && 2 * r <= m) n     puts( First ); n   else n     puts( Second ); n } n


#include <bits/stdc++.h> n using namespace std; n struct edge { n   int v, u, w; n   edge() {} n   edge(int v, int u, int w) : v(v), u(u), w(w) {} n }; n const int N = 2e5 + 7; n vector<pair<int, bool>> g[N]; n vector<pair<int, int>> gg[N]; n vector<edge> glob_ans; n int color[N]; n void init(int n) { n   for (int i = 1; i <= n; i++) { n     g[i].clear(); n     gg[i].clear(); n     color[i] = -1; n   } n   glob_ans.clear(); n } n bool dfs0(int v, int cl) { n   color[v] = cl; n   for (auto [u, c] : g[v]) { n     if (color[u] == -1) { n       if (!dfs0(u, c ^ cl)) return 0; n     } else { n       if (color[u] != (c ^ cl)) return 0; n     } n   } n   return 1; n } n void dfs(int v, int pr = -1) { n   for (auto [u, w] : gg[v]) { n     if (u == pr) continue; n     if (w != -1) { n       assert(__builtin_popcount(w) % 2 == (color[v] ^ color[u])); n       glob_ans.push_back(edge(v, u, w)); n     } else { n       glob_ans.push_back(edge(v, u, color[v] ^ color[u])); n     } n     dfs(u, v); n   } n } n void solve() { n   int n, m; n   cin >> n >> m; n   init(n); n   for (int i = 0; i < n - 1; i++) { n     int x, y, v; n     cin >> x >> y >> v; n     gg[x].push_back({y, v}); n     gg[y].push_back({x, v}); n     if (v != -1) { n       int c = __builtin_popcount(v) % 2; n       g[x].push_back({y, c}); n       g[y].push_back({x, c}); n     } n   } n   for (int i = 0; i < m; i++) { n     int a, b, p; n     cin >> a >> b >> p; n     g[a].push_back({b, p}); n     g[b].push_back({a, p}); n   } n   for (int i = 1; i <= n; i++) { n     if (color[i] == -1) { n       if (!dfs0(i, 0)) { n         cout <<  NO n ; n         return; n       } n     } n   } n   dfs(1); n   cout <<  YES n ; n   for (auto elem : glob_ans) { n     cout << elem.v <<     << elem.u <<     << elem.w <<   n ; n   } n } n signed main() { n   ios_base ::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   for (int i = 0; i < t; i++) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n vector<long long> v(100005); n vector<int> cache(1e5 + 10, -1); n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   map<int, int> mp; n   for (long long i = 0; i < n; i++) { n     int x; n     cin >> x; n     set<int> st; n     for (int k = 2; k * k <= x; k++) { n       if (x % k == 0) { n         st.insert(k); n         while (x % k == 0) { n           x = x / k; n         } n       } n     } n     int mx = 0; n     if (x > 1) { n       st.insert(x); n     } n     for (auto it : st) { n       mp[it]++; n       mx = max(mx, mp[it]); n     } n     for (auto it : st) { n       mp[it] = mx; n     } n   } n   int maxi = 1; n   for (auto it : mp) maxi = max(maxi, it.second); n   cout << maxi <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int a[10], b[10]; n int main() { n   int m, n; n   cin >> m >> n; n   for (int i = 0; i < m; i++) cin >> a[i]; n   for (int j = 0; j < n; j++) cin >> b[j]; n   sort(a, a + m); n   sort(b, b + n); n   int flag = 0, ans; n   for (int i = 0, j = 0; i < m && j < n;) { n     if (a[i] == b[j]) { n       ans = a[i]; n       flag = 1; n       break; n     } else if (a[i] < b[j]) n       i++; n     else if (a[i] > b[j]) n       j++; n   } n   if (flag == 1) { n     cout << ans << endl; n   } else { n     if (a[0] == b[0]) n       cout << a[0] << endl; n     else { n       if (a[0] < b[0]) n         cout << a[0] * 10 + b[0] << endl; n       else n         cout << b[0] * 10 + a[0] << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1005; n int n, m; n char c[maxn][maxn]; n static int dx[] = {-1, 0, 0, 1}; n static int dy[] = {0, -1, 1, 0}; n namespace dsu { n int fa[maxn * maxn]; n int cnt[maxn * maxn]; n int id(int x, int y) { return x * m + y; } n int findfa(int x) { n   if (fa[x] == x) return x; n   return fa[x] = findfa(fa[x]); n } n void unite(int x, int y) { n   x = findfa(x); n   y = findfa(y); n   if (x == y) return; n   if (cnt[x] < cnt[y]) swap(x, y); n   fa[y] = x; n   cnt[x] += cnt[y]; n } n }  // namespace dsu n using namespace dsu; n bool judge(int x, int y) { n   if (x < 0 || y < 0 || x >= n || y >= m) return 0; n   if (c[x][y] ==  * ) return 0; n   return 1; n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       cin >> c[i][j]; n     } n   for (int i = 0; i < n * m; i++) fa[i] = i, cnt[i] = 1; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       if (c[i][j] ==  * ) continue; n       for (int k = 0; k < 4; k++) { n         int _i = i + dx[k]; n         int _j = j + dy[k]; n         if (!judge(_i, _j)) continue; n         int id1 = id(i, j); n         int id2 = id(_i, _j); n         unite(id1, id2); n       } n     } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (c[i][j] !=  * ) { n         cout <<  . ; n         continue; n       } n       set<int> st; n       for (int k = 0; k < 4; k++) { n         int _i = i + dx[k]; n         int _j = j + dy[k]; n         if (!judge(_i, _j)) continue; n         st.insert(findfa(id(_i, _j))); n       } n       int ans = 0; n       while (!st.empty()) { n         int id = *st.begin(); n         st.erase(st.begin()); n         ans += cnt[id]; n       } n       cout << (ans + 1) % 10; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int b, d, ct; n int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } n int main() { n   cin >> b >> d; n   while (gcd(b, d) > 1) { n     d /= gcd(b, d); n     ++ct; n   } n   if (d == 1) n     cout <<  2-type n  << ct <<   n ; n   else if (!ct && b % d == 1) n     cout <<  3-type n ; n   else if (!ct && b % d == d - 1) n     cout <<  11-type n ; n   else if ((b - 1) * (b + 1) / (b % 2 + 1) % d == 0) n     cout <<  6-type n ; n   else n     cout <<  7-type n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, mod, sumz, sumy, sum, last, first, kol, z; n long long run(long long x, long long step) { n   long long res = 1; n   while (step) { n     if (step & 1) res = (res * x) % mod; n     x = x * x % mod; n     step >>= 1; n   } n   return res % mod; n } n int main() { n   cin >> a >> b; n   mod = 1000 * 1000 * 1000 + 7; n   sumz = (a * b) % mod; n   sumz = (sumz * (b - 1)) % mod; n   sumz = (sumz * run(2, mod - 2)) % mod; n   sumy = (a * (a + 1)) % mod; n   sumy = (sumy * b) % mod; n   sumy = (sumy * (b - 1)) % mod; n   sumy = (sumy * run(4, mod - 2)) % mod; n   sum = ((b * sumy) % mod + sumz) % mod; n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int ans = 0; n   int tub[3] = {0}; n   int n, a; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a); n     tub[a % 3]++; n   } n   ans = (tub[0] / 2) + ((tub[1] > tub[2]) ? tub[2] : tub[1]); n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1 << 30; n const double EPS = 1e-7; n int main() { n   ios::sync_with_stdio(false); n   int n; n   cin >> n; n   string s; n   cin >> s; n   int ans = 0; n   for (int i = n; i < (int)s.length(); i += n) { n     bool equal = true; n     for (int j = 1; j <= 3; j++) n       if (s[i - j] != s[i - 1]) equal = false; n     if (equal) ans++; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int din[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; n bool correct(int d, int m, int y) { n   if (d > 31 || m > 12 || y > 99) return false; n   int dc = din[m - 1]; n   if (y % 4 == 0 && m == 2) dc++; n   if (d > dc) return false; n   return true; n } n bool good(int db, int mb, int yb, int df, int mf, int yf) { n   yb += 18; n   if (yb > yf) return false; n   if (yb < yf) return true; n   if (mb > mf) return false; n   if (mb < mf) return true; n   if (db > df) return false; n   return true; n } n int main() { n   int db, mb, yb, df, mf, yf; n   scanf( %d.%d.%d , &df, &mf, &yf); n   scanf( %d.%d.%d , &db, &mb, &yb); n   if (correct(db, mb, yb) && good(db, mb, yb, df, mf, yf)) { n     cout <<  YES ; n     return 0; n   } n   if (correct(db, yb, mb) && good(db, yb, mb, df, mf, yf)) { n     cout <<  YES ; n     return 0; n   } n   if (correct(mb, db, yb) && good(mb, db, yb, df, mf, yf)) { n     cout <<  YES ; n     return 0; n   } n   if (correct(mb, yb, db) && good(mb, yb, db, df, mf, yf)) { n     cout <<  YES ; n     return 0; n   } n   if (correct(yb, db, mb) && good(yb, db, mb, df, mf, yf)) { n     cout <<  YES ; n     return 0; n   } n   if (correct(yb, mb, db) && good(yb, mb, db, df, mf, yf)) { n     cout <<  YES ; n     return 0; n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n constexpr int N = 23; n int n, m, u, v, adj[N], hamsaye[1 << N], ans = N, ans2; n bool connected[1 << N]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   if (2 * m == n * (n - 1)) { n     cout << 0 <<   n ; n     return 0; n   } n   for (int i = 0; i < m; i++) { n     cin >> u >> v; n     u--, v--; n     adj[u] ^= 1 << v; n     adj[v] ^= 1 << u; n   } n   for (int i = 0; i < n; i++) adj[i] ^= (1 << i); n   connected[0] = true; n   for (int mask = 1; mask < (1 << n); mask++) { n     if (__builtin_popcount(mask) == 1) { n       connected[mask] = true; n       continue; n     } n     for (int i = 0; i < n; i++) { n       if ((adj[i] & (mask ^ (1 << i))) && connected[mask ^ (1 << i)]) n         connected[mask] = true; n     } n   } n   for (int mask = 1; mask < (1 << n); mask++) { n     hamsaye[mask] = n         adj[__builtin_ctz(mask)] | hamsaye[mask ^ (1 << __builtin_ctz(mask))]; n     if (connected[mask] && __builtin_popcount(hamsaye[mask]) == n) { n       if (__builtin_popcount(mask) < ans) { n         ans = __builtin_popcount(mask); n         ans2 = mask; n       } n     } n   } n   cout << ans <<   n ; n   for (int i = 0; i < n; i++) n     if (ans2 & (1 << i)) cout << i + 1 <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k; n   cin >> k; n   auto n = 19; n   auto t = 1; n   while (true) { n     auto temp = n; n     auto sum = 0; n     while (temp > 0) { n       auto a = temp % 10; n       temp = temp / 10; n       sum = sum + a; n     } n     if (sum == 10) { n       if (t == k) { n         break; n       } else { n         t++; n       } n     } n     n++; n   } n   cout << n <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int k; n   cin >> k; n   string s, t; n   cin >> s; n   cin >> t; n   int sarr[k]; n   int tarr[k]; n   for (int i = k - 1; i >= 0; i--) { n     sarr[i] = s[i] -  a ; n     tarr[i] = t[i] -  a ; n   } n   int sumarr[k + 1]; n   int carry = 0; n   for (int i = k - 1; i >= 0; i--) { n     sumarr[i + 1] = (sarr[i] + tarr[i] + carry) % 26; n     if (sarr[i] + tarr[i] + carry >= 26) { n       carry = 1; n     } else { n       carry = 0; n     } n   } n   sumarr[0] = carry; n   for (int i = 0; i <= k; i++) { n     if (sumarr[i] % 2 == 1) { n       sumarr[i + 1] += 26; n     } n     sumarr[i] /= 2; n   } n   for (int i = 1; i <= k; i++) { n     cout << (char)(sumarr[i] +  a ); n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x, c = 0; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &x); n     if (!x && !c) n       c = 1; n     else if (c == 1 && !x) n       c = 2; n   } n   if (n == 1) { n     if (x) n       printf( YES n ); n     else n       printf( NO n ); n   } else { n     if (c == 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 int INF = 1e9 + 10; n const long long int INFLL = 1e18 + 10; n const long double EPS = 1e-8; n const long double EPSLD = 1e-14; n const long long int MOD = 1000000007; n template <class T> n T &chmin(T &a, const T &b) { n   return a = min(a, b); n } n template <class T> n T &chmax(T &a, const T &b) { n   return a = max(a, b); n } n const int MAX_N = 256; n int x, n, ip; n long double p; n int a[MAX_N]; n long double dp[2][MAX_N][MAX_N]; n long double dp2[2][MAX_N]; n long double ans; n int main() { n   scanf( %d %d %d , &x, &n, &ip); n   p = (long double)ip / 100.0; n   int nx = x; n   int it = 0; n   while (x > 0) { n     a[it++] = x % 2; n     x /= 2; n   } n   if (nx % 256 == 0) { n     for (int i = (8); i < (int)(MAX_N); i++) { n       if (a[i] == 1) { n         dp2[0][i - 8] = 1.0; n         break; n       } n     } n   } else { n     for (int i = (8); i < (int)(MAX_N); i++) { n       if (a[i] == 0) { n         dp[0][i - 8][nx % 256] = 1.0; n         break; n       } n     } n   } n   for (int i = (0); i < (int)(n); i++) { n     for (int j = (0); j < (int)(MAX_N); j++) n       for (int k = (0); k < (int)(MAX_N); k++) dp[(i + 1) % 2][j][k] = 0.0; n     for (int j = (0); j < (int)(MAX_N); j++) dp2[(i + 1) % 2][j] = 0.0; n     for (int j = (0); j < (int)(MAX_N); j++) n       for (int k = (0); k < (int)(MAX_N); k++) n         if (dp[i % 2][j][k] > EPSLD) { n           int nk = k + 1; n           if (nk == 256) { n             dp2[(i + 1) % 2][j] += dp[i % 2][j][k] * (1.0 - p); n           } else { n             dp[(i + 1) % 2][j][nk] += dp[i % 2][j][k] * (1.0 - p); n           } n           if (k / 128 == 1) { n             if (k % 128 == 0) { n               dp2[(i + 1) % 2][0] += dp[i % 2][j][k] * p; n             } else { n               dp[(i + 1) % 2][j + 1][(k * 2) % 256] += dp[i % 2][j][k] * p; n             } n           } else { n             dp[(i + 1) % 2][0][(k * 2) % 256] += dp[i % 2][j][k] * p; n           } n         } n     for (int j = (0); j < (int)(MAX_N); j++) n       if (dp2[i % 2][j] > EPSLD) { n         dp[(i + 1) % 2][0][1] += dp2[i % 2][j] * (1.0 - p); n         dp2[(i + 1) % 2][j + 1] += dp2[i % 2][j] * p; n       } n   } n   for (int j = (0); j < (int)(MAX_N); j++) n     for (int k = (0); k < (int)(MAX_N); k++) n       if (dp[n % 2][j][k] > EPSLD) { n         int nk = k; n         int res = 0; n         while (nk % 2 == 0) { n           res++; n           nk /= 2; n         } n         ans += dp[n % 2][j][k] * res; n       } n   for (int j = (0); j < (int)(MAX_N); j++) n     if (dp2[n % 2][j] > EPSLD) { n       ans += dp2[n % 2][j] * (8 + j); n     } n   printf( %.18lf n , (double)ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> s; n vector<vector<int> > t; n bool sortFunc(vector<int> a, vector<int> b) { n   if (a.size() == 0) return false; n   if (b.size() == 0) return true; n   return a.size() < b.size(); n } n int main() { n   cin.sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   s.resize(n + 1); n   for (int i = 1; i <= n; i++) cin >> s[i]; n   vector<bool> was(n + 1, false); n   int index = 0; n   t.push_back(vector<int>()); n   for (int i = 1; i <= n; i++) { n     if (was[i]) continue; n     int ind = i; n     while (!was[ind]) { n       was[ind] = true; n       t[index].push_back(ind); n       ind = s[ind]; n     } n     t.push_back(vector<int>()); n     index++; n   } n   vector<int> sol(n + 1); n   sort(t.begin(), t.end(), sortFunc); n   bool poss = true; n   for (int i = 0; i < index; i++) { n     vector<int> real; n     if (t[i].size() % 2 == 1) { n       real.resize(t[i].size()); n       for (int j = 0; j < t[i].size() / 2; j++) { n         real[j * 2] = t[i][j]; n         int b = t[i].size() / 2 + 1 + j; n         real[j * 2 + 1] = t[i][b]; n       } n       int b = t[i].size() / 2; n       real[t[i].size() - 1] = t[i][b]; n     } else if (t[i + 1].size() == t[i].size()) { n       real.resize(2 * t[i].size()); n       for (int j = 0; j < t[i].size(); j++) { n         real[2 * j] = t[i][j]; n         real[2 * j + 1] = t[i + 1][j]; n       } n       i++; n     } else n       poss = false; n     for (int j = 0; j < real.size(); j++) { n       sol[real[j]] = real[(j + 1) % real.size()]; n     } n   } n   if (poss) { n     for (int i = 1; i <= n; i++) { n       cout << sol[i] <<    ; n     } n     cout <<   n ; n   } else { n     cout <<  -1 n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int digSum(long long int n) { n   long long int sum = 0; n   while (n != 0) { n     sum += n % 10; n     n = n / 10; n   } n   return sum; n } n bool cmp1(int a, int b) { return a < b; } n bool cmp2(int a, int b) { return a > b; } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int n, k, sum2 = 0, sum1 = 0, x; n   cin >> n >> k; n   vector<int> v(n), ans; n   for (int(i) = 0; (i) < (n); (i)++) { n     cin >> v[i]; n     sum1 += v[i]; n   } n   x = sum1 / k; n   bool ok = true; n   if (sum1 % k == 0) { n     int i = 0; n     while (i < n) { n       long long int sum2 = 0; n       long long int ct = 0; n       while (i < n && sum2 < x) { n         sum2 += v[i]; n         i++; n         ct++; n       } n       if (sum2 == x) { n         ans.push_back(ct); n       } else { n         ok = false; n         break; n       } n     } n     if (ok) { n       cout <<  Yes ; n       cout << endl; n       for (int i = 0; i < ans.size(); i++) { n         cout << ans[i] <<    ; n       } n     } else { n       cout <<  No ; n       cout << endl; n     } n   } else { n     cout <<  No ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int p, n; n vector<int> gra[100010]; n double dp[100010], sz[100010]; n void dfs(int u) { n   sz[u] = 1; n   int m = gra[u].size(); n   for (int i = 0; i <= m - 1; i++) { n     dfs(gra[u][i]); n     sz[u] += sz[gra[u][i]]; n   } n } n void solve(int u) { n   int m = gra[u].size(); n   for (int i = 0; i <= m - 1; i++) { n     dp[gra[u][i]] = dp[u] + 1 + (sz[u] - sz[gra[u][i]] - 1) / 2.0; n     solve(gra[u][i]); n   } n } n int main() { n   dp[1] = 1; n   scanf( %d , &n); n   for (int i = 2; i <= n; i++) { n     scanf( %d , &p); n     gra[p].push_back(i); n   } n   dfs(1); n   solve(1); n   for (int i = 1; i <= n; i++) printf( %.6f  , dp[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, T, low, mid, high, a[200005], t[200005]; n   vector<int> ans; n   scanf( %d%d , &n, &T); n   for (int i = 1; i <= n; i++) { n     scanf( %d%d , &a[i], &t[i]); n   } n   low = 0; n   high = n; n   while (low <= high) { n     mid = (low + high) / 2; n     vector<pair<int, int> > v; n     int cnt = 0, tot_t = 0, idx = -1; n     for (int i = 1; i <= n; i++) { n       if (a[i] >= mid) v.push_back(make_pair(t[i], i)); n     } n     sort(v.begin(), v.end()); n     for (int i = 0; i < v.size(); i++) { n       if (tot_t + v[i].first > T) break; n       cnt++; n       tot_t += v[i].first; n       if (cnt == mid) { n         idx = i; n         break; n       } n     } n     if (cnt >= mid) { n       ans.clear(); n       for (int i = 0; i <= idx; i++) ans.push_back(v[i].second); n       low = mid + 1; n     } else { n       high = mid - 1; n     } n   } n   printf( %d n%d n , ans.size(), ans.size()); n   for (int i = 0; i < ans.size(); i++) printf( %d  , ans[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target(   n      avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n long long MOD = 998244353; n long long INF = 1e18; n const int N = 100001; n long long dp[N][101]; n long long sm[N]; n long long cnt[N][101]; n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), n       cout << fixed << setprecision(20); n   long long n, k, len; n   cin >> n >> k >> len; n   if (len == 1) { n     cout << 0; n     return 0; n   } n   vector<long long> a(n + 1); n   sm[0] = 1; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     for (int j = 1; j <= k; j++) { n       cnt[i][j] = cnt[i - 1][j] + (a[i] == -1 || a[i] == j); n       if (a[i] != -1 && j != a[i]) { n         cnt[i][j] = 0; n       } n     } n     if (a[i] != -1) { n       dp[i][a[i]] += sm[i - 1]; n       if (cnt[i][a[i]] >= len) dp[i][a[i]] -= sm[i - len] - dp[i - len][a[i]]; n     } else { n       for (int j = 1; j <= k; j++) { n         dp[i][j] += sm[i - 1]; n         if (cnt[i][j] >= len) dp[i][j] -= sm[i - len] - dp[i - len][j]; n       } n     } n     for (int j = 1; j <= k; j++) { n       dp[i][j] %= MOD; n       dp[i][j] += MOD; n       dp[i][j] %= MOD; n       sm[i] += dp[i][j]; n       sm[i] %= MOD; n     } n   } n   cout << sm[n]; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 100005; n int n; n int m; n int cnt[MAX_N]; n int a[MAX_N]; n int main() { n   scanf( %d %d , &m, &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   int diff = 0; n   for (int i = 1; i <= n; i++) { n     cnt[a[i]]++; n     if (cnt[a[i]] == 1) { n       diff++; n     } n     if (diff == m) { n       cout << 1; n       for (int j = 1; j <= m; j++) { n         cnt[j]--; n         if (cnt[j] == 0) { n           diff--; n         } n       } n     } else { n       cout << 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC n        <<  ms n ; n   long long t; n   cin >> t; n   while (t--) { n     long long n, g = 0, s = 0, b = 0, i, gidx, bidx, cidx; n     cin >> n; n     int flag = 0; n     long long p[n]; n     for (i = 0; i < n; i++) { n       cin >> p[i]; n     } n     long long m = n / 2; n     cidx = m; n     cidx--; n     while (p[cidx + 1] == p[cidx]) { n       cidx--; n       if (cidx < 4) { n         cout <<  0 0 0  n              <<   n ; n         flag = 1; n         break; n       } n     } n     if (flag) continue; n     gidx = 1; n     while (p[gidx] == p[gidx - 1]) { n       gidx++; n       if (gidx >= cidx) { n         cout <<  0 0 0  n              <<   n ; n         flag = 1; n         break; n       } n     } n     if (flag) continue; n     bidx = 2 * gidx + 1; n     while (p[bidx] == p[bidx - 1]) { n       bidx++; n       if (bidx >= cidx) { n         cout <<  0 0 0  n              <<   n ; n         flag = 1; n         break; n       } n     } n     if (flag) continue; n     g = gidx; n     b = bidx - gidx; n     s = cidx - bidx + 1; n     if (g == 0 || b == 0 || s <= 0 || g >= s) n       cout <<  0 0 0  n            <<   n ; n     else n       cout << g <<     << b <<     << s <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> graph[2001]; n vector<int> level[2001]; n int visited[2001]; n int a, b; n void dfs(int u, int depth) { n   visited[u] = 1; n   level[depth].push_back(u); n   for (int v : graph[u]) { n     if (!visited[v]) { n       dfs(v, depth + 1); n     } n   } n } n int query = 0; n void ask(vector<int>& v) { n   cout <<  ?   << v.size() <<    ; n   for (int x : v) { n     cout << x <<    ; n   } n   cout <<   n  << flush; n   cin >> a >> b; n } n void bs(int l, int r, int ref) { n   int curr_node = 0, curr_level = 0; n   while (l <= r) { n     if (r - l <= 1) { n       ask(level[r]); n       if (b == ref) { n         curr_level = r; n         curr_node = a; n       } else { n         ask(level[l]); n         curr_node = a; n         curr_level = l; n       } n       break; n     } n     int mid = (l + r) / 2; n     ask(level[mid]); n     if (b == ref) { n       l = mid; n     } else { n       r = mid - 1; n     } n   } n   for (int i = 0; i <= 2000; i++) { n     visited[i] = 0; n     level[i].clear(); n   } n   dfs(curr_node, 1); n   ask(level[ref + 1]); n   cout <<  !   << curr_node <<     << a <<   n  << flush; n   string s; n   cin >> s; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     query = 0; n     int n, x, y; n     cin >> n; n     for (int i = 0; i <= 2000; i++) { n       graph[i].clear(); n       level[i].clear(); n       visited[i] = 0; n     } n     for (int i = 0; i < n - 1; i++) { n       cin >> x >> y; n       graph[x].push_back(y); n       graph[y].push_back(x); n     } n     cout <<  ?   << n <<    ; n     for (int i = 1; i <= n; i++) { n       cout << i <<    ; n     } n     cout <<   n  << flush; n     cin >> x >> y; n     dfs(x, 1); n     int len = 0; n     for (int i = n; i >= 1; i--) { n       if (level[i].size() != 0) { n         len = i; n         break; n       } n     } n     bs(1, len, y); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxiz = 1000 * 1000 + 100; n int d[maxiz]; n int main() { n   int n; n   long long A, M = 0; n   cin >> n >> A; n   for (int i = 0; i < n; i++) { n     cin >> d[i]; n     M = (M + d[i] * 1ll) * 1ll; n   } n   for (int i = 0; i < n; i++) { n     long long maxi, mini; n     if (A - M + d[i] > 1) n       mini = A - (M - d[i]); n     else n       mini = 1; n     if (d[i] < A - n + 1) n       maxi = d[i]; n     else n       maxi = A - n + 1; n     cout << d[i] - (maxi - mini + 1) <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int f[20001][101]; n struct node { n   int ai, bi; n } a[1001]; n bool cmp(node x, node y) { return x.bi > y.bi; } n int main() { n   int n, sum1 = 0, sum2 = 0, d = 0; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i].ai); n     sum1 += a[i].ai; n   } n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i].bi); n   } n   sort(a + 1, a + n + 1, cmp); n   while (sum1 > sum2) sum2 += a[++d].bi; n   printf( %d  , d); n   memset(f, 128, sizeof(f)); n   f[0][0] = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = sum2; j >= a[i].bi; j--) { n       for (int k = 1; k <= d; k++) { n         f[j][k] = max(f[j][k], f[j - a[i].bi][k - 1] + a[i].ai); n       } n     } n   } n   int ans = 0; n   for (int i = sum1; i <= sum2; i++) { n     ans = max(ans, f[i][d]); n   } n   printf( %d n , sum1 - ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 110; n const int M = 10010; n int n, m; n char mat[N][M]; n int dir[2] = {-1, 1}; n long long solve() { n   long long ans = 0; n   int x = 0, y = 0, d = 1; n   bool isLeft = true, isRight = true; n   int pos[2] = {0, 0}; n   while (true) { n     if (!isLeft && !isRight) return -1; n     if (x == n - 1) return ans; n     if (mat[x + 1][y] ==  . ) { n       ans++; n       x++; n       isLeft = isRight = true; n       pos[0] = pos[1] = y; n     } else if (y == pos[d]) { n       int ty = y + dir[d]; n       ans++; n       if (ty < 0 || ty >= m || mat[x][ty] ==  # ) { n         if (d == 0) n           isLeft = false; n         else n           isRight = false; n         d ^= 1; n       } else { n         pos[d] += dir[d]; n         if (mat[x][ty] ==  . ) n           y += dir[d]; n         else n           d ^= 1; n       } n     } else { n       ans += (long long)abs((long long)pos[d] - (long long)y); n       y = pos[d]; n     } n   } n   return -1; n } n int main() { n   while (scanf( %d%d%*c , &n, &m) != EOF) { n     for (int i = 0; i < n; i++) gets(mat[i]); n     long long ans = solve(); n     if (ans == -1) n       puts( Never ); n     else n       cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t[1000005], r = 1000004; n int dp[1000005]; n int main() { n   memset(dp, 0, sizeof(dp)); n   memset(t, 0, sizeof(t)); n   int n, ans = 0, x; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x; n     cin >> t[x]; n   } n   dp[0] = 0; n   if (t[0] != 0) dp[0] = 1; n   for (int i = 1; i <= r; i++) { n     if (!t[i]) n       dp[i] = dp[i - 1]; n     else { n       if (t[i] >= i) n         dp[i] = 1; n       else n         dp[i] = dp[i - t[i] - 1] + 1; n     } n     ans = max(ans, dp[i]); n   } n   cout << n - ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int N = 2e5 + 5; n int n, q; n ll a[N], tree[N << 2], lz[N << 2]; n void push(int node, int s, int e) { n   tree[node] += lz[node]; n   if (s != e) { n     lz[node << 1] += lz[node]; n     lz[node << 1 | 1] += lz[node]; n   } n   lz[node] = 0; n } n void upd(int node, int s, int e, int l, int r, ll v) { n   push(node, s, e); n   if (r < s || e < l || l > r) return; n   if (l <= s && e <= r) { n     lz[node] += v; n     push(node, s, e); n     return; n   } n   int md = (s + e) >> 1; n   upd(node << 1, s, md, l, r, v); n   upd(node << 1 | 1, md + 1, e, l, r, v); n   tree[node] = max(tree[node << 1], tree[node << 1 | 1]); n } n int get(int node, int s, int e) { n   push(node, s, e); n   if (tree[node] < 0) return -1; n   if (s == e) return tree[node] != 0 ? -1 : s + 1; n   int md = (s + e) >> 1; n   int x = get(node << 1, s, md); n   if (~x) return x; n   return get(node << 1 | 1, md + 1, e); n } n int main() { n   scanf( %d%d , &n, &q); n   for (int i = 0; i < n; i++) { n     scanf( %lld , a + i); n     upd(1, 0, n - 1, i, i, a[i]); n     upd(1, 0, n - 1, i + 1, n - 1, -a[i]); n   } n   while (q--) { n     int x, v; n     scanf( %d%d , &x, &v); n     upd(1, 0, n - 1, x - 1, x - 1, -a[x - 1] + v); n     upd(1, 0, n - 1, x, n - 1, a[x - 1] - v); n     a[x - 1] = v; n     printf( %d n , get(1, 0, n - 1)); n   } n   return 0; n } n


#include <bits/stdc++.h> n const double pi = acos(-1.0), eps = 1e-9; n const int dx[8] = {1, -1, 0, 0, 1, 1, -1, -1}; n const int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1}; n const int MO = (int)(1e9 + 7); n using namespace std; n int main() { n   long long n; n   cin >> n; n   while (n % 3 == 0) n /= 3; n   cout << n / 3 + 1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void fileio() {} n vector<vector<long long int>> g; n long long int cube_root(long long int x) { n   long long int lo = 0, hi = 1e6 + 10; n   while (lo <= hi) { n     long long int m = (lo + hi) / 2; n     long long int val = m * m * m; n     if (val == x) return m; n     if (val > x) { n       hi = m - 1; n     } else { n       lo = m + 1; n     } n   } n   return -1; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   fileio(); n   long long int t; n   cin >> t; n   while (t-- > 0) { n     long long int a, b; n     cin >> a >> b; n     long long int x = a * b; n     long long int c = cube_root(x); n     if (c == -1) { n       cout <<  NO ; n       cout <<   n ; n       continue; n     } n     if (a % c != 0 or b % c != 0) { n       cout <<  NO ; n       cout <<   n ; n       continue; n     } n     cout <<  YES ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int vis[51]; n int main() { n   string s; n   int n, len; n   cin >> len >> n; n   cin >> s; n   while (n--) { n     for (int i = 0; i <= len; i++) { n       if (s[i] ==  B  && s[i + 1] ==  G ) { n         swap(s[i], s[i + 1]); n         i++; n       } n     } n   } n   cout << s << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int N; n   cin >> N; n   int a[10000], b[10000]; n   for (int n = 0; n < N; n++) { n     cout <<  ?   << 0 <<     << n << endl; n     cin >> a[n]; n   } n   for (int n = 0; n < N; n++) { n     cout <<  ?   << n <<     << 0 << endl; n     cin >> b[n]; n   } n   int nm = 0, fa = 0; n   int ac[10000], bc[10000]; n   for (int n = 0; n < N; n++) { n     for (int x = 0; x < N; x++) { n       ac[x] = a[x] ^ n; n     } n     for (int x = 0; x < N; x++) { n       bc[x] = b[x] ^ ac[0]; n     } n     bool p = true; n     for (int x = 0; x < N; x++) { n       if (ac[bc[x]] != x) { n         p = false; n       } n     } n     if (p) { n       fa = n; n       nm++; n     } n   } n   cout <<  !  << endl; n   cout << nm << endl; n   fa = fa ^ a[0]; n   for (int x = 0; x < N; x++) { n     if (x) cout <<    ; n     cout << (fa ^ b[x]); n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ans1 = 0, ans2 = 0; n int main(void) { n   int t, i, j; n   cin >> t; n   while (t--) { n     int n, mx = INT_MIN, ans = 0, sz; n     cin >> n; n     int a[n]; n     set<int> s; n     for (i = 0; i < n; i++) { n       cin >> a[i]; n       mx = max(mx, a[i]); n       s.insert(a[i]); n     } n     for (i = 12; i >= 0; i--) { n       if (((1 << i) & mx) != 0) break; n     } n     mx = (1 << (i + 1)); n     for (i = 1; i <= mx; i++) { n       map<int, int> mp; n       sz = 0; n       for (j = 0; j < n; j++) { n         if ((s.count(a[j] ^ i) > 0) && (mp[a[j] ^ i] == 0)) { n           sz++; n           mp[a[j] ^ i]++; n         } n       } n       if (sz == s.size()) ans = 1; n       if (ans == 1) break; n     } n     if (ans == 0) n       cout << -1 << endl; n     else n       cout << i << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, a, b; n   scanf( %d%d , &n, &k); n   printf( %d , n); n   for (int i = n - 1; i > k; --i) printf(  %d , i); n   a = 1, b = k; n   while (a < b) printf(  %d %d , a++, b--); n   if (a == b) printf(  %d , a); n   puts(  ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, m, c; n   cin >> n >> m >> c; n   int a[n], b[m]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < m; i++) cin >> b[i]; n   for (int i = 0; i < n - m + 1; i++) { n     int k = i; n     for (int j = 0; j < m; j++) { n       a[k] += b[j]; n       a[k] = a[k] % c; n       k++; n     } n   } n   for (int i = 0; i < n; i++) cout << a[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, c, l, tl, ans, ca, cb, cc; n long long min(long long a, long long b) { return a < b ? a : b; } n void cpy() { n   a = ca, b = cb; n   c = cc; n } n int main() { n   scanf( %lld%lld%lld%lld , &a, &b, &c, &l); n   ca = a; n   cb = b; n   cc = c; n   for (int i = l + 2; i >= 2; --i) ans += 1ll * i * (1ll * i - 1) / 2; n   if (b + c - a <= l) { n     if (a > b + c) n       tl = l; n     else n       tl = l - (b + c - a), a = b + c; n     for (int i = 0; i <= tl; ++i) { n       long long tb = min(a - b - c + 1ll * i, tl - 1ll * i); n       ans -= (tb + 1) * (tb + 2) / 2; n     } n   } n   cpy(); n   if (a + b - c <= l) { n     if (c > a + b) n       tl = l; n     else n       tl = l - (a + b - c), c = a + b; n     for (int i = 0; i <= tl; ++i) { n       long long tb = min(c - a - b + i * 1ll, tl - i * 1ll); n       ans -= (tb + 1) * (tb + 2) / 2; n     } n   } n   cpy(); n   if (a + c - b <= l) { n     if (b > a + c) n       tl = l; n     else n       tl = l - (a + c - b), b = a + c; n     for (int i = 0; i <= tl; ++i) { n       long long tb = min(b - a - c + i * 1ll, tl - i * 1ll); n       ans -= (tb + 1) * (tb + 2) / 2; n     } n   } n   printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string a, b; n bool func(string s, long n) { n   if (s.size() % n) return false; n   for (long i = 0; i < s.size(); i++) n     if (s[i] != a[i % n]) return 0; n   return 1; n } n int main() { n   cin >> a >> b; n   long ans = 0, i = 1; n   string p = a, q = b; n   long minx = min(a.size(), b.size()); n   while (i <= minx) { n     ans += (func(p, i) && func(q, i)); n     i++; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma warning(disable : 4996) n const double PI = acos(-1); n const long long N = 500005, md = 1e9 + 7, inf = 1e18, iinf = 1e9 + 5, MX = 3e5; n long long g, w, h, x, y, z, i, j, k, q, n, cnt, res, sum, r[N], a[N], b[N]; n char c[N]; n string s, t; n pair<int, int> p[N]; n vector<int> e[N]; n int main() { n   ios::sync_with_stdio(false), cin.tie(0); n   cin >> n >> k; n   if (k == 2 && (n < 3 || n == 4)) n     cout <<  NO ; n   else if (k == 3 && (n < 6 || n == 8)) n     cout <<  NO ; n   else { n     if (n < k * (k + 1) / 2) cout <<  NO , exit(0); n     cout <<  YES n ; n     x = (n - k * (k + 1) / 2) / k; n     for (long long i = 0; i < k; i++) a[i] = i + 1 + x, sum += a[i]; n     while (sum < n) { n       for (long long i = k - 1; i >= 0; i--) { n         if (a[i] + 1 > a[i - 1] * 2) i = k - 1; n         if (sum == n) break; n         if (sum < n) sum++, a[i]++; n       } n     } n     for (long long i = 0; i < k; i++) cout << a[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool ask(int val) { n   cout <<  ?   << val + 1 << endl; n   string resp; n   cin >> resp; n   return resp[0] ==  Y  ? true : false; n } n void fix() { cout <<  R  << endl; } n int main() { n   int n, k; n   cin >> n >> k; n   vector<bool> check(n + 1, 0); n   int block = k % 2 ? 1 : k / 2; n   for (int blockno = 1; blockno < n / block; blockno += 1) { n     for (int j = 0; j < blockno && (blockno + j < n / block); j += 1) { n       for (int k = j; k < n / block; k += blockno) { n         for (int a = 0; a < block; a += 1) { n           if (ask(k * block + a)) { n             check[k * block + a + 1] = true; n           } n         } n       } n       fix(); n     } n   } n   int res = 0; n   for (int i = 1; i <= n; i += 1) { n     if (check[i] == 0) { n       res += 1; n     } n   } n   cout <<  !   << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int _ = 1, tc = 1; n int dx[] = {0, 0, 1, -1}; n int dy[] = {1, -1, 0, 0}; n const int MAXN = 1e7 + 1; n int spf[MAXN]; n int d, x, y; n void sieve() { n   for (int i = 1; i < MAXN; i++) spf[i] = i; n   for (int i = 4; i < MAXN; i += 2) spf[i] = 2; n   for (int i = 3; i * i < MAXN; i += 2) { n     if (spf[i] == i) { n       for (int j = i * i; j < MAXN; j += i) { n         if (spf[j] == j) spf[j] = i; n       } n     } n   } n } n void extended_gcd(int a, int b) { n   if (b == 0) { n     d = a; n     x = 1; n     y = 0; n   } else { n     extended_gcd(b, a % b); n     int temp = y; n     y = x - y * (a / b); n     x = temp; n   } n } n int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } n int lcm(int a, int b) { return a * (b / gcd(a, b)); } n int getmod(int x, int y, int mod) { return (((x - y) % mod) + mod) % mod; } n vector<string> split(string line, char dil) { n   vector<string> tokens; n   stringstream check1(line); n   string intermediate; n   while (getline(check1, intermediate, dil)) { n     tokens.push_back(intermediate); n   } n   return tokens; n } n void read(vector<long long>& v) { n   for (int i = 0; i < v.size(); i++) cin >> v[i]; n } n long long calc(long long curr, long long cuts) { n   int p2 = curr % cuts; n   int p1 = cuts - p2; n   long long w = curr / cuts; n   long long val = p1 * w * w + p2 * (w + 1) * (w + 1); n   return val; n } n void solve() { n   int n, k; n   cin >> n >> k; n   vector<long long> v(n); n   read(v); n   priority_queue<pair<long long, pair<long long, long long> > > q; n   long long time = 0; n   for (int i = 0; i < n; i++) { n     long long curr = v[i]; n     time += curr * curr; n     q.push(make_pair(calc(curr, 1) - calc(curr, 2), make_pair(curr, 2))); n   } n   while (n < k) { n     pair<long long, pair<long long, long long> > curr = q.top(); n     q.pop(); n     long long dec = curr.first; n     long long past = curr.second.second; n     long long org = curr.second.first; n     q.push(make_pair(calc(org, past) - calc(org, past + 1), n                      make_pair(org, past + 1))); n     n++; n     time -= dec; n   } n   cout << time << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   while (_--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n const int MAXN = 1000; n int n; n char s[MAXN + 1]; n int solve() { n   int ret = n; n   for (int i = (0); i < (n); ++i) n     if (s[i] ==  1  || s[n - i - 1] ==  1 ) ret = max(ret, 2 * (n - i)); n   return ret; n } n void run() { n   scanf( %d , &n); n   scanf( %s , s); n   assert(strlen(s) == n); n   printf( %d n , solve()); n } n int main() { n   int ncase; n   scanf( %d , &ncase); n   for (int i = (1); i <= (ncase); ++i) run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long const mod = 1000000007; n long long const md = 998244353; n long long mypow(long long a, long long b) { n   long long res = 1; n   a %= mod; n   assert(b >= 0); n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n ifstream in( txt.in ); n ofstream out( txt.out ); n int f[105]; n int main() { n   cout << fixed << setprecision(12); n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   cout.tie(0); n   long long n, x, y; n   cin >> n >> x >> y; n   for (int i = 1; i <= n; ++i) { n     cin >> f[i]; n   } n   sort(f + 1, f + n + 1); n   if (x > y) return cout << n, 0; n   int u = 0; n   for (int i = 1; i <= n; ++i) { n     if (x >= f[i]) u = i; n   } n   cout << (u + 1) / 2 <<   n ; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int M = 1e9 + 7; n int INF = 1e6; n long long int n, m; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long int i, j, t, k, x, y, z, N; n   cin >> n; n   long long int a[n], b[n], c[n]; n   for (i = 0; i < n; i++) cin >> a[i]; n   for (i = 0; i < n; i++) cin >> b[i]; n   for (i = 0; i < n; i++) cin >> c[i]; n   long long int dp[n][2]; n   memset(dp, 0, sizeof(dp)); n   ; n   dp[n - 1][0] = a[n - 1]; n   dp[n - 1][1] = b[n - 1]; n   for (i = n - 2; i >= 0; i--) { n     dp[i][0] = max(dp[i + 1][0] + b[i], dp[i + 1][1] + a[i]); n     dp[i][1] = max(dp[i + 1][0] + c[i], dp[i + 1][1] + b[i]); n   } n   cout << dp[0][0]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int arr[1000010]; n char ch[1000010]; n map<int, int> mp, mp1; n vector<int> vec(1000010); n int main() { n   int i, j, k, n, m, t, p, cas = 1; n   memset(arr, 0, sizeof arr); n   vec.clear(); n   mp.clear(); n   mp1.clear(); n   int cnt = 0, l = 0, r = 0; n   stack<int> st; n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     scanf( %d , &arr[i]); n     mp[arr[i]] = i + 1; n   } n   getchar(); n   scanf( %s , &ch); n   sort(arr, arr + n); n   int len = strlen(ch); n   for (i = 0; i < len; i++) { n     if (ch[i] ==  0 ) { n       cnt++; n       st.push(cnt - 1); n       vec.push_back(mp[arr[cnt - 1]]); n     } else { n       int n1 = st.top(); n       st.pop(); n       vec.push_back(mp[arr[n1]]); n     } n   } n   for (i = 0; i < vec.size(); i++) { n     if (i == 0) n       printf( %d , vec[i]); n     else n       printf(  %d , vec[i]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, flag = 0; n     cin >> n; n     vector<int> v(n); n     for (int i = 0; i < n; i++) { n       cin >> v[i]; n     } n     sort(v.begin(), v.end()); n     if (v[0] == 0) { n       vector<int> v1(n); n       for (int k = 1; k < 2000; k++) { n         for (int i = 0; i < n; i++) { n           v1[i] = (v[i] ^ k); n         } n         sort(v1.begin(), v1.end()); n         if (v1 == v) { n           cout << k << endl; n           flag++; n           break; n         } n       } n     } else { n       vector<int> v1(n); n       for (int k = 1; k < 2000; k++) { n         for (int i = 0; i < n; i++) { n           v1[i] = (v[i] ^ k); n         } n         sort(v1.begin(), v1.end()); n         if (v1 == v) { n           cout << k << endl; n           flag++; n           break; n         } n       } n     } n     if (flag == 0) { n       cout <<  -1  << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n, m, a, b, count = 0; n   ; n   cin >> n >> m; n   while (cin >> a >> b) { n     if (a == 1 || b == 1) { n       count++; n     } n   } n   cout << count; n } n signed main() { n   long long test = 1; n   while (test--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, c = 0; n   cin >> n; n   bool* V = new bool[n]; n   bool Back = false; n   for (int i = 0; i < n; ++i) { n     cin >> V[i]; n     if (V[i]) { n       if (Back && c) c++; n       c++; n       Back = false; n     } else { n       Back = true; n     } n   } n   cout << c << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct pt { n   long long x, y; n   pt operator-(pt b) const { return {x - b.x, y - b.y}; } n   bool operator==(pt b) const { return x == b.x && y == b.y; } n   bool operator<(pt b) const { n     if (x != b.x) return x < b.x; n     return y < b.y; n   } n }; n long long det(pt a, pt b, pt c) { n   return a.x * b.y + b.x * c.y + c.x * a.y - a.y * b.x - b.y * c.x - c.y * a.x; n } n long long sq(long long x) { return x * x; } n long long d2(pt a, pt b) { return sq(a.x - b.x) + sq(a.y - b.y); } n long long sp(pt a, pt b) { return a.x * b.x + a.y * b.y; } n bool kolin(pt a, pt b, pt c) { n   if (det(a, b, c) != 0) return false; n   return b == a || b == c || sp(a - b, b - c) > 0; n } n long long sgn(long long x) { n   if (x < 0) n     return -1; n   else if (x == 0) n     return 0; n   else n     return 1; n } n bool sek(pt a, pt b, pt c, pt d) { n   return sgn(det(a, b, c)) * sgn(det(a, b, d)) == -1 && n          sgn(det(c, d, a)) * sgn(det(c, d, b)) == -1; n } n bool pip(pt b, pt* a, int n) { n   long double w = 0; n   for (int i = 0; i < n; i++) { n     int j = (i + 1) % n; n     long double arg = sp(b - a[i], b - a[j]); n     arg /= sqrt(d2(b, a[i])); n     arg /= sqrt(d2(b, a[j])); n     arg = max(arg, (long double)-1); n     arg = min(arg, (long double)1); n     if (det(b, a[i], a[j]) < 0) n       w += acos(arg); n     else n       w -= acos(arg); n   } n   return abs(w) > 1.5; n } n long long area(pt* a, int n) { n   long long s = 0; n   for (int i = 1; i < n - 1; i++) s += det(a[0], a[i], a[i + 1]); n   return s; n } n basic_string<pt> hull_half(basic_string<pt> a) { n   basic_string<pt> b; n   for (pt p : a) { n     while (b.size() >= 2 && det(b[b.size() - 2], b[b.size() - 1], p) <= 0) n       b.pop_back(); n     b += p; n   } n   return b; n } n basic_string<pt> hull(basic_string<pt> a) { n   sort(a.begin(), a.end()); n   a.erase(unique(a.begin(), a.end()), a.end()); n   auto p = hull_half(a); n   p.pop_back(); n   reverse(a.begin(), a.end()); n   auto q = hull_half(a); n   q.pop_back(); n   return p + q; n } n const long long H = 100000; n basic_string<pt> find_pts(long long x, long long y, long long r) { n   basic_string<pt> z; n   if (x - r >= 0) { n     z += {x - r, y}; n   } else { n     long long u = y - abs(x - r); n     long long v = y + abs(x - r); n     u = max(u, 0ll); n     v = min(v, H); n     z += pt{0, u}; n     z += pt{0, v}; n   } n   if (x + r <= H) { n     z += {x + r, y}; n   } else { n     long long u = y - abs(x + r - H); n     long long v = y + abs(x + r - H); n     u = max(u, 0ll); n     v = min(v, H); n     z += pt{H, u}; n     z += pt{H, v}; n   } n   if (y - r >= 0) { n     z += {x, y - r}; n   } else { n     long long u = x - abs(y - r); n     long long v = x + abs(y - r); n     u = max(u, 0ll); n     v = min(v, H); n     z += pt{u, 0}; n     z += pt{v, 0}; n   } n   if (y + r <= H) { n     z += {x, y + r}; n   } else { n     long long u = x - abs(y + r - H); n     long long v = x + abs(y + r - H); n     u = max(u, 0ll); n     v = min(v, H); n     z += pt{u, H}; n     z += pt{v, H}; n   } n   return z; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   cerr.tie(nullptr); n   long long n; n   cin >> n; n   basic_string<pt> b; n   while (n--) { n     long long x, y, v; n     cin >> x >> y >> v; n     b += find_pts(x, y, v); n   } n   b = hull(b); n   b += b.substr(0, 2); n   long double sol = 0; n   basic_string<pt> zz; n   for (int i = 0; i + 2 < (int)b.size(); i++) { n     long double A = sqrt((long double)d2(b[i + 0], b[i + 1])); n     long double B = sqrt((long double)d2(b[i + 1], b[i + 2])); n     long double C = sqrt((long double)d2(b[i + 2], b[i + 0])); n     long double H = abs(det(b[i], b[i + 1], b[i + 2])); n     long double R = A * B * C / H; n     if (R > sol) { n       sol = R; n       zz = b.substr(i, 3); n     } n   } n   for (int i = 0; i < 3; i++) cout << zz[i].x <<     << zz[i].y <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, n     p = 0, q = 0, r, s, t, u, v, w, x, y, z, temp = 0, ans = 0, t1, t2, sum = 0; n vector<long long int> v1, v2, v3, v4, v5, v6; n vector<string> vs1, vs2, vs3, vs4; n double f1, f2 = 0, f3, f4; n vector<double> v10; n vector<pair<long long int, long long int>> v11, v12, v13, v14; n string s1, s2, s3, s4, s5, s6; n long long int a10[100][3]; n long long int a1[1000000], a2[1000000]; n char c1, c2, c3; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (i = 0; i < n; i++) { n     p = 0; n     cin >> g >> h; n     while (g != 0) { n       if (g % h == 0) { n         g = g / h; n         p++; n       } else { n         p = p + g % h; n         g = g - g % h; n       } n     } n     cout << p << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool vis[1000][1000]; n bool lab[1000][1000]; n vector<int> ans; n int comp[1000][1000]; n int cur_ans; n int cur_comp = 0; n int dfs(int x, int y) { n   if (!lab[x][y]) { n     ++cur_ans; n     return 0; n   } n   if (!vis[x][y]) { n     comp[x][y] = cur_comp; n     vis[x][y] = true; n     dfs(x + 1, y); n     dfs(x, y + 1); n     dfs(x - 1, y); n     dfs(x, y - 1); n   } n   return 0; n } n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       char c; n       cin >> c; n       if (c ==  * ) { n         lab[i][j] = false; n       } else { n         lab[i][j] = true; n       } n     } n   } n   for (int i = 0; i < k; ++i) { n     int x, y; n     cin >> x >> y; n     --x; n     --y; n     if (!vis[x][y]) { n       cur_ans = 0; n       dfs(x, y); n       cur_comp++; n       ans.push_back(cur_ans); n       cout << cur_ans << endl; n     } else { n       cout << ans[comp[x][y]] << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long readLL() { n   long long n = 0; n   int ch = getchar(); n   while (!isdigit(ch)) ch = getchar(); n   while (isdigit(ch)) n = n * 10 + ch -  0 , ch = getchar(); n   return n; n } n const int MAX_N = 500000 + 3, MAX_LOG_V = 61; n int n; n long long a[MAX_N], b[MAX_LOG_V]; n int main() { n   n = readLL(); n   long long v = 0; n   for (int i = 0; i < n; ++i) { n     a[i] = readLL(), v ^= a[i]; n     a[i] ^= readLL(); n   } n   int cnt = 0; n   for (int i = 0; i < n; ++i) n     for (int j = MAX_LOG_V - 1; j >= 0; --j) n       if (a[i] >> j & 1) { n         if (b[j]) n           a[i] ^= b[j]; n         else { n           b[j] = a[i]; n           ++cnt; n           break; n         } n       } n   long long nowV = 0; n   for (int i = MAX_LOG_V - 1; i >= 0; --i) n     if ((v >> i & 1) != (nowV >> i & 1)) nowV ^= b[i]; n   if (nowV != v) n     puts( 1/1 ); n   else n     printf( %lld/%lld , (1LL << cnt) - 1, 1LL << cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int i, n, k; n string Yes_No, n     names[] = { a ,   b ,   c ,   d ,   e ,   f ,   g ,   h ,   i ,   j ,   k , n                 l ,   m ,   n ,   o ,   p ,   q ,   r ,   s ,   t ,   u ,   v , n                 w ,   x ,   y ,   z ,   aa ,  bb ,  cc ,  dd ,  ee ,  ff ,  gg , n                 hh ,  ii ,  jj ,  kk ,  ll ,  mm ,  nn ,  oo ,  pp ,  qq ,  rr , n                 ss ,  tt ,  uu ,  vv ,  ww ,  xx ,  yy ,  zz }; n int main() { n   for (i = 0; i < 52; i++) names[i] =  A  + names[i]; n   cin >> n >> k; n   for (i = 1; i <= n - k + 1; i++) { n     cin >> Yes_No; n     if (Yes_No ==  NO ) names[i + k - 1] = names[i]; n   } n   for (i = 1; i <= n; i++) cout << names[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n string gd, str, ask; n int q, n, t, ans, tmp, cnt, ara[1000]; n int main() { n   cin >> gd >> str >> n; n   for (int i = 0; i < gd.size(); i++) ara[gd[i] -  a ] = 1; n   while (n--) { n     cin >> ask; n     int in = -1, fin = -1; n     ans = 0; n     for (int i = 0; i < max(str.size(), ask.size()); i++) { n       if (str[i] ==  ? ) { n         if (ara[ask[i] -  a ] != 1) { n           ans = 2; n           break; n         } n       } else if (str[i] ==  * ) { n         in = i; n         break; n       } else { n         if (str[i] != ask[i]) { n           ans = 2; n           break; n         } n       } n     } n     if (ans == 2) { n       printf( NO n ); n       continue; n     } else if (in == -1) { n       printf( YES n ); n       continue; n     } else { n       for (int i = str.size() - 1, j = ask.size() - 1; i >= 0; i--, j--) { n         if (str[i] ==  ? ) { n           if (ara[ask[j] -  a ] != 1) { n             ans = 2; n             break; n           } n         } else if (str[i] ==  * ) { n           fin = j + 1; n           break; n         } else { n           if (str[i] != ask[j]) { n             ans = 2; n             break; n           } n         } n       } n     } n     if (ans == 2 || fin == -1 || in > fin) { n       printf( NO n ); n       continue; n     } else { n       for (int i = in; i < fin; i++) { n         if (ara[ask[i] -  a ] == 1) { n           ans = 2; n           break; n         } n       } n     } n     if (ans == 2) { n       printf( NO n ); n     } else n       printf( YES n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t1, t2, x1, x2, t0, ans1 = 1000000000, ans2 = 1000000000; n double best = 1e16; n int main() { n   cin >> t1 >> t2 >> x1 >> x2 >> t0; n   if (t1 == t2 && t1 == t0) { n     cout << x1 <<     << x2 <<   n ; n     return 0; n   } n   if (t2 == t0) { n     cout <<  0   << x2 <<   n ; n     return 0; n   } n   for (int y1 = 0; y1 <= x1; y1++) { n     int temp = y1 * double(t0 - t1) / double(t2 - t0); n     for (int y2 = temp - 3; y2 <= temp + 2; y2++) { n       if (y1 == 0 && y2 == temp - 3) { n         y2 = x2; n       } n       if (y2 < 0 || y2 > x2) { n         continue; n       } n       double cur = n           ((long long)y1 * t1 + (long long)y2 * t2) / (double)(y1 + y2); n       if (cur < t0) { n         continue; n       } n       if (cur < best) { n         best = cur; n         ans1 = y1; n         ans2 = y2; n       } else if (cur == best) { n         if (y1 + y2 > ans1 + ans2) { n           ans1 = y1; n           ans2 = y2; n         } n       } n     } n   } n   cout << ans1 <<     << ans2 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXR = 1e6 + 1e3; n int n; n vector<int> b, dp, s; n vector<pair<int, int> > v; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   while (cin >> n) { n     b = vector<int>(MAXR, 0); n     s = vector<int>(MAXR, 0); n     dp = vector<int>(MAXR, 0); n     for (int i = 0; i < n; ++i) { n       int x, y; n       cin >> x >> y; n       b[x] = y; n       s[x] = 1; n     } n     int ans = 0; n     dp[0] = s[0]; n     for (int i = 1; i <= MAXR; ++i) { n       if (b[i]) n         dp[i] = i - b[i] <= 0 ? 1 : dp[i - b[i] - 1] + 1; n       else n         dp[i] = dp[i - 1]; n       ans = max(ans, dp[i]); n     } n     cout << n - ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, i; n   cin >> n; n   int la, ra; n   int cnt00 = 0, cnt01 = 0, cnt10 = 0, cnt11 = 0; n   for (i = 0; i < n; i++) { n     cin >> la >> ra; n     if (la == 1) { n       if (ra == 0) n         cnt10++; n       else n         cnt11++; n     } else { n       if (ra == 0) n         cnt00++; n       else n         cnt01++; n     } n   } n   int a00 = cnt01 + cnt10 + 2 * cnt11; n   int a01 = cnt11 + cnt00 + 2 * cnt10; n   int a10 = cnt11 + cnt00 + 2 * cnt01; n   int a11 = cnt01 + cnt10 + 2 * cnt00; n   cout << min(a00, min(a01, min(a10, a11))); n   return 0; n } n