// Author : Epsilon573   // If it works, don t touch it.      #include <bits/stdc++.h>   using namespace std;      typedef unsigned long long ull;   typedef long long ll;   typedef long double ld;      const ll mod  = 1e9+7;   const ld eps  = 1e-9 ;   const ll maxn = 1e5+1;   const ll inf  = 1e15 ;   const ll minf = -inf ;      #define mp make_pair   #define pb push_back   #define endl   n       #ifdef EPSILON          #define deb(args...)       cerr <<  [   #args <<   ] :   , debug(args);       #define debug(args...)     (Debugger()) , args           class Debugger       {           public:           Debugger(const std::string& _separator =  ,  ) :           first(true), separator(_separator){}               template<typename ObjectType>           Debugger& operator , (const ObjectType& v)           {               if(!first)                   std::cerr << separator;               std::cerr << v;               first = false;               return *this;           }           ~Debugger() {  std::cerr << endl;}               private:           bool first;           std::string separator;       };           template <typename T1, typename T2>       inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p)       {           return os <<  (  << p.first <<  ,   << p.second <<  ) ;       }           template<typename T>       inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v)       {           bool first = true;           os <<  [ ;           for(unsigned int i = 0; i < v.size(); i++)           {               if(!first)                   os <<  ,  ;               os << v[i];               first = false;           }           return os <<  ] ;       }           template<typename T>       inline std::ostream &operator << (std::ostream & os,const std::set<T>& v)       {           bool first = true;           os <<  [ ;           for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii)           {               if(!first)                   os <<  ,  ;               os << *ii;               first = false;           }           return os <<  ] ;       }           template<typename T1, typename T2>       inline std::ostream &operator << (std::ostream & os,const std::map<T1, T2>& v)       {           bool first = true;           os <<  [ ;           for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii)           {               if(!first)                   os <<  ,  ;               os << *ii ;               first = false;           }           return os <<  ] ;       }       #else       #define deb(args...)       #define debug(args...)   #endif      bool solve()   {       ll n;       cin >> n;       vector<pair<pair<ll,ll>,ll>> hw(n),wh(n);       vector<ll> ans(n+1,-1),prefw(n),prefh(n),valh(n),valw(n);          for(ll i=0 ; i<n ; ++i)       {           hw[i].second = wh[i].second = i+1;           cin >> (hw[i].first).first >> (hw[i].first).second;           (wh[i].first).first = (hw[i].first).second;           (wh[i].first).second = (hw[i].first).first;       }          sort(hw.begin(),hw.end());       sort(wh.begin(),wh.end());          for(ll i=0 ; i<n ; ++i)       {           if(i){               if((hw[i].first).second < prefw[i-1])               {                   prefw[i] = (hw[i].first).second;                   valw[i] = hw[i].second;               }               else               {                   prefw[i] = prefw[i-1];                   valw[i] = valw[i-1];               }               if((wh[i].first).second < prefh[i-1])               {                   prefh[i] = (wh[i].first).second;                   valh[i] = wh[i].second;               }               else               {                   prefh[i] = prefh[i-1];                   valh[i] = valh[i-1];               }           }           else           {               prefw[i] = (hw[i].first).second;               valw[i] = hw[i].second;               prefh[i] = (wh[i].first).second;               valh[i] = wh[i].second;           }          }             for(ll i=0 ; i<n ; ++i)       {           ll ht = (hw[i].first).first;           ll wt = (hw[i].first).second;              ll low = 0 , high = n-1 , mid , ptr = -1;              while(low<=high)           {               mid = (low+high)/2;                              if( (hw[mid].first).first < ht )               {                   ptr = mid;                   low = mid+1;               }               else               {                   high = mid-1;               }           }              if(ptr==-1) continue;           else           {               if(prefw[ptr] < wt)               {                   ans[hw[i].second] = valw[ptr];               }           }          }          for(ll i=0 ; i<n ; ++i)       {           if(ans[hw[i].second]!=-1) continue;              ll ht = (hw[i].first).first;           ll wt = (hw[i].first).second;              ll low = 0 , high = n-1 , mid , ptr = -1;              while(low<=high)           {               mid = (low+high)/2;               if( (wh[mid].first).first < ht )               {                   ptr = mid;                   low = mid+1;               }               else               {                   high = mid-1;               }           }              if(ptr==-1) continue;           else           {               if(prefh[ptr] < wt)               {                   ans[hw[i].second] = valh[ptr];               }           }       }          for(ll i=1 ; i<=n ; ++i) cout << ans[i] <<    ;           cout << endl;          return true;       }      int main()   {       ios_base :: sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);          #ifdef EPSILON       freopen( input.txt , r ,stdin);       freopen( output.txt , w ,stdout);       freopen( error.txt , w ,stderr);       #endif          ll t=1;       cin >> t;          while(t--)       {           if(solve())           {               // do this;           }           else           {               // do this;           }       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[1234567], ans[1234567];   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     int in = 0;     for (int i = 0; i < n; i++)       if (!a[i]) {         in = i;         break;       }     for (int i = 0; i <= in; i++) ans[i] = in - i;     for (int i = in + 1; i < n; i++) {       if (!a[i]) in = i;       ans[i] = abs(i - in);     }     for (int i = n - 1; i >= 0; i--)       if (!a[i]) {         in = i;         break;       }     for (int i = n - 1; i >= 0; i--) {       if (!a[i]) in = i;       ans[i] = min(ans[i], abs(i - in));     }     for (int i = 0; i < n; i++) cout << ans[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, s = 0, a;   int sg(int x) {     if (x == 0 || x == 1) return x;     if (k % 2 == 0) {       if (x == 2) return 2;       if (x % 2 == 0)         return 1;       else         return 0;     } else {       if (x == 2) return 0;       if (x == 3) return 1;       if (x == 4) return 2;       if (x % 2 == 0) {         int cnt = 0;         while (x % 2 == 0) x /= 2, cnt++;         if (x == 3) cnt++;         if (cnt % 2)           return 1;         else           return 2;       } else         return 0;     }   }   int main(void) {     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a;       s ^= sg(a);     }     if (s == 0)       cout <<  Nicky n ;     else       cout <<  Kevin n ;   }


#include <bits/stdc++.h>   using namespace std;   const int mn = 2e5 + 10;   int bit[mn];   void update(int a, int b) {     for (; a < mn; a += a & -a) bit[a] += b;   }   int query(int a) {     int b = 0;     for (; a; a -= a & -a) b += bit[a];     return b;   }   int a[mn], v[mn], n;   void go() {     int i;     for (i = 0; i < n; i++) scanf( %d , a + i), a[i]++;     for (i = 1; i <= n; i++) update(i, 1);     for (i = 0; i < n; i++) {       v[i] += query(a[i]) - 1;       update(a[i], -1);     }   }   int main() {     int i;     scanf( %d , &n);     go();     go();     for (i = n - 1; i; i--) {       if (v[i] >= n - i) v[i] -= n - i, v[i - 1]++;     }     v[0] %= n;     for (i = 1; i <= n; i++) update(i, 1);     for (i = 0; i < n; i++) {       int cur = 0, tot = 0;       for (int j = 1 << 17; j; j >>= 1) {         if (cur + j > n) continue;         if (tot + bit[cur + j] < v[i] + 1) cur += j, tot += bit[cur];       }       printf( %d  , cur);       update(cur + 1, -1);     }   }


