#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 7; n long long eq(long long start, long long k) { n   long long num = k - (start - 1); n   return ((num * (start + k)) / 2) - (num - 1); n } n void solve() { n   long long n, k; n   cin >> n >> k; n   long long q = eq(2, k); n   if (n == 1) n     cout << 0 <<   n ; n   else if (n <= k) n     cout << 1 <<   n ; n   else if (q < n) n     cout << -1 <<   n ; n   else { n     long long en = k; n     long long st = 2; n     long long res = -1; n     while (st < en && st > 1) { n       long long mid = st + en >> 1; n       if (eq(mid, k) < n) { n         en = mid; n       } else { n         st = mid + 1; n         res = mid; n       } n     } n     res--; n     cout << k - res <<   n ; n   } n } n int main() { n   ios::sync_with_stdio(0), cin.tie(nullptr), cout.tie(nullptr); n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = (1 << 30); n const double Exp = 1e-8; n const int maxm = 1e5 + 7; n const int maxn = 1e5 + 7; n const int inf = 0x3f3f3f3f; n const long long INF = 0x3f3f3f3f3f3f3f3f; n const double pi = 3.1415926535898; n string s; n int q, n, sum1, sum2, sum3; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   cin >> q; n   while (q--) { n     cin >> n; n     sum1 = sum2 = sum3 = 0; n     for (int i = 1; i <= n; ++i) { n       cin >> s; n       if (s.size() % 2) sum3++; n       for (int j = 0; j < s.size(); ++j) { n         if (s[j] ==  1 ) n           sum1++; n         else n           sum2++; n       } n     } n     if (sum1 % 2 && sum2 % 2 && !sum3) n       cout << n - 1 << endl; n     else n       cout << n << endl; n   } n   return 0; n } n


