#include <bits/stdc++.h>   template <class T>   inline bool chmax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   inline bool chmin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   const long long MAX = 5100000;   const long long INF = 1LL << 60;   const long long mod = 1000000007LL;   using namespace std;   long long t[200500];   long long tmp[200500];   int main() {     long long n;     scanf( %lld , &n);     long long a[3];     scanf( %lld %lld %lld , &a[0], &a[1], &a[2]);     sort(a, a + 3);     multiset<long long> ms;     for (long long i = 0; i < n; i++) {       scanf( %lld , &t[i]);       ms.emplace(t[i]);     }     if (*ms.rbegin() > a[0] + a[1] + a[2]) {       puts( -1 );       return 0;     }     long long res = 0;     while (!ms.empty() && *ms.rbegin() > a[1] + a[2]) {       res++;       ms.erase(--ms.end());     }     while (!ms.empty() && *ms.rbegin() > a[0] + a[2]) {       res++;       ms.erase(--ms.end());       auto itr = ms.upper_bound(a[0]);       if (itr == ms.begin()) continue;       itr--;       ms.erase(itr);     }     while (!ms.empty() && *ms.rbegin() > a[2] && *ms.rbegin() > a[0] + a[1]) {       res++;       ms.erase(--ms.end());       if (ms.empty()) break;       auto itr = ms.upper_bound(a[1]);       if (itr == ms.begin()) continue;       itr--;       ms.erase(itr);     }     while (!ms.empty()) {       res++;       if (a[0] + a[1] <= a[2]) {         ms.erase(--ms.end());         if (ms.empty()) break;         if (*ms.begin() <= a[0]) {           ms.erase(ms.begin());           if (ms.empty()) break;           auto itr = ms.upper_bound(a[1]);           if (itr == ms.begin()) continue;           itr--;           ms.erase(itr);         } else if (*ms.begin() <= a[0] + a[1]) {           auto itr = ms.upper_bound(a[1] + a[0]);           itr--;           ms.erase(itr);         }       } else {         if (*ms.rbegin() <= a[2]) {           auto itr = ms.upper_bound(a[1]);           if (!(*ms.begin() > a[0] || itr == ms.begin() || itr == ++ms.begin())) {             ms.erase(--ms.end());             if (ms.empty()) break;             ms.erase(ms.begin());             if (ms.empty()) break;             auto itr = ms.upper_bound(a[1]);             itr--;             ms.erase(itr);             continue;           }         }         ms.erase(--ms.end());         auto itr = ms.upper_bound(a[2]);         if (itr != ms.begin()) {           itr--;           ms.erase(itr);         }       }     }     printf( %lld n , res);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   using namespace std;   const int maxn = 200000;   int t[4 * maxn];   int p[maxn];   int n;   int mina(int x, int y) {     if (x == -1) return y;     if (y == -1) return x;     return (p[x] < p[y] ? x : y);   }   void build(int x, int cl, int cr) {     if (cr - cl > 1) {       build(2 * x, cl, (cl + cr) / 2);       build(2 * x + 1, (cl + cr) / 2, cr);       t[x] = mina(t[2 * x], t[2 * x + 1]);     } else       t[x] = cl;   }   int get(int x, int cl, int cr, int l, int r) {     if (cr <= l || r <= cl) return -1;     if (l <= cl && cr <= r) return t[x];     return mina(get(2 * x, cl, (cl + cr) / 2, l, r),                 get(2 * x + 1, (cl + cr) / 2, cr, l, r));   }   int a[maxn], dpl[maxn], dpr[maxn];   int mx = 0;   void dfs(int i, int cl, int cr, int cd) {     dpl[i] = dpr[i] = 1;     if (i != cl) {       int u = get(1, 0, maxn, cl, i);       dfs(u, cl, i, cd + 1);       dpl[i] += max(dpl[u], dpr[u]);     }     if (cr - i > 1) {       int u = get(1, 0, maxn, i + 1, cr);       dfs(u, i + 1, cr, cd + 1);       dpr[i] += max(dpr[u], dpl[u]);     }   }   pair<int, int> solve(int sd) {     for (int i = sd; i < n; i++) p[i - sd] = a[i];     for (int i = n - sd; i < n; i++) p[i] = a[i - n + sd];     build(1, 0, maxn);     mx = 0;     int st = get(1, 0, maxn, 0, n);     dfs(st, 0, n, 1);     return {max(dpl[st], dpr[st]), dpl[st] - dpr[st]};   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     int ans = solve(0).first;     int mi = 0;     int st = get(1, 0, maxn, 0, n);     int l = 0, r = st;     while (r - l > 10) {       int md = (l + r) / 2;       if (solve(md).second >= 0)         l = md;       else         r = md;     }     for (int i = l; i <= r; i++) {       int fuck = solve(i).first;       if (fuck < ans) {         mi = i;       }       ans = min(ans, fuck);     }     l = st;     r = n - 1;     while (r - l > 10) {       int md = (l + r) / 2;       if (solve(md).second >= 0)         l = md;       else         r = md;     }     for (int i = l; i <= r; i++) {       int fuck = solve(i).first;       if (fuck < ans) {         mi = i;       }       ans = min(ans, fuck);     }     cout << ans <<     << mi;     return 0;   }


#include <bits/stdc++.h>   int a[500];   int temp1[500];   int temp2[500];   int sum[500];   void merge(int l, int mid, int r) {     int i, j, k;     for (i = l; i <= mid; i++) temp1[i - l] = a[i];     temp1[i - l] = 10000000;     for (j = mid + 1; j <= r; j++) temp2[j - mid - 1] = a[j];     temp2[j - mid - 1] = 1000000;     i = 0;     j = 0;     k = l;     while (k <= r) {       if (temp1[i] < temp2[j]) {         a[k] = temp1[i];         i++;       } else {         a[k] = temp2[j];         j++;       }       k++;     }   }   void sorti(int l, int r) {     if (l >= r) return;     int mid = (l + r) / 2;     sorti(l, mid);     sorti(mid + 1, r);     merge(l, mid, r);   }   int main() {     int n;     scanf( %d , &n);     int i, j, k;     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     int left = 0, right = 0;     for (i = 1; i <= n; i++) {       sum[i] = sum[i - 1] + a[i];     }     int val, val1;     int ans = 360;     for (i = 1; i <= n; i++) {       for (j = i; j <= n; j++) {         val1 = (sum[j] - sum[i - 1]);         val = 360 - val1;         val = val > val1 ? (val - val1) : (val1 - val);         ans = ans > val ? val : ans;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxn = 2e5 + 5;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     int tc;     cin >> tc;     while (tc--) {       string s;       cin >> s;       int a = 0, b = 0, c = 0;       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  A )           a++;         else if (s[i] ==  B )           b++;         else           c++;       }       if (a + c == b)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 4 ;   int a[N] , prefMin[N] , prefMax[N] , suffixMin[N] , suffixMax[N];   int main()   {   ios_base::sync_with_stdio(0);       cin.tie(0);       int t ;       cin >> t ;       while(t--){            int n , m , q  , sum =0 , s1 = 0 , s2 =0;            cin >> n >> m ;            string s;            cin >> s;            s =  #  + s ;            for(int i = 1 ; i<=n ;++i){               if(s[i] ==  + )                   sum++ ;               else                   sum--;               a[i] = sum;               prefMin[i] = min(prefMin[i-1] ,sum);               prefMax[i] = max(prefMax[i-1] , sum);            }            suffixMin[n+1] = suffixMax[n+1] = 0 ;            sum = 0;            for(int i = n ; i>=1; --i){               if(s[i] ==  + )                   s1++ , s2++;               else                  s1-- , s2--;               s1 = min(s1 , 0);               s2 = max(s2 ,0);               suffixMin[i] = s1;               suffixMax[i] = s2;            }            while(m--){               int l , r ;               cin >> l >> r;               int maxi = max(prefMax[l-1] , suffixMax[r+1] + a[l-1]) ;      int mini = min(prefMin[l-1] , suffixMin[r+1] + a[l-1]) ;      cout<<maxi+abs(mini)+1<<   n  ;            }             }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) f = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar())       x = (x << 1) + (x << 3) + ch -  0 ;     return x * f;   }   const int N = 2e5 + 5;   struct BIT {     int tree[N];     void add(int x) {       for (; x < N; x += x & -x) ++tree[x];     }     int query(int x) {       int res = 0;       for (; x; x -= x & -x) res += tree[x];       return res;     }   } bit;   struct SegmentTree {     int size[N << 2];     void build(int cur, int l, int r) {       if (l == r) {         size[cur] = 1;         return;       }       build((cur << 1), l, (l + r >> 1));       build((cur << 1 | 1), (l + r >> 1) + 1, r);       size[cur] = size[(cur << 1)] + size[(cur << 1 | 1)];     }     int kth(int cur, int l, int r, int k) {       if (l == r) {         size[cur] = 0;         return l;       }       int res = 0;       if (k <= size[(cur << 1)])         res = kth((cur << 1), l, (l + r >> 1), k);       else         res = kth((cur << 1 | 1), (l + r >> 1) + 1, r, k - size[(cur << 1)]);       size[cur] = size[(cur << 1)] + size[(cur << 1 | 1)];       return res;     }   } sgt;   int p[N];   int main() {     int n = read();     for (int i = 1; i <= n; ++i) {       int x = read();       p[i] += x - bit.query(x);       bit.add(x + 1);     }     memset(bit.tree, 0, sizeof(bit.tree));     for (int i = 1; i <= n; ++i) {       int x = read();       p[i] += x - bit.query(x);       bit.add(x + 1);     }     for (int i = n; i >= 1; --i) {       p[i - 1] += p[i] / (n - i + 1);       p[i] %= (n - i + 1);     }     sgt.build(1, 1, n);     for (int i = 1; i <= n; ++i) printf( %d  , sgt.kth(1, 1, n, p[i] + 1) - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     reverse(a, a + n);     stack<pair<int, int>> st;     for (int i = 0; i < n; i++) {       pair<int, int> p = make_pair(a[i], 0);       while (!st.empty()) {         pair<int, int> q = st.top();         if (q.first < p.first) {           st.pop();           p.second = max(p.second + 1, q.second);         } else           break;       }       st.push(p);     }     int pas = 0;     while (!st.empty()) {       pas = max(pas, st.top().second);       st.pop();     }     cout << pas;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   struct edge {    public:     int flow, cap, cost;     int u, v;     edge(int _u, int _v, int _flow, int _cost, int _cap) {       u = _u;       v = _v;       flow = _flow;       cost = _cost;       cap = _cap;     }     edge() {}   } E[10000];   vector<int> V[10000];   int say[100], src, dest;   int phi[10000];   int B[10000], par[10000], D[10000];   bool dijkstra() {     memset(B, 0, sizeof(B));     for (int i = 1; i <= dest; i++) D[i] = 1000000000;     D[0] = 0;     par[0] = -1;     D[dest + 1] = 1000000000;     for (int it = 0; it <= dest; it++) {       int v = dest + 1;       for (int i = 0; i <= dest; i++)         if (D[i] < D[v] && (!B[i])) v = i;       B[v] = 1;       if (v == dest + 1) break;       for (int j = 0; j < V[v].size(); j++) {         int idx = V[v][j];         if (E[idx].u == v) {           if (E[idx].flow < E[idx].cap) {             int nv = E[idx].v;             assert(D[v] + (phi[v] - phi[nv] + E[idx].cost) >= 0);             if ((!B[nv]) && D[nv] > D[v] + (phi[v] - phi[nv] + E[idx].cost)) {               D[nv] = D[v] + (phi[v] - phi[nv] + E[idx].cost);               par[nv] = idx;             }           }         } else {           if (E[idx].flow > 0) {             int nv = E[idx].u;             assert(D[v] + (phi[v] - phi[nv] - E[idx].cost) >= 0);             if ((!B[nv]) && D[nv] > D[v] + (phi[v] - phi[nv] - E[idx].cost)) {               D[nv] = D[v] + (phi[v] - phi[nv] - E[idx].cost);               par[nv] = idx;             }           }         }       }     }     for (int i = 0; i <= dest; i++)       if (B[i]) phi[i] += D[i];     return B[dest];   }   void augment() {     int cur = dest, aug = 1000000000;     while (par[cur] >= 0) {       int idx = par[cur];       if (E[idx].v == cur) {         aug = min(aug, E[idx].cap - E[idx].flow);         cur = E[idx].u;       } else {         aug = min(aug, E[idx].flow);         cur = E[idx].v;       }     }     cur = dest;     while (par[cur] >= 0) {       int idx = par[cur];       if (E[idx].v == cur) {         E[idx].flow += aug;         cur = E[idx].u;       } else {         E[idx].flow -= aug;         cur = E[idx].v;       }     }   }   int main() {     string t, s;     int n, a;     cin >> t >> n;     src = 0;     dest = n + n * 26 + 27;     int cv = n + 1, ce = 0;     for (int i = 1; i <= n; i++) {       cin >> s >> a;       memset(say, 0, sizeof(say));       int len = s.length();       for (int j = 0; j < len; j++) say[s[j] -  a ]++;       for (int j = 0; j < 26; j++) {         E[ce] = edge(i, cv, 0, 0, say[j]);         V[i].push_back(ce);         V[cv].push_back(ce);         ce++;         E[ce] = edge(cv, n + n * 26 + j + 1, 0, 0, 1000000000);         V[cv].push_back(ce);         V[n + n * 26 + j + 1].push_back(ce);         ce++;         cv++;       }       E[ce] = edge(0, i, 0, i, a);       V[0].push_back(ce);       V[i].push_back(ce);       ce++;     }     memset(say, 0, sizeof(say));     int len = t.length();     for (int i = 0; i < len; i++) say[t[i] -  a ]++;     for (int i = 1; i <= 26; i++) {       E[ce] = edge(n + n * 26 + i, dest, 0, 0, say[i - 1]);       V[n + n * 26 + i].push_back(ce);       V[dest].push_back(ce);       ce++;     }     while (dijkstra()) {       augment();     }     int can = 1;     for (int i = 0; i < V[dest].size(); i++) {       int idx = V[dest][i];       if (E[idx].flow != E[idx].cap) can = 0;     }     if (!can) {       cout << -1 << endl;       return 0;     }     int ans = 0;     for (int i = 0; i < V[0].size(); i++) {       int idx = V[0][i];       ans += E[idx].cost * E[idx].flow;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   istream &operator>>(istream &in, pair<T1, T2> &P) {     in >> P.first >> P.second;     return in;   }   template <class T1, class T2>   ostream &operator<<(ostream &out, const pair<T1, T2> &P) {     out <<  (  << P.first <<  ,   << P.second <<  ) ;     return out;   }   template <class T>   istream &operator>>(istream &in, vector<T> &arr) {     for (auto &x : arr) in >> x;     return in;   }   template <class T>   ostream &operator<<(ostream &out, const vector<T> &arr) {     for (auto &x : arr) out << x <<    ;     cout <<   n ;     return out;   }   template <class T>   istream &operator>>(istream &in, deque<T> &arr) {     for (auto &x : arr) in >> x;     return in;   }   template <class T>   ostream &operator<<(ostream &out, const deque<T> &arr) {     for (auto &x : arr) out << x <<    ;     cout <<   n ;     return out;   }   long long n, m, q, k, v[1000050], l, pref[1000050];   pair<long long, long long> TT, w[1000050];   string second;   long long dp[1000050];   long long prox[1000050];   long long resolve(long long cost) {     memset(dp, 0, sizeof dp);     for (long long i = n; i >= 1; i--) {       long long A =           dp[min(n + 1, i + l)] + (pref[min(n, i + l - 1)] - pref[i - 1]) - cost;       long long B = dp[i + 1];       if (A > B)         prox[i] = 0;       else         prox[i] = 1;       dp[i] = max(A, B);     }     long long j = 1, usados = 0;     while (j <= n) {       if (!prox[j])         usados++, j = j + l;       else         j = j + 1;     }     return usados;   }   long long solve(long long a, long long b) {     long long ini = 0, fim = 200000000000000000, mid, best = -1;     while (fim >= ini) {       mid = (ini + fim) / 2;       long long us = resolve(mid);       if (us <= k)         best = mid, fim = mid - 1;       else         ini = mid + 1;     }     if (best == -1) return 0;     long long us = resolve(best);     return dp[1] + k * best;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k >> l;     cin >> second;     for (long long i = 1; i <= n; i++) {       if ( a  <= second[i - 1] and second[i - 1] <=  z )         v[i] = 0;       else         v[i] = 1;     }     for (long long i = 1; i <= n; i++) pref[i] = pref[i - 1] + v[i];     long long A = pref[n] - solve(1, k);     for (long long i = 1; i <= n; i++) {       v[i] ^= 1;       pref[i] = pref[i - 1] + v[i];     }     long long B = pref[n] - solve(1, k);     cout << min(A, B) <<   n ;   }