#include <bits/stdc++.h>   using namespace std;   void reverseQueue(queue<long long int>& q) {     if (q.empty()) return;     long long int data = q.front();     q.pop();     reverseQueue(q);     q.push(data);   }   int main() {     ios_base::sync_with_stdio(0);     int n, k;     cin >> n >> k;     vector<long long int> friends;     queue<long long int> q;     map<long long int, int> check;     for (int i = 0, temp; i < n; i++) {       cin >> temp;       friends.emplace_back(temp);       if (i < k) {         if (check.find(friends[i]) == check.end() || check[friends[i]] == 0) {           q.push(temp);           check[temp] = 1;         }       }     }     for (int i = k; i < n; i++) {       if (check.find(friends[i]) == check.end() || check[friends[i]] == 0) {         if (q.size() == k) {           check[q.front()] = 0;           q.pop();         }         q.push(friends[i]);         check[friends[i]] = 1;       }     }     reverseQueue(q);     cout << q.size() << endl;     while (!q.empty()) {       cout << q.front() <<    ;       q.pop();     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   int main(void) {     int n, m;     char g[1000][1000];     int min_row = 1000, max_row = -1;     int min_col = 1000, max_col = -1;     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         scanf(  %c , &g[i][j]);         if (g[i][j] ==  B ) {           min_row = std::min(min_row, i);           max_row = std::max(max_row, i);           min_col = std::min(min_col, j);           max_col = std::max(max_col, j);         }       }     }     if (max_row == -1) {       puts( 1 );     } else {       int missing_from_rect = 0;       for (int i = min_row; i <= max_row; i++) {         for (int j = min_col; j <= max_col; j++) {           missing_from_rect += (g[i][j] ==  W );         }       }       const int n_rows = (max_row - min_row + 1);       const int n_cols = (max_col - min_col + 1);       bool feasible = true;       int additional = 0;       if (n_rows > n_cols) {         const int needed = n_rows - n_cols;         if (n_cols + needed > m) {           feasible = false;         } else {           additional = needed * n_rows;         }       } else if (n_rows < n_cols) {         const int needed = n_cols - n_rows;         if (n_rows + needed > n) {           feasible = false;         } else {           additional = needed * n_cols;         }       }       if (feasible) {         printf( %d n , missing_from_rect + additional);       } else {         puts( -1 );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct qq {     char c;     long long dis;   } a[500050], b[500050], c[500050], d[500050], e[500050], f[500050], g[500050],       h[500050];   int cmp(qq a, qq b) { return a.dis < b.dis; }   int main() {     int n;     cin >> n;     int x, y;     cin >> x >> y;     int fa = 0, fb = 0, fc = 0, fd = 0, fe = 0, ff = 0, fg = 0, fh = 0;     for (int i = 0; i < n; i++) {       int xx, yy;       char cc;       getchar();       scanf( %c%d%d , &cc, &xx, &yy);       xx -= x;       yy -= y;       if (xx == 0) {         if (yy < 0)           a[fa].c = cc, a[fa++].dis = -yy;         else           b[fb].c = cc, b[fb++].dis = yy;       }       if (yy == 0) {         if (xx < 0)           c[fc].c = cc, c[fc++].dis = -xx;         else           d[fd].c = cc, d[fd++].dis = xx;       }       if (xx == yy) {         if (yy < 0) {           e[fe].c = cc, e[fe++].dis = -xx;         } else {           f[ff].c = cc, f[ff++].dis = xx;         }       }       if (xx == -yy) {         if (yy < 0) {           g[fg].c = cc, g[fg++].dis = xx;         } else {           h[fh].c = cc, h[fh++].dis = -xx;         }       }     }     sort(a, a + fa, cmp);     sort(b, b + fb, cmp);     sort(c, c + fc, cmp);     sort(d, d + fd, cmp);     sort(e, e + fe, cmp);     sort(f, f + ff, cmp);     sort(g, g + fg, cmp);     sort(h, h + fh, cmp);     if (a[0].c ==  R  || a[0].c ==  Q ) {       printf( YES n );       return 0;     }     if (b[0].c ==  R  || b[0].c ==  Q ) {       printf( YES n );       return 0;     }     if (c[0].c ==  R  || c[0].c ==  Q ) {       printf( YES n );       return 0;     }     if (d[0].c ==  R  || d[0].c ==  Q ) {       printf( YES n );       return 0;     }     if (e[0].c ==  B  || e[0].c ==  Q ) {       printf( YES n );       return 0;     }     if (f[0].c ==  B  || f[0].c ==  Q ) {       printf( YES n );       return 0;     }     if (g[0].c ==  B  || g[0].c ==  Q ) {       printf( YES n );       return 0;     }     if (h[0].c ==  B  || h[0].c ==  Q ) {       printf( YES n );       return 0;     }     printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool ok[100010];   int a[100010];   int b[100010];   int c[100010];   vector<int> ans;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     memset(ok, false, sizeof(ok));     long long now, min_value;     for (int i = 1; i <= n; i++) c[i] = a[i] - b[i];     now = 0;     min_value = 0;     for (int i = 1; i <= n; i++) {       now += c[i];       min_value = min(min_value, now);     }     for (int i = 1; i <= n; i++) {       if (min_value == 0) ok[i] = true;       min_value -= c[i];       min_value = min((long long)0, min_value);     }     c[n] = a[1] - b[n];     for (int i = n; i >= 2; i--) c[n - i + 1] = a[i] - b[i - 1];     now = 0;     min_value = 0;     for (int i = 1; i <= n; i++) {       now += c[i];       min_value = min(min_value, now);     }     for (int i = 1; i <= n; i++) {       if (min_value == 0) ok[n - i + 1] = true;       min_value -= c[i];       min_value = min((long long)0, min_value);     }     ans.clear();     for (int i = 1; i <= n; i++)       if (ok[i]) ans.push_back(i);     int len = ans.size();     printf( %d n , len);     for (int i = 0; i < len; i++) {       printf( %d , ans[i]);       if (i == len - 1)         printf(  n );       else         printf(   );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, p;   int bin[32] = {0};   bool check(int x) {     int m = n - x * p;     int res = 0;     if (m < x) return 0;     for (int i = 0; i <= 31; i++)       if (m & bin[i]) {         x--;         if (x < 0) return 0;       }     return 1;   }   int main() {     bin[0] = 1;     for (int i = 1; i <= 31; i++) bin[i] = bin[i - 1] << 1;     n = read();     p = read();     for (int i = 1; i <= 100; i++)       if (check(i)) {         cout << i << endl;         return 0;       }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long k;     cin >> k;     map<char, long long> m;     for (long long g = 0; g < k; g++) {       long long n;       cin >> n;       string s, t;       cin >> s >> t;       m.clear();       for (long long i = 0; i < n; i++) {         m[s[i]]++;         m[t[i]]++;       }       bool found = 0;       for (map<char, long long>::iterator it = m.begin(); it != m.end(); it++)         if ((*it).second % 2 == 1) {           found = 1;           break;         }       if (found) {         cout <<  No n ;       } else {         cout <<  Yes n ;         vector<pair<long long, long long> > ans;         ans.clear();         for (long long i = 0; i < n; i++)           if (s[i] != t[i]) {             for (long long j = 0; j < n; j++)               if (i != j && t[j] != s[j]) {                 if (s[i] == s[j] || t[i] == t[j]) {                   swap(s[i], t[j]);                   ans.push_back({i, j});                   i = 0;                   break;                 }                 if (s[i] == t[j]) {                   swap(s[j], t[j]);                   swap(s[j], t[i]);                   ans.push_back({j, j});                   ans.push_back({j, i});                   i = 0;                   break;                 }                 if (t[i] == s[j]) {                   swap(s[j], t[j]);                   swap(s[i], t[j]);                   ans.push_back({j, j});                   ans.push_back({i, j});                   i = 0;                   break;                 }               }           }         cout << ans.size() << endl;         for (long long i = 0; i < ans.size(); i++)           cout << ans[i].first + 1 <<     << ans[i].second + 1 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   const int N = 1e6 + 100;   const int inf = 1e9 + 100;   int n, w, m, a[N], seg[N << 2];   long long fen[N];   void change(int dex, int val, int v = 1, int s = 0, int e = N) {     if (dex < s || e <= dex) {       return;     }     if (e - s == 1) {       seg[v] = val;       return;     }     int mid = (s + e) >> 1, lc = v << 1, rc = lc | 1;     change(dex, val, lc, s, mid);     change(dex, val, rc, mid, e);     seg[v] = max(seg[lc], seg[rc]);   }   int get_max(int l, int r, int v = 1, int s = 0, int e = N) {     if (r <= s || e <= l) return -inf;     if (l <= s && e <= r) return seg[v];     int mid = (s + e) >> 1, lc = v << 1, rc = lc | 1;     return max(get_max(l, r, lc, s, mid), get_max(l, r, rc, mid, e));   }   void add(int dex, long long val) {     for (++dex; dex < N; dex += dex & -dex) fen[dex] += val;   }   long long get(int dex) {     long long res = 0;     for (; dex; dex ^= dex & -dex) res += fen[dex];     return res;   }   void ADD(int l, int r, long long x) {     add(l, x);     add(r, -x);   }   void act(int i) {     ADD(i, i + 1, max(i + m < w || i >= w ? 0 : -inf, get_max(i + m - w, i + 1)));   }   void get_line() {     int maxi = 0;     cin >> m;     for (int i = 0; i < m; i++) {       cin >> a[i];       change(i, a[i]);       maxi = max(maxi, a[i]);     }     for (int i = 0; i < m; i++) {       act(i);     }     for (int i = 0; i < m && w - i - 1 >= m; i++) {       act(w - i - 1);     }     if (2 * m < w) {       ADD(m, w - m, maxi);     }     for (int i = 0; i < m; i++) {       change(i, 0);     }   }   int main() {     cin >> n >> w;     for (int i = 0; i < n; i++) {       get_line();     }     for (int i = 0; i < w; i++) {       cout << get(i + 1) <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000;   int n;   long long int d[MAXN], st[2 * MAXN];   long long int arr(int i) {     if (i == 0 || i == n - 1) return 0;     return max(0ll, -d[i - 1]) + max(0ll, d[i]);   }   void build() {     for (int i = 0; i < n; ++i) st[i + n] = arr(i);     for (int i = n - 1; i > 0; --i) st[i] = min(st[2 * i], st[2 * i + 1]);   }   long long int query(int l, int r) {     long long int res = LLONG_MAX;     for (l += n, r += n; l < r; l /= 2, r /= 2) {       if (l & 1) res = min(res, st[l++]);       if (r & 1) res = min(res, st[--r]);     }     return res;   }   void update(int idx) {     st[idx + n] = arr(idx);     for (int i = idx + n; i > 1; i /= 2) st[i / 2] = min(st[i], st[i ^ 1]);   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin >> n;     long long int sum = 0;     int a1, a2;     cin >> a1;     for (int i = 0; i < n - 1; ++i)       cin >> a2, d[i] = a2 - a1, sum += abs(d[i]), a1 = a2;     int q;     cin >> q;     build();     while (q--) {       int t, l, r;       long long int x;       cin >> t >> l >> r >> x;       l--, r--;       if (t == 1) {         long long int res = sum + (l == r ? abs(d[l - 1] + x) - abs(d[l - 1]) +                                                 abs(d[l] - x) - abs(d[l])                                           : max(0ll, 2 * (x - query(l, r + 1))));         cout << res << endl;       } else {         for (int i : {l - 1, r})           sum -= abs(d[i]), d[i] += (i == l - 1 ? x : -x), sum += abs(d[i]);         for (int i : {l - 1, l, r, r + 1}) update(i);       }     }   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   template <class T1, class T2>   ostream &operator<<(ostream &os, const pair<T1, T2> &p) {     os <<  {  << p.first <<  ,  << p.second <<  } ;     return os;   }   const int N = 3e5 + 5;   const int oo = 1e9 + 7;   double s, a, b, c;   double func(double x, double y, double z) {     return a * log(x) + b * log(y) + c * log(z);   }   double ans2(double x, double S, double &y) {     double l = 1e-9, r = S;     for (int i = 0; i < 500; i++) {       double l1 = (l * 2 + r) / 3;       double l2 = (l + 2 * r) / 3;       if (func(x, l1, S - l1) > func(x, l2, S - l2))         r = l2;       else         l = l1;     }     y = l;     return func(x, l, S - l);   }   pair<double, pair<double, double> > ans1(double S) {     double l = 1e-9, r = S;     double y;     for (int i = 0; i < 500; i++) {       double l1 = (l * 2 + r) / 3;       double l2 = (l + 2 * r) / 3;       if (ans2(l1, S - l1, y) > ans2(l2, S - l2, y))         r = l2;       else         l = l1;     }     ans2(l, S - l, y);     return {l, {y, S - l - y}};   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> s >> a >> b >> c;     auto x = ans1(s);     cout << fixed << setprecision(15) << x.first <<     << x.second.first <<              << x.second.second <<   n ;   }


#include <bits/stdc++.h>   int main() {     int a;     scanf( %d , &a);     int A[a];     for (int i = 0; i < a; ++i) {       scanf( %d , &A[i]);     }     for (int i = 0; i < a; ++i) {       int l, m;       int K = 0;       l = (int)(sqrtl(A[i]));       m = (int)(cbrtl(A[i]));       int z = 0;       z = (int)cbrtl(sqrtl(A[i]));       K = (l + m - z);       printf( %d n , K);     }     return 0;   }


