#include <bits/stdc++.h>   using namespace std;   int n, k;   string s1, s2;   vector<pair<string, string> > ans;   map<string, int> u;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> s1 >> s2;       map<string, int>::iterator it = u.find(s1);       if (it == u.end()) {         u[s1] = k, u[s2] = k;         ans.push_back(make_pair(s1, s2));         k++;       } else {         u[s2] = it->second;         ans[it->second].second = s2;       }     }     cout << ans.size() << endl;     for (size_t i = 0; i < ans.size(); i++) {       cout << ans[i].first <<     << ans[i].second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int nr, K, mod, ans[33], v[70];   long long N;   struct matrix {     int a[33][33];     matrix() { memset(a, 0, sizeof(a)); }     matrix(bool type) {       memset(a, 0, sizeof(a));       if (type == 1)         for (int i = 0; i <= K; i++) a[i][i] = 1;     }   } dp[70][33], pref[33], suf[33];   matrix operator*(matrix a, matrix b) {     matrix c;     for (int i = 0; i <= K; i++)       for (int j = 0; j <= K; j++) {         c.a[i][j] = 0;         for (int k = 0; k <= K; k++)           c.a[i][j] = ((long long)c.a[i][j] + 1LL * a.a[i][k] * b.a[k][j]) % mod;       }     return c;   }   void Prod(matrix a) {     int old[33];     for (int i = 0; i <= K; i++) old[i] = ans[i];     for (int i = 0; i <= K; i++) {       ans[i] = 0;       for (int j = 0; j <= K; j++)         ans[i] = ((long long)ans[i] + 1LL * old[j] * a.a[j][i]) % mod;     }   }   void Finish() {     int sum = 0;     for (int i = 0; i <= K; i++) sum = ((long long)sum + ans[i]) % mod;     printf( %d n , sum);   }   int main() {     scanf( %I64d %d , &N, &K), mod = 1e9 + 7;     long long aux = N;     while (aux) v[nr++] = aux % K, aux /= K;     for (int i = 0; i < K; i++) {       for (int j = 0; j <= K; j++)         if (j != i) dp[0][i].a[j][j] = 1;       for (int j = 0; j <= K; j++) dp[0][i].a[j][i] = 1;     }     for (int i = 1; i < nr; i++) {       pref[0] = dp[i - 1][0];       for (int j = 1; j < K; j++) pref[j] = pref[j - 1] * dp[i - 1][j];       suf[K] = matrix(1);       for (int j = K - 1; j >= 0; j--) suf[j] = dp[i - 1][j] * suf[j + 1];       dp[i][0] = suf[0];       for (int j = 1; j < K; j++) dp[i][j] = suf[j] * pref[j - 1];     }     ans[K] = 1;     int curr = 0;     for (int i = nr - 1; i >= 0; i--)       while (v[i]--) Prod(dp[i][curr]), curr = (curr + 1) % K;     Finish();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[200000];   map<long long, bool> mm;   int main() {     int n, t, k, d;     cin >> n >> t >> k >> d;     int res0 = 0, res1 = 0, sum0 = 0, sum1 = 0;     while (sum0 < n) res0 += t, sum0 += k;     for (int i = 1; i <= 10000; i++) {       if (i % t == 0) sum1 += k, res1 = i;       if (sum1 >= n) break;       if (i % (d + t) == 0) sum1 += k, res1 = i;       if (sum1 >= n) break;     }     if (res1 < res0)       cout <<  YES n ;     else       cout <<  NO n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 10, mod = 1e9 + 7;   long long ans = 1, t, n, a, b, f[N];   int main() {     scanf( %lld , &n);     f[0] = f[1] = 1;     for (long long i = 2; i <= n; i++)       f[i] = (f[i - 1] + f[i - 2] * (i - 1) % mod) % mod;     for (long long i = 1; i <= n; i++) {       long long x;       scanf( %lld , &x);       if (x == 1)         a++;       else         b++;     }     for (long long i = n; i >= n - b + 1; i--) ans = (ans * i) % mod;     printf( %lld n , ans * f[a] % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s, t;   bool B1[1000001];   bool B2[1000001];   vector<int> R;   int main() {     int n;     getline(cin, s);     getline(cin, t);     int i = 0;     bool b = true;     while (i < t.size()) {       if (t[i] != s[i]) b = false;       B1[i] = b;       i++;     }     i = 0;     b = true;     while (i < t.size()) {       if (t[t.size() - i - 1] != s[s.size() - i - 1]) b = false;       B2[s.size() - i - 1] = b;       i++;     }     for (int i = 0; i < s.size() + 1; i++) {       bool b1 = true, b2 = true;       if (i > 0) b1 = B1[i - 1];       if (i + 1 < s.size()) b2 = B2[i + 1];       if (b1 && b2) R.push_back(i);     }     cout << R.size() << endl;     for (int i = 0; i < R.size(); i++) cout << R[i] + 1 <<    ;     cin >> n;   }


