#include <bits/stdc++.h> n using namespace std; n void DEBUG(vector<long long> a) { n   printf( { ); n   for (long long x : a) printf( %lld  , x); n   printf( } n ); n } n int mod; n void DEBUG(long long mask) { n   printf( mask:  ); n   for (int i = 0; i < mod; ++i) printf( %d , (mask >> i) & 1); n   printf(  n ); n } n struct TorSum { n   int n, m; n   long long** a; n   long long** pref; n   TorSum(){}; n   TorSum(long long** _a) : n(mod), m(mod) { n     a = new long long*[n]; n     for (int i = 0; i < n; ++i) { n       a[i] = new long long[m]; n       for (int j = 0; j < m; ++j) a[i][j] = _a[i][j]; n     } n     pref = new long long*[n + 1]; n     for (int i = 0; i <= n; ++i) { n       pref[i] = new long long[m + 1]; n       for (int x = 0; x < mod; ++x) pref[i][x] = 0; n     } n     for (int i = 0; i < n; ++i) n       for (int j = 0; j < m; ++j) n         pref[i + 1][j + 1] = n             a[i][j] + pref[i + 1][j] + pref[i][j + 1] - pref[i][j]; n   } n   long long stupid(int lx, int rx, int ly, int ry) { n     if (lx == -1 || rx == -1 || ly == -1 || ry == -1) return 0; n     long long res = 0; n     for (int x = lx;; x = (x + 1) % n) { n       for (int y = ly;; y = (y + 1) % m) { n         res += a[x][y]; n         if (y == ry) break; n       } n       if (x == rx) break; n     } n     return res; n   } n   long long get_sum_safe(int lx, int rx, int ly, int ry) { n     return pref[rx][ry] - pref[rx][ly] - pref[lx][ry] + pref[lx][ly]; n   } n   long long get_sum(int lx, int rx, int ly, int ry) { n     if (lx == -1 || rx == -1 || ly == -1 || ry == -1) return 0; n     if (lx <= rx) { n       if (ly <= ry) { n         return get_sum_safe(lx, rx + 1, ly, ry + 1); n       } n       return get_sum_safe(lx, rx + 1, 0, m) - n              get_sum_safe(lx, rx + 1, ry + 1, ly); n     } else { n       if (ly <= ry) { n         return get_sum_safe(0, n, ly, ry + 1) - n                get_sum_safe(rx + 1, lx, ly, ry + 1); n       } n       return get_sum_safe(0, n, 0, m) - get_sum_safe(0, n, ry + 1, ly) - n              get_sum_safe(rx + 1, lx, 0, m) + n              get_sum_safe(rx + 1, lx, ry + 1, ly); n     } n   } n }; n int mlog(long long r, long long d) { n   int k = 0; n   for (long long pw = 1; pw <= r / d; ++k) pw *= d; n   return k; n } n long long mpow(long long x, int k) { n   long long res = 1; n   while (k--) res *= x; n   return res; n } n int a[66]; n vector<pair<int, int>> split_segment(long long mask) { n   int n = mod; n   int cnt = 0; n   for (int i = 0; i < n; ++i) { n     a[i] = (mask >> i) & 1; n     cnt += a[i]; n   } n   if (cnt == 0) return {}; n   if (cnt == n) return {{0, n - 1}}; n   vector<pair<int, int>> res; n   for (int i = 0; i < n; ++i) { n     int l = i; n     while (l < n && !a[l]) ++l; n     if (l == n) break; n     int r = l; n     while (r < n && a[r]) ++r; n     res.push_back({l, r - 1}); n     i = r; n   } n   if (res[0].first == 0 && res.back().second == n - 1) { n     int r = res[0].second; n     int l = res.back().first; n     res.erase(res.begin()); n     res.erase(--res.end()); n     res.push_back({l, r}); n   } n   return res; n } n const int D = 22; n const int MOD = 66; n const int N = 30000; n const int LOG = 16; n using Zet = long long*; n int d; n int logn; n int gen[D]; n vector<int> big_gen; n long long pwd[66]; n long long jump[N][LOG]; n pair<vector<pair<int, int>>, vector<pair<int, int>>> segments[N * D]; n void add(Zet arr, Zet to_add, int shift) { n   for (int i = 0; i + shift < mod; ++i) arr[i] += to_add[i + shift]; n   for (int i = mod - shift; i < mod; ++i) arr[i] += to_add[i + shift - mod]; n } n Zet zeroes; n unordered_map<long long, Zet> cnt; n Zet get_cnt(long long r) { n   if (r <= 0) return zeroes; n   if (cnt.count(r)) return cnt[r]; n   Zet res = new long long[mod]; n   for (int x = 0; x < mod; ++x) res[x] = 0; n   int k = mlog(r, d); n   long long dk = mpow(d, k); n   if (dk == r) dk /= d; n   int i = 0; n   for (; r >= (i + 1) * dk; ++i) add(res, get_cnt(dk), (mod - gen[i]) % mod); n   add(res, get_cnt(r - i * dk), (mod - gen[i % d]) % mod); n   cnt[r] = res; n   return res; n }; n void inters(long long& mask1, long long mask2, int shift) { n   long long shift_mask = mask2 & ((1LL << shift) - 1); n   mask1 &= ((mask2 >> shift) | (shift_mask << (mod - shift))); n } n long long query(int l, int r, int pos) { n   long long res = (1LL << mod) - 1; n   while (l != r) { n     for (int i = logn;; --i) { n       if (l % pwd[i] == 0 && l + pwd[i] <= r) { n         inters(res, jump[pos][i], big_gen[l]); n         l += pwd[i]; n         pos += pwd[i]; n         break; n       } n     } n   } n   return res; n }; n unordered_map<long long, TorSum> solver; n long long get_sum(long long R, int lx, int rx, int ly, int ry) { n   if (!solver.count(R)) { n     Zet* a = new Zet[mod]; n     for (int i = 0; i < mod; ++i) { n       a[i] = new long long[mod]; n       for (int x = 0; x < mod; ++x) a[i][x] = 0; n     } n     for (int i = 0; pwd[i] - 1 <= R; ++i) { n       for (int digit = 0; digit < d - 1; ++digit) { n         if (R < (digit + 1) * pwd[i] - 1) break; n         Zet kek = get_cnt((R - (digit + 1) * pwd[i] + 1) / pwd[i + 1] + 1); n         for (int r = 0; r < mod; ++r) n           a[(r + gen[digit] + i * gen[d - 1]) % mod] n            [(r + gen[digit + 1]) % mod] += kek[r]; n       } n     } n     solver[R] = TorSum(a); n   } n   return solver[R].get_sum(lx, rx, ly, ry); n }; n long long solve(long long R) { n   long long res = 0; n   for (int rem = 0; rem < pwd[logn] && rem <= R; ++rem) { n     vector<pair<int, int>>& v1 = segments[rem].first; n     vector<pair<int, int>>& v2 = segments[rem].second; n     for (auto& [lx, rx] : v1) n       for (auto& [ly, ry] : v2) n         res += get_sum((R - rem) / pwd[logn], lx, rx, ly, ry); n   } n   return res; n }; n int main() { n   scanf( %d %d , &d, &mod); n   for (int i = 0; i < d; ++i) scanf( %d , &gen[i]); n   int n; n   scanf( %d , &n); n   vector<int> a(n); n   for (int i = 0; i < n; ++i) scanf( %d , &a[i]); n   logn = 1; n   for (int i = 0; i < d; ++i) big_gen.push_back(gen[i]); n   for (; (int)(big_gen).size() < n; ++logn) { n     vector<int> new_big_gen; n     for (int i = 0; i < d; ++i) { n       for (int x : big_gen) new_big_gen.push_back((x + gen[i]) % mod); n     } n     big_gen = new_big_gen; n   } n   int pos = 0; n   pwd[pos] = 1; n   while (pwd[pos] < (long long)4e17) { n     long long x = d * pwd[pos]; n     pwd[++pos] = x; n   } n   int start, end; n   double time; n   start = clock(); n   for (int i = n - 1; i >= 0; --i) { n     jump[i][0] = (1LL << (a[i] + 1)) - 1; n     for (int k = 1; i + pwd[k] <= n; ++k) { n       jump[i][k] = (1LL << mod) - 1; n       for (int ii = 0; ii < d; ++ii) n         inters(jump[i][k], jump[i + ii * pwd[k - 1]][k - 1], gen[ii]); n     } n   } n   end = clock(); n   start = clock(); n   for (int rem = 0; rem <= pwd[logn] - n; ++rem) { n     long long draw = query(rem, rem + n, 0); n     segments[rem] = {split_segment(draw), {{0, mod - 1}}}; n   } n   end = clock(); n   start = clock(); n   for (int rem = pwd[logn] - n + 1; rem < pwd[logn]; ++rem) { n     long long draw1 = query(rem, pwd[logn], 0); n     long long draw2 = query(0, n - (pwd[logn] - rem), pwd[logn] - rem); n     segments[rem] = {split_segment(draw1), split_segment(draw2)}; n   } n   end = clock(); n   zeroes = new long long[mod]; n   for (int x = 0; x < mod; ++x) zeroes[x] = 0; n   cnt[0] = zeroes; n   Zet ozero = new long long[mod]; n   for (int x = 0; x < mod; ++x) ozero[x] = 0; n   ozero[0] = 1; n   cnt[1] = ozero; n   start = clock(); n   long long l, r; n   scanf( %lld %lld , &l, &r); n   --l; n   --r; n   printf( %lld n , solve(r - n + 1) - solve(l - 1)); n   end = clock(); n } n


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


