#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   template <typename T>   struct modular {     constexpr modular() : val(0) {}     constexpr modular(const modular<T>& _m) : val(_m.val) {}     template <typename U>     constexpr modular(const U& _r = U()) {       val = -MOD <= _r && _r < MOD ? _r : _r % MOD;       if (val < 0) {         val += MOD;       }     }     const T operator()() { return val; }     template <typename U>     explicit operator U() const {       return static_cast<U>(val);     }     modular<T>& operator+=(const modular<T>& _m) {       if ((val += _m.val) >= MOD) {         val -= MOD;       }       return *this;     }     modular<T>& operator-=(const modular<T>& _m) {       if ((val -= _m.val) < 0) {         val += MOD;       }       return *this;     }     modular<T>& operator*=(const modular<T>& _m) {       val = modular<T>(static_cast<int64_t>(val) * static_cast<int64_t>(_m.val))                 .val;       return *this;     }     modular<T>& operator/=(const modular<T>& _m) {       T a = _m.val, b = MOD, u = 0, v = 1;       while (a != 0) {         T q = b / a;         b -= q * a;         swap(a, b);         u -= q * v;         swap(u, v);       }       return *this *= u;     }     modular<T>& operator=(const modular<T>& _m) {       val = _m.val;       return *this;     }     template <typename U>     modular<T>& operator+=(const U& _r) {       return *this += modular<T>(_r);     }     template <typename U>     modular<T>& operator-=(const U& _r) {       return *this -= modular<T>(_r);     }     template <typename U>     modular<T>& operator*=(const U& _r) {       return *this *= modular<T>(_r);     }     template <typename U>     modular<T>& operator/=(const U& _r) {       return *this /= modular<T>(_r);     }     template <typename U>     modular<T>& operator=(const U& _r) {       val = modular<T>(_r).val;       return *this;     }     modular<T> operator-() { return modular<T>(-val); }     template <typename U>     friend bool operator==(const modular<U>&, const modular<U>&);     friend std::istream& operator>>(std::istream& os, modular<T>& _m) {       os >> _m.val;       _m *= 1;       return os;     }     friend std::ostream& operator<<(std::ostream& os, const modular<T>& _m) {       return os << _m.val;     }     template <typename U>     modular<T> exp(U e) {       modular<T> res = 1;       modular<T> b = val;       if (e < 0) {         b = 1 / b;         e *= -1;       }       for (; e; e >>= 1) {         if (e & 1) {           res *= b;         }         b *= b;       }       return res;     }       private:     T val;   };   template <typename T>   inline modular<T> operator+(const modular<T>& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) += _rhs;   }   template <typename T, typename U>   inline modular<T> operator+(const modular<T>& _lhs, const U& _rhs) {     return modular<T>(_lhs) += _rhs;   }   template <typename T, typename U>   inline modular<T> operator+(const U& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) += _rhs;   }   template <typename T>   inline modular<T> operator-(const modular<T>& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) -= _rhs;   }   template <typename T, typename U>   inline modular<T> operator-(const modular<T>& _lhs, const U& _rhs) {     return modular<T>(_lhs) -= _rhs;   }   template <typename T, typename U>   inline modular<T> operator-(const U& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) -= _rhs;   }   template <typename T>   inline modular<T> operator*(const modular<T>& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) *= _rhs;   }   template <typename T, typename U>   inline modular<T> operator*(const modular<T>& _lhs, const U& _rhs) {     return modular<T>(_lhs) *= _rhs;   }   template <typename T, typename U>   inline modular<T> operator*(const U& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) *= _rhs;   }   template <typename T>   inline modular<T> operator/(const modular<T>& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) /= _rhs;   }   template <typename T, typename U>   inline modular<T> operator/(const modular<T>& _lhs, const U& _rhs) {     return modular<T>(_lhs) /= _rhs;   }   template <typename T, typename U>   inline modular<T> operator/(const U& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) /= _rhs;   }   template <typename T>   inline bool operator==(const modular<T>& _lhs, const modular<T>& _rhs) {     return _lhs.val == _rhs.val;   }   template <typename T, typename U>   inline bool operator==(const modular<T>& _lhs, const U& _rhs) {     return _lhs == modular<T>(_rhs);   }   template <typename T, typename U>   inline bool operator==(const U& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) == _rhs;   }   template <typename T>   inline bool operator!=(const modular<T>& _lhs, const modular<T>& _rhs) {     return !(_lhs == _rhs);   }   template <typename T, typename U>   inline bool operator!=(const modular<T>& _lhs, const U& _rhs) {     return !(_lhs == _rhs);   }   template <typename T, typename U>   inline bool operator!=(const U& _lhs, const modular<T>& _rhs) {     return !(_lhs == _rhs);   }   void __solve() {     int n;     cin >> n;     vector<int> pa(n);     pa[0] = -1;     vector<vector<int>> g(n);     for (int i = 1; i < n; i++) {       int x;       cin >> x;       x--;       pa[i] = x;       g[x].push_back(i);     }     vector<array<modular<int>, 2>> dn(n);     for (int u = n - 1; u >= 0; u--) {       modular<int> x = 1, z = 1;       for (int v : g[u]) {         x *= dn[v][0] + dn[v][1];         z *= dn[v][0];       }       dn[u][0] = z;       dn[u][1] = x;     }     vector<array<modular<int>, 2>> up(n);     up[0][0] = up[0][1] = 1;     for (int u = 0; u < n; u++) {       int m = g[u].size();       {         vector<modular<int>> pref(m + 1), suff(m + 1);         pref[0] = suff[m] = 1;         for (int i = 0; i < m; i++) {           pref[i + 1] = pref[i] * dn[g[u][i]][0];         }         for (int i = m - 1; i >= 0; i--) {           suff[i] = suff[i + 1] * dn[g[u][i]][0];         }         for (int i = 0; i < m; i++) {           int v = g[u][i];           up[v][0] = up[u][0] * pref[i] * suff[i + 1];         }       }       {         vector<modular<int>> pref(m + 1), suff(m + 1);         pref[0] = suff[m] = 1;         for (int i = 0; i < m; i++) {           pref[i + 1] = pref[i] * (dn[g[u][i]][0] + dn[g[u][i]][1]);         }         for (int i = m - 1; i >= 0; i--) {           suff[i] = suff[i + 1] * (dn[g[u][i]][0] + dn[g[u][i]][1]);         }         for (int i = 0; i < m; i++) {           int v = g[u][i];           up[v][1] = up[v][0] + up[u][1] * pref[i] * suff[i + 1];         }       }     }     for (int i = 0; i < n; i++) {       modular<int> res = dn[i][1] * up[i][1];       cout << res <<    ;     }   }   void solve() {     int n;     cin >> n;     vector<int> pa(n);     pa[0] = -1;     vector<vector<int>> g(n);     for (int i = 1; i < n; i++) {       int x;       cin >> x;       x--;       pa[i] = x;       g[x].push_back(i);     }     vector<modular<int>> dn(n);     for (int u = n - 1; u >= 0; u--) {       dn[u] = 1;       for (int v : g[u]) {         dn[u] *= dn[v] + 1;       }     }     vector<modular<int>> up(n);     up[0] = 1;     for (int u = 0; u < n; u++) {       int m = g[u].size();       vector<modular<int>> pref(m + 1), suff(m + 1);       pref[0] = suff[m] = 1;       for (int i = 0; i < m; i++) {         int v = g[u][i];         pref[i + 1] = pref[i] * (dn[v] + 1);       }       for (int i = m - 1; i >= 0; i--) {         int v = g[u][i];         suff[i] = suff[i + 1] * (dn[v] + 1);       }       for (int i = 0; i < m; i++) {         int v = g[u][i];         up[v] = 1 + up[u] * pref[i] * suff[i + 1];       }     }     for (int i = 0; i < n; i++) {       cout << dn[i] * up[i] <<    ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   vector<string> a;   vector<int> big;   vector<int> mark;   string s;   string t;   int main() {     cin >> N;     string s1;     for (int i = 0; i < N; i++) {       cin >> s1;       a.push_back(s1);     }     cin >> s;     cin >> t;     for (int i = 0; i < s.size(); i++) {       string s1 = s.substr(i, 1);       if (s1[0] <=  Z ) {         big.push_back(1);       } else {         big.push_back(0);       }     }     for (int i = 0; i < s.length(); i++) mark.push_back(0);     transform(s.begin(), s.end(), s.begin(), ::tolower);     for (int i = 0; i < N; i++)       transform(a[i].begin(), a[i].end(), a[i].begin(), ::tolower);     for (int i = 0; i < N; i++) {       int start = 0;       while (s.substr(start).find(a[i]) != -1) {         start += s.substr(start).find(a[i]) + 1;         for (int j = start - 1; j <= start + a[i].length() - 2; j++) mark[j] = 1;       }     }     string answ;     for (int i = 0; i < s.length(); i++) {       if (mark[i] == 0)         answ.append(s.substr(i, 1));       else {         if (s.substr(i, 1) == t) {           if (t ==  a )             answ.append( b );           else             answ.append( a );         } else {           answ.append(t);         }       }     }     for (int i = 0; i < answ.length(); i++) {       if (big[i]) {         string s1 = answ.substr(i, 1);         transform(s1.begin(), s1.end(), s1.begin(), ::toupper);         string s2 = answ.substr(0, i);         s2.append(s1);         if (i + 1 < answ.length()) s2.append(answ.substr(i + 1));         answ = s2;       }     }     cout << answ << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct w {     int c, mi;   } tr[1010 * 1010 * 8];   struct ww {     int h, b, l, r, x, y;   } c[1010 * 1010];   int i, j, k, n, m, s, vx, vy, t, ans;   int a[1010][1010], b[1010][1010];   double d[1010 * 1010];   long long an;   inline bool cc1(const ww &a, const ww &b) { return a.b > b.b; }   inline void update(int x) { tr[x].mi = min(tr[x * 2].mi, tr[x * 2 + 1].mi); }   inline void Cover(int x, int y) {     tr[x].c = max(tr[x].c, y);     tr[x].mi = max(tr[x].mi, y);   }   inline void renew(int x) {     if (tr[x].c) Cover(x * 2, tr[x].c), Cover(x * 2 + 1, tr[x].c);     tr[x].c = 0;   }   void cover(int q, int x, int y, int l, int r, int h) {     if (l <= x && y <= r) {       Cover(q, h);       return;     }     renew(q);     int mid = (x + y) / 2;     if (l <= mid) cover(q * 2, x, mid, l, r, h);     if (mid < r) cover(q * 2 + 1, mid + 1, y, l, r, h);     update(q);   }   void cal(int q, int x, int y, int l, int r) {     if (l <= x && y <= r) {       ans = min(ans, tr[q].mi);       return;     }     renew(q);     int mid = (x + y) / 2;     if (l <= mid) cal(q * 2, x, mid, l, r);     if (mid < r) cal(q * 2 + 1, mid + 1, y, l, r);   }   int main() {     scanf( %d%d%d , &n, &vx, &vy);     for (i = 1; i <= n; i++)       for (j = 1; j <= n; j++) scanf( %d , &a[i][j]);     vx = -vx, vy = -vy;     if (vx < 0) {       vx = -vx;       for (j = 1; j <= n; j++)         for (i = 1; i <= n / 2; i++) swap(a[i][j], a[n - i + 1][j]);     }     if (vy < 0) {       vy = -vy;       for (i = 1; i <= n; i++)         for (j = 1; j <= n / 2; j++) swap(a[i][j], a[i][n - j + 1]);     }     if (!vx) {       swap(vx, vy);       for (i = 1; i <= n; i++)         for (j = 1; j <= n; j++) b[i][j] = a[i][j];       for (i = 1; i <= n; i++)         for (j = 1; j <= n; j++) a[j][n - i + 1] = b[i][j];     }     sort(d + 1, d + t + 1);     for (i = 1; i <= t; i++)       if (!m || d[m] < d[i]) d[++m] = d[i];     double ay = 1. * vy / vx;     for (i = 0; i <= n; i++)       for (j = 0; j <= n; j++) d[++m] = j - i * ay;     sort(d + 1, d + m + 1);     for (i = 1; i <= m; i++)       if (!t || d[t] + (1e-9) < d[i]) d[++t] = d[i];     for (i = 1; i <= n; i++)       for (j = 0; j <= n - 1; j++) {         int l = lower_bound(d + 1, d + t + 1, j - i * ay - (1e-9)) - d;         int r = lower_bound(d + 1, d + t + 1, j + 1 - (i - 1) * ay - (1e-9)) - d;         c[++s] = (ww){a[i][j + 1], i + j, l * 2, r * 2};       }     m = t * 2;     sort(c + 1, c + s + 1, cc1);     for (i = 1; i <= s; i++) {       ans = 2000000000;       cal(1, 1, m, c[i].l, c[i].r);       if (ans < c[i].h) an += c[i].h - ans;       cover(1, 1, m, c[i].l, c[i].r, c[i].h);     }     printf( %I64d n , an);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long arr[1000007];   long long cs[1000007];   long long ps[1000007];   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       for (int i = 1; i <= n; i++) cin >> arr[i];       for (int i = 1; i <= n; i++) {         if (i % 2) {           if (arr[i] > 0)             cout << -1 * arr[i] <<    ;           else             cout << arr[i] <<    ;         } else {           if (arr[i] < 0)             cout << -1 * arr[i] <<    ;           else             cout << arr[i] <<    ;         }       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   double const PI = 4 * atan(1.0);   using namespace std;   int main() {     long long a, b, x1, y1, x2, y2;     scanf( %I64d %I64d %I64d %I64d %I64d %I64d , &a, &b, &x1, &y1, &x2, &y2);     a = 2 * a;     b = 2 * b;     long long t1 = (x1 + y1);     long long t2 = (x2 + y2);     long long g1 = (x1 - y1);     long long g2 = (x2 - y2);     if (t1 < 0)       t1 = t1 / a - 1;     else       t1 = t1 / a;     if (t2 < 0)       t2 = t2 / a - 1;     else       t2 = t2 / a;     if (g1 < 0)       g1 = g1 / b - 1;     else       g1 = g1 / b;     if (g2 < 0)       g2 = g2 / b - 1;     else       g2 = g2 / b;     printf( %I64d , max(abs(t1 - t2), abs(g1 - g2)));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long int n, c;     cin >> n >> c;     long int ar[n], i, sum = 0;     for (i = 0; i < n; ++i) {       cin >> ar[i];       if (i != 0) {         if ((ar[i] - ar[i - 1]) > c)           sum = 0;         else           sum++;       }     }     cout << sum + 1;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5;   const long long mol = 1e9 + 7;   int fa[maxn + 11], siz[maxn + 11], x[maxn + 11], y[maxn + 11];   bool cir[maxn + 11];   vector<int> row, cul;   int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); }   void merge(int x, int y) {     int fax = get(x);     int fay = get(y);     if (fax == fay) {       cir[fax] = true;       return;     }     fa[fay] = fax;     cir[fax] |= cir[fay];     siz[fax] += siz[fay];   }   long long qpow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % mol;       a = a * a % mol;       b >>= 1;     }     return ans;   }   long long sub(long long a, long long b) {     a -= b;     if (a < 0) a += mol;     return a;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d %d , &x[i], &y[i]);       row.emplace_back(x[i]);       cul.emplace_back(y[i]);     }     sort((row).begin(), (row).end());     row.erase(unique((row).begin(), (row).end()), row.end());     sort((cul).begin(), (cul).end());     cul.erase(unique((cul).begin(), (cul).end()), cul.end());     int m = row.size() + cul.size();     for (int i = 1; i <= m; i++) fa[i] = i, siz[i] = 1, cir[i] = false;     for (int i = 1; i <= n; i++) {       x[i] = lower_bound((row).begin(), (row).end(), x[i]) - row.begin() + 1;       y[i] = lower_bound((cul).begin(), (cul).end(), y[i]) - cul.begin() +              row.size() + 1;       merge(x[i], y[i]);     }     long long ans = 1;     for (int i = 1; i <= m; i++)       if (get(i) == i) {         int p = siz[i];         long long t = qpow(2, p);         if (!cir[i]) t = sub(t, 1);         ans = ans * t % mol;       }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T gcd(T a, T b) {     T r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <class T>   int getbit(T s, int i) {     return (s >> i) & 1;   }   template <class T>   T onbit(T s, int i) {     return s | (T(1) << i);   }   template <class T>   T offbit(T s, int i) {     return s & (~(T(1) << i));   }   const double PI = 2 * acos(0.0);   const double eps = 1e-9;   const int infi = (1 << 31) - 1;   const long long Linfi = (long long)1e18;   const int MOD = 1000000007;   int n, cnt = 0;   int a[110005], p[110005], u[110005], vitri[110005];   vector<pair<int, int> > ans;   void sang(int n) {     memset(p, 0, sizeof(p));     for (int i = 2; i <= sqrt(n); i++) {       if (p[i] == 0) {         for (int j = i * i; j <= n; j += i) p[j] = 1;       }     }     for (int i = 2; i <= n; i++)       if (p[i] == 0) u[++cnt] = i - 1;   }   void solve() {     for (int i = 1; i <= n; i++) {       int pos = vitri[i];       if (pos == i) continue;       int delta = pos - i;       int tmp = lower_bound(u + 1, u + cnt + 1, delta) - u;       if (u[tmp] > delta) tmp--;       int x = u[tmp];       int k = pos - x;       swap(a[k], a[pos]);       ans.push_back(make_pair(k, pos));       swap(vitri[a[k]], vitri[a[pos]]);       while (k > i) {         while (u[tmp] > k - i) tmp--;         x = u[tmp];         if (x == 0) break;         swap(a[k], a[k - x]);         ans.push_back(make_pair(k - x, k));         swap(vitri[a[k]], vitri[a[k - x]]);         k -= x;         if (k == i) break;         if (ans.size() >= 500000) return;       }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       printf( %d %d n , ans[i].first, ans[i].second);     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       vitri[a[i]] = i;     }     sang(110001);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[3005];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     int ans = 0;     for (int i = 1; i < n; i++) {       for (int j = 0; j < i; j++) {         if (a[i] < a[j]) {           ans++;         }       }     }     if (ans & 1)       ans = (ans << 1) - 1;     else       ans <<= 1;     printf( %.6f n , (double)ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = int(1e5) + 5;   const int INF = int(1e9) + 7;   const long long MINF = 1e18;   vector<int> g[N];   set<int> x;   int a[N];   int b[N];   vector<int> ans;   void solve() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int l, r;       cin >> l >> r;       g[l].push_back(r);       g[r].push_back(l);     }     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] == 0) {         x.insert(i);       }     }     int kol = 0;     while (x.size() != 0) {       int num = *x.begin();       x.erase(num);       ans.push_back(num);       kol++;       b[num]++;       int v = num;       for (int i = 0; i < g[v].size(); i++) {         if (b[g[v][i]] == a[g[v][i]]) {           b[g[v][i]]++;           x.erase(g[v][i]);         } else {           b[g[v][i]]++;           if (b[g[v][i]] == a[g[v][i]]) {             x.insert(g[v][i]);           }         }       }       if (kol == n && x.size() != 0) {         cout << -1;         return;       }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(0);     int TT = 1;     while (TT--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   int main() {     cin >> n >> k;     long long falta = (n % k);     long long ans = n + (k - falta);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1 << 24;   int n, f[MAXN], Tohka;   bool p[MAXN];   int lowbit(int first) { return first & -first; }   int main() {     cin >> n;     char str[4];     for (int i = 1; i <= n; ++i) {       scanf( %s , str);       int s = 0;       for (int j = 0; j < 3; ++j) s |= 1 << (str[j] -  a );       ++f[s];     }     for (int i = 0; i < 24; ++i)       for (int j = 1; j < MAXN; ++j)         if (!(j & (1 << i))) f[j] += f[j + (1 << i)];     p[0] = 0;     for (int i = 1; i < MAXN; ++i)       p[i] = p[i - lowbit(i)] ^ 1, f[i] *= (p[i]) ? 1 : -1;     for (int i = 0; i < 24; ++i)       for (int j = MAXN - 1; j >= 0; --j)         if (j & (1 << i)) f[j] += f[j - (1 << i)];     for (int i = 0; i < MAXN; ++i) Tohka ^= f[i] * f[i];     cout << Tohka << endl;     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     for (int x = 0; x < T; x++) {       vector<long long> arry(7);       for (int i = 0; i < 7; i++) cin >> arry[i];       long long least, all_sum;       all_sum = arry[6];       least = arry[0];       vector<long long> a(3);       a[0] = least;       long long ab = all_sum - least;       a[1] = arry[1];       a[2] = all_sum - a[1] - a[0];       cout << a[0] <<     << a[1] <<     << a[2] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 15;   struct Node {     int x0, y0, x1, y1;     int num;     int nex;     int x, y;     int tim;     Node() { x0 = y0 = x1 = y1 = num = nex = tim = x = y = 0; }     Node(int x0, int y0, int x1, int y1, int num)         : x0(x0), y0(y0), x1(x1), y1(y1), num(num) {}     int clear() {       nex = x = y = tim = 0;       return 0;     }   } sz[maxn];   struct Que {     int x0, y0;     long long tt;     int dx, dy;     int nex, x, y, tim;     Que() { x0 = y0 = tt = dx = dy = nex = x = y = tim = 0; }     Que(int x0, int y0, int dx, int dy, long long tt)         : x0(x0), y0(y0), dx(dx), dy(dy), tt(tt) {}     int clear() {       nex = x = y = tim = 0;       return 0;     }   } que[maxn];   struct Bj {     int key1, key2;     int num;     int sy;   } bj[2 * maxn], bj2[2 * maxn];   int sum, ss;   int n, bod, m;   struct TT {     int wz;     int x, y;     long long tim;   } lca[52][maxn];   int abs(int x) {     if (x < 0) return -x;     return x;   }   bool cmp(Bj a, Bj b) {     if (a.key1 == b.key1) return a.key2 < b.key2;     return a.key1 < b.key1;   }   bool sam(int x, int y) {     if (x == 0 && y == 0) return true;     if (x == 0 || y == 0) return false;     return 1ll * x * y > 0;   }   int tree[maxn * 4];   int down(int root) {     if (tree[root] == 0) return 0;     int x = tree[root];     tree[root << 1] = tree[root << 1 | 1] = x;     tree[root] = 0;     return 0;   }   int ins(int root, int l, int r, int x, int y, int z) {     if (l > y || r < x) return 0;     if (x <= l && r <= y) {       tree[root] = z;       return 0;     }     down(root);     int mid = (l + r) >> 1;     ins(root << 1, l, mid, x, y, z);     ins(root << 1 | 1, mid + 1, r, x, y, z);     return 0;   }   int found(int root, int l, int r, int x) {     if (l > x || r < x) return 0;     if (l == r) return tree[root];     down(root);     int mid = (l + r) >> 1;     if (mid >= x) return found(root << 1, l, mid, x);     return found(root << 1 | 1, mid + 1, r, x);   }   int done(int ddx, int ddy) {     sum = 0;     memset(tree, 0, sizeof(tree));     for (int i = 1; i <= n; i++)       if (!sam(ddx, sz[i].x1 - sz[i].x0) && !sam(ddy, sz[i].y1 - sz[i].y0)) {         sum++;         bj[sum].sy = 0;         bj[sum].num = i;         bj[sum].key1 = -ddx * sz[i].x0;         bj[sum].key2 = -ddy * sz[i].y0;       }     sort(bj + 1, bj + sum + 1, cmp);     ss = 0;     for (int i = 1; i <= n; i++)       if (sam(ddx, sz[i].x1 - sz[i].x0) && sam(ddy, sz[i].y1 - sz[i].y0)) {         ss++;         bj2[ss].sy = 0;         bj2[ss].num = i;         bj2[ss].key1 = -ddx * sz[i].x0;         bj2[ss].key2 = -ddy * sz[i].y0;       }     for (int i = 1; i <= m; i++)       if (sam(ddx, que[i].dx) && sam(ddy, que[i].dy)) {         ss++;         bj2[ss].sy = 1;         bj2[ss].num = i;         bj2[ss].key1 = -ddx * que[i].x0;         bj2[ss].key2 = -ddy * que[i].y0;       }     sort(bj2 + 1, bj2 + ss + 1, cmp);     int kk = 1;     for (int i = 1; i <= ss; i++) {       while (kk <= sum &&              (bj[kk].key1 <= bj2[i].key1 && bj[kk].key2 <= bj2[i].key2)) {         int ge = bj[kk].num;         if (ddx == 0)           ins(1, 0, bod, min(sz[ge].x1, sz[ge].x0), max(sz[ge].x1, sz[ge].x0),               ge);         else           ins(1, 0, bod, min(sz[ge].y1, sz[ge].y0), max(sz[ge].y1, sz[ge].y0),               ge);         kk++;       }       int ge = bj2[i].num, gs = bj2[i].sy;       if (gs == 0) {         if (ddx == 0) {           sz[ge].nex = found(1, 0, bod, sz[ge].x0);           if (sz[ge].nex == 0) continue;           sz[ge].x = sz[ge].x0;           sz[ge].y = sz[sz[ge].nex].y0;           sz[ge].tim = abs(sz[ge].y - sz[ge].y1);         } else {           sz[ge].nex = found(1, 0, bod, sz[ge].y0);           if (sz[ge].nex == 0) continue;           sz[ge].x = sz[sz[ge].nex].x0;           sz[ge].y = sz[ge].y0;           sz[ge].tim = abs(sz[ge].x - sz[ge].x1);         }       } else {         if (ddx == 0) {           que[ge].nex = found(1, 0, bod, que[ge].x0);           if (que[ge].nex == 0) continue;           que[ge].x = que[ge].x0;           que[ge].y = sz[que[ge].nex].y0;           que[ge].tim = abs(que[ge].y - que[ge].y0);         } else {           que[ge].nex = found(1, 0, bod, que[ge].y0);           if (que[ge].nex == 0) continue;           que[ge].x = sz[que[ge].nex].x0;           que[ge].y = que[ge].y0;           que[ge].tim = abs(que[ge].x - que[ge].x0);         }       }     }     return 0;   }   int pre[maxn * 2], nex[maxn * 2];   int done2() {     sum = 0;     for (int i = 1; i <= n; i++)       if (sz[i].x0 == sz[i].x1) {         sum++;         bj[sum].key1 = sz[i].x0;         bj[sum].key2 = sz[i].y0;         bj[sum].num = i;         bj[sum].sy = 0;       }     for (int i = 1; i <= m; i++)       if (que[i].dx == 0) {         sum++;         bj[sum].key1 = que[i].x0;         bj[sum].key2 = que[i].y0;         bj[sum].num = i;         bj[sum].sy = 1;       }     sort(bj + 1, bj + sum + 1, cmp);     for (int i = 1; i <= sum; i++)       if (i != 1 && bj[i].key1 == bj[i - 1].key1) {         if (bj[i - 1].sy == 0)           pre[i] = i - 1;         else           pre[i] = pre[i - 1];       } else         pre[i] = 0;     for (int i = sum; i >= 1; i--)       if (i != sum && bj[i].key1 == bj[i + 1].key1) {         if (bj[i + 1].sy == 0)           nex[i] = i + 1;         else           nex[i] = nex[i + 1];       } else         nex[i] = 0;     for (int i = 1; i <= sum; i++)       if (bj[i].sy == 0) {         int q = bj[i].num, pr = bj[pre[i]].num, ne = bj[nex[i]].num;         if (sz[q].y1 > sz[q].y0 && ne != 0 &&             (min(sz[ne].y0, sz[ne].y1) - sz[q].y1 < sz[q].tim ||              sz[q].nex == 0)) {           sz[q].tim = min(sz[ne].y0, sz[ne].y1) - sz[q].y1;           sz[q].nex = ne;           sz[q].y = min(sz[ne].y0, sz[ne].y1);           sz[q].x = sz[q].x0;         }         if (sz[q].y1 < sz[q].y0 && pr != 0 &&             (sz[q].y1 - max(sz[pr].y0, sz[pr].y1) < sz[q].tim ||              sz[q].nex == 0)) {           sz[q].tim = sz[q].y1 - max(sz[pr].y0, sz[pr].y1);           sz[q].nex = pr;           sz[q].y = max(sz[pr].y0, sz[pr].y1);           sz[q].x = sz[q].x0;         }       } else {         int q = bj[i].num, pr = bj[pre[i]].num, ne = bj[nex[i]].num;         if (ne != 0 && que[q].y0 >= min(sz[ne].y0, sz[ne].y1) &&             que[q].y0 <= max(sz[ne].y0, sz[ne].y1)) {           que[q].tim = 0;           que[q].nex = ne;           que[q].y = que[q].y0;           que[q].x = que[q].x0;         } else if (pr != 0 && que[q].y0 >= min(sz[pr].y0, sz[pr].y1) &&                    que[q].y0 <= max(sz[pr].y0, sz[pr].y1)) {           que[q].tim = 0;           que[q].nex = pr;           que[q].y = que[q].y0;           que[q].x = que[q].x0;         } else if (que[q].dy == 1 && ne != 0 &&                    (min(sz[ne].y0, sz[ne].y1) - que[q].y0 < que[q].tim ||                     que[q].nex == 0)) {           que[q].tim = min(sz[ne].y0, sz[ne].y1) - que[q].y0;           que[q].nex = ne;           que[q].y = min(sz[ne].y0, sz[ne].y1);           que[q].x = que[q].x0;         } else if (que[q].dy == -1 && pr != 0 &&                    (que[q].y0 - max(sz[pr].y0, sz[pr].y1) < que[q].tim ||                     que[q].nex == 0)) {           que[q].tim = que[q].y0 - max(sz[pr].y0, sz[pr].y1);           que[q].nex = pr;           que[q].y = max(sz[pr].y0, sz[pr].y1);           que[q].x = que[q].x0;         }       }     sum = 0;     for (int i = 1; i <= n; i++)       if (sz[i].y0 == sz[i].y1) {         sum++;         bj[sum].key1 = sz[i].y0;         bj[sum].key2 = sz[i].x0;         bj[sum].num = i;         bj[sum].sy = 0;       }     for (int i = 1; i <= m; i++)       if (que[i].dy == 0) {         sum++;         bj[sum].key1 = que[i].y0;         bj[sum].key2 = que[i].x0;         bj[sum].num = i;         bj[sum].sy = 1;       }     sort(bj + 1, bj + sum + 1, cmp);     for (int i = 1; i <= sum; i++)       if (i != 1 && bj[i].key1 == bj[i - 1].key1) {         if (bj[i - 1].sy == 0)           pre[i] = i - 1;         else           pre[i] = pre[i - 1];       } else         pre[i] = 0;     for (int i = sum; i >= 1; i--)       if (i != sum && bj[i].key1 == bj[i + 1].key1) {         if (bj[i + 1].sy == 0)           nex[i] = i + 1;         else           nex[i] = nex[i + 1];       } else         nex[i] = 0;     for (int i = 1; i <= sum; i++)       if (bj[i].sy == 0) {         int q = bj[i].num, pr = bj[pre[i]].num, ne = bj[nex[i]].num;         if (sz[q].x1 > sz[q].x0 && ne != 0 &&             (min(sz[ne].x0, sz[ne].x1) - sz[q].x1 < sz[q].tim ||              sz[q].nex == 0)) {           sz[q].tim = min(sz[ne].x0, sz[ne].x1) - sz[q].x1;           sz[q].nex = ne;           sz[q].x = min(sz[ne].x0, sz[ne].x1);           sz[q].y = sz[q].y0;         }         if (sz[q].x1 < sz[q].x0 && pr != 0 &&             (sz[q].x1 - max(sz[pr].x0, sz[pr].x1) < sz[q].tim ||              sz[q].nex == 0)) {           sz[q].tim = sz[q].x1 - max(sz[pr].x0, sz[pr].x1);           sz[q].nex = pr;           sz[q].x = max(sz[pr].x0, sz[pr].x1);           sz[q].y = sz[q].y0;         }       } else {         int q = bj[i].num, pr = bj[pre[i]].num, ne = bj[nex[i]].num;         if (ne != 0 && que[q].x0 >= min(sz[ne].x0, sz[ne].x1) &&             que[q].x0 <= max(sz[ne].x0, sz[ne].x1)) {           que[q].tim = 0;           que[q].nex = ne;           que[q].x = que[q].x0;           que[q].y = que[q].y0;         } else if (pr != 0 && que[q].x0 >= min(sz[pr].x0, sz[pr].x1) &&                    que[q].x0 <= max(sz[pr].x0, sz[pr].x1)) {           que[q].tim = 0;           que[q].nex = pr;           que[q].x = que[q].x0;           que[q].y = que[q].y0;         } else if (que[q].dx == 1 && ne != 0 &&                    (min(sz[ne].x0, sz[ne].x1) - que[q].x0 < que[q].tim ||                     que[q].nex == 0)) {           que[q].tim = min(sz[ne].x0, sz[ne].x1) - que[q].x0;           que[q].nex = ne;           que[q].x = min(sz[ne].x0, sz[ne].x1);           que[q].y = que[q].y0;         } else if (que[q].dx == -1 && pr != 0 &&                    (que[q].x0 - max(sz[pr].x0, sz[pr].x1) < que[q].tim ||                     que[q].nex == 0)) {           que[q].tim = que[q].x0 - max(sz[pr].x0, sz[pr].x1);           que[q].nex = pr;           que[q].x = max(sz[pr].x0, sz[pr].x1);           que[q].y = que[q].y0;         }       }     return 0;   }   const long long oo = 10000000000000000ll;   int ycl() {     for (int i = 1; i <= n; i++)       lca[0][i].wz = sz[i].nex, lca[0][i].x = sz[i].x, lca[0][i].y = sz[i].y,       lca[0][i].tim = sz[i].tim;     for (int i = 1; i <= 50; i++)       for (int j = 1; j <= n; j++)         if (lca[i - 1][j].wz != 0 && lca[i - 1][lca[i - 1][j].wz].wz != 0) {           lca[i][j].wz = lca[i - 1][lca[i - 1][j].wz].wz;           lca[i][j].x = lca[i - 1][lca[i - 1][j].wz].x;           lca[i][j].y = lca[i - 1][lca[i - 1][j].wz].y;           int g = lca[i - 1][j].wz;           int x1 = lca[i - 1][j].x, y1 = lca[i - 1][j].y, x2 = sz[g].x1,               y2 = sz[g].y1;           lca[i][j].tim =               lca[i - 1][j].tim + lca[i - 1][g].tim + abs(x1 - x2) + abs(y1 - y2);           if (lca[i][j].tim >= oo) lca[i][j].wz = 0;         }     return 0;   }   int main() {     scanf( %d%d , &n, &bod);     for (int i = 1; i <= n; i++) {       int x0, y0, x1, y1;       scanf( %d%d%d%d , &x0, &y0, &x1, &y1);       sz[i] = Node(x0, y0, x1, y1, i);       sz[i].clear();     }     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       int x, y;       long long t;       char ch[2];       scanf( %d%d%s%I64d , &x, &y, ch, &t);       int dx, dy;       if (ch[0] ==  L ) dx = -1, dy = 0;       if (ch[0] ==  R ) dx = 1, dy = 0;       if (ch[0] ==  U ) dx = 0, dy = 1;       if (ch[0] ==  D ) dx = 0, dy = -1;       que[i] = Que(x, y, dx, dy, t);       que[i].clear();     }     done(0, 1);     done(0, -1);     done(1, 0);     done(-1, 0);     done2();     ycl();     for (int i = 1; i <= m; i++) {       int x = que[i].x0, y = que[i].y0;       long long tt = que[i].tt;       if (que[i].nex == 0) {         int dx = que[i].dx, dy = que[i].dy;         tt = min(tt, (long long)bod);         if (dx == 0) {           if (dy > 0)             y = min(bod, y + (int)tt);           else             y = max(0, y - (int)tt);         } else if (dx > 0)           x = min(bod, x + (int)tt);         else           x = max(0, x - (int)tt);         printf( %d %d n , x, y);         continue;       }       int xx = que[i].x, yy = que[i].y;       if (tt < que[i].tim) {         if (x == xx)           printf( %d  , x);         else if (x < xx)           printf( %d  , x + (int)tt);         else           printf( %d  , x - (int)tt);         if (y == yy)           printf( %d n , y);         else if (y < yy)           printf( %d n , y + (int)tt);         else           printf( %d n , y - (int)tt);         continue;       } else {         tt -= que[i].tim;         x = xx;         y = yy;       }       int sy = que[i].nex;       for (int i = 50; i >= 0; i--)         if (lca[i][sy].wz != 0) {           long long degt =               lca[i][sy].tim + abs(x - sz[sy].x1) + abs(y - sz[sy].y1);           if (degt > tt) continue;           tt -= degt;           x = lca[i][sy].x;           y = lca[i][sy].y;           sy = lca[i][sy].wz;         }       tt = min(tt, (long long)bod);       if (sz[sy].x0 == sz[sy].x1) {         if (sz[sy].y0 > sz[sy].y1)           y = max(0, y - (int)tt);         else           y = min(bod, y + (int)tt);       } else if (sz[sy].x0 > sz[sy].x1)         x = max(0, x - (int)tt);       else         x = min(bod, x + (int)tt);       printf( %d %d n , x, y);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI =       3.14159265358979323846264338327950288419716939937510582097494459230;   struct debugger {     static void call(const char *arg) {}     template <typename T, typename... aT>     static void call(const char *it, T a, aT... rest) {       string b;       for (; *it && (*it) !=  , ; it++) {         b += *it;       }       cerr << b <<   =   << a <<    ;       call(++it, rest...);     }   };   int main() {     int n, b, m;     cin >> n >> b;     int ar[n];     m = b;     for (int i = 0; i < (n); i++) {       cin >> ar[i];     }     for (int i = 0; i < (n); i++) {       int c = b / ar[i], r = b % ar[i];       for (int j = (i + 1); j < (n); j++) {         int w = ar[j] * c;         w = w + r;         m = max(w, m);       }     }     cout << m;   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int x, long long int y) {     if (x < y) swap(x, y);     if (x % y == 0) return y;     return gcd(y, x % y);   }   long long int pwm(long long int a, long long int n) {     long long int ans = 1;     while (n > 0) {       if (n % 2 == 1) {         ans = (ans * a) % 1000000007;       }       a = (a * a) % 1000000007;       n /= 2;     }     return ans % 1000000007;   }   const int pwn = 100010;   long long int pw[pwn];   void pwtwo() {     pw[0] = 1;     for (int i = 1; i < pwn; i++) {       pw[i] = (pw[i - 1] * 2) % 1000000007;     }   }   long long int gcdExtended(long long int a, long long int b, long long int *x,                             long long int *y);   long long int modInverse(long long int a, long long int m) {     if (a == 1) return 1;     long long int x, y;     long long int g = gcdExtended(a, m, &x, &y);     if (g != 1) {       return -1;     } else {       long long int res = (x % m + m) % m;       return res;     }   }   long long int gcdExtended(long long int a, long long int b, long long int *x,                             long long int *y) {     if (a == 0) {       *x = 0, *y = 1;       return b;     }     long long int x1, y1;     long long int gcd = gcdExtended(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   long long int fact[1010];   long long int init() {     fact[0] = 1;     for (int i = 1; i < 1010; i++) fact[i] = (fact[i - 1] * i) % 1000000007;   }   long long int ncr(long long int n, long long int r) {     long long int ans = fact[n];     ans = (ans * modInverse(fact[r], 1000000007)) % 1000000007;     ans = (ans * modInverse(fact[n - r], 1000000007)) % 1000000007;     return ans;   }   long long int t[42];   bool check(int x) {     for (int i = 1; i <= 40; i++) {       if (x == t[i] - 1) return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int a, b;     cin >> a >> b;     if (a == 1 || b == 1) {       cout << 0 << endl;       return 0;     }     if (a == b) {       cout << 0 << endl;       return 0;     }     long long int x = abs(b - a);     long long int ans = a * b;     ans = ans / gcd(a, b);     long long int c = 0;     for (int i = 1; i <= sqrt(x); i++) {       if ((x % i) == 0) {         long long int y = a % i;         y = (i - y) % i;         long long int k = (a + y) * (b + y);         k = k / gcd(a + y, b + y);         if (ans > k) {           ans = k;           c = y;         }         int z = x / i;         y = a % z;         y = (z - y) % z;         k = (a + y) * (b + y);         k = k / gcd(a + y, b + y);         if (ans > k) {           ans = k;           c = y;         }       }     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e7 + 9, MAXN = 1e6;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     unsigned long long int k, x;     cin >> n;     while (n--) {       cin >> k >> x;       cout << x + 9 * (k - 1) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int tree[1000000 + 5], a[1000000 + 5], data[1000000 + 5], rear, sum;   int lowbit(int x) { return (x & -x); }   void modify(int x, int value) {     for (int i = x; i <= 1000000; i += lowbit(i)) tree[i] += value;     return;   }   int query(int x) {     int sum = 0;     for (int i = x; i; i -= lowbit(i)) sum += tree[i];     return sum;   }   void del(int rear, int x) {     int l = 1, r = rear, mid;     while (l < r) {       mid = (l + r) / 2;       if (query(mid) < x)         l = mid + 1;       else         r = mid;     }     modify(l, -1);     data[l] = -1;     return;   }   int main() {     int n, m, i, j, ch;     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) scanf( %d , &a[i]);     a[i] = 1000005;     for (i = 1; i <= n; i++) {       scanf( %d , &ch);       if (ch == -1) {         for (j = 1; a[j] <= sum; j++) del(rear, a[j] - j + 1);         sum -= (j - 1);       } else {         modify(++rear, 1);         data[rear] = ch;         sum++;       }     }     if (!sum)       printf( Poor stack! n );     else {       for (i = 1; i <= rear; i++)         if (data[i] != -1) printf( %d , data[i]);       printf(  n );     }     return 0;   }