#include <bits/stdc++.h>   int N;   int T[20000 + 10];   int Cnt[20000 + 10];   int Ans;   int main() {     scanf( %d , &N);     for (int i = 0; i < N; i++) scanf( %d , &T[i]);     Ans = -1000000000;     for (int i = 1; i <= N; i++)       if (N % i == 0 && N / i >= 3) {         for (int j = 0; j < i; j++) Cnt[j] = 0;         for (int j = 0; j < N; j++) Cnt[j % i] += T[j];         for (int j = 0; j < i; j++)           if (Cnt[j] > Ans) Ans = Cnt[j];       }     printf( %d n , Ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i[105] = {0};   int j[105] = {0};   int f[100005] = {0};   int main() {     int n, m;     cin >> n;     for (int a = 1; a <= n; a++) cin >> i[a];     cin >> m;     for (int a = 1; a <= m; a++) cin >> j[a];     for (int a = 1; a <= m; a++) {       for (int b = 1; b <= n; b++) {         if (j[a] % i[b] == 0) {           f[j[a] / i[b]]++;         }       }     }     int Themax = 0;     for (int a = 10000; a >= 1; a--) {       if (f[a] != 0) {         cout << f[a] << endl;         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 205;   char g[N];   map<char, int> h;   void work() {     int i, j;     int s1 = 0, s2 = 0;     h[ q ] = 9;     h[ r ] = 5;     h[ b ] = 3;     h[ n ] = 3;     h[ p ] = 1;     h[ k ] = 0;     for (i = 0; i < 8; ++i) {       scanf( %s , g);       for (j = 0; j < 8; ++j)         if (islower(g[j]))           s1 += h[g[j]];         else if (isupper(g[j]))           s2 += h[g[j] -  A  +  a ];     }     if (s1 > s2)       puts( Black );     else if (s1 == s2)       puts( Draw );     else       puts( White );   }   int main() {     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct segment {     int pos;     int len;     int type;   };   struct lengthComparator {     bool operator()(const segment &a, const segment &b) const {       if (a.len != b.len)         return a.len > b.len;       else         return a.pos < b.pos;     }   };   struct positionComparator {     bool operator()(const segment &a, const segment &b) const {       return a.pos < b.pos;     }   };   set<segment, lengthComparator> lengthSet;   set<segment, positionComparator> positionSet;   void add_segment(segment s) {     lengthSet.insert({s});     positionSet.insert({s});   }   void remove_segment(segment s) {     lengthSet.erase({s});     positionSet.erase({s});   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     a.push_back(-1);     int start = 0;     for (int i = 0; i < a.size(); i++) {       if (i > 0 and a[i] != a[i - 1]) {         segment s = {start, (i - 1) - start + 1, a[i - 1]};         lengthSet.insert(s);         positionSet.insert(s);         start = i;       }     }     int sol = 0;     while (!lengthSet.empty()) {       segment s = *lengthSet.begin();       segment left, right;       bool leftExists = false, rightExists = false;       auto lbIterator = positionSet.find(s);       if (lbIterator != positionSet.begin()) {         left = *(--lbIterator);         leftExists = true;       }       auto ubIterator = positionSet.find(s);       if (++ubIterator != positionSet.end()) {         right = *ubIterator;         rightExists = true;       }       if (leftExists and rightExists and left.type == right.type) {         segment merged = {left.pos, left.len + right.len, left.type};         remove_segment(left);         remove_segment(right);         add_segment(merged);       }       remove_segment(s);       sol++;     }     cout << sol <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dr[] = {-1, 0, 1, 0, -1, -1, 1, 1};   const int dc[] = {0, -1, 0, 1, -1, 1, -1, 1};   long long ax, ay, bx, by, cx, cy;   long long dist(long long x1, long long y1, long long x2, long long y2) {     return ((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2));   }   int main() {     cin >> ax >> ay >> bx >> by >> cx >> cy;     if (dist(ax, ay, bx, by) != dist(bx, by, cx, cy)) {       cout <<  No n ;       return 0;     }     if (ax - bx == bx - cx && ay - by == by - cy)       cout <<  No n ;     else if (ax - cx == cx - bx && ay - cy == cy - by)       cout <<  No n ;     else if (bx - ax == ax - cx && by - ay == ay - cy)       cout <<  No n ;     else if (bx - cx == cx - ax && by - cy == cy - ay)       cout <<  No n ;     else if (cx - ax == ax - cx && cy - ay == ay - cy)       cout <<  No n ;     else if (cx - bx == bx - cx && cy - by == by - cy)       cout <<  No n ;     else       cout <<  Yes n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e2 + 7;   int c[N], n;   int f[N][N];   int main() {     memset(f, 0x7f7f, sizeof f);     scanf( %d , &n);     for (register int i = 1; i <= n; ++i) {       scanf( %d , &c[i]);       f[i][i] = 1;     }     for (register int i = 1; i < n; ++i) {       if (c[i] == c[i + 1])         f[i][i + 1] = 1;       else         f[i][i + 1] = 2;     }     for (register int le = 3; le <= n; ++le)       for (register int l = 1, r = l + le - 1; r <= n; l++, r++) {         if (c[l] == c[r]) f[l][r] = f[l + 1][r - 1];         for (register int k = l; k < r; ++k)           f[l][r] = min(f[l][r], f[l][k] + f[k + 1][r]);       }     cout << f[1][n];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s, ans;   int p;   int main() {     cin >> s;     while (p < s.length()) {       if (s[p] ==  . )         ans.push_back( 0 ), ++p;       else if (s[p + 1] ==  . )         ans.push_back( 1 ), p += 2;       else         ans.push_back( 2 ), p += 2;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int a[N];   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n;       scanf( %d , &n);       for (int i = 1; i <= n; ++i) {         scanf( %d , &a[i]);       }       sort(a + 1, a + n + 1);       int ans = a[1];       for (int i = 1; i < n; ++i) {         ans = max(a[i + 1] - a[i], ans);       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s[100];     int i, j, count = 0, num = 0;     cin >> s[0];     for (i = 0; i < s[0].length(); i++) {       s[i + 1] = s[i];       num = 0;       rotate(s[i + 1].rbegin(), s[i + 1].rbegin() + 1, s[i + 1].rend());     }     for (i = 0; i < s[0].length(); i++) {       num = 0;       for (j = i + 1; j < s[0].length(); j++) {         if (i != j && s[i].compare(s[j]) == 0) {           num = 1;           break;         }       }       if (num != 1) count++;     }     cout << count;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d%d , &n, &m);     queue<int> x, y;     for (int i = 0; i < n; ++i) {       int tmp;       scanf( %d , &tmp);       x.push(tmp);     }     for (int i = 0; i < m; ++i) {       int tmp;       scanf( %d , &tmp);       y.push(tmp);     }     int ans = 0, xSum = x.front(), ySum = y.front();     x.pop(), y.pop();     while (!x.empty() && !y.empty()) {       if (xSum == ySum) {         ++ans;         xSum = x.front();         x.pop();         ySum = y.front();         y.pop();       } else {         if (xSum < ySum) {           xSum += x.front();           x.pop();         } else {           ySum += y.front();           y.pop();         }       }     }     cout << ans + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   void err() { std::cout << std::endl; }   template <typename T, typename... Args>   void err(T a, Args... args) {     std::cout << a <<    ;     err(args...);   }   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 1e3 + 22;   int n, m, d[maxn], vis[maxn], root0, g[maxn];   int v[maxn][maxn], c, x, y;   int main() {     cin >> n;     for (int i = 1; i <= n - 1; i++) {       cin >> x >> y;       d[x]++;       d[y]++;       v[x][y] = 1;       v[y][x] = 1;     }     int k1, k2, cnt = 1;     while (cnt <= n / 2) {       int a, b;       for (int i = 1; i <= n; i++) {         if (d[i] == 1) {           a = i;           d[i]--;           break;         }       }       for (int i = 1; i <= n; i++) {         if (d[i] == 1) {           b = i;           d[i]--;           break;         }       }       for (int i = 1; i <= n; i++) {         if (v[a][i]) {           v[a][i] = 0;           v[i][a] = 0;           d[i]--;         }       }       for (int i = 1; i <= n; i++) {         if (v[b][i]) {           v[b][i] = 0;           v[i][b] = 0;           d[i]--;         }       }       g[a] = 1;       g[b] = 1;       cout <<  ?   << a <<     << b << endl;       cin >> c;       if (c == a || c == b) {         cout <<  !   << c << endl;         return 0;       }       cnt++;     }     for (int i = 1; i <= n; i++) {       if (!g[i]) {         cout <<  !   << i << endl;         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 50;   char str[maxn];   int pre[30], now[30];   int l, r, len, cnt;   void sov() {     scanf( %s , str);     len = strlen(str);     cnt = 1;     l = 0, r = 0;     memset(now, 0, sizeof(now));     int i = 1;     while (i < len) {       if (str[i] == str[i - 1])         cnt++;       else         break;       i++;     }     if (cnt == len) return;     l = cnt;     cnt = 1;     int j = len - 2;     while (j >= 0) {       if (str[j] == str[j + 1])         cnt++;       else         break;       j--;     }     r = cnt;     if (cnt + l == len) return;     cnt = 1;     for (++i; i <= j + 1; i++) {       if (str[i] != str[i - 1]) {         now[str[i - 1] -  a ] = max(now[str[i - 1] -  a ], cnt);         cnt = 1;       } else if (str[i] == str[i - 1])         cnt++;     }   }   int main() {     int n;     scanf( %d , &n);     for (int j = 0; j < n; j++) {       if (j == 3) int ok = 1;       sov();       if (cnt == len) {         int t = str[0] -  a ;         pre[t] = pre[t] + (pre[t] + 1) * len;         for (int i = 0; i < 26; i++)           if (i != t) {             if (pre[i])               pre[i] = 1;             else               pre[i] = 0;           }       } else if (str[0] == str[len - 1]) {         int t = str[0] -  a ;         if (pre[t])           pre[t] = max(now[t], l + r + 1);         else           pre[t] = max(max(l, r), now[t]);         for (int i = 0; i < 26; i++)           if (i != t) {             if (pre[i])               pre[i] = max(1, now[i]);             else               pre[i] = now[i];           }       } else {         int t = str[0] -  a ;         if (pre[t])           pre[t] = max(1 + l, now[t]);         else           pre[t] = max(l, now[t]);         t = str[len - 1] -  a ;         if (pre[t])           pre[t] = max(1 + r, now[t]);         else           pre[t] = max(r, now[t]);         for (int i = 0; i < 26; i++)           if (i != str[0] -  a  && i != str[len - 1] -  a ) {             if (pre[i])               pre[i] = max(1, now[i]);             else               pre[i] = now[i];           }       }     }     int anss = -1;     for (int i = 0; i < 26; i++) anss = max(anss, pre[i]);     printf( %d n , anss);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, x, res = 0;     cin >> n;     int t[n + 1];     fill(t, t + (n + 1), 0);     for (int i = 1; i <= n; i++) {       cin >> x;       t[x] = t[x - 1] + 1;       res = max(res, t[x]);     }     cout << n - res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   string direc =  RDLU ;   long long ln, lk, lm;   int r, c;   vector<int> v[3105];   multiset<int> ms;   int pos[30];   void fmain() {     scanf( %d%d%d%d , &r, &c, &n, &k);     for (int i = 0, x, y; i < n; i++) {       scanf( %d%d , &x, &y);       v[x].push_back(y);     }     long long ans = 0, cnt = 0;     for (int(i) = 1; (i) <= (int)(r); (i)++) {       ms.clear();       cnt = 0;       for (int(j) = 0; (j) < (int)(k + 1); (j)++) {         ms.insert(0);         ms.insert(c + 1);       }       for (int j = i; j <= r; j++) {         for (int x : v[j]) {           auto it = ms.insert(x), it1 = it;           for (int z = k; z >= 0; z--) {             pos[z] = *it;             it--;           }           it1++;           for (int z = k + 1; z <= k + k; z++) {             pos[z] = *it1;             it1++;           }           for (int z = k; z < k + k; z++) {             cnt += (long long)(pos[z + 1] - pos[z]) *                    (pos[z - (k - 1)] - pos[z - k]);           }         }         ans += cnt;       }     }     printf( %lld n , ans);   }   int main() {     fmain();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T, a, b, c;     cin >> T;     for (int t = 0; t < T; t++) {       cin >> a >> b >> c;       cout << (min(c / 2, b) * 3) + min(a, (b - min(c / 2, b)) / 2) * 3 <<   n ;     }   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int M = 505;   const int nmax = 1e3 + 5;   const long long inf = 1e9;   const int mod = 1e9 + 7;   const long long P = 31;   const int K = 20;   const long double eps = 1e-9;   const int dx[4] = {-1, 0, 1, 0};   const int dy[4] = {0, -1, 0, 1};   set<double> s;   long long a[N];   int main() {     ios_base::sync_with_stdio(false);     long long sum;     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];       s.insert(double(a[i]));       sum += a[i];     }     sort(a, a + n);     long long sm = a[(n >> 1) - 1], bg = a[n >> 1];     while ((int)s.size() > 2) {       double med = 1.0 * (sm + bg) / 2.0;       auto ib = s.begin();       auto ie = s.end();       ie--;       if ((med - *ib) < (*ie - med)) {         auto it = s.lower_bound(sm);         sm = *(--it);         it++;         sum -= *ie;         sum -= *it;         s.erase(ie);         s.erase(it);       } else {         auto it = s.lower_bound(bg);         bg = *(++it);         it--;         sum -= *ib;         sum -= *it;         s.erase(ib);         s.erase(it);       }     }     cout << bg - sm <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool CHMAX(T& a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <class T>   inline bool CHMIN(T& a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   constexpr long long INF = 1e18;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long N;     cin >> N;     vector<long long> a(N);     for (long long i = 0; i < (long long)(N); i++) cin >> a[i];     map<long long, long long> mp;     for (long long i = 0; i < (long long)(N); i++) {       mp[a[i]]++;     }     vector<long long> cnt(N + 1);     long long now = 0;     for (auto e : mp) cnt[e.second]++;     for (long long i = (long long)cnt.size() - 1 - 1; i >= 0; i--) {       cnt[i] += cnt[i + 1];     }     long long ma = -INF;     long long h, w;     for (long long i = 1; i < (long long)cnt.size(); i++) {       now += cnt[i];       for (long long j = i; j * j <= now; j++) {         long long nj = now / j;         if (CHMAX(ma, j * nj)) {           h = j, w = nj;         }       }     }     vector<long long> c;     map<long long, long long> mpp;     for (long long i = 0; i < (long long)(N); i++)       if (++mpp[a[i]] <= h) {         c.push_back(a[i]);         if (c.size() == h * w) break;       }     sort(c.begin(), c.end());     vector<pair<long long, long long>> d;     long long ren = 1;     for (long long i = 0; i < (long long)(c.size()); i++) {       if (i + 1 == c.size() || c[i] != c[i + 1]) {         d.push_back({ren, c[i]});         ren = 1;       } else {         ren++;       }     }     sort(d.begin(), d.end());     reverse(d.begin(), d.end());     vector<long long> e;     for (long long i = 0; i < (long long)(d.size()); i++) {       for (long long j = 0; j < (long long)(d[i].first); j++) {         e.push_back(d[i].second);       }     }     vector<vector<long long>> ans(h, vector<long long>(w));     long long cntcnt = 0;     for (long long j = 0; j < (long long)(w); j++)       for (long long i = 0; i < (long long)(h); i++) ans[i][j] = e[cntcnt++];     cout << h * w <<   n ;     cout << h <<     << w <<   n ;     for (long long i = 0; i < (long long)(h); i++) {       for (long long j = 0; j < (long long)(w); j++) {         if (j) cout <<    ;         cout << ans[i][(j - i + w) % w];       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   int main(void) {     int a, b, x, y;     scanf( %d %d , &a, &b);     x = (a > b) ? a : b;     y = (a < b) ? a : b;     printf( %d %d n , y, ((x - y) / 2));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = int64_t;   using ull = uint64_t;   using ld = long double;   using uint = uint32_t;   const double EPS = 1e-8;   const int INF = 0x3F3F3F3F;   const ll LINF = 4611686018427387903;   const int MOD = 1e9 + 7;   signed main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     int n, m, mx = 0;     string a, b;     cin >> n >> m >> a >> b;     vector<vector<int>> dp(n + 1, vector<int>(m + 1));     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= m; j++) {         if (i) dp[i][j] = max(dp[i][j], dp[i - 1][j] - 1);         if (j) dp[i][j] = max(dp[i][j], dp[i][j - 1] - 1);         if (i && j && a[i - 1] == b[j - 1])           dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);         mx = max(mx, dp[i][j]);       }     }     cout << mx <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int dis(char a, char b) {     if (a > b) swap(b, a);     return min(b - a, a + 26 - b);   }   string tmp =  ACTG ;   int main() {     int n;     scanf( %d , &n);     string s;     cin >> s;     int mn = INT_MAX;     for (int i = 0; i + 4 - 1 < n; i++) {       int now = 0;       for (int j = i, k = 0; k < 4; j++, k++) {         now += dis(s[j], tmp[k]);       }       mn = min(mn, now);     }     printf( %d n , mn);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 90;   vector<long long> col[2];   long long savecol[maxn];   long long dis[maxn][12];   long long g[88][88];   void solve() {     long long n, k;     scanf( %lld %lld , &n, &k);     for (long long i = 1; i <= n; i++)       for (long long j = 1; j <= n; j++) scanf( %lld , &g[i][j]);     long long t = 2000;     long long ans = LLONG_MAX;     while ((double)clock() / 1000 < 0.8) {       col[0].clear();       col[1].clear();       for (long long i = 1; i <= n; i++) {         savecol[i] = rand() % 2;         col[savecol[i]].push_back(i);       }       memset(dis, 0x3f, sizeof(dis));       dis[1][0] = 0;       for (long long nowk = 1; nowk <= k; nowk++) {         for (long long s = 1; s <= n; s++) {           for (long long d : col[savecol[s] ^ 1]) {             dis[d][nowk] = min(dis[d][nowk], dis[s][nowk - 1] + g[s][d]);           }         }       }       ans = min(ans, dis[1][k]);     }     cout << ans << endl;   }   signed main() {     srand(time(NULL));     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 55;   int a[MAXN];   int nxt[6];   long long solve() {     int n;     scanf( %d , &n);     vector<int> ids[6];     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       if (x == 4) ids[0].push_back(i);       if (x == 8) ids[1].push_back(i);       if (x == 15) ids[2].push_back(i);       if (x == 16) ids[3].push_back(i);       if (x == 23) ids[4].push_back(i);       if (x == 42) ids[5].push_back(i);     }     for (int i = 0; i < 6; i++) nxt[i] = 0;     int res = 0;     for (int i : ids[0]) {       int lst = i;       nxt[0]++;       for (int j = 1; j < 6; j++) {         while (nxt[j] < ids[j].size() && ids[j][nxt[j]] < lst) {           nxt[j]++;           res++;         }         if (nxt[j] == ids[j].size()) {           for (int k = 0; k < 6; k++) {             res += ids[k].size() - nxt[k];           }           res += j;           return res;         }         lst = ids[j][nxt[j]];         nxt[j]++;       }     }     int len = ids[0].size();     return (n - res) - len * 6;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int T;     T = 1;     while (T--) {       printf( %lld n , solve());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 11, inf = 1e9 + 10;   char ch[4] = { D ,  I ,  M ,  A };   int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1}, ans = -inf, tans[N][N], n, m;   char c[N][N];   bool mark[N][N], indfs[N][N];   bool isOkay(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m); }   void calcans(int i, int j, int X, int Y) {     tans[i][j] = max(tans[i][j], tans[X][Y]);   }   void dfs(int i, int j, int ind) {     indfs[i][j] = true;     mark[i][j] = true;     bool r = false;     for (int k = 0; k < 4; k++) {       int X = i + dx[k], Y = j + dy[k], t = (ind + 1) % 4;       if (!isOkay(X, Y) || c[X][Y] != ch[t]) continue;       r = true;       if (indfs[X][Y]) {         tans[i][j] = inf;         continue;       }       if (mark[X][Y]) {         calcans(i, j, X, Y);         continue;       }       dfs(X, Y, t);       calcans(i, j, X, Y);     }     if (!r && c[i][j] !=  A )       tans[i][j] = -inf;     else if (c[i][j] ==  A )       tans[i][j]++;     indfs[i][j] = false;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> c[i][j];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (c[i][j] !=  D  || mark[i][j]) continue;         dfs(i, j, 0);       }     }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) ans = max(ans, tans[i][j]);     if (ans <= 0)       cout <<  Poor Dima! ;     else if (ans >= inf)       cout <<  Poor Inna! ;     else       cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int maxn = 611111;   long long num[maxn];   namespace SAM {   int trans[maxn][30], par[maxn], len[maxn], tot, last;   long long cnt[maxn][3];   inline int NewNode() {     memset(trans[tot], 0, sizeof(trans[tot]));     return tot++;   }   inline int NewNode(int u) {     memcpy(trans[tot], trans[u], sizeof(trans[u]));     par[tot] = par[u];     return tot++;   }   inline int h(int u) { return len[u] - len[par[u]]; }   void Extend(int w) {     int p = last, np = NewNode();     len[np] = len[p] + 1;     while (p && !trans[p][w]) {       trans[p][w] = np;       p = par[p];     }     if (!p && !trans[p][w]) {       trans[p][w] = np;       par[np] = 0;     } else {       int q = trans[p][w];       if (len[p] + 1 == len[q])         par[np] = q;       else {         int nq = NewNode(q);         len[nq] = len[p] + 1;         par[q] = par[np] = nq;         while (p && trans[p][w] == q) {           trans[p][w] = nq;           p = par[p];         }         if (!p && trans[p][w] == q) trans[p][w] = nq;       }     }     last = np;   }   bool vis[maxn];   void Dp(int u) {     if (vis[u]) return;     vis[u] = true;     for (int k = 0; k < 3; k++) {       if (trans[u][26 + k]) cnt[u][k] = 1;     }     for (int i = 0; i < 26; i++) {       int v = trans[u][i];       if (v) {         Dp(v);         for (int k = 0; k < 3; k++) {           cnt[u][k] = (cnt[u][k] + cnt[v][k]) % MOD;         }       }     }   }   void Gao() {     for (int i = 1; i < tot; i++) {       long long tmp = ((cnt[i][0] * cnt[i][1]) % MOD * cnt[i][2]) % MOD;       num[len[i]] = (num[len[i]] + tmp) % MOD;       num[len[par[i]]] = (num[len[par[i]]] - tmp + MOD) % MOD;     }     for (int i = tot - 2; i >= 1; i--) {       num[i] = (num[i] + num[i + 1]) % MOD;     }   }   void Init() {     memset(vis, 0, sizeof(vis));     memset(cnt, 0, sizeof(cnt));     tot = 0;     NewNode();   }   void Debug(int tp = 0) {     if (tp == 0)       for (int i = 0; i < tot; i++) {         printf( i=%d,par=%d,len=%d n , i, par[i], len[i]);         for (int j = 0; j < 30; j++) {           if (trans[i][j]) {             printf( to %d %c n , trans[i][j], (char)(j +  a ));           }         }       }     if (tp == 1)       for (int i = 0; i < tot; i++) {         printf( i=%d %I64d %I64d %I64d n , i, cnt[i][0], cnt[i][1], cnt[i][2]);       }   }   }  // namespace SAM   const int INF = 0x3f3f3f3f;   char s[maxn];   int main() {     SAM::Init();     int n = INF;     scanf( %s , s);     n = min(n, (int)strlen(s));     for (int i = 0; s[i]; i++) SAM::Extend(s[i] -  a );     SAM::Extend(26);     scanf( %s , s);     n = min(n, (int)strlen(s));     for (int i = 0; s[i]; i++) SAM::Extend(s[i] -  a );     SAM::Extend(27);     scanf( %s , s);     n = min(n, (int)strlen(s));     for (int i = 0; s[i]; i++) SAM::Extend(s[i] -  a );     SAM::Extend(28);     SAM::Dp(0);     SAM::Gao();     for (int i = 1; i <= n; i++) {       if (i > 1) printf(   );       printf( %I64d , num[i]);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, z;     int x1, y1, z1;     cin >> x >> y >> z;     cin >> x1 >> y1 >> z1;     int a[6];     int ans(0);     for (int i(0); i < 6; ++i) cin >> a[i];     if (z > z1) ans += a[3];     if (z < 0) ans += a[2];     if (x < 0) ans += a[4];     if (x > x1) ans += a[5];     if (y > y1) ans += a[1];     if (y < 0) ans += a[0];     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char** argv) {     string str;     cin >> str;     char g = str[0];     long count = 0, d = 1;     for (string::iterator i = str.begin() + 1; i < str.end(); ++i) {       if (*i != g) {         count++;         g = *i;         d = 1;       } else if (d == 5) {         count++;         d = 1;       } else {         d++;       }     }     cout << ++count;     return 0;   }


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


