#include <bits/stdc++.h> n using namespace std; n bool is_prime[100000]; n void gen_is_primes(int n); n void gen_prime_groups(int n, vector<bool>& to_match, n                       list<int>& candidate_primes, n                       list<pair<int, int> >& groups); n void gen_prime_groups(int n, int p, vector<bool>& to_match, n                       list<pair<int, int> >& groups); n void gen_unmatched_multiples(int n, int i, vector<bool>& to_match, n                              list<int>& unmatched_multiples); n void gen_even_groups(vector<bool>& to_match, list<pair<int, int> >& groups); n void gen_is_primes(int n) { n   fill_n(is_prime, n, true); n   is_prime[0] = false; n   is_prime[1] = false; n   for (int i = 2; i <= n / 2; i++) { n     if (is_prime[i]) { n       for (int j = 2 * i; j <= n; j += i) { n         is_prime[j] = false; n       } n     } n   } n } n void gen_prime_groups(int n, vector<bool>& to_match, n                       list<int>& candidate_primes, n                       list<pair<int, int> >& groups) { n   for (list<int>::iterator i = candidate_primes.begin(); n        i != candidate_primes.end(); i++) { n     gen_prime_groups(n, *i, to_match, groups); n   } n } n void gen_prime_groups(int n, int p, vector<bool>& to_match, n                       list<pair<int, int> >& groups) { n   list<int>* unmatched_multiples = new list<int>(); n   gen_unmatched_multiples(n, p, to_match, *unmatched_multiples); n   for (list<int>::iterator it = unmatched_multiples->begin(); n        it != unmatched_multiples->end(); it++) { n     int curr = *it; n     int curr_partner = *(++it); n     to_match[curr] = false; n     to_match[curr_partner] = false; n     groups.push_back(make_pair(curr, curr_partner)); n   } n   delete unmatched_multiples; n } n void gen_unmatched_multiples(int n, int i, vector<bool>& to_match, n                              list<int>& unmatched_multiples) { n   for (int curr_multiple = i; curr_multiple <= n; curr_multiple += i) { n     if (to_match[curr_multiple]) { n       unmatched_multiples.push_back(curr_multiple); n     } n   } n   if (unmatched_multiples.size() % 2 != 0) { n     unmatched_multiples.remove(2 * i); n   } n } n void gen_even_groups(vector<bool>& to_match, list<pair<int, int> >& groups) { n   list<int> unmatched; n   for (vector<bool>::iterator i = to_match.begin(); i != to_match.end(); i++) { n     if (*i) { n       int i_index = i - to_match.begin(); n       unmatched.push_back(i_index); n     } n   } n   if (unmatched.size() % 2 != 0) { n     unmatched.erase(unmatched.begin()); n   } n   for (list<int>::iterator i = unmatched.begin(); i != unmatched.end(); i++) { n     int curr = *i; n     int curr_partner = *(++i); n     groups.push_back(make_pair(curr, curr_partner)); n   } n } n int main() { n   int n; n   cin >> n; n   gen_is_primes(n); n   vector<bool> to_match(n, false); n   for (int i = 2; i <= n; i++) { n     to_match[i] = !is_prime[i] || (i <= n / 2); n   } n   list<int>* candidate_primes = new list<int>; n   for (int i = n / 2; i >= 3; i--) { n     if (is_prime[i]) { n       candidate_primes->push_back(i); n     } n   } n   list<pair<int, int> >* groups = new list<pair<int, int> >; n   gen_prime_groups(n, to_match, *candidate_primes, *groups); n   gen_even_groups(to_match, *groups); n   cout << groups->size() << endl; n   for (list<pair<int, int> >::iterator it = groups->begin(); n        it != groups->end(); it++) { n     cout << it->first <<     << it->second << endl; n   } n   delete groups; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n long long MOD9 = 998244353; n long long MOD = 1000000007; n double eps = 1e-12; n void solve() { n   int n; n   cin >> n; n   vector<pair<int, int> > v(n); n   for (int i = 0; i < n; i++) cin >> v[i].first >> v[i].second; n   sort((v).begin(), (v).end()); n   int p = 0, c = 0; n   for (int i = 1; i < n; i++) { n     if (v[i].second < v[p].second) n       c++; n     else n       p = i; n   } n   cout << c <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   { solve(); } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, d1, d2; n bool d[400001]; n int a[200001]; n int nextprime(int x) { n   for (int i = x + 1; i <= 2 * n; ++i) n     if (d[i]) return i; n   return 2 * n + 1000000; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n; n   int x; n   for (int i = 1; i <= n; ++i) { n     cin >> x; n     d1 += x == 1; n     d2 += x == 2; n   } n   memset(d, sizeof(d), 0); n   for (int i = 2; i <= 2 * n; ++i) { n     bool f = 1; n     for (int j = 2; j * j <= i; ++j) n       if (i % j == 0) { n         f = 0; n         break; n       } n     d[i] = f; n   } n   int prime = 0; n   int t = n; n   while (n > 0) { n     int tmp = nextprime(prime); n     while (tmp - prime >= 2 && d2 > 0 && n > 0) prime += 2, d2--, a[n] = 2, n--; n     while (tmp - prime >= 1 && d1 > 0 && n > 0) prime += 1, d1--, a[n] = 1, n--; n     while (tmp - prime >= 1 && d1 == 0 && d2 > 0) n       prime += 2, d2--, a[n] = 2, n--; n   } n   for (int i = t; i > 0; --i) cout << a[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n long long pwr(long long base, long long p, long long mod = (1000000007LL)) { n   long long ans = 1; n   while (p) { n     if (p & 1) ans = (ans * base) % mod; n     base = (base * base) % mod; n     p /= 2; n   } n   return ans; n } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n const double eps = 1e-7; n struct PT { n   double x, y; n   PT() {} n   PT(double x, double y) : x(x), y(y) {} n   bool operator<(const PT &rhs) const { n     return make_pair(y, x) < make_pair(rhs.y, rhs.x); n   } n   bool operator==(const PT &rhs) const { n     return make_pair(y, x) == make_pair(rhs.y, rhs.x); n   } n }; n double cross(PT p, PT q) { return p.x * q.y - p.y * q.x; } n double area2(PT a, PT b, PT c) { n   return cross(a, b) + cross(b, c) + cross(c, a); n } n void ConvexHull(vector<PT> &pts) { n   sort(pts.begin(), pts.end()); n   pts.erase(unique(pts.begin(), pts.end()), pts.end()); n   vector<PT> up, dn; n   for (int i = 0; i < pts.size(); i++) { n     while (up.size() > 1 && area2(up[up.size() - 2], up.back(), pts[i]) > eps) n       up.pop_back(); n     while (dn.size() > 1 && area2(dn[dn.size() - 2], dn.back(), pts[i]) < -eps) n       dn.pop_back(); n     up.push_back(pts[i]); n     dn.push_back(pts[i]); n   } n   pts = dn; n   for (int i = (int)up.size() - 2; i >= 1; i--) pts.push_back(up[i]); n } n vector<PT> arr; n set<PT> banned; n int main() { n   int n1, n2; n   scanf( %d%d , &n1, &n2); n   int X, Y; n   scanf( %d%d , &X, &Y); n   while (n1--) { n     int x, y; n     scanf( %d%d , &x, &y); n     banned.insert(PT(x, y)); n     arr.push_back(PT(x, y)); n   } n   int max_x = -1, max_y = -1; n   while (n2--) { n     int x, y; n     scanf( %d%d , &x, &y); n     arr.push_back(PT(x, y)); n     max_x = max(max_x, x); n     max_y = max(max_y, y); n   } n   arr.push_back(PT(0, max_y)); n   arr.push_back(PT(max_x, 0)); n   arr.push_back(PT(0, 0)); n   ConvexHull(arr); n   for (auto it : arr) n     if (banned.find(it) != banned.end()) { n       printf( Max ); n       return 0; n     } n   printf( Min ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   short n; n   int n1, n2; n   bool state = false; n   char handle[11]; n   cin >> n; n   for (short i = 0; i < n; i++) { n     cin >> handle; n     cin >> n1; n     cin >> n2; n     if (n1 >= 2400 && n2 > n1) state = true; n   } n   if (state) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000 * 1000 * 1000 + 7; n const double EPS = 1e-9; n int bit_count(int first) { n   return first == 0 ? 0 : 1 + bit_count(first & (first - 1)); n } n inline int low_bit(int first) { return first & -first; } n inline int sign(double first) { n   return first < -EPS ? -1 : first > EPS ? 1 : 0; n } n inline int sign(int first) { return (first > 0) - (first < 0); } n int nextComb(int first) { n   if (!first) { n     fprintf(stderr,  nextComb(0) called n ); n     return ((1 << 30) - 1 + (1 << 30)); n   } n   int smallest = first & -first; n   int ripple = first + smallest; n   int ones = first ^ ripple; n   ones = (ones >> 2) / smallest; n   return ripple | ones; n } n template <class T> n inline T gcd(T a, T b) { n   a = abs(a); n   b = abs(b); n   while (b) { n     int r = a % b; n     a = b; n     b = r; n   } n   return a; n } n template <class T> n inline T lcm(T a, T b) { n   return a / gcd(a, b) * b; n } n inline int getInt() { n   int a; n   return scanf( %d , &a) ? a : (fprintf(stderr,  trying to read n ), -1); n } n inline double getDouble() { n   double a; n   return scanf( %lf , &a) ? a : (fprintf(stderr,  trying to read n ), -1.0); n } n inline double myRand() { n   return ((double)rand() / RAND_MAX) + ((double)rand() / RAND_MAX / RAND_MAX); n } n const int N = 109; n int s, c; n int Left[N], Right[N]; n vector<pair<int, pair<int, int> > > getOptions(int n) { n   vector<pair<int, pair<int, int> > > ret; n   for (int i = (int)0; i < (int)s; ++i) { n     if (Left[i] == -1) { n       int L = c - n / 2, R = c + (n - 1) / 2, cost = 0; n       for (int j = L; j <= R; ++j) cost += abs(c - i) + abs(c - j); n       ret.push_back(make_pair(cost, pair<int, int>(i, L))); n     } else { n       int L = Left[i] - n, R = Left[i] - 1, cost = 0; n       if (L >= 0) { n         for (int j = L; j <= R; ++j) cost += abs(c - i) + abs(c - j); n         ret.push_back(make_pair(cost, pair<int, int>(i, L))); n       } n       L = Right[i] + 1; n       R = Right[i] + n; n       cost = 0; n       if (R < s) { n         for (int j = L; j <= R; ++j) cost += abs(c - i) + abs(c - j); n         ret.push_back(make_pair(cost, pair<int, int>(i, L))); n       } n     } n   } n   return ret; n } n void update(int first, int a, int b) { n   if (Left[first] == -1) { n     Left[first] = a; n     Right[first] = b; n   } else { n     if (a < Left[first]) Left[first] = a; n     if (b > Right[first]) Right[first] = b; n   } n } n void myCode() { n   int n = getInt(); n   s = getInt(); n   c = s / 2; n   for (int i = (int)0; i < (int)s; ++i) Left[i] = Right[i] = -1; n   for (int i = (int)0; i < (int)n; ++i) { n     int first = getInt(); n     if (first > s) { n       printf( -1 n ); n       continue; n     } n     vector<pair<int, pair<int, int> > > a = getOptions(first); n     if (a.empty()) { n       printf( -1 n ); n       continue; n     } n     sort((a).begin(), (a).end()); n     printf( %d %d %d n , a[0].second.first + 1, a[0].second.second + 1, n            a[0].second.second + first); n     update(a[0].second.first, a[0].second.second, n            a[0].second.second + first - 1); n   } n } n int main() { n   srand(time(NULL)); n   myCode(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int graph[27]; n int grapht[27]; n vector<bool> used(27, false); n vector<bool> opened(27, false); n string result; n void dfs(int node) { n   used[node] = true; n   opened[node] = true; n   if (graph[node] == -1) { n     result += (node +  a ); n     opened[node] = false; n     return; n   } n   if (opened[graph[node]]) { n     cout <<  NO ; n     exit(0); n   } n   dfs(graph[node]); n   opened[node] = false; n   result += (node +  a ); n } n void dfsn(int node) { n   opened[node] = true; n   if (graph[node] != -1) { n     if (opened[graph[node]]) { n       cout <<  NO ; n       exit(0); n     } n     dfsn(graph[node]); n   } n   opened[node] = false; n } n set<int> letter; n int main() { n   int n; n   cin >> n; n   fill(graph, graph + 27, -1); n   fill(grapht, grapht + 27, -1); n   while (n--) { n     string s; n     cin >> s; n     for (int i = 0; i < s.size() - 1; i++) { n       int b = s[i] -  a ; n       int e = s[i + 1] -  a ; n       if ((graph[b] != -1 && graph[b] != e) || n           (grapht[e] != -1 && grapht[e] != b)) { n         cout <<  NO ; n         exit(0); n       } n       graph[b] = e; n       grapht[e] = b; n     } n     for (auto i = s.begin(); i != s.end(); i++) { n       letter.insert(*i -  a ); n     } n   } n   for (int i = 0; i < 27; i++) { n     dfsn(i); n   } n   for (int i = 26; i >= 0; i--) { n     if (letter.find(i) != letter.end() && grapht[i] == -1) { n       dfs(i); n     } n   } n   reverse(result.begin(), result.end()); n   cout << result; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using pii = pair<ll, ll>; n const ll MOD = 1e9 + 7, N = 1e5 + 10; n void test() { n   ll n; n   cin >> n; n   vector<ll> a(n); n   for (ll i = 0; i < n; i++) { n     cin >> a[i]; n   } n   vector<ll> ans; n   sort(a.begin(), a.end()); n   ll l = 0, h = n - 1; n   while (l < h) { n     ans.push_back(a[l]); n     ans.push_back(a[h]); n     l++, h--; n   } n   if (l == h) ans.push_back(a[l]); n   reverse(ans.begin(), ans.end()); n   for (ll i = 0; i < n; i++) { n     cout << ans[i] <<    n [i == n - 1]; n   } n   return; n } n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   ll tt = 1; n   cin >> tt; n   for (ll i = 0; i < tt; i++) test(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 7; n const int N = 1e4 + 10; n int main() { n   string str; n   cin >> str; n   cout << str[0]; n   int flag = 0; n   for (int i = 1; i < str.length(); i++) { n     if (!(i + 2 >= str.length() || flag == 1)) { n       if (str.substr(i, 2) ==  at ) { n         cout <<  @ ; n         i++; n         flag = 1; n         continue; n       } n     } n     if (i + 3 < str.length()) { n       if (str.substr(i, 3) ==  dot ) { n         cout <<  . ; n         i += 2; n         continue; n       } n     } n     cout << str[i]; n   } n   return 0; n } n