#include <bits/stdc++.h>   namespace my_std {   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   template <typename T>   inline T rnd(T first, T second) {     return uniform_int_distribution<T>(first, second)(rng);   }   template <typename T>   inline bool chkmax(T &x, T y) {     return x < y ? x = y, 1 : 0;   }   template <typename T>   inline bool chkmin(T &x, T y) {     return x > y ? x = y, 1 : 0;   }   template <typename T>   inline void read(T &t) {     t = 0;     char f = 0, ch = getchar();     double d = 0.1;     while (ch >  9  || ch <  0 ) f |= (ch ==  - ), ch = getchar();     while (ch <=  9  && ch >=  0 ) t = t * 10 + ch - 48, ch = getchar();     if (ch ==  . ) {       ch = getchar();       while (ch <=  9  && ch >=  0 ) t += d * (ch ^ 48), d *= 0.1, ch = getchar();     }     t = (f ? -t : t);   }   template <typename T, typename... Args>   inline void read(T &t, Args &...args) {     read(t);     read(args...);   }   char __sr[1 << 21], __z[20];   int __C = -1, __zz = 0;   inline void Ot() { fwrite(__sr, 1, __C + 1, stdout), __C = -1; }   inline void print(int x) {     if (__C > 1 << 20) Ot();     if (x < 0) __sr[++__C] =  - , x = -x;     while (__z[++__zz] = x % 10 + 48, x /= 10)       ;     while (__sr[++__C] = __z[__zz], --__zz)       ;     __sr[++__C] =   n ;   }   void file() {}   inline void chktime() {}   long long ksm(long long x, int y) {     long long ret = 1;     for (; y; y >>= 1, x = x * x)       if (y & 1) ret = ret * x;     return ret;   }   }  // namespace my_std   using namespace my_std;   int n, T, _cnt;   pair<int, int> D[403030 >> 1];   int _w[403030 >> 1];   void init() {     static int first[403030], second[403030], p[403030], _l[403030], _r[403030];     for (int i = (1); i <= (n); i++)       read(first[i], second[i]), chkmax(first[i], 0);     int m = 0, K = 0;     for (int i = (1); i <= (n); i++)       if (second[i] >= first[i] && second[i] - first[i] < 2 * T - 2)         p[++m] = first[i], p[++m] = second[i], ++K, _l[K] = first[i],         _r[K] = second[i];       else if (second[i] >= first[i])         ++_cnt;     sort(p + 1, p + m + 1);     m = unique(p + 1, p + m + 1) - p - 1;     n = K;     for (int i = (1); i <= (n); i++) first[i] = _l[i], second[i] = _r[i];     for (int i = (1); i <= (n); i++)       first[i] = lower_bound(p + 1, p + m + 1, first[i]) - p,       second[i] = lower_bound(p + 1, p + m + 1, second[i]) - p;     long long dt = p[1];     p[1] = 0;     for (int i = (2); i <= (m); i++)       if ((p[i] -= dt) > p[i - 1] + 2ll * T)         dt += p[i] - (p[i - 1] + 2 * T), p[i] = p[i - 1] + 2 * T;     for (int i = (1); i <= (n); i++)       D[i] = make_pair(p[first[i]], p[second[i]] + 1);     sort(D + 1, D + n + 1);     for (int i = (1); i <= (n); i++) {       int second = D[i].second;       int x = lower_bound(D + 1, D + n + 1, make_pair(second, -1)) - D;       ++_w[i], --_w[x];     }     for (int i = (1); i <= (n); i++) _w[i] += _w[i - 1];   }   vector<pair<int, int> > Dec[403030 << 1];   struct hh {     int tp, ti, first, second;     hh(int a, int b, int c, int d) { tp = a, ti = b, first = c, second = d; }     const bool operator<(const hh &a) const {       return ti == a.ti ? tp < a.tp : ti < a.ti;     }   };   vector<hh> op[403030 << 1];   vector<pair<int, int> > inc[403030 << 1];   const int Tree = 403030 * 35;   int ch[Tree][2], mx[Tree], cc;   int root[403030 << 1];   void add(int &k, int first, int second, int x, int y, int w) {     if (!k) return;     int kk = k;     k = ++cc;     ch[k][0] = ch[kk][0], ch[k][1] = ch[kk][1], mx[k] = mx[kk];     if (x <= first && second <= y) return mx[k] += w, void();     int tg = mx[k] - max(mx[ch[k][0]], mx[ch[k][1]]), mid = (first + second) >> 1;     if (x <= mid) add(ch[k][0], first, mid, x, y, w);     if (y > mid) add(ch[k][1], mid + 1, second, x, y, w);     mx[k] = tg + max(mx[ch[k][0]], mx[ch[k][1]]);   }   int query(int k, int first, int second, int x, int y) {     if (!k) return -1e7;     if (x <= first && second <= y) return mx[k];     int tg = mx[k] - max(mx[ch[k][0]], mx[ch[k][1]]), mid = (first + second) >> 1,         res = -1e7;     if (x <= mid) chkmax(res, query(ch[k][0], first, mid, x, y));     if (y > mid) chkmax(res, query(ch[k][1], mid + 1, second, x, y));     return res + tg;   }   void modify(int &k, int first, int second, int x, int w) {     int kk = k;     k = ++cc;     mx[k] = mx[kk], ch[k][0] = ch[kk][0], ch[k][1] = ch[kk][1];     if (first == second) return chkmax(mx[k], w), void();     int mid = (first + second) >> 1;     int tg = (ch[k][0] || ch[k][1]) ? mx[k] - max(mx[ch[k][0]], mx[ch[k][1]]) : 0;     w -= tg;     if (x <= mid)       modify(ch[k][0], first, mid, x, w);     else       modify(ch[k][1], mid + 1, second, x, w);     mx[k] = max(mx[ch[k][0]], mx[ch[k][1]]) + tg;   }   vector<pair<int, int> > V[3];   void rebuild(int k, int first, int second, int tg, int tp) {     if (!k) return;     if (first == second) return V[tp].push_back(make_pair(first, tg + mx[k]));     int mid = (first + second) >> 1;     tg += mx[k] - max(mx[ch[k][0]], mx[ch[k][1]]);     rebuild(ch[k][0], first, mid, tg, tp),         rebuild(ch[k][1], mid + 1, second, tg, tp);   }   void Rebuild(int second) {     int first = max(0, second - 2);     for (int i = (0); i <= (2); i++) V[i].clear();     for (int i = (first); i <= (second); i++)       rebuild(root[i], 0, T - 1, 0, i - first);     cc = 0;     for (int i = (first); i <= (second); i++) {       root[i] = 0;       for (auto t : V[i - first]) modify(root[i], 0, T - 1, t.first, t.second);     }   }   int main() {     file();     read(n, T);     init();     for (int i = (1); i <= (n); i++) {       op[D[i].first / T].push_back(hh(i, D[i].first % T, 0, 0));       if (D[i].second - D[i].first > T) {         auto add = [&](int first, int second, int re) {           Dec[first / T].push_back(               make_pair(first % T, (second % T == 0 ? T : second % T))),               op[re / T].push_back(hh(-1, re % T, first, second));         };         int first = D[i].first, second = D[i].second - T;         if (first % T < second % T || second % T == 0)           add(first, second, D[i].second);         else           add(first, first - first % T + T, D[i].second),               add(second - second % T, second, D[i].second);       }       int first = D[i].first, second = D[i].second;       while (first - first % T + T <= second)         inc[first / T].push_back(make_pair(first % T, T)),             first = first - first % T + T;       if (first < second)         inc[first / T].push_back(make_pair(first % T, second % T));     }     mx[0] = -1e7;     const int RE = n / 10;     int ti = 0;     for (int i = (0); i <= (4 * n); i++) {       if (i) root[i] = root[i - 1];       for (auto p : inc[i]) {         add(root[i], 0, T - 1, p.first, p.second - 1, 1);         if ((++ti) > RE) ti = 0, Rebuild(i);       }       sort(op[i].begin(), op[i].end());       for (auto p : op[i]) {         ++ti;         if (p.tp == -1)           add(root[p.first / T], 0, T - 1, p.first % T,               (p.second % T == 0 ? T - 1 : p.second % T - 1), 1);         else {           int x = p.ti, w = 0;           if (i > 0) chkmax(w, query(root[i - 1], 0, T - 1, 0, x));           if (i > 1) chkmax(w, mx[root[i - 2]]);           modify(root[i], 0, T - 1, x, w + _w[p.tp]);         }         if (ti > RE) ti = 0, Rebuild(i);       }       for (auto p : Dec[i]) {         add(root[i], 0, T - 1, p.first, p.second - 1, -1);         if ((++ti) > RE) ti = 0, Rebuild(i);       }     }     cout << max(0, mx[root[n * 4]]) + _cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 2000 + 10;   int n, k, a[MAX_N], dp[MAX_N];   bool check(int x) {     for (int i = 0; i < n; i++) {       dp[i] = 1;       for (int j = i - 1; ~j; j--)         if (abs(a[i] - a[j]) <= 1LL * (i - j) * x) dp[i] = max(dp[i], dp[j] + 1);       if (n - dp[i] <= k) return true;     }     return false;   }   int main() {     ios_base ::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     int L = -1, R = 2e9 + 10;     while (L + 1 < R) {       int mid = (1LL * L + R) >> 1;       check(mid) ? R = mid : L = mid;     }     cout << R << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   enum actions { JUMP1, UP1, DOWN1, JUMP2, UP2, DOWN2, NONE };   int n, x;   vector<vector<int> > v(6);   bool wut(int state, int i, actions last, int water) {     if (water - 1 >= i) return false;     if (state == 1) {       if (n < 50000) {         if (v[JUMP1][i] == 1) {           bool isTrue = wut(2, i + x, JUMP1, water + 1);           if (isTrue == false)             v[JUMP1][i] = 0;           else             return true;         } else if (v[JUMP1][i] == 2)           return true;       }       if (v[UP1][i] == 1 && last != DOWN1) {         bool isTrue = wut(state, i + 1, UP1, water + 1);         if (isTrue == false)           v[UP1][i] = 0;         else           return true;       } else if (v[UP1][i] == 2)         return true;       if (v[DOWN1][i] == 1 && last != UP1) {         bool isTrue = wut(state, i - 1, DOWN1, water + 1);         if (isTrue == false)           v[DOWN1][i] = 0;         else           return true;       }       if (n >= 50000) {         if (v[JUMP1][i] == 1) {           bool isTrue = wut(2, i + x, JUMP1, water + 1);           if (isTrue == false)             v[JUMP1][i] = 0;           else             return true;         } else if (v[JUMP1][i] == 2)           return true;       }     } else {       if (n < 50000) {         if (v[JUMP2][i] == 1) {           bool isTrue = wut(1, i + x, JUMP2, water + 1);           if (isTrue == false)             v[JUMP2][i] = 0;           else             return true;         } else if (v[JUMP2][i] == 2)           return true;       }       if (v[UP2][i] == 1 && last != DOWN2) {         bool isTrue = wut(state, i + 1, UP2, water + 1);         if (isTrue == false)           v[UP2][i] = 0;         else           return true;       } else if (v[UP2][i] == 2)         return true;       if (v[DOWN2][i] == 1 && last != UP2) {         bool isTrue = wut(state, i - 1, DOWN2, water + 1);         if (isTrue == false)           v[DOWN2][i] = 0;         else           return true;       }       if (n >= 50000) {         if (v[JUMP2][i] == 1) {           bool isTrue = wut(1, i + x, JUMP2, water + 1);           if (isTrue == false)             v[JUMP2][i] = 0;           else             return true;         } else if (v[JUMP2][i] == 2)           return true;       }     }     return false;   }   int main() {     cin >> n >> x;     string first;     string second;     cin >> first;     cin >> second;     for (int i = 0; i < 6; i++) v[i].assign(n, 0);     for (int i = 0; i < first.size(); i++) {       if (first[i] !=  X ) {         if (i != first.size() - 1 && first[i + 1] !=  X ) v[UP1][i] = 1;         if (i > 0 && first[i - 1] !=  X ) v[DOWN1][i] = 1;         if (i + x < first.size() && second[i + x] !=  X ) v[JUMP1][i] = 1;         if (i == first.size() - 1) v[UP1][i] = 2;         if (i + x >= first.size()) v[JUMP1][i] = 2;       }       if (second[i] !=  X ) {         if (i != second.size() - 1 && second[i + 1] !=  X ) v[UP2][i] = 1;         if (i > 0 && second[i - 1] !=  X ) v[DOWN2][i] = 1;         if (i + x < second.size() && first[i + x] !=  X ) v[JUMP2][i] = 1;         if (i == second.size() - 1) v[UP2][i] = 2;         if (i + x >= second.size()) v[JUMP2][i] = 2;       }     }     if (wut(1, 0, NONE, 0))       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, ans;   struct aa {     int l, r;     int v;   };   bool operator<(aa a, aa b) { return a.r < b.r; }   inline aa qwq(int l, int r, int v) {     aa a;     a.l = l;     a.r = r;     a.v = v;     return a;   }   set<aa> s;   int read() {     register int x = 0, ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return x;   }   void wt() {     for (set<aa>::iterator i = s.begin(); i != s.end(); i++) {       cout << i->l <<     << i->r <<     << i->v <<   n ;     }     cout <<  ------ n ;   }   void spliT(set<aa>::iterator i, int x) {     int l = i->l;     int r = i->r;     int v = i->v;     if (x >= r) return;     if (x < l) return;     s.erase(i);     s.insert(qwq(l, x, v));     s.insert(qwq(x + 1, r, v));     if (v == 1) ans++;   }   void mergE(set<aa>::iterator i) {     int l = i->l, r = i->r, v = i->v;     set<aa>::iterator j = i, k = i;     if (l != 1) {       j--;       if (j->v == v) {         l = j->l;         s.erase(j);         if (v == 1) ans--;       }     }     if (r != n) {       k++;       if (k->v == v) {         r = k->r;         s.erase(k);         if (v == 1) ans--;       }     }     s.erase(i);     s.insert(qwq(l, r, v));   }   void Ass(int l, int r) {     set<aa>::iterator x = s.lower_bound((aa){0, l - 1, 0});     if (l != 1) spliT(x, l - 1);     set<aa>::iterator y = s.lower_bound((aa){0, r, 0});     spliT(y, r);     x = s.lower_bound((aa){0, l, 0});     y = s.lower_bound((aa){0, r + 1, 0});     for (set<aa>::iterator i = x; i != y; i++) {       if (i->v == 1) ans--;     }     s.erase(x, y);     s.insert(qwq(l, r, 1));     ans++;     x = s.lower_bound((aa){0, l, 0});     mergE(x);   }   signed main() {     n = 1000000005;     cin >> m;     s.insert(qwq(1, n, 0));     for (int i = 1; i <= m; i++) {       int l, r;       l = read();       r = read();       r--;       Ass(l, r);       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long MAXN = 1e5 + 7;   const long long MAXM = 1e5 + 7;   const long long MOD = 1e9 + 7;   const double eps = 1e-6;   const double pi = acos(-1.0);   long long a[200005];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     sort(a + 1, a + 1 + n);     long long ans = 0x3f3f3f3f;     for (int i = 1; i <= n / 2; i++) ans = min(ans, a[i + n / 2] - a[i]);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     map<pair<int, int>, int> mp;     map<int, int> mp1;     vector<pair<int, int>> v;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       mp1[x]++;       mp1[y]++;       mp[{x, y}]++;       mp[{y, x}]++;     }     bool f = 0;     for (int i = 1; i <= n; i++) {       v.push_back({mp1[i], i});     }     sort(v.begin(), v.end());     for (int i = 0; i < v.size(); i++) {       if (f) break;       for (int j = i - 1; j > -1 && v[i].first + v[j].first >= m; j--) {         int x = v[i].second, y = v[j].second;         int ans = 0;         ans += mp1[x];         ans += mp1[y];         ans -= mp[{x, y}];         if (ans >= m) {           f = 1;           break;         }       }     }     if (f)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     vector<long long> a;     vector<int> pos;     for (int i = n; i > 0; i--) {       long long p;       cin >> p;       if (p == 0) continue;       a.push_back(p);       pos.push_back(i);     }     reverse(a.begin(), a.end());     reverse(pos.begin(), pos.end());     if (a.empty()) {       cout << string(n,  0 );       return 0;     }     int sz = a.size();     vector<int> last_id(sz);     for (int i = sz - 1; i >= 0; i--) {       if (i < sz - 1 && a[i] == a[i + 1])         last_id[i] = last_id[i + 1];       else         last_id[i] = i;     }     auto get_sum = [&](int l, int r) {       return 1LL * r * (r + 1) / 2 - 1LL * (l - 1) * l / 2;     };     auto solve = [&](long long sum, int l, int r) {       vector<pair<int, int>> res;       if (sum == 0) return res;       if (l > r) {         res = {{-1, -1}};         return res;       }       if (sum < 0 || sum > get_sum(l, r)) {         res = {{-1, -1}};         return res;       }       if (sum == get_sum(l, r)) {         res.emplace_back(l, r);         return res;       }       int lo = 0, hi = r - l + 1;       while (hi - lo > 1) {         int mid = (hi + lo) >> 1;         if (sum >= get_sum(l, l + mid - 1))           lo = mid;         else           hi = mid;       }       int st = lo;       if (sum > get_sum(r - st + 1, r)) {         res = {{-1, -1}};         return res;       }       int skip = r - (l + st - 1);       long long add = sum - get_sum(l, l + st - 1);       int cnt = add / skip;       pair<int, int> a = {l, l + st - 1 - cnt};       pair<int, int> b = {r - cnt + 1, r};       if (add > skip * cnt) {         int c = a.second;         a.second--;         c += add - 1LL * skip * cnt;         res.push_back({c, c});       }       if (a.first <= a.second) res.push_back(a);       if (b.first <= b.second) res.push_back(b);       return res;     };     auto check = [&](vector<pair<int, int>> foo) {       return !(foo.size() == 1 && foo[0] == make_pair(-1, -1));     };     vector<long long> supose(n + 1);     for (int i = n; i > 0; i--) {       int p = lower_bound(pos.begin(), pos.end(), i) - pos.begin();       if (pos[p] == i)         supose[i] = a[p];       else         supose[i] = a[p] - 1;     }     vector<bool> dp(n + 1);     vector<int> par(n + 1);     vector<vector<pair<int, int>>> aux_seg(n + 1);     vector<int> last_true(sz);     int go_from = pos.back();     auto add = [&](int from, int to, int l, int r) {       long long sum = supose[from] - from;       if (to <= n) sum -= supose[to];       auto foo = solve(sum, l, r);       if (check(foo)) {         dp[from] = true;         par[from] = to;         aux_seg[from] = foo;       }     };     for (int cur = go_from; cur > 0; cur--) {       int p = lower_bound(pos.begin(), pos.end(), cur) - pos.begin();       if (pos[p] == cur && p < sz - 1) {         if (a[p] == a[p + 1]) continue;         if (a[p] == a[p + 1] - 1) {           int np = last_id[p + 1];           if (np == sz - 1 || dp[pos[np + 1]]) {             int l = pos[np] + 1;             int r = np == sz - 1 ? n : pos[np + 1] - 1;             add(cur, r + 1, l, r);           }           if (last_true[np]) {             int l = pos[np] + 1;             int r = last_true[np] - 1;             add(cur, r + 1, l, r);           }         }       }       int np = last_id[p];       if (np == sz - 1 || dp[pos[np + 1]]) {         int l = pos[np] + 1;         int r = np == sz - 1 ? n : pos[np + 1] - 1;         add(cur, r + 1, l, r);       }       if (last_true[np]) {         int l = pos[np] + 1;         int r = last_true[np] - 1;         add(cur, r + 1, l, r);       }       if (pos[p] != cur && p && !last_true[p - 1] && dp[cur]) {         last_true[p - 1] = cur;       }     }     string res(n + 1,  0 );     long long bound = -1;     for (int i = 1; i <= n; i++) {       if (dp[i] && (bound == -1 || supose[i] == bound - 1)) {         while (i <= n) {           res[i] =  1 ;           for (auto foo : aux_seg[i]) {             for (int j = foo.first; j <= foo.second; j++) res[j] =  1 ;           }           i = par[i];         }         break;       }       if (pos[0] == i) {         bound = a[0];       }     }     res.erase(res.begin());     reverse(res.begin(), res.end());     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char com[200];     char *p;     int man = 0;     int sum = 0;     int i;     int word;     while (scanf( %c , com) == 1) {       i = 1;       while ((com[i] = getchar()) !=   n ) i++;       com[i] =   0 ;       word = 0;       if (com[0] ==  + ) {         man++;         continue;       }       if (com[0] ==  - ) {         man--;         continue;       }       p = strchr(com,  : );       p += 1;       while (*(p++) !=   0 ) {         word++;       }       sum += word * man;     }     printf( %d , sum);   }