#include <bits/stdc++.h>   const double EPS = 1e-9;   const int INT_INF = 1 << 31 - 1;   const long long I64_INF = 1ll << 63 - 1ll;   const double PI = acos(-1.0);   using namespace std;   long long solve(int len) {     if (len == 1 || len == 2) return 9LL;     long long pow = 1LL;     for (int i = 0; i < len - 2; i++) pow *= 10LL;     return 9LL * pow;   }   long long go(long long r) {     if (r <= 0) return 0;     int len = 0;     long long R = r;     long long c[20];     while (R) c[len] = R % 10LL, len++, R /= 10LL;     long long res = 0;     for (int i = 1; i < len; i++) res += solve(i);     for (int i = 0; i < (int)len / 2; i++) swap(c[i], c[len - i - 1]);     long long pow = 1LL;     for (int i = 0; i < len - 2; i++) pow *= 10LL;     res += (c[0] - 1LL) * pow;     long long mid = 0;     for (int i = 1; i <= len - 2; i++) mid = mid * 10LL + 1LL * c[i];     if (c[0] <= c[len - 1])       res += mid + 1LL;     else       res += mid;     return res;   };   bool ok(int a) {     int last = a % 10;     int first;     while (a) first = a % 10, a /= 10;     return first == last;   }   long long l, r;   int main() {     cin >> l >> r;     cout << go(r) - go(l - 1) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MxN = (int)2e5 + 9;   const int mod = 998244353;   long long fact[MxN + 9];   vector<int> adj[MxN + 9];   long long f(const int u, const int parent) {     long long res = fact[(int)adj[u].size()];     for (int v : adj[u])       if (v != parent) {         res *= f(v, u);         res %= mod;       }     return res;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr), cout.tie(nullptr);     fact[0] = 1;     for (int i = 1; i <= MxN; ++i) {       fact[i] = fact[i - 1] * i % mod;     }     int n;     cin >> n;     for (int i = 1; i < n; ++i) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     long long ans = n * fact[adj[1].size()] % mod;     for (int x : adj[1]) {       ans *= f(x, 1);       ans %= mod;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x1, x2, x3, x4;   int main() {     cin >> n;     cout <<  YES  << endl;     for (int i = 0; i < n; i++) {       cin >> x1 >> x2 >> x3 >> x4;       x1 = abs(x1) % 2;       x2 = abs(x2) % 2;       cout << x1 * 2 + x2 + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int mod = 1000000009;   long long int power(int x, int y) {     if (y == 0) return 1;     long long int temp = power(x, y / 2);     temp *= temp;     temp %= mod;     if (y & 1) temp *= x;     return temp % mod;   }   long long int ans[100005];   int main() {     int m, n;     cin >> n >> m;     ans[1] = power(2, m) - 1;     for (int i = 2; i <= n; i++) {       ans[i] = ans[i - 1] * (ans[1] - i + 1);       ans[i] %= mod;     }     ans[n] += mod;     ans[n] %= mod;     cout << ans[n] << endl;   }


