#include <bits/stdc++.h> n using namespace std; n const int MAX = 2005; n pair<int, int> q[MAX * MAX]; n char a[MAX][MAX]; n int dx[4] = {-1, 0, 1, 0}; n int dy[4] = {0, 1, 0, -1}; n char tt[4] = { v ,  < ,  ^ ,  > }; n int n, m; n bool isav(int x, int y) { n   return (0 <= x && x < n && 0 <= y && y < m && a[x][y] ==  . ); n } n int deg(int x, int y) { n   int ans = 0; n   for (int i = 0; i < 4; i++) { n     int nx = x + dx[i]; n     int ny = y + dy[i]; n     if (isav(nx, ny)) ans++; n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   ios::sync_with_stdio(false); n   cin >> n >> m; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) cin >> a[i][j]; n   int h = 0, t = 0; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) n       if (isav(i, j) && deg(i, j) == 1) q[t++] = make_pair(i, j); n   while (h < t) { n     int x = q[h].first, y = q[h].second; n     h++; n     for (int i = 0; i < 4; i++) { n       int nx = x + dx[i]; n       int ny = y + dy[i]; n       if (isav(nx, ny)) { n         a[x][y] = tt[i]; n         a[nx][ny] = tt[i ^ 2]; n         for (int j = 0; j < 4; j++) { n           int nnx = nx + dx[j]; n           int nny = ny + dy[j]; n           if (isav(nnx, nny) && deg(nnx, nny) == 1) n             q[t++] = make_pair(nnx, nny); n         } n         break; n       } n     } n   } n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) n       if (a[i][j] ==  . ) { n         cout <<  Not unique  << endl; n         return 0; n       } n   for (int i = 0; i < n; i++, cout << endl) n     for (int j = 0; j < m; j++) cout << a[i][j]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace chrono; n void _print(long long 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 template <class T, class V> n void _print(pair<T, V> p); n template <class T> n void _print(vector<T> v); n template <class T> n void _print(set<T> v); n template <class T, class V> n void _print(map<T, V> v); n template <class T> n void _print(multiset<T> v); n template <class T, class V> n void _print(pair<T, V> p) { n   cerr <<  { ; n   _print(p.first); n   cerr <<  , ; n   _print(p.second); n   cerr <<  } ; n } n template <class T> n void _print(vector<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T> n void _print(set<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T> n void _print(multiset<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T, class V> n void _print(map<T, V> v) { n   cerr <<  [  ; n   for (auto i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n long long gcd(long long a, long long b) { n   if (b > a) { n     return gcd(b, a); n   } n   if (b == 0) { n     return a; n   } n   return gcd(b, a % b); n } n long long expo(long long a, long long b, long long mod) { n   long long res = 1; n   while (b > 0) { n     if (b & 1) res = (res * a) % mod; n     a = (a * a) % mod; n     b = b >> 1; n   } n   return res; n } n void extendgcd(long long a, long long b, long long *v) { n   if (b == 0) { n     v[0] = 1; n     v[1] = 0; n     v[2] = a; n     return; n   } n   extendgcd(b, a % b, v); n   long long x = v[1]; n   v[1] = v[0] - v[1] * (a / b); n   v[0] = x; n   return; n } n long long mminv(long long a, long long b) { n   long long arr[3]; n   extendgcd(a, b, arr); n   return arr[0]; n } n long long mminvprime(long long a, long long b) { return expo(a, b - 2, b); } n bool revsort(long long a, long long b) { return a > b; } n void swap(int &x, int &y) { n   int temp = x; n   x = y; n   y = temp; n } n long long combination(long long n, long long r, long long m, long long *fact, n                       long long *ifact) { n   long long val1 = fact[n]; n   long long val2 = ifact[n - r]; n   long long val3 = ifact[r]; n   return (((val1 * val2) % m) * val3) % m; n } n void google(int t) { cout <<  Case #  << t <<  :  ; } n vector<long long> sieve(int n) { n   int *arr = new int[n + 1](); n   vector<long long> vect; n   for (int i = 2; i <= n; i++) n     if (arr[i] == 0) { n       vect.push_back(i); n       for (int j = 2 * i; j <= n; j += i) arr[j] = 1; n     } n   return vect; n } n long long mod_add(long long a, long long b, long long m) { n   a = a % m; n   b = b % m; n   return (((a + b) % m) + m) % m; n } n long long mod_mul(long long a, long long b, long long m) { n   a = a % m; n   b = b % m; n   return (((a * b) % m) + m) % m; n } n long long mod_sub(long long a, long long b, long long m) { n   a = a % m; n   b = b % m; n   return (((a - b) % m) + m) % m; n } n long long mod_div(long long a, long long b, long long m) { n   a = a % m; n   b = b % m; n   return (mod_mul(a, mminvprime(b, m), m) + m) % m; n } n long long phin(long long n) { n   long long number = n; n   if (n % 2 == 0) { n     number /= 2; n     while (n % 2 == 0) n /= 2; n   } n   for (long long i = 3; i <= sqrt(n); i += 2) { n     if (n % i == 0) { n       while (n % i == 0) n /= i; n       number = (number / i * (i - 1)); n     } n   } n   if (n > 1) number = (number / n * (n - 1)); n   return number; n } n int isprime(int N) { n   if (N < 2 || (!(N & 1) && N != 2)) return 0; n   for (int i = 3; i * i <= N; i += 2) { n     if (!(N % i)) return 0; n   } n   return 1; n } n int bin_pow(int ind, int power) { n   if (power == 0) { n     return 1; n   } n   if (power & 1) { n     return ind * bin_pow(ind, power - 1) % 1000000007; n   } else { n     return bin_pow((ind * ind) % 1000000007, power / 2) % 1000000007; n   } n } n int fact(int x) { n   int ret = 1; n   for (int i = 2; i <= x; i++) { n     ret *= i; n     ret %= 1000000007; n   } n   return ret; n } n int ncr(int n, int r) { n   if (r > n) return 0; n   return (fact(n) * n           (bin_pow((fact(r) * fact(n - r)) % 1000000007, 1000000007 - 2))) % n          1000000007; n } n void solve() { n   int n; n   cin >> n; n   long long arr[200010], total = 0; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     if (i > 0) n       total += abs(arr[i] - arr[i - 1]); n     else n       total += abs(arr[i]); n   } n   cout << total << endl; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   auto start1 = high_resolution_clock::now(); n   solve(); n   auto stop1 = high_resolution_clock::now(); n   auto duration = duration_cast<microseconds>(stop1 - start1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[8][8], b[8][8]; n long long get() { n   char c = getchar(); n   long long x = 0LL; n   while (c <  0  || c >  9 ) c = getchar(); n   while (c >=  0  && c <=  9 ) { n     x *= 10LL; n     x += (c -  0 ); n     c = getchar(); n   } n   return x; n } n int main() { n   char c; n   for (int i = 0; i < 8; i++) n     for (int j = 0; j < 8; j++) { n       cin >> c; n       if (c ==  B ) a[i][j] = 1; n     } n   int ans = 16; n   for (int i = 0; i < (1 << 8); i++) n     for (int j = 0; j < (1 << 8); j++) { n       for (int x = 0; x < 8; x++) n         for (int y = 0; y < 8; y++) { n           if (i & (1 << x) || j & (1 << y)) n             b[x][y] = 1; n           else n             b[x][y] = 0; n         } n       bool f = true; n       for (int x = 0; x < 8; x++) n         for (int y = 0; y < 8; y++) n           if (b[x][y] != a[x][y]) f = false; n       if (f) { n         ans = min(ans, __builtin_popcount(i) + __builtin_popcount(j)); n       } n     } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, kk, a[500010], b[500010]; n int sum1[500010], sum2[500010], sum3[500010], num[500010], k1[500010], n     k2[500010], k3[500010]; n unordered_map<int, int> mp; n int main() { n   scanf( %d%d , &n, &kk); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   sort(a + 1, a + 1 + n); n   b[1] = a[1]; n   mp[b[1]] = 1; n   int k = 1; n   for (int i = 2; i <= n; i++) { n     if (a[i] != b[k]) { n       k++; n       b[k] = a[i]; n       mp[b[k]] = k; n     } n   } n   int p = (kk * 8) / n; n   int kind = 1; n   for (int i = 1; i <= p; i++) { n     kind = kind * 2; n     if (kind >= k) { n       printf( 0 n ); n       return (0); n     } n   } n   int res = k - kind; n   for (int i = 1; i <= n; i++) num[mp[a[i]]]++; n   for (int i = 1; i <= k; i++) { n     sum1[i] = sum1[i - 1] + num[i]; n     k1[i] = k1[i - 1] + (num[i] > 0); n   } n   for (int i = k; i >= 1; i--) { n     sum2[i] = sum2[i + 1] + num[i]; n     k2[i] = k2[i + 1] + (num[i] > 0); n   } n   for (int i = 1; i <= k; i++) { n     sum3[i] = sum2[k - i + 1]; n     k3[i] = k2[k - i + 1]; n   } n   int ans = 1e9 + 7; n   for (int i = 1; i <= k; i++) { n     int x = res - k1[i]; n     if (x <= 0) ans = min(ans, sum1[i]); n     int l = lower_bound(k3 + 1, k3 + 1 + k - i, x) - k3; n     if (l != k + 1 - i) { n       ans = min(ans, sum1[i] + sum3[l]); n     } n   } n   for (int i = 1; i <= k; i++) { n     int x = res - k3[i]; n     if (x <= 0) ans = min(ans, sum3[i]); n   } n   printf( %d n , ans); n   return (0); n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n const int N = 5e5 + 2; n int seg[N * 4]; n int lazy[N * 4]; n int hi[N]; n int h[N]; n int n; n vector<int> g[N]; n vector<int> y[N]; n pair<int, int> t[N]; n void dfs(int v, int p) { n   t[v] = t[p]; n   if (hi[t[v].second] > hi[v]) { n     t[v].second = v; n   } n   if (hi[t[v].second] < hi[t[v].first]) swap(t[v].second, t[v].first); n   for (auto &u : g[v]) { n     if (u == p) continue; n     dfs(u, v); n   } n } n void upd(int nod, int l, int r, int L, int R, int val) { n   if (l >= R || L >= r) return; n   if (l >= L && r <= R) { n     seg[nod] += val; n     lazy[nod] += val; n     return; n   } n   int mid = (r + l) >> 1; n   upd(nod << 1, l, mid, L, R, val); n   upd(nod << 1 | 1, mid, r, L, R, val); n   seg[nod] = min(seg[nod << 1], seg[nod << 1 | 1]) + lazy[nod]; n } n inline bool check(int v, int val) { n   for (auto &u : y[v]) { n     int x = hi[t[u].first]; n     int y = min(hi[t[u].second], hi[t[u].first] + val); n     int z = upper_bound(h + 1, h + n + 1, x) - h; n     int e = upper_bound(h + 1, h + n + 1, y) - h; n     upd(1, 1, N, z, e, +1); n   } n   bool p1 = 0; n   if (seg[1] >= 0) p1 = 1; n   for (auto &u : y[v]) { n     int x = hi[t[u].first]; n     int y = min(hi[t[u].second], hi[t[u].first] + val); n     int z = upper_bound(h + 1, h + n + 1, x) - h; n     int e = upper_bound(h + 1, h + n + 1, y) - h; n     upd(1, 1, N, z, e, -1); n   } n   return p1; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &hi[i]); n   } n   for (int i = 0; i < n - 1; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     g[u].push_back(v); n     g[v].push_back(u); n   } n   int k; n   scanf( %d , &k); n   for (int i = 1; i <= k; i++) { n     scanf( %d , &h[i]); n   } n   sort(h + 1, h + n + 1); n   for (int i = n; i; i--) { n     upd(1, 1, N, 1, i + 1, -1); n   } n   hi[0] = 1e9 + 100; n   t[0] = {0, 0}; n   dfs(1, 0); n   for (int i = 1; i <= n; i++) { n     y[t[i].first].push_back(i); n     int z = upper_bound(h + 1, h + n + 1, hi[t[i].first]) - h; n     upd(1, 1, N, 1, z, +1); n   } n   int l1 = -1, r1 = 1e9 + 2; n   for (int i = 1; i <= n; i++) { n     int l = -1, r = r1; n     if (!(check(i, r - 1))) continue; n     while (r - l > 1) { n       int mid = (r + l) / 2; n       int z = check(i, mid); n       if (z) n         r = mid; n       else n         l = mid; n     } n     r1 = r; n   } n   if (r1 > 1e9) { n     printf( %d , -1); n     return 0; n   } n   printf( %d , r1); n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n void solve() { n   ll n, k; n   cin >> n >> k; n   vector<ll> arr(n); n   for (int i = 0; i < n; i++) cin >> arr[i]; n   ll dp[n][n]; n   for (int i = 1; i < n; i++) dp[0][i] = 0; n   ll curr = 0; n   for (int i = 0; i < n; i++) { n     if (arr[i] == (i + 1)) curr += 1; n     dp[i][0] = curr; n   } n   for (int i = 1; i < n; i++) { n     for (int j = 1; j < n; j++) { n       ll temp = (arr[i] == (i - j + 1)); n       dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j] + temp); n     } n   } n   ll ans = -1; n   for (int i = 0; i < n; i++) { n     if (dp[n - 1][i] >= k) { n       ans = i; n       break; n     } n   } n   cout << ans <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int maxn = 2e5 + 1; n void solve() { n   string s, even, odd; n   cin >> s; n   for (long long int i = 0; i < s.length(); i++) { n     long long int val = s[i] -  0 ; n     if (val % 2 == 0) n       even += s[i]; n     else n       odd += s[i]; n   } n   if (odd.length() == 0) { n     cout << even <<   n ; n   } else if (even.length() == 0) { n     cout << odd <<   n ; n   } else { n     long long int n1 = odd.length(), n2 = even.length(); n     long long int i = 0, j = 0; n     while (i < n1 && j < n2) { n       if (odd[i] < even[j]) { n         cout << odd[i]; n         i++; n       } else if (odd[i] > even[j]) { n         cout << even[j]; n         j++; n       } else { n         cout << odd[i] << even[j]; n         i++; n         j++; n       } n     } n     while (i < n1) { n       cout << odd[i]; n       i++; n     } n     while (j < n2) { n       cout << even[j]; n       j++; n     } n     cout <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int T = 1, p = 0; n   cin >> T; n   do { n     solve(); n     p++; n   } while (p < T); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   int n; n   cin >> n; n   vector<int> a(n); n   int odd = 0; n   for (auto &i : a) cin >> i, odd += i & 1; n   if (odd > 0 && odd < n) sort(a.begin(), a.end()); n   for (auto &i : a) cout << i <<    n [&i == &a.back()]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353; n const int mxn = 1000001, k = 4; n const char c[k] = { ( ,  ) ,  ? ,  ? }; n int n; n string second; n long long first[mxn], rf[mxn], iv[mxn], a[k]; n vector<long long> dp[mxn]; n long long sol() { n   int x = a[2] + a[3], y = a[1] + a[3] - a[0] - 1; n   if (y < 0) return 0; n   if (!dp[x].empty()) return dp[x][min(x, y)]; n   dp[x].resize(x + 1); n   dp[x][0] = 1; n   for (int i = 1; i <= x; i++) { n     dp[x][i] = (first[x] * rf[i] % mod * rf[x - i] + dp[x][i - 1]) % mod; n   } n   return dp[x][min(x, y)]; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> second; n   n = second.size(); n   for (int i = 1; i < k; i += 2) n     a[i] = count(second.begin(), second.end(), c[i]); n   first[0] = rf[0] = iv[0] = 1; n   for (int i = 1; i <= n; i++) { n     iv[i] = ~-i ? mod - mod / i * iv[mod % i] % mod : 1; n     first[i] = i * first[i - 1] % mod; n     rf[i] = iv[i] * rf[i - 1] % mod; n   } n   long long ret = 0; n   for (long long i = 0; i < n; i++) { n     for (int j = 1; j < k; j += 2) a[j] -= (second[i] == c[j]); n     if (!((find(c, c + k, second[i]) - c) & 1)) (ret += sol()) %= mod; n     for (int j = 0; j < k; j += 2) a[j] += (second[i] == c[j]); n   } n   cout << ret <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char key[] =  (8[ ; n   char fir[100], sec[100]; n   int i, len, a, b, c; n   scanf( %s%s , fir, sec); n   len = strlen(fir); n   c = 0; n   for (i = 0; i < len; i += 2) { n     a = strchr(key, fir[i]) - key; n     b = strchr(key, sec[i]) - key; n     if (a == b) continue; n     if ((a + 1) % 3 == b) n       c++; n     else n       c--; n   } n   if (c > 0) n     puts( TEAM 1 WINS ); n   else if (c < 0) n     puts( TEAM 2 WINS ); n   else n     puts( TIE ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef long long ll; n typedef __int128_t LL; n typedef long double ld; n typedef pair<int, int> pii; n typedef pair<ll, ll> pll; n #define F first n #define S second n #define pb push_back n mt19937 rnd; n  n const int N = 1e5 + 10; n bool good[N], ban[N]; n  n vector<int> get(const vector<int>& a) { n     vector<int> res; n     for (int i = 1; i < a.size(); i++) { n         res.pb(a[i] - a[i - 1] - 1); n     } n     return res; n } n  n bool solve0(int n) { n     for (int i = 1; i <= n; i++) { n         if (!good[i]) { n             return 0; n         } n     } n     return 1; n } n  n vector<int> solve1(int n) { n     if (good[1] || good[n]) { n         return {}; n     } n     for (int i = 1; i <= n - 1; i++) { n         if (good[i] && good[i + 1]) { n             return {}; n         } n     } n     vector<int> res; n     for (int i = 1, cnt = 0; i <= n; i++) { n         if (!good[i]) { n             cnt++; n             if (i == n || good[i + 1]) { n                 res.pb(cnt); n                 cnt = 0; n             } n         } n     } n     return res; n } n  n vector<int> solve2(int n) { n     if (!good[1] || !good[n]) { n         return {}; n     } n     vector<int> a = {0}; n     for (int i = 1, cnt = 0; i <= n; i++) { n         if (good[i]) { n             cnt++; n             if (i == n || !good[i + 1]) { n                 if (i == cnt) { n                     if (!(cnt & 1)) { n                         return {}; n                     } n                     else { n                         for (int j = 2; j <= i; j += 2) { n                             a.pb(j); n                         } n                     } n                 } n                 else if (i == n) { n                     if (!(cnt & 1)) { n                         return {}; n                     } n                     else { n                         for (int j = i - cnt + 1; j <= i; j += 2) { n                             a.pb(j); n                         } n                     } n                 } n                 else { n                     if (cnt & 1) { n                         return {}; n                     } n                     else { n                         for (int j = i - cnt + 1; j <= i; j += 2) { n                             a.pb(j); n                         } n                     } n                 } n                 cnt = 0; n             } n         } n     } n     return get(a); n } n  n vector<int> solve3(int n) { n     vector<int> kek; n     for (int i = 1; i <= n; i++) { n         if (!good[i]) { n             ban[i] = 1; n             kek.pb(i); n         } n     } n     for (int j = 1; j <= kek.back(); j++) { n         ban[j] = 1; n     } n     for (int j = 1; j <= n + 2 - kek.front() - 1; j++) { n         ban[j] = 1; n     } n     ban[n - kek.front() + 3] = 1; n     for (int i = 1; i <= n - 1; i++) { n         if (!good[i] && good[i + 1]) { n             ban[i + 2] = 1; n         } n     } n     for (int i = 0; i + 1 < kek.size(); i++) { n         ban[n + kek[i] - kek[i + 1] + 4] = 1; n     } n     for (int s = n - 1; s >= 2; s--) { n         if (!ban[s]) { n             vector<int> a = {0}; n             for (int i = 1, cnt = 0; i <= n; i++) { n                 if (good[i]) { n                     cnt++; n                     if (i == n) { n                         int l = i - cnt + 1; n                         int r = s; n                         if (l <= r) { n                             for (int j = l; j <= r; j += 2) { n                                 a.pb(j); n                             } n                             a.back() = r; n                         } n                         cnt = 0; n                     } n                     else if (!good[i + 1]) { n                         int l = i - cnt + 1; n                         int r = i + 1 - (n + 2 - s); n                         if (i == cnt) { n                             l = 2; n                         } n                         if (l <= r) { n                             for (int j = l; j <= r; j += 2) { n                                 a.pb(j); n                             } n                             a.back() = r; n                         } n                         cnt = 0; n                     } n                 } n             } n             return get(a); n         } n     } n     return {}; n } n  n vector<int> solve(int n) { n     if (n == 1) { n         if (good[1]) { n             return {}; n         } n         else { n             return {1}; n         } n     } n     if (solve0(n)) { n         return {}; n     } n     vector<int> ans = solve1(n); n     if (!ans.empty()) return ans; n     ans = solve2(n); n     if (!ans.empty()) return ans; n     ans = solve3(n); n     if (!ans.empty()) return ans; n     return {-1}; n } n  n int main() { n     ios_base::sync_with_stdio(0); cin.tie(0); n #ifdef LOCAL n     freopen( input.txt ,  r , stdin); n #endif n  n     string s; n     cin >> s; n     int n = s.size(); n     for (int i = 1; i <= n; i++) { n         good[i] = (s[i - 1] ==  _ ); n     } n     vector<int> ans = solve(n); n     if (!ans.empty() && ans.front() == -1) { n         cout <<  -1 n ; n     } n     else { n         cout << ans.size() <<   n ; n         for (int i : ans) { n             cout << i <<    ; n         } n         cout <<   n ; n     } n  n #ifdef LOCAL n     cerr <<   nTime elapsed:   << 1.0 * clock() / CLOCKS_PER_SEC <<   s. n ; n #endif n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dirx[8] = {0, 0, 1, -1, 1, 1, -1, -1}; n int diry[8] = {1, -1, 0, 0, 1, -1, 1, -1}; n string tostring(long long n) { n   if (!n) return  0 ; n   string ans =   ; n   while (n != 0) { n     ans += (n % 10) +  0 ; n     n /= 10; n   } n   reverse(ans.begin(), ans.end()); n   return ans; n } n double toDouble(string s) { n   double ans = 0; n   int i = 0, flag = 0, cnt = 0, ff = 1; n   while (i < s.length()) { n     if (s[i] ==  - ) { n       ff = -1; n       i++; n       continue; n     } n     if (s[i] ==  . ) { n       flag = 1; n       i++; n       continue; n     } n     ans *= 10; n     ans += s[i] -  0 ; n     if (flag) cnt++; n     i++; n   } n   ans *= ff; n   return ans / pow(10, cnt); n } n int ar[1005]; n int main() { n   int n, a, b; n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     scanf( %d %d , &a, &b); n     ar[a]++; n     ar[b]++; n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     ans += (ar[i] == 1); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string str; n   cin >> str; n   cout <<  Mike n ; n   int freq[26] = {0}; n   freq[str[0] -  a ]++; n   for (int i = 1; i < str.length(); i++) { n     int val = 0; n     for (int j = 0; j < str[i] -  a ; j++) { n       if (freq[j] > 0) { n         val = 1; n         break; n       } n     } n     freq[str[i] -  a ]++; n     if (val == 1) { n       cout <<  Ann n ; n     } else { n       cout <<  Mike n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[105][105]; n int main() { n   vector<int> v; n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) cin >> a[i][j]; n     v.push_back(i); n   } n   int cnt = 0; n   for (int i = 1; i <= n; i++) { n     int flag = 0; n     for (int j = 1; j <= n; j++) { n       if (a[i][j] == 1 || a[i][j] == 3 || a[j][i] == 2 || a[j][i] == 3) { n         flag = 1; n         v[i - 1] = 0; n       } n     } n     if (flag == 0) cnt++; n   } n   cout << cnt << endl; n   for (auto i = v.begin(); i != v.end(); i++) { n     if (*i != 0) cout << *i <<    ; n   } n   v.clear(); n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) f = -1; n   for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ; n   return x * f; n } n const int N = 500005, INF = 1e9; n const double DINF = 1e18; n struct Edge { n   int fr, to, nxt, cap; n   double cost; n } e[N << 1]; n int head[N], pre[N], q[N], En = 1, S, T, n; n double dis[N]; n bool vis[N]; n inline void add_edge(int u, int v, int f, double w) { n   ++En; n   e[En].fr = u, e[En].to = v, e[En].nxt = head[u], e[En].cap = f, n   e[En].cost = w; n   head[u] = En; n   ++En; n   e[En].fr = v, e[En].to = u, e[En].nxt = head[v], e[En].cap = 0, n   e[En].cost = -w; n   head[v] = En; n } n bool spfa() { n   for (int i = 0; i <= T; ++i) dis[i] = DINF, vis[i] = false, pre[i] = 0; n   int L = 1, R = 0; n   dis[S] = 0, q[++R] = S, vis[S] = true, pre[S] = 0; n   while (L <= R) { n     int u = q[L++]; n     vis[u] = false; n     for (int i = head[u]; i; i = e[i].nxt) { n       int v = e[i].to; n       if (dis[v] > dis[u] + e[i].cost && e[i].cap > 0) { n         dis[v] = dis[u] + e[i].cost; n         pre[v] = i; n         if (!vis[v]) q[++R] = v; n       } n     } n   } n   return dis[T] != DINF; n } n void mcf() { n   int Flow = 0; n   double Cost = 0; n   while (spfa()) { n     int now = INF; n     for (int i = T; i != S; i = e[pre[i]].fr) now = min(now, e[pre[i]].cap); n     for (int i = T; i != S; i = e[pre[i]].fr) n       e[pre[i]].cap -= now, e[pre[i] ^ 1].cap += now; n     Flow += now; n     Cost += 1.0 * now * dis[T]; n   } n   if (Flow >= n - 1) n     printf( %.10lf , Cost); n   else n     puts( -1 ); n } n struct Node { n   int x, y; n } A[N]; n int sqr(int x) { return x * x; } n double dist(const Node &A, const Node &B) { n   return sqrt(1.0 * (sqr(A.x - B.x) + sqr(A.y - B.y))); n } n int main() { n   n = read(); n   for (int i = 1; i <= n; ++i) A[i].x = read(), A[i].y = read(); n   S = 0, T = n + n + 1; n   for (int i = 1; i <= n; ++i) add_edge(S, i, 2, 0), add_edge(i + n, T, 1, 0); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) n       if (A[j].y > A[i].y) add_edge(j, i + n, 1, dist(A[i], A[j])); n   mcf(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n char s1[51], s2[51], op[50][5]; n int memo1[50][50][26], memo2[50][50][26], memo3[50][50]; n int check1(int l, int r, char c) { n   if (l == r) return s1[l] == c; n   int &ret = memo1[l][r][c -  a ]; n   if (ret == -1) { n     ret = 0; n     for (int i = l; i < r; ++i) n       for (int j = 0; j < n; ++j) n         if (op[j][0] == c && check1(l, i, op[j][3]) && n             check1(i + 1, r, op[j][4])) n           ret = 1; n   } n   return ret; n } n int check2(int l, int r, char c) { n   if (l == r) return s2[l] == c; n   int &ret = memo2[l][r][c -  a ]; n   if (ret == -1) { n     ret = 0; n     for (int i = l; i < r; ++i) n       for (int j = 0; j < n; ++j) n         if (op[j][0] == c && check2(l, i, op[j][3]) && n             check2(i + 1, r, op[j][4])) n           ret = 1; n   } n   return ret; n } n int solve(int pos1, int pos2) { n   if (pos1 == -1 && pos2 == -1) return 0; n   if (pos1 == -1 || pos2 == -1) return 51; n   int &ret = memo3[pos1][pos2]; n   if (ret == -1) { n     ret = 51; n     for (int i = 0; i <= pos1; ++i) n       for (int j = 0; j <= pos2; ++j) n         for (char c =  a ; c <=  z ; ++c) n           if (check1(i, pos1, c) && check2(j, pos2, c)) n             ret = min(ret, 1 + solve(i - 1, j - 1)); n   } n   return ret; n } n int main() { n   scanf( %s %s , s1, s2); n   int L1 = strlen(s1), L2 = strlen(s2); n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) scanf( %s , op[i]); n   memset(memo1, -1, sizeof memo1); n   memset(memo2, -1, sizeof memo2); n   memset(memo3, -1, sizeof memo3); n   int ans = solve(L1 - 1, L2 - 1); n   printf( %d n , ans == 51 ? -1 : ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Node { n   int a, b, c, d; n } temp; n queue<Node> q1, q2; n string s1[305][305], s2[305][305]; n int main() { n   int n, m; n   int ans = 0, m1 = 0, m2 = 0; n   int num1 = 0, num0 = 0; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       cin >> s1[i][j]; n       ans += 2 * s1[i][j].length(); n       if (i == 1 && j == m) ans -= s1[i][j].length(); n       if (i == n && j == 1) ans -= s1[i][j].length(); n     } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       cin >> s2[i][j]; n       ans += 2 * s2[i][j].length(); n       if (i == 1 && j == m) ans -= s2[i][j].length(); n       if (i == n && j == 1) ans -= s2[i][j].length(); n     } n   printf( %d n , ans); n   for (int i = 1; i < m; i++) { n     temp.a = 1; n     temp.b = m; n     for (int k = s1[1][i].size() - 1; k >= 0; k--) { n       printf( %d %d %d %d n , 1, i, 1, m); n       if (s1[1][i][k] ==  0 ) { n         temp.c = 1; n         temp.d = 1; n       } else { n         temp.c = n; n         temp.d = m; n       } n       q1.push(temp); n     } n   } n   for (int i = 2; i <= m; i++) { n     temp.a = n; n     temp.b = 1; n     for (int k = s1[n][i].size() - 1; k >= 0; k--) { n       printf( %d %d %d %d n , n, i, n, 1); n       if (s1[n][i][k] ==  0 ) { n         temp.c = 1; n         temp.d = 1; n       } else { n         temp.c = n; n         temp.d = m; n       } n       q2.push(temp); n     } n   } n   for (int i = s1[1][m].size() - 1; i >= 0; i--) { n     if (s1[1][m][i] ==  0 ) n       printf( %d %d %d %d n , 1, m, 1, 1); n     else n       printf( %d %d %d %d n , 1, m, n, m); n   } n   while (!q1.empty()) { n     temp = q1.front(); n     q1.pop(); n     printf( %d %d %d %d n , temp.a, temp.b, temp.c, temp.d); n   } n   for (int i = s1[n][1].size() - 1; i >= 0; i--) { n     if (s1[n][1][i] ==  0 ) n       printf( %d %d %d %d n , n, 1, 1, 1); n     else n       printf( %d %d %d %d n , n, 1, n, m); n   } n   while (!q2.empty()) { n     temp = q2.front(); n     q2.pop(); n     printf( %d %d %d %d n , temp.a, temp.b, temp.c, temp.d); n   } n   for (int i = 2; i < n; i++) n     for (int j = 1; j <= m; j++) n       for (int k = s1[i][j].size() - 1; k >= 0; k--) { n         if (s1[i][j][k] ==  0 ) { n           if (j != 1) n             printf( %d %d %d %d n%d %d %d %d n , i, j, 1, j, 1, j, 1, 1); n           else n             printf( %d %d %d %d n%d %d %d %d n , i, j, n, j, n, j, 1, 1); n         } else { n           if (j != m) n             printf( %d %d %d %d n%d %d %d %d n , i, j, n, j, n, j, n, m); n           else n             printf( %d %d %d %d n%d %d %d %d n , i, j, 1, j, 1, j, n, m); n         } n       } n   for (int i = 2; i < n; i++) n     for (int j = 1; j <= m; j++) { n       for (int k = s2[i][j].length() - 1; k >= 0; k--) { n         if (s2[i][j][k] ==  0 ) { n           if (j == 1) n             printf( %d %d %d %d n%d %d %d %d n , 1, 1, n, j, n, j, i, j); n           else n             printf( %d %d %d %d n%d %d %d %d n , 1, 1, 1, j, 1, j, i, j); n         } else { n           if (j == m) n             printf( %d %d %d %d n%d %d %d %d n , n, m, 1, j, 1, j, i, j); n           else n             printf( %d %d %d %d n%d %d %d %d n , n, m, n, j, n, j, i, j); n         } n       } n     } n   for (int i = 1; i < m; i++) { n     temp.a = 1; n     temp.b = m; n     temp.c = 1; n     temp.d = i; n     for (int j = s2[1][i].length() - 1; j >= 0; j--) { n       if (s2[1][i][j] ==  0 ) n         printf( %d %d %d %d n , 1, 1, 1, m); n       else n         printf( %d %d %d %d n , n, m, 1, m); n       q1.push(temp); n     } n   } n   for (int i = s2[1][m].length() - 1; i >= 0; i--) { n     if (s2[1][m][i] ==  0 ) n       printf( %d %d %d %d n , 1, 1, 1, m); n     else n       printf( %d %d %d %d n , n, m, 1, m); n   } n   for (int i = 2; i <= m; i++) { n     temp.a = n; n     temp.b = 1; n     temp.c = n; n     temp.d = i; n     for (int j = s2[n][i].length() - 1; j >= 0; j--) { n       if (s2[n][i][j] ==  0 ) n         printf( %d %d %d %d n , 1, 1, n, 1); n       else n         printf( %d %d %d %d n , n, m, n, 1); n       q2.push(temp); n     } n   } n   for (int i = s2[n][1].length() - 1; i >= 0; i--) { n     if (s2[n][1][i] ==  0 ) n       printf( %d %d %d %d n , 1, 1, n, 1); n     else n       printf( %d %d %d %d n , n, m, n, 1); n   } n   while (!q1.empty()) { n     temp = q1.front(); n     q1.pop(); n     printf( %d %d %d %d n , temp.a, temp.b, temp.c, temp.d); n   } n   while (!q2.empty()) { n     temp = q2.front(); n     q2.pop(); n     printf( %d %d %d %d n , temp.a, temp.b, temp.c, temp.d); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long is_query = -(1LL << 62); n struct Line { n   long long m, b; n   mutable function<const Line*()> succ; n   bool operator<(const Line& rhs) const { n     if (rhs.b != is_query) return m < rhs.m; n     const Line* s = succ(); n     if (!s) return 0; n     long long x = rhs.m; n     return b - s->b < (s->m - m) * x; n   } n }; n struct HullDynamic : public multiset<Line> { n   bool bad(iterator y) { n     auto z = next(y); n     if (y == begin()) { n       if (z == end()) return 0; n       return y->m == z->m && y->b <= z->b; n     } n     auto x = prev(y); n     if (z == end()) return y->m == x->m && y->b <= x->b; n     return (x->b - y->b) * (z->m - y->m) >= (y->b - z->b) * (y->m - x->m); n   } n   void insert_line(long long m, long long b) { n     auto y = insert({m, b}); n     y->succ = [=] { return next(y) == end() ? 0 : &*next(y); }; n     if (bad(y)) { n       erase(y); n       return; n     } n     while (next(y) != end() && bad(next(y))) erase(next(y)); n     while (y != begin() && bad(prev(y))) erase(prev(y)); n   } n   long long eval(long long x) { n     auto l = *lower_bound((Line){x, is_query}); n     return l.m * x + l.b; n   } n } convex; n const int N = 2e5 + 5; n long long dp[N], arr[N]; n int n; n int main() { n   long long sum = 0, ans; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %lld , &arr[i]); n     dp[i] = dp[i - 1] + arr[i]; n     sum += arr[i] * i; n   } n   ans = sum; n   convex.insert_line(n, -dp[n]); n   for (int i = n - 1; i >= 1; i--) { n     long long best = 0; n     long long e = dp[i] - i * arr[i] + sum; n     ans = max(ans, convex.eval(arr[i]) + e); n     convex.insert_line(i, -dp[i]); n   } n   convex.clear(); n   convex.insert_line(1, 0); n   for (int i = 2; i <= n; i++) { n     long long e = sum + dp[i - 1] - i * arr[i]; n     ans = max(ans, convex.eval(arr[i]) + e); n     convex.insert_line(i, -dp[i - 1]); n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct mat { n   double a[3][3]; n   mat() { n     for (int i = (int)(0); i <= (int)(2); ++i) n       for (int j = (int)(0); j <= (int)(2); ++j) a[i][j] = 0; n   } n   mat operator*(const mat &b) const { n     mat c; n     for (int i = (int)(0); i <= (int)(2); ++i) n       for (int j = (int)(0); j <= (int)(2); ++j) n         for (int k = (int)(0); k <= (int)(2); ++k) n           c.a[i][j] += a[i][k] * b.a[k][j]; n     return c; n   } n }; n struct node { n   int id; n   long long las; n   mat pre; n }; n vector<node> S; n mat bas[100005], f[40], org; n pair<double, double> p[100005]; n int n; n long long m; n double b; n int main() { n   scanf( %d%lld , &n, &m); n   for (int i = (int)(1); i <= (int)(n); ++i) { n     double x, y, v; n     scanf( %lf%lf%lf , &x, &y, &v); n     b = max(b, y * v); n     p[i] = pair<double, double>(x * v, v); n   } n   sort(p + 1, p + n + 1, greater<pair<double, double> >()); n   org.a[2][0] = 1; n   for (int i = (int)(1); i <= (int)(n); ++i) { n     bas[i].a[1][1] = 1; n     bas[i].a[2][2] = 1; n     bas[i].a[0][0] = 1 - p[i].second; n     bas[i].a[0][1] = p[i].second; n     bas[i].a[0][2] = p[i].first; n     bas[i].a[1][2] = b; n   } n   S.push_back((node){1, m, org}); n   for (int i = (int)(2); i <= (int)(n); ++i) { n     for (;;) n       if ((bas[i] * S.back().pre).a[0][0] > n           (bas[S.back().id] * S.back().pre).a[0][0]) n         S.pop_back(); n       else n         break; n     if (!S.back().las) continue; n     node tmp = S.back(); n     f[0] = bas[tmp.id]; n     for (int j = (int)(1); j <= (int)(35); ++j) f[j] = f[j - 1] * f[j - 1]; n     for (int j = (int)(35); j >= (int)(0); --j) n       if (tmp.las - (1ll << j) >= 1) n         if ((bas[i] * f[j] * tmp.pre).a[0][0] <= n             (bas[tmp.id] * f[j] * tmp.pre).a[0][0]) { n           tmp.pre = f[j] * tmp.pre; n           tmp.las -= (1ll << j); n         } n     tmp.pre = f[0] * tmp.pre; n     --tmp.las; n     if (tmp.las) tmp.id = i; n     S.push_back(tmp); n   } n   int id = S.back().id; n   long long las = S.back().las; n   mat ans = S.back().pre, x = bas[id]; n   for (; las; las /= 2, x = x * x) n     if (las & 1) ans = x * ans; n   printf( %.15lf n , ans.a[0][0]); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 110, MOD = 1e9 + 7; n long long dp[MAXN][2]; n int main() { n   ios_base::sync_with_stdio(NULL); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int n, k, d; n   cin >> n >> k >> d; n   dp[0][0] = 1; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= min(k, i); j++) { n       if (j >= d) { n         dp[i][1] += (dp[i - j][0] + dp[i - j][1]); n         dp[i][1] %= MOD; n       } else { n         dp[i][0] += dp[i - j][0]; n         dp[i][1] += dp[i - j][1]; n         dp[i][1] %= MOD; n         dp[i][0] %= MOD; n       } n     } n   } n   cout << dp[n][1] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long me[10000][1001]; n long long n, m; n long long d[10000]; n long long g, r; n int main() { n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   cin >> n >> m; n   for (long long i = 0; i < m; i++) cin >> d[i]; n   sort(d, d + m); n   cin >> g >> r; n   queue<pair<long long, long long> > mq[2]; n   mq[1].push(pair<long long, long long>(0, g)); n   me[0][g] = 1; n   int ini = 1; n   while (!mq[0].empty() || !mq[1].empty()) { n     while (!mq[ini % 2].empty()) { n       pair<long long, long long> t = mq[ini % 2].front(); n       mq[ini % 2].pop(); n       long long i = t.first; n       long long j = t.second; n       long long np = me[i][j]; n       if (np == ini) { n         if (j == 0) np++, j = g; n         if (i && d[i] - d[i - 1] <= j && n             (me[i - 1][j - (d[i] - d[i - 1])] == 0 || n              me[i - 1][j - (d[i] - d[i - 1])] > np)) { n           me[i - 1][j - (d[i] - d[i - 1])] = np; n           mq[np % 2].push( n               pair<long long, long long>(i - 1, j - (d[i] - d[i - 1]))); n         } n         if (i < m - 1 && d[i + 1] - d[i] <= j && n             (me[i + 1][j - (d[i + 1] - d[i])] == 0 || n              me[i + 1][j - (d[i + 1] - d[i])] > np)) { n           me[i + 1][j - (d[i + 1] - d[i])] = np; n           mq[np % 2].push( n               pair<long long, long long>(i + 1, j - (d[i + 1] - d[i]))); n         } n       } n     } n     ini++; n   } n   long long res = -1; n   for (int i = 0; i <= g; i++) { n     if (me[m - 1][i]) { n       long long can = (me[m - 1][i] - 1) * (g + r) + g - i; n       if (res == -1 || can < res) res = can; n     } n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e3 + 1; n int accept() { n   int b[N] = {0}; n   int d[N] = {0}; n   int n; n   cin >> n; n   int mx, check; n   for (int i = 0; i < n; i++) cin >> b[i]; n   sort(b, b + n); n   for (int i = 1; i < n; i++) { n     if (b[i] == b[i - 1]) { n       cout <<  YES  n            <<   n ; n       return 0; n     } n   } n   cout <<  NO  n        <<   n ; n   return 0; n } n int main() { n   int t = 1; n   cin >> t; n   while (t--) { n     accept(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mx = 100010; n int arr[mx]; n int main() { n   string x; n   int n, c = -1, temp = 0; n   queue<int> stek; n   map<int, int> visit; n   cin >> n >> x; n   for (int i = 0; i < n - 1; i++) { n     if ((x[i] ==  o  and x[i + 1] ==  g ) || n         (x[i] ==  g  and x[i + 1] ==  o )) { n       temp++; n       if (c == -1 and x[i] ==  g ) { n         temp = 0; n         continue; n       } n       if (c == -1) c = i; n     } else if (c != -1) { n       if (x[i] ==  g  and temp == 1) { n         temp = 0; n         c = -1; n         continue; n       } else if (x[i] ==  g  and temp > 1) { n         temp--; n       } n       stek.push(c); n       visit[c] = temp; n       temp = 0; n       c = -1; n     } n   } n   if (c != -1) { n     if (x[n - 1] ==  g  and temp == 1) { n     } else { n       if (x[n - 1] ==  g  and temp > 1) { n         temp--; n       } n       stek.push(c); n       visit[c] = temp; n       temp = 0; n       c = -1; n     } n   } n   for (int i = 0; i < n; i++) { n     if (stek.front() == i) { n       printf( *** ); n       i += visit[stek.front()]; n       stek.pop(); n     } else { n       printf( %c , x[i]); n     } n   } n   printf(  n ); n } n