#include <iostream>   #include <bits/stdc++.h>   using namespace std;      #define int long long       void solve(){      // int n;       //cin>>n;              /*int a[n];       for(int i=0;i<n;i++)       cin>>a[i]; */       string s;       cin>>s;       int n=s.length();              cout << n << endl;         }      int32_t main() {          ios_base::sync_with_stdio(false);       cin.tie(NULL);              int t;       cin>>t;       while(t){           t--;        solve();               }                 }


#include <bits/stdc++.h>   using namespace std;   string st;   int main() {     cin >> st;     char q[11] = { A ,  I ,  O ,  M ,  H ,  U ,  V ,  W ,  X ,  Y ,  T };     set<char> s(q, q + 11);     for (long long i = 0; i < st.size() / 2 + 1; i++) {       if (st[i] != st[st.size() - i - 1] || s.count(st[i]) == 0) {         cout <<  NO ;         return 0;       }     }     if (st.size() == 1) {       if (s.count(st[0]) == 0) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n, sum = 0;       cin >> n;       for (int i = 0; i < 60; i++) {         long long x = 1LL << i;         if (n & x) {           sum += (1LL << (i + 1)) - 1;         }       }       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, q, a, b, x, y, i = 1, j, p[150000], mas[150005];   pair<int, int> m[10];   int main() {     cin >> n >> k >> q;     while (i <= n) {       cin >> p[i];       i++;     }     i = 0;     while (i < q) {       cin >> a >> b;       if (a == 1) {         if (p[b] > m[k - 1].first) {           mas[m[k - 1].second] = 0;           mas[b] = 1;           m[k - 1].first = p[b];           m[k - 1].second = b;           sort(m, m + k);           reverse(m, m + k);         }       }       if (a == 2) {         if (mas[b] == 0) {           cout <<  NO  << endl;         } else {           cout <<  YES  << endl;         }       }       i++;     }   }