#include <bits/stdc++.h> n const int maxn = 3005, maxm = maxn << 1; n int n, e, ans, minn; n int start[maxn], to[maxm], then[maxm], worth[maxm], f[maxn], tot[maxn], n     xx[maxm], yy[maxm]; n inline int min(int a, int b) { return a < b ? a : b; } n inline int max(int a, int b) { return a > b ? a : b; } n inline void add(int x, int y, int z) { n   then[++e] = start[x], start[x] = e, to[e] = y, worth[e] = z; n } n void dfs(int x, int last) { n   minn = min(minn, tot[x]); n   for (int i = start[x]; i; i = then[i]) { n     int y = to[i]; n     if (y == last) continue; n     tot[y] = tot[x] + (worth[i] == 0 ? -1 : 1); n     dfs(y, x); n     f[x] += f[y] + (worth[i] ^ 1); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     add(x, y, 1), add(y, x, 0); n   } n   ans = n - 1; n   for (int i = 1; i <= n; i++) n     for (int j = start[i]; j; j = then[j]) n       if (worth[j] == 1) { n         int k = to[j], sum = 0; n         for (int p = 1; p <= n; p++) f[p] = tot[p] = 0; n         dfs(i, 0), ans = min(ans, f[i]); n         for (int p = 1; p <= n; p++) f[p] = tot[p] = 0; n         minn = 1000000000, dfs(i, k); n         sum += f[i] + minn; n         for (int p = 1; p <= n; p++) f[p] = tot[p] = 0; n         minn = 1000000000, dfs(k, i); n         sum += f[k] + minn; n         ans = min(ans, sum); n       } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 4; n int n, A, B, a[N], par[N]; n map<int, int> Map; n int root(int u) { return (par[u] < 0) ? u : (par[u] = root(par[u])); } n void Merge(int u, int v) { n   u = root(u); n   v = root(v); n   if (u != v) { n     if (par[u] > par[v]) swap(u, v); n     par[u] += par[v]; n     par[v] = u; n   } n } n void sol() { n   for (int i = 0; i <= n + 1; ++i) par[i] = -1; n   for (int i = 1; i <= n; ++i) { n     if (Map.count(A - a[i])) n       Merge(i, Map[A - a[i]]); n     else n       Merge(i, n + 1); n     if (Map.count(B - a[i])) n       Merge(i, Map[B - a[i]]); n     else n       Merge(i, 0); n   } n   int u = root(0), v = root(n + 1); n   if (u == v) n     cout <<  NO ; n   else { n     cout <<  YES  n ; n     for (int i = 1; i <= n; ++i) { n       int tmp = root(i); n       if (tmp == u) n         cout << 0 <<    ; n       else n         cout << 1 <<    ; n     } n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> A >> B; n   for (int i = 1; i <= n; ++i) cin >> a[i], Map[a[i]] = i; n   sol(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void print(vector<int> v) { n   for (int i = 0; i < v.size(); i++) { n     cout << v[i] <<    ; n   } n   cout <<   n ; n   return; n } n bool isSubsetSum(vector<int> set, int n, int sum) { n   bool subset[n + 1][sum + 1]; n   for (int i = 0; i <= n; i++) subset[i][0] = true; n   for (int i = 1; i <= sum; i++) subset[0][i] = false; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= sum; j++) { n       if (j < set[i - 1]) subset[i][j] = subset[i - 1][j]; n       if (j >= set[i - 1]) n         subset[i][j] = subset[i - 1][j] || subset[i - 1][j - set[i - 1]]; n     } n   } n   return subset[n][sum]; n } n int main(int argc, char const *argv[]) { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int N; n   cin >> N; n   for (int I = 0; I < N; I++) { n     int n; n     cin >> n; n     vector<int> v(2 * n); n     for (int i = 0; i < 2 * n; i++) { n       cin >> v[i]; n     } n     int p = 0; n     int t = v[0]; n     vector<int> temp; n     for (int i = 0; i < 2 * n; i++) { n       if (v[i] > t) { n         t = v[i]; n         temp.push_back(i - p); n         p = i; n       } n     } n     temp.push_back(2 * n - p); n     if (isSubsetSum(temp, temp.size(), n)) { n       cout <<  YES  n            <<   n ; n     } else { n       cout <<  NO  n            <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n, m, k, A, B; n   cin >> n; n   int r1 = -1, p2 = 100000, p1 = -1; n   for (int(i) = 0; (i) < (n); (i)++) { n     int x; n     cin >> x; n     r1 = max(x, r1); n   } n   cin >> m; n   for (int(i) = 0; (i) < (m); (i)++) { n     int x; n     cin >> x; n     p1 = max(p1, x); n   } n   cin >> k; n   for (int(i) = 0; (i) < (k); (i)++) { n     int x; n     cin >> x; n     p2 = min(p2, x); n   } n   cin >> A >> B; n   double a = r1, b = p1, c = p2; n   double ans = (a * a * B * b) / (B * b + A * c); n   cout << fixed << setprecision(10) << sqrt(ans) <<   n ; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n bool isFile; n using namespace std; n const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; n const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; n const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; n void _(); n void faster() { n   _(); n   if (isFile) { n     freopen( n          taskA  n          .in , n          r , stdin); n     freopen( n          taskA  n          .out , n          w , stdout); n   } n   if (1) { n     ios_base::sync_with_stdio(false); n     cin.tie(0); n     cout.tie(0); n   } n } n const long long INF = 9e18; n const int inf = 2e9; n const int MOD = 998244353; n const long double PI = acos(-1); n const long double EPS = 1e-7; n const int N = (int)2e5 + 5; n const int M = 1234; n vector<int> g[N]; n int dp[N]; n void dfs(int v, int pr = -1, int lvl = 0) { n   dp[lvl % 2]++; n   for (int to : g[v]) n     if (to != pr) dfs(to, v, lvl + 1); n } n void solve() { n   int n; n   cin >> n; n   for (int i = 1; i < n; i++) { n     int u, v; n     cin >> u >> v; n     u--, v--; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   dfs(1); n   cout << min(dp[0], dp[1]) - 1 << endl; n } n void _() {} n int main() { n   faster(); n   int t = 1; n   int id = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cout.tie(NULL); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> v(n); n     vector<int> cnt(n + 1, 0); n     for (int i = 0; i < n; i++) { n       cin >> v[i]; n       cnt[v[i]]++; n     } n     long long sum = 0, ans = 0, len = 0; n     for (int i = 0; i < n; i++) { n       sum = v[i], len = 1; n       for (int j = i + 1; j < n; j++) { n         sum += v[j]; n         len++; n         if (len >= 2) { n           if (sum <= n) { n             ans += cnt[sum]; n             cnt[sum] = 0; n           } else n             break; n         } n       } n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include<bits/stdc++.h> n #define maxn 200005 n #define endl   n  n using namespace std; n   n int n,m,a[maxn],dis[maxn]; n vector<int> e[maxn]; n   n queue<int> q; n   n void bfs() n { n  while(!q.empty()) n  { n   int u=q.front(); n   q.pop(); n   for(int i=0;i<e[u].size();i++) n   { n    int v=e[u][i]; n    if(dis[v]!=-1) continue; n    dis[v]=dis[u]+1; n    q.push(v); n   } n  } n } n   n   n   n int mx[maxn],ans[maxn],ok[maxn]; n vector<int> b[maxn]; n   n void bfs2(int tt) n { n  while(!q.empty()) n  { n   int u=q.front(); n   q.pop(); n   for(int i=0;i<e[u].size();i++) n   { n    int v=e[u][i]; n    if(ok[v]) continue; n    ans[v]=max(ans[v],tt); n    if(mx[v]>=mx[u]-1) continue; n    mx[v]=mx[u]-1; n    q.push(v); n   } n  } n } n   n signed main() n { n  ios::sync_with_stdio(0); n  cin>>n; n  for(int i=1,u,v;i<n;i++)  n  { n   cin>>u>>v; n   e[u].push_back(v); n   e[v].push_back(u); n  } n  cin>>m; n  memset(dis,-1,sizeof(dis)); n  for(int i=1;i<=m;i++)  n  { n   cin>>a[i]; n   ok[a[i]]=1; n   dis[a[i]]=0; n   q.push(a[i]); n  } n  bfs(); n  for(int i=1;i<=n;i++) n   b[dis[i]].push_back(i),ans[i]=dis[i]; n  for(int i=n;i>=1;i--) n  { n   if(b[i].size()==0) continue; n   while(!q.empty()) q.pop(); n //  q.clear(); n   for(int j=0;j<b[i].size();j++)  n   { n    q.push(b[i][j]); n    if(mx[b[i][j]]>=i-1) continue; n    mx[b[i][j]]=i-1; n    ans[b[i][j]]=max(i,ans[b[i][j]]); n   } n   bfs2(i); n  } n  for(int i=1;i<=n;i++) n   cout<<ans[i]<<   ; n  cout<<endl; n }