#include<bits/stdc++.h> n #define mod 998244353 n using namespace std; n int n, A[2], f[200010], pw2; n int powmod(int x, int y){ n  int ans = 1; n  for(;y;y >>= 1, x = 1ll * x * x % mod) n   if(y & 1)ans = 1ll * x * ans % mod; n  return ans; n } n int main(){ n  scanf( %d , &n); n  A[0] = 1; n  A[1] = 0; n  pw2 = powmod(2, mod - 2); n  for(int i = 1; i <= n; i++){ n   A[0] = 1ll * A[0] * pw2 % mod; n   A[1] = 1ll * A[1] * pw2 % mod; n   f[i] = A[!(i & 1)]; n   A[i & 1] += f[i]; n  } n  printf( %d n , f[n]); n } n  n


#include <bits/stdc++.h> n using namespace std; n const int N = 100; n int gi() { n   int w = 0; n   bool q = 1; n   char c = getchar(); n   while ((c <  0  || c >  9 ) && c !=  - ) c = getchar(); n   if (c ==  - ) q = 0, c = getchar(); n   while (c >=  0  && c <=  9 ) w = w * 10 + c -  0 , c = getchar(); n   return q ? w : -w; n } n const int mod = 1e9 + 7; n int f[N][N], g[N][N]; n int inv[N]; n inline void inc(int &x, int y) { (x += y) >= mod ? x -= mod : 0; } n inline int C(int n, int m) { n   n += m - 1; n   int ans = 1; n   for (int i = 1; i <= m; i++) n     ans = 1LL * ans * (n - i + 1) % mod * inv[i] % mod; n   return ans; n } n int main() { n   int n = gi(), m = gi(), i, j, k, t, s, lim = n + 1; n   for (inv[0] = inv[1] = 1, i = 2; i < N; i++) n     inv[i] = mod - 1LL * (mod / i) * inv[mod % i] % mod; n   f[0][1] = 1; n   for (i = 0; i <= n; i++) n     for (j = 0; j <= lim; j++) { n       if (f[i][j]) n         for (k = 0; k <= i && k + i <= n; k++) n           for (t = 0; t <= lim; t++) { n             if (k == i) n               if (t < j) n                 inc(g[i + k + 1][t], 2LL * f[i][j] * f[k][t] % mod); n               else if (t == j) n                 inc(g[i + k + 1][j], 1LL * f[i][j] * f[k][t] % mod); n               else n                 break; n             else n               inc(g[i + k + 1][min(j, t)], 2LL * f[i][j] * f[k][t] % mod); n           } n       if (g[i][j]) n         for (k = n - i; k >= 0; k--) n           for (t = lim - j; t >= 0; t--) n             if (f[k][t]) n               for (s = min((n - k) / i, (lim - t) / j); s; s--) n                 inc(f[k + i * s][t + j * s], n                     1LL * f[k][t] * C(g[i][j], s) % mod); n     } n   printf( %d n , f[n][m]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   while (~scanf( %d , &n)) { n     printf( %d n , n); n     for (int i = 1; i <= n; i++) printf( 1  ); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool compare(const pair<long long, long long> &a, n              const pair<long long, long long> &b) { n   return a.second > b.second; n } n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(nullptr); n   long long i, j; n   string s; n   cin >> s; n   long long n = s.length(); n   long long f = 1; n   if (n < 4) { n     cout << 0; n   } else { n     long long sm = 0; n     long long fsm = 0; n     for (i = 0; i < n - 3; i++) { n       if (s[i] ==  b  && s[i + 1] ==  e  && s[i + 2] ==  a  && n           s[i + 3] ==  r ) { n         sm = i + 1; n       } n       fsm += sm; n     } n     cout << fsm; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n; n   cin >> n; n   long long ar[n]; n   for (long long i = 0; i < n; i++) cin >> ar[i]; n   sort(ar, ar + n); n   long long dist = 0; n   for (long long i = 0; i < n; i++) dist += (long long)abs(ar[i] - (i + 1)); n   cout << dist <<   n ; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   long long T = 1; n   while (T--) solve(); n   return 0; n } n


#include <cstdio> n #include <cstring> n #include <iostream> n #include <algorithm> n  n using namespace std; n  n const int N = 100000; n  n long long n; n  n struct ab n { n  long long a; n  long long b; n  bool operator < (const struct ab &c) const n  { n   return b < c.b; n  } n } aa[N + 5]; n long long sus[N + 5]; n  n int main() n { n  scanf( %lld , &n); n  long long su = 0; n  for (int i = 1; i <= n; ++i) n  { n   scanf( %lld%lld , &aa[i].a, &aa[i].b); n   su += aa[i].a; n  } n  sort(aa + 1, aa + n + 1); n  sus[n + 1] = 0; n  for (int i = n; i >= 1; --i) n  { n   sus[i] = sus[i + 1] + aa[i].a; n  } n  long long ans = 0; n  long long p = 0, ext = 0; n  for (int i = 1; i <= n; ++i) n  { n   long long cc = aa[i].b - (p + ext); n   if (sus[i + 1] <= ext) n   { n    if (aa[i].b <= p + ext) n    { n     ans += aa[i].a - (ext - sus[i + 1]); n    } n    else if (aa[i].b <= p + ext + aa[i].a - (ext - sus[i + 1])) n    { n     ans += p + ext + aa[i].a - (ext - sus[i + 1]) - aa[i].b; n     ans += 2 * cc; n    } n    else n    { n     ans += 2 * (aa[i].a - (ext - sus[i + 1])); n    } n    break; n   } n   else if (aa[i].b <= p + ext) n   { n    ans += aa[i].a; n    p += aa[i].a; n   } n   else if (sus[i + 1] - ext >= cc) n   { n    ans += 2 * cc; n    ext += cc; n    ans += aa[i].a; n    p += aa[i].a; n   } n   else n   { n    ans += 2 * (sus[i + 1] - ext); n    cc -= sus[i + 1] - ext; n    if (cc >= aa[i].a) n    { n     ans += 2 * aa[i].a; n    } n    else n    { n     ans += 2 * cc + (aa[i].a - cc); n    } n    break; n   } n  } n   n // for (int i = 1; i <= n; ++i) n // { n //  if (aa[i].b >= su) n //  { n //   ans += 2 * (su - p - ext); n //   break; n //  } n //  else if (aa[i].b <= p + ext) n //  { n //   ans += aa[i].a; n //   p += aa[i].a; n //  } n //  else if (sus[i + 1] >= aa[i].b - p) n //  { n //   ans += 2 * (aa[i].b - p - ext); n //   ext += aa[i].b - p - ext; n //   ans += aa[i].a; n //   p += aa[i].a; n //  } n //  else if (sus[i + 1] < aa[i].b - p - ext) n //  { n //   ans +=  n //  } n // } n   n  printf( %lld , ans); n  return 0; n } n  n


#include <bits/stdc++.h> n using namespace std; n const int iinf = 1e9 + 7; n const long long linf = 1ll << 60; n const double dinf = 1e10; n template <typename T> n inline void scf(T &x) { n   bool f = 0; n   x = 0; n   char c = getchar(); n   while ((c <  0  || c >  9 ) && c !=  - ) c = getchar(); n   if (c ==  - ) { n     f = 1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   if (f) x = -x; n   return; n } n template <typename T1, typename T2> n void scf(T1 &x, T2 &y) { n   scf(x); n   return scf(y); n } n template <typename T1, typename T2, typename T3> n void scf(T1 &x, T2 &y, T3 &z) { n   scf(x); n   scf(y); n   return scf(z); n } n const int N = 233; n int n, l, k; n int p[N], a[N]; n double dp[N][N][N * 2]; n int main() { n   scf(n, l, k); n   for (int i = (1); i <= (n); i++) scf(p[i]); n   for (int i = (1); i <= (n); i++) scf(a[i]); n   dp[0][0][k + 200] = 1.0; n   for (int i = 0; i < (n); i++) n     for (int j = (0); j <= (i); j++) n       for (int k = (0); k <= (400); k++) n         if (dp[i][j][k] > 1e-20) { n           dp[i + 1][j][k] += dp[i][j][k] * (1.0 * (100 - p[i + 1]) / 100.0); n           int nxtk = k; n           if (a[i + 1] < 0) n             nxtk--; n           else n             nxtk += a[i + 1]; n           if (nxtk > 400) nxtk = 400; n           if (k >= 0) n             dp[i + 1][j + 1][nxtk] += dp[i][j][k] * (1.0 * p[i + 1] / 100.0); n         } n   double ans = 0.0; n   for (int j = (l); j <= (n); j++) n     for (int k = (200); k <= (400); k++) ans += dp[n][j][k]; n   printf( %.12f n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long int t; n   cin >> t; n   while (t--) { n     int n, m; n     cin >> n >> m; n     vector<int> v1(n), v2(m); n     vector<int> v; n     for (auto &x : v1) cin >> x; n     for (auto &x : v2) cin >> x; n     for (int i = 0; i < n; i++) n       for (int j = 0; j < m; j++) { n         if (v1[i] == v2[j]) v.push_back(v1[i]); n       } n     if (v.size()) { n       cout <<  Yes  <<   n ; n       cout << 1 <<     << v[0] <<   n ; n     } else n       cout <<  No  <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n static int LOCAL = 0; n const long long int mod = 1000000007ll; n const long long int MOD = 1000000009ll; n const long long int INF = LLONG_MAX / 10; n const int inf = INT_MAX / 10; n long long int powermod(long long int _a, long long int _b, n                        long long int _m = mod) { n   long long int _r = 1; n   while (_b) { n     if (_b % 2 == 1) _r = (_r * _a) % _m; n     _b /= 2; n     _a = (_a * _a) % _m; n   } n   return _r; n } n long long int power(long long int _a, long long int _b) { n   long long int _r = 1; n   while (_b) { n     if (_b % 2 == 1) _r = (_r * _a); n     _b /= 2; n     _a = (_a * _a); n   } n   return _r; n } n long long int add(long long int a, long long int b, long long int m = mod) { n   long long int x = a + b; n   while (x >= m) x -= m; n   return x; n } n long long int sub(long long int a, long long int b, long long int m = mod) { n   long long int x = a - b; n   while (x < 0) x += m; n   return x; n } n long long int mul(long long int a, long long int b, long long int m = mod) { n   return ((a % m) * (b % m)) % m; n } n long long int gcd(long long int a, long long int b) { n   while (a && b) a > b ? a %= b : b %= a; n   return a + b; n } n long long int lcm(long long int a, long long int b) { n   return (max(a, b) / gcd(a, b)) * min(a, b); n } n struct pair_hash { n   std::size_t operator()(const std::pair<int, int> &p) const { n     auto h1 = std::hash<long long int>{}(p.first); n     auto h2 = std::hash<long long int>{}(p.second); n     return (int)add(h1, mul(h2, h1, MOD)); n   } n }; n struct cmp { n   bool operator()(pair<int, pair<long long int, long long int> > const &l, n                   pair<int, pair<long long int, long long int> > const &r) { n     return l.second.first < r.second.first; n   } n } myobject; n multiset<int> second; n int main() { n   int n, x; n   cin >> n; n   double sum = 0; n   for (int i = 1; i <= n; i++) scanf( %d , &x), second.insert(x), sum += x; n   double avg = sum / n; n   int cnt = 0; n   while (!(avg >= 4.50)) { n     x = *second.begin(); n     second.erase(second.begin()); n     sum -= x; n     sum += 5; n     avg = sum / n; n     cnt++; n   } n   cout << cnt; n   return 0; n } n