#include <bits/stdc++.h>   using namespace std;   void chmax(int& a, int b) { a = max(a, b); }   void chmin(int& a, int b) { a = min(a, b); }   int nth_bit(int64_t num, int n) { return (num >> n) & 1; }   int main() {     string S;     int X;     cin >> S >> X;     int N = S.size();     vector<int> A(N);     for (int i = 0; i < N; i++) A[i] = S[i] -  0 ;     vector<int> ds;     for (int i = 1; i < X; i++)       if (X % i == 0) ds.push_back(i);     if (X == 1) {       cout << count(A.begin(), A.end(), 1) << endl;       return 0;     }     int B = 1 << (X + 1);     vector<int> valid;     for (int b = 0; b < B; b++) {       bool ok = true;       for (int i = 0; i < X; i++)         if (nth_bit(b, i) && nth_bit(b, i + 1)) ok = false;       if (ok) valid.push_back(b);     }     vector<bool> ok(B);     for (int b = 0; b < B; b++) {       if (nth_bit(b, X) == 0) ok[b] = true;       for (int d : ds)         for (int i = 0; i < X; i++)           if (nth_bit(b, i) && nth_bit(b, i + d)) ok[b] = true;     }     vector<int> dp(B), dp2(B);     auto solve = [&](vector<int>& V) -> int {       int N = V.size();       for (int b : valid) dp[b] = 1e9;       dp[1] = 0;       for (int i = 0; i < N; i++) {         for (int b : valid) dp2[b] = dp[b] + 1;         for (int b : valid) {           int b2 = ((b << V[i]) | 1) & (B - 1);           if (ok[b2]) chmin(dp2[b2], dp[b]);         }         for (int b : valid) dp[b] = dp2[b];       }       int ans = 1e9;       for (int b : valid) chmin(ans, dp[b]);       return ans;     };     int ans = 0;     vector<int> V;     for (int i = 0; i < N; i++) {       if (A[i] == 1) {         if (V.size()) ans += solve(V);         V.clear();       } else {         V.push_back(A[i]);       }     }     if (V.size()) ans += solve(V);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, arr[100005], has[100005], t;   vector<int> v[100005];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       int a;       cin >> a;       arr[a]++;       has[i] = arr[a];       v[has[i]].push_back(a);       t = max(t, has[i]);     }     for (int i = 0; i < 100000; i++) {       int p = v[i].size();       if (p != 0) {         int tmp = 0;         for (int j = 0; j < p; j++) {           tmp += v[i][j];         }         if (tmp != ((p * (p + 1)) / 2)) {           cout <<  -1  << endl;           return 0;         }       }     }     cout << t << endl;     for (int i = 1; i <= n; i++) cout << has[i] <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void _R(T &x) {     cin >> x;   }   void _R(int &x) { scanf( %d , &x); }   void _R(long long &x) { scanf( %  PRId64, &x); }   void _R(double &x) { scanf( %lf , &x); }   void _R(char &x) { scanf(  %c , &x); }   void _R(char *x) { scanf( %s , x); }   void R() {}   template <typename T, typename... U>   void R(T &head, U &...tail) {     _R(head);     R(tail...);   }   template <typename T>   void _W(const T &x) {     cout << x;   }   void _W(const int &x) { printf( %d , x); }   template <typename T>   void _W(const vector<T> &x) {     for (auto i = x.cbegin(); i != x.cend(); i++) {       if (i != x.cbegin()) putchar(   );       _W(*i);     }   }   void W() {}   template <typename T, typename... U>   void W(const T &head, const U &...tail) {     _W(head);     putchar(sizeof...(tail) ?     :   n );     W(tail...);   }   int ans;   inline void chkmax(int &a, int b) {     if (b > ans) ans = b;     if (b > a) a = b;   }   const int N = 1010;   const int K = 11;   int n, m, k, dp[K][N][N][2];   char a[N], b[N];   int main() {     memset(dp, -1, sizeof(dp));     dp[0][0][0][0] = 0;     R(n, m, k, a, b);     for (int i = (0); i <= int(k); i++)       for (int x = 0; x < int(n); x++)         for (int y = 0; y < int(m); y++)           for (int j = 0; j < int(2); j++) {             int me = dp[i][x][y][j];             if (me == -1) continue;             chkmax(dp[i][x + 1][y][0], me);             chkmax(dp[i][x][y + 1][0], me);             if (a[x] == b[y]) {               int ni = i + (j == 0);               if (ni <= k) chkmax(dp[i + (j == 0)][x + 1][y + 1][1], me + 1);             }           }     W(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;      //.define   // #define FILE_IN_OUT   #define RET(_x) cout << (_x) <<   n ; return;   #define all(_obj) (_obj).begin(), (_obj).end()   #define loop(_n) for (int i = 0; i < (_n); ++i)   #define sz(_obj) static_cast<int>((_obj).size())   #ifdef SHJ_LOCAL   #define debug(_x) std::cerr << (#_x) <<   =   << (_x) <<   n  << std::flush;   #else   #define debug(_x) {}   #endif   #define endl   n    template <typename P, typename Q>   P CeilDiv(P _dividend, Q _divider) {       return static_cast<P>((_dividend - 1LL + _divider) / _divider);   }   template <typename Tp>   inline void outarr(Tp _begin, Tp _end, const char* _delim =    ) {       for (Tp current = _begin; current != _end; ++current) {           std::cout << *current << _delim;       }       std::cout <<   n ;   }      //.constant   using ll = int64_t;   using pii = std::pair<int, int>;   constexpr int INF = 0x3f3f3f3f;   constexpr int MOD = static_cast<int>(1e9 + 7);      //.data   bool Ask(int l1, int r1, int l2, int r2) {       cout <<  ?   << r1 - l1 + 1 <<     << r2 - l2 + 1 << endl;       for (int i = l1; i <= r1; ++i) {           cout << i <<    ;       }       cout << endl;       for (int i = l2; i <= r2; ++i) {           cout << i <<    ;       }       cout << endl << flush;       int res;       cin >> res;       return res;   }      //.code   void SolveTask() {       int n;       cin >> n;       int j = -1;       for (int i = 2; i <= n; ++i) {           if (Ask(1, i - 1, i, i)) {               j = i;               break;           }       }       vector<int> ans;       for (int i = j + 1; i <= n; ++i) {           if (!Ask(j, j, i, i)) {               ans.push_back(i);           }       }       int l = 1;       int r = j - 1;       while (l <= r) {           int mid = (l + r) >> 1;           if (Ask(1, mid, j, j)) {               r = mid - 1;           } else {               l = mid + 1;           }       }       for (int i = 1; i <= r; ++i) {           ans.push_back(i);       }       for (int i = r + 2; i < j; ++i) {           ans.push_back(i);       }       cout <<  !   << sz(ans) <<    ;       outarr(all(ans));       cout << flush;   }      int main() {   #ifdef FILE_IN_OUT       std::ifstream cin( input.txt , std::ios::in);       std::ofstream cout( output.txt , std::ios::out);   #else       std::ios_base::sync_with_stdio(false);       std::cin.tie(nullptr);   #endif       int test_cases = 1;       cin >> test_cases;       for (int yt = 1; yt <= test_cases; ++yt) {           SolveTask();       }   #ifdef FILE_IN_OUT       cin.close();       cout.close();   #endif       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 5e3 + 10;   int a[M];   int dp[M][M];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , a + i), dp[i][i] = a[i];     for (int d = 1; d < n; d++) {       for (int i = 1; i + d <= n; i++) {         int j = i + d;         dp[i][j] = dp[i][j - 1] ^ dp[i + 1][j];       }     }     for (int d = 1; d < n; d++) {       for (int i = 1; i + d <= n; i++) {         int j = i + d;         dp[i][j] = max({dp[i][j], dp[i + 1][j], dp[i][j - 1]});       }     }     int q, l, r;     scanf( %d , &q);     while (q--) {       scanf( %d%d , &l, &r);       printf( %d n , dp[l][r]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long eps = 1e9 + 7;   const double inf = 1e-12;   bool F(set<pair<int, int> > &a) {     pair<int, int> p = *a.rbegin();     a.erase(p);     --p.first;     if (p.first != 0) {       a.insert(p);     }     if (!a.empty() && a.rbegin()->first == a.begin()->first) {       if (p.first != 0) {         a.erase(p);       }       ++p.first;       a.insert(p);       return true;     }     if (p.first != 0) {       a.erase(p);     }     ++p.first;     a.insert(p);     p = *a.begin();     a.erase(p);     --p.first;     if (p.first != 0) {       a.insert(p);     }     if (!a.empty() && a.rbegin()->first == a.begin()->first) {       if (p.first != 0) {         a.erase(p);       }       ++p.first;       a.insert(p);       return true;     }     if (p.first != 0) {       a.erase(p);     }     ++p.first;     a.insert(p);     return false;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     set<pair<int, int> > a;     vector<int> b(1e5 + 5);     int max1 = 1;     for (int i = 1; i <= n; ++i) {       int first;       cin >> first;       a.erase(pair<int, int>(b[first], first));       ++b[first];       a.insert(pair<int, int>(b[first], first));       if (F(a)) {         max1 = i;       }     }     cout << max1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     bool f = 0;     int x = 0;     char c = getchar();     while (c <  0  ||  9  < c) {       if (c ==  - ) f = 1;       c = getchar();     }     while ( 0  <= c && c <=  9 )       x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();     return !f ? x : -x;   }   const int MAXN = 200000;   const int INF = 0x3f3f3f3f;   int fa[MAXN + 5], ch[MAXN + 5][2];   long long a[MAXN + 5], siz[MAXN + 5], sum[MAXN + 5], ans[MAXN + 5],       all[MAXN + 5], ad[MAXN + 5], de[MAXN + 5];   bool pan(int u) { return ch[fa[u]][1] == u; }   bool isroot(int u) { return (ch[fa[u]][0] != u && ch[fa[u]][1] != u); }   void PushUp(int u) {     sum[u] = sum[ch[u][0]] + sum[ch[u][1]] + siz[u];     all[u] = all[ch[u][0]] + all[ch[u][1]] + siz[u] * a[u];     ans[u] = ans[ch[u][0]] + ans[ch[u][1]] + ad[u] +              a[u] * (siz[u] * siz[u] - de[u]) +              2 * a[u] * siz[u] * sum[ch[u][1]] +              2 * all[ch[u][0]] * (sum[u] - sum[ch[u][0]]);     return;   }   void Rotate(int x) {     int y = fa[x], z = fa[y], dx = pan(x), dy = pan(y), w = ch[x][dx ^ 1];     if (!isroot(y)) ch[z][dy] = x;     ch[x][dx ^ 1] = y, ch[y][dx] = w;     if (w) fa[w] = y;     fa[y] = x, fa[x] = z;     PushUp(y);     return;   }   void Splay(int x) {     for (int y = fa[x]; !isroot(x); Rotate(x), y = fa[x])       if (!isroot(y)) Rotate(pan(x) == pan(y) ? y : x);     PushUp(x);     return;   }   int Access(int x) {     int y = 0;     while (x) {       Splay(x);       siz[x] -= sum[y];       ad[x] -= ans[y];       de[x] -= sum[y] * sum[y];       siz[x] += sum[ch[x][1]];       ad[x] += ans[ch[x][1]];       de[x] += sum[ch[x][1]] * sum[ch[x][1]];       ch[x][1] = y, PushUp(x), y = x, x = fa[x];     }     return y;   }   void Link(int x, int y) {     Access(y);     Splay(y);     Access(x);     Splay(x);     fa[y] = x;     siz[x] += sum[y];     ad[x] += ans[y];     de[x] += 1ll * sum[y] * sum[y];     PushUp(x);     return;   }   void Cut(int x, int y) {     Access(x);     Splay(x);     Splay(y);     siz[x] -= sum[y];     ad[x] -= ans[y];     de[x] -= 1ll * sum[y] * sum[y];     fa[y] = 0;     PushUp(x);     return;   }   char Re[5];   int f[MAXN + 5];   bool check(int x, int y) {     Access(y);     Splay(y), Splay(x);     return !isroot(y);   }   int main() {     int n = read();     for (int i = 2; i <= n; i++) f[i] = read();     for (int i = 1; i <= n; i++)       a[i] = read(), sum[i] = siz[i] = 1, ans[i] = all[i] = a[i];     for (int i = 2; i <= n; i++) Link(f[i], i);     Access(1), Splay(1);     printf( %.10f n , 1.0 * ans[1] / n / n);     int m = read();     for (int i = 1; i <= m; i++) {       scanf( %s , Re);       if (Re[0] ==  P ) {         int x = read(), y = read();         if (f[x] == y || f[y] == x) goto Break;         if (check(x, y)) swap(x, y);         Cut(f[x], x), f[x] = y;         Link(f[x], x);       } else {         int x = read(), y = read();         Access(x), Splay(x);         a[x] = y;         PushUp(x);       }     Break:       Access(1), Splay(1);       printf( %.10f n , 1.0 * ans[1] / n / n);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 200005;   const int MOD = 1000000007;   long long fun(long long a, long long b) {     if (a > b) return a;     return b;   }   void swp(long long *a, long long *b) {     long long temp = *a;     *a = *b;     *b = temp;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     ;     int n;     cin >> n;     char ch;     long long x, y;     cin >> ch >> x >> y;     if (x > y) swp(&x, &y);     long long mx = x, my = y;     n--;     while (n--) {       cin >> ch >> x >> y;       if (x > y) swp(&x, &y);       if (ch ==  + ) {         mx = fun(mx, x);         my = fun(my, y);       } else {         if ((x >= mx && y >= my) || (x >= my && y >= mx))           cout <<  YES n ;         else           cout <<  NO n ;       }     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   long long max(long long a, long long b) {     if (a > b) {       return a;     } else {       return b;     }   }   long long min(long long a, long long b) {     if (a < b) {       return a;     } else {       return b;     }   }   long long power(long long b, long long e) {     if (e == 0) return 1;     if (e % 2)       return ((b * power((b) * (b), (e - 1) / 2)));     else       return power((b) * (b), e / 2);   }   long long modpower(long long b, long long e, long long q) {     long long MOD = q;     if (e == 0) return 1;     if (e % 2)       return ((b % MOD) * modpower((b % MOD) * (b % MOD), (e - 1) / 2, q)) % MOD;     else       return modpower((b % MOD) * (b % MOD), e / 2, q) % MOD;   }   void dpv(vector<long long> v) {     for (long long i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     cout <<   n ;   }   void dpv(vector<pair<long long, long long> > v) {     for (long long i = 0; i < v.size(); i++) {       cout << v[i].first <<     << v[i].second <<   n ;     }   }   void dpv(set<long long> v) {     for (auto i : v) {       cout << i <<    ;     }     cout <<   n ;   }   void oblivious() {     string s;     cin >> s;     long long p = 0, ans = 0, q = 1;     for (long long i = 0; i <= s.length(); i++) {       if (s[i] ==  +  || s[i] ==  -  || i == s.length()) {         ans += p * q;         p = 0;         if (i == s.length()) {           continue;         }         if (s[i] ==  + ) {           q = 1;         } else if (s[i] ==  - ) {           q = -1;         }       } else {         p = (10 * p + s[i] -  0 );       }     }     long long u = ans;     long long y = 0;     string s1;     if (u == 0) {       s1.push_back( 0 );     } else {       while (u != 0) {         s1.push_back(u % 10 +  0 );         u = u / 10;       }     }     reverse(s1.begin(), s1.end());     for (long long i = 0; i < s1.length(); i++) {       long long z = s1[i];       while (z--) {         cout <<  + ;       }       cout <<  .> ;       cout <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       oblivious();     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int test = 0; test < t; test++) {       bool answer = true;       int n;       cin >> n;       vector<int> a(n);       vector<int> b(n);       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) cin >> b[i];       unordered_map<int, int> keys_to_counts;       keys_to_counts[1] = 0;       keys_to_counts[-1] = 0;       keys_to_counts[0] = 0;       for (int x : a) {         keys_to_counts[x]++;       }       keys_to_counts[a[n - 1]]--;       for (int i = n - 1; i >= 0; i--) {         if (b[i] > a[i]) {           answer &= (keys_to_counts[1] > 0);         } else if (b[i] < a[i]) {           answer &= (keys_to_counts[-1] > 0);         }         if (i != 0) keys_to_counts[a[i - 1]]--;       }       if (answer)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long arr[200000], cum[200000];   unsigned long long forone;   unsigned long long n;   unsigned long long make(unsigned long long st, unsigned long long mult,                           unsigned long long lim, unsigned long long level) {     if (st > n) return 0;     unsigned long long end = min(n, st + lim - 1);     return make(end + 1, mult, lim * mult, level + 1) +            (cum[end] - cum[st - 1]) * level;   }   bool comp(int p, int q) { return p > q; }   int main() {     while (cin >> n) {       unsigned long long i;       for (i = 1; i <= n; i++) cin >> arr[i];       sort(&arr[1], &arr[n + 1], comp);       cum[0] = 0;       forone = 0;       for (i = 1; i <= n; i++) {         forone += (i - 1) * arr[i];         cum[i] = cum[i - 1] + arr[i];       }       unsigned long long q;       cin >> q;       unsigned long long tem;       for (i = 1; i <= q; i++) {         cin >> tem;         if (tem == 1) {           cout << forone;           if (i != q) cout <<    ;           continue;         }         cout << make(2, tem, tem, 1);         if (i != q) cout <<    ;       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x, t, a, b, da, db, i, j, p, ans = 0;   int main() {     scanf( %d %d %d %d %d %d , &x, &t, &a, &b, &da, &db);     i = 0;     for (i = 0; i < t; i++)       for (j = 0; j < t; j++) {         if (a - i * da + b - j * db == x) ans = 1;       }     for (i = 0; i < t; i++)       if (a - i * da == x || b - i * db == x) ans = 1;     if (ans == 1 || x == 0)       printf( YES );     else       printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, a, b;     cin >> n >> a >> b;     long long left = a;     long long right = n - b - 1;     long long end = max(left, right);     long long ans = n - end;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n, p, start[390000], fin[390000];   map<pair<int, int>, int> mp;   int main() {     scanf( %d %d , &n, &p);     vector<int> cnt(n, 0);     for (int i = 0; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       x--;       y--;       if (x > y) swap(x, y);       start[i] = x;       fin[i] = y;       cnt[x]++;       cnt[y]++;       mp[make_pair(x, y)]++;     }     vector<int> cnt2(cnt.begin(), cnt.end());     sort(cnt.begin(), cnt.end());     long long ans = 0;     int j = n;     for (int i = 0; i < n; i++) {       while (j - 1 >= i && cnt[i] + cnt[j - 1] >= p) j--;       if (j < i + 1) j = i + 1;       ans += n - j;     }     for (int i = 0; i < n; i++) {       if (cnt2[start[i]] + cnt2[fin[i]] < p) continue;       if (cnt2[start[i]] + cnt2[fin[i]] - mp[make_pair(start[i], fin[i])] < p)         ans--;       mp[make_pair(start[i], fin[i])] = 0;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 + 5;   int main() {     int n, que[maxn];     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &que[i]);     sort(que, que + n);     if (n % 2 == 0) n--;     printf( %d n , que[n / 2]);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   int n, k, x, y;   set<pair<int, int> > s;   vector<pair<int, int> > a[MAXN];   vector<int> ans;   inline void start() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &x, &y);       a[x].push_back({y, i});     }   }   inline void solve() {     for (int i = 1; i <= 2e5 + 1; i++) {       for (int j = 0; j < a[i].size(); j++) s.insert(a[i][j]);       while (s.size() > k) {         ans.push_back((--s.end())->second);         s.erase(--s.end());       }       while (!s.empty() && s.begin()->first == i) s.erase(s.begin());     }     sort(ans.begin(), ans.end());     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) printf( %d  , ans[i]);     puts(  );   }   int main() {     start();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j, k, sum = 0;     cin >> n;     pair<int, int> a[n];     for (i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i;     }     sort(a, a + n);     for (i = 0; i < n; i++) {       sum = sum + ((a[n - i - 1].first * i) + 1);     }     cout << sum <<   n ;     for (i = 0; i < n; i++) cout << a[n - i - 1].second + 1 <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = +100500;   const long long INF = 4e18;   long long a[MAXN];   int main() {     long long n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     if (k >= 3) {       sort(a + 1, a + n + 1);       cout << a[n];       return 0;     }     if (k == 1) {       sort(a + 1, a + n + 1);       cout << a[1];       return 0;     }     multiset<long long> b;     multiset<long long> c;     for (int i = 1; i <= n; i++) {       c.insert(a[i]);     }     long long ans = -INF;     long long pt = 1;     while (pt < n) {       b.insert(a[pt]);       c.erase(c.equal_range(a[pt]).first);       long long x = max(*c.begin(), *b.begin());       ans = max(ans, x);       pt++;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b;   bool check(int k, int x, int y) {     long long ca = 1LL * k * x;     long long cb = 1LL * k * y;     return ca <= a && cb <= b;   }   long long gcd(long long a, long long b) {     if (!b)       return a;     else       return gcd(b, a % b);   }   int main() {     int x, y;     cin >> a >> b >> x >> y;     int l = 1, r = 2 * 1e9;     long long ans = 2e9 + 1;     long long g = gcd(x, y);     x /= g;     y /= g;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid, x, y)) {         ans = mid;         l = mid + 1;       } else         r = mid - 1;     }     if (ans == 2e9 + 1)       cout <<  0 0  << endl;     else       cout << x * ans <<     << y * ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   int n, k;   int v[N], c[N], p[N];   double f[N];   double C(int n, int m) { return f[n] - f[m] - f[n - m]; }   struct Node {     int Max, Min;   } node[N * 4];   void pushup(int x) {     node[x].Max = max(node[((x << 1) + 1)].Max, node[((x << 1) + 2)].Max);     node[x].Min = min(node[((x << 1) + 1)].Min, node[((x << 1) + 2)].Min);   }   void build(int l, int r, int x = 0) {     if (l == r) {       node[x].Max = v[l];       node[x].Min = c[l];       return;     }     int mid = (l + r) >> 1;     build(l, mid, ((x << 1) + 1));     build(mid + 1, r, ((x << 1) + 2));     pushup(x);   }   int Max1, Min1;   void rmq(int l, int r, int L = 1, int R = n, int x = 0) {     if (L >= l && R <= r) {       Max1 = max(Max1, node[x].Max);       Min1 = min(Min1, node[x].Min);       return;     }     int mid = (L + R) >> 1;     if (l <= mid) rmq(l, r, L, mid, ((x << 1) + 1));     if (r > mid) rmq(l, r, mid + 1, R, ((x << 1) + 2));   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &v[i]);     for (int i = 1; i <= n; i++) scanf( %d , &c[i]);     p[n] = min(v[n] * 100, c[n]);     int pre = n;     int Max = v[n], Min = c[n];     for (int i = n - 1; i >= 1; i--) {       Max = max(Max, v[i]);       Min = min(Min, c[i]);       if (min(Max * 100, Min) < min(v[i] * 100, c[i])) Max = v[i], Min = c[i];       p[i] = min(Max * 100, Min);     }     sort(p + 1, p + 1 + n);     for (int i = 1; i <= n; i++) f[i] = f[i - 1] + log(i * 1.0);     double ans = 0;     for (int i = 1; i <= n; i++) {       if (k - 1 > n - i) break;       ans += exp(log(p[i] * 1.0) + C(n - i, k - 1) - C(n, k));     }     printf( %.12f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int inv(long long int k) {     long long int vl = 1000000007 - 2;     long long int val = 1;     long long int b = k;     for (int i = 0; i < 63; i++) {       if ((vl >> i) & 1) {         val *= b;         val %= 1000000007;       }       b = b * b;       b %= 1000000007;     }     return val;   }   int main() {     string s;     cin >> s;     long long int l = s.size();     vector<long long int> vr(l + 1), op(l + 1);     vr[0] = 1;     for (int i = 1; i <= l; i++) {       vr[i] = i * vr[i - 1];       vr[i] %= 1000000007;     }     for (int i = 0; i < l; i++) {       if (s[i] ==  ( ) op[i + 1]++;       op[i + 1] += op[i];     }     long long int ans = 0;     for (int i = 0; i < l; i++) {       if (s[i] ==  ) ) continue;       long long int v = op[i + 1];       long long int v1 = op[l] - op[i + 1];       v1 = l - i - 1 - v1;       if (v1 == 0) continue;       long long int n = v + v1 - 1;       long long int k = v;       k = (vr[k] * vr[n - k]) % 1000000007;       k = inv(k);       k = (vr[n] * k) % 1000000007;       ans += k;       ans %= 1000000007;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, temp;     cin >> n;     long long int sum = 0, sum2 = 0;     for (int i = 0; i < n; i++) {       cin >> temp;       sum += temp;     }     for (int i = 0; i < n - 1; i++) {       cin >> temp;       sum2 += temp;     }     cout << sum - sum2 << endl;     sum = 0;     for (int i = 0; i < n - 2; i++) {       cin >> temp;       sum += temp;     }     cout << sum2 - sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int inf_int = 1e9;   long long inf_ll = 1e16;   const double pi = 3.1415926535898;   const int mod = 1e9 + 9;   const int MAXN = 2e5 + 100;   bool debug = false;   char a[1005][1005];   char used[1005][1005][4][3];   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   int n, m;   inline bool is_ok(int x, int y, int d, int z) {     return x >= 1 && x <= n && y >= 1 && y <= m && z <= 2 && a[x][y] !=  *  &&            !used[x][y][d][z];   }   void solve() {     cin >> n >> m;     int x1, y1;     for (int i = 1; i <= n; ++i) {       for (int e = 1; e <= m; ++e) {         cin >> a[i][e];         if (a[i][e] ==  S ) {           x1 = i;           y1 = e;         }       }     }     queue<pair<pair<int, int>, pair<int, int> > > q;     used[x1][y1][0][0] = 1;     used[x1][y1][1][0] = 1;     used[x1][y1][2][0] = 1;     used[x1][y1][3][0] = 1;     q.push({{x1, y1}, {0, 0}});     q.push({{x1, y1}, {1, 0}});     q.push({{x1, y1}, {2, 0}});     q.push({{x1, y1}, {3, 0}});     while (!q.empty()) {       int x = q.front().first.first, y = q.front().first.second;       int d = q.front().second.first, z = q.front().second.second;       q.pop();       if (is_ok(x + dx[d], y + dy[d], d, z)) {         q.push({{x + dx[d], y + dy[d]}, {d, z}});         used[x + dx[d]][y + dy[d]][d][z] = 1;       }       for (int i = 0; i < 4; ++i) {         if (is_ok(x + dx[i], y + dy[i], i, z + 1)) {           q.push({{x + dx[i], y + dy[i]}, {i, z + 1}});           used[x + dx[i]][y + dy[i]][i][z + 1] = 1;         }       }     }     for (int i = 1; i <= n; ++i) {       for (int e = 1; e <= m; ++e) {         if (a[i][e] ==  T ) {           for (int j = 0; j < 4; ++j) {             for (int f = 0; f <= 2; ++f) {               if (used[i][e][j][f]) {                 cout <<  YES ;                 return;               }             }           }         }       }     }     cout <<  NO ;   }   int main() {     if (!debug) {       ios_base::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);     }     int t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300005;   int n, k, pos[N];   long long c[N], ans;   vector<int> v;   priority_queue<pair<long long, int> > q;   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %lld , &c[i]);     for (int i = 1; i <= n + k; i++) {       if (i <= n) q.push(make_pair(c[i], i));       if (k < i) {         int x = q.top().second;         long long w = q.top().first;         q.pop();         ans += w * ((long long)i - (long long)x);         v.push_back(x);       }     }     printf( %lld n , ans);     for (int i = 0; i < v.size(); i++) pos[v[i]] = i + k + 1;     for (int i = 1; i <= n; i++) printf( %d  , pos[i]);     return 0;   }


