#include <bits/stdc++.h>   using namespace std;   template <class T>   void _R(T &x) {     cin >> x;   }   void _R(int &x) { scanf( %d , &x); }   void _R(int64_t &x) { scanf( %lld , &x); }   void _R(double &x) { scanf( %lf , &x); }   void _R(char &x) { scanf(  %c , &x); }   void _R(char *x) { scanf( %s , x); }   void R() {}   template <class T, class... U>   void R(T &head, U &...tail) {     _R(head);     R(tail...);   }   template <class T>   void _W(const T &x) {     cout << x;   }   void _W(const int &x) { printf( %d , x); }   void _W(const int64_t &x) { printf( %lld , x); }   void _W(const double &x) { printf( %.16f , x); }   void _W(const char &x) { putchar(x); }   void _W(const char *x) { printf( %s , x); }   template <class T, class U>   void _W(const pair<T, U> &x) {     _W(x.first);     putchar(   );     _W(x.second);   }   template <class T>   void _W(const vector<T> &x) {     for (auto i = x.begin(); i != x.end(); _W(*i++))       if (i != x.cbegin()) putchar(   );   }   void W() {}   template <class T, class... U>   void W(const T &head, const U &...tail) {     _W(head);     putchar(sizeof...(tail) ?     :   n );     W(tail...);   }   int MOD = 1e9 + 7;   void ADD(long long &x, long long v) {     x = (x + v) % MOD;     if (x < 0) x += MOD;   }   const int SIZE = 1e6 + 10;   const int MATRIX_SIZE = 500;   long long mypow(long long x, long long y) {     x %= MOD;     long long res = 1 % MOD;     while (y) {       if (y & 1) res = res * x % MOD;       y >>= 1;       x = x * x % MOD;     }     return res;   }   struct Matrix_Power {     long long AA[60][MATRIX_SIZE][MATRIX_SIZE], aa[62][MATRIX_SIZE];     int N;     void set(long long _A[][MATRIX_SIZE], int _N,              long long bb = (long long)1e18) {       N = _N;       for (int i = 0; i < (N); ++i)         for (int j = 0; j < (N); ++j) AA[0][i][j] = _A[i][j];       for (int round = (1); round < (60); ++round) {         if ((1LL << round) > bb) break;         for (int i = 0; i < (N); ++i)           for (int j = 0; j < (N); ++j) AA[round][i][j] = 0;         for (int i = 0; i < (N); ++i)           for (int j = 0; j < (N); ++j)             for (int k = 0; k < (N); ++k) {               AA[round][i][k] += AA[round - 1][i][j] * AA[round - 1][j][k];               AA[round][i][k] %= MOD;             }       }     }     long long get(long long _a[], long long v) {       memset((aa), 0, sizeof((aa)));       for (int i = 0; i < (N); ++i) aa[0][i] = _a[i];       for (int i = 0; i < (61); ++i) {         if ((1LL << i) > v) return aa[i][N - 1];         if ((v >> i) & 1) {           for (int j = 0; j < (N); ++j)             for (int k = 0; k < (N); ++k) {               aa[i + 1][j] += AA[i][j][k] * aa[i][k];               aa[i + 1][j] %= MOD;             }         } else           for (int j = 0; j < (N); ++j) aa[i + 1][j] = aa[i][j];       }       return -1;     }   } mat;   long long A[1000][MATRIX_SIZE];   long long a[SIZE];   int main() {     MOD = 1000003;     int c, w, h;     R(c, w, h);     for (int i = 0; i < (w + 1); ++i) {       if (i < w)         A[i][i + 1] = 1;       else {         for (int j = 0; j < (w + 1); ++j) A[i][i - j] = mypow(h, j);       }     }     a[w - 1] = a[w] = 1;     mat.set(A, w + 1, c * 2);     W(mat.get(a, c));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   int arr[2 * MAXN];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= 2 * n; i++) scanf( %d , arr + i);     sort(arr + 1, arr + 2 * n + 1);     long long best = LONG_LONG_MAX;     for (int start_x = 1; start_x <= n + 1; start_x++) {       int r_x = arr[start_x + n - 1] - arr[start_x];       int y_max = ((start_x == n + 1) ? arr[n] : arr[2 * n]);       int y_min = ((start_x == 1) ? arr[n + 1] : arr[1]);       int r_y = y_max - y_min;       best = min(best, 1ll * r_x * r_y);     }     printf( %lld n , best);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};   int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};   template <class T>   inline T biton(T n, T pos) {     return n | ((T)1 << pos);   }   template <class T>   inline T bitoff(T n, T pos) {     return n & ~((T)1 << pos);   }   template <class T>   inline T ison(T n, T pos) {     return (bool)(n & ((T)1 << pos));   }   template <class T>   inline T gcd(T a, T b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   inline int nxt() {     int aaa;     scanf( %d , &aaa);     return aaa;   }   inline long long lxt() {     long long aaa;     scanf( %lld , &aaa);     return aaa;   }   inline double dxt() {     double aaa;     scanf( %lf , &aaa);     return aaa;   }   template <class T>   inline T bigmod(T p, T e, T m) {     T ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % m;       p = (p * p) % m;     }     return (T)ret;   }   template <class T>   istream& operator>>(istream& is, vector<T>& input) {     for (T& in : input) is >> in;     return is;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& input) {     bool isFirst = true;     for (T out : input) {       if (isFirst) {         os << out;         isFirst = false;       } else         os <<     << out;     }     return os;   }   void solve() {     int r = nxt(), g = nxt(), b = nxt(), w = nxt();     if (r == 0 || g == 0 || b == 0) {       int cnt = 0;       if (r & 1) cnt++;       if (g & 1) cnt++;       if (b & 1) cnt++;       if (w & 1) cnt++;       if (cnt > 1) {         cout <<  No n ;         return;       }       cout <<  Yes n ;       return;     }     int mn = min({r, g, b});     r -= mn, g -= mn, b -= mn;     w += (mn * 3);     for (int i = 0; i < min(mn, 5); i++) {       r += i;       g += i;       b += i;       w -= (i * 3);       int cnt = 0;       if (r & 1) cnt++;       if (g & 1) cnt++;       if (b & 1) cnt++;       if (w & 1) cnt++;       if (cnt <= 1) {         cout <<  Yes n ;         return;       }     }     cout <<  No n ;   }   int main() {     cout.setf(ios::fixed);     cout.precision(10);     int tc = nxt();     while (tc--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const int INF = 1000000000;   int s(int first) {     int r = 0;     while (first) {       r += first % 10;       first /= 10;     }     return r;   }   int main() {     long long m;     cin >> m;     long long b = 1000 * 1000 * 1000;     long long r = b * b;     r = 9 * r % m;     r = 9 * r % m;     r = (m - (r + 1) % m) % m;     cout << 1 + r <<     << b * b + r << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[2000], y[2000], c[2000];   vector<int> poss;   multiset<int> xx[2000];   vector<pair<int, int> > events;   map<pair<int, int>, int> M;   long long int sum = 0, ans = 0;   int update(int e, int m) {     if (e < 0) return 0;     auto it = M.upper_bound(make_pair(e, 2e9));     it--;     if (it->first.second != e) {       pair<int, int> p = it->first;       int v = it->second;       M.erase(it);       M[make_pair(p.first, e)] = v;       M[make_pair(e + 1, p.second)] = v;     }     it = M.upper_bound(make_pair(e, 2e9));     it--;     if (it->second < m) return 0;     pair<int, int> p = make_pair(e, e);     while (it->second >= m) {       p.first = it->first.first;       sum -= (long long int)(it->first.second - it->first.first + 1) * it->second;       it = M.erase(it);       if (it == M.begin())         break;       else         it--;     }     M[p] = m;     sum += (long long int)(p.second - p.first + 1) * m;     return 0;   }   int main() {     int i;     int n, k, L;     scanf( %d %d %d , &n, &k, &L);     poss.push_back(-1), poss.push_back(L);     for (i = 0; i < n; i++) {       scanf( %d %d %d , &x[i], &y[i], &c[i]), c[i]--;       poss.push_back(y[i]);     }     sort(poss.begin(), poss.end());     poss.resize(unique(poss.begin(), poss.end()) - poss.begin());     int j;     for (i = 1; i < poss.size(); i++) {       int yy = poss[i] - poss[i - 1];       for (j = 0; j < n; j++) {         if (y[j] > poss[i - 1]) {           events.push_back(make_pair(y[j], j));           xx[c[j]].insert(x[j]);         }       }       M.clear();       M[make_pair(0, L - 1)] = L, sum = (long long int)L * L;       for (j = 0; j < k; j++) {         if (xx[j].empty()) break;         int p = -1;         for (auto it = xx[j].begin(); it != xx[j].end(); it++)           update(*it - 1, p + 1), p = *it;         update(L - 1, p + 1);       }       if (j < k) break;       sort(events.begin(), events.end(), greater<pair<int, int> >());       int l = L;       for (j = 0; j < events.size(); j++) {         int u = events[j].second;         long long int nn = (long long int)yy * (l - events[j].first);         nn %= 1000000007;         ans += nn * (sum % 1000000007), ans %= 1000000007;         auto it = xx[c[u]].lower_bound(x[u]);         it = xx[c[u]].erase(it);         int a = (it == xx[c[u]].end()) ? L - 1 : *it - 1;         int b = (it == xx[c[u]].begin()) ? 0 : *(--it) + 1;         update(a, b);         if (xx[c[u]].empty()) break;         l = events[j].first;       }       for (j = 0; j < k; j++) xx[j].clear();       events.clear();     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long xpow(long long a, long long b) {     if (!b) return 1;     if (b == 1) return a;     if (b & 1) {       return ((a * xpow(a, b - 1)));     } else {       long long p = xpow(a, b / 2);       return ((p * p));     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long w, m;     cin >> w >> m;     vector<long long> v(102, 0);     long long x = m, k = 0;     while (x) {       v[k] = x % w;       x /= w;       k++;     }     bool f = 0;     for (long long i = 0; i < 102; i++) {       if (v[i] == 1 || !v[i]) {         continue;       } else {         if (v[i] == w - 1 || v[i] == w) {           v[i + 1]++;         } else {           cout <<  NO ;           f = 1;           break;         }       }     }     if (!f) cout <<  YES ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[5111], y, yy;   int lmax[5111], cnt[5111], llmax;   int N, i, j, k;   int main() {     scanf( %d , &N);     for (i = 1; i <= N; i++) scanf( %I64d , &a[i]);     for (llmax = 0, i = 1; i <= N; i++) {       lmax[i] = 0;       cnt[i] = 0;       y = a[i];       while ((y & 1) == 0) {         y >>= 1;         cnt[i]++;       }       for (j = i - 1; j >= 1; j--) {         k = i - j;         if (k > cnt[i]) {           if (a[j] % y == 0 && lmax[j] > lmax[i]) lmax[i] = lmax[j];         } else {           yy = y << (cnt[i] - k);           if (a[j] % yy == 0 && ((a[j] / yy) & 1 == 1) && lmax[j] > lmax[i])             lmax[i] = lmax[j];         }       }       lmax[i]++;       if (lmax[i] > llmax) llmax = lmax[i];     }     printf( %d n , N - llmax);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int v[200001], i, n, poz;   bool cmp(int a, int b) { return a < b; }   int main() {     cin >> n;     for (i = 1; i <= n; i++) cin >> v[i];     sort(v + 1, v + n + 1, cmp);     poz = 1;     for (i = 1; i <= n; i++) {       if (v[i] >= poz) poz++;     }     cout << poz - 1;   }