#include <bits/stdc++.h>   using namespace std;   char s[1000001];   int main() {     int n, v = 0;     cin >> n;     sprintf(s,  %X , n);     for (int i = 0; i < strlen(s); i++) {       if (s[i] ==  0  || s[i] ==  4  || s[i] ==  6  || s[i] ==  9  ||           s[i] ==  A  || s[i] ==  D )         v++;       else if (s[i] ==  8  || s[i] ==  B )         v += 2;     }     cout << v << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unordered_map<int, int> errors;   void get_codes(unordered_map<int, int>& quantity, int cnt, int inc) {     for (int i = 0; i < cnt; i++) {       int code;       cin >> code;       quantity[code] += inc;     }   }   int main() {     ios_base::sync_with_stdio(0);     int bugs;     cin >> bugs;     get_codes(errors, bugs, 1);     get_codes(errors, bugs - 1, -3);     for (auto it = errors.begin(); it != errors.end(); ++it) {       if ((it->second) % 2 != 0) {         cout << (it->first) <<   n ;         (it->second) -= 1;       }     }     get_codes(errors, bugs - 2, 2);     for (auto it = errors.begin(); it != errors.end(); ++it)       if ((it->second) != 0) cout << (it->first) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;   int head[10010], cnt = 1, cur[10010], dis[N], s, t;   struct edge {     int next, to, w;   } e[N << 1];   struct query {     int u, t;   } q[N];   int main() {     auto add = [&](int u, int v, int w) {       e[++cnt] = {head[u], v, w};       head[u] = cnt;     };     auto add_edge = [&](int u, int v, int w) {       add(u, v, w);       add(v, u, 0);     };     auto bfs = [&]() {       for (int i = 1; i <= t; i++) dis[i] = -1;       dis[s] = 0;       queue<int> q;       q.push(s);       while (!q.empty()) {         int u = q.front();         q.pop();         for (int i = head[u]; i; i = e[i].next) {           int v = e[i].to;           if (e[i].w && dis[v] == -1) {             dis[v] = dis[u] + 1;             q.push(v);           }         }       }       return dis[t] != -1;     };     function<int(int, int)> dfs = [&](int u, int flo) {       if (u == t) return flo;       int detla = flo;       for (int &i = cur[u]; i; i = e[i].next) {         int v = e[i].to;         if (e[i].w && dis[v] == dis[u] + 1) {           int d = dfs(v, min(detla, e[i].w));           e[i].w -= d;           e[i ^ 1].w += d;           detla -= d;           if (detla == 0) break;         }       }       return flo - detla;     };     auto dini = [&]() {       int ans = 0;       while (bfs()) memcpy(cur, head, sizeof cur), ans += dfs(s, INF);       return ans;     };     auto cal = [&](int l, int r, int k) {       int L = l - k + 5, R = r - k + 5;       return R / 5 - L / 5;     };     int n, b, Q;     scanf( %d %d %d , &n, &b, &Q);     for (int i = 1; i <= Q; i++) scanf( %d %d , &q[i].u, &q[i].t);     q[++Q] = query{0, 0};     q[++Q] = query{b, n};     sort(q + 1, q + Q + 1, [](const query a, const query b) {       return a.u == b.u ? a.t < b.t : a.u < b.u;     });     for (int i = 2; i <= Q; i++)       if ((q[i - 1].u == q[i].u && q[i - 1].t < q[i].t) || q[i - 1].t > q[i].t)         return puts( unfair );     int p = 0;     s = Q + 5 + 1, t = s + 1;     for (int i = 1; i <= Q; i++) {       add_edge(s, i, q[i].t - q[i - 1].t);       p += q[i].t - q[i - 1].t;       for (int j = 0; j < 5; j++) {         add_edge(i, Q + j + 1, cal(q[i - 1].u, q[i].u, j));       }     }     for (int i = 0; i < 5; i++) add_edge(Q + i + 1, t, n / 5);     puts(dini() == n ?  fair  :  unfair );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, string> a[3005];   int h[3005];   vector<pair<string, int> > ans;   int main() {     int n, m;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i].second >> a[i].first;     sort(a, a + n);     for (int i = 0; i < n; i++)       if (a[i].first > i) {         cout <<  -1 n ;         return 0;       }     m = h[0] = 0;     for (int i = 1; i < n; i++)       m = max(m, h[i] = h[i - 1] + (a[i].first > a[i - 1].first));     for (int i = 0; i < n; i++)       ans.insert(ans.begin() + a[i].first, make_pair(a[i].second, h[i]));     for (int i = 0; i < n; i++)       cout << ans[i].first <<     << m - ans[i].second + 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int a[3];       cin >> a[0] >> a[1] >> a[2];       sort(a, a + 3, greater<long long int>());       if (a[0] != a[1]) {         cout <<  NO               <<   n ;       } else {         cout <<  YES               <<   n ;         cout << a[0] <<     << a[2] <<     << a[2] <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long int p, pre, k, cnt;   vector<long long int> ans;   int main() {     scanf( %lld %lld , &p, &k);     if (p < k) {       printf( 1 n%lld n , p);       return 0;     }     pre = p;     while (1) {       cnt = (k - pre);       if (cnt <= 0) {         cnt = cnt / k;         cnt -= 1;       } else {         cnt = cnt / k;         if (cnt * k == (k - pre)) {           cnt -= 1;         }       }       pre = cnt;       if (pre == 0) {         printf( -1 n );         return 0;       }       ans.push_back(pre);       if (pre > 0 && pre < k) {         break;       }     }     reverse(ans.begin(), ans.end());     pre = p;     for (int i = ans.size() - 1; i >= 0; i--) {       long long int temp = ans[i] * k + pre;       pre = ans[i];       ans[i] = temp;     }     reverse(ans.begin(), ans.end());     ans.push_back(pre);     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long v1, v2;   vector<int> sz;   vector<vector<pair<int, int>>> g;   void dfs(int u, int p, int c) {     sz[u] = 1;     for (auto &e : g[u]) {       int v = e.first;       if (v == p) continue;       dfs(v, u, e.second);       sz[u] += sz[v];     }     v1 += 1LL * (sz[u] & 1) * c;     v2 += 1LL * min(sz[u], 2 * n - sz[u]) * c;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int T;     cin >> T;     while (T--) {       cin >> n;       g.assign(2 * n + 1, vector<pair<int, int>>());       for (int i = 1, a, b, c; i <= 2 * n - 1; ++i) {         cin >> a >> b >> c;         g[a].push_back({b, c});         g[b].push_back({a, c});       }       v1 = v2 = 0;       sz.assign(2 * n + 1, 0);       dfs(1, 0, 0);       cout << v1 <<     << v2 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[205], b[205];   long long dp[205][205], k;   int n, m;   char ans[205];   bool cmp(int x, int y) { return a[x] < a[y]; }   int main() {     scanf( %d%d , &n, &m);     cin >> k;     int t = n + m - 1;     for (int i = 0; i < t; i++) {       a[i] = n * m;       b[i] = i;     }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         int tmp;         scanf( %d , &tmp);         if (tmp < a[i + j]) a[i + j] = tmp;       }     sort(b, b + t, cmp);     for (int q = 0; q < t; q++) {       ans[b[q]] =  ( ;       dp[0][0] = 1;       for (int i = 0; i < t; i++)         for (int j = i & 1; j <= i && j <= t - i; j += 2)           if (dp[i][j]) {             if (dp[i][j] > k) dp[i][j] = k;             if (ans[i] !=  ) ) dp[i + 1][j + 1] += dp[i][j];             if (ans[i] !=  (  && j) dp[i + 1][j - 1] += dp[i][j];             dp[i][j] = 0;           }       if (dp[t][0] < k) {         k -= dp[t][0];         ans[b[q]] =  ) ;       }       dp[t][0] = 0;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cout.put(ans[i + j]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   const int base = 1000000000;   const int base_digits = 9;   struct bigint {     std::vector<int> z;     int sign;     bigint() : sign(1) {}     bigint(long long v) { *this = v; }     bigint(const std::string &s) { read(s); }     void operator=(const bigint &v) {       sign = v.sign;       z = v.z;     }     void operator=(long long v) {       sign = 1;       if (v < 0) sign = -1, v = -v;       z.clear();       for (; v > 0; v = v / base) z.push_back(v % base);     }     bigint operator+(const bigint &v) const {       if (sign == v.sign) {         bigint res = v;         for (int i = 0, carry = 0;              i < (int)std::max(z.size(), v.z.size()) || carry; ++i) {           if (i == (int)res.z.size()) res.z.push_back(0);           res.z[i] += carry + (i < (int)z.size() ? z[i] : 0);           carry = res.z[i] >= base;           if (carry) res.z[i] -= base;         }         return res;       }       return *this - (-v);     }     bigint operator-(const bigint &v) const {       if (sign == v.sign) {         if (abs() >= v.abs()) {           bigint res = *this;           for (int i = 0, carry = 0; i < (int)v.z.size() || carry; ++i) {             res.z[i] -= carry + (i < (int)v.z.size() ? v.z[i] : 0);             carry = res.z[i] < 0;             if (carry) res.z[i] += base;           }           res.trim();           return res;         }         return -(v - *this);       }       return *this + (-v);     }     void operator*=(int v) {       if (v < 0) sign = -sign, v = -v;       for (int i = 0, carry = 0; i < (int)z.size() || carry; ++i) {         if (i == (int)z.size()) z.push_back(0);         long long cur = z[i] * (long long)v + carry;         carry = (int)(cur / base);         z[i] = (int)(cur % base);       }       trim();     }     bigint operator*(int v) const {       bigint res = *this;       res *= v;       return res;     }     friend std::pair<bigint, bigint> divmod(const bigint &a1, const bigint &b1) {       int norm = base / (b1.z.back() + 1);       bigint a = a1.abs() * norm;       bigint b = b1.abs() * norm;       bigint q, r;       q.z.resize(a.z.size());       for (int i = a.z.size() - 1; i >= 0; i--) {         r *= base;         r += a.z[i];         int s1 = b.z.size() < r.z.size() ? r.z[b.z.size()] : 0;         int s2 = b.z.size() - 1 < r.z.size() ? r.z[b.z.size() - 1] : 0;         int d = ((long long)s1 * base + s2) / b.z.back();         r -= b * d;         while (r < 0) r += b, --d;         q.z[i] = d;       }       q.sign = a1.sign * b1.sign;       r.sign = a1.sign;       q.trim();       r.trim();       return std::make_pair(q, r / norm);     }     friend bigint sqrt(const bigint &a1) {       bigint a = a1;       while (a.z.empty() || a.z.size() % 2 == 1) a.z.push_back(0);       int n = a.z.size();       int firstDigit = (int)sqrt((double)a.z[n - 1] * base + a.z[n - 2]);       int norm = base / (firstDigit + 1);       a *= norm;       a *= norm;       while (a.z.empty() || a.z.size() % 2 == 1) a.z.push_back(0);       bigint r = (long long)a.z[n - 1] * base + a.z[n - 2];       firstDigit = (int)sqrt((double)a.z[n - 1] * base + a.z[n - 2]);       int q = firstDigit;       bigint res;       for (int j = n / 2 - 1; j >= 0; j--) {         for (;; --q) {           bigint r1 =               (r - (res * 2 * base + q) * q) * base * base +               (j > 0 ? (long long)a.z[2 * j - 1] * base + a.z[2 * j - 2] : 0);           if (r1 >= 0) {             r = r1;             break;           }         }         res *= base;         res += q;         if (j > 0) {           int d1 = res.z.size() + 2 < r.z.size() ? r.z[res.z.size() + 2] : 0;           int d2 = res.z.size() + 1 < r.z.size() ? r.z[res.z.size() + 1] : 0;           int d3 = res.z.size() < r.z.size() ? r.z[res.z.size()] : 0;           q = ((long long)d1 * base * base + (long long)d2 * base + d3) /               (firstDigit * 2);         }       }       res.trim();       return res / norm;     }     bigint operator/(const bigint &v) const { return divmod(*this, v).first; }     bigint operator%(const bigint &v) const { return divmod(*this, v).second; }     void operator/=(int v) {       if (v < 0) sign = -sign, v = -v;       for (int i = (int)z.size() - 1, rem = 0; i >= 0; --i) {         long long cur = z[i] + rem * (long long)base;         z[i] = (int)(cur / v);         rem = (int)(cur % v);       }       trim();     }     bigint operator/(int v) const {       bigint res = *this;       res /= v;       return res;     }     int operator%(int v) const {       if (v < 0) v = -v;       int m = 0;       for (int i = z.size() - 1; i >= 0; --i)         m = (z[i] + m * (long long)base) % v;       return m * sign;     }     void operator+=(const bigint &v) { *this = *this + v; }     void operator-=(const bigint &v) { *this = *this - v; }     void operator*=(const bigint &v) { *this = *this * v; }     void operator/=(const bigint &v) { *this = *this / v; }     bool operator<(const bigint &v) const {       if (sign != v.sign) return sign < v.sign;       if (z.size() != v.z.size()) return z.size() * sign < v.z.size() * v.sign;       for (int i = z.size() - 1; i >= 0; i--)         if (z[i] != v.z[i]) return z[i] * sign < v.z[i] * sign;       return false;     }     bool operator>(const bigint &v) const { return v < *this; }     bool operator<=(const bigint &v) const { return !(v < *this); }     bool operator>=(const bigint &v) const { return !(*this < v); }     bool operator==(const bigint &v) const {       return !(*this < v) && !(v < *this);     }     bool operator!=(const bigint &v) const { return *this < v || v < *this; }     void trim() {       while (!z.empty() && z.back() == 0) z.pop_back();       if (z.empty()) sign = 1;     }     bool isZero() const { return z.empty() || (z.size() == 1 && !z[0]); }     bigint operator-() const {       bigint res = *this;       res.sign = -sign;       return res;     }     bigint abs() const {       bigint res = *this;       res.sign *= res.sign;       return res;     }     long long longValue() const {       long long res = 0;       for (int i = z.size() - 1; i >= 0; i--) res = res * base + z[i];       return res * sign;     }     friend bigint gcd(const bigint &a, const bigint &b) {       return b.isZero() ? a : gcd(b, a % b);     }     friend bigint lcm(const bigint &a, const bigint &b) {       return a / gcd(a, b) * b;     }     void read(const std::string &s) {       sign = 1;       z.clear();       int pos = 0;       while (pos < (int)s.size() && (s[pos] ==  -  || s[pos] ==  + )) {         if (s[pos] ==  - ) sign = -sign;         ++pos;       }       for (int i = s.size() - 1; i >= pos; i -= base_digits) {         int x = 0;         for (int j = std::max(pos, i - base_digits + 1); j <= i; j++)           x = x * 10 + s[j] -  0 ;         z.push_back(x);       }       trim();     }     friend std::istream &operator>>(std::istream &stream, bigint &v) {       std::string s;       stream >> s;       v.read(s);       return stream;     }     friend std::ostream &operator<<(std::ostream &stream, const bigint &v) {       if (v.sign == -1) stream <<  - ;       stream << (v.z.empty() ? 0 : v.z.back());       for (int i = (int)v.z.size() - 2; i >= 0; --i)         stream << std::setw(base_digits) << std::setfill( 0 ) << v.z[i];       return stream;     }     static std::vector<int> convert_base(const std::vector<int> &a,                                          int old_digits, int new_digits) {       std::vector<long long> p(std::max(old_digits, new_digits) + 1);       p[0] = 1;       for (int i = 1; i < (int)p.size(); i++) p[i] = p[i - 1] * 10;       std::vector<int> res;       long long cur = 0;       int cur_digits = 0;       for (int i = 0; i < (int)a.size(); i++) {         cur += a[i] * p[cur_digits];         cur_digits += old_digits;         while (cur_digits >= new_digits) {           res.push_back(int(cur % p[new_digits]));           cur /= p[new_digits];           cur_digits -= new_digits;         }       }       res.push_back((int)cur);       while (!res.empty() && res.back() == 0) res.pop_back();       return res;     }     static std::vector<long long> karatsubaMultiply(         const std::vector<long long> &a, const std::vector<long long> &b) {       int n = a.size();       std::vector<long long> res(n + n);       if (n <= 32) {         for (int i = 0; i < n; i++)           for (int j = 0; j < n; j++) res[i + j] += a[i] * b[j];         return res;       }       int k = n >> 1;       std::vector<long long> a1(a.begin(), a.begin() + k);       std::vector<long long> a2(a.begin() + k, a.end());       std::vector<long long> b1(b.begin(), b.begin() + k);       std::vector<long long> b2(b.begin() + k, b.end());       std::vector<long long> a1b1 = karatsubaMultiply(a1, b1);       std::vector<long long> a2b2 = karatsubaMultiply(a2, b2);       for (int i = 0; i < k; i++) a2[i] += a1[i];       for (int i = 0; i < k; i++) b2[i] += b1[i];       std::vector<long long> r = karatsubaMultiply(a2, b2);       for (int i = 0; i < (int)a1b1.size(); i++) r[i] -= a1b1[i];       for (int i = 0; i < (int)a2b2.size(); i++) r[i] -= a2b2[i];       for (int i = 0; i < (int)r.size(); i++) res[i + k] += r[i];       for (int i = 0; i < (int)a1b1.size(); i++) res[i] += a1b1[i];       for (int i = 0; i < (int)a2b2.size(); i++) res[i + n] += a2b2[i];       return res;     }     bigint operator*(const bigint &v) const {       std::vector<int> a6 = convert_base(this->z, base_digits, 6);       std::vector<int> b6 = convert_base(v.z, base_digits, 6);       std::vector<long long> a(a6.begin(), a6.end());       std::vector<long long> b(b6.begin(), b6.end());       while (a.size() < b.size()) a.push_back(0);       while (b.size() < a.size()) b.push_back(0);       while (a.size() & (a.size() - 1)) a.push_back(0), b.push_back(0);       std::vector<long long> c = karatsubaMultiply(a, b);       bigint res;       res.sign = sign * v.sign;       for (int i = 0, carry = 0; i < (int)c.size(); i++) {         long long cur = c[i] + carry;         res.z.push_back((int)(cur % 1000000));         carry = (int)(cur / 1000000);       }       res.z = convert_base(res.z, 6, base_digits);       res.trim();       return res;     }   };   bigint lastans;   const int maxn = 6e5 + 222;   const int mask = (1 << 30);   using ll = long long;   int q, s[maxn], nxt[maxn], pre[maxn], w[maxn];   std::map<int, int> cnt;   std::vector<int> stk;   char t[10];   ll sum = 0;   int query(int x) { return w[*std::lower_bound(stk.begin(), stk.end(), x)]; }   int main() {     scanf( %d , &q);     scanf( %s%d , t + 1, &w[1]);     s[1] = t[1] -  a ;     lastans = w[1];     stk.push_back(1);     std::cout << lastans <<   n ;     for (int n = 2, j = 0; n <= q; ++n) {       scanf( %s%d , t + 1, &w[n]);       int c = (lastans + t[1] -  a ) % 26;       s[n] = c;       w[n] = w[n] ^ (lastans % mask);       while (j && s[j + 1] != s[n]) j = nxt[j];       if (s[j + 1] == s[n]) j++;       nxt[n] = j;       if (s[nxt[n - 1] + 1] == s[n])         pre[n - 1] = pre[nxt[n - 1]];       else         pre[n - 1] = nxt[n - 1];       int x = nxt[n - 1];       while (x) {         if (s[x + 1] == s[n])           x = pre[x];         else {           int w = query(n - x);           cnt[w]--;           sum -= w;           x = nxt[x];         }       }       while (stk.size() && w[stk.back()] >= w[n]) stk.pop_back();       stk.push_back(n);       int cw = 0;       for (auto it = cnt.upper_bound(w[n]); it != cnt.end();) {         sum -= (ll)it->second * (it->first - w[n]);         cw += it->second;         auto nw = std::next(it);         cnt.erase(it);         it = nw;       }       cnt[w[n]] += cw;       if (s[1] == s[n]) {         cnt[w[n]]++;         sum += w[n];       }       lastans += sum + w[stk[0]];       std::cout << lastans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nmax = 16, MX = 16 * 2000 + 42;   int n, k, inp[nmax];   int outp[nmax];   void print() {     vector<pair<int, int> > active;     cout <<  YES  << endl;     for (int i = 0; i < n; i++) active.push_back({inp[i], outp[i]});     for (int t = 1; t < n; t++) {       for (int i = 0; i < active.size(); i++)         for (int j = i + 1; j < active.size(); j++)           if (active[i].second == active[j].second) {             cout << active[i].first <<     << active[j].first << endl;             active[i].first += active[j].first;             while (active[i].first % k == 0) {               active[i].first = active[i].first / k;               active[i].second--;             }             active.erase(active.begin() + j, active.begin() + j + 1);             i = n;             j = n;           }     }     exit(0);   }   bitset<MX> on[1 << nmax];   int sum[1 << nmax];   void go(int aim, int deg, int mask) {     if (aim == 0 && mask == 0) print();     if (aim > sum[mask] || aim < 0) return;     if (on[mask][aim]) return;     on[mask][aim] = 1;     go(aim * k, deg + 1, mask);     for (int i = 0; i < n; i++)       if ((mask & (1 << i))) {         outp[i] = deg;         go(aim - inp[i], deg, mask - (1 << i));       }   }   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> inp[i];     for (int mask = 0; mask < (1 << n); mask++)       for (int i = 0; i < n; i++)         if ((mask & (1 << i))) sum[mask] += inp[i];     go(1, 0, (1 << n) - 1);     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v[2000006], pp[2000006];   long long first[2000006], cur = 0, w[2000006], n, m, i, xx, second, d, h, ans,                             w1, p, tt, o, temp, t;   void dfs(long long node, long long l) {     if (node > n) return;     long long i, j;     first[node] = l;     v[node].push_back(l);     dfs(2 * node, l + w[2 * node]);     dfs(2 * node + 1, l + w[2 * node + 1]);     for (j = 0; j < v[2 * node].size(); ++j) v[node].push_back(v[2 * node][j]);     for (j = 0; j < v[2 * node + 1].size(); ++j)       v[node].push_back(v[2 * node + 1][j]);     sort(v[node].begin(), v[node].end());     pp[node].resize(v[node].size());     pp[node][0] = v[node][0];     for (i = 1; i < v[node].size(); ++i)       pp[node][i] = v[node][i] + pp[node][i - 1];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (i = 2; i <= n; ++i) cin >> w[i];     dfs(1, 0);     for (i = 0; i < m; ++i) {       ans = 0;       cin >> d >> h;       t = upper_bound(v[d].begin(), v[d].end(), h + first[d]) - v[d].begin();       if (t) ans = (h + first[d]) * t - pp[d][t - 1];       while (d != 1) {         w1 = w[d];         p = d / 2;         if (h > w1) ans += h - w1;         o = d - (d % 2) + !(d % 2);         if (o <= n) {           temp = h - (w[o] + w1) + first[o];           tt = upper_bound(v[o].begin(), v[o].end(), temp) - v[o].begin();           if (tt) ans += tt * temp - pp[o][tt - 1];         }         h -= w[d];         d >>= 1;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   map<int, long long> ans;   inline long long go(int n) {     if (ans.find(n) != ans.end()) return ans[n];     long long cur = n + 1;     for (int i = 2; i * i <= n; ++i) {       if (n % i == 0) {         cur = max(cur, n + go(i));         cur = max(cur, n + go(n / i));       }     }     return ans[n] = cur;   }   int main() {     cin >> n;     ans[1] = 1;     cout << go(n) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, d;   bool ck[100005];   vector<int> adj[100005];   int dep[100005], ans;   void dfs(int u, int p) {     dep[u] = (ck[u] ? 0 : -(1 << 20));     for (int i = 0; i < adj[u].size(); ++i) {       int v = adj[u][i];       if (v == p) continue;       dfs(v, u);       if (dep[v] != -(1 << 20)) dep[u] = max(dep[u], dep[v] + 1);     }   }   void get(int u, int p, int bef) {     if (ck[u]) bef = max(0, bef);     ans += (bef <= d && dep[u] <= d);     int m1 = -1, m2 = -1, c1 = 0;     for (int i = 0; i < adj[u].size(); ++i) {       int v = adj[u][i];       if (v == p) continue;       int dd = dep[v] + 1;       if (dd > m1)         m2 = m1, m1 = dd;       else if (dd > m2)         m2 = dd;     }     for (int i = 0; i < adj[u].size(); ++i) {       int v = adj[u][i];       if (v == p) continue;       int dd = dep[v] + 1;       if (dd == m1) c1++;     }     for (int i = 0; i < adj[u].size(); ++i) {       int v = adj[u][i];       if (v == p) continue;       int dd = dep[v] + 1;       if (dd == m1) {         if (c1 > 1)           get(v, u, max(bef + 1, m1 + 1));         else if (m2 != -1)           get(v, u, max(bef + 1, m2 + 1));         else           get(v, u, bef + 1);       } else         get(v, u, max(bef + 1, m1 + 1));     }   }   int main() {     scanf( %d%d%d , &n, &m, &d);     for (int i = 0; i < m; ++i) {       int u;       scanf( %d , &u), u--;       ck[u] = 1;     }     for (int i = 0; i < n - 1; ++i) {       int u, v;       scanf( %d%d , &u, &v), u--, v--;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(0, -1), get(0, -1, ck[0] ? 0 : -(1 << 20));     printf( %d , ans);   }