#include <bits/stdc++.h>   using namespace std;   char s[302][302];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     int n, p;     cin >> n >> p;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     vector<int> ans;     for (int i = 1; i < 2003; i++) {       int cnt = 1, x = i;       for (int j = 0; cnt > 0 && j < n; j++) {         int y = upper_bound(a, a + n, x) - a;         cnt *= (y - j);         cnt %= p;         x++;       }       if (cnt > 0) ans.push_back(i);     }     cout << ans.size() <<   n ;     for (int i = 0; i < (int)ans.size(); i++) {       cout << (i == 0 ?    :    ) << ans[i];     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     long long n;     cin >> t;     while (t--) {       set<long long> a;       a.insert(0);       cin >> n;       for (int i = 1; i <= sqrt(n); i++) {         a.insert(i);         a.insert(n / i);       }       cout << a.size() << endl;       for (auto i : a) cout << i <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:66777216 )   using namespace std;   int inf = 1e9 + 7;   long long INF = 1e18;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     ios_base::sync_with_stdio(false);     int k;     cin >> k;     vector<long long> a;     map<long long, pair<int, int> > sums;     for (int i = 0; i < k; i++) {       int n;       long long sum = 0;       cin >> n;       a.resize(n);       for (int j = 0; j < n; j++) {         cin >> a[j];         sum += a[j];       }       for (int j = 0; j < n; j++) {         if (sums[sum - a[j]] != make_pair(0, 0) &&             sums[sum - a[j]].first != i + 1) {           cout <<  YES  <<   n ;           cout << sums[sum - a[j]].first <<     << sums[sum - a[j]].second                <<   n ;           cout << i + 1 <<     << j + 1;           return 0;         }         sums[sum - a[j]] = make_pair(i + 1, j + 1);       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int N = 1e7 + 5;   const long long INF = 9e18;   const int M = 1e5 + 5;   map<long long, vector<int> > f;   long long p[N], ans1[M], a[M];   void solve() {     for (int i = 2; i <= N; ++i) {       if (i % 2 == 0) {         p[i] = 2;         continue;       }       if (p[i]) continue;       p[i] = i;       for (int j = i * 2; j <= N; j += i) {         if (!p[j]) p[j] = i;       }     }     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       long long x;       cin >> x;       a[i] = x;       while (x > 1) {         long long y = p[x];         while (x > 1 && x % y == 0) {           f[y].push_back(i);           x /= y;         }       }     }     for (int i = 1; i <= m; ++i) {       ans1[i] = 1;       long long x;       cin >> x;       while (x > 1) {         long long y = p[x];         while (x > 1 && x % y == 0) {           if ((int)f[y].size()) {             a[f[y].back()] /= y;             f[y].pop_back();           } else             ans1[i] *= y;           x /= y;         }       }     }     cout << n <<     << m <<   n ;     for (int i = 1; i <= n; ++i) {       cout << a[i] <<    ;     }     cout <<   n ;     for (int i = 1; i <= m; ++i) {       cout << ans1[i] <<    ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     while (T--) {       long long n, k;       cin >> n >> k;       if (k % 3 != 0) {         if (n % 3 == 0)           cout <<  Bob  << endl;         else           cout <<  Alice  << endl;       } else {         n %= (k + 1);         if (n == k || n % 3)           cout <<  Alice  << endl;         else           cout <<  Bob  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string tostr(int n) {     stringstream rr;     rr << n;     return rr.str();   }   int sc() {     register int c = getchar();     register int x = 0;     int neg = 0;     for (; ((c < 48 || c > 57) && c !=  - ); c = getchar())       ;     if (c ==  - ) {       neg = 1;       c = getchar();     }     for (; c > 47 && c < 58; c = getchar()) {       x = (x << 1) + (x << 3) + c - 48;     }     if (neg) x = -x;     return x;   }   inline void out(int n) {     int N = n < 0 ? -n : n, rev, cnt = 0;     rev = N;     if (N == 0) {       putchar( 0 );       putchar(  n );       return;     }     while ((rev % 10) == 0) {       cnt++;       rev /= 10;     }     if (n < 0) putchar( - );     rev = 0;     while (N != 0) {       rev = (rev << 3) + (rev << 1) + N % 10;       N /= 10;     }     while (rev != 0) {       putchar(rev % 10 +  0 );       rev /= 10;     }     while (cnt--) putchar( 0 );     putchar(  n );     return;   }   void deb(istream_iterator<string> it) {}   template <typename T, typename... Args>   void deb(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a << endl;     deb(++it, args...);   }   const int mod = 1e9 + 7;   const int N = 3e5 + 9;   const long double eps = 1e-9;   const long double PI = acos(-1.0);   long long gc(long long a, long long b) {     while (b) {       long long x = a % b;       a = b;       b = x;     }     return a;   }   long long lc(long long a, long long b) { return a / gc(a, b) * b; }   long long qpow(long long n, long long k) {     long long ans = 1;     assert(k >= 0);     n %= mod;     while (k > 0) {       if (k & 1) ans = (ans * n) % mod;       n = (n * n) % mod;       k >>= 1;     }     return ans % mod;   }   vector<long long> v;   void solve() {     long long n;     cin >> n;     long long id = (upper_bound(v.begin(), v.end(), n) - v.begin());     cout << id << endl;   }   int main() {     int t;     cin >> t;     long long ct = 0;     long long add = 1;     long long prv = 0;     for (long long i = 1;; i++) {       ct += add;       add *= 2;       long long x = (ct * (ct + 1) / 2);       x += prv;       prv = x;       if (x > 1000000000000000000LL) break;       v.push_back(x);     }     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   struct circle {     double x, y, r;   };   double dis(circle a, circle b) {     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));   }   bool canGo(circle tar, circle small, circle big) {     if (small.r >= tar.r + dis(tar, small)) return true;     if (big.r + tar.r <= dis(tar, big)) return true;     if (tar.r >= big.r + dis(tar, big)) return true;     return false;   }   int main() {     circle ain, aout, bin, bout;     int ret;     double x, y, r, R;     while (scanf( %lf%lf%lf%lf , &x, &y, &r, &R) != EOF) {       ain.x = aout.x = x;       ain.y = aout.y = y;       ain.r = r;       aout.r = R;       scanf( %lf%lf%lf%lf , &x, &y, &r, &R);       bin.x = bout.x = x;       bin.y = bout.y = y;       bin.r = r;       bout.r = R;       ret = 0;       if (canGo(ain, bin, bout)) ret++;       if (canGo(aout, bin, bout)) ret++;       if (canGo(bin, ain, aout)) ret++;       if (canGo(bout, ain, aout)) ret++;       printf( %d n , ret);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int m;   void bfs(int u, vector<pair<int, int>> &p,            vector<vector<pair<int, int>>> &adj) {     queue<int> q;     q.push(u);     while (!q.empty()) {       int cur = q.front();       q.pop();       for (auto as : adj[cur]) {         int v = as.first;         if (v == p[cur].first) continue;         int e = as.second;         p[v].first = cur;         p[v].second = e;         q.push(v);       }     }   }   int main() {     scanf( %d , &n);     vector<vector<pair<int, int>>> adj(n + 1);     for (int i = 1; i <= n - 1; ++i) {       int u, v;       scanf( %d %d , &u, &v);       adj[u].push_back(make_pair(v, i));       adj[v].push_back(make_pair(u, i));     }     vector<vector<pair<int, int>>> pre(n + 1, vector<pair<int, int>>(n + 1));     for (int i = 1; i <= n; ++i) {       pre[i][i] = make_pair(0, 0);       bfs(i, pre[i], adj);     }     scanf( %d , &m);     vector<int> val(n, 0);     vector<vector<int>> query(m + 1, vector<int>(3, 0));     for (int i = 1; i <= m; ++i) {       scanf( %d %d %d , &query[i][0], &query[i][1], &query[i][2]);     }     for (int i = 1; i <= m; ++i) {       int u = query[i][0];       int v = query[i][1];       int f = query[i][2];       while (true) {         int pree = pre[u][v].second;         int prev = pre[u][v].first;         val[pree] = max(val[pree], f);         v = prev;         if (v == u) break;       }     }     for (int i = 1; i <= m; ++i) {       int u = query[i][0];       int v = query[i][1];       int f = query[i][2];       int mx = 1000000 + 10;       while (true) {         int pree = pre[u][v].second;         int prev = pre[u][v].first;         mx = min(mx, val[pree]);         v = prev;         if (v == u) break;       }       if (mx != f) {         printf( -1 );         return 0;       }     }     for (int i = 1; i <= n - 1; ++i) {       if (val[i] == 0)         printf( 100  );       else         printf( %d  , val[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 2e18 + 33;   const int MX = 2 * 1e5 + 11;   long long N, M, k, s, d;   int arr[MX];   vector<pair<int, int> > v;   int main() {     cin >> N >> M >> s >> d;     for (int i = 0; i < N; i++) scanf( %d , &arr[i]);     arr[N] = M + 1;     sort(arr, arr + N + 1);     long long pos = arr[0] - 1;     if (pos < s) {       cout <<  IMPOSSIBLE n ;       return 0;     }     v.push_back(make_pair(pos, 0));     for (int i = 0; i < N; i++) {       if (i < N - 1 && arr[i + 1] - arr[i] - 2 < s) continue;       if (arr[i] - pos + 1 <= d) {         v.push_back(make_pair(arr[i] - pos + 1, 1));         v.push_back(make_pair(arr[i + 1] - arr[i] - 2, 0));         pos = arr[i + 1] - 1;       }     }     if (pos < M)       cout <<  IMPOSSIBLE n ;     else       for (int i = 0; pos >= M && i < v.size(); i++) {         if (v[i].first == 0) continue;         if (v[i].second == 1)           cout <<  JUMP  ;         else           cout <<  RUN  ;         cout << v[i].first <<   n ;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a;   int main() {     string s;     cin >> s;     int i, l = 0, can = 0, can_too = 0;     for (i = 0; i < s.length(); i++) {       if (s[i] ==  @  && can == 0) {         can = 1;         a.push_back(i);       } else if (s[i] ==  .  && can && !can_too) {         a.push_back(i);       } else if (s[i] ==  /  && can) {         can_too = 1;         a.push_back(i);       }     }     for (i = 0; i < a.size(); i++) {       int ta, tb;       if (i == 0) {         ta = -1;         tb = a[i];       } else {         ta = a[i - 1];         tb = a[i];       }       if (abs(ta - tb) == 1) {         cout <<  NO  << endl;         return 0;       }       for (int j = ta + 1, l = 0; j < tb; j++) {         l++;         if ((s[j] <  a  || s[j] >  z ) && (s[j] <  A  || s[j] >  Z ) &&             (s[j] <  0  || s[j] >  9 ) && s[j] !=  _ ) {           cout <<  NO  << endl;           return 0;         } else if (l > 16) {           cout <<  NO  << endl;           return 0;         }       }       if (i == a.size() - 1) {         ta = a[i];         tb = s.length();         if (abs(ta - tb) == 0) {           cout <<  NO  << endl;           return 0;         }         for (int j = ta + 1, l = 0; j < tb; j++) {           l++;           if ((s[j] <  a  || s[j] >  z ) && (s[j] <  A  || s[j] >  Z ) &&               (s[j] <  0  || s[j] >  9 ) && s[j] !=  _ ) {             cout <<  NO  << endl;             return 0;           } else if (l > 16) {             cout <<  NO  << endl;             return 0;           }         }       }     }     int px = 0, py = 0;     for (i = 0; i < a.size(); i++) {       if (s[a[i]] ==  @ ) {         px = a[i];         break;       }     }     for (i = 0; i < a.size(); i++) {       if (s[a[i]] ==  / ) {         py = a[i];         break;       }     }     if (abs(py - px - 1) > 32 && px && py) {       cout <<  NO  << endl;       return 0;     }     if (a.size() == 0) {       cout <<  NO  << endl;       return 0;     }     if (a.size() == 1 && a[0] == s.length() - 1) {       cout <<  NO  << endl;       return 0;     }     for (i = 0; i < a.size(); i++) {       if (a[i] + 1 == s.length()) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char** argv) {     int n;     int k;     cin >> n >> k;     auto dp = vector<int>(n);     auto mas = vector<int>(n);     for (int i = 0; i < n; ++i) cin >> mas[i];     if (k == n || k == n - 1) {       for (int i = 0; i < n; ++i) cout << n <<    ;       return 0;     }     dp[0] = 1 + k;     for (int i = 1; i < n; ++i)       if (mas[i] == 0)         dp[i] = 1 + min(i - 0, k) + min(n - 1 - i, k);       else if (i - mas[i] >= 2 * k)         dp[i] = 1 + k + min(n - 1 - i, k) + dp[mas[i] - 1];       else {         if (i <= k)           dp[i] = 1 + min(i - 0, k) + min(n - 1 - i, k);         else if (n - mas[i] <= k)           dp[i] = dp[mas[i] - 1];         else           dp[i] = 1 + k + min(n - 1 - i, k) + dp[mas[i] - 1] -                   ((mas[i] - 1 + k) - (i - k) + 1);       }     for (int i = 0; i < n; ++i) cout << dp[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[1000000 + 342];   set<int> ans;   bool incl[1000000 + 342];   bool isleader[1000000 + 342];   map<pair<int, int>, bool> egd;   int main() {     ios::sync_with_stdio(false);     int n, m, x, y;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> x >> y;       if (egd[make_pair(x, y)] == false) {         adj[x].push_back(y);         egd[make_pair(x, y)] = true;       }     }     for (int i = 1; i <= n; i++) {       if (incl[i] == false) {         for (auto next : adj[i]) {           if (next > i)             if (incl[next] == false) {               incl[next] = true;             }         }       }     }     for (int i = n; i >= 1; i--) {       if (incl[i] == false) {         ans.insert(i);         for (auto next : adj[i]) {           incl[next] = true;         }       }     }     cout << ans.size() <<   n ;     for (auto bc : ans) cout << bc <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, les, m, f[5010], g[5010];   char s[5010];   template <class Aqua>   inline void read(Aqua &s) {     s = 0;     Aqua f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) s = s * 10 + c -  0 , c = getchar();     s *= f;   }   int main() {     scanf( %s , s + 1);     m = n = strlen(s + 1);     for (les = 1; n; n >>= 1, les <<= 1)       ;     (les >>= 1)--;     for (int i = 0; i <= les; i++) f[i] = 1;     for (int i = 1; i <= m - les; i++) {       char mn =  z  + 1;       for (int j = 0; j <= les; j++)         if (f[j]) mn = min(mn, s[i + j]);       putchar(mn);       for (int j = 0; j <= les; j++) {         if (f[j] && s[i + j] == mn)           g[j] = 1;         else {           g[j] = 0;           for (int k = 0; (1 << k) <= j; k++)             if ((j >> k) & 1) g[j] |= g[j ^ (1 << k)];         }       }       memcpy(f, g, sizeof(g));     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, l[1010], ch, h = 0, kol = 0;   int main() {     cin >> n;     memset(l, 0, sizeof l);     for (int i = 0; i < n; ++i) {       cin >> ch;       ++l[ch];     }     for (int i = 0; i <= 1000; ++i) {       if (l[i]) ++kol;       h = max(h, l[i]);     }     cout << h <<     << kol;     return 0;   }


