#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-9; n const double pi = acos(-1.0); n const int inf = 0x3f3f3f3f; n const int N = 100010; n int n, q; n int a[N], b[N], c[N]; n struct node { n   int low, high; n   vector<pair<int, int> > v; n } tree[N << 2]; n void build(int p, int low, int high, int c[]) { n   tree[p].low = low; n   tree[p].high = high; n   tree[p].v.clear(); n   for (int k = low; k <= high; ++k) { n     int i = c[k]; n     vector<pair<int, int> >& v = tree[p].v; n     while (!v.empty()) { n       int j = v.back().second; n       if (b[j] >= b[i]) break; n       int t = (a[j] - a[i]) / (b[i] - b[j]) + 1; n       if (v.back().first >= t) n         v.pop_back(); n       else { n         v.push_back(make_pair(t, i)); n         break; n       } n     } n     if (v.empty()) v.push_back(make_pair(0, i)); n   } n   if (low == high) return; n   int mid = (low + high) >> 1; n   stable_partition(c + low, c + high + 1, bind2nd(less<int>(), mid + 1)); n   build(p * 2 + 1, low, mid, c); n   build(p * 2 + 2, mid + 1, high, c); n } n pair<long long, int> query(int p, int low, int high, int t) { n   node& cur = tree[p]; n   if (low <= cur.low && cur.high <= high) { n     int id = lower_bound(cur.v.begin(), cur.v.end(), make_pair(t, inf)) - n              cur.v.begin(); n     id = cur.v[id - 1].second; n     return make_pair(a[id] + (long long)t * b[id], id); n   } n   pair<long long, int> ans = make_pair(0, 0); n   int mid = (cur.low + cur.high) >> 1; n   if (low <= mid) ans = max(ans, query(p * 2 + 1, low, high, t)); n   if (mid < high) ans = max(ans, query(p * 2 + 2, low, high, t)); n   return ans; n } n bool cmp(int i, int j) { n   if (a[i] != a[j]) return a[i] > a[j]; n   return b[i] < b[j]; n } n void solve() { n   for (int i = 0; i < (int)(n); ++i) scanf( %d%d , a + i, b + i); n   for (int i = 0; i < (int)(n); ++i) c[i] = i; n   sort(c, c + n, cmp); n   build(0, 0, n - 1, c); n   int l, r, t; n   for (int i = 0; i < (int)(q); ++i) { n     scanf( %d%d%d , &l, &r, &t); n     printf( %d n , query(0, l - 1, r - 1, t).second + 1); n   } n } n int main() { n   while (scanf( %d%d , &n, &q) != EOF) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b; n map<long long, bool> mp; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   for (long long i = 1; i <= 1000; i++) mp[i * i] = 1; n   cin >> a >> b; n   for (long long i = -1; i > -a; i--) { n     if (mp[a * a - i * i] == 0) continue; n     long long j = sqrt(a * a - i * i); n     for (long long x = 1; x < b; x++) { n       if (mp[b * b - x * x] == 0) continue; n       long long y = sqrt(b * b - x * x); n       if (-i * x == j * y && j != y) { n         cout <<  YES n ; n         cout << 0 <<     << 0 << endl; n         cout << i <<     << j << endl; n         cout << x <<     << y; n         return 0; n       } n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int a, b, c, d; n   scanf( %d%d%d%d , &a, &b, &c, &d); n   a > b ? printf( First ) : printf( Second ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Nmax = 1e6 + 7; n int n; n string s; n int dp[Nmax]; n vector<int> v; n int ans, ans1, ans2; n inline int get(string s) { n   int cnt = 0; n   int mx = 4 * n; n   ans = 0; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  ) ) n       cnt--; n     else n       cnt++; n     if (cnt < mx) { n       mx = cnt; n       ans = i; n     } n   } n   int pos = ans; n   if (cnt != 0) return 0; n   s = s + s; n   dp[0] = 0; n   ans = 0; n   ans1 = 1, ans2 = 1; n   for (int i = pos + 1, j = 0; j < n; j++, i++) { n     if (s[i] ==  ( ) n       dp[j + 1] = dp[j] + 1; n     else n       dp[j + 1] = dp[j] - 1; n   } n   for (int i = 0; i <= n; i++) { n     if (!dp[i]) { n       v.push_back(i); n       ans++; n     } n   } n   ans--; n   int zero = ans; n   int sum = v.size(); n   for (int i = 0; i < sum - 1; i++) { n     int j = i + 1; n     int cnt = 0; n     for (int k = v[i]; k <= v[j]; k++) { n       if (dp[k] == 1) cnt++; n     } n     if (cnt > ans) { n       ans = cnt; n       ans1 = v[i] + 1, ans2 = v[j]; n     } n   } n   v.clear(); n   for (int i = 1; i <= n; i++) n     if (dp[i] == 1) v.push_back(i); n   sum = v.size(); n   for (int i = 0; i < sum - 1; i++) { n     int j = i + 1; n     int cnt = 0; n     for (int k = v[i]; k <= v[j]; k++) { n       if (dp[k] == 2) cnt++; n       if (dp[k] < 1) { n         cnt = 0; n         break; n       } n     } n     if (cnt + zero > ans) { n       ans = cnt + zero; n       ans1 = v[i] + 1, ans2 = v[j]; n     } n   } n   pos++; n   ans1 += pos, ans2 += pos; n   if (ans1 > n) ans1 %= n; n   if (ans2 > n) ans2 %= n; n   cout << ans << endl; n   cout << ans1 <<     << ans2 << endl; n   return ans; n } n int main() { n   cin >> n; n   cin >> s; n   int ans = 0, ans1 = 1, ans2 = 1; n   if (get(s) == 0) { n     cout << ans << endl; n     cout << ans1 <<     << ans2 << endl; n     return 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k, a, b; n vector<long long> v; n long long rec(long long l, long long r) { n   long long i = lower_bound(v.begin(), v.end(), l) - v.begin(); n   long long j = upper_bound(v.begin(), v.end(), r) - v.begin(); n   j--; n   long long na = j - i + 1; n   long long val1 = b * (r - l + 1) * na; n   if (na == 0) return a; n   if (l == r) { n     if (na == 0) n       return a; n     else n       return val1; n   } n   long long mid = (r + l) / 2; n   long long val2 = rec(l, mid) + rec(mid + 1, r); n   long long ans = min(val1, val2); n   return ans; n } n int main() { n   cin >> n >> k >> a >> b; n   long long x; n   for (long long i = 0; i < k; i++) { n     cin >> x; n     v.push_back(x); n   } n   sort(v.begin(), v.end()); n   long long l = 1, r = pow(2, n); n   long long ans = rec(l, r); n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int N; n   cin >> N; n   int* results = new int[N]; n   for (int i = 0; i < N; i++) { n     int num, pos; n     cin >> num >> pos; n     results[i] = pos * 2; n   } n   for (int i = 0; i < N; i++) cout << results[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> v[100000 + 1]; n vector<int> sol[100000 + 1]; n int is[100000 + 1]; n int pos[100000 + 1]; n int main() { n   int i, j, first, N, res = 0; n   scanf( %d , &N); n   for (i = 1; i <= N; ++i) { n     scanf( %d , &first); n     v[i] = {first, i}; n   } n   sort(v + 1, v + N + 1); n   for (i = 1; i <= N; ++i) n     if (!is[i]) { n       ++res; n       is[i] = 1; n       for (j = v[i].second; j != i; j = v[j].second) n         is[j] = 1, sol[res].push_back(j); n       sol[res].push_back(i); n     } n   printf( %d n , res); n   for (i = 1; i <= res; ++i) { n     printf( %d  , sol[i].size()); n     for (j = 0; j < sol[i].size(); ++j) printf( %d  , sol[i][j]); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n using ll = long long; n using ull = unsigned long long; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ll n; n   int k; n   cin >> n >> k; n   ll s = n * (n - 1) / 2; n   s %= n; n   ll t = 0; n   ll cnt = 0; n   for (int i = 0; i < k; i++) { n     ll a, b; n     cin >> a >> b; n     (t += a * b) %= n; n     cnt += b; n   } n   if (cnt < n) { n     cout <<  1 n ; n   } else if (cnt > n) { n     cout <<  -1 n ; n   } else { n     if (s == t) { n       cout <<  1 n ; n     } else { n       cout <<  -1 n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, q; n   cin >> n >> m >> q; n   int a[n][m]; n   struct a { n     int o; n     int p; n   } arr[q]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> a[i][j]; n     } n   } n   int fo[n]; n   for (int i = 0; i < n; i++) { n     int c = 0; n     int max = 0; n     for (int j = 0; j < m; j++) { n       if (a[i][j] == 1) c++; n       if (c > max) max = c; n       if (a[i][j] == 0) c = 0; n     } n     fo[i] = max; n   } n   for (int i = 0; i < q; i++) { n     cin >> arr[i].o; n     cin >> arr[i].p; n     arr[i].o--; n     arr[i].p--; n   } n   for (int i = 0; i < q; i++) { n     a[arr[i].o][arr[i].p] = a[arr[i].o][arr[i].p] ^ 1; n     int max = 0; n     int c = 0; n     for (int j = 0; j < m; j++) { n       if (a[arr[i].o][j] == 1) c++; n       if (c > max) max = c; n       if (a[arr[i].o][j] == 0) c = 0; n     } n     fo[arr[i].o] = max; n     int maxi = 0; n     for (int j = 0; j < n; j++) { n       if (fo[j] > maxi) maxi = fo[j]; n     } n     cout << maxi << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n const long long int maxn = 2e7 + 5; n const long long mod = 1e9 + 7; n using namespace std; n long long int power(long long int a, long long int b) { n   long long int res = 1; n   while (b > 0) { n     if (b % 2 == 1) res = res * a; n     a = a * a; n     b = b / 2; n   } n   return res; n } n long long po(long long x, long long y) { n   long long res = 1; n   x = x % mod; n   while (y > 0) { n     if (y & 1) res = ((res % mod) * (x % mod)) % mod; n     y = y >> 1; n     x = ((x % mod) * (x % mod)) % mod; n   } n   return res; n } n int dp[3001][3001]; n int n; n vector<pair<long long int, long long int> > p(3001); n int fun(int i, int pp) { n   if (i >= n) return 0; n   if (dp[i][pp] != -1) return dp[i][pp]; n   return dp[i][pp] = min(p[i].second + fun(i + 1, i), n                          abs(p[i].first - p[pp].first) + fun(i + 1, pp)); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t = 1; n   while (t--) { n     memset(dp, -1, sizeof(dp)); n     cin >> n; n     for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second; n     p.resize(n); n     sort((p).begin(), (p).end()); n     cout << p[0].second + fun(1, 0) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, c = 0, i, aa = 0, bb = 0; n   cin >> n; n   int a[n], b[n]; n   for (i = 0; i < n; i++) { n     cin >> a[i] >> b[i]; n     aa = aa + a[i]; n     bb = bb + b[i]; n   } n   if (aa % 2 == 1 && bb % 2 == 1) { n     for (i = 0; i < n; i++) { n       if ((a[i] + b[i]) % 2 == 1) { n         c++; n         break; n       } n     } n   } n   if (aa % 2 == 0 && bb % 2 == 0) n     cout <<  0 ; n   else if (c == 1) n     cout <<  1 ; n   else n     cout <<  -1 ; n } n