#include<bits/stdc++.h> n using  namespace std; n  n #define  ll                  long long n #define  inf                  1e18    n #define  memset(a , b)       memset((a) , (b) , sizeof(a)) n #define  mod                 1000000007 n #define  rep(i , n)          for((i) = 0 ; (i) < n ; (i)++) n #define  N                   200005        n  n   ll t , d , ct  , q, ans , l ,m , r , n , mx , mn , i, j , k , x , y , z , s  ; n  n   char ch ;           string ss =    ,  str =    ; n  n   ll a[N] ,  b[N] ;      n  n  n  void dbg(ll x, ll y = 0, ll z = 0, ll a = 0) n   { cout <<  Dbg:   << x <<     << y <<     << z <<     << a <<   n ;   }  n  n  n  /*---------------------------------------Main Code----------------------------------------------------- */       n  n  n  n int main(){                     n  n        ios_base::sync_with_stdio (false),  n         cin.tie(nullptr);        n  n  n   n       cin >> x >> y >> k; n   n       if (y == 1) n       { n           if (k) n           { n               cout <<  No n ; n               return 0; n           } n           cout <<  Yes n ; n   n           cout <<  1 ; n           rep(i, x) n                   cout n               <<  0 ; n           cout <<   n ; n   n           cout <<  1 ; n           rep(i, x) n                   cout n               <<  0 ; n           return 0; n       } n   n   n       if (!x) n       { n           if (k) n           { n               cout <<  No n ; n               return 0; n           } n   n           cout <<  Yes n ; n           rep(i, y) n                   cout n               <<  1 ; n           cout <<   n ; n           rep(i, y) n                   cout n               <<  1 ; n           return 0; n       } n  n       if (k > x + y - 2) n       { n           cout <<  No ; n           return 0; n       } n  n       cout <<  Yes n ; n  n       rep(i, y) n               cout n           <<  1 ; n       rep(i, x) n               cout n           <<  0 ; n  n       cout <<   n ; n  n       if (k <= x) n       { n           rep(i, y - 1) n                   cout n               <<  1 ; n           rep(i, k) n                   cout n               <<  0 , n               x--; n  n           cout <<  1 ; n  n           rep(i, x) n                   cout n               <<  0 ; n  n           return 0; n       } n  n       k -= x; n  n       rep(i, y  - k -1) n               cout n           <<  1 ; n  n       cout <<  0 ; n  n       y -= (y -k-  1); n  n       rep(i, y - 1) n               cout n           <<  1 ; n  n       rep(i, x - 1) n               cout n           <<  0 ; n  n       cout <<  1 ; n  n       return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int D, m, x, y; n vector<vector<long double>> e; n const long double oo = 1e13; n vector<long double> mns(vector<long double> a, vector<long double> b) { n   vector<long double> ret; n   ret.resize(D); n   for (int i = 0; i < D; i++) ret[i] = a[i] - b[i]; n   return ret; n } n vector<long double> tms(vector<long double> a, long double c) { n   for (int i = 0; i < D; i++) a[i] *= c; n   return a; n } n vector<long double> perp(vector<long double> a, vector<long double> b) { n   long double norma = 0, normb = 0, dot = 0; n   for (int i = 0; i < D; i++) { n     norma += a[i] * a[i]; n     normb += b[i] * b[i]; n     dot += a[i] * b[i]; n   } n   if (normb < 1e-9) return a; n   long double tmp = dot / normb; n   vector<long double> bb = tms(b, tmp); n   return mns(a, bb); n } n struct subspace { n   vector<vector<long double>> vectors; n   vector<vector<long long>> canon; n   subspace(vector<vector<long double>> _vectors) { n     int d = _vectors.size(); n     vectors = _vectors; n     for (int i = 0; i < d; i++) n       for (int j = 0; j < i; j++) vectors[i] = perp(vectors[i], vectors[j]); n     for (int i = 0; i < D; i++) { n       vector<long double> x = e[i]; n       for (int j = 0; j < d; j++) x = perp(x, vectors[j]); n       vector<long long> y(D); n       for (int i = 0; i < D; i++) { n         y[i] = llround(x[i] * oo); n       } n       canon.push_back(y); n     } n   } n }; n map<vector<vector<long long>>, int> mp; n int cnt = 1; n int main() { n   std::ios::sync_with_stdio(false); n   cin >> m >> D; n   e.resize(D); n   for (int i = 0; i < D; i++) { n     e[i].resize(D); n     e[i][i] = 1; n   } n   for (int i = 1; i <= m; i++) { n     vector<vector<long double>> tmp; n     cin >> x; n     for (int j = 0; j < x; j++) { n       vector<long double> v; n       for (int k = 0; k < D; k++) { n         cin >> y; n         v.push_back(y); n       } n       tmp.push_back(v); n     } n     auto c = subspace(tmp).canon; n     if (mp.count(c)) n       cout << mp[c] <<    ; n     else n       cout << (mp[c] = cnt++) <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 233333; n int par[N][25], dep[N]; n int u, v, ans; n int n; n inline int lca(int u, int v) { n   if (dep[u] < dep[v]) { n     u ^= v; n     v ^= u; n     u ^= v; n   } n   for (int i = 0; i < 25; i++) n     if (((dep[u] - dep[v]) >> i) & 1) u = par[u][i]; n   if (u == v) return u; n   for (int i = 24; i >= 0; i--) n     if (par[u][i] != par[v][i]) { n       u = par[u][i]; n       v = par[v][i]; n     } n   return par[u][0]; n } n int main() { n   scanf( %d , &n); n   par[1][0] = 0; n   dep[1] = 0; n   u = v = 1; n   for (int i = 2; i <= n; i++) { n     int w; n     scanf( %d , &w); n     par[i][0] = w; n     dep[i] = dep[w] + 1; n     for (int j = 1; j < 24; j++) par[i][j] = par[par[i][j - 1]][j - 1]; n     w = i; n     int l = lca(u, w); n     int dst = dep[u] - dep[l] + dep[w] - dep[l]; n     int nu = u, nv = v; n     if (dst > ans) { n       ans = dst; n       nu = u; n       nv = w; n     } n     l = lca(v, w); n     dst = dep[v] - dep[l] + dep[w] - dep[l]; n     if (dst > ans) { n       ans = dst; n       nu = w; n       nv = v; n     } n     printf( %d%c , ans, i == n ?   n  :    ); n     u = nu; n     v = nv; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long llINF = 1e18; n const int MAXN = 1e5 + 5; n int n, Q; n int a[MAXN]; n namespace SegmentTree { n struct Node { n   int lmax, rmax, lmin, rmin, maxl, maxr, minl, minr, sum, maxsum, minsum, n       maxposl, minposl, maxposr, minposr; n   Node(int pos = 0, int v = 0) { n     maxl = maxr = minl = minr = maxposl = maxposr = minposl = minposr = pos; n     lmax = rmax = lmin = rmin = sum = maxsum = minsum = v; n   } n   friend Node operator+(const Node &lhs, const Node &rhs) { n     Node res; n     if (lhs.lmax > lhs.sum + rhs.lmax) n       res.lmax = lhs.lmax, res.maxl = lhs.maxl; n     else n       res.lmax = lhs.sum + rhs.lmax, res.maxl = rhs.maxl; n     if (rhs.rmax > rhs.sum + lhs.rmax) n       res.rmax = rhs.rmax, res.maxr = rhs.maxr; n     else n       res.rmax = rhs.sum + lhs.rmax, res.maxr = lhs.maxr; n     if (lhs.lmin < lhs.sum + rhs.lmin) n       res.lmin = lhs.lmin, res.minl = lhs.minl; n     else n       res.lmin = lhs.sum + rhs.lmin, res.minl = rhs.minl; n     if (rhs.rmin < rhs.sum + lhs.rmin) n       res.rmin = rhs.rmin, res.minr = rhs.minr; n     else n       res.rmin = rhs.sum + lhs.rmin, res.minr = lhs.minr; n     res.sum = lhs.sum + rhs.sum; n     res.maxsum = lhs.rmax + rhs.lmax; n     res.maxposl = lhs.maxr; n     res.maxposr = rhs.maxl; n     if (res.maxsum < lhs.maxsum) n       res.maxsum = lhs.maxsum, res.maxposl = lhs.maxposl, n       res.maxposr = lhs.maxposr; n     if (res.maxsum < rhs.maxsum) n       res.maxsum = rhs.maxsum, res.maxposl = rhs.maxposl, n       res.maxposr = rhs.maxposr; n     res.minsum = lhs.rmin + rhs.lmin; n     res.minposl = lhs.minr; n     res.minposr = rhs.minl; n     if (res.minsum > lhs.minsum) n       res.minsum = lhs.minsum, res.minposl = lhs.minposl, n       res.minposr = lhs.minposr; n     if (res.minsum > rhs.minsum) n       res.minsum = rhs.minsum, res.minposl = rhs.minposl, n       res.minposr = rhs.minposr; n     return res; n   } n   void rev() { n     sum = -sum; n     swap(lmax, lmin); n     swap(maxl, minl); n     lmax = -lmax; n     lmin = -lmin; n     swap(rmax, rmin); n     swap(maxr, minr); n     rmax = -rmax; n     rmin = -rmin; n     swap(maxsum, minsum); n     swap(maxposl, minposl); n     swap(maxposr, minposr); n     maxsum = -maxsum; n     minsum = -minsum; n   } n }; n struct Tree { n   int l, r; n   int tag; n   Node val; n } tree[MAXN << 2]; n void update(int k) { tree[k].val = tree[k << 1].val + tree[k << 1 | 1].val; } n void apply(int k) { n   tree[k].tag ^= 1; n   tree[k].val.rev(); n } n void down(int k) { n   if (tree[k].tag) { n     apply(k << 1); n     apply(k << 1 | 1); n     tree[k].tag = 0; n   } n } n void Build(int k, int l, int r) { n   tree[k].l = l; n   tree[k].r = r; n   if (l == r) { n     tree[k].val = Node(l, a[l]); n     return; n   } n   int mid = (l + r) >> 1; n   Build(k << 1, l, mid); n   Build(k << 1 | 1, mid + 1, r); n   update(k); n } n void Modify(int k, int x, int v) { n   if (tree[k].l == tree[k].r) { n     tree[k].val = Node(tree[k].l, v); n     return; n   } n   down(k); n   int mid = (tree[k].l + tree[k].r) >> 1; n   if (x <= mid) n     Modify(k << 1, x, v); n   else n     Modify(k << 1 | 1, x, v); n   update(k); n } n void Reverse(int k, int l, int r) { n   if (tree[k].l >= l && tree[k].r <= r) { n     apply(k); n     return; n   } n   down(k); n   int mid = (tree[k].l + tree[k].r) >> 1; n   if (l <= mid) Reverse(k << 1, l, r); n   if (r > mid) Reverse(k << 1 | 1, l, r); n   update(k); n } n Node Query(int k, int l, int r) { n   if (tree[k].l >= l && tree[k].r <= r) return tree[k].val; n   down(k); n   int mid = (tree[k].l + tree[k].r) >> 1; n   if (r <= mid) return Query(k << 1, l, r); n   if (l > mid) return Query(k << 1 | 1, l, r); n   return Query(k << 1, l, r) + Query(k << 1 | 1, l, r); n } n }  // namespace SegmentTree n using SegmentTree::Node; n vector<Node> vec; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   SegmentTree::Build(1, 1, n); n   scanf( %d , &Q); n   while (Q--) { n     int op, l, r, k, x, ans; n     scanf( %d , &op); n     if (op == 0) { n       scanf( %d%d , &x, &k); n       SegmentTree::Modify(1, x, k); n     } else { n       scanf( %d%d%d , &l, &r, &k); n       vec.clear(); n       ans = 0; n       for (int i = 1; i <= k; i++) { n         Node tmp = SegmentTree::Query(1, l, r); n         if (tmp.maxsum <= 0) break; n         SegmentTree::Reverse(1, tmp.maxposl, tmp.maxposr); n         vec.push_back(tmp); n         ans += tmp.maxsum; n       } n       for (auto x : vec) SegmentTree::Reverse(1, x.maxposl, x.maxposr); n       printf( %d n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n unsigned long long mulmod(unsigned long long a, unsigned long long b, n                           unsigned long long c) { n   unsigned long long x = 0, y = a % c; n   while (b > 0) { n     if (b % 2 == 1) { n       x = (x + y) % c; n     } n     y = (y * 2) % c; n     b /= 2; n   } n   return x % c; n } n unsigned long long pow(unsigned long long a, unsigned long long b, n                        unsigned long long c) { n   unsigned long long x = 1, y = a; n   while (b > 0) { n     if (b & 1) x = mulmod(x, y, c); n     y = mulmod(y, y, c); n     b >>= 1; n   } n   return x; n } n bool Miller(unsigned long long p, int iteration) { n   if (p < 2) { n     return false; n   } n   if (p != 2 && p % 2 == 0) { n     return false; n   } n   unsigned long long second = p - 1; n   while (second % 2 == 0) { n     second /= 2; n   } n   for (int i = 0; i < iteration; i++) { n     unsigned long long a = rand() % (p - 1) + 1, temp = second; n     unsigned long long mod = pow(a, temp, p); n     while (temp != p - 1 && mod != 1 && mod != p - 1) { n       mod = mulmod(mod, mod, p); n       temp *= 2; n     } n     if (mod != p - 1 && temp % 2 == 0) { n       return false; n     } n   } n   return true; n } n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   int pos = 0; n   string ans =   ; n   string text[2][10] = {{ zero ,  one ,  two ,  three ,  four ,  five ,  six , n                           seven ,  eight ,  nine }, n                         {  ,  ten- ,  twenty- ,  thirty- ,  forty- ,  fifty- , n                           sixty- ,  seventy- ,  eighty- ,  ninety- }}; n   string tens[9] = { ten ,    twenty ,   thirty ,  forty ,  fifty , n                      sixty ,  seventy ,  eighty ,  ninety }; n   if (n % 10 == 0 && n != 0) { n     cout << tens[(n / 10) - 1] <<   n ; n     return 0; n   } else if (n < 20) { n     if (n < 10) { n       cout << text[0][n] <<   n ; n     } else { n       switch (n) { n         case 11: n           cout <<  eleven n ; n           break; n         case 12: n           cout <<  twelve n ; n           break; n         case 13: n           cout <<  thirteen n ; n           break; n         case 14: n           cout <<  fourteen n ; n           break; n         case 15: n           cout <<  fifteen n ; n           break; n         case 16: n           cout <<  sixteen n ; n           break; n         case 17: n           cout <<  seventeen n ; n           break; n         case 18: n           cout <<  eighteen n ; n           break; n         case 19: n           cout <<  nineteen n ; n       } n     } n     return 0; n   } n   while (n) { n     int d = n % 10; n     ans.insert(0, text[pos][d]); n     pos++; n     n /= 10; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   long long s[n][n]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       cin >> s[i][j]; n     } n   } n   long long ans = sqrt((long long)((s[0][1] * s[0][2]) / s[1][2])); n   cout << ans; n   for (int i = 1; i < n; i++) { n     cout <<     << s[0][i] / ans; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string str(string s) { n   if (s.size() % 2) return s; n   string a = str(s.substr(0, s.size() / 2)); n   string b = str(s.substr(s.size() / 2, s.size() / 2)); n   if (a < b) n     return a + b; n   else n     return b + a; n } n int main() { n   ios_base::sync_with_stdio(0); n   string s1, s2; n   cin >> s1 >> s2; n   if (str(s1) == str(s2)) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n long long mod = 1000000007; n using namespace std; n int n; n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= mod; n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n int a[100005]; n int main() { n   int i, j, fl, test, pos = 0, mx = 0; n   scanf( %d , &n); n   long long ans = 0; n   for (i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     if (a[i] > mx) { n       mx = a[i]; n       pos = i; n     } n   } n   for (i = pos; i < n; i++) { n     ans = ans + (mx - a[i]); n   } n   int sofar[100005]; n   sofar[0] = 0; n   for (i = 1; i < pos; i++) { n     sofar[i] = max(sofar[i - 1], a[i]); n   } n   for (i = pos - 1; i >= 0; i--) { n     mx--; n     mx = max(mx, a[i]); n     ans = ans + max((mx - a[i]), (sofar[i] - a[i])); n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename _T> n inline void _DBG(const char *s, _T x) { n   cerr << s <<   =   << x <<   n ; n } n template <typename _T, typename... args> n void _DBG(const char *s, _T x, args... a) { n   while (*s !=  , ) cerr << *s++; n   cerr <<   =   << x <<  , ; n   _DBG(s + 1, a...); n } n const int N = 307; n int n, m, p[] = {1, 0, 0, 1, -1, 0, 0, -1}; n char s[N][N]; n long long P, q; n long long val[N][N]; n queue<pair<pair<int, int>, long long> > Q; n bool vis[N][N]; n vector<pair<int, int> > kto; n void bfs(int x, int y, long long v) { n   Q.push({{x, y}, v}); n   for (auto xx : kto) vis[xx.first][xx.second] = 0; n   kto.clear(); n   vis[x][y] = 1; n   while (!Q.empty()) { n     int xx = Q.front().first.first, yy = Q.front().first.second; n     long long vv = Q.front().second; n     val[xx][yy] += vv; n     Q.pop(); n     kto.push_back({xx, yy}); n     vv /= 2; n     if (vv == 0) continue; n     for (int i = 0; i < 8; i += 2) { n       int ux = xx + p[i], uy = yy + p[i + 1]; n       if (s[ux][uy] ==  * ) continue; n       if (1 > ux || ux > n || 1 > uy || uy > m) continue; n       if (!vis[ux][uy]) { n         vis[ux][uy] = 1; n         Q.push({{ux, uy}, vv}); n       } n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m >> q >> P; n   for (int i = 1; i <= n; i++) cin >> (s[i] + 1); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if ( A  <= s[i][j] && s[i][j] <=  Z ) { n         long long vv = (long long)(s[i][j] -  A  + 1) * q; n         bfs(i, j, vv); n       } n     } n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       if (val[i][j] > P) ans++; n     } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int parent[200005], par[200005], root; n int find(int i) { n   if (parent[i] != i) parent[i] = find(parent[i]); n   return parent[i]; n } n void merge(int x, int y) { n   int xroot = find(x); n   int yroot = find(y); n   if (xroot == yroot) { n     if (!root) root = xroot; n     par[x] = root; n   } else n     parent[xroot] = yroot; n } n int main() { n   int n, temp[200005], dsu[200005], k = 0, cnt = 0; n   cin >> n; n   for (int i = 1; i <= n; i++) parent[i] = i; n   for (int i = 1; i <= n; i++) { n     cin >> par[i]; n     temp[i] = par[i]; n     if (par[i] == i) root = i; n   } n   for (int i = 1; i <= n; i++) { n     if (par[i] == i) { n       if (i == root) { n       } else n         par[i] = root; n     } else n       merge(i, par[i]); n   } n   for (int i = 1; i <= n; i++) n     if (temp[i] != par[i]) cnt++; n   cout << cnt <<   n ; n   for (int i = 1; i <= n; i++) cout << par[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void pr(vector<T> &v) { n   for (int i = 0; i < (int)(v).size(); i++) cout << v[i] <<    ; n   cout <<   n ; n   ; n } n template <typename T> n void pr(vector<vector<T>> &v) { n   for (int i = 0; i < (int)(v).size(); i++) { n     pr(v[i]); n   } n } n template <typename T> n void re(T &x) { n   cin >> x; n } n template <typename T> n void re(vector<T> &a) { n   for (int i = 0; i < (int)(a).size(); i++) re(a[i]); n } n template <class Arg, class... Args> n void re(Arg &first, Args &...rest) { n   re(first); n   re(rest...); n } n template <typename T> n void pr(T x) { n   cout << x <<   n ; n   ; n } n template <class Arg, class... Args> n void pr(const Arg &first, const Args &...rest) { n   cout << first <<    ; n   pr(rest...); n   cout <<   n ; n   ; n } n void ps() { n   cout <<   n ; n   ; n } n template <class T, class... Ts> n void ps(const T &t, const Ts &...ts) { n   cout << t; n   if (sizeof...(ts)) cout <<    ; n   ps(ts...); n } n const long long MOD = 998244353; n long double PI = 4 * atan(1); n long double eps = 1e-12; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long n, A, cf, cm, m; n   cin >> n >> A >> cf >> cm >> m; n   vector<pair<long long, int>> a(n + 1); n   for (int i = 1; i < n + 1; i++) { n     cin >> a[i].first; n     a[i].second = i; n   } n   vector<long long> pre(n + 1); n   vector<long long> pre2(n + 1); n   sort(a.begin(), a.end()); n   vector<long long> ac(n); n   long long minv = MOD; n   for (int i = 0; i < n; i++) { n     ac[i] = a[i + 1].first; n     minv = min(minv, ac[i]); n   } n   pre[0] = 0; n   pre2[0] = 0; n   for (int i = 1; i < n + 1; i++) { n     pre[i] = a[n - i + 1].first + pre[i - 1]; n     pre2[i] = a[i].first + pre2[i - 1]; n   } n   long long ans = cm * minv; n   long long ind = 0; n   long long besti = 0; n   long long bestm = 0; n   for (int i = 0; i < n + 1; i++) { n     long long cost = (i)*A - pre[i]; n     if (cost > m) { n       break; n     } n     long long lo = 0; n     long long hi = A; n     while (lo != hi) { n       long long mid = (lo + hi + 1) / 2; n       vector<long long>::iterator high = n           upper_bound(ac.begin(), ac.begin() + n - i, mid); n       long long ntm = high - ac.begin(); n       long long cost2 = cost + (mid * ntm - pre2[ntm]); n       if (cost2 <= m) { n         if (i * cf + cm * mid > ans) { n           ans = i * cf + cm * mid; n           besti = i; n           bestm = mid; n         } n         lo = mid; n       } else { n         hi = mid - 1; n       } n     } n   } n   for (int i = 0; i < besti; i++) { n     a[n - i].first = A; n   } n   for (int i = 1; i < n + 1; i++) { n     if (a[i].first < bestm) a[i].first = bestm; n   } n   vector<long long> out(n + 1); n   for (int i = 1; i < n + 1; i++) { n     out[a[i].second] = a[i].first; n   } n   cout << ans <<   n ; n   ; n   for (int i = 1; i < n + 1; i++) { n     cout << out[i] <<    ; n   } n   cout <<   n ; n   ; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int maxn = 105; n const int N = 200; n int f[maxn][maxn][maxn]; n int g[maxn][maxn][maxn]; n bool usedf[maxn][maxn]; n bool usedg[maxn][maxn]; n int n, m, K, ans, c[N + 5][N + 5]; n int main() { n   scanf( %d %d %d , &n, &m, &K); n   if (K == 0) { n     puts( 0 ); n     return 0; n   } n   for (int i = 0; i <= N; i++) { n     c[i][0] = c[i][i] = 1; n     for (int j = 1; j < i; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod; n   } n   for (int i = 1; i <= m; i++) { n     for (int j = 1; j <= n; j++) n       for (int k = 1; k <= K; k++) n         if (usedg[j][k]) memset(g[j][k], 0, sizeof(g[j][k])); n     memset(usedg, 0, sizeof usedg); n     for (int t = 1; t <= n; t++) usedg[t][1] = true, g[t][1][t] = 1; n     for (int j = 1; j <= n; j++) n       for (int k = 1; k <= K; k++) n         if (usedf[j][k]) { n           for (int l = 1; l <= n; l++) n             if (int val = f[j][k][l]) { n               int tmp; n               for (int t = l; t <= n - j; t++) n                 if (c[t - 1][l - 1] <= K && (tmp = k * c[t - 1][l - 1]) <= K) n                   (g[j + t][tmp][t - l] += val) %= mod, n                       usedg[j + t][tmp] = true; n             } n         } n     swap(f, g); n     swap(usedf, usedg); n     for (int j = 1; j <= n; j++) n       for (int k = 1; k <= K; k++) (ans += f[j][k][0]) %= mod; n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod(long long x) { n   return ((x % 1000000007 + 1000000007) % 1000000007); n } n long long add(long long a, long long b) { return mod(mod(a) + mod(b)); } n long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); } n template <class T> n void print(T a) { n   cerr << a; n } n template <class T, class V> n void print(pair<T, V> p); n template <class T> n void print(vector<T> v); n template <class T> n void print(set<T> v); n template <class T, class V> n void print(map<T, V> v); n template <class T> n void print(multiset<T> v); n template <class T, class V> n void print(pair<T, V> p) { n   cerr <<  { ; n   print(p.first); n   cerr <<  , ; n   print(p.second); n   cerr <<  } ; n } n template <class T> n void print(vector<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     print(i); n     cerr <<  , ; n   } n   cerr <<  ] ; n } n template <class T> n void print(set<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     print(i); n     cerr <<  , ; n   } n   cerr <<  ] ; n } n template <class T> n void print(multiset<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     print(i); n     cerr <<  , ; n   } n   cerr <<  ] ; n } n template <class T, class V> n void print(map<T, V> v) { n   cerr <<  [  ; n   for (auto i : v) { n     print(i); n     cerr <<  , ; n   } n   cerr <<  ] ; n } n long long modPow(long long a, long long b) { n   if (b == 0) return 1LL; n   if (b == 1) return a % 1000000007; n   long long res = 1; n   while (b) { n     if (b % 2 == 1) res = mul(res, a); n     a = mul(a, a); n     b = b / 2; n   } n   return res; n } n const long long N = 2e5 + 2; n long long fact[N]; n void precalc() { n   fact[0] = 1; n   for (long long i = 1; i < N; i++) { n     fact[i] = mul(fact[i - 1], i); n   } n } n long long inv(long long x) { return modPow(x, 1000000007 - 2); } n long long divide(long long a, long long b) { return mul(a, inv(b)); } n long long nCr(long long n, long long r) { n   return divide(fact[n], mul(fact[r], fact[n - r])); n } n void solve() { n   long long n; n   cin >> n; n   string s; n   cin >> s; n   for (long long i = 0; i < n; i++) { n     if (s[i] ==  0 ) { n       if ((i + 1) <= n / 2) { n         cout << i + 1 <<     << n <<     << i + 2 <<     << n << endl; n         return; n       } else { n         cout << 1 <<     << i + 1 <<     << 1 <<     << i << endl; n         return; n       } n     } n   } n   cout << 1 <<     << n - 1 <<     << 2 <<     << n << endl; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int mod = 1000000007; n const long long int inf = 9e18; n void __print(long long int x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char *x) { cerr <<     << x <<    ; } n void __print(const string &x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V> &x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename T> n void __print(const T &x) { n   long long int f = 0; n   cerr <<  { ; n   for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n void tc() { n   long long int n; n   cin >> n; n   string a, b; n   cin >> a >> b; n   for (long long int i = 0; i < n; i++) { n     if (a[i] > b[i]) { n       cout << -1 << endl; n       return; n     } n   } n   long long int ans = 0; n   for (char ch =  a ; ch <=  z ; ch++) { n     set<long long int> idx; n     char mini =  z ; n     for (long long int i = 0; i < n; i++) { n       if (a[i] == ch && a[i] != b[i]) { n         idx.insert(i); n         mini = min(mini, b[i]); n       } n     } n     bool done = false; n     for (auto it = idx.begin(); it != idx.end(); it++) { n       a[(*it)] = mini; n       done = true; n     } n     if (done) { n       ans++; n     } n   }; n   cout << ans << endl; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t = 1; n   cin >> t; n   while (t--) { n     tc(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int N; n char S[100005]; n int main() { n   scanf( %d , &N); n   scanf( %s , S); n   string ANS =   ; n   int a = (N - 11) / 2, b = a; n   for (int i = 0; i < N; i++) { n     if (S[i] ==  8 ) { n       if (a) n         --a; n       else n         ANS += S[i]; n     } else { n       if (b) n         --b; n       else n         ANS += S[i]; n     } n   } n   if (ANS[0] ==  8 ) n     printf( YES n ); n   else n     printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n istream &operator>>(istream &in, vector<T> &arr) { n   for (T &i : arr) { n     in >> i; n   } n   return in; n } n template <class T> n ostream &operator<<(ostream &in, vector<T> &arr) { n   for (T &i : arr) { n     in << i <<    ; n   } n   return in; n } n long long debb = 1; n long long next(vector<long long> &t) { n   long long c = (t[1] / t[2] + 1) * (t[1] / t[2] + 1) * (t[1] % t[2]); n   long long u = (t[1] / t[2]) * (t[1] / t[2]) * (t[2] - (t[1] % t[2])); n   long long su = c + u; n   t[2] += 1; n   c = (t[1] / t[2] + 1) * (t[1] / t[2] + 1) * (t[1] % t[2]); n   u = (t[1] / t[2]) * (t[1] / t[2]) * (t[2] - (t[1] % t[2])); n   long long su1 = c + u; n   t[2] -= 1; n   return su - su1; n } n signed main() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(false); n   long long n, k; n   cin >> n >> k; n   long long co = k - n; n   multiset<vector<long long>, greater<vector<long long>>> u; n   for (int i = 0; i < n; ++i) { n     long long x; n     cin >> x; n     vector<long long> k = {x, x, 1}; n     long long ra = next(k); n     u.insert({ra, x, x, 1}); n   } n   for (int i = 0; i < co; ++i) { n     vector<long long> r = *(u.begin()); n     u.erase(u.begin()); n     vector<long long> o = {r[1], r[2], r[3]}; n     o[2] += 1; n     o[0] = o[1] / o[2] + min(o[1] % o[2], 1ll); n     long long ra = next(o); n     u.insert({ra, o[0], o[1], o[2]}); n   } n   long long ans = 0; n   for (auto r : u) { n     vector<long long> t = {r[1], r[2], r[3]}; n     for (int i = 0; i < t[2]; ++i) { n       long long c = t[1] / t[2] + max(min(t[1] % t[2] - i, 1ll), 0ll); n       ans += c * c; n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, ans, up, top; n unsigned long long k; n unsigned long long st[201], ed[201], sum[201], num[201]; n int s[300010]; n inline void init() { n   unsigned long long mi = 1; n   st[0] = 0; n   ed[0] = 0; n   for (int i = 1; i <= 64; i++) { n     st[i] = ed[i - 1] + i; n     num[i] = ((mi * 10 - 1) - mi + 1); n     ed[i] = st[i] + i * (num[i] - 1); n     sum[i] = sum[i - 1] + (st[i] + ed[i]) * num[i] / 2; n     up = i; n     if (sum[i] >= 1e18) break; n     mi *= 10; n   } n } n inline void prework() { scanf( %lld , &k); } n inline int findans(unsigned long long x, int pos) { n   top = 0; n   while (x > 0) { n     s[++top] = x % 10; n     x /= 10; n   } n   return s[top - pos + 1]; n } n inline void mainwork() { n   unsigned long long mi = 1, id; n   for (int i = 1; i <= up; i++) { n     if (sum[i] >= k) { n       id = i; n       break; n     } n     mi *= 10; n   } n   k -= sum[id - 1]; n   unsigned long long l = 0, r = num[id] - 1, mid; n   unsigned long long t, d; n   while (l + 1 < r) { n     mid = (l + r) >> 1; n     t = (st[id] + id * (mid - 1) + st[id]) * mid / 2; n     if (t < k) n       l = mid; n     else n       r = mid; n   } n   if ((st[id] + id * (r - 1) + st[id]) * r / 2 < k) n     d = r; n   else n     d = r - 1; n   k -= (st[id] + id * (d - 1) + st[id]) * d / 2; n   unsigned long long len = st[id] + d, sum = 0; n   for (int i = 1; i <= up; i++) { n     if (k <= num[i] * i) { n       id = i; n       break; n     } n     k -= num[i] * i; n     sum += num[i]; n   } n   unsigned long long val = k / id; n   if (k % id == 0) n     ans = findans(val + sum, id); n   else n     ans = findans(val + sum + 1, k % id); n } n inline void print() { printf( %d n , ans); } n int main() { n   init(); n   int t = 1; n   scanf( %d , &t); n   for (int i = 1; i <= t; i++) { n     prework(); n     mainwork(); n     print(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[10][10]; n int main() { n   int bl = 0, wh = 0; n   for (int i = 0; i < 8; i++) scanf( %s , s[i]); n   for (int i = 0; i < 8; i++) n     for (int j = 0; j < 8; j++) { n       if (s[i][j] ==  Q ) n         wh += 9; n       else if (s[i][j] ==  R ) n         wh += 5; n       else if (s[i][j] ==  B ) n         wh += 3; n       else if (s[i][j] ==  N ) n         wh += 3; n       else if (s[i][j] ==  P ) n         wh += 1; n       else if (s[i][j] ==  q ) n         bl += 9; n       else if (s[i][j] ==  r ) n         bl += 5; n       else if (s[i][j] ==  b ) n         bl += 3; n       else if (s[i][j] ==  n ) n         bl += 3; n       else if (s[i][j] ==  p ) n         bl += 1; n     } n   if (bl > wh) n     printf( Black n ); n   else if (bl == wh) n     printf( Draw n ); n   else n     printf( White n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5, maxm = 1e4 + 5, maxe = maxn * 4 + maxm, n           maxp = 4 * maxe; n int n, m, b[maxe], id[maxe], tot, cnt, d; n double p[maxp], ans; n int read() { n   int ret = 0, f = 1; n   char ch = getchar(); n   while (ch >  9  || ch <  0 ) { n     if (ch ==  - ) f = -f; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) ret = ret * 10 + ch -  0 , ch = getchar(); n   return ret * f; n } n struct tree { n   int x, h, l, r; n } a[maxn]; n struct mogu { n   int x, v; n } c[maxn]; n int find(int x) { n   int L = 1, R = cnt, mid; n   while (L <= R) { n     mid = L + R >> 1; n     if (id[mid] == x) return mid; n     id[mid] < x ? L = mid + 1 : R = mid - 1; n   } n } n void build(int l, int r, int k) { n   p[k] = 1, d++; n   if (l == r) return; n   int mid = l + r >> 1; n   build(l, mid, k << 1), build(mid + 1, r, k << 1 | 1); n } n void change(int L, int R, int k, int l, int r, double x) { n   if (L > r || R < l) return; n   if (l <= L && R <= r) { n     p[k] *= x / 100.0; n     return; n   } n   if (L == R) return; n   int mid = L + R >> 1; n   change(L, mid, k << 1, l, r, x), change(mid + 1, R, k << 1 | 1, l, r, x); n } n double ask(int l, int r, int k, int x) { n   if (l == r) return p[k]; n   int mid = l + r >> 1; n   if (mid >= x) n     return ask(l, mid, k << 1, x) * p[k]; n   else n     return ask(mid + 1, r, k << 1 | 1, x) * p[k]; n } n int main() { n   n = read(), m = read(); n   for (int i = 1; i <= n; i++) { n     a[i].x = read(), a[i].h = read(), a[i].l = read(), a[i].r = read(); n     b[++tot] = a[i].x - a[i].h, b[++tot] = a[i].x - 1, b[++tot] = a[i].x + 1, n     b[++tot] = a[i].x + a[i].h; n   } n   for (int i = 1; i <= m; i++) { n     c[i].x = read(), c[i].v = read(); n     b[++tot] = c[i].x; n   } n   sort(b + 1, b + 1 + tot); n   for (int i = 1; i <= tot; i++) n     if (b[i] != b[i + 1]) id[++cnt] = b[i]; n   build(1, cnt, 1); n   for (int i = 1; i <= n; i++) { n     int L = find(a[i].x - a[i].h), midl = find(a[i].x - 1), n         midr = find(a[i].x + 1), R = find(a[i].x + a[i].h); n     change(1, cnt, 1, L, midl, (double)100.0 - a[i].l), n         change(1, cnt, 1, midr, R, (double)100.0 - a[i].r); n   } n   for (int i = 1; i <= m; i++) { n     int x = find(c[i].x); n     ans += (double)ask(1, cnt, 1, x) * c[i].v; n   } n   printf( %.10lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n constexpr static int MAXD = 20000; n using namespace std; n bool check() { n   int n; n   cin >> n; n   int dist = 0; n   bool r = true; n   for (int i = 0; i < n; i++) { n     int t; n     string dir; n     cin >> t >> dir; n     if (dist == 0 && dir !=  South ) r = false; n     if (dist == MAXD && dir !=  North ) r = false; n     if (dir ==  North ) { n       dist -= t; n       if (dist < 0) r = false; n     } n     if (dir ==  South ) { n       dist += t; n       if (dist > MAXD) r = false; n     } n   } n   if (dist != 0) r = false; n   return r; n } n int main() { n   if (check()) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int cmpint(const void *a, const void *b) { n   if (((int *)a)[0] == ((int *)b)[0]) return ((int *)a)[1] - ((int *)b)[1]; n   return ((int *)a)[0] - ((int *)b)[0]; n } n char s[100005]; n int a[4] = {0}; n int abs(int a) { n   if (a > 0) return a; n   return -a; n } n int main() { n   int i, j, n, m, k, l, o, p; n   n = m = k = 0; n   gets(s); n   l = strlen(s); n   for (i = (0); i < (l); i++) n     if (s[i] ==  0 ) n       m++; n     else if (s[i] ==  1 ) n       n++; n     else n       k++; n   if (m + k - n >= 1) a[0] = 1; n   if (n + k - m >= 2) a[3] = 1; n   if (l % 2 == 0) { n     if (abs(n - m) <= k) { n       if (abs(n - m) == k && s[l - 1] ==  ? ) { n         if (n < m) n           s[l - 1] =  1 ; n         else n           s[l - 1] =  0 ; n       } n       if (s[l - 1] ==  0 ) n         a[2] = 1; n       else if (s[l - 1] ==  1 ) n         a[1] = 1; n       else { n         a[1] = a[2] = 1; n       } n     } n   } else { n     if (n == 0) n       k--; n     else n       n -= 1; n     if (abs(n - m) <= k) { n       if (abs(n - m) == k && s[l - 1] ==  ? ) { n         if (n < m) n           s[l - 1] =  1 ; n         else n           s[l - 1] =  0 ; n       } n       if (s[l - 1] ==  0 ) n         a[2] = 1; n       else if (s[l - 1] ==  1 ) n         a[1] = 1; n       else { n         a[1] = a[2] = 1; n       } n     } n   } n   for (i = (0); i < (4); i++) n     if (a[i] == 1) { n       printf( %d%d n , i / 2, i % 2); n     } n   return 0; n } n


