#include <bits/stdc++.h>   using namespace std;   const long long int maxn = 1e6 + 500;   const long long int mod = 998244353;   int dep[maxn], low[maxn], ans[maxn], dp[maxn];   int head[maxn], cnt;   int n, k;   struct C {     int next, to;   } E[maxn];   void add(int x, int y) {     E[cnt].to = y;     E[cnt].next = head[x];     head[x] = cnt++;   }   void dfs1(int u, int fa) {     low[u] = 0x7f7f7f7f;     dep[u] = dep[fa] + 1;     if (head[u] == -1) {       low[u] = dep[u];       dp[u] = 1;     } else {       for (int i = head[u]; i + 1; i = E[i].next) {         int v = E[i].to;         dfs1(v, u);         low[u] = min(low[u], low[v]);         if (low[v] - k <= dep[u]) dp[u] += dp[v];       }     }   }   int dfs(int u, int fa) {     if (head[u] == -1) return 1;     int ans = 0;     for (int i = head[u]; i + 1; i = E[i].next) {       int v = E[i].to;       int temp = dp[u];       if (low[v] - k <= dep[u]) temp -= dp[v];       ans = max(ans, temp + dfs(v, u));     }     return ans;   }   int main() {     int x;     scanf( %d%d , &n, &k);     memset(head, -1, sizeof head);     for (int i = 2; i <= n; i++) {       scanf( %d , &x);       add(x, i);     }     dfs1(1, 0);     printf( %d n , dfs(1, 0));   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int m, n, a[100009], b[100009];   long long sa, sb;   long long proca() {     long long ans = 0;     ans += sa;     for (int(x) = (1); (x) < (n); ++(x)) {       ans += min(sa, (long long)b[x]);     }     return ans;   }   long long procb() {     long long ans = 0;     ans += sb;     for (int(x) = (1); (x) < (m); ++(x)) ans += min(sb, (long long)a[x]);     return ans;   }   int main() {     while (scanf( %d%d , &m, &n) == 2) {       sa = sb = 0;       for (int(x) = (0); (x) < (m); ++(x)) {         scanf( %d , &a[x]);         sa += a[x];       }       for (int(x) = (0); (x) < (n); ++(x)) {         scanf( %d , &b[x]);         sb += b[x];       }       sort(a, a + m);       reverse(a, a + m);       sort(b, b + n);       reverse(b, b + n);       cout << min(proca(), procb()) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Edge {     int t, v, next;     Edge() {}     Edge(int a, int b, int c) : t(a), v(b), next(c) {}   };   Edge e[600005];   int head[300005];   long long dis[300005];   int p[300005];   priority_queue<pair<long long, int>, vector<pair<long long, int> >,                  greater<pair<long long, int> > >       q;   void dijkstra(int k) {     memset(dis, 0x3f, sizeof(dis));     dis[1] = 0;     q.push(pair<long long, int>(0, 1));     int cnt = 0;     while (!q.empty()) {       pair<long long, int> t = q.top();       q.pop();       if (dis[t.second] < t.first) continue;       int a = t.second;       long long b = t.first;       if (p[a] && cnt < k) {         printf( %d  , p[a]);         cnt++;       }       for (int i = head[a]; i; i = e[i].next)         if (b + e[i].v < dis[e[i].t]) {           int u = e[i].t;           dis[u] = b + e[i].v;           p[u] = ((i + 1) >> 1);           q.push(pair<long long, int>(dis[u], u));         }     }     printf(  n );   }   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     k = min(k, n - 1);     for (int i = 1; i <= m; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       e[2 * i - 1] = Edge(y, z, head[x]);       head[x] = 2 * i - 1;       e[2 * i] = Edge(x, z, head[y]);       head[y] = 2 * i;     }     printf( %d n , k);     dijkstra(k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, j;     char s[101];     cin >> n >> m;     for (i = 0; i < n; i++) {       cin >> s;       for (j = 0; j < m; j++) {         if (s[j] ==  . ) s[j] = ((i + j) % 2 == 0) ?  B  :  W ;       }       cout << s << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e5 + 10;   int main() {     ios::sync_with_stdio(0);     int n;     cin >> n;     string s;     cin >> s;     s +=  _ ;     int ln = 0, lng = 0, imin = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  ( ) {         imin = 1;         ln = 0;       } else if (s[i] ==  ) ) {         imin = 0;         ln = 0;       } else if (!imin) {         if (s[i] !=  _ ) {           ln++;           lng = max(lng, ln);         } else           ln = 0;       } else         ln = 0;     }     cout << lng <<    ;     imin = 0, ln = 0;     int cnt = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  ( ) {         imin = 1;         ln = 0;       } else if (s[i] ==  ) ) {         imin = 0;         if (ln) cnt++;         ln = 0;       } else if (imin) {         if (s[i] !=  _ )           ln++;         else {           if (ln) cnt++;           ln = 0;         }       } else         ln = 0;     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N, K;     cin >> N >> K;     using arr2 = array<int, 2>;     vector<arr2> binTrie;     const int w = 30;     binTrie.push_back({-1, -1});     vector<int> sz(1, 0);     auto add = [&](int x) {       int v = 0;       for (int i = w - 1; i >= 0; --i) {         int b = (x >> i) & 1;         ++sz[v];         if (binTrie[v][b] >= 0) {           v = binTrie[v][b];           continue;         }         int v_ = binTrie.size();         binTrie[v][b] = v_;         binTrie.push_back({-1, -1});         sz.push_back(0);         v = v_;       }       ++sz[v];     };     auto xor_lower_bound_size = [&](int x, int k) {       int v = 0, ret = 0;       for (int i = w - 1; i >= 0; --i) {         int b = ((x ^ k) >> i) & 1;         int t = (k >> i) & 1;         if ((!t) and binTrie[v][b ^ 1] >= 0) ret += sz[binTrie[v][b ^ 1]];         if (binTrie[v][b] < 0) {           v = -1;           break;         }         v = binTrie[v][b];       }       if (v >= 0) ret += sz[v];       return ret;     };     vector<int> A(N + 1);     for (int i = 0; i < N; ++i) {       cin >> A[i + 1];       A[i + 1] ^= A[i];     }     long long ans = 0;     for (int i = 0; i <= N; ++i) {       ans += xor_lower_bound_size(A[i], K);       add(A[i]);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t = 1;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       if (k > n) {         cout <<  NO n ;         continue;       }       if (n % 2 == 0 && k % 2 == 1 && k > n / 2) {         cout <<  NO n ;         continue;       }       if (n % 2 != 0 && k % 2 == 0) {         cout <<  NO n ;         continue;       }       if (k % 2 != n % 2) {         cout <<  YES n ;         cout << n - 2 * (k - 1) <<    ;         for (long long i = 0; i < k - 1; i++) cout << 2 <<    ;         cout << endl;         continue;       }       if (n % 2 == k % 2) {         cout <<  YES n ;         cout << n - (k - 1) <<    ;         for (long long i = 0; i < k - 1; i++) cout << 1 <<    ;         cout << endl;         continue;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     if (b == 0) return a;     while ((a = a % b) != 0) {       swap(a, b);     }     return b;   }   long long mpow(long long x, long long y, long long m) {     long long res = 1;     while (y > 0) {       if (y & 1) res = res * x % m;       y = y >> 1;       x = x * x % m;     }     return res;   }   long long ncr(long long n, long long r) {     if (r > n) return 0;     long long res = 1;     for (long long i = (1); i < (r + 1); i++) res = res * (n - r + i) / i;     return res;   }   long long *sieve(long long n) {     long long *lpf = new long long[n + 1];     for (long long i = 1; i <= n; i++) lpf[i] = i;     long long rt = (long long)floor(sqrt(n)) + 1;     for (long long i = (2); i < (rt); i++) {       if (lpf[i] != i) continue;       for (long long j = i * i; j <= n; j += i) {         if (lpf[j] == j) lpf[j] = i;       }     }     return lpf;   }   void solve() {     long long n;     cin >> n;     long long a[n];     for (long long i = (0); i < (n); i++) cin >> a[i];     long long mx = *max_element(a, a + n), mn = *min_element(a, a + n);     if (mx == mn) {       if (mx != 0)         cout <<  NO ;       else {         cout <<  YES n ;         for (long long i = (0); i < (n); i++) cout <<  1  ;       }       return;     }     long long k;     for (long long i = (0); i < (n); i++) {       long long prev = i - 1;       if (prev == -1) prev = n - 1;       if (a[i] == mx && a[prev] != mx) {         k = i;         break;       }     }     long long pt = k;     long long b[n];     b[pt] = mx;     pt--;     if (pt == -1) pt = n - 1;     if (a[pt] == 0)       b[pt] = mx * 2;     else       b[pt] = mx + a[pt];     pt--;     if (pt == -1) pt = n - 1;     while (pt != k) {       b[pt] = b[(pt + 1) % n] + a[pt];       pt--;       if (pt == -1) pt = n - 1;     }     cout <<  YES n ;     for (long long i = (0); i < (n); i++) cout << b[i] <<    ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     for (long long i = (1); i < (t + 1); i++) {       solve();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n;     cin >> m >> n;     vector<pair<int, int>> a, b;     a.resize(n);     for (int i = 0; i < n; ++i) {       a[i].second = i;       cin >> a[i].first;     }     sort(a.begin(), a.end());     b.resize(n);     for (int i = 0; i < n; ++i) {       b[i].second = i;       cin >> b[i].first;     }     sort(b.begin(), b.end());     vector<long long> sum;     sum.resize(n * 2 + 1);     for (int i = 0; i < n * 2 + 1; ++i) {       sum[i] = 0;     }     for (int i = 0, p0 = 0, p1 = 0, p2 = 0; i < n; ++i) {       while (p0 < n && b[p0].first < a[i].first - 1.0 * m / 2) {         ++p0;       }       while (p1 < n && b[p1].first < a[i].first) {         ++p1;       }       while (p2 < n && b[p2].first < a[i].first + 1.0 * m / 2) {         ++p2;       }       int beg = n - i;       sum[beg + 0] += m - a[i].first;       sum[beg + p0] -= m - a[i].first;       sum[beg + p0] += a[i].first;       sum[beg + p1] -= a[i].first;       sum[beg + p1] += -a[i].first;       sum[beg + p2] -= -a[i].first;       sum[beg + p2] += m + a[i].first;       sum[beg + n] -= m + a[i].first;     }     for (int i = 1; i < n * 2; ++i) {       sum[i] += sum[i - 1];     }     for (int i = 0; i < n; ++i) {       sum[i] += sum[i + n];     }     vector<long long> rsum;     rsum.resize(n * 2 + 1);     for (int i = 0; i < n * 2 + 1; ++i) {       rsum[i] = 0;     }     for (int i = 0, p0 = 0, p1 = 0, p2 = 0; i < n; ++i) {       while (p0 < n && a[p0].first <= b[i].first - 1.0 * m / 2) {         ++p0;       }       while (p1 < n && a[p1].first <= b[i].first) {         ++p1;       }       while (p2 < n && a[p2].first <= b[i].first + 1.0 * m / 2) {         ++p2;       }       int beg = n - i - 1;       rsum[beg + 0] += -b[i].first;       rsum[beg + p0] -= -b[i].first;       rsum[beg + p0] += b[i].first;       rsum[beg + p1] -= b[i].first;       rsum[beg + p1] += -b[i].first;       rsum[beg + p2] -= -b[i].first;       rsum[beg + p2] += b[i].first;       rsum[beg + n] -= b[i].first;     }     for (int i = 1; i < n * 2; ++i) {       rsum[i] += rsum[i - 1];     }     for (int i = 0; i < n; ++i) {       rsum[i] += rsum[i + n];     }     vector<long long> cost;     cost.resize(n);     for (int i = 0; i < n; ++i) {       cost[i] = sum[i] + rsum[n - 1 - i];     }     long long cur = (long long)(1e18);     int pos;     for (int i = 0; i < n; ++i) {       if (cost[i] < cur) {         cur = cost[i];         pos = i;       }     }     cout << cur << endl;     vector<int> at;     at.resize(n);     for (int i = 0; i < n; ++i) {       at[a[i].second] = b[(i + pos) % n].second;     }     for (int i = 0; i < n; ++i) {       cout << at[i] + 1 <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int getFldsFromLine(char *line, std::vector<char *> &res,                       const char *sep =    t n v f r );   int main(int argc, char **argv) {     FILE *infile = stdin;     char *line;     line = (char *)calloc(5000000, sizeof(char));     if (line == NULL) {       fprintf(stderr,  Couldn t allocate space for  %s  nBye! n ,  line );       exit(-1);     };     std::vector<char *> flds;     int numFlds, numCases, caseNum = 0;     fgets(line, 5000000, infile);     numFlds = getFldsFromLine(line, flds);     numCases = atoi(flds[0]);     bool isGood = false;     for (caseNum = 1; caseNum <= numCases; ++caseNum) {       fgets(line, 5000000, infile);       numFlds = getFldsFromLine(line, flds);       int num1 = atoi(flds[1]), num2 = atoi(flds[2]);       if ((num1 >= 2400) && (num2 > num1)) isGood = true;     }     if (isGood)       printf( YES n );     else       printf( NO n );     return (0);   }   int getFldsFromLine(char *line, std::vector<char *> &res, const char *sep) {     res.clear();     char *tok = strtok(line, sep);     while (tok) {       res.push_back(tok);       tok = strtok(0, sep);     }     return res.size();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, j, i, l, r, ans = 0, x, y, minimum;     scanf( %d , &n);     scanf( %d , &k);     int count_a[n], count_b[n];     char str[n + 1], ch;     scanf( %s , str);     for (i = 0; i < n; i++) {       count_a[i] = 0;       count_b[i] = 0;     }     for (i = 0; i < n; i++) {       if (str[i] ==  a ) count_a[i]++;       if (str[i] ==  b ) count_b[i]++;     }     for (i = 1; i < n; i++) {       count_a[i] += count_a[i - 1];       count_b[i] += count_b[i - 1];     }     l = 0;     r = 0;     while (r < n) {       if (l == 0) {         x = count_a[r];         y = count_b[r];       } else {         x = count_a[r] - count_a[l - 1];         y = count_b[r] - count_b[l - 1];       }       minimum = min(x, y);       if (k >= minimum) {         ans = max(ans, r - l + 1);         r++;       } else         l++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( Ofast )   using namespace std;   const long long INF64 = 1e18;   const long long INF32 = 1e9;   const double EPS = static_cast<double>(1e-10);   const double PI = 2.0 * acos(0.0);   const long long MOD = (long long)1e9 + 7;   long long powMod(long long a, long long b) {     long long res = 1;     a %= MOD;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % MOD;       a = a * a % MOD;     }     return res;   }   long long invMod(long long a) {     long long b = MOD, u = 1, v = 0;     while (b) {       long long t = a / b;       a -= t * b;       swap(a, b);       u -= t * v;       swap(u, v);     }     return (MOD + u) % MOD;   }   const long long day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   mt19937 rnd(239);   vector<long long> prefixSum(vector<long long> &a) {     vector<long long> b;     std::partial_sum(a.begin(), a.end(), b.begin());     return b;   }   long long mostSignDigit(long long n) {     double k = log10(n);     return (long long)pow(10, k - floor(k));   }   long long numOfDigits(long long n) { return (long long)floor(log10(n)) + 1; }   bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); }   bool allPositive(vector<long long> &a) {     return all_of(begin(a), end(a), [](long long x) { return x > 0; });   }   bool anyPositive(vector<long long> &a) {     return any_of(begin(a), end(a), [](long long x) { return x > 0; });   }   bool nonePositive(vector<long long> &a) {     return none_of(begin(a), end(a), [](long long x) { return x > 0; });   }   void FILEIO() {     freopen( in.txt ,  r , stdin);     freopen( out.txt ,  w , stdout);   }   void __print(long long x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  T  :  F ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     long long f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   vector<vector<long long>> adj;   vector<long long> lvl;   vector<long long> par;   void dfs(long long vertex) {     for (long long nxt : adj[vertex]) {       if (lvl[nxt] == 0) {         par[nxt] = vertex;         lvl[nxt] = lvl[vertex] + 1;         dfs(nxt);       }     }   }   void init(long long n) {     adj.clear();     adj.assign(n, vector<long long>());     lvl.clear();     lvl.resize(n);     par.clear();     par.resize(n);   }   void DFS() {     lvl[0] = 1;     dfs(0);   }   void solve() {     long long n, m;     cin >> n >> m;     init(n);     for (long long i = (0); i < (m); i++) {       long long u, v;       cin >> u >> v;       u--, v--;       adj[u].push_back(v);       adj[v].push_back(u);     };     DFS();     ;     ;     long long mx = -1, umx = 0;     for (long long u = (0); u < (n); u++) {       if (lvl[u] > mx) {         umx = u;         mx = lvl[u];       }     }     if (mx >= (n + 1) / 2) {       vector<long long> ans;       long long u = umx;       for (long long i = (0); i < (mx); i++) {         if (((long long)(ans).size()) >= (n + 1) / 2) break;         ans.push_back(u);         u = par[u];       }       reverse(begin(ans), end(ans));       cout <<  PATH  << endl;       cout << ((long long)(ans).size()) << endl;       for (long long i = (0); i < (((long long)(ans).size())); i++)         cout << ans[i] + 1 <<    ;       cout << endl;     } else {       vector<vector<long long>> lvlvec(mx);       for (long long u = (0); u < (n); u++) lvlvec[lvl[u] - 1].push_back(u);       ;       vector<pair<long long, long long>> ans;       for (long long i = (0); i < (mx); i++) {         vector<long long> vc = lvlvec[i];         for (long long j = (0); j < (((long long)(vc).size()) / 2); j++) {           long long a = vc[2 * j], b = vc[2 * j + 1];           ans.push_back(make_pair(a, b));         }         if (((long long)(ans).size()) * 2 >= (n + 1) / 2) break;       }       cout <<  PAIRING  << endl;       cout << ((long long)(ans).size()) << endl;       for (long long i = (0); i < (((long long)(ans).size())); i++) {         cout << ans[i].first + 1 <<     << ans[i].second + 1 <<   n ;       }     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie();     long long t;     cin >> t;     for (long long i = (1); i <= (t); i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   int n, q, a, b, blo, arr[N];   struct node {     int a, b, id;   } qq[N];   long long ans[N], dp[N];   bool cmp(node a, node b) {     if (a.b != b.b) return a.b > b.b;     return a.a < b.a;   }   int main() {     scanf( %d , &n);     blo = sqrt(n);     for (int i = 1; i <= n; i++) scanf( %d , &arr[i]);     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       scanf( %d%d , &qq[i].a, &qq[i].b);       qq[i].id = i;     }     sort(qq + 1, qq + q + 1, cmp);     int n_b = -1;     for (int i = 1; i <= q; i++) {       node nn = qq[i];       if (nn.b >= blo) {         for (int i = nn.a; i <= n; i += nn.b) ans[nn.id] += arr[i];       } else {         if (nn.b != n_b || dp[nn.a] == 0) {           for (int j = n; j >= 1; j--) {             if (j + nn.b > n)               dp[j] = arr[j];             else               dp[j] = dp[j + nn.b] + arr[j];           }           n_b = nn.b;         }         ans[nn.id] = dp[nn.a];       }     }     for (int i = 1; i <= q; i++) {       printf( %I64d n , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int stones, counter = 0;     string colours;     cin >> stones;     cin >> colours;     for (int i = 0; i < stones - 1; i++) {       if (colours[i] == colours[i + 1]) {         counter++;       }     }     cout << counter << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool possible(int smaller, int bigger) { return (bigger <= smaller * 3 + 1); }   int main() {     ios::sync_with_stdio(false);     int q;     cin >> q;     for (int i = 0; i < q; ++i) {       int b, w;       cin >> b >> w;       if ((b < w && !possible(b, w)) || (w < b && !possible(w, b))) {         cout <<  NO  << endl;         continue;       }       cout <<  YES  << endl;       int offset = (b < w) ? 1 : 0;       if (b < w) swap(b, w);       int column = 1;       while (w + 1 < b) {         cout << column <<     << (2 + offset) << endl;         column++;         cout << column <<     << (1 + offset) << endl;         cout << column <<     << (2 + offset) << endl;         cout << column <<     << (3 + offset) << endl;         column++;         w -= 1;         b -= 3;       }       if (w < b) {         cout << column <<     << (2 + offset) << endl;         b--;         column++;       }       for (; 0 < b; b--) {         cout << column <<     << (1 + offset) << endl;         cout << column <<     << (2 + offset) << endl;         column++;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int man = 0, ans = 0, n, m;     int a[1000];     while (cin >> n >> m) {       ans = 0;       if (n > m) {         printf( %d n , n - m);       } else {         while (n < m) {           if (m % 2 != 0) {             m++;             ans++;           }           m /= 2;           ans++;         }         ans += n - m;         printf( %d n , ans);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const double pi = acos(-1);   const long long int INF = 1e18;   const int inf = 1e9;   const int MOD = 1e9 + 7;   const int nax = 1000000 + 10;   int n, arr[nax];   int main() {     ios::sync_with_stdio(0);     cin >> n;     if (n % 10 == 0) {       cout << n;       return 0;     }     if (n <= 5)       cout << 0;     else {       int div = (n + 10 - 1) / 10;       int ans = 10 * div;       int rem = (n % 10);       if (rem <= 5) ans -= 10;       cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     scanf( %d %d , &n, &k);     if (k > (n * n + 1) / 2) {       printf( NO );       return 0;     }     int i, j, count = 0;     printf( YES n );     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if ((i + j) % 2 == 0 and count < k) {           count++;           printf( L );         } else           printf( S );       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 36;   long long dp[maxn][maxn];   int main() {     long long n, h;     cin >> n >> h;     for (long long i = 0; i <= n; i++) dp[0][i] = 1;     for (long long i = 1; i <= n; i++)       for (long long j = 1; j <= n; j++)         for (long long k = 0; k < i; k++) {           dp[i][j] += dp[k][j - 1] * dp[i - 1 - k][j - 1];         }     cout << dp[n][n] - dp[n][h - 1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string ans1, ans2;     string s1, s2, ss1, ss2;     int a, b;     cin >> s1 >> s2;     a = atoi(s1.c_str()) + atoi(s2.c_str());     stringstream ss;     ss << a;     ss >> ans1;     for (int i = 0; i < s1.length(); ++i) {       if (s1[i] !=  0 ) {         ss1 += s1[i];       }     }     for (int i = 0; i < ans1.length(); ++i) {       if (ans1[i] !=  0 ) {         ans2 += ans1[i];       }     }     for (int i = 0; i < s2.length(); ++i) {       if (s2[i] !=  0 ) {         ss2 += s2[i];       }     }     b = atoi(ss1.c_str()) + atoi(ss2.c_str());     stringstream sss;     sss << b;     sss >> ans1;     if (ans1 == ans2) {       cout <<  YES ;     } else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long mod, dp[18][250005];   unsigned long long fac[250005], inv[250005];   unsigned long long n, k;   inline unsigned long long qpow(unsigned long long a, unsigned long long b) {     unsigned long long res = 1ll, tp = a;     while (b) {       if (b & 1ll) {         res *= tp;         res %= mod;       }       tp *= tp;       tp %= mod;       b >>= 1ll;     }     return res;   }   inline unsigned long long cal(int a, int b) {     return (((fac[a] * inv[b]) % mod) * inv[a - b]) % mod;   }   inline unsigned long long calc() {     int i, j, l;     fac[0] = 1ll;     for (i = 1; i <= n; i++)       fac[i] = fac[i - 1] * ((unsigned long long)(i)) % mod;     inv[n] = qpow(fac[n], mod - 2ll);     for (i = n - 1; i >= 0; i--)       inv[i] = inv[i + 1] * ((unsigned long long)(i + 1)) % mod;     for (i = 1; i <= n; i++) {       dp[1][i] = inv[i];     }     unsigned long long ans = dp[1][n] * cal(k, 1) % mod;     int t = min(17, ((int)(k)));     for (i = 2; i <= t; i++) {       for (j = 1; j <= n; j++) {         if ((j & n) != j) {           continue;         }         int cnt = 0;         for (l = j; l; l = (l - 1) & j) {           dp[i][j] += dp[i - 1][j ^ l] * inv[l];           cnt++;           if (cnt == 18) {             cnt = 0;             dp[i][j] %= mod;           }         }         dp[i][j] %= mod;       }       ans += dp[i][n] * cal(k, i);       ans %= mod;     }     ans *= fac[n];     ans %= mod;     return ans;   }   int main() {     cin >> n >> k >> mod;     unsigned long long ans = qpow(k, n);     if (n & 1) {       cout << ans << endl;       return 0;     }     ans = (ans - calc() + mod) % mod;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   static const long long maxn = 2005;   long long M[maxn][maxn];   long long MyM[maxn][maxn];   vector<vector<long long>*> graph;   long long dsu[maxn];   bool PreCheck() {     for (long long i = 0; i < n; i++) {       if (M[i][i] != 0) return false;     }     for (long long i = 0; i < n; i++)       for (long long j = 0; j < n; j++) {         if (M[i][j] != M[j][i]) return false;       }     return true;   }   long long edge_count = 0;   struct edge {     long long u;     long long v;     long long d;     bool operator<(const edge& rhs) const { return d < rhs.d; }   };   long long dsu_root(long long i) {     while (dsu[i] != i) {       dsu[i] = dsu[dsu[i]];       i = dsu[i];     }     return i;   }   bool dsu_connected(long long i, long long j) {     return dsu_root(i) == dsu_root(j);   }   void dsu_join(long long i, long long j) {     long long r = rand() % 2;     if (r)       dsu[dsu_root(i)] = j;     else       dsu[dsu_root(j)] = i;   }   void init() {     for (long long i = 0; i < n; i++) {       dsu[i] = i;       vector<long long>* v = new vector<long long>();       graph.push_back(v);     }   }   bool dfs_visited[maxn];   void dfs(long long i, long long root, long long curr) {     if (dfs_visited[i]) return;     dfs_visited[i] = true;     for (auto it : *graph[i]) {       if (dfs_visited[it])         continue;       else {         long long d = curr + M[i][it];         MyM[root][it] = d;         MyM[it][root] = d;         dfs(it, root, d);       }     }   }   bool FinalCheck() {     for (long long i = 1; i < n; i++) {       if (!dsu_connected(i, 0)) return false;     }     for (long long i = 0; i < n; i++)       for (long long j = 0; j < i; j++) {         if (M[i][j] != MyM[i][j]) return false;       }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     init();     for (long long i = 0; i < n; i++)       for (long long j = 0; j < n; j++) {         cin >> M[i][j];         MyM[i][j] = 0;       }     if (!PreCheck()) {       cout <<  NO  << endl;       return 0;     }     vector<edge> edges;     for (long long i = 0; i < n; i++)       for (long long j = 0; j < i; j++) {         edge curr;         curr.u = i;         curr.v = j;         curr.d = M[i][j];         if (curr.d > 0) edges.push_back(curr);       }     sort(edges.begin(), edges.end());     for (auto it : edges) {       if (!dsu_connected(it.u, it.v)) {         edge_count++;         graph[it.u]->push_back(it.v);         graph[it.v]->push_back(it.u);         dsu_join(it.u, it.v);       }     }     if (edge_count != n - 1) {       cout <<  NO  << endl;       return 0;     }     for (long long i = 0; i < n; i++) {       memset(dfs_visited, 0, sizeof(dfs_visited));       dfs(i, i, 0);     }     if (FinalCheck()) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 200005;   int l[MAX_N], r[MAX_N];   int a[MAX_N];   int n;   int F[MAX_N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) {       l[i] = i;       while (a[l[i] - 1] >= a[i]) l[i] = l[l[i] - 1];     }     for (int i = n; i >= 1; i--) {       r[i] = i;       while (a[r[i] + 1] >= a[i]) r[i] = r[r[i] + 1];     }     for (int i = 1; i <= n; i++)       F[r[i] - l[i] + 1] = max(F[r[i] - l[i] + 1], a[i]);     for (int i = n; i >= 1; i--) F[i] = max(F[i], F[i + 1]);     for (int i = 1; i <= n; i++) printf( %d  , F[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace FFT {   const int N = 20;   const int MAXN = (1 << N);   class cmplx {    private:     double x, y;       public:     cmplx() : x(0.0), y(0.0) {}     cmplx(double a) : x(a), y(0.0) {}     cmplx(double a, double b) : x(a), y(b) {}     double get_real() { return this->x; }     double get_img() { return this->y; }     cmplx conj() { return cmplx(this->x, -(this->y)); }     cmplx operator=(const cmplx& a) {       this->x = a.x;       this->y = a.y;       return *this;     }     cmplx operator+(const cmplx& b) {       return cmplx(this->x + b.x, this->y + b.y);     }     cmplx operator-(const cmplx& b) {       return cmplx(this->x - b.x, this->y - b.y);     }     cmplx operator*(const double& num) {       return cmplx(this->x * num, this->y * num);     }     cmplx operator/(const double& num) {       return cmplx(this->x / num, this->y / num);     }     cmplx operator*(const cmplx& b) {       return cmplx(this->x * b.x - this->y * b.y, this->y * b.x + this->x * b.y);     }     cmplx operator/(const cmplx& b) {       cmplx temp(b.x, -b.y);       cmplx n = (*this) * temp;       return n / (b.x * b.x + b.y * b.y);     }   };   cmplx w[MAXN];   cmplx f1[MAXN];   int rev[MAXN];   void ReserveBits(int k) {     static int rk = -1, lim;     if (k == rk) return;     rk = k, lim = 1 << k;     for (int i = 1; i <= lim; ++i) {       int j = rev[i - 1], t = k - 1;       while (t >= 0 && ((j >> t) & 1)) {         j ^= 1 << t;         --t;       }       if (t >= 0) {         j ^= 1 << t;         --t;       }       rev[i] = j;     }   }   void fft(cmplx* a, int k) {     ReserveBits(k);     int n = 1 << k;     for (int i = 0; i < n; ++i)       if (rev[i] > i) swap(a[i], a[rev[i]]);     for (int l = 2, m = 1; l <= n; l += l, m += m) {       if (w[m].get_real() == 0 && w[m].get_img() == 0) {         double angle = M_PI / m;         cmplx ww(cos(angle), sin(angle));         if (m > 1) {           for (int j = 0; j < m; ++j) {             if (j & 1)               w[m + j] = w[(m + j) / 2] * ww;             else               w[m + j] = w[(m + j) / 2];           }         } else           w[m] = cmplx(1, 0);       }       for (int i = 0; i < n; i += l) {         for (int j = 0; j < m; ++j) {           cmplx v = a[i + j], u = a[i + j + m] * w[m + j];           a[i + j] = v + u;           a[i + j + m] = v - u;         }       }     }   }   vector<long long> mul(vector<long long> a, vector<long long> b) {     int k = 1;     while ((1 << k) < (a.size() + b.size())) ++k;     int n = (1 << k);     for (int i = 0; i < n; ++i) f1[i] = cmplx(0, 0);     for (int i = 0; i < a.size(); ++i) f1[i] = f1[i] + cmplx(a[i], 0);     for (int i = 0; i < b.size(); ++i) f1[i] = f1[i] + cmplx(0, b[i]);     fft(f1, k);     for (int i = 0; i <= n / 2; ++i) {       cmplx p = f1[i] + f1[(n - i) % n].conj();       cmplx _q = f1[(n - i) % n] - f1[i].conj();       cmplx q(_q.get_img(), _q.get_real());       f1[i] = (p * q) * 0.25;       if (i > 0) f1[(n - i)] = f1[i].conj();     }     for (int i = 0; i < n; ++i) f1[i] = f1[i].conj();     fft(f1, k);     vector<long long> ans(a.size() + b.size() - 1);     for (int i = 0; i < ans.size(); ++i) {       ans[i] = (long long)(f1[i].get_real() / n + 0.5);     }     return ans;   }   };  // namespace FFT   int buff = 2e5 + 5;   int main() {     ios_base::sync_with_stdio(false);     long long int n, x;     long long int an[200005];     cin >> n >> x;     long long int nn = 2 * buff + 5;     vector<long long int> v(nn, 0);     vector<long long int> v1(nn, 0);     v[0] = 1;     v1[buff] = 1;     long long int cool = 0;     for (int i = 0; i <= n - 1; i++) {       long long int xx;       cin >> xx;       if (xx < x) cool++;       an[0] += v[cool];       v[cool]++;       v1[buff - cool]++;     }     vector<long long int> res = FFT::mul(v, v1);     int sz = res.size();     an[0] = (n * (n + 1)) / 2;     for (int i = buff + 1; i <= buff + n; i++) {       an[i - buff] = res[i];       an[0] -= res[i];     }     for (int i = 0; i <= n; i++) {       cout << an[i];       cout <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int h;     long long n, l = 1, r, rpta = 0, aux2;     cin >> h >> n;     r = 1LL << h;     aux2 = r;     int aux = 1;     while (r > l) {       rpta++;       long long m = (l + r) / 2;       if (n <= m && aux == 0) {         rpta += aux2 - 1;       } else if (n > m && aux == 1) {         rpta += aux2 - 1;       } else         aux ^= 1;       if (n <= m)         r = m;       else         l = m + 1;       aux2 >>= 1;     }     cout << rpta << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = (int)1e3 + 10;   int a[MaxN][MaxN];   int main() {     int n, i, m, k, x, y, j;     char c;     scanf( %d%d%d n , &n, &m, &k);     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) scanf( %d , &a[i][j]);     scanf(  n );     for (i = 1; i <= m; i++) a[0][i] = i;     for (i = 1; i <= n; i++) a[i][0] = i;     for (i = 1; i <= k; i++) {       scanf( %c , &c);       if (c ==  c ) {         scanf( %d%d n , &x, &y);         swap(a[0][x], a[0][y]);       }       if (c ==  r ) {         scanf( %d%d n , &x, &y);         swap(a[x][0], a[y][0]);       }       if (c ==  g ) {         scanf( %d%d n , &x, &y);         printf( %d n , a[a[x][0]][a[0][y]]);       }     }     cin.get();     cin.get();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const int M = 1e4 + 10;   const int MOD = 1e9 + 7;   const int inf = 1e9;   const double pi = acos(-1.0);   const double eps = 1e-6;   int dx[] = {0, -1, 0, 1};   int dy[] = {1, 0, -1, 0};   int n, m;   int a[101];   int sum[102];   int l, r;   int res;   int main() {     cin >> n >> m;     sum[0] = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       sum[i + 1] += sum[i] + a[i];     }     for (int i = 0; i < m; i++) {       cin >> l >> r;       int v = sum[r] - sum[l - 1];       if (v > 0) res += v;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T& s) {     s = 0;     int f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       s = s * 10 + c -  0 ;       c = getchar();     }     s *= f;   }   void exkmp(char* s, char* t, int n, int m, int* f, int* g) {     int mx = 0;     f[1] = n;     for (int i = 2; i <= m; i++) {       f[i] = max(0, min(mx + f[mx] - i, f[i - mx + 1]));       while (i + f[i] <= m && t[i + f[i]] == t[f[i] + 1]) f[i]++;       if (i + f[i] > mx + f[mx]) mx = i;     }     mx = 0;     for (int i = 1; i <= n; i++) {       g[i] = max(0, min(f[i - mx + 1], mx + g[mx] - i));       while (i + g[i] <= n && s[i + g[i]] == t[g[i] + 1]) g[i]++;       if (i + g[i] > mx + g[mx]) mx = i;     }   }   int n, m;   char a[1000005], b[1000005], at[1000005];   int f[1000005], g1[1000005], g2[1000005];   int mxw[1000005];   int main() {     n = m = 1;     char c = getchar();     while (c !=   n ) {       a[n++] = c;       c = getchar();     }     c = getchar();     while (c !=   n ) {       b[m++] = c;       c = getchar();     }     n--;     m--;     if (n != m) {       printf( -1 -1 n );       return 0;     }     if (a[1] != b[n]) {       printf( -1 -1 n );       return 0;     }     int mxi = 1;     for (mxi; mxi < n && a[mxi + 1] == b[n - mxi]; mxi++)       ;     for (int i = 1; i <= m; i++) at[i] = a[m + 1 - i];     exkmp(a, b, n, m, f, g1);     exkmp(b, at, n, m, f, g2);     memset(mxw, 23, sizeof(mxw));     for (int i = 1; i <= n; i++)       mxw[1 + n - g2[i] - i] = min(mxw[1 + n - g2[i] - i], i);     for (int i = 1; i <= n; i++) mxw[i] = min(mxw[i], mxw[i - 1]);     for (int i = mxi; i >= 1; i--) {       int mx = min(g1[i + 1] + 1, n - i);       int gg = mxw[i];       if (gg > mx) continue;       printf( %d %d n , i - 1, gg + i - 1);       return 0;     }     printf( -1 -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   int n, i, j, o, ans, cnt, num;   double a, b, c, d, first[1010], second[1010], p, q, r;   pair<pair<double, double>, double> m[1010 * 1010];   bool cmp(pair<pair<double, double>, double> a,            pair<pair<double, double>, double> b) {     if (fabs(a.first.first - b.first.first) > 1e-8)       return a.first.first < b.first.first;     if (fabs(a.first.second - b.first.second) > 1e-8)       return a.first.second < b.first.second;     return a.second < b.second;   }   int main() {     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %lf %lf %lf %lf , &a, &b, &c, &d);       p = a / b, q = c / d;       r = p * p + q * q;       first[i] = p / r, second[i] = q / r;     }     for (i = 0; i < n; i++) {       for (j = i + 1; j < n; j++) {         p = first[i] + first[j], q = second[i] + second[j];         m[o++] = pair<pair<double, double>, double>(             pair<double, double>(p, q),             fabs(first[i] - first[j]) < 1e-8                 ? 0x3f3f3f3f                 : (second[i] - second[j]) / (first[i] - first[j]));       }     }     sort(m, m + o, cmp);     for (i = 0; i < o; i = j) {       cnt = num = 1;       for (j = i + 1; j < o; j++) {         if (fabs(m[j].first.first - m[j - 1].first.first) > 1e-8) break;         if (fabs(m[j].first.second - m[j - 1].first.second) > 1e-8) break;         if (fabs(m[j].second - m[j - 1].second) > 1e-8) {           cnt = (long long)cnt * (num + 1) % 1000000007;           num = 1;         } else           num++;       }       cnt = (long long)cnt * (num + 1) % 1000000007;       ans = (ans + cnt) % 1000000007;       ans = (ans + 1000000007 - (j - i + 1)) % 1000000007;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   int main() {     long n;     scanf( %ld , &n);     std::vector<long> a(n);     for (long p = 0; p < n; p++) {       scanf( %ld , &a[p]);     }     sort(a.begin(), a.end());     long cur(0);     for (long p = 0; p < n; p++) {       if (a[p] >= cur + 1) {         ++cur;       }     }     printf( %ld n , cur);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-9;   const int inf = (1 << 30) - 1;   const long long inf64 = ((long long)1 << 62) - 1;   const long double pi = acos(-1);   template <class T>   T sqr(T x) {     return x * x;   }   template <class T>   T abs(T x) {     return x < 0 ? -x : x;   }   template <class T>   vector<T> ReadVector(int n) {     vector<T> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     return a;   }   template <class T>   void WriteVector(const vector<T>& a) {     for (int i = 0; i < ((int)(a).size()); ++i) {       cout << a[i] << (i + 1 < ((int)(a).size()) ?     :   n );     }   }   void Solve() {     long long x;     cin >> x;     vector<long long> a;     a.push_back(x);     vector<string> res;     while (a[0] != 1) {       long long val = -1;       for (int i = 0; i < ((int)(a).size()); ++i) {         for (int j = 0; j <= i; ++j) {           long long tmp = a[i] + a[j];           val = tmp;           for (int k = ((int)(a).size()) - 1; k >= 0; --k) {             tmp = min(tmp, tmp ^ a[k]);           }           if (tmp > 0) {             res.push_back(to_string(a[i]) +   +   + to_string(a[j]));             break;           }           val = -1;         }         if (val > 0) {           break;         }       }       for (int i = ((int)(a).size()) - 1; i >= 0; --i) {         if ((val ^ a[i]) < val) {           res.push_back(to_string(a[i]) +   ^   + to_string(val));           val ^= a[i];         }       }       for (int i = 0; i < ((int)(a).size()); ++i) {         if ((a[i] ^ val) < a[i]) {           res.push_back(to_string(a[i]) +   ^   + to_string(val));           a[i] ^= val;         }       }       a.push_back(val);       sort((a).begin(), (a).end());     }     cout << ((int)(res).size()) <<   n ;     for (int i = 0; i < ((int)(res).size()); ++i) {       cout << res[i] <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     std::cin.tie(nullptr);     int tc = 1;     for (int ti = 0; ti < tc; ++ti) {       Solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char ara[100005];   map<int, int> mp;   int main() {     int t, test;     long long a, b, c, n;     char ch;     double d;     gets(ara);     t = strlen(ara);     int aa = ara[t - 1] -  0 ;     int bb = ara[t - 2] -  0 ;     aa += (bb * 10);     if (aa % 4 == 0) {       cout <<  4 n ;     } else {       cout <<  0 n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int ans;   int a[2002], b[2002];   int le;   int p;   int ssearch(int x) {     int maxd = 0;     for (int i = 1; i <= n; i++) {       int z = abs(a[i] - b[x - le + i]) + abs(b[x - le + i] - p);       if (z > maxd) maxd = z;     }     return maxd;   }   int main() {     int k;     scanf( %d%d%d , &n, &k, &p);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= k; i++) {       scanf( %d , &b[i]);     }     sort(a + 1, a + 1 + n);     sort(b + 1, b + 1 + k);     le = n;     for (int i = 1; i <= n; i++)       if (a[i] >= p) {         le = i - 1;         break;       }     ans = 2147483647;     for (int i = le; i <= k + le - n; i++) {       int y = ssearch(i);       if (y < ans) ans = y;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   #define ull unsigned long long   #define ll long long   #define il inline   #define db double   #define ls rt << 1   #define rs rt << 1 | 1   #define pb push_back   #define mp make_pair   #define pii pair<int, int>   #define X first   #define Y second   #define pcc pair<char, char>   #define vi vector<int>   #define vl vector<ll>   #define rep(i, x, y) for(int i = x; i <= y; i ++)   #define rrep(i, x, y) for(int i = x; i >= y; i --)   #define rep0(i, n) for(int i = 0; i < (n); i ++)   #define per0(i, n) for(int i = (n) - 1; i >= 0; i --)   #define ept 1e-9   #define sz(x) (x).size()   #define All(x) (x).begin(), (x).end()   using namespace std;   inline int read()   {    int x = 0, f = 1; char ch = getchar();    while (ch <  0  || ch >  9 ) { if (ch ==  - ) f = -1; ch = getchar(); }    while (ch >=  0  && ch <=  9 ) { x = x * 10 + ch -  0 ; ch = getchar(); }    return x * f;   }   inline ll read1()   {    ll x = 0, f = 1; char ch = getchar();    while (ch <  0  || ch >  9 ) { if (ch ==  - ) f = -1; ch = getchar(); }    while (ch >=  0  && ch <=  9 ) { x = x * 10 + ch -  0 ; ch = getchar(); }    return x * f;   }   #define int long long   const int N = 50010;   const int mod = 998244353;   int n, m;   int d[N][25];   void add(int &a, int b) {a += b; if (a >= mod) a -= mod;}   void dec(int &a, int b) {a -= b; if (a < 0) a += mod;}   int pow_mod(int a, int i)   {    int s = 1;    while (i)    {     if (i & 1) s = 1LL * s * a % mod;     a = 1LL * a * a % mod;     i >>= 1;    }    return s;   }   signed main()   {    n = read();    m = read();    rep0(i, n)     rep0(j, m)      d[j][i] = read();    rep0(i, m) sort(d[i], d[i] + n);    int ans = m;    int jc = 1;    rep(i, 1, n) jc = 1LL * jc * i % mod;    jc = pow_mod(jc, mod - 2);    rep0(i, m)    {     int res = 1;     rrep(j, n - 1, 0) res = 1LL * res * max(0LL, d[i][j] - (j + 1)) % mod;     dec(ans, 1LL * res * jc % mod);    }    printf( %d n , ans);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int count1(int x) {     int ans = 0;     while (x) {       ans += x & 1;       x >>= 1;     }     return ans;   }   int main() {     int n, p;     cin >> n >> p;     for (int x = 0; x * (p + 1) <= n; x++)       if (count1(n - x * p) <= x) {         cout << x;         return 0;       }     cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   using vi = vector<int>;   using vll = vector<ll>;   using vii = vector<ii>;   const ll MOD = 998244353;   const ll INF = 1e18 + 9;   const int MAXN = 1000006;   const int MAXC = 20;   int n, arr[MAXN], num[MAXC];   ll dist[MAXC][MAXC], mem[1 << MAXC], realDist[1 << MAXC][MAXC];   ll solve(int p) {     if (mem[p] != -1) return mem[p];     mem[p] = INF;     for (int i = 0; i < MAXC; i++) {       if ((p & (1 << i)) == 0) {         mem[p] = min(mem[p], solve(p | (1 << i)) + realDist[p][i]);       }     }     return mem[p];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];       arr[i]--;       for (int j = 0; j < MAXC; j++) {         dist[arr[i]][j] += num[j];       }       num[arr[i]]++;     }     int p = 0;     for (int i = 0; i < (1 << MAXC); i++) {       for (int j = 0; j < MAXC; j++) {         for (int k = 0; k < MAXC; k++) {           if (i & (1 << k)) realDist[i][j] += dist[k][j];         }       }     }     memset(mem, -1, sizeof(mem));     ll ans = INF;     mem[(1 << MAXC) - 1] = 0;     for (int i = 0; i < MAXC; i++) {       ans = min(ans, solve(p | (1 << i)));     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long a[3000], b[3000];   map<long long, pair<long long, long long> > mymap;   pair<long long, long long> p1, p2;   int main() {     std::ios::sync_with_stdio(false);     long long n, m, sa = 0, sb = 0;     p1.first = p1.second = p2.first = p2.second = -1;     mymap.clear();     cin >> n;     for (long long i = (long long)(1); i <= (long long)(n); i++) {       cin >> a[i];       sa += a[i];     }     cin >> m;     for (long long i = (long long)(1); i <= (long long)(m); i++) {       cin >> b[i];       sb += b[i];     }     long long curdiff = abs(sa - sb);     for (long long i = (long long)(1); i <= (long long)(n); i++) {       for (long long j = (long long)(1); j <= (long long)(m); j++) {         long long tmpsa, tmpsb;         tmpsa = sa - a[i] + b[j];         tmpsb = sb + a[i] - b[j];         if (abs(tmpsa - tmpsb) < curdiff) {           curdiff = abs(tmpsa - tmpsb);           p1.first = i;           p1.second = j;         }       }     }     for (long long i = (long long)(1); i <= (long long)(n - 1); i++) {       for (long long j = (long long)(i + 1); j <= (long long)(n); j++) {         long long val = a[i] + a[j];         val = val * 2ll;         mymap[val] = make_pair(i, j);       }     }     map<long long, pair<long long, long long> >::iterator it;     for (long long i = (long long)(1); i <= (long long)(m - 1); i++) {       for (long long j = (long long)(i + 1); j <= (long long)(m); j++) {         long long val = sa - sb + 2 * (b[i] + b[j]);         it = mymap.lower_bound(val);         if (it != mymap.begin()) it--;         if (it == mymap.end()) continue;         long long temp = val;         temp = abs(val - it->first);         if (temp < curdiff) {           curdiff = temp;           p1.first = (it->second).first;           p1.second = i;           p2.first = (it->second).second;           p2.second = j;         }         it++;         if (it != mymap.end()) {           temp = abs(val - it->first);           if (temp < curdiff) {             curdiff = temp;             p1.first = (it->second).first;             p1.second = i;             p2.first = (it->second).second;             p2.second = j;           }         }       }     }     cout << curdiff << endl;     if (p2.first != -1) {       cout <<  2  << endl;       cout << p1.first <<     << p1.second << endl;       cout << p2.first <<     << p2.second << endl;     } else if (p1.first != -1) {       cout <<  1  << endl;       cout << p1.first <<     << p1.second << endl;     } else {       cout <<  0  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       vector<int> vt;       while (n) {         int lst = -1;         for (int i = 2;; i++) {           if (1ll * i * (i - 1) / 2 <= n)             lst = i;           else             break;         }         vt.push_back(lst);         n -= 1ll * lst * (lst - 1) / 2;       }       int maxi = vt[0];       reverse(vt.begin(), vt.end());       printf( 1 );       int x = 0, sum = 0;       for (int i = 1; i <= maxi; i++) {         printf( 3 );         while (x < vt.size() && i == vt[x]) {           printf( 7 );           x++;         }       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000 + 50;   int n, cnt[maxn], a[maxn];   vector<int> q;   int main() {     cin >> n;     int sign = 0;     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       if (x > y) swap(x, y);       if (y != n) sign = 1;       cnt[x]++;       a[i] = x;     }     sort(a + 1, a + n);     for (int i = 1; i < n; i++) {       if (a[i] < i) {         sign = 1;       }     }     if (sign) {       cout <<  NO  << endl;       return 0;     }     cout <<  YES  << endl;     for (int i = 1; i < n; i++) {       if (cnt[i]) {         q.push_back(i);       }     }     int opt = 1;     for (int x = 0; x < q.size(); x++) {       int pre = n;       for (int i = 1; i <= cnt[q[x]] - 1; i++) {         while (cnt[opt]) opt++;         cout << pre <<     << opt << endl;         pre = opt;         opt++;       }       cout << pre <<     << q[x] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mxn = 0;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     cin >> t;     while (t--) {       long long int i, j, k, n, m;       string s;       cin >> s;       n = s.length();       string a, b, c;       i = -1;       j = n;       while ((i + 1) < (j - 1) && s[i + 1] == s[j - 1]) {         a += s[i + 1];         i++, j--;       }       c = a;       reverse(c.begin(), c.end());       long long int pr = -1, sf = -1;       for (long long int i1 = i + 1; i1 < j; i1++) {         long long int st = i + 1, en = i1;         while (st <= en && s[st] == s[en]) st++, en--;         if (st > en) pr = i1;       }       for (long long int i1 = i + 1; i1 < j; i1++) {         long long int st = i1, en = j - 1;         while (st <= en && s[st] == s[en]) st++, en--;         if (st > en) {           sf = i1;           break;         }       }       if (pr != -1) {         if (pr - i > j - sf) {           for (long long int i1 = i + 1; i1 <= pr; i1++) b += s[i1];         } else {           for (long long int i1 = sf; i1 < j; i1++) b += s[i1];         }       }       cout << a << b << c <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 650;   int kd[MAXN], edges[100010][2];   int idA[MAXN], idB[MAXN];   int g[MAXN][MAXN];   int P;   inline int advPow(int a, int b) {     int ret = 1;     while (b) {       if (b & 1) ret = (long long)ret * a % P;       a = (long long)a * a % P;       b >>= 1;     }     return ret;   }   inline int inverse(int a) { return advPow(a, P - 2); }   int gauss(int N) {     int ret = 1;     for (int col = 1; col <= N; col++) {       int pos = 0;       for (int row = col; row <= N; row++)         if (g[row][col]) {           pos = row;           break;         }       if (pos && pos != col) {         for (int i = 1; i <= N; i++) swap(g[pos][i], g[col][i]);         ret *= -1;       }       if (pos == 0) return 0;       int inv = inverse(g[col][col]);       for (int row = 1; row <= N; row++) {         if (!g[row][col] || row == col) continue;         int cur = (long long)g[row][col] * inv % P;         for (int i = col; i <= N; i++)           g[row][i] = (g[row][i] - (long long)g[col][i] * cur % P + P) % P;       }     }     for (int i = 1; i <= N; i++) ret = (long long)ret * g[i][i] % P;     return (ret + P) % P;   }   struct Node {     int v, nxt;   } d[100010];   int head[MAXN], etot;   inline void addEdge(int a, int b) {     etot++;     d[etot].v = b;     d[etot].nxt = head[a];     head[a] = etot;   }   int rin[MAXN], rout[MAXN];   int plans[MAXN][MAXN];   queue<int> que;   int main() {     int N, M;     scanf( %d%d%d , &N, &M, &P);     for (int i = 1; i <= M; i++) {       int a, b;       scanf( %d%d , &a, &b);       if (a == b) continue;       rin[b]++, rout[a]++;       addEdge(a, b);     }     for (int i = 1; i <= N; i++)       if (!rin[i]) que.push(i);     for (int i = 1; i <= N; i++) plans[i][i] = 1;     int cnt1 = 0, cnt2 = 0;     for (int i = 1; i <= N; i++)       if (!rin[i]) idA[++cnt1] = i;     for (int i = 1; i <= N; i++)       if (!rout[i]) idB[++cnt2] = i;     if (cnt1 != cnt2) {       puts( 0 );       return 0;     }     while (!que.empty()) {       int u = que.front();       que.pop();       for (int e = head[u]; e; e = d[e].nxt) {         rin[d[e].v]--;         for (int i = 1; i <= N; i++) (plans[i][d[e].v] += plans[i][u]) %= P;         if (!rin[d[e].v]) que.push(d[e].v);       }     }     for (int i = 1; i <= cnt1; i++)       for (int j = 1; j <= cnt2; j++) g[i][j] = plans[idA[i]][idB[j]];     printf( %d n , gauss(cnt1));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double r, x, y, x1, y1;     cin >> r >> x >> y >> x1 >> y1;     double dist = sqrt(pow(x - x1, 2) + pow(y - y1, 2));     double ans = dist / (2 * r);     cout << ceil(ans) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 3e5;   int a[MAX] = {};   int main() {     int t;     cin >> t;     while (t--) {       char c;       long long s;       cin >> c >> s;       long long a1 = 0;       for (int i = 0; i < 18; i++) {         a1 = a1 * 2 + s % 2;         s /= 10;       }       if (c ==  + ) {         a[a1]++;       } else if (c ==  - ) {         a[a1]--;       } else {         cout << a[a1] <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> l[100007];   int parent[100007];   int color[100007];   int k;   int p;   int dfs(int u, int c) {     int sz = l[u].size();     {       for (int i = 0; i < sz; i++) {         if (color[u] - color[l[u][i]] >= k && color[l[u][i]] != 0) {           parent[l[u][i]] = u;           return u;         } else if (color[l[u][i]] == 0) {           color[l[u][i]] = c + 2;           parent[l[u][i]] = u;           return dfs(l[u][i], c + 1);         }       }     }   }   int main() {     int n, m;     cin >> n >> m >> k;     int a, b;     for (int i = 0; i < m; i++) {       cin >> a >> b;       l[a].push_back(b);       l[b].push_back(a);     }     color[1] = 1;     int u = dfs(1, 0);     int v = parent[u];     int cycle = 1;     while (v != u) {       v = parent[v];       cycle++;     }     cout << cycle << endl;     cout << u <<    ;     v = parent[u];     while (v != u) {       cout << v <<    ;       v = parent[v];     }   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   bool dentro[410000];   int main() {     int n, k;     scanf( %d %d , &n, &k);     int vazio = 0;     int v[n];     vector<int> proximo(n, inf);     vector<int> mapa(n, -1);     for (int i = 0; i < n; i++) {       scanf( %d , &v[i]);       if (mapa[v[i]] != -1) {         proximo[mapa[v[i]]] = i;       }       mapa[v[i]] = i;     }     int resp = 0;     priority_queue<pair<int, int> > q;     int qt = 0;     for (int i = 0; i < n; i++) {       if (dentro[v[i]]) {         q.push(pair<int, int>(proximo[i], v[i]));         continue;       }       if (qt < k) {         q.push(pair<int, int>(proximo[i], v[i]));         qt++;         dentro[v[i]] = true;         resp++;         continue;       }       pair<int, int> aux = q.top();       q.pop();       resp++;       int u = aux.second;       dentro[u] = false;       dentro[v[i]] = true;       q.push(pair<int, int>(proximo[i], v[i]));     }     printf( %d n , resp);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mapping[200001];   int main(int narg, char **arg) {     int h, m, n;     cin >> h >> m >> n;     int hh = 0, occup_size = 0;     while (true) {       mapping[hh] = occup_size;       hh += m;       hh %= h;       occup_size++;       if (!hh) break;     }     int n_occup = h / occup_size;     map<int, int> occup[n_occup];     for (int i = 0; i < occup_size; i++) mapping[i] = mapping[i * n_occup];     long long counter = 0;     map<int, pair<int, int> > positions;     for (int i = 0; i < n; i++) {       char op;       int id, hash_value;       cin >> op >> id;       int i_occup, i_start;       if (op ==  + ) {         cin >> hash_value;         i_occup = hash_value % n_occup;         i_start = mapping[hash_value / n_occup];         while (true) {           map<int, int>::iterator it = occup[i_occup].upper_bound(i_start);           if (it == occup[i_occup].begin()) {             occup[i_occup][i_start] = i_start;             it = occup[i_occup].begin();           } else {             --it;             if (it->second >= i_start - 1) {               if (it->second == occup_size - 1) {                 counter += occup_size - i_start;                 i_start = 0;                 continue;               }               it->second++;               counter += it->second - i_start;               i_start = it->second;             } else {               it = occup[i_occup].insert(make_pair(i_start, i_start)).first;             }           }           map<int, int>::iterator it2 = it;           ++it2;           if (it2 != occup[i_occup].end()) {             if (it->second + 1 == it2->first) {               it->second = it2->second;               occup[i_occup].erase(it2);             }           }           break;         }         positions[id] = make_pair(i_occup, i_start);       } else {         pair<int, int> p = positions[id];         i_occup = p.first;         i_start = p.second;         positions.erase(id);         map<int, int>::iterator it = occup[i_occup].upper_bound(i_start);         --it;         if (it->first == i_start) {           int last = it->second;           occup[i_occup].erase(it);           if (last != i_start) occup[i_occup][i_start + 1] = last;         } else if (it->second == i_start)           it->second--;         else {           int last = it->second;           it->second = i_start - 1;           occup[i_occup][i_start + 1] = last;         }       }     }     cout << counter << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, i, j, alp[27] = {0}, flg = 1;       cin >> n;       string s[n + 1];       for (i = 0; i < n; i++) cin >> s[i];       for (i = 0; i < n; i++) {         for (j = 0; j < s[i].size(); j++) {           alp[s[i][j] * 1 - 96]++;         }       }       for (i = 1; i < 27; i++) {         if (alp[i] != 0) {           if (alp[i] % n != 0) {             flg = 0;             break;           }         }       }       if (flg == 1)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 10000 + 10;   int a[maxn];   int main() {     int i, j, k, m, n;     cin >> n;     int sum = 0;     while (n > 0) {       if (n % 8 == 1) sum++;       n /= 8;     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cout.setf(ios::fixed);     cout.precision(20);     int n;     cin >> n;     if (n == 5) return 0 * puts( 1 );     cout << n % 3 + 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     cin >> a >> b;     int x = 0, y = 0;     int n = b.length();     while (x < n && a[x] == b[x]) x++;     while (y < n && a[n - y] == b[n - 1 - y]) y++;     int res = x + y + 2 - (n + 1);     res = max(0, min(res, n + 1));     cout << res << endl;     int start = n - y + 1;     for (int i = 0; i < res; i++) cout << (start + i) <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma optimize( Ofast )   using namespace std;   using ll = long long;   const int N = 2e5 + 5;   vector<int> g[N];   bool vis[N];   int cnt;   void dfs(int s) {     ++cnt;     vis[s] = true;     for (auto it : g[s]) {       if (!vis[it]) {         dfs(it);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       g[i + 1].push_back(x);       g[x].push_back(i + 1);     }     deque<ll> d;     for (int i = 1; i <= n; ++i) {       if (!vis[i]) {         cnt = 0;         dfs(i);         d.push_back(cnt);       }     }     sort(d.rbegin(), d.rend());     if (d.size() == 1) d.push_back(0);     ll ans = (d[0] + d[1]) * (d[0] + d[1]);     for (int i = 2; i < d.size(); ++i) {       ans += d[i] * d[i];     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long i, j, n, t, sum = 0, k, c1 = 1;   int main() {     cin >> n;     vector<string> c(n);     vector<string> s(n);     for (i = 0; i < n; i++) {       cin >> c[i] >> s[i];     }     for (i = 1; i < n; i++) {       k = 0;       for (j = i - 1; j >= 0; j--) {         if (c[i] == c[j] && s[i] == s[j]) {           k++;           if (k != 0) {             break;           }         }       }       if (k == 0) {         c1++;       }     }     cout << c1;   }