#include <bits/stdc++.h> n using namespace std; n inline bool SR(int &x) { return scanf( %d , &x) == 1; } n inline bool SR(long long &x) { return scanf( %lld , &x) == 1; } n inline bool SR(double &x) { return scanf( %lf , &x) == 1; } n inline bool SR(char *s) { return scanf( %s , s) == 1; } n inline bool RI() { return true; } n template <typename I, typename... T> n inline bool RI(I &x, T &...tail) { n   return SR(x) && RI(tail...); n } n inline void SP(const int x) { printf( %d , x); } n inline void SP(const long long x) { printf( %lld , x); } n inline void SP(const double x) { printf( %.16lf , x); } n inline void SP(const char *s) { printf( %s , s); } n inline void PL() { puts(  ); } n template <typename I, typename... T> n inline void PL(const I x, const T... tail) { n   SP(x); n   if (sizeof...(tail)) putchar(   ); n   PL(tail...); n } n template <typename I> n void _DOING(const char *s, I &&x) { n   cerr << s <<   =   << x << endl; n } n template <typename I, typename... T> n void _DOING(const char *s, I &&x, T &&...tail) { n   int c = 0; n   while (*s !=  ,  || c != 0) { n     if (*s ==  (  || *s ==  [  || *s ==  { ) c++; n     if (*s ==  )  || *s ==  ]  || *s ==  } ) c--; n     cerr << *s++; n   } n   cerr <<   =   << x <<   ,  ; n   _DOING(s + 1, tail...); n } n const int INF = 0x3f3f3f3f; n const long long INF64 = 0x3f3f3f3f3f3f3f3fll; n inline int RAND() { n   static int x = 880301; n   return (x = x * 0xdefaced + 1) % 0x7fffffff; n } n const int MAX_N = 100000 + 7; n int main() { n   int n; n   RI(n); n   vector<int> v; n   for (int i = 0; i < int(2 * n); i++) { n     int x; n     RI(x); n     v.push_back(x); n   } n   sort((v).begin(), (v).end()); n   long long ans = 1ll * (v[n - 1] - v[0]) * (v[2 * n - 1] - v[n]); n   for (int i = 1; i + n - 1 < 2 * n; i++) { n     long long t = 1ll * (v.back() - v[0]) * (v[i + n - 1] - v[i]); n     ans = min(ans, t); n   } n   PL(ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000100; n const int MOD = 1000000007; n vector<long long> al[N], sum[N]; n vector<pair<int, int> > adj[N]; n pair<int, int> p[N]; n int cnt(int u, long long ls) { n   return upper_bound(al[u].begin(), al[u].end(), ls) - al[u].begin(); n } n long long hp(int u, long long h, long long ls) { n   long long c1 = cnt(u, ls); n   if (c1 == 0) return 0; n   return h * c1 - sum[u][c1 - 1]; n } n int n, k, l[N], q, a, h; n void dfs(int u, long long cost) { n   al[u].push_back(0); n   for (int i = 0; i < adj[u].size(); ++i) { n     int v = adj[u][i].first; n     dfs(v, cost + adj[u][i].second); n     for (int k = 0; k < al[v].size(); ++k) { n       al[u].push_back(al[v][k] + adj[u][i].second); n     } n   } n   sort(al[u].begin(), al[u].end()); n   for (int i = 0; i < al[u].size(); ++i) { n     sum[u].push_back((i ? sum[u].back() : 0) + (al[u][i])); n   } n } n int main() { n   memset(p, -1, sizeof p); n   scanf( %d%d , &n, &q); n   for (int i = 1; i <= n - 1; ++i) { n     scanf( %d , &l[i]); n     int u = (i + 1) / 2; n     int v = (i + 1); n     p[v] = make_pair(u, l[i]); n     adj[u].push_back(make_pair(v, l[i])); n   } n   dfs(1, 0); n   while (q--) { n     scanf( %d%d , &a, &h); n     long long cur = a, prev = -1, rem = h; n     long long add = 0; n     while (1) { n       add += hp(cur, rem, rem); n       if (prev != -1) { n         long long kk = rem - p[prev].second; n         add -= hp(prev, kk, kk); n       } n       prev = cur; n       rem = rem - p[cur].second; n       cur = p[cur].first; n       if (cur == -1 || rem < 0) break; n     } n     printf( %lld n , add); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 300100, maxv = 100, mod = 1e9 + 7, maxa = 1005, n                 maxs = 820, maxb = 20, base = 737, base2 = 3079, n                 mod3 = 998244353, delt = 10513; n const long long inf = 2e16; n const long long infint = 1e9 + 11; n long long max(long long x, long long y) { return (x > y ? x : y); } n long long min(long long x, long long y) { return (x < y ? x : y); } n vector<long long> v[maxn]; n long long dp[maxn][2]; n bool visited[maxn]; n long long ans = 0; n void dfs(long long x) { n   visited[x] = 1; n   long long kid = v[x].size(); n   vector<long long> tmp; n   if (x != 0) { n     kid--; n   } n   for (auto u : v[x]) { n     if (!visited[u]) { n       dfs(u); n       ans = max(ans, dp[u][1] + 1); n       dp[x][0] = max(dp[x][0], dp[u][0] + kid); n       tmp.push_back(dp[u][0]); n       sort(tmp.begin(), tmp.end()); n       reverse(tmp.begin(), tmp.end()); n       if (tmp.size() > 2) { n         tmp.pop_back(); n       } n     } n   } n   dp[x][1] = dp[x][0]; n   if (tmp.size() == 2) { n     dp[x][1] = max(dp[x][1], tmp[0] + tmp[1] + kid - 1); n   } n   ans = max(ans, dp[x][1]); n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long q; n   cin >> q; n   while (q--) { n     ans = 1; n     long long n; n     cin >> n; n     for (long long i = 0; i < n; i++) { n       visited[i] = 0; n       v[i].clear(); n       dp[i][0] = 1; n       dp[i][1] = 1; n     } n     for (long long i = 0; i < n - 1; i++) { n       long long a, b; n       cin >> a >> b; n       a--; n       b--; n       v[a].push_back(b); n       v[b].push_back(a); n     } n     dfs(0); n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int N = 2e5 + 123; n int a[N]; n vector<int> g[N]; n int n, node, stdist = 0; n void dfs(int k, int par, int dist) { n   if (dist > stdist) { n     node = k; n     stdist = dist; n   } n   for (auto it : g[k]) { n     if (it == par) continue; n     dfs(it, k, dist + (a[k] ^ a[it])); n   } n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= n - 1; i++) { n     int u, v; n     cin >> u >> v; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   node = 1; n   dfs(node, node, 0); n   dfs(node, node, 0); n   cout << (stdist + 1) / 2; n   return false; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 510; n const long long INF = 1e18; n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n int n, m, now; n bitset<N> f[2][70][N], g, tmp; n long long ans, fac[N]; n int main() { n   n = read(); n   m = read(); n   for (int i = 1, u, v, w; i <= m; i++) { n     u = read(); n     v = read(); n     w = read(); n     f[w][0][u][v] = 1; n   } n   for (int i = 1; i <= 60; i++) n     for (int u = 1; u <= n; u++) n       for (int v = 1; v <= n; v++) { n         if (f[0][i - 1][u][v] != 0) f[0][i][u] |= f[1][i - 1][v]; n         if (f[1][i - 1][u][v] != 0) f[1][i][u] |= f[0][i - 1][v]; n       } n   if (f[0][60][1].count()) { n     puts( -1 ); n     return 0; n   } n   fac[0] = 1; n   for (int i = 1; i <= 60; i++) fac[i] = fac[i - 1] * 2; n   now = 0; n   tmp[1] = 1; n   for (int i = 60; i >= 0; i--) { n     g.reset(); n     for (int j = 1; j <= n; j++) n       if (tmp[j]) g |= f[now][i][j]; n     if (g.count() != 0) { n       now ^= 1; n       tmp = g; n       ans += fac[i]; n     } n   } n   if (ans > INF) n     puts( -1 ); n   else n     printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> v[200010]; n vector<long long> traversal; n long long cnt; n long long color[200010]; n long long start[200010]; n long long enddd[200010]; n void dfs(long long curr) { n   start[curr] = cnt; n   traversal.push_back(curr); n   cnt++; n   for (int i = 0; i < v[curr].size(); i++) { n     dfs(v[curr][i]); n   } n   enddd[curr] = cnt; n } n long long tree[800010]; n long long lazy[800010]; n void build_tree(int node, int a, int b) { n   if (a > b) return; n   if (a == b) { n     tree[node] = color[traversal[a]]; n     return; n   } n   build_tree(node * 2, a, (a + b) / 2); n   build_tree(node * 2 + 1, 1 + (a + b) / 2, b); n   tree[node] = tree[node * 2] + tree[node * 2 + 1]; n } n void update_tree(int node, int a, int b, int i, int j, int value) { n   if (lazy[node] != 0) { n     tree[node] = (b - a + 1 - tree[node]); n     if (a != b) { n       lazy[node * 2] += lazy[node]; n       lazy[node * 2 + 1] += lazy[node]; n       lazy[node * 2] %= 2; n       lazy[node * 2 + 1] %= 2; n     } n     lazy[node] = 0; n   } n   if (a > b || a > j || b < i) return; n   if (a >= i && b <= j) { n     tree[node] = (b - a + 1 - tree[node]); n     if (a != b) { n       lazy[node * 2] += value; n       lazy[node * 2 + 1] += value; n       lazy[node * 2] %= 2; n       lazy[node * 2 + 1] %= 2; n     } n     return; n   } n   update_tree(node * 2, a, (a + b) / 2, i, j, value); n   update_tree(1 + node * 2, 1 + (a + b) / 2, b, i, j, value); n   tree[node] = tree[node * 2] + tree[node * 2 + 1]; n } n int query_tree(int node, int a, int b, int i, int j) { n   if (a > b || a > j || b < i) return 0; n   if (lazy[node] != 0) { n     tree[node] = (b - a + 1 - tree[node]); n     if (a != b) { n       lazy[node * 2] += lazy[node]; n       lazy[node * 2 + 1] += lazy[node]; n       lazy[node * 2] %= 2; n       lazy[node * 2 + 1] %= 2; n     } n     lazy[node] = 0; n   } n   if (a >= i && b <= j) return tree[node]; n   int q1 = query_tree(node * 2, a, (a + b) / 2, i, j); n   int q2 = query_tree(1 + node * 2, 1 + (a + b) / 2, b, i, j); n   int res = q1 + q2; n   return res; n } n char str[4]; n int main() { n   long long n, temp; n   cin >> n; n   cnt = 0; n   for (int i = 2; i <= n; i++) { n     cin >> temp; n     v[temp].push_back(i); n   } n   for (int i = 1; i <= n; i++) { n     cin >> color[i]; n   } n   dfs(1); n   build_tree(1, 0, cnt - 1); n   long long q; n   cin >> q; n   long long vertex; n   while (q--) { n     scanf( %s , str); n     cin >> vertex; n     if (str[0] ==  p ) { n       update_tree(1, 0, cnt - 1, start[vertex], enddd[vertex] - 1, 1); n     } else { n       cout << query_tree(1, 0, cnt - 1, start[vertex], enddd[vertex] - 1) n            << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n map<int, int> M; n long long posSum[300001]; n int A[300001]; n int main() { n   int N; n   cin >> N; n   for (int i = 1; i <= N; i++) cin >> A[i]; n   posSum[0] = 0; n   for (int i = 1; i <= N; i++) { n     if (A[i] < 0) n       posSum[i] = posSum[i - 1]; n     else n       posSum[i] = posSum[i - 1] + A[i]; n   } n   int a = 1; n   int b = N; n   long long best = -1000000000000000LL; n   long long cur; n   for (int i = 1; i <= N; i++) { n     if (M.find(A[i]) != M.end()) { n       if (A[i] < 0) n         cur = 2LL * A[i] + posSum[i] - posSum[M[A[i]]]; n       else n         cur = posSum[i] - posSum[M[A[i]] - 1]; n       if (best < cur) { n         best = cur; n         a = M[A[i]]; n         b = i; n       } n     } else n       M[A[i]] = i; n   } n   int cnt = 0; n   for (int i = 1; i <= N; i++) { n     if ((i < a) || (i > b) || ((i > a) && (i < b) && (A[i] < 0))) cnt++; n   } n   cout << best <<     << cnt <<   n ; n   for (int i = 1; i <= N; i++) n     if ((i < a) || (i > b) || ((i > a) && (i < b) && (A[i] < 0))) n       cout << i <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long A = 100000000000000LL, N = 10000, M = 1000001; n long long i, j, n, m, a, t[M * 4]; n void modi(long long v, long long l, long long r, long long g, long long h) { n   if (l == r) { n     t[v] = h % 1000000007; n     return; n   } n   long long mid = (l + r) / 2; n   if (g <= mid) n     modi(v * 2, l, mid, g, h); n   else n     modi(v * 2 + 1, mid + 1, r, g, h); n   t[v] = (t[v * 2] + t[v * 2 + 1]) % 1000000007; n } n long long get(long long v, long long l, long long r, long long _l, n               long long _r) { n   if (l > r || _l > _r) return 0; n   if (l == _l && r == _r) return t[v]; n   long long mid = (l + r) / 2; n   return get(v * 2, l, mid, _l, min(mid, _r)) + n          get(v * 2 + 1, mid + 1, r, max(mid + 1, _l), _r); n } n int main() { n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> a; n     modi(1, 1, M, a, get(1, 1, M, 1, a) * a + a); n   } n   cout << get(1, 1, M, 1, M); n } n