#include <bits/stdc++.h>   const long long INF = (long long)1e18 + 2;   using namespace std;   void solve();   void fastIO() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   int main() {     fastIO();     solve();   }   void solve() {     int n, m;     cin >> n >> m;     char a[n][m];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> a[i][j];     int rs = 200, re = -1, cs = 200, ce = -1;     bool flag = true;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  B ) {           if (i < rs) rs = i;           if (i > re) re = i;           if (j < cs) cs = j;           if (j > ce) ce = j;           flag = false;         }       }     }     if (flag) {       cout << 1;       return;     }     int x = re - rs + 1;     int y = ce - cs + 1;     int mx = max(x, y);     if (n < mx || m < mx) {       cout << -1;       return;     }     int ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  B ) ans++;       }     }     cout << (mx * mx - ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     if (b % a) {       cout << -1 <<   n ;     } else {       int x = b / a;       int ans = 0;       while (x % 2 == 0) {         ans++;         x /= 2;       }       while (x % 3 == 0) {         ans++;         x /= 3;       }       if (x != 1) {         cout << -1 << endl;       } else {         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, nn = 0, nm = 0, dr[5069], dh[10069], pd[5069], pr[5069], fq[10069],                sbt[10069], sm = 0, z = 1e18;   vector<pair<long long, long long>> fz[5069], al[10069];   pair<long long, long long> sk[5069];   vector<long long> pst[5069];   bitset<10069> vtd;   void ae(long long x, long long y, long long w) {     al[x].push_back({y, w});     al[y].push_back({x, w});   }   void bd(long long x) {     long long i, sz = al[x].size(), l;     vtd[x] = 1;     sbt[x] = fq[x];     for (i = 0; i < sz; i++) {       l = al[x][i].first;       if (!vtd[l]) {         bd(l);         sbt[x] += sbt[l];       }     }   }   void dfs(long long x) {     long long i, sz = al[x].size(), l, w;     vtd[x] = 1;     z = min(z, sm);     for (i = 0; i < sz; i++) {       l = al[x][i].first;       w = al[x][i].second;       if (!vtd[l]) {         nn += sbt[x] - sbt[l];         sm += w * (nn - (n - nn));         dfs(l);         sm -= w * (nn - (n - nn));         nn -= sbt[x] - sbt[l];       }     }   }   int main() {     long long i, j, k, l, w, ll, c, p = 0, sz, bg, lca;     for (i = 2; i <= 5000; i++) {       if (fz[i].empty()) {         p++;         for (j = i; j <= 5000; j += i) {           for (c = 0, k = j; k % i == 0; k /= i, c++)             ;           fz[j].push_back({p, c});           dr[j] += c;         }       }     }     nm = 5000;     for (i = 1; i <= 5000; i++) {       sz = fz[i].size();       lca = dh[i - 1];       if (sz) {         bg = fz[i][sz - 1].first;         for (j = 1; j < bg; j++) {           lca -= pd[j];         }       }       for (j = 0; j < sz; j++) {         l = fz[i][j].first;         w = fz[i][j].second;         pd[l] += w;       }       dh[i] = dh[i - 1] + dr[i];       l = 0;       for (; nn && sk[nn].second >= lca; nn--) {         l = sk[nn].first;       }       if (l) {         nn++;         sk[nn] = {l, lca};         sz = pst[l].size();         if (lca < dh[pst[l][sz - 1]]) {           nm++;           dh[nm] = lca;           pst[l].push_back(nm);           sz++;         }         pr[i] = pst[l][sz - 1];       }       nn++;       sk[nn] = {i, dh[i]};       pst[i].push_back(i);     }     for (i = 1; i <= 5000; i++) {       sz = pst[i].size();       for (j = 0; j < sz; j++) {         l = pst[i][j];         if (j) {           ae(ll, l, dh[ll] - dh[l]);         }         ll = l;       }       if (pr[i]) {         ae(pst[i][sz - 1], pr[i], dh[pst[i][sz - 1]] - dh[pr[i]]);       }     }     scanf( %lld , &n);     for (i = 0; i < n; i++) {       scanf( %lld , &k);       k += !k;       fq[k]++;       sm += dh[k];     }     bd(1);     vtd.reset();     nn = 0;     dfs(1);     printf( %lld n , z);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, n, i, j, k;     double p, q, m;     cin >> n >> m;     p = pow(1.000000011, m);     q = n * p;     printf( %.12lf , q);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005], in[100005];   int main() {     int n, m;     scanf( %d , &n);     int i, j;     for (i = 0; i < n; i++) {       scanf( %d , &in[i]);       in[i] = ++a[in[i]];     }     for (i = 2; i <= 100000; i++)       if (a[i] > a[i - 1]) break;     if (i <= 100000)       printf( -1 n );     else {       printf( %d n , a[1]);       for (i = 0; i < n; i++) printf( %d%c , in[i],    n [i == n - 1]);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   struct ST {     int l, r, mx, c;   } t[N << 2];   int n, k, m, nn, tot, R, sum;   int ls[N], rs[N], a[N], rk[N], sa[N], h[N], tp[N], tax[N], f[N][18], lg[N],       tag[N], len[N], num[N];   long long ans[N];   char s[N];   void rsort() {     int i;     for (i = 0; i <= m; i++) tax[i] = 0;     for (i = 1; i <= n; i++) tax[rk[tp[i]]]++;     for (i = 1; i <= m; i++) tax[i] += tax[i - 1];     for (i = n; i >= 1; i--) sa[tax[rk[tp[i]]]--] = tp[i];   }   void suffix() {     int i;     for (i = 1; i <= n; i++) rk[i] = a[i], tp[i] = i;     m = tot;     rsort();     for (int w = 1, p = 0; p < n; w += w, m = p) {       p = 0;       for (i = n - w + 1; i <= n; i++) tp[++p] = i;       for (i = 1; i <= n; i++)         if (sa[i] > w) tp[++p] = sa[i] - w;       rsort();       swap(rk, tp);       rk[sa[1]] = p = 1;       for (i = 2; i <= n; i++)         if (tp[sa[i]] == tp[sa[i - 1]] && tp[sa[i] + w] == tp[sa[i - 1] + w])           rk[sa[i]] = p;         else           rk[sa[i]] = ++p;     }   }   void height() {     int i, j = 0, k = 0;     for (i = 1; i <= n; i++) rk[sa[i]] = i;     for (i = 1; i <= n; i++) {       if (k) k--;       if (rk[i] == 1) continue;       j = sa[rk[i] - 1];       while (a[j + k] == a[i + k]) k++;       h[rk[i]] = k;     }   }   void build(int k, int l, int r) {     t[k].l = l;     t[k].r = r;     t[k].mx = 0;     t[k].c = 0;     if (l == r) return;     int mid = (l + r) >> 1;     build(k << 1, l, mid);     build(k << 1 | 1, mid + 1, r);   }   void add(int k, int w) {     t[k].mx = max(t[k].mx, w);     t[k].c = max(t[k].c, w);   }   void pushdown(int k) {     if (t[k].c) {       add(k << 1, t[k].c);       add(k << 1 | 1, t[k].c);       t[k].c = 0;     }   }   void modify(int k, int L, int R, int w) {     if (L <= t[k].l && t[k].r <= R) {       add(k, w);       return;     }     pushdown(k);     int mid = (t[k].l + t[k].r) >> 1;     if (L <= mid) modify(k << 1, L, R, w);     if (R > mid) modify(k << 1 | 1, L, R, w);   }   int query(int k, int p) {     if (t[k].l == t[k].r) return t[k].mx;     pushdown(k);     int mid = (t[k].l + t[k].r) >> 1;     if (p <= mid)       return query(k << 1, p);     else       return query(k << 1 | 1, p);   }   void init() {     int i, j;     for (i = 1; i <= n; i++) f[i][0] = h[i];     for (i = 1; i <= n; i++) lg[i] = log2(i);     for (i = 1; i <= 17; i++)       for (j = 1; j + (1 << i) - 1 <= n; j++)         f[j][i] = min(f[j][i - 1], f[j + (1 << i - 1)][i - 1]);   }   int rmq(int l, int r) {     l = rk[l];     r = rk[r];     if (l > r) swap(l, r);     l++;     if (l > r) return len[sa[r]];     int d = lg[r - l + 1];     return min(f[l][d], f[r - (1 << d) + 1][d]);   }   void solve() {     int i, l1, r1 = 0, l2 = 0, r2 = 0;     build(1, 1, n);     for (l1 = 1; l1 <= n; l1++) {       if (!tag[sa[l1]]) continue;       if (l1 > 1) {         num[tag[sa[l1 - 1]]]--;         if (!num[tag[sa[l1 - 1]]] && tag[sa[l1 - 1]]) sum--;       }       while (r1 < n && sum < k) {         r1++;         if (!num[tag[sa[r1]]] && tag[sa[r1]]) sum++;         num[tag[sa[r1]]]++;       }       if (sum < k) break;       modify(1, l1, r1, rmq(sa[l1], sa[r1]));       if (l2 > 0)         for (i = r2 + 1; i <= r1; i++) modify(1, i, i, rmq(sa[l2], sa[i]));       l2 = l1;       r2 = r1;     }     if (r2 < n && l2 > 0)       for (i = r2 + 1; i <= n; i++) modify(1, i, i, rmq(sa[l2], sa[i]));   }   int main() {     int i, j;     scanf( %d%d , &nn, &k);     tot = 26;     for (i = 1; i <= nn; i++) {       scanf( %s , s + 1);       m = strlen(s + 1);       ls[i] = n + 1;       for (j = 1; j <= m; j++) {         a[++n] = s[j] -  a  + 1;         tag[n] = i;         len[n] = m - j + 1;       }       rs[i] = n;       if (i < nn) a[++n] = ++tot;       if (k == 1) ans[i] = 1ll * m * (m + 1) / 2;     }     if (k == 1) {       for (i = 1; i <= nn; i++) printf( %I64d  , ans[i]);       return 0;     }     a[0] = -1;     a[n + 1] = 1000000000;     suffix();     height();     init();     solve();     for (i = 1; i <= n; i++)       if (tag[sa[i]]) ans[tag[sa[i]]] += 1ll * query(1, i);     for (i = 1; i <= nn; i++) printf( %I64d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> arr(5, vector<int>(200005));   int main() {     int t, n, i, ans, a, b, c, d, e, m, j, s, curr;     string s1;     cin >> t;     while (t--) {       cin >> n;       for (i = 0; i < n; i++) {         cin >> s1;         a = 0;         b = 0;         c = 0;         d = 0;         e = 0;         m = s1.size();         for (j = 0; j < m; j++) {           if (s1[j] ==  a )             a++;           else if (s1[j] ==  b )             b++;           else if (s1[j] ==  c )             c++;           else if (s1[j] ==  d )             d++;           else if (s1[j] ==  e )             e++;         }         arr[0][i] = a - (m - a);         arr[1][i] = b - (m - b);         arr[2][i] = c - (m - c);         arr[3][i] = d - (m - d);         arr[4][i] = e - (m - e);       }       for (i = 0; i < 5; i++)         sort(arr[i].begin(), arr[i].begin() + n, greater<int>());       ans = 0;       for (i = 0; i < 5; i++) {         curr = 0;         j = 0;         s = 0;         while (j < n && arr[i][j] > 0) {           s += arr[i][j];           curr++;           j++;         }         while (j < n && (s + arr[i][j]) > 0) {           s += arr[i][j];           curr++;           j++;         }         ans = max(ans, curr);       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9;   int c2i(char c) {     if (c <=  9 ) return c -  0 ;     return c -  A  + 10;   }   long long conv(string num, int base) {     long long res = 0;     for (int i = 0; i < (int)num.length(); i++) {       if (c2i(num[i]) >= base) return INF;       res = res * base + c2i(num[i]);     }     return res;   }   int main() {     string inp, h, m;     cin >> inp;     for (int i = 0; i < (int)inp.length(); i++)       if (inp[i] ==  : ) inp[i] =    ;     istringstream sin(inp);     sin >> h >> m;     vector<int> res;     for (int base = 2; base <= 100; base++)       if (conv(h, base) < 24 && conv(m, base) < 60) res.push_back(base);     if (res.empty())       cout << 0 << endl;     else if (res.back() == 100)       cout << -1 << endl;     else {       for (int i = 0; i < (int)res.size(); i++) cout << res[i] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   int n;   int m;   int a, b;   long long fast_mod_pow(long long a, long long b) {     long long res = 1;     a %= mod;     while (b) {       if (b & 1) {         res = (res * a) % mod;       }       a = (a * a) % mod;       b >>= 1;     }     return res;   }   const int MAXN = 1000005;   long long fac[MAXN];   long long invfact[MAXN];   int main() {     cin >> n >> m >> a >> b;     long long ans = 0;     fac[0] = 1;     fac[1] = 1;     for (int i = 2; i < MAXN; i++) {       fac[i] = fac[i - 1] * i;       fac[i] %= mod;     }     invfact[MAXN - 1] = fast_mod_pow(fac[MAXN - 1], mod - 2);     for (int i = MAXN - 2; i >= 0; i--) {       invfact[i] = (invfact[i + 1] * (i + 1)) % mod;     }     for (int i = 1; i <= m; i++) {       if (i > n - 1) break;       long long temp = 1;       temp *= fac[m - 1];       temp %= mod;       temp *= invfact[m - i];       temp %= mod;       temp *= invfact[i - 1];       temp %= mod;       temp *= fac[n - 2];       temp %= mod;       temp *= invfact[n - i - 1];       temp %= mod;       if ((n - i - 1) == 0) {         ans += temp;         ans %= mod;         continue;       }       temp *= fast_mod_pow((long long)m, (long long)(n - i - 1));       temp %= mod;       temp *= (i + 1);       temp %= mod;       temp *= fast_mod_pow((long long)n, (long long)(n - i - 2));       temp %= mod;       ans += temp;       ans %= mod;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(pair<float, int> a, pair<float, int> b) {     if (a.first > b.first)       return true;     else if (a.first == b.first)       return a.second < b.second;     else       return false;   }   inline istream& skip_endl(istream& is) {     return is.ignore(numeric_limits<streamsize>::max(),   n );   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     long double t1, t2, k, a, b, h1, h2;     cin >> n >> t1 >> t2 >> k;     vector<pair<long double, int>> heights;     for (int i = 1; i <= n; i++) {       cin >> a >> b;       h1 = (a * t1) - (a * t1 * (k / 100.0)) + (b * t2);       h2 = (b * t1) - (b * t1 * (k / 100.0)) + (a * t2);       heights.push_back(make_pair(max(h1, h2), i));     }     sort(heights.begin(), heights.end(), comp);     for (auto h : heights) {       cout << fixed << setprecision(2) << h.second;       cout <<     << h.first <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937_64 rd(787);   int a[500010];   int cnt[500010];   unsigned long long has[500010];   unsigned long long val[500010];   list<int> vec[500010];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     auto t = clock();     auto now_time = [&] { return (clock() - t) / (double)CLOCKS_PER_SEC; };     int n;     cin >> n;     unsigned long long anss = 1e18;     for (int i = 1; i <= n; i++) cin >> a[i];     while (now_time() < 4) {       for (int i = 1; i <= n; i++) val[i] = rd(), vec[i].clear();       unsigned long long ans = 0;       map<unsigned long long, int> mp;       mp[0]++;       int pre = 0;       for (int i = 1; i <= n; i++) {         int tmp = a[i];         has[i] = has[i - 1] + val[tmp], cnt[tmp]++, vec[tmp].push_back(i);         if (cnt[tmp] % 3 == 0) {           has[i] -= 3 * val[tmp];         }         mp[has[i]]++;         if (vec[tmp].size() > 3) {           int now = vec[tmp].front();           vec[tmp].pop_front();           for (; pre < now; pre++) {             mp[has[pre]]--;           }         }         ans += mp[has[i]] - 1;       }       anss = min(ans, anss);       break;     }     cout << anss << endl;   }