#include<bits/stdc++.h>   #define ll long long   using namespace std;      int x[100005];   int idx=0;   int d[100005];   int main()   {       int t;       cin>>t;       while(t--){           int n;           cin>>n;           idx=0;           for(int i=1;i<=n;i++){               scanf( %d ,&x[i]);           }           for(int i=n;i>=1;i--){               if(idx==0){                   d[++idx]=i;               }               else{                   while(idx>0&&x[i]>x[d[idx]]){                       idx--;                   }                   d[++idx]=i;               }           }           for(int i=1;i<=idx;i++){               int ma;               if(i==1) ma=n+1;               else ma=d[i-1];               for(int j=d[i];j<ma;j++){                   cout<<x[j]<<   ;               }           }           cout<<endl;       }       return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (T i : v) os << i <<  ,  ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, const set<T> &v) {     for (T i : v) os << i <<    ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, const multiset<T> &v) {     for (T i : v) os << i <<    ;     return os;   }   template <class T, class second>   ostream &operator<<(ostream &os, const pair<T, second> &v) {     os << v.first <<     << v.second;     return os;   }   template <class T, class second>   ostream &operator<<(ostream &os, const map<T, second> &v) {     for (auto i : v) os <<  (  << i.first <<   =>   << i.second <<  )  <<    ;     return os;   }   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   void f1(string &s) {     int n = s.length() + 1;     vector<int> ans(n);     int pos = 0, c = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  > ) pos = i + 1;     }     ans[pos] = ++c;     if (pos > 1) {       for (int i = pos - 2; i >= 0; i--) {         if (s[i] ==  > ) {           ans[i + 1] = ++c;           if (i == 0) ans[i] = ++c;         }       }     }     set<int> to_do;     while (c < n) to_do.insert(++c);     for (int i = 1; i < n; i++) {       if (s[i - 1] ==  >  || ans[i] != 0) continue;       int c = i;       while (c < n && s[c - 1] ==  < ) c++;       c--;       while (c >= i) {         ans[c] = *to_do.rbegin();         to_do.erase(--to_do.end());         c--;       }     }     for (int i = 0; i < n; i++)       if (ans[i] == 0) {         ans[i] = *to_do.rbegin();         to_do.erase(--to_do.end());       }     for (int i : ans) cout << i <<    ;     cout <<   n ;   }   void f2(string &s) {     int n = s.length() + 1;     vector<int> ans(n);     reverse(s.begin(), s.end());     int pos = 0, c = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  < ) pos = i + 1;     }     ans[pos] = ++c;     if (pos > 1) {       for (int i = pos - 2; i >= 0; i--) {         if (s[i] ==  < ) {           ans[i + 1] = ++c;         }       }     }     c = n;     for (int i = n - 1; i >= 0; i--)       if (ans[i] == 0) ans[i] = c--;     reverse(ans.begin(), ans.end());     for (int i : ans) cout << i <<    ;     cout <<   n ;   }   void solve() {     int n;     cin >> n;     string s;     cin >> s;     f1(s);     f2(s);   }   int main() {     fast();     int t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 10;   const int maxm = 100 + 10;   const int inf = 0x3f;   long long f[maxm][maxn], D[maxn], H[maxn], T[maxn], q[maxn];   long long g[maxn];   int N, M, P;   long long A[maxn], S[maxn];   void init() {     sort(A + 1, A + 1 + M);     for (int i = (1); i <= (M); i++) {       S[i] = S[i - 1] + A[i];     }     memset(f, inf, sizeof(f));     memset(g, 0, sizeof(g));     memset(q, 0, sizeof(q));     f[0][0] = 0;   }   void solve() {     for (int i = (1); i <= (P); i++) {       for (int k = (1); k <= (M); k++) g[k] = f[i - 1][k] + S[k];       int l = 1, r = 1;       q[1] = 0;       for (int j = (1); j <= (M); j++) {         while (l < r && (g[q[l + 1]] - g[q[l]]) <= (A[j] * (q[l + 1] - q[l])))           l++;         f[i][j] = min(f[i - 1][j], g[q[l]] + A[j] * (j - q[l]) - S[j]);         while (l < r && ((g[q[r]] - g[q[r - 1]]) * (j - q[r]) >=                          (g[j] - g[q[r]]) * (q[r] - q[r - 1])))           r--;         q[++r] = j;       }     }     cout << f[P][M] << endl;   }   int main() {     cin >> N >> M >> P;     for (int i = (2); i <= (N); i++) {       int x;       scanf( %d , &x);       D[i] = D[i - 1] + x;     }     for (int i = (1); i <= (M); i++) {       int h, t;       scanf( %d%d , &h, &t);       A[i] = t - D[h];     }     init();     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5, M = 1e9 + 7;   const unsigned long long base = 13331;   const double Pi = acos(-1.0);   const long long C = 299792458;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   char a[505][505];   int n, m;   bool check() {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (a[i][j] ==  * ) {           if (i - 1 < 1 || i + 1 > n || j - 1 < 1 || j + 1 > m) continue;           if (a[i - 1][j] ==  *  && a[i + 1][j] ==  *  && a[i][j - 1] ==  *  &&               a[i][j + 1] ==  * ) {             a[i][j] =  . ;             for (int k = i - 1; k >= 1; k--) {               if (a[k][j] ==  * )                 a[k][j] =  . ;               else                 break;             }             for (int k = i + 1; k <= n; k++) {               if (a[k][j] ==  * )                 a[k][j] =  . ;               else                 break;             }             for (int k = j - 1; k >= 1; k--) {               if (a[i][k] ==  * )                 a[i][k] =  . ;               else                 break;             }             for (int k = j + 1; k <= m; k++) {               if (a[i][k] ==  * )                 a[i][k] =  . ;               else                 break;             }             return true;           }         }       }     }     return false;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> a[i][j];       }     }     if (!check()) {       cout <<  NO  << endl;     } else {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           if (a[i][j] ==  * ) {             cout <<  NO  << endl;             return 0;           }         }       }       cout <<  YES  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 25;   inline int getDis(pair<int, int> a, pair<int, int> b) {     return (b.first - a.first) * (b.first - a.first) +            (b.second - a.second) * (b.second - a.second);   }   pair<int, int> G[maxn];   int dp[1 << maxn];   int dis[maxn][maxn], route[1 << maxn];   int n;   int main() {     scanf( %d%d , &G[0].first, &G[0].second);     scanf( %d , &n);     for (register int i = 1; i <= n; i++)       scanf( %d%d , &G[i].first, &G[i].second);     for (register int i = 0; i <= n; i++)       for (register int j = i; j <= n; j++)         dis[i][j] = dis[j][i] = getDis(G[i], G[j]);     memset(route, -1, sizeof route);     for (register int i = 0; i < (1 << maxn); i++) dp[i] = 0x3f3f3f3f;     dp[0] = 0;     for (register int i = 0; i < (1ll << n); i++) {       if (dp[i] == 0x3f3f3f3f) continue;       for (register int j = 1; j <= n; j++) {         if (i & (1ll << (j - 1))) continue;         for (register int k = 1; k <= n; k++) {           if (i & (1ll << (k - 1))) continue;           if (dp[i] + dis[0][j] + dis[j][k] + dis[k][0] <               dp[i | (1ll << (j - 1)) | (1ll << (k - 1))]) {             route[i | (1ll << (j - 1) | (1ll << (k - 1)))] = i;             dp[i | (1ll << (j - 1)) | (1ll << (k - 1))] =                 min(dp[i | (1ll << (j - 1)) | (1ll << (k - 1))],                     dp[i] + dis[0][j] + dis[j][k] + dis[k][0]);           }         }         break;       }     }     printf( %d n , dp[(1 << n) - 1]);     int now = (1 << n) - 1, last = -1;     printf( 0  );     while (true) {       if (last == -1) {         last = now;         now = route[now];         continue;       } else {         int change = now ^ last;         for (register int i = 1; i <= n; i++) {           if (change & (1ll << (i - 1))) {             printf( %d  , i);           }         }         last = now;         now = route[now];         if (now == -1) {           for (register int i = 1; i <= n; i++) {             if (last & (1 << (i - 1))) {               printf( %d  , i);             }           }           break;         }       }       printf( 0  );     }     printf( 0 );     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4786)   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;   const double PI = acos(-1.0);   const double eps = 1e-6;   const int maxn = 2e5 + 5;   int isu[maxn], sz[maxn], dis[maxn], kk;   long long ans;   vector<int> G[maxn];   void dfs1(int root, int fa, long long depth) {     int siz = G[root].size(), nt;     dis[root] = depth;     if (isu[root]) {       sz[root] = 1;       ans += depth;     }     for (int i = 0; i < siz; i++) {       nt = G[root][i];       if (nt == fa) continue;       dfs1(nt, root, depth + 1LL);       sz[root] += sz[nt];     }   }   void solve(int root, int fa) {     if (kk <= 0) return;     priority_queue<pair<int, int> > Q;     int siz = G[root].size(), nt;     for (int i = 0; i < siz; i++) {       nt = G[root][i];       if (nt == fa) continue;       if (sz[nt] > 0) {         Q.push(make_pair(sz[nt], nt));       }     }     if (isu[root]) {       Q.push(make_pair(1, root));     }     pair<int, int> f1 = Q.top(), f2;     int fir = f1.first, sec = f1.second, sum = 0;     if (Q.size() == 1) {       solve(sec, root);     } else {       Q.pop();       while (!Q.empty()) {         f2 = Q.top();         Q.pop();         sum += f2.first;       }       sum = min(sum, kk);       kk -= sum;       ans -= 2LL * dis[root] * sum;       if (kk > 0) solve(sec, root);     }   }   int main() {     int n, k, x, y;     scanf( %d %d , &n, &k);     kk = k;     for (int i = 1; i <= 2 * k; i++) {       scanf( %d , &x);       isu[x] = 1;     }     for (int i = 1; i < n; i++) {       scanf( %d %d , &x, &y);       G[x].push_back(y);       G[y].push_back(x);     }     ans = 0;     dfs1(1, 0, 0);     solve(1, 0);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, i;     cin >> n;     long long int arr1[n];     for (i = 0; i < n; i++) cin >> arr1[i];     cin >> m;     long long int arr2[m];     for (i = 0; i < m; i++) cin >> arr2[i];     sort(arr1, arr1 + n);     sort(arr2, arr2 + m);     cout << arr1[n - 1] <<     << arr2[m - 1];   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, n, a, b, c, ret = 0, t;     scanf( %d %d %d %d , &n, &a, &b, &c);     n *= 10;     for (i = 0; i <= a; i++)       for (j = 0; j <= b; j++) {         t = (i * 5);         t += (j * 10);         if (n - t < 0) continue;         if ((n - t) % 20 == 0 && (n - t) / 20 <= c) ret++;       }     printf( %d n , ret);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long parse(string s) {     long long k = 1, ret = 0;     for (int i = 0; i < s.size(); i++)       ret += k * (long long)(s[s.size() - i - 1] -  0 ), k *= 4;     return ret;   }   string change(string s) {     string ret = s;     for (int i = 0; i < ret.size(); i++) {       if (ret[i] ==  1 )         ret[i] =  2 ;       else if (ret[i] ==  2 )         ret[i] =  3 ;       else if (ret[i] ==  3 )         ret[i] =  1 ;     }     return ret;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long idx = (n + 2) / 3, m = n % 3;       long long k = 0, sum = 0;       while (sum < idx) sum += (1ll << (2 * k)), k++;       k--;       long long buf = (1ll << (2 * k)), c = sum - buf + 1;       string ans =  1 ;       for (int i = k - 1; i >= 0; i--) {         long long div = (1ll << (2 * i));         long long d = (idx - c) / div;         ans += (char)( 0  + d);         c += div * d;       }       long long f = parse(ans);       long long s = parse(change(ans));       if (m == 1)         cout << f <<   n ;       else if (m == 2)         cout << s <<   n ;       else         cout << (f ^ s) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   inline void sub(long long &a, long long b) {     a -= b;     if (a < 0) a += 1000000007;   }   inline void add(long long &a, long long b) {     a += b;     if (a >= 1000000007) a -= 1000000007;   }   template <typename T>   inline T const &MAX(T const &a, T const &b) {     return a > b ? a : b;   }   template <typename T>   inline T const &MIN(T const &a, T const &b) {     return a < b ? a : b;   }   inline long long qp(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % 1000000007;       a = a * a % 1000000007, b >>= 1;     }     return ans;   }   inline long long qp(long long a, long long b, long long c) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % c;       a = a * a % c, b >>= 1;     }     return ans;   }   using namespace std;   const unsigned long long ba = 233;   const double eps = 1e-6;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const int N = 100000 + 10, maxn = 1000000 + 10, inf = 0x3f3f3f3f;   long long h[N], a[N];   int cnt, pre[N];   struct sgt {     pair<int, int> ma[N << 2];     void update(int pos, pair<int, int> v, int l, int r, int rt) {       if (l == r) {         ma[rt] = v;         return;       }       int m = (l + r) >> 1;       if (pos <= m)         update(pos, v, l, m, rt << 1);       else         update(pos, v, m + 1, r, rt << 1 | 1);       ma[rt] = max(ma[rt << 1], ma[rt << 1 | 1]);     }     pair<int, int> query(int L, int R, int l, int r, int rt) {       if (L <= l && r <= R) return ma[rt];       int m = (l + r) >> 1;       pair<int, int> ans = make_pair(0, 0);       if (L <= m) ans = max(ans, query(L, R, l, m, rt << 1));       if (m < R) ans = max(ans, query(L, R, m + 1, r, rt << 1 | 1));       return ans;     }   } sg;   int main() {     int n, d;     scanf( %d%d , &n, &d);     for (int i = 1; i <= n; i++) {       scanf( %lld , &h[i]);       a[cnt++] = h[i];     }     sort(a, a + cnt);     cnt = unique(a, a + cnt) - a;     for (int i = 1; i <= n; i++) {       pair<int, int> x = make_pair(0, 0), y;       int p = upper_bound(a, a + cnt, h[i] - d) - a;       p--;       if (p >= 0) x = max(x, sg.query(1, p + 1, 1, cnt, 1));       p = lower_bound(a, a + cnt, h[i] + d) - a;       if (p < cnt) x = max(x, sg.query(p + 1, cnt, 1, cnt, 1));       p = lower_bound(a, a + cnt, h[i]) - a;       y = sg.query(p + 1, p + 1, 1, cnt, 1);       if (x.first + 1 > y.first) {         sg.update(p + 1, make_pair(x.first + 1, i), 1, cnt, 1);         pre[i] = x.second;       }     }     pair<int, int> x = sg.query(1, cnt, 1, cnt, 1);     printf( %d n , x.first);     stack<int> st;     for (int now = x.second; now != 0; now = pre[now]) st.push(now);     while (!st.empty()) printf( %d  , st.top()), st.pop();     return 0;   }