#include <bits/stdc++.h>   using namespace std;   void dropAny(const vector<int> &a, int offset, vector<bool> &used) {     vector<int> next(used.size(), a.size());     for (int i = int(a.size()) - 1; i >= offset; --i) {       next[a[i]] = i;     }     int best = -1;     for (int i = 0; i < (int)used.size(); ++i) {       if (!used[i]) {         continue;       }       if (best == -1 || next[best] < next[i]) {         best = i;       }     }     used[best] = false;     ;   }   struct RangeTree {     int kk;     vector<pair<int, int> > b;     RangeTree(int n) {       kk = 1;       while (kk < n) {         kk *= 2;       }       b.assign(2 * kk + 10, pair<int, int>(-1, -1));     }     int getMaxPos() { return b[1].second; }     int get(int pos) { return b[pos + kk].first; }     void set(int pos, int val) {       ;       int t = pos + kk;       b[t] = pair<int, int>(val, pos);       while (t > 1) {         t /= 2;         b[t] = max(b[2 * t], b[2 * t + 1]);       }     }   };   int main() {     int n, k;     scanf( %d%d , &n, &k);     int maxA = 0;     vector<int> a(n);     vector<pair<int, int> > z(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       z[i] = pair<int, int>(a[i], i);       maxA = max(maxA, a[i] + 1);     }     sort(z.begin(), z.end());     vector<int> next(n, n);     for (int i = 1; i < int(z.size()); ++i) {       if (z[i - 1].first == z[i].first) {         next[z[i - 1].second] = z[i].second;       }     }     for (int i = 0; i < n; ++i) {       ;     };     RangeTree tree(maxA);     int cnt = 0;     int ans = 0;     for (int i = 0; i < n; ++i) {       if (tree.get(a[i]) == -1) {         ;         if (cnt == k) {           int pos = tree.getMaxPos();           ;           tree.set(pos, -1);           cnt--;         }         tree.set(a[i], next[i]);         ans++;         cnt++;       } else {         tree.set(a[i], next[i]);       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int MAX = 1e3 + 5;   const int MOD = 1e9 + 7;   const int64_t INF = INT_MAX;   const int64_t _INF = INT_MIN;   int k, n;   int h[MAX];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> k;     while (k--) {       cin >> n;       for (int i = 1; i <= n; i++) cin >> h[i];       int ans = 0;       sort(h + 1, h + n + 1);       for (int i = 1; i <= n; i++) ans = max(ans, min(h[n - i + 1], i));       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long fac[200001];   long long inv[200001];   long long modexp(long long b, long long e) {     long long ans = 1;     while (e > 0) {       if (e & 1) {         ans = (ans * b) % mod;       }       b = (b * b) % mod;       e >>= 1;     }     return ans;   }   long long comb(long long n, long long k) {     long long ans = (fac[n] * inv[k]) % mod;     ans = (ans * inv[n - k]) % mod;     return ans;   }   int main() {     fac[0] = fac[1] = 1;     inv[0] = inv[1] = 1;     for (int i = 2; i <= 200000; i++) {       fac[i] = (fac[i - 1] * i) % mod;       inv[i] = modexp(fac[i], mod - 2);     }     int n, k;     cin >> n >> k;     vector<pair<int, int> > list;     for (int i = 1; i <= n; i++) {       int a, b;       cin >> a >> b;       list.push_back(make_pair(a, 1));       list.push_back(make_pair(b + 1, -1));     }     sort(list.begin(), list.end());     int maintain = 0;     long long ans = 0;     int selisih;     for (int i = 0; i < list.size(); i++) {       if (i > 0 && list[i].first != list[i - 1].first) {         if (maintain >= k) {           ans += comb(maintain, k) * (list[i].first - selisih);           ans %= mod;         }       }       maintain += list[i].second;       selisih = list[i].first;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, i, a, b, x, y, o, z, p, q, sum, c;   int main() {     cin >> n;     vector<long long> v;     for (i = 0; i < n; i++) {       cin >> x;       if (x == 0)         o++;       else         v.push_back(x);     }     sort(v.begin(), v.end());     a = 0;     b = v.size() - 1;     sum += o * (o - 1) / 2;     if (v.size() > 1) {       while (a < b) {         if (v[a] > 0 || v[b] < 0)           break;         else {           if (v[a] + v[b] < 0)             a++;           else if (v[a] + v[b] > 0)             b--;           else {             p = 1;             q = 1;             x = v[a];             a++;             y = v[b];             b--;             while (1) {               if (v[a] == x) {                 p++;                 a++;               } else                 break;             }             while (1) {               if (v[b] == y) {                 q++;                 b--;               } else                 break;             }             sum += p * q;           }         }       }     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4 * 1000 * 100 + 10;   int n, c[N], st[N], en[N], who[N], TM;   vector<int> adj[N];   void dfs(int root, int par = 0) {     st[root] = TM++;     who[st[root]] = root;     for (auto u : adj[root])       if (u ^ par) dfs(u, root);     en[root] = TM;   }   struct Node {     int lazy = -1;     long long lol = 0;     void merge(Node L, Node R) { lol = L.lol | R.lol; }     void add(int x) {       if (x == -1) return;       lazy = x;       lol = 1LL << x;     }   } seg[N << 2];   void push(int root) {     seg[root << 1].add(seg[root].lazy), seg[root << 1 | 1].add(seg[root].lazy);     seg[root].lazy = -1;   }   void build(int l = 0, int r = n, int root = 1) {     if (l + 1 == r) {       seg[root].add(c[who[l]]);       return;     }     int mid = l + r >> 1;     build(l, mid, root << 1), build(mid, r, root << 1 | 1);     seg[root].merge(seg[root << 1], seg[root << 1 | 1]);   }   void upd(int s, int e, int w, int l = 0, int r = n, int root = 1) {     if (s <= l && e >= r) {       seg[root].add(w);       return;     }     if (s >= r || e <= l) return;     push(root);     int mid = l + r >> 1;     upd(s, e, w, l, mid, root << 1), upd(s, e, w, mid, r, root << 1 | 1);     seg[root].merge(seg[root << 1], seg[root << 1 | 1]);   }   Node get(int s, int e, int l = 0, int r = n, int root = 1) {     if (s <= l && e >= r) return seg[root];     if (s >= r || e <= l) return seg[0];     push(root);     int mid = l + r >> 1;     Node res;     res.merge(get(s, e, l, mid, root << 1), get(s, e, mid, r, root << 1 | 1));     return res;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int Q;     cin >> n >> Q;     for (int i = 1; i <= n; i++) cin >> c[i];     for (int i = 1, v, u; i < n; i++) {       cin >> v >> u;       adj[v].push_back(u);       adj[u].push_back(v);     }     dfs(1);     build();     while (Q--) {       int t, v, c;       cin >> t;       if (t == 1) {         cin >> v >> c;         upd(st[v], en[v], c);       } else {         cin >> v;         cout << __builtin_popcountll(get(st[v], en[v]).lol) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int num = 0, num1, num2;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  A ) {         num1 = 0;         for (int j = 0; j < i; j++)           if (s[j] ==  Q ) num1++;         num2 = 0;         for (int j = i + 1; j < s.size(); j++)           if (s[j] ==  Q ) num2++;         num += (num1 * num2);       }     }     cout << num;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using ld = long double;   const ll llinf = (1ll << 61) - 1;   const double eps = 1e-6, ldeps = 1e-9;   template <class C, size_t Y>   struct tp {     void operator()(ostream &os, const C &t) {       tp<C, Y - 1>()(os, t);       os <<  ,   << get<Y - 1>(t);     }   };   template <class C>   struct tp<C, 1> {     void operator()(ostream &os, const C &t) { os << get<0>(t); }   };   template <class... C>   ostream &operator<<(ostream &os, const tuple<C...> &t) {     os <<  { , tp<decltype(t), sizeof...(C)>()(os, t);     return os <<  } ;   }   struct Dbg {     static constexpr auto &os = cout;     template <class C>     static auto dud(C *x) -> decltype(os << *x, 0);     template <class C>     static char dud(...);     template <class C>     typename enable_if<sizeof dud<C>(0) != 1, Dbg &>::type operator<<(         const C &x) {       os << x;       return *this;     }     template <class C>     Dbg &dump(C b, C e) {       *this <<   n[ ;       int cur = 0;       for (C i = b; i != e and cur < 20; i++, cur++)         *this <<  ,   + 2 * (i == b) << *i;       return *this <<  ] ;     }     template <class C>     typename enable_if<sizeof dud<C>(0) == 1, Dbg &>::type operator<<(         const C &x) {       return dump(begin(x), end(x));     }     template <class C, size_t X>     typename enable_if<sizeof(C) != 1, Dbg &>::type operator<<(C (&x)[X]) {       return dump(begin(x), end(x));     }     template <class B, class C>     Dbg &operator<<(const pair<B, C> &x) {       return *this <<  {  << x.first <<  ,   << x.second <<  } ;     }     Dbg &operator<<(ostream &(*x)(std::ostream &)) {       os << x;       return *this;     }   } dbg;   void err(istringstream *iss) { delete iss; }   template <class C, class... Args>   void err(istringstream *iss, const C &val, const Args &...args) {     string name;     *iss >> name;     if (name.back() ==  , ) name.pop_back();     dbg << name <<   =   << val <<  ;  , err(iss, args...);   }   int n, m, K, T, Q, cn;   const int inf = 1000000007, mxn = 53;   char s1[mxn], s2[mxn];   int s1l, s2l, rp[30][30], dp1[mxn][mxn], dp2[mxn][mxn];   int memo[mxn][mxn];   bitset<mxn> vstd[mxn];   int dp(int at1, int at2) {     if (at1 == s1l or at2 == s2l) return at1 == s1l and at2 == s2l ? 0 : inf;     int &ret = memo[at1][at2];     if (vstd[at1][at2]) return ret;     vstd[at1][at2] = 1;     ret = inf;     for (int i = at1; i <= s1l - 1; i++) {       for (int j = at2; j <= s2l - 1; j++) {         if ((dp1[at1][i] & dp2[at2][j])) ret = min(ret, 1 + dp(i + 1, j + 1));       }     }     return ret;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.precision(11);     cin >> s1 >> s2 >> n;     for (int i = 0; i < n; i++) {       string tmp;       cin >> tmp;       rp[tmp[3] -  a ][tmp[4] -  a ] |= 1 << (tmp[0] -  a );     }     s1l = int(strlen(s1)), s2l = int(strlen(s2));     for (int L = 1; L <= s1l; L += 1) {       for (int i = 0, j = i + L - 1; j < s1l; i++, j++) {         if (L == 1) {           dp1[i][j] |= 1 << (s1[i] -  a );           continue;         }         for (int k = i; k <= j - 1; k++) {           for (int l = 0; l < 26; l++) {             if ((dp1[i][k] >> l) & 1)               for (m = 0; m < 26; m++) {                 if ((dp1[k + 1][j] >> m) & 1) dp1[i][j] |= rp[l][m];               }           }         }       }     }     for (int L = 1; L <= s2l; L += 1) {       for (int i = 0, j = i + L - 1; j < s2l; i++, j++) {         if (L == 1) {           dp2[i][j] |= 1 << (s2[i] -  a );           continue;         }         for (int k = i; k <= j - 1; k++) {           for (int l = 0; l < 26; l++) {             if ((dp2[i][k] >> l) & 1)               for (m = 0; m < 26; m++) {                 if ((dp2[k + 1][j] >> m) & 1) dp2[i][j] |= rp[l][m];               }           }         }       }     }     int ans = dp(0, 0);     cout << (ans == inf ? -1 : ans) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int a[maxn];   int n, x, k;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> x >> k;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     long long ans = 0;     for (int i = 0; i < n; i++) {       long long l = (a[i] - 1) / x;       long long r = l + k;       ans += (long long)(lower_bound(a, a + n, (r + 1) * x) -                          lower_bound(a, a + n, max(r * x, (long long)a[i])));     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout << fixed;     int a1, a2;     cin >> a1 >> a2;     int minutes = 0;     while (a1 > 0 && a2 > 0) {       if (a1 == 1 && a2 == 1) {         break;       }       if (a1 <= 2) {         a1 += 1;         a2 -= 2;       } else if (a2 <= 2) {         a2 += 1;         a1 -= 2;       } else {         a1 += 1;         a2 -= 2;       }       minutes++;     }     cout << minutes;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300 * 1000 + 100;   const long long mod = 1e9 + 7;   const long long inf = 2 * 1e18;   int n, m, k;   int ans = -1;   char c[maxn];   vector<int> adj[maxn];   int cnt[30][maxn];   int d_in[maxn];   bool mark[maxn], mark1[maxn];   void dfs(int v) {     if (mark[v]) {       cout << -1;       exit(0);     } else       mark[v] = true;     if (mark1[v]) {       mark[v] = false;       return;     } else       mark1[v] = true;     for (auto x : adj[v]) {       dfs(x);       for (int j = 0; j <= 26; j++) {         cnt[j][v] = max(cnt[j][v], cnt[j][x]);         ans = max(ans, cnt[j][v]);       }     }     cnt[c[v] -  a ][v]++;     ans = max(ans, cnt[c[v] -  a ][v]);     mark[v] = false;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     string s;     cin >> s;     for (int i = 1; i <= n; i++) c[i] = s[i - 1];     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       d_in[v]++;     }     for (int i = 1; i <= n; i++) {       dfs(i);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   bool is_prime(int n) {     if (n < 2) {       return false;     }     for (int d = 2; d * d <= n; d++) {       if (n % d == 0) {         return false;       }     }     return true;   }   int main() {     int n;     std::cin >> n;     int m = n, cross = 0;     while (!is_prime(m + cross)) {       cross++;     }     assert(2 * cross <= n);     std::cout << m + cross << std::endl;     for (int i = 1; i <= n; i++) {       std::cout << i <<     << i % n + 1 << std::endl;     }     int jump = std::max(2, cross);     for (int i = 1; i <= cross; i++) {       assert(i < 1 + jump);       assert(i + jump <= n);       std::cout << i <<     << i + jump << std::endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const long long OO = 1LL << 61;   const long long MOD = 10007;   const int maxn = 100000 + 5;   long long dp[(1 << (16)) + 6];   int ans[20], g[20], mark[20], full;   int main() {     int n, m, a, b, f;     long long y;     while (scanf( %d %I64d %d , &n, &y, &m) != EOF) {       memset(g, 0, sizeof g);       memset(ans, -1, sizeof ans);       memset(mark, 0, sizeof mark);       for (int i = 0; i < m; i++) {         scanf( %d %d , &a, &b);         g[--b] |= (1 << (--a));       }       f = 1;       y -= 2001;       full = (1 << (n)) - 1;       for (int i = 0; i < n && f; i++) {         for (ans[i] = 0;; ans[i]++)           if (!mark[ans[i]]) {             if (ans[i] >= n) {               f = 0;               puts( The times have changed );               break;             }             memset(dp, 0, sizeof dp);             dp[0] = 1;             for (int s = 0; s <= full; s++)               if (dp[s]) {                 int cnt = __builtin_popcount(s);                 for (int k = 0; k < n; k++)                   if (!(s & (1 << (k))))                     if ((ans[k] == -1 || ans[k] == cnt) && ((s & g[k]) == g[k]))                       dp[s | (1 << (k))] += dp[s];               }             if (y >= dp[full])               y -= dp[full];             else {               mark[ans[i]] = 1;               break;             }           }       }       if (!f) continue;       for (int i = 0; i < n; i++)         printf( %d%c , ans[i] + 1, i + 1 == n ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int s[105];   int main() {     int n, x;     while (cin >> n >> x) {       for (int i = 0; i < n; i++) {         cin >> s[i];       }       sort(s, s + n);       int index = lower_bound(s, s + n, x) - s;       if (s[index] == x) {         cout << 1 + x - index << endl;       } else {         cout << x - index << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[111111];   int b[111111];   int main() {     int n, i, j;     vector<pair<int, int> > v;     scanf( %d , &n);     a[0] = a[1] = 1;     for (i = 2; i <= n; i++) {       if (a[i] == 0) {         for (j = i * 2; j <= n; j += i) a[j] = 1;       }     }     for (i = n / 2; i > 0; i--) {       if (a[i] == 0) {         vector<int> w;         for (j = i; j <= n; j += i) {           if (b[j] == 0) w.push_back(j);         }         if (w.size() % 2 == 0) {           for (j = 0; j < w.size(); j += 2) {             v.push_back(make_pair(w[j], w[j + 1]));             b[w[j]] = b[w[j + 1]] = 1;           }         } else {           for (j = 0; j < w.size(); j++) {             if (w[j] % 2 == 0) {               swap(w[j], w.back());               break;             }           }           for (j = 0; j < w.size() - 1; j += 2) {             v.push_back(make_pair(w[j], w[j + 1]));             b[w[j]] = b[w[j + 1]] = 1;           }         }       }     }     printf( %d n , v.size());     for (i = 0; i < v.size(); i++) printf( %d %d n , v[i].first, v[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos((double)(-1));   const int maxn = 100010;   const int mod = 1e9 + 7;   int moven2[10][5] = {{1, 0, 0},  {-1, 0, 0}, {0, 1, 0},                        {0, -1, 0}, {0, 0, 1},  {0, 0, -1}};   int moven1[10][5] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   int n, m, q, f[2 * maxn];   map<string, int> mp;   string a, b;   int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }   void Union(int x, int y) {     int fx = find(x);     int fy = find(y);     f[fx] = fy;   }   int main() {     cin >> n >> m >> q;     for (int i = 1; i <= n; i++) {       cin >> a;       mp[a] = i;     }     for (int i = 1; i <= 2 * n; i++) f[i] = i;     for (int i = 1, t; i <= m; i++) {       cin >> t >> a >> b;       int x = mp[a];       int y = mp[b];       if (t == 1) {         if (find(x) == find(y + n) || find(y) == find(x + n))           cout <<  NO                 <<   n ;         else {           cout <<  YES                 <<   n ;           Union(x, y);           Union(x + n, y + n);         }       } else {         if (find(x) == find(y) || find(x + n) == find(y + n))           cout <<  NO                 <<   n ;         else {           cout <<  YES                 <<   n ;           Union(x + n, y);           Union(x, y + n);         }       }     }     for (int i = 1; i <= q; i++) {       cin >> a >> b;       int x = mp[a];       int y = mp[b];       if (find(x) == find(y) || find(x + n) == find(y + n))         cout << 1 <<   n ;       else if (find(x + n) == find(y) || find(x) == find(y + n))         cout << 2 <<   n ;       else         cout << 3 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     int res = 0, cur = 0, tmp;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> tmp;       res = (cur + tmp) / m;       cur = (cur + tmp) % m;       cout << res <<    ;     }   }