#include <bits/stdc++.h>   using namespace std;   int N;   vector<int> V;   bool solve(int n);   int main() {     ios_base::sync_with_stdio(false);     int i, st, dr, mid;     cin >> N;     V.resize(N);     for (i = 0; i < N; ++i) {       cin >> V[i];     }     sort(V.begin(), V.end());     st = 1;     dr = N;     while (st < dr) {       mid = (st + dr) / 2;       if (solve(mid)) {         dr = mid;       } else {         st = mid + 1;       }     }     cout << dr <<   n ;     return 0;   }   bool solve(int n) {     int i, j, nr;     vector<int> piles;     piles.resize(n, 101);     j = 0;     for (i = N - 1; i >= 0; --i) {       nr = 0;       while (piles[j] == 0) {         ++j;         ++nr;         if (j == n) j = 0;         if (nr == n + 1) break;       }       if (nr == n + 1) break;       piles[j] = min(piles[j] - 1, V[i]);       ++j;       if (j == n) j = 0;     }     if (i == -1) {       return true;     }     return false;   }


#include <bits/stdc++.h>   using namespace std;   string s, t;   int l = 0, r = 0;   int main() {     cin >> s >> t;     while (s[l] !=  | ) l++;     r = s.size() - l - 1;     int dif;     if (l > r)       dif = t.size() - (l - r);     else       dif = t.size() - (r - l);     if (dif < 0 || dif & 1) {       cout <<  Impossible  << endl;       return 0;     }     if (l < r) {       reverse(s.begin(), s.end());       int i = 0;       while (l < r) {         s += t[i];         i++;         l++;       }       while (i < t.size()) {         s += t[i];         i++;         s = t[i] + s;         i++;       }       reverse(s.begin(), s.end());       cout << s << endl;       return 0;     }     int i = 0;     while (r < l) {       s += t[i];       i++;       r++;     }     while (i < t.size()) {       s += t[i];       i++;       s = t[i] + s;       i++;     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fib[100];   void init() {     fib[0] = 1, fib[1] = 2;     for (int i = 2; i <= 85; i++) fib[i] = fib[i - 1] + fib[i - 2];   }   int w[100];   int dp[100][2];   void solve(long long x) {     memset(w, 0, sizeof(w));     memset(dp, 0, sizeof(dp));     int num = 0;     for (int i = 85; i >= 0; i--) {       if (x >= fib[i]) {         x -= fib[i];         w[num++] = i;       }     }     num--;     dp[0][1] = 1;     dp[0][0] = w[num] >> 1;     int i = 0;     while (num > 0) {       num--;       dp[i + 1][0] = dp[i][0] * ((w[num] - w[num + 1]) >> 1) +                      dp[i][1] * ((w[num] - w[num + 1] - 1) >> 1);       dp[i + 1][1] = dp[i][0] + dp[i][1];       i++;     }     cout << dp[i][0] + dp[i][1] << endl;   }   int main() {     ios::sync_with_stdio(false);     init();     int t;     cin >> t;     while (t--) {       long long x;       cin >> x;       solve(x);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, s, d, n;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a >> s;       if (s - a >= 2) d++;     }     cout << d;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   int n, t1, t2, cnt;   vector<int> mem[N];   int imp[N], hgt[N], res[N];   int p[N], noww[2 * N], goal[2 * N];   void link(int f, int t) {     noww[++cnt] = p[f];     goal[cnt] = t, p[f] = cnt;   }   void DFS(int nde, int fth) {     for (int i = p[nde]; i; i = noww[i])       if (goal[i] != fth) {         DFS(goal[i], nde);         if (hgt[nde] <= hgt[goal[i]])           hgt[nde] = hgt[goal[i]] + 1, imp[nde] = goal[i];       }     if (!imp[nde])       mem[nde].push_back(1);     else {       swap(mem[nde], mem[imp[nde]]), res[nde] = res[imp[nde]];       for (int i = p[nde]; i; i = noww[i])         if (goal[i] != fth && goal[i] != imp[nde]) {           int s1 = mem[nde].size(), s2 = mem[goal[i]].size();           for (int j = 0; j < s2; j++) {             mem[nde][s1 - s2 + j] += mem[goal[i]][j];             if (mem[nde][res[nde]] <= mem[nde][s1 - s2 + j])               res[nde] = s1 - s2 + j;           }         }       mem[nde].push_back(1);       if (mem[nde][res[nde]] == 1) res[nde] = mem[nde].size() - 1;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scanf( %d%d , &t1, &t2);       link(t1, t2), link(t2, t1);     }     DFS(1, 0);     for (int i = 1; i <= n; i++) printf( %d n , hgt[i] - res[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) f = ch ==  -  ? -1 : f, ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return x * f;   }   const int N = 200050;   int sta[3][N], f[3][N], F[3];   int n, m, s, e;   int pos[N];   void dp() {     for (int t = 0; t < 3; t++)       for (int i = sta[t][0] - 1; i >= 1; i--)         f[t][i] = f[t][i + 1] + max(sta[t][i + 1] - sta[t][i] - s, 0);   }   int binary_search(int t, int x) {     int ret, l = 1, r = sta[t][0], mid;     while (l <= r) {       mid = l + r >> 1;       if (sta[t][mid] >= x)         ret = mid, r = mid - 1;       else         l = mid + 1;     }     return ret;   }   int main() {     pos[0] = e = read(), s = read(), n = read(), m = read();     for (int i = 0; i < 3; i++) sta[i][++sta[i][0]] = pos[0];     for (int i = 1, tp; i <= n; i++) {       tp = read(), pos[i] = read();       if (pos[i] >= e) continue;       switch (tp) {         case 3:           sta[2][++sta[2][0]] = pos[i];         case 2:           sta[1][++sta[1][0]] = pos[i];         case 1:           sta[0][++sta[0][0]] = pos[i];       }     }     sort(sta[0] + 1, sta[0] + sta[0][0] + 1),         sort(sta[1] + 1, sta[1] + sta[1][0] + 1),         sort(sta[2] + 1, sta[2] + sta[2][0] + 1);     dp();     for (int i = 1, x; i <= m; i++) {       x = read();       for (int t = 0; t < 3; t++) {         int y = binary_search(t, x);         F[t] = f[t][y] + max(sta[t][y] - x - s, 0);       }       if (F[0] > 0)         printf( -1 -1 n );       else         printf( %d %d n , F[1], F[2] - F[1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ans {     int s, t;   };   const int nmax = 100006;   int n, v[nmax], s1[nmax], s2[nmax], rasp, acts, fp1[nmax], fp2[nmax];   ans vrasp[nmax];   bool ver;   int compar(ans a, ans b) {     if (a.t != b.t)       return a.t < b.t;     else       return a.s < b.s;   }   int main() {     int player_unu = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> v[i];       s1[i] = s1[i - 1];       s2[i] = s2[i - 1];       if (v[i] == 1) {         s1[i]++;         fp1[s1[i]] = i;       } else {         s2[i]++;         fp2[s2[i]] = i;       }     }     if (v[n] == 2)       for (int i = 1; i <= n; i++) {         v[i] = 3 - v[i];         swap(s1[i], s2[i]);         swap(fp1[i], fp2[i]);       }     for (int i = n; i > 0; i--) {       if (s1[n] - s1[i - 1] > s2[n] - s2[i - 1] && v[i] == 1) {         acts = s1[n] - s1[i - 1];         int nrs1 = 0, nrs2 = 0, pozact = i;         ver = 0;         for (int j = 0; j < n;) {           if (s1[j] + acts > s1[n] && s2[j] + acts > s2[n]) {             ver = 1;             break;           }           if (s2[j] + acts > s2[n]) {             nrs1++;             j = fp1[s1[j] + acts];             continue;           }           if (s1[j] + acts > s1[n]) {             nrs2++;             j = fp2[s2[j] + acts];             continue;           }           if (fp1[s1[j] + acts] < fp2[s2[j] + acts]) {             nrs1++;             j = fp1[s1[j] + acts];           } else {             nrs2++;             j = fp2[s2[j] + acts];           }         }         if (ver == 0 && nrs1 > nrs2) {           vrasp[rasp].s = acts;           vrasp[rasp].t = nrs1;           rasp++;         }       }     }     sort(vrasp, vrasp + rasp, compar);     cout << rasp <<   n ;     for (int i = 0; i < rasp; i++)       cout << vrasp[i].t <<     << vrasp[i].s <<   n ;     return player_unu;   }