#include <bits/stdc++.h>   using namespace std;   long long inf = 1e9;   int main() {     std::ios::sync_with_stdio(false);     int n;     cin >> n;     long long noemer = 0;     for (long long i = 1; i <= n; i++) {       noemer += (n + 1 - i) * (n + 1 - i);     }     string s1, s2;     cin >> s1;     cin >> s2;     double ans = 0.0;     long long teller = 0;     for (char ch =  A ; ch <=  Z ; ch++) {       long long x, y, z;       x = 0;       y = 0;       z = 0;       for (int i = n - 1; i >= 0; i--) {         if (s2[i] == ch) {           z += n - i;         }       }       x = z;       if (s1[0] == ch) {         if (teller >= inf) {           ans += 1.0 * teller / noemer;           teller = 0;         }         teller += x;       }       for (int i = 1; i < n; i++) {         if (s2[i - 1] == ch) {           y += i;           z -= (n + 1 - i);         }         long long now = x - y + z;         if (s1[i] == ch) {           if (teller >= inf) {             ans += 1.0 * teller / noemer;             teller = 0;           }           teller += now;         }         x = now;       }     }     ans += 1.0 * teller / noemer;     cout << fixed << setprecision(12) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const double PI = 3.141592653589793238463;   const int N = 1e5 + 100;   vector<int> v[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int x;     cin >> x;     int r, l;     for (int i = 1; i < x; i++) {       cin >> r >> l;       v[r].push_back(l);       v[l].push_back(r);     }     bool ans = true;     for (int i = 1; i <= x; i++) {       if (v[i].size() == 2) {         ans = false;         break;       }     }     cout << (ans ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   struct edge {     int u, v, st, nt;   } e[MAXN * 2];   vector<int> lis;   int hd[MAXN], etot, used[MAXN], in[MAXN], u[MAXN], v[MAXN];   void addedge(int u, int v, int st) {     e[etot].u = u;     e[etot].v = v;     e[etot].st = st;     e[etot].nt = hd[u];     hd[u] = etot++;   }   void dfs(int p) {     used[p] = 1;     lis.push_back(p);     for (int i = hd[p]; ~i; i = e[i].nt) {       if (used[e[i].v]) continue;       dfs(e[i].v);     }   }   queue<int> Q;   int topsort() {     for (int i = 0; i < (int)lis.size(); i++)       if (!in[lis[i]]) Q.push(lis[i]);     int cnt = 0, u;     for (; !Q.empty();) {       cnt++;       u = Q.front();       Q.pop();       for (int i = hd[u]; ~i; i = e[i].nt) {         if (!e[i].st) continue;         in[e[i].v]--;         if (!in[e[i].v]) Q.push(e[i].v);       }     }     return cnt == (int)lis.size();   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     etot = 0;     memset(hd, -1, sizeof(hd));     for (int i = 0; i < m; i++) {       scanf( %d%d , u + i, v + i);       addedge(u[i], v[i], 1);       addedge(v[i], u[i], 0);       in[v[i]]++;     }     int ans = 0;     for (int i = 1; i < n + 1; i++) {       lis.clear();       if (!used[i]) dfs(i);       if ((int)lis.size() == 0) continue;       ans += (int)lis.size() - topsort();     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 9;   int a[N], n;   double ans(double x) {     double arr[N];     for (int i = 0; i < n; i++) arr[i] = a[i] - x;     double neg = 0;     double pos = 0;     double ans = 0;     for (int i = 0; i < n; i++) {       if (neg > 0) neg = 0;       if (pos < 0) pos = 0;       neg += arr[i];       pos += arr[i];       ans = max(ans, max(-neg, pos));     }     return ans;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     double l = -1e5 - 9, r = 1e5 + 9;     for (int i = 0; i < 100; i++) {       double m1 = l + (r - l) / 3, m2 = r - (r - l) / 3;       if (ans(m1) > ans(m2))         l = m1;       else         r = m2;     }     cout << setprecision(12) << fixed << ans(l) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     long long int n, a, b, c, d, e, f, g, h, i, j, x, y, count = 0;     cin >> n >> x >> y;     n = n / 2;     if ((x == n || x == n + 1) && (y == n || y == n + 1))       cout <<  NO ;     else       cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Pt {     long long int x, y;     friend ostream& operator<<(ostream& os, const Pt& a) {       os << a.x <<     << a.y;       return os;     }   };   struct R {     long long int a, b, c;   };   int main() {     ios::sync_with_stdio(false);     long long int N, K;     cin >> N >> K;     vector<long long int> w[4];     for (long long int i = 0; i < (long long int)(4); ++i)       w[i] = vector<long long int>(N);     vector<Pt> wp[4];     for (long long int i = 0; i < (long long int)(4); ++i) wp[i] = vector<Pt>(N);     for (long long int i = 0; i < (long long int)(4); ++i)       for (int j = 0; j < N; ++j) wp[i][j] = {i + 1, j + 1};     for (long long int i = 0; i < (long long int)(4); ++i)       for (int j = 0; j < N; ++j) cin >> w[i][j];     vector<long long int> a[2];     for (long long int i = 0; i < (long long int)(2); ++i)       a[i] = vector<long long int>(2 * N);     vector<Pt> p[2];     for (long long int i = 0; i < (long long int)(2); ++i)       p[i] = vector<Pt>(2 * N);     for (long long int i = 0; i < (long long int)(N); ++i) a[0][i] = w[0][i];     for (long long int i = 0; i < (long long int)(N); ++i)       a[0][N + i] = w[3][N - 1 - i];     for (long long int i = 0; i < (long long int)(N); ++i) a[1][i] = w[1][i];     for (long long int i = 0; i < (long long int)(N); ++i)       a[1][N + i] = w[2][N - 1 - i];     for (long long int i = 0; i < (long long int)(N); ++i) p[0][i] = wp[0][i];     for (long long int i = 0; i < (long long int)(N); ++i)       p[0][N + i] = wp[3][N - 1 - i];     for (long long int i = 0; i < (long long int)(N); ++i) p[1][i] = wp[1][i];     for (long long int i = 0; i < (long long int)(N); ++i)       p[1][N + i] = wp[2][N - 1 - i];     N *= 2;     vector<R> res;     for (int t = 0; t < 151; ++t) {       long long int c = 0;       for (long long int i = 0; i < (long long int)(N); ++i) {         if (a[1][i] != 0 && a[1][i] == a[0][i]) {           res.push_back({a[1][i], p[0][i].x, p[0][i].y});           a[1][i] = 0;         }         if (a[1][i] == 0) c++;       }       if (c == N) break;       if (c == 0 || t == 150) {         cout << -1 << endl;         return 0;       }       int j = 0;       for (; j < N; ++j)         if (a[1][j] == 0) break;       for (int i = 0; i < N - 1; ++i) {         long long int w = (j + i) % N;         long long int q = (j + i + 1) % N;         if (a[1][q] != 0) {           res.push_back({a[1][q], p[1][w].x, p[1][w].y});           a[1][w] = a[1][q];           a[1][q] = 0;         }       }     }     cout << res.size() << endl;     for (long long int i = 0; i < (long long int)(res.size()); ++i) {       cout << res[i].a <<     << res[i].b <<     << res[i].c <<     << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void pr(vector<T> &v) {     for (int i = 0; i < (int)(v).size(); i++) cout << v[i] <<    ;     cout <<   n ;     ;   }   template <typename T>   void pr(vector<vector<T>> &v) {     for (int i = 0; i < (int)(v).size(); i++) {       pr(v[i]);     }   }   template <typename T>   void re(T &x) {     cin >> x;   }   template <typename T>   void re(vector<T> &a) {     for (int i = 0; i < (int)(a).size(); i++) re(a[i]);   }   template <class Arg, class... Args>   void re(Arg &first, Args &...rest) {     re(first);     re(rest...);   }   template <typename T>   void pr(T x) {     cout << x <<   n ;     ;   }   template <class Arg, class... Args>   void pr(const Arg &first, const Args &...rest) {     cout << first <<    ;     pr(rest...);     cout <<   n ;     ;   }   void ps() {     cout <<   n ;     ;   }   template <class T, class... Ts>   void ps(const T &t, const Ts &...ts) {     cout << t;     if (sizeof...(ts)) cout <<    ;     ps(ts...);   }   const long long MOD = 1000000007;   long double PI = 4 * atan(1);   long double eps = 1e-12;   int LPS[200005] = {};   vector<pair<long long, char>> t;   vector<pair<long long, char>> s;   vector<pair<long long, char>> tcp;   vector<pair<long long, char>> scp;   void computeLPS() {     int M = scp.size();     int i = 1;     int j = 0;     LPS[0] = 0;     while (i < M) {       if (scp[j] == scp[i]) {         j++;         LPS[i] = j;         i++;       } else {         if (j == 0) {           LPS[i] = 0;           i++;         } else {           j = LPS[j - 1];         }       }     }   }   vector<int> KMP() {     int M = (int)scp.size();     int N = (int)tcp.size();     computeLPS();     int i = 0;     int j = 0;     vector<int> matches;     while (i < N) {       if (scp[j] == tcp[i]) {         i++;         j++;       }       if (j == M) {         matches.push_back(i - j);         j = LPS[j - 1];       } else if (i < N && scp[j] != tcp[i]) {         if (j != 0) {           j = LPS[j - 1];         } else {           i++;         }       }     }     return matches;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       long long k;       cin >> k;       char dash;       cin >> dash;       char c;       cin >> c;       if (t.size() == 0 || c != t.back().second) {         t.push_back(make_pair(k, c));       } else {         t.back().first += k;       }     }     for (int i = 0; i < m; i++) {       long long k;       cin >> k;       char dash;       cin >> dash;       char c;       cin >> c;       if (s.size() == 0 || c != s.back().second) {         s.push_back(make_pair(k, c));       } else {         s.back().first += k;       }     }     long long ans = 0;     if (s.size() == 1) {       for (int i = 0; i < t.size(); i++) {         if (t[i].second == s[0].second) {           ans += max(0ll, t[i].first - s[0].first + 1ll);         }       }       cout << ans <<   n ;       ;       return 0;     } else if (s.size() == 2) {       for (int i = 0; i < t.size() - 1; i++) {         if (t[i].second == s[0].second && t[i + 1].second == s[1].second &&             t[i].first >= s[0].first && t[i + 1].first >= s[1].first) {           ans += 1;         }       }       cout << ans <<   n ;       ;       return 0;     }     for (int i = 1; i < t.size() - 1; i++) tcp.push_back(t[i]);     for (int i = 1; i < s.size() - 1; i++) scp.push_back(s[i]);     vector<int> matches = KMP();     for (int ind : matches) {       if (t[ind].first >= s[0].first && t[ind].second == s[0].second &&           t[ind + s.size() - 1].first >= s.back().first &&           t[ind + s.size() - 1].second == s.back().second) {         ans++;       }     }     cout << ans <<   n ;     ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int length;     cin >> length;     int query;     cin >> query;     string result;     cin >> result;     for (int i = 0; i < query; ++i) {       int left;       int right;       cin >> left >> right;       char which;       char what;       cin >> which >> what;       for (int j = left; j <= right; ++j)         if (result[j - 1] == which) result[j - 1] = what;     }     cout << result;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long int n, x, y, cn = 0, ans = 0;     string s;     cin >> n >> x >> y >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  0 )         cn++;       else {         if (cn) ans++;         cn = 0;       }     }     if (cn) ans++;     if (!ans)       cout << 0 << endl;     else       cout << (ans - 1) * min(x, y) + y << endl;     return 0;   }