#include <bits/stdc++.h> n int main() { n   int h, l; n   float a; n   scanf( %d %d , &h, &l); n   a = l * tan(atan(1.0 * h / l) - atan(1.0 * l / h)); n   if (a < 0) a = -a; n   printf( %.10f , a); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   double a; n   int b; n   friend const bool operator<(const node& x, const node& y) { n     if (fabs(x.a - y.a) < 1e-10) n       return x.b < y.b; n     else n       return x.a < y.a; n   } n }; n int n, t, q, p[200007], l[200007], cnt[200007]; n double res; n set<node> a, b; n int read() { n   int num = 0; n   char c = getchar(); n   while (c <  0  || c >  9 ) c = getchar(); n   while (c >=  0  && c <=  9 ) num = num * 10 + c -  0 , c = getchar(); n   return num; n } n int ins(int x) { n   if (cnt[x] < l[x]) n     a.insert(node{((((double)cnt[x] + 1) / (l[x] + cnt[x] + 1)) * p[x]) - n                       ((((double)cnt[x]) / (l[x] + cnt[x])) * p[x]), n                   x}); n   if (cnt[x]) n     b.insert(node{((((double)cnt[x] - 1) / (l[x] + cnt[x] - 1)) * p[x]) - n                       ((((double)cnt[x]) / (l[x] + cnt[x])) * p[x]), n                   x}); n   res += ((((double)cnt[x]) / (l[x] + cnt[x])) * p[x]); n   return 0; n } n int del(int x) { n   if (cnt[x] < l[x]) n     a.erase(node{((((double)cnt[x] + 1) / (l[x] + cnt[x] + 1)) * p[x]) - n                      ((((double)cnt[x]) / (l[x] + cnt[x])) * p[x]), n                  x}); n   if (cnt[x]) n     b.erase(node{((((double)cnt[x] - 1) / (l[x] + cnt[x] - 1)) * p[x]) - n                      ((((double)cnt[x]) / (l[x] + cnt[x])) * p[x]), n                  x}); n   res -= ((((double)cnt[x]) / (l[x] + cnt[x])) * p[x]); n   return 0; n } n int add(int x) { n   del(x); n   cnt[x]++; n   t--; n   ins(x); n   return 0; n } n int era(int x) { n   del(x); n   cnt[x]--; n   t++; n   ins(x); n   return 0; n } n int main() { n   n = read(); n   t = read(); n   q = read(); n   for (int i = 1; i <= n; i++) p[i] = read(); n   for (int i = 1; i <= n; i++) l[i] = read(); n   for (int i = 1; i <= n; i++) n     a.insert(node{((((double)1) / (l[i] + 1)) * p[i]), i}); n   while (t && !a.empty()) add(a.rbegin()->b); n   for (int i = 1; i <= q; i++) { n     int tp = read(), x = read(); n     if (tp == 2 && cnt[x] == l[x]) era(x); n     del(x); n     if (tp == 1) n       l[x]++; n     else n       l[x]--; n     ins(x); n     if (t && !a.empty()) add(a.rbegin()->b); n     if (!a.empty() && !b.empty() && (a.rbegin()->a + b.rbegin()->a) > 0) { n       int x = a.rbegin()->b, y = b.rbegin()->b; n       era(y); n       add(x); n     } n     printf( %.010lf n , res); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int power(long long int x, long long int y, long long int p) { n   long long int res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n bool sortbysec(const pair<long long int, long long int> &a, n                const pair<long long int, long long int> &b) { n   return (a.second > b.second); n } n string decToBin(long long int n) { n   string s =  0 ; n   if (n == 0) return s; n   s =   ; n   while (n > 0) { n     s += (n % 2) +  0 ; n     n = n / 2; n   } n   reverse(s.begin(), s.end()); n   return s; n } n long long int binToDec(string s) { n   long long int ans = 0; n   reverse(s.begin(), s.end()); n   for (__typeof(s.size()) i = (0) - ((0) > (s.size())); n        i != (s.size()) - ((0) > (s.size())); i += 1 - 2 * ((0) > (s.size()))) { n     ans += pow(2, i) * (s[i] -  0 ); n   } n   return ans; n } n long long int nCr(long long int n, long long int r) { n   vector<long long int> fac(200000); n   fac.push_back(1); n   for (long long int i = 1; i < n + 1; i++) { n     fac.push_back((fac[i - 1] * i) % 1000000007); n   } n   long long int ans = fac[n] / (fac[n - r] * fac[r]); n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int n; n   cin >> n; n   string s; n   cin >> s; n   long long int mn = 0; n   vector<long long int> st; n   if (n % 2 == 1) { n     cout << -1 << endl; n     exit(0); n   } n   long long int op = 0, cl = 0; n   for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n)); n        i += 1 - 2 * ((0) > (n))) { n     if (s[i] ==  ( ) { n       st.push_back(0); n       op++; n     } else { n       if (st.size() != 0) { n         st.pop_back(); n       } n       cl++; n     } n     if (cl == op) { n       if (st.size() == 0) { n         cl = 0; n         op = 0; n         continue; n       } n       mn += cl + op; n       cl = 0; n       op = 0; n       st.clear(); n     } n   } n   if (cl == 0 && op == 0) n     cout << mn << endl; n   else n     cout << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     long long a, b; n     int cnt = 0; n     cin >> a >> b; n     long long d = abs(a - b); n     if (d % 10 == 0) { n       cout << d / 10 << endl; n     } else { n       cout << d / 10 + 1 << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> alph(26, 0); n vector<int> comp(26, 0); n int main() { n   int n, t, even = 0, l1, l2; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> t; n     if (t % 2 == 0) { n       even++; n       l1 = i; n     } else { n       even--; n       l2 = i; n     } n   } n   if (even > 0) n     cout << l2 + 1; n   else n     cout << l1 + 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int z = 1000000007; n map<int, int> parent; n map<int, int> XOR; n pair<long long int, long long int> finding(int n, int xo) { n   if (parent.find(n) == parent.end()) n     return pair<long long int, long long int>(n, 0); n   pair<long long int, long long int> temp = finding(parent[n], 0); n   int pa = temp.first; n   parent[n] = pa; n   XOR[n] = (temp.second) ^ XOR[n]; n   return pair<long long int, long long int>(parent[n], XOR[n]); n } n void unite(int a, int b, int xo) { n   parent[a] = b; n   XOR[a] = xo; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int q; n   cin >> q; n   int ans = 0; n   for (int i = 1; i <= q; i++) { n     int op; n     cin >> op; n     if (op == 1) { n       int l, r, x; n       cin >> l >> r >> x; n       l = l ^ ans; n       r = r ^ ans; n       if (l > r) swap(l, r); n       r = r + 1; n       x = x ^ ans; n       int xl = 0, xr = 0; n       pair<long long int, long long int> temp = finding(l, xl); n       int nl = temp.first; n       xl = temp.second; n       temp = finding(r, xr); n       int nr = temp.first; n       xr = temp.second; n       if (nl != nr) unite(nl, nr, ((xl ^ xr) ^ x)); n     } else { n       int l, r; n       cin >> l >> r; n       l = l ^ ans; n       r = r ^ ans; n       if (l > r) swap(l, r); n       r = r + 1; n       int xl = 0, xr = 0; n       pair<long long int, long long int> temp = finding(l, xl); n       int nl = temp.first; n       xl = temp.second; n       temp = finding(r, xr); n       int nr = temp.first; n       xr = temp.second; n       if (nl == nr) { n         cout << (xl ^ xr) << endl; n         ans = (xl ^ xr); n       } else { n         ans = 1; n         cout << -1 << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, i, j, k, l, art[505][505], low[505][505], used[505][505], ans, cn, t, n     x, y, z, mx, mn, s, timer, vis[505][505]; n char c[505][505], d[1000009], ch; n void dfs(int row, int col) { n   timer++; n   used[row][col] = 1; n   if ((row - 1 >= 0) && (used[row - 1][col] == 0) && (timer < s) && n       (c[row - 1][col] ==  . )) { n     dfs(row - 1, col); n   } n   if ((col - 1 >= 0) && (used[row][col - 1] == 0) && (timer < s) && n       (c[row][col - 1] ==  . )) { n     dfs(row, col - 1); n   } n   if ((row + 1 < n) && (used[row + 1][col] == 0) && (timer < s) && n       (c[row + 1][col] ==  . )) { n     dfs(row + 1, col); n   } n   if ((col + 1 < m) && (used[row][col + 1] == 0) && (timer < s) && n       (c[row][col + 1] ==  . )) { n     dfs(row, col + 1); n   } n } n int main() { n   while (scanf( %d %d %d , &n, &m, &k) != EOF) { n     x = y = s = 0; n     timer = 1; n     for (i = 0; i < n; i++) { n       scanf( %s , c[i]); n       for (j = 0; j < m; j++) { n         if (c[i][j] ==  . ) { n           s++; n           x = i; n           y = j; n         } n       } n     } n     s -= k; n     memset(used, 0, sizeof(used)); n     timer = 0; n     dfs(x, y); n     for (i = 0; i < n; i++) { n       for (j = 0; j < m; j++) { n         if ((used[i][j] == 0) && (c[i][j] ==  . )) { n           k--; n           printf( X ); n         } else { n           printf( %c , c[i][j]); n         } n       } n       printf(  n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T, class U> n void ckmin(T &a, U b) { n   if (a > b) a = b; n } n template <class T, class U> n void ckmax(T &a, U b) { n   if (a < b) a = b; n } n int N; n bitset<200013> bs; n int nxt[200013]; n long long ans; n long long c(int r, int m, int mod) { return (r + (mod - m)) / mod; } n int cc(int lt, int rt, int m, int mod) { n   if (lt > rt) return 0; n   return c(rt, m, mod) - c(lt - 1, m, mod); n } n int32_t main() { n   cout << fixed << setprecision(12); n   cerr << fixed << setprecision(4); n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   string temps; n   cin >> temps; n   N = ((int)(temps).size()); n   for (auto i = (1); i < (N + 1); i++) { n     bs[i] = (temps[i - 1] ==  1 ); n   } n   nxt[N + 1] = N + 1; n   for (auto i = (N + 1) - 1; i >= (0); i--) { n     nxt[i] = (bs[i + 1] ? i + 1 : nxt[i + 1]); n   } n   int co = N / (213 - 1) + 5; n   for (auto i = (1); i < (N + 1); i++) { n     long long num = bs[i], lt = i, rt = nxt[i] - 1; n     while (true) { n       if (num) { n         ans += cc(max(num * 213 + i - 1, lt), rt, (i - 1) % num, num); n       } n       rt++; n       lt = rt; n       if (rt > N) break; n       rt = nxt[rt] - 1; n       num++; n       if (num > co) break; n     } n   } n   for (auto i = (1); i < (213); i++) { n     vector<long long> vec; n     vec.push_back(0); n     for (auto j = (1); j < (N + 1); j++) { n       vec.push_back(vec.back() + 1 - (bs[j] ? i : 0)); n     } n     sort((vec).begin(), (vec).end()); n     long long dp = 0; n     for (auto j = (0); j < (((int)(vec).size())); j++) { n       ans += dp; n       if (j != ((int)(vec).size()) - 1 && vec[j] == vec[j + 1]) { n         dp++; n       } else { n         dp = 0; n       } n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC optimize( O1 ) n #pragma GCC optimize( O2 ) n #pragma GCC optimize( Os ) n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx2 ) n #pragma GCC optimization( unroll-loops ) n long long int gcd(long long int a, long long int b) { n   return (b ? gcd(b, a % b) : a); n } n long long int P(long long int B, long long int power, long long int modulo) { n   long long int ans = 1LL; n   while (power > 0LL) { n     if (power % 2LL == 1LL) { n       ans = (ans * B) % modulo; n     } n     B = (B * B) % modulo; n     power /= 2LL; n   } n   return ans; n } n bool isPrime(long long int n) { n   if (n <= 1LL) { n     return false; n   } n   if (n <= 3LL) { n     return true; n   } n   if (n % 2 == 0LL || n % 3 == 0LL) { n     return false; n   } n   for (long long int i = 5LL; (i * i) <= n; i += 6LL) { n     if (n % i == 0LL || n % (i + 2LL) == 0LL) { n       return false; n     } n   } n   return true; n } n using namespace std; n void vok() { n   ios_base::sync_with_stdio(false); n   cout.tie(NULL); n   cin.tie(NULL); n } n const int mxN = int(1e5) + 100; n int dp[mxN]; n bool vis[mxN]; n void dfs(int u, vector<int> graph[]) { n   vis[u] = 1; n   for (auto x : graph[u]) { n     if (!vis[x]) { n       dfs(x, graph); n     } n     dp[u] = max(dp[u], dp[x] + 1); n   } n } n int main() { n   vok(); n   int t; n   cin >> t; n   while (t--) { n     int n, k; n     cin >> n >> k; n     vector<int> v(n); n     set<int> index; n     for (int i = 0; i < n; i++) { n       cin >> v[i]; n       if (v[i] == k) { n         index.insert(i); n       } n     } n     if (int(index.size()) == 0) { n       cout <<  no  n            <<   n ; n       continue; n     } n     bool flag = false; n     for (int i = 0; i < n - 1; i++) { n       if (v[i] >= k && v[i + 1] >= k) { n         flag = true; n         break; n       } n       if (i < n - 2) { n         if (v[i] >= k && v[i + 2] >= k) { n           flag = true; n           break; n         } n       } n     } n     if (flag || int(index.size()) == n || n == 1) { n       cout <<  yes  n            <<   n ; n       continue; n     } n     cout <<  no  n          <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC target( avx2 ) n #pragma GCC optimization( O3 ) n #pragma GCC optimization( unroll-loops ) n void solve() { n   long long n, m, k; n   cin >> n >> m >> k; n   long long lb = n / m; n   long long ub = (n + m - 1) / m; n   vector<long long> seat; n   for (long long i = 0; i <= m; i++) { n     long long remain = n - i * lb; n     if (remain >= 0 && remain % ub == 0 && (i + remain / ub == m)) { n       for (long long j = 0; j < i; j++) seat.push_back(lb); n       for (long long j = 0; j < remain / ub; j++) seat.push_back(ub); n       break; n     } n   } n   sort(seat.begin(), seat.end()); n   priority_queue<pair<long long, long long>> pq; n   for (long long i = 0; i < n; i++) pq.push({0, i}); n   while (k--) { n     priority_queue<pair<long long, long long>> temp; n     for (auto &x : seat) { n       cout << x <<    ; n       for (long long i = 0; i < x; i++) { n         long long p = pq.top().first, u = pq.top().second; n         pq.pop(); n         p += (x != lb); n         cout << (u + 1) <<    n [i == x - 1]; n         temp.push({p, u}); n       } n     } n     pq = temp; n   } n   cout <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string a, b, p1 =  Widget , p2 =  VBox , p3 =  HBox , ans[105]; n map<string, int> q; n vector<int> d[105]; n int id[105]; n long long l[105], r[105], h1[105], h2[105]; n void dfs(int x) { n   if (l[x] != -1) return; n   l[x] = 0; n   for (int i = 0; i < (int)d[x].size(); ++i) { n     int v = d[x][i]; n     dfs(v); n     if (id[x] == 2) { n       l[x] += l[v]; n       r[x] = max(r[x], r[v]); n     } else { n       r[x] += r[v]; n       l[x] = max(l[x], l[v]); n     } n   } n   if (d[x].size()) { n     if (id[x] == 2) { n       l[x] = l[x] + (d[x].size() - 1) * h2[x]; n       r[x] += 2 * h1[x]; n       l[x] += 2 * h1[x]; n     } else { n       r[x] = r[x] + (d[x].size() - 1) * h2[x]; n       l[x] += 2 * h1[x]; n       r[x] += 2 * h1[x]; n     } n   } n } n int main() { n   memset(l, -1, sizeof(l)); n   int n, tot = 0; n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     cin >> a; n     if (a == p1) { n       cin >> a; n       b =   ; n       for (int j = 0, k; j < (int)a.size(); ++j) { n         if (a[j] ==  ( ) { n           q[b] = ++tot; n           ans[tot] = b; n           l[tot] = 0; n           for (k = j + 1;; ++k) { n             if (a[k] ==  , ) break; n             l[tot] = l[tot] * 10 + a[k] -  0 ; n           } n           for (++k;; ++k) { n             if (a[k] ==  ) ) break; n             r[tot] = r[tot] * 10 + a[k] -  0 ; n           } n           break; n         } n         b += a[j]; n       } n     } else if (a == p2) { n       cin >> a; n       q[a] = ++tot; n       ans[tot] = a; n       id[tot] = 1; n     } else if (a == p3) { n       cin >> a; n       q[a] = ++tot; n       ans[tot] = a; n       id[tot] = 2; n     } else { n       string c =   ; n       for (int j = 0; j < (int)a.size(); ++j) { n         if (a[j] ==  . ) { n           if (a[j + 1] ==  p ) { n             b =   ; n             for (int k = j + 6; k < (int)a.size() - 1; ++k) b += a[k]; n             d[q[c]].push_back(q[b]); n           } else { n             long long tp = 0; n             for (int k = j + 1; k < (int)a.size(); ++k) n               if (a[k] >=  0  && a[k] <=  9 ) tp = tp * 10 + a[k] -  0 ; n             if (a[j + 5] ==  b ) n               h1[q[c]] = tp; n             else n               h2[q[c]] = tp; n           } n           break; n         } n         c += a[j]; n       } n     } n   } n   sort(ans + 1, ans + tot + 1); n   for (int i = 1; i <= tot; ++i) { n     dfs(q[ans[i]]); n     cout << ans[i] <<    ; n     printf( %I64d %I64d n , l[q[ans[i]]], r[q[ans[i]]]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int IINF = 0x3f3f3f3f; n const long long LINF = 0x3f3f3f3f3f3f3f3fll; n const double DINF = numeric_limits<double>::infinity(); n const long long MOD = 1000000007; n const double EPS = 1e-9; n const int DX[] = {1, 0, -1, 0, 1, -1, 1, -1}; n const int DY[] = {0, 1, 0, -1, 1, -1, -1, 1}; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long sqr(long long x) { return x * x; } n long long sqr(int x) { return (long long)x * x; } n double sqr(double x) { return x * x; } n long double sqr(long double x) { return x * x; } n const int N = 200500; n class SSet { n   multiset<int> s1, s2; n   long long sum = 0; n  n  public: n   void insert(int x) { n     if (s2.empty() || (*s2.begin()) > x) { n       s1.insert(x); n       sum += x; n     } else n       s2.insert(x); n   } n   void erase(int x) { n     auto it = s1.find(x); n     if (it != s1.end()) { n       s1.erase(it); n       sum -= x; n     } else n       s2.erase(s2.find(x)); n   } n   long long getSum(int m) { n     if (((int)((s1).size())) + ((int)((s2).size())) < m || m < 0) return LINF; n     while (((int)((s1).size())) > m) { n       auto it = s1.end(); n       --it; n       s2.insert(*it); n       sum -= *it; n       s1.erase(it); n     } n     while (((int)((s1).size())) < m) { n       auto it = s2.begin(); n       s1.insert(*it); n       sum += *it; n       s2.erase(it); n     } n     return sum; n   } n } ss; n int n, m, k; n int costs[N]; n bool good1[N], good2[N]; n vector<int> c[2][2]; n vector<long long> cs[2][2]; n int main() { n   ios::sync_with_stdio(false); n   scanf( %d%d%d , &n, &m, &k); n   for (int i = 0; i < n; ++i) scanf( %d , &costs[i]); n   int gc; n   scanf( %d , &gc); n   for (int i = 0; i < gc; ++i) { n     int x; n     scanf( %d , &x); n     --x; n     good1[x] = 1; n   } n   scanf( %d , &gc); n   for (int i = 0; i < gc; ++i) { n     int x; n     scanf( %d , &x); n     --x; n     good2[x] = 1; n   } n   for (int i = 0; i < n; ++i) c[good1[i]][good2[i]].push_back(costs[i]); n   for (int i = 0; i < 2; ++i) n     for (int j = 0; j < 2; ++j) { n       sort(c[i][j].begin(), c[i][j].end()); n       cs[i][j].push_back(0); n       for (int x : c[i][j]) cs[i][j].push_back(cs[i][j].back() + x); n     } n   for (int x : c[0][0]) ss.insert(x); n   for (int i = k; i < ((int)((c[0][1]).size())); ++i) ss.insert(c[0][1][i]); n   for (int i = k; i < ((int)((c[1][0]).size())); ++i) ss.insert(c[1][0][i]); n   long long ans = LINF; n   for (int cnt11 = 0; cnt11 <= ((int)((c[1][1]).size())); ++cnt11) { n     if (cnt11 >= k) n       ans = min(ans, cs[1][1][cnt11] + ss.getSum(m - cnt11)); n     else if (k - cnt11 <= ((int)((c[1][0]).size())) && n              k - cnt11 <= ((int)((c[0][1]).size()))) n       ans = min(ans, cs[1][1][cnt11] + cs[0][1][k - cnt11] + n                          cs[1][0][k - cnt11] + ss.getSum(m - 2 * k + cnt11)); n     if (cnt11 != ((int)((c[1][1]).size()))) { n       if (k - cnt11 - 1 >= 0 && k - cnt11 - 1 < ((int)((c[0][1]).size()))) n         ss.insert(c[0][1][k - cnt11 - 1]); n       if (k - cnt11 - 1 >= 0 && k - cnt11 - 1 < ((int)((c[1][0]).size()))) n         ss.insert(c[1][0][k - cnt11 - 1]); n     } n   } n   if (ans >= LINF) ans = -1; n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n int n, a[maxn], ans; n int gcd(int x, int y) { n   if (y == 0) return x; n   return gcd(y, x % y); n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   int x = gcd(a[1], a[2]); n   for (int i = 3; i <= n; i++) n     if (x > 1) { n       x = gcd(x, a[i]); n     } n   if (x > 1) { n     cout <<  YES  << endl; n     cout <<  0  << endl; n   } else { n     for (int i = 1; i < n; i++) { n       if (a[i] % 2 == 0) n         continue; n       else if (a[i + 1] % 2 == 0) n         ans += 2, a[i] = 0; n       else n         ans++, a[i + 1] = 0, a[i] = 0; n     } n     if (a[n] % 2 == 0) { n       cout <<  YES  << endl; n       cout << ans << endl; n     } else { n       cout <<  YES  << endl; n       cout << ans + 2 << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n = 0, T = 0; n long long D[1003], g[1003]; n long long x1[1003], xn[1003], Y1[1003], Yn[1003]; n void getDisPre(long long x, int N, long long (&t1)[1003], n                long long (&tn)[1003]) { n   if (N == 0) { n     t1[0] = tn[0] = 0; n     return; n   } n   if (N == 1) { n     t1[1] = (x == 2); n     tn[1] = (x == 1); n     return; n   } n   if (x <= D[N - 1]) { n     getDisPre(x, N - 1, t1, tn); n     t1[N] = min(t1[N - 1], tn[N - 1] + 2); n     tn[N] = min(t1[N - 1], tn[N - 1]) + g[N - 2] + 1; n   } else { n     getDisPre(x - D[N - 1], N - 2, t1, tn); n     t1[N] = t1[N - 2] + 1; n     tn[N] = tn[N - 2]; n   } n } n long long dis(long long x, long long y, long long N) { n   if (N <= 1) return x != y; n   if (x > y) swap(x, y); n   if (x <= D[N - 1] && y <= D[N - 1]) n     return min(min(min(x1[N - 1] + Y1[N - 1], xn[N - 1] + Yn[N - 1]), n                    min(x1[N - 1] + Yn[N - 1] + 2, xn[N - 1] + Y1[N - 1] + 2)), n                dis(x, y, N - 1)); n   else if (x <= D[N - 1]) n     return min(x1[N - 1], xn[N - 1]) + 1 + Y1[N - 2]; n   else n     return dis(x - D[N - 1], y - D[N - 1], N - 2); n } n int main() { n   scanf( %d %d , &T, &n); n   if (n > 80) n = 80; n   D[0] = 1; n   D[1] = 2; n   for (int i = 2; i <= n; ++i) D[i] = D[i - 1] + D[i - 2]; n   g[0] = 0; n   g[1] = 1; n   g[2] = 1; n   for (int i = 3; i <= n; ++i) g[i] = g[i - 2] + 1; n   for (int t = 1; t <= T; ++t) { n     long long x = 0, y = 0; n     scanf( %lld %lld , &x, &y); n     if (x > y) swap(x, y); n     getDisPre(x, n, x1, xn); n     getDisPre(y, n, Y1, Yn); n     printf( %lld n , dis(x, y, n)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool debug = 0; n int n, m, k; n int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; n string direc =  RDLU ; n long long ln, lk, lm; n void etp(bool f = 0) { n   puts(f ?  YES  :  NO ); n   exit(0); n } n void addmod(int &x, int y, int mod = 1000000007) { n   assert(y >= 0); n   x += y; n   if (x >= mod) x -= mod; n   assert(x >= 0 && x < mod); n } n void et() { n   puts( -1 ); n   exit(0); n } n long long fastPow(long long x, long long y, int mod = 1000000007) { n   long long ans = 1; n   while (y > 0) { n     if (y & 1) ans = (x * ans) % mod; n     x = x * x % mod; n     y >>= 1; n   } n   return ans; n } n long long gcd1(long long x, long long y) { n   long long z = y; n   while (x % y != 0) { n     z = x % y; n     x = y; n     y = z; n   } n   return z; n } n char s[100005]; n bool vis[30]; n void fmain(int ID) { n   scanf( %d%d , &n, &k); n   scanf( %s , s + 1); n   for (int(i) = 1; (i) <= (int)(n); (i)++) vis[s[i] -  a ] = 1; n   if (n < k) { n     for (int(i) = 1; (i) <= (int)(n); (i)++) printf( %c , s[i]); n     for (int(j) = 0; (j) < (int)(26); (j)++) n       if (vis[j]) { n         for (int(cc) = 0; (cc) < (int)(k - n); (cc)++) printf( %c ,  a  + j); n         break; n       } n     return; n   } n   for (int i = k; i; i--) { n     for (int j = (s[i] -  a ) + 1; j < 26; j++) n       if (vis[j]) { n         for (int(z) = 1; (z) <= (int)(i - 1); (z)++) printf( %c , s[z]); n         printf( %c ,  a  + j); n         for (int(tar) = 0; (tar) < (int)(26); (tar)++) n           if (vis[tar]) { n             for (int z = i + 1; z <= k; z++) printf( %c ,  a  + tar); n             return; n           } n         return; n       } n   } n } n int main() { n   int t = 1; n   for (int(i) = 1; (i) <= (int)(t); (i)++) { n     fmain(i); n   } n   return 0; n } n