/* n  #include <ext/pb_ds/assoc_container.hpp> n  #include <ext/pb_ds/priority_queue.hpp> n  n  using namespace __gnu_pbds; n  n  n __gnu_pbds::priority_queue<int, less<int>> pq; n gp_hash_table<int, int> mp; n */ n  n /** Begin fast allocation */ n /* n const int mx_MEM = 10 * 1e7; n int mpos = 0; n char mem[mx_MEM]; n  n inline void *operator new(size_t n) { n     assert((mpos += n) <= mx_MEM); n     return (void *) (mem + mpos - n); n } n  n inline void operator delete(void *) noexcept {} // must have! n */ n /** End fast allocation */ n  n /** Pragmas */ n // mt19937 gen(2281337); n  n //#pragma GCC optimize( O3 ,  Ofast ,  unroll-loops ,  unswitch-loops ,  fast-math ,  no-stack-protector ) n  n //#pragma GCC target( sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,avx ) n // sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx, n //#pragma comment(linker,  /STACK:66777216 ) n  n /* n  * @author kamil.sharipov n  */ n  n #include <bits/stdc++.h> n  n //#define int long long n #define all(x) (x).begin(), (x).end() n #define fo(i, a, b) for (int i = a; i < b; ++i) n #define ll long long n #define pii pair<int, int> n  n using namespace std; n  n int n, m, inf = 2e9, dst = 51; n  n vector<vector<pii > > adj; n  n vector<vector<vector<int> > > we; n  n int dist[100001][51]; n  n signed main() { n #ifdef _LOCAL n     freopen( input.txt ,  r , stdin); n     freopen( output.txt ,  w , stdout); n #endif n  n     cin >> n >> m; n  n     adj.resize(n), we.resize(n); n     for (int i = 0; i < n; ++i) { n         we[i].resize(dst); n     } n  n     for (int i = 0; i < m; ++i) { n         int u, v, w; n         cin >> u >> v >> w; n         --u, --v; n         adj[u].push_back({v, w}); n         adj[v].push_back({u, w}); n     } n  n     for (int i = 0; i < n; ++i) { n         for (int j = 0; j < dst; ++j) { n             dist[i][j] = inf; n         } n     } n  n     dist[0][0] = 0; n  n     set<pair<int, pii > > st; n     st.insert({0, {0, 0}}); n  n     while (!st.empty()) { n         auto[w, p] = *st.begin(); n         st.erase(st.begin()); n         int v = p.first; n         int d = p.second; n  n         if (w > dist[v][d]) continue; n  n         if (d == 0) { n             for (int i = 0; i < adj[v].size(); ++i) { n                 int to = adj[v][i].first; n                 int wei = adj[v][i].second; n  n                 if (dist[to][wei] > w) { n                     dist[to][wei] = w; n                     st.insert({dist[to][wei], {to, wei}}); n                 } n             } n         } else { n             for (int i = 0; i < adj[v].size(); ++i) { n                 int to = adj[v][i].first; n                 int wei = adj[v][i].second; n  n                 int len = (d + wei) * (d + wei) + w; n  n                 if (dist[to][0] > len) { n                     dist[to][0] = len; n                     st.insert({dist[to][0], {to, 0}}); n                 } n             } n         } n     } n  n     for (int i = 0; i < n; ++i) { n         if (dist[i][0] == inf) cout <<  -1  ; n         else cout << dist[i][0] <<    ; n     } n } n  n  n  n  n