/* Author: EndlessK n  * Time: 2021-05-06 20:40:25 n **/ n #include<bits/stdc++.h> n #define maxn 100010 n #define pb push_back n #define ll long long n #define fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) n using namespace std; n int main() n { n     fast; n     int t; n     cin>>t; n     map<int,int> mp; n     while(t--) n     { n         int n; n         int ans=0; n         cin>>n; n         for(int i=1;i<=min(9,n);i++) n         { n             ans++; n         } n         for(int i=11;i<=min(99,n);i+=11) n         { n             ans++; n         } n         for(int i=111;i<=min(999,n);i+=111) n         { n             ans++; n         } n         for(int i=1111;i<=min(9999,n);i+=1111) n         { n             ans++; n         } n         for(int i=11111;i<=min(99999,n);i+=11111) n         { n             ans++; n         } n         for(int i=111111;i<=min(999999,n);i+=111111) n         { n             ans++; n         } n         for(int i=1111111;i<=min(9999999,n);i+=1111111) n         { n             ans++; n         } n         for(int i=11111111;i<=min(99999999,n);i+=11111111) n         { n             ans++; n         } n         for(int i=111111111;i<=min(999999999,n);i+=111111111) n         { n             ans++; n         } n         cout<<ans<<  n ; n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n bool way[5003][5003]; n int dis[5003], counter; n vector<pair<int, int> > edge[5003], child[5003]; n priority_queue<pair<int, int> > pq[5003]; n void cari(int pos) { n   int j, sz; n   sz = edge[pos].size(); n   for (j = 0; j < sz; ++j) { n     if (way[pos][edge[pos][j].first]) { n       way[pos][edge[pos][j].first] = false; n       way[edge[pos][j].first][pos] = false; n       child[pos].push_back(edge[pos][j]); n       cari(edge[pos][j].first); n     } n   } n } n void cek(int posisi, int time) { n   int i, j, x, size, sz; n   sz = child[posisi].size(); n   for (i = 0; i < sz; ++i) { n     x = child[posisi][i].first; n     size = child[posisi][i].second; n     for (j = 0; j < size; ++j) { n       if (pq[x].empty()) break; n       pq[posisi].push(pq[x].top()); n       if (posisi == 1) { n         dis[pq[x].top().second] = time; n         ++counter; n       } n       pq[x].pop(); n     } n     cek(x, time); n   } n } n int main() { n   int i, a, b, c, n, sz, arrive, dummy, division[5003]; n   scanf( %d , &n); n   for (i = 1; i <= n; ++i) scanf( %d , &division[i]); n   memset(way, true, sizeof(way)); n   for (i = 1; i < n; ++i) { n     scanf( %d %d %d , &a, &b, &c); n     edge[a].push_back(make_pair(b, c)); n     edge[b].push_back(make_pair(a, c)); n   } n   cari(1); n   for (i = 2; i <= n; ++i) pq[i].push(make_pair(-division[i], i)); n   sz = child[1].size(); n   dis[1] = 0; n   int temp = 1; n   counter = 1; n   while (counter < n) { n     cek(1, temp); n     ++temp; n   } n   for (i = 1; i <= n; ++i) { n     if (i != n) n       printf( %d  , dis[i]); n     else n       printf( %d n , dis[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long GCD(long long a, long long b) { n   if (b == 0) return a; n   return (a % b == 0 ? b : GCD(b, a % b)); n } n long long POW(long long base, long long exp) { n   long long val; n   val = 1; n   while (exp > 0) { n     if (exp % 2 == 1) { n       val = (val * base) % 1000000007; n     } n     base = (base * base) % 1000000007; n     exp = exp / 2; n   } n   return val; n } n int a[100005]; n int pos[100005]; n int main() { n   int n, i, c, mx; n   scanf( %d , &n); n   for (i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   for (i = 1; i <= n; i++) { n     pos[a[i]] = i; n   } n   mx = 0; n   for (i = 1; i <= n; i++) { n     c = 1; n     while (i < n && pos[i + 1] > pos[i]) { n       i++; n       c++; n     } n     mx = max(mx, c); n   } n   printf( %d n , n - mx); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(2) n using namespace std; n const int maxn = 2e5 + 10, mod = 1e9 + 7, inf = 0x3f3f3f3f; n int n, a[maxn]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int _t; n   cin >> _t; n   while (_t--) { n     cin >> n; n     for (int i = 1; i <= n; i++) cin >> a[i]; n     bool isok = true; n     sort(a + 1, a + 1 + n); n     for (int i = 2; i <= n; i++) n       if (a[i] - a[i - 1] > 1) isok = false; n     (isok ? cout <<  YES n  : cout <<  NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000ll * 1000 * 1000 + 7; n int main() { n   vector<string> name; n   string str; n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> str; n     name.push_back(str); n   } n   long long ans = 1ll; n   for (int i = 0; i < m; i++) { n     set<char> s; n     for (int j = 0; j < n; j++) s.insert(name[j][i]); n     ans = (ans * s.size()) % mod; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[26]; n int A[26]; n string s, t; n int x1, x2; n char c; n int main() { n   cin >> s >> t; n   for (int i = 0; i < t.size(); i++) { n     c = t[i]; n     if (c > 96) n       a[c - 97]++; n     else n       A[c - 65]++; n   } n   for (int i = 0; i < s.size(); i++) { n     c = s[i]; n     if (c > 96) { n       if (a[c - 97]) { n         a[c - 97]--; n         x1++; n         s[i] =  0 ; n       } n     } else if (A[c - 65]) { n       A[c - 65]--; n       x1++; n       s[i] =  0 ; n     } n   } n   for (int i = 0; i < s.size(); i++) { n     c = s[i]; n     if (c ==  0 ) continue; n     if (c >= 97) { n       c = c - 32; n       if (A[c - 65]) { n         x2++; n         A[c - 65]--; n       } n     } else { n       c = c + 32; n       if (a[c - 97]) { n         x2++; n         a[c - 97]--; n       } n     } n   } n   cout << x1 <<     << x2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200000 + 10; n int T, n, m, sum, du[maxn], K; n vector<pair<int, int> > p[maxn]; n struct node { n   int x, y; n   long long val; n   bool operator<(const node i) const { return val < i.val; } n } a[maxn]; n queue<int> q2; n int b[maxn], cnt; n long long dis[1000][1000]; n long long ans[maxn], sum1, INF; n int main() { n   cin >> n >> m >> K; n   for (int i = 1; i <= m; i++) { n     scanf( %d %d %lld , &a[i].x, &a[i].y, &a[i].val); n   } n   sort(a + 1, a + m + 1); n   int Mx = min(m, K); n   memset(dis, 0x3f, sizeof(dis)); n   INF = dis[0][0]; n   for (int i = 1; i <= Mx; i++) { n     if (!b[a[i].x]) { n       cnt++; n       b[a[i].x] = cnt; n     } n     if (!b[a[i].y]) { n       cnt++; n       b[a[i].y] = cnt; n     } n     dis[b[a[i].x]][b[a[i].y]] = dis[b[a[i].y]][b[a[i].x]] = a[i].val; n   } n   for (int i = 1; i <= cnt; i++) dis[i][i] = 0; n   for (int k = 1; k <= cnt; k++) { n     for (int i = 1; i <= cnt; i++) { n       for (int j = 1; j <= cnt; j++) { n         dis[i][j] = min(dis[i][k] + dis[k][j], dis[i][j]); n       } n     } n   } n   for (int i = 1; i <= cnt; i++) { n     for (int j = i + 1; j <= cnt; j++) { n       if (i != j && dis[i][j] != INF) { n         ans[++sum1] = dis[i][j]; n       } n     } n   } n   sort(ans + 1, ans + sum1 + 1); n   cout << ans[K] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct online_hull { n   map<int, int> points; n   long long area; n   inline online_hull() { n     points.clear(); n     area = 0; n   } n   inline map<int, int>::iterator prev(map<int, int>::iterator it) { n     return it == points.begin() ? it : --it; n   } n   inline map<int, int>::iterator next(map<int, int>::iterator it) { n     return it == points.end() ? it : ++it; n   } n   inline long long traparea(long long x1, long long y1, long long x2, n                             long long y2) { n     return (x2 - x1) * (y1 + y2); n   } n   inline long long triarea(long long x1, long long y1, long long x2, n                            long long y2, long long x3, long long y3) { n     return traparea(x1, y1, x2, y2) + traparea(x2, y2, x3, y3) + n            traparea(x3, y3, x1, y1); n   } n   inline long long traparea(map<int, int>::iterator a, n                             map<int, int>::iterator b) { n     return traparea(a->first, a->second, b->first, b->second); n   } n   inline long long triarea(map<int, int>::iterator it) { n     long long sum = 0; n     if (it != points.begin()) sum += traparea(prev(it), it); n     if (next(it) != points.end()) sum += traparea(it, next(it)); n     if (it != points.begin() && next(it) != points.end()) n       sum += traparea(next(it), prev(it)); n     return sum; n   } n   inline bool bad(map<int, int>::iterator it) { n     if (points.size() < 3 || it == points.begin() || next(it) == points.end()) n       return false; n     return triarea(it) <= 0; n   } n   inline bool insert(int x, int y) { n     if (points.find(x) != points.end()) { n       if (y <= points[x]) return false; n       area -= triarea(points.find(x)); n       points.erase(x); n     } n     map<int, int>::iterator it = points.insert(make_pair(x, y)).first; n     if (bad(it)) { n       points.erase(it); n       return false; n     } n     area += triarea(it); n     while (bad(prev(it))) { n       area -= triarea(prev(it)); n       points.erase(prev(it)); n     } n     while (bad(next(it))) { n       area -= triarea(next(it)); n       points.erase(next(it)); n     } n     return true; n   } n   inline bool contains(int x, int y) { n     if (points.empty()) return false; n     map<int, int>::iterator first = points.begin(), last = prev(points.end()); n     if (x < first->first || x > last->first) return false; n     if (x == first->first) return y <= first->second; n     if (x == last->first) return y <= last->second; n     map<int, int>::iterator it = points.lower_bound(x), p = prev(it); n     return triarea(p->first, p->second, x, y, it->first, it->second) <= 0; n   } n }; n int Q; n online_hull upper, lower; n int main() { n   scanf( %d , &Q); n   while (Q-- > 0) { n     int type, x, y; n     scanf( %d %d %d , &type, &x, &y); n     if (type == 1) { n       upper.insert(x, y); n       lower.insert(x, -y); n     } else if (type == 2) n       puts((upper.contains(x, y) && lower.contains(x, -y)) ?  YES  :  NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<string, int> id; n inline int getID(string s) { n   if (id.find(s) == id.end()) { n     int sz = id.size(); n     id[s] = sz; n   } n   return id[s]; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n, a, b, k, f; n   cin >> n >> a >> b >> k >> f; n   map<pair<int, int>, int> rcost; n   int last = -1, sum = 0; n   for (int i = 0; i < n; ++i) { n     string u, v; n     cin >> u >> v; n     int su = getID(u); n     int sv = getID(v); n     if (last == su) { n       rcost[pair<int, int>(min(su, sv), max(su, sv))] += b; n       sum += b; n     } else { n       rcost[pair<int, int>(min(su, sv), max(su, sv))] += a; n       sum += a; n     } n     last = sv; n   } n   vector<int> diff; n   for (auto it = rcost.begin(); it != rcost.end(); it++) { n     int cost = it->second; n     if (cost > f) { n       diff.push_back(cost - f); n     } n   } n   sort(diff.rbegin(), diff.rend()); n   for (int i = 0; i < min((int)diff.size(), k); ++i) { n     sum -= diff[i]; n   } n   cout << sum; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int two(int n) { return 1 << n; } n inline void set_bit(int& n, int b) { n |= two(b); } n inline void unset_bit(int& n, int b) { n &= ~two(b); } n inline int last_bit(int n) { return n & (-n); } n template <class T> n T gcd(T a, T b) { n   return (b != 0 ? gcd<T>(b, a % b) : a); n } n template <class T> n T lcm(T a, T b) { n   return (a / gcd<T>(a, b) * b); n } n int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; n const double pi = 2 * acos(0.0); n const int mod = 1000000; n int main() { n   std::ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   ; n   long long m, n; n   cin >> m >> n; n   double res = m; n   for (int i = 1; i < m; i++) { n     res -= pow(i / double(m), n); n   } n   cout << fixed << setprecision(10) << res; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2005; n const long long inf = 0x3f3f3f3f3f3f3f3f; n const int mod = 998244353; n vector<int> ga[N], gb[N]; n int n, a, b; n int ca[N], cb[N]; n int dp[N][N][2]; n int ha[N], hb[N]; n int lfta[N], rgta[N], lftb[N], rgtb[N]; n int cnta, cntb; n int faa[N][11], fab[N][11]; n void dfsa(int u, int last) { n   lfta[u] = ++cnta; n   ha[u] = ha[last] + 1; n   for (int i = 1; i < 11; i++) faa[u][i] = faa[faa[u][i - 1]][i - 1]; n   for (auto v : ga[u]) { n     if (v == last) continue; n     faa[v][0] = u; n     dfsa(v, u); n   } n   rgta[u] = cnta; n } n void dfsb(int u, int last) { n   lftb[u] = ++cntb; n   hb[u] = hb[last] + 1; n   for (int i = 1; i < 11; i++) fab[u][i] = fab[fab[u][i - 1]][i - 1]; n   for (auto v : gb[u]) { n     if (v == last) continue; n     fab[v][0] = u; n     dfsb(v, u); n   } n   rgtb[u] = cntb; n } n int costa(int u, int v) { n   int x = u; n   if (!v) return ha[u] - 1; n   for (int i = 10; i >= 0; i--) { n     if (!faa[x][i]) continue; n     if (lfta[faa[x][i]] <= lfta[v] && rgta[faa[x][i]] >= rgta[v]) continue; n     x = faa[x][i]; n   } n   return ha[u] - ha[x] + 1; n } n int costb(int u, int v) { n   int x = u; n   if (!v) return hb[u] - 1; n   for (int i = 10; i >= 0; i--) { n     if (!fab[x][i]) continue; n     if (lftb[fab[x][i]] <= lftb[v] && rgtb[fab[x][i]] >= rgtb[v]) continue; n     x = fab[x][i]; n   } n   return hb[u] - hb[x] + 1; n } n int main() { n   int i, j; n   cin >> n; n   cin >> a; n   for (i = 2; i <= a; i++) { n     int fa; n     cin >> fa; n     ga[i].push_back(fa); n     ga[fa].push_back(i); n   } n   for (i = 1; i <= n; i++) cin >> ca[i]; n   cin >> b; n   for (i = 2; i <= b; i++) { n     int fa; n     cin >> fa; n     gb[i].push_back(fa); n     gb[fa].push_back(i); n   } n   for (i = 1; i <= n; i++) cin >> cb[i]; n   dfsa(1, 0); n   dfsb(1, 0); n   memset(dp, 0x3f, sizeof(dp)); n   dp[0][0][0] = dp[0][0][1] = 0; n   for (i = 1; i <= n; i++) { n     for (j = 0; j < i; j++) { n       dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j][0] + costa(ca[i], ca[i - 1])); n       dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][1] + costb(cb[i], cb[i - 1])); n       dp[i][i - 1][0] = n           min(dp[i][i - 1][0], dp[i - 1][j][1] + costa(ca[i], ca[j])); n       dp[i][i - 1][1] = n           min(dp[i][i - 1][1], dp[i - 1][j][0] + costb(cb[i], cb[j])); n     } n   } n   int ans = 0x3f3f3f3f; n   for (i = 0; i < n; i++) { n     ans = min(ans, dp[n][i][0]); n     ans = min(ans, dp[n][i][1]); n   } n   cout << (a - 1) + (b - 1) - ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct th { n   int id, num; n   th() { id = 0, num = 0; } n   th(int a, int b) { id = a, num = b; } n   bool operator<(const th &a) const { n     if (num != a.num) return num < a.num; n     return id < a.id; n   } n }; n set<th> x; n vector<int> ns[1000005]; n int n, m; n int hp[1000005]; n long long dv = 0; n int a[1000005]; n long long sm = 0; n void work(int bg, int n) { n   if (!n) n     return; n   else { n     if (bg == m) a[bg] = n; n     while (1) { n       set<th>::iterator t = x.end(); n       t--; n       if ((*t).num < n) break; n       th n1 = (*t); n       x.erase(n1); n       int nd = n1.num / n; n       for (int j = bg; j <= m; j++) n         for (int tm = 0; tm < nd; tm++) ns[j].push_back(n1.id); n       sm -= nd * n; n       n1.num %= n; n       x.insert(n1); n     } n     if (bg == m) return; n     set<th>::iterator q = x.begin(); n     int nt = sm / n; n     a[bg] = (*q).num; n     ns[bg].push_back((*q).id); n     x.erase(q); n     sm -= nt * a[bg]; n     if (a[bg]) { n       set<th>::iterator t = x.begin(); n       for (int j = 1; j < nt; j++) { n         th q1 = *t; n         t++; n         x.erase(q1); n         ns[bg].push_back(q1.id); n         q1.num -= a[bg]; n         x.insert(q1); n       } n     } n     work(bg + 1, n - a[bg]); n   } n } n int main() { n   scanf( %d%d , &n, &m); n   long long sum = 0; n   for (int i = 1; i <= m; i++) { n     scanf( %d , &hp[i]); n     sum += hp[i]; n   } n   dv = sum / n; n   if (sum % n) dv++; n   sum = dv * n; n   sm = sum; n   for (int i = 1; i < m; i++) sum -= hp[i]; n   hp[m] = sum; n   for (int i = 1; i <= m; i++) x.insert(th(i, hp[i])); n   work(1, n); n   cout << dv << endl; n   for (int i = 1; i <= m; i++) printf( %d  , a[i]); n   printf(  n ); n   for (int j = 1; j <= m; j++) n     while (ns[j].size() < dv) ns[j].push_back(1); n   for (int i = 1; i <= dv; i++) { n     for (int j = 1; j <= m; j++) printf( %d  , ns[j][i - 1]); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, m; n int arr[50]; n int sub[50]; n int result = 0; n int task_tot_time = 0; n void take(int score, int t) { n   if (0 >= t) return; n   int tt = t; n   int ss = score; n   for (decltype(0) i = 0; i < k; i++) { n     int su = sub[i]; n     while (su > 0) { n       if (arr[i] > tt) break; n       ss++; n       tt -= arr[i]; n       su--; n     } n   } n   result = max(result, ss); n   if (t >= task_tot_time) { n     int task_left = sub[0]; n     for (decltype(1) i = 1; i < k; i++) task_left = min(task_left, sub[i]); n     if (task_left == 0) return; n     for (decltype(0) i = 0; i < k; i++) sub[i]--; n     result = max(result, score + k + 1); n     take(score + k + 1, t - task_tot_time); n   } n } n int main() { n   scanf( %d , &n) == 0, scanf( %d , &k) == 0, scanf( %d , &m) == 0; n   for (decltype(0) i = 0; i < k; i++) { n     scanf( %d , &arr[i]) == 0; n     task_tot_time += arr[i]; n   } n   for (decltype(0) i = 0; i < k; i++) sub[i] = n; n   sort(arr, arr + k); n   take(0, m); n   printf( %d , result); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 110; n const int MOD = 1e9 + 7; n long long n, k, dp[MAXN][MAXN][MAXN], local[MAXN][MAXN]; n vector<int> adj[MAXN]; n void add(long long& v, long long u) { v = (v + u) % MOD; } n void dfs(int v, int par = -1) { n   dp[v][1][0] = dp[v][0][1] = 1; n   for (auto i : adj[v]) { n     if (i == par) continue; n     dfs(i, v); n     for (int w = 0; w < 23; w++) n       for (int j = 0; j < 50; j++) { n         local[w][j] = dp[v][w][j]; n         dp[v][w][j] = 0; n       } n     for (int a = 0; a <= (k + 1); a++) n       for (int b = 0; b <= (2 * k + 1); b++) n         for (int c = 0; c <= (k + 1); c++) n           for (int d = 0; d <= (2 * k + 1); d++) { n             int locala = 0; n             if (!d) locala = b; n             if (!b && d) locala = d + 1; n             if (b && d) locala = min(b, d + 1); n             int localb = a; n             if (localb && locala) { n               if ((localb - 1 + locala - 1) <= k) localb = 0; n             } n             int localc = c; n             if (localc) localc++; n             if (localc && locala) { n               if ((locala - 1 + localc - 1) <= k) localc = 0; n             } n             int locald = 0; n             if (!localc) locald = localb; n             if (!localb && localc) locald = localc; n             if (localb && localc) locald = max(localc, localb); n             if (locald <= (k + 1) && locala <= (2 * k + 3)) n               add(dp[v][locald][locala], local[a][b] * dp[i][c][d] % MOD); n           } n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin >> n >> k; n   for (int i = 1; i < n; i++) { n     int u, v; n     cin >> u >> v; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   dfs(1); n   long long answer = 0; n   for (int i = 0; i <= (2 * k + 3); i++) answer = (answer + dp[1][0][i]) % MOD; n   cout << answer << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long arr[200200]; n int main() { n   string a, b; n   cin >> a >> b; n   long long x = 0, y = 0; n   for (int i = 0; i <= b.size() - a.size(); i++) x += (b[i] -  0 ); n   for (int i = 0; i < a.size(); i++) { n     y += (a[i] ==  0 ) ? x : (b.size() - a.size() + 1) - x; n     x += b[b.size() - a.size() + 1 + i] - b[i]; n   } n   cout << y; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void Heap(int A[], int n, int l, int r) { n   int x, i, j; n   x = A[l]; n   i = l; n   while (1) { n     j = 2 * i; n     if (j > r) break; n     if (j < r && A[j + 1] >= A[j]) j++; n     if (x >= A[j]) break; n     A[i] = A[j]; n     i = j; n   } n   A[i] = x; n } n void HeapSort(int A[], int n) { n   int l, r, temp; n   l = n / 2; n   while (l >= 0) { n     Heap(A, n, l, n - 1); n     l--; n   } n   r = n - 1; n   while (r >= 1) { n     temp = A[0]; n     A[0] = A[r]; n     A[r] = temp; n     r--; n     Heap(A, n, 0, r); n   } n } n int mini(int a, int b, int c = 1000000010) { n   if (a <= b && a <= c) n     return a; n   else if (b <= c && b <= a) n     return b; n   else n     return c; n } n int maxi(int a, int b) { n   if (a > b) n     return a; n   else n     return b; n } n unsigned long long int fac(unsigned long long int a) { n   unsigned long long int r = 1; n   for (int i = 2; i <= a; i++) r *= i; n   return r; n } n bool issimple(unsigned long long n) { n   for (unsigned long long i = 2; i <= sqrt(n); i++) n     if (n % i == 0) return false; n   return true; n } n unsigned long long nod(unsigned long long a, unsigned long long b) { n   unsigned long long temp; n   while (b) { n     a %= b; n     temp = a; n     a = b; n     b = temp; n   } n   return a; n } n unsigned long long nok(unsigned long long a, unsigned long long b, n                        unsigned long long nod) { n   return a / nod * b; n } n int main() { n   int x, y, count, t, i, n, k, m; n   bool flag; n   cin >> t; n   while (t--) { n     cin >> n; n     count = n / 2 + n % 2; n     cout << count << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long dot(complex<long long> c1, complex<long long> c2) { n   return imag(c1 * conj(c2)); n } n double dot(complex<double> c1, complex<double> c2) { n   return imag(c1 * conj(c2)); n } n long long point(complex<long long> c1, complex<long long> c2) { n   return real(c1 * conj(c2)); n } n double point(complex<double> c1, complex<double> c2) { n   return real(c1 * conj(c2)); n } n void solve() { n   long double n, pi2, alpha, res; n   pi2 = acos(0.0); n   cin >> n; n   alpha = pi2 * (n - 1.0) / n; n   res = tan(alpha); n   cout << res << endl; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t, cases; n   cin >> cases; n   cout << fixed << setprecision(10); n   for (t = 0; t < cases; t++) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 45; n int nd, nm, G[N][N]; n int cntClique, pts[N], res[N], cnt[N]; n map<string, int> H; n int n; n vector<int> v; n bool dfs(int pos, int num) { n   for (int i = pos + 1; i <= n; ++i) { n     if (cnt[i] + num <= cntClique) return false; n     if (G[pos][i]) { n       int ok = 1; n       for (int id = 1; id <= num; ++id) { n         if (!G[i][pts[id]]) { n           ok = 0; n           break; n         } n       } n       if (ok) { n         pts[num + 1] = i; n         if (dfs(i, num + 1)) return true; n       } n     } n   } n   if (num > cntClique) { n     for (int i = 1; i <= num; ++i) { n       res[i] = pts[i]; n     } n     cntClique = num; n     return true; n   } n   return false; n } n void maxClique() { n   cntClique = -1; n   for (int i = n; i > 0; --i) { n     pts[1] = i; n     dfs(i, 1); n     cnt[i] = cntClique; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   memset(G, 1, sizeof G); n   cin >> nd >> nm; n   for (int i = 1; i <= nd; ++i) { n     int op; n     string s; n     cin >> op; n     if (op == 1) { n       v.clear(); n     } else { n       cin >> s; n       if (!H.count(s)) { n         H[s] = ++n; n       } n       int y = H[s]; n       for (auto& x : v) { n         G[x][y] = 0; n         G[y][x] = 0; n       } n       v.push_back(y); n     } n   } n   maxClique(); n   if (cntClique < 0) { n     cout <<  0 ; n   } else { n     cout << cntClique; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void _print(long long int t) { cerr << t; } n void _print(int t) { cerr << t; } n void _print(string t) { cerr << t; } n void _print(char t) { cerr << t; } n void _print(long double t) { cerr << t; } n void _print(double t) { cerr << t; } n void _print(unsigned long long t) { cerr << t; } n bool cmp(pair<long long int, long long int> a, n          pair<long long int, long long int> b) { n   if (a.first != b.first) n     return a.first > b.first; n   else n     return a.second > b.second; n } n long long int binarySearch(vector<long long int> v, long long int l, n                            long long int r, long long int x) { n   while (l <= r) { n     long long int mid = l + (r - l) / 2; n     if (v[mid] == x) n       return mid; n     else if (v[mid] < x) n       l = mid + 1; n     else n       r = mid - 1; n   } n   return -1; n } n long long int power(long long int x, long long int n) { n   if (n == 0) n     return 1; n   else if (n % 2 == 0) n     return power(x * x, n / 2); n   else n     return x * power(x * x, (n - 1) / 2); n } n long long int ModularExpo(long long int x, long long int y, long long int p) { n   long long int res = 1; n   x = x % p; n   if (x == 0) return 0; 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 void solve() { n   long long int n; n   cin >> n; n   for (long long int i = 0; i < n; i++) cout << i + 2 <<    ; n   cout <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long int t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 100001; n int n, m, x, y, b, r, p, l, ri; n long long ans; n vector<int> B, R, P; n int bef(int x, int c) { n   if (!c) return (lower_bound(B.begin(), B.end(), x) - B.begin() - 1); n   return (lower_bound(R.begin(), R.end(), x) - R.begin() - 1); n } n int aft(int x, int c) { n   if (!c) return (lower_bound(B.begin(), B.end(), x) - B.begin()); n   return (lower_bound(R.begin(), R.end(), x) - R.begin()); n } n long long get(int x) { n   long long mn = ri - B[x]; n   for (int i = x; i < b && B[i] < ri; i++) { n     long long left = B[i] - l, right = 0; n     if (i + 1 != b && B[i + 1] < ri) right = ri - B[i + 1]; n     mn = min(mn, left + right); n   } n   return mn; n } n long long get1(int x) { n   long long mn = ri - R[x]; n   for (int i = x; i < r && R[i] < ri; i++) { n     long long left = R[i] - l, right = 0; n     if (i + 1 != r && R[i + 1] < ri) right = ri - R[i + 1]; n     mn = min(mn, left + right); n   } n   return mn; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cin >> n; n   for (int i = 0; i < n; i++) { n     char c; n     cin >> x >> c; n     if (c ==  B ) n       B.push_back(x); n     else if (c ==  R ) n       R.push_back(x); n     else n       P.push_back(x); n   } n   b = B.size(); n   r = R.size(); n   p = P.size(); n   if (!P.size()) { n     if (b) ans = B[b - 1] - B[0]; n     if (r) ans += R[r - 1] - R[0]; n     cout << ans; n     return 0; n   } n   x = bef(P[0], 0); n   y = bef(P[0], 1); n   if (x >= 0) ans += P[0] - B[0]; n   if (y >= 0) ans += P[0] - R[0]; n   x = aft(P[p - 1], 0); n   y = aft(P[p - 1], 1); n   if (x != B.size()) ans += B[b - 1] - P[p - 1]; n   if (y != R.size()) ans += R[r - 1] - P[p - 1]; n   for (int i = 0; i < p - 1; i++) { n     l = P[i]; n     ri = P[i + 1]; n     long long dist = ri - l; n     int x = aft(l, 0), y = aft(l, 1); n     if ((x == b || B[x] > ri) && (y == r || R[y] > ri)) { n       ans += dist; n       continue; n     } n     long long mn = 2 * dist; n     long long k = dist; n     if (x < b && B[x] < ri) k += get(x); n     if (y < r && R[y] < ri) k += get1(y); n     ans += min(mn, k); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 2 * int(1e9); n const long long INFll = 1ll * int(1e9) * int(1e9); n const int MOD = 1000000007; n template <typename T> n ostream& operator<<(ostream& out, pair<T, T>& a) { n   out << a.first <<     << a.second; n   return out; n } n template <typename T> n istream& operator>>(istream& in, pair<T, T>& a) { n   in >> a.first >> a.second; n   return in; n } n template <typename T> n ostream& operator<<(ostream& out, vector<pair<T, T> > a) { n   for (int i = 0; i < a.size(); ++i) out << a[i] << endl; n   return out; n } n template <typename T> n istream& operator>>(istream& in, vector<T>& a) { n   for (int i = 0; i < a.size(); ++i) in >> a[i]; n   return in; n } n template <typename T> n ostream& operator<<(ostream& out, vector<T> a) { n   for (int i = 0; i < a.size(); ++i) n     if (i == a.size() - 1) n       out << a[i]; n     else n       out << a[i] <<    ; n   return out; n } n struct IN { n   bool any; n   operator bool() const { return any; } n } CIN; n inline IN& operator>>(IN& in, int& x) { n   x = 0, in.any = 0; n   char c; n   while ((c = getchar()) > 0) { n     if (c < 48 || c > 57) n       if (in.any) n         return in; n       else n         continue; n     in.any = 1, x = x * 10 + c -  0 ; n   } n   return in; n } n int main() { n   ios_base::sync_with_stdio(0); n   int q; n   CIN >> q; n   while (q--) { n     int n, m; n     CIN >> n >> m; n     vector<vector<int> > a(n, vector<int>(m)); n     for (int i = 0; i < n; ++i) n       for (int j = 0; j < m; ++j) CIN >> a[i][j]; n     int sum = 0; n     for (int j = 0; j < m; ++j) sum += abs(a[n / 2][j] - a[n / 2 - 1][j]); n     if (sum / long double(m) > 17) n       cout <<  YES n ; n     else n       cout <<  NO n ; n     if (0) cerr << sum / long double(m) << endl; n   } n   if (0) n     cerr << fixed << setprecision(0) n          <<  TIME =   << clock() / (long double)CLOCKS_PER_SEC * 1000 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n void dir(char& smb, int& x, int& y) { n   if (smb ==  L ) n     x--; n   else if (smb ==  R ) n     x++; n   else if (smb ==  U ) n     y++; n   else n     y--; n } n void solve() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   map<pair<int, int>, int> mpp; n   int x = 0, y = 0; n   mpp[make_pair(0, 0)] = 0; n   int mn = n + 5, l = -1, r = n + 1; n   for (int i = 1; i < n + 1; i++) { n     char smb = s[i - 1]; n     dir(smb, x, y); n     auto it = mpp.find(make_pair(x, y)); n     if (it != mpp.end()) { n       pair<pair<int, int>, int> p = *it; n       int ind = p.second; n       if (i - ind - 1 < mn) { n         mn = i - ind - 1; n         l = ind; n         r = i - 1; n       } n     } n     mpp[make_pair(x, y)] = i; n   } n   if (l == -1) n     cout <<  -1 n ; n   else n     cout << l + 1 <<     << r + 1 <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int tc; n   cin >> tc; n   while (tc--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, x1, y1, x2, y2; n   cin >> n >> m >> x1 >> y1 >> x2 >> y2; n   int x = abs(x1 - x2), y = abs(y1 - y2); n   if (x <= 4 && y <= 4 && x + y <= 6) n     cout <<  First  << endl; n   else n     cout <<  Second  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1e9 + 7; n template <typename T> n void print(vector<T> v) { n   for (T &i : v) cout << i <<    ; n   cout <<   n ; n } n void solve() { n   unsigned long long int n, x; n   cin >> n >> x; n   vector<unsigned long long int> v(n); n   for (unsigned long long int &i : v) cin >> i; n   sort(v.begin(), v.end()); n   unsigned long long int sum = 0; n   for (unsigned long long int i : v) { n     sum += i * x; n     if (x > 1) x--; n   } n   cout << sum <<   n ; n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int tcs = 1; n   while (tcs--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   long long n, m; n   int dig[10]; n   char cn[12], cm[12]; n   while (scanf( %s n%s , &cn, &cm) != EOF) { n     if (strlen(cn) != strlen(cm)) { n       printf( WRONG_ANSWER n ); n       continue; n     } n     n = atol(cn); n     m = atol(cm); n     for (int i = 0; i < 10; i++) dig[i] = 0; n     if (n < 10) { n       if (n == m) n         printf( OK n ); n       else n         printf( WRONG_ANSWER n ); n     } else { n       while (n) { n         dig[n % 10]++; n         n /= 10; n       } n       long long ret = 0; n       for (int i = 1; i <= 9; i++) { n         if (dig[i]) { n           ret *= 10; n           ret += i; n           dig[i]--; n           break; n         } n       } n       for (int i = 0; i <= 9; i++) { n         while (dig[i]) { n           ret *= 10; n           ret += i; n           dig[i]--; n         } n       } n       if (ret == m) n         printf( OK n ); n       else n         printf( WRONG_ANSWER n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void input(long &n) { scanf( %ld , &n); } n void output(long n) { printf( %ld , n); } n void input(long &n, long a[]) { n   input(n); n   for (long i = 1; i <= n; i++) input(a[i]); n } n bool test(long n, long a[], long id1, long id2, long tid, vector<long> &st1, n           vector<long> &st2) { n   st1.clear(); n   st2.clear(); n   st1.push_back(a[id1]); n   st1.push_back(a[id2]); n   long isize2; n   if (tid == -1) { n     isize2 = 0; n   } else { n     isize2 = 1; n     st2.push_back(a[tid]); n   } n   long seed = a[id2] - a[id1]; n   long seed2 = 0; n   long nextnum2 = 0; n   long nextnum = a[id2] + seed; n   for (long i = id2 + 1; i <= n; i++) { n     if (isize2 >= 2 && a[i] == nextnum && a[i] == nextnum2) { n       if (i == n) { n         nextnum += seed; n         st1.push_back(a[i]); n       } else if (nextnum + seed == a[i + 1]) { n         nextnum += seed; n         st1.push_back(a[i]); n       } else if (nextnum2 + seed2 == a[i + 1]) { n         st2.push_back(a[i]); n         nextnum2 += seed2; n         isize2++; n       } else n         return false; n     } else if (a[i] == nextnum) { n       nextnum += seed; n       st1.push_back(a[i]); n     } else { n       if (isize2 >= 2) { n         if (nextnum2 == a[i]) { n           st2.push_back(a[i]); n           isize2++; n           nextnum2 += seed2; n         } else if (isize2 == 2) { n           st2.push_back(st2[1]); n           isize2++; n           st2[1] = st1.back(); n           st1.pop_back(); n           if (st2[2] - st2[1] != st2[1] - st2[0]) return false; n           seed2 = st2[2] - st2[1]; n           nextnum2 = st2[2] + seed2; n           i--; n         } else n           return false; n       } else { n         st2.push_back(a[i]); n         isize2++; n         if (isize2 == 2) { n           seed2 = st2[1] - st2[0]; n           nextnum2 = st2[1] + seed2; n         } n       } n     } n   } n   if (seed == 0 && st1.size() > 2) return false; n   if (seed2 == 0 && st2.size() > 2) return false; n   if (isize2 == 0) return false; n   return true; n } n bool solve(long n, long a[], vector<long> &st1, vector<long> &st2) { n   if (n == 2) { n     st1.push_back(a[1]); n     st2.push_back(a[2]); n     return true; n   } else if (n == 3 && a[1] == a[2] && a[2] == a[3]) { n     st1.push_back(a[1]); n     st1.push_back(a[1]); n     st2.push_back(a[1]); n     return true; n   } else if (n == 4 && a[1] == a[2] && a[2] == a[3] && a[3] == a[4]) { n     st1.push_back(a[1]); n     st1.push_back(a[1]); n     st2.push_back(a[1]); n     st2.push_back(a[1]); n     return true; n   } n   if (test(n, a, 1, 3, 2, st1, st2)) return true; n   if (test(n, a, 2, 3, 1, st1, st2)) return true; n   if (test(n, a, 1, 2, -1, st1, st2)) return true; n   return false; n } n void output(bool res, vector<long> &st1, vector<long> &st2) { n   if (res) { n     for (vector<long>::iterator it = st1.begin(); it < st1.end(); it++) n       printf( %ld  , *it); n     printf(  n ); n     for (vector<long>::iterator it = st2.begin(); it < st2.end(); it++) n       printf( %ld  , *it); n   } else n     cout <<  No solution n ; n } n long n, a[30010 + 1]; n vector<long> st1, st2; n int main() { n   input(n, a); n   bool res = solve(n, a, st1, st2); n   output(res, st1, st2); n } n