#include <bits/stdc++.h>   int main() {     int n, count = 0, i = 0, ans, flag = 1;     char s[201];     scanf( %d %s , &n, s);     while (s[i] !=   0 ) {       if (s[i] ==  x ) count++;       i++;     }     if (n / 2 > count) {       ans = n / 2 - count;       flag = 0;     } else       ans = count - n / 2;     printf( %d n , ans);     i = 0;     while (n-- && ans) {       if (s[i] ==  x  && flag) {         s[i] =  X ;         ans--;       } else if (s[i] ==  X  && !flag) {         s[i] =  x ;         ans--;       }       i++;     }     printf( %s n , s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9 + 7;   const int maxn = 5e1 + 10;   const int maxq = 1e3 + 10;   const int alf = 26;   const long long dlm = 1e9 + 7;   const int del = 998244353;   const int eps = 1e-7;   char t[maxn][maxn];   char g[maxn][maxn];   char t2[maxn][maxn];   int n;   void rot() {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         t2[j][n + 1 - i] = t[i][j];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         t[i][j] = t2[i][j];       }     }   }   int flh() {     for (int i1 = 1, i2 = n; i1 < i2; i1++, i2--) {       for (int j = 1; j <= n; j++) {         swap(t[i1][j], t[i2][j]);       }     }   }   int flv() {     for (int i = 1; i <= n; i++) {       for (int j1 = 1, j2 = n; j1 < j2; j1++, j2--) {         swap(t[i][j1], t[i][j2]);       }     }   }   int same() {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (t[i][j] != g[i][j]) return 0;       }     }     return 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       string st;       cin >> st;       for (int j = 1; j <= n; j++) {         t[i][j] = st[j - 1];       }     }     for (int i = 1; i <= n; i++) {       string st;       cin >> st;       for (int j = 1; j <= n; j++) {         g[i][j] = st[j - 1];       }     }     for (int vaf = 0; vaf < 2; vaf++) {       for (int haf = 0; haf < 2; haf++) {         for (int r = 0; r < 4; r++) {           if (same() == 1) {             return cout <<  Yes , 0;           }           rot();         }         flh();       }       flv();     }     cout <<  No ;   }


#include <bits/stdc++.h>   using namespace std;   int ntest = 0, test = 0;   inline void init();   inline void run();   inline void stop() { ntest = test - 1; }   int main() {     init();     while (++test <= ntest) {       run();     }     return 0;   }   const int INF = (int)1E9 + 5;   const double EPS = 1E-11;   const long long MOD = (long long)1E9 + 7;   const int dx[] = {-1, 0, 0, 1};   const int dy[] = {0, -1, 1, 0};   inline void init() { ntest = 1; }   int cnt[(int)(1e6 + 5)];   inline void run() {     int n, m, a, b;     cin >> n >> m;     for (int i = 0; i < (m); i++) {       scanf( %d%d , &a, &b);       cnt[a]++;       cnt[b]++;     }     long long x = 0;     for (int i = (1); i <= (n); i++) x += (n - 1 - cnt[i]) * cnt[i];     x /= 2;     cout << (n - 1ll) * n * (n - 2ll) / 6 - x;   }