#include <bits/stdc++.h> n using namespace std; n int p[300002], pi; n bool tag[300002]; n int main() { n   int n, x; n   long long cnt; n   while (scanf( %d , &n) != EOF) { n     memset(tag, false, sizeof(tag)); n     pi = 0; n     for (int i = 0; i < n; i++) { n       scanf( %d , &x); n       if (x < 1 || x > n || tag[x]) n         p[pi++] = x; n       else n         tag[x] = true; n     } n     sort(p, p + pi); n     cnt = 0; n     for (int i = 0, j = 1; i < pi; i++, j++) { n       while (tag[j]) j++; n       cnt += (long long)abs(p[i] - j); n     } n     printf( %I64d n , cnt); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char a[514][514]; n int n, m; n int ID[514][514]; n int RID[20005]; n int idt[20005]; n int g[20005]; n int FIND(int x) { return g[x] == x ? x : (g[x] = FIND(g[x])); } n void UNION(int x, int y) { n   x = FIND(x); n   y = FIND(y); n   g[x] = y; n } n int edge(int x, int y) { n   if (FIND(x) == FIND(y)) return 1; n   UNION(x, y); n   return 0; n } n long long P[2][514][514]; n int MOD = 1e9 + 7; n int nid = 0, Pid[2] = {}; n void bridge(int x, int y) { n   x = FIND(x); n   y = FIND(y); n   if (x == y) return; n   P[idt[x]][RID[x]][RID[x]]++; n   P[idt[x]][RID[x]][RID[y]]--; n   P[idt[x]][RID[y]][RID[x]]--; n   P[idt[x]][RID[y]][RID[y]]++; n } n long long inv(long long x, long long y, long long p, long long q, long long r, n               long long s) { n   if (y == 0) return (p % MOD + MOD) % MOD; n   return inv(y, x % y, r, s, p - r * (x / y), q - s * (x / y)); n } n long long det(long long F[514][514], int D) { n   long long ans = 1; n   for (int i = 0; i < D; i++) { n     int r = i; n     while (r < D && F[r][i] == 0) ++r; n     if (r >= D) return 0; n     if (r != i) ans = ans * (MOD - 1) % MOD; n     for (int j = i; j < D; j++) swap(F[r][j], F[i][j]); n     ans = ans * F[i][i] % MOD; n     long long t = inv(F[i][i], MOD, 1, 0, 0, 1); n     for (int j = i; j < D; j++) F[i][j] = (F[i][j] * t) % MOD; n     for (int r = i + 1; r < D; r++) n       if (F[r][i] != 0) { n         long long s = F[r][i]; n         for (int j = i; j < D; j++) { n           F[r][j] = (F[r][j] - s * F[i][j]) % MOD; n           if (F[r][j] < 0) F[r][j] += MOD; n         } n       } n   } n   return ans; n } n int main(void) { n   scanf( %d%d%d , &n, &m, &MOD); n   assert(1 <= n && n <= 100); n   assert(1 <= m && m <= 100); n   for (int i = 0; i < n; i++) scanf( %s , a[i]); n   for (int i = 0; i < n; i++) assert(strlen(a[i]) == m); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) n       assert(a[i][j] ==  /  || a[i][j] ==      || a[i][j] ==  * ); n   for (int i = 0; i <= n; i++) n     for (int j = 0; j <= m; j++) { n       ID[i][j] = ++nid; n       g[nid] = nid; n       idt[nid] = (i % 2) ^ (j % 2); n     } n   int fail = 0; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       if (a[i][j] ==  / ) { n         fail |= edge(ID[i + 1][j], ID[i][j + 1]); n       } else if (a[i][j] ==     ) { n         fail |= edge(ID[i][j], ID[i + 1][j + 1]); n       } n     } n   if (fail) { n     puts( 0 ); n     return 0; n   } n   for (int i = 0; i <= n; i++) n     for (int j = 0; j <= m; j++) n       if (FIND(ID[i][j]) == ID[i][j]) { n         RID[ID[i][j]] = Pid[idt[ID[i][j]]]++; n       } n   int cnt = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (a[i][j] ==  * ) { n         bridge(ID[i][j], ID[i + 1][j + 1]); n         bridge(ID[i + 1][j], ID[i][j + 1]); n         ++cnt; n       } n     } n   } n   assert(cnt <= 200); n   for (int z = 0; z < 2; z++) n     for (int i = 0; i < Pid[z]; i++) n       for (int j = 0; j < Pid[z]; j++) P[z][i][j] = (P[z][i][j] + MOD) % MOD; n   long long ans = det(P[0], Pid[0] - 1) + det(P[1], Pid[1] - 1); n   printf( %d n , (int)(ans % MOD)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 410000; n char ch[N]; n int a[N]; n int n, t; n int main() { n   scanf( %d%d , &n, &t); n   scanf( %s , ch + 1); n   if (t == 0) { n     printf( %s , ch + 1); n     return 0; n   } n   int s = 0; n   for (int i = 1; i <= n; i++) { n     if (ch[i] ==  . ) n       s = i + 1; n     else if (s == 0) n       a[i + 1] = ch[i] -  0 ; n     else n       a[i] = ch[i] -  0 ; n   } n   int ok = 0; n   for (int i = s; i <= n; i++) n     if (a[i] >= 5) { n       n = i - 1; n       ok = 1; n       t--; n       a[i - 1]++; n       break; n     } n   if (ok == 0) { n     printf( %s , ch + 1); n     return 0; n   } n   while (t && n >= s && a[n] >= 5) { n     a[n - 1]++; n     a[n] %= 10; n     if (a[n]) t--; n     n--; n   } n   while (n >= s && a[n] == 0) n--; n   for (int i = n - 1; i >= 1; i--) a[i] += a[i + 1] / 10, a[i + 1] %= 10; n   if (a[1]) printf( %d , a[1]); n   for (int i = 2; i <= n; i++) { n     if (i == s) printf( . ); n     printf( %d , a[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int const N = 222; n int const M = 1e9 + 7; n int n; n ll f[N][N]; n struct point { n   ll x, y; n   point(ll _x = 0, ll _y = 0) : x(_x), y(_y) {} n   ll operator*(const point &rhs) const { return x * rhs.y - y * rhs.x; } n   point operator-(const point &rhs) const { n     return point(x - rhs.x, y - rhs.y); n   } n } p[N]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) scanf( %I64d%I64d , &p[i].x, &p[i].y); n   ll area = 0; n   for (int i = 1; i + 1 < n; ++i) area += (p[i] - p[0]) * (p[i + 1] - p[0]); n   if (area < 0) reverse(p, p + n); n   for (int i = 0; i < n; ++i) f[i][i] = f[i][(i + 1) % n] = 1; n   for (int step = 2; step < n; ++step) n     for (int i = 0; i < n; ++i) { n       int j = (i + step) % n; n       for (int t = 1; t <= step - 1; ++t) { n         int k = (i + t) % n; n         if ((p[k] - p[i]) * (p[j] - p[i]) > 0) { n           f[i][j] = (f[i][j] + f[i][k] * f[k][j]) % M; n         } n       } n     } n   printf( %I64d n , f[0][n - 1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void think() { n   long long n, m; n   cin >> n >> m; n   vector<long long> v(n); n   for (long long i = 0; i < n; i++) { n     cin >> v[i]; n   } n   long long ans = 0; n   for (long long i = 0; i < m; i++) { n     long long x, y; n     cin >> x >> y; n     ans += min(v[x - 1], v[y - 1]); n   } n   cout << ans <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   long long testcase = 1; n   while (testcase--) { n     think(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     long long k = (n + 1) / 2; n     k = k - 1; n     long long ans = 0; n     for (long long i = 1; i <= k; ++i) { n       ans += 8 * i * i; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e4 + 5; n int n, q; n bool possible[MAXN]; n vector<int> seg[4 * MAXN]; n void update(int u, int l, int r, int tl, int tr, int x) { n   if (l > tr || r < tl) n     return; n   else if (l <= tl && tr <= r) { n     seg[u].push_back(x); n   } else { n     int tm = (tl + tr) / 2; n     update(u << 1, l, r, tl, tm, x); n     update(u << 1 | 1, l, r, tm + 1, tr, x); n   } n } n void query(int u, int tl, int tr, bitset<MAXN> parsums) { n   bitset<MAXN> sums = parsums; n   for (int v : seg[u]) { n     sums |= sums << v; n   } n   for (int i = 1; i <= n; ++i) { n     possible[i] |= sums[i]; n   } n   if (tl != tr) { n     int tm = (tl + tr) / 2; n     query(2 * u, tl, tm, sums); n     query(2 * u + 1, tm + 1, tr, sums); n   } n } n int main() { n   cin >> n >> q; n   while (q--) { n     int l, r, x; n     cin >> l >> r >> x; n     update(1, l, r, 1, n, x); n   } n   query(1, 1, n, bitset<MAXN>(1)); n   int cnt = 0; n   for (int i = 0; i <= n; ++i) { n     if (possible[i]) { n       ++cnt; n     } n   } n   cout << cnt <<   n ; n   for (int i = 0; i <= n; ++i) { n     if (possible[i]) { n       cout << i <<    ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int f[100010], g[100010]; n int _Max(int x, int y) { return x > y ? x : y; } n void upd(int x, int ans, int k) { n   if (f[x] < ans) n     f[x] = ans, g[x] = k; n   else if (f[x] == ans && k < g[x]) n     g[x] = k; n } n int main() { n   int n, L, p, t, i, j, l = 1, r = 0, x, y, s = 0, ans = 0; n   scanf( %d%d%d%d , &L, &n, &p, &t); n   for (i = 1; i <= n; i++) { n     scanf( %d%d , &x, &y); n     while (r < i - 1 && g[r + 1] + t <= y) r++; n     while (l < i && g[l] + t <= x) s = _Max(s, f[l++]); n     f[i] = -1; n     upd(i, s + (y - x) / p, x + (y - x) / p * p); n     for (j = l; j <= r; j++) n       upd(i, f[j] + (y - g[j] - t) / p, g[j] + t + (y - g[j] - t) / p * p); n     ans = _Max(ans, f[i]); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:256000000 ) n using namespace std; n template <class T> n double sqrt(T x) { n   return sqrt((double)x); n } n template <class T> n T sqr(T x) { n   return x * x; n } n const double PI = acos(-1.0); n const int INF = 1000000000; n const int MOD = 1000000007; n void wa() { n   cout << 5; n   exit(0); n } n void tl() { n   while (1) n     ; n } n void pe() { n   cout <<  abc abc n 453534 wff sf sd n ; n   exit(0); n } n void re() { exit(1); } n void ml() { int *b = new int[1000]; } n int main() { n   double TIME_START = clock(); n   int n; n   cin >> n; n   unsigned long long ans = 1, lay; n   if (n >= 2) { n     lay = 12; n     for (int x = 2; x <= n; x++) { n       ans += lay; n       lay += 12; n     } n   } n   cout << ans; n   fprintf(stderr,   n n%.15lf n n , n           (double)(clock() - TIME_START) / CLOCKS_PER_SEC); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long M = 998244353; n const long long inf = 4e18; n const long long N = 3e5; n long long fac[N + 1]; n long long power(long long x, long long y) { n   if (y < 0) return power(x, M - 2) * power(x, y + 1) % M; n   y %= (M - 1); n   long long res = 1; n   while (y > 0) { n     if (y & 1) res = res * x % M; n     y = y >> 1; n     x = x * x % M; n   } n   return res; n } n void factorial() { n   fac[0] = 1; n   for (long long i = 1; i <= N; i++) fac[i] = fac[i - 1] * i % M; n } n long long nCr(long long n, long long r) { n   if (r > n || r < 0) return 0; n   if (r == 0) return 1; n   return (fac[n] * power(fac[r], M - 2) % M * power(fac[n - r], M - 2) % M) % M; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   factorial(); n   long long n, k; n   cin >> n >> k; n   vector<pair<long long, long long> > v; n   vector<long long> right; n   for (long long i = 0; i < n; i++) { n     long long l, r; n     cin >> l >> r; n     v.emplace_back(l, r); n     right.emplace_back(r); n   } n   sort(v.begin(), v.end()); n   sort(right.begin(), right.end()); n   long long o = 0; n   for (long long i = 0; i < n; i++) { n     long long j = n         upper_bound(v.begin(), v.end(), make_pair(right[i], inf)) - v.begin(); n     o = (o + nCr(j - i - 1, k - 1)) % M; n   } n   cout << o <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n; n   cin >> n; n   vector<long long int> cost(n); n   for (long long int i = 0; i < n; i++) { n     cin >> cost[i]; n   } n   sort(cost.begin(), cost.end()); n   long long int m; n   cin >> m; n   vector<long long int> coup(m); n   for (long long int i = 0; i < m; i++) { n     cin >> coup[i]; n   } n   long long int temp_sum = 0; n   for (long long int i = 0; i < n; i++) { n     temp_sum += cost[i]; n   } n   for (long long int i = 0; i < m; i++) { n     cout << temp_sum - cost.at(n - coup[i]) << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool chk[5000050]; n int ara[5000050], sum[5000050]; n void sieve() { n   int i, j, k, x, y, z; n   for (i = 2; i <= 5000000; i++) n     if (!chk[i]) { n       for (j = i; j <= 5000000; j += i) { n         x = 0; n         k = j; n         while (k % i == 0) { n           x++; n           k /= i; n         } n         chk[j] = true; n         ara[j] += x; n       } n     } n   sum[2] = ara[2]; n   for (i = 3; i <= 5000000; i++) sum[i] = sum[i - 1] + ara[i]; n } n int main() { n   sieve(); n   int i, t, n, m, k, ans; n   scanf( %d , &t); n   for (i = 0; i < t; i++) { n     scanf( %d %d , &m, &n); n     ans = sum[m] - sum[n]; n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100100; n string S; n int N; n int Z[MAXN]; n int len[MAXN]; n void Zalg() { n   int L = 0, R = 0; n   for (int i = 1; i < N; i++) { n     if (i > R) { n       L = R = i; n       while (R < N && S[R] == S[R - L]) R++; n       Z[i] = R - L; n       R--; n     } else { n       int j = i - L; n       if (Z[j] < R - i + 1) n         Z[i] = Z[j]; n       else { n         L = i; n         while (R < N && S[R] == S[R - L]) R++; n         Z[i] = R - L; n         R--; n       } n     } n   } n } n int main() { n   cin >> S; n   N = S.size(); n   Z[0] = N; n   Zalg(); n   memcpy(len, Z, sizeof(len)); n   sort(len, len + N); n   int total = 0; n   for (int i = 1; i <= N; i++) n     if (Z[N - i] == i) total++; n   cout << total <<   n ; n   int idx = 0; n   for (int i = 1; i <= N; i++) { n     if (Z[N - i] != i) continue; n     while (idx < N && len[idx] < i) idx++; n     cout << i <<     << N - idx <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = (x << 3) + (x << 1) + (c ^ 48); n     c = getchar(); n   } n   return f == 1 ? x : -x; n } n inline void print(int x) { n   if (x < 0) x = ~x + 1, putchar( - ); n   if (x >= 10) print(x / 10); n   putchar((x % 10) | 48); n } n int n, m; n int ans[200010]; n pair<int, int> edg[200010]; n int len[200010]; n bool tre[200010]; n namespace tree { n vector<pair<int, int> > vec[200010]; n int maxn[800010], ano[800010], tag[800010]; n int siz[200010], son[200010], fa[200010], dfn[200010], top[200010], val[200010], n     dep[200010]; n int id; n void add(int u, int v, int w) { n   vec[u].push_back(make_pair(v, w)); n   vec[v].push_back(make_pair(u, w)); n } n void pushup(int p) { n   maxn[p] = max(maxn[p << 1], maxn[p << 1 | 1]); n   ano[p] = min(ano[p << 1], ano[p << 1 | 1]); n } n void pushdown(int p) { n   if (tag[p] != -1) { n     if (tag[p] < ano[p << 1]) { n       ano[p << 1] = tag[p]; n     } n     if (tag[p] < ano[p << 1 | 1]) { n       ano[p << 1 | 1] = tag[p]; n     } n     tag[p << 1] = (tag[p << 1] == -1 ? tag[p] : min(tag[p << 1], tag[p])); n     tag[p << 1 | 1] = n         (tag[p << 1 | 1] == -1 ? tag[p] : min(tag[p << 1 | 1], tag[p])); n     tag[p] = -1; n   } n } n void update(int p, int l, int r, int L, int R, int k) { n   if (l >= L && r <= R) { n     if (k < ano[p]) { n       ano[p] = k; n     } n     tag[p] = (tag[p] == -1 ? k : min(tag[p], k)); n     return; n   } n   pushdown(p); n   int mid = l + r >> 1; n   if (L <= mid) update(p << 1, l, mid, L, R, k); n   if (R > mid) update(p << 1 | 1, mid + 1, r, L, R, k); n   pushup(p); n } n int qano(int p, int l, int r, int L, int R) { n   if (l >= L && r <= R) { n     return ano[p]; n   } n   pushdown(p); n   pushup(p); n   int mid = l + r >> 1; n   int res = 0x3f3f3f3f; n   if (L <= mid) res = min(res, qano(p << 1, l, mid, L, R)); n   if (R > mid) res = min(res, qano(p << 1 | 1, mid + 1, r, L, R)); n   return res; n } n void build(int p, int l, int r) { n   tag[p] = -1; n   if (l == r) { n     maxn[p] = val[l]; n     ano[p] = 0x3f3f3f3f; n     return; n   } n   int mid = l + r >> 1; n   build(p << 1, l, mid); n   build(p << 1 | 1, mid + 1, r); n   pushup(p); n } n int query(int p, int l, int r, int L, int R) { n   if (l >= L && r <= R) return maxn[p]; n   int mid = l + r >> 1; n   int res = 0; n   if (L <= mid) res = max(res, query(p << 1, l, mid, L, R)); n   if (R > mid) res = max(res, query(p << 1 | 1, mid + 1, r, L, R)); n   return res; n } n int Query(int u, int v) { n   int res = 0; n   while (top[u] != top[v]) { n     if (dep[top[u]] < dep[top[v]]) swap(u, v); n     res = max(res, query(1, 1, id, dfn[top[u]], dfn[u])); n     u = fa[top[u]]; n   } n   if (u == v) return res; n   if (dep[u] > dep[v]) swap(u, v); n   res = max(res, query(1, 1, id, dfn[u] + 1, dfn[v])); n   return res; n } n void dfs1(int x, int f) { n   fa[x] = f, dep[x] = dep[f] + 1, siz[x] = 1; n   for (auto i : vec[x]) { n     int v = i.first; n     if (v == f) continue; n     dfs1(v, x); n     siz[x] += siz[v]; n     if (siz[v] > siz[son[x]]) son[x] = v; n   } n } n void dfs2(int x, int topf, int va) { n   dfn[x] = ++id; n   val[id] = va; n   top[x] = topf; n   if (!son[x]) return; n   for (auto i : vec[x]) { n     int v = i.first; n     if (v == son[x]) { n       dfs2(v, topf, i.second); n     } n   } n   for (auto i : vec[x]) { n     int v = i.first; n     if (v == fa[x] || v == son[x]) continue; n     dfs2(v, v, i.second); n   } n } n void UPD(int x, int y, int k) { n   while (top[x] != top[y]) { n     if (dep[top[x]] < dep[top[y]]) swap(x, y); n     update(1, 1, id, dfn[top[x]], dfn[x], k); n     x = fa[top[x]]; n   } n   if (x == y) return; n   if (dep[x] > dep[y]) swap(x, y); n   update(1, 1, id, dfn[x] + 1, dfn[y], k); n } n int another(int x, int y) { n   if (dep[x] < dep[y]) swap(x, y); n   return qano(1, 1, id, dfn[x], dfn[x]); n } n void solve() { n   memset(ano, 0x3f, sizeof(ano)); n   dfs1(1, 0); n   dfs2(1, 1, 0); n   build(1, 1, id); n } n }  // namespace tree n namespace MST { n int cnt; n int fa[200010]; n struct edge { n   int u, v, w, id; n } e[200010]; n void add(int u, int v, int w, int id) { e[++cnt] = edge{u, v, w, id}; } n bool cmp(edge x, edge y) { return x.w < y.w; } n int find(int x) { n   if (fa[x] == x) return x; n   return fa[x] = find(fa[x]); n } n void kruskal() { n   int t = 1; n   for (int i = 1; i <= m; ++i) { n     int fx = find(e[i].u); n     int fy = find(e[i].v); n     if (fx == fy) { n       continue; n     } n     ++t; n     tree::add(e[i].u, e[i].v, e[i].w); n     tre[e[i].id] = 1; n     fa[fx] = fy; n     if (t == n) break; n   } n } n void solve() { n   for (int i = 1; i <= n; ++i) fa[i] = i; n   sort(e + 1, e + m + 1, cmp); n   kruskal(); n } n }  // namespace MST n int main() { n   n = read(), m = read(); n   for (int i = 1; i <= m; ++i) { n     int u = read(), v = read(), w = read(); n     edg[i].first = u, edg[i].second = v, len[i] = w; n     MST::add(u, v, w, i); n   } n   MST::solve(); n   tree::solve(); n   for (int i = 1; i <= m; ++i) { n     if (!tre[i]) { n       tree::UPD(edg[i].first, edg[i].second, len[i]); n     } n   } n   for (int i = 1; i <= m; ++i) { n     if (ans[i] == -1) continue; n     if (tre[i]) { n       ans[i] = tree::another(edg[i].first, edg[i].second) - 1; n       if (ans[i] > 0x3f3f3f15) ans[i] = -1; n       continue; n     } n     int maxn = tree::Query(edg[i].first, edg[i].second); n     ans[i] = maxn - 1; n   } n   for (int i = 1; i <= m; ++i) print(ans[i]), putchar(   ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x[4]; n int y[4]; n int ii[4] = {1, -1, 0, 0}; n int jj[4] = {0, 0, -1, 1}; n int main() { n   ios_base::sync_with_stdio(0); n   int x1, x2, x3, y1, y2, y3; n   for (int i = 1; i <= 3; i++) { n     cin >> x[i] >> y[i]; n   } n   set<pair<int, int>> s; n   long long xx = 0, yy = 0; n   long long d = 1e9; n   for (int j = 0; j <= 1000; j++) { n     for (int i = 0; i <= 1000; i++) { n       if (abs(x[1] - i) + abs(y[1] - j) + abs(x[2] - i) + abs(y[2] - j) + n               abs(x[3] - i) + abs(y[3] - j) < n           d) { n         xx = i; n         yy = j; n         d = abs(x[1] - i) + abs(y[1] - j) + abs(x[2] - i) + abs(y[2] - j) + n             abs(x[3] - i) + abs(y[3] - j); n       } n     } n   } n   for (int t = 1; t <= 3; t++) { n     int i, j; n     i = xx; n     j = yy; n     s.insert({x[t], y[t]}); n     while (i != x[t] || j != y[t]) { n       s.insert({i, j}); n       for (int e = 0; e < 4; e++) { n         if (abs(i - x[t]) > abs(i + ii[e] - x[t]) || n             abs(j - y[t]) > abs(j + jj[e] - y[t])) { n           i += ii[e]; n           j += jj[e]; n           break; n         } n       } n     } n   } n   cout << s.size() <<   n ; n   for (auto p : s) { n     cout << p.first <<     << p.second <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int N, M; n int Candidates[100]; n int main() { n   cin >> N >> M; n   for (int i = 0; i < M; i++) { n     int MaxVotesNum = -1; n     int idx = -1; n     for (int j = 0; j < N; j++) { n       int Temp; n       cin >> Temp; n       if (MaxVotesNum < Temp) { n         MaxVotesNum = Temp; n         idx = j; n       } n     } n     Candidates[idx]++; n   } n   cout << (max_element(Candidates, Candidates + 100) - Candidates) + 1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int arr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; n void solve() { n   int d, x; n   int a, b; n   cin >> a >> b; n   int ans = 0; n   for (int i = a; i <= b; i++) { n     x = i; n     while (x) { n       d = x % 10; n       x = x / 10; n       ans += arr[d]; n     } n   } n   cout << ans << endl; n } n int main() { n   int t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int lss[2000][2000] = {}; n int main() { n   string s; n   cin >> s; n   int n = s.length(); n   if (n == 1) { n     cout << 0 << endl; n     return 0; n   } n   for (int i = 0; i < n; i++) { n     lss[i][i] = 1; n     int temp = s[i]; n     int zero = 0; n     if (s[i] ==  0 ) { n       zero++; n     } n     for (int j = i + 1; j < n; j++) { n       if (s[j] ==  1 ) { n         lss[i][j] = lss[i][j - 1] + 1; n       } else { n         zero++; n         lss[i][j] = max(zero, lss[i][j - 1]); n       } n     } n   } n   for (int i = 0; i < n; i++) { n     if (s[i] ==  0 ) { n       continue; n     } n     int temp1 = 0; n     int zero = 0; n     for (int j = 0; j <= i; j++) { n       if (j != i && s[j] ==  1 ) { n         temp1 = temp1 + 1; n       } else { n         zero++; n         temp1 = max(zero, temp1); n       } n     } n     int temp2 = 0; n     zero = 0; n     for (int j = i; j < n; j++) { n       if (j != i && s[j] ==  1 ) { n         temp2 = temp2 + 1; n       } else { n         zero++; n         temp2 = max(zero, temp2); n       } n     } n     if (temp1 == lss[0][i] && temp2 == lss[i][n - 1]) { n       s[i] =  0 ; n     } n   } n   cout << s << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const bool OJ = true; n const long long inf = 1LL << 60; n template <class T> n ostream& operator<<(ostream& os, const vector<T>& v) { n   for (long long i = 0; i < (((long long)((v).size()))); i++) os << v[i] <<    ; n   return os; n } n template <class T> n istream& operator>>(istream& is, vector<T>& v) { n   for (long long i = 0; i < (((long long)((v).size()))); i++) is >> v[i]; n   return is; n } n template <class A, class B> n istream& operator>>(istream& is, tuple<A, B>& p) { n   is >> get<0>(p) >> get<1>(p); n   return is; n } n long long dp[100005][30]; n string s; n long long k; n vector<tuple<char, char>> f; n bool ok(char x, char y) { n   return !binary_search((f).begin(), (f).end(), make_tuple(x, y)); n } n long long solve(long long i, char prev) { n   if (i == ((long long)((s).size()))) return 0; n   long long& d = dp[i][prev - 26]; n   if (d != -1) return d; n   long long ans = inf; n   if (ok(prev, s[i])) { n     ans = min(ans, solve(i + 1, s[i])); n   } n   ans = min(ans, 1 + solve(i + 1, prev)); n   return d = ans; n } n void run() { n   cin >> s; n   cin >> k; n   f = vector<tuple<char, char>>(); n   for (long long i = 0; i < (k); i++) { n     string tmp; n     cin >> tmp; n     char x = tmp[0]; n     char y = tmp[1]; n     f.emplace_back(x, y); n     f.emplace_back(y, x); n   } n   sort((f).begin(), (f).end()); n   memset(dp, -1, sizeof(dp)); n   cout << solve(0,  a  + 28) << endl; n } n int main(int argc, char* argv[]) { n   run(); n   return 0; n } n