#include <bits/stdc++.h> n using namespace std; n int L, R; n int main() { n   int n, m, i, j, u, v; n   cin >> n >> m; n   int ans = 100001; n   for (i = 0; i < m; i++) { n     scanf( %d%d , &L, &R); n     ans = min(ans, R - L + 1); n   } n   cout << ans << endl; n   for (i = 1; i <= n; i++) cout << i % ans <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 100005, INF = 2000000000000000000; n vector<long long> g[N]; n long long power(long long a, long long b, long long p) { n   if (a == 0) return 0; n   long long res = 1; n   a %= p; n   while (b > 0) { n     if (b & 1) res = (res * a) % p; n     b >>= 1; n     a = (a * a) % p; n   } n   return res; n } n vector<long long> prime; n bool isprime[N]; n void pre() { n   for (long long i = 2; i < N; i++) { n     if (isprime[i]) { n       for (long long j = i * i; j < N; j += i) isprime[j] = false; n       prime.push_back(i); n     } n   } n   return; n } n bool isPowerOfTwo(long long n) { n   if (n == 0) return false; n   return (ceil(log2(n)) == floor(log2(n))); n } n long long gcd(long long a, long long b) { n   if (a < b) n     return gcd(b, a); n   else if (a % b == 0) n     return b; n   else n     return gcd(b, a % b); n } n bool isPrime(long long n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (long long i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n long long spf[N + 1]; n void spfFun() { n   for (long long i = 0; i <= N; i++) spf[i] = i; n   for (long long i = 2; i * i <= N; i++) { n     if (spf[i] == i) { n       for (long long j = i * i; j <= N; j += i) { n         spf[j] = min(spf[j], i); n       } n     } n   } n } n bool isPerfectSquare(long double x) { n   long double sr = sqrt(x); n   return ((sr - floor(sr)) == 0); n } n void print(bool n) { n   if (n) { n     cout <<  YES ; n   } else { n     cout <<  NO ; n   } n } n int32_t main() { n   std::ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long n; n   cin >> n; n   long long l[n], r[n]; n   for (long long i = 0; i < n; i++) { n     cin >> l[i] >> r[i]; n   } n   long long k; n   cin >> k; n   k--; n   long long ans = n; n   for (long long i = 0; i < n; i++) { n     if (r[i] > k) { n       ans = i; n       break; n     } n   } n   cout << n - ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int num; n   bool flag = true; n   int* numbers = new int[n]; n   for (int i = 0; i < n; i++) { n     cin >> num; n     numbers[i] = num; n     if (i == n - 1) break; n   } n   for (int i = 0; i < n - 1; i++) n     for (int j = i + 1; j < n; j++) { n       if (numbers[i] > numbers[j]) swap(numbers[i], numbers[j]); n     } n   int s; n   if (n == 1) n     flag = false; n   else { n     for (int i = 0; i < n; i++) { n       if (numbers[i] > numbers[0]) { n         flag = true; n         s = numbers[i]; n         break; n       } n       flag = false; n     } n   } n   if (flag) n     cout << s << endl; n   else n     cout <<  NO ; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n template <typename T1, typename T2> n inline T1 max(T1 a, T2 b) { n   return b < a ? a : b; n } n template <typename T1, typename T2> n inline T1 min(T1 a, T2 b) { n   return a < b ? a : b; n } n namespace ae86 { n const int bufl = 1 << 15; n char buf[bufl], *s = buf, *t = buf; n inline int fetch() { n   if (s == t) { n     t = (s = buf) + fread(buf, 1, bufl, stdin); n     if (s == t) return EOF; n   } n   return *s++; n } n inline int ty() { n   int a = 0, b = 1, c = fetch(); n   while (!isdigit(c)) b ^= c ==  - , c = fetch(); n   while (isdigit(c)) a = a * 10 + c - 48, c = fetch(); n   return b ? a : -a; n } n }  // namespace ae86 n using ae86::ty; n const int _ = 300007; n int n, val[_] = {0}, cho[_] = {0}; n long long f[_]; n vector<int> ans; n inline void gay(int x) { n   if (val[x] <= 0 || val[x + 1] <= 0) return; n   int dlt = min(val[x], val[x + 1]); n   ans.push_back(x), val[x] -= dlt, val[x + 1] -= dlt; n } n int main() { n   n = ty(); n   for (int i = 1; i <= n; i++) val[i] = ty(); n   for (int i = 1; i <= n; i++) { n     long long a = f[max(i - 2, 0)] + val[i], n               b = f[max(i - 3, 0)] + max(val[i - 1], val[i]); n     f[i] = min(a, b); n     if (f[i] == b) cho[i] = 1; n   } n   for (int i = (min(f[n], f[n - 1]) == f[n]) ? (n) : (n - 1); i >= 1; n        i -= 2 + cho[i]) { n     gay(i - 1); n     if (cho[i]) gay(i - 2); n     gay(i); n   } n   printf( %lu n , ans.size()); n   for (auto i : ans) printf( %d n , i); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const ll N = 105, inf = 4e18 + 4, mod = 1e9 + 7; n ll n, a2[N], num[N], ans, sum, dp[N][N * N], tmp[N][N * N], fac[N], inv[N]; n bool mark[N]; n ll pw(ll a, ll b) { n   if (b == 0) return 1; n   a %= mod; n   if (b % 2 == 1) return a * pw(a, (b - 1)) % mod; n   return pw((a * a % mod), (b / 2)) % mod; n } n ll choose(ll a, ll b) { n   if (b > a) return 0; n   if (b == 0 || b == a) return 1; n   return fac[a] % mod * inv[b] % mod * inv[a - b] % mod; n } n int main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   tmp[0][0] = 1; n   fac[0] = 1; n   for (ll i = 1; i < N - 1; i++) fac[i] = (fac[i - 1] * i) % mod; n   inv[N - 2] = pw(fac[N - 2], mod - 2) % mod; n   for (ll i = N - 3; i >= 0; i--) { n     ll x = i + 1; n     inv[i] = (inv[x] * (x)) % mod; n   } n   cin >> n; n   ll y = 0; n   for (ll i = 0; i < n; i++) { n     cin >> a2[i]; n     if (!mark[a2[i]]) { n       mark[a2[i]] = 1; n       y++; n     } n     num[a2[i]]++; n     sum += a2[i]; n     for (ll j = 0; j < n; j++) { n       for (ll k = a2[i]; k <= sum; k++) { n         dp[j + 1][k] = tmp[j][k - a2[i]]; n       } n     } n     for (ll j = 0; j <= n; j++) { n       for (ll k = 0; k <= sum; k++) { n         (tmp[j][k] += dp[j][k]) % mod; n         dp[j][k] = 0; n       } n     } n   } n   if (y < 3) { n     cout << n << endl; n     return 0; n   } n   for (ll i = 100; i >= 1; i--) { n     for (ll j = num[i]; j > 0; j--) { n       if (choose(num[i], j) != tmp[j][j * i]) continue; n       ans = max(ans, j); n     } n   } n   cout << ans << endl; n } n


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