#include <bits/stdc++.h>   long long MOD = 1000000007;   using namespace std;   bool sortbysec(const pair<long long, long long> &a,                  const pair<long long, long long> &b) {     return (a.second < b.second);   }   long long POW(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a % MOD;     long long temp = POW(a, b / 2);     if (b % 2 == 0)       return (temp * temp) % MOD;     else       return (((temp * temp) % MOD) * a) % MOD;   }   vector<char> capl = { A ,  B ,  C ,  D ,  E ,  F ,  G ,  H ,  I ,                         J ,  K ,  L ,  M ,  N ,  O ,  P ,  Q ,  R ,                         S ,  T ,  U ,  V ,  W ,  X ,  Y ,  Z };   vector<char> sml = { a ,  b ,  c ,  d ,  e ,  f ,  g ,  h ,  i ,                        j ,  k ,  l ,  m ,  n ,  o ,  p ,  q ,  r ,                        s ,  t ,  u ,  v ,  w ,  x ,  y ,  z };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       map<int, int> m;       for (int i = 1; i < 201; i++) {         m[i]++;       }       for (int i = 0; i < n; i++) {         cin >> arr[i];         m[arr[i]]--;       }       int b[2 * n];       for (int i = 0; i < n; i++) {         b[2 * i] = arr[i];         for (auto x : m) {           if (x.first > arr[i] && x.second != 0) {             b[2 * i + 1] = x.first;             m[x.first] = 0;             break;           }         }       }       int c[2 * n], f = 0;       copy(b, b + 2 * n, c);       sort(c, c + 2 * n);       for (int i = 0; i < 2 * n; i++) {         if (c[i] != i + 1) {           f = 1;           break;         }       }       if (f == 1) {         cout <<  -1 n ;       } else {         for (int i = 0; i < 2 * n; i++) {           cout << b[i] <<    ;         }         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T sqr(T x) {     return x * x;   }   template <typename T>   T abs(T x) {     return x < 0 ? -x : x;   }   template <typename T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   const int MAXN = 1e5 + 10;   int n;   int sum = 0;   pair<int, int> a[200000];   int col[MAXN];   int cost[300];   int ans = 2000000007;   inline bool cmp(pair<int, int> a, pair<int, int> b) {     if (a.first < b.first) return true;     if (a.first == b.first) return a.second > b.second;     return false;   }   int main() {     ios_base ::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i].first, col[a[i].first]++;     for (int i = 1; i <= n; i++) cin >> a[i].second, cost[a[i].second]++;     sort(a + 1, a + n + 1);     if (n == 1) {       cout << 0;       return 0;     }     if (n == 2) {       if (a[1].first != a[2].first)         cout << min(a[1].second, a[2].second);       else         cout << 0;       return 0;     }     a[0].first = 2000000007;     int s = 0;     for (int i = n; i; i--) {       s += a[i].second;       cost[a[i].second]--;       if (a[i].first != a[i - 1].first) {         int c = 0, del = max(0, i - col[a[i].first]);         for (int j = 1; j <= 200; j++) {           int r = min(del, cost[j]);           c += j * r, del -= r;           if (!del) break;         }         ans = min(ans, sum + c);         sum += s, s = 0;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   struct Node {     int is, id, x;     bool operator<(const Node &a) const {       if (x != a.x)         return x < a.x;       else         return is < a.is;     }   };   int a[maxn * 4], s[maxn], p[maxn], inc[maxn], b[maxn], treea[maxn * 4],       treeb[maxn * 4], pb[maxn];   int ans[maxn];   map<int, int> ma;   int cnt = 0, tt = 0;   Node que[maxn * 3];   int getid(int x) {     x = -x;     return ma[x];   }   void add1(int x, int y) {     for (int i = x; i < 4 * maxn; i += (i & -i)) treea[i] += y;   }   void add2(int x, int y) {     for (int i = x; i < 4 * maxn; i += (i & -i)) treeb[i] += -y;   }   int quer1(int x) {     int res = 0;     for (int i = x; i >= 1; i -= (i & -i)) res += treea[i];     return res;   }   int quer2(int x) {     int res = 0;     for (int i = x; i >= 1; i -= (i & -i)) res += treeb[i];     return res;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &p[i]);     for (int i = 1; i <= n; i++) scanf( %d , &s[i]);     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     for (int i = 1; i <= m; i++) scanf( %d , &inc[i]);     for (int i = 1; i <= m; i++) scanf( %d , &pb[i]);     for (int i = 1; i <= n; i++) {       a[++cnt] = -(p[i] + b[i] - 1), a[++cnt] = -(b[i] - p[i]);       que[++tt] = Node{0, i, p[i]};       que[++tt] = Node{2, i, s[i]};     }     for (int i = 1; i <= m; i++) {       a[++cnt] = -(inc[i] + pb[i]), a[++cnt] = -(pb[i] - inc[i]);       que[++tt] = Node{1, i, inc[i]};     }     sort(que + 1, que + 1 + tt);     sort(a + 1, a + cnt + 1);     int pz = 1;     for (int i = 1; i <= cnt; i++)       if (ma[a[i]] == 0) ma[a[i]] = pz++;     for (int i = 1; i <= tt; i++) {       Node now = que[i];       if (now.is == 0) {         add1(getid(b[now.id] - p[now.id]), 1);         add2(getid(p[now.id] + b[now.id] - 1), 1);       } else if (now.is == 1) {         ans[now.id] = quer1(getid(pb[now.id] - inc[now.id])) +                       quer2(getid(inc[now.id] + pb[now.id]));       } else if (now.is == 2) {         add1(getid(b[now.id] - p[now.id]), -1);         add2(getid(p[now.id] + b[now.id] - 1), -1);       }     }     for (int i = 1; i <= m; i++) {       printf( %d  , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int p, q, l, r;     cin >> p >> q >> l >> r;     vector<pair<int, int> > z_timing, x_timing;     int start, stop;     for (int i = 0; i < p; i++) {       cin >> start >> stop;       z_timing.push_back(make_pair(start, stop));     }     for (int i = 0; i < q; i++) {       cin >> start >> stop;       x_timing.push_back(make_pair(start, stop));     }     int answer = 0;     for (int i = l; i <= r; i++) {       for (int j = 0; j < q; j++) {         bool has_intersected = false;         start = x_timing[j].first + i;         stop = x_timing[j].second + i;         for (int k = 0; k < p; k++) {           if (start <= z_timing[k].second && stop >= z_timing[k].first) {             answer++;             has_intersected = true;             break;           }         }         if (has_intersected == true) {           break;         }       }     }     cout << answer;     return 0;   }