#include <bits/stdc++.h>   const size_t N = 2 * 100002;   int main(void) {     long long n, k, res = 0;     std::cin >> n >> k;     int arr[N];     for (long long i = 0; i < n; ++i) std::cin >> arr[i];     int next[N];     next[n - 1] = n;     for (long long i = n - 2; i >= 0; --i)       next[i] = arr[i + 1] != 1 ? i + 1 : next[i + 1];     for (long long left = 0; left < n; ++left) {       long long right = left;       long long mult = arr[left];       long long sum = arr[left];       if (mult == sum * k) res += 1;       while (next[right] != n) {         if (LLONG_MAX / mult < arr[next[right]]) break;         mult *= arr[next[right]];         sum += next[right] - right - 1 + arr[next[right]];         right = next[right];         int k_mult = 0;         if (mult % k == 0) k_mult = mult / k;         if (sum <= k_mult && k_mult <= sum + next[right] - right - 1) res += 1;       }     }     std::cout << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void dbs(string str, T t) {     cerr << str <<   :   << t <<   n ;   }   template <class T, class... S>   void dbs(string str, T t, S... s) {     int idx = str.find( , );     cerr << str.substr(0, idx) <<   :   << t <<  , ;     dbs(str.substr(idx + 1), s...);   }   template <class S, class T>   ostream& operator<<(ostream& os, const pair<S, T>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class T>   ostream& operator<<(ostream& os, const set<T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class S, class T>   ostream& operator<<(ostream& os, const map<S, T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class T>   void prc(T a, T b) {     cerr <<  [ ;     for (T i = a; i != b; ++i) {       if (i != a) cerr <<  ,  ;       cerr << *i;     }     cerr <<  ] n ;   }   const int N = 100010;   const int LOG = 18;   string s;   int n;   int p[LOG][N];   pair<pair<int, int>, int> vec[N];   pair<int, int> suff[N];   int save[N];   int lcp(int a, int b) {     int temp = a;     for (int i = LOG - 1; i >= 0 and max(a, b) < n; i--) {       if (p[i][a] == p[i][b]) {         a += (1 << i), b += (1 << i);       }     }     return a - temp;   }   int main() {     cin >> s;     n = int(s.size());     for (int i = (int)(0); i <= (int)(n - 1); i++) {       p[0][i] = s[i];     }     for (int i = (int)(1); i <= (int)(LOG - 1); i++) {       for (int j = (int)(0); j <= (int)(n - 1); j++) {         if (j + (1 << (i - 1)) >= n) {           vec[j] = make_pair(make_pair(p[i - 1][j], -1), j);         } else {           vec[j] =               make_pair(make_pair(p[i - 1][j], p[i - 1][j + (1 << (i - 1))]), j);         }       }       sort(vec, vec + n);       for (int j = (int)(1); j <= (int)(n - 1); j++) {         if (vec[j].first == vec[j - 1].first) {           p[i][vec[j].second] = p[i][vec[j - 1].second];         } else {           p[i][vec[j].second] = j;         }       }     }     for (int i = (int)(0); i <= (int)(n - 1); i++) {       suff[i] = make_pair(p[LOG - 1][i], i);     }     sort(suff, suff + n);     for (int i = (int)(0); i <= (int)(n - 2); i++) {       save[i] = lcp(suff[i].second, suff[i + 1].second);     }     long long answer1 = 0;     stack<pair<long long, long long>> s1;     s1.push(make_pair(save[0], 1));     long long currSum = save[0];     for (int i = (int)(1); i <= (int)(n - 1); i++) {       answer1 += currSum;       long long x = save[i], cnt = 1;       if (i == n - 1) break;       while (!s1.empty() and s1.top().first > x) {         currSum -= s1.top().first * s1.top().second;         cnt += s1.top().second;         s1.pop();       }       s1.push(make_pair(save[i], cnt));       currSum += x * cnt;     }     cout << answer1 + (n * 1LL * (n + 1)) / 2 <<   n ;     return 0;   }