#include <bits/stdc++.h>   using namespace std;   int n, qc;   int a[100005];   int freq[100005], ord[100005], inv[100005];   int cnt[100005] = {}, small[100005] = {};   int from[100005], to[100005];   const int ROOT = 320;   const int BIG_COUNT = 100;   const int SMALL = (100000 + BIG_COUNT - 1) / BIG_COUNT;   inline bool cmp(const int &lhs, const int &rhs) {     return freq[lhs] > freq[rhs];   }   inline bool qcmp(const int &lhs, const int &rhs) {     if (from[lhs] / ROOT != from[rhs] / ROOT) return from[lhs] < from[rhs];     return to[lhs] < to[rhs];   }   int l = 0, r = -1;   void extendRight() {     ++r;     if (a[r] >= BIG_COUNT) {       --small[cnt[a[r]]];       ++small[cnt[a[r]] + 1];     }     ++cnt[a[r]];   }   void extendLeft() {     --l;     if (a[l] >= BIG_COUNT) {       --small[cnt[a[l]]];       ++small[cnt[a[l]] + 1];     }     ++cnt[a[l]];   }   void shrinkRight() {     if (a[r] >= BIG_COUNT) {       --small[cnt[a[r]]];       ++small[cnt[a[r]] - 1];     }     --cnt[a[r]];     --r;   }   void shrinkLeft() {     if (a[l] >= BIG_COUNT) {       --small[cnt[a[l]]];       ++small[cnt[a[l]] - 1];     }     --cnt[a[l]];     ++l;   }   priority_queue<int, vector<int>, greater<int> > q;   int c[SMALL + 1];   int res[100005];   int main() {     scanf( %d , &n);     for (int i = 0; i < (int)(n); ++i) scanf( %d , a + i), --a[i];     for (int i = 0; i < (int)(n); ++i) ++freq[a[i]];     for (int i = 0; i < (int)(100000); ++i) ord[i] = i;     sort(ord, ord + 100000, cmp);     for (int i = 0; i < (int)(100000); ++i) inv[ord[i]] = i;     for (int i = 0; i < (int)(n); ++i) a[i] = inv[a[i]];     scanf( %d , &qc);     for (int i = 0; i < (int)(qc); ++i)       scanf( %d%d , from + i, to + i), --from[i], --to[i];     for (int i = 0; i < (int)(qc); ++i) ord[i] = i;     sort(ord, ord + qc, qcmp);     for (int ii = 0; ii < (int)(qc); ++ii) {       int i = ord[ii];       while (r < to[i]) extendRight();       while (l > from[i]) extendLeft();       while (r > to[i]) shrinkRight();       while (l < from[i]) shrinkLeft();       for (int j = 1; j <= SMALL; ++j) {         c[j] = small[j];       }       int ans = 0;       int rem = -1;       for (int i = 0; i < (int)(BIG_COUNT); ++i)         if (cnt[i] <= SMALL) {           ++c[cnt[i]];         } else {           q.push(cnt[i]);         }       for (int j = 1; j <= SMALL; ++j)         if (c[j]) {           if (rem != -1) {             --c[j];             ans += j + rem;             if (j + rem <= SMALL) {               ++c[j + rem];             } else {               q.push(j + rem);             }           }           ans += j * (c[j] & ~1);           int nj = j << 1;           if (nj <= SMALL) {             c[nj] += c[j] >> 1;           } else {             for (int times = 0; times < (int)(c[j] >> 1); ++times) {               q.push(nj);             }           }           if (c[j] & 1) {             rem = j;           } else {             rem = -1;           }         }       if (rem != -1) {         q.push(rem);       }       while ((int)q.size() > 1) {         int a = q.top();         q.pop();         int b = q.top();         q.pop();         ans += a + b;         q.push(a + b);       }       assert(!q.empty());       q.pop();       res[i] = ans;     }     for (int i = 0; i < (int)(qc); ++i) {       printf( %d n , res[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ring {     int c1;     int c2;     int r1;     int r2;   };   int contour(struct ring a, struct ring b, double dist) {     int cnt = 0;     if (dist >= a.r2 + b.r2 || dist <= b.r1 - a.r2 || dist <= a.r2 - b.r2) cnt++;     if (dist >= a.r1 + b.r2 || dist <= b.r1 - a.r1 || dist <= a.r1 - b.r2) cnt++;     return cnt;   }   int main() {     struct ring a, b;     cin >> a.c1 >> a.c2 >> a.r1 >> a.r2;     cin >> b.c1 >> b.c2 >> b.r1 >> b.r2;     double dist =         sqrt((a.c1 - b.c1) * (a.c1 - b.c1) + (a.c2 - b.c2) * (a.c2 - b.c2));     int ans = contour(a, b, dist) + contour(b, a, dist);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline void write(int a) {     if (a >= 10) write(a / 10);     putchar( 0  + a % 10);   }   inline void writeln(int a) {     write(a);     puts(  );   }   int n, ans;   struct data {     int bo;     string first;   };   map<string, data> M;   const int N = 1005;   string a[N], b[N], t;   map<string, bool> MM;   int main() {     n = read();     for (int i = 1; i <= n; i++) {       cin >> a[i] >> b[i];       if (M[a[i]].bo)         t = M[a[i]].first;       else         t = a[i];       M[a[i]] = (data){0, a[i]};       M[b[i]] = (data){1, t};     }     for (int i = 1; i <= n; i++) {       if (MM[b[i]])         continue;       else         MM[b[i]] = 1;       if (M[b[i]].bo) ans++;     }     MM.clear();     writeln(ans);     for (int i = 1; i <= n; i++)       if (M[b[i]].bo && MM[b[i]] == 0) {         MM[b[i]] = 1;         cout << M[b[i]].first <<     << b[i] << endl;       }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   int n, m;   double dp_mai[155], dp_cul[155];   int d_mai[155], d_cul[155];   bool adj[155][155], used[155];   void dijk(int source, int *d, double *dp) {     fill(d + 1, d + n + 1, INF);     memset(used, 0, sizeof(used));     d[source] = 0;     dp[source] = 1.;     for (int(i) = 0; (i) < (n); i++) {       int id, low = INF;       for (int(j) = (1); (j) <= (n); j++) {         if (used[j]) continue;         if (low > d[j]) {           low = d[j];           id = j;         }       }       used[id] = true;       for (int(j) = (1); (j) <= (n); j++) {         if (used[j] || !adj[id][j]) continue;         if (d[j] > d[id] + 1) {           d[j] = d[id] + 1;           dp[j] = dp[id];         } else if (d[j] == d[id] + 1) {           dp[j] += dp[id];         }       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     int x, y;     for (int(i) = 0; (i) < (m); i++) {       cin >> x >> y;       adj[x][y] = adj[y][x] = true;     }     dijk(n, d_mai, dp_mai);     dijk(1, d_cul, dp_cul);     double res = 0.;     for (int(i) = (1); (i) <= (n); i++) {       double temp = 0.;       for (int(j) = (1); (j) <= (n); j++) {         if (!adj[i][j]) continue;         if (d_mai[i] + d_cul[j] + 1 == d_mai[1]) temp += dp_mai[i] * dp_cul[j];         if (d_cul[i] + d_mai[j] + 1 == d_cul[n]) temp += dp_cul[i] * dp_mai[j];       }       res = max(res, temp);     }     cout << fixed << setprecision(10) << res / dp_mai[1] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   using ll = long long;   using pll = pair<ll, ll>;   template <class T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (const T &t : v) os <<   t  << t;     return os << endl;   }   template <class T>   istream &operator>>(istream &is, vector<T> &v) {     for (T &a : v) is >> a;     return is;   }   template <class T, class U>   ostream &operator<<(ostream &os, const pair<T, U> &v) {     return os <<  <  << v.first <<     << v.second <<  > ;   }   bool solve() {     int q;     cin >> q;     map<pll, ll> cost;     for (int i = 0; i < (int)(q); i++) {       int t;       cin >> t;       if (t == 1) {         ll v, u, w;         cin >> v >> u >> w;         set<ll> visited;         {           ll vv = v;           while (vv) {             visited.insert(vv);             vv /= 2;           }         }         ll lca = -1;         {           ll uu = u;           while (!visited.count(uu)) uu /= 2;           lca = uu;         }         assert(lca > 0);         while (v > lca) {           cost[make_pair(v / 2, v)] += w;           v /= 2;         }         while (u > lca) {           cost[make_pair(u / 2, u)] += w;           u /= 2;         }       } else if (t == 2) {         ll v, u;         cin >> v >> u;         ll sum = 0;         set<ll> visited;         {           ll vv = v;           while (vv) {             visited.insert(vv);             vv /= 2;           }         }         ll lca = -1;         {           ll uu = u;           while (!visited.count(uu)) uu /= 2;           lca = uu;         }         assert(lca > 0);         while (v > lca) {           sum += cost[make_pair(v / 2, v)];           v /= 2;         }         while (u > lca) {           sum += cost[make_pair(u / 2, u)];           u /= 2;         }         cout << sum << endl;       } else         assert(0);     }     return false;   }   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     while (solve())       ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(const pair<int, int>& p1, const pair<int, int>& p2) {     return p1.first < p2.first;   }   struct node {     int a;     int b;   };   bool operator<(const node& x, const node& y) { return x.a > y.a; }   int sol(int x) {     int ans = 0;     if (x == 0) return 10;     if (x == 100) return 0;     if (x % 10 == 0) return 10;     while (x > ans) ans += 10;     return ans - x;   }   int main() {     int n, k;     scanf( %d , &n);     scanf( %d , &k);     priority_queue<node> q;     for (int i = 0; i < n; i++) {       int x;       node xx;       scanf( %d , &x);       int z;       z = sol(x);       xx.a = z;       xx.b = x;       q.push(xx);     }     int ans = 0;     while (k > 0 && !q.empty()) {       int xx = q.top().a;       int yy = q.top().b;       if (xx > k) break;       if (xx == 0) {         ans += (yy / 10);         q.pop();         continue;       }       node my;       my.b = yy + xx;       my.a = sol(my.b);       q.pop();       q.push(my);       k -= xx;     }     while (!q.empty()) {       ans += (q.top().b) / 10;       q.pop();     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   inline int min(const int &first, const int &second) {     return (((second - first) >> (32 - 1)) & (first ^ second)) ^ first;   }   inline int max(const int &first, const int &second) {     return (((second - first) >> (32 - 1)) & (first ^ second)) ^ second;   }   inline long long min(const long long &first, const long long &second) {     return (((second - first) >> (64 - 1)) & (first ^ second)) ^ first;   }   inline long long max(const long long &first, const long long &second) {     return (((second - first) >> (64 - 1)) & (first ^ second)) ^ second;   }   using namespace std;   char string_in_buffer[(int)260];   void fast_scan(int &first) { scanf( %d , &first); }   void fast_scan(long long &first) { scanf( %lld , &first); }   void fast_scan(unsigned long long &first) { scanf( %llu , &first); }   void fast_scan(double &first) { scanf( %lf , &first); }   void fast_scan(long double &first) { scanf( %Lf , &first); }   void fast_scan(char &first) {     scanf( %c , &first);     if (first ==   n ) {       fast_scan(first);     }   }   void fast_scan(string &first) {     scanf( %s , string_in_buffer);     first = string(string_in_buffer);   }   template <class TFirst, class TSecond>   void fast_scan(pair<TFirst, TSecond> &p) {     fast_scan(p.first);     fast_scan(p.second);   }   template <class T>   void fast_scan(vector<T> &v) {     for (auto &first : v) fast_scan(first);   }   void fast_print(const int &first) { printf( %d , first); }   void fast_print(const unsigned int &first) { printf( %u , first); }   void fast_print(const long long &first) { printf( %lld , first); }   void fast_print(const unsigned long long &first) { printf( %llu , first); }   void fast_print(const double &first) { printf( %.15lf , first); }   void fast_print(const long double &first) { printf( %.15Lf , first); }   void fast_print(const char &first) { printf( %c , first); };   void fast_print(const string &first) { printf( %s , first.c_str()); }   void fast_print(const char v[]) { fast_print((string)v); }   template <class TFirst, class TSecond>   void fast_print(const pair<TFirst, TSecond> &p) {     fast_print(p.first);     fast_print(   );     fast_print(p.second);   }   template <class T>   void fast_print(const vector<T> &v) {     if (v.empty()) return;     fast_print(v[0]);     for (int i = 1; i < v.size(); i++) {       fast_print(   );       fast_print(v[i]);     }   }   template <class T>   void fast_print(const vector<vector<T>> &v) {     if (v.empty()) return;     fast_print(v[0]);     for (int i = 1; i < v.size(); i++) {       fast_print(  n );       fast_print(v[i]);     }   }   template <class T>   void fast_print(const T &v) {     for (const auto &first : v) {       fast_print(first);       fast_print(   );     }   }   using namespace std;   namespace smart_io {   string print_start =   ;   string sep =    ;   bool first_print = false;   void precall_print() {     fast_print(print_start);     print_start =   n ;     first_print = true;   }   void _print(deque<string>) {}   template <class T, class... Args>   void _print(deque<string> names, T elem, Args... args) {     if (!first_print) {       fast_print(  n );     } else {       first_print = false;     }     fast_print(names.front());     fast_print(  =  );     fast_print(elem);     names.pop_front();     _print(names, args...);   }   }  // namespace smart_io   template <class T>   ostream &operator,(ostream &os, const T &object) {     if (!smart_io::first_print) {       fast_print(smart_io::sep);     } else {       smart_io::first_print = false;     }     fast_print(object);     return os;   }   template <class T>   istream &operator,(istream &is, T &object) {     fast_scan(object);     return is;   }   namespace escape__from__random__aetuhoetnuhshe {   using namespace std::chrono;   mt19937 rng(duration_cast<milliseconds>(system_clock::now().time_since_epoch())                   .count());   uniform_real_distribution<> prob_dist(0.0, 1.0);   };  // namespace escape__from__random__aetuhoetnuhshe   namespace typedefs {}   namespace numbers_operation {   template <class T>   T floor_mod(T a, T b) {     if (a >= 0 && b >= 0) return a % b;     if (a <= 0 && b <= 0) return a % b;     return abs(b) - (abs(a) % abs(b));   }   }  // namespace numbers_operation   using namespace numbers_operation;   using namespace typedefs;   using namespace escape__from__random__aetuhoetnuhshe;   const int N = (1 << 18);   int T[2 * N + 1], M[2 * N + 1];   void push(int i, int tl, int tr) {     if (tl + 1 != tr) {       M[i * 2 + 1] = max(M[i * 2 + 1], M[i]);       M[i * 2 + 2] = max(M[i * 2 + 2], M[i]);     } else {       T[i] = max(T[i], M[i]);     }     M[i] = -1;   }   void change(int i, int tl, int tr, int j, int value) {     push(i, tl, tr);     if (tl + 1 == tr) {       T[i] = value;     } else {       int m = (tl + tr) / 2;       if (j < m)         change(i * 2 + 1, tl, m, j, value);       else         change(i * 2 + 2, m, tr, j, value);     }   }   int get(int i, int tl, int tr, int j) {     push(i, tl, tr);     if (tl + 1 == tr) return T[i];     int m = (tl + tr) / 2;     if (j < m)       return get(i * 2 + 1, tl, m, j);     else       return get(i * 2 + 2, m, tr, j);   }   signed main(signed argc, char *argv[]) {     int n;     cin, n;     vector<int> v(n);     cin, v;     for (int i = 0; i < n; i++) change(0, 0, N, i, v[i]);     int q;     cin, q;     for (int i = 0; i < q; i++) {       int type;       cin, type;       if (type == 1) {         int p, first;         cin, p, first;         p--;         change(0, 0, N, p, first);       } else {         int first;         cin, first;         M[0] = max(M[0], first);       }     }     for (int i = 0; i < n; i++) {       smart_io::precall_print();       cout, get(0, 0, N, i);       smart_io::print_start =    ;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   using ll = long long;   using ull = unsigned long long;   using db = double;   using ld = long double;   template <typename T>   using V = vector<T>;   template <typename T>   using VV = vector<vector<T>>;   constexpr ll mod = 1000000007;   constexpr ll INF = 1000000099;   constexpr ll LINF = (ll)(1e18 + 99);   const ld PI = acos((ld)-1);   const vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};   template <typename T, typename U>   inline bool chmin(T& t, const U& u) {     if (t > u) {       t = u;       return 1;     }     return 0;   }   template <typename T, typename U>   inline bool chmax(T& t, const U& u) {     if (t < u) {       t = u;       return 1;     }     return 0;   }   template <typename T>   inline T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   inline void yes() { cout <<  YES  <<   n ; }   inline void no() { cout <<  NO  <<   n ; }   template <typename T, typename Y>   inline T mpow(T a, Y n) {     T res = 1;     for (; n; n >>= 1) {       if (n & 1) res = res * a;       a = a * a;     }     return res;   }   template <typename T>   V<T> prefix_sum(const V<T>& v) {     int n = v.size();     V<T> ret(n + 1);     for (ll i = 0; i < (ll)(n); ++i) ret[i + 1] = ret[i] + v[i];     return ret;   }   template <typename T>   istream& operator>>(istream& is, vector<T>& vec) {     for (auto&& x : vec) is >> x;     return is;   }   template <typename T, typename Y>   ostream& operator<<(ostream& os, const pair<T, Y>& p) {     return os <<  {  << p.first <<  ,  << p.second <<  } ;   }   template <typename T>   ostream& operator<<(ostream& os, const V<T>& v) {     os <<  { ;     for (auto e : v) os << e <<  , ;     return os <<  } ;   }   template <typename... Args>   void debug(Args&... args) {     for (auto const& x : {args...}) {       cerr << x <<    ;     }     cerr <<   n ;   }   template <typename T, typename Y, T(F_up)(T, T), Y(F_gt)(T, Y)>   struct BUPSegTree {     int sz, ex;     T ini_d;     vector<T> dat;     BUPSegTree(vector<T> init, T _ini_d) : ini_d(_ini_d) {       int n = (int)(init.size());       ex = 1;       while ((1 << ex) < n) ex++;       sz = (1 << ex);       dat = vector<T>(2 * sz, ini_d);       for (int i = 0; i < n; ++i) dat[sz + i] = init[i];       for (int i = sz - 1; i > 0; --i) dat[i] = F_up(dat[2 * i], dat[2 * i + 1]);     }     void up_q(int p, T x) {       for (dat[p += sz] = x; p > 1; p >>= 1) {         dat[p >> 1] = F_up(dat[p], dat[p ^ 1]);       }     }     T get_q(int l, int r) {       T res = ini_d;       for (l += sz, r += sz; l < r; l >>= 1, r >>= 1) {         if (l & 1) {           res = F_gt(res, dat[l]);           ++l;         }         if (r & 1) {           --r;           res = F_gt(res, dat[r]);         }       }       return res;     }   };   ll my_max(ll a, ll b) { return max(a, b); }   signed main() {     cin.tie(0);     cerr.tie(0);     ios::sync_with_stdio(false);     cout << fixed << setprecision(20);     ll n;     cin >> n;     set<int> addse;     V<int> buyt(n);     V<int> addt(n);     BUPSegTree<ll, ll, my_max, my_max> buymx(V<ll>(n * 2, -1), -1);     for (ll i = 0; i < (ll)(n * 2); ++i) {       char c;       cin >> c;       if (c ==  + )         addse.insert(i);       else {         int x;         cin >> x;         --x;         buyt[x] = i;         buymx.up_q(i, x);       }     }     for (ll i = 0; i < (ll)(n); ++i) {       ll b = buyt[i];       auto itr = addse.lower_bound(b);       if (itr == addse.begin()) {         no();         return 0;       }       --itr;       ll a = *itr;       if (buymx.get_q(a, b) > i) {         no();         return 0;       }       addt[i] = a;       addse.erase(itr);     }     yes();     V<pair<int, int>> ans(0);     for (ll i = 0; i < (ll)(n); ++i) ans.emplace_back(addt[i], i);     sort((ans).begin(), (ans).end());     for (ll i = 0; i < (ll)(n); ++i) cout << ans[i].second + 1 <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int p[100009], a[100009], pos[100009], m, n, ri[100009], le[100009];   set<pair<int, int>> st;   inline bool cmp(const int& A, const int& B) { return p[A] < p[B]; }   int getdis(int x, int y) {     if (x == y) return 1000000000;     int d = (p[y] - p[x] + m) % m;     if (y < x) d = (d + a[y]) % m;     if (d <= a[x]) return 1;     if (a[x] <= a[y]) return 1000000000;     return (d - a[y] - 1) / (a[x] - a[y]) + 1;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d%d , p + i, a + i), pos[i] = i, p[i]--;     sort(pos + 1, pos + n + 1, cmp);     for (int i = 1; i <= n; i++) ri[pos[i]] = pos[i + 1], le[pos[i]] = pos[i - 1];     ri[pos[n]] = pos[1], le[pos[1]] = pos[n];     for (int i = 1; i <= n; i++) st.insert(make_pair(getdis(i, ri[i]), i));     while (1) {       if (st.begin()->first == 1000000000) break;       int u = st.begin()->second;       st.erase(st.begin());       st.erase(make_pair(getdis(ri[u], ri[ri[u]]), ri[u]));       if (!st.empty()) st.erase(make_pair(getdis(le[u], u), le[u]));       p[u] += getdis(u, ri[u]), p[u] %= m, a[u]--;       ri[u] = ri[ri[u]], le[ri[u]] = u;       st.insert(make_pair(getdis(le[u], u), le[u])),           st.insert(make_pair(getdis(u, ri[u]), u));     }     printf( %lu n , st.size());     for (set<pair<int, int>>::iterator it = st.begin(); it != st.end(); it++)       printf( %d  , it->second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double A[200009];   double B[200009];   int main() {     int N, i;     cin >> N;     for (i = 0; i < N; i++) {       cin >> A[i];     }     B[0] = A[0];     for (i = 1; i < N; i++) {       B[i] = (B[i - 1] + 1) * A[i];     }     double sum = 0;     for (i = 0; i < N; i++) {       sum += 2 * B[i];       sum -= A[i];     }     printf( %0.15lf n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int powm(long long int a, int b, int n) {     long long int rm = 1;     while (b) {       if (b % 2) {         rm = (rm * a) % n;       }       a = (a * a) % n;       b /= 2;     }     return rm;   }   int nxt[int(1e5 + 1000)] = {0}, g, r, tq[int(1e5 + 1000)];   long long int timedp[int(1e5 + 1000)], l[int(1e5 + 1000)], layer;   int seg[4 * int(1e5 + 1000)];   pair<int, int> diff[int(1e5 + 1000)];   int rev[int(1e5 + 1000)];   const long long int ninf = -10000000000000000L;   int mod;   void update(int node, int it, int f, int q, int val) {     if (it == f) {       seg[node] = val;       return;     }     int m = (it + f) / 2;     if (q <= m)       update(node * 2, it, m, q, val);     else       update(node * 2 + 1, m + 1, f, q, val);     seg[node] = min(seg[node * 2], seg[node * 2 + 1]);   }   int get(int node, int it, int f, int q1, int q2) {     if (it == q1 && f == q2) return seg[node];     int m = (it + f) / 2;     if (q2 <= m)       return get(node * 2, it, m, q1, q2);     else if (q1 > m)       return get(node * 2 + 1, m + 1, f, q1, q2);     else {       int val = get(node * 2, it, m, q1, m);       return min(val, get(node * 2 + 1, m + 1, f, m + 1, q2));     }   }   pair<int, int> go(int n, int l1, int r1) {     int it = 1, f = n + 1, m;     while (it != f) {       m = (it + f) / 2;       if (diff[m].first >= l1)         f = m;       else         it = m + 1;     }     int l1v = f;     it = 1, f = n + 1;     while (it != f) {       m = (it + f) / 2;       if (diff[m + 1].first <= r1)         it = m + 1;       else         f = m;     }     int r1v = f;     if (r1v < l1v) return make_pair(-1, -1);     return make_pair(l1v, r1v);   }   void insert(int node, int it, int f) {     if (it == f) {       seg[node] = diff[f].second;       return;     }     int m = (it + f) / 2;     insert(node * 2, it, m);     insert(node * 2 + 1, m + 1, f);     seg[node] = min(seg[node * 2], seg[node * 2 + 1]);   }   int main() {     int n, Q;     scanf( %d , &n);     ;     scanf( %d , &g);     ;     scanf( %d , &r);     ;     mod = g + r;     l[0] = 0;     int val;     for (int i = int(1); i <= (int)n + 1; i++) {       scanf( %d , &val);       ;       l[i] = val;       l[i] += l[i - 1];     }     layer = 0;     diff[n + 1] = make_pair(0, n + 1);     for (int i = n; i >= 1; --i) {       layer += l[i + 1] - l[i];       layer %= mod;       long long int l2 = -layer;       l2 = (l2 % mod + mod) % mod;       diff[i] = make_pair((int)l2, i);     }     sort(diff + 1, diff + n + 2);     for (int i = int(1); i <= (int)4 * int(1e5 + 1000) - 1; i++) seg[i] = 1e9;     for (int i = int(1); i <= (int)n + 1; i++) rev[diff[i].second] = i;     update(1, 1, n + 1, rev[n + 1], n + 1);     layer = 0;     int it, f, m;     nxt[n + 1] = n + 1;     timedp[n + 1] = 0;     for (int i = n; i >= 1; --i) {       layer += l[i + 1] - l[i];       layer %= mod;       update(1, 1, n + 1, rev[i], i);       int l1 = g + r + (g - layer), r1 = g + r - 1;       nxt[i] = 1e9;       if (r1 >= l1) {         pair<int, int> qu = go(n, l1, r1);         int l1v = qu.first, r1v = qu.second;         if (l1v != -1 && diff[l1v].first >= l1 && diff[r1v].first <= r1) {           nxt[i] = get(1, 1, n + 1, l1v, r1v);         }       }       int l2 = max(0, g - (int)layer), r2 = g + r - 1 - layer;       pair<int, int> qu = go(n, l2, r2);       int l2v = qu.first, r2v = qu.second;       if (l2v != -1 && diff[l2v].first >= l2 && diff[r2v].first <= r2)         nxt[i] = min(nxt[i], get(1, 1, n + 1, l2v, r2v));       if (nxt[i] > 2 * n) nxt[i] = n + 1;       timedp[i] = l[nxt[i]] - l[i];       if (nxt[i] < n + 1)         timedp[i] += (r + g - (l[nxt[i]] - l[i]) % mod) + timedp[nxt[i]];     }     scanf( %d , &Q);     ;     for (int i = int(1); i <= (int)Q; i++) scanf( %d , &tq[i]);     ;     layer = 0;     for (int i = 1; i <= n + 1; ++i) {       layer += l[i] - l[i - 1];       diff[i] = make_pair(layer % mod, i);     }     sort(diff + 1, diff + n + 2);     for (int i = int(1); i <= (int)n + 1; i++) rev[diff[i].second] = i;     insert(1, 1, n + 1);     int l1v, r1v;     for (int i = int(1); i <= (int)Q; i++) {       layer = tq[i] % mod;       int l1 = g + r + (g - layer), r1 = g + r - 1;       int nxt2 = 1e9;       l1v = r1v = 1e9;       if (r1 >= l1) {         pair<int, int> qu = go(n, l1, r1);         l1v = qu.first, r1v = qu.second;         if (l1v != -1 && diff[l1v].first >= l1 && diff[r1v].first <= r1) {           nxt2 = get(1, 1, n + 1, l1v, r1v);         }       }       int l2 = max(0, g - (int)layer), r2 = g + r - 1 - layer;       pair<int, int> qu = go(n, l2, r2);       int l2v = qu.first, r2v = qu.second;       if (l2v != -1 && diff[l2v].first >= l2 && diff[r2v].first <= r2)         nxt2 = min(nxt2, get(1, 1, n + 1, l2v, r2v));       if (nxt2 > 2 * n) nxt2 = n + 1;       long long int actual_time = tq[i] + l[nxt2];       if (nxt2 < n + 1)         actual_time += (g + r - (l[nxt2] + tq[i]) % mod) + timedp[nxt2];       printf( %lld n , actual_time);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[4000000];   int f[4000000];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int s, t;     cin >> s >> t;     s--;     t--;     long long ans = 0;     for (int i = s; i < t; i++) ans += a[i];     long long num = ans;     int pos = 1;     for (int i = 2; i <= n; i++) {       ans = ans - a[(t + 1 - i + n) % n] + a[(s + 1 - i + n) % n];       if (ans > num) {         ans = num;         pos = i;       }     }     cout << pos;     return 0;   }