// vaziat meshki-ghermeze !   #include <bits/stdc++.h>      #define pb push_back   #define F first   #define S second   #define all(x) x.begin(), x.end()   #define debug(x) cerr << #x <<   :   << x <<   n       using namespace std;      typedef long long ll;   typedef long double ld;   typedef string str;   typedef pair<ll, ll> pll;      const ll Mod = 1000000007LL;   const int N = 2e5 + 10;   const ll Inf = 2242545357980376863LL;   const ll Log = 30;      pll A[N];   ll dis(ll i, ll j){    return (A[i].F - A[j].F)*(A[i].F - A[j].F) + (A[i].S - A[j].S)*(A[i].S - A[j].S);   }   ll mk[N];   int main(){    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);    int n;    cin >> n;    pll mn = {Inf, Inf};    ll idx = -1;    for(int i = 1; i <= n; i++){     cin >> A[i].F >> A[i].S;     if(A[i] < mn){      mn = A[i];      idx = i;     }    }    cout << idx <<    ;    mk[idx] = 1;    for(int i = 2; i <= n; i++){     ll mx = -1;     ll id = -1;     for(int j = 1; j <= n; j++){      if(mk[j]) continue;      if(mx < dis(idx, j)){       mx = dis(idx, j);       id = j;      }     }     idx = id;     mk[id] = 1;     cout << idx <<    ;    }    cout <<   n ;    return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void rd(T &x) {     x = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) x = x * 10 -  0  + c, c = getchar();     x *= f;   }   template <class T>   inline void cmax(T &x, T y) {     if (x < y) x = y;   }   template <class T>   inline void cmin(T &x, T y) {     if (y < x) x = y;   }   const int N = 5e5 + 10, M = N << 1;   int n, m;   struct Tree {     int F[M], fa[M], ch[M][2], ti[M], sz[M], ncnt;     int dfn[M], lb[M], rb[M], id;     void init() {       ncnt = n;       for (int i = 1; i <= n; ++i) fa[i] = i, sz[i] = 1;     }     int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }     void un(int x, int y, int t) {       int fx = find(x), fy = find(y), u = ++ncnt;       fa[u] = fa[fx] = fa[fy] = u, ti[u] = t, sz[u] = sz[fx] + sz[fy];       ch[u][0] = fx, ch[u][1] = fy;     }     void dfs(int u) {       if (!ch[u][0]) {         lb[u] = rb[u] = dfn[u] = ++id;       } else {         lb[u] = id + 1;         dfs(ch[u][0]), dfs(ch[u][1]);         F[ch[u][0]] = F[ch[u][1]] = u;         rb[u] = id;       }     }     void build() {       for (int i = 1; i <= ncnt; ++i)         if (find(i) == i) dfs(i);       for (int i = 1; i <= n; ++i) fa[i] = i;     }     int get(int x, int t) {       while (F[fa[x]] && ti[F[fa[x]]] <= t) fa[x] = F[fa[x]];       return fa[x];     }   } A, B;   namespace seg {   int cov[N << 2];   inline void push_down(int c) {     if (cov[c]) {       cmax(cov[c << 1], cov[c]);       cmax(cov[c << 1 | 1], cov[c]);       cov[c] = 0;     }   }   void upd(int l, int r, int c, int L, int R, int v) {     if (L <= l && R >= r) return (void)(cov[c] = v);     int mid = l + r >> 1;     push_down(c);     if (L <= mid) upd(l, mid, c << 1, L, R, v);     if (R > mid) upd(mid + 1, r, c << 1 | 1, L, R, v);   }   int query(int l, int r, int c, int v) {     if (l == r) return cov[c];     int mid = l + r >> 1;     push_down(c);     if (v <= mid)       return query(l, mid, c << 1, v);     else       return query(mid + 1, r, c << 1 | 1, v);   }   }  // namespace seg   namespace Bit {   long long c[N];   void add(int i, int t) {     for (; i <= n; i += i & -i) c[i] += t;   }   void add(int l, int r, int t) { add(l, t), add(r + 1, -t); }   long long query(int i) {     long long ans = 0;     for (; i; i -= i & -i) ans += c[i];     return ans;   }   }  // namespace Bit   struct OPT {     int ty, t, x;     OPT(int ty = 0, int t = 0, int x = 0) : ty(ty), t(t), x(x) {}   };   vector<OPT> Q;   long long ans[N];   struct Que {     int p, id, sgn;     Que(int p = 0, int id = 0, int sgn = 0) : p(p), id(id), sgn(sgn) {}   };   vector<Que> R[N];   char ty[20];   int main() {     rd(n), rd(m);     A.init(), B.init();     for (int i = 1, x, y; i <= m; ++i) {       scanf( %s , ty);       if (ty[0] ==  U ) {         rd(x), rd(y);         A.un(x, y, i);       } else if (ty[0] ==  M ) {         rd(x), rd(y);         B.un(x, y, i);       } else {         rd(x);         Q.push_back(OPT(ty[0] ==  A  ? 1 : (ty[0] ==  Z  ? 2 : 3), i, x));       }     }     A.build(), B.build();     int qtot = 0;     for (int i = 0; i < Q.size(); ++i)       if (Q[i].ty == 2) {         int x = B.get(Q[i].x, Q[i].t);         seg::upd(1, n, 1, B.lb[x], B.rb[x], Q[i].t);       } else if (Q[i].ty == 3) {         R[Q[i].t].push_back(Que(A.dfn[Q[i].x], ++qtot, 1));         int pre = seg::query(1, n, 1, B.dfn[Q[i].x]);         if (pre) R[pre].push_back(Que(A.dfn[Q[i].x], qtot, -1));       }     int q = 0;     for (int i = 1; i <= m; ++i) {       while (q < Q.size() && Q[q].t <= i) {         if (Q[q].ty == 1) {           int anc = A.get(Q[q].x, Q[q].t);           Bit::add(A.lb[anc], A.rb[anc], A.sz[anc]);         }         q++;       }       for (int j = 0; j < R[i].size(); ++j)         ans[R[i][j].id] += R[i][j].sgn * Bit::query(R[i][j].p);     }     for (int i = 1; i <= qtot; ++i) printf( %lld n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int SZ = 1e6 + 10;   const int INF = 1e9 + 10;   const int mod = 998244353;   const long double eps = 1e-8;   long long read() {     long long n = 0;     char a = getchar();     bool flag = 0;     while (a >  9  || a <  0 ) {       if (a ==  - ) flag = 1;       a = getchar();     }     while (a <=  9  && a >=  0 ) {       n = n * 10 + a -  0 , a = getchar();     }     if (flag) n = -n;     return n;   }   struct seg {     int l, r, mx, add;   } tree[SZ * 4];   void update(int p) { tree[p].mx = max(tree[p << 1].mx, tree[p << 1 | 1].mx); }   void build(int p, int l, int r) {     tree[p].l = l;     tree[p].r = r;     if (l == r) return;     int mid = l + r >> 1;     build(p << 1, l, mid);     build(p << 1 | 1, mid + 1, r);     update(p);   }   void pushadd(int p, int d) {     tree[p].add += d;     tree[p].mx += d;   }   void pushdown(int p) {     if (tree[p].add) {       pushadd(p << 1, tree[p].add);       pushadd(p << 1 | 1, tree[p].add);       tree[p].add = 0;     }   }   void change(int p, int l, int r, int d) {     if (l <= tree[p].l && tree[p].r <= r) {       pushadd(p, d);       return;     }     pushdown(p);     int mid = tree[p].l + tree[p].r >> 1;     if (l <= mid) change(p << 1, l, r, d);     if (mid < r) change(p << 1 | 1, l, r, d);     update(p);   }   struct haha {     int pos, x, y, d;   } l[SZ];   bool cmp(haha a, haha b) { return a.pos < b.pos; }   int lsh[SZ];   int main() {     int n = read(), m = read(), tot = 0;     for (int i = 1; i <= n; i++) {       int a = read(), b = read(), x, y;       x = a + b;       y = a - b;       l[++tot] = (haha){x - m, y - m, y + m, 1};       l[++tot] = (haha){x + m + 1, y - m, y + m, -1};     }     for (int i = 1; i <= tot; i++) {       lsh[++lsh[0]] = l[i].x;       lsh[++lsh[0]] = l[i].y;     }     sort(lsh + 1, lsh + 1 + lsh[0]);     lsh[0] = unique(lsh + 1, lsh + 1 + lsh[0]) - lsh - 1;     for (int i = 1; i <= tot; i++) {       l[i].x = lower_bound(lsh + 1, lsh + 1 + lsh[0], l[i].x) - lsh;       l[i].y = lower_bound(lsh + 1, lsh + 1 + lsh[0], l[i].y) - lsh;     }     int ans = 0;     build(1, 1, lsh[0]);     sort(l + 1, l + 1 + tot, cmp);     for (int i = 1, lst = 1; i <= tot; i++) {       if (i == tot || l[i + 1].pos != l[i].pos) {         for (int j = lst; j <= i; j++) {           change(1, l[j].x, l[j].y, l[j].d);         }         ans = max(ans, tree[1].mx);         lst = i + 1;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     vector<int> poss;     for (int i = 0; i < n; ++i) {       int x = a[i];       while (x > 0) {         poss.push_back(x);         x /= 2;       }     }     int ans = 1e9;     for (auto res : poss) {       vector<int> cnt;       for (int i = 0; i < n; ++i) {         int x = a[i];         int cur = 0;         while (x > res) {           x /= 2;           ++cur;         }         if (x == res) {           cnt.push_back(cur);         }       }       if (int(cnt.size()) < k) continue;       sort(cnt.begin(), cnt.end());       ans = min(ans, accumulate(cnt.begin(), cnt.begin() + k, 0));     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     sort(v.begin(), v.end());     int l = v[n - 1], q = v[n - 2];     int d = 0;     for (int i = 0; i < n - 2; i++) {       if (q > i + 1) d = i + 1;     }     cout << d << endl;   }   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   int main() {     long long p, y;     cin >> p >> y;     int flag = 1;     for (long long j = y; j > p; j--) {       flag = 0;       for (long long k = 2; k <= p && k * k <= j; k++) {         if (j % k == 0) {           flag = 1;           break;         }       }       if (flag == 0) {         cout << j;         return 0;       }     }     cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   bool b[4000000];   int main() {     int n, cnt, x[2007], y[2007];     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x[i];       b[x[i]] = 1;     }     for (int i = 1; i <= n; i++) {       cin >> y[i];       b[y[i]] = 1;     }     cnt = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++)         if (b[x[i] ^ y[j]]) cnt++;     }     if (cnt % 2)       puts( Koyomi );     else       puts( Karen );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 10;   long long f[maxn], a[maxn];   int n;   map<long long, long long> pre, sum;   vector<long long> ans;   void fir() {     int st = 1;     while (st <= n) {       sum.clear();       pre.clear();       stack<long long> s;       for (int& i = st; i <= n; i++) {         if (pre[a[i]]) {           ans.push_back(pre[a[i]]);           ans.push_back(a[i]);           ans.push_back(pre[a[i]]);           ans.push_back(a[i]);           break;         }         while (!s.empty() &&                (sum[a[i]] > 1 || (sum[a[i]] == 1 && s.top() != a[i]))) {           pre[s.top()] = a[i];           sum[s.top()]--;           s.pop();         }         s.push(a[i]);         sum[a[i]]++;       }       st++;     }     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) {       printf( %I64d , ans[i]);       if (i == ans.size() - 1) {         printf(  n );       } else         printf(   );     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %I64d , &a[i]);     }     fir();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     cin >> a >> b >> c >> d;     int p1 = max((3 * a) / 10, a - ((a / 250) * c));     int p2 = max((3 * b) / 10, b - ((b / 250) * d));     if (p1 == p2)       cout <<  Tie  << endl;     else if (p1 > p2)       cout <<  Misha  << endl;     else       cout <<  Vasya  << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void umax(T &a, T b) {     if (a < b) a = b;   }   template <class T>   inline void umin(T &a, T b) {     if (a > b) a = b;   }   template <class T>   inline T abs(T a) {     return a > 0 ? a : -a;   }   template <class T>   inline T gcd(T a, T b) {     return __gcd(a, b);   }   template <class T>   inline T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   const int inf = 1e9 + 143;   const long long longinf = 1e18 + 143;   inline int read() {     int x;     scanf(  %d , &x);     return x;   }   const int N = 1 << 17;   int n;   int up[N];   int a[N], d[N], sz[N], par[N];   int tin[N], tout[N], ptr = 0;   vector<pair<int, int> > g[N];   bool isanc(int p, int u) { return tin[p] <= tin[u] && tin[u] <= tout[p]; }   int get_lca(int u, int v) {     if (!u) return v;     if (!v) return u;     for (;;) {       if (isanc(u, v)) return u;       if (isanc(v, u)) return v;       int hu = up[u] ? up[u] : par[u];       int hv = up[v] ? up[v] : par[v];       if (d[hu] >= d[hv]) {         u = hu;       } else {         v = hv;       }     }   }   namespace lca_tree {   int tree[N << 1];   void add(int x) {     tree[x + N - 1] = x;     x += N - 1;     while (x > 1) {       x >>= 1;       tree[x] = get_lca(tree[x + x], tree[x + x + 1]);     }   }   void del(int x) {     tree[x += N - 1] = 0;     while (x > 1) {       x >>= 1;       tree[x] = get_lca(tree[x + x], tree[x + x + 1]);     }   }   };  // namespace lca_tree   namespace Magic_Tree {   struct info {     int minv;     long long sum, all;   };   info tree[N << 1];   int add[N << 1];   inline void push(int x) {     if (add[x]) {       add[x + x] += add[x];       add[x + x + 1] += add[x];       add[x] = 0;     }   }   inline info apply(int x) {     return (info){tree[x].minv + add[x], tree[x].sum, tree[x].all};   }   inline info merge(const info &a, const info &b) {     info res;     res.minv = min(a.minv, b.minv);     res.all = a.all + b.all;     res.sum = 0ll;     if (a.minv == res.minv) res.sum += a.sum;     if (b.minv == res.minv) res.sum += b.sum;     return res;   }   inline void relax(int x) { tree[x] = merge(apply(x + x), apply(x + x + 1)); }   void init() {     for (int i = 1; i <= n; i++) tree[tin[i] + N - 1] = (info){0, a[i], a[i]};     for (int i = N - 1; i > 0; i--) tree[i] = merge(tree[i + i], tree[i + i + 1]);     memset(add, 0, sizeof add);   }   void update(int x, int l, int r, int x1, int x2, int val) {     if (l > x2 || r < x1) return;     if (l >= x1 && r <= x2) {       add[x] += val;       return;     }     push(x);     int m = (l + r) >> 1;     update(x + x, l, m, x1, x2, val);     update(x + x + 1, m + 1, r, x1, x2, val);     relax(x);   }   info get(int x, int l, int r, int x1, int x2) {     if (l > x2 || r < x1) return (info){0, 0, 0};     if (l >= x1 && r <= x2) return apply(x);     int m = (l + r) >> 1;     push(x);     info L = get(x + x, l, m, x1, x2);     info R = get(x + x + 1, m + 1, r, x1, x2);     relax(x);     return merge(L, R);   }   long long getsum(int l, int r) {     info t = get(1, 1, N, l, r);     if (t.minv > 0) return t.all;     return t.all - t.sum;   }   };  // namespace Magic_Tree   void dfs1(int u, int p) {     sz[u] = 1;     for (__typeof((g[u]).begin()) it = (g[u]).begin(); it != (g[u]).end(); it++) {       int v = it->first;       int c = it->second;       if (v != p) {         d[v] = d[u] + 1;         a[v] = c;         par[v] = u;         dfs1(v, u);         sz[u] += sz[v];       }     }   }   void dfs2(int u, int p) {     tin[u] = ++ptr;     int hv = -1;     for (__typeof((g[u]).begin()) it = (g[u]).begin(); it != (g[u]).end(); it++) {       int v = it->first;       int c = it->second;       if (v != p && (hv == -1 || sz[hv] < sz[v])) hv = v;     }     if (hv != -1) {       up[hv] = up[u] ? up[u] : u;       dfs2(hv, u);     }     for (__typeof((g[u]).begin()) it = (g[u]).begin(); it != (g[u]).end(); it++) {       int v = it->first;       int c = it->second;       if (v != p && v != hv) {         up[v] = 0;         dfs2(v, u);       }     }     tout[u] = ptr;   }   int main() {     n = read();     for (int i = 1; i < n; i++) {       int u = read(), v = read(), c = read();       g[u].push_back(pair<int, int>(v, c));       g[v].push_back(pair<int, int>(u, c));     }     par[1] = 0;     dfs1(1, 0);     dfs2(1, 0);     Magic_Tree::init();     int q = read();     while (q--) {       char foo;       scanf(  %c , &foo);       if (foo ==  ? ) {         int lca = lca_tree::tree[1];         0;         if (lca == 0) {           puts( 0 );         } else {           printf( %I64d n , Magic_Tree::getsum(tin[lca] + 1, tout[lca]));         }       } else {         int u = read();         if (foo ==  + )           lca_tree::add(u);         else           lca_tree::del(u);         0;         int delta = (foo ==  + ) ? +1 : -1;         while (u > 0) {           if (up[u]) {             Magic_Tree::update(1, 1, N, tin[up[u]] + 1, tin[u], delta);             u = up[u];           } else {             Magic_Tree::update(1, 1, N, tin[u], tin[u], delta);             u = par[u];           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long a[n];       for (long long i = 0; i < n; i++) cin >> a[i];       sort(a, a + n);       long long flg = 0;       for (long long i = 0; i < n - 1; i++)         if (a[i] == a[i + 1]) flg = 1;       if (flg)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }