/*       author:  Maksim1744       created: 10.03.2021 16:47:29   */      #include  bits/stdc++.h       using namespace std;      #define ll   long long   #define ld   long double      #define mp   make_pair   #define pb   push_back   #define eb   emplace_back      #define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))   #define mine(a)    (*min_element((a).begin(), (a).end()))   #define maxe(a)    (*max_element((a).begin(), (a).end()))   #define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())   #define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())   #define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())   #define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())      template<typename T>             vector<T>& operator--            (vector<T>& v){for (auto& i : v) --i;            return  v;}   template<typename T>             vector<T>& operator++            (vector<T>& v){for (auto& i : v) ++i;            return  v;}   template<typename T>             istream& operator>>(istream& is,  vector<T>& v){for (auto& i : v) is >> i;        return is;}   template<typename T>             ostream& operator<<(ostream& os,  vector<T>& v){for (auto& i : v) os << i <<    ; return os;}   template<typename T, typename U> pair<T,U>& operator--           (pair<T, U> &p){--p.first; --p.second;            return  p;}   template<typename T, typename U> pair<T,U>& operator++           (pair<T, U> &p){++p.first; ++p.second;            return  p;}   template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p){is >> p.first >> p.second;        return is;}   template<typename T, typename U> ostream& operator<<(ostream& os, pair<T, U>& p){os << p.first <<     << p.second; return os;}   template<typename T, typename U> pair<T,U> operator-(pair<T,U> a, pair<T,U> b){return mp(a.first-b.first, a.second-b.second);}   template<typename T, typename U> pair<T,U> operator+(pair<T,U> a, pair<T,U> b){return mp(a.first+b.first, a.second+b.second);}   template<typename T, typename U> void umin(T& a, U b){if (a > b) a = b;}   template<typename T, typename U> void umax(T& a, U b){if (a < b) a = b;}      #ifdef HOME   #define SHOW_COLORS   #include  C:/C++ libs/print.cpp    #else   #define show(...)     42   #define mclock        42   #define shows         42   #define debug if (false)   #endif      const int mod = 1e9 + 7;      int main() {       ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);          int n;       cin >> n;       vector<int> a(n);       vector<char> t(n);       {           int m;           cin >> m;           vector<int> p(m), k(m), b(m), w(m);           for (int i = 0; i < m; ++i) {               cin >> p[i] >> k[i] >> b[i] >> w[i];           }           for (int i = 0; i < m; ++i) {               ll seed = b[i];               ll base = w[i];               auto rn = [&]() {                   ll ret = seed;                   seed = (seed * base + 233) % mod;                   return ret;               };               for (int j = (i == 0 ? 0ll : p[i - 1]) + 1; j <= p[i]; ++j) {                   t[j - 1] = (rn() % 2) + 1;                   a[j - 1] = (rn() % k[i]) + 1;               }           }       }       if (t[0] == 2) {           for (int i = 0; i < n; ++i) {               t[i] = 3 - t[i];           }       }          show(a);       show(t);          auto calc = [&]() {           vector<int> res(n, 0);           ll s1 = 0, s2 = 0;           for (int i = 0; i < n; ++i) {               if (t[i] == 1) {                   s1 += a[i];               } else {                   s2 += a[i];               }           }           show(s1, s2);           if (s1 == s2) {               res = a;               return res;           }           vector<ll> sms(n, 0);           bool sw = false;           int fr = 0;           // show(a);           // show(t);           if (s1 < s2) {               sw = true;               for (int i = 0; i < n; ++i) {                   if (t[i] == 2) {                       fr = i;                       break;                   }               }               a[0]--;               vector<char> tt;               vector<int> aa;               for (int i = 0; i < n; ++i) {                   tt.pb(t[(i + fr) % n]);                   aa.pb(a[(i + fr) % n]);               }               // show(fr);               swap(t, tt);               swap(a, aa);               for (int i = 0; i < n; ++i) {                   t[i] = 3 - t[i];               }           }              show(a);           show(t);              if (true) {               vector<pair<int, ll>> v;               for (int i = 0; i < n; ++i) {                   if (v.empty() || t[v.back().first] != t[i])                       v.eb(i, 0);                   v.back().second += a[i];               }               // show(v);               sms[0]++;               v[0].second--;               auto ad = [&](pair<int, ll> p) {                   if (v.empty() || t[v.back().first] != t[p.first]) {                       v.pb(p);                       return;                   }                   v.back().second += p.second;               };               if (v[0].second == 0) {                   v.erase(v.begin());               } else {                   auto x = v[0];                   // v.pb(v[0]);                   v.erase(v.begin());                   ad(x);               }               show(v);               while (v.size() > 1) {                   show(v);                   if (t[v[0].first] == 1) {                       auto x = v[0];                       v.erase(v.begin());                       ad(x);                   }                   pair<int, ll> tmp = {-1, -1};                   if (t[v.back().first] == 2) {                       tmp = v.back();                       v.pop_back();                   }                   if (v.size() < 2) {                       show(v, tmp);                       if (tmp.first != -1)                           show(t[tmp.first]);                       show(t[v[0].first]);                       assert(false);                   }                   if (v[v.size() - 2].second == v[v.size() - 1].second) {                       ll x = v[v.size() - 2].second;                       sms[v[v.size() - 1].first] += x;                       sms[v[v.size() - 2].first] += x;                       v.pop_back();                       v.pop_back();                   } else if (v[v.size() - 2].second < v[v.size() - 1].second) {                       ll x = v[v.size() - 2].second;                       sms[v[v.size() - 1].first] += x;                       sms[v[v.size() - 2].first] += x;                       auto u = v.back();                       v.pop_back();                       v.pop_back();                       u.second -= x;                       ad(u);                   } else {                       ll x = v[v.size() - 1].second;                       sms[v[v.size() - 1].first] += x;                       sms[v[v.size() - 2].first] += x;                       v.pop_back();                       v.back().second -= x;                   }                   if (tmp.first != -1)                       ad(tmp);               }              }              show(sms);              if (sw) {               vector<ll> smss;               vector<char> tt;               vector<int> aa;               for (int i = 0; i < n; ++i) {                   tt.pb(t[(i - fr + n) % n]);                   aa.pb(a[(i - fr + n) % n]);                   smss.pb(sms[(i - fr + n) % n]);               }               swap(t, tt);               swap(a, aa);               swap(sms, smss);               for (int i = 0; i < n; ++i) {                   t[i] = 3 - t[i];               }               sms[0]++;               a[0]++;           }              show(sms);              vector<ll> have(3, 0);           for (int i = 0; i < n * 2 + 5; ++i) {               sms[i % n] += have[t[i % n]];               ll v = min(sms[i % n], (ll)a[i % n] - res[i % n]);               res[i % n] += v;               have[t[i % n]] = sms[i % n] - v;               sms[i % n] = 0;           }              return res;       };          auto r = calc();       show(r);       ll res = 1;       for (ll i = 1; i <= n; ++i) {           ll ans = r[i - 1];           ans ^= (i * i);           ans += 1;           ans %= mod;           res = res * ans % mod;       }       cout << res <<   n ;          return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool chmax(T& a, const T& b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool chmin(T& a, const T& b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   long long int gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long int ceil(long long int a, long long int b) { return (a + b - 1) / b; }   long long int digit(long long int a) { return (long long int)log10(a); }   const long long int MOD = 1e9 + 7, INF = 1e18;   long long int dx[8] = {1, 0, -1, 0, 1, -1, 1, -1},                 dy[8] = {0, 1, 0, -1, -1, -1, 1, 1};   void YN(bool flag) { cout << (flag ?  YES  :  NO ) <<   n ; }   struct point {     long long int r;     long long int x, y;   };   long long int N, K;   int main() {     cin >> N >> K;     vector<long long int> arr(N);     for (long long int i = (0), i_end_ = (N); i < i_end_; i++) {       cin >> arr[i];     }     sort((arr).begin(), (arr).end());     vector<pair<long long int, long long int> > vec;     long long int curr = arr[0], cnt = 1;     for (long long int i = (0), i_end_ = (N - 1); i < i_end_; i++) {       if (arr[i + 1] != curr) {         vec.push_back({curr, cnt});         curr = arr[i + 1];         cnt = 1;       } else {         cnt++;       }     }     vec.push_back({curr, cnt});     N = ((long long int)(vec).size());     vector<long long int> sums_l(N);     vector<long long int> sums_r(N);     vector<long long int> sumn_l(N);     vector<long long int> sumn_r(N);     long long int sum = 0;     for (long long int i = (0), i_end_ = (N - 1); i < i_end_; i++) {       sum += vec[i].second;       sums_l[i + 1] = sums_l[i] + (vec[i + 1].first - vec[i].first) * sum;       sumn_l[i + 1] = sum;     }     sum = 0;     for (long long int i = (0), i_end_ = (N - 1); i < i_end_; i++) {       sum += vec[N - i - 1].second;       sums_r[i + 1] =           sums_r[i] + (vec[N - i - 1].first - vec[N - i - 2].first) * sum;       sumn_r[i + 1] = sum;     }     long long int minv = INF;     for (long long int i = (0), i_end_ = (((long long int)(vec).size()));          i < i_end_; i++) {       long long int rest = K - sums_l[i];       if (rest < 0) continue;       long long int idx =           upper_bound((sums_r).begin(), (sums_r).end(), rest) - sums_r.begin();       idx--;       rest -= sums_r[idx];       long long int score = vec[N - idx - 1].first - vec[i].first;       score -= rest / sumn_r[idx + 1];       chmin(minv, score);     }     for (long long int i = (0), i_end_ = (((long long int)(vec).size()));          i < i_end_; i++) {       long long int rest = K - sums_r[i];       if (rest < 0) continue;       long long int idx =           upper_bound((sums_l).begin(), (sums_l).end(), rest) - sums_l.begin();       idx--;       rest -= sums_l[idx];       long long int score = vec[N - i - 1].first - vec[idx].first;       score -= rest / sumn_l[idx + 1];       chmin(minv, score);     }     cout << max(0ll, minv) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long modpow(long long a, long long b,                    long long mod = (long long)(1e9 + 7)) {     if (!b) return 1;     a %= mod;     return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int mxn = 1e5, mod = 1e9 + 9;   long long ans = 0;   int n;   int x[mxn], y[mxn];   int support[mxn];   bool inqueue[mxn];   map<int, map<int, int> > ds;   priority_queue<int, vector<int>, greater<int> > pq;   priority_queue<int, vector<int>, less<int> > pq2;   int take(int i, int j) {     if (!ds.count(i) || !ds[i].count(j)) return -1;     return ds[i][j];   }   void supportAdjust(int i) {     if (i == -1) return;     support[i] = 0;     for (int d = -1; d <= 1; d++)       if (take(x[i] + d, y[i] - 1) != -1) support[i]++;     if (y[i] == 0) support[i] = 30000;   }   void evaluate(int i) {     if (i == -1) return;     bool b4 = inqueue[i];     inqueue[i] = false;     for (int d = -1; d <= 1; d++)       if (take(x[i] + d, y[i] + 1) != -1)         inqueue[i] |= support[take(x[i] + d, y[i] + 1)] == 1;     inqueue[i] ^= 1;     if (!b4 && inqueue[i]) {       pq.push(i);       pq2.push(i);     }   }   void takeout(int turn) {     int i;     if (turn % 2 == 0) {       while (pq2.size() && !inqueue[pq2.top()]) pq2.pop();       if (!pq2.size()) return;       i = pq2.top();       pq2.pop();     } else {       while (pq.size() && !inqueue[pq.top()]) pq.pop();       if (!pq.size()) return;       i = pq.top();       pq.pop();     }     ans = ((ans * n) % mod + i) % mod;     inqueue[i] = 0;     ds[x[i]].erase(y[i]);     for (int d = -1; d <= 1; d++) supportAdjust(take(x[i] + d, y[i] + 1));     for (int d = -2; d <= 2; d++) evaluate(take(x[i] + d, y[i]));     for (int d = -1; d <= 1; d++) evaluate(take(x[i] + d, y[i] - 1));   }   void solve() {     scanf( %d , &n);     for (int i = 0; i < n; i++) inqueue[i] = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &x[i]);       scanf( %d , &y[i]);       if (!ds.count(x[i])) ds[x[i]] = map<int, int>();       ds[x[i]][y[i]] = i;     }     for (int i = 0; i < n; i++) supportAdjust(i);     for (int i = 0; i < n; i++) evaluate(i);     for (int i = 0; i < n; i++) takeout(i);     cout << ans % mod << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     string number;     cin >> number;     int n = number.length();     int answer;     vector<vector<int> > remainders = {         {}, {1}, {1, 2, 4, 3}, {1, 3, 4, 2}, {1, 4}};     int last_digit = number[n - 1] -  0 ;     if (n == 1) {       answer = (remainders[1][last_digit % 1] + remainders[2][last_digit % 4] +                 remainders[3][last_digit % 4] + remainders[4][last_digit % 2]) %                5;     } else {       int last_two_digits = (number[n - 1] -  0 ) + 10 * (number[n - 2] -  0 );       answer = (remainders[1][last_two_digits % 1] +                 remainders[2][last_two_digits % 4] +                 remainders[3][last_two_digits % 4] +                 remainders[4][last_two_digits % 2]) %                5;     }     cout << answer << endl;   }   int main() {     {       ios::sync_with_stdio(false);       cout << fixed << setprecision(10);     }     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 500005, mod = 1000000007;   long long int a, b, c, d, e, f, g, h[N], arr[N];   string s;   vector<long long int> v;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> a;     long long int ans = 0, tek = 0, cift = 0;     for (long long int i = 1; i <= a; i++) {       cin >> arr[i];       ans += arr[i] / 2;       if (i % 2 == 0)         cift += arr[i] % 2;       else         tek += arr[i] % 2;       if (tek and cift) tek--, cift--, ans++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int cnt = 1e8;   int main() {     cin >> n >> m;     cout << (n >= 27 ? m : m % (1 << n));   }