#include <bits/stdc++.h>   int mod = 1000000007;   const double pi = 3.141592653689793238460;   const int inf = 0x3f3f3f3f;   using namespace std;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, k;     cin >> n >> k;     int a[10005];     for (int i = 0; i < n; i++) cin >> a[i];     vector<int> pos;     for (int i = 0; i < n; i++) {       int x = a[i];       while (x > 0) {         pos.push_back(x);         x /= 2;       }     }     int ans = inf;     for (auto x : pos) {       vector<int> cur;       for (int i = 0; i < n; i++) {         int cnt = 0;         int y = a[i];         while (y > x) {           y /= 2;           cnt++;         }         if (y == x) {           cur.push_back(cnt);         }       }       if (cur.size() < k) continue;       sort(cur.begin(), cur.end());       ans = min(ans, accumulate(cur.begin(), cur.begin() + k, 0));     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 6;   int g[N];   int main() {     int n, m, v, i;     cin >> n >> m >> v;     long long top = 1 + (n - 1) * (n - 2) / 2;     if (n - 1 > m || top < (long long)m) {       cout << -1;       return 0;     }     --v;     for (i = 0; i < n; ++i) g[i] = i;     swap(g[1], g[v]);     for (i = 0; i < n - 1; ++i) {       cout << g[i] + 1 <<     << g[i + 1] + 1 << endl;       --m;     }     int j;     for (i = 1; i < n - 1 && m; ++i) {       for (j = i + 2; j < n && m; ++j) {         cout << g[i] + 1 <<     << g[j] + 1 << endl;         --m;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double M;   struct E {     int x, y, z, tp, id;     bool operator<(const E yy) const {       double p1 = tp ? z : z + M, p2 = yy.tp ? yy.z : yy.z + M;       return p1 < p2;     }   } e[100005];   int n, m, k, fa[50005], p[50005], d[50005];   int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); }   int Calc(double mid, int r) {     for (int i = 1; i <= n; i++) fa[i] = i;     M = mid, sort(e + 1, e + m + 1);     int ans[2] = {0}, w = n - 1;     for (int i = 1; i <= m; i++) {       int fx = gf(e[i].x), fy = gf(e[i].y);       if (fx == fy) continue;       ans[1] += e[i].z, ans[0] += !e[i].tp;       if (r && ans[0] > k) {         ans[1] -= e[i].z, ans[0] -= !e[i].tp;         continue;       }       fa[fx] = fy, w--;       if (r) p[++p[0]] = e[i].id;     }     if (w) puts( -1 ), exit(0);     return ans[r];   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1, x, y, z; i <= m; i++)       scanf( %d%d%d , &x, &y, &z), e[i] = {x, y, z, !(x == 1 || y == 1), i},                                    d[x]++, d[y]++;     if (d[1] < k || (n > 1 && !k)) return puts( -1 ), 0;     double l = -100001, r = 100001, ans = 0;     while (r - l > 1e-8) {       double mid = (l + r) / 2;       int w = Calc(mid, 0);       if (w == k) {         ans = mid;         break;       }       if (r - l < 0.1 && w > k) {         ans = mid;         break;       }       if (w < k)         r = mid;       else         ans = mid, l = mid;     }     Calc(ans, 1);     printf( %d n , n - 1);     while (p[0]) printf( %d  , p[p[0]--]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fac[100001];   long long inv_fac[100001];   int val[100001];   vector<int> cnt(53, 0);   int l[100001];   int r[100001];   long long keep[53][53];   long long dp[54][100001];   long long dp1[54][100001];   long long mod = 1e9 + 7;   inline void add(long long &a, long long b) {     a += b;     if (a >= mod) a -= mod;   }   inline void sub(long long &a, long long b) {     a -= b;     if (a < 0) a += mod;   }   long long pw(long long x, int p) {     if (p == 0) return 1;     if (p == 1) return x % mod;     long long temp = pw(x, p / 2);     temp = (temp * temp) % mod;     if (p % 2 == 0) return temp;     temp = (x * temp) % mod;     return temp;   }   void calc() {     fac[0] = fac[1] = 1;     inv_fac[0] = inv_fac[1] = 1;     for (int i = 2; i <= 100000; i++) {       fac[i] = (i * fac[i - 1]) % mod;       inv_fac[i] = pw(fac[i], mod - 2);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     int q;     cin >> q;     for (int i = 0; i < q; i++) cin >> l[i] >> r[i];     int n = s.size();     int mx = n / 2;     calc();     for (int i = 0; i < n; i++) {       if (s[i] >=  a  && s[i] <=  z ) {         val[i + 1] = int(s[i] -  a ) + 1;         cnt[int(s[i] -  a ) + 1]++;       } else {         val[i + 1] = 26 + int(s[i] -  A ) + 1;         cnt[26 + int(s[i] -  A ) + 1]++;       }     }     for (int i = 1; i <= 52; i++) {       int temp = cnt[i];       if (temp > n / 2 || cnt[i] == 0) {         continue;       }       temp = n / 2 - temp;       for (int w = 0; w <= mx; w++) dp[0][w] = dp1[53][w] = 0;       dp[0][0] = dp1[53][0] = 1;       for (int k = 1; k <= 52; k++) {         if (k == i || cnt[k] == 0) {           for (int w = 0; w <= mx; w++) dp[k][w] = dp[k - 1][w];           continue;         }         for (int w = 0; w <= mx; w++) {           dp[k][w] = dp[k - 1][w];           if (w >= cnt[k]) add(dp[k][w], dp[k - 1][w - cnt[k]]);         }       }       for (int k = 52; k >= 1; k--) {         if (k == i || cnt[k] == 0) {           for (int w = 0; w <= mx; w++) dp1[k][w] = dp1[k + 1][w];           continue;         }         for (int w = 0; w <= mx; w++) {           dp1[k][w] = dp1[k + 1][w];           if (w >= cnt[k]) add(dp1[k][w], dp1[k + 1][w - cnt[k]]);         }       }       for (int k = i; k <= 52; k++) {         if (k == i) {           keep[k][i] = dp[52][temp];           continue;         }         long long t1 = 0;         int rem = temp - cnt[k];         if (rem < 0) {           keep[k][i] = keep[i][k] = 0;           continue;         }         for (int w = 0; w <= rem; w++) {           long long t2 = (dp[k - 1][w] * dp1[k + 1][rem - w]) % mod;           add(t1, t2);         }         keep[i][k] = keep[k][i] = t1;       }     }     long long ans = (fac[n / 2] * fac[n / 2]) % mod;     for (int i = 1; i <= 52; i++) ans = (ans * inv_fac[cnt[i]]) % mod;     ans = (2 * ans) % mod;     for (int i = 0; i < q; i++) {       int x = val[l[i]];       int y = val[r[i]];       long long temp = ans;       temp = (temp * keep[x][y]) % mod;       cout << temp << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 100010, M = 100010, inf = 1e18;   long long m, n, p, d[N], a[M], f[M], sum[M], g[M], x[M], y[M];   inline long long read() {     char ch = getchar();     long long as = 0, f = 1;     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) f = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) as = as * 10 + ch -  0 ;     return as;   }   long long q[M << 1], l, r;   long long as = inf;   int main() {     long long h, t;     n = read();     m = read();     p = read();     for (long long i = 1; i < n; i++) d[i] = read();     for (long long i = n - 2; i; i--) d[i] += d[i + 1];     for (long long i = 1; i <= m; i++) {       h = read();       t = read();       a[i] = t + d[h];     }     sort(a + 1, a + m + 1);     for (long long i = 1; i <= m; i++) sum[i] = sum[i - 1] + a[i], f[i] = inf;     for (long long i = 1; i <= p; i++) {       memcpy(g, f, sizeof(g));       l = M;       r = M;       for (long long j = 0; j <= m; j++) y[j] = g[j] + sum[j];       q[r] = 0;       for (long long j = 1; j <= m; j++) {         while (r > l)           if ((y[q[l + 1]] - y[q[l]]) <= a[j] * (q[l + 1] - q[l]))             l++;           else             break;         f[j] = min(g[j], -a[j] * q[l] + y[q[l]] + a[j] * j - sum[j]);         while (r > l)           if ((y[q[r]] - y[q[r - 1]]) * (j - q[r]) >=               (y[j] - y[q[r]]) * (q[r] - q[r - 1]))             r--;           else             break;         r++;         q[r] = j;       }       as = min(as, f[m]);     }     printf( %lld , as);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e5 + 5;   vector<pair<long long, long long>> v;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long x, y, bx, by, xs, ys, t, temp1, temp2, temp;     long long ax, ay;     int ans = 0;     cin >> x >> y >> ax >> ay >> bx >> by >> xs >> ys >> t;     while (x <= 5e16 && y <= 5e16) {       v.push_back({x, y});       x = ax * x + bx;       y = ay * y + by;     }     for (int i = 0; i < v.size(); i++) {       for (int j = i; j < v.size(); j++) {         temp = abs(v[i].first - v[j].first) + abs(v[i].second - v[j].second);         temp1 = abs(v[i].first - xs) + abs(v[i].second - ys);         temp2 = abs(xs - v[j].first) + abs(ys - v[j].second);         if (temp + temp1 <= t) {           ans = max(ans, j - i + 1);         }         if (temp + temp2 <= t) {           ans = max(ans, j - i + 1);         }       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int f[101010];   long long s[101010];   long long a[101010];   int main() {     ios_base::sync_with_stdio(0);     long long n, l;     cin >> n >> l;     for (int i = 1; i <= n; ++i) cin >> a[i];     sort(a + 1, a + n + 1);     if (n == 1) {       cout << fixed << setprecision(10) << (long double)max(a[1], l - a[1]);       return 0;     }     a[0] = 0;     long long ans = 0;     a[n + 1] = l;     for (int i = 1; i <= n + 1; ++i) ans = max(ans, a[i] - a[i - 1]);     ans = max(ans, max(a[1] * 2, (a[n + 1] - a[n]) * 2));     cout << fixed << setprecision(10) << (long double)(ans / 2.0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 501;   int dp[maxn][maxn];   int n;   int a[maxn];   int dp2[maxn];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i], dp[i][i] = a[i];     for (int len = 1; len <= n; len++) {       for (int i = 1; i <= n - len + 1; i++) {         for (int k = i; k < i + len - 1; k++) {           if (dp[i][k] != 0 && dp[i][k] == dp[k + 1][i + len - 1]) {             dp[i][i + len - 1] = dp[i][k] + 1;           }         }       }     }     for (int i = 1; i <= n; i++) {       dp2[i] = dp2[i - 1] + 1;       for (int j = 1; j < i; j++) {         if (dp[j][i] > 0) {           dp2[i] = min(dp2[i], dp2[j - 1] + 1);         }       }     }     printf( %d n , dp2[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T __sqr(const T x) {     return x * x;   }   template <class T, class X>   inline T __pow(T a, X y) {     T z = 1;     for (int i = 1; i <= y; i++) {       z *= a;     }     return z;   }   template <class T>   inline T gcd(T a, T b) {     a = abs(a);     b = abs(b);     if (!b) return a;     return __gcd(b, a % b);   }   template <class T>   inline T lcm(T a, T b) {     a = abs(a);     b = abs(b);     return (a / __gcd(a, b)) * b;   }   inline bool ispow2(int x) { return (x != 0 && (x & (x - 1)) == 0); }   template <class T>   void UpdateMin(T &x, T y) {     if (y < x) {       x = y;     }   }   template <class T>   void UpdateMax(T &x, T y) {     if (x < y) {       x = y;     }   }   template <class T, class X, class Y>   inline T bigmod(T n, X m, Y mod) {     unsigned long long ret = 1, a = n % mod;     while (m) {       if (m & 1) ret = (ret * a) % mod;       m >>= 1;       a = (a * a) % mod;     }     ret %= mod;     return (T)ret;   }   template <class T, class Y>   inline T modinv(T n, Y mod) {     return bigmod(n, mod - 2, mod);   }   template <class T, class X>   int getbit(T s, X i) {     return (s >> i) & 1;   }   template <class T, class X>   T onbit(T s, X i) {     return s | (T(1) << i);   }   template <class T, class X>   T offbit(T s, X i) {     return s & (~(T(1) << i));   }   template <class T>   inline void read(T &n) {     char c;     for (c = getchar(); !(c >=  0  && c <=  9 ); c = getchar())       ;     n = c -  0 ;     for (c = getchar(); c >=  0  && c <=  9 ; c = getchar()) n = n * 10 + c -  0 ;   }   void extended_euclid(long long a, long long b, long long &x, long long &y) {     if (!b) {       x = 1, y = 0;       return;     }     long long first, second;     extended_euclid(b, a % b, first, second);     x = second;     y = first - (a / b) * second;   }   pair<long long, pair<long long, long long> > extendedEuclid(long long a,                                                               long long b) {     long long x = 1, y = 0;     long long xLast = 0, yLast = 1;     long long q, r, m, n;     while (a != 0) {       q = b / a;       r = b % a;       m = xLast - q * x;       n = yLast - q * y;       xLast = x, yLast = y;       x = m, y = n;       b = a, a = r;     }     return make_pair(b, make_pair(xLast, yLast));   }   const long long mod[] = {0,          1000000007, 1000000009,                            1000000021, 1000000033, 1000000097,                            1000000093, 1000000097, 1000000103};   const long long base[] = {0,       1000003, 1000033, 1000037, 1000039,                             1000081, 1000099, 1000117, 1000121};   int a[(2000 + 20)], b[(2000 + 20)], pos[(2000 + 20)], loc[(2000 + 20)];   vector<pair<int, int> > ans;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);     }     for (int i = 1; i <= n; i++) {       scanf( %d , b + i);       swap(a[i], b[i]);     }     for (int i = 1; i <= n; i++) {       pos[a[i]] = i;     }     for (int i = 1; i <= n; i++) {       b[i] = pos[b[i]];       loc[b[i]] = i;     }     int tot = 0;     for (int i = n; i >= 1; i--) {       if (i == b[i]) continue;       tot += i - loc[i];       int idx = loc[i];       for (int j = idx + 1; j <= i; j++) {         if (b[j] <= 0) assert(0);         if (idx >= b[j]) {           if (idx > 2000)             assert(1 > 0);           else             ans.push_back(make_pair(idx, j));           loc[b[j]] = idx;           swap(b[j], b[idx]);           idx = j;         }       }     }     printf( %d n , tot);     printf( %d n , ans.size());     for (int i = 0; i < ((int)ans.size()); i++) {       printf( %d %d n , ans[i].first, ans[i].second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   istream& operator>>(istream& in, vector<T>& vec) {     for (auto& v : vec) {       in >> v;     }     return in;   }   template <class T>   ostream& operator<<(ostream& o, const vector<T>& vec) {     o <<  [ ;     for (const auto& v : vec) {       o << v <<    ;     }     o <<  ] n ;     return o;   }   int main() {     int n, m, t;     cin >> n >> m >> t;     vector<vector<int>> mat(n, vector<int>(m));     vector<vector<int>> bsm(m);     cin >> mat;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (mat[i][j] != 2) {           bsm[j].push_back(i);         }       }     }     while (t--) {       int colI, rowI = -1;       cin >> colI;       colI--;       while (true) {         int newRowI = n;         {           auto& bsv = bsm[colI];           int l = 0, r = bsv.size(), m;           while (l < r) {             m = (l + r) / 2;             if (bsv[m] < rowI) {               l = m + 1;             } else {               r = m;             }           }           if (l < bsv.size()) {             newRowI = bsv[l];             int i = l + 1;             for (; i < bsv.size() && bsv[i] == bsv[l]; i++) {             }             if (i < bsv.size()) {               for (int a = l; a < i; a++) {                 bsv[a] = bsv[i];               }             } else {               while (i-- > l) {                 bsv.pop_back();               }             }           }         }         rowI = newRowI;         if (rowI >= n) {           cout << colI + 1 <<    ;           break;         } else {           if (mat[rowI][colI] == 1) {             colI++;           } else {             colI--;           }         }       }     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   int n, m, ans[N], h[N];   bitset<N> a[N];   vector<int> e[N];   bool check1() {     for (int i = (int)(1); i <= (int)(n); i++)       if (e[i].size() & 1) return 0;     return 1;   }   void gauss() {     int it = 1;     for (int i = (int)(1); i <= (int)(n); i++) {       int j = it;       for (; j <= n; j++)         if (a[j][i]) break;       if (j > n) continue;       if (j > it) swap(a[j], a[it]);       h[it] = i;       for (int j = (int)(it + 1); j <= (int)(n); j++)         if (a[j][i]) a[j] ^= a[it];       it++;     }     int las = n + 1;     for (int i = (int)(it - 1); i >= (int)(1); i--) {       for (int j = (int)(h[i] + 1); j <= (int)(las - 1); j++) ans[j] = 0;       ans[h[i]] = a[i][0];       for (int j = (int)(1); j <= (int)(i - 1); j++)         if (a[j][h[i]]) a[j] ^= a[i];       las = h[i];     }     for (int i = (int)(1); i <= (int)(las - 1); i++) ans[i] = 0;   }   void solve() {     scanf( %d%d , &n, &m);     for (int i = (int)(1); i <= (int)(n); i++) e[i].clear();     for (int i = (int)(1); i <= (int)(m); i++) {       int x, y;       scanf( %d%d , &x, &y);       e[x].push_back(y);       e[y].push_back(x);     }     if (check1()) {       puts( 1 );       for (int i = (int)(1); i <= (int)(n); i++) printf( 1  );       puts(  );       return;     }     for (int i = (int)(1); i <= (int)(n); i++) {       a[i] = 0;       for (auto j : e[i]) a[i].set(j);       if (e[i].size() & 1) a[i].set(i), a[i].set(0);     }     memset(ans, 0, sizeof(ans));     gauss();     puts( 2 );     for (int i = (int)(1); i <= (int)(n); i++) printf( %d  , ans[i] + 1);     puts(  );   }   int main() {     int T;     scanf( %d , &T);     while (T--) solve();   }