#include <bits/stdc++.h>   int inp() {     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     int sum = 0;     while (c >=  0  && c <=  9 ) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     return sum;   }   int n, x[200010];   long long ans[200010], sum[200010];   void solve(int a, int b) {     if (a == b) return;     if (a > b) std::swap(a, b);     sum[1] += b - a;     sum[a] -= b - a;     sum[b + 1] += b - a;     sum[a + 1] += (b - a - 1);     sum[b] -= (b - a - 1);     ans[a] += b - 1;     ans[b] += a;   }   int main() {     n = inp();     int m = inp();     for (int i = 1; i <= m; i++) x[i] = inp();     for (int i = 1; i < m; i++) solve(x[i], x[i + 1]);     long long tot = 0;     for (int i = 1; i <= n; i++) {       tot += sum[i];       printf( %lld  , tot + ans[i]);     }     putchar(  n );   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long maxn = 1e5 + 7;   const long long maxe = 1e6 + 7;   const long long INF = 1e9 + 7;   const double PI = acos(-1);   int dx[4] = {0, 0, 1, -1};   int dy[4] = {-1, 1, 0, 0};   inline void Max(int &a, int b) {     if (b > a) a = b;   }   inline void Min(int &a, int b) {     if (a == -1 || b < a) a = b;   }   int n, t, p, L;   pair<int, int> dp[maxn];   int l[maxn], r[maxn];   void update(int k, pair<int, int> t) {     if (dp[k].first < t.first)       dp[k] = t;     else if (dp[k].first == t.first)       dp[k].second = min(dp[k].second, t.second);   }   int main() {     cin >> L >> n >> p >> t;     for (int i = 1; i <= n; i++) scanf( %d%d , &l[i], &r[i]);     dp[0] = make_pair(0, -INF);     for (int i = 1, j = 0; i <= n; i++) {       if (j) j--;       for (; j < i && dp[j].second + t <= r[i]; j++) {         int pos = max(dp[j].second + t, l[i]);         int num = (r[i] - pos) / p;         update(i, make_pair(num + dp[j].first, pos + num * p));       }       update(i, dp[i - 1]);     }     cout << dp[n].first << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[] = {0, 0, 1, -1}, dy[] = {-1, 1, 0, 0};   const int dxx[] = {0, 0, 1, -1, -1, -1, 1, 1},             dyy[] = {-1, 1, 0, 0, 1, -1, 1, -1};   ifstream f(  );   ofstream g(  );   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long n, m, prv = 0, prvmax = -1;     cin >> n >> m;     vector<int> v(0);     for (int a; n; n--) cin >> a, v.push_back(a);     vector<pair<long long, long long> > w(0);     for (int a, b; m; m--) cin >> a >> b, w.push_back({a, b});     sort(w.begin(), w.end());     for (int i = 0; i <= w.size() - 1; i++) {       w[i].first = max(w[i].first, prvmax);       prvmax = w[i].first;       w[i].second += prv;       prv = w[i].second;     }     for (auto i : v)       if (i < w.front().first)         cout <<  0  ;       else if (i >= w.back().first)         cout << w.back().second <<    ;       else {         int st = 0, dr = w.size() - 1, rz;         while (st <= dr) {           int m = (st + dr) / 2;           if (w[m].first <= i)             st = m + 1, rz = m;           else             dr = m - 1;         }         cout << w[rz].second <<    ;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s, a, b;   int to[27], k, T;   bool vis[27];   bool up(int dir) {     if (dir == s.size()) return 1;     if (to[s[dir] -  a ] != -1) {       int t = to[s[dir] -  a ];       if (t > a[dir] -  a ) return 1;       if (t < a[dir] -  a ) return 0;       return up(dir + 1);     }     for (int i = a[dir] -  a  + 1; i < k; ++i)       if (!vis[i]) return vis[to[s[dir] -  a ] = i] = 1;     if (!vis[a[dir] -  a ]) {       vis[a[dir] -  a ] = 1;       to[s[dir] -  a ] = a[dir] -  a ;       if (up(dir + 1)) return 1;       to[s[dir] -  a ] = -1;       vis[a[dir] -  a ] = 0;     }     return 0;   }   bool down(int dir) {     if (dir == s.size()) return 1;     if (to[s[dir] -  a ] != -1) {       int t = to[s[dir] -  a ];       if (t > b[dir] -  a ) return 0;       if (t < b[dir] -  a ) return 1;       return down(dir + 1);     }     for (int i = 0; i < b[dir] -  a ; ++i)       if (!vis[i]) return vis[to[s[dir] -  a ] = i] = 1;     if (!vis[b[dir] -  a ]) {       vis[b[dir] -  a ] = 1;       to[s[dir] -  a ] = b[dir] -  a ;       if (down(dir + 1)) return 1;       to[s[dir] -  a ] = -1;       vis[b[dir] -  a ] = 0;     }     return 0;   }   bool dfs(int dir) {     if (dir == s.size()) return 1;     if (to[s[dir] -  a ] != -1) {       int t = to[s[dir] -  a ];       if (t > a[dir] -  a  && t < b[dir] -  a ) return 1;       if (t < a[dir] -  a  || t > b[dir] -  a ) return 0;       if (t == a[dir] -  a  && t == b[dir] -  a ) return dfs(dir + 1);       if (t == a[dir] -  a ) return up(dir + 1);       if (t == b[dir] -  a ) return down(dir + 1);     }     for (int i = a[dir] -  a  + 1; i < b[dir] -  a ; ++i)       if (!vis[i]) return vis[to[s[dir] -  a ] = i] = 1;     if (!vis[a[dir] -  a ]) {       vis[a[dir] -  a ] = 1;       to[s[dir] -  a ] = a[dir] -  a ;       if (a[dir] -  a  == b[dir] -  a ) return dfs(dir + 1);       if (up(dir + 1)) return 1;       vis[a[dir] -  a ] = 0;       to[s[dir] -  a ] = 0;     }     if (!vis[b[dir] -  a ]) {       vis[b[dir] -  a ] = 1;       to[s[dir] -  a ] = b[dir] -  a ;       if (down(dir + 1)) return 1;     }     return 0;   }   int main() {     ios::sync_with_stdio(0);     for (cin >> T; T; --T) {       cin >> k >> s >> a >> b;       memset(to, -1, sizeof(to));       memset(vis, 0, sizeof(vis));       if (dfs(0)) {         cout <<  YES  <<   n ;         for (int i = 0; i < k; ++i)           if (to[i] == -1) {             for (int j = 0; j < k; ++j)               if (!vis[j]) {                 vis[j] = 1;                 cout << (char)( a  + j);                 break;               }           } else             cout << (char)( a  + to[i]);         cout <<   n ;       } else         cout <<  NO  <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     map<int, int> container_1;     map<int, int> container_2;     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       int a, b;       cin >> a >> b;       container_1[a] = b;       container_2[a] = 0;     }     int k;     cin >> k;     for (int i = 0; i < k; ++i) {       int a, b;       cin >> a >> b;       container_2[a] = b;       if (container_1.find(a) == container_1.end()) {         container_1[a] = 0;       }     }     long long sum = 0;     for (auto it : container_1) {       if (it.second > container_2[it.first]) {         sum += it.second;       } else {         sum += container_2[it.first];       }     }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int MAX = 1000005;   vector<int> dp[MAX];   int a[MAX];   void add(int &a, int b) {     a += b;     if (a >= MOD) a -= MOD;   }   int main() {     int n, k;     long long l;     scanf( %d %I64d %d , &n, &l, &k);     for (int i = 0; i < n; i++) dp[i].resize(k + 1);     vector<int> vals;     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       vals.push_back(a[i]);     }     sort(vals.begin(), vals.end());     vals.resize(unique(vals.begin(), vals.end()) - vals.begin());     for (int i = 0; i < n; i++) {       a[i] = lower_bound(vals.begin(), vals.end(), a[i]) - vals.begin();       dp[i][1] = 1;     }     vector<int> cnt;     cnt.resize(vals.size());     for (int j = 2; j <= k; j++) {       for (int i = 0; i < (int)cnt.size(); i++) cnt[i] = 0;       for (int i = 0; i < n; i++) add(cnt[a[i]], dp[i][j - 1]);       for (int i = 1; i < (int)cnt.size(); i++) add(cnt[i], cnt[i - 1]);       for (int i = 0; i < n; i++) dp[i][j] = cnt[a[i]];     }     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 1; j <= k; j++) {         long long b = l / n;         if (i < l % n) b++;         b = b - j + 1;         if (b > 0) ans = (ans + (b % MOD) * dp[i][j]) % MOD;       }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i, j, x, y, b, a, temp;     cin >> n >> b >> a;     temp = a;     long long int c[n];     for (i = 0; i < n; i++) cin >> c[i];     for (i = 0; i < n; i++) {       if (c[i] == 0 && a != 0)         a--;       else {         if (b > 0 && c[i] == 1) {           if (a < temp) {             a++;             b--;           } else {             a--;           }         } else {           if (b > 0 && c[i] == 0)             b--;           else {             if (b == 0) a--;           }         }       }       if (b == 0 && a == 0) break;     }     if (i == n)       cout << i;     else       cout << i + 1;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       bool gt = true;       long long mn = m, mx = m;       long long curt = 0;       for (long long i = 0; i < n; i++) {         long long t, l, h;         cin >> t >> l >> h;         long long ti = t - curt;         mn -= ti;         mx += ti;         if (l > mx || h < mn) gt = false;         mn = max(mn, l);         mx = min(mx, h);         curt = t;       }       if (gt)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int maxSubArraySum(long long int a[], long long int size) {     long long int max_so_far = INT_MIN, max_ending_here = 0;     for (long long int i = 0; i < size; i++) {       max_ending_here = max_ending_here + a[i];       if (max_so_far < max_ending_here) max_so_far = max_ending_here;       if (max_ending_here < 0) max_ending_here = 0;     }     return max_so_far;   }   int32_t main() {     long long int t;     t = 1;     while (t--) {       long long int n;       cin >> n;       long long int sum = 0;       long long int a[n];       string s;       vector<long long int> v;       long long int k;       cin >> k;       long long int b[n];       for (long long int i = 0; i < n; i++) {         cin >> a[i];         b[i] = a[i];       }       sort(b, b + n);       long long int p = 0;       for (long long int i = 0; i < n; i++) {         if (a[i] != b[i]) {           p = 1;           break;         }       }       if (p == 0) {         cout << maxSubArraySum(a, n);       } else {         long long int ansfinal = -1e9;         for (long long int i = 0; i < n; i++) {           for (long long int j = i; j < n; j++) {             long long int u = k;             long long int ans = 0;             priority_queue<long long int> pq;             priority_queue<long long int, vector<long long int>,                            greater<long long int>>                 pqmin;             for (long long int k = 0; k < n; k++) {               if (k >= i && k <= j) {                 ans += a[k];                 pqmin.push(a[k]);               } else {                 pq.push(a[k]);               }             }             while (u && pq.size() && pqmin.size()) {               if (pqmin.top() >= pq.top()) {                 break;               } else {                 ans -= pqmin.top();                 pqmin.pop();                 ans += pq.top();                 pq.pop();               }               u--;             }             ansfinal = max(ans, ansfinal);           }         }         cout << ansfinal;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   long long a[N], f[N];   int main() {     long long o, t, n = 1;     long long s = 0;     scanf( %I64d , &o);     while (o--) {       scanf( %I64d , &t);       if (t == 2) {         n++;         scanf( %I64d , &a[n]);         f[n] = 0;         s += a[n];       } else if (t == 1) {         long long cnt, x;         scanf( %I64d%I64d , &cnt, &x);         f[cnt] += x;         s += cnt * x;       } else if (t == 3) {         s -= (f[n] + a[n]);         f[n - 1] += f[n];         f[n] = 0;         n--;       }       printf( %.9lf n , s * 1.0 / n);     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, d[500][500], dist[500][500];   long long t, a, c, b;   int main() {     cin >> n;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= n; j++) {         cin >> d[i][j];         dist[i][j] = d[i][j];       }     }     long long tong;     cin >> t;     while (t--) {       cin >> a >> b >> c;       tong = 0;       dist[a][b] = dist[b][a] = min(dist[a][b], min(dist[b][a], c));       for (long long i = 1; i <= n; i++) {         for (long long j = 1; j <= n; j++) {           dist[i][j] = min(dist[i][j], min(dist[i][a] + c + dist[b][j],                                            dist[i][b] + c + dist[a][j]));         }       }       for (long long i = 1; i <= n; i++) {         for (long long j = i + 1; j <= n; j++) {           tong += dist[i][j];         }       }       cout << tong <<    ;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   const int MAX = 2e5 + 5;   const long long MAX2 = 11;   const int MOD = 1000000000 + 7;   const long long INF = 20000;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1};   const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};   const double pi = acos(-1);   long long n, h, ans;   bool st, ada;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> h >> n;     n--;     for (int i = (int)h - 1; i >= (int)0; i--) {       ada = (1ll << i) & n;       if (ada ^ st)         ans += (1ll << (i + 1));       else         ans++, st ^= 1;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     while (a % b != 0) {       long long aux = a % b;       a = b;       b = aux;     }     return b;   }   int main() {     ios::sync_with_stdio(0);     cin.tie();     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       long long a, b, d;       cin >> a >> b >> d;       long long div = gcd(a, b);       a /= div;       b /= div;       while (true) {         div = gcd(b, d);         if (1 == div)           break;         else {           while (b % div == 0) b /= div;           d = div;         }       }       if (b == 1)         cout <<  Finite n ;       else         cout <<  Infinite n ;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     double exp, ans, pi;     exp = ans = 0.0;     for (int i = 0; i < n; i++) {       scanf( %lf , &pi);       exp = exp * pi + pi;       ans = ans + 2 * exp - pi;     }     printf( %.12lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T sqr(T x) {     return x * x;   }   const double EPS = 1e-10;   const int INF = 0x3fffffff;   const long long LINF = INF * 1ll * INF;   const double PI = acos(-1.0);   using namespace std;   int sign(double x) { return x > 0 ? 1 : -1; }   int main(void) {     int x1, y1, x2, y2;     scanf( %d %d %d %d , &x1, &y1, &x2, &y2);     int vmax, t;     scanf( %d %d , &vmax, &t);     double low = 0, high = t;     double windX, windY;     scanf( %lf %lf , &windX, &windY);     double newX, newY;     scanf( %lf %lf , &newX, &newY);     bool find = false;     while (low + EPS <= high) {       double mid = (low + high) / 2.0;       double deltaX = x2 - x1;       double deltaY = y2 - y1;       double vx = deltaX / mid - windX;       if (abs(vx) - abs(vmax) > 0) {         low = mid;         continue;       }       double vy = sqrt(vmax * vmax - vx * vx) + windY;       double mx = vy * mid;       vy = -sqrt(vmax * vmax - vx * vx) + windY;       double mi = vy * mid;       if (mx < mi) swap(mx, mi);       if (mi - EPS <= deltaY && deltaY <= mx + EPS) {         high = mid;         find = true;       } else         low = mid;     }     if (!find) {       low = t, high = 1e9;       while (low + EPS <= high) {         double mid = (low + high) / 2.0;         double deltaX = x2 - x1;         double deltaY = y2 - y1;         double vx = deltaX - t * windX - newX * (mid - t);         vx /= mid;         if (abs(vx) - abs(vmax) > 0) {           low = mid;           continue;         }         double vy = sqrt(vmax * vmax - vx * vx);         double mx = vy * mid + t * windY + (mid - t) * newY;         vy = -sqrt(vmax * vmax - vx * vx);         double mi = vy * mid + t * windY + (mid - t) * newY;         if (mx < mi) swap(mx, mi);         if (mi - EPS <= deltaY && deltaY <= mx + EPS) {           high = mid;         } else           low = mid;       }     }     printf( %.10lf n , low);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k, rt, i, j;     char a[] = { a ,  e ,  i ,  o ,  u };     cin >> k;     rt = (int)sqrt(k);     for (; k % rt != 0; rt--)       ;     if (rt > 4) {       for (i = 0; i != k / rt; i++) {         for (j = 0; j != rt; j++) {           cout << a[(i + j) % 5];         }       }     } else       cout <<  -1 ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 505;   int dp[N][N];   int a[N];   int calc(int l, int r) {     if (dp[l][r] != -1) return dp[l][r];     if (l > r) {       return dp[l][r] = 1;     }     if (l == r) {       return dp[l][r] = 1;     }     dp[l][r] = N;     if (a[l] == a[r]) {       dp[l][r] = min(dp[l][r], calc(l + 1, r - 1));     }     for (int j = l; j < r; j++) {       dp[l][r] = min(dp[l][r], calc(l, j) + calc(j + 1, r));     }     return dp[l][r];   }   int main() {     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++) dp[i][j] = -1;     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     cout << calc(0, n - 1) << endl;   }