#include <bits/stdc++.h>   using namespace std;   const int N = 31;   int a[1000010];   long long cnt1[N + 10];   long long cnt2[N + 10];   long long cnt3[N + 10];   long long cnt4[N + 10];   int b[1000010];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = (0); i < (n); ++i) scanf( %d , &a[i]);     int c = 0;     for (int i = (0); i < (n); ++i) {       for (int j = (0); j < (N); ++j)         if ((a[i] >> j) & 1) cnt1[j]++;     }     for (int i = (0); i < (m); ++i) {       scanf( %d , &b[i]);       cnt4[b[i]]++;     }     int res = 0;     int l = 0, r = m;     while (l <= r) {       int mid = (l + r) / 2;       int k = N - 1;       int now = mid;       for (int j = (0); j < (N); ++j) {         cnt3[j] = ((now < cnt4[j]) ? (now) : (cnt4[j]));         now -= cnt3[j];       }       for (int j = (0); j < (N); ++j) cnt2[j] = cnt1[j];       bool f = true;       for (int i = N - 1; i >= 0; --i) {         cnt2[i] += cnt2[i + 1] + cnt2[i + 1];         if (cnt2[i] < cnt3[i]) {           f = false;           break;         } else           cnt2[i] -= cnt3[i];       }       if (f) {         res = mid;         l = mid + 1;       } else         r = mid - 1;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int movei[] = {0, 0, 1, -1, 1, 1, -1, -1};   int movej[] = {1, -1, 0, 0, 1, -1, 1, -1};   const int MXN = 1e5 + 7;   int can(vector<int> &FRQ, int k) {     int mx = 1;     while (true) {       bool makable = true;       int total = 0;       for (int x : FRQ) total += x / mx;       if (total < k) makable = false;       if (!makable) {         mx--;         break;       }       mx++;     }     return k * mx;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       string s;       cin >> s;       vector<int> frq(26, 0);       for (char c : s) frq[c -  a ]++;       int ans = 1;       for (int i = 1; i * i <= k; i++) {         if (k % i == 0) ans = max({ans, can(frq, i), can(frq, k / i)});       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       long long arr[n], arr1[n], arr2[n];       long long F1 = INT_MIN, F2 = INT_MIN;       for (int i = 0; i < n; ++i) {         cin >> arr[i];         F1 = max(F1, arr[i]);       }       for (int i = 0; i < n; ++i) {         arr1[i] = F1 - arr[i];         F2 = max(F2, arr1[i]);       }       for (int i = 0; i < n; ++i) {         arr2[i] = F2 - arr1[i];       }       if ((k - 1) & 1) {         for (int i = 0; i < n; ++i) {           cout << arr2[i] <<    ;         }       } else {         for (int i = 0; i < n; ++i) {           cout << arr1[i] <<    ;         }       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   long long int gcd(long long int a, long long int b) {     return a ? gcd(b % a, a) : b;   }   long long int power(long long int a, long long int b) {     long long int ans = 1;     long long int s = a;     long long int t = b;     while (t) {       if (t % 2 == 1) ans *= s, ans %= 998244353;       s *= s, s %= 998244353;       t /= 2;     }     return ans;   }   long long int inv(long long int k) { return power(k, 998244353 - 2); }   long long int fact[110];   long long int invFact[110];   std::vector<long long int> prime;   int check[110];   std::vector<int> V;   long long int func(long long int k) {     V.clear();     for (int i = 0; i < prime.size(); i++) {       if (k % prime[i] != 0) continue;       int count = 0;       while (k % prime[i] == 0) count++, k /= prime[i];       V.push_back(count);     }     int sum = 0;     for (int i = 0; i < V.size(); i++) sum += V[i];     long long int ans = fact[sum];     for (int i = 0; i < V.size(); i++) ans *= invFact[V[i]], ans %= 998244353;     return ans;   }   std::vector<long long int> P;   int main() {     fact[0] = 1;     for (int i = 1; i <= 100; i++)       fact[i] = fact[i - 1] * i, fact[i] %= 998244353;     for (int i = 0; i <= 100; i++) invFact[i] = inv(fact[i]);     long long int a;     int b;     scanf( %lld%d , &a, &b);     long long int a2 = a;     for (long long int i = 2; i * i <= a; i++) {       if (a2 % i == 0) {         prime.push_back(i);         while (a2 % i == 0) a2 /= i;       }     }     if (a2 > 1) prime.push_back(a2);     for (int i = 1; i <= b; i++) {       long long int c, d;       scanf( %lld%lld , &c, &d);       long long int e = gcd(c, d);       long long int s1 = func(c / e);       long long int s2 = func(d / e);       printf( %lld n , (s1 * s2) % 998244353);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cout << 2000 << endl;     for (int i = 1; i <= 1000; ++i) cout << i <<     << 1 <<     << i <<   2 n ;     for (int i = 1000; i >= 1; --i) cout << i <<     << 1 <<     << i <<   2 n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e3 + 10;   int n, a[N], k, dp[N];   void bsearch() {     long long l = -1, r = 2e9 + 1;     while (l + 1 < r) {       long long mid = (r + l) / 2;       bool check = false;       for (int i = 0; i < n; i++) {         dp[i] = i;         for (int j = 0; j < i; j++) {           if (abs(a[i] - a[j]) > (i - j) * mid) continue;           dp[i] = min(dp[i], dp[j] + i - j - 1);         }         if (dp[i] + n - i - 1 <= k) {           check = true;           break;         }       }       if (check) {         r = mid;       } else {         l = mid;       }     }     cout << r << endl;   }   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     bsearch();   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double eps = 1e-9;   const int inf = 2000000000;   const long long infLL = 9000000000000000000;   template <typename first, typename second>   ostream &operator<<(ostream &os, const pair<first, second> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  { ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  } ;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   template <typename T>   ostream &operator<<(ostream &os, const multiset<T> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   template <typename first, typename second>   ostream &operator<<(ostream &os, const map<first, second> &v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); ++it) {       if (it != v.begin()) os <<  ,  ;       os << it->first <<   =   << it->second;     }     return os <<  ] ;   }   void faltu() { cerr <<   n ; }   template <typename T>   void faltu(T a[], int n) {     for (int i = 0; i < n; ++i) cerr << a[i] <<    ;     cerr <<   n ;   }   template <typename T, typename... hello>   void faltu(T arg, const hello &...rest) {     cerr << arg <<    ;     faltu(rest...);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n, cnt1 = 0, cnt2 = 0, x;     cin >> n;     while (n--) {       cin >> x;       if (x == 100) {         cnt1++;       } else {         cnt2++;       }     }     if (cnt1 % 2 == 1) {       cout <<  NO  <<   n ;     } else if (cnt1 == 0 && cnt2 % 2 == 1) {       cout <<  NO  <<   n ;     } else {       cout <<  YES  <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 600005;   int minx[Maxn], tip[Maxn];   int a[Maxn], b[Maxn], c[Maxn];   int n, m, i, h, L, R, t, ans;   void ins(int p, int l, int r, int pos, int data) {     if (l == r) {       minx[p] = data;       return;     }     int mid = (l + r) >> 1;     if (pos <= mid)       ins(p * 2 + 1, l, mid, pos, data);     else       ins(p * 2 + 2, mid + 1, r, pos, data);     minx[p] = min(minx[p * 2 + 1], minx[p * 2 + 2]);   }   void push(int p) {     minx[p * 2 + 1] += tip[p];     tip[p * 2 + 1] += tip[p];     minx[p * 2 + 2] += tip[p];     tip[p * 2 + 2] += tip[p];     tip[p] = 0;   }   void add(int p, int l, int r, int L, int R, int dlt) {     if (L > r || l > R) return;     if (L <= l && R >= r) {       minx[p] += dlt;       tip[p] += dlt;       return;     }     if (tip[p]) push(p);     int mid = (l + r) >> 1;     add(p * 2 + 1, l, mid, L, R, dlt);     add(p * 2 + 2, mid + 1, r, L, R, dlt);     minx[p] = min(minx[p * 2 + 1], minx[p * 2 + 2]);   }   int main() {     scanf( %d%d%d , &n, &m, &h);     for (i = 1; i <= m; i++) scanf( %d , &b[i]);     sort(b + 1, b + m + 1);     for (i = 1; i <= m / 2; i++) swap(b[i], b[m - i + 1]);     for (i = 1; i <= m; i++) b[i] = h - b[i];     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     for (i = 1; i <= m; i++) c[i] = a[i];     sort(c + 1, c + m + 1);     for (i = 1; i <= m; i++) {       t = lower_bound(c + 1, c + m + 1, b[i]) - c;       ins(0, 1, m, i, i - t);     }     ans += (minx[0] >= 0);     for (i = m + 1; i <= n; i++) {       if (a[i] > a[i - m]) {         L = upper_bound(b + 1, b + m + 1, a[i - m]) - b;         R = upper_bound(b + 1, b + m + 1, a[i]) - b - 1;         if (L <= R && L <= m) add(0, 1, m, L, R, 1);       } else if (a[i] < a[i - m]) {         L = upper_bound(b + 1, b + m + 1, a[i]) - b;         R = upper_bound(b + 1, b + m + 1, a[i - m]) - b - 1;         if (L <= R && L <= m) add(0, 1, m, L, R, -1);       }       ans += (minx[0] >= 0);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int len(char* a) {     int count;     for (int i = 0; a[i] !=   0 ; ++i) {       ++count;     }     return count;   }   int main() {     char a[101], b[101], c[101];     int found = 0, i, j;     fscanf(stdin,  %s%s%s , a, b, c);     if (len(a) + len(b) != len(c)) {       fprintf(stdout,  NO );       return 0;     }     for (i = 0; c[i] !=   0 ; ++i) {       for (j = 0; a[j] !=   0 ; ++j) {         if (c[i] == a[j]) {           found = 1;           a[j] = 1;           break;         }       }       if (!found) {         for (j = 0; b[j] !=   0 ; ++j) {           if (c[i] == b[j]) {             found = 1;             b[j] = 1;             break;           }         }       }       if (!found) {         fprintf(stdout,  NO );         return 0;       }       found = 0;     }     fprintf(stdout,  YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e6;   const int Linf = 1e9;   const long long LLinf = (long long)1e18;   const int maxn = 1e5 + 5;   int n, a[maxn];   long long k, res = 0;   int sum[maxn], sum1[maxn], cnt;   map<int, int> mmap;   set<int> s;   void Enter() {     cin >> n >> k;     for (int i = (1); i <= (n); ++i) cin >> a[i], s.insert(a[i]);     cnt = 0;     for (int c : s) mmap[c] = ++cnt;     for (int i = (1); i <= (n); ++i) a[i] = mmap[a[i]];   }   void update(int key, int x, int delta) {     for (; x <= cnt; x += x & -x)       if (key)         sum[x] += delta;       else         sum1[x] += delta;   }   int su(int key, int x) {     int r = 0;     for (; x > 0; x &= x - 1)       if (key)         r += sum[x];       else         r += sum1[x];     return r;   }   void Init() {     int j = 1;     int i = 1;     long long now = 0;     for (int i = (1); i <= (n); ++i) {       now += i - 1 - su(0, a[i]);       update(0, a[i], 1);     }     while (i <= n) {       update(1, a[i], 1);       now += su(0, a[i] - 1) + (su(1, cnt) - su(1, a[i]));       while ((now > k || j <= i) && j <= n) {         now -= su(1, cnt) - su(1, a[j]) + su(0, a[j] - 1);         update(0, a[j], -1);         ++j;       }       ++i;       res += n - j + 1;     }     cout << res;   }   void Solve() {}   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     Enter();     Init();     Solve();   }