#include <bits/stdc++.h>   const int N = 1e5 + 10;   const int MOD = 1e9 + 7;   const int INF = 2e9;   const long long INFLL = 1e18;   const double PI = acos((double)-1);   inline int mult(int a, int b, int p = MOD) { return (1ll * a * b) % p; }   inline int add(int a, int b, int p = MOD) { return (1ll * a + b) % p; }   inline int fpow(long long n, long long k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }   using namespace std;   int main() {     ios::sync_with_stdio(false);     string s;     cin >> s;     int n = s.length();     int x = 0, y = 0;     int ans = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  - ) {         y++;         if (x > 0)           x--;         else           ans++;       } else {         x++;         if (y > 0)           y--;         else           ans++;       }     }     cout << ans;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int in() {     int x;     scanf( %d , &x);     return x;   }   int main() {     ios::sync_with_stdio(false);     long long k, d, t;     cin >> k >> d >> t;     t *= 2;     long long p = (k + d - 1) / d * d;     long double res = t / (p + k) * p;     t %= (p + k);     if (t > 2 * k) {       res += k;       t -= 2 * k;       res += t;     } else       res += (long double)t / 2;     cout << setprecision(10) << fixed << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   double arr[550];   int m;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> arr[i];     double ans = 0;     for (int i = 1; i <= m; i++) {       int u, v;       double w;       cin >> u >> v;       cin >> w;       double rr = (arr[u] + arr[v]) / w;       if (rr > ans) ans = rr;     }     printf( %.9lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   const long double PI = acos(-1.0);   long long diff[200010];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     ;     int T, j, t, i, buckN = 1;     int N = 1;     scanf( %d , &T);     long long sum = 0, a, x, lE = 0;     while (T--) {       scanf( %d , &t);       if (t == 1) {         scanf( %lld%lld , &a, &x);         sum += a * x;         diff[a] -= x;         if (a == N) {           diff[a] += x;           lE += x;         }       } else if (t == 2) {         scanf( %lld , &a);         diff[N] = a - lE;         lE = a;         N++;         sum += a;       } else {         sum -= lE;         --N;         lE -= diff[N];         diff[N] = 0;       }       printf( %.10f n , (1.0 * sum) / N);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int fir[201], tot, in[201], In[201];   int nxt[400201], to[400201];   inline void add_edge(int u, int v) {     to[++tot] = v;     nxt[tot] = fir[u];     fir[u] = tot;   }   int n, c[201], cc[4][201];   queue<int> q[5];   inline int solve(int x) {     int ans = 0;     for (register int i = 1; i <= 3; i++) {       for (register int j = 1; j <= cc[i][0]; j++) {         if (!in[cc[i][j]]) q[i].push(cc[i][j]);       }     }     int now = x - 1;     while (1) {       now++;       if (now == 4) now = 1;       while (!q[now].empty()) {         ans++;         int u = q[now].front();         q[now].pop();         for (register int i = fir[u]; i; i = nxt[i]) {           int v = to[i];           in[v]--;           if (!in[v]) {             q[c[v]].push(v);           }         }       }       if (q[1].empty() && q[2].empty() && q[3].empty()) return ans;       ans++;     }   }   int main() {     scanf( %d , &n);     for (register int i = 1; i <= n; i++) {       scanf( %d , c + i);       cc[c[i]][++cc[c[i]][0]] = i;     }     for (register int i = 1; i <= n; i++) {       int sze = 0, tmp = 0;       scanf( %d , &sze);       for (register int j = 1; j <= sze; j++) {         scanf( %d , &tmp);         add_edge(tmp, i);         In[i]++;         in[i]++;       }     }     int ans = 0x7fffffff;     ans = min(ans, solve(1));     for (register int i = 1; i <= n; i++) in[i] = In[i];     ans = min(ans, solve(2));     for (register int i = 1; i <= n; i++) in[i] = In[i];     ans = min(ans, solve(3));     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   const int inf = 0x3f3f3f3f;   int main() {     long long n, m, k, p[maxn], ans = 0, sub = 0;     cin >> n >> m >> k;     for (int i = 1; i <= m; i++) {       scanf( %lld , &p[i]);       p[i]--;     }     for (int i = 1; i <= m; i++) {       long long now = (p[i] - sub) / k;       for (int j = 1;; j++) {         long long a = (p[i + j] - sub) / k;         if (i + j > m || a != now) {           sub += j;           i += j - 1;           ans++;           break;         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1 * 1000 + 10;   int ans[MAXN][MAXN];   int main() {     ios::sync_with_stdio(false);     int n, d, k;     cin >> n;     vector<int> a(n), b(n);     for (int i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(a.begin(), a.end(), [&](int a, int b) { return a <= b; });     int ct = 0;     for (int i = 0; i < n; i++) ct = (a[i] == b[i]) ? ct : ct + 1;     if (ct == 0 || ct == 2)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int dp[2010][2010], a[2010];   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     int n, i, j, ans, mn, cnt;     scanf( %d , &n);     cnt = 0;     for (i = 0; i < n; i++) {       scanf( %d , a + i);       if (a[i] == 1) cnt++;     }     if (cnt) {       ans = n - cnt;     } else {       mn = 0x3fffffff;       for (i = 0; i < n; i++) {         for (j = i; j < n; j++) {           dp[i][j] = (i == j ? a[i] : gcd(dp[i][j - 1], a[j]));           if (dp[i][j] == 1) mn = min(mn, j - i);         }       }       if (mn == 0x3fffffff)         ans = -1;       else         ans = mn + n - 1;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[1000005];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);     }     sort(a + 1, a + 1 + n);     int x = 1;     int y = n;     long long ans = 0;     while (x < y) {       ans += abs(a[y] - a[x]) * 2;       x += m;       y -= m;     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   const int inf = 1e9 + 7;   const int mod = 998244353;   namespace __________ {   namespace _in {   template <class T>   inline T read() {     char ch;     bool flag = 0;     T x = 0;     while (ch = getchar(), !isdigit(ch))       if (ch ==  - ) flag = 1;     while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();     return flag ? -x : x;   }   struct {     inline operator long long() { return read<long long>(); }     inline operator int() { return read<int>(); }     inline operator bool() { return read<bool>(); }     template <class T>     inline void operator()(T &x) {       x = *this;     }     template <class T, class... A>     inline void operator()(T &x, A &...a) {       x = *this, this->operator()(a...);     }   } IN;   }  // namespace _in   namespace _std {   template <class T>   inline T abs(T x) {     if (x < 0) x = -x;     return x;   }   template <class T>   inline T max(T x, T y) {     if (x < y) x = y;     return x;   }   template <class T>   inline T min(T x, T y) {     if (x > y) x = y;     return x;   }   template <class T>   inline void swap(T &x, T &y) {     x ^= y ^= x ^= y;   }   template <class T>   inline void chkmax(T &x, T y) {     if (x < y) x = y;   }   template <class T>   inline void chkmin(T &x, T y) {     if (x > y) x = y;   }   }  // namespace _std   namespace _mod {   inline int mul(int x, int y) { return 1ll * x * y % mod; }   inline int dec(int x, int y) {     x -= y;     if (x < 0) x += mod;     return x;   }   inline int add(int x, int y) {     x += y;     if (x >= mod) x -= mod;     return x;   }   inline void pls(int &x, int y) {     x += y;     if (x >= mod) x -= mod;   }   inline void sub(int &x, int y) {     x -= y;     if (x < 0) x += mod;   }   inline int modpow(int x, int y, int res = 1) {     if (y == -1) y = mod - 2;     for (; y; y >>= 1, x = mul(x, x))       if (y & 1) res = mul(res, x);     return res;   }   }  // namespace _mod   using namespace _in;   using namespace _std;   using namespace _mod;   }  // namespace __________   using namespace __________;   const int N = 2e3 + 5;   int n, k, L[N], R[N], a[N];   long long dp[N], sum;   inline void calc(int &tot, int p, int &tim) {     int _, a = ::a[p], L = ::L[p];     if (a <= tot)       tot -= a, tim = L;     else       _ = a - tot, tot = (k - (_ % k)) % k, tim = L + (_ / k - (_ % k == 0)) + 1;   }   inline void solve() {     IN(n, k);     for (int i = 1; i <= n; ++i) IN(L[i], R[i], a[i]), sum += a[i];     dp[n + 1] = 0;     for (int i = n; i >= 1; --i) {       dp[i] = 1e18;       int tot = k, tim;       for (int j = i; j <= n; ++j) {         calc(tot, j, tim);         if (tim > R[j]) break;         if (j == n) dp[i] = 0;         if (L[j + 1] > tim) chkmin(dp[i], dp[j + 1] + tot);       }     }     printf( %lld n , dp[1] > 1e14 ? -1 : dp[1] + sum);   }   int main() {     int T = 1;     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long T, N, M;     cin >> T;     while (T--) {       cin >> N >> M;       N /= M;       long long Sum = 0, Ans = 0;       long long digits[20];       for (int i = 1; i <= 10; i++) Sum += (digits[i] = (i * M % 10));       for (int i = 1; i <= N % 10; i++) Ans += digits[i];       Ans += N / 10 * Sum;       cout << Ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   const int NINF = -INF - 1;   const int N = 2e5 + 5;   using namespace std;   char a[N];   int c[N];   int b[26];   int main() {     int n, ans = 0, maxn = -1000000;     scanf( %d , &n);     scanf( %s , a);     for (int i = 0; i < n; i++) {       ans = 1;       for (int j = a[i] -  a  + 1; j < 26; j++) {         ans = max(ans, b[j] + 1);       }       b[a[i] -  a ] = ans;       c[i] = ans;       maxn = max(maxn, c[i]);     }     cout << maxn << endl;     for (int i = 0; i < n; i++) printf( %d  , c[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, finall = 0, t1 = 0;     vector<string> v;     cin >> n;     int cop = n;     while (n--) {       string s;       cin >> s;       v.push_back(s);     }     for (int j = 0; j < 7; j++) {       t1 = 0;       for (int k = 0; k < cop; k++) t1 += v[k][j] -  0 ;       if (t1 > finall) finall = t1;     }     cout << finall;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f, N = 2e5 + 5;   inline int read() {     int sum = 0, f = 1;     char c = getchar();     while (c >  9  || c <  0 ) {       if (c ==  - ) f = -f;       c = getchar();     }     while (c >=  0  && c <=  9 ) sum = sum * 10 + c - 48, c = getchar();     return sum * f;   }   int n, d, x[N], minn = INF;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> d;     for (int i = 1; i <= n; i++) cin >> x[i];     for (int i = 1; i <= 100; i++) {       int j = i + d, cnt = 0;       for (int k = 1; k <= n; k++) {         if (x[k] < i || x[k] > j) cnt++;       }       minn = min(minn, cnt);       ;     }     cout << minn <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   void yes() {     cout <<  Yes           <<   n ;   }   void no() {     cout <<  No           <<   n ;   }   struct Sync_stdio {     Sync_stdio() {       cin.tie(NULL);       ios_base::sync_with_stdio(false);     }   } _sync_stdio;   struct FAIL {     FAIL() {       cout <<  CHANGE!!!             <<   n ;     }   };   class BipartiteMatching {    public:     struct Edge {       int first_part_vertex;       int second_part_vertex;     };     struct Vertex {       int vertex_id;       int part;     };     BipartiteMatching(int size_first_, int size_second_)         : size_first(size_first_), size_second(size_second_), graph(size_first) {}     void add_edge(int first_part_vertex, int second_part_vertex) {       graph[first_part_vertex].push_back(second_part_vertex);     }     vector<Edge> find_matching() {       if (!calculated_matching) {         calculate_matching();       }       vector<Edge> answer;       for (int i = 0; i < size_second; ++i) {         if (mt[i] != -1) {           answer.push_back({mt[i], i});         }       }       return answer;     }     vector<Vertex> find_minimum_vertex_cover() {       if (!calculated_matching) {         calculate_matching();       }       cerr <<  Doesn t work             <<   n ;       return {};     }       private:     bool try_kuhn(int vertex) {       if (used[vertex]) {         return false;       }       used[vertex] = true;       for (int to : graph[vertex]) {         if (mt[to] == -1 || try_kuhn(mt[to])) {           mt[to] = vertex;           return true;         }       }       return false;     }     void calculate_matching() {       mt.assign(size_second, -1);       for (int i = 0; i < size_first; ++i) {         used.assign(size_first, false);         try_kuhn(i);       }       calculated_matching = true;     }     int size_first, size_second;     int calculated_matching = false;     vector<vector<int>> graph;     vector<int> mt;     vector<char> used;   };   bool can(int n, int m) {     BipartiteMatching matching(n * m, n * m);     for (int i1 = (0); i1 < (n); ++i1) {       for (int j1 = (0); j1 < (m); ++j1) {         for (int i2 = (0); i2 < (n); ++i2) {           for (int j2 = (0); j2 < (m); ++j2) {             if ((i1 + j1) % 2 && abs(i1 - i2) + abs(j1 - j2) == 3) {               matching.add_edge(i1 * m + j1, i2 * m + j2);             }           }         }       }     }     return matching.find_matching().size() == n * m / 2;   }   void build_table(int n, int m) {     vector<vector<int>> ans(n, vector<int>(m));     for (int i = (0); i < (n); ++i) {       for (int j = (0); j < (m); ++j) {         ans[i][j] = can(i + 1, j + 1);       }     }     for (int i = (0); i < (n); ++i) {       for (int j = (0); j < (m); ++j) {         cout << ans[i][j];       }       cout <<   n ;     }   }   int main() {     long long n, m;     cin >> n >> m;     if (n > m) {       swap(n, m);     }     if (n >= 3) {       cout << n * m / 2 * 2;       return 0;     }     if (n == 2) {       if (m == 7) {         cout << 12;       } else if (m >= 4) {         cout << n * m / 2 * 2;       } else if (m == 3) {         cout << 4;       } else {         cout << 0;       }       return 0;     }     cout << m / 6 * 6 + max((m % 6 - 3) * 2, 0LL);   }