#include <bits/stdc++.h> n const long long mod = 1e9 + 7; n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n long long n, m; n vector<long long> a, b, v, pat; n long long cal() { n   v.clear(); n   for (long long i = 1; i < m; i++) v.push_back(a[i]); n   v.push_back(1e18); n   for (long long j = 1; j < n; j++) v.push_back(b[j]); n   long long sz = v.size(); n   long long ans = 0; n   pat.clear(); n   pat.resize(sz, 0); n   for (long long i = 1; i < sz; i++) { n     long long j = pat[i - 1]; n     while (j > 0 && v[j] != v[i]) j = pat[j - 1]; n     if (v[j] == v[i]) j++; n     pat[i] = j; n     if (j == m - 1) ans++; n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n >> m; n   long long pre, cur; n   b.clear(); n   b.resize(n); n   for (long long i = 0; i < n; i++) { n     cin >> b[i]; n     cur = b[i]; n     if (i) b[i] -= pre; n     pre = cur; n   } n   a.clear(); n   a.resize(m); n   for (long long i = 0; i < m; i++) { n     cin >> a[i]; n     cur = a[i]; n     if (i) a[i] -= pre; n     pre = cur; n   } n   if (m == 1) { n     cout << n <<   n ; n     return 0; n   } n   cout << cal() <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int num, skill; n   cin >> num >> skill; n   int A[num]; n   for (int i = 0; i < num; i++) cin >> A[i]; n   int k = 0; n   while (A[k] <= skill && k < num) k++; n   int soluve; n   soluve = k; n   int stay; n   if (k == num) { n     cout << num << endl; n     return 0; n   } else { n     int z = num - 1; n     while (A[z] <= skill && z >= 1) z--; n     stay = num - z - 1; n     soluve += stay; n   } n   cout << soluve << endl; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( inline ) n int rd() { n   register int k = 0; n   char c = getchar(); n   while (c >  9  || c <  0 ) c = getchar(); n   while (c >=  0  && c <=  9 ) k = k * 10 + c - 48, c = getchar(); n   return k; n } n const int N = 100001; n struct Q { n   int o, t, l, r; n } q[N]; n struct C { n   int x, v; n } c[N]; n int n, m, p, l = 1, r, qn, cn, a[N], bl[N], ans[N], T, b[N << 1], B, v[N << 1], n              sv[N], s; n bool cmp(register const Q& x, register const Q& y) { n   return bl[x.l] != bl[y.l] ? x.l < y.l n                             : (bl[x.r] == bl[y.r] ? x.t < y.t : x.r < y.r); n } n void Ins(register int p) { --sv[v[p]], ++sv[++v[p]]; } n void Del(register int p) { --sv[v[p]], ++sv[--v[p]]; } n void Set(register int t, register int i) { n   if (q[i].l <= c[t].x && c[t].x <= q[i].r) Del(a[c[t].x]), Ins(c[t].v); n   std::swap(a[c[t].x], c[t].v); n } n int main() { n   B = n = rd(), m = rd(), p = pow(n, 0.66); n   for (register int i = 1; i <= n; ++i) b[i] = a[i] = rd(), bl[i] = i / p; n   for (register int i = 1; i <= m; ++i) { n     if (rd() == 1) n       ++qn, q[qn] = {qn, cn, rd(), rd()}; n     else n       c[++cn] = {rd(), b[++B] = rd()}; n   } n   std::sort(b + 1, b + B + 1), B = std::unique(b + 1, b + B + 1) - b - 1, n                                std::sort(q + 1, q + qn + 1, cmp); n   for (register int i = 1; i <= n; ++i) n     a[i] = std::lower_bound(b + 1, b + B + 1, a[i]) - b; n   for (register int i = 1; i <= cn; ++i) n     c[i].v = std::lower_bound(b + 1, b + B + 1, c[i].v) - b; n   for (register int i = 1; i <= qn; ++i) { n     while (l > q[i].l) Ins(a[--l]); n     while (r < q[i].r) Ins(a[++r]); n     while (l < q[i].l) Del(a[l++]); n     while (r > q[i].r) Del(a[r--]); n     while (T < q[i].t) Set(++T, i); n     while (T > q[i].t) Set(T--, i); n     for (s = 1; sv[s] > 0; ++s) n       ; n     ans[q[i].o] = s; n   } n   for (register int i = 1; i <= qn; ++i) printf( %d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma optimize( -Ofast ) n const int mod = 998244353; n struct num { n   int x; n   num(int x_ = 0) { x = x_; } n } G, _1[2222222], X[2222222], rot[2222222], inv[2222222]; n inline bool operator<(const num x, const num y) { return x.x > y.x; } n inline num operator+(const num x, const num y) { n   int z = x.x + y.x; n   return z < mod ? num(z) : num(z - mod); n } n inline num operator-(const num x, const num y) { n   int z = x.x - y.x; n   return z >= 0 ? num(z) : num(z + mod); n } n inline num operator*(const num x, const num y) { n   return num((long long)x.x * y.x % mod); n } n inline num operator*(const int x, const num y) { n   return num((long long)x * y.x % mod); n } n inline num operator^(num x, int y) { n   num z = num(1); n   while (y) { n     if (y & 1) { n       z = z * x; n     } n     x = x * x; n     y >>= 1; n   } n   return z; n } n void _(int n) { n   inv[1] = num(1); n   for (int i = 2; i <= n; i++) { n     inv[i] = (mod - mod / i) * inv[mod % i]; n   } n   for (int i = 2; i <= n; i <<= 1) { n     rot[i] = G ^ ((mod - 1) / i); n   } n } n void rader(num x[], int n) { n   int i, j = 0, k; n   for (register int i = 0; i != n; i++) { n     if (i > j) { n       swap(x[i], x[j]); n     } n     k = n >> 1; n     while ((j ^= k) < k) { n       k >>= 1; n     } n   } n } n void NTT(num x[], int n, int o) { n   int k; n   num r, u, v, w; n   rader(x, n); n   for (int l = 2; l <= n; l <<= 1) { n     k = l >> 1; n     r = rot[l]; n     for (int i = 0; i < n; i += l) { n       w = num(1); n       for (register int j = i; j < i + k; j++) { n         u = x[j]; n         v = x[j + k] * w; n         x[j] = u + v; n         x[j + k] = u - v; n         w = w * r; n       } n     } n   } n   if (o == -1) { n     for (register int i = 0; i < n; i++) { n       x[i] = x[i] * inv[n]; n     } n     for (register int i = 1; i < (n >> 1); i++) { n       swap(x[i], x[n - i]); n     } n   } n } n int main() { n   int n, k, z[11], oo[11] = {0}; n   G = num(3); n   scanf( %d%d , &n, &k); n   n /= 2; n   for (int i = 1; i <= k; i++) { n     scanf( %d , &z[i]); n     oo[z[i]] = 1; n   } n   for (int i = 0; i <= 9; i++) { n     if (oo[i]) { n       _1[i] = num(1); n     } n   } n   int xxx = n; n   n *= 10; n   int S = 1; n   while (S <= n) { n     S <<= 1; n   } n   S <<= 1; n   _(S); n   X[0] = num(1); n   NTT(_1, S, 1); n   NTT(X, S, 1); n   while (xxx) { n     if (xxx & 1) { n       for (register int i = 0; i < S; i++) { n         X[i] = X[i] * _1[i]; n       } n     } n     for (register int i = 0; i < S; i++) { n       _1[i] = _1[i] * _1[i]; n     } n     xxx >>= 1; n   } n   NTT(X, S, -1); n   num ans = num(0); n   for (int i = 0; i <= S; i++) { n     ans = ans + (X[i] * X[i]); n   } n   printf( %d , ans.x); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 100010; n vector<int> a[MAX], ans; n int x, y, n; n bool v[MAX], d[MAX], f[MAX], l[MAX], odd[MAX], even[MAX]; n void DFS(int start) { n   v[start] = true; n   if (d[start] && odd[start]) { n     f[start] = (1 - f[start]); n   } n   if (!d[start] && even[start]) { n     f[start] = (1 - f[start]); n   } n   if (f[start] != l[start]) { n     ans.push_back(start); n     if (d[start]) { n       odd[start] = (1 - odd[start]); n     } else { n       even[start] = (1 - even[start]); n     } n   } n   int current; n   for (int i = 0; i < a[start].size(); i++) { n     current = a[start][i]; n     if (!v[current]) { n       d[current] = (1 - d[start]); n       odd[current] = odd[start]; n       even[current] = even[start]; n       DFS(current); n     } n   } n } n int main() { n   cin >> n; n   for (int i = 1; i < n; i++) { n     cin >> x >> y; n     a[x].push_back(y); n     a[y].push_back(x); n   } n   for (int i = 1; i <= n; i++) { n     cin >> f[i]; n   } n   for (int i = 1; i <= n; i++) { n     cin >> l[i]; n   } n   DFS(1); n   cout << ans.size() <<   n ; n   for (int i = 0; i < ans.size(); i++) { n     cout << ans[i] <<   n ; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[3]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> a[0] >> a[1] >> a[2]; n   sort(a, a + 3); n   if (a[0] + a[1] > a[2]) { n     cout << 0 << endl; n     return 0; n   } n   cout << a[2] - a[1] - a[0] + 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<int> d; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t, n, a, k = 0; n   cin >> t >> n; n   int x[200] = {}; n   for (int i = 1; i <= t; ++i) { n     cin >> a; n     if (x[a] >= 1) n       continue; n     else { n       x[a] += 1; n       d.insert(i); n     } n   } n   if (d.size() < n) n     cout <<  NO n ; n   else { n     cout <<  YES n ; n     for (auto i : d) { n       k += 1; n       cout << i <<    ; n       if (k == n) break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline double sq(double a) { return a * a; } n int a, b; n int n; n complex<double> p1[1024], p2[1024]; n double d[1024][1024]; n int vis[1024]; n double distanceSP(const complex<double>& s0, const complex<double>& s1, n                   const complex<double>& p) { n   if (s0.real() <= p.real() && p.real() <= s1.real()) { n     return sq(p.imag() - s0.imag()); n   } n   if (s0.imag() <= p.imag() && p.imag() <= s1.imag()) { n     return sq(p.real() - s0.real()); n   } n   return min(norm(s0 - p), norm(s1 - p)); n } n double distanceSS(const complex<double>& s0, const complex<double>& s1, n                   const complex<double>& t0, const complex<double>& t1) { n   return min(min(distanceSP(s0, s1, t0), distanceSP(s0, s1, t1)), n              min(distanceSP(t0, t1, s0), distanceSP(t0, t1, s1))); n } n double solve() { n   for (int i = 0; i < (int)(n); i++) n     for (int j = 0; j < (int)(i); j++) { n       d[i][j] = d[j][i] = distanceSS(p1[i], p2[i], p1[j], p2[j]); n     } n   queue<pair<double, int> > q; n   q.push(make_pair(0.0, 0)); n   vis[0] = 1; n   double ans = -1; n   while (!q.empty()) { n     const pair<double, int> vv(q.front()); n     q.pop(); n     const double t = -vv.first; n     const int at = vv.second; n     if (ans >= 0 && t >= ans) break; n     for (int i = 0; i < (int)(n); i++) n       if (vis[i] == 0 && d[at][i] <= a * a) { n         if (i == 1) { n           const double nt = t + sqrt(d[at][i]); n           if (ans == -1 || ans > nt) ans = nt; n         } else { n           vis[i] = 1; n           q.push(make_pair(-t - a - b, i)); n         } n       } n   } n   return ans; n } n int main() { n   scanf( %d%d , &a, &b); n   for (int i = 0; i < (int)(2); i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     p1[i] = p2[i] = complex<double>(x, y); n   } n   scanf( %d , &n); n   for (int i = 0; i < (int)(n); i++) { n     int x1, y1, x2, y2; n     scanf( %d%d%d%d , &x1, &y1, &x2, &y2); n     if (x1 > x2) swap(x1, x2); n     if (y1 > y2) swap(y1, y2); n     p1[i + 2] = complex<double>(x1, y1); n     p2[i + 2] = complex<double>(x2, y2); n   } n   n += 2; n   const double ans = solve(); n   if (ans < 0) n     printf( %d n , -1); n   else n     printf( %.9f n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using pi = pair<int, int>; n using pll = pair<ll, ll>; n int n, k; n vector<int> x; n bool disjoint(int l1, int r1, int l2, int r2) { return r1 < l2 || r2 < l1; } n int main() { n   ios_base::sync_with_stdio(false); n   cout << setprecision(12); n   cin.tie(nullptr); n   cin >> n >> k; n   x.resize(k); n   for (int i = 0; i < int(k); i++) cin >> x[i], x[i]--; n   vector<int> fst(n, -1), lst(n, k); n   for (int i = 0; i < int(k); i++) lst[x[i]] = i; n   for (int i = k - 1; i >= 0; i--) fst[x[i]] = i; n   ll ans = 0; n   for (int i = 0; i < int(n); i++) n     if (fst[i] == -1) ans++; n   for (int i = 0; i < int(n - 1); i++) { n     if (fst[i] == -1 || fst[i + 1] == -1) { n       ans += 2; n       continue; n     } n     if (lst[i] < fst[i + 1]) ans++; n     if (lst[i + 1] < fst[i]) ans++; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int mx = 110, Mod = 1e6 + 3; n int C, W, H; n struct Matrix { n   int val[mx][mx]; n   int n; n   Matrix(int _n = mx, int _base = 0) { n     n = _n; n     for (int i = 0; i < n; i++) n       for (int j = 0; j < n; j++) val[i][j] = (i == j ? _base : 0); n   } n   int* operator[](int x) { return val[x]; } n }; n Matrix operator*(Matrix A, Matrix B) { n   Matrix res(A.n); n   for (int i = 0; i < res.n; i++) n     for (int j = 0; j < res.n; j++) n       for (int k = 0; k < res.n; k++) n         res[i][k] = (0LL + res[i][k] + 1LL * A[i][j] * B[j][k]) % Mod; n   return res; n } n Matrix operator^(Matrix A, long long int B) { n   Matrix res(A.n, 1); n   while (B) { n     if (B & 1) res = res * A; n     A = A * A; n     B >>= 1; n   } n   return res; n } n int main() { n   scanf( %d%d%d , &C, &W, &H); n   Matrix res(W + 1); n   for (int i = 0; i <= W; i++) res[0][i] = 1, res[i + 1][i] = H; n   res = res ^ C; n   int ans = 0; n   for (int i = 0; i <= W; i++) ans = (0LL + ans + res[i][0]) % Mod; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e3 + 123; n const int K = (int)500; n const int maxn = (int)2e9; n const int mod = (int)1e9 + 7; n long long n; n vector<long long> v; n void solve() { n   cin >> n; n   long long cnt = 1; n   for (int i = 0; i <= 62; ++i) { n     if (i) { n       cnt *= 2ll; n     } n     long long cnt2 = cnt - 1; n     long long ok = 0; n     long long l = 1, r = 1ll * 1e18; n     while (l <= r) { n       long long m = l + (r - l) / 2; n       if (n % m) { n         if ((m - 1) / 2 + cnt2 < n / m) n           l = m + 1; n         else n           r = m - 1; n         continue; n       } n       if ((m - 1) / 2 + cnt2 == n / m) { n         if (m % 2) { n           ok = m + m * cnt2; n         } n         break; n       } n       if ((m - 1) / 2 + cnt2 < n / m) { n         l = m + 1; n       } else { n         r = m - 1; n       } n     } n     if (ok) { n       v.push_back(ok); n     } n   } n   if (!(int)v.size()) { n     cout << -1; n     return; n   } n   sort(v.begin(), v.end()); n   v.resize(unique(v.begin(), v.end()) - v.begin()); n   for (long long i : v) { n     cout << i <<   n ; n   } n } n int main() { n   ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int q = 1; n   while (q--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void r1(T &x) { n   x = 0; n   char c(getchar()); n   int f(1); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = -1; n   for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); n   x *= f; n } n const int maxn = 100000 + 5; n const int maxm = maxn << 1; n typedef int room[maxn]; n int n, m, d; n int dis[maxn], f[maxn][2]; n int head[maxn], cnt; n struct Edge { n   int to, next; n } edg[maxn << 1]; n void add(int u, int v) { edg[++cnt] = (Edge){v, head[u]}, head[u] = cnt; } n int vis[maxn]; n void dfs(int p, int fa) { n   if (vis[p]) f[p][0] = 0; n   for (int i = head[p]; i; i = edg[i].next) { n     int to = edg[i].to; n     if (to == fa) continue; n     dfs(to, p); n     if (f[to][0] + 1 > f[p][0]) { n       f[p][1] = f[p][0], f[p][0] = f[to][0] + 1; n     } else n       f[p][1] = max(f[p][1], f[to][0] + 1); n   } n } n void dfs1(int p, int fa) { n   for (int i = head[p]; i; i = edg[i].next) { n     int to = edg[i].to; n     if (to == fa) continue; n     if (f[p][0] == f[to][0] + 1) { n       dis[to] = max(f[p][1] + 1, dis[p] + 1); n     } else n       dis[to] = max(dis[p] + 1, f[p][0] + 1); n     dfs1(to, p); n   } n } n signed main() { n   int i, j; n   memset(f, -0x3f, sizeof(f)), memset(dis, -0x3f, sizeof(dis)); n   r1(n), r1(m), r1(d); n   for (i = 1; i <= m; ++i) { n     int x; n     r1(x); n     vis[x] = 1; n   } n   for (i = 1; i < n; ++i) { n     int u, v; n     r1(u), r1(v); n     add(u, v), add(v, u); n   } n   dfs(1, 0), dfs1(1, 0); n   int ans((bool)(f[1][1] <= d && f[1][0] <= d)); n   for (i = 2; i <= n; ++i) n     if (dis[i] <= d && f[i][0] <= d) { n       ++ans; n     } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 0xFFFFFFFFFFFFFFFL; n clock_t time_p = clock(); n void time() { n   time_p = clock() - time_p; n   cerr <<  Time Taken :   << (float)(time_p) / CLOCKS_PER_SEC <<   n ; n } n long long mul_mod(long long a, long long b, long long m) { n   long long y = n       (long long)((long double)a * (long double)b / m + (long double)1 / 2); n   y = y * m; n   long long x = a * b; n   long long r = x - y; n   if (r < 0) { n     r = r + m; n     y = y - 1; n   } n   return r; n } n long long pot(long long a, long long b, long long c) { n   if (b == 0) return 1; n   if (b == 1) return a % c; n   long long resp = pot(a, b >> 1, c); n   resp = mul_mod(resp, resp, c); n   if (b & 1) resp = mul_mod(resp, a, c); n   return resp; n } n bool isPrime(long long n) { n   long long d = n - 1; n   long long s = 0; n   if (n <= 3 || n == 5) return true; n   if (!(n & 1)) return false; n   while (!(d & 1)) { n     s++; n     d >>= 1; n   } n   for (long long i = 0; i < 32; i++) { n     long long a = rand(); n     a <<= 32; n     a += rand(); n     a %= (n - 3); n     a += 2; n     long long x = pot(a, d, n); n     if (x == 1 || x == n - 1) continue; n     for (long long j = 1; j <= s - 1; j++) { n       x = mul_mod(x, x, n); n       if (x == 1) return false; n       if (x == n - 1) break; n     } n     if (x != n - 1) return false; n   } n   return true; n } n pair<long long, long long> breaker(long long n) { n   if (isPrime(n)) return {n, 0}; n   for (long long i = 2; i < n; i++) { n     if (isPrime(i) && isPrime(n - i)) return {i, n - i}; n   } n } n int main(void) { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long n; n   cin >> n; n   if (isPrime(n)) { n     cout << 1 <<   n  << n <<   n ; n     return 0; n   } n   if (isPrime(n - 2)) { n     cout << 2 <<   n ; n     cout << 2 <<     << n - 2 <<   n ; n     return 0; n   } n   if (isPrime(n - 3)) { n     cout << 2 <<   n ; n     cout << 3 <<     << n - 3 <<   n ; n     return 0; n   } n   if (isPrime(n - 4)) { n     cout << 3 <<   n ; n     cout << 2 <<     << 2 <<     << n - 4 <<   n ; n     return 0; n   } n   long long part1 = 0, part2 = 0, part3 = 0; n   for (long long i = n - 5; i >= 0; i--) { n     if (isPrime(i)) { n       part1 = i; n       pair<long long, long long> p = breaker(n - i); n       part2 = p.first; n       part3 = p.second; n       break; n     } n   } n   long long ct = 0; n   vector<long long> list; n   if (part1 != 0) { n     ct++; n     list.push_back(part1); n   } n   if (part2 != 0) { n     ct++; n     list.push_back(part2); n   } n   if (part3 != 0) { n     ct++; n     list.push_back(part3); n   } n   cout << ct <<   n ; n   for (long long i = 0; i < (long long)list.size(); i++) cout << list[i] <<    ; n   cout <<   n ; n   time(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char a[1000]; n   int i = 0, lower = 0, upper = 0; n   cin >> a; n   int len = strlen(a); n   while (a[i] != 0) { n     if (a[i] >=  a  && a[i] <=  z ) { n       lower++; n       i++; n     } else if (a[i] >=  A  && a[i] <=  Z ) { n       upper++; n       i++; n     } else n       i++; n   } n   if (upper > lower) { n     for (i = 0; i < len; i++) { n       if (a[i] >= 97 && a[i] <= 122) { n         a[i] = a[i] - 32; n       } n     } n     cout << a; n   } else { n     for (i = 0; i < len; i++) { n       if (a[i] >= 65 && a[i] <= 92) { n         a[i] = a[i] + 32; n       } n     } n     cout << a; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   vector<int> a(n); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   vector<int> t(n); n   for (int i = 0; i < n; i++) { n     cin >> t[i]; n   } n   a.push_back((int)1.01e9); n   t.push_back(0); n   ++n; n   vector<int> order(n); n   iota(order.begin(), order.end(), 0); n   sort(order.begin(), order.end(), [&](int i, int j) { return a[i] < a[j]; }); n   unsigned long long ans = 0; n   int last = 0; n   multiset<int> s; n   long long sum = 0; n   for (int i : order) { n     while (a[i] > last && !s.empty()) { n       ++last; n       auto it = prev(s.end()); n       sum -= *it; n       s.erase(it); n       ans += sum; n     } n     last = a[i]; n     s.insert(t[i]); n     sum += t[i]; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9 + 10; n const long long INF = 4e18 + 10; n const int maxn = 1 * 1e5 + 5; n const int maxe = maxn; n int a[maxn]; n int p[maxn]; n int n, m; n bool check(long long t) { n   for (int i = 1; i <= n; ++i) p[i] = a[i]; n   int j = n; n   for (int i = 0; i < m; ++i) { n     while (j > 0 && p[j] == 0) --j; n     if (j == 0) return true; n     long long res = t - j; n     if (res <= 0) return false; n     while (j > 0 && res >= p[j]) res -= p[j--]; n     if (j > 0) p[j] -= res; n   } n   if (j == 0) return true; n   return false; n } n int MAIN() { n   scanf( %d%d , &n, &m); n   long long lb = -1, rb = 0; n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n     rb += i + a[i]; n   } n   while (rb - lb > 1) { n     long long mid = lb + (rb - lb) / 2; n     if (check(mid)) n       rb = mid; n     else n       lb = mid; n   } n   printf( %I64d n , rb); n   return 0; n } n int main() { n   ios_base::sync_with_stdio(false); n   cout << fixed << setprecision(16); n   int ret = MAIN(); n   return ret; n } n