#include <bits/stdc++.h> n using namespace std; n int a1, a2; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> a1 >> a2; n   int res = 0; n   if (a1 == 1 && a2 == 1) { n     cout << 0 <<   n ; n     return 0; n   } n   while (a1 > 0 && a2 > 0) { n     if (a1 < a2) n       ++a1, a2 -= 2; n     else n       ++a2, a1 -= 2; n     ++res; n   } n   cout << res <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b = 1, c = 2, o = 1, j, k; n   cin >> a; n   int p = a / 2; n   for (k = 0; k < a; k++) { n     for (j = 0; j < p; j++) { n       cout << c <<    ; n       c += 2; n     } n     for (j = 0; j < a - p * 2; j++) { n       cout << b <<    ; n       b += 2; n     } n     for (int j = 0; j < p; j++) { n       cout << c <<    ; n       c += 2; n     } n     cout << endl; n     if (p == 0) o = 0; n     if (o == 0) n       p++; n     else n       p--; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void aayush() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n } n int main() { n   aayush(); n   long long int t; n   cin >> t; n   while (t--) { n     long long int n; n     cin >> n; n     if (n % 4 == 0) { n       cout <<  YES  << endl; n     } else { n       cout <<  NO  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, h; n pair<int, int> arr[100010]; n int res[100010]; n int ptr = -1; n int cnt, bits; n int main() { n   cin >> n >> h; n   for (int i = 0; i < n; i++) { n     scanf( %d , &arr[i].first); n     arr[i].second = i; n     res[i] = 1; n   } n   sort(arr, arr + n); n   int ans = arr[n - 1].first + arr[n - 2].first - arr[0].first - arr[1].first; n   for (int i = n - 2; i >= 0; i--) { n     int mx = arr[i].first + arr[n - 1].first + h; n     if (i < n - 2) mx = max(mx, arr[n - 1].first + arr[n - 2].first); n     int init = min(7, i); n     int col[7]; n     if (i <= 6) { n       col[i] = 2; n       for (int j = i + 1; j < min(n, 7); j++) col[j] = 1; n     } n     for (int j = 0; j < (1 << init); j++) { n       for (int k = 0; k < init; k++) { n         col[k] = ((j & (1 << k)) ? 1 : 2); n       } n       int mn = 1000000000; n       for (int k = 0; k < min(n, 7); k++) { n         for (int l = k + 1; l < min(n, 7); l++) { n           int val = arr[k].first + arr[l].first; n           if (col[k] != col[l]) val += h; n           mn = min(mn, val); n         } n       } n       int dif = mx - mn; n       if (dif < ans) { n         ans = dif; n         ptr = i; n         cnt = init; n         bits = j; n       } n     } n   } n   if (ptr != -1) { n     for (int i = 0; i < cnt; i++) { n       res[arr[i].second] = ((bits & (1 << i)) ? 1 : 2); n     } n     res[arr[ptr].second] = 2; n     for (int i = ptr + 1; i < n; i++) res[arr[i].second] = 1; n   } n   cout << ans << endl; n   for (int i = 0; i < n; i++) { n     if (i) printf(   ); n     printf( %d , res[i]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long add(long long a, long long b) { n   return (a % 1000000007 + b % 1000000007) % 1000000007; n } n inline long long mul(long long a, long long b) { n   return (a % 1000000007 * b % 1000000007) % 1000000007; n } n long long pwr(long long a, long long b) { n   if (!b) return 1ll; n   long long t = pwr(a, b / 2); n   t = mul(t, t); n   if (b & 1) t = mul(t, a); n   return t; n } n long long modinv(long long a, long long b = 1000000007) { n   return pwr(a, b - 2); n } n long long gcd(long long a, long long b) { n   if (!b) return a; n   return gcd(b, a % b); n } n long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n, a, b, c, d; n     cin >> n >> a >> b >> c >> d; n     int x = a - b, y = a + b; n     int p = c - d, q = c + d; n     int mn = x * n, flag = 1; n     for (int i = 1; i <= n; i++) { n       if (mn <= q && mn >= p) { n         flag = 0; n         break; n       } n       if (mn < p) { n         int diff = p - mn; n         mn += min(diff, 2 * b); n       } n     } n     if (mn <= q && mn >= p) { n       flag = 0; n     } n     if (flag) n       cout <<  No n ; n     else n       cout <<  Yes n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, a, b, i, a1, b1, y, y1, ans, ans1, ans2, x; n   cin >> n >> a >> b; n   for (i = 1; i <= n; i++) { n     cin >> x; n     y = x * a; n     ans = y % b; n     if (a != 0) n       cout << ans / a <<    ; n     else n       cout << x <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:16777216 ) n using namespace std; n int dp[100005][30] = {0}; n int A[40][40] = {0}; n int main() { n   string s, b; n   cin >> s; n   int k; n   cin >> k; n   for (int i = 0; i < k; i++) { n     cin >> b; n     int x, y; n     x = b[0] -  a ; n     y = b[1] -  a ; n     A[x][y] = A[y][x] = 1; n   } n   int n = s.length(); n   for (int i = 1; i <= n; i++) n     for (int k = 0; k < 26; k++) { n       dp[i][k] = dp[i - 1][k]; n       for (int j = 0; j < 26; j++) n         if (!A[k][j] && s[i - 1] -  a  == k) n           dp[i][k] = max(dp[i][k], dp[i - 1][j] + 1); n     } n   int res = 0; n   for (int i = 0; i < 26; i++) { n     res = max(res, dp[n][i]); n   } n   cout << n - res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100005; n const long long oo = ((long long)1e18) + 7; n int N, M, T, K, Q; n vector<int> G[MAXN]; n int num[MAXN]; n int dep[MAXN]; n int pa[MAXN][25]; n int LOG = 20; n int cnt = 0; n int child[MAXN]; n int DFS(int u, int par, int depth) { n   num[u] = ++cnt; n   dep[num[u]] = depth; n   pa[num[u]][0] = num[par]; n   for (auto v : G[u]) n     if (v != par) { n       child[num[u]] += DFS(v, u, dep[num[u]] + 1); n     } n   return child[num[u]]; n } n int LCA(int u, int v) { n   if (u == v) return u; n   if (dep[u] < dep[v]) swap(u, v); n   for (int i = LOG; i >= 0; i--) n     if (dep[pa[u][i]] >= dep[v]) u = pa[u][i]; n   if (u == v) return u; n   for (int i = LOG; i >= 0; i--) n     if (pa[u][i] != pa[v][i]) { n       u = pa[u][i]; n       v = pa[v][i]; n     } n   return pa[u][0]; n } n int findParent(int u, int k) { n   if (k == 0) return u; n   int i = 0; n   while (k > 0) { n     if (k & 1) u = pa[u][i]; n     i++; n     k >>= 1; n   } n   return u; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   if (fopen( 519E  n              .inp , n              r )) { n     freopen( n          519E  n          .inp , n          r , stdin); n     freopen( n          519E  n          .out , n          w , stdout); n   } n   cin >> N; n   for (int i = 1; i < N; i++) { n     int u, v; n     cin >> u >> v; n     G[u].push_back(v); n     G[v].push_back(u); n   } n   for (int i = 1; i <= N; i++) child[i] = 1; n   dep[0] = -1; n   DFS(1, 0, 0); n   for (int k = 1; k <= LOG; k++) n     for (int i = 1; i <= N; i++) pa[i][k] = pa[pa[i][k - 1]][k - 1]; n   cin >> Q; n   while (Q--) { n     int u, v; n     cin >> u >> v; n     u = num[u]; n     v = num[v]; n     if (dep[u] < dep[v]) swap(u, v); n     int p = LCA(u, v); n     if (u == v) { n       cout << N <<   n ; n       continue; n     } n     int diff1 = dep[u] - dep[p]; n     int diff2 = dep[v] - dep[p]; n     if ((diff1 + diff2) & 1) { n       cout << 0 <<   n ; n       continue; n     } n     int avg = (diff1 + diff2) >> 1; n     int mid = findParent(u, avg); n     if (mid == p) { n       int fakeParent1 = findParent(u, diff1 - 1); n       int fakeParent2 = findParent(v, diff2 - 1); n       cout << (child[mid] - child[fakeParent1] - child[fakeParent2]) + N - n                   child[mid] n            <<   n ; n       continue; n     } n     diff1 = dep[u] - dep[mid]; n     int fakeParent1 = findParent(u, diff1 - 1); n     cout << child[mid] - child[fakeParent1] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool checkPal(string s) { n   for (int i = 0, j = s.size() - 1; i <= j; i++, j--) { n     if (s[i] != s[j]) { n       return false; n     } n   } n   return true; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   for (int i = 0; i < t; i++) { n     string s; n     cin >> s; n     map<char, int> m; n     for (int j = 0; j < s.size(); j++) { n       m[s[j]]++; n     } n     string ch =   ; n     for (auto it = m.rbegin(); it != m.rend(); it++) { n       pair<int, int> p = *it; n       char c = p.first; n       int cnt = p.second; n       for (int j = 0; j < cnt; j++) { n         ch += c; n       } n     } n     if (!checkPal(ch)) { n       cout << ch << endl; n     } else { n       cout << -1 << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[1000010]; n pair<long long, long long> st[1000010]; n bool check(pair<long long, long long> a, pair<long long, long long> b, n            pair<long long, long long> c) { n   double k1 = 1.0 * (b.second - a.second) / (b.first - a.first); n   double k2 = 1.0 * (c.second - b.second) / (c.first - b.first); n   if (k1 > k2) return 1; n   return 0; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     a[i] += a[i - 1]; n   } n   int top = 0; n   st[top++] = make_pair(0, 0); n   for (int i = 1; i <= n; i++) { n     pair<long long, long long> tmp = make_pair(i, a[i]); n     while (top > 1 && check(st[top - 2], st[top - 1], tmp)) top--; n     st[top++] = tmp; n   } n   for (int i = 0; i < top - 1; i++) { n     long long l = st[i].first, r = st[i + 1].first, n               tot = st[i + 1].second - st[i].second; n     for (int j = l + 1; j <= r; j++) { n       printf( %.9f n , 1.0 * tot / (r - l)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n int A[50], B[50]; n int main() { n   int N, M, i, j, Max, now, Cnt; n   while (scanf( %d , &N) != EOF) { n     for (i = 0; i < N; ++i) { n       scanf( %d , &A[i]); n     } n     scanf( %d , &M); n     for (i = 0; i < M; ++i) { n       scanf( %d , &B[i]); n     } n     for (Max = i = 0; i < N; ++i) { n       for (j = 0; j < M; ++j) { n         now = B[j] / A[i]; n         if (now * A[i] == B[j] && Max < now) { n           Max = now; n         } n       } n     } n     for (Cnt = i = 0; i < N; ++i) { n       for (j = 0; j < M; ++j) { n         now = B[j] / A[i]; n         if (now * A[i] == B[j] && Max == now) { n           ++Cnt; n         } n       } n     } n     printf( %d n , Cnt); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n = 5; n   int arr[5], sum = 0; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     sum += arr[i]; n   } n   if (sum == 0) n     cout << -1 << endl; n   else if (sum % 5 != 0) n     cout << -1 << endl; n   else { n     int s = sum / 5; n     int a = 0, b = 0; n     for (int i = 0; i < n; i++) { n       if (arr[i] > s) n         a += s - arr[i]; n       else n         b += arr[i] - s; n     } n     if (a == b) n       cout << s << endl; n     else n       cout << -1 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 840; n long long cnt[10]; n long long f[10][N]; n int main() { n   long long w; n   cin >> w; n   for (int i = 1; i <= 8; i++) cin >> cnt[i]; n   memset(f, 0xcf, sizeof f); n   f[0][0] = 0; n   long long res = 0; n   for (int i = 1; i <= 8; i++) { n     for (int j = 0; j < 840 / i && j <= cnt[i]; j++) { n       for (int k = 0; k < 840; k++) { n         int a = (k + j * i) / 840; n         int b = (k + j * i) % 840; n         f[i][b] = max(f[i][b], f[i - 1][k] + a + (cnt[i] - j) * i / 840); n         if (b <= w) res = max(res, min(f[i][b], (w - b) / 840) * 840 + b); n       } n     } n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     long long int n, a, b; n     cin >> n >> a >> b; n     string s; n     cin >> s; n     long long int ans = n * (a + 2 * b) + 2 * a; n     int st = 0, en = 0; n     while (en < n and s[en] ==  0 ) en++; n     if (en == n) { n       ans = n * a + (n + 1) * b; n       cout << ans <<   n ; n       continue; n     } n     ans -= (en - 1) * b; n     while (en != n) { n       st = en; n       while (s[st] !=  0 ) st++; n       en = st; n       while (en < n and s[en] ==  0 ) en++; n       if (en == n) { n         ans -= (en - st - 1) * b; n         break; n       } n       if (en - st != 1 and 2 * a < (en - st - 1) * b) n         ans += 2 * a - (en - st - 1) * b; n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int kN = 18; n const int kT = 1 << kN; n const int kInf = 0x3f3f3f3f; n int a[kT]; n bool fan_of[kT]; n std::map<std::pair<int, int>, int> cal[4]; n int Cal(int l, int r, int st) { n   if (r == l + 2) { n     int cnt_fan = (int)fan_of[l] + fan_of[l + 1], cnt_st = (st & 1) + (st >> 1); n     return cnt_fan == cnt_st ? std::min(cnt_st, 1) : -kInf; n   } n   std::pair<int, int> tmp = std::make_pair(l, r); n   if (cal[st].count(tmp)) return cal[st][tmp]; n   int mid = (l + r) >> 1, ret = -kInf; n   for (int i = 0; i < 4; ++i) n     for (int j = 0; j < 4; ++j) { n       int v1 = ((i << 1) | (i & 2) | j) & 3, v2 = ((j << 1) | (j & 2) | i) & 3; n       if (v1 == st || v2 == st) { n         ret = std::max(ret, Cal(l, mid, i) + Cal(mid, r, j)); n       } n     } n   return cal[st][tmp] = ret + st; n } n int main() { n   int n, k, t, ans = 0; n   scanf( %d%d , &n, &k); n   t = 1 << n; n   for (int i = 1; i <= k; ++i) scanf( %d , a + i), fan_of[--a[i]] = true; n   for (int i = 0; i < 4; ++i) ans = std::max(ans, Cal(0, t, i)); n   printf( %d , ans + !(!k)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long d[111111]; n long long sum[111111]; n int q[111111]; n long long cat[111111]; n long long dp[101][100001]; n long long getDP(int i, int j, int k) { n   return (long long)j * cat[j] + dp[i - 1][k] - j * cat[k]; n } n long long getUP(int i, int j, int k) { n   return (long long)dp[i - 1][j] - dp[i - 1][k]; n } n long long getDOWN(int j, int k) { return (long long)cat[j] - cat[k]; } n int main() { n   int i, j, k, n, m, p, h; n   cin >> n >> m >> p; n   for (i = 2; i <= n; i++) { n     cin >> d[i]; n     d[i] += d[i - 1]; n   } n   for (i = 1; i <= m; i++) { n     cin >> h >> cat[i]; n     cat[i] -= d[h]; n   } n   sort(cat + 1, cat + 1 + m); n   for (i = 1; i <= m; i++) sum[i] = sum[i - 1] + cat[i]; n   for (i = 1; i <= p; i++) n     for (j = 1; j <= m; j++) dp[i][j] = 999999999999999; n   dp[1][m] = (long long)m * cat[m] - sum[m]; n   for (i = 2; i <= p; i++) { n     int head, tail; n     head = tail = 0; n     q[tail++] = m; n     for (j = m; j >= 1; j--) { n       while (head + 1 < tail && (getUP(i, q[head + 1], q[head]) <= n                                  j * getDOWN(q[head + 1], q[head]))) n         head++; n       dp[i][j] = min(dp[i][j], getDP(i, j, q[head])); n       while (head + 1 < tail && n              getUP(i, j, q[tail - 1]) * getDOWN(q[tail - 1], q[tail - 2]) > n                  getUP(i, q[tail - 1], q[tail - 2]) * getDOWN(j, q[tail - 1])) n         tail--; n       q[tail++] = j; n     } n   } n   long long ans = dp[p][1]; n   for (i = 1; i <= m; i++) ans = min(ans, dp[p][i]); n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100000 + 5; n struct BIT { n   int a[N], n; n   void Init(int n) { this->n = n; } n   void add(int p, int v) { n     for (p = p + 1; p <= n; p += p & -p) a[p] += v; n     return; n   } n   int query(int p) { n     int res = 0; n     for (p = p + 1; p >= 1; p -= p & -p) res += a[p]; n     return res; n   } n } * TA; n struct Node { n   int val, idx; n   Node(int v, int i) { n     val = v; n     idx = i; n   } n }; n void update(Node &des, Node src) { n   des.val += src.val; n   TA->add(des.idx, src.val); n } n int main() { n   int n, q; n   cin >> n >> q; n   TA = new BIT(); n   TA->Init(n); n   deque<Node> Q; n   for (int i = 0; i < n; i++) TA->add(i, 1), Q.push_back(Node(1, i)); n   int s = 0; n   for (int i = 0; i < q; i++) { n     int f; n     scanf( %d , &f); n     if (f == 1) { n       int p; n       scanf( %d , &p); n       if (2 * p <= Q.size()) { n         if (s == 0) { n           for (int i = 0; i < p; i++) { n             update(Q[2 * p - 1 - i], Q[i]); n           } n           for (int i = 0; i < p; i++) Q.pop_front(); n         } else { n           for (int i = (int)Q.size() - 1; i >= Q.size() - p; i--) { n             update(Q[2 * (Q.size() - p) - 1 - i], Q[i]); n           } n           for (int i = 0; i < p; i++) Q.pop_back(); n         } n       } else { n         if (s == 0) { n           for (int i = (int)Q.size() - 1; i >= p; i--) { n             update(Q[2 * p - 1 - i], Q[i]); n           } n           int d = (int)Q.size() - p; n           for (int i = 0; i < d; i++) Q.pop_back(); n         } else { n           for (int i = 0; i < Q.size() - p; i++) { n             update(Q[2 * (Q.size() - p) - 1 - i], Q[i]); n           } n           int d = (int)Q.size() - p; n           for (int i = 0; i < d; i++) Q.pop_front(); n         } n         s = s ^ 1; n       } n     } else { n       int L, R; n       scanf( %d %d , &L, &R); n       --R; n       if (s == 1) { n         int ll = L, rr = R; n         L = Q[Q.size() - rr - 1].idx; n         R = Q[Q.size() - ll - 1].idx; n       } else { n         L = Q[L].idx, R = Q[R].idx; n       } n       printf( %d n , TA->query(R) - TA->query(L - 1)); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   while (cin >> s) { n     string integer; n     string decimal; n     bool isnegative = false; n     bool isdecimal = false; n     int pos = 0; n     if (s[0] ==  - ) { n       isnegative = true; n       pos++; n     } n     for (; pos < s.size(); pos++) { n       if (s[pos] ==  . ) { n         isdecimal = true; n       } else if (!isdecimal) { n         integer += s[pos]; n       } else { n         decimal += s[pos]; n       } n     } n     reverse(integer.begin(), integer.end()); n     string integerWithComma; n     for (int i = 0; i < integer.size(); i++) { n       integerWithComma += integer[i]; n       if (i != integer.size() - 1 && i % 3 == 2) { n         integerWithComma +=  , ; n       } n     } n     reverse(integerWithComma.begin(), integerWithComma.end()); n     string decimalProcess; n     if (decimal.size() == 0) { n       decimalProcess =  .00 ; n     } else if (decimal.size() == 1) { n       decimalProcess =  .  + decimal +  0 ; n     } else { n       decimalProcess =  .  + decimal.substr(0, 2); n     } n     if (isnegative) { n       cout <<  ( ; n     } n     cout <<  $ ; n     cout << integerWithComma; n     cout << decimalProcess; n     if (isnegative) { n       cout <<  ) ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string op, s1, s2; n map<string, int> mp; n int solve(string s) { n   int ast, amp; n   ast = count(s.begin(), s.end(),  * ); n   amp = count(s.begin(), s.end(),  & ); n   return ast - amp; n } n string remove(string s) { n   s.erase(remove(s.begin(), s.end(),  * ), s.end()); n   s.erase(remove(s.begin(), s.end(),  & ), s.end()); n   return s; n } n int main() { n   int N; n   cin >> N; n   mp[ void ] = 0; n   while (N--) { n     cin >> op; n     if (op ==  typedef ) { n       cin >> s1 >> s2; n       int d = solve(s1); n       s1 = remove(s1); n       if (mp.find(s1) != mp.end() && mp[s1] >= 0) n         mp[s2] = mp[s1] + d; n       else n         mp[s2] = -1; n     } else { n       cin >> s1; n       int d = solve(s1); n       s1 = remove(s1); n       if (mp.find(s1) != mp.end() && mp[s1] >= 0) { n         d += mp[s1]; n         if (d >= 0) { n           cout <<  void ; n           for (int i = 0; i < d; i++) cout <<  * ; n           cout << endl; n         } else n           cout <<  errtype  << endl; n       } else n         cout <<  errtype  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n unsigned long long power(unsigned long long x, unsigned long long y) { n   if (y == 0) return 1; n   unsigned long long tmp = power(x, y / 2); n   tmp *= tmp; n   if (y % 2) tmp *= x; n   return tmp; n } n unsigned long long get(unsigned long long n) { n   if (n <= 9) return n; n   unsigned long long cnt, temp, d = 0; n   unsigned long long tmp = n; n   while (tmp / 10) { n     tmp /= 10; n     d++; n   } n   stringstream s; n   s << n; n   string str = s.str(); n   unsigned long long x = str[0] -  0 ; n   temp = power(10, d); n   n -= (str[0] -  0 ) * temp; n   n /= 10; n   if (str[0] <= str[str.size() - 1]) n     cnt = n + 1; n   else n     cnt = n; n   cnt += ((power(10, d - 1)) * (x - 1)); n   return cnt + get(power(10, d) - 1); n } n int main() { n   unsigned long long l, r; n   cin >> l >> r; n   cout << get(r) - get(l - 1) << endl; n } n