#include <bits/stdc++.h> n template <class T> n inline bool rd(T &ret) { n   char c; n   int sgn; n   if (c = getchar(), c == EOF) return 0; n   while (c !=  -  && (c <  0  || c >  9 )) c = getchar(); n   sgn = (c ==  - ) ? -1 : 1; n   ret = (c ==  - ) ? 0 : (c -  0 ); n   while (c = getchar(), c >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 ); n   ret *= sgn; n   return 1; n } n template <class T> n inline void pt(T x) { n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   if (x > 9) pt(x / 10); n   putchar(x % 10 +  0 ); n } n using namespace std; n const long long inf = 1e10; n const int N = 10019; n const int M = 10000000; n template <class T> n struct Max_Flow { n   int n; n   int Q[N], sign; n   int head[N], level[N], cur[N], pre[N]; n   int nxt[M], pnt[M], E; n   T cap[M]; n   void Init(int n) { n     this->n = n + 1; n     E = 0; n     std::fill(head, head + this->n, -1); n   } n   void add(int from, int to, T c, T rw) { n     pnt[E] = to; n     cap[E] = c; n     nxt[E] = head[from]; n     head[from] = E++; n     pnt[E] = from; n     cap[E] = rw; n     nxt[E] = head[to]; n     head[to] = E++; n   } n   bool Bfs(int s, int t) { n     sign = t; n     std::fill(level, level + n, -1); n     int *front = Q, *tail = Q; n     *tail++ = t; n     level[t] = 0; n     while (front < tail && level[s] == -1) { n       int u = *front++; n       for (int e = head[u]; e != -1; e = nxt[e]) { n         if (cap[e ^ 1] > 0 && level[pnt[e]] < 0) { n           level[pnt[e]] = level[u] + 1; n           *tail++ = pnt[e]; n         } n       } n     } n     return level[s] != -1; n   } n   void Push(int t, T &flow) { n     T mi = inf; n     int p = pre[t]; n     for (int p = pre[t]; p != -1; p = pre[pnt[p ^ 1]]) { n       mi = std::min(mi, cap[p]); n     } n     for (int p = pre[t]; p != -1; p = pre[pnt[p ^ 1]]) { n       cap[p] -= mi; n       if (!cap[p]) { n         sign = pnt[p ^ 1]; n       } n       cap[p ^ 1] += mi; n     } n     flow += mi; n   } n   void Dfs(int u, int t, T &flow) { n     if (u == t) { n       Push(t, flow); n       return; n     } n     for (int &e = cur[u]; e != -1; e = nxt[e]) { n       if (cap[e] > 0 && level[u] - 1 == level[pnt[e]]) { n         pre[pnt[e]] = e; n         Dfs(pnt[e], t, flow); n         if (level[sign] > level[u]) { n           return; n         } n         sign = t; n       } n     } n   } n   T Dinic(int s, int t) { n     pre[s] = -1; n     T flow = 0; n     while (Bfs(s, t)) { n       std::copy(head, head + n, cur); n       Dfs(s, t, flow); n     } n     return flow; n   } n }; n Max_Flow<long long> F; n struct node { n   int x, y; n   long long t; n   node(int a = 0, int b = 0, long long c = 0) : x(a), y(b), t(c) {} n } AA[N], B[N], C; n int n, m, a, b; n char mp[24][24]; n long long Dis[24][24][24][24]; n int has1(int x) { return x - 1; } n int has2(int x, int y) { return a + (x - 1) * m + y - 1; } n int has3(int x, int y) { return a + n * m + (x - 1) * m + y - 1; } n int has4(int x) { return a + 2 * n * m + x - 1; } n bool ok(long long now) { n   int from = has4(b) + 1, to = from + 1; n   F.Init(to + 10); n   for (int i = 1; i <= a; i++) { n     F.add(from, has1(i), 1, 0); n     for (int x = 1; x <= n; x++) n       for (int y = 1; y <= m; y++) n         if (Dis[x][y][AA[i].x][AA[i].y] < inf && n             Dis[x][y][AA[i].x][AA[i].y] * AA[i].t <= now) n           F.add(has1(i), has2(x, y), 1, 0); n   } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (mp[i][j] ==  . ) F.add(has2(i, j), has3(i, j), 1, 0); n   for (int i = 1; i <= b; i++) { n     F.add(has4(i), to, 1, 0); n     for (int x = 1; x <= n; x++) n       for (int y = 1; y <= m; y++) n         if (Dis[x][y][B[i].x][B[i].y] < inf && n             Dis[x][y][B[i].x][B[i].y] * B[i].t <= now) n           F.add(has3(x, y), has4(i), 1, 0); n   } n   return F.Dinic(from, to) == b; n } n long long solve() { n   if (a != b) return -1; n   long long ans = -1, l = 0, r = 1e18; n   while (l <= r) { n     long long mid = (l + r) >> 1; n     if (ok(mid)) { n       r = mid - 1; n       ans = mid; n     } else n       l = mid + 1; n   } n   return ans; n } n void pre() { n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       for (int x = 1; x <= n; x++) n         for (int y = 1; y <= m; y++) Dis[i][j][x][y] = inf; n   int step[4][2] = {0, 1, 0, -1, 1, 0, -1, 0}; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       if (mp[i][j] ==  * ) continue; n       Dis[i][j][i][j] = 0; n       for (int k = 0; k < 4; k++) { n         int x = i + step[k][0], y = j + step[k][1]; n         if (1 <= x && x <= n && 1 <= y && y <= m && mp[x][y] ==  . ) n           Dis[i][j][x][y] = 1; n       } n     } n   for (int x1 = 1; x1 <= n; x1++) n     for (int y1 = 1; y1 <= m; y1++) n       if (mp[x1][y1] ==  . ) n         for (int x2 = 1; x2 <= n; x2++) n           for (int y2 = 1; y2 <= m; y2++) n             if (mp[x2][y2] ==  .  && Dis[x2][y2][x1][y1] < inf) n               for (int x3 = 1; x3 <= n; x3++) n                 for (int y3 = 1; y3 <= m; y3++) n                   if (mp[x3][y3] ==  . ) n                     Dis[x2][y2][x3][y3] = n                         min(Dis[x2][y2][x3][y3], n                             Dis[x2][y2][x1][y1] + Dis[x1][y1][x3][y3]); n   if (a > b) n     B[++b] = C; n   else n     AA[++a] = C; n } n void input() { n   rd(n); n   rd(m); n   rd(a); n   rd(b); n   for (int i = 1; i <= n; i++) scanf( %s , mp[i] + 1); n   rd(C.x); n   rd(C.y); n   rd(C.t); n   for (int i = 1; i <= a; i++) { n     rd(AA[i].x); n     rd(AA[i].y); n     rd(AA[i].t); n   } n   for (int i = 1; i <= b; i++) { n     rd(B[i].x); n     rd(B[i].y); n     rd(B[i].t); n   } n } n int main() { n   input(); n   pre(); n   cout << solve() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int hr = s[0] -  0 ; n   hr = hr * 10 + s[1] -  0 ; n   if (hr >= 12) hr -= 12; n   int min = s[3] -  0 ; n   min = min * 10 + s[4] -  0 ; n   double b = min * 6; n   double a = ((double)hr + (double)min / 60) * 30; n   printf( %.9lf %.9lf , a, b); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t = 0, counterarr[3] = {5, 7, 5}, c = 0; n   string x; n   bool arr[3] = {}; n   while (t < 3) { n     getline(cin, x); n     for (int i = 0; i < x.length(); i++) { n       if (x[i] ==  a  || x[i] ==  e  || x[i] ==  u  || x[i] ==  i  || n           x[i] ==  o ) n         c++; n     } n     if (c == counterarr[t]) { n       arr[t] = true; n     } n     c = 0; n     t++; n   } n   if (arr[0] == 1 && arr[1] == 1 && arr[2] == 1) n     cout <<  YES n ; n   else n     cout <<  NO n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int sum1 = 0, sum2 = 0, sum3 = 0; n   int n; n   cin >> n; n   int a, b, c; n   for (int i = 0; i < n; i++) { n     cin >> a >> b >> c; n     sum1 += a; n     sum2 += b; n     sum3 += c; n   } n   if (sum1 == 0 && sum2 == 0 && sum3 == 0) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     n *= 2; n     int arr[n]; n     vector<int> ans; n     unordered_set<int> s; n     for (int i = 0; i < n; i++) { n       cin >> arr[i]; n       if (s.find(arr[i]) == s.end()) { n         ans.push_back(arr[i]); n         s.insert(arr[i]); n       } n     } n     for (int i = 0; i < ans.size(); i++) { n       cout << ans[i] <<    ; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int64_t INF = 1e18, MOD = 1e9 + 7; n const int64_t MAXN = 1e3; n pair<int64_t, int64_t> last = {0, 0}; n pair<int64_t, int64_t> ask(int64_t i) { n   if (i != -1) cout <<  +   << (i + 1) << endl; n   int64_t a, b; n   cin >> a >> b; n   a -= last.first, b -= last.second; n   last = {a + last.first, b + last.second}; n   return {a, b}; n } n int64_t search(int64_t v) { n   for (int64_t i = 1; i < MAXN; i++) { n     if ((i * (i - 1)) / 2 == v) return i; n   } n   return -1; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   int64_t n; n   cin >> n; n   ask(-1); n   vector<int64_t> ans(n); n   pair<int64_t, int64_t> q1 = ask(0); n   pair<int64_t, int64_t> q2 = ask(1); n   pair<int64_t, int64_t> q3 = ask(2); n   pair<int64_t, int64_t> q4 = ask(0); n   ans[0] = search(q4.first) + 1; n   if (q2.second == 0) n     ans[2] = 1; n   else n     ans[2] = search(q3.first) + 1; n   ans[1] = q4.second / ans[2]; n   int64_t carry = q3.second - ans[1] * (ans[0] - 1); n   for (int64_t i = 3; i < n - 1; i++) { n     pair<int64_t, int64_t> qur = ask(i); n     if (carry == 0) n       ans[i] = 1; n     else n       ans[i] = search(qur.first) + 1; n     carry = qur.second - ans[i - 1] * ans[i - 2]; n   } n   if (carry == 0) n     ans[n - 1] = 0; n   else n     ans[n - 1] = carry / ans[n - 3]; n   ans[0]--; n   for (int64_t i = 0; i < n - 1; i++) ans[i]--; n   cout <<  !  ; n   for (int64_t i = 0; i < n; i++) cout << ans[i] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9; n const int Maxn = 1005; n const int dx[] = {-1, 0, 1, 0}; n const int dy[] = {0, 1, 0, -1}; n struct pos { n   int first, second, third; n }; n string s; n int n, k; n pair<int, int> d[11111]; n int main() { n   scanf( %d%d , &n, &k); n   cin >> s; n   int ans = INF; n   string as =   ; n   string os = s; n   for (char c =  0 ; c <=  9 ; c++) { n     s = os; n     for (int(i) = 0; (i) < (int)(n); i++) n       d[i] = {abs(s[i] - c), s[i] >= c ? -(n - i) : n - i}; n     sort(d, d + n); n     int cur = 0; n     for (int(i) = 0; (i) < (int)(k); i++) { n       cur += d[i].first; n       int x = d[i].second; n       if (x < 0) x = -x; n       x = -x + n; n       s[x] = c; n     } n     if (cur < ans || (cur == ans && s < as)) { n       as = s; n       ans = cur; n     } n   } n   printf( %d n , ans); n   puts(as.c_str()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int L[100000 + 10], dp1[100000 + 10], dp2[100000 + 10]; n int lis(int *seq, int *ls, int N) { n   int len = 0; n   for (int i = 1; i <= N; ++i) { n     int lo = 1, hi = len; n     while (lo <= hi) { n       int m = (lo + hi) / 2; n       if (L[m] <= seq[i]) n         lo = m + 1; n       else n         hi = m - 1; n     } n     L[lo] = seq[i], ls[i] = lo; n     if (len < lo) len = lo; n   } n   return len; n } n int A[100000 + 10], Rev[100000 + 10]; n int solve(int n) { n   lis(A, dp1, n); n   lis(Rev, dp2, n); n   int ans = 0; n   for (int i = 1, j = n; i <= n; i++, j--) { n     ans = max(ans, dp1[i] + dp2[j] - 1); n   } n   return ans; n } n int go(vector<int> &arr, int n) { n   for (int i = 1, j = n; i <= n; i++, j--) A[i] = arr[i - 1], Rev[j] = A[i]; n   return solve(n); n } n vector<int> V; n int arr[100000 + 5]; n int main() { n   int n, m, i, l, r, ans = 0; n   scanf( %d %d , &n, &m); n   for (i = 1; i <= n; i++) { n     scanf( %d %d , &l, &r); n     arr[l]++; n     arr[r + 1]--; n   } n   for (i = 1; i <= m; i++) arr[i] += arr[i - 1]; n   for (int i = 1; i <= m; i++) { n     V.push_back(arr[i]); n   } n   cout << go(V, V.size()) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, c0, c1, t0, t1, w0, w1, tot, q[2][1000010]; n char s[1000010]; n vector<int> v[1000010]; n int main() { n   scanf( %s , s + 1); n   n = strlen(s + 1); n   for (int i = (1); i <= (n); i++) n     if (s[i] ==  0 ) n       c0++; n     else n       c1++; n   if (c0 < c1) { n     puts( -1 ); n     return 0; n   } n   t0 = 1; n   w0 = 0; n   t1 = 1; n   w1 = 0; n   for (int i = (1); i <= (n); i++) { n     if (s[i] ==  0 ) { n       if (t1 > w1) { n         v[++tot].push_back(i); n         q[0][++w0] = tot; n       } else { n         int now = q[1][t1]; n         v[now].push_back(i); n         q[0][++w0] = now; n         t1++; n       } n     } else { n       if (t0 > w0) { n         puts( -1 ); n         return 0; n       } n       int now = q[0][t0]; n       v[now].push_back(i); n       q[1][++w1] = now; n       t0++; n     } n   } n   for (int i = (1); i <= (tot); i++) { n     int w = (int)v[i].size() - 1; n     if (s[v[i][w]] ==  1 ) { n       puts( -1 ); n       return 0; n     } n   } n   printf( %d n , tot); n   for (int i = (1); i <= (tot); i++) { n     printf( %d , (int)v[i].size()); n     for (int j = (0); j <= ((int)v[i].size() - 1); j++) printf(  %d , v[i][j]); n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long left(long long i, long long n) { n   if (i == 0) return n - 1; n   return i - 1; n } n long long solve(string a, long long n) { n   long long cw = 0; n   long long ccw = 0; n   for (long long i = 0; i < n; i++) { n     if (a[i] ==  - ) continue; n     if (a[i] ==  < ) n       ccw++; n     else n       cw++; n   } n   if (cw == 0 || ccw == 0) return n; n   long long cnt = 0; n   for (long long i = 0; i < n; i++) { n     if (a[left(i, n)] ==  -  || a[i] ==  - ) cnt++; n   } n   return cnt; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     string a; n     cin >> a; n     cout << solve(a, n) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n int read() { n   int ans = 0, c, f = 1; n   while (!isdigit(c = getchar())) n     if (c ==  - ) f *= -1; n   do ans = ans * 10 + c -  0 ; n   while (isdigit(c = getchar())); n   return ans * f; n } n const int N = 10050; n int n, A[N], B[N]; n int m, a[N], b[N], c[N], d[N]; n void por(int x1, int y1, int x2, int y2) { n   a[m] = x1; n   b[m] = y1; n   c[m] = x2; n   d[m] = y2; n   ++m; n } n int main() { n   n = read(); n   for (int i = 1; i <= n; ++i) A[i] = read(); n   for (int i = 1; i <= n; ++i) B[i] = read(); n   for (int k = 1; k <= n; ++k) { n     int ti = 0, tj = 0; n     for (int i = k; i <= n; ++i) { n       if (A[i] == k) ti = i; n       if (B[i] == k) tj = i; n     } n     if (ti == k && tj == k) n       ; n     else if (ti == k) n       por(k, k, k, tj); n     else if (tj == k) n       por(k, k, ti, k); n     else n       por(ti, k, k, tj); n     std::swap(A[k], A[ti]); n     std::swap(B[k], B[tj]); n   } n   printf( %d n , m); n   for (int i = 0; i < m; ++i) printf( %d %d %d %d n , a[i], b[i], c[i], d[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, a, b; n   cin >> n >> m >> a >> b; n   int x = m - n, r = 0, t = 14; n   if (b >= a && a * 8 < x) { n     cout << -1; n     return 0; n   } n   while (x > 0) { n     if (10 <= t && t < 22) n       x -= a; n     else n       x += b; n     t++; n     if (t == 24) r++, t = 0; n   } n   cout << r; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s, str[10]; n   cin >> s; n   for (int i = 0; i < 10; i++) cin >> str[i]; n   for (int i = 0; i < s.length(); i += 10) { n     string w; n     for (int j = i; j < i + 10; j++) w = w + s[j]; n     for (int i = 0; i < 10; i++) { n       if (w.compare(str[i]) == 0) { n         cout << i; n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool check(string &w, string &s, map<char, int> &cnt) { n   int used[ z  -  a  + 1] = {}; n   int arr[ z  -  a  + 1] = {}; n   for (int i = 0; i < w.size(); ++i) { n     if (w[i] !=  * ) { n       used[w[i] -  a ] = 1; n     } n   } n   for (int i = 0; i < w.size(); ++i) { n     if (w[i] ==  * ) { n       if (used[s[i] -  a ]) { n         return false; n       } n       arr[s[i] -  a ] += 1; n     } else if (w[i] != s[i]) { n       return false; n     } n   } n   for (int i = 0; i <  z  -  a  + 1; ++i) { n     if (arr[i]) { n       cnt[ a  + i] += 1; n     } n   } n   return true; n } n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   string w; n   cin >> w; n   map<char, int> cnt; n   int k = 0; n   int m; n   cin >> m; n   string s; n   for (int i = 0; i < m; ++i) { n     cin >> s; n     if (check(w, s, cnt)) { n       k++; n     } n   } n   int ans = 0; n   for (auto p : cnt) { n     if (p.second == k) { n       ans++; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n, h; n   cin >> n >> h; n   for (int i = 1; i < n; i++) printf( %.10f  , h * sqrt(1. * i / n)); n   puts(  ); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9; n vector<int> primes(int n) { n   vector<int> p(n + 1, 1); n   for (int i = 2; i * i <= n; ++i) n     if (p[i]) n       for (int j = i * i; j <= n; j += i) p[j] = 0; n   vector<int> res; n   for (int i = 2; i <= n; ++i) n     if (p[i]) res.push_back(i); n   return res; n } n int a[128], b[128]; n int dp[128][1 << 16]; n int pr[128][1 << 16]; n int bit[64]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < (int)(n); i++) cin >> a[i]; n   vector<int> prime = primes(54); n   for (int i = 0; i < (int)(128); i++) n     for (int j = 0; j < (int)(1 << 16); j++) dp[i][j] = INF; n   dp[0][0] = 0; n   for (int i = 0; i < (int)(64); i++) n     for (int j = 0; j < (int)(16); j++) n       if (i % prime[j] == 0) bit[i] += (1 << j); n   for (int i = 0; i < (int)(n); i++) n     for (int j = 0; j < (int)(1 << 16); j++) { n       for (int k = 0; k < (int)(54); k++) n         if ((bit[k] & j) == 0) n           if (dp[i + 1][bit[k] | j] > dp[i][j] + abs(a[i] - k)) { n             dp[i + 1][bit[k] | j] = dp[i][j] + abs(a[i] - k); n             pr[i + 1][bit[k] | j] = k; n           } n     } n   int pos = 0; n   for (int i = 0; i < (int)(1 << 16); i++) n     if (dp[n][pos] > dp[n][i]) pos = i; n   vector<int> res; n   for (int i = n; i > 0; --i) { n     res.push_back(pr[i][pos]); n     int k = pr[i][pos]; n     pos = pos - bit[k]; n   } n   reverse((res).begin(), (res).end()); n   for (int i = 0; i < (int)(res.size()); i++) { n     if (i > 0) cout <<    ; n     cout << res[i]; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 10005; n int gcd(int a, int b) { return !b ? a : gcd(b, a % b); } n int T, n, A, B, C, cnt, p[N], mu[N], du[N], fe[N], tot; n long long a[N], b[N], c[N]; n bool np[N]; n void init() { n   mu[1] = 1; n   for (int i = 2; i <= n; i++) { n     if (!np[i]) p[++cnt] = i, mu[i] = -1; n     for (int j = 1; j <= cnt && i * p[j] <= n; j++) { n       np[i * p[j]] = 1; n       if (i % p[j] == 0) break; n       mu[i * p[j]] = -mu[i]; n     } n   } n } n struct edge { n   int u, v, w; n }; n struct _ { n   int v, w; n }; n vector<_> G[N]; n int main() { n   n = 10000; n   init(); n   scanf( %d%d%d , &A, &B, &C); n   n = max(A, max(B, C)); n   for (int i = 0; i <= n; i++) a[i] = b[i] = c[i] = du[i] = 0, G[i].clear(); n   for (int i = 1; i <= A; i++) n     for (int j = i; j <= A; j += i) a[i] += A / j; n   for (int i = 1; i <= B; i++) n     for (int j = i; j <= B; j += i) b[i] += B / j; n   for (int i = 1; i <= C; i++) n     for (int j = i; j <= C; j += i) c[i] += C / j; n   long long ans = 0; n   for (int i = 1; i <= n; i++) n     ans += mu[i] * mu[i] * mu[i] * a[i] * b[i] * c[i]; n   vector<edge> e; n   for (int d = 1; d <= n; d++) n     for (int i = 1, l = n / d; i <= l; i++) n       if (mu[i * d]) n         for (int j = i + 1, r = n / d / i; j <= r; j++) n           if (mu[j * d] && gcd(i, j) == 1) { n             int u = i * d, v = j * d, lcm = i * j * d; n             ans += mu[u] * mu[u] * mu[v] * n                    (a[u] * b[lcm] * c[lcm] + a[lcm] * b[u] * c[lcm] + n                     a[lcm] * b[lcm] * c[u]); n             ans += mu[u] * mu[v] * mu[v] * n                    (a[v] * b[lcm] * c[lcm] + a[lcm] * b[v] * c[lcm] + n                     a[lcm] * b[lcm] * c[v]); n             ++du[u]; n             ++du[v]; n             e.push_back((edge){u, v, lcm}); n           } n   for (auto &f : e) n     if (du[f.u] > du[f.v] || (du[f.u] == du[f.v] && f.u < f.v)) n       G[f.u].push_back((_){f.v, f.w}); n     else n       G[f.v].push_back((_){f.u, f.w}); n   for (int u = 1; u <= n; u++) { n     for (auto &f : G[u]) fe[f.v] = f.w; n     for (auto &f : G[u]) n       for (auto &p : G[f.v]) n         if (fe[p.v]) n           ans += mu[u] * mu[f.v] * mu[p.v] * n                  (a[f.w] * b[p.w] * c[fe[p.v]] + a[f.w] * b[fe[p.v]] * c[p.w] + n                   a[p.w] * b[f.w] * c[fe[p.v]] + a[fe[p.v]] * b[f.w] * c[p.w] + n                   a[fe[p.v]] * b[p.w] * c[f.w] + a[p.w] * b[fe[p.v]] * c[f.w]); n     for (auto &f : G[u]) fe[f.v] = 0; n   } n   printf( %d n , int(ans & ((1 << 30) - 1))); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, m, n, a, ans; n   cin >> t; n   while (t--) { n     ans = 0; n     cin >> n >> m; n     for (int i = 0; i < n; i++) { n       cin >> a; n       ans += a; n     } n     if (n > m || n == 2) n       cout <<  -1  << endl; n     else { n       cout << 2 * ans << endl; n       for (int i = 1; i < n; i++) { n         cout << i <<     << i + 1 << endl; n       } n       cout <<  1  <<     << n << endl; n     } n   } 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(nullptr); n   int n, k; n   cin >> n >> k; n   set<long long> myset; n   for (int i = 0; i < n; i++) { n     int c; n     cin >> c; n     myset.insert(c); n   } n   auto it = myset.begin(); n   int ans = 0; n   do { n     long long x = (*it) * k; n     if (x != *it) { n       if (myset.count(x)) myset.erase(x); n     } n     ans++; n     if (it != myset.end()) it++; n   } while (it != myset.end()); n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n int n, k; n int a[maxn]; n long long pre[maxn]; n void read_input() { n   cin >> n >> k; n   for (int i = 1; i <= n; ++i) cin >> a[i]; n } n void init() { n   for (int i = 1; i <= n; ++i) pre[i] = pre[i - 1] + a[i]; n } n vector<int> get_divs(int x) { n   vector<int> res; n   for (int i = 2; i * 1LL * i <= x; ++i) n     if (x % i == 0) { n       res.push_back(i); n       if (i * i != x) res.push_back(x / i); n     } n   return res; n } n void solve() { n   if (pre[n] % k != 0) { n     cout <<  No n ; n     return; n   } n   int x = pre[n] / k; n   int cur = 1, lst = 0; n   vector<int> ans; n   for (int i = 1; i <= n; ++i) n     if (pre[i] == cur * x) { n       ans.push_back(i - lst); n       lst = i; n       ++cur; n     } n   if ((int)ans.size() != k) { n     cout <<  No n ; n     return; n   } n   cout <<  Yes n ; n   for (auto& x : ans) cout << x <<    ; n   cout <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   read_input(); n   init(); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n long long s, x; n int main() { n   cin >> s >> x; n   s -= x; n   if (s < 0 || s % 2 != 0) { n     cout << 0 << endl; n     return 0; n   } n   s /= 2; n   if (s & x) { n     cout << 0 << endl; n     return 0; n   } n   long long bit = 0, result = 0; n   if (!s) result -= 2; n   while (x > 0) { n     bit += x & 1; n     x >>= 1; n   } n   result += 1LL << bit; n   cout << result << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a, n, trans = 0, cnt = 0, b, c, m, s, d; n   vector<int> v, vd; n   cin >> n; n   for (long long x = 0; x < n; x++) { n     cin >> m; n     v.clear(); n     for (long long j = 0; j < m; j++) { n       cin >> d; n       v.push_back(d); n     } n     sort(v.rbegin(), v.rend()); n     vd.clear(); n     trans = 0; n     for (long long j = 1; j < v.size(); j++) { n       if ((v[j] - v[0]) % 2 != 0) { n         trans = 1; n         cout <<  NO  << endl; n         break; n       } n     } n     if (trans == 0) cout <<  YES  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[303][303], dp[602][301][301], n; n bool valid(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < n); } n int update(int d, int x1, int x2) { n   if (x2 < x1) swap(x1, x2); n   int y1 = d - x1, y2 = d - x2; n   if (!valid(x1, y1) || !valid(x2, y2)) return INT_MIN; n   if (dp[d][x1][x2] != INT_MIN) return dp[d][x1][x2]; n   for (long long mask = 0; mask < 4; mask++) { n     dp[d][x1][x2] = max(dp[d][x1][x2], n                         update(d - 1, x1 - (mask & 1), x2 - ((mask & 2) >> 1))); n   } n   if (dp[d][x1][x2] == INT_MIN) dp[d][x1][x2] = 0; n   dp[d][x1][x2] += a[x1][y1] + (x1 != x2 ? a[x2][y2] : 0); n   return dp[d][x1][x2]; n } n int main() { n   cin >> n; n   for (long long i = 0; i < n; i++) n     for (long long j = 0; j < n; j++) cin >> a[i][j]; n   for (long long i = 0; i < 2 * n; i++) n     for (long long j = 0; j < n; j++) n       for (long long k = 0; k < n; k++) dp[i][j][k] = INT_MIN; n   cout << update(2 * n - 2, n - 1, n - 1) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<long int, long int>> adj[100001]; n bool visit[100001] = {}; n long int val[100001]; n long int ans = 0; n void dfs(long int node, long int w) { n   if (w > val[node]) { n     return; n   } n   ans++; n   for (long int i = 0; i < (int)adj[node].size(); i++) { n     dfs(adj[node][i].first, max(w + adj[node][i].second, (long int)0)); n   } n   return; n } n int main() { n   long int n; n   cin >> n; n   for (long int i = 1; i <= n; i++) cin >> val[i]; n   for (long int i = 1; i <= n - 1; i++) { n     long int x, y; n     cin >> x >> y; n     adj[x].push_back(make_pair(i + 1, y)); n   } n   dfs(1, 0); n   cout << n - ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace rel_ops; n struct Fraction { n   long long p, q; n   static inline __attribute__((always_inline)) long long gcd(long long a, n                                                              long long b) { n     while (b ^= a ^= b ^= a = a % b) n       ; n     return a; n   } n   inline __attribute__((always_inline)) void clear() { p = 0, q = 1; } n   inline __attribute__((always_inline)) Fraction() { clear(); } n   inline __attribute__((always_inline)) Fraction(long long a, long long b) { n     p = a, q = b; n   } n   inline __attribute__((always_inline)) Fraction& simplify() { n     long long x = gcd(p, q); n     p /= x, q /= x; n     return *this; n   } n   inline __attribute__((always_inline)) bool operator<( n       const Fraction& rhs) const { n     return p * rhs.q < rhs.p * q; n   } n   inline __attribute__((always_inline)) bool operator==( n       const Fraction& rhs) const { n     return p * rhs.q == rhs.p * q; n   } n }; n const int N = 1e5 + 5; n pair<Fraction, Fraction> d[N]; n int n; n long long ans; n inline __attribute__((always_inline)) bool pffcomp( n     const pair<Fraction, Fraction>& a, const pair<Fraction, Fraction>& b) { n   return a.first < b.first || (a.first == b.first && a.second > b.second); n } n void mergesort(int l, int r) { n   static pair<Fraction, Fraction> tmp[N]; n   if (l >= r) return; n   int mid = (l + r) >> 1; n   mergesort(l, mid); n   mergesort(mid + 1, r); n   int pl = l, pr = mid + 1, pt = l; n   while (pl <= mid && pr <= r) { n     if (d[pl].second < d[pr].second) n       tmp[pt++] = d[pl++]; n     else { n       ans += mid - pl + 1; n       tmp[pt++] = d[pr++]; n     } n   } n   while (pl <= mid) tmp[pt++] = d[pl++]; n   while (pr <= r) tmp[pt++] = d[pr++]; n   for (pt = l; pt <= r; ++pt) d[pt] = tmp[pt]; n } n int main() { n   int w; n   scanf( %d%d , &n, &w); n   for (int i = 1, x, v; i <= n; ++i) { n     scanf( %d%d , &x, &v); n     d[i] = make_pair(Fraction(-x, v - w).simplify(), n                      Fraction(-x, v + w).simplify()); n   } n   sort(d + 1, d + 1 + n, pffcomp); n   mergesort(1, n); n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void imGonnaDoIt() { n   long long r, x, y, xx, yy; n   cin >> r >> x >> y >> xx >> yy; n   cout << ceil(hypot((x - xx), (y - yy)) / (r * 2)); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   imGonnaDoIt(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   map<string, int> puncte, cnt, goluri, rateu; n   int x, y; n   char c1[25], c2[25]; n   for (int i = 0; i < 5; i++) { n     scanf( %s%s%d:%d , c1, c2, &x, &y); n     cnt[c1]++; n     cnt[c2]++; n     if (x > y) { n       puncte[c1] += 3; n     } n     if (x < y) { n       puncte[c2] += 3; n     } n     if (x == y) { n       puncte[c1]++; n       puncte[c2]++; n     } n     goluri[c1] += x; n     rateu[c1] += y; n     goluri[c2] += y; n     rateu[c2] += x; n   } n   string czn; n   vector<string> echipe; n   for (auto &s : cnt) { n     echipe.push_back(s.first); n     if (s.second == 2 && s.first !=  BERLAND ) { n       czn = s.first; n     } n   } n   for (int i = 1; i < 100; i++) { n     for (int j = 0; j < 100; j++) { n       int k = i + j; n       goluri[ BERLAND ] += k; n       rateu[ BERLAND ] += j; n       goluri[czn] += j; n       rateu[czn] += k; n       puncte[ BERLAND ] += 3; n       vector<tuple<int, int, int, string>> w; n       for (auto &s : echipe) { n         w.push_back( n             make_tuple(-puncte[s], -goluri[s] + rateu[s], -goluri[s], s)); n       } n       sort(w.begin(), w.end()); n       if (get<3>(w[0]) ==  BERLAND  || get<3>(w[1]) ==  BERLAND ) { n         printf( %d:%d , k, j); n         return 0; n       } n       puncte[ BERLAND ] -= 3; n       goluri[ BERLAND ] -= k; n       rateu[ BERLAND ] -= j; n       goluri[czn] -= j; n       rateu[czn] -= k; n     } n   } n   printf( IMPOSSIBLE ); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const long long mod = 998244353; n long long sum[55][100005], f[55][100005], t[100005]; n int l[55], r[55]; n int add(int p, int x, int y) { n   if (x < 0) return 0; n   if (y < 0) return sum[p][x]; n   return sum[p][x] - sum[p][y]; n } n long long solve1(int n, int m) { n   long long ans = 0; n   for (int i = l[1]; i <= r[1]; i++) f[1][i] = 1; n   for (int i = 1; i <= m; i++) sum[1][i] = (sum[1][i - 1] + f[1][i]) % mod; n   for (int i = 2; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       f[i][j] = add(i - 1, j - l[i], j - r[i] - 1); n       sum[i][j] = (sum[i][j - 1] + f[i][j]) % mod; n     } n   } n   for (int i = 1; i <= m; i++) ans = (ans + f[n][i]) % mod; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) f[i][j] = sum[i][j] = 0; n   return ans; n } n long long solve2(int n, int m, int d) { n   long long ans = 0; n   for (int i = d; i <= m; i += d) n     if (i >= l[1] && i <= r[1]) f[1][i] = 1; n   for (int i = d; i <= m; i += d) sum[1][i] = f[1][i] + sum[1][i - d]; n   for (int i = 2; i <= n; i++) { n     for (int j = d; j <= m; j += d) { n       int R = j - l[i] - ((j - l[i]) % d + d) % d; n       int L = j - r[i] - ((j - r[i]) % d + d) % d; n       if ((j - r[i]) % d == 0) L -= d; n       f[i][j] = add(i - 1, R, L); n       sum[i][j] = (sum[i][j - d] + f[i][j]) % mod; n     } n   } n   for (int i = d; i <= m; i += d) ans = (ans + f[n][i]) % mod; n   for (int i = 1; i <= n; i++) n     for (int j = d; j <= m; j += d) f[i][j] = sum[i][j] = 0; n   return ans; n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d%d , &l[i], &r[i]); n   long long ans = solve1(n, m); n   for (int d = 2; d <= m / n; d++) { n     ans = ((ans - (1 - t[d]) * solve2(n, m, d)) % mod + mod) % mod; n     for (int j = 2; j * d <= m; j++) t[j * d] += 1 - t[d]; n   } n   printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n void solve() { n   int n, z; n   std::cin >> n >> z; n   std::vector<int> xs(n); n   for (auto& x : xs) std::cin >> x; n   std::sort(xs.begin(), xs.end()); n   int ok = 0, ng = n / 2 + 1; n   while (ng - ok > 1) { n     int k = (ok + ng) / 2; n     bool judge = true; n     for (int i = 0; i < k; ++i) { n       if (xs[n - k + i] - xs[i] < z) judge = false; n     } n     if (judge) { n       ok = k; n     } else { n       ng = k; n     } n   } n   std::cout << ok <<   n ; n } n int main() { n   std::cin.tie(nullptr); n   std::ios::sync_with_stdio(false); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c; n   cin >> a >> b >> c; n   bool flag = 0; n   int by1, by2; n   int x, y; n   for (int i = 0; i <= a; i++) { n     x = a - i; n     y = i; n     by1 = b - x; n     by2 = c - y; n     if (by1 == by2 and by1 >= 0) { n       flag = 1; n       break; n     } n   } n   if (flag) n     cout << x <<     << by1 <<     << y << endl; n   else n     cout <<  Impossible  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m; n string s; n long long q; n char ch; n long long k = 0; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m >> s; n   for (long long i = 0; i < n - 1; i++) n     if (s[i] ==  .  && s[i + 1] ==  . ) k++; n   for (long long i = 0; i < m; i++) { n     cin >> q >> ch; n     q--; n     if ((q > 0 && s[q - 1] ==  . ) || (q < n - 1 && s[q + 1] ==  . )) { n       if (ch ==  . ) { n         if (s[q] !=  . ) { n           if ((q > 0 && s[q - 1] ==  . ) && (q < n - 1 && s[q + 1] ==  . )) n             k += 2; n           else n             k++; n         } n       } else { n         if (s[q] ==  . ) { n           if ((q > 0 && s[q - 1] ==  . ) && (q < n - 1 && s[q + 1] ==  . )) n             k -= 2; n           else n             k--; n         } n       } n     } n     s[q] = ch; n     if (i > 0) cout <<   n ; n     cout << k; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int arr[100100]; n vector<int> adj[100100]; n int cnt[100100]; n queue<int> q[2]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; ++i) scanf( %d , &arr[i]); n   for (int i = 0; i < m; ++i) { n     int u, v; n     scanf( %d%d , &u, &v); n     adj[v].push_back(u); n     cnt[u]++; n   } n   for (int i = 0; i < n; ++i) { n     if (cnt[i] == 0) { n       q[arr[i]].push(i); n     } n   } n   int ans = 0; n   while (1) { n     int a = q[0].size(), b = q[1].size(); n     if (a + b == 0) break; n     for (int i = 0; i < 2; ++i) { n       if (!q[i].empty() && i == 1) ans++; n       while (!q[i].empty()) { n         int u = q[i].front(); n         q[i].pop(); n         for (int j = 0; j < adj[u].size(); ++j) { n           int to = adj[u][j]; n           cnt[to]--; n           if (!cnt[to]) { n             q[arr[to]].push(to); n           } n         } n       } n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   int total = 0; n   for (int i = 1; i <= n; ++i) { n     int temp; n     cin >> temp; n     if (n - i < m) { n       total += min(k, temp); n     } else { n       total += temp; n     } n   } n   cout << total << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n; n   long long int k; n   cin >> n; n   cin >> k; n   long long int arr[k]; n   for (long long int i = 0; i < k; i++) cin >> arr[i]; n   long long minrem = n % arr[0]; n   long long number = 0; n   long long pos = 0; n   for (long long int i = 0; i < k; i++) { n     long long int rem = n % arr[i]; n     if (minrem >= rem) { n       number = n / arr[i]; n       minrem = rem; n       pos = i; n     } n   } n   cout << (pos + 1) <<     << number; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 10; n const int M = 128; n const int inf = 0x7fffffff; n const long long INF = 9E18; n const int mod = 1e9 + 7; n int tree[maxn << 2][2], a[maxn]; n int in[maxn], out[maxn], dis[maxn]; n int dfs_clock = 0; n vector<int> g[maxn]; n void dfs(int u, int fa) { n   dis[u] = dis[fa] ^ 1; n   in[u] = ++dfs_clock; n   for (int i = 0; i < g[u].size(); i++) { n     int to = g[u][i]; n     if (to == fa) continue; n     dfs(to, u); n   } n   out[u] = dfs_clock; n } n void pushdown(int rt, int odd) { n   if (tree[rt][odd]) { n     tree[rt << 1 | 1][odd] += tree[rt][odd]; n     tree[rt << 1][odd] += tree[rt][odd]; n     tree[rt][odd] = 0; n   } n } n void update(int x, int y, int l, int r, int val, int odd, int rt) { n   if (x <= l && r <= y) { n     tree[rt][odd] += val; n     return; n   } n   pushdown(rt, odd); n   int mid = (l + r) >> 1; n   if (x <= mid) update(x, y, l, mid, val, odd, rt << 1); n   if (y > mid) update(x, y, mid + 1, r, val, odd, rt << 1 | 1); n } n int query(int p, int l, int r, int rt, int odd) { n   if (l == r) { n     return tree[rt][odd]; n   } n   pushdown(rt, odd); n   int mid = (l + r) >> 1; n   if (p <= mid) n     return query(p, l, mid, rt << 1, odd); n   else n     return query(p, mid + 1, r, rt << 1 | 1, odd); n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 0; i < n - 1; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     g[x].push_back(y); n     g[y].push_back(x); n   } n   dis[0] = 0; n   dfs(1, 0); n   for (int i = 0; i < m; i++) { n     int op; n     scanf( %d , &op); n     if (op == 1) { n       int x, val; n       scanf( %d%d , &x, &val); n       update(in[x], out[x], 1, n, val, dis[x], 1); n       update(in[x], out[x], 1, n, -val, dis[x] ^ 1, 1); n     } else { n       int num; n       scanf( %d , &num); n       cout << query(in[num], 1, n, 1, dis[num]) + a[num] <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1010; n int n, q, ans; n int mat[maxn][maxn]; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       int k; n       scanf( %d , &k); n       if (i == j) { n         ans += k; n       } n     } n   } n   ans %= 2; n   cin >> q; n   for (int i = 0; i < q; i++) { n     int c; n     scanf( %d , &c); n     if (c == 1 || c == 2) { n       int bucket; n       scanf( %d , &bucket); n       ans = (ans + 1) % 2; n     } else { n       printf( %d , ans); n     } n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 81; n const int inf = 1e9; n int n, c, a[N]; n int dp[N][N][N * N]; n vector<int> vc; n int main() { n   scanf( %d , &n); n   c = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     c += a[i]; n     if (a[i]) vc.push_back(i); n   } n   int m = n * (n - 1) / 2; n   for (int i = 0; i <= n; i++) { n     for (int j = 0; j <= c; j++) { n       for (int k = 0; k <= m; k++) { n         dp[i][j][k] = (j == 0 && k == 0) ? 0 : -inf; n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= c; j++) { n       for (int k = 0; k <= m; k++) { n         if (j > i) continue; n         int tmp = vc[j - 1]; n         for (int p = 1; p <= i; p++) { n           int ops = abs(tmp - p); n           if (k < ops) continue; n           dp[i][j][k] = n               max(dp[i][j][k], dp[p - 1][j - 1][k - ops] + (p - j) * (i - p)); n         } n       } n     } n   } n   int mx = -inf; n   for (int i = 0; i <= n * (n - 1) / 2; i++) { n     mx = max(mx, dp[n][c][i]); n     printf( %d  , mx); n   } n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n void cass() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n const int N = 10; n int n, a[N], res = 1e9, x[N]; n string s; n void read() { n   cin >> s; n   n = 6; n   for (int i = 0; i < s.length(); ++i) a[i + 1] = s[i] -  0 ; n } n void cmp() { n   int sum1 = x[1] + x[2] + x[3]; n   int sum2 = x[4] + x[5] + x[6]; n   if (sum1 != sum2) return; n   int dem = 0; n   for (int i = 1; i <= n; ++i) n     if (a[i] != x[i]) dem++; n   res = min(res, dem); n } n void tried(int i) { n   for (int j = 0; j <= 9; ++j) { n     x[i] = j; n     if (i == n) n       cmp(); n     else n       tried(i + 1); n   } n } n int main() { n   cass(); n   read(); n   tried(1); n   cout << res; n   return 0; n } n


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