#include <bits/stdc++.h>   inline long long MAX2(long long a, long long int b) {     return (a) > (b) ? (a) : (b);   }   inline long long MAX3(long long a, long long b, long long c) {     return (a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c));   }   inline long long MIN2(long long a, long long b) {     return (a) < (b) ? (a) : (b);   }   inline long long MIN3(long long a, long long b, long long c) {     return (a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c));   }   using namespace std;   int n, a, b;   int p[1000006];   pair<int, int> compute() {     if (n % b == 0) return pair<int, int>(0, n / b);     if (n % a == 0) return pair<int, int>(n / a, 0);     int div = (n / b);     int rem = (n % b);     int ch;     while (div > 0) {       ch = rem % a;       if (ch == 0) break;       div--;       rem += b;     }     if (div == 0) return pair<int, int>(-1, -1);     return pair<int, int>((rem / a), div);   }   void make(int i, int j) {     int k;     for (k = i; k < j; k++) {       p[k] = k + 1;     }     p[j] = i;   }   int main() {     cin >> n >> a >> b;     if (a > b) {       int temp = a;       a = b;       b = temp;     }     pair<int, int> cycles = compute();     if (cycles.first == -1) {       cout << -1;       return 0;     }     int i = 1;     while (i <= n) {       if (cycles.first > 0) {         make(i, i + a - 1);         cycles.first--;         i += a;       } else {         make(i, i + b - 1);         cycles.second--;         i += b;       }     }     for (i = 1; i < n + 1; i++) {       cout << p[i] <<    ;     }   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 1e4 + 5;   int a[N], b[N];   long long check(long long x, int n, int c) {     long long ans = 0;     for (int i = 1; i <= n; ++i) {       ans += x * a[i] / b[i] + 1;       if (ans > c) ans = c + 1;     }     return ans;   }   int main() {     int n, c;     scanf( %d%d , &n, &c);     long long sum = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &a[i], &b[i]);       sum += a[i];     }     long long limit = 1000000000000000000LL;     long long l, r;     if (check(1, n, c) >= c)       l = 1;     else {       long long head = 1, tail = limit / sum;       while (head < tail - 1) {         long long mid = head + tail >> 1;         if (check(mid, n, c) >= c)           tail = mid;         else           head = mid;       }       l = tail;     }     if (check(limit / sum, n, c) <= c)       r = limit / sum;     else {       long long head = 1, tail = limit / sum;       while (head < tail - 1) {         long long mid = head + tail >> 1;         if (check(mid, n, c) <= c)           head = mid;         else           tail = mid;       }       r = head;     }     long long ans = 0;     if (l <= r && check(l, n, c) == c && check(r, n, c) == c) ans = r - l + 1;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   int m;   int n;   map<int, int> id;   int rev[100500];   int a[2];   int w[100500], ans[100500];   set<int> s;   set<int> ss;   void go(int x) {     w[x] = 1;     x = rev[x];     s.insert(x);     for (int i = 0; i < (2); i++) {       int tmp = a[i] - x;       if (ss.find(tmp) != s.end()) {         int p = id[tmp];         if (!w[p]) go(p);       }     }   }   int check(set<int> s) {     for (int i = 0; i < (2); i++) {       int g = 1;       for (set<int>::const_iterator it = s.begin(); it != s.end(); it++) {         int tmp = a[i] - *it;         if (s.find(tmp) == s.end()) {           g = 0;           break;         }       }       if (g) {         for (set<int>::const_iterator it = s.begin(); it != s.end(); it++) {           ans[id[*it]] = i;         }         return 1;       }     }     return 0;   }   int main() {     cin >> n >> a[0] >> a[1];     for (int i = 0; i < (n); i++) {       int x;       cin >> x;       id[x] = i;       rev[i] = x;       ss.insert(x);     }     for (int i = 0; i < (n); i++)       if (!w[i]) {         s.clear();         go(i);         if (!check(s)) {           cout <<  NO  << endl;           return 0;         }       }     cout <<  YES  << endl;     for (int i = 0; i < (n); i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int tc;     cin >> tc;     while (tc-- > 0) {       int arr[7];       for (int i = 0; i < 7; i++) {         cin >> arr[i];       }       cout << arr[0] <<     << arr[1] <<     << arr[6] - arr[0] - arr[1] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     return b == 0 ? a : gcd(b, a % b);   }   long long int power(long long int x, long long int n) {     long long int result = 1;     while (n > 0) {       if (n % 2 == 1) result = (result * x) % 1000000007;       x = (x * x) % 1000000007;       n = n / 2;     }     return result % 1000000007;   }   bool isPrime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long int inv(long long int a, long long int m) { return power(a, m - 2); }   long long int lcm(long long int a, long long int b) {     return a * b / (gcd(a, b));   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t;     cin >> t;     while (t--) {       long long int index = -1, res = -1;       string str;       cin >> str;       long long int n = str.length(), ans = -1;       for (long long int i = 0; i < n; i++) {         if (str[i] ==  R ) {           index = max(index, i - res);           res = i;         }       }       index = max(index, n - res);       cout << index <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, arr[100000], arr1[100000];     cin >> n;     string s =   ;     for (int x = 0; x < n; x++) cin >> arr[x], arr1[x] = arr[x];     sort(arr1, arr1 + n);     for (int x = 0; x <= arr1[n - 1]; x++) {       for (int y = 0; y < n - 1; y++) {         if (arr[y] != 0) s +=  P , arr[y]--;         s +=  R ;       }       for (int z = n - 1; z > 0; z--) {         if (arr[z] != 0) s +=  P , arr[z]--;         s +=  L ;       }     }     for (int x = s.size(); x >= 0; x--)       if (s[x] ==  P ) {         s.erase(x + 1, s.size());         break;       }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   const int maxn = 1e5 + 10;   const int mod = 1e9 + 7;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   ll pwr(ll a, ll pw) {     ll ret = 1;     while (pw > 0) {       if (pw & 1) {         ret = ret * a % mod;       }       a = a * a % mod;       pw >>= 1;     }     return ret;   }   ll modinv(ll a) { return pwr(a, mod - 2); }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     int n;     cin >> n;     vector<ll> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     vector<vector<ll> > prob_win(n, vector<ll>(n));     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         prob_win[i][j] = v[i] * modinv(v[i] + v[j]) % mod;         prob_win[j][i] = v[j] * modinv(v[i] + v[j]) % mod;       }     }     vector<vector<ll> > win_msk(n, vector<ll>(1 << n, 1ll));     for (int i = 0; i < n; i++) {       for (int msk = 0; msk < 1 << n; msk++) {         for (int bit = 0; bit < n; bit++) {           if (msk >> bit & 1) {             win_msk[i][msk] = win_msk[i][msk] * prob_win[i][bit] % mod;           }         }       }     }     ll ans = 0;     vector<ll> dp_prob(1 << n, 1ll);     for (int msk = 1; msk < 1 << n; msk++) {       ll num_winners = __builtin_popcount(msk);       for (int bit = 0; bit < n; bit++) {         if (msk >> bit & 1) {           dp_prob[msk] = dp_prob[msk] * win_msk[bit][(1 << n) - 1 - msk] % mod;         }       }       for (int sub_winners = (msk - 1) & msk; sub_winners > 0;            sub_winners = (sub_winners - 1) & msk) {         int sub_losers = msk ^ sub_winners;         ll p = dp_prob[sub_winners];         for (int bit = 0; bit < n; bit++) {           if (sub_losers >> bit & 1) {             p = p * win_msk[bit][(1 << n) - 1 - msk] % mod;           }         }         dp_prob[msk] = (dp_prob[msk] - p + mod) % mod;       }       ans = (ans + dp_prob[msk] * num_winners % mod) % mod;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   constexpr int N = 2e5 + 5;   vector<int> E[N];   LL Size[N], Dep[N];   int ord[N];   int tourism[N];   void dfs(int x, int p, int lvl) {     Size[x] = 1;     Dep[x] = lvl;     for (const int &to : E[x]) {       if (to == p) continue;       dfs(to, x, lvl + 1);       Size[x] += Size[to];     }   }   LL res;   void go(int x, int p, int val) {     if (tourism[x])       val++;     else       res += val;     for (const int &to : E[x]) {       if (to == p) continue;       go(to, x, val);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, k;     cin >> n >> k;     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       E[x].push_back(y);       E[y].push_back(x);     }     dfs(0, 0, 0);     iota(ord, ord + n, 0);     sort(ord, ord + n,          [](int x, int y) { return Dep[x] - Size[x] < Dep[y] - Size[y]; });     k = n - k;     for (int i = 0; i < k; i++) {       tourism[ord[i]] = 1;     }     go(0, 0, 0);     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200009;   const long long mod = 1e9 + 7;   char s[N]{};   long long prea[N];   long long pref[N];   long long sac[N];   long long saf[N];   long long ksm(int n, int y) {     if (y < 1) return 1;     long long x = n;     long long ret = 1;     while (y) {       if (y & 1) {         ret *= x;         ret %= mod;       }       x *= x;       x %= mod;       y /= 2;     }     return ret;   }   int main() {     int n;     cin >> n;     cin >> s + 1;     for (int i = 1; i <= n; i++) {       prea[i] = prea[i - 1];       pref[i] = pref[i - 1];       if (s[i] ==  a ) prea[i]++;       if (s[i] ==  ? ) pref[i]++;     }     for (int i = n; i >= 1; i--) {       sac[i] = sac[i + 1];       saf[i] = saf[i + 1];       if (s[i] ==  c ) sac[i]++;       if (s[i] ==  ? ) saf[i]++;     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (s[i] ==  b  || s[i] ==  ? ) {         long long l = pref[i - 1];         long long r = saf[i + 1];         ans += (prea[i - 1] * sac[i + 1] % mod) * (ksm(3, l + r) % mod) % mod;         ans %= mod;         ans += (prea[i - 1] * saf[i + 1] % mod) * (ksm(3, l + r - 1) % mod) % mod;         ans %= mod;         ans += (pref[i - 1] * sac[i + 1] % mod) * (ksm(3, l + r - 1) % mod) % mod;         ans %= mod;         ans += (pref[i - 1] * saf[i + 1] % mod) * (ksm(3, l + r - 2) % mod) % mod;         ans %= mod;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, cr;   bool f = 0;   pair<long long, long long> a[25], b[25], c[25];   void gen(long long i, long long s1, long long s2) {     if (i == n) {       if (s1 != s2) cr++;     } else {       gen(i + 1, s1 + a[i].first, s2 + c[i].first);       gen(i + 1, s1, s2);     }   }   int main() {     ios::sync_with_stdio(0);     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i;       c[i] = a[i];     }     sort(a, a + n);     sort(c, c + n);     for (long long k = 0; k < n; k++) {       for (long long i = 0; i < n; i++) {         b[i] = a[i];       }       a[0] = b[n - 1];       for (long long i = 1; i < n; i++) {         a[i] = b[i - 1];       }       cr = 0;       gen(0, 0, 0);       if (cr == ((1 << n) - 2)) {         f = 1;         for (long long i = 0; i < n; i++) {           c[i].first = c[i].second;           c[i].second = a[i].first;         }         break;       }     }     if (!f) {       cout << -1;       return 0;     }     sort(c, c + n);     for (long long i = 0; i < n; i++) {       cout << c[i].second <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long a, b, x, y, n;       cin >> a >> b >> x >> y >> n;       long long a1 = a, b1 = b, n1 = n;       long long an = a - x, bn = b - y;       b -= min(bn, n);       n -= min(bn, n);       a -= min(an, n);       a1 -= min(an, n1);       n1 -= min(an, n1);       b1 -= min(bn, n1);       cout << min(a1 * b1, a * b) <<   n ;     }   }