#include <bits/stdc++.h>   using namespace std;   int o, trues, Bruh, YO;   bool levls[696969];   int main() {     int n, X;     cin >> n;     for (int a = 0; a < 2; a++) {       cin >> Bruh;       for (int AL = 0; AL < Bruh; AL++) {         cin >> YO;         levls[YO] = true;       }     }     for (int x = 1; x <= n; x++) {       if (levls[x] == true) trues++;     }     if (trues == n)       cout <<  I become the guy.  << endl;     else       cout <<  Oh, my keyboard!  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int N = 1000040;   long long fact[N], invf[N];   vector<long long> primes;   long long add(long long x, long long y) { return (x + y) % mod; }   long long mul(long long x, long long y) { return (x % mod) * (y % mod) % mod; }   long long powll(long long x, long long y) {     long long res = 1LL;     while (y) {       if (y & 1LL) res *= x;       res %= mod;       x = (x * x) % mod;       y >>= 1LL;     }     return res;   }   long long divll(long long x, long long y) {     return (x * powll(y, mod - 2)) % mod;   }   long long nPr(long long n, long long r) {     if (n < r || r < 0) return 0;     return mul(fact[n], invf[n - r]);   }   long long nCr(long long n, long long r) {     if (n < r || r < 0) return 0;     return mul(mul(fact[n], invf[r]), invf[n - r]);   }   long long solve() {     long long x, y;     scanf( %lld %lld , &x, &y);     vector<long long> c;     for (long long p : primes) {       int k = 0;       while (x % p == 0) {         k++;         x /= p;       }       if (k) c.push_back(k);     }     if (x > 1) c.push_back(1);     long long ret = powll(2, y - 1);     for (long long a : c) {       ret = (ret * nCr(y + a - 1, a)) % mod;     }     return ret;   }   int main() {     int q;     cin >> q;     fact[0] = invf[0] = 1;     for (int i = 1; i <= N - 1; ++i) {       fact[i] = (fact[i - 1] * i) % mod;       invf[i] = divll(invf[i - 1], i);     }     long long lim = 1000;     vector<int> check(lim, 1);     for (int i = 2; i <= lim - 1; ++i) {       if (!check[i]) continue;       primes.push_back(i);       for (int j = 2 * i; j < lim; j += i) check[j] = 0;     }     while (q--) {       printf( %lld n , solve());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, y;     cin >> t;     while (t--) {       int n;       cin >> n;       long long a[n];       for (int i = 0; i < n; i++) cin >> a[i];       long long res, mx = 0;       for (int i = 0; i < n - 1; i++) {         res = a[i] * a[i + 1];         mx = max(res, mx);       }       cout << mx << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     cin >> n;     if (n == 0) {       printf( a );       return 0;     }     for (char c =  a ; c <=  z  && n; c++) {       int sum = 0, i;       for (i = 0; i <= n; i++) {         n -= i;         cout << c;       }     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int setbit(int n, int pos) { return n = n | (1 << pos); }   int resetbit(int n, int pos) { return n = n & ~(1 << pos); }   bool checkbit(int n, int pos) { return (bool)(n & (1 << pos)); }   template <typename T>   T modMul(T x, T y, T mod = 1e9 + 7) {     x %= mod;     y %= mod;     return (x * y) % mod;   }   template <typename T>   T modAdd(T x, T y, T mod = 1e9 + 7) {     x %= mod;     y %= mod;     return (x + y) % mod;   }   template <typename T>   T ext_gcd(T num1, T num2, T &X, T &Y) {     T r2, r1, q2, q1, x2, x1, y2, y1, x, y, r;     x2 = 1;     y2 = 0;     x1 = 0;     y1 = 1;     for (r2 = num1, r1 = num2; r1 != 0;          y2 = y1, y1 = y, x2 = x1, x1 = x, r2 = r1, r1 = r) {       q1 = r2 / r1;       x = x2 - q1 * x1;       y = y2 - q1 * y1;       r = r2 % r1;     }     X = x2;     Y = y2;     return r2;   }   template <typename T>   void print(const T &v) {     cerr << v <<    ;   }   template <typename T1, typename... T2>   void print(const T1 &first, const T2 &...rest) {     print(first);     print(rest...);   }   template <class T>   string to_str(T t) {     stringstream second;     second << t;     return second.str();   }   template <typename T>   T modPow(T x, T k, T mod = 1e9 + 7) {     if (k == 0) return (T)1;     if (k & 1) {       return ((x % mod) * modPow(x, k - 1, mod) % mod) % mod;     } else {       T ret = modPow(x, k / 2, mod);       ret %= mod;       return (ret * ret) % mod;     }   }   template <typename T>   T modInv(T x, T m) {     return modPow(x, m - 2, m);   }   template <typename T>   void dbg_a(T a[], int n = 10) {     cerr <<  [  ;     for (int i = 0; i < n; i++) cerr << a[i] <<    ;     cerr <<   ]           <<   n ;   }   template <typename F, typename S>   ostream &operator<<(ostream &os, const pair<F, S> &p) {     return os <<  [   << p.first <<  ,   << p.second <<   ] ;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  [  ;     for (int i = 0; i < v.size(); i++) os << v[i] <<    ;     return os <<   ] n ;   }   template <typename T>   ostream &operator<<(ostream &os, const map<T, T> &Map) {     os <<  [  ;     for (__typeof((Map).begin()) it = (Map).begin(); it != (Map).end(); ++it)       os <<  [  << (*it).first <<     << (*it).second <<  ]  ;     return os <<  ] n ;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &Set) {     os <<  [  ;     for (__typeof((Set).begin()) it = (Set).begin(); it != (Set).end(); ++it)       os << *it <<    ;     return os <<   ] n ;   }   const int maxn = (int)2e6 + 123;   const int inf = 0x3f;   const long long mod = (long long)1e9 + 7LL;   int a[maxn];   void solve() {     int n, q, cnt = 0, ans = 0, magic = 0;     vector<int> even, odd;     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) {       int x = s[i] -  0 ;       if (x & 1)         odd.push_back(x);       else         even.push_back(x);     }     reverse(odd.begin(), odd.end());     reverse(even.begin(), even.end());     for (int i = 0; i < s.size(); i++) {       if (odd.size() == 0) {         cout << even.back();         even.pop_back();       } else if (even.size() == 0) {         cout << odd.back();         odd.pop_back();       } else {         if (even.back() < odd.back()) {           cout << even.back();           even.pop_back();         } else {           cout << odd.back();           odd.pop_back();         }       }     }     cout <<   n ;   }   int main() {     ios ::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1, c = 0;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T max(T a, T b, T c) {     return max(a, max(b, c));   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long a, b, c;     cin >> a >> b >> c;     cout << 2 * min(a + c, min(b + c, (a + b + c) / 2)) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int x, y, z;     cin >> x >> y >> z;     if (x > y) {       if (x > y + z)         cout <<  + ;       else         cout <<  ? ;     } else if (x < y) {       if (y > x + z)         cout <<  - ;       else         cout <<  ? ;     } else if (z != 0)       cout <<  ? ;     else       cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)2e9;   const long long INFL = (long long)9e18;   const int MAXINT = ((~0) ^ (1 << 31));   const long long MAXLL = ((~0) ^ ((long long)1 << 63));   template <class T>   inline T pow2(T a) {     return a * a;   }   template <class T>   inline bool mineq(T& a, T b) {     return (a > b) ? (a = b, true) : false;   }   template <class T>   inline bool maxeq(T& a, T b) {     return (a < b) ? (a = b, true) : false;   }   const int maxn = (int)2222;   ;   char grid[maxn][maxn];   int v[maxn][maxn], h[maxn][maxn], t[maxn][maxn], n, m;   long long ans0() {     long long ans = 0;     for (int i = 2; i < (int)(n); i++) {       ans += (v[i][m] == 0);     }     return ans;   }   long long ans1() {     long long ans = 0;     for (int i = 2; i < (int)(n); i++) {       for (int j = 2; j < (int)(m); j++) {         if (grid[i][j] ==  # ) continue;         ans += (h[i][j] == 0 && v[i][j] == 0);         ans += (h[i][j] == h[n][j] && v[i][j] == 0);         ans += (h[i][j] == 0 && v[i][j] == v[i][m]);         ans += (h[i][j] == h[n][j] && v[i][j] == v[i][m]);       }     }     return ans;   }   long long ans2() {     long long ans = 0;     int up[maxn] = {}, down[maxn] = {};     for (int i = 2; i < (int)(n); i++) {       int l = 2, r;       while (l < m) {         if (grid[i][l] ==  # ) {           l++;           continue;         }         r = l;         while (r < m && v[i][l] == v[i][r]) r++;         for (int j = l; j < (int)(r); j++) {           up[j] = (h[i][j] == 0);           down[j] = (h[i][j] == h[n][j]);           if (j - 2 >= l) ans += up[j] * up[j - 2] + down[j] * down[j - 2];           if (j - 1 >= l) ans += up[j] * down[j - 1] + down[j] * up[j - 1];           if (j != l) up[j] += up[j - 1];           if (j != l) down[j] += down[j - 1];         }         l = r;       }     }     return ans;   }   void pre() {     for (int i = 1; i < (int)(n + 1); i++) {       for (int j = 1; j < (int)(m + 1); j++) {         v[i][j] = v[i][j - 1] + (grid[i][j] ==  # );         h[i][j] = h[i - 1][j] + (grid[i][j] ==  # );       }     }   }   void reversegrid() {     for (int i = 1; i < (int)(n + 1); i++)       for (int j = 1; j < (int)(m + 1); j++) t[j][i] = grid[i][j];     for (int i = 1; i < (int)(m + 1); i++)       for (int j = 1; j < (int)(n + 1); j++) grid[i][j] = t[i][j];     swap(n, m);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i < (int)(n + 1); i++)       for (int j = 1; j < (int)(m + 1); j++) cin >> grid[i][j];     pre();     long long ans = ans0() + ans1() + ans2();     reversegrid();     pre();     cout << ans + ans0() + ans2();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(NULL);     int n;     cin >> n;     priority_queue<int, vector<int>, greater<int>> servers;     priority_queue<pair<int, int>, vector<pair<int, int>>,                    greater<pair<int, int>>>         pq;     for (int i = 0; i < n; i++) {       servers.push(i + 1);     }     int q, t, k, d;     cin >> q;     for (int i = 0; i < q; i++) {       cin >> t >> k >> d;       while (pq.empty() == false) {         pair<int, int> top = pq.top();         if (top.first < t) {           servers.push(top.second);           pq.pop();         } else {           break;         }       }       if (servers.size() >= k) {         int total = 0, serverId;         int endTime = t + d - 1;         for (int j = 0; j < k; j++) {           serverId = servers.top();           servers.pop();           total += serverId;           pq.push(make_pair(endTime, serverId));         }         cout << total <<   n ;       } else {         cout <<  -1 n ;       }     }     return 0;   }