#include <bits/stdc++.h>   int main() {     char abc[105];     scanf( %s , abc);     int n = strlen(abc);     int i = 0;     int max = 1, count = 0;     while (i < n) {       if (abc[i] ==  A  || abc[i] ==  E  || abc[i] ==  I  || abc[i] ==  O  ||           abc[i] ==  U  || abc[i] ==  Y ) {         if (max < count + 1) max = count + 1;         count = 0;       } else         count++;       i++;     }     if (max < count + 1) max = count + 1;     printf( %d , max);   }


#include <bits/stdc++.h>   using namespace std;   int find(int a[], int n) {     int max = 1;     int m = a[1];     for (int i = 2; i < n; i++) {       if (m <= a[i]) {         max = i;         m = a[i];       }     }     return max;   }   int main() {     int c = 0;     int n;     cin >> n;     int a[n];     cin >> a[0];     for (int i = 1; i < n; i++) {       int temp;       cin >> a[i];     }     int m = 0;     do {       m = find(a, n);       if (a[m] >= a[0]) {         a[m]--;         a[0]++;         c++;       } else         break;     } while (true);     cout << c <<   n ;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 400005;   vector<int> adj[N];   vector<int> st;   int cTime = 1;   int in[N];   int low[N];   vector<vector<int>> comps;   map<array<int, 2>, int> edgeToI;   array<int, 2> res[N];   int edgeToIndex(int a, int b) { return edgeToI[{min(a, b), max(a, b)}]; }   void addRes(int a, int b) { res[edgeToIndex(a, b)] = {a, b}; }   void dfs(int node, int par) {     in[node] = cTime++;     low[node] = in[node];     st.push_back(node);     for (int next : adj[node]) {       if (next == par) continue;       if (in[next]) {         low[node] = min(low[next], low[node]);       } else {         dfs(next, node);         low[node] = min(low[node], low[next]);       }     }     if (in[node] == low[node]) {       vector<int> cur;       while (true) {         int last = st.back();         st.pop_back();         cur.push_back(last);         if (last == node) break;       }       comps.push_back(cur);     }   }   bool onCircle[N];   bool vis[N];   void getEdges(int node) {     vis[node] = true;     for (int next : adj[node]) {       if (res[edgeToIndex(node, next)][0] != 0) continue;       addRes(next, node);       if (!vis[next]) getEdges(next);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);       edgeToI[{min(a, b), max(a, b)}] = i;     }     dfs(1, -1);     vector<int> best;     for (auto comp : comps) {       if (comp.size() > best.size()) best = comp;     }     for (int i : best) onCircle[i] = true;     vector<array<int, 2>> edges;     cout << best.size() <<   n ;     if (best.size() != 1) {     }     getEdges(best[0]);     for (int i = 0; i < m; i++) {       cout << res[i][0] <<     << res[i][1] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int hed[600010], nxt[600010], to[600010], cnt;   inline void addedge(int u, int v) {     nxt[++cnt] = hed[u];     hed[u] = cnt;     to[cnt] = v;   }   int siz[300010], root[300010], ans[300010];   int mx[300010];   int id[6000010], son[6000010][2], tot;   int n, q;   int merge(int x, int y) {     if (!x) return y;     if (!y) return x;     if (mx[id[y]] < mx[id[x]]) id[x] = id[y];     son[x][0] = merge(son[x][0], son[y][0]);     son[x][1] = merge(son[x][1], son[y][1]);     return x;   }   void update(int &x, int l, int r, int p, int v, int i) {     if (!x) x = ++tot;     if (v < mx[id[x]]) id[x] = i;     if (l == r) return;     int mid = (l + r) >> 1;     if (p <= mid)       update(son[x][0], l, mid, p, v, i);     else       update(son[x][1], mid + 1, r, p, v, i);   }   int query(int a, int b, int k, int l, int r) {     if (a > b || l > r || !k) return 0;     if (a == l && b == r) return id[k];     int mid = (l + r) >> 1;     if (b <= mid)       return query(a, b, son[k][0], l, mid);     else if (a > mid)       return query(a, b, son[k][1], mid + 1, r);     else {       int L = query(a, mid, son[k][0], l, mid),           R = query(mid + 1, b, son[k][1], mid + 1, r);       if (!L) return R;       if (!R) return L;       if (mx[L] < mx[R])         return L;       else         return R;     }   }   void dfs(int x) {     siz[x] = 1;     for (int i = hed[x]; i; i = nxt[i]) {       int y = to[i];       dfs(y);       siz[x] += siz[y];       root[x] = merge(root[x], root[y]);       mx[x] = max(mx[x], siz[y]);     }     update(root[x], 1, n, siz[x], mx[x], x);     ans[x] = query((siz[x] + 1) / 2, siz[x], root[x], 1, n);   }   int main() {     scanf( %d%d , &n, &q);     mx[0] = 1e9;     for (int i = 2; i <= n; i++) {       int p;       scanf( %d , &p);       addedge(p, i);     }     dfs(1);     while (q--) {       int x;       scanf( %d , &x);       printf( %d n , ans[x]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, temp, prev, A[100005];     bool f = false;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> A[i];     }     for (int i = 0; i < k; i++) {       cin >> temp;     }     if (k == 1) {       if (n == 1) {         cout <<  Yes ;         f = true;       } else {         int prevMax;         for (int i = 0; i < n; i++) {           if (A[i] == 0) {             A[i] = temp;           }           if (i != 0) {             if (A[i] <= prevMax) {               cout <<  Yes ;               f = true;               break;             }             prevMax = A[i];           } else {             prevMax = A[0];           }         }       }     } else {       cout <<  Yes ;       f = true;     }     if (!f) {       cout <<  No ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<char, pair<int, int> > ins;   void operator+=(pair<int, int> &i, pair<int, int> &j) {     i.first += j.first, i.second += j.second;   }   int main() {     ins[ U ] = pair<int, int>(0, 1), ins[ D ] = pair<int, int>(0, -1),     ins[ L ] = pair<int, int>(-1, 0), ins[ R ] = pair<int, int>(1, 0);     int n, m, w = 0;     pair<int, int> p;     char s[205];     scanf( %d %s , &n, s), m = strlen(s);     for (int i = 0; i < m - 1; ++i) {       p = ins[s[i]];       for (int j = i + 1; j < m; ++j) {         p += ins[s[j]];         if (p == pair<int, int>(0, 0)) w++;       }     }     printf( %d n , w);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long a[n];     vector<long long> pref(n + 1, 0);     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       pref[i + 1] = pref[i] + a[i];     }     map<long long, int> m;     m[0] = 0;     long long ans = 0;     int prev = -1;     for (int i = 1; i <= n; i++) {       if (m.find(pref[i]) != m.end()) {         if (m[pref[i]] >= prev - 1) {           ans++;           prev = i;         }       }       m[pref[i]] = i;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   namespace ZDY {   #pragma GCC optimize(3)   template <class T>   __inline__ __attribute__((always_inline)) T ABS(T x) {     return x > 0 ? x : -x;   }   template <class T>   __inline__ __attribute__((always_inline)) T MAX(T x, T y) {     return x > y ? x : y;   }   template <class T>   __inline__ __attribute__((always_inline)) T MIN(T x, T y) {     return x < y ? x : y;   }   template <class T>   __inline__ __attribute__((always_inline)) T GCD(T x, T y) {     return y ? GCD(y, x % y) : x;   }   template <class T>   __inline__ __attribute__((always_inline)) void SWAP(T& x, T& y) {     T t = x;     x = y;     y = t;   }   }  // namespace ZDY   using namespace ZDY;   using namespace std;   namespace IO {   const char* ln =   n ;   const int str = 1 << 20;   struct IN {     char buf[str], *s, *t;     bool _;     IN() : s(buf), t(buf), _(0) {}     __inline__ __attribute__((always_inline)) char gc() {       return s == t && ((t = (s = buf) + fread(buf, 1, str, stdin)) == s)                  ? EOF                  : (*s++);     }     IN& operator>>(char& ch) {       if (_) return *this;       char c;       while ((c = gc()) != EOF && isspace(c))         ;       if (c == EOF)         _ = 1;       else         ch = c;       return *this;     }     IN& operator>>(char* ch) {       memset(ch, 0, sizeof(ch));       if (_) return *this;       char c;       while ((c = gc()) != EOF && isspace(c))         ;       if (c == EOF) return _ = 1, *this;       *ch = c;       ch++;       while ((c = gc()) != EOF && !isspace(c)) *ch = c, ch++;       if (c == EOF) _ = 1;       return *this;     }     IN& operator>>(string& ch) {       if (_) return *this;       char c;       while ((c = gc()) != EOF && isspace(c))         ;       if (c == EOF) return _ = 1, *this;       ch += c;       while ((c = gc()) != EOF && !isspace(c)) ch += c;       if (c == EOF) _ = 1;       return *this;     }     template <typename T>     IN& operator>>(T& x) {       if (_) return *this;       char c = gc();       bool ff = 0;       while (c != EOF && (c <  0  || c >  9 )) ff ^= (c ==  - ), c = gc();       if (c == EOF) {         _ = 1;         return *this;       }       x = 0;       while (c != EOF &&  0  <= c && c <=  9 )         x = (x << 3) + (x << 1) + c - 48, c = gc();       if (c == EOF) _ = 1;       if (ff) x = -x;       return *this;     }   } in;   struct OUT {     char buf[str], *s, *t;     OUT() : s(buf), t(buf + str) {}     ~OUT() { fwrite(buf, 1, s - buf, stdout); }     void pt(char c) {       (s == t) ? (fwrite(s = buf, 1, str, stdout), *s++ = c) : (*s++ = c);     }     OUT& operator<<(const char* s) {       while (*s) pt(*s++);       return *this;     }     OUT& operator<<(char* s) {       while (*s) pt(*s++);       return *this;     }     OUT& operator<<(string s) {       for (int i = 0; s[i]; i++) pt(s[i]);       return *this;     }     template <typename T>     OUT& operator<<(T x) {       if (!x) return pt( 0 ), *this;       if (x < 0) pt( - ), x = -x;       char a[30], t = 0;       while (x) a[t++] = x % 10, x /= 10;       while (t--) pt(a[t] +  0 );       return *this;     }   } out;   }  // namespace IO   using namespace IO;   int n, b[1000011], a[1000011], cnt = 0, head[1000011];   bool cmp(int x, int y) { return a[x] > a[y]; }   bool cmp2(int x, int y) { return a[x] < a[y]; }   struct edge {     int to, nxt;   } e[1000011 * 2];   void add(int x, int y) {     e[++cnt].to = y;     e[cnt].nxt = head[x];     head[x] = cnt;   }   int f[1000011], sz[1000011];   int gf(int x) { return (x == f[x]) ? x : (f[x] = gf(f[x])); }   bool v[1000011];   int main() {     in >> n;     for (int i = 1; i <= n; ++i) in >> a[i], b[i] = i;     sort(b + 1, b + n + 1, cmp2);     int x, y;     for (int i = 1; i <= n - 1; ++i) in >> x >> y, add(x, y), add(y, x);     long long ans = 0;     for (int i = 1; i <= n; ++i) f[i] = i, sz[i] = 1;     for (int i = 1; i <= n; ++i) {       x = b[i];       v[x] = 1;       int t = 0;       for (int i = head[x], to; to = e[i].to, i; i = e[i].nxt)         if (v[to]) {           ans += 1ll * sz[x] * sz[gf(to)] * a[x];           sz[x] += sz[gf(to)];           f[gf(to)] = x;         }     }     memset(v, 0, sizeof(v));     for (int i = 1; i <= n; ++i) f[i] = i, sz[i] = 1;     sort(b + 1, b + n + 1, cmp);     for (int i = 1; i <= n; ++i) {       x = b[i];       v[x] = 1;       int t = 0;       for (int i = head[x], to; to = e[i].to, i; i = e[i].nxt)         if (v[to]) {           ans -= 1ll * sz[x] * sz[gf(to)] * a[x];           sz[x] += sz[gf(to)];           f[gf(to)] = x;         }     }     out << ans << ln;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[100007];   pair<int, int> b[100007];   pair<int, int> p, r;   double t, q, x, y, w;   int fl = 1;   int main() {     int n;     int d1, d2, res = 0;     scanf( %d , &n);     ;     scanf( %d , &d1);     ;     scanf( %d , &d2);     ;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i].first);       ;       scanf( %d , &a[i].second);       ;       scanf( %d , &b[i].first);       ;       scanf( %d , &b[i].second);       ;     }     for (int i = 1; i < n; ++i) {       p.first = b[i + 1].first - a[i + 1].first;       p.second = b[i + 1].second - a[i + 1].second;       r.first = b[i].first - a[i].first;       r.second = b[i].second - a[i].second;       t = 2.0 * r.first * (p.first - r.first);       t += 2.0 * r.second * (p.second - r.second);       q = 2.0 * (r.first - p.first) * (r.first - p.first);       q += 2.0 * (r.second - p.second) * (r.second - p.second);       t = t / q;       t = -t;       x = r.first * r.first + r.second * r.second;       y = p.first * p.first + p.second * p.second;       if (t <= 0.0 || t >= 1.0) {         if (y <= 1.0 * d1 * d1 && fl == 1) {           res += 1;           fl = 0;         } else if (y > 1.0 * d2 * d2 && fl == 0)           fl = 1;       } else {         w = (t * (p.first - r.first) + r.first) *             (t * (p.first - r.first) + r.first);         w += (t * (p.second - r.second) + r.second) *              (t * (p.second - r.second) + r.second);         if (w < x) {           if (w <= 1.0 * d1 * d1 && fl == 1) {             res += 1;             fl = 0;           }           if (y > 1.0 * d2 * d2 && fl == 0) fl = 1;         } else {           if (w > 1.0 * d2 * d2 && fl == 0) fl = 1;           if (y <= 1.0 * d1 * d1 && fl == 1) {             res += 1;             fl = 0;           }         }       }     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 400000 + 5;   int n, m, tr[N << 2][3], q;   set<int> ssp[N][2];   void modify(int x, int who, int v, int l = 1, int r = n, int k = 1) {     if (l == r) {       if (ssp[l][who].count(v))         ssp[l][who].erase(v);       else         ssp[l][who].insert(v);       tr[k][0] = ssp[l][0].empty() ? 0x3f3f3f3f : *ssp[l][0].begin();       tr[k][1] = ssp[l][1].empty() ? 0 : *ssp[l][1].rbegin();       tr[k][2] = tr[k][1] >= tr[k][0];       return;     }     int mid = (l + r) >> 1;     if (x <= mid)       modify(x, who, v, l, mid, k << 1);     else       modify(x, who, v, mid + 1, r, k << 1 | 1);     tr[k][1] = max(tr[k << 1][1], tr[k << 1 | 1][1]);     tr[k][0] = min(tr[k << 1][0], tr[k << 1 | 1][0]);     tr[k][2] =         (tr[k << 1 | 1][1] >= tr[k << 1][0]) | tr[k << 1][2] | tr[k << 1 | 1][2];   }   void build(int l = 1, int r = n, int k = 1) {     tr[k][0] = 0x3f3f3f3f, tr[k][1] = tr[k][2] = 0;     if (l == r) return;     int mid = (l + r) >> 1;     build(l, mid, k << 1), build(mid + 1, r, k << 1 | 1);   }   int main() {     scanf( %d%d%d , &n, &m, &q);     n <<= 1, m <<= 1, build();     while (q--) {       int x, y;       scanf( %d%d , &x, &y);       if (x & 1) {         modify(x, 0, y);       } else {         --x, --y;         modify(x, 1, y);       }       printf( %s n , !tr[1][2] ?  YES  :  NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& a) {     in >> a.first >> a.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> a) {     out << a.first <<     << a.second;     return out;   }   template <typename T, typename T1>   T amax(T& a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T amin(T& a, T1 b) {     if (b < a) a = b;     return a;   }   const long long INF = 1e18;   const int32_t M = 1e9 + 7;   const int32_t MM = 998244353;   const long long N = 2 * 100005;   struct node {     long long mn, sum;     bool lazyset;     long long lazyval;     void assign(long long val) {       mn = val;       sum = val;     }     void merge(node& a, node& b) {       mn = min(a.mn, b.mn);       sum = a.sum + b.sum;     }   };   struct segtree {     node t[4 * N];     void pushdown(long long v, long long tl, long long tr) {       long long tm = (tl + tr) / 2;       if (t[v].lazyset) {         apply(v * 2, tl, tm, t[v].lazyval);         apply(v * 2 + 1, tm + 1, tr, t[v].lazyval);         t[v].lazyset = 0;       }     }     void apply(long long v, long long tl, long long tr, long long val) {       t[v].mn = val;       t[v].sum = val * (tr - tl + 1);       t[v].lazyset = 1;       t[v].lazyval = val;     }     void build(long long a[], long long v, long long tl, long long tr) {       if (tl == tr) {         t[v].assign(a[tl]);       } else {         long long tm = (tl + tr) / 2;         build(a, v * 2, tl, tm);         build(a, v * 2 + 1, tm + 1, tr);         t[v].merge(t[v * 2], t[v * 2 + 1]);       }       t[v].lazyset = 0;     }     long long query(long long v, long long tl, long long tr, long long l,                     long long r) {       if (tl > r || tr < l) return 0;       if (l <= tl && tr <= r) {         return t[v].sum;       }       pushdown(v, tl, tr);       long long tm = (tl + tr) / 2;       return query(v * 2, tl, tm, l, r) + query(v * 2 + 1, tm + 1, tr, l, r);     }     long long sumdescent(long long v, long long tl, long long tr, long long val) {       if (tl == tr) return t[v].sum > val ? tl : N;       pushdown(v, tl, tr);       long long tm = (tl + tr) / 2;       if (t[v * 2].sum > val) return sumdescent(v * 2, tl, tm, val);       return sumdescent(v * 2 + 1, tm + 1, tr, val - t[v * 2].sum);     }     long long descent(long long v, long long tl, long long tr, long long val) {       if (t[v].mn >= val) return tr + 1;       if (tl == tr) return tl;       pushdown(v, tl, tr);       long long tm = (tl + tr) / 2;       if (t[v * 2].mn < val) return descent(v * 2, tl, tm, val);       return descent(v * 2 + 1, tm + 1, tr, val);     }     void rupd(long long v, long long tl, long long tr, long long l, long long r,               long long val) {       if (tl > r || tr < l) return;       if (l <= tl && tr <= r) {         apply(v, tl, tr, val);         return;       }       pushdown(v, tl, tr);       long long tm = (tl + tr) / 2;       rupd(v * 2, tl, tm, l, r, val);       rupd(v * 2 + 1, tm + 1, tr, l, r, val);       t[v].merge(t[v * 2], t[v * 2 + 1]);     }   } st;   void solve() {     long long n, q;     cin >> n >> q;     long long a[n];     for (long long i = 0; i < n; ++i) {       cin >> a[i];     }     st.build(a, 1, 0, n - 1);     for (long long i = 0; i < q; ++i) {       long long t, x, y;       cin >> t >> x >> y;       if (t == 1) {         long long l = st.descent(1, 0, n - 1, y);         long long r = x - 1;         if (l <= r) st.rupd(1, 0, n - 1, l, r, y);       } else {         long long cur = y;         long long idx = x - 1;         long long ans = 0;         while (idx < n) {           long long nxtidx = st.descent(1, 0, n - 1, cur + 1);           amax(idx, nxtidx);           long long sumidx =               st.sumdescent(1, 0, n - 1,                             cur + st.query(1, 0, n - 1, 0, idx - 1)) -               1;           amin(sumidx, n - 1);           ans += sumidx - idx + 1;           cur -= st.query(1, 0, n - 1, idx, sumidx);           idx = sumidx + 1;         }         cout << ans <<   n ;       }     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     unsigned long long k, res = 0;     cin >> n >> k;     unsigned long long *arr = new unsigned long long[n + 1];     arr[0] = 1;     for (int i = 1; i <= n; i++) arr[i] = arr[i - 1] * 2;     bool left = true;     while (n > 1) {       if (k > arr[n - 1]) {         if (left) {           res += arr[n];         } else {           res++;           left = true;         }         k -= arr[n - 1];       } else {         if (left) {           res++;         } else {           res += arr[n];         }         left = false;       }       n--;     }     if (k == 1 && left)       res += 2;     else if (k == 2 && left)       res += 3;     else if (k == 1)       res += 3;     else       res += 2;     cout << res - 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int n;     cin >> n;     multiset<long long int> s;     for (long long int i = 0; i < n; i++) {       long long int x;       cin >> x;       s.insert(x);     }     long long int ans = 0;     for (long long int i = 1; i <= n; i++) {       while (s.size()) {         long long int x = *(s.begin());         if (x >= i) break;         s.erase(s.begin());       }       if (!s.size()) break;       ans++;       s.erase(s.begin());     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O2 )   const int P = 998244353;   int n, k, ans;   int dp[2][510][510];   int cnt[510], pre[510];   template <typename T>   inline void read(T &x) {     T f = 1;     x = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c -  0 ;     x *= f;   }   inline int exp_mod(int a, int n) {     int b = a, res = 1;     while (n) {       if (n & 1) res = 1ll * res * b % P;       b = 1ll * b * b % P;       n >>= 1;     }     return res;   }   int main() {     read(n);     read(k);     if (n == 1) {       printf( 0 n );       return 0;     }     dp[0][0][0] = 1;     for (int i = 0; i <= n; i++) {       int now = i & 1, nxt = now ^ 1;       for (int j = 0; j <= n; j++) {         for (int x = 0; x <= n; x++) {           dp[nxt][j][x] = 0;         }       }       for (int j = 0; j <= i; j++) {         for (int x = 0; x <= n; x++) {           dp[nxt][j + 1][max(x, j + 1)] =               (1ll * dp[nxt][j + 1][max(x, j + 1)] + dp[now][j][x]) % P;           dp[nxt][1][max(x, 1)] =               (1ll * dp[nxt][1][max(x, 1)] + dp[now][j][x]) % P;         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cnt[i] = (1ll * cnt[i] + dp[n & 1][j][i]) % P;       }     }     for (int i = 1; i <= n; i++) pre[i] = (pre[i - 1] + cnt[i]) % P;     for (int i = 1; i <= n; i++)       ans = (ans + 1ll * cnt[i] * 1ll * pre[min(n, (k - 1) / i)]) % P;     printf( %d n , 1ll * ans * exp_mod(2, P - 2) % P);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (1 << 22) + 20;   bool vis[2][N];   int a[N], n, m, ex[N];   int get_not(int x) { return (1 << n) - 1 - x; }   void dfs(int type, int msk) {     vis[type][msk] = true;     if (type == 1) {       if (!vis[0][get_not(msk)]) dfs(0, get_not(msk));       for (int i = 0; i < n; i++)         if ((!(msk & (1 << i))) && (!vis[1][msk ^ (1 << i)]))           dfs(1, msk ^ (1 << i));     } else if (!vis[1][msk] && ex[msk])       dfs(1, msk);   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 0; i < m; i++) cin >> a[i], ex[a[i]] = 1;     int ans = 0;     for (int i = 0; i < m; i++) {       if (!vis[0][a[i]]) dfs(0, a[i]), ans++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0;     cin >> n;     n++;     for (int i = 1; i < n - 2; i++) {       for (int j = i; j < n - 1; j++) {         int k = (int)(i ^ j);         if (k < n && k > j) {           if (!(i ^ j ^ k)) {             double p = (i + j + k) / 2;             double s = sqrt(p * (p - i) * (p - j) * (p - k));             if (s > 0) {               sum++;             }           }         }       }     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mul(long long a, long long b, long long p) {     long long s = 0;     while (b) {       if (b & 1) s = (s + a) % p;       a = (a + a) % p;       b >>= 1;     }     return s;   }   long long ksm(long long a, long long b, long long p) {     long long s = 1;     while (b) {       if (b & 1) s = mul(s, a, p);       a = mul(a, a, p);       b >>= 1;     }     return s;   }   int main() {     long long n;     cin >> n;     while (n--) {       long long a;       cin >> a;       long long n = to_string(a).length();       for (long long m = 0;; m++) {         long long b = ((1 << n + m) - a % (1 << n + m)) % (1 << n + m);         if ((a + b) % 5 == 0) b += 1 << n + m;         if (b < pow(10, m)) {           long long x = (a + b) >> n + m, d = -1;           for (long long i = 0; i < 5; i++)             if ((1 << i) % 5 == x % 5) {               d = i;               break;             }           for (long long i = 2, p = 5; i <= n + m; i++) {             long long phi = p / 5 * 4;             p *= 5;             for (long long k = 0; k < 5; k++)               if (ksm(2, d + k * phi, p) == x % p) {                 d += k * phi;                 break;               }           }           cout << d + n + m <<   n ;           break;         }         a *= 10;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000005;   int n, m, _m, cnt, d[maxn], fa[maxn];   bool vis[maxn];   struct Edge {     int x, y;   } Es[maxn];   long long ans;   int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); }   void merge(int x, int y) {     x = getfa(x);     y = getfa(y);     if (x != y) fa[x] = y;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       if (x != y) {         Es[++_m].x = x, Es[_m].y = y;         d[x]++;         d[y]++;         vis[x] = vis[y] = true;         merge(x, y);       } else         cnt++, vis[x] = true;     }     int rt = 0;     for (int i = 1; i <= n; i++)       if (vis[i]) rt = i;     if (!rt) return printf( 0 n ), 0;     for (int i = 1; i <= n; i++)       if (vis[i] && getfa(rt) != getfa(i)) return printf( 0 n ), 0;     for (int i = 1; i <= _m; i++) ans += (d[Es[i].x] - 1) + (d[Es[i].y] - 1);     ans = ans / 2 + (long long)_m * cnt + (long long)cnt * (cnt - 1) / 2;     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, a, b;     cin >> n >> a >> b;     long long ma, mi;     ma = max(a, b);     mi = min(a, b);     long long seated = 0;     for (long long i = (long long)(0); i < (long long)(n); i++) {       char t;       cin >> t;       while (t ==  .  and i < n) {         if (ma != 0) {           ma--;           seated++;         }         a = ma;         ma = mi;         mi = a;         i++;         if (i < n) cin >> t;       }       a = ma;       ma = max(mi, ma);       mi = min(mi, a);     }     cout << seated << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   int num[222222];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> num[i];     int sum = 1;     int ans = 1;     for (int i = 1; i < n; i++) {       if (num[i] <= num[i - 1] * 2) {         sum++;       } else {         ans = max(ans, sum);         sum = 1;       }     }     ans = max(ans, sum);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     double df, de;     void init(double _df, double _de) {       df = _df;       de = _de;     }   } V[100];   int nf, ne, ns, rf, re, rs, df, de;   int n, top, place[13];   double ans = 0, dp[21][21], lf, le, ls;   bool cmp(const point &a, const point &b) { return a.df > b.df; }   double cross(double l1, double r1, double l2, double r2) {     if (l2 >= r1 || l1 >= r2) return 0;     return min(r1, r2) - max(l1, l2);   }   void init_V() {     top = 0;     for (int i = 0; i < n; i++)       if (place[i] < 2) {         double t1 = lf * df, t2 = le * de;         for (int j = 0; j < n; j++)           if (place[j]) {             t1 += df * place[j] *                   cross(j - ls / 2, j + ls / 2, i - lf / 2, i + lf / 2);             t2 += de * place[j] *                   cross(j - ls / 2, j + ls / 2, i - le / 2, i + le / 2);           }         for (int j = 1; j + place[i] <= 2; j++) V[top++].init(t1, t2);       }     sort(V, V + top, cmp);   }   void init_dp() {     memset(dp, 0, sizeof(dp));     for (int i = 0; i <= nf; i++)       for (int j = 0; j <= ne; j++) {         if (i) dp[i][j] = max(dp[i][j], dp[i - 1][j] + V[i + j - 1].df);         if (j) dp[i][j] = max(dp[i][j], dp[i][j - 1] + V[i + j - 1].de);       }     ans = max(ans, dp[nf][ne]);   }   void dfs(int p, int left) {     if ((n - p) * 2 < left) return;     if (p == n) {       init_V();       init_dp();       return;     }     for (int i = 0; i <= 2 && left >= i; i++) {       place[p] = i;       dfs(p + 1, left - i);     }   }   int main() {     cin >> nf >> ne >> ns >> rf >> re >> rs >> df >> de;     n = (nf + ne + ns) / 3 * 2 + 1;     lf = 2 * sqrt(rf * rf - 1.0);     le = 2 * sqrt(re * re - 1.0);     ls = 2 * sqrt(rs * rs - 1.0);     dfs(0, ns);     printf( %.10lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 10003;   int32_t main() {     int n, a, b, c;     cin >> n >> a >> b >> c;     if (n == 1) {       cout <<  0 ;       return 0;     }     n--;     long long ans = 0;     ans += min(a, b);     n--;     if (min(a, b) > c) {       ans += n * c;       cout << ans;       return 0;     }     ans += n * min(a, b);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> vec1, vec2, vec3;     int n, sz;     cin >> n;     for (int i = 1; i <= n; ++i) {       int x;       cin >> x;       if (x == 1)         vec1.push_back(i);       else if (x == 2)         vec2.push_back(i);       else         vec3.push_back(i);     }     sz = min(min(vec1.size(), vec2.size()), vec3.size());     cout << sz << endl;     for (int i = 0; i < sz; ++i)       cout << vec1[i] <<     << vec2[i] <<     << vec3[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, arr[100000], r, arr1[100000], z;   bool boo[100000];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> r;       arr[i] = r;     }     for (int i = 0; i < n; i++) arr1[i] = arr[i];     reverse(arr1, arr1 + n);     z = arr1[0];     boo[0] = 1;     for (int i = 0; i < n; i++) {       if (arr1[i] > z) boo[i] = 1;       if (arr1[i] >= z)         z = arr1[i];       else         arr1[i] = z;     }     reverse(arr1, arr1 + n);     reverse(boo, boo + n);     for (int i = 0; i < n; i++) {       int k = arr1[i] - arr[i];       if (boo[i] == 1)         cout << 0 << endl;       else         cout << k + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[222222];     scanf( %d n , &n);     pair<int, int> p;     vector<pair<int, int> > v, v1;     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       p.first = x;       p.second = 0;       v.push_back(p);     }     reverse(v.begin(), v.end());     int maxi = v[0].first, pos = 0;     ;     for (int i = 0; i < v.size(); i++) {       if (pos != i) {         if (maxi >= v[i].first) v[i].second = maxi - v[i].first + 1;         if (maxi < v[i].first) {           maxi = v[i].first;           pos = i;         }       }     }     reverse(v.begin(), v.end());     for (int i = 0; i < v.size(); i++) printf( %d  , v[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.length();     s += s;     int ans = -1;     int len = 1;     for (int i = 1; i < 2 * n; i++) {       if (s[i] != s[i - 1])         len++;       else {         if (len <= n) ans = max(len, ans);         len = 1;       }     }     if (len <= n) ans = max(len, ans);     if (len > n) ans = n;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     int curr = 1;     for (int i = 0; i < n; i++) {       if (arr[i] >= curr) {         curr++;       }     }     cout << curr;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1E5 + 10;   int n, tot;   int a[N], vis[N], twom[N], threem[N];   vector<int> x, y;   stack<int> one, two, three;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = n; i >= 1; --i) {       if (a[i] == 1) {         one.push(i);       } else if (a[i] == 2) {         if (!one.size()) {           cout << -1 << endl;           return 0;         } else {           twom[i] = one.top();           one.pop();         }         two.push(i);       } else if (a[i] == 3) {         if (three.size()) {           threem[i] = three.top();           three.pop();         } else if (two.size()) {           threem[i] = two.top();         } else if (one.size()) {           threem[i] = one.top();           one.pop();         } else {           cout << -1 << endl;           return 0;         }         three.push(i);       }     }     int currow = 1;     for (int i = 1; i <= n; ++i) {       if (a[i] == 0 || vis[i] == 1) continue;       int curcol = i;       while (curcol) {         vis[curcol] = 1;         if (a[curcol] == 1) {           x.push_back(currow);           y.push_back(curcol);           curcol = 0;           ++currow;         } else if (a[curcol] == 2) {           x.push_back(currow);           y.push_back(curcol);           curcol = twom[curcol];         } else if (a[curcol] == 3) {           x.push_back(currow);           y.push_back(curcol);           curcol = threem[curcol];           x.push_back(currow);           y.push_back(curcol);           ++currow;         }       }     }     cout << x.size() << endl;     for (int i = 0; i <= (int)x.size() - 1; ++i) printf( %d %d n , x[i], y[i]);   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   vector<pair<long long, int> > v;   int main() {     long long a, b, d;     cin >> a;     cin >> b;     d = a * b / gcd(a, b);     if (a < b) {       for (int i = 0; i * a <= d; i++) {         v.push_back(make_pair(i * a, 1));       }       for (int i = 0; i * b <= d; i++) {         v.push_back(make_pair(i * b, 0));       }     } else {       for (int i = 0; i * a <= d; i++) {         v.push_back(make_pair(i * a, 0));       }       for (int i = 0; i * b <= d; i++) {         v.push_back(make_pair(i * b, 1));       }     }     sort(v.begin(), v.end());     long long s1, s2;     s1 = 0;     s2 = 0;     for (int i = 0; i < (int)v.size() - 1; i++) {       if (v[i + 1].second == 0) {         s1 += v[i + 1].first - v[i].first;       } else         s2 += v[i + 1].first - v[i].first;     }     if (a > b) {       if (s1 > s2) printf( Dasha n );       if (s1 < s2) printf( Masha n );     } else {       if (s1 < s2) printf( Dasha n );       if (s1 > s2) printf( Masha n );     }     if (s1 == s2) printf( Equal n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, long long> mp;   long long ar[200005];   long long br[200005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     t = 1;     while (t--) {       int n;       cin >> n;       for (int i = 1; i <= n; i++) {         cin >> ar[i];       }       long long prv = 1;       mp[0] = 0;       long long ans = 0;       for (int i = 1; i <= n; i++) {         br[i] = br[i - 1] + ar[i];         if (mp.count(br[i])) {           prv = max(prv, mp[br[i]] + 2);         }         ans += i - prv + 1;         mp[br[i]] = i;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n + 1);     vector<int> b(n + 1);     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a.begin() + 1, a.end());     for (int i = 1; i <= n / 2; i++) b[2 * i] = a[i];     for (int i = n / 2 + 1; i <= n; i++) b[(i - n / 2) * 2 - 1] = a[i];     int ans = 0;     for (int i = 2; i < n; i++) ans += (b[i] < b[i - 1]) * (b[i] < b[i + 1]);     cout << ans << endl;     for (auto i = b.begin() + 1; i != b.end(); i++) cout << *i <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout << (n * n) / 4 << endl;     for (int i = 1; i <= n / 2; i++) cout << n <<     << i << endl;     for (int i = 1; i <= n / 2; i++)       for (int j = n / 2 + 1; j < n; j++) cout << i <<     << j << endl;   }


#include <bits/stdc++.h>   using namespace std;   short memo[6][40][1 << 6][1 << 6][1 << 6];   int n, m;   short roll(int row, int col, int a, int b, int c) {     if (col == m) {       return (n - __builtin_popcount(a));     }     if (row == n) {       return roll(0, col + 1, b, c, 0) +              (col > 0 ? (n - __builtin_popcount(a)) : 0);     }     short &ans = memo[row][col][a][b][c];     if (~ans) {       return ans;     }     ans = roll(row + 1, col, a, b | (1 << row), c);     if (col > 0) {       ans = max(ans, roll(row + 1, col, a | (1 << row), b, c));     }     if (col < m - 1) {       ans = max(ans, roll(row + 1, col, a, b, c | (1 << row)));     }     if (row > 0) {       ans = max(ans, roll(row + 1, col, a, b | (1 << (row - 1)), c));     }     if (row < n - 1) {       ans = max(ans, roll(row + 1, col, a, b | (1 << (row + 1)), c));     }     return ans;   }   int main() {     scanf( %d %d , &n, &m);     if (n > m) {       swap(n, m);     }     memset(memo, -1, sizeof memo);     cout << roll(0, 0, 0, 0, 0) <<   n ;     return 0;   }