#include <bits/stdc++.h>   using namespace std;   char getDiffColor(char a, char b) {     map<char, bool> mp;     mp[a] = true, mp[b] = true;     if (mp.find( R ) == mp.end())       return  R ;     else if (mp.find( G ) == mp.end())       return  G ;     else       return  B ;   }   int main() {     int cnt = 0;     string st;     cin >> cnt >> st;     cnt = 0;     int i = 0;     while (i + 2 < (st.size())) {       if (st[i] == st[i + 1] && st[i] == st[i + 2])         st[i + 1] = getDiffColor(st[i], st[i]), cnt++;       i++;     }     char pre = st[0];     for (int i = 0; i < st.size() - 1; i++)       if (st[i] == st[i + 1])         st[i] = getDiffColor(pre, st[i]), pre = st[i], cnt++;       else         pre = st[i];     cout << cnt <<   n  << st;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using pi = pair<int, int>;   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return b > a ? a = b, 1 : 0;   }   void setIO(string name =   ) {     cin.tie(0)->sync_with_stdio(0);     if (int((name).size())) {       freopen((name +  .in ).c_str(),  r , stdin);       freopen((name +  .out ).c_str(),  w , stdout);     }   }   const string yes =  YES n , no =  NO n ;   const int MOD = 1e9 + 7;   const int MX = 2e2 + 10;   const ll INF = 1e18;   const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};   const char dc[4] = { D ,  R ,  U ,  L };   string S;   int K, A, B;   bool dp[MX][MX];   vi ans;   int main() {     setIO();     cin >> K >> A >> B >> S;     dp[0][0] = true;     for (int i = 1; i <= K; ++i)       for (int k = 1; k < MX; ++k)         for (int j = A; j <= B; ++j)           if (k - j >= 0) dp[i][k] |= dp[i - 1][k - j];     if (dp[K][int((S).size())] == false) return cout <<  No solution , 0;     int num = K, sub = int((S).size());     ans.push_back(sub);     while (num && sub) {       for (int i = A; i <= B; ++i) {         if (sub - i >= 0 && dp[num - 1][sub - i]) {           --num;           ans.push_back(sub - i);           sub -= i;           break;         }       }     }     reverse(begin(ans), end(ans));     for (int i = 0; i < int((ans).size()) - 1; ++i) {       for (int j = ans[i]; j < ans[i + 1]; ++j) {         cout << S[j];       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 10;   const int maxm = 100000 + 10;   vector<int> adj[maxn];   int fa[maxn][18], dep[maxn];   void trans(int prev, int u) {     dep[u] = dep[prev] + 1;     fa[u][0] = prev;     for (int i = 1; (1 << i) <= dep[u]; i++) {       fa[u][i] = fa[fa[u][i - 1]][i - 1];     }     int len = adj[u].size();     for (int i = 0; i < len; i++) {       int v = adj[u][i];       if (v == prev) continue;       trans(u, v);     }   }   int lca(int u, int v) {     if (dep[u] > dep[v]) swap(u, v);     for (int i = 0; (1 << i) <= dep[v] - dep[u]; i++) {       if ((dep[v] - dep[u]) & 1 << i) v = fa[v][i];     }     if (u == v) return u;     for (int i = 18; i >= 0; i--) {       if ((1 << i) <= dep[u] && fa[u][i] != fa[v][i]) {         u = fa[u][i];         v = fa[v][i];       }     }     return fa[u][0];   }   int dis(int u, int v) {     int fff = lca(u, v);     return dep[u] + dep[v] - 2 * dep[fff];   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 2; i <= n; i++) {       int j;       scanf( %d , &j);       adj[i].push_back(j);       adj[j].push_back(i);     }     dep[1] = 0;     trans(1, 1);     for (int i = 0; i < m; i++) {       int q[3];       for (int i = 0; i < 3; i++) scanf( %d , &q[i]);       int a[3], ttt = 0;       for (int i = 0; i < 3; i++) {         for (int j = i + 1; j < 3; j++) {           a[ttt++] = lca(q[i], q[j]);         }       }       int k = 0;       for (int i = 0; i < 3; i++)         if (dep[a[i]] > dep[a[k]]) k = i;       k = a[k];       int ans = 0;       for (int i = 0; i < 3; i++) ans = max(ans, dis(k, q[i]));       printf( %d n , ans + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gd(const string &a, const string &b) {     int d = 0;     for (int i = 0; i < (int)a.size(); i++)       if (a[i] != b[i]) d++;     return d;   }   string a[1005];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int mind = 1000;     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++) mind = min(mind, gd(a[i], a[j]));     cout << min(6, (mind - 1) / 2) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool a[4111][4111];   int n;   bool v[4111] = {0};   int p[4111] = {0};   int cnt = 0;   int ans[4111] = {0};   bool dfs_find(int i, int lt) {     v[i] = true;     for (int j = 1; j <= n; j++) {       if (a[i][j] > 0 && lt != j && i != j) {         if (v[j]) {           p[cnt++] = j;           return true;         } else {           p[cnt++] = j;           if (dfs_find(j, i)) {             return true;           }           cnt--;         }       }     }     return false;   }   void dfs(int i) {     for (int j = 1; j <= n; j++) {       if (i != j && a[i][j] > 0 && ans[j] == -1) {         ans[j] = ans[i] + 1;         dfs(j);       }     }   }   int main() {     memset(a, 0, sizeof(a));     memset(ans, -1, sizeof(ans));     cin >> n;     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       a[x][y] = a[y][x] = 1;     }     p[cnt++] = 1;     dfs_find(1, 0);     ans[p[cnt - 1]] = 0;     for (int i = cnt - 2; i >= 0; i--) {       if (p[i] == p[cnt - 1]) break;       ans[p[i]] = 0;     }     for (int i = 1; i <= n; i++) {       if (ans[i] == 0) {         dfs(i);       }     }     for (int i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 501000;   const int INF = 0x3f3f3f3f;   vector<int> v[MAX_N], w[MAX_N];   struct skt {     int x, y;   };   int dis[MAX_N][2];   int tox[MAX_N][2], toy[MAX_N][2];   int n;   int b[MAX_N];   void bfs() {     int i;     queue<int> q;     skt t;     memset(dis, INF, sizeof(dis));     q.push(n);     dis[n][0] = 0;     dis[n][1] = 0;     while (!q.empty()) {       int x = q.front();       q.pop();       for (i = 0; i < v[x].size(); i++) {         int y = v[x][i];         int k = w[x][i];         if (dis[y][k] > max(dis[x][0], dis[x][1]) + 1) {           dis[y][k] = max(dis[x][0], dis[x][1]) + 1;           q.push(y);         }       }     }   }   int main(void) {     int m, i, x, y, t;     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) {       scanf( %d%d%d , &x, &y, &t);       if (x == y) continue;       v[y].push_back(x);       w[y].push_back(t);     }     bfs();     if (dis[1][0] == INF || dis[1][1] == INF)       printf( -1 n );     else       printf( %d n , max(dis[1][0], dis[1][1]));     for (i = 1; i <= n; i++) {       if (dis[i][0] > dis[i][1])         b[i] = 0;       else         b[i] = 1;       printf( %d , b[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     long long sum = 0;     for (int i = 0; i < n; ++i) sum += a[i];     long long cntWhite = 0;     for (int i = 0; i < n; ++i) cntWhite += (a[i] + i % 2) / 2;     cout << min(cntWhite, sum - cntWhite) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   map<string, int> mp;   const int N = 1e5 + 5;   int a[N];   int cost[N];   int g[N];   int main() {     int n, k, m;     cin >> n >> k >> m;     for (int i = 1; i <= n; i++) {       cin >> s;       mp[s] = i;     }     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     int x;     int minn;     while (k--) {       scanf( %d , &x);       minn = 0x3f3f3f3f;       for (int i = 0; i < x; i++) {         scanf( %d , &g[i]);         minn = min(minn, a[g[i]]);       }       for (int i = 0; i < x; i++) {         cost[g[i]] = minn;       }     }     long long ans = 0;     for (int i = 0; i < m; i++) {       cin >> s;       ans += cost[mp[s]];     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long md = 1e9 + 7;   int n, k, ans, mx, edg[1010][1010], dis[1001];   vector<int> v, gr[100000];   bool vis[1001];   void dfs(int x, int l) {     vis[x] = true;     dis[x] = 0;     for (int i = 0; i < gr[x].size(); i++) {       int u = gr[x][i];       if (vis[u] == false) {         dfs(u, l + 1);       }       dis[x] = max(dis[x], dis[u] + 1);       mx = max(mx, dis[x]);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> k;     int kk = k;     while (k--) {       for (int i = 1; i <= n; i++) {         int x;         cin >> x;         edg[x][k] = i;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == j) continue;         bool t = false;         for (int z = 0; z < kk; z++) {           if (edg[i][z] > edg[j][z]) t = true;         }         if (t == false) gr[i].push_back(j);       }     }     for (int i = 1; i <= n; i++) {       dfs(i, 1);       memset(vis, 0, sizeof vis);     }     cout << mx + 1;   }


#include <bits/stdc++.h>   using namespace std;   ifstream fin( abc.in );   string str[2];   long long let[26][500001];   long long a, b, sum, m;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int main() {     cin >> a >> b;     cin >> str[0] >> str[1];     long long len_mx = str[1].size(), len_mn = str[0].size(), i, j, dif_len;     int p = 1;     if (str[0].size() > str[1].size())       p = 0, len_mx = str[0].size(), len_mn = str[1].size();     dif_len = str[p].size() - str[1 - p].size();     long long cmmmc = len_mx * len_mn / gcd(len_mx, len_mn);     m = a / (cmmmc / str[0].size());     long long cmmdc = gcd(len_mn, len_mx);     long long sx = 0;     if (dif_len == 0) {       for (i = 0; i < len_mx; i++)         if (str[0][i] != str[1][i]) sx += m;     } else {       for (i = 0; i < len_mx; i++) {         char c = str[p][i];         let[(long)(c -  a )][i % cmmdc]++;       }       for (i = 0; i < len_mn; i++) {         char c = str[1 - p][i];         sx += m * (str[p].size() / cmmdc - let[c -  a ][i % cmmdc]);       }     }     cout << sx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long a, long long b) {     long long prod = 1;     while (b) {       if (b & 1) prod = (prod * a);       a = (a * a);       b >>= 1;     }     return prod;   }   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> odd, even;       for (int i = 0; i < n; i++) {         int x;         cin >> x;         if (x % 2 == 1) {           odd.push_back(i + 1);         } else           even.push_back(i + 1);       }       if (even.size() > 0)         cout << 1 << endl << even[0] << endl;       else {         if (odd.size() >= 2) {           cout << 2 << endl << odd[0] <<     << odd[1] << endl;         } else {           cout << -1 << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long long maxn = 60;   const long long mod = 1e9 + 7;   const long double PI = acos((long double)-1);   long long pw(long long a, long long b, long long md = mod) {     long long res = 1;     while (b) {       if (b & 1) {         res = (a * res) % md;       }       a = (a * a) % md;       b >>= 1;     }     return (res);   }   long long n, t;   long long c[maxn][maxn];   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> t;     long long ans = 0;     if (t == 1) ans--;     if (__builtin_popcountll(t) != 1) cout << 0, exit(0);     ;     c[0][0] = 1;     for (long long i = 1; i < maxn; i++) {       c[i][0] = 1;       for (long long j = 1; j <= i; j++) c[i][j] = c[i - 1][j] + c[i - 1][j - 1];     }     t = __builtin_ctzll(t) + 1;     n += 1;     long long cnt = 0;     for (long long i = 50; i >= 0; i--) {       if (cnt > t) break;       if (n & (1LL << i)) ans += c[i][t - cnt], cnt++;     }     if (__builtin_popcountll(n) == t) ans++;     cout << ans;     return (0);   }