#include <bits/stdc++.h> n using namespace std; n int cnt[15]; n int s[15]; n char c[1 << 20]; n int need[15]; n int digits(int first) { return !first ? 0 : 1 + digits(first / 10); } n int main(void) { n   int n; n   string str; n   cin >> (c + 1) >> str; n   n = strlen(c + 1); n   for (auto it : str) ++need[it -  0 ]; n   for (int i = 1; i <= n; ++i) ++cnt[c[i] -  0 ]; n   for (int nr = 1; nr < n; ++nr) n     if (digits(nr) + nr == n) { n       for (int i = 0; i <= 9; ++i) s[i] = cnt[i]; n       int sum = nr; n       while (sum) --s[sum % 10], sum /= 10; n       int can = 1; n       for (int i = 0; i <= 9; ++i) n         if (s[i] < need[i]) can = 0; n       int prim = 1; n       for (int i = 0; i <= 9; ++i) s[i] -= need[i]; n       for (; prim <= 9; ++prim) n         if (s[prim] || (prim == str[0] -  0  && !s[prim])) break; n       if (prim == 10) can = 0; n       if (can) { n         string ans1 =   , ans2 =   ; n         int ct = 0; n         while (ct + 1 < str.length() && str[ct] == str[ct + 1]) ++ct; n         int after = -1; n         if (ct + 1 >= str.length() || str[ct] > str[ct + 1]) n           after = 0; n         else n           after = 1; n         string str1 = str, str2 = str; n         if (prim == str[0] -  0 ) { n           ans1 += str1; n           str1 =   ; n         } n         for (int i = 0; i <= 9; ++i) cnt[i] -= need[i]; n         ans2 += prim +  0 ; n         int sum = nr; n         while (sum) --cnt[sum % 10], sum /= 10; n         --cnt[prim]; n         for (int i = 0; i <= 9; ++i) n           while (s[i] > 0) --s[i], ans1 += i +  0 ; n         for (int i = 0; i <= 9; ++i) { n           if (!str2.empty()) { n             if (after && i > str2[0] -  0 ) n               ans2 += str2, str2 =   ; n             else if (!after && i >= str2[0] -  0 ) n               ans2 += str2, str2 =   ; n           } n           while (cnt[i] > 0) --cnt[i], ans2 += i +  0 ; n         } n         for (int i = 0; i <= 9; ++i) n           if (cnt[i] < 0) ans2 =   ; n         if (ans1.length() == ans2.length()) n           cout << min(ans1, ans2) <<   n ; n         else { n           if (ans2 ==   ) n             cout << ans1 <<   n ; n           else n             cout << ans2 <<   n ; n         } n         return 0; n       } n     } n   assert(cnt[0] == 1 && cnt[1] == 1 && n == 2); n   cout <<  0 n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, p; n   string s; n   bool f = 0; n   cin >> n >> p >> s; n   s =      + s; n   for (int i = n + 1; i > 1; i--) { n     for (char j = s[i] + 1; j <  a  + p; j++) { n       if (j != s[i - 1] && j != s[i - 2]) { n         f = 1; n         s[i] = j; n         for (int k = i + 1; k <= n + 1; k++) { n           char ch =  a ; n           for (; ch <  a  + p; ch++) { n             if (ch != s[k - 1] && ch != s[k - 2]) break; n           } n           s[k] = ch; n         } n       } n       if (f) break; n     } n     if (f) break; n   } n   if (f) { n     for (int i = 2; i < s.size(); i++) cout << s[i]; n     cout <<   n ; n   } else n     cout <<  NO n ; n } n


#include <bits/stdc++.h> n using namespace std; n struct unionfind_t { n   vector<int> parent, rank; n   unionfind_t(int n) : parent(n), rank(n, 0) { n     iota(parent.begin(), parent.end(), 0); n   } n   int find(int v) { n     if (parent[v] == v) return v; n     return parent[v] = find(parent[v]); n   } n   int join(int a, int b) { n     a = find(a), b = find(b); n     if (a == b) return a; n     if (rank[a] > rank[b]) swap(a, b); n     parent[a] = b; n     if (rank[a] == rank[b]) ++rank[b]; n     return b; n   } n }; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   struct edge_t { n     int a, b, value; n   }; n   vector<edge_t> edges(m); n   for (int i = 0; i < m; ++i) { n     scanf( %d %d %d , &edges[i].a, &edges[i].b, &edges[i].value); n     --edges[i].a, --edges[i].b; n   } n   unionfind_t uf(n); n   vector<int> node_count(n, 1); n   vector<int> edge_count(n, 0); n   sort(edges.rbegin(), edges.rend(), n        [](const edge_t &a, const edge_t &b) { return a.value < b.value; }); n   int result = 0; n   for (const edge_t &ed : edges) { n     int a = uf.find(ed.a), b = uf.find(ed.b); n     bool should_add; n     if (a == b) { n       should_add = (edge_count[a] + 1 <= node_count[a]); n     } else { n       should_add = n           (edge_count[a] + 1 + edge_count[b] <= node_count[a] + node_count[b]); n     } n     if (should_add) { n       int id; n       if (a != b) { n         id = uf.join(a, b); n         edge_count[id] = edge_count[a] + edge_count[b]; n         node_count[id] = node_count[a] + node_count[b]; n       } else { n         id = a; n       } n       ++edge_count[id]; n       result += ed.value; n     } n   } n   printf( %d n , result); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct edge { n   int v, nxt; n } e[2050]; n int ecnt; n int n, m; n int totdep; n int pw[2050]; n map<int, int> head; n map<int, bool> has_fa; n map<int, int> sz; n map<int, bool> vis; n void adde(int u, int v) { n   e[++ecnt].v = v; n   e[ecnt].nxt = head[u]; n   head[u] = ecnt; n } n int getdep(int pos) { return pos == 0 ? 0 : getdep(pos / 2) + 1; } n int getsz(int pos) { n   int curdep = getdep(pos); n   int tmp = curdep; n   int lc = pos, rc = pos; n   while (curdep < totdep) { n     curdep++; n     lc = lc << 1; n     rc = rc << 1 | 1; n   } n   if (n < lc) n     return pw[totdep - tmp - 1]; n   else if (n > rc) n     return pw[totdep - tmp]; n   else n     return pw[totdep - tmp - 1] + n - lc + 1; n } n int us[2050], vs[2050]; n int seq[2050], scnt; n long long ans; n const int mod = 1000000007; n void mark(int pos) { n   while (pos / 2) { n     if (has_fa[pos]) return; n     has_fa[pos] = 1; n     seq[++scnt] = pos; n     pos = pos / 2; n   } n } n void dfs_sz(int pos) { n   sz[pos] = getsz(pos); n   if (has_fa[pos << 1]) dfs_sz(pos << 1), sz[pos] -= getsz(pos << 1); n   if (has_fa[pos << 1 | 1]) n     dfs_sz(pos << 1 | 1), sz[pos] -= getsz(pos << 1 | 1); n } n int cur; n void dfs_solv(int pos) { n   vis[pos] = 1; n   ans += 1ll * cur * sz[pos] % mod; n   ans %= mod; n   if (!vis[pos << 1] && has_fa[pos << 1]) dfs_solv(pos << 1); n   if (!vis[pos << 1 | 1] && has_fa[pos << 1 | 1]) dfs_solv(pos << 1 | 1); n   if (!vis[pos >> 1] && (pos >> 1)) dfs_solv(pos >> 1); n   for (int i = head[pos]; i; i = e[i].nxt) { n     int v = e[i].v; n     if (!vis[v]) dfs_solv(v); n   } n   vis[pos] = 0; n } n int main() { n   scanf( %d%d , &n, &m); n   if (m == 0) { n     printf( %lld n , n * 1ll * n % mod); n     return 0; n   } n   seq[++scnt] = 1; n   totdep = getdep(n); n   pw[0] = 1; n   for (int i = 1; i <= 1000; ++i) pw[i] = pw[i - 1] * 2 + 1; n   for (int i = 1; i <= m; ++i) { n     scanf( %d%d , &us[i], &vs[i]); n     mark(us[i]); n     mark(vs[i]); n     adde(us[i], vs[i]); n     adde(vs[i], us[i]); n   } n   dfs_sz(1); n   for (int i = 1; i <= scnt; ++i) { n     cur = sz[seq[i]]; n     dfs_solv(seq[i]); n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n #define int long long n int P = 1000000007; n #define F first n #define S second n #define pb push_back n #define mp make_pair n  n void solve () { n  int n, c; cin >> n >> c; int a[n], b[n-1]; n  int mi=INT_MAX; n  for (int i=0; i<n; ++i) {cin >> a[i];} n  for (int i=0; i<n-1; ++i) {cin >> b[i];} n  int cum=0, day=0; n  for (int i=0; i<n; ++i) { n   int k = (c-cum+a[i]-1)/a[i]+day; n   mi=min(mi,k); n   if (i==n-1) {break;} n   int x=(b[i]-cum+a[i]-1)/a[i]; n   day+=x+1; n   cum=cum+x*a[i]-b[i]; n   // cout << i <<     << cum <<     << day <<     << mi <<   n ; n  } n  cout << mi <<   n ; n } n  n signed main() { n     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); n     #ifndef ONLINE_JUDGE n      freopen( input.txt ,  r , stdin); n      freopen( output.txt ,  w , stdout); n  #endif n     int t = 1; n     cin >> t; n     for (int _t=0; _t<t;++_t) { n         // cout <<  Case #  << _t+1 <<  :  ; n         solve(); n     } n }


#include <bits/stdc++.h> n using namespace std; n string tostr(long long x) { n   stringstream ss; n   ss << x; n   return ss.str(); n } n long long toint(string &s) { n   stringstream ss; n   ss << s; n   long long x; n   ss >> x; n   return x; n } n int main() { n   long long a1, a2, tmp, arr[20], sum, j; n   string st1; n   scanf( %lld %lld , &a2, &a1); n   st1 = tostr(a1); n   reverse(st1.begin(), st1.end()); n   tmp = a2 + toint(st1); n   printf( %lld , tmp); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int T; n   cin >> T; n   for (int P = 0; P < T; P++) { n     int n, k, d; n     cin >> n >> k >> d; n     vector<int> ar(n); n     map<int, int> s; n     int count = 0; n     for (int i = 0; i < n; i++) { n       int tmp = 0; n       cin >> tmp; n       if (s.find(tmp) == s.end()) { n         s.insert(pair<int, int>(tmp, count)); n         tmp = count; n         count++; n       } else { n         tmp = s.find(tmp)->second; n       } n       ar[i] = tmp; n     } n     vector<int> b(count, 0); n     int price = 0; n     for (int i = 0; i < d; i++) { n       if (b[ar[i]] == 0) { n         price++; n       } n       b[ar[i]]++; n     } n     int min_price = price; n     for (int i = d; i < n; i++) { n       if (b[ar[i - d]] == 1) { n         price--; n       } n       b[ar[i - d]]--; n       if (b[ar[i]] == 0) { n         price++; n       } n       b[ar[i]]++; n       min_price = min(min_price, price); n     } n     cout << min_price <<   n ; n   } n   return 0; n } n