#include <bits/stdc++.h> n template <class C, class E> n inline bool contains(const C& container, const E& element) { n   return container.find(element) != container.end(); n } n template <class T> n inline void checkmin(T& a, T b) { n   if (b < a) a = b; n } n template <class T> n inline void checkmax(T& a, T b) { n   if (b > a) a = b; n } n using namespace std; n int n; n string s; n bool Check(int i) { n   if (i == 0) return true; n   vector<bool> d(10, false); n   while (i != 0) { n     int dig = i % 10; n     if (d[dig]) return false; n     d[dig] = true; n     i = i / 10; n   } n   return true; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cout << std::setprecision(15); n   cout << std::fixed; n   int l, r; n   cin >> l >> r; n   for (int i = (l), _b = (r); i <= _b; i++) { n     if (Check(i)) { n       cout << i; n       return 0; n     } n   } n   cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct debugger { n   template <typename T> n   debugger& operator,(const T& x) { n     clog << x <<    ; n     return *this; n   } n } dbg; n auto ____ = []() { n   std::ios::sync_with_stdio(false); n   cin.tie(nullptr); n   return nullptr; n }(); n int main(int argc, char* argv[]) { n   int n, K; n   cin >> n >> K; n   vector<pair<int, int> > edges(n - 1); n   vector<vector<pair<int, int> > > g(n); n   for (int i = 0; i < (n - 1); ++i) { n     int x, y; n     cin >> x >> y; n     --x, --y; n     edges[i].first = x, edges[i].second = y; n     g[x].push_back(make_pair(y, i)); n     g[y].push_back(make_pair(x, i)); n   } n   vector<pair<int, int> > deg(n); n   for (int i = 0; i < (n); ++i) deg[i] = make_pair((int)(g[i]).size(), i); n   sort(deg.begin(), deg.end(), greater<pair<int, int> >()); n   int R = deg[K].first; n   vector<int> edge_color(n - 1, -1); n   stack<pair<int, int> > S; n   S.push(make_pair(0, -1)); n   while (!S.empty()) { n     auto p = S.top(); n     S.pop(); n     int x = p.first, c = p.second; n     int d = 0; n     for (auto y : g[x]) { n       d %= R; n       if (edge_color[y.second] == -1) { n         if (R == 1) n           d = 0; n         else if (d == c) { n           d++; n           d %= R; n         } n         edge_color[y.second] = d; n         S.push(make_pair(y.first, d)); n         ++d; n       } n     } n   } n   cout << R <<   n ; n   for (auto c : edge_color) { n     cout << c + 1 <<    ; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   while (cin >> n) { n     int res[100]; n     memset(res, 0, sizeof(res)); n     for (int i = 0; i < n; ++i) { n       for (int j = 0; j < n; ++j) { n         int r; n         cin >> r; n         if (i < j) continue; n         switch (r) { n           case 1: n             ++res[i]; n             break; n           case 2: n             ++res[j]; n             break; n           case 3: n             ++res[i]; n             ++res[j]; n           default: n             break; n         } n       } n     } n     int count = 0; n     for (int i = 0; i < n; ++i) { n       if (res[i] == 0) { n         res[count++] = i + 1; n       } n     } n     cout << count << endl; n     if (count > 0) { n       for (int i = 0; i < count; ++i) { n         cout << res[i] <<    ; n       } n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T BM(T p, T e, T M) { n   long long int ret = 1; n   for (; e > 0; e >>= 1) { n     if (e & 1) ret = (ret * p) % M; n     p = (p * p) % M; n   } n   return (T)ret; n } n template <class T> n inline T gcd(T a, T b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n template <class T> n inline T mdINV(T a, T M) { n   return BM(a, M - 2, M); n } n template <class T> n inline T PW(T p, T e) { n   long long int ret = 1; n   for (; e > 0; e >>= 1) { n     if (e & 1) ret = (ret * p); n     p = (p * p); n   } n   return (T)ret; n } n template <class T> n string NTS(T Number) { n   stringstream ss; n   ss << Number; n   return ss.str(); n } n template <class T> n T stringtonumber(const string &Text) { n   istringstream ss(Text); n   T result; n   return ss >> result ? result : 0; n } n template <class T> n bool ISLEFT(T a, T b, T c) { n   if (((a.first.first - b.first.first) * (b.second.second - c.second.second) - n        (b.first.first - c.first.first) * (a.second.second - b.second.second)) < n       0.0) n     return 1; n   else n     return 0; n } n int main() { n   int n; n   scanf( %d , &n); n   string a[n + 2]; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   for (int i = n - 1; i >= 1; i--) { n     string s; n     int l = a[i + 1].size(); n     int l1 = a[i].size(); n     int first = 0; n     s +=  # ; n     bool fl = 0; n     for (int j = 1; j <= min(l - 1, l1 - 1); j++) { n       if (a[i][j] < a[i + 1][j]) fl = 1; n       if (a[i][j] > a[i + 1][j]) { n         break; n       } n       s += a[i][j]; n     } n     if (fl) n       a[i] = a[i]; n     else n       a[i] = s; n   } n   for (int i = 1; i <= n; i++) cout << a[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cerr << name <<   :   << arg1 << std::endl; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cerr.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n void pre() {} n void solve() {} n bool vis[200009]; n int ans[200009]; n int main() { n   cin.sync_with_stdio(0); n   cin.tie(0); n   cin.exceptions(cin.failbit); n   pre(); n   int n; n   cin >> n; n   int a, b; n   cin >> a >> b; n   priority_queue<pair<int, int> > q; n   q.push(make_pair(0, 0)); n   memset(ans, -1, sizeof(ans)); n   ans[0] = 0; n   while (!q.empty()) { n     pair<int, int> z = q.top(); n     q.pop(); n     if (vis[z.second]) continue; n     vis[z.second] = 1; n     if (z.second + a < a + b && !vis[z.second + a] && n         (ans[z.second + a] == -1 || n          ans[z.second + a] > max(z.second + a, ans[z.second]))) { n       ans[z.second + a] = max(z.second + a, ans[z.second]); n       q.push(make_pair(-ans[z.second + a], z.second + a)); n     } n     if (z.second - b >= 0 && !vis[z.second - b] && n         (ans[z.second - b] == -1 || ans[z.second - b] > ans[z.second])) { n       ans[z.second - b] = ans[z.second]; n       q.push(make_pair(-ans[z.second - b], z.second - b)); n     } n   } n   long long fns = 0; n   int m = min(a + b - 2, n); n   for (int i = 0; i < (a + b - 1); ++i) { n     if (ans[i] == -1) { n       continue; n     } n     fns += max(0, m + 1 - ans[i]); n   } n   if (n > a + b - 2) { n     m = n; n     for (int i = 0; i < (a); ++i) { n       if (ans[i] == -1) continue; n       int l = (m) / a; n       if (m % a >= i) l++; n       int d = -a; n       int st = m - i + 1; n       fns += 1ll * l * (2 * st + 1ll * (l - 1) * d) / 2; n     } n     m = a + b - 2; n     for (int i = 0; i < (a); ++i) { n       if (ans[i] == -1) continue; n       int l = (m) / a; n       if (m % a >= i) l++; n       int d = -a; n       int st = m - i + 1; n       fns -= 1ll * l * (2 * st + 1ll * (l - 1) * d) / 2; n     } n   } n   cout << fns; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n map<string, int> m; n string s; n string pr[109]; n int darab[109][26]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   cout <<  ?   << 1 <<     << n << endl; n   for (int i = 1; i <= (n * (n + 1)) / 2; i++) { n     cin >> s; n     sort(s.begin(), s.end()); n     m[s]++; n   } n   if (n == 1) { n     cout <<  !   << s << endl; n     return 0; n   } n   cout <<  ?   << 2 <<     << n << endl; n   for (int i = 1; i <= (n * (n - 1)) / 2; i++) { n     cin >> s; n     sort(s.begin(), s.end()); n     m[s]--; n   } n   auto it = m.begin(); n   while (it != m.end()) { n     if (it->second > 0) { n       pr[(it->first).size()] = (it->first); n     } n     it++; n   } n   for (int i = n; i >= 1; i--) { n     for (int j = 0; j < i; j++) { n       darab[i][pr[i][j] -  a ]++; n     } n   } n   string ans =   ; n   for (int i = 1; i <= n; i++) { n     int kul = 0; n     for (int j = 0; j < 26; j++) { n       if (darab[i][j] != darab[i - 1][j]) { n         kul = j; n         break; n       } n     } n     ans += ((char)( a  + kul)); n   } n   cout <<  !   << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long solve() { n   long long a, b; n   cin >> a >> b; n   long long m = b / 2 + 1; n   if (m > a) n     return b % m; n   else n     return b % a; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   ; n   long long t; 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 int n, m, mr; n vector<string> v; n string s, s2, tmp, res; n vector<pair<int, int> > e; n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> s; n     v.push_back(s); n   } n   sort(v.begin(), v.end()); n   for (int i = 0; i < m; i++) { n     cin >> s >> s2; n     int a; n     for (a = 0; a < n; a++) n       if (v[a] == s) break; n     int b; n     for (b = 0; b < n; b++) n       if (v[b] == s2) break; n     e.push_back(make_pair(a, b)); n   } n   int mx = (int)pow(2.0, n); n   for (int x = mx - 1; x > 0; x--) { n     bool f = true; n     for (int i = 0; i < e.size(); i++) { n       int e1 = n - e[i].first - 1, e2 = n - e[i].second - 1; n       if ((x >> e1 & 1) && (x >> e2 & 1)) f = false; n     } n     if (f) { n       int amx = mx; n       int r = 0; n       for (int o = 0; o < n; o++) { n         if (x & (mx >> 1)) r++; n         mx /= 2; n       } n       mx = amx; n       tmp =   ; n       for (int o = 0; o < n; o++) { n         if (x & (mx >> 1)) tmp += v[o] +   n ; n         mx /= 2; n       } n       mx = amx; n       if (r > mr) res = tmp, mr = r; n     } n   } n   cout << mr << endl; n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const long long int INF = 9e18 + 2e17; n const int inf = 2e9; n const int N = 1e5 + 22; n const double eps = 1e-10; n bool cmp(pair<int, int> A, pair<int, int> B) { n   if (A.first != B.first) return A.first < B.first; n   return A.second > B.second; n } n void _solve() { n   int n, m; n   cin >> n >> m; n   pair<int, int> sr[n]; n   for (int i = (int)0; i < (int)n; i++) cin >> sr[i].first >> sr[i].second; n   sort(sr, sr + n, cmp); n   int c = 0; n   for (int i = 0; i < n;) { n     int x = sr[i].first; n     while (i < n && x == sr[i].first) i++; n     c++; n   } n   vector<vector<int> > row_sum(c); n   vector<int> tot_sum; n   int p = 0; n   for (int i = 0; i < n;) { n     int x = sr[i].first, sum = 0; n     while (i < n && x == sr[i].first) { n       sum += sr[i].second; n       i++; n       if (sum <= 0) continue; n       row_sum[p].push_back(sum); n     } n     if (!row_sum[p].empty()) p++; n   } n   pair<int, int> row_sz[p]; n   for (int i = (int)0; i < (int)p; i++) row_sz[i] = {row_sum[i].size(), i}; n   sort(row_sz, row_sz + p); n   for (int y = 0, i = 0; y < p;) { n     int x = row_sz[y].first; n     while (i < x) { n       int sum = 0; n       for (int j = (int)y; j < (int)p; j++) sum += row_sum[row_sz[j].second][i]; n       tot_sum.push_back(sum); n       i++; n     } n     while (x == row_sz[y].first) y++; n   } n   int ans = 0; n   for (int i = (int)0; i < (int)tot_sum.size(); i++) ans = max(ans, tot_sum[i]); n   cout << ans; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   _solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, cnt; n vector<int> a[150004]; n int num[150004], sl[150004]; n int d[150004]; n void DFS(int u) { n   num[u] = cnt; n   for (int i = 0; i < a[u].size(); i++) n     if (num[a[u][i]] == 0) DFS(a[u][i]); n } n int main() { n   ios::sync_with_stdio(0); n   cin >> n >> m; n   while (m--) { n     int u, v; n     cin >> u >> v; n     d[u]++, d[v]++; n     a[u].push_back(v); n     a[v].push_back(u); n   } n   for (int u = 1; u <= n; u++) n     if (num[u] == 0) { n       cnt++; n       DFS(u); n     } n   for (int i = 1; i <= n; i++) sl[num[i]]++; n   for (int i = 1; i <= n; i++) n     if (d[i] != sl[num[i]] - 1) { n       cout <<  NO ; n       return 0; n     } n   cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool arng(pair<long long, long long> p, pair<long long, long long> q) { n   if (p.first > q.first) return true; n   if (p.first == q.first) { n     return (p.second < q.second); n   } n   return false; n } n void solve() { n   long long n, m; n   cin >> n; n   long long ac[n]; n   pair<long long, long long> a[n]; n   for (long long i = 0; i < n; i++) { n     cin >> a[i].first; n     ac[i] = a[i].first; n     a[i].second = i; n   } n   sort(a, a + n, arng); n   cin >> m; n   while (m--) { n     long long k, pos; n     cin >> k >> pos; n     long long s = 0; n     long long posa[k]; n     for (long long i = 0; i < k; i++) { n       posa[i] = a[i].second; n     } n     sort(posa, posa + k); n     cout << ac[posa[pos - 1]] << endl; n   } n   return; n } n int32_t main() { solve(); } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int arr[n + 1]; n     for (int i = 1; i <= n; i++) cin >> arr[i]; n     sort(arr + 1, arr + n + 1); n     int dp[n + 1][405]; n     for (int i = 0; i <= n; i++) n       for (int j = 0; j < 405; j++) dp[i][j] = 1000000; n     for (int j = 0; j < 405; j++) dp[0][j] = 0; n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j < 405; j++) { n         dp[i][j] = min(dp[i][j - 1], dp[i - 1][j - 1] + abs(j - arr[i])); n       } n     } n     cout << dp[n][404] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int N = 1e6 + 5; n using namespace std; n int n, k, a[N], cnt[N], Min = N; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> k; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     Min = min(Min, a[i]); n     cnt[a[i]]++; n   } n   for (int i = 1; i < N; i++) cnt[i] += cnt[i - 1]; n   for (int i = Min; i > k; i--) { n     bool ck = 0; n     int j; n     for (j = i; j < N; j += i) { n       if (cnt[j - 1] - cnt[j - i + k]) { n         ck = 1; n         break; n       } n     } n     if (j - i + k < N && cnt[N - 1] - cnt[j - i + k]) ck = 1; n     if (!ck) return cout << i, 0; n   } n   cout << min(Min, k) <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int a[n]; n   for (long long i = 0; i < n; i++) cin >> a[i]; n   int ans = 1e9; n   for (long long i = 0; i < n; i++) { n     int j = max(n - i - 1, i); n     int k; n     if (i - j < 0) n       k = min(a[n - 1], a[i]); n     else n       k = min(a[0], a[j]); n     int cans = k / j; n     ans = min(ans, cans); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }; n   int n, cnt = 0; n   cin >> n; n   while (n) { n     if (n >= 100) { n       cnt += n / 100; n       n %= 100; n     } n     if (n >= 20) { n       cnt += n / 20; n       n %= 20; n     } n     if (n >= 10) { n       cnt += n / 10; n       n %= 10; n     } n     if (n >= 5) { n       cnt += n / 5; n       n %= 5; n     } n     if (n >= 1) { n       cnt += n; n       n = 0; n     } n   } n   cout << cnt; n } n