#include <bits/stdc++.h>   using namespace std;   long long Set(long long N, long long pos) { return N = N | (1 << pos); }   long long reset(long long N, long long pos) { return N = N & ~(1 << pos); }   bool check(long long N, long long pos) { return (bool)(N & (1 << pos)); }   void CI(long long &_x) { scanf( %I64d , &_x); }   void CO(long long &_x) { cout << _x; }   template <typename T>   void getarray(T a[], long long n) {     for (long long i = 0; i < n; i++) cin >> a[i];   }   template <typename T>   void prLLIarray(T a[], long long n) {     for (long long i = 0; i < n - 1; i++) cout << a[i] <<    ;     cout << a[n - 1] << endl;   }   const double EPS = 1e-9;   const long long INF = 0x7f7f7f7f;   long long dr8[8] = {1, -1, 0, 0, 1, -1, -1, 1};   long long dc8[8] = {0, 0, -1, 1, 1, 1, -1, -1};   long long dr4[4] = {0, 0, 1, -1};   long long dc4[4] = {-1, 1, 0, 0};   long long kn8r[8] = {1, 2, 2, 1, -1, -2, -2, -1};   long long kn8c[8] = {2, 1, -1, -2, -2, -1, 1, 2};   char grid[155][155];   int main() {     vector<pair<int, int> > V;     int n, m;     cin >> n >> m;     int last;     for (int i = 0; i < n; i++) {       int mini = 1 << 30, maxi = -1;       for (int j = 0; j < m; j++) {         cin >> grid[i][j];         if (grid[i][j] ==  W ) {           last = i;           mini = min(mini, j);           maxi = max(maxi, j);         }       }       V.push_back(make_pair(mini, maxi));     }     int ans = 0, pos_x = 0, pos_y = 0;     for (int i = 0; i <= last; i++) {       int dir = i % 2;       if (dir == 0) {         int mm = pos_y;         mm = max(mm, V[i].second);         if (i < last) mm = max(mm, V[i + 1].second);         ans += mm - pos_y + 1;         pos_y = mm;       } else {         int mm = pos_y;         mm = min(mm, V[i].first);         if (i < last) mm = min(mm, V[i + 1].first);         ans += (pos_y - mm) + 1;         pos_y = mm;       }     }     cout << max(ans - 1, 0) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const double PI = acos(-1.0);   long long f[555], n;   string g[] = { < ,  ^ ,  > ,  v };   string s, t;   int main() {     cin >> s >> t;     cin >> n;     if (n % 2 == 0) {       cout <<  undefined ;       return 0;     }     for (int i = 0; i < 4; i++)       if (s == g[i]) {         if (g[(i + (n % 4)) % 4] == t)           cout <<  cw ;         else           cout <<  ccw ;       }   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int v, id, tag;   } a[100010];   int cmp1(node x, node y) { return x.v < y.v; }   int cmp2(node x, node y) { return x.id < y.id; }   int ccount[100010];   int main() {     int n, tt;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i].v), a[i].id = i;     sort(a + 1, a + n + 1, cmp1);     a[1].tag = tt = 1;     ccount[tt] = 1;     for (int i = 2; i <= n; i++) {       if (a[i].v != a[i - 1].v) tt++;       a[i].tag = tt;       ccount[tt]++;     }     sort(a + 1, a + n + 1, cmp2);     int nowh = 1, maxh = 0, block = 0;     for (int i = 1; i <= n; i++) {       ccount[a[i].tag]--;       maxh = max(maxh, a[i].tag);       while (!ccount[nowh]) nowh++;       if (nowh >= maxh) block++;     }     printf( %d n , block);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 501;   int n, k;   int C[N];   bool Dp[N][N][N];   vector<int> Ans;   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , C + i);     Dp[n][0][0] = true;     for (int idx = n - 1; idx >= 0; idx--)       for (int Sum = 0; Sum <= k; Sum++)         for (int X = 0; X <= k; X++) {           Dp[idx][Sum][X] |= Dp[idx + 1][Sum][X];           Dp[idx][Sum][X] |= (Sum >= C[idx] && Dp[idx + 1][Sum - C[idx]][X]);           Dp[idx][Sum][X] |= (Sum >= C[idx] && X >= C[idx] &&                               Dp[idx + 1][Sum - C[idx]][X - C[idx]]);         }     for (int X = 0; X <= k; X++)       if (Dp[0][k][X]) Ans.push_back(X);     printf( %d n , Ans.size());     for (auto x : Ans) printf( %d  , x);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, x, f[5005][5005], g[5005], h[5005], cnt[5005];   long long ans;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &x);       ++cnt[x];     }     m = 5000;     for (int i = 1; i <= m; ++i) {       memcpy(f[i], f[i - 1], sizeof f[i]);       g[i] = g[i - 1];       for (int j = 2, x = i; j <= x; ++j)         while (x % j == 0) {           x /= j;           ++f[i][j];           ++g[i];         }       for (int j = i; j; --j)         if (f[i][j] == f[i - 1][j])           h[i] += f[i][j];         else {           h[i] += f[i - 1][j];           break;         }     }     ans = 0x3f3f3f3f3f3f3f3fLL;     for (int i = 0; i <= m; ++i) {       long long sum = 0;       for (int j = i - 1, k = g[i]; ~j; --j) {         k = min(k, h[j + 1]);         sum += (long long)(g[i] + g[j] - k * 2) * cnt[j];       }       for (int j = i + 1, k = g[i]; j <= m; ++j) {         k = min(k, h[j]);         sum += (long long)(g[i] + g[j] - k * 2) * cnt[j];       }       ans = min(ans, sum);       sum = 0;       for (int j = i - 1, k = h[i]; ~j; --j) {         k = min(k, h[j + 1]);         sum += (long long)(h[i] + g[j] - k * 2) * cnt[j];       }       for (int j = i, k = h[i]; j <= m; ++j) {         k = min(k, h[j]);         sum += (long long)(h[i] + g[j] - k * 2) * cnt[j];       }       ans = min(ans, sum);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   int n, m, k, par[N], portal[N];   long long dist[N];   vector<pair<int, int> > gr[N];   vector<pair<int, pair<int, int> > > edges;   vector<pair<long long, pair<int, int> > > new_edges;   inline int get(int x) {     if (par[x] < 0) return x;     return par[x] = get(par[x]);   }   inline bool unin(int x, int y) {     x = get(x);     y = get(y);     if (x == y) return false;     par[x] += par[y];     par[y] = x;     return true;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b, c;       scanf( %d %d %d , &a, &b, &c);       gr[a].push_back({c, b});       gr[b].push_back({c, a});       edges.push_back({c, {a, b}});     }     for (int i = 1; i <= n; i++) {       dist[i] = 1e18;       par[i] = -1;     }     set<pair<long long, int> > q;     scanf( %d , &k);     for (int i = 0; i < k; i++) {       int p;       scanf( %d , &p);       dist[p] = 0;       portal[p] = p;       q.insert({0, p});     }     while (!q.empty()) {       auto pp = *q.begin();       q.erase(pp);       int v = pp.second;       for (auto pp : gr[v]) {         int cost = pp.first, to = pp.second;         if (dist[to] > dist[v] + cost) {           q.erase({dist[to], to});           dist[to] = dist[v] + cost;           portal[to] = portal[v];           q.insert({dist[to], to});         }       }     }     for (int i = 1; i <= n; i++) gr[i].clear();     for (auto edge : edges) {       int cost = edge.first, a = edge.second.first, b = edge.second.second;       if (portal[a] == portal[b]) continue;       new_edges.push_back({dist[a] + dist[b] + cost, {portal[a], portal[b]}});     }     sort(new_edges.begin(), new_edges.end());     long long ans = dist[1];     for (auto edge : new_edges) {       long long cost = edge.first;       int a = edge.second.first, b = edge.second.second;       if (unin(a, b)) {         ans += cost;       }     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     int i, j;     cin >> n >> k;     int arr[n];     for (i = 0; i < n; i++) cin >> arr[i];     int one, two;     int m = 0;     for (i = 0; i < k; i++) {       one = 0, two = 0;       for (j = i; j < n; j = j + k) {         if (arr[j] == 1)           one++;         else           two++;       }       m = m + min(one, two);     }     cout << m << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long inf = numeric_limits<long long>::max();   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int cases;     cin >> cases;     while (cases--) {       int n;       cin >> n;       if (n % 2 == 0)         cout << 1;       else         cout << 7;       n -= 2;       n /= 2;       while (n--) cout << 1;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5010;   vector<int> ne[maxn];   int cnt[maxn], n;   int dp[maxn], res[maxn];   void dfs(int v, int prev = -1) {     cnt[v] = 1;     vector<int> w;     int last = n - 1;     for (int i = 0; i < (int)ne[v].size(); i++) {       int u = ne[v][i];       if (u != prev) {         dfs(u, v);         cnt[v] += cnt[u];         w.push_back(cnt[u]);         last -= cnt[u];       }     }     if (last > 0) {       w.push_back(last);     }     fill(dp, dp + n, 0);     dp[0] = 1;     for (int i = 0, sum = 0; i < (int)w.size(); sum += w[i], i++) {       for (int s = sum; s >= 0; s--) {         if (dp[s]) {           dp[s + w[i]] = 1;         }       }     }     for (int i = 1; i + 1 < n; i++) {       res[i] |= dp[i];     }   }   int main(void) {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       ne[a].push_back(b);       ne[b].push_back(a);     }     dfs(1);     int res_n = 0;     for (int i = 1; i + 1 < n; i++) {       res_n += res[i];     }     printf( %d n , res_n);     for (int i = 1; i + 1 < n; i++) {       if (res[i]) {         printf( %d %d n , i, n - i - 1);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, x;     cin >> a >> b >> x;     string s =   ;     if (a >= b) {       s.push_back( 0 );       a--;     } else {       s.push_back( 1 );       b--;     }     while (x) {       if (x == 1) {         if (s.back() ==  1 ) {           while (b) s.push_back( 1 ), b--;           while (a) s.push_back( 0 ), a--;         } else {           while (a) s.push_back( 0 ), a--;           while (b) s.push_back( 1 ), b--;         }       } else if (s.back() ==  1 ) {         s.push_back( 0 );         a--;       } else {         s.push_back( 1 );         b--;       }       x--;     }     cout << s << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a[2222];   int dis[2222];   int main() {     for (int i = 0; i < 2222; ++i) dis[i] = -1;     dis[0] = 0;     int n, m;     cin >> n >> m;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         char c;         cin >> c;         if (c ==  # ) a[i].push_back(n + j), a[n + j].push_back(i);       }     queue<int> q;     q.push(0);     while (!q.empty()) {       int p = q.front();       q.pop();       for (int i = 0; i < a[p].size(); ++i)         if (dis[a[p][i]] == -1) {           q.push(a[p][i]);           dis[a[p][i]] = dis[p] + 1;         }     }     cout << dis[n - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> ans;   int b;   queue<pair<int, int> > qu;   void OUT() {     if (ans.size() == 201) ans.pop_back();     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) printf( %d  , ans[i]);   }   int solve(int last, int i) {     if (last == 0) return 0;     qu.push(pair<int, int>(last, i));     return (last + b - 1) / b;   }   int main() {     int n, a, k, cnt = 0, last2 = 0;     string s;     scanf( %d %d %d %d , &n, &a, &b, &k);     cin >> s;     s +=  1 ;     int last = 0;     string tmp = s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  1 ) {         for (last = max(last, i - b + 1); last <= i; last++) tmp[last] =  1 ;       }     }     s = tmp;     last = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  1 )         cnt += solve(last, i), last = 0;       else         last++;     }     while (cnt >= a) {       ans.push_back(qu.front().second);       cnt--;       if (qu.front().first > b)         qu.front().second -= b, qu.front().first -= b;       else         qu.pop();     }     OUT();   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long r, x1, x2, y1, y2, ans;     cin >> r >> x1 >> y1 >> x2 >> y2;     double d1, d2;     x1 -= x2;     y1 -= y2;     d1 = sqrt(1.0 * (x1 * x1 + y1 * y1));     d2 = d1;     d2 /= (2 * r * 1.0);     if (floor(d2) == ceil(d2)) {       ans = d2;     } else {       ans = d2 + 1;     }     cout << ans;   }   int main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   template <typename _T>   inline void _DBG(const char *s, _T x) {     cerr << s <<   =   << x <<   n ;   }   template <typename _T, typename... args>   void _DBG(const char *s, _T x, args... a) {     while (*s !=  , ) cerr << *s++;     cerr <<   =   << x <<  , ;     _DBG(s + 1, a...);   }   const int M = 1e9 + 7;   long long P(long long a, int x) {     long long res = 1;     while (x--) res = res * a % M;     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     cout << (P(2, m) * P(n + 1, m - 1)) % M * (n + 1 - m) % M <<   n ;     return 0;   }