#include <bits/stdc++.h>   const int maxn = 1e5, maxm = 1e5, maxCell = 1e5;   const int maxv = maxCell + 4, maxe = maxCell * 4 + 4 * maxCell;   const int inf = std::numeric_limits<int>::max() / 2;   namespace Network {   struct GraphInfo {     int vertex, source, sink;   };   struct Edge {     int from, to;     mutable int flow;     const Edge *pre, *rev;   } ed[maxe * 2 + 10], *end = ed;   const Edge *head[maxv + 10], *cur[maxv + 10];   int exceed[maxv + 10], dep[maxv + 10];   enum class EdgeType { Normal, Required };   inline void addGraphEdge(const int from, const int to, const int flow) {     new (end) Edge{from, to, flow, head[from], end + 1};     head[from] = end++;     new (end) Edge{to, from, 0, head[to], end - 1};     head[to] = end++;   }   template <EdgeType et>   inline void addUnitEdge(const int from, const int to) {     if constexpr (et == EdgeType::Required) {       --exceed[from];       ++exceed[to];     } else       addGraphEdge(from, to, 1);   }   bool bfs(const int n, const int source, const int sink) {     std::queue<int> q;     std::fill(dep, dep + n, inf);     q.push(source);     dep[source] = 0;     while (!q.empty()) {       const int cur = q.front();       q.pop();       for (const Edge *i = head[cur]; i; i = i->pre)         if (i->flow && dep[i->to] == inf) {           dep[i->to] = dep[cur] + 1;           q.push(i->to);         }     }     return dep[sink] != inf;   }   int dfs(const int x, const int cap, const int sink) {     if (x == sink || !cap) return cap;     int rst = cap;     for (; cur[x]; cur[x] = cur[x]->pre) {       const Edge *i = cur[x];       if (i->flow && dep[i->to] == dep[x] + 1) {         const int d = dfs(i->to, std::min(rst, i->flow), sink);         i->flow -= d;         i->rev->flow += d;         rst -= d;         if (!rst) break;       }     }     return cap - rst;   }   int dinic(const GraphInfo gi) {     int ret = 0;     while (bfs(gi.vertex, gi.source, gi.sink)) {       std::memcpy(cur, head, sizeof(cur[0]) * gi.vertex);       ret += dfs(gi.source, inf, gi.sink);     }     return ret;   }   bool hasSolution(const int virtSource) {     for (const Edge *i = head[virtSource]; i; i = i->pre)       if (i->flow) return false;     return true;   }   void init(const int n) {     end = ed;     std::memset(head, 0, sizeof(head[0]) * (n + 2));     std::memset(exceed, 0, sizeof(exceed[0]) * (n + 2));   }   int findMatch(const int v, const int limit) {     for (const Edge *i = head[v]; i; i = i->pre)       if (!i->flow && i->to < limit) return i->to;     return limit;   }   bool boundMaxFlow(const GraphInfo gi) {     const int virtSource = gi.vertex, virtSink = virtSource + 1;     addGraphEdge(gi.sink, gi.source, inf);     for (int i = 0; i < gi.vertex; ++i)       if (exceed[i] > 0)         addGraphEdge(virtSource, i, exceed[i]);       else if (exceed[i] < 0)         addGraphEdge(i, virtSink, -exceed[i]);     dinic(GraphInfo{virtSink + 1, virtSource, virtSink});     return hasSolution(virtSource);   }   }  // namespace Network   int n, m;   enum Direction { Left, Right, Down, Up, None };   const Direction reverse[]{Right, Left, Up, Down, None};   struct Step {     int dx, dy;     inline bool operator==(const Step s) const {       return dx == s.dx && dy == s.dy;     }   };   const Step step[]{{0, -1}, {0, 1}, {1, 0}, {-1, 0}};   const char directionName[] = { L ,  R ,  D ,  U };   struct Position {     int x, y;     inline static Position fromId(const int id) {       const div_t d = div(id, m);       return Position{d.quot, d.rem};     }     inline Position operator+(const struct Step s) const {       return Position{x + s.dx, y + s.dy};     }     inline Step operator-(const Position r) const {       return Step{x - r.x, y - r.y};     }     inline bool isValid() const { return x >= 0 && y >= 0 && x < n && y < m; }     inline int id() const { return x * m + y; }   };   struct Cell {     Direction next;     int sum, val;   } cell[maxCell + 10];   namespace GraphBuilder {   template <bool rev, Network::EdgeType type>   inline void linkVertex(const int from, const int to) {     if constexpr (rev)       Network::addUnitEdge<type>(to, from);     else       Network::addUnitEdge<type>(from, to);   }   template <bool toSink>   inline void linkCell(const Position pos, const int endpoint) {     using Network::EdgeType;     const int cid = pos.id();     Cell &cur = cell[cid];     cur.next = Direction::None;     for (int k = 0; k < 4; ++k)       if (const auto nxt = pos + step[k]; nxt.isValid()) {         const int nextId = nxt.id();         if (cell[nextId].sum < cur.sum)           cur.next = static_cast<Direction>(k);         else if (!toSink && cell[nextId].sum == cur.sum)           Network::addUnitEdge<EdgeType::Normal>(cid, nextId);       }     if (cur.next == Direction::None)       linkVertex<toSink, EdgeType::Required>(endpoint, cid);     else       linkVertex<toSink, EdgeType::Normal>(endpoint, cid);   }   inline bool isLinkSink(const Position &p) {     return (p.x & 0x01) ^ (p.y & 0x01);   }   static Network::GraphInfo build(const int n, const int m) {     const int source = n * m, sink = source + 1;     Network::init(sink + 1);     for (int i = 0; i < n; ++i)       for (Position pos{i, 0}; pos.y < m; ++pos.y)         if (isLinkSink(pos))           linkCell<true>(pos, sink);         else           linkCell<false>(pos, source);     return Network::GraphInfo{sink + 1, source, sink};   }   }  // namespace GraphBuilder   void construct(const int n, const int m) {     const int lim = n * m;     for (int i = 0, cid = 0; i < n; ++i)       for (Position pos{i, 0}; pos.y < m; ++pos.y, ++cid)         if (Cell &cur = cell[cid]; cur.next != Direction::None)           cur.val = cur.sum - cell[(pos + step[cur.next]).id()].sum;     for (int i = 0, cid = 0; i < n; ++i)       for (Position pos{i, 0}; pos.y < m; ++pos.y, ++cid)         if (!GraphBuilder::isLinkSink(pos))           if (const int nxt = Network::findMatch(cid, lim); nxt < lim) {             Cell &cur = cell[cid];             const int typ =                 std::find(step, step + 4, Position::fromId(nxt) - pos) - step;             cur.val = cur.sum - 1;             cur.next = static_cast<Direction>(typ);             cell[nxt].val = 1;             cell[nxt].next = reverse[typ];           }   }   template <class Func>   void printMatrix(const int n, const int m, Func fun) {     const Cell *ptr = cell;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j, ++ptr) std::cout << fun(*ptr) <<    ;       std::cout.put(  n );     }   }   void solve() {     std::cin >> n >> m;     for (Cell *i = cell; i < cell + n * m; ++i) std::cin >> i->sum;     if (!Network::boundMaxFlow(GraphBuilder::build(n, m)))       std::cout <<  NO n ;     else {       construct(n, m);       std::cout <<  YES n ;       printMatrix(n, m, [](const Cell &i) { return i.val; });       printMatrix(n, m, [](const Cell &i) { return directionName[i.next]; });     }   }   int main() {     std::ios::sync_with_stdio(false);     int t;     std::cin >> t;     for (int i = t; i; --i) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int i = k - 1;     while (n % i != 0) {       i--;     }     cout << n / i * k + i << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[30];   string s[100010];   char aver[300010];   long long f(int p, int ch, int si) {     int mi = 99999999;     if (v[ch].size() == 0) return s[si].size();     for (int i = 0; i < v[ch].size(); i++) mi = min(mi, abs(p - v[ch][i]));     return mi;   }   int main() {     long long n, k;     cin >> n >> k;     cin >> aver;     for (int i = 1; i <= n; i++) cin >> s[i];     for (long long i = 0; i < k; i++) v[aver[i] -  a ].push_back(i);     for (int i = 1; i <= n; i++) {       long long F = 0;       for (int j = 0; j < s[i].size(); j++) {         if (s[i][j] != aver[j]) {           F += f(j, s[i][j] -  a , i);         }       }       cout << F << endl;     }   }