#include <bits/stdc++.h> n using namespace std; n int dx[] = {0, 1, 0, -1}; n int dy[] = {1, 0, -1, 0}; n string blank =   ; n const int N = 2e5 + 10; n vector<double> arr(N); n int n; n vector<double> can(double mid) { n   vector<double> ans; n   vector<double>::iterator i = arr.begin(); n   ans.push_back(min(arr[n - 1], *i + mid)); n   i = upper_bound(arr.begin(), arr.begin() + n, *i + (mid * 2)); n   if (i == arr.begin() + n) i = arr.begin() + n - 1; n   ans.push_back(min(arr[n - 1], *i + mid)); n   i = upper_bound(arr.begin(), arr.begin() + n, *i + (mid * 2)); n   if (i == arr.begin() + n) i = arr.begin() + n - 1; n   ans.push_back(min(arr[n - 1], *i + mid)); n   if (ans[2] + mid < arr[n - 1]) ans.clear(); n   return ans; n } n void solve() { n   cin >> n; n   for (long long i = (0); i < (n); i++) cin >> arr[i]; n   sort(arr.begin(), arr.begin() + n); n   double l = 0, r = arr[n - 1] - arr[0], mid; n   int rep = 100; n   vector<double> ans; n   while (rep--) { n     mid = l + ((r - l) / 2.0); n     vector<double> res = can(mid); n     if (!res.empty()) n       r = mid, ans = res; n     else n       l = mid; n   } n   cout << fixed << setprecision(6) << l <<   n ; n   for (long long i = (0); i < (3); i++) n     cout << fixed << setprecision(6) << ans[i] <<    ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n const long long INF = 2e18; n void print(int a[], int n) { n   for (int i = 0; i < n; i++) cout << a[i] <<    ; n   cout <<   n ; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int tc = 1; n jump: n   while (tc--) { n     int n, k; n     cin >> n >> k; n     string s; n     cin >> s; n     string t =   ; n     for (int i = 0; i < (n); i++) { n       if (k == 0) { n         for (int j = i; j < n; j++) t += s[j]; n         break; n       } n       int f =  z  - s[i]; n       int b = s[i] -  a ; n       if (f > b) { n         int x = s[i] + min(f, k); n         t += (char)x; n         k -= min(f, k); n       } else { n         int x = s[i] - min(b, k); n         t += (char)x; n         k -= min(b, k); n       } n     } n     if (k > 0) n       cout << -1; n     else n       cout << t; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 10e18; n map<long long, long long> mp; n int main() { n   int t; n   cin >> t; n   long long int type, u, v, w; n   while (t--) { n     scanf( %lld , &type); n     if (type == 1) { n       scanf( %lld%lld%lld , &u, &v, &w); n       while (u != v) { n         if (u > v) n           mp[u] += w, u /= 2; n         else n           mp[v] += w, v /= 2; n       } n     } else { n       scanf( %lld%lld , &u, &v); n       long long ans = 0; n       while (u != v) { n         if (u > v) n           ans += mp[u], u /= 2; n         else n           ans += mp[v], v /= 2; n       } n       printf( %lld n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct triplet { n   int first, second, third; n } per[1005]; n pair<int, int> pr[1005 / 2][1005], s[1005 / 2]; n int n, a[1005], dp[1005], k, l, ind[1005 / 2][1005], indice, minim = 1 << 30, n                                                              pas; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= n + 2; i++) dp[i] = 1 << 30; n   pas = 1; n   per[1] = {1, 2, 3}; n   dp[1] = 0; n   while (pas + 2 <= n) { n     ++k; n     for (int i = 1; i <= pas; i++) { n       if (dp[pas + 1] > dp[i] + max(a[per[i].first], a[per[i].third])) { n         dp[pas + 1] = dp[i] + max(a[per[i].first], a[per[i].third]); n         pr[k][pas + 1] = {per[i].first, per[i].third}; n         ind[k][pas + 1] = i; n       } n       if (dp[pas + 2] > dp[i] + max(a[per[i].first], a[per[i].second])) { n         dp[pas + 2] = dp[i] + max(a[per[i].first], a[per[i].second]); n         pr[k][pas + 2] = {per[i].first, per[i].second}; n         ind[k][pas + 2] = i; n       } n       dp[i] = dp[i] + max(a[per[i].second], a[per[i].third]); n       pr[k][i] = {per[i].second, per[i].third}; n       ind[k][i] = i; n       per[i] = {i, pas + 3, pas + 4}; n     } n     per[pas + 1] = {pas + 1, pas + 3, pas + 4}; n     per[pas + 2] = {pas + 2, pas + 3, pas + 4}; n     pas += 2; n   } n   l = 1; n   for (int i = 1; i <= pas; i++) n     if (dp[i] + max(a[per[i].first], a[per[i].second]) < minim) { n       minim = dp[i] + max(a[per[i].first], a[per[i].second]); n       s[l] = {per[i].first, per[i].second}; n       indice = i; n     } n   for (int i = k; i >= 1; i--) { n     s[++l] = pr[i][indice]; n     indice = ind[i][indice]; n   } n   cout << minim <<   n ; n   for (int i = l; i > 1; i--) cout << s[i].first <<     << s[i].second <<   n ; n   if (n % 2 == 0) n     cout << s[1].first <<     << s[1].second; n   else n     cout << s[1].first; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000005; n const int MD = 1000 * 1000 * 1000 + 7; n vector<int> g[maxn]; n long long dp[maxn][2], mult[maxn][2], ans, cnt[maxn]; n bool visited[maxn]; n int binPow(int a, int b) { n   if (!b) return 1; n   if (b & 1) { n     return (1LL * binPow(a, b - 1) * a) % MD; n   } else { n     int half = binPow(a, b / 2); n     return (1LL * half * half) % MD; n   } n } n long long inv(int a) { return binPow(a, MD - 2); } n void dfs(int v) { n   cnt[v] = 1; n   visited[v] = true; n   mult[v][0] = mult[v][1] = 1; n   for (int i = 0; i < g[v].size(); i++) { n     int to = g[v][i]; n     if (visited[to]) continue; n     dfs(to); n     cnt[v] += cnt[to]; n     mult[v][0] *= dp[to][0]; n     mult[v][0] %= MD; n     mult[v][1] *= dp[to][1]; n     mult[v][1] %= MD; n   } n   if (cnt[v] == 1) { n     dp[v][0] = dp[v][1] = 1; n   } else { n     dp[v][0] = (mult[v][0] + mult[v][1]) % MD; n     dp[v][1] = (mult[v][0] + mult[v][1]) % MD; n   } n } n void set_root(int v, int to) { n   cnt[v] -= cnt[to]; n   cnt[to] += cnt[v]; n   mult[v][0] *= inv(dp[to][0]); n   mult[v][0] %= MD; n   mult[v][1] *= inv(dp[to][1]); n   mult[v][1] %= MD; n   if (cnt[v] > 1) { n     dp[v][0] = (mult[v][0] + mult[v][1]) % MD; n     dp[v][1] = (mult[v][0] + mult[v][1]) % MD; n   } else { n     dp[v][0] = dp[v][1] = 1; n   } n   mult[to][0] *= dp[v][0]; n   mult[to][0] %= MD; n   mult[to][1] *= dp[v][1]; n   mult[to][1] %= MD; n   dp[to][0] = (mult[to][0] + mult[to][1]) % MD; n   dp[to][1] = (mult[to][0] + mult[to][1]) % MD; n } n void calc(int v, int parent) { n   ans += dp[v][0]; n   if (ans >= MD) ans -= MD; n   for (auto to : g[v]) { n     if (to == parent) continue; n     set_root(v, to); n     calc(to, v); n     set_root(to, v); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     int u, v; n     cin >> u >> v; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   ans = 0; n   memset(visited, false, sizeof(visited)); n   dfs(1); n   calc(1, 0); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   int a[n]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   int m = 1e9; n   for (int i = 0; i < n; i++) n     if (s[i] ==  R  && s[i + 1] ==  L ) m = min(m, (a[i + 1] - a[i]) / 2); n   if (m == 1e9) n     cout << -1 << endl; n   else n     cout << m << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string f0 = n      What are you doing at the end of the world? Are you busy? Will you save   n      us? ; n string fi1 =  What are you doing while sending   ; n string fi2 =   ? Are you busy? Will you send   ; n string fi3 =   ? ; n string ff = n      What are you doing while sending  What are you doing at the end of the   n      world? Are you busy? Will you save us? ? Are you busy? Will you send   n       What are you doing at the end of the world? Are you busy? Will you save   n      us? ? ; n string answer; n long long l0, li1, li2, li3; n long long q, n, k, maxn = 53; n long long len[54]; n void prep() { n   l0 = f0.size(); n   li1 = fi1.size(); n   li2 = fi2.size(); n   li3 = fi3.size(); n   len[0] = l0; n   for (int i = 1; i <= maxn; i++) { n     len[i] = 2 * len[i - 1] + li1 + li2 + li3; n   } n } n char ans(long long n, long long k) { n   if (n > maxn) n     return k <= (n - maxn) * li1 ? fi1[(k - 1) % li1] n                                  : ans(maxn, k - (n - maxn) * li1); n   if (k > len[n]) return  . ; n   if (n == 0) return f0[k - 1]; n   if (k <= li1) return fi1[k - 1]; n   if (k <= li1 + len[n - 1]) return ans(n - 1, k - li1); n   if (k <= li1 + len[n - 1] + li2) return fi2[k - li1 - len[n - 1] - 1]; n   if (k <= li1 + len[n - 1] + li2 + len[n - 1]) n     return ans(n - 1, k - li1 - len[n - 1] - li2); n   return fi3[k - li1 - len[n - 1] - li2 - len[n - 1] - 1]; n } n int main() { n   prep(); n   cin >> q; n   for (int i = 1; i <= q; i++) { n     cin >> n >> k; n     answer += ans(n, k); n   } n   cout << answer << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC optimize( -O3 ) n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int a1, a2, k1, k2, n; n   cin >> a1 >> a2 >> k1 >> k2 >> n; n   if (k1 > k2) { n     swap(a1, a2); n     swap(k1, k2); n   } n   if (n <= a1 * (k1 - 1) + a2 * (k2 - 1)) { n     cout <<  0  ; n   } else { n     cout << n - (a1 * (k1 - 1) + a2 * (k2 - 1)) <<    ; n   } n   long long int ans = n / k1; n   n = n % k1; n   if (ans > a1) { n     n += (ans - a1) * k1; n     ans = a1; n   } n   ans += n / k2; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long t, a, b, c, d; n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> t; n   while (t--) { n     cin >> a >> b >> c >> d; n     long long l = 0, r = (c + d - 1) / d; n     while (l < r) { n       long long mid = l + r + 1 >> 1; n       long long sum1 = (mid + 1) * mid / 2 * d * b - (mid + 1) * a; n       if (mid == (c + d - 1) / d) sum1 -= (mid * d - c) * b; n       long long sum2 = (mid - 1) * mid / 2 * d * b - mid * a; n       if (sum1 >= sum2) n         r = mid - 1; n       else n         l = mid; n     } n     if (l == (c + d - 1) / d) n       cout <<  -1 n ; n     else { n       long long sum = (l + 1) * l / 2 * d * b - (l + 1) * a; n       cout << -sum <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n void show() {} n template <typename T, typename... V> n void show(T t, V... v) { n   cerr << t; n   if (sizeof...(v)) cerr <<  ,  ; n   show(v...); n } n template <class X> n bool mini(X& a, const X& b) { n   if (a > b) { n     a = b; n     return true; n   } n   return false; n } n template <class X> n bool maxi(X& a, const X& b) { n   if (a < b) { n     a = b; n     return true; n   } n   return false; n } n typedef const int& ci; n int n; n int dp[1 << 24]; n void enter() { n   cin >> n; n   for (int i = 1, _b = (n) + 1; i < _b; ++i) { n     char a, b, c; n     cin >> a >> b >> c; n     ++dp[(1 << a -  a ) | (1 << b -  a ) | (1 << c -  a )]; n   } n } n void solve() { n   int MASK = (1 << 24); n   for (int i = 0; i < 24; ++i) n     for (int mask = 0; mask < MASK; ++mask) n       if (mask >> i & 1) dp[mask] += dp[mask ^ (1 << i)]; n   int res = 0; n   for (int mask = 0; mask < MASK; ++mask) n     if (dp[mask] != n) res ^= (n - dp[mask]) * (n - dp[mask]); n   cout << res; n } n int main() { n   ios_base ::sync_with_stdio(false); n   cin.tie(nullptr); n   enter(); n   solve(); n   cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms ; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long int> adj[101]; n set<pair<long long int, long long int>> color[101]; n long long int visited[101]; n long long int x; n void bfs(long long int a, long long int b, long long int c) { n   queue<long long int> q; n   q.push(a); n   while (!q.empty()) { n     long long int p = q.front(); n     q.pop(); n     if (p == b) { n       x = 1; n       visited[p] = 1; n     } n     if (visited[p]) continue; n     visited[p] = 1; n     for (long long int i = 0; i < adj[p].size(); i++) { n       if (color[c].find({p, adj[p][i]}) != color[c].end()) { n         q.push(adj[p][i]); n       } n     } n   } n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int i, j, k, l, m, n, p, t, a, b, c, q; n   cin >> n >> m; n   set<pair<long long int, long long int>> s; n   for (i = 0; i < m; i++) { n     cin >> a >> b >> c; n     if (s.find({a, b}) == s.end()) { n       s.insert({a, b}); n       adj[a].push_back(b); n       adj[b].push_back(a); n     } n     color[c].insert({a, b}); n     color[c].insert({b, a}); n   } n   cin >> q; n   for (i = 0; i < q; i++) { n     cin >> a >> b; n     p = 0; n     for (j = 1; j <= m; j++) { n       x = 0; n       bfs(a, b, j); n       p += x; n       memset(visited, 0, sizeof(visited)); n     } n     cout << p <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, g; n int a[100010]; n int gcd(int x, int y) { n   if (y == 0) return x; n   return gcd(y, x % y); n } n bool used[100010]; n int main() { n   scanf( %d%d , &n, &k); n   g = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     a[i] %= k; n     g = gcd(g, a[i]); n     g = gcd(g, k - a[i]); n   } n   int cnt = 0; n   for (int i = 0; i < k; i += g) { n     if (used[i] == 1) break; n     used[i] = 1; n     cnt++; n   } n   printf( %d n , cnt); n   for (int i = 0; i < k; i++) n     if (used[i] == 1) printf( %d  , i); n } n