#include <bits/stdc++.h>   const int MaxN = 100000, MaxLog = 17;   struct graph_t {     int cnte;     int head[MaxN + 5], to[MaxN * 2 + 5], next[MaxN * 2 + 5];     inline void clear() {       cnte = 0;       memset(head, 0, sizeof head);       memset(to, 0, sizeof to);       memset(next, 0, sizeof next);     }     inline void addEdge(int u, int v) {       cnte++;       to[cnte] = v;       next[cnte] = head[u];       head[u] = cnte;     }   };   int Te, N, Pos_A, Pos_B, L;   int Mx[MaxN + 5], Mmx[MaxN + 5], Mmmx[MaxN + 5], Mupx[MaxN + 5];   int Fa[MaxLog + 1][MaxN + 5], Dep[MaxN + 5], Deepest[MaxN + 5];   graph_t Gr;   void init() {     scanf( %d %d %d , &N, &Pos_A, &Pos_B);     for (int i = 1; i < N; ++i) {       int u, v;       scanf( %d %d , &u, &v);       Gr.addEdge(u, v);       Gr.addEdge(v, u);     }   }   void dfs_getL(int u, int f, int d) {     if (u == Pos_B) {       L = d;       return;     }     for (int i = Gr.head[u]; i; i = Gr.next[i]) {       int v = Gr.to[i];       if (v == f) continue;       dfs_getL(v, u, d + 1);     }   }   void dfs1(int u, int f) {     for (int i = Gr.head[u]; i; i = Gr.next[i]) {       int v = Gr.to[i];       if (v == f) continue;       dfs1(v, u);       if (Mx[v] + 1 > Mx[u]) {         Mmmx[u] = Mmx[u];         Mmx[u] = Mx[u];         Mx[u] = Mx[v] + 1;       } else if (Mx[v] + 1 > Mmx[u]) {         Mmmx[u] = Mmx[u];         Mmx[u] = Mx[v] + 1;       } else if (Mx[v] + 1 > Mmmx[u]) {         Mmmx[u] = Mx[v] + 1;       }     }   }   void dfs2(int u, int f) {     for (int i = Gr.head[u]; i; i = Gr.next[i]) {       int v = Gr.to[i];       if (v == f) continue;       if (Mx[v] + 1 == Mx[u])         Mupx[v] = std::max(Mupx[u], Mmx[u]) + 1;       else         Mupx[v] = std::max(Mupx[u], Mx[u]) + 1;       dfs2(v, u);     }   }   void dfs3(int u) {     Deepest[u] = u;     for (int i = Gr.head[u]; i; i = Gr.next[i]) {       int v = Gr.to[i];       if (v == Fa[0][u]) continue;       Dep[v] = Dep[u] + 1;       Fa[0][v] = u;       for (int j = 1; (1 << j) <= Dep[v]; ++j) Fa[j][v] = Fa[j - 1][Fa[j - 1][v]];       dfs3(v);       if (Dep[Deepest[v]] > Dep[Deepest[u]]) Deepest[u] = Deepest[v];     }   }   inline int kthAncestor(int u, int k) {     for (int i = MaxLog; i >= 0; --i)       if (k & (1 << i)) u = Fa[i][u];     return u;   }   inline bool isAncestor(int u, int v) {     if (Dep[u] < Dep[v]) std::swap(u, v);     return kthAncestor(u, Dep[u] - Dep[v]) == v;   }   inline int getLca(int u, int v) {     if (Dep[u] < Dep[v]) std::swap(u, v);     int d = Dep[u] - Dep[v];     for (int i = MaxLog; i >= 0; --i)       if (d & (1 << i)) u = Fa[i][u];     if (u == v) return u;     for (int i = MaxLog; i >= 0; --i)       if (Fa[i][u] != Fa[i][v]) {         u = Fa[i][u];         v = Fa[i][v];       }     return Fa[0][u];   }   void solve() {     dfs_getL(Pos_A, 0, 0);     dfs1(1, 0);     dfs2(1, 0);     int pivot = 0;     for (int i = 1; i <= N; ++i) {       int cnt = 0;       if (Mx[i] >= L) cnt++;       if (Mmx[i] >= L) cnt++;       if (Mmmx[i] >= L) cnt++;       if (Mupx[i] >= L) cnt++;       if (cnt >= 3) {         pivot = i;       }     }     if (pivot == 0) {       puts( NO );       return;     }     dfs3(pivot);     int a = Pos_A, b = Pos_B, lca = getLca(a, b);     int maxdepa = Dep[a], maxdepb = Dep[b];     for (;;) {       if (isAncestor(a, b) == true) {         puts( YES );         return;       }       if (Dep[Deepest[a]] > maxdepa) {         int pace = Dep[Deepest[a]] - Dep[a];         a = Deepest[a];         if (pace >= Dep[b] - Dep[lca]) {           puts( YES );           return;         } else           b = kthAncestor(b, pace);         maxdepa = Dep[a];       } else if (Dep[Deepest[b]] > maxdepb) {         int pace = Dep[Deepest[b]] - Dep[b];         b = Deepest[b];         if (pace >= Dep[a] - Dep[lca]) {           puts( YES );           return;         } else           a = kthAncestor(a, pace);         maxdepb = Dep[b];       } else {         puts( NO );         return;       }     }   }   void clear() {     N = Pos_A = Pos_B = L = 0;     memset(Mx, 0, sizeof Mx);     memset(Mmx, 0, sizeof Mmx);     memset(Mmmx, 0, sizeof Mmmx);     memset(Mupx, 0, sizeof Mupx);     memset(Fa, 0, sizeof Fa);     memset(Dep, 0, sizeof Dep);     memset(Deepest, 0, sizeof Deepest);     Gr.clear();   }   int main() {     scanf( %d , &Te);     for (int t = 1; t <= Te; ++t) {       init();       solve();       clear();     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   map<string, long long int> month;   void Month() {     month[ January ] = 1, month[ February ] = 2, month[ March ] = 3,     month[ April ] = 4, month[ May ] = 5, month[ June ] = 6;     month[ July ] = 7, month[ August ] = 8, month[ September ] = 9,     month[ October ] = 10, month[ November ] = 11, month[ December ] = 12;   }   long long int A[1000000];   long long int B[1000000];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     vector<long long int> v;     long long int n, res, x = 0;     cin >> n;     res = n;     while (res != 0) x++, res /= 10;     x *= 9;     if (x >= n)       x = 1;     else       x = n - x;     for (long long int i = x; i <= n; i++) {       long long int val = i, s = 0;       while (val != 0) s += (val % 10), val /= 10;       if ((i + s) == n) v.push_back(i);     }     if (v.size()) {       cout << v.size() << endl;       for (long long int i = 0; i < v.size(); i++) cout << v[i] << endl;     } else       cout << 0 << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   using ll = long long;   using vi = vector<int>;   using pii = pair<int, int>;   const int BSZ = 600;   const int N = 100228;   const int LG = 17;   int n, m;   vector<vi> g;   vi pred;   vi in, out;   int timer;   int up[LG][N];   vi ts;   vi evs;   vi sgn;   vector<bool> alive;   vi cnt;   vi dif;   vector<bool> any;   int cur_add;   vi ans;   vi bkt[2 * N];   vi srt[2 * BSZ];   void dfs(int v) {     in[v] = timer++;     for (int to : g[v]) {       dfs(to);     }     out[v] = timer++;   }   bool upper(int u, int v) { return (in[u] <= in[v] && out[v] <= out[u]); }   int lca(int u, int v) {     if (in[u] > in[v]) {       swap(u, v);     }     if (upper(u, v)) {       return u;     }     for (int i = LG - 1; i >= 0; i--) {       if (!upper(up[i][u], v)) {         u = up[i][u];       }     }     return up[0][u];   }   void dfs_calc(int v) {     cnt[v] = !alive[v];     for (int to : g[v]) {       dfs_calc(to);       cnt[v] += cnt[to];       any[v] = any[v] | any[to];     }     dif[v] = ts[v] - cnt[v];     if (!any[v] && alive[v]) {       cur_add += (dif[v] < 0);     }   }   int32_t main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     pred.resize(n, -1);     g.resize(n);     for (int i = 0; i < n - 1; i++) {       int p;       cin >> p;       --p;       pred[i + 1] = p;       g[p].push_back(i + 1);       up[0][i + 1] = p;     }     ts.resize(n);     for (auto& x : ts) {       cin >> x;     }     for (int j = 1; j < LG; j++) {       for (int i = 0; i < n; i++) {         up[j][i] = up[j - 1][up[j - 1][i]];       }     }     in.resize(n);     out.resize(n);     dfs(0);     evs.resize(m);     sgn.resize(m);     for (int i = 0; i < m; i++) {       auto& x = evs[i];       cin >> x;       sgn[i] = (x > 0 ? -1 : 1);       x = abs(x) - 1;     }     alive.resize(n, true);     cnt.resize(n);     dif.resize(n);     any.resize(n);     ans.resize(m, 0);     for (int lb = 0; lb < m; lb += BSZ) {       int rb = min(m, lb + BSZ);       vi guys(rb - lb);       fill((any).begin(), (any).end(), false);       for (int i = lb; i < rb; i++) {         guys[i - lb] = evs[i];         any[guys[i - lb]] = true;       }       sort((guys).begin(), (guys).end(),            [](int u, int v) { return (in[u] < in[v]); });       guys.reserve(2 * (int)((guys).size()));       for (int i = (int)((guys).size()) - 2; i >= 0; i--) {         guys.push_back(lca(guys[i], guys[i + 1]));       }       guys.push_back(0);       sort((guys).begin(), (guys).end(),            [](int u, int v) { return (in[u] < in[v]); });       guys.resize(unique((guys).begin(), (guys).end()) - guys.begin());       vi comp_pred((int)((guys).size()), -1);       vi st;       int edge_check = 0;       for (int i = 0; i < (int)((guys).size()); i++) {         while (!st.empty() && !upper(guys[st.back()], guys[i])) {           st.pop_back();         }         if (!st.empty()) {           comp_pred[i] = st.back();           edge_check++;         }         st.push_back(i);       }       assert(edge_check == (int)((guys).size()) - 1);       cur_add = 0;       dfs_calc(0);       for (int i = lb; i < rb; i++) {         ans[i] = cur_add;       }       for (int i = 0; i < (int)((guys).size()); i++) {         srt[i].clear();       }       for (int i = 0; i < 2 * N; i++) {         bkt[i].clear();       }       for (int i = 0; i < (int)((guys).size()); i++) {         int u = guys[i];         bool st = alive[u];         int udif = dif[u];         for (int j = lb; j < rb; j++) {           if (upper(u, evs[j])) {             udif += sgn[j];           }           if (evs[j] == u) {             st = !st;           }           if (st) {             ans[j] += (udif < 0);           }         }         if (i) {           int anc = guys[comp_pred[i]];           int v = pred[u];           if (anc != v) {             while (v != anc) {               if (alive[v]) {                 bkt[dif[v] + N].push_back(i);               }               v = pred[v];             }           }         }       }       for (int i = 0; i < 2 * N; i++) {         for (int who : bkt[i]) {           srt[who].push_back(i - N);         }       }       for (int i = 0; i < (int)((guys).size()); i++) {         auto u = guys[i];         auto& difs = srt[i];         vector<pii> pref;         pref.reserve((int)((difs).size()));         for (auto x : difs) {           if (pref.empty()) {             pref.push_back({x, 1});           } else if (x != pref.back().first) {             pref.push_back({x, pref.back().second + 1});           } else {             pref.back().second++;           }         }         int pt = (int)((pref).size());         while (pt > 0 && pref[pt - 1].first >= 0) {           pt--;         }         int bound = 0;         for (int j = lb; j < rb; j++) {           if (upper(u, evs[j])) {             bound -= sgn[j];             if (pt < (int)((pref).size()) && pref[pt].first < bound) {               pt++;             }             if (pt > 0 && pref[pt - 1].first >= bound) {               pt--;             }           }           ans[j] += (pt ? pref[pt - 1].second : 0);         }       }       for (int i = lb; i < rb; i++) {         int u = evs[i];         alive[u] = !alive[u];       }     }     for (int i = 0; i < m; i++) {       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   void ex() {     cout <<  NO n ;     exit(0);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<pair<bool, int> > q(2 * n);     for (int i = 0; i < 2 * n; ++i) {       char t;       cin >> t;       if (t ==  + ) {         q[i] = {true, -1};       } else {         int x;         cin >> x;         q[i] = {false, x};       }     }     reverse(q.begin(), q.end());     vector<int> w, e;     for (int i = 0; i < 2 * n; ++i) {       if (q[i].first) {         if (!e.empty()) {           w.push_back(e.back());           e.pop_back();         } else {           ex();         }       } else {         if (!e.empty() and e.back() < q[i].second) {           ex();         }         e.push_back(q[i].second);       }     }     if (!e.empty()) {       ex();     }     cout <<  YES n ;     for (int i = n - 1; i > -1; --i) {       cout << w[i] <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int num = 1001;   struct node {     long long l, r;     int t;   } a[1008611];   long long ans[1008611], tm[1008611];   int main() {     long long n, m;     cin >> n >> m;     for (long long i = 0; i < m; i++) {       cin >> a[i].t >> a[i].l >> a[i].r;       if (a[i].t) {         for (long long k = a[i].l; k < a[i].r; k++) {           tm[k] = 1;         }       }     }     ans[1] = num;     for (long long i = 2; i <= n; i++) {       if (tm[i - 1] == 0) num--;       ans[i] = num;     }     for (long long j = 0; j < m; j++) {       int pos = 1;       for (long long k = a[j].l; k < a[j].r; k++) {         if (ans[k] > ans[k + 1]) {           pos = 0;           break;         }       }       if (pos != a[j].t) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long w1, h1, w2, h2, ans = 0;   int main() {     cin >> w1 >> h1 >> w2 >> h2;     ans += (h1 + h2) + 2;     ans += w2 + 1;     ans += (h1 + h2) + 1;     ans += w1 - w2;     ans += w1;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 1e5;   int t;   int n, m, k;   vector<int> graph[NMAX + 5];   int gr[NMAX + 5];   bool active[NMAX + 5];   bool in[NMAX + 5];   bool exists(int i, int j) {     vector<int>::iterator it = lower_bound(graph[i].begin(), graph[i].end(), j);     if (it != graph[i].end() && *it == j) {       return true;     }     return false;   }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d %d %d , &n, &m, &k);       for (int i = 1; i <= n; i++) {         gr[i] = 0;         graph[i].clear();         active[i] = 1;         in[i] = 0;       }       for (int i = 1; i <= m; i++) {         int u, v;         scanf( %d %d , &u, &v);         graph[u].push_back(v);         graph[v].push_back(u);         gr[u]++;         gr[v]++;       }       if (1LL * k * (k - 1) > 2 * m) {         printf( -1 n );         continue;       }       queue<int> q;       for (int i = 1; i <= n; i++) {         sort(graph[i].begin(), graph[i].end());         if (gr[i] < k) {           q.push(i);           in[i] = 1;         }       }       while (!q.empty()) {         int nod = q.front();         active[nod] = 0;         q.pop();         for (auto it : graph[nod]) {           gr[it]--;           if (in[it] == 0 && gr[it] < k) {             in[it] = 1;             q.push(it);           }         }       }       vector<int> ans;       for (int i = 1; i <= n; i++) {         if (active[i] == 1) {           ans.push_back(i);         }       }       if (ans.empty() == false) {         printf( 1 %d n , (int)ans.size());         for (auto it : ans) {           printf( %d  , it);         }         printf(  n );         continue;       }       for (int i = 1; i <= n; i++) {         gr[i] = graph[i].size();         active[i] = 1;         in[i] = 0;       }       for (int i = 1; i <= n; i++) {         if (gr[i] < k) {           in[i] = 1;           q.push(i);         }       }       bool found = false;       while (!q.empty()) {         int nod = q.front();         q.pop();         active[nod] = 0;         if (gr[nod] == k - 1) {           vector<int> nodes = {nod};           for (auto it : graph[nod]) {             if (active[it] == 1) {               nodes.push_back(it);             }           }           bool ok = true;           for (int i = 0; i < (int)nodes.size() && ok; i++) {             for (int j = i + 1; j < (int)nodes.size() && ok; j++) {               ok &= exists(nodes[i], nodes[j]);             }           }           if (ok == true) {             found = true;             printf( 2 n );             for (auto it : nodes) {               printf( %d  , it);             }             printf(  n );             break;           }         }         for (auto it : graph[nod]) {           gr[it]--;           if (in[it] == 0 && gr[it] < k) {             in[it] = 1;             q.push(it);           }         }       }       if (found == false) {         printf( -1 n );         continue;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string t =  abacaba ;   int get(string a) {     int cnt = 0;     for (int i = 0; i < a.size(); i++) {       if (a.substr(i, t.size()) == t) cnt++;     }     return cnt;   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n;       string a;       cin >> n >> a;       int cnt = 0;       for (int i = 0; i < a.size(); i++) {         if (a.substr(i, t.size()) == t) cnt++;       }       if (cnt > 1)         puts( No );       else if (cnt == 1) {         puts( Yes );         for (int i = 0; i < a.size(); i++) {           if (a[i] !=  ? )             printf( %c , a[i]);           else             putchar( z );         }         puts(  );       } else {         bool f = false;         for (int i = 0; i < n; i++) {           int cnt = 0;           for (int k = i, j = 0; j < t.size() && k < a.size(); k++, j++) {             if (a[k] == t[j] || a[k] ==  ? )               cnt++;             else               break;           }           if (cnt == t.size()) {             string ts = a;             for (int k = i, j = 0; j < t.size(); k++, j++) ts[k] = t[j];             if (get(ts) > 1)               continue;             else {               f = true;               puts( Yes );               for (int i = 0; i < ts.size(); i++)                 if (ts[i] ==  ? ) ts[i] =  z ;               cout << ts << endl;             }             break;           }         }         if (!f) puts( No );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     assert(1 <= n && n <= (int)(2e5));     string sex;     cin >> sex;     assert(sex.size() == n);     for (int i = 0; i < n; ++i) {       assert(sex[i] ==  B  || sex[i] ==  G );     }     vector<int> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];       assert(1 <= a[i] && a[i] <= (int)(1e7));     }     vector<int> pre(n), nxt(n);     priority_queue<pair<int, pair<int, int> >,                    vector<pair<int, pair<int, int> > >,                    greater<pair<int, pair<int, int> > > >         pq;     for (int i = 0; i < n; ++i) {       pre[i] = i - 1;       nxt[i] = i + 1;       if (i > 0 && sex[i - 1] != sex[i]) {         pq.push(make_pair(abs(a[i - 1] - a[i]), make_pair(i - 1, i)));       }     }     vector<bool> mark(n, true);     vector<pair<int, int> > result;     while (!pq.empty()) {       int i = pq.top().second.first;       int j = pq.top().second.second;       pq.pop();       if (mark[i] && mark[j]) {         mark[i] = false;         mark[j] = false;         result.push_back(make_pair(i, j));         i = pre[i];         j = nxt[j];         if (i != -1) {           nxt[i] = j;         }         if (j != n) {           pre[j] = i;         }         if (i != -1 && j != n && sex[i] != sex[j] && mark[i] && mark[j]) {           pq.push(make_pair(abs(a[i] - a[j]), make_pair(i, j)));         }       }     }     cout << result.size() << endl;     for (int i = 0; i < result.size(); ++i) {       cout << result[i].first + 1 <<     << result[i].second + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q, x, y;   int a[200005];   long long lazy[200005 * 4], S[200005 * 4];   void push(int node, int bas, int son) {     S[node * 2] += lazy[node];     S[node * 2 + 1] += lazy[node];     lazy[node * 2] += lazy[node];     lazy[node * 2 + 1] += lazy[node];     lazy[node] = 0;   }   int get(int node, int bas, int son) {     if (bas == son) return (S[node] == 0 ? bas : -1);     if (S[node] < 0) return -1;     push(node, bas, son);     return max(get(node * 2, bas, ((bas + son) / 2)),                get(node * 2 + 1, ((bas + son) / 2) + 1, son));   }   void up(int node, int bas, int son, int x, int y, long long val) {     if (bas > y || son < x) return;     if (bas >= x && son <= y) {       S[node] += val;       lazy[node] += val;       return;     }     push(node, bas, son);     up(node * 2, bas, ((bas + son) / 2), x, y, val);     up(node * 2 + 1, ((bas + son) / 2) + 1, son, x, y, val);     S[node] = max(S[node * 2], S[node * 2 + 1]);   }   int main() {     long long sum = 0;     scanf( %d %d , &n, &q);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       up(1, 1, n, i, i, a[i] - sum);       sum += a[i];     }     while (q--) {       scanf( %d %d , &x, &y);       up(1, 1, n, x, x, y - a[x]);       up(1, 1, n, x + 1, n, a[x] - y);       a[x] = y;       printf( %d n , get(1, 1, n));     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int x, y, z;     cin >> x >> y >> z;     int x1, y1, z1;     cin >> x1 >> y1 >> z1;     int a[6];     for (auto &z : a) cin >> z;     int sum = 0;     if (x < 0)       sum += a[4];     else if (x > x1)       sum += a[5];     if (y < 0)       sum += a[0];     else if (y > y1)       sum += a[1];     if (z < 0)       sum += a[2];     else if (z > z1)       sum += a[3];     cout << sum <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   const int M = 1000005;   const long long INF = (long long)(1e15);   long long a[N][N];   long long retc[M], retr[M];   priority_queue<pair<long long, int> > sc, sr;   int main() {     int n, m, k, p;     scanf( %d%d%d%d , &n, &m, &k, &p);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %I64d , &a[i][j]);       }     }     for (int i = 1; i <= n; i++) {       long long s = 0;       for (int j = 1; j <= m; j++) {         s += a[i][j];       }       sr.push(make_pair(s, i));     }     for (int j = 1; j <= m; j++) {       long long s = 0;       for (int i = 1; i <= n; i++) {         s += a[i][j];       }       sc.push(make_pair(s, j));     }     for (int i = 1; i <= k; i++) {       long long s = sr.top().first;       int id = sr.top().second;       retr[i] = retr[i - 1] + s;       s -= p * m;       sr.pop();       sr.push(make_pair(s, id));     }     for (int i = 1; i <= k; i++) {       long long s = sc.top().first;       int id = sc.top().second;       retc[i] = retc[i - 1] + s;       s -= p * n;       sc.pop();       sc.push(make_pair(s, id));     }     long long ans = -INF;     for (int i = 0; i <= k; i++) {       ans = max(ans, retr[i] + retc[k - i] - (long long)i * (k - i) * p);     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double PI = 3.14159265359;   long long inf = 1000000000000000007;   long long mod = 1000000007;   long long mod1 = 998244353;   const bool multi = 0;   long long DP[500007];   long long s[500007];   vector<long long> G[500007];   long long ans = inf, n;   void dfs(long long v, long long o) {     s[v] = 1;     vector<pair<pair<long long, long long>, long long>> DPs;     DP[v] = inf;     if ((long long)(G[v]).size() == 1) DP[v] = 0;     long long sum = 0;     for (auto u : G[v]) {       if (u == o) continue;       dfs(u, v);       s[v] += s[u];       DPs.push_back({{-2 * s[u], 2 * DP[u] + s[u] * (s[u] + 1)}, u});     }     sort(DPs.begin(), DPs.end());     vector<pair<long long, long long>> CHT;     for (auto x : DPs) {       long long l = 0, r = (long long)(CHT).size() - 1, sr;       long long S = n - s[x.second];       ans =           min(ans, 2 * DP[x.second] + (n - s[x.second]) * (n - s[x.second] - 1));       while (l <= r) {         sr = (l + r) / 2;         long long L =             2 * DP[x.second] + S * (S - 1) + S * CHT[sr].first + CHT[sr].second;         ans = min(ans, L);         if (sr + 1 == (long long)(CHT).size()) break;         long long R = 2 * DP[x.second] + S * (S - 1) + S * CHT[sr + 1].first +                       CHT[sr + 1].second;         ans = min(ans, R);         if (L <= R)           r = sr - 1;         else           l = sr + 1;       }       if ((long long)(CHT).size() == 0 || x.first.first != CHT.back().first)         CHT.push_back({x.first.first, x.first.second});       DP[v] = min(DP[v], DP[x.second] +                              (s[v] - s[x.second]) * (s[v] - s[x.second] - 1) / 2);     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long tt;     if (multi)       cin >> tt;     else       tt = 1;     while (tt--) {       long long a, b;       cin >> n;       for (long long i = 1; i < n; i++) {         cin >> a >> b;         G[a].push_back(b);         G[b].push_back(a);       }       dfs(1, -1);       ans /= 2;       cout << ans + 2 * (n * (n - 1) / 2 - ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() *                  ((uint64_t) new char | 1));   int K, N;   vector<int> A, B, Z;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> K;     N = 1 << K;     Z.resize(N);     int all_xor = 0;     for (auto &z : Z) {       cin >> z;       all_xor ^= z;     }     if (all_xor != 0) {       cout <<  Fou  <<   n ;       return 0;     }     A.resize(N);     B.resize(N);     vector<int> location(N);     for (int i = 0; i < N; i++) A[i] = B[i] = i;     shuffle(A.begin(), A.end(), rng);     shuffle(B.begin(), B.end(), rng);     for (int i = 0; i < N; i++) location[B[i]] = i;     for (int i = 0; i < N; i++) {       int u = i;       while (Z[u] != (A[u] ^ B[u])) {         int v = location[A[u] ^ Z[u]];         swap(B[u], B[v]);         swap(location[B[u]], location[B[v]]);         if (v > i) {           break;         } else {           swap(A[v], A[i + 1]);           u = v;         }       }     }     cout <<  Shi  <<   n ;     for (int i = 0; i < N; i++) cout << A[i] << (i < N - 1 ?     :   n );     for (int i = 0; i < N; i++) cout << B[i] << (i < N - 1 ?     :   n );   }