#include <bits/stdc++.h> n using namespace std; n char a[200][200]; n long long check(long long x, long long y, long long n) { n   if (x >= 0 and x < n and y >= 0 and y < n and a[x][y] ==  . ) n     return 1; n   else n     return 0; n } n void solve() { n   long long n; n   cin >> n; n   map<long long, long long> m; n   for (long long i = 0; i < n; i++) { n     long long t; n     cin >> t; n     m[t]++; n   } n   auto i = m.rbegin(); n   long long ans = 0; n   long long hold = 0; n   for (; i != m.rend(); i++) { n     long long k = min(hold, i->second); n     ans += k; n     hold = hold - k + i->second; n   } n   cout << ans << endl; n   return; n } n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int v[361 * 2], acum[360 * 2]; n int main() { n   int n, tmp; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> v[i]; n     v[i + n] = v[i]; n   } n   int ans = (1 << 20); n   for (int i = 0; i < n; i++) { n     for (int j = i; j < i + n; j++) { n       int acum1 = 0, acum2 = 0; n       for (int k = i; k < i + n; k++) { n         if (k < j) n           acum1 += v[k]; n         else n           acum2 += v[k]; n       } n       ans = min(ans, abs(acum1 - acum2)); n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<int, pair<int, int> > > g[300043]; n int main() { n   int n, m, k; n   scanf( %d %d %d , &n, &m, &k); n   for (int i = 0; i < m; i++) { n     int x, y, w; n     scanf( %d %d %d , &x, &y, &w); n     --x; n     --y; n     g[x].push_back(make_pair(y, make_pair(w, i))); n     g[y].push_back(make_pair(x, make_pair(w, i))); n   } n   set<pair<long long, int> > q; n   vector<long long> d(n, (long long)(1e18)); n   d[0] = 0; n   q.insert(make_pair(0, 0)); n   vector<int> last(n, -1); n   int cnt = 0; n   vector<int> ans; n   while (!q.empty() && cnt < k) { n     set<pair<long long, int> >::iterator it = q.begin(); n     q.erase(q.begin()); n     pair<int, int> top = *it; n     int k = top.second; n     if (last[k] != -1) { n       cnt++; n       ans.push_back(last[k]); n     } n     vector<pair<int, pair<int, int> > >::iterator ii; n     for (ii = g[k].begin(); ii != g[k].end(); ii++) { n       pair<int, pair<int, int> > y = *ii; n       int to = y.first; n       int w = y.second.first; n       int idx = y.second.second; n       if (d[to] > d[k] + w) { n         q.erase(make_pair(d[to], to)); n         d[to] = d[k] + w; n         last[to] = idx; n         q.insert(make_pair(d[to], to)); n       } n     } n   } n   printf( %d n , ans.size()); n   vector<int>::iterator x; n   for (x = ans.begin(); x != ans.end(); x++) printf( %d  , *x + 1); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 41; n const int mod = 1e9 + 7; n const long long INF = 1e18; n const int inf = 2e9; n vector<int> g[N]; n long long res; n int cnt[2]; n int a[N]; n int sz[N]; n bool used[N]; n int cur_sz; n long long cur; n void pre(int v = 1, int p = -1) { n   sz[v] = 1; n   for (int to : g[v]) n     if (to != p && !used[to]) { n       pre(to, v); n       sz[v] += sz[to]; n     } n } n int f(int v, int p = -1) { n   for (int to : g[v]) n     if (!used[to] && to != p && sz[to] * 2 > cur_sz) { n       return f(to, v); n     } n   return v; n } n bool kth(int val, int bit) { n   if (val & (1 << bit)) n     return true; n   else n     return false; n } n void addcur(int v, int p, int bit, bool pref = 0) { n   pref ^= kth(a[v], bit); n   cur += cnt[pref ^ 1]; n   for (int to : g[v]) n     if (!used[to] && to != p) { n       addcur(to, v, bit, pref); n     } n } n void addcnt(int v, int p, int bit, bool pref = 0) { n   pref ^= kth(a[v], bit); n   cnt[pref]++; n   for (int to : g[v]) n     if (!used[to] && to != p) { n       addcnt(to, v, bit, pref); n     } n } n void dfs(int v = 1) { n   pre(v); n   cur_sz = sz[v]; n   v = f(v); n   for (int bit = 0; bit < 20; ++bit) { n     cur = 0; n     cnt[1] = 0, cnt[0] = 1; n     for (int to : g[v]) n       if (!used[to]) { n         bool st = kth(a[v], bit); n         addcur(to, v, bit, st); n         addcnt(to, v, bit); n       } n     res += (1ll << bit) * 1ll * cur; n   } n   used[v] = 1; n   for (int to : g[v]) n     if (!used[to]) { n       dfs(to); n     } n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   ; n   int n; n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     res += a[i]; n   } n   for (int i = 1; i < n; ++i) { n     int a, b; n     cin >> a >> b; n     g[a].push_back(b); n     g[b].push_back(a); n   } n   dfs(); n   cout << res; n } n