#include <bits/stdc++.h>   template <class T>   inline void read(T &x) {     x = 0;     register char c = getchar();     register bool f = 0;     while (!isdigit(c)) f ^= c ==  - , c = getchar();     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     if (f) x = -x;   }   template <class T>   inline void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) print(x / 10);     putchar(x % 10 +  0 );   }   template <class T>   inline void print(T x, char c) {     print(x), putchar(c);   }   const int N = 2e5 + 10, mod = 998244353;   struct z {     int x;     z(int x = 0) : x(x) {}     friend inline z operator*(z a, z b) { return (long long)a.x * b.x % mod; }     friend inline z operator-(z a, z b) {       return (a.x -= b.x) < 0 ? a.x + mod : a.x;     }     friend inline z operator+(z a, z b) {       return (a.x += b.x) >= mod ? a.x - mod : a.x;     }   } inv100, p[N];   inline z fpow(z a, int b) {     z s(1);     for (; b; b >>= 1, a = a * a)       if (b & 1) s = s * a;     return s;   }   struct pair {     z x, y;     inline z set(z k) { return x * k + y; }     friend inline pair operator*(const pair &x, const pair &y) {       return (pair){x.x * y.x, x.x * y.y + x.y};     }   };   struct seg {     struct node {       int l, r, mid;       pair x;     } p[N << 2];     void build(int u, int l, int r, pair foo(int)) {       p[u].l = l, p[u].r = r, p[u].mid = (l + r) >> 1;       if (l == r) {         p[u].x = foo(l);         return;       }       build(u << 1, l, p[u].mid, foo);       build(u << 1 | 1, p[u].mid + 1, r, foo);       p[u].x = p[u << 1].x * p[u << 1 | 1].x;     }     void modify(int u, int k, pair x) {       if (p[u].l == p[u].r) {         p[u].x = x;         return;       }       modify(k <= p[u].mid ? u << 1 : u << 1 | 1, k, x);       p[u].x = p[u << 1].x * p[u << 1 | 1].x;     }     pair query(int u, int l, int r) {       if (p[u].l == l && p[u].r == r) return p[u].x;       if (r <= p[u].mid) return query(u << 1, l, r);       if (l > p[u].mid) return query(u << 1 | 1, l, r);       return query(u << 1, l, p[u].mid) * query(u << 1 | 1, p[u].mid + 1, r);     }   } f, g, h, res;   int n, m;   std::set<int> set;   pair calc(int l, int r) {     z a = f.query(1, l, r).set(0);     z b = g.query(1, l, r).set(1);     z c = h.query(1, l, r).set(0);     z inv = fpow(1 - a, mod - 2);     return (pair){b * inv, c * inv};   }   int main() {     read(n), read(m), p[0] = 1, inv100 = fpow(100, mod - 2);     for (int i = 1; i <= n; i++) read((int &)p[i]), p[i] = p[i] * inv100;     set.insert(0), set.insert(1), set.insert(n + 1);     f.build(1, 0, n, [](int i) { return (pair){p[i], 1 - p[i]}; });     g.build(1, 0, n, [](int i) { return (pair){p[i], z(0)}; });     h.build(1, 0, n, [](int i) { return (pair){p[i], z(1)}; });     res.build(1, 0, n, [](int k) {       if (k == 0) return calc(0, 0);       if (k == 1) return calc(1, n);       return (pair){1, 0};     });     for (int x, i = 1; i <= m; i++) {       read(x);       if (set.find(x) == set.end()) {         set.insert(x);         auto it = set.find(x);         int l = *std::prev(it), r = *std::next(it);         res.modify(1, l, calc(l, x - 1));         res.modify(1, x, calc(x, r - 1));       } else {         auto it = set.find(x);         int l = *std::prev(it), r = *std::next(it);         res.modify(1, l, calc(l, r - 1));         res.modify(1, x, {1, 0});         set.erase(it);       }       printf( %d n , (res.query(1, 0, n).set(0) - 1).x);     }   }