#include <bits/stdc++.h> n using namespace std; n int a[109]; n int main() { n   int n, m; n   while (cin >> n >> m) { n     for (int i = 0; i < n; i++) cin >> a[i]; n     int p = 0; n     sort(a, a + n); n     for (int i = 0; i < n; i++) { n       int flag = 0; n       while (a[i]) { n         if (a[i] % 10 == 4 || a[i] % 10 == 7) flag++; n         a[i] /= 10; n       } n       if (flag <= m) p++; n     } n     cout << p << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a; n   cin >> a; n   for (int i = 0; i < a; i++) { n     int c = 0; n     int j; n     cin >> j; n     int f = j % 10; n     if (j > 1) f = (f - 1) * 10; n     if (j > 1000) { n       f = f + 10; n     } else if (j > 100) { n       f = f + 6; n     } else if (j > 10) { n       f = f + 3; n     } else if (j > 1 && j < 10) { n       f = f + 1; n     } n     cout << f << endl; n   } n } n


#include<bits/stdc++.h> n using namespace std; n #define size(v) (int)v.size() n #define all(v) (v).begin(),(v).end() n using lint = long long; n using fint = long double; n const int INF = 1e9 + 9; n const int MOD = 998244353; n  n int n, a[200000]; n  n int solve(){ n     int ret = 0; n  n     // pp...p cc...c n     lint psum = 0, sum = accumulate(a,a+n,0ll); n     for(int i=0;i<n;++i){ n         psum += a[i]; n         if(psum > sum - psum) n             ret++; n     } n  n     // cc...c pcpc...pc pp...p n     //      i         ^ (lower bonud) n     auto f = [&](vector<int> a,lint base){ n         vector<lint> pa, ev, od; n         for(int i=0;i<size(a);++i) pa.push_back(a[i]); n         for(int i=0;i<size(a)-1;i+=2) ev.push_back(a[i]); n         for(int i=1;i<size(a)-1;i+=2) od.push_back(a[i]); n         for(int i=1;i<size(pa);++i) pa[i] += pa[i-1]; n         for(int i=1;i<size(ev);++i) ev[i] += ev[i-1]; n         for(int i=1;i<size(od);++i) od[i] += od[i-1]; n         for(int i=0;i<size(a)-1;++i){ n             vector<lint> &oe = (i&1 ? od : ev); n             lint dff = base + pa[size(a)-1] - pa[i] - pa[i]; n             int cnt = lower_bound(all(oe), oe[i/2] + (dff+1)/2) - lower_bound(all(oe), oe[i/2]); n             if(dff > 0) ret = (ret + cnt) % MOD; n         } n     }; n  n     // Case1: cc...c pcpc...pc pp...p n     if(1 < n) f(vector<int>(a,a+n), 0); n     // Case2: cc...c pcpc...pc pp...p(c) n     if(2 < n) f(vector<int>(a,a+n-1), -a[n-1]); n     // Case3: (p)ccc...c pcpc...pc pp...p n     if(2 < n) f(vector<int>(a+1,a+n), a[0]); n     // Case4: (p)ccc...c pcpc...pc pp...p(c) n     if(3 < n) f(vector<int>(a+1,a+n-1), a[0]-a[n-1]); n  n     return ret; n  n } n  n int main(){ n     int tc; scanf( %d ,&tc); n     while(tc--){ n         scanf( %d ,&n); n         for(int i=0;i<n;++i) n             scanf( %d ,a+i); n         printf( %d n ,solve()); n     } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200005; n int n; n long long A[N]; n map<long long, long long> MP; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %lld , &A[i]); n   MP.insert({A[1] - 1, 0}); n   for (int i = 2; i <= n; i++) { n     long long B = -1; n     while (MP.rbegin()->first >= A[i]) { n       long long a = MP.rbegin()->first; n       long long b = MP.rbegin()->second; n       MP[a % A[i]] = max(MP[a % A[i]], b + a / A[i] * A[i] * (i - 1)); n       B = max(B, b + (a / A[i] - 1) * A[i] * (i - 1)); n       MP.erase(a); n     } n     if (B >= 0) MP[A[i] - 1] = max(MP[A[i] - 1], B); n   } n   long long MX = 0; n   for (auto X : MP) MX = max(MX, X.first * n + X.second); n   return !printf( %lld n , MX); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e6; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   long long a[n + 2]; n   a[0] = 0; n   long long sum = 0; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     if (a[i] > a[i - 1]) n       sum += (a[i] - a[i - 1]) * (n - a[i] + 1); n     else if (a[i] < a[i - 1]) n       sum += a[i] * (a[i - 1] - a[i]); n   } n   cout << sum << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n int num[maxn]; n int F[1010]; n int fnd(int t) { n   if (F[t] == t) return t; n   return F[t] = fnd(F[t]); n } n void join(int a, int b) { n   int t1 = fnd(a); n   int t2 = fnd(b); n   if (t1 != t2) F[t1] = t2; n } n int main() { n   int n, m, k; n   int cap[maxn]; n   cin >> n >> m >> k; n   memset(num, 0, sizeof(num)); n   memset(F, 0, sizeof(F)); n   for (int i = 1; i <= n; ++i) F[i] = i; n   for (int i = 1; i <= k; ++i) cin >> cap[i]; n   for (int i = 1, a, b; i <= m; ++i) { n     cin >> a >> b; n     join(a, b); n   } n   for (int i = 1; i <= n; ++i) num[fnd(i)]++; n   int maxn = 0, lef = n; n   int ans = 0; n   for (int i = 1; i <= k; ++i) { n     num[cap[i]] = num[fnd(cap[i])]; n     maxn = max(maxn, num[cap[i]]); n     lef -= num[cap[i]]; n     ans += (num[cap[i]] - 1) * (num[cap[i]]) / 2; n   } n   ans += (lef + maxn) * (lef + maxn - 1) / 2; n   ans -= maxn * (maxn - 1) / 2 + m; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 1000005; n int n, a[maxN], p[230], b[230]; n bool bo[1 << 22]; n void Init() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , a + i); n } n void Work() { n   int ans = 0; n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= 20; ++j) { n       while (p[j] <= n && (p[j] < i || ((a[p[j]] >> (j - 1)) & 1) == 0)) ++p[j]; n       b[j] = p[j]; n     } n     sort(b + 1, b + 1 + 20); n     int x = a[i]; n     if (!bo[x]) { n       ++ans; n       bo[x] = 1; n     } n     for (int j = 1; j <= 20; ++j) { n       x |= a[b[j]]; n       if (!bo[x]) { n         ++ans; n         bo[x] = 1; n       } n     } n   } n   cout << ans << endl; n } n int main() { n   Init(); n   Work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int T; n   cin >> T; n   while (T-- > 0) { n     long long n, k; n     cin >> n >> k; n     int m; n     for (m = 2; m <= n; m++) { n       if (n % m == 0) break; n     } n     long long ans = n + m + (k - 1) * 2; n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void read_file(bool outToFile = true) {} n struct point; n struct vec; n struct line; n struct circle; n struct triangle; n double to_rad(double theta); n double to_deg(double theta); n double dist(point p, point q); n point middle(point p, point q); n point translate(point p, vec u); n double norm_sq(vec u); n double dot(vec u, vec v); n double cross(vec u, vec v); n bool are_parallel(line l, line d); n bool are_same(line l, line d); n double dist_to_line(point p, point a, point b); n bool ccw(point p, point q, point r); n bool collinear(point p, point q, point r); n double angle(point a, point o, point b); n point rotate(point p, double theta, point q); n point intersection(line l, line d); n point projection(point p, point a, point b); n double dist_to_segment(point p, point a, point b); n point reflection(point p, point a, point b); n line perpendicular(point p, point a, point b); n line bisector(point a, point o, point b); n circle find_circle(point p, point q, double r); n circle in_circle(triangle t); n circle circum_circle(triangle t); n double perimeter(vector<point> P); n double area(vector<point> P); n bool is_convex(vector<point> P); n bool is_in(point p, vector<point> P); n vector<point> cut(vector<point> P, point a, point b); n bool ch_cmp(point a, point b); n vector<point> convex_hull(vector<point> P); n struct point { n   double x, y; n   point(double nx = 0, double ny = 0) { x = nx, y = ny; } n   bool operator==(point p) { n     return fabs(x - p.x) <= (1e-9) && fabs(y - p.y) <= (1e-9); n   } n   bool operator!=(point p) { n     return fabs(x - p.x) > (1e-9) || fabs(y - p.y) > (1e-9); n   } n   bool operator<(point p) { n     if (fabs(x - p.x) > (1e-9)) return x < p.x - (1e-9); n     return y < p.y - (1e-9); n   } n   friend istream &operator>>(istream &is, point &p) { return is >> p.x >> p.y; } n   friend ostream &operator<<(ostream &os, point &p) { n     return os << p.x <<     << p.y; n   } n }; n struct vec { n   double x, y; n   vec(double nx = 0, double ny = 0) { x = nx, y = ny; } n   vec(point p, point q) { x = q.x - p.x, y = q.y - p.y; } n   vec operator+(vec u) { return vec(x + u.x, y + u.y); } n   vec operator-(vec u) { return vec(x - u.x, y - u.y); } n   vec operator*(double k) { return vec(k * x, k * y); } n   friend istream &operator>>(istream &is, vec &u) { return is >> u.x >> u.y; } n   friend ostream &operator<<(ostream &os, vec &u) { n     return os << u.x <<     << u.y; n   } n }; n struct line { n   double a, b, c; n   line(double na = 0, double nb = 0, double nc = 0) { a = na, b = nb, c = nc; } n   line(point p, point q) { n     double dx = q.x - p.x; n     double dy = q.y - p.y; n     if (fabs(dx) <= (1e-9)) { n       a = 1, b = 0, c = -p.x; n       return; n     } n     a = -dy / dx; n     b = 1.0; n     c = dy / dx * p.x - p.y; n   } n   line(point p, double m) { n     a = -m; n     b = 1.0; n     c = -(a * p.x + p.y); n   } n   pair<point, point> to_points() { n     point p, q; n     if (fabs(b) <= (1e-9)) n       p.x = -c / a, q.x = p.x, p.y = 0, q.y = 1; n     else n       p.x = 0, q.x = 1, p.y = -(a * p.x + c), q.y = -(a * q.x + c); n     return make_pair(p, q); n   } n }; n struct circle { n   double x, y, r; n   circle(point c = point(0, 0), double nr = 0) { x = c.x, y = c.y, r = nr; } n   int is_in(point p) { n     double dx = p.x - x, dy = p.y - y; n     double d = dx * dx + dy * dy, R = r * r; n     return (d < R - (1e-9)) ? 0 : (fabs(d - R) <= (1e-9)) ? 1 : 2; n   } n   double perimeter(double theta = 360) { n     theta = to_rad(theta); n     return theta * r; n   } n   double area(double theta = 360) { n     theta = to_rad(theta); n     return theta * r * r / 2; n   } n }; n struct triangle { n   point A, B, C; n   double a, b, c; n   triangle(double na = 0, double nb = 0, double nc = 0) { n     a = na, b = nb, c = nc; n   } n   triangle(point nA, point nB, point nC) { n     A = nA, B = nB, C = nC; n     c = dist(A, B), a = dist(B, C), b = dist(C, A); n   } n   bool is_triangle() { n     return a + b > c + (1e-9) && b + c > a + (1e-9) && c + a > b + (1e-9); n   } n   double perimeter() { return a + b + c; } n   double area() { n     double s = perimeter() / 2; n     return sqrt(s * (s - a) * (s - b) * (s - c)); n   } n }; n double to_rad(double theta) { return theta * acos(-1.0) / 180; } n double to_deg(double theta) { return theta * 180 / acos(-1.0); } n double dist(point p, point q) { return hypot(p.x - q.x, p.y - q.y); } n point middle(point p, point q) { n   return point((p.x + q.x) / 2, (p.y + q.y) / 2); n } n point translate(point p, vec u) { return point(p.x + u.x, p.y + u.y); } n double norm_sq(vec u) { return u.x * u.x + u.y * u.y; } n double dot(vec u, vec v) { return u.x * v.x + u.y * v.y; } n double cross(vec u, vec v) { return u.x * v.y - u.y * v.x; } n bool are_parallel(line l, line d) { n   return fabs(l.a - d.a) <= (1e-9) && fabs(l.b - l.b) <= (1e-9); n } n bool are_same(line l, line d) { n   return are_parallel(l, d) && fabs(l.c - d.c) <= (1e-9); n } n double dist_to_line(point p, point a, point b) { n   return dist(p, projection(p, a, b)); n } n bool ccw(point p, point q, point r) { n   return cross(vec(p, q), vec(p, r)) > 0 + (1e-9); n } n bool collinear(point p, point q, point r) { n   return fabs(cross(vec(p, q), vec(p, r))) <= (1e-9); n } n double angle(point a, point o, point b) { n   vec oa = vec(o, a), ob = vec(o, b); n   return acos(dot(oa, ob) / sqrt(norm_sq(oa) * norm_sq(ob))); n } n point rotate(point p, double theta, point q = point(0, 0)) { n   vec oq = vec(point(0, 0), q); n   p = translate(p, oq * -1); n   theta = to_rad(theta); n   double x = p.x * cos(theta) - p.y * sin(theta); n   double y = p.x * sin(theta) + p.y * cos(theta); n   p = point(x, y); n   p = translate(p, oq); n   return p; n } n point intersection(line l, line d) { n   point p; n   p.x = (d.b * l.c - l.b * d.c) / (d.a * l.b - l.a * d.b); n   if (fabs(l.b) > (1e-9)) n     p.y = -(l.a * p.x + l.c); n   else n     p.y = -(d.a * p.x + d.c); n   return p; n } n point projection(point p, point a, point b) { n   vec ap = vec(a, p), ab = vec(a, b); n   double u = dot(ap, ab) / norm_sq(ab); n   return translate(a, ab * u); n } n double dist_to_segment(point p, point a, point b) { n   vec ap = vec(a, p), ab = vec(a, b); n   double u = dot(ap, ab) / norm_sq(ab); n   if (u < 0 - (1e-9)) return dist(p, a); n   if (u > 1 + (1e-9)) return dist(p, b); n   return dist_to_line(p, a, b); n } n point reflection(point p, point a, point b) { n   point c = projection(p, a, b); n   vec pc = vec(p, c); n   return translate(p, pc * 2); n } n line perpendicular(point p, point a, point b) { n   if (!collinear(p, a, b)) return line(p, projection(p, a, b)); n   line l = line(a, b); n   if (fabs(l.b) <= (1e-9)) return line(p, point(p.x + 1, p.y)); n   if (fabs(l.a) <= (1e-9)) return line(p, point(p.x, p.y + 1)); n   return line(p, 1 / l.a); n } n line bisector(point a, point o, point b) { n   double ratio = dist(o, a) / dist(o, b); n   ratio /= ratio + 1; n   vec ab = vec(a, b); n   point c = translate(a, ab * ratio); n   return line(o, c); n } n circle find_circle(point p, point q, double r) { n   point m = middle(p, q); n   vec mp = vec(m, p); n   double mc = r * r - norm_sq(mp); n   if (mc < 0 - (1e-9)) return circle(); n   mc = sqrt(mc); n   double u = mc / dist(m, p); n   point c = translate(m, mp * u); n   c = rotate(c, 90, m); n   return circle(c, r); n } n circle in_circle(triangle t) { n   double r = 2 * t.area() / t.perimeter(); n   if (fabs(r) <= (1e-9)) return circle(); n   line l = bisector(t.B, t.A, t.C); n   line d = bisector(t.C, t.B, t.A); n   point c = intersection(l, d); n   return circle(c, r); n } n circle circum_circle(triangle t) { n   double r = (t.a * t.b * t.c) / (4 * t.area()); n   if (fabs(r) <= (1e-9)) return circle(); n   line l = perpendicular(middle(t.A, t.B), t.A, t.B); n   line d = perpendicular(middle(t.A, t.C), t.A, t.C); n   point c = intersection(l, d); n   return circle(c, r); n } n point pivot; n double perimeter(vector<point> P) { n   int n = P.size(); n   double ret = 0; n   for (int i = 0; i < n - 1; i++) ret += dist(P[i], P[i + 1]); n   return ret; n } n double area(vector<point> P) { n   int n = P.size(); n   double ret = 0; n   double x1, x2, y1, y2; n   for (int i = 0; i < n - 1; i++) { n     x1 = P[i].x, x2 = P[i + 1].x; n     y1 = P[i].y, y2 = P[i + 1].y; n     ret += x1 * y2 - x2 * y1; n   } n   ret /= 2, ret = fabs(ret); n   return ret; n } n bool is_convex(vector<point> P) { n   int n = P.size(); n   if (n <= 3) return false; n   bool turn = ccw(P[0], P[1], P[2]); n   for (int i = 1; i < n - 1; i++) n     if (ccw(P[i], P[i + 1], P[i + 2 != n ? i + 2 : 1]) != turn) return false; n   return true; n } n bool is_in(point p, vector<point> P) { n   int n = P.size(); n   double sum = 0; n   for (int i = 0; i < n - 1; i++) n     if (ccw(P[i], p, P[i + 1])) n       sum += angle(P[i], p, P[i + 1]); n     else n       sum -= angle(P[i], p, P[i + 1]); n   sum = fabs(sum); n   return fabs(sum - 2 * acos(-1.0)) <= (1e-9); n } n vector<point> cut(vector<point> P, point a, point b) { n   int n = P.size(); n   vector<point> ret; n   for (int i = 0; i < n; i++) { n     double left1 = cross(vec(a, b), vec(a, P[i])); n     double left2 = (i != n - 1) ? cross(vec(a, b), vec(a, P[i + 1])) : 0; n     if (left1 >= -(1e-9)) ret.push_back(P[i]); n     if (left1 * left2 < -(1e-9)) n       ret.push_back(intersection(line(a, b), line(P[i], P[i + 1]))); n   } n   if (!ret.empty() && ret.front() != ret.back()) ret.push_back(ret.front()); n   return ret; n } n bool ch_cmp(point a, point b) { n   if (collinear(pivot, a, b)) return dist(pivot, a) < dist(pivot, b) - (1e-9); n   double dx1 = a.x - pivot.x, dy1 = a.y - pivot.y; n   double dx2 = b.x - pivot.x, dy2 = b.y - pivot.y; n   return atan2(dy1, dx1) < atan2(dy2, dx2) - (1e-9); n } n vector<point> convex_hull(vector<point> P) { n   int n = P.size(); n   if (n <= 3) { n     if (n != 0 && P[0] != P[n - 1]) P.push_back(P[0]); n     return P; n   } n   int idx = 0; n   for (int i = 1; i < n; i++) n     if (P[idx].y > P[i].y + (1e-9) || n         (fabs(P[idx].y - P[i].y) <= (1e-9) && P[idx].x < P[i].x - (1e-9))) n       idx = i; n   swap(P[0], P[idx]); n   pivot = P[0]; n   sort(P.begin() + 1, P.end(), ch_cmp); n   vector<point> ch; n   ch.push_back(P[n - 1]), ch.push_back(P[0]), ch.push_back(P[1]); n   int i = 2; n   while (i < n) { n     int j = ch.size() - 1; n     if (ccw(ch[j - 1], ch[j], P[i])) n       ch.push_back(P[i]), i++; n     else n       ch.pop_back(); n   } n   return ch; n } n void print(vector<point> P) { n   int n = P.size(); n   cout << endl; n   for (int i = 0; i < n; i++) cout << P[i] << endl; n   cout << endl; n } n int main() { n   read_file(); n   int x; n   while (cin >> x) { n     point p = point(0, 0); n     vector<point> P; n     P.push_back(p); n     vec u(1, 0); n     point q = translate(p, u * x); n     P.push_back(q); n     for (int i = 0; i < 5; i++) { n       cin >> x; n       u = vec(p, q); n       u = u * (1 / dist(p, q)); n       p = q; n       q = translate(q, u * x); n       q = rotate(q, 60, p); n       P.push_back(q); n     } n     P.push_back(point(0, 0)); n     double a = area(P); n     triangle t = triangle(1, 1, 1); n     double b = t.area(); n     int ans = a / b + 1e-6; n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void readi(int &x) { n   int v = 0, f = 1; n   char c = getchar(); n   while (!isdigit(c) && c !=  - ) c = getchar(); n   if (c ==  - ) n     f = -1; n   else n     v = v * 10 + c -  0 ; n   while (isdigit(c = getchar())) v = v * 10 + c -  0 ; n   x = v * f; n } n void readll(long long &x) { n   long long v = 0ll, f = 1ll; n   char c = getchar(); n   while (!isdigit(c) && c !=  - ) c = getchar(); n   if (c ==  - ) n     f = -1; n   else n     v = v * 10 + c -  0 ; n   while (isdigit(c = getchar())) v = v * 10 + c -  0 ; n   x = v * f; n } n void readc(char &x) { n   char c; n   while ((c = getchar()) ==    ) n     ; n   x = c; n } n void writes(string s) { puts(s.c_str()); } n void writeln() { writes(  ); } n void writei(int x) { n   if (!x) putchar( 0 ); n   char a[25]; n   int top = 0; n   while (x) { n     a[++top] = (x % 10) +  0 ; n     x /= 10; n   } n   while (top) { n     putchar(a[top]); n     top--; n   } n } n void writell(long long x) { n   if (!x) putchar( 0 ); n   char a[25]; n   int top = 0; n   while (x) { n     a[++top] = (x % 10) +  0 ; n     x /= 10; n   } n   while (top) { n     putchar(a[top]); n     top--; n   } n } n long long n, m, aa, b, i, j, k, mx[1005][1005], mx2[1005][1005], a[1005][1005], n     l, r, qx[1005][2], vis[1005][1005], c[1005][1005]; n vector<pair<long long, pair<int, int> > > s; n vector<pair<pair<int, int>, long long> > ans; n int main() { n   ios::sync_with_stdio(false); n   ; n   cin >> n >> m >> aa >> b; n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= m; j++) { n       cin >> a[i][j]; n       c[i][j] = c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1] + a[i][j]; n     } n   } n   for (i = 1; i <= n; i++) { n     k = 1; n     l = r = 0; n     for (j = 1; j <= m; j++) { n       while (k <= m && j + b > k) { n         while (l < r && qx[r - 1][0] >= a[i][k]) r--; n         qx[r][0] = a[i][k]; n         qx[r][1] = k; n         r++; n         k++; n       } n       while (l < r && qx[l][1] < j) l++; n       mx[i][j] = qx[l][0]; n     } n   } n   for (i = 1; i <= m; i++) { n     k = 1; n     l = r = 0; n     for (j = 1; j <= n; j++) { n       while (k <= n && j + aa > k) { n         while (l < r && qx[r - 1][0] >= mx[k][i]) r--; n         qx[r][0] = mx[k][i]; n         qx[r][1] = k; n         r++; n         k++; n       } n       while (l < r && qx[l][1] < j) l++; n       mx2[j][i] = qx[l][0]; n     } n   } n   for (i = 1; i + aa - 1 <= n; i++) { n     for (j = 1; j + b - 1 <= m; j++) { n       s.push_back(make_pair(c[i + aa - 1][j + b - 1] - c[i + aa - 1][j - 1] - n                                 c[i - 1][j + b - 1] + c[i - 1][j - 1] - n                                 mx2[i][j] * aa * b, n                             make_pair(i, j))); n     } n   } n   stable_sort((s).begin(), (s).end()); n   int pos = 0; n   while (pos < s.size()) { n     pair<long long, pair<int, int> > cur = s[pos]; n     pos++; n     i = cur.second.first, j = cur.second.second; n     if (vis[i][j]) continue; n     for (int xx = max(i - aa + 1, 1ll); xx <= i + aa - 1 && xx <= n; xx++) { n       for (int yy = max(j - b + 1, 1ll); yy <= j + b - 1 && yy <= m; yy++) { n         vis[xx][yy] = 1; n       } n     } n     ans.push_back(make_pair(make_pair(i, j), cur.first)); n   } n   writell((long long)ans.size()); n   writeln(); n   for (i = 0; i < ans.size(); i++) n     printf( %d %d %I64d n , ans[i].first.first, ans[i].first.second, n            ans[i].second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9 + 3; n const long long linf = (long long)inf * inf + 2; n int N, K; n struct TrieNode { n   TrieNode *children[26]; n   bool canWin, canLose; n   TrieNode() { n     canWin = canLose = false; n     for (int i = 0; i < 26; ++i) children[i] = nullptr; n   } n }; n TrieNode *root; n struct Trie { n   Trie() { root = new TrieNode(); } n   void insert(string &key, int idx = 0, TrieNode *pCrawl = root) { n     if (idx == (int)key.length()) return; n     int charId = key[idx] -  a ; n     if (pCrawl->children[charId] == nullptr) n       pCrawl->children[charId] = new TrieNode(); n     insert(key, idx + 1, pCrawl->children[charId]); n   } n   void precompute(TrieNode *pCrawl = root) { n     bool hasChildren = false; n     for (int i = 0; i < 26; ++i) n       if (pCrawl->children[i] != nullptr) { n         hasChildren = true; n         precompute(pCrawl->children[i]); n         if (!pCrawl->children[i]->canWin) pCrawl->canWin = true; n         if (!pCrawl->children[i]->canLose) pCrawl->canLose = true; n       } n     if (!hasChildren) pCrawl->canLose = true; n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> N >> K; n   Trie myTrie = Trie(); n   string str; n   for (int i = 0; i < N; ++i) { n     cin >> str; n     myTrie.insert(str); n   } n   myTrie.precompute(); n   bool canForceWin = root->canWin, canForceLose = root->canLose; n   if (canForceWin && canForceLose) n     cout <<  First n ; n   else if (canForceWin) n     cout << (K % 2 ?  First n  :  Second n ); n   else n     cout <<  Second n ; n   return 0; n } n