#include <bits/stdc++.h> n using namespace std; n const int dx[] = {0, 0, -1, 1}; n const int dy[] = {1, -1, 0, 0}; n const int N = 505; n int n, m; n char adj[N][N]; n bool vis[N][N]; n struct node { n   int type, x, y; n   node() {} n   node(int type, int x, int y) : type(type), x(x), y(y) {} n   void print() { n     if (type == 0) n       putchar( B ); n     else if (type == 1) n       putchar( R ); n     else n       putchar( D ); n     printf(  %d %d n , x + 1, y + 1); n   } n }; n vector<node> ans; n void dfs(int x, int y) { n   vis[x][y] = 1; n   for (int i = 0; i < 4; i++) { n     int xx = x + dx[i]; n     int yy = y + dy[i]; n     if (xx >= 0 && xx < n && yy >= 0 && yy < m && vis[xx][yy] == 0) { n       ans.push_back(node(0, xx, yy)); n       dfs(xx, yy); n       ans.push_back(node(2, xx, yy)); n       ans.push_back(node(1, xx, yy)); n     } n   } n } n int main() { n   while (scanf( %d%d , &n, &m) != EOF) { n     ans.clear(); n     memset(vis, 0, sizeof(vis)); n     for (int i = 0; i < n; i++) scanf( %s , adj[i]); n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         if (adj[i][j] ==  # ) vis[i][j] = 1; n       } n     } n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) n         if (vis[i][j] == 0) { n           ans.push_back(node(0, i, j)); n           dfs(i, j); n         } n     } n     int len = (int)ans.size(); n     printf( %d n , len); n     for (int i = 0; i < len; i++) ans[i].print(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int arr[N]; n int main() { n   int n; n   memset(arr, 0, sizeof arr); n   cin >> n; n   int maxx = n; n   int num; n   for (int i = 0; i < n; i++) { n     cin >> num; n     arr[num] = -1; n     while (arr[maxx] == -1) { n       cout << maxx <<    ; n       maxx -= 1; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int abs(int x) { return x > 0 ? x : -x; } n int min(int x, int y) { return x < y ? x : y; } n int max(int x, int y) { return x > y ? x : y; } n int main() { n   int a1, a2, a3, a4; n   scanf( %d%d%d%d , &a1, &a2, &a3, &a4); n   if (abs(a3 - a4) > 1 || max(a3, a4) > min(a1, a2) || a3 + a4 + 1 > a1 + a2 || n       a3 + a4 == 0) { n     printf( -1 n ); n     return 0; n   } n   int c = min(a3, a4); n   a3 -= c; n   a4 -= c; n   a1 -= c, a2 -= c; n   if (!a3 && !a4) { n     if (!a1) { n       for (int i = 1; i <= c; i++) printf( 74 ); n       for (int i = 1; i <= a2; i++) printf( 7 ); n     } else { n       for (int i = 1; i < a1; i++) printf( 4 ); n       for (int i = 1; i <= c; i++) printf( 47 ); n       for (int i = 1; i <= a2; i++) printf( 7 ); n       printf( 4 n ); n     } n   } else if (a3) { n     for (int i = 1; i < a1; i++) printf( 4 ); n     for (int i = 1; i <= c + 1; i++) printf( 47 ); n     for (int i = 1; i < a2; i++) printf( 7 ); n   } else if (a4) { n     printf( 74 ); n     for (int i = 1; i < a1; i++) printf( 4 ); n     for (int i = 1; i < c; i++) printf( 74 ); n     for (int i = 1; i <= a2; i++) printf( 7 ); n     printf( 4 ); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void c_p_c() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cout << name <<   :   << arg1 <<   n ; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cout.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n long long int n, m; n char a[50][50]; n long long int vis[50][50]; n long long int cnt = 0; n long long int dx[] = {1, -1, 0, 0}; n long long int dy[] = {0, 0, 1, -1}; n bool is_valid(long long int i, long long int j) { n   if (i >= 0 and j >= 0 and i < n and j < m and a[i][j] ==  B ) { n     return true; n   } n   return false; n } n void dfs(long long int i, long long int j, long long int dn, n          long long int dir) { n   if (vis[i][j] == 0) { n     vis[i][j] = 1; n     cnt++; n   } n   for (long long int k = 0; k < 4; k++) { n     long long int x = i + dx[k]; n     long long int y = j + dy[k]; n     if (is_valid(x, y)) { n       long long int g; n       long long int p; n       if (dir == -1) { n         g = 0; n       } n       if (dir != -1) { n         if (k == dir) { n           g = dn; n         } else { n           g = dn + 1; n         } n       } n       if (g > 1) { n         continue; n       } n       dfs(x, y, g, k); n     } n   } n } n int32_t main() { n   c_p_c(); n   cin >> n >> m; n   long long int k = 0; n   for (long long int i = 0; i < n; i++) { n     for (long long int j = 0; j < m; j++) { n       cin >> a[i][j]; n       if (a[i][j] ==  B ) { n         k++; n       } n     } n   } n   for (long long int i = 0; i < n; i++) { n     for (long long int j = 0; j < m; j++) { n       if (a[i][j] ==  B ) { n         memset(vis, 0, sizeof(vis)); n         cnt = 0; n         dfs(i, j, 0, -1); n         if (cnt != k) { n           cout <<  NO  <<   n ; n           return 0; n         } n       } n     } n   } n   cout <<  YES  <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   long long x, q = k - 1, flag, a[k], i, j; n   for (i = 0; i < n; i++) { n     cin >> x; n     if (!i) n       a[q--] = x; n     else { n       flag = 0; n       for (j = k - 1; j > q; j--) { n         if (a[j] == x) { n           flag = 1; n           break; n         } n       } n       if (flag == 0) { n         if (q < 0) { n           for (j = k - 1; j > 0; j--) a[j] = a[j - 1]; n           a[0] = x; n         } else n           a[q--] = x; n       } n     } n   } n   cout << k - (q + 1) << endl; n   for (i = q + 1; i < k; i++) cout << a[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1000100100; n int n, m; n string s[105]; n int team[105]; n int dp[21][(1 << 21)]; n int a[104]; n int solve(int cur, int mask) { n   if (cur == m) return 0; n   int &ret = dp[cur][mask]; n   if (ret == inf) { n     if (s[cur] ==  p ) { n       int j = 0; n       while (j < m && ((mask >> j) & 1)) ++j; n       if (team[cur] == 1) n         ret = solve(cur + 1, mask | (1 << j)) + a[j]; n       else n         ret = solve(cur + 1, mask | (1 << j)) - a[j]; n     } else { n       ret = solve(cur + 1, mask); n       for (int j = 0; j < m; ++j) { n         if ((mask >> j) & 1) continue; n         if (team[cur] == 1) n           ret = max(ret, solve(cur + 1, mask | (1 << j))); n         else n           ret = min(ret, solve(cur + 1, mask | (1 << j))); n       } n     } n   } n   return ret; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   sort(a, a + n, greater<int>()); n   cin >> m; n   for (int i = 0; i < m; ++i) { n     cin >> s[i] >> team[i]; n   } n   fill(&dp[0][0], &dp[0][0] + (21 * (1 << 21)), inf); n   cout << solve(0, 0); n } n