#include <iostream> n #include <vector> n #include <string> n #include <cstring> n #include <cmath> n #include <climits> n #include <algorithm> n #include <map> n #include <stack> n #include <unordered_map> n #include <set> n #include <unordered_set> n #include <utility> n #include <iomanip> n  n using namespace std; n typedef long long int ll; n ll pw(ll a, ll b, ll m){ n  ll ans=1; n  while(b>0){ n   if(b&1) ans=(ans*a)%m; n   a=(a*a)%m; n   b>>=1; n  } n  return ans; n } n  n ll gcd(ll a,ll b){ n  if(a==0) return b; n  return gcd(b % a , a); n } n  n bool comp(const pair<int,int> &a,const pair<int,int> &b){ n     return a.second>b.second; n } n  n ll n,m; n set<ll> has; n vector<ll> input; n  n void solve(ll l,ll r){ n  ll sum=0; n  for(ll i=l;i<r+1;i++){ n   sum+=input[i]; n  } n  has.insert(sum); n  ll mid=(input[l]+input[r])/2; n  ll pos=-1; n  for(ll i=l;i<r+1;i++){ n   if(input[i]<=mid){ n    pos=i; n   } n   else{ n    break; n   } n  } n  if(pos==-1 || pos==r) return; n  solve(l,pos); n  solve(pos+1,r); n } n void randomevent(){ n  ll right=n; n  while(right>=0 && input[right-1]==right){ n   right--; n  } n  double f=(right>0) ? 1:0; n  for(ll i=0;i<m;i++){ n   ll r;cin>>r; n   double p;cin>>p; n   if(r>=right){ n    f*=(1-p); n   } n  } n  cout<<fixed<<setprecision(12)<<(1-f)<<endl; n } n  n  n  n int main(){ n #ifndef ONLINE_JUDGE n     freopen( input.txt , r , stdin); n     freopen( output.txt , w , stdout); n #endif  n  n     int t;cin>>t; n     while(t--){ n      cin>>n>>m; n      for(ll i=0;i<n;i++){ n       ll p;cin>>p; n       input.push_back(p); n      } n      randomevent(); n      input.clear(); n  n     } n }


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector ) n #pragma GCC target( avx ) n int V[100000]; n float x; n int main() { n   int n, m, l, r, A, T; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) scanf( %d , &V[i]); n   while (m--) { n     scanf( %d%d%d%f , &T, &l, &r, &x); n     if (T == 1) n       for (int i = l; i <= r; ++i) V[i] -= V[i] > x ? x : 0; n     else { n       A = 0; n       for (int i = l; i <= r; ++i) V[i] == x ? ++A : 0; n       printf( %d n , A); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 998244353; n const long long N = 5e2 + 1; n const long long M = 1e6 + 1; n long long dp[2 * N][2 * N], min1[2 * N][2 * N], ar[2 * N], ar1[M]; n bool check[2 * N][2 * N]; n vector<long long> occur[N]; n long long solve(long long l, long long r) { n   if (l > r) { n     return 1; n   } n   if (check[l][r]) { n     return dp[l][r]; n   } n   long long y = min1[l][r]; n   if (occur[y][0] < l || occur[y][occur[y].size() - 1] > r) { n     check[l][r] = true; n     return 0; n   } n   if (l == r) { n     check[l][r] = true; n     dp[l][r] = 1; n     return dp[l][r]; n   } n   check[l][r] = true; n   long long tich = 1, sum = solve(l, occur[y][0] - 1), n             sum1 = solve(occur[y][occur[y].size() - 1] + 1, r), i; n   if (l <= occur[y][0] - 1) { n     sum *= 2; n   } n   if (occur[y][occur[y].size() - 1] + 1 <= r) { n     sum1 *= 2; n   } n   for (i = 0; i + 1 < occur[y].size(); i++) { n     tich *= solve(occur[y][i] + 1, occur[y][i + 1] - 1); n     tich %= mod; n   } n   for (i = l; i < occur[y][0] - 1; i++) { n     sum += solve(l, i) * solve(i + 1, occur[y][0] - 1); n     sum %= mod; n   } n   for (i = occur[y][occur[y].size() - 1] + 1; i < r; i++) { n     sum1 += solve(occur[y][occur[y].size() - 1] + 1, i) * solve(i + 1, r); n     sum1 %= mod; n   } n   dp[l][r] = ((sum * sum1) % mod * tich) % mod; n   return dp[l][r]; n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   long long n, m, i, j, k, l = 0; n   cin >> n >> m; n   ar1[0] = -1; n   for (i = 1; i <= m; i++) { n     cin >> ar1[i]; n     if (ar1[i] != ar1[i - 1]) { n       l++; n       ar[l] = ar1[i]; n       if (l > 2 * n + 1) { n         cout << 0; n         exit(0); n       } n     } n   } n   n = l; n   for (i = 1; i <= n; i++) { n     min1[i][i] = ar[i]; n     occur[ar[i]].push_back(i); n     for (j = i + 1; j <= n; j++) { n       min1[i][j] = min(min1[i][j - 1], ar[j]); n     } n   } n   cout << solve(1, n); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 11; n string s; n bool vis[maxn]; n int n; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> s; n   n = s.length(); n   vector<pair<int, int> > vec, tmp; n   for (int i = 0; i < n; i++) { n     if (vec.empty() || s[vec.back().first] != s[i]) n       vec.emplace_back(i, i); n     else { n       pair<int, int> p = vec.back(); n       vec.pop_back(); n       vec.emplace_back(p.first, i); n     } n   } n   int ans = 0; n   while (vec.size() > 1) { n     for (int i = 0; i < (int)(vec).size(); i++) { n       int sub = 2 - (i == 0 || i == (int)(vec).size() - 1); n       if (vec[i].second >= vec[i].first + sub) { n         if (tmp.empty() || s[tmp.back().first] != s[vec[i].first]) { n           vec[i].second -= sub; n           tmp.push_back(vec[i]); n         } else { n           pair<int, int> p = tmp.back(); n           tmp.pop_back(); n           p.second += vec[i].second - vec[i].first + 1 - sub; n           tmp.push_back(p); n         } n       } n     } n     ans++; n     tmp.swap(vec); n     tmp.clear(); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n int n, m, k; n int main() { n   long long ans = 1; n   scanf( %d%d%d , &n, &m, &k); n   if (k == n) { n     int mid = k / 2 + (k & 1); n     for (int i = 0; i < mid; ++i) ans = (ans * m) % 1000000007; n     printf( %I64d , ans); n   } else if (!(k % 2) && k < n) n     printf( %d , m); n   else if (k == 1 || k > n) { n     for (int i = 0; i < n; ++i) ans = (ans * m) % 1000000007; n     printf( %I64d , ans); n   } else { n     printf( %d , m * m); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1000000007; n const int MM = 998244353; n const long double PI = acos(-1); n long long power(long long b, long long e, long long m) { n   if (e == 0) return 1; n   if (e & 1) return b * power(b * b % m, e / 2, m) % m; n   return power(b * b % m, e / 2, m); n } n long long power(long long b, long long e) { n   if (e == 0) return 1; n   if (e & 1) return b * power(b * b, e / 2); n   return power(b * b, e / 2); n } n template <typename T, typename U> n static inline void amin(T &x, U y) { n   if (y < x) x = y; n } n template <typename T, typename U> n static inline void amax(T &x, U y) { n   if (x < y) x = y; n } n template <typename T, typename U> n ostream &operator<<(ostream &os, const pair<T, U> &p) { n   return os <<  (  << p.first <<  ,  << p.second <<  ) ; n } n const int N = 100005; n vector<int> zFunction(string &s) { n   int n = (long long)s.size(), l, r, i; n   vector<int> z(n); n   z[0] = n; n   l = r = 0; n   for (i = 1; i < n; ++i) { n     if (i <= r) z[i] = min(r - i + 1, z[i - l]); n     while (i + z[i] < n && s[z[i]] == s[z[i] + i]) ++z[i]; n     if (i + z[i] - 1 > r) { n       l = i; n       r = i + z[i] - 1; n     } n   } n   return z; n } n int _runtimeTerror_() { n   string s, t; n   cin >> s >> t; n   int n = (long long)s.size(), m = (long long)t.size(); n   string u = t +  #  + s; n   vector<int> z = zFunction(u); n   vector<int> start(n + 10, false); n   for (int i = m + 1; i < n + m + 1; ++i) { n     if (z[i] == m) start[i - m - 1] = 1; n   } n   int last = -1; n   long long ans = 0; n   vector<long long> suf(n + 10, 0); n   vector<long long> val(n + 10, 0); n   suf[n + 1] = 0; n   val[n + 1] = 0; n   for (int i = n - 1; i >= 0; --i) { n     suf[i] = suf[i + 1]; n     val[i] = val[i + 1] + suf[i]; n     if (start[i] == 1) last = i; n     if (last == -1) continue; n     long long u = (n - 1 - (last + m - 1) + 1); n     val[i] += u; n     val[i] %= M; n     suf[i] += u; n     suf[i] %= M; n     ans += u; n     ans %= M; n     suf[i] += val[last + m]; n     suf[i] %= M; n     val[i] += val[last + m]; n     val[i] %= M; n     ans += val[last + m]; n     ans %= M; n   } n   cout << ans <<   n ; n   return 0; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int TESTS = 1; n   while (TESTS--) _runtimeTerror_(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, cnt[200200], mx = 0, val = 0, arr[200200], pr[200200], a[200200], ans; n vector<int> lst, bd; n void tryBuild(int i) { n   vector<int> lPos(400400, -1); n   lPos[200000] = 0; n   for (int i1 = 1; i1 <= n; i1++) { n     if (a[i1] == i) { n       arr[i1] = 1; n     } else { n       if (a[i1] != val) { n         arr[i1] = 0; n       } n     } n     pr[i1] = pr[i1 - 1] + arr[i1]; n     if (lPos[pr[i1] + 200000] == -1) { n       lPos[pr[i1] + 200000] = i1; n     } else { n       ans = max(ans, i1 - lPos[pr[i1] + 200000]); n     } n   } n } n vector<vector<int> > pose(200200); n int pref[200200]; n int num[200200]; n void solve() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     cnt[a[i]]++; n     if (cnt[a[i]] > mx) { n       mx = cnt[a[i]]; n       val = a[i]; n     } n     pose[a[i]].push_back(i); n   } n   for (int i = 1; i <= n; i++) { n     if (cnt[i] >= (int)sqrt(n)) { n       lst.push_back(i); n     } else { n       bd.push_back(i); n     } n   } n   for (int i = 1; i <= n; i++) { n     pref[i] = pref[i - 1]; n     if (a[i] == val) { n       arr[i] = -1; n       pref[i]++; n       num[pref[i]] = i; n     } n   } n   for (auto i : lst) { n     if (i == val) { n       continue; n     } n     tryBuild(i); n   } n   for (auto ch : bd) { n     if (ch == val) { n       continue; n     } n     for (int i = 0; i < pose[ch].size(); i++) { n       int x = pose[ch][i]; n       for (int i1 = pose[ch].size() - 1; i1 >= i; i1--) { n         int y = pose[ch][i1]; n         int cnt = i1 - i + 1 - (pref[y] - pref[x - 1]); n         if (cnt < 0) { n           continue; n         } n         int be = pref[x - 1]; n         int all = pref[y]; n         for (int i2 = 0; i2 <= cnt; i2++) { n           int l = (be < i2 ? 1 : num[be - i2] + 1); n           int r = (cnt - i2 + all >= mx ? n : num[cnt - i2 + all + 1] - 1); n           ans = max(ans, r - l + 1); n         } n       } n     } n   } n   cout << ans; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int q; n   q = 1; n   while (q != 0) { n     solve(); n     --q; n   } n } n


#include <bits/stdc++.h> n using namespace std; n using cat = long long; n int main() { n   cin.sync_with_stdio(0); n   cin.tie(0); n   cout << fixed << setprecision(10); n   int W, N, M; n   cin >> W >> N >> M; n   vector<int> A(1 << W, 0); n   for (int i = 0; i < N; i++) { n     int a; n     cin >> a; n     A[a]++; n   } n   vector<vector<int> > B(1 << W, vector<int>(1 << W, 0)); n   for (int i = 0; i < (1 << W); i++) n     for (int j = 0; j < (1 << W); j++) B[i][i & j] += A[j]; n   for (int i = 0; i < M; i++) { n     string s; n     cin >> s; n     int mask[6] = {}; n     for (int j = 0; j < W; j++) { n       if ( O  == s[j]) mask[0] |= 1 << (W - 1 - j); n       if ( a  == s[j]) mask[1] |= 1 << (W - 1 - j); n       if ( X  == s[j]) mask[2] |= 1 << (W - 1 - j); n       if ( x  == s[j]) mask[3] |= 1 << (W - 1 - j); n       if ( A  == s[j]) mask[4] |= 1 << (W - 1 - j); n       if ( o  == s[j]) mask[5] |= 1 << (W - 1 - j); n     } n     int vc = mask[1] | mask[3] | mask[5]; n     int vm = mask[2] | mask[3] | mask[5]; n     int im = (1 << W) - 1 - mask[4], m = mask[4] | mask[5]; n     int ans = 0; n     for (int j = 0; j < (1 << W); j++) n       if ((j & (mask[0] | mask[1])) == mask[1]) { n         int mask_cur = (j & m) ^ im; n         int val_cur = vc ^ (j & vm); n         ans += B[mask_cur][val_cur] * A[j]; n       } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n long long powmod(long long a, long long b, long long MOD) { n   long long ans = 1; n   while (b) { n     if (b % 2) ans = ans * a % MOD; n     a = a * a % MOD; n     b /= 2; n   } n   return ans; n } n const int N = 2e5 + 11; n int main() { n   ios::sync_with_stdio(false); n   int a; n   cin >> a; n   int b = a; n   int cnt = 0; n   while (a % 10) { n     cnt++; n     a++; n   } n   int p = 0; n   while (b % 10) { n     b--; n     p++; n   } n   if (cnt <= p) n     cout << a; n   else n     cout << b; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n int main() { n   long double x1, y1, r1, x2, y2, r2; n   while (~scanf( %Lf%Lf%Lf%Lf%Lf%Lf , &x1, &y1, &r1, &x2, &y2, &r2)) { n     long double de = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); n     long double d = sqrt(de); n     if (d >= (r1 + r2)) { n       printf( 0.00000000000000000000 n ); n       continue; n     } n     if (d <= fabs(r1 - r2)) { n       printf( %.20Lf n , pi * min(r1, r2) * min(r1, r2)); n       continue; n     } n     long double s1 = acos((r1 * r1 + de - r2 * r2) / (2.0 * r1 * d)); n     long double s2 = acos((r2 * r2 + de - r1 * r1) / (2.0 * r2 * d)); n     long double v1 = s1 * r1 * r1; n     long double ss1 = 1.0 / 2.0 * r1 * r1 * sin(2.0 * s1); n     long double v2 = s2 * r2 * r2; n     long double ss2 = 1.0 / 2.0 * r2 * r2 * sin(2.0 * s2); n     printf( %.20Lf n , v1 + v2 - ss1 - ss2); n   } n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n template <class t> n using V = vector<t>; n constexpr ll INF = 1e16; n int n, m; n ll dp[1502][1502]; n int tab[1502][1502]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) n     for (int k = 1; k <= m; ++k) scanf( %d , &tab[i][k]); n   for (int i = 1; i <= n; ++i) n     for (int k = 1; k <= m; ++k) tab[i][k] += tab[i][k - 1]; n   for (int i = 1; i <= n + 1; ++i) n     for (int k = 0; k <= m + 1; ++k) dp[i][k] = -INF; n   for (int i = 1; i <= n; ++i) { n     if (i & 1) { n       for (int k = 1; k <= m; ++k) n         dp[i - 1][k] = max(dp[i - 1][k - 1], dp[i - 1][k]); n       for (int k = 2; k <= m; ++k) dp[i][k] = dp[i - 1][k - 1] + tab[i][k]; n     } else { n       for (int k = m; k >= 1; --k) n         dp[i - 1][k] = max(dp[i - 1][k], dp[i - 1][k + 1]); n       for (int k = 1; k <= m - 1; ++k) dp[i][k] = dp[i - 1][k + 1] + tab[i][k]; n     } n   } n   ll res = -INF; n   for (int i = 1; i <= m; ++i) res = max(res, dp[n][i]); n   printf( %lld n , res); n } n