#include<bits/stdc++.h> n  n #define pb push_back n #define x first n #define y second n #define all(a) (a).begin(), (a).end() n  n using namespace std; n  n typedef long long ll; n typedef pair<int, int> ii; n  n const int maxn = 3e5 + 5; n  n int n, m, X; n ll A[maxn]; n int par[maxn]; n set<pair<ll, ii>> adj[maxn]; n map<ii, int> pos; n set<pair<ll, int>> s; n int exists = 1; n  n int find(int x) {return (x == par[x]) ? x : par[x] = find(par[x]);} n  n int merge(int x, int y) { n  x = find(x), y = find(y); n  if(x == y) return 0; n   n  if(adj[x].size() < adj[y].size()) swap(x, y); n  par[y] = x; n  s.erase({A[y], y}); n  s.erase({A[x], x}); n  A[x] += A[y]; n  A[x] -= X; n  s.insert({A[x], x}); n  if(A[x] < 0) exists = 0; n  for(auto p : adj[y]) adj[x].insert(p); n  return 1; n } n  n int main() { n  scanf( %d %d %d , &n, &m, &X); n  for(int i = 0;i < n;i++) scanf( %lld , A + i); n  for(int i = 0;i < n;i++) par[i] = i; n  for(int i = 0;i < m;i++) { n   int x, y; n   scanf( %d %d , &x, &y); n   x--, y--; n   if(x > y) swap(x, y); n   pos[{x, y}] = i + 1; n   adj[x].insert({A[y], {x, y}}); n   adj[y].insert({A[x], {x, y}}); n  } n   n  vector<int> ans; n  for(int i = 0;i < n;i++) s.insert({A[i], i}); n  for(int i = 0;i < n - 1;i++) { n   auto it1 = s.end();it1--; n   auto p1 = *it1; n    n   while(1) { n    auto it2 = adj[p1.y].end();it2--; n    auto p2 = *it2; n    int flag = merge(p2.y.x, p2.y.y); n    if(flag) { n     ans.pb(pos[{p2.y.x, p2.y.y}]); n     break; n    } n    adj[p1.y].erase(it2); n   } n   if(!exists) {printf( NO n );return 0;} n  } n   n  printf( YES n ); n  for(int i : ans) printf( %d n , i); n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200100; n struct seat { n   int w, id; n   bool operator<(const seat& st) const { return w < st.w; } n   bool operator>(const seat& st) const { return w > st.w; } n }; n seat st[maxn]; n int n; n char tp[maxn * 2]; n int main() { n   while (scanf( %d , &n) == 1) { n     for (int i = 1; i <= n; i++) { n       scanf( %d , &st[i].w); n       st[i].id = i; n     } n     scanf( %s , tp); n     sort(st + 1, st + 1 + n); n     priority_queue<seat, vector<seat>, less<seat>> que; n     int cnt = 1; n     for (int i = 0; i < n * 2; i++) { n       if (tp[i] ==  0 ) { n         printf( %d  , st[cnt].id); n         que.push(st[cnt]); n         cnt++; n       } else { n         printf( %d  , que.top().id); n         que.pop(); n       } n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 9; n int arr[maxn]; n int vis[maxn]; n int n; n int mu; n long long re[111]; n long long gcd(long long a, long long b) { n   long long c = 1; n   while (b) { n     c = a % b; n     a = b; n     b = c; n   } n   return a; n } n int sol(int a) { n   vis[a] = 1; n   int e = arr[a]; n   if (vis[e]) { n     if (e == mu) { n       return 1; n     } else { n       return -1; n     } n   } else { n     int g = sol(e); n     if (g == -1) n       return -1; n     else n       return g + 1; n   } n } n int main() { n   int a, b, c, d, e, f, g, h; n   while (scanf( %d , &n) == 1) { n     for (d = 1; d <= n; d++) { n       scanf( %d , &arr[d]); n     } n     memset(vis, 0, sizeof(vis)); n     g = 0; n     h = 0; n     a = 0; n     for (d = 1; d <= n; d++) { n       if (!vis[d]) { n         mu = d; n         e = sol(d); n         if (e == -1) { n           g = -1; n           break; n         } n         if (e % 2) { n           re[a++] = e; n         } else n           re[a++] = e / 2; n       } n     } n     if (g < 0) { n       printf( -1 n ); n     } else { n       long long res = 1, tmp; n       for (d = 0; d < a; d++) { n         tmp = gcd(res, re[d]); n         res = res * re[d] / tmp; n       } n       cout << res << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int ar[500009], br[500009]; n int main() { n   long long int a, b, c, i, j = 999999999999, k, e, f, g, w, h, i1, j1; n   string s, d; n   cin >> a >> b >> c; n   e = a; n   c = c * 5; n   j = a; n   for (i = 1;; i++) { n     a = e; n     if (a - (i * b) < 0) { n       break; n     } n     a = a - (i * b); n     a = a - ((a / c) * c); n     j = min(j, a); n   } n   for (i = 1;; i++) { n     a = e; n     if (a - (i * c) < 0) { n       break; n     } n     a = a - (i * c); n     a = a - ((a / b) * b); n     j = min(j, a); n   } n   cout << j << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void pv(T a, T b) { n   for (T i = a; i != b; ++i) cerr << *i <<    ; n   cerr << endl; n } n int main() { n   for (long long N, M; cin >> N >> M;) { n     for (int i = 0; i < (int)(N); ++i) { n       long long S, F, T; n       cin >> S >> F >> T; n       if (S == F) { n         cout << T << endl; n         continue; n       } n       long long loop = (M - 1) * 2; n       long long ans = 0; n       if (S < F) { n         ans = T / loop * loop; n         T = T % loop; n         if (S - 1 < T) ans += (M - 1) * 2; n         ans += F - 1; n       } else { n         ans = T / loop * loop; n         T = T % loop; n         if (M - S + M - 1 < T) ans += (M - 1) * 2; n         ans += M - 1; n         ans += (M - F); n       } n       cout << ans << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[300001], d[300001]; n long long b[300001], c[300001]; n map<int, int> mp; n int main() { n   int n, i, l, r, j, k; n   long long s, _s; n   for (scanf( %d , &n), i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     b[i] = b[i - 1] + a[i]; n     c[i] = c[i - 1] + (a[i] > 0 ? a[i] : 0); n     d[i] = d[i - 1] + (a[i] < 0); n     if (!mp.count(a[i])) mp[a[i]] = i; n   } n   for (i = n, s = 1ll << 63; i; i--) { n     j = mp[a[i]]; n     if (i == j) continue; n     _s = c[i] - c[j - 1]; n     if (a[i] < 0) _s += 2 * a[i]; n     if (_s > s) { n       s = _s; n       l = j; n       r = i; n     } n   } n   printf( %I64d %d n , s, d[r - 1] - d[l] + l - 1 + n - r); n   for (i = 1; i < l; i++) printf( %d  , i); n   for (i = l + 1; i < r; i++) { n     if (a[i] < 0) printf( %d  , i); n   } n   for (i = r + 1; i <= n; i++) printf( %d  , i); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> x_coord, y_coord; n vector<vector<int>> adj; n vector<bool> used; n int n; n void dfs(int v) { n   used[v] = true; n   for (auto u : adj[v]) { n     if (!used[u]) { n       used[u] = true; n       dfs(u); n     } n   } n } n int main() { n   scanf( %d , &n); n   x_coord.resize(n); n   y_coord.resize(n); n   adj.resize(n); n   for (int i = 0; i < n; i++) { n     scanf( %d%d , &x_coord[i], &y_coord[i]); n     for (int j = 0; j < i; j++) { n       if (x_coord[j] == x_coord[i] || y_coord[j] == y_coord[i]) { n         adj[i].push_back(j); n         adj[j].push_back(i); n       } n     } n   } n   used.resize(n, false); n   int cnt = 0; n   for (int i = 0; i < n; i++) { n     if (!used[i]) { n       cnt++; n       dfs(i); n     } n   } n   printf( %d n , cnt - 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-8; n const int mod = 1e9 + 7; n const int N = 1e6 + 10; n const int inf = 1e9; n int t, n, a[N], b[N]; n int gao(int x) { n   int res = b[1] - x; n   for (int i = 2; i <= n; i++) { n     res = b[i] - max(a[i] - res, 0); n     if (res < 0) return -1; n   } n   return res; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> t; n   while (t--) { n     cin >> n; n     for (int i = 1; i <= n; i++) cin >> a[i]; n     for (int i = 1; i <= n; i++) cin >> b[i]; n     int l = 0, r = b[1], ans = 0; n     while (l <= r) { n       int mid = l + r >> 1; n       int ret = gao(mid); n       if (ret == -1) { n         r = mid - 1; n       } else n         l = mid + 1; n       if (ret != -1 && ret + mid >= a[1]) { n         ans = 1; n       } n     } n     if (ans) n       puts( YES ); n     else n       puts( NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, mini = 0, maxi = 0; n int x[200005]; n bool o[200005]; n int main() { n   cin >> n; n   for (int i = 0; i < (n); i++) { n     int a; n     cin >> a; n     x[a]++; n   } n   for (int i = 0; i < (n + 1); i++) { n     while (i < n + 1 && x[i] == 0) i++; n     if (i == n + 1) break; n     mini++; n     i += 2; n   } n   for (int i = 0; i < (n + 1); i++) { n     while (i < n + 1 && x[i] == 0) i++; n     if (i == n + 1) break; n     for (int j = 0; j < (min(3, x[i])); j++) { n       if (!o[i - 1]) { n         o[i - 1] = true; n         maxi++; n       } else if (!o[i]) { n         o[i] = true; n         maxi++; n       } else if (!o[i + 1]) { n         o[i + 1] = true; n         maxi++; n       } n     } n   } n   cout << mini <<     << maxi << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   char ar[n]; n   for (int i = 0; i < n; ++i) { n     cin >> ar[i]; n   } n   int co = 0; n   vector<int> po; n   for (int i = 0; i < n - 1; ++i) { n     if (ar[i] ==  W ) { n       ar[i] =  B ; n       co++; n       po.push_back(i + 1); n       if (ar[i + 1] ==  B ) { n         ar[i + 1] =  W ; n       } else { n         ar[i + 1] =  B ; n       } n     } n   } n   if (ar[n - 1] ==  B ) { n     cout << co << endl; n     for (int i = 0; i < po.size(); ++i) { n       cout << po[i] <<    ; n     } n     cout << endl; n   } else { n     if (n % 2 == 0) { n       cout << -1 << endl; n     } else { n       cout << co + (n - 1) / 2 << endl; n       for (int i = 0; i < po.size(); ++i) { n         cout << po[i] <<    ; n       } n       for (int i = 0; i < (n - 1) / 2; ++i) { n         cout << 2 * i + 1 <<    ; n       } n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline void fast() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n const long long int mod = 1e9 + 7; n long long int pmod(long long int x, long long int n) { n   long long int r = 1; n   while (n) { n     if (n & 1LL) r = (r * x) % mod; n     x = (x * x) % mod; n     n = n / 2; n   } n   return r; n } n void solve() { n   long long int a, b; n   cin >> a >> b; n   if (a < b) { n     cout << -1; n     return; n   } n   long long int d1 = (a + b) / 2; n   d1 /= b; n   d1 = d1 * 2; n   double ans = (double)(a + b) / d1; n   cout << setprecision(10) << ans; n } n int main() { n   fast(); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   if (n <= 2) cout << -1; n   if (n == 3) cout << 210; n   if (n >= 4) { n     string s =  1 ; n     int sign; n     int z = 0; n     if (n % 3 == 0) z = 100; n     if (n % 3 == 1) z = 1; n     if (n % 3 == 2) z = 10; n     if (((n - 1) / 3) % 2 == 0) n       sign = 1; n     else n       sign = -1; n     for (int i = 1; i < n; i++) s +=  0 ; n     bool OK = false; n     for (char i =  0 ; i <=  9 ; i++) { n       for (char j =  0 ; j <=  9 ; j++) { n         s[n - 2] = j; n         s[n - 3] = i; n         if (((1 + s[n - 2] -  0  + s[n - 3] -  0 ) % 3 == 0) && n             (((s[n - 3] -  0 ) * 100 + (s[n - 2] -  0 ) * 10 + z * sign) % 7 == n              0)) { n           cout << s; n           OK = true; n           break; n         } n       } n       if (OK) break; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 998244353; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   long long k; n   cin >> n >> k; n   if (!k) { n     cout <<  0 n ; n     return 0; n   } n   vector<int> h(n); n   for (int i = 0; i < n; i++) { n     cin >> h[i]; n   } n   h.push_back(h[0]); n   long long** dp; n   dp = new long long*[n + 79]; n   for (int i = 0; i < n + 2; i++) { n     dp[i] = new long long[2 * n + 79]; n     for (int j = 0; j < 2 * n + 79; j++) { n       dp[i][j] = 0; n     } n   } n   dp[0][n + 1] = 1; n   for (int i = 1; i <= n; i++) { n     for (int score = 1; score <= 2 * n + 2; score++) { n       if (h[i] != h[i - 1]) { n         dp[i][score] += dp[i - 1][score - 1]; n         dp[i][score] += dp[i - 1][score + 1]; n         dp[i][score] += (dp[i - 1][score] * (k - 2ll)) % mod; n       } else { n         dp[i][score] = dp[i - 1][score] * k; n       } n       dp[i][score] %= mod; n     } n   } n   long long ans = 0; n   for (int score = n + 2; score <= 2 * n + 1; score++) { n     ans += dp[n][score]; n   } n   cout << (ans % mod) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, x, i, p; n   char y; n   string ch =   ; n   cin >> n >> k; n   for (i = 0; i < k; i++) { n     p = 97 + i; n     y = (char)p; n     ch += y; n   } n   if (n == k) n     cout << ch; n   else { n     x = n - k; n     i = 0; n     while (x--) { n       ch += ch[i]; n       i++; n     } n     cout << ch; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); n const long long inf = 1e15 + 7; n bool check(long long n) { return __builtin_popcount(n + 1) == 1; } n vector<long long> res; n bool solve(long long n, long long k, long long par) { n   if (n == 11 && k == 3) { n     res[10] = par; n     res[9] = 10; n     res[8] = 9; n     res[7] = 9; n     return solve(7, 2, 10); n   } n   if (k <= 1) { n     if ((!check(n) && k == 0) || (check(n) && k == 1)) return false; n     res[0] = par; n     for (long long i = 1; i < n; i++) res[i] = (i - 1) / 2; n     return true; n   } n   if (k == 2 && check(n - 2)) { n     res[n - 1] = par; n     res[n - 2] = n - 1; n     res[n - 3] = n - 2; n     res[n - 4] = n - 2; n     return solve(n - 4, k - 1, n - 1); n   } n   res[n - 1] = par; n   res[n - 2] = n - 1; n   return solve(n - 2, k - 1, n - 1); n } n signed main() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(0); n   long long n, k; n   cin >> n >> k; n   if (n == 1 && k == 0) { n     cout <<  YES  << endl << 0; n     return 0; n   } n   if (n % 2 == 0 || (n - 3) / 2 < k || (k == 0 && !check(n)) || n       (k == 1 && check(n)) || (k == 2 && n == 9)) { n     cout <<  NO ; n     return 0; n   } n   res.resize(n); n   bool temp = solve(n, k, -1); n   if (!temp) cout <<  Bad  << endl; n   cout <<  YES  << endl; n   for (long long i : res) cout << i + 1 <<    ; n } n


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