#include <bits/stdc++.h> n const double PI = 3.141592653589793238460; n using namespace std; n int main() { n   long long int t, n, k; n   cin >> t; n   while (t--) { n     cin >> n >> k; n     if ((n < k * k)) n       cout <<  NO  <<   n ; n     else if ((k % 2) != (n % 2)) n       cout <<  NO  <<   n ; n     else n       cout <<  YES  <<   n ; n   } n } n


////JAI SHREE RAM//// n #include <iostream> n #include<bits/stdc++.h> n using namespace std; n const long long int INF = (long long)1e15; n const long long int mod = 1e9+7; n #define ll long long n #define f(i,a,b) for(int i=a;i<b;i++) n #define pb push_back n #define all(c) c.begin(),c.end() n #define rall(c) c.rbegin(),c.rend() n #define yes cout<< YES n  n #define no cout<< NO n  n #define sd second n #define ft first n // n bool cmp(const pair<int,int> &a, const pair<int,int> &b) n { n     //return (a.sd>=b.sd); n     return abs(a.ft)+abs(a.sd) < abs(b.ft)+abs(b.sd); n } n  n void solve() n { n     int n;cin>>n; n     int o=0; n     n*=2; n     f(i,0,n){ n         int x;cin>>x; n         if(x%2) o++; n     } n     if(o==n/2) yes; n     else no; n } n int main() n { n     //ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); n     int t=1; n     cin>>t; n  n     while(t--) n     { n         solve(); n     } n     return 0; n } n  n


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


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 7; n vector<int> gr[N]; n bool access = true; n int p[N], h[N], a[N], g[N]; n void dfs(int v, int ancestor = -1) { n   a[v] = p[v]; n   int sum_g = 0; n   for (int to : gr[v]) { n     if (to == ancestor) continue; n     dfs(to, v); n     sum_g += g[to]; n     a[v] += a[to]; n   } n   if ((a[v] + h[v]) % 2 == 0) { n   } else n     access = false; n   g[v] = (a[v] + h[v]) / 2; n   if (g[v] >= 0 && g[v] <= a[v]) { n   } else n     access = false; n   if (sum_g <= g[v]) { n   } else n     access = false; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int q; n   cin >> q; n   while (q--) { n     int n, m; n     cin >> n >> m; n     for (int i = 0; i < n; ++i) cin >> p[i]; n     for (int i = 0; i < n; ++i) cin >> h[i]; n     for (int i = 0; i < n - 1; ++i) { n       int a, b; n       cin >> a >> b; n       --a, --b; n       gr[a].push_back(b); n       gr[b].push_back(a); n     } n     dfs(0); n     cout << (access ?  YES  :  NO ) << endl; n     access = true; n     for (int i = 0; i < n; ++i) gr[i].clear(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, A[6], B[(1 << 6)], C[100001], P[(1 << 6)], Q[(1 << 6)]; n char s[100001]; n void TakeInputs() { n   string s; n   cin >> s; n   for (auto c : s) { n     int i = c -  a ; n     ++A[i]; n   } n   n = s.size(); n   for (int i = 0; i < n; ++i) { n     C[i] = (1 << 6) - 1; n   } n   int m; n   cin >> m; n   while (m--) { n     int i, mask = 0; n     cin >> i >> s; n     for (auto c : s) { n       int j = c -  a ; n       mask |= (1 << j); n     } n     --i; n     C[i] = mask; n   } n   for (int i = 0; i < n; ++i) { n     ++B[C[i]]; n   } n } n bool Check() { n   for (int i = 0; i < (1 << 6); ++i) { n     P[i] = 0; n     Q[i] = B[i]; n   } n   for (int k = 0; k < 6; ++k) { n     P[(1 << k)] = A[k]; n   } n   for (int j = 0; j < 6; ++j) { n     for (int i = 0; i < (1 << 6); ++i) { n       if ((i & (1 << j)) > 0) { n         P[i] += P[(i ^ (1 << j))]; n         Q[i] += Q[(i ^ (1 << j))]; n       } n     } n   } n   bool ans = 1; n   for (int i = 0; i < (1 << 6) && ans == 1; ans = (P[i] >= Q[i]), ++i) n     ; n   return ans; n } n int main() { n   TakeInputs(); n   for (int i = 0; i < n; ++i) { n     for (int k = 0; k < 6; ++k) { n       if (A[k] == 0 || s[i] >=  a  || ((1 << k) & C[i]) == 0) { n         continue; n       } n       --A[k]; n       --B[C[i]]; n       if (Check()) { n         s[i] =  a  + k; n       } else { n         ++A[k]; n         ++B[C[i]]; n       } n     } n     if (!(s[i] >=  a )) { n       break; n     } n   } n   if (strlen(s) == n) { n     printf( %s n , s); n   } else { n     printf( Impossible n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int team[101]; n char c[101]; n int dp[21][(1 << 20) + 5]; n int a[1001]; n int solve(int pos, int mask) { n   if (pos == n) return 0; n   if (dp[pos][mask] != -1) return dp[pos][mask]; n   int ans; n   if (team[pos] == 1) { n     ans = -(1 << 30); n     for (int i = 0; i < m; i++) { n       if (mask & (1 << i)) { n         if (c[pos] ==  p ) n           ans = max(ans, a[i] + solve(pos + 1, mask ^ (1 << i))); n         else n           ans = max(ans, solve(pos + 1, mask ^ (1 << i))); n       } n     } n   } else { n     ans = (1 << 30); n     for (int i = 0; i < m; i++) { n       if (mask & (1 << i)) { n         if (c[pos] ==  p ) n           ans = min(ans, solve(pos + 1, mask ^ (1 << i)) - a[i]); n         else n           ans = min(ans, solve(pos + 1, mask ^ (1 << i))); n       } n     } n   } n   return dp[pos][mask] = ans; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   reverse(a, a + n); n   cin >> m; n   n = m; n   memset(dp, -1, sizeof(dp)); n   for (int i = 0; i < m; i++) { n     cin >> c[i] >> team[i]; n   } n   cout << solve(0, (1 << m) - 1) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   scanf( %lld , &n); n   long long a, b, c; n   scanf( %lld , &a); n   scanf( %lld , &b); n   scanf( %lld , &c); n   if (a <= (b - c)) { n     printf( %lld n , n / a); n   } else { n     n -= b; n     long long x = 0; n     if (n >= 0) { n       x = n / (b - c); n       n %= (b - c); n     } n     n += b; n     if (n >= b) { n       n = n - (b - c); n       x++; n     } n     x += max(n / a, n / b); n     printf( %lld n , x); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, kk, a[200]; n   scanf( %d%d , &n, &kk); n   for (int i = 0; i < n; i++) scanf( %d , &a[i]); n   int sum, tp, mx = a[0]; n   for (int i = 0; i < n; i++) n     for (int j = i; j < n; j++) { n       priority_queue<int> la, sm; n       sum = 0; n       for (int k = 0; k < n; k++) n         if (k >= i && k <= j) { n           sm.push(-a[k]); n           sum += a[k]; n         } else n           la.push(a[k]); n       if (mx < sum) mx = sum; n       int ts = sum; n       for (int k = 0; k < kk; k++) { n         sum += sm.top(); n         la.push(-sm.top()); n         sm.pop(); n         sum += la.top(); n         sm.push(-la.top()); n         la.pop(); n         if (ts >= sum) break; n       } n       if (mx < sum) mx = sum; n     } n   printf( %d , mx); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s, p; n long long l, r, dp[32][3][3][3][3]; n string ts(long long x) { n   string ans; n   while (x) { n     ans.push_back( 0  + x % 2); n     x /= 2; n   } n   while (ans.size() != 31) ans.push_back( 0 ); n   reverse(ans.begin(), ans.end()); n   return ans; n } n long long f(int x, int a, int b, int c, int d) { n   if (x == s.size()) return 1; n   if (dp[x][a][b][c][d] != -1) return dp[x][a][b][c][d]; n   long long ans = 0; n   for (int i = 0; i <= 1; i++) { n     for (int j = 0; j <= 1; j++) { n       if (i == j && i) continue; n       char aa = i +  0 , bb = j +  0 ; n       if (a && s[x] > aa) continue; n       if (b && p[x] < aa) continue; n       if (c && s[x] > bb) continue; n       if (d && p[x] < bb) continue; n       int na = (a & (s[x] == aa)); n       int nb = (b & (p[x] == aa)); n       int nc = (c & (s[x] == bb)); n       int nd = (d & (p[x] == bb)); n       ans += f(x + 1, na, nb, nc, nd); n     } n   } n   return dp[x][a][b][c][d] = ans; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     memset(dp, -1, sizeof dp); n     cin >> l >> r; n     s = ts(l), p = ts(r); n     cout << f(0, 1, 1, 1, 1) << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T gcd(T a, T b) { n   return !b ? a : gcd(b, a % b); n } n template <typename T> n T lcm(T a, T b) { n   return a * (b / gcd(a, b)); n } n template <typename T> n T sqr(T a) { n   return a * a; n } n template <typename T> n T cube(T a) { n   return a * a * a; n } n template <typename T> n inline void smin(T &a, T b) { n   a = a < b ? a : b; n } n template <typename T> n inline void smax(T &a, T b) { n   a = a > b ? a : b; n } n template <typename T> n inline void Int(T &n) { n   n = 0; n   int f = 1; n   register int ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) f = -1; n   for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch -  0 ; n   n = n * f; n } n vector<string> split(const string &s, char c) { n   vector<string> v; n   stringstream second(s); n   string x; n   while (getline(second, x, c)) v.emplace_back(x); n   return move(v); n } n void err(vector<string>::iterator it) {} n template <typename T, typename... Args> n void err(vector<string>::iterator it, T a, Args... args) { n   cout << it->substr((*it)[0] ==    , it->length()) <<   =   << a <<  ,  ; n   err(++it, args...); n } n inline int in() { n   int n; n   scanf( %d , &n); n   return n; n } n inline long long Lin() { n   long long n; n   scanf( %lld , &n); n   return n; n } n inline double Din() { n   double n; n   scanf( %lf , &n); n   return n; n } n inline int add(int a, int b, int mod) { n   a += b; n   return a >= mod ? a - mod : a; n } n inline int sub(int a, int b, int mod) { n   a -= b; n   return a < 0 ? a + mod : a; n } n inline int mul(int a, int b, int mod) { return (long long)a * b % mod; } n const int N = 2e5 + 5; n const int inf = (int)2e9 + 5; n const long long Inf = (long long)1e18 + 5; n const int mod = (int)1e9 + 7; n const long long Mod = (long long)1e9 + 7; n vector<int> b[N]; n int solve() { n   int n = in(), k = in(); n   vector<int> a(n); n   for (int i = 0; i < n; i++) { n     a[i] = in(); n   } n   for (int i = 0; i < n; i++) { n     int x = a[i], cur = 0; n     while (x >= 1) { n       b[x].push_back(cur); n       x /= 2; n       cur++; n     } n   } n   long long ans = Inf; n   for (int i = 0; i <= 2e5; i++) { n     sort(b[i].begin(), b[i].end()); n     if ((int)b[i].size() >= k) { n       long long cur = 0; n       for (int j = 0; j < k; j++) { n         cur += b[i][j]; n       } n       smin(ans, cur); n     } n   } n   printf( %lld n , ans); n   return 0; n } n int main() { n   int test = 1, tc = 0; n   while (test--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long LL_INF = 0x3f3f3f3f3f3f3f3f; n const double PI = 3.14159265359; n const int mod = 1000 * 1000 * 1000 + 7; n int dx[4] = {1, -1, 0, 0}; n int dy[4] = {0, 0, 1, -1}; n string s; n int dp[100005]; n int solve(int idx) { n   if (idx == s.size()) return 1; n   int &ret = dp[idx]; n   if (~ret) return ret; n   ret = 0; n   if (s[idx] ==  u  or s[idx] ==  n ) { n     if (idx + 1 < s.size() and s[idx + 1] == s[idx]) { n       ret = (solve(idx + 1) + solve(idx + 2)) % mod; n     } else n       ret = solve(idx + 1) % mod; n   } else n     ret = solve(idx + 1) % mod; n   return ret; n } n int main() { n   cin >> s; n   if (s.find( w ) != -1 or s.find( m ) != -1) return cout << 0 << endl, 0; n   memset(dp, -1, sizeof dp); n   cout << solve(0) % mod << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> arr[100005]; n vector<int> v1[100005]; n int visited[100005]; n stack<int> s; n int n, m; n set<int> se[100005]; n void dfs(int node) { n   int i; n   visited[node] = 1; n   int n = v1[node].size(); n   for (i = 0; i < n; i++) { n     if (visited[v1[node][i]] == 0) { n       dfs(v1[node][i]); n     } n   } n   s.push(node); n } n bool check(int mid) { n   int i; n   bool ans = true; n   for (i = 1; i <= mid; i++) { n     v1[arr[i].first].push_back(arr[i].second); n     se[arr[i].first].insert(arr[i].second); n   } n   for (i = 1; i <= n; i++) visited[i] = 0; n   for (i = 1; i <= n; i++) { n     if (visited[i] == 0) { n       dfs(i); n     } n   } n   int x; n   x = s.top(); n   s.pop(); n   while (!s.empty()) { n     if (se[x].find(s.top()) == se[x].end()) ans = false; n     x = s.top(); n     s.pop(); n   } n   for (i = 1; i <= n; i++) { n     v1[i].clear(); n     se[i].clear(); n   } n   return ans; n } n int main() { n   int i, j, k; n   scanf( %d , &n); n   scanf( %d , &m); n   for (i = 1; i <= m; i++) { n     scanf( %d , &arr[i].first); n     scanf( %d , &arr[i].second); n   } n   int l = 0, r = m, mid; n   while (l <= r) { n     mid = (l + r) / 2; n     bool temp1 = check(mid); n     if (mid == m) { n       if (temp1 == false) { n         printf( -1 n ); n         return 0; n       } else { n         r = mid - 1; n         continue; n       } n     } n     bool temp2 = check(mid + 1); n     if (temp1 == false && temp2 == true) { n       printf( %d n , mid + 1); n       return 0; n     } else if (temp2 == true) { n       r = mid - 1; n     } else { n       l = mid + 1; n     } n   } n   printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n const int Maxn = 1000; n const int Inf = 0x3f3f3f3f; n int n, m; n int a[Maxn + 5], b[Maxn + 5]; n std::vector<int> edge[Maxn + 5]; n int pre[Maxn + 5]; n long long dis[Maxn + 5]; n bool vis[Maxn + 5]; n bool check(int x) { n   for (int i = 1; i <= n; i++) { n     vis[i] = 0; n   } n   vis[1] = 1; n   long long now = x, tot = 1; n   while (tot < n) { n     std::queue<int> q; n     for (int i = 1; i <= n; i++) { n       pre[i] = 0; n       dis[i] = 0; n       if (vis[i]) { n         q.push(i); n         dis[i] = now; n       } n     } n     int x = 0, y = 0; n     while (!q.empty()) { n       int u = q.front(); n       q.pop(); n       for (int i = 0; i < (int)edge[u].size(); i++) { n         int v = edge[u][i]; n         if (!vis[v]) { n           if (dis[u] <= a[v]) { n             continue; n           } n           if (pre[v] == 0) { n             pre[v] = u; n             dis[v] = dis[u] + b[v]; n             q.push(v); n           } else if (v != pre[u]) { n             x = u, y = v; n             goto OUT; n           } n         } else if (!vis[u] && v != pre[u]) { n           x = u, y = v; n           goto OUT; n         } n       } n     } n   OUT:; n     if (x == 0) { n       return 0; n     } n     for (int u = x; u; u = pre[u]) { n       if (!vis[u]) { n         vis[u] = 1; n         now += b[u]; n         tot++; n       } n     } n     for (int u = y; u; u = pre[u]) { n       if (!vis[u]) { n         vis[u] = 1; n         now += b[u]; n         tot++; n       } n     } n   } n   return 1; n } n void solve() { n   int left = Inf, right = 0; n   scanf( %d%d , &n, &m); n   for (int i = 2; i <= n; i++) { n     scanf( %d , &a[i]); n     left = std::min(left, a[i]); n     right = std::max(right, a[i]); n   } n   right++; n   for (int i = 2; i <= n; i++) { n     scanf( %d , &b[i]); n   } n   for (int i = 1; i <= n; i++) { n     edge[i].clear(); n   } n   for (int i = 1; i <= m; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     edge[u].push_back(v), edge[v].push_back(u); n   } n   while (left < right) { n     int mid = (left + right) >> 1; n     if (check(mid)) { n       right = mid; n     } else { n       left = mid + 1; n     } n   } n   printf( %d n , left); n } n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int n = s.size(); n   cout <<  3 nL 2 nR 2 nR   << n + n - 1; n } n


#include <bits/stdc++.h> n using namespace std; n const int Maxn = 102; n int n, K; n double dp[2][Maxn][Maxn]; n int a[Maxn]; n inline int c2(int x) { return x * (x - 1) / 2; } n inline int max(int x, int y) { return x > y ? x : y; } n inline int min(int x, int y) { return x < y ? x : y; } n int main() { n   scanf( %d%d , &n, &K); n   if (K > 875) K = 875; n   for (int i = 1; i <= n; i++) scanf( %d , a + i); n   for (int i = 1; i <= n; i++) n     for (int j = i + 1; j <= n; j++) dp[0][i][j] = a[i] > a[j]; n   int cs = 1; n   for (int k = 1; k <= K; k++, cs ^= 1) { n     for (int i = 1; i <= n; i++) n       for (int j = i + 1; j <= n; j++) { n         dp[cs][i][j] = 0; n         dp[cs][i][j] += dp[cs ^ 1][i][j] * (c2(i) + c2(n - j + 1) + c2(j - i)); n         for (int sum = j + 1; sum <= i + n; sum++) { n           dp[cs][i][j] += (1.0 - dp[cs ^ 1][sum - j][sum - i]) * n                           (min(i, sum - j) - max(1, sum - n) + 1); n         } n         for (int sum = i + 1; sum <= i + j - 1; sum++) n           dp[cs][i][j] += dp[cs ^ 1][sum - i][j] * n                           (min(i, sum - i) - max(1, sum - j + 1) + 1); n         for (int sum = j + i + 1; sum <= n + j; sum++) n           dp[cs][i][j] += dp[cs ^ 1][i][sum - j] * n                           (min(j, sum - j) - max(i + 1, sum - n) + 1); n         dp[cs][i][j] /= c2(n + 1); n       } n   } n   double ans = 0; n   for (int i = 1; i <= n; i++) n     for (int j = i + 1; j <= n; j++) ans += dp[cs ^ 1][i][j]; n   printf( %.12f n , ans); 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   long long n, x, y = 0; n   cin >> n >> x; n   for (int i = 1; i <= n; i++) { n     char a; n     long long d; n     cin >> a >> d; n     if (a ==  + ) n       x += d; n     else if (x >= d) n       x -= d; n     else n       y++; n   } n   cout << x <<     << y << endl; n } n


#include <bits/stdc++.h> n using namespace std; n struct segtree2 { n   int seg[512 * 1024 * 2]; n   int mum; n   void init(int n) { n     mum = 1; n     while (mum < n) mum <<= 1; n     for (int i = 0; i < mum * 2; i++) seg[i] = -1; n   } n   void add(int k, int x) { n     k += mum - 1; n     seg[k] = x; n     while (k > 0) { n       k = (k - 1) / 2; n       seg[k] = max(seg[k * 2 + 1], seg[k * 2 + 2]); n     } n   } n   int get(int a, int b, int k, int l, int r) { n     if (b <= l || r <= a) return -1; n     if (a <= l && r <= b) n       return seg[k]; n     else { n       int vl = get(a, b, k * 2 + 1, l, (l + r) / 2); n       int vr = get(a, b, k * 2 + 2, (l + r) / 2, r); n       return max(vl, vr); n     } n   } n   int get(int a, int b) { return get(a, b, 0, 0, mum); } n }; n struct segtree1 { n   int seg[512 * 1024 * 2]; n   int mum; n   void init(int n) { n     mum = 1; n     while (mum < n) mum <<= 1; n     for (int i = 0; i < mum * 2; i++) seg[i] = 1000000005; n   } n   void update(int a, int b, int k, int l, int r, int v) { n     if (b <= l || r <= a) return; n     if (a <= l && r <= b) n       seg[k] = min(seg[k], v); n     else { n       update(a, b, k * 2 + 1, l, (l + r) / 2, v); n       update(a, b, k * 2 + 2, (l + r) / 2, r, v); n     } n   } n   void update(int a, int b, int v) { update(a, b, 0, 0, mum, v); } n   void pass(int k) { n     seg[k * 2 + 1] = min(seg[k * 2 + 1], seg[k]); n     seg[k * 2 + 2] = min(seg[k * 2 + 2], seg[k]); n     seg[k] = 1000000005; n   } n   void erase(int x) { n     int l = 0, r = mum, k = 0; n     while (l + 1 < r) { n       pass(k); n       int m = (l + r) / 2; n       if (x < m) { n         r = m; n         k = k * 2 + 1; n       } else { n         l = m; n         k = k * 2 + 2; n       } n     } n     seg[k] = 1000000005; n   } n   int get(int k) { n     k += mum - 1; n     int ret = seg[k]; n     while (k > 0) { n       k = (k - 1) / 2; n       ret = min(ret, seg[k]); n     } n     return ret; n   } n }; n segtree1 s1; n segtree2 s2; n int L[300005], R[300005], X[300005]; n int pos[300005], dt[300005]; n int tp[300005]; n int mx[300005], nowA[300005]; n set<int> st[300005]; n set<int>::iterator it; n vector<int> vec[40]; n bool use[300005]; n bool ng[300005]; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   s1.init(n + 2); n   s2.init(n + 2); n   memset(nowA, -1, sizeof(nowA)); n   memset(use, false, sizeof(use)); n   for (int i = 0; i < m; i++) { n     scanf( %d , &tp[i]); n     if (tp[i] == 1) { n       scanf( %d %d %d , &L[i], &R[i], &X[i]); n       L[i]--, R[i]--; n       s1.update(L[i], R[i] + 1, X[i]); n       int gt = s2.get(L[i], R[i] + 1); n       if (gt > X[i]) { n         puts( NO ); n         return 0; n       } n       use[i] = gt == X[i]; n     } else { n       scanf( %d %d , &pos[i], &dt[i]); n       pos[i]--; n       int gt = s1.get(pos[i]); n       gt = min(gt, 1000000000); n       if (nowA[pos[i]] == -1) mx[pos[i]] = gt; n       nowA[pos[i]] = dt[i]; n       s2.add(pos[i], dt[i]); n     } n   } n   for (int i = 0; i < n; i++) { n     if (nowA[i] == -1) { n       mx[i] = s1.get(i); n       mx[i] = min(mx[i], 1000000000); n     } n   } n   vector<int> vx; n   for (int i = 0; i < n; i++) vx.push_back(mx[i]); n   sort(vx.begin(), vx.end()); n   vx.erase(unique(vx.begin(), vx.end()), vx.end()); n   for (int i = 0; i < n; i++) { n     mx[i] = lower_bound(vx.begin(), vx.end(), mx[i]) - vx.begin(); n     st[mx[i]].insert(i); n   } n   for (int i = 0; i < m; i++) { n     if (tp[i] == 1 && !use[i]) { n       int t = lower_bound(vx.begin(), vx.end(), X[i]) - vx.begin(); n       if (t == vx.size() || vx[t] != X[i]) { n         puts( NO ); n         return 0; n       } n       it = st[t].lower_bound(L[i]); n       if (it == st[t].end() || *it > R[i]) { n         puts( NO ); n         return 0; n       } n       int to = *it; n       it++; n       if (it == st[t].end() || *it > R[i]) { n         ng[to] = true; n       } n     } else { n       int v = pos[i]; n       st[mx[v]].erase(v); n     } n   } n   for (int i = 0; i < n; i++) { n     mx[i] = vx[mx[i]]; n     int vl = mx[i]; n     if (vl > 0) { n       int cnt = 0; n       while (vl > 0) { n         vl /= 2; n         cnt++; n       } n       vec[cnt - 1].push_back(i); n     } n   } n   int ret = 0; n   for (int i = 40 - 1; i >= 0; i--) { n     if (vec[i].empty()) continue; n     if (ret >> i & 1) { n       bool U = true; n       for (int j = 0; j < vec[i].size(); j++) { n         int v = vec[i][j]; n         if (!ng[v] && U) { n           mx[v] = ((mx[v] >> (i + 1)) << (i + 1)) + (1 << i) - 1; n           U = false; n         } n         ret |= mx[v]; n       } n       if (!U) break; n     } else { n       if (vec[i].size() == 1) { n         int v = vec[i][0]; n         if (!ng[v]) { n           int zan = mx[v] - ((mx[v] >> i) << i); n           ret |= 1 << i; n           if (zan > 0) { n             int vl = zan, cnt = 0; n             while (vl > 0) { n               vl /= 2; n               cnt++; n             } n             vec[cnt - 1].push_back(v); n           } n         } else n           ret |= mx[v]; n       } else { n         bool up = false; n         for (int j = 0; j < vec[i].size(); j++) { n           int v = vec[i][j]; n           up |= !ng[v]; n         } n         if (up) { n           for (int j = 0; j < vec[i].size(); j++) { n             int v = vec[i][j]; n             if (!ng[v]) { n               mx[v] = ((mx[v] >> (i + 1)) << (i + 1)) + (1 << i) - 1; n               break; n             } n           } n           ret |= (1 << (i + 1)) - 1; n           break; n         } else { n           for (int j = 0; j < vec[i].size(); j++) { n             int v = vec[i][j]; n             ret |= mx[v]; n           } n         } n       } n     } n   } n   puts( YES ); n   for (int i = 0; i < n; i++) { n     if (i != 0) printf(   ); n     printf( %d , mx[i]); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = (int)1e9; n int a, c; n int arrA[2000]; n int arrC[2000]; n void sol() { n   cin >> c >> a; n   for (int i = 0; i < c; i++) { n     cin >> arrC[i]; n   } n   for (int i = 0; i < a; i++) { n     cin >> arrA[i]; n   } n   int result = 0; n   int j = 0; n   for (int i = 0; i < a && j < c; i++, j++) { n     while (j < c && arrC[j] > arrA[i]) j++; n     if (j >= c) break; n     result++; n   } n   cout << result << endl; n } n int main(void) { n   sol(); n   return 0; n } n