#include <bits/stdc++.h> n int main() { n   int n, m; n   while (scanf( %d %d , &n, &m) != EOF) { n     if (n * m < 2) { n       printf( 0 n ); n     } else { n       printf( %d n , n * m / 2); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class A, class B> n A cvt(B x) { n   stringstream s; n   s << x; n   A r; n   s >> r; n   return r; n } n typedef vector<int> VI; n typedef vector<pair<int, int> > VII; n typedef vector<string> VS; n struct Treap { n   int val, priority; n   int maxVal, size; n   Treap *left; n   Treap *right; n   Treap() { n     val = priority = maxVal = size = 0; n     left = right = 0; n   } n   Treap(int _val, int _priority, int _maxVal, int _size) { n     val = _val; n     maxVal = _maxVal; n     size = _size; n     priority = _priority; n     left = right = 0; n   } n }; n int SZ(Treap *&t) { return t ? t->size : 0; } n int MAX(Treap *&t) { return t ? t->maxVal : 0; } n void Adjust(Treap *&T) { n   T->size = 1 + SZ(T->left) + SZ(T->right); n   T->maxVal = max(T->val, max(MAX(T->left), MAX(T->right))); n } n void rotateLeft(Treap *&T) { n   Treap *t = T->left; n   T->left = t->right; n   Adjust(T); n   t->right = T; n   Adjust(t); n   T = t; n } n void rotateRight(Treap *&T) { n   Treap *t = T->right; n   T->right = t->left; n   Adjust(T); n   t->left = T; n   Adjust(t); n   T = t; n } n void Balance(Treap *&T) { n   if (T->left) { n     if (T->left->priority > T->priority) rotateLeft(T); n   } n   if (T->right) { n     if (T->right->priority > T->priority) rotateRight(T); n   } n } n void insert(Treap *&T, int val, int where, int pri) { n   if (!T) n     T = new Treap(val, pri, val, 1); n   else { n     if (SZ(T->right) >= where) { n       insert(T->right, val, where, pri); n     } else if (max(T->val, MAX(T->right)) > val) { n       insert(T->right, val, where, pri); n     } else n       insert(T->left, val, where - SZ(T->right) - 1, pri); n     Adjust(T); n     Balance(T); n   } n } n int idx[101010]; n void print(Treap *&T) { n   if (T) { n     print(T->left); n     printf( %d  , idx[T->val]); n     print(T->right); n   } n } n int main() { n   int n, a, c; n   scanf( %d , &n); n   Treap *T = NULL; n   for (int i = (int)0; i < (int)n; ++i) { n     scanf( %d%d , &a, &c); n     idx[a] = i + 1; n     insert(T, a, c, rand() % 101010); n   } n   print(T); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Dinic { n   struct Edge { n     int to, flow, next; n   }; n   vector<Edge> edges; n   vector<int> head, act, h; n   int S, D; n   void AddEdge(int from, int to, int f, int rev_f = 0) { n     edges.push_back({to, f, (int)edges.size()}); n     swap(edges.back().next, head[from]); n     edges.push_back({from, rev_f, (int)edges.size()}); n     swap(edges.back().next, head[to]); n   } n   bool bfs() { n     fill(h.begin(), h.end(), -1); n     h[S] = 0; n     vector<int> q = {S}; n     for (int it = 0; it < q.size() && h[D] == -1; it++) { n       int nod = q[it]; n       for (int i = head[nod]; i != -1; i = edges[i].next) n         if (edges[i].flow && h[edges[i].to] == -1) n           h[edges[i].to] = 1 + h[nod], q.push_back(edges[i].to); n     } n     return h[D] != -1; n   } n   int dfs(int nod, int flow) { n     if (flow == 0 || nod == D) return flow; n     while (act[nod] != -1) { n       Edge& e = edges[act[nod]]; n       int d; n       if (e.flow && h[e.to] == 1 + h[nod] && n           (d = dfs(e.to, min(flow, e.flow))) != 0) { n         e.flow -= d; n         edges[act[nod] ^ 1].flow += d; n         return d; n       } n       act[nod] = edges[act[nod]].next; n     } n     return 0; n   } n   int GetFlow() { n     int f = 0; n     while (bfs()) { n       act = head; n       int d; n       while ((d = dfs(S, 1e9)) != 0) f += d; n     } n     return f; n   } n   Dinic(int dim = 0, int s = 0, int d = 0) n       : head(dim + 1, -1), h(dim + 1), S(s), D(d) {} n }; n struct FlowWithMinRestrictions { n   struct Edge { n     int from, to, flowmin, flowmax, id; n   }; n   vector<Edge> edges; n   int S, D, n; n   void AddEdge(int from, int to, int flowmin, int flowmax) { n     edges.push_back({from, to, flowmin, flowmax, 0}); n   } n   vector<int> Solve(bool& feasible, int& flow) { n     feasible = 1; n     flow = 0; n     int news = n + 1, newd = n + 2; n     Dinic first_flow(n + 2, news, newd); n     first_flow.AddEdge(D, S, 1e9); n     int s_minime = 0; n     for (auto& i : edges) { n       if (i.flowmax < i.flowmin) { n         feasible = 0; n         return vector<int>(); n       } n       s_minime += i.flowmin; n       i.id = first_flow.edges.size(); n       first_flow.AddEdge(i.from, i.to, i.flowmax - i.flowmin); n       first_flow.AddEdge(news, i.to, i.flowmin); n       first_flow.AddEdge(i.from, newd, i.flowmin); n     } n     if (first_flow.GetFlow() != s_minime) { n       feasible = 0; n       return vector<int>(); n     } n     Dinic curent_flow(n, S, D); n     for (auto& i : edges) { n       int dif = i.flowmax - i.flowmin; n       int passed = dif - first_flow.edges[i.id].flow; n       int nid = curent_flow.edges.size(); n       curent_flow.AddEdge(i.from, i.to, first_flow.edges[i.id].flow, passed); n       i.id = nid; n     } n     curent_flow.GetFlow(); n     vector<int> ans(edges.size()); n     for (int i = 0; i < edges.size(); i++) { n       int cntflow = curent_flow.edges[edges[i].id ^ 1].flow + edges[i].flowmin; n       ans[i] = cntflow; n       if (edges[i].from == S) flow += cntflow; n       if (edges[i].to == S) flow -= cntflow; n     } n     return ans; n   } n   FlowWithMinRestrictions(int n = 0, int s = 0, int d = 0) : n(n), S(s), D(d) {} n }; n namespace ProbD { n const int NMAX = 200010; n map<int, int> nrmx, nrmy; n FlowWithMinRestrictions flow; n pair<int, int> shields[NMAX]; n int idshield[NMAX]; n int n, S, D; n int difmax[NMAX]; n int nr_on_poz[NMAX]; n int cnt = 0; n void normalize() { n   for (int i = 0; i < n; i++) n     nrmx[shields[i].first] = nrmy[shields[i].second] = 0; n   for (auto& i : nrmx) i.second = cnt++; n   for (auto& i : nrmy) i.second = cnt++; n   S = cnt++; n   D = cnt; n   fill(difmax, difmax + cnt + 1, 1e9); n } n void solve() { n   int r, b; n   int nrc; n   cin >> n >> nrc >> r >> b; n   for (int i = 0; i < n; i++) cin >> shields[i].first >> shields[i].second; n   normalize(); n   flow = FlowWithMinRestrictions(cnt, S, D); n   for (int i = 0; i < n; i++) { n     shields[i].first = nrmx[shields[i].first], n     shields[i].second = nrmy[shields[i].second]; n     idshield[i] = flow.edges.size(); n     nr_on_poz[shields[i].first]++, nr_on_poz[shields[i].second]++; n     flow.AddEdge(shields[i].first, shields[i].second, 0, 1); n   } n   while (nrc--) { n     int t, p, val; n     cin >> t >> p >> val; n     if (t == 1 && nrmx.find(p) != nrmx.end()) n       difmax[nrmx[p]] = min(difmax[nrmx[p]], val); n     else if (t == 2 && nrmy.find(p) != nrmy.end()) n       difmax[nrmy[p]] = min(difmax[nrmy[p]], val); n   } n   vector<pair<int, pair<int, int>>> verif; n   for (auto i : nrmx) { n     int nr = nr_on_poz[i.second]; n     int dmax = difmax[i.second]; n     int vmax = (dmax + nr) / 2; n     int vmin = max(0, (nr - dmax + 1) / 2); n     verif.push_back({(int)flow.edges.size(), {vmin, vmax}}); n     flow.AddEdge(S, i.second, vmin, vmax); n   } n   for (auto i : nrmy) { n     int nr = nr_on_poz[i.second]; n     int dmax = difmax[i.second]; n     int vmax = (dmax + nr) / 2; n     int vmin = max(0, (nr - dmax + 1) / 2); n     verif.push_back({(int)flow.edges.size(), {vmin, vmax}}); n     flow.AddEdge(i.second, D, vmin, vmax); n   } n   int f; n   bool posibil; n   auto ans = flow.Solve(posibil, f); n   if (!posibil) { n     cout <<  -1 n ; n     return; n   } n   for (auto i : verif) n     assert(ans[i.first] >= i.second.first && ans[i.first] <= i.second.second); n   cout << 1LL * f * min(r, b) + 1LL * (n - f) * max(r, b) <<   n ; n   string s =  rb ; n   if (r < b) s =  br ; n   for (int i = 0; i < n; i++) cout << s[ans[idshield[i]]]; n   cout <<   n ; n } n }  // namespace ProbD n int main() { n   ios_base::sync_with_stdio(0); n   ProbD::solve(); n   return 0; n   FILE* in = fopen( cuplaj.in ,  r ); n   int n, m; n   fscanf(in,  %d%d , &n, &m); n   FlowWithMinRestrictions flow(n, 1, n); n   while (m--) { n     int a, b, c, d; n     fscanf(in,  %d%d%d%d , &a, &b, &c, &d); n     flow.AddEdge(a, b, c, d); n   } n   bool feasible; n   int f; n   auto ans = flow.Solve(feasible, f); n   ofstream out( flux.out ); n   out << feasible <<   n  << f <<   n ; n   for (auto i : ans) out << i <<    ; n   return 0; n } n