#include <bits/stdc++.h>   using namespace std;   long long int cost(long long int x[], long long int a, long long int n,                      long long int r, long long int m, long long int val) {     long long int pos = 0;     long long int neg = 0;     for (int i = 0; i < n; i++) {       if (x[i] > val)         pos += x[i] - val;       else         neg += val - x[i];     }     if (a + r < m)       return a * neg + r * pos;     else {       if (pos > neg)         return neg * m + (pos - neg) * r;       else         return pos * m + (neg - pos) * a;     }   }   long long int binary(long long int x[], long long int a, long long int n,                        long long int r, long long int m, long long int min,                        long long int max) {     if (min > max)       return -1;     else {       long long int mid = (min + max) / 2;       long long int q = cost(x, a, n, r, m, mid);       long long int w = cost(x, a, n, r, m, mid - 1);       long long int e = cost(x, a, n, r, m, mid + 1);       if (q <= w && q <= e) {         return q;       } else if (w > q && q > e)         return binary(x, a, n, r, m, mid + 1, max);       else         return binary(x, a, n, r, m, min, mid - 1);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, a, r, m;     cin >> n >> a >> r >> m;     long long int *x = new long long int[n];     long long int min = 100000001;     long long int max = 0;     for (int i = 0; i < n; i++) {       cin >> x[i];       if (x[i] > max) max = x[i];       if (x[i] < min) min = x[i];     }     long long int sum = binary(x, a, n, r, m, min, max);     cout << sum <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <typename TYPE>   inline void chkmax(TYPE &first, TYPE second) {     first < second ? first = second : 0;   }   template <typename TYPE>   inline void chkmin(TYPE &first, TYPE second) {     second < first ? first = second : 0;   }   template <typename TYPE>   void readint(TYPE &first) {     first = 0;     int f = 1;     char c;     for (c = getchar(); !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) first = first * 10 + c -  0 ;     first *= f;   }   const int MAXN = 800005;   const long long INF = 1ll << 60;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   void exgcd(int a, int b, int &first, int &second) {     if (!b) {       first = 1, second = 0;       return;     }     exgcd(b, a % b, first, second);     int t = first;     first = second;     second = t - (a / b) * second;   }   int n, m, stot, invn, invm;   vector<int> a[MAXN], b[MAXN], ta, tb;   map<int, int> ma, mb;   long long dis[MAXN];   bool hap[MAXN];   priority_queue<pair<long long, int>, vector<pair<long long, int> >,                  greater<pair<long long, int> > >       pq;   struct Edge {     int v;     long long c;     Edge *next;   } pool[MAXN * 3], *h[MAXN];   int etot = 0;   inline void addEdge(int u, int v, long long c) {     Edge *p = &pool[++etot];     p->v = v;     p->c = c;     p->next = h[u];     h[u] = p;   }   void read(int d, vector<int> *a) {     int n, first;     readint(n);     while (n--) {       readint(first);       a[first % d].push_back(first / d);     }   }   int gma(int first) { return ma.count(first) ? ma[first] : ma[first] = ++stot; }   int gmb(int first) { return mb.count(first) ? mb[first] : mb[first] = ++stot; }   void dijkstra(int src) {     for (int i = 1; i <= stot; ++i) dis[i] = INF;     dis[src] = 0;     pq.push(make_pair(0, src));     while (!pq.empty()) {       pair<long long, int> pr = pq.top();       pq.pop();       int u = pr.second;       if (pr.first > dis[u]) continue;       for (Edge *p = h[u]; p; p = p->next)         if (dis[p->v] > dis[u] + p->c) {           dis[p->v] = dis[u] + p->c;           pq.push(make_pair(dis[p->v], p->v));         }     }   }   long long solve(vector<int> a, vector<int> b) {     ma.clear();     ta.clear();     mb.clear();     tb.clear();     for (int i = 1; i <= stot; ++i) h[i] = NULL, hap[i] = 0;     stot = etot = 0;     int src = ++stot;     for (int i = 0; i < a.size(); ++i) {       int first = 1ll * a[i] * invm % n;       addEdge(src, gma(first), a[i]);       addEdge(gma(first), gmb(1ll * a[i] * invn % m), 0);       hap[gma(first)] = 1;       ta.push_back(first ? first - 1 : n - 1);       tb.push_back(1ll * a[i] * invn % m);       tb.push_back((1ll * a[i] * invn + m - 1) % m);       a[i] = first;     }     for (int i = 0; i < b.size(); ++i) {       int first = 1ll * b[i] * invn % m;       addEdge(src, gmb(first), b[i]);       addEdge(gmb(first), gma(1ll * b[i] * invm % n), 0);       hap[gmb(first)] = 1;       tb.push_back(first ? first - 1 : m - 1);       ta.push_back(1ll * b[i] * invm % n);       ta.push_back((1ll * b[i] * invm + n - 1) % n);       b[i] = first;     }     for (auto first : ta) a.push_back(first);     for (auto first : tb) b.push_back(first);     sort(a.begin(), a.end());     auto edu = unique(a.begin(), a.end());     a.erase(edu, a.end());     sort(b.begin(), b.end());     edu = unique(b.begin(), b.end());     b.erase(edu, b.end());     for (int i = 1; i < a.size(); ++i)       addEdge(gma(a[i - 1]), gma(a[i]), 1ll * (a[i] - a[i - 1]) * m);     addEdge(gma(a.back()), gma(a[0]), 1ll * (a[0] - a.back() + n) * m);     for (int i = 1; i < b.size(); ++i)       addEdge(gmb(b[i - 1]), gmb(b[i]), 1ll * (b[i] - b[i - 1]) * n);     addEdge(gmb(b.back()), gmb(b[0]), 1ll * (b[0] - b.back() + m) * n);     dijkstra(src);     long long ans = -1;     for (int i = 2; i <= stot; ++i)       if (!hap[i]) chkmax(ans, dis[i]);     return ans;   }   int main() {     readint(n), readint(m);     int d = gcd(n, m);     if (d > 200000) return 0 * printf( -1 n );     read(d, a);     read(d, b);     for (int i = 0; i < d; ++i)       if (!a[i].size() && !b[i].size()) return 0 * printf( -1 n );     n /= d, m /= d;     int temp;     exgcd(n, m, invn, temp);     if (invn < 0) invn += m;     exgcd(n, m, temp, invm);     if (invm < 0) invm += n;     long long ans = 0;     for (int i = 0; i < d; ++i) chkmax(ans, solve(a[i], b[i]) * d + i);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   const int inf = 0x3f3f3f3f;   int t, n;   int a[200];   int main() {     int n, q, t, k, d;     int cnt;     int sum;     memset(a, 0, sizeof a);     cin >> n >> q;     for (int i = 0; i < q; i++) {       cnt = 0;       sum = 0;       cin >> t >> k >> d;       for (int j = 0; j < n; j++) {         if (a[j] < t) cnt++;       }       if (cnt < k)         cout <<  -1  << endl;       else {         for (int j = 0; j < n; j++) {           if (a[j] < t) {             k--;             a[j] = t + d - 1;             sum += j + 1;           }           if (k == 0) break;         }         cout << sum << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[110];   int b[110];   int main() {     string s;     getline(cin, s);     int num = 0, ten = 1;     for (int i = s.size() - 1; i >= 0; i--) {       if (s[i] ==  = ) break;       if (s[i] <=  9  && s[i] >=  0 ) {         int x = s[i] -  0 ;         num += x * ten;         ten *= 10;       }     }     int cnt = 0;     a[0] = 1;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  + ) {         a[++cnt] = 1;       } else if (s[i] ==  - ) {         a[++cnt] = 0;       }     }     int x = 0;     for (int i = 0; i <= cnt; i++) {       b[i] = 1;       if (a[i])         x += b[i];       else         x -= b[i];     }     x = num - x;     for (int i = 0; i <= cnt; i++) {       if (x < 0) {         if (a[i] == 0 && b[i] < num) {           int k = min(num - b[i], -x);           b[i] += k;           x += k;         }       } else if (x > 0) {         if (a[i] == 1 && b[i] < num) {           int k = min(num - b[i], x);           b[i] += k;           x -= k;         }       } else         break;     }     x = 0;     for (int i = 0; i <= cnt; i++) {       if (a[i])         x += b[i];       else         x -= b[i];     }     if (x != num) {       cout <<  Impossible  << endl;       return 0;     }     cout <<  Possible  << endl;     cnt = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  +  || s[i] ==  -  || s[i] ==  = ) {         cout << b[cnt++] <<     << s[i] <<    ;       }     }     cout << num << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, x;     cin >> n >> x;     long long sum = 0;     for (int i = 0; i < n; i++) {       long long a;       cin >> a;       sum += a;     }     if (sum + n - 1 == x) return 0 * puts( YES );     puts( NO );     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   using namespace std;   using ll = long long;   using lld = long double;   using vll = int64_t;   int main() {     map<int, pair<int, int> > hm;     int a[] = {4, 8, 15, 16, 23, 42};     for (int i = 0; i < 6; i++) {       for (int j = i + 1; j < 6; j++) hm[a[i] * a[j]] = {a[i], a[j]};     }     int ans[7];     cout <<  ?            <<  1 2 n           << flush;     int x;     cin >> x;     auto p1 = hm[x];     cout <<  ? 2 3 n  << flush;     cin >> x;     auto p2 = hm[x];     if (p1.first == p2.first || p1.first == p2.second) {       ans[2] = p1.first;       ans[1] = p1.second;       if (p1.first == p2.first) {         ans[3] = p2.second;       } else {         ans[3] = p2.first;       }     } else {       ans[2] = p1.second;       ans[1] = p1.first;       if (p1.second == p2.first)         ans[3] = p2.second;       else         ans[3] = p2.first;     }     cout <<  ? 4 5 n  << flush;     cin >> x;     p1 = hm[x];     cout <<  ? 5 6 n  << flush;     cin >> x;     p2 = hm[x];     if (p1.first == p2.first || p1.first == p2.second) {       ans[5] = p1.first;       ans[4] = p1.second;       if (p1.first == p2.first) {         ans[6] = p2.second;       } else {         ans[6] = p2.first;       }     } else {       ans[5] = p1.second;       ans[4] = p1.first;       if (p1.second == p2.first)         ans[6] = p2.second;       else         ans[6] = p2.first;     }     cout <<  !  ;     for (int i = 1; i < 7; i++) cout << ans[i] <<    ;     cout <<   n  << flush;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s;   int dp[111][55][222][3];   int res;   void dfs(int pos, int left, int x, int dx) {     if (dp[pos][left][x + 100][dx + 1]) return;     dp[pos][left][x + 100][dx + 1] = 1;     if (pos == s.size()) {       if (left == 0) res = max(res, abs(x));       return;     }     for (int i = 0; i <= left; i++) {       int ddx = (s[pos] ==  F );       if (i % 2 == 1) ddx = !ddx;       dfs(pos + 1, left - i, x + (ddx == 1 ? dx : 0), dx * (ddx == 0 ? -1 : 1));     }   }   int main() {     cin >> s;     cin >> n;     dfs(0, n, 0, 1);     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int hv[5];   map<string, int> dys;   string dyi[5] = { S ,  M ,  L ,  XL ,  XXL };   int order[5][5] = {{0, 1, 2, 3, 4},                      {1, 2, 0, 3, 4},                      {2, 3, 1, 4, 0},                      {3, 4, 2, 1, 0},                      {4, 3, 2, 1, 0}};   int k;   string sk;   void init() {     dys[ S ] = 0;     dys[ M ] = 1;     dys[ L ] = 2;     dys[ XL ] = 3;     dys[ XXL ] = 4;   }   int main() {     init();     for (int i = 0; i < 5; i++) scanf( %d , hv + i);     scanf( %d , &k);     for (int i = 0; i < k; i++) {       cin >> sk;       int dyk = dys[sk];       for (int j = 0; j < 5; j++)         if (hv[order[dyk][j]]) {           hv[order[dyk][j]]--;           cout << dyi[order[dyk][j]] << endl;           break;         }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, a, k = 0;     vector<int> v;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a;       v.push_back(a);     }     sort(v.begin(), v.end(), greater<int>());     for (i = 0; i <= n - 3; i++) {       if (v[i] < v[i + 1] + v[i + 2]) k++;     }     if (k > 0)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     double l, p, q;     cin >> l >> p >> q;     cout << setprecision(9) << (p * l) / (p + q);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     vector<int> result;     for (int i = 0; i < t; i++) {       int b, p, f, h, c;       cin >> b >> p >> f >> h >> c;       int res = 0;       b /= 2;       if (h > c) {         if (b - p > 0) {           res += p * h;           b -= p;         } else {           res += b * h;           b = 0;         }         if (b > 0) {           if (b > f) {             res += f * c;             b = 0;           } else {             res += b * c;             b = 0;           }         }       } else if (c > h) {         if (b - f > 0) {           res += f * c;           b -= f;         } else {           res += b * c;           b = 0;         }         if (b > 0) {           if (b > p) {             res += p * h;             b = 0;           } else {             res += b * h;             b = 0;           }         }       } else {         if (f + p <= b)           res += (f + p) * h;         else           res += b * h;       }       result.push_back(res);     }     for (int i = 0; i < t; i++) cout << result.at(i) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n;     cin >> t;     while (t--) {       cin >> n;       cout << n / 2 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long x;   int getAdded(long long n) {     int lo = 1, hi = 10000000;     while (lo < hi) {       long long mid = (lo + hi) / 2 + (lo + hi) % 2;       long long temp = (mid * mid + mid) / 2;       if (temp == n)         return mid;       else if (temp < n)         lo = mid;       else         hi = mid - 1;     }     return lo;   }   bool isPossible(int h, int mod, long long n) {     long long temp = x + h;     return getAdded(temp) >= h * 3 + mod;   }   int main() {     long long n;     cin >> n;     int mod = (n % 3 - 3) * -1;     int lo = 0, hi = 10000000;     x = (n + mod) / 3;     while (lo < hi) {       int mid = (lo + hi) / 2 + (lo + hi) % 2;       if (isPossible(mid, mod, n))         lo = mid;       else         hi = mid - 1;     }     if (!isPossible(lo, mod, n))       cout << 0;     else       cout << lo + 1;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000000,100000000000 )   using namespace std;   const long long inf = 1e18 + 7;   const long long mod = 1e9 + 7;   const double eps = 1e-12;   const double PI = 2 * acos(0.0);   const double E = 2.71828;   int n;   long long a[1000005];   long long d[1000005], sz;   long long cnt[1000005];   long long res = 1;   long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }   void up(long long x) {     sz = 0;     for (long long i = 1; i * i <= x; ++i) {       if (x % i == 0) {         d[sz++] = i;         if (i * i != x) {           d[sz++] = x / i;         }       }     }     sort(d, d + sz);     for (long long(i) = 0; (i) < (long long)(sz); (i)++) {       cnt[i] = 0;     }     for (long long(i) = 0; (i) < (long long)(n); (i)++) {       long long cur = gcd(x, a[i]);       int num = lower_bound(d, d + sz, cur) - d;       ++cnt[num];     }     for (long long(i) = 0; (i) < (long long)(sz); (i)++) {       for (int j = i + 1; j < sz; ++j) {         if (d[j] % d[i] == 0) {           cnt[i] += cnt[j];         }       }       if (cnt[i] + cnt[i] >= n && res < d[i]) {         res = d[i];       }     }   }   int main(void) {     srand(time(NULL));     scanf( %d , &n);     for (long long(i) = 0; (i) < (long long)(n); (i)++) {       scanf( %I64d , a + i);     }     for (long long(i) = 0; (i) < (long long)(10); (i)++) {       up(a[(rand() << 16 | rand()) % n]);     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using u32 = unsigned int;   using u64 = unsigned long long;   char buf[10];   void NO() {     puts( Impossible );     exit(0);   }   ll update(ll x, ll c) {     if (x == LLONG_MAX || x == LLONG_MIN) return x;     return x + c;   }   int main() {     int n;     scanf( %d , &n);     ll max_r = LLONG_MAX;     ll min_r = LLONG_MIN;     for (int i = (0); i < (n); ++i) {       ll c_i, d_i;       scanf( %lld%lld , &c_i, &d_i);       ;       if (d_i == 2) {         if (min_r >= 1900) NO();         if (max_r >= 1900) max_r = 1899;       } else if (d_i == 1) {         if (max_r < 1900) NO();         if (min_r < 1900) min_r = 1900;       }       max_r = update(max_r, c_i);       min_r = update(min_r, c_i);     }     if (max_r == LLONG_MAX)       puts( Infinity );     else       printf( %lld , max_r);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[300005];   int cnt[300005];   int vis[300005];   int ans[300001][26];   int res = 0;   int main() {     queue<int> q;     int n, m;     cin >> n >> m;     string s;     cin >> s;     int x, y;     while (m--) {       scanf( %d%d , &x, &y);       x--, y--;       g[x].push_back(y);       cnt[y]++;     }     for (int i = 0; i < s.size(); i++) {       ans[i][s[i] -  a ]++;       if (!cnt[i]) q.push(i);     }     while (!q.empty()) {       int i = q.front();       q.pop();       for (auto v : g[i]) {         cnt[v]--;         for (int j = 0; j < 26; j++) {           ans[v][j] = max(ans[v][j], ans[i][j] + (s[v] == j +  a ));           res = max(res, ans[v][j]);         }         if (!cnt[v]) q.push(v);       }     }     if (*max_element(cnt, cnt + s.size())) return cout << -1, 0;     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int c[4100];   int s[4100];   vector<long long> g;   string str;   int main() {     long long a;     cin >> a;     cin >> str;     int len = str.length();     for (int i = 0; str[i]; i++) c[i + 1] = str[i] -  0 ;     for (int i = 1; i <= len; i++) {       s[i] = s[i - 1] + (long long)c[i];     }     for (int i = 0; i <= len; i++)       for (int j = i + 1; j <= len; j++) g.push_back(s[j] - s[i]);     sort(g.begin(), g.end());     int sz = g.size(), sz1;     sz1 = upper_bound(g.begin(), g.end(), 0) - lower_bound(g.begin(), g.end(), 0);     long long ans = 0;     for (int i = 0; i < sz; i++) {       if (g[i] == 0) {         if (a == 0) ans += sz;         continue;       }       if (a % g[i] == 0 &&           *lower_bound(g.begin(), g.end(), a / g[i]) == a / g[i]) {         if (a == 0) {           ans += sz1;           continue;         }         ans += upper_bound(g.begin(), g.end(), a / g[i]) -                lower_bound(g.begin(), g.end(), a / g[i]);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int l[100005], r[100005], q[100005];   struct node {     int v, add;   };   node t[4 * 100005];   const int MX = (1LL << 31) - 1;   void Push(int v, int tl, int tm, int tr) {     if (t[v].add != 0) {       t[2 * v].add |= t[v].add;       t[2 * v].v |= t[v].add;       t[2 * v + 1].add |= t[v].add;       t[2 * v + 1].v |= t[v].add;       t[v].add = 0;     }   }   void Update(int v, int tl, int tr, int l, int r, int value) {     if (l > r) return;     if ((tl == l) && (tr == r)) {       t[v].add |= value;       t[v].v |= value;       return;     }     int tm = (tl + tr) / 2;     Push(v, tl, tm, tr);     Update(2 * v, tl, tm, l, min(tm, r), value);     Update(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, value);     t[v].v &= t[2 * v].v;     t[v].v &= t[2 * v + 1].v;   }   int Get(int v, int tl, int tr, int l, int r) {     if (l > r) return MX;     if ((tl == l) && (tr == r)) return t[v].v;     int tm = (tl + tr) / 2;     Push(v, tl, tm, tr);     return Get(2 * v, tl, tm, l, min(tm, r)) &            Get(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);   }   int main() {     scanf( %d %d , &n, &m);     for (int(i) = (0); (i) < int(m); ++(i)) {       scanf( %d %d %d , l + i, r + i, q + i);       Update(1, 0, n - 1, l[i] - 1, r[i] - 1, q[i]);     }     bool Ok = 1;     for (int(i) = (0); (i) < int(m); ++(i)) {       int x = Get(1, 0, n - 1, l[i] - 1, r[i] - 1);       if (x != q[i]) {         Ok = 0;         break;       }     }     if (!Ok) {       puts( NO );       cin.sync();       cin.get();       return 0;     } else {       puts( YES );       for (int(i) = (0); (i) < int(n); ++(i)) {         printf( %d  , Get(1, 0, n - 1, i, i));       }     }     cin.sync();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.length(), cur = 1, best = 1;     s += s;     for (size_t i = 1; i < s.size(); i++)       if (s[i] != s[i - 1])         cur++;       else {         best = max(best, cur);         cur = 1;       }     best = max(best, cur);     cout << min(n, best);     return 0;   }