#include <bits/stdc++.h>   const long long int M = 2000000005;   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int t;     t = 1;     while (t--) {       long long int n, i, c, j;       string s;       cin >> s;       n = s.size();       vector<long long int> v[26];       for (i = 0; i < 26; i++) {         v[i].push_back(-1);       }       for (i = 0; i < n; i++) {         c = (long long int)s[i] - 97;         v[c].push_back(i);       }       for (i = 0; i < 26; i++) {         v[i].push_back(n);       }       long long int ans = 1e18, ans1;       for (i = 0; i < 26; i++) {         if (v[i].size() == 2) {           continue;         }         ans1 = -1e18;         for (j = 1; j < v[i].size(); j++) {           ans1 = max(ans1, v[i][j] - v[i][j - 1]);         }         ans = min(ans, ans1);       }       cout << ans;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     long long an1 = 1, an2 = 1;     for (int i = 0; i < n; ++i) {       an1 = (an1 * 7) % 1000000007;     }     for (int i = 0; i < 3 * n; ++i) {       an2 = (an2 * 3) % 1000000007;     }     long long ot = an2 - an1;     while (ot < 0) ot += 1000000007;     cout << ot;     return 0;   }


#include <bits/stdc++.h>   int p, prime[100005], count[100005][20];   void Prime() {     int i, j;     for (i = 2, p = 0; i < 100005; i++) {       for (j = 2; j <= sqrt(i); j++)         if (i % j == 0) break;       if (j > sqrt(i)) prime[p++] = i;     }   }   void Count() {     int i, j;     memset(count, 0, sizeof(count));     for (i = 0; i < p; i++)       for (j = prime[i]; j < 100005; j += prime[i])         count[j][++count[j][0]] = prime[i];   }   int main() {     Prime();     Count();     char sym;     int n, m, i, j, ind, flag[100005], num[100005];     while (scanf( %d%d , &n, &m) != EOF) {       memset(flag, 0, sizeof(flag));       memset(num, 0, sizeof(num));       for (i = 0; i < m; i++) {         getchar();         scanf( %c %d , &sym, &ind);         if (sym ==  + ) {           if (flag[ind])             printf( Already on n );           else {             for (j = 1; j <= count[ind][0]; j++)               if (num[count[ind][j]]) break;             if (j > count[ind][0]) {               printf( Success n );               flag[ind] = 1;               for (j = 1; j <= count[ind][0]; j++) num[count[ind][j]] = ind;             } else               printf( Conflict with %d n , num[count[ind][j]]);           }         } else {           if (!flag[ind])             printf( Already off n );           else {             printf( Success n );             flag[ind] = 0;             for (j = 1; j <= count[ind][0]; j++) num[count[ind][j]] = 0;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a << endl;     err(++it, args...);   }   long long powMod(long long x, long long y) {     long long p = 1;     while (y) {       if (y % 2) {         p = (p * x) % ((long long)1e9 + 7);       }       y /= 2;       x = (x * x) % ((long long)1e9 + 7);     }     return p;   }   long long CpowMod(long long x, long long y, long long w) {     long long p = 1;     while (y) {       if (y % 2) {         p = (p * x) % w;       }       y /= 2;       x = (x * x) % w;     }     return p;   }   long long invMod(long long x) { return powMod(x, ((long long)1e9 + 7) - 2); }   long long CinvMod(long long x, long long w) { return CpowMod(x, w - 2, w); }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   void solve() {     long long n;     cin >> n;     long long ans = 1;     for (long long i = 1; i <= n - 1; i++) {       if (i != n / 2) ans *= i;     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout.precision(20);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int x, id;     friend bool operator<(node a, node b) {       if (a.x == b.x) return a.id < b.id;       return a.x < b.x;     }   } a[200005];   priority_queue<node> Q;   struct edge {     int s, e;   } ans[2000005];   int id;   int main() {     int n, s;     while (scanf( %d %d , &n, &s) != EOF) {       int i, j, k;       for (i = 1; i <= n; ++i) {         scanf( %d , &a[i].x);         a[i].id = i;         Q.push(a[i]);       }       node x;       id = 0;       while (!Q.empty()) {         x = Q.top();         Q.pop();         j = 0;         for (i = 0; i < x.x && (!Q.empty()); ++i) {           a[j] = Q.top();           Q.pop();           ans[id].s = x.id;           ans[id].e = a[j].id;           a[j].x--;           j++;           id++;         }         if (i == x.x) {           --j;           while (j >= 0) {             if (a[j].x) {               Q.push(a[j]);             }             j--;           }         } else {           s = 0;           break;         }       }       if (s == 0) {         puts( No );       } else {         puts( Yes );         printf( %d n , id);         for (i = 0; i < id; ++i) {           printf( %d %d n , ans[i].s, ans[i].e);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1E5 + 1;   long long int n, m, rk, ans;   set<pair<long long int, long long int> > dep[N], dpt;   vector<pair<long long int, pair<long long int, long long int> > > query;   pair<long long int, long long int> arrival[N];   long long int setarrival() {     for (long long int i = 0; i <= n; i++) {       arrival[i].first = -1;       arrival[i].second = 1E17;     }     long long int i = 0;     set<long long int> s;     for (i = 0; i < query.size(); i++) {       if (s.size() < n) {         long long int c1 = query[i].second.second;         long long int f = query[i].second.first;         if (arrival[f].second > c1) {           arrival[f].second = c1;           arrival[f].first = query[i].first;         }         s.insert(f);       } else         break;     }     if (s.size() < n) return -1;     return i;   }   long long int setd() {     for (long long int i = 1; i <= n; i++) {       if (dep[i].empty()) return -1;       set<pair<long long int, long long int> >::iterator it = dep[i].begin();       long long int c = (*it).first;       long long int d = (*it).second;       ans += c;       dpt.insert({d, i});     }     return 1;   }   long long int check() {     long long int mx = 0;     for (long long int i = 1; i <= n; i++) {       long long int d = arrival[i].first;       ans += arrival[i].second;       if (d == -1) return -1;       mx = max(d, mx);     }     return mx;   }   long long int setdept(long long int day) {     long long int rd = day + rk + 1;     while (1) {       set<pair<long long int, long long int> >::iterator k = dpt.begin();       long long int d = (*k).first;       long long int i = (*k).second;       if (d >= rd) break;       long long int f = 0, in = 0;       while (!dep[i].empty()) {         set<pair<long long int, long long int> >::iterator it = dep[i].begin();         long long int c = (*it).first;         d = (*it).second;         if (d < rd) {           if (in == 0) ans -= c;           in++;           dep[i].erase(*dep[i].begin());         } else {           f = 1;           ans += c;           dpt.erase(k);           dpt.insert({d, i});           break;         }       }       if (f == 0) return -1;     }     return 1;   }   int main() {     cin >> n >> m >> rk;     vector<long long int> v;     while (m--) {       long long int d, f, t, c;       cin >> d >> f >> t >> c;       if (f == 0)         dep[t].insert({c, d});       else         query.push_back({d, {f, c}});     }     sort(query.begin(), query.end());     ans = 0;     long long int idx = setarrival();     long long int ik = setd();     if (idx == -1 || ik == -1) {     REP:       cout << -1;       return 0;     }     long long int day = check();     if (day == -1) goto REP;     long long int sd = setdept(day);     if (sd == -1) goto REP;     v.push_back(ans);     for (long long int i = idx; i < query.size(); i++) {       long long int f = query[i].second.first;       long long int d = query[i].first;       long long int c = query[i].second.second;       if (arrival[f].second > c) {         ans = v.back();         ans -= arrival[f].second;         ans += c;         sd = setdept(d);         if (sd == -1) break;         v.push_back(ans);         arrival[f].second = c;         arrival[f].first = d;       }     }     ans = *min_element(v.begin(), v.end());     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string a, b;     cin >> a >> b;     int pa = 0;     while (pa + 1 < a.size() && a[pa + 1] < b[0]) pa++;     for (int i = 0; i <= pa; i++) cout << a[i];     cout << b[0];   }