#include <bits/stdc++.h>   char a[1111];   int main() {     int i, j, k, l, s, flag;     while (~scanf( %s , a + 2)) {       a[0] = a[1] =  0 ;       s = 0;       l = strlen(a);       flag = 0;       for (i = 0; i < l - 2; i++) {         if (flag) break;         for (j = i + 1; j < l - 1; j++) {           if (flag) break;           for (k = j + 1; k < l; k++) {             s = (a[i] -  0 ) * 100 + (a[j] -  0 ) * 10 + a[k] -  0 ;             if (s % 8 == 0) {               flag = 1;               break;             }           }         }       }       if (flag)         printf( YES n%d n , s);       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 510;   const int INF = 0x3f3f3f3f;   const int MOD = (int)1e9 + 7;   int n;   long long ans;   void dfs(int a, int b, int c) {     if (a == n) {       ++ans;       return;     }     for (int i = 0; i < n; ++i) {       if (b & (1 << i)) continue;       if (c & (1 << ((a + i) % n))) continue;       dfs(a + 1, b | (1 << i), c | (1 << ((a + i) % n)));     }     return;   }   int main() {     cin >> n;     if (n % 2 == 0) {       cout << 0 << endl;       return 0;     }     if (n == 15) {       cout << 150347555 << endl;       return 0;     }     dfs(0, 0, 0);     for (int i = 1; i <= n; ++i) {       ans = (ans * i) % MOD;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     while (cin >> a >> b >> c) {       if (b == a / 2 && c == a / 2)         cout <<  NO  << endl;       else if (b == a / 2 && c == a / 2 + 1)         cout <<  NO  << endl;       else if (b == a / 2 + 1 && c == a / 2 + 1)         cout <<  NO  << endl;       else if (b == a / 2 + 1 && c == a / 2)         cout <<  NO  << endl;       else         cout <<  YES  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[100000], p[100000], i, ans = 0, price = INT_MAX;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d %d , &a[i], &p[i]);     for (i = 0; i < n; i++) {       price = min(price, p[i]);       ans += (a[i] * price);     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool used[1005];   vector<int> v;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k, a, b, c, d;     cin >> n >> k >> a >> b >> c >> d;     if (n == 4 or k <= n) {       cout << -1;       return 0;     }     used[a] = used[b] = used[c] = used[d] = true;     for (int i = 1; i <= n; i++) {       if (!used[i]) {         v.push_back(i);       }     }     cout << a <<     << c <<     << v[0] <<     << d <<    ;     for (int i = 1; i <= n - 5; i++) {       cout << v[i] <<    ;     }     cout << b <<   n ;     cout << c <<     << a <<     << v[0] <<     << b <<    ;     for (int i = n - 5; i >= 1; i--) {       cout << v[i] <<    ;     }     cout << d;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, h, m, i, j, x, y, z, ans;     cin >> n >> h >> m;     long long int a[n + 10];     for (i = 1; i <= n; i++) {       a[i] = h;     }     for (i = 1; i <= m; i++) {       cin >> x >> y >> z;       for (j = x; j <= y; j++) {         a[j] = min(a[j], z);       }     }     ans = 0;     for (i = 1; i <= n; i++) {       ans += a[i] * a[i];     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   char jz[1000006][5];   int cnt2 = 0, cnt3 = 0, dp[1000006][8];   int cal(int x) {     int ans = 0;     while (x > 0) {       if (x & 1) ans++;       x /= 2;     }     return ans;   }   bool check_3(int x, int y) {     int sum = cal(x / 2) + cal(y / 2);     if (sum % 2 == 0) return false;     if (x >= 4) x -= 4;     if (y >= 4) y -= 4;     sum = cal(x) + cal(y);     if (sum % 2 == 0) return false;     return true;   }   bool check_2(int x, int y) {     if ((cal(x) + cal(y)) % 2 == 0) return false;     return true;   }   int change(int x, int y) { return cal(x ^ y); }   struct s3 {     int x;     vector<int> v;   } a3[10], a2[5];   int main() {     memset(dp, 0x3f3f3f3f, sizeof(dp));     cin >> n >> m;     if (n > 3 && m > 3) {       cout << -1;       return 0;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (m >= 4)           cin >> jz[j][i];         else if (m < 4)           cin >> jz[i][j];       }       getchar();     }     if (m >= 4) swap(n, m);     if (m == 1) {       cout << 0;       return 0;     } else if (m == 2) {       for (int i = 0; i < 4; i++)         for (int j = 0; j < 4; j++) {           if (check_2(i, j)) {             a2[i].v.push_back(j);           }         }       if (n == 1) {         cout << 0;         return 0;       }       int num1 = 0;       for (int i = 1; i <= m; i++) {         num1 *= 2;         if (jz[1][i] ==  1 ) num1++;       }       for (int i = 2; i <= n; i++) {         int num = 0;         for (int l = 1; l <= m; l++) {           num *= 2;           if (jz[i][l] ==  1 ) num++;         }         if (i == 2) {           for (int j = 0; j < 4; j++) {             for (int k = 0; k < a2[j].v.size(); k++)               dp[i][j] = min(dp[i][j], change(j, num) + change(a2[j].v[k], num1));           }         } else {           for (int j = 0; j < 4; j++) {             for (int k = 0; k < a2[j].v.size(); k++)               dp[i][j] = min(dp[i][j], dp[i - 1][a2[j].v[k]] + change(j, num));           }         }       }       int ans = 2100000000;       for (int i = 0; i < 4; i++) ans = min(ans, dp[n][i]);       cout << ans;     } else if (m == 3) {       for (int i = 0; i <= 7; i++) {         for (int j = 0; j <= 7; j++) {           if (check_3(i, j)) {             a3[i].x = i;             a3[i].v.push_back(j);           }         }       }       int num1 = 0;       for (int i = 1; i <= m; i++) {         num1 *= 2;         if (jz[1][i] ==  1 ) num1++;       }       if (n == 1) {         cout << 0;         return 0;       }       for (int i = 2; i <= n; i++) {         int num = 0;         for (int l = 1; l <= m; l++) {           num *= 2;           if (jz[i][l] ==  1 ) num++;         }         if (i == 2) {           for (int j = 0; j < 8; j++)             for (int k = 0; k < a3[j].v.size(); k++) {               dp[i][j] = min(dp[i][j], change(j, num) + change(a3[j].v[k], num1));             }         } else {           for (int j = 0; j < 8; j++)             for (int k = 0; k < a3[j].v.size(); k++) {               dp[i][j] = min(dp[i][j], dp[i - 1][a3[j].v[k]] + change(j, num));             }         }       }       int ans = 2100000000;       for (int i = 0; i < 8; i++) ans = min(ans, dp[n][i]);       cout << ans;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, q, p;   long long* pt;   long long a[200000], k, sum = 0LL;   int main() {     cin >> n >> q;     for (int i = (0); i < (n); i++) {       cin >> a[i];       if (i) a[i] += a[i - 1];     }     for (int i = (0); i < (q); i++) {       cin >> k;       sum += k;       pt = upper_bound(a, a + n, sum);       p = pt - a;       if (p == n) {         p = 0;         sum = 0LL;       }       cout << n - p <<   n ;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   inline bool chmax(int& a, int b) {     if (a < b) {       a = b;       return true;     }     return false;   }   constexpr int B = 210;   int q, n, e, i, j, ans, res, l, r, val, x, mid;   void solve() {     cin >> n;     vector<vector<int>> sum(n + 1, vector<int>(B, 0));     for (i = 0; i < n; i++) {       for (j = 0; j < B; j++) sum[i + 1][j] = sum[i][j];       cin >> e;       sum[i + 1][e]++;     }     ans = 0;     for (x = 0; x < B; x++) {       res = 0;       l = 0;       r = n;       val = 0;       while (l < r) {         mid = 0;         while (l < n and sum[l][x] < val) l++;         while (0 < r and sum[n][x] - sum[r][x] < val) r--;         if (r <= l) break;         for (i = 0; i < B; i++) chmax(mid, sum[r][i] - sum[l][i]);         chmax(res, mid + sum[l][x] + sum[l][x]);         val++;       }       chmax(ans, res);     }     cout << ans <<   n ;     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> q;     while (q--) {       cin >> n;       vector<vector<int>> sum(n + 1, vector<int>(B, 0));       for (i = 0; i < n; i++) {         for (j = 0; j < B; j++) sum[i + 1][j] = sum[i][j];         cin >> e;         sum[i + 1][e]++;       }       ans = 0;       for (x = 0; x < B; x++) {         res = 0;         l = 0;         r = n;         val = 0;         while (l < r) {           mid = 0;           while (l < n and sum[l][x] < val) l++;           while (0 < r and sum[n][x] - sum[r][x] < val) r--;           if (r < l) break;           for (i = 0; i < B; i++) chmax(mid, sum[r][i] - sum[l][i]);           chmax(res, mid + sum[l][x] + sum[l][x]);           val++;         }         chmax(ans, res);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   const int maxn = 100000 + 5;   using namespace std;   int main() {     int n, a[maxn];     cin >> n;     bool flag = false;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (int i = 2; i < n; i++) {       int x = a[i], y = a[i - 1];       int z = a[i - 2];       if ((y + z) > x && (x - y) < z) flag = true;     }     if (flag)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll MOD = 998244353;   const ll MX = 3e5 + 5;   ll fct[MX] = {1}, inv[MX] = {1};   ll power(ll a, ll b, ll p = 1) {     if (b == 0) return 1;     ll res = power(a, b / 2) % MOD;     if (b & 1) {       return (((res * res) % MOD) * a) % MOD;     } else {       return (((res * res) % MOD) * 1) % MOD;     }   }   void func() {     ll i;     fct[1] = 1;     for (i = 2; i < MX; i++) {       fct[i] = fct[i - 1] * i;       fct[i] %= MOD;     }     for (i = 1; i < MX; i++) {       inv[i] = power(fct[i], MOD - 2);     }   }   int main() {     func();     ll n, i, k;     cin >> n >> k;     vector<pair<ll, ll>> vt;     for (i = 0; i < n; i++) {       ll l, r;       cin >> l >> r;       vt.push_back({l, -1});       vt.push_back({r, 1});     }     sort(vt.begin(), vt.end());     ll cur = 0, ans = 0;     for (i = 0; i < vt.size(); i++) {       if (vt[i].second < 0) {         cur++;       } else {         cur--;         if (cur >= k - 1)           ans += (((fct[cur] * inv[k - 1]) % MOD) * inv[cur - k + 1]) % MOD;         ans %= MOD;       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int a[100][100], n, row[55][100005], col[55][100005];   bool valid(int i, int j) {     for (int k = 0; k < n; k++) {       if (k == i) continue;       int x = a[i][j] - a[k][j];       if (x > 0 && row[i][x] && (x != a[i][j] || row[i][x] > 1)) return 1;     }     return 0;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         scanf( %d , &a[i][j]);         row[i][a[i][j]]++;         col[j][a[i][j]]++;       }     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (a[i][j] != 1 && !valid(i, j)) {           printf( No n );           return 0;         }     printf( Yes n );   }


