#include <bits/stdc++.h> n using namespace std; n template <class T> n using v2d = vector<vector<T> >; n template <class T> n bool uin(T &a, T b) { n   return a > b ? (a = b, true) : false; n } n template <class T> n bool uax(T &a, T b) { n   return a < b ? (a = b, true) : false; n } n mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); n const int maxN = 2e5 + 10; n int n, q; n vector<int> adj[maxN]; n int t[maxN], in[maxN], out[maxN], f[maxN * 4], lazy[maxN * 4], mp[maxN]; n int L, R; n void dfs(int u) { n   in[u] = ++in[0]; n   mp[in[u]] = u; n   for (auto &v : adj[u]) { n     dfs(v); n   } n   out[u] = in[0]; n } n void build(int x, int lo, int hi) { n   if (lo == hi) { n     f[x] = t[mp[lo]]; n     return; n   } n   int mid = (lo + hi) / 2; n   build(x * 2, lo, mid); n   build(x * 2 + 1, mid + 1, hi); n   f[x] = f[x * 2] + f[x * 2 + 1]; n } n void down(int x, int lo, int hi) { n   int t = lazy[x]; n   lazy[x] = 0; n   if (t & 1) { n     int mid = (lo + hi) / 2; n     ++lazy[x * 2]; n     f[x * 2] = mid - lo + 1 - f[x * 2]; n     ++lazy[x * 2 + 1]; n     f[x * 2 + 1] = hi - mid - f[x * 2 + 1]; n   } n } n void update(int x, int lo, int hi) { n   if (lo > R || hi < L) { n     return; n   } n   if (lo >= L && hi <= R) { n     f[x] = hi - lo + 1 - f[x]; n     ++lazy[x]; n     return; n   } n   down(x, lo, hi); n   int mid = (lo + hi) / 2; n   update(x * 2, lo, mid); n   update(x * 2 + 1, mid + 1, hi); n   f[x] = f[x * 2] + f[x * 2 + 1]; n } n int query(int x, int lo, int hi) { n   if (lo > R || hi < L) { n     return 0; n   } n   if (lo >= L && hi <= R) { n     return f[x]; n   } n   int mid = (lo + hi) / 2; n   down(x, lo, hi); n   return query(x * 2, lo, mid) + query(x * 2 + 1, mid + 1, hi); n } n void solve() { n   cin >> n; n   for (int i = (int)(2); i <= (int)(n); ++i) { n     int p; n     cin >> p; n     adj[p].emplace_back(i); n   } n   for (int i = 1; i <= (int)(n); ++i) { n     cin >> t[i]; n   } n   dfs(1); n   build(1, 1, n); n   cin >> q; n   while (q--) { n     string task; n     int v; n     cin >> task >> v; n     if (task ==  get ) { n       L = in[v], R = out[v]; n       cout << query(1, 1, n) <<   n ; n     } else { n       L = in[v], R = out[v]; n       update(1, 1, n); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int T = 1; n   while (T--) { n     solve(); n   } n   return 0; n } n


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


#include <bits/stdc++.h> n const long long MOD = 1000000007; n using namespace std; n long long ans[2005][2005]; n int main() { n   long long i, j, k; n   long long A[2005], N, H; n   cin >> N >> H; n   for (i = 0; i < N; i++) { n     cin >> A[i]; n   } n   if (A[0] == H - 1) { n     ans[0][0] = 1; n     ans[0][1] = 1; n   } n   if (A[0] == H) { n     ans[0][0] = 1; n   } n   for (i = 1; i <= N; i++) { n     for (j = 0; j <= i + 1; j++) { n       if (A[i] + j == H - 1) { n         ans[i][j] += ans[i - 1][j]; n         ans[i][j] %= MOD; n         ans[i][j] += (ans[i - 1][j + 1] * (j + 1)); n         ans[i][j] %= MOD; n         if (j > 0) { n           ans[i][j] += (ans[i - 1][j] * j); n           ans[i][j] %= MOD; n         } n       } else if (A[i] + j == H) { n         ans[i][j] += ans[i - 1][j]; n         ans[i][j] %= MOD; n         if (j > 0) { n           ans[i][j] += ans[i - 1][j - 1]; n           ans[i][j] %= MOD; n         } n       } n     } n   } n   ans[i][j] %= MOD; n   cout << ans[N - 1][0] <<   n ; n   return 0; n } n


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const int SIZE = 1e6 + 10; n char A[SIZE]; n long long d[SIZE]; n int len; n vector<long long> D; n long long dp[2][4000][2][2]; n void ADD(long long &x, long long v) { x = (x + v) % MOD; } n long long CC(long long x) { return x * (x - 1) / 2 % MOD; } n long long con(long long x, long long y) { n   if (x > y) return 0; n   return (x + y) * (y - x + 1) / 2 % MOD; n } n int main() { n   int p, a; n   scanf( %d%d , &p, &a); n   scanf( %s , (A)); n   len = strlen(A); n   for (int i = 0; i < (len); ++i) { n     d[len - 1 - i] = A[i] -  0 ; n   } n   int top = len - 1; n   while (top >= 0) { n     long long r = 0; n     for (int i = top; i >= 0; i--) { n       r *= 10; n       d[i] += r; n       r = d[i] % p; n       d[i] /= p; n     } n     D.push_back(r); n     while (top >= 0 && d[top] == 0) top--; n   } n   if (a >= ((int)(D).size())) return 0 * puts( 0 ); n   int now = 0, nxt = 1; n   dp[now][0][1][0] = 1; n   for (int i = ((int)(D).size()) - 1; i >= 0; i--) { n     memset((dp[nxt]), 0, sizeof((dp[nxt]))); n     for (int j = 0; j < (a + 1); ++j) { n       ADD(dp[nxt][j][1][0], dp[now][j][1][1] * (p - 1 - D[i])); n       ADD(dp[nxt][min(j + 1, a)][1][1], dp[now][j][1][1] * (p - D[i])); n       ADD(dp[nxt][j][0][0], dp[now][j][1][1] * con(p - D[i], p - 1)); n       ADD(dp[nxt][min(j + 1, a)][0][1], n           dp[now][j][1][1] * con(p - D[i] + 1, p)); n       ADD(dp[nxt][j][1][0], dp[now][j][1][0] * (D[i] + 1)); n       ADD(dp[nxt][min(j + 1, a)][1][1], dp[now][j][1][0] * D[i]); n       ADD(dp[nxt][j][0][0], dp[now][j][1][0] * con(1, D[i])); n       ADD(dp[nxt][min(j + 1, a)][0][1], dp[now][j][1][0] * con(1, D[i] - 1)); n       ADD(dp[nxt][j][0][0], dp[now][j][0][1] * con(1, p - 1)); n       ADD(dp[nxt][min(j + 1, a)][0][1], dp[now][j][0][1] * con(1, p)); n       ADD(dp[nxt][j][0][0], dp[now][j][0][0] * con(1, p)); n       ADD(dp[nxt][min(j + 1, a)][0][1], dp[now][j][0][0] * con(1, p - 1)); n     } n     swap(now, nxt); n   } n   long long an = 0; n   for (int j = 0; j < (2); ++j) ADD(an, dp[now][a][j][0]); n   cout << an; n   return 0; n } n


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


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


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


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


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


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


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