#include<bits/stdc++.h>   #define PI acos(-1.0)    #define eps 1e-8   #define fi first   #define se second   #define m_p make_pair   //#define int long long   #define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)   using namespace std;   typedef long long ll;   typedef unsigned int uint;    const double E_num = 0.57721566490153286060651209;   const int maxn = 2e3 + 10;   const int N = 5e5 + 10;   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;         int n,m,w;   int mp[maxn][maxn];   ll dis1[maxn][maxn],dis2[maxn][maxn],ans1 = 1e18,ans2 = 1e18;   queue<pair<int,int>> q;   inline void bfs1(int x,int y)   {    #define dis dis1    memset(dis,INF,sizeof(dis));    q.push(m_p(x,y));    dis[x][y] = 0;    while(!q.empty())    {     x = q.front().fi,y = q.front().se;     q.pop();     if(dis[x - 1][y] > dis[x][y] + w && mp[x - 1][y] >= 0)     {      q.push(m_p(x - 1,y));      dis[x - 1][y] = dis[x][y] + w;     }     if(dis[x + 1][y] > dis[x][y] + w && mp[x + 1][y] >= 0)     {      q.push(m_p(x + 1,y));      dis[x + 1][y] = dis[x][y] + w;     }     if(dis[x][y - 1] > dis[x][y] + w && mp[x][y - 1] >= 0)     {      q.push(m_p(x,y - 1));      dis[x][y - 1] = dis[x][y] + w;     }     if(dis[x][y + 1] > dis[x][y] + w && mp[x][y + 1] >= 0)     {      q.push(m_p(x,y + 1));      dis[x][y + 1] = dis[x][y] + w;     }    }    #undef dis   }   inline void bfs2(int x,int y)   {    #define dis dis2    memset(dis,INF,sizeof(dis));    q.push(m_p(x,y));    dis[x][y] = 0;    while(!q.empty())    {     x = q.front().fi,y = q.front().se;     q.pop();     if(dis[x - 1][y] > dis[x][y] + w && mp[x - 1][y] >= 0)     {      q.push(m_p(x - 1,y));      dis[x - 1][y] = dis[x][y] + w;     }     if(dis[x + 1][y] > dis[x][y] + w && mp[x + 1][y] >= 0)     {      q.push(m_p(x + 1,y));      dis[x + 1][y] = dis[x][y] + w;     }     if(dis[x][y - 1] > dis[x][y] + w && mp[x][y - 1] >= 0)     {      q.push(m_p(x,y - 1));      dis[x][y - 1] = dis[x][y] + w;     }     if(dis[x][y + 1] > dis[x][y] + w && mp[x][y + 1] >= 0)     {      q.push(m_p(x,y + 1));      dis[x][y + 1] = dis[x][y] + w;     }    }    #undef dis   }   int main()   {    IOS;    cin >> n >> m >> w;    for(int i = 0;i <= m + 1; ++i)    {     mp[0][i] = mp[n + 1][i] = -1;    }    for(int i = 1;i <= n + 1; ++i)    {     mp[i][0] = mp[i][m + 1] = -1;    }    for(int i = 1;i <= n; ++i)    {     for(int j = 1;j <= m; ++j)      {      cin >> mp[i][j];     }    }    bfs1(1,1);    bfs2(n,m);    for(int i = 1;i <= n; ++i)    {     for(int j = 1;j <= m; ++j)     {      if(mp[i][j] > 0) ans1 = min(ans1,dis1[i][j] + mp[i][j]);     }    }    for(int i = 1;i <= n; ++i)    {     for(int j = 1;j <= m; ++j)     {      if(mp[i][j] > 0) ans2 = min(ans2,dis2[i][j] + mp[i][j]);     }    }    ans1 = min(dis1[n][m] ,ans1 + ans2);    if(ans1 < 1e18) cout << ans1 << endl;    else cout << -1 << endl;    return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define lc cout<<  n    #define f1(a) for(int i=0;i<a;++i)   int main(){    ios_base::sync_with_stdio(false);    cin.tie(NULL);    cout.tie(NULL);    int t;cin>>t;    while(t--){     int n;cin>>n;     int a[n],b[n];     std::vector<int> pos_index,pos_dif;     std::vector<int> neg_index,neg_dif;     f1(n){cin>>a[i];}     f1(n){cin>>b[i];}     int test=0;     f1(n){test+=a[i]-b[i];      if(a[i]-b[i]>0){pos_index.emplace_back(i);pos_dif.emplace_back(a[i]-b[i]);}      else{       if(a[i]-b[i]<0){       neg_index.emplace_back(i);neg_dif.emplace_back(b[i]-a[i]);       }      }}     if(test!=0){cout<<-1;lc;}     else{      f1(n){test+=abs(a[i]-b[i]);}      int res=test/2;      cout<<res;lc;      vector<int>fr,se;      f1(pos_dif.size()){while(pos_dif[i]--){fr.emplace_back(pos_index[i]);}}      f1(neg_dif.size()){while(neg_dif[i]--){se.emplace_back(neg_index[i]);}}      f1(fr.size()){cout<<fr[i]+1<<   <<se[i]+1;lc;}                    }            }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool read(T &x) {     int c = getchar();     int sgn = 1;     while (~c && c< 0  | c>  9 ) {       if (c ==  - ) sgn = -1;       c = getchar();     }     for (x = 0; ~c &&  0  <= c && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ;     x *= sgn;     return ~c;   }   const long long N = 200005;   const long long MOD = 1e9 + 7;   long long cnt[N];   long long ara[N];   int main() {     long long n = ({       long long a;       read(a);       a;     });     long long mx = 0;     long long val;     for (int i = 1; i <= n; i++) {       ara[i] = ({         long long a;         read(a);         a;       });       ++cnt[ara[i]];       if (cnt[ara[i]] > mx) {         mx = cnt[ara[i]];         val = ara[i];       }     }     if (mx == n)       puts( 0 );     else {       cout << n - mx << endl;       for (int i = 1; i <= n; i++) {         if (ara[i] == val) {           for (long long j = i - 1; j >= 1; --j) {             if (ara[j] != val) {               if (ara[j] > val) {                 cout << 2 <<     << j <<     << j + 1 << endl;               } else {                 cout << 1 <<     << j <<     << j + 1 << endl;               }               ara[j] = val;             } else               break;           }           for (long long j = i + 1; j <= n; ++j) {             if (ara[j] != val) {               if (ara[j] > val) {                 cout << 2 <<     << j <<     << j - 1 << endl;               } else {                 cout << 1 <<     << j <<     << j - 1 << endl;               }               ara[j] = val;             } else               break;           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int a[1000004];   int main() {     int n, x;     long long sum;     int cnt;     while (scanf(  %d , &n) == 1) {       sum = 0LL;       cnt = 0;       for (int i = 0; i < n; i++) {         scanf(  %d , &a[i]);         if (a[i] % 2 == 1) cnt++;         sum += a[i];       }       if (sum % 2LL == 0LL) {         if (cnt % 2 == 0 && cnt > 0)           cout <<  First n ;         else           cout <<  Second n ;       } else         cout <<  First n ;     }   }