#include <bits/stdc++.h> n using namespace std; n long long int binary_exp(long long int a, long long int n) { n   long long int i = 1; n   while (n > 0) { n     if (n % 2 == 1) i = (i * a) % 1000000007; n     a = (a * a) % 1000000007; n     n /= 2; n   } n   return i; n } n long long int IsPrime(long long int n) { n   if (n == 0 || n == 1) return n; n   if (n % 2 == 0) return (long long int)2; n   if (n % 3 == 0) n     return (long long int)3; n   else { n     for (long long int i = 5; i * i <= n; i += 6) { n       if (n % i == 0) return i; n       if (n % (i + 2) == 0) return (i + 2); n     } n     return n; n   } n } n void solve() { n   int n, i, j, k, a, b, mex = 1, ans = 0; n   cin >> n; n   int ind[n + 1]; n   bool vis[n + 1]; n   memset(vis, false, sizeof(vis)); n   for (i = 1; i <= n; i++) { n     cin >> k; n     ind[k] = i; n   } n   for (i = 1; i <= n; i++) { n     cin >> k; n     vis[ind[k]] = true; n     while (mex <= n && vis[mex]) mex++; n     if (ind[k] > mex) ans++; n   } n   cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   srand(time(NULL)); n   ; n   int t = 1; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 3e5 + 5, inf = 1e9 + 7; n long long int bigmod(long long int b, long long int p, long long int m) { n   long long int rt = 1; n   while (p) { n     if (p & 1) rt = (rt * b) % m; n     b = (b * b) % m; n     p >>= 1; n   } n   return rt; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int tc = 1, t = 0; n   while (tc--) { n     long long int x, n; n     cin >> x >> n; n     vector<long long int> prim; n     for (int i = 2; i * i <= x; i++) { n       if (x % i == 0) { n         prim.push_back(i); n         while (x % i == 0) x /= i; n       } n     } n     if (x > 1) prim.push_back(x); n     long long int rs = 1; n     for (auto x : prim) { n       long long int fact = x, pw = 0; n       while (fact <= n) { n         pw += n / fact; n         if (n / x >= fact) n           fact *= x; n         else n           break; n       } n       rs *= bigmod(x, pw, inf); n       rs %= inf; n     } n     cout << rs <<   n ; n   } n   return 0; n } n