#include <bits/stdc++.h> n bool g[1111][1111]; n int main() { n   int n, m; n   memset(g, false, sizeof(g)); n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     g[u][v] = true; n   } n   int count = 0; n   for (int i = 2; i < n; i++) { n     bool flag = false; n     for (int j = 1; j <= n; j++) n       if (g[i][j] == true) { n         flag = true; n         break; n       } n     if (flag) continue; n     count++; n   } n   for (int j = 2; j < n; j++) { n     bool flag = false; n     for (int i = 1; i <= n; i++) n       if (g[i][j]) { n         flag = true; n         break; n       } n     if (flag) continue; n     count++; n   } n   if (n & 1) { n     int i, j; n     for (i = 1; i <= n; i++) n       if (g[i][n / 2 + 1]) break; n     for (j = 1; j <= n; j++) n       if (g[n / 2 + 1][j]) break; n     if (i > n && j > n) n       if (count) count--; n   } n   printf( %d n , count); n   return 0; n } n


#include <bits/stdc++.h> n char s1[100100], s2[100100], s3[100100]; n bool dist[100100]; n int pos[100100]; n int main() { n   int n, t, i; n   int num = 0, po = 0; n   memset(dist, false, sizeof(dist)); n   scanf( %d%d , &n, &t); n   scanf( %s%s , s1, s2); n   for (i = 0; i < n; i++) s3[i] =  1 ; n   for (i = 0; i < n; i++) { n     if (s1[i] == s2[i]) { n       dist[i] = true; n       pos[po++] = i; n       num += 2; n     } else n       num++; n   } n   if (num < 2 * (n - t)) n     printf( -1 n ); n   else { n     int j = 0; n     int l = n - t; n     while (l > 0 && j < po) { n       s3[pos[j]] = s1[pos[j]]; n       j++; n       l--; n     } n     for (i = 0; i < n; i++) { n       if (l > 0) { n         while (s3[i] !=  1 ) i++; n         s3[i] = s1[i]; n         while (s3[i] !=  1 ) i++; n         s3[i] = s2[i]; n         l--; n         i--; n       } else if (s3[i] ==  1 ) { n         char ch =  a ; n         while (ch == s1[i] || ch == s2[i]) ch++; n         s3[i] = ch; n       } n     } n     s3[n] =   0 ; n     printf( %s n , s3); n     return 0; n   } n } n