#include <bits/stdc++.h>   using namespace std;   int mobius[500005], prime_cnt[500005], prime[500005], present[500005],       nums[500005], cnt[500005];   vector<int> divisors[500005];   void calc_divisors(int val) {     int i;     if (divisors[val].size() > 0) return;     int foo = sqrt(val);     for (i = 1; i <= foo; i++) {       if ((val % i) == 0) {         divisors[val].push_back(i);         divisors[val].push_back(val / i);       }     }     if ((foo * foo) == val) {       int temp = divisors[val].size();       divisors[val][temp - 1] = 0;     }     return;   }   void calc_mobius() {     mobius[0] = 0;     long long int i, j, temp;     prime[1] = 1;     mobius[1] = 1;     for (i = 2; i < 500005; i++) {       if (prime[i] == 0) {         for (j = 2 * i; j < 500005; j += i) {           prime[j] = 1;           prime_cnt[j]++;         }         temp = i * i;         j = 1;         while (temp < 500005) {           mobius[temp] = 0;           j++;           temp = j * i * i;         }         mobius[i] = -1;       } else {         if (mobius[i] == 500005) {           if ((prime_cnt[i] % 2) == 0)             mobius[i] = 1;           else             mobius[i] = -1;         }       }     }     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     ;     int i, j, t, n, m, k, l, r, temp, mini, maxi, flag;     long long int result = 0LL;     for (i = 0; i < 500005; i++) {       mobius[i] = 500005;       prime[i] = 0;       prime_cnt[i] = 0;       cnt[i] = 0;       present[i] = 0;     }     calc_mobius();     divisors[1].push_back(1);     divisors[2].push_back(1);     divisors[2].push_back(2);     divisors[3].push_back(1);     divisors[3].push_back(3);     cin >> n >> m;     for (i = 1; i <= n; i++) {       cin >> nums[i];       calc_divisors(nums[i]);     }     for (i = 0; i < m; i++) {       cin >> k;       temp = nums[k];       if (present[k] == 0) {         present[k] = 1;         for (j = 0; j < divisors[temp].size(); j++) {           result = result + (long long int)mobius[divisors[temp][j]] *                                 cnt[divisors[temp][j]];           cnt[divisors[temp][j]]++;         }       } else {         present[k] = 0;         for (j = 0; j < divisors[temp].size(); j++) {           result = result - (long long int)mobius[divisors[temp][j]] *                                 (cnt[divisors[temp][j]] - 1LL);           cnt[divisors[temp][j]]--;         }       }       cout << result << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, T, i, j, temp, le, ri, mid, ma = 0;     cin >> n >> a >> b >> T;     char str[n];     cin >> str;     int r[n], l[n];     if (str[0] ==  h )       r[0] = 1;     else       r[0] = b + 1;     for (i = 1; i < n; i++) {       if (str[i] ==  h )         r[i] = r[i - 1] + a + 1;       else         r[i] = r[i - 1] + a + b + 1;     }     if (str[n - 1] ==  h )       l[0] = a + 1;     else       l[0] = a + b + 1;     for (i = 1; i < n - 1; i++) {       if (str[n - 1 - i] ==  h )         l[i] = l[i - 1] + a + 1;       else         l[i] = l[i - 1] + a + b + 1;     }     for (i = 0; i < n; i++)       if (r[i] <= T) ma = max(ma, i + 1);     for (i = 0; i < n - 1; i++) {       temp = l[i];       if (temp >= T) continue;       le = 0;       ri = n - 1 - i - 1;       while (ri - le > 1) {         mid = (le + ri) / 2;         temp = l[i] + min(i + 1, mid) * a;         if (temp + r[mid] < T)           le = mid;         else           ri = mid;       }       if (l[i] + r[le] + min(i + 1, le) * a <= T) ma = max(ma, i + le + 2);       if (l[i] + r[ri] + min(i + 1, ri) * a <= T) ma = max(ma, i + ri + 2);     }     cout << ma;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e3 + 10;   char s[N], x[N], y[N];   int n, d;   namespace Trie {   const int M = N * 60;   int ch[M][10], tot = 1, rt = 1, fail[M];   bool ed[M];   inline void insert(int l, int r) {     int now = rt;     for (int i = l; i <= r; ++i) {       int v = s[i] -  0 ;       if (!ch[now][v]) ch[now][v] = ++tot;       now = ch[now][v];     }     ed[now] = true;   }   inline void getfail() {     for (int i = 0; i < 10; ++i) ch[0][i] = rt;     fail[rt] = 0;     queue<int> q;     q.push(rt);     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 0; i < 10; ++i) {         if (!ch[u][i])           ch[u][i] = ch[fail[u]][i];         else           fail[ch[u][i]] = ch[fail[u]][i], q.push(ch[u][i]);       }     }   }   }  // namespace Trie   using namespace Trie;   int dp[2][N * 50][2][2][2];   inline void upd(int &x, int y) { x = (x + y >= mod) ? x + y - mod : x + y; }   int main() {     scanf( %s%s%s , s + 1, x + 1, y + 1);     n = strlen(s + 1);     d = strlen(x + 1);     int nd = d / 2;     for (int i = 1; i + nd - 1 <= n; ++i) insert(i, i + nd - 1);     getfail();     dp[0][rt][1][1][0] = 1;     for (int i = 1; i <= d; ++i) {       int cur = i & 1, last = !cur;       for (int pos = 0; pos <= tot; ++pos)         for (int limx = 0; limx <= 1; ++limx)           for (int limy = 0; limy <= 1; ++limy)             for (int ok = 0; ok <= 1; ++ok) {               int &d = dp[last][pos][limx][limy][ok];               if (!d) continue;               int s = limx ? x[i] -  0  : 0, t = limy ? y[i] -  0  : 9;               for (int c = s; c <= t; ++c) {                 int npos = ch[pos][c];                 upd(dp[cur][npos][limx && c == x[i] -  0 ]                       [limy && c == y[i] -  0 ][ok | ed[npos]],                     d);               }               d = 0;             }     }     int ans = 0;     for (int pos = 0; pos <= tot; ++pos)       for (int limx = 0; limx <= 1; ++limx)         for (int limy = 0; limy <= 1; ++limy)           upd(ans, dp[d & 1][pos][limx][limy][1]);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int inp[105][105];   int a[105];   int b[105];   int temp[105];   int main() {     int n, m;     scanf( %d , &n);     scanf( %d , &m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %d , &inp[i][j]);     for (int i = 0; i < m; i++) b[i] = inp[0][i];     int up = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) up = max(up, inp[i][j]);     int prevk = 0;     for (int i = 1; i <= n - 1; i++) {       map<int, int> mp;       for (int j = 0; j < m; j++) {         temp[j] = inp[i][j] - b[j];         mp[temp[j]] = 1;       }       int currk = 0;       if (mp.size() == 2) {         int f = mp.rbegin()->first;         int s = mp.begin()->first;         if (max(f, s) >= 0 && min(f, s) <= 0)           currk = max(s, f) - min(s, f);         else           currk = -1;       }       if (mp.size() > 2 || (currk && prevk && currk != prevk) ||           (currk != 0 && currk <= up)) {         printf( NO n );         return 0;       }       prevk = max(prevk, currk);       a[i] = max(mp.rbegin()->first, mp.begin()->first);     }     printf( YES n );     if (prevk == 0) prevk = 2e9 + 7;     printf( %d n , prevk);     for (int i = 0; i < n; i++)       printf( %d  , (a[i] >= 0) ? a[i] : (a[i] + prevk));     cout << endl;     for (int i = 0; i < m; i++) printf( %d  , b[i]);     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 55, maxm = 9;   int loc[maxn][2], col[maxn];   char s[maxn][maxn], res[maxn][maxn];   int num[maxn][maxn], used[maxm][maxm];   int n, m, ans, cnt;   void dfs(int u, int v) {     int i, j, x, y;     if (u > 14) {       memset(used, 0, sizeof used);       for (i = 1; i <= 28; ++i) {         x = col[loc[i][0]];         y = col[loc[i][1]];         if (used[x][y]) return;         used[x][y] = used[y][x] = true;       }       ++ans;       if (ans == 1) {         for (i = 1; i <= n; ++i)           for (j = 1, res[i][m + 1] =   0 ; j <= m; ++j)             res[i][j] = num[i][j] ? col[num[i][j]] - 1 +  0  :  . ;       }       return;     }     if (col[u])       dfs(u + 1, v);     else {       for (i = u + 1, col[u] = v; i <= 14; ++i)         if (!col[i]) {           col[i] = v;           dfs(u + 1, v + 1);           col[i] = 0;         }       col[u] = 0;     }   }   int main() {     int i, j, t;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; ++i) scanf( %s , s[i] + 1);     for (i = 1; i <= n; ++i)       for (j = 1; j <= m; ++j)         if (s[i][j] !=  . ) {           if (!num[i][j])             num[i][j] = num[i + 1][j] = num[i][j + 1] = num[i + 1][j + 1] = ++cnt;           t = s[i][j] <  a  ? s[i][j] -  A  + 27 : s[i][j] -  a  + 1;           if (!loc[t][0])             loc[t][0] = num[i][j];           else             loc[t][1] = num[i][j];         }     dfs(1, 1);     printf( %I64d n , (long long)ans * 5040);     for (i = 1; i <= n; ++i) puts(res[i] + 1);     return 0;   }