#include <bits/stdc++.h>   #pragma warning(disable : 4786)   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   int A[100005];   int I[100005];   int D[100005];   int n;   int max(int a, int b) {     if (a > b) return a;     return b;   }   int ABS(int a) {     if (a < 0) return a = a * -1;     return a;   }   int main() {     int i, j, len, res, cur, res1;     while (scanf( %d , &n) != EOF) {       for (i = 0; i < n; i++) {         scanf( %d , &A[i]);       }       I[0] = 1;       for (i = 1; i < n; i++) {         if (A[i] > A[i - 1]) {           I[i] = I[i - 1] + 1;         } else {           I[i] = 1;         }       }       D[n - 1] = 1;       for (i = n - 1; i >= 0; i--) {         if (A[i] < A[i + 1]) {           D[i] = D[i + 1] + 1;         } else {           D[i] = 1;         }       }       res = 1;       for (i = 0; i < n; i++) {         if (i == 0) {           if (i + 1 < n) res = max(res, D[i + 1] + 1);         } else if (i == n - 1) {           if (i - 1 >= 0) res = max(res, I[i - 1] + 1);         } else {           int r = I[i - 1] + D[i + 1];           if (ABS(A[i - 1] - A[i + 1]) > 1 && A[i + 1] > A[i - 1]) {             res = max(res, r + 1);           }           res = max(res, I[i - 1] + 1);           res = max(res, D[i + 1] + 1);         }       }       printf( %d n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   long long POW(long long a, long long b, long long MMM = MOD) {     long long ret = 1;     for (; b; b >>= 1, a = (a * a) % MMM)       if (b & 1) ret = (ret * a) % MMM;     return ret;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lcm(long long a, long long b) {     if (a == 0 || b == 0) return a + b;     return a * (b / gcd(a, b));   }   int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, 1, -1};   int ddx[] = {-1, -2, 1, -2, 2, -1, 2, 1}, ddy[] = {-2, -1, -2, 1, -1, 2, 1, 2};   struct Edge {     int to, r;     Edge* ori;     Edge* rev;     Edge(int T, int R) { to = T, r = R; }   };   vector<Edge*> v[2605];   void addedge(int f, int t, int r) {     Edge* ori = new Edge(t, r);     Edge* rev = new Edge(f, 0);     ori->rev = rev;     rev->rev = ori;     v[f].push_back(ori);     v[t].push_back(rev);   }   const int S = 2603, T = 2604;   int level[2605], work[2605];   bool bfs() {     memset((level), -1, sizeof(level));     ;     level[S] = 0;     queue<int> q;     q.push(S);     while (!q.empty()) {       int x = q.front();       q.pop();       for (auto& nn : v[x]) {         int next = nn->to;         if (level[next] == -1 && nn->r > 0) {           level[next] = level[x] + 1;           q.push(next);         }       }     }     return level[T] != -1;   }   int dfs(int N, int des, int flow) {     if (N == des) return flow;     for (int& i = work[N]; i < v[N].size(); i++) {       int next = v[N][i]->to;       if (level[next] == level[N] + 1 && v[N][i]->r > 0) {         int df = dfs(next, des, min(v[N][i]->r, flow));         if (df > 0) {           v[N][i]->r -= df;           v[N][i]->rev->r += df;           return df;         }       }     }     return 0;   }   int main() {     int n, h, m;     scanf( %d%d%d , &n, &h, &m);     int ans = n * h * h;     for (int(i) = (0); (i) <= (n - 1); (i) += (1)) {       addedge(S, i * 51, h * h);       for (int(j) = (1); (j) <= (h); (j) += (1))         addedge(51 * i + j - 1, 51 * i + j, h * h - j * j);     }     for (int(i) = (0); (i) <= (m - 1); (i) += (1)) {       int x, y, z, w;       scanf( %d%d%d%d , &x, &y, &z, &w);       x--, y--;       for (int(j) = (x); (j) <= (y); (j) += (1))         addedge(51 * j + z, 2551 + i, 987654321);       addedge(2551 + i, T, w);     }     while (bfs()) {       memset((work), 0, sizeof(work));       ;       while (1) {         int f = dfs(S, T, 987654321);         if (f == 0) break;         ans -= f;       }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int N = 1000005;   const double PI = 4 * atan(1);   const double eps = 1e-7;   long long x, y, z;   int main() {     ios::sync_with_stdio(0);     cin >> x >> y >> z;     long long ans = 0;     ans = x / z + y / z;     long long a, b;     a = x;     b = y;     long long c = (z - x % z) % z;     long long res = 0;     if (b >= c && ((a + c) / z + (b - c) / z) > ans) {       ans = ((a + c) / z + (b - c) / z);       res = c;     }     a = x;     b = y;     c = (z - y % z) % z;     if (a >= c && ((a - c) / z + (b + c) / z) > ans) {       ans = ((a + c) / z + (b - c) / z);       res = c;     } else if (a >= c && ((a - c) / z + (b + c) / z) == ans) {       res = min(res, c);     }     cout << ans <<     << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int a[N], b[N], d[N], used[N], dis[N], ANS[N], dlt[N];   int n, m, Y0, Y1, lft, ans;   vector<int> ch[N], fa[N];   priority_queue<pair<int, int>, vector<pair<int, int> >,                  greater<pair<int, int> > >       pq;   int ABS(int x) {     if (x >= 0)       return x;     else       return -x;   }   int lnk(int x, int y) {     ch[x].push_back(y);     fa[y].push_back(x);     return ABS(b[x] - a[y]);   }   int avi(int x) {     int ret = 0;     for (int i = 0; i < int(fa[x].size()); i++) {       int to = fa[x][i];       if (used[to] == -1 || used[to] == dis[x]) ret++;     }     return ret;   }   int main() {     scanf( %d%d%d%d , &n, &m, &Y0, &Y1);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= m; i++) scanf( %d , b + i);     for (int i = 1; i <= m; i++) used[i] = -1;     for (int i = 1; i <= n; i++) {       int x = lower_bound(b + 1, b + 1 + m, a[i]) - b - 1;       int y = x + 1;       if (x == 0)         dis[i] = lnk(y, i);       else if (y == m + 1)         dis[i] = lnk(x, i);       else if (a[i] - b[x] < b[y] - a[i])         dis[i] = lnk(x, i);       else if (a[i] - b[x] > b[y] - a[i])         dis[i] = lnk(y, i);       else {         dis[i] = lnk(x, i);         lnk(y, i);       }       if (avi(i) == 1) {         dlt[i] = 1;         pq.push(make_pair(dis[i], i));       }     }     lft = n;     while (!pq.empty()) {       int D = pq.top().first, x = pq.top().second, y;       pq.pop();       lft--;       if (avi(x) == 0) continue;       for (int i = 0; i < int(fa[x].size()); i++) {         y = fa[x][i];         if (used[y] == -1 || used[y] == D) break;       }       used[y] = D;       ANS[y]++;       for (int i = 0; i < int(ch[y].size()); i++) {         int to = ch[y][i];         if (dis[to] != D && !dlt[to] && avi(to) == 1) {           dlt[to] = 1;           pq.push(make_pair(dis[to], to));         }       }     }     for (int i = 1; i <= m; i++) ans += ANS[i];     ans += lft;     printf( %d n , n - ans);     return 0;   }