#include <bits/stdc++.h>   using namespace std;   double a[220005];   double b[220005];   int n;   double check(double x) {     double q1 = 0.0, q2 = 0.0, q3 = 0.0;     for (int i = 1; i <= n; i++) b[i] = a[i] - x;     for (int i = 1; i <= n; i++) q1 = max(b[i], b[i] + q1), q3 = max(q1, q3);     for (int i = 1; i <= n; i++) b[i] = (-1.0) * b[i];     for (int i = 1; i <= n; i++) q2 = max(b[i], b[i] + q2), q3 = max(q3, q2);     return q3;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lf , &a[i]);     double l, r;     l = -30000.0, r = 30000.0;     while (r - l > 1e-11) {       double mid1 = (l + r) / 2.0;       double mid2 = (mid1 + r) / 2.0;       if (check(mid1) >= check(mid2))         l = mid1;       else         r = mid2;     }     printf( %.13lf n , check((l + r) / (2.0)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 2e5 + 5;   const long long INF = 1e18;   const long long MOD = 1e9 + 7;   int seg[2][8 * maxN], lzy[2][8 * maxN];   int lt[maxN], rt[maxN], Q[2][2 * maxN], N;   vector<int> vec;   long long two_to_the_power_of(long long x) {     if (x == 0) return 1;     long long y = two_to_the_power_of(x / 2);     y = y * y % MOD;     if (x & 1) y = y * 2 % MOD;     return y;   }   void apply(bool b, int id, int s, int e, int x) {     seg[b][id] = 1ll * (e - s) * x % MOD;     lzy[b][id] = x;     return;   }   void shift(bool b, int id, int s, int e) {     if (lzy[b][id] == -1) return;     int md = (s + e) / 2;     apply(b, 2 * id, s, md, lzy[b][id]);     apply(b, 2 * id + 1, md, e, lzy[b][id]);     lzy[b][id] = -1;     return;   }   void update(bool b, int l, int r, int x, int id = 1, int s = 0, int e = N) {     if (l <= s && e <= r) {       apply(b, id, s, e, x);       return;     }     if (l >= e || s >= r) return;     shift(b, id, s, e);     int md = (s + e) / 2;     update(b, l, r, x, 2 * id, s, md);     update(b, l, r, x, 2 * id + 1, md, e);     seg[b][id] = (seg[b][2 * id] + seg[b][2 * id + 1]) % MOD;     return;   }   int fetch(bool b, int l, int r, int id = 1, int s = 0, int e = N) {     if (l <= s && e <= r) return seg[b][id];     if (l >= e || s >= r) return 0;     shift(b, id, s, e);     int md = (s + e) / 2;     return (fetch(b, l, r, 2 * id, s, md) + fetch(b, l, r, 2 * id + 1, md, e)) %            MOD;   }   int main() {     time_t START = clock();     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(lzy, -1, sizeof lzy);     int n, m, k;     scanf( %d%d%d , &k, &n, &m);     for (int i = 0; i < n + m; i++) {       scanf( %d%d , lt + i, rt + i);       vec.push_back(lt[i]);       vec.push_back(rt[i]);     }     vec.push_back(0);     vec.push_back(1);     vec.push_back(k);     sort(vec.begin(), vec.end());     vec.resize(unique(vec.begin(), vec.end()) - vec.begin());     N = vec.size();     for (int i = 0; i < n + m; i++) {       lt[i] = lower_bound(vec.begin(), vec.end(), lt[i]) - vec.begin();       rt[i] = lower_bound(vec.begin(), vec.end(), rt[i]) - vec.begin();       Q[i < n][rt[i]] = max(Q[i < n][rt[i]], lt[i]);     }     update(0, 0, 1, 1);     update(1, 0, 1, 1);     for (int i = 1; i < N; i++) {       update(0, 0, Q[1][i], 0);       update(1, 0, Q[0][i], 0);       if (i == N - 1) break;       for (int b = 0; b < 2; b++) {         int tmp = (1ll * fetch(b, 0, i) *                    (two_to_the_power_of(vec[i + 1] - vec[i] - 1) - 1) % MOD) %                   MOD;         tmp = (tmp + 1ll * fetch(1 - b, 0, i) *                          two_to_the_power_of(vec[i + 1] - vec[i] - 1) % MOD) %               MOD;         update(b, i, i + 1, tmp);       }     }     printf( %d n , (seg[0][1] + seg[1][1]) % MOD);     time_t FINISH = clock();     cerr <<  Execution time:            << (long double)(FINISH - START) / CLOCKS_PER_SEC * 1000.0          <<   milliseconds. n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ar[500005 + 5];   int main() {     long long i, j, k, n;     cin >> n;     if (n <= 2)       cout << 1 << endl;     else if (n == 3)       cout << 2 << endl;     else {       long long lo = 1LL, hi = n, ans = 1LL;       while (lo <= hi) {         long long md = (lo + hi) / 2LL;         if (md * 3LL <= n) {           ans = max(ans, md);           lo = md + 1LL;         } else           hi = md - 1LL;       }       if (ans * 3 + 1 <= n) {         cout << (ans * 2) + 1 << endl;       } else         cout << ans * 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll inf = 1e18;   int n, m;   int edges[22][2];   bool used[6][6];   int arr[7];   void init() {}   void input() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> edges[i][0] >> edges[i][1];       edges[i][0]--;       edges[i][1]--;     }   }   int check() {     int now = 0;     for (int i = 1; i <= 6; i++) {       for (int j = 1; j <= 6; j++) {         used[i][j] = false;       }     }     for (int i = 0; i < m; i++) {       int v = edges[i][0], u = edges[i][1];       if (!used[arr[v]][arr[u]]) {         now++;         used[arr[v]][arr[u]] = true;         used[arr[u]][arr[v]] = true;       }     }     return now;   }   void solve() {     int ans = 0;     for (arr[0] = 1; arr[0] < 7; arr[0]++) {       for (arr[1] = 1; arr[1] < 7; arr[1]++) {         for (arr[2] = 1; arr[2] < 7; arr[2]++) {           for (arr[3] = 1; arr[3] < 7; arr[3]++) {             for (arr[4] = 1; arr[4] < 7; arr[4]++) {               for (arr[5] = 1; arr[5] < 7; arr[5]++) {                 for (arr[6] = 1; arr[6] < 7; arr[6]++) {                   ans = max(ans, check());                 }               }             }           }         }       }     }     cout << ans << endl;   }   void output() {}   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int number_of_testcases = 1;     while (number_of_testcases--) {       init();       input();       solve();       output();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, t, n;     double x, y;     cin >> t;     while (t--) {       cin >> n;       switch (n) {         case 1:           j = 0;           break;         case 2:           j = 1;           break;         case 3:           j = 2;           break;         default:           x = double(n);           y = sqrt(x);           i = int(y);           if (n == (i * i)) {             j = (i - 1) + (i - 1);           } else {             n = n - (i * i);             if ((n % i) == 0) {               j = (i - 1) + (n / i) + (i - 1);             } else {               j = i + (n / i) + (i - 1);             }           }       }       cout << j << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > edge;   int flo[120][120], flo2[120][120], dp[120][120], menda[120][120], com;   int st[120], en[120];   vector<int> vc[120];   void sho(int n) {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == j) continue;         flo[i][j] = 1e7;       }     }     for (int i = 0; i < edge.size(); i++) {       flo[edge[i].first][edge[i].second] = 1;     }     for (int k = 1; k <= n; k++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           flo[i][j] = min(flo[i][k] + flo[k][j], flo[i][j]);         }       }     }   }   void sho2(int n, int stop) {     memset(flo2, 0, sizeof flo2);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == j && i != stop) continue;         flo2[i][j] = 1e7;       }     }     for (int i = 0; i < edge.size(); i++) {       if (edge[i].first == stop || edge[i].second == stop) continue;       flo2[edge[i].first][edge[i].second] = 1;     }     for (int k = 1; k <= n; k++) {       if (k == stop) continue;       for (int i = 1; i <= n; i++) {         if (i == stop) continue;         for (int j = 1; j <= n; j++) {           if (j == stop) continue;           flo2[i][j] = min(flo2[i][k] + flo2[k][j], flo2[i][j]);         }       }     }   }   void dp_func(int v, int bus, int x, int y) {     int f = -1;     for (int i = 0; i < vc[v].size(); i++) {       int w = vc[v][i];       if (flo[v][y] == flo[w][y] + 1) f = max(f, dp[w][bus]);     }     if (f == -1) f = 1e7;     for (int i = 1; i <= com; i++) {       if (bus == i) continue;       int c = st[i], d = en[i];       if (flo[c][d] == 1e7) continue;       if (menda[i][v] == 0) continue;       f = min(f, dp[v][i] + 1);     }     dp[v][bus] = min(f, dp[v][bus]);   }   int main() {     int i, j, k, l, n, m, a, b;     scanf( %d%d%d%d , &n, &m, &a, &b);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &l, &k);       edge.push_back(make_pair(l, k));       vc[l].push_back(k);     }     sho(n);     if (flo[a][b] == 1e7) {       cout <<  -1 ;       return 0;     }     scanf( %d , &com);     for (int i = 1; i <= com; i++) {       scanf( %d%d , &st[i], &en[i]);     }     for (int i = 1; i <= n; i++) {       sho2(n, i);       for (int j = 1; j <= com; j++) {         int x = st[j], y = en[j];         if (flo[x][y] < flo2[x][y]) menda[j][i] = 1;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= com; j++) dp[i][j] = 1e7;     }     for (int j = 1; j <= com; j++) {       if (flo[st[j]][en[j]] == 1e7) continue;       if (menda[j][b]) dp[b][j] = 0;     }     for (int ite = 1; ite <= n; ite++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= com; j++) {           int x = st[j], y = en[j];           if (flo[x][y] == 1e7) continue;           dp_func(i, j, x, y);         }       }     }     int ans = 1e7;     for (int j = 1; j <= com; j++) {       if (!menda[j][a]) continue;       ans = min(ans, dp[a][j]);     }     if (ans == 1e7)       ans = -1;     else       ans++;     cout << ans << endl;   }