#include <bits/stdc++.h> n using namespace std; n bool alph[26] = {1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, n                  0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0}; n bool check(string s) { n   for (int i = 0; i < s.length(); i++) n     if (!alph[s[i] -  A ]) return false; n   return true; n } n int main() { n   string s; n   cin >> s; n   string t = s; n   reverse(s.begin(), s.end()); n   if (s == t && check(s)) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   if (n == 5) { n     cout <<  >...v  << endl n          <<  v.<..  << endl n          <<  ..^..  << endl n          <<  >....  << endl n          <<  ..^.<  << endl n          <<  1 1 ; n     return 0; n   } n   if (n == 3) { n     cout <<  >vv  << endl <<  ^<.  << endl <<  ^.<  << endl <<  1 3 ; n     return 0; n   } n   for (int i = 0; i < 50; i++) { n     for (int j = 0; j < 50; j++) { n       cout <<  > ; n     } n     for (int j = 0; j < 24; j++) { n       cout <<  .> ; n     } n     cout <<  .v  << endl; n     cout <<  ^. ; n     for (int j = 0; j < 24; j++) { n       cout <<  <. ; n     } n     for (int j = 0; j < 50; j++) { n       cout <<  < ; n     } n     cout << endl; n   } n   cout <<  1 100 ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long tests, a, b, c; n   cin >> tests; n   while (tests--) { n     cin >> a >> b >> c; n     vector<long long> v; n     v.push_back(a); n     v.push_back(b); n     v.push_back(c); n     sort(v.begin(), v.end()); n     a = v[0]; n     b = v[1]; n     c = v[2]; n     if (a + c <= b) n       cout << a + c <<   n ; n     else if (a + c > b) { n       cout << (a + b + c) / 2 <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n const int MAXN = 200000; n using namespace std; n inline int read() { n   int x = 0, w = 1; n   char c =    ; n   while (c <  0  || c >  9 ) { n     c = getchar(); n     if (c ==  - ) w = -1; n   } n   while (c >=  0  && c <=  9 ) { n     x = (x << 1) + (x << 3) + (c ^ 48); n     c = getchar(); n   } n   return x * w; n } n int n, a[MAXN + 5]; n void init() { n   n = read(); n   for (int i = 1; i <= n; ++i) a[i] = read(); n } n int mx, mxi, ans[MAXN + 5], len; n map<int, int> dp; n int main() { n   init(); n   for (int i = 1; i <= n; ++i) { n     dp[a[i]] = dp[a[i] - 1] + 1; n     if (dp[a[i]] > mx) { n       mx = dp[a[i]]; n       mxi = a[i]; n     } n   } n   printf( %d n , mx); n   for (int i = n; i > 0; --i) n     if (mxi == a[i]) { n       --mxi; n       ans[++len] = i; n     } n   for (int i = len; i > 0; --i) printf( %d  , ans[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n  n using namespace std; n  n int main() n { n    int t; n    cin>>t; n    while(t--) n    { n        int n,m; n        int count=0; n        cin>>n>>m; n        map <int, int > ma; n        int a[n],b[m]; n        for(int i=0;i<n;i++) n        { n            cin>>a[i]; n            ma[a[i]]++; n        } n        for(int i=0;i<m;i++) n        { n            cin>>b[i]; n            ma[b[i]]++; n        } n        for(auto i=ma.begin();i!=ma.end();i++) n        { n            if(i->second>1) n            { n                count=count+2; n            } n        } n        cout<<count/2<<  n ; n    } n  n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int n; n struct Line { n   int k, b; n } a[100100]; n struct Fraction { n   int x, y; n } b[100100]; n int gcd(int x, int y) { n   if (x == 0) n     return y; n   else n     return gcd(y % x, x); n } n bool cmp(const Fraction &t1, const Fraction &t2) { n   if (t1.x != t2.x) return (t1.x < t2.x); n   return (t1.y < t2.y); n } n int main() { n   scanf( %d , &n); n   int tot = 0; n   for (int i = 1; i <= n; ++i) { n     scanf( %d%d , &a[i].k, &a[i].b); n     if (a[i].k != 0) { n       b[++tot].x = -a[i].b; n       b[tot].y = a[i].k; n       if (b[tot].x < 0) { n         b[tot].x *= -1; n         b[tot].y *= -1; n       } n       int g = gcd(abs(b[tot].x), abs(b[tot].y)); n       b[tot].x /= g; n       b[tot].y /= g; n       if (b[tot].x == 0) b[tot].y = 1; n     } n   } n   sort(b + 1, b + tot + 1, cmp); n   int ans = 0; n   for (int i = 1; i <= tot; ++i) { n     if (i == 1 || b[i].x != b[i - 1].x || b[i].y != b[i - 1].y) ans++; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 10; n int n, a[N], b[N], c[N]; n int Log[N]; n int l[19][N], r[19][N]; n struct rmq { n   int st[N][19], val[N]; n   int type; n   inline int Max(int x, int y) { return (val[x] < val[y]) ? y : x; } n   void build(int *b, int n, int _type) { n     type = _type; n     for (int i = 1; i <= n; i++) st[i][0] = i, val[i] = type * b[i]; n     for (int j = 1; j <= Log[n]; j++) { n       for (int i = 1; i + (1 << j) - 1 <= n; i++) n         st[i][j] = Max(st[i][j - 1], st[i + (1 << j - 1)][j - 1]); n     } n   } n   inline int query(int l, int r) { n     int k = Log[r - l + 1]; n     return Max(st[l][k], st[r - (1 << k) + 1][k]); n   } n } rmq_l, rmq_r; n int main() { n   scanf( %d , &n); n   for (int i = 2; i <= 3 * n; i++) Log[i] = Log[i >> 1] + 1; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     a[i + n] = a[i + n * 2] = a[i]; n   } n   if (n == 1) return puts( 0 ), 0; n   for (int i = 1; i <= 3 * n; i++) { n     b[i] = max(1, i - a[i]); n     c[i] = min(3 * n, i + a[i]); n   } n   for (int i = 0; i <= Log[3 * n]; i++) r[i][3 * n] = 3 * n, l[i][1] = 1; n   for (int i = 1; i <= 3 * n; i++) { n     l[0][i] = b[i]; n     r[0][i] = c[i]; n   } n   rmq_l.build(l[0], n * 3, -1); n   rmq_r.build(r[0], n * 3, 1); n   for (int i = 1; i <= Log[3 * n]; i++) n     for (int j = 1; j <= 3 * n; j++) { n       int posl = rmq_l.query(l[i - 1][j], r[i - 1][j]); n       int posr = rmq_r.query(l[i - 1][j], r[i - 1][j]); n       l[i][j] = min(l[i - 1][posl], l[i - 1][posr]); n       r[i][j] = max(r[i - 1][posl], r[i - 1][posr]); n     } n   for (int j = n + 1; j <= n * 2; j++) { n     int u = j, v = j; n     int ans = 0; n     for (int i = Log[3 * n]; i >= 0; i--) { n       if (max(r[i][v], r[i][u]) - min(l[i][u], l[i][v]) + 1 >= n) continue; n       int nu = rmq_l.query(l[i][u], r[i][v]); n       int nv = rmq_r.query(l[i][u], r[i][v]); n       u = nu; n       v = nv; n       ans += 1 << i; n     } n     ans++; n     printf( %d  , ans); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   char str[105]; n   scanf( %s , str); n   int l = 0, r = 0, u = 0, d = 0; n   for (int i = 0; i < n; i++) n     if (str[i] ==  L ) n       l++; n     else if (str[i] ==  R ) n       r++; n     else if (str[i] ==  U ) n       u++; n     else if (str[i] ==  D ) n       d++; n   printf( %d n , min(l, r) * 2 + min(u, d) * 2); n } n