#include <bits/stdc++.h> n const int N = 517; n const int mod = 998244353; n using namespace std; n inline int read() { n   int x = 0; n   char ch = getchar(); n   while (!isdigit(ch)) ch = getchar(); n   while (isdigit(ch)) x = (x << 1) + (x << 3) + ch -  0 , ch = getchar(); n   return x; n } n int n, k; n long long dp[N][N], ans; n int main() { n   n = read(), k = read(); n   dp[0][0] = 1; n   for (int i = 1, I = (n) + 1; i < I; ++i) n     for (int j = 1, I = (i) + 1; j < I; ++j) n       for (int k = i - j, I = (i - 1) + 1; k < I; ++k) n         dp[i][j] = (dp[i][j] + dp[k][min(j, k)]) % mod; n   for (int i = n, I = (1) - 1; i > I; --i) n     dp[n][i] = (dp[n][i] - dp[n][i - 1] + mod) % mod; n   for (int i = 1, I = (n) + 1; i < I; ++i) n     for (int j = 1, I = (n) + 1; j < I; ++j) n       if (i * j < k) ans = (ans + dp[n][i] * dp[n][j]) % mod; n   printf( %lld n , (ans << 1) % mod); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t; n long long sx, sy, ex, ey; n int main(void) { n   cin >> t >> sx >> sy >> ex >> ey; n   int ans = 0; n   for (int i = 0; i < t; i++) { n     char c; n     cin >> c; n     if (sx == ex && sy == ey) { n       cout << ans <<   n ; n       return 0; n     } n     if (c ==  N  && sy < ey) sy++; n     if (c ==  W  && sx > ex) sx--; n     if (c ==  S  && sy > ey) sy--; n     if (c ==  E  && sx < ex) sx++; n     ans++; n   } n   if (sx == ex && sy == ey) { n     cout << ans <<   n ; n     return 0; n   } n   cout <<  -1 n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> g[100010]; n int t[100010], p[18][100010], L[100010], d[100010]; n vector<int> a[18][100010], c[100010]; n void dfs(int u) { n   for (int i = 0; i < (int)g[u].size(); i++) { n     int v = g[u][i]; n     if (t[v] == -1) { n       t[v] = u; n       d[v] = d[u] + 1; n       dfs(v); n     } n   } n } n void Merge(const vector<int>& A, const vector<int>& B, vector<int>& C, n            int L = 10) { n   int i = 0, j = 0, k = 0, n = (int)A.size(), m = (int)B.size(); n   while (i < n && j < m && k < L) { n     if (A[i] < B[j]) { n       C.push_back(A[i]); n       i++, k++; n     } else if (B[j] < A[i]) { n       C.push_back(B[j]); n       j++, k++; n     } else { n       C.push_back(A[i]); n       i++; n       j++; n     } n   } n   while (i < n && k < L) { n     C.push_back(A[i]); n     i++, k++; n   } n   while (j < m && k < L) { n     C.push_back(B[j]); n     j++, k++; n   } n } n int scan() { n   int ret = 0; n   int ip = getchar(); n   for (; ip <  0  || ip >  9 ; ip = getchar()) n     ; n   for (; ip >=  0  && ip <=  9 ; ip = getchar()) ret = ret * 10 + ip -  0 ; n   return ret; n } n int main() { n   int n, m, q, i, j, u, v, l, x, y; n   vector<int> ans, temp, temp1; n   L[1] = 0; n   for (i = 2; i < 100010; i++) L[i] = L[i >> 1] + 1; n   n = scan(); n   m = scan(); n   q = scan(); n   for (i = 0; i < n - 1; i++) { n     u = scan(); n     v = scan(); n     --u, --v; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   for (i = 0; i < m; i++) { n     u = scan(); n     --u; n     c[u].push_back(i + 1); n   } n   for (i = 0; i < n; i++) t[i] = -1; n   t[0] = 0; n   d[0] = 0; n   dfs(0); n   t[0] = -1; n   for (i = 0; i < n; i++) n     for (j = 0; (1 << j) < n; j++) p[j][i] = -1; n   for (i = 0; i < n; i++) { n     p[0][i] = t[i]; n     if (t[i] != -1 && (int)c[t[i]].size() > 0) n       for (j = 0; j < (int)c[t[i]].size() && j < 10; j++) n         a[0][i].push_back(c[t[i]][j]); n   } n   for (j = 1; (1 << j) < n; j++) { n     for (i = 0; i < n; i++) { n       if (p[j - 1][i] != -1) { n         p[j][i] = p[j - 1][p[j - 1][i]]; n         Merge(a[j - 1][i], a[j - 1][p[j - 1][i]], a[j][i]); n       } n     } n   } n   while (q--) { n     u = scan(); n     v = scan(); n     m = scan(); n     --u, --v; n     if (u == v) { n       if (!c[u].empty()) { n         m = min(m, (int)c[u].size()); n         printf( %d , m); n         for (i = 0; i < m; i++) printf(  %d , c[u][i]); n         printf(  n ); n       } else n         printf( 0 n ); n       continue; n     } n     x = u; n     y = v; n     temp.clear(); n     temp1.clear(); n     ans.clear(); n     if (d[u] < d[v]) swap(u, v); n     temp = c[u]; n     temp1 = c[v]; n     Merge(temp, temp1, ans); n     l = L[d[u]]; n     for (i = l; i >= 0; i--) n       if (d[u] - (1 << i) >= d[v]) { n         temp = ans; n         ans.clear(); n         Merge(temp, a[i][u], ans, m); n         u = p[i][u]; n       } n     if (u != v) { n       for (i = l; i >= 0; i--) n         if (p[i][u] != -1 && p[i][u] != p[i][v]) { n           temp.clear(); n           Merge(a[i][u], a[i][v], temp, m); n           temp1 = ans; n           ans.clear(); n           Merge(temp, temp1, ans, m); n           u = p[i][u]; n           v = p[i][v]; n         } n       temp = ans; n       ans.clear(); n       Merge(temp, a[0][u], ans, m); n     } n     m = min(m, (int)ans.size()); n     printf( %d , m); n     for (i = 0; i < m; i++) printf(  %d , ans[i]); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, ans = 0, c; n   cin >> n; n   for (long long i = 1; i <= n; i++) { n     cin >> c; n     ans += c; n   } n   c = (n == 1 ? 1 : n - 1); n   if (ans == c) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INT_INF = 1e9; n const long long LL_INF = 1e18; n const int MAXN = 200003; n int n, m; n int A[MAXN]; n long long calc(int m) { n   long long ret = 0; n   map<int, int> dp; n   int sum = 0; n   dp[sum] = 1; n   long long add = 0; n   for (int i = 1; i <= n; i++) { n     if (A[i] < m) { n       sum--; n       add -= dp[sum]; n     } else if (A[i] >= m) { n       add += dp[sum]; n       sum++; n     } n     ret += add; n     dp[sum]++; n   } n   return ret; n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1, x; i <= n; i++) { n     scanf( %d , &x); n     A[i] = x; n   } n   long long ret1 = calc(m); n   long long ret2 = calc(m + 1); n   printf( %lld , ret1 - ret2); n   return 0; n } n