#include <bits/stdc++.h>   const size_t Size = 1e5 + 5;   const size_t SqrtS = 775 + 5;   int f[Size];   int sum[Size];   int cost[Size];   std::vector<int> d[Size];   int n, k;   int main(void) {     std::scanf( %d%d , &n, &k);     for (int i = 1, x, y; i <= k; ++i) {       std::scanf( %d%d , &x, &y);       d[y].push_back(n - x + 1);     }     int sqrtK = SqrtS;     std::memset(f, -0x3f, sizeof f);     for (int i = 1, lim; i <= n; ++i) {       std::memset(sum, 0, sizeof sum);       lim = std::min(n + 1 - i, sqrtK);       for (int j = d[i].size() - 1; j >= 0; --j)         if (d[i][j] <= lim) sum[d[i][j]] = 1;       for (int j = 1; j <= lim + 1; ++j) sum[j] += sum[j - 1];       cost[0] = std::max(0, f[0]);       for (int j = 1; j <= lim; ++j) cost[j] = std::max(cost[j - 1], f[j]);       f[0] = std::max(cost[0], std::max(f[1], cost[0] - 3) + 3 * sum[1]);       for (int j = 1; j <= lim; ++j)         f[j] = std::max(f[j + 1], cost[j] - (j + 2) * (j + 1) / 2 - 2) +                3 * sum[j + 1];     }     std::printf( %d n , k * 3 - f[0]);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long small = 1298173;   int n, m, a = 1, b = 2;   void step() {     if (a == 1 and b == n - 1) {       a++;       b = a + 1;     } else if (b < n) {       b++;     } else {       a++;       b = a + 1;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cin >> n >> m;     if (m == 1) {       cout <<  2 2 n ;       cout <<  1   << n <<   2 n ;       return 0;     }     cout << 2 <<     << small <<   n ;     cout << 1 <<     << n <<   2  <<   n ;     small -= 2;     int counter = n - 2;     while (counter > 1) {       cout << a <<     << b <<     << 10 <<   n ;       small -= 10;       step();       counter--;     }     cout << a <<     << b <<     << small <<   n ;     step();     m -= (n - 1);     while (m > 0) {       cout << a <<     << b <<     << 1298183 <<   n ;       step();       m--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100000 + 10];   int b[100000 + 10];   int main() {     int n, x, m, y;     scanf( %d%d%d%d , &n, &m, &x, &y);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= m; i++) {       scanf( %d , &b[i]);     }     printf( %s , a[x] < b[m - y + 1] ?  YES  :  NO );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     unordered_map<int, int> nums;     int n;     cin >> n;     while (n--) {       int dummy;       cin >> dummy;       nums[dummy]++;     }     int res = 0;     for (auto p : nums) res = max(res, p.second);     cout << res << endl;   }