#include <bits/stdc++.h> n using namespace std; n string a, b, c; n long long n, x, y, z; n pair<long long, long long> f[2000]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> a >> b >> c; n   for (auto i : a) { n     f[i].first++; n     x = max(x, f[i].first); n   } n   for (auto i : b) { n     if (f[i].second != 2) f[i] = {0, 2}; n     f[i].first++; n     y = max(y, f[i].first); n   } n   for (auto i : c) { n     if (f[i].second != 3) f[i] = {0, 3}; n     f[i].first++; n     z = max(z, f[i].first); n   } n   if (n == 1) { n     if (a.size() == x) a.erase(0, 1); n     if (b.size() == y) b.erase(0, 1); n     if (c.size() == z) c.erase(0, 1); n   } n   x = min(x + n, (long long)a.size()); n   y = min(y + n, (long long)b.size()); n   z = min(z + n, (long long)c.size()); n   if (x > y && x > z) return cout <<  Kuro , 0; n   if (y > x && y > z) return cout <<  Shiro , 0; n   if (z > x && z > y) return cout <<  Katie , 0; n   cout <<  Draw ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace { n int CC_; n const double EPS = 1E-9; n const double PI = 2 * acos(0.0); n const long long MOD = 1000000007; n template <class T> n void DA(T i, T e) { n   while (i != e) { n     cout <<  Con>>(   << ++CC_ <<   )   << *i++ <<   n ; n   } n } n template <class T> n void DA(T* x, int l) { n   for (int i = 0; i < l; i++) cout <<  [  << i <<  ]>>   << x[i] <<   n ; n } n template <class T> n inline void sary(T* st, T* nd) { n   while (st < nd) cin >> *st++; n } n template <class T> n void tobin(T n, char* bin) { n   int pos = 1 << ((int)log2(n)); n   while (pos >= 1) { n     if ((n & pos) == 0) n       *bin =  0 ; n     else n       *bin =  1 ; n     pos >>= 1; n     bin++; n   } n   *bin =   0 ; n } n template <class T> n int strOccur(string& s, T& tgt) { n   int oc = 0, p = s.find(tgt); n   while (p != string::npos) { n     p = s.find(tgt, p + 1); n     oc++; n   } n   return oc; n } n template <class T> n inline T LCM(T x, T y) { n   return ((x * y) / __gcd(x, y)); n } n long long todec(string& num, int b) { n   long long dec = num[0] - (isupper(num[0]) ?  A  - 10 :  0 ); n   for (int i = 1; num[i]; i++) { n     if (num[i] >=  A  && num[i] <=  Z ) n       num[i] -=  A  - 10; n     else n       num[i] -=  0 ; n     dec *= b; n     dec += num[i]; n   } n   return dec; n } n int bigMod(int b, int e, int m) { n   if (e == 0) return 1; n   if (!(e & 1)) { n     int temp = bigMod(b, e / 2, m) % m; n     return (temp * temp) % m; n   } else n     return ((b % m) * (bigMod(b, e - 1, m)) % m) % m; n } n bool comp(const int a, const int b) { return a > b; } n }  // namespace n const int sss = 1E6; n int a[200019]; n void solve(void) { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   int lim = n / 2; n   for (int i = 0, j = n - 1; i < lim; i++, j--) { n     if (i % 2 == 0) { n       swap(a[i], a[j]); n     } n   } n   for (int i = 0; i < n; i++) { n     cout << a[i] <<    ; n   } n   cout <<   n ; n   ; n } n int main(void) { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e5 + 10; n const long long M = 998244353; n const long double PI = acos(-1); n long long n, k; n long long a[N], d[N], mn[N] = {INT_MAX}; n signed main() { n   long long i, s = 0, ans = 0; n   cin >> n >> k; n   for (i = 1; i <= n; i++) cin >> a[i]; n   for (i = 1; i <= n; i++) cin >> d[i], mn[i] = min(mn[i - 1], d[i]); n   for (i = n; i >= 1; i--) a[i] += a[i + 1]; n   if (k == 0) { n     for (i = 1; i <= n; i++) ans = max(ans, a[i] - d[i]); n     cout << ans; n   } else if (k == 1) { n     for (i = 2; i <= n; i++) n       ans = max(ans, max(0ll, a[1] - a[i] - mn[i - 1]) + max(0ll, a[i] - d[i])); n     for (i = 1; i < n; i++) n       ans = max(ans, a[1] - (a[i + 1] - a[i + 2]) - d[1] + n                          max(0ll, a[i + 1] - a[i + 2] - d[i + 1])); n     cout << ans; n   } else n     cout << max({0ll, a[1] - mn[n - 1], a[n] - d[n]}); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n multiset<int64_t> h, hl, v, vl; n int main() { n   cin.tie(0), ios_base::sync_with_stdio(0); n   int W, H, q, r, c, nr, nc, pr, pc; n   auto tmp = h.begin(); n   char t; n   cin >> W >> H >> q; n   int64_t mv = H, mh = W; n   h.insert(0); n   h.insert(W); n   hl.insert(W); n   v.insert(0); n   v.insert(H); n   vl.insert(H); n   while (q--) { n     cin >> t; n     if (t ==  H ) { n       cin >> r; n       tmp = v.insert(r); n       nr = *next(tmp); n       pr = *prev(tmp); n       vl.erase(vl.find(nr - pr)); n       vl.insert(r - pr); n       vl.insert(nr - r); n     } else { n       cin >> c; n       tmp = h.insert(c); n       nc = *next(tmp); n       pc = *prev(tmp); n       hl.erase(hl.find(nc - pc)); n       hl.insert(c - pc); n       hl.insert(nc - c); n     } n     cout << *prev(hl.end()) * *(prev(vl.end())) <<   n ; n   } n   return 0; n   ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   char str[1000][1000]; n   int i; n   for (i = 0; i < n; i++) { n     scanf(  %[^ n] , str[i]); n   } n   int cnt = 0; n   int j; n   for (i = 0; i < n; i++) { n     if (strcmp(str[i],  -1 ) == 0) continue; n     cnt++; n     int flag = 0; n     for (j = i + 1; j < n; j++) { n       if (strcmp(str[j],  -1 ) == 0) continue; n       if (strcmp(str[i], str[j]) == 0) { n         strcpy(str[j],  -1 ); n       } n     } n   } n   printf( %d n , cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18 + 9; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long n, k; n   cin >> n >> k; n   vector<long long> a(n); n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort(a.begin(), a.end()); n   vector<long long> pref(n, 0), suf(n, 0); n   for (long long i = 1, sm = a[0]; i < n; i++) { n     pref[i] = a[i] * i - sm; n     sm += a[i]; n   } n   for (long long i = n - 2, sm = a[n - 1]; i >= 0; i--) { n     suf[i] = sm - a[i] * (n - i - 1); n     sm += a[i]; n   } n   long long ans = INF; n   for (long long i = 0, j = 0; i < n; i = j) { n     for (; j < n && a[j] == a[i]; j++) n       ; n     long long prev = 0, forw = 0; n     long long base = INF; n     prev += pref[i]; n     prev -= i; n     if (i >= k - j + i) base = min(base, prev); n     forw += suf[j - 1]; n     forw -= (n - j); n     if (n - j >= k - j + i) base = min(base, forw); n     base = min(base, prev + forw); n     ans = min(ans, base + k - (j - i)); n     if (j - i >= k) ans = 0; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int test; n   cin >> test; n   while (test--) { n     long long int n; n     cin >> n; n     long long int a[n]; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n     } n     long long int total_sum = 0; n     for (int i = 0; i < n; i++) { n       total_sum += a[i]; n     } n     if (total_sum < 0 && n == 1) { n       cout <<  YES  << endl; n       continue; n     } else if (total_sum < 0) { n       cout <<  NO  << endl; n       continue; n     } n     long long int sum = 0; n     long long int max_so_far = 0; n     long long int element = 0; n     long long int element_f = 0; n     for (int i = 0; i < n; i++) { n       sum = sum + a[i]; n       element++; n       if (sum <= 0) { n         element = 0; n         sum = 0; n       } else if (sum > max_so_far) { n         element_f = element; n         max_so_far = sum; n       } n     } n     if (max_so_far >= total_sum && element_f < n) n       cout <<  NO  << endl; n     else n       cout <<  YES  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int maxn = 1e5 + 3; n int n; n int k; n int A; n int a[maxn]; n int ans[maxn]; n int main() { n   int sum = 0; n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]), sum += a[i]; n   if (sum % k) { n     puts( No ); n     return 0; n   } n   sum /= k; n   for (int i = 1; i <= n;) { n     int now = 0, nowsum = 0; n     while (nowsum < sum && i <= n) nowsum += a[i++], ++now; n     if (nowsum > sum) { n       puts( No ); n       return 0; n     } n     ans[++A] = now; n   } n   puts( Yes ); n   for (int i = 1; i < A; ++i) printf( %d  , ans[i]); n   printf( %d n , ans[A]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n ifstream fi( test.txt ); n ifstream fir( inp.txt ); n ofstream fo( out.txt ); n const long long MOD = 1e9 + 7; n const long long base = 269; n const int ooi = 1 << 30; n const int N = 1e5 + 5; n long long n, m, q, k, pos, rs, t, T, cnt, rs1; n long long maxx = -1e9, minn = 1e9; n long long a[N], b[N]; n vector<long long> c[N]; n int main() { n   cin >> n >> k; n   for (long long(i) = 0; (i) < (n); (i)++) { n     cin >> a[i]; n   } n   for (long long(i) = 0; (i) < (n); (i)++) { n     cin >> b[i]; n     c[a[i]].push_back(b[i]); n   } n   for (long long(i) = 1; (i) <= (k); (i)++) { n     sort(c[i].begin(), c[i].end()); n     if (c[i].size()) c[i].pop_back(), cnt++; n   } n   cnt = k - cnt; n   vector<long long> ans; n   for (long long(i) = 1; (i) <= (k); (i)++) { n     for (long long(j) = 0; (j) < (c[i].size()); (j)++) ans.push_back(c[i][j]); n   } n   sort(ans.begin(), ans.end()); n   for (long long(i) = 0; (i) < (cnt); (i)++) rs += ans[i]; n   cout << rs; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> gr[200011]; n vector<long long> v; n vector<long long> v1; n bool vis[200011]; n queue<pair<long long, bool> > q; n long long n, m; n void bfs(long long s, bool k) { n   q.push({s, k}); n   while (!q.empty()) { n     long long node = q.front().first; n     bool z = q.front().second; n     q.pop(); n     if (vis[node]) continue; n     if (z) n       v.push_back(node); n     else n       v1.push_back(node); n     vis[node] = 1; n     for (int i = 0; i < gr[node].size(); i++) n       if (!vis[gr[node][i]]) q.push({gr[node][i], !z}); n   } n } n int main() { n   ios::sync_with_stdio(0); n   long long q, i, x, y; n   cin >> q; n   while (q--) { n     cin >> n >> m; n     for (i = 0; i < m; i++) { n       cin >> x >> y; n       gr[x].push_back(y); n       gr[y].push_back(x); n     } n     v.clear(); n     v1.clear(); n     bfs(1, 0); n     if (v.size() <= n / 2) { n       cout << v.size() << endl; n       for (i = 0; i < v.size(); i++) cout << v[i] <<    ; n       cout << endl; n     } else { n       cout << v1.size() << endl; n       for (i = 0; i < v1.size(); i++) cout << v1[i] <<    ; n       cout << endl; n     } n     for (i = 1; i <= n; i++) { n       vis[i] = 0; n       gr[i].clear(); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n using vc = vector<T>; n template <class T> n using vvc = vc<vc<T>>; n template <class T> n void mkuni(vector<T>& v) { n   sort(v.begin(), v.end()); n   v.erase(unique(v.begin(), v.end()), v.end()); n } n template <class T> n void print(T x, int suc = 1) { n   cout << x; n   if (suc == 1) n     cout <<   n ; n   else n     cout <<    ; n } n template <class T> n void print(const vector<T>& v, int suc = 1) { n   for (int i = 0; i < v.size(); i++) n     print(v[i], i == (int)(v.size()) - 1 ? suc : 2); n } n const int INF = 0x3f3f3f3f; n const int maxn = 2e5 + 7; n const int mod = 998244353; n long long quick(long long a, long long b) { n   long long ret = 1; n   while (b) { n     if (b & 1) ret = ret * a % mod; n     a = a * a % mod; n     b >>= 1; n   } n   return ret; n } n long long inv(long long a) { return quick(a, mod - 2); } n long long sufm[maxn], sufsum[maxn]; n int p[maxn]; n long long calc(int l, int r) { n   long long ret = sufsum[l] - sufsum[r]; n   ret = (ret + mod) % mod; n   ret = ret * inv(sufm[r]) % mod; n   return ret; n } n int main() { n   std::ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> p[i]; n   sufm[n + 1] = 1; n   for (int i = n; i >= 1; i--) { n     sufm[i] = sufm[i + 1] * (100 * inv(p[i]) % mod) % mod; n     sufsum[i] = (sufsum[i + 1] + sufm[i]) % mod; n   } n   long long ans = sufsum[1]; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n  n using namespace std; n #define  ll long long n #define f first n #define s second n const int N = 2e5+5; n  n int n , dp[N] , ans; n vector<int> adj[N]; n  n void dfs(int node , int par) n { n     vector<int> v; n     for(auto ch : adj[node]) n     { n         if (ch==par) continue; n         dfs(ch , node); n         v.push_back(dp[ch]+1); n     } n     sort(v.begin() , v.end()); n  n     if (v.size()) n     { n         if (node != 1) n         { n             int mx = v.back() , mn = v[0]; n             if (adj[node].size() > 1) ans = max(ans , mx+1); n  n             dp[node] = mn; n         } n         else n         { n             int mx = v.back() , mn; n             v.pop_back(); n             if (v.size()) mn = v.back(); n             else mn = -1; //second maximum n  n             ans = max(ans , mn+1); n             ans = max(ans , mx); n             dp[node] = mx; n         } n     } n } n  n void clear() n { n     ans = 0; n     for(int i=1; i<=n; i++) n         adj[i].clear() , dp[i] = 0; n } n  n int main() n { n     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); n  n     int t; n     cin >> t; n     while(t--) n     { n         cin >> n; n         for(int i=1; i<n; i++) n         { n             int v,u; n             cin >> v >> u; n             adj[v].push_back(u) , adj[u].push_back(v); n         } n  n         dfs(1,1); n  n         cout << ans <<   n ; n  n         clear(); n     } n  n  n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n; n   cin >> n; n   int a[n][2]; n   int l = 0, r = 0; n   for (int i = 0; i < n; i++) { n     cin >> a[i][0] >> a[i][1]; n     l += a[i][0]; n     r += a[i][1]; n   } n   int ans = abs(l - r); n   int ind = 0; n   int res = ans; n   for (int i = 0; i < n; i++) { n     int temp; n     temp = abs(l - r + 2 * (a[i][1]) - 2 * a[i][0]); n     if (temp > res) { n       res = temp; n       ind = i + 1; n     } n   } n   cout << ind << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e7 + 5; n int l, r, x, y; n char c; n int main() { n   cin >> l >> c >> r; n   cin >> x >> c >> y; n   l = l * 60 + r; n   x = x * 60 + y; n   l = l - x; n   if (l < 0) { n     l += 24 * 60; n   } n   printf( %02d:%02d n , l / 60, l % 60); 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(NULL); n   long long int tc; n   cin >> tc; n   while (tc-- > 0) { n     long long int n; n     cin >> n; n     if (n % 2 == 0) { n       long long int a = 2; n       long long int b = n / 2; n       cout << a <<     << b <<   n ; n     } else { n       cout << 2 <<     << n - 1 <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200 + 10; n int main() { n   int n, arr[N]; n   char f; n   char ch[N]; n   scanf( %d , &n); n   cin >> ch; n   n = 2 * n; n   for (int i = 0; i < n; i++) arr[i] = ch[i] -  0 ; n   sort(arr, arr + n / 2); n   sort(arr + n / 2, arr + n); n   bool a = false, b = false; n   for (int i = 0; i < n / 2; i++) { n     if (arr[i] >= arr[n / 2 + i]) a = true; n     if (arr[i] <= arr[n / 2 + i]) b = true; n   } n   if (a && b) n     cout <<  NO ; n   else n     cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   long long int i, j, a, b, ans; n   for (i = 1; i <= t; i++) { n     cin >> a >> b; n     ans = 0; n     while ((a + b + ans * (ans + 1) / 2) % 2 != 0 || n            (a + b + ans * (ans + 1) / 2) < 2 * max(a, b)) { n       ans++; n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct point { n   long long x, a; n } p[100]; n int n; n long long key[100][100]; n long long k[100]; n long long s[3], ans; n long long v; n void getb(long long ab, long long b, int cur) { n   if (ab < b * b) return; n   if (cur > n + 1) return; n   if (cur == n + 1) { n     long long a = ab / b; n     long long c = v / ab; n     long long tmp = a * c + ab + b * c; n     if (tmp < ans) { n       ans = tmp; n       s[0] = a, s[1] = b, s[2] = c; n     } n     return; n   } n   int t = p[cur].a - k[cur]; n   for (int i = t; i >= 0; i--) { n     getb(ab, b * key[cur][i], cur + 1); n   } n } n void dfs(long long c, int cur) { n   if (v / c < c * c || cur > n + 1) return; n   if (cur == n + 1) { n     long long ab = v / c; n     if (ab + 2 * sqrt(1.0 * v * c) <= ans) { n       getb(ab, 1, 1); n     } n     return; n   } n   for (int i = p[cur].a; i >= 0; i--) { n     k[cur] = i; n     dfs(c * key[cur][i], cur + 1); n   } n } n int main() { n   int cas; n   long long suma, sumb; n   scanf( %d , &cas); n   while (cas--) { n     scanf( %d , &n); n     v = 1; n     for (int i = 1; i <= n; i++) { n       cin >> p[i].x >> p[i].a; n       long long t = 1; n       key[i][0] = 1; n       for (int j = 1; j <= p[i].a; j++) { n         t *= p[i].x; n         key[i][j] = t; n       } n       v *= t; n     } n     ans = 2 * v + 1; n     s[0] = v, s[1] = s[2] = 1; n     dfs(1, 1); n     ans *= 2; n     cout << ans <<     << s[0] <<     << s[1] <<     << s[2] << endl; n   } n   return 0; n } n