#include <bits/stdc++.h> n int main() { n   char str[1000][1000], str1[] =  bcdfghjklmpqrstvwxyz ; n   int i, j, k, c = 0, s = 0; n   scanf( %s , str[0]); n   for (i = 0; i < strlen(str[0]); i++) { n     for (j = 0; j < strlen(str1); j++) { n       if (str[0][i] == str1[j]) { n         s = s + 1; n         if (str[0][i + 1] ==  a  || str[0][i + 1] ==  e  || n             str[0][i + 1] ==  i  || str[0][i + 1] ==  o  || n             str[0][i + 1] ==  u ) { n           c = c + 1; n         } n       } n     } n   } n   if (s == c) { n     printf( YES ); n   } else { n     printf( NO ); n   } n } n


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


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


#include <bits/stdc++.h> n using namespace std; n int G[16][110]; n bool B[110][2]; n int main() { n   memset(G, -1, sizeof(G)); n   for (int i = 0; i < 16; i++) { n     G[i][0] = 0; n   } n   for (int j = 1; j <= 105; j++) { n     for (int i = 0; i < 16; i++) { n       if ((i & 5) == 5 || (i & 10) == 10) { n         continue; n       } n       vector<int> gs; n       for (int k = (i & 4 ? 1 : 0); k + (i & 8 ? 1 : 0) < j; k++) { n         gs.push_back(G[(i & 5) | 2][max(0, k)] ^ n                      G[(i & 10) | 1][max(0, j - k - 1)]); n       } n       for (int k = (i & 1 ? 1 : 0); k + (i & 2 ? 1 : 0) < j; k++) { n         gs.push_back(G[(i & 5) | 8][max(0, k)] ^ n                      G[(i & 10) | 4][max(0, j - k - 1)]); n       } n       sort(gs.begin(), gs.end()); n       gs.resize(unique(gs.begin(), gs.end()) - gs.begin()); n       G[i][j] = 0; n       assert(gs.empty() || gs[0] >= 0); n       for (int& g = G[i][j]; g < gs.size() && gs[g] == g; g++) n         ; n     } n   } n   int R, N; n   cin >> R >> N; n   for (int i = 0; i < N; i++) { n     int r, c; n     cin >> r >> c; n     r--; n     c--; n     B[r][c] = true; n     B[r][1 - c] = true; n     if (r > 0) B[r - 1][1 - c] = true; n     if (r + 1 < R) B[r + 1][1 - c] = true; n   } n   int gg = 0; n   for (int i = 0;;) { n     while (i < R && B[i][0] && B[i][1]) i++; n     if (i == R) break; n     int sz = 0; n     int lf = 0; n     int rh = 0; n     while (i + sz < R && !(B[i + sz][0] && B[i + sz][1])) { n       if (B[i + sz][0]) { n         lf++; n       } else if (B[i + sz][1]) { n         rh++; n       } n       sz++; n     } n     if (lf == 0 && rh == 0) { n       gg ^= G[0][sz]; n     } else if (lf + rh == 1) { n       gg ^= G[1][sz]; n     } else if (lf == 2 || rh == 2) { n       gg ^= G[3][sz]; n     } else if (lf == 1 && rh == 1) { n       gg ^= G[9][sz]; n     } else { n       assert(0); n     } n     i += sz; n   } n   if (gg) { n     cout <<  WIN  << endl; n   } else { n     cout <<  LOSE  << endl; n   } n   return 0; n } n


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


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


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


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


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


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


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


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


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


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


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