#include <bits/stdc++.h> n using namespace std; n using namespace std::chrono; n template <class T> n bool cmin(T& a, const T& b) { n   return b < a ? a = b, 1 : 0; n } n template <class T> n bool cmax(T& a, const T& b) { n   return a < b ? a = b, 1 : 0; n } n struct starter { n   high_resolution_clock::time_point t1, t2; n   starter() { n     ios::sync_with_stdio(0); n     cin.tie(0); n     t1 = high_resolution_clock::now(); n   } n   ~starter() { n     t2 = high_resolution_clock::now(); n     duration<double> time_span = duration_cast<duration<double>>(t2 - t1); n     cerr <<  It took   << time_span.count() <<   seconds. ; n   } n } starter_; n const int64_t MOD = 998244353; n struct mi { n   using ll = long long; n   ll v; n   explicit operator ll() const { return v; } n   mi() { v = 0; } n   mi(ll _v) { n     v = (-MOD < _v && _v < MOD) ? _v : _v % MOD; n     if (v < 0) v += MOD; n   } n   friend bool operator==(const mi& a, const mi& b) { return a.v == b.v; } n   friend bool operator!=(const mi& a, const mi& b) { return !(a == b); } n   friend bool operator<(const mi& a, const mi& b) { return a.v < b.v; } n   mi& operator+=(const mi& m) { n     if ((v += m.v) >= MOD) v -= MOD; n     return *this; n   } n   mi& operator-=(const mi& m) { n     if ((v -= m.v) < 0) v += MOD; n     return *this; n   } n   mi& operator*=(const mi& m) { n     v = v * m.v % MOD; n     return *this; n   } n   mi& operator/=(const mi& m) { return (*this) *= inv(m); } n   friend mi pow(mi a, ll p) { n     mi ans = 1; n     assert(p >= 0); n     for (; p; p /= 2, a *= a) n       if (p & 1) ans *= a; n     return ans; n   } n   friend mi inv(const mi& a) { n     assert(a.v != 0); n     return pow(a, MOD - 2); n   } n   mi operator-() const { return mi(-v); } n   mi& operator++() { return *this += 1; } n   mi& operator--() { return *this -= 1; } n   mi operator++(int32_t) { n     mi temp; n     temp.v = v++; n     return temp; n   } n   mi operator--(int32_t) { n     mi temp; n     temp.v = v--; n     return temp; n   } n   friend mi operator+(mi a, const mi& b) { return a += b; } n   friend mi operator-(mi a, const mi& b) { return a -= b; } n   friend mi operator*(mi a, const mi& b) { return a *= b; } n   friend mi operator/(mi a, const mi& b) { return a /= b; } n   friend ostream& operator<<(ostream& os, const mi& m) { n     os << m.v; n     return os; n   } n   friend istream& operator>>(istream& is, mi& m) { n     ll x; n     is >> x; n     m.v = x; n     return is; n   } n }; n struct BIT { n   int64_t N; n   vector<int64_t> bit; n   void init(int64_t n) { n     N = n; n     bit.assign(n + 1, 0); n   } n   void update(int64_t idx, int64_t val) { n     while (idx <= N) { n       bit[idx] += val; n       idx += idx & -idx; n     } n   } n   void updateMax(int64_t idx, int64_t val) { n     while (idx <= N) { n       bit[idx] = max(bit[idx], val); n       idx += idx & -idx; n     } n   } n   int64_t pref(int64_t idx) { n     int64_t ans = 0; n     while (idx > 0) { n       ans += bit[idx]; n       idx -= idx & -idx; n     } n     return ans; n   } n   int64_t rsum(int64_t l, int64_t r) { return pref(r) - pref(l - 1); } n   int64_t prefMax(int64_t idx) { n     int64_t ans = -2e9; n     while (idx > 0) { n       ans = max(ans, bit[idx]); n       idx -= idx & -idx; n     } n     return ans; n   } n } T; n const int64_t inf = 1e18; n const int64_t N = 2e5 + 5; n int64_t n, p[N], have[N]; n int64_t unknown, cnt_unknown[N]; n int32_t main() { n   cin >> n; n   for (int64_t i = (1); i <= (n); ++i) { n     cin >> p[i]; n     if (~p[i]) { n       have[p[i]] = 1; n     } else { n       unknown++; n       cnt_unknown[i] = 1; n     } n   } n   for (int64_t i = (1); i <= (n); ++i) { n     cnt_unknown[i] += cnt_unknown[i - 1]; n     have[i] += have[i - 1]; n   } n   mi ans = mi(unknown) * (unknown - 1) / 2; n   ans /= 2; n   auto get_poss = [&](int64_t L, int64_t R) { n     if (L > R) return int64_t(0); n     return (R - L + 1) - (have[R] - have[L - 1]); n   }; n   if (unknown) n     for (int64_t i = (1); i <= (n); ++i) { n       if (p[i] == -1) continue; n       int64_t tot = cnt_unknown[i - 1]; n       int64_t poss = get_poss(p[i] + 1, n); n       ans += mi(tot) * poss / unknown; n     } n   if (unknown) n     for (int64_t i = n; i; --i) { n       if (p[i] == -1) continue; n       int64_t tot = cnt_unknown[n] - cnt_unknown[i - 1]; n       int64_t poss = unknown - get_poss(p[i] + 1, n); n       ans += mi(tot) * poss / unknown; n     } n   T.init(n); n   for (int64_t i = (1); i <= (n); ++i) { n     if (~p[i]) { n       ans += T.rsum(p[i] + 1, n); n       T.update(p[i], 1); n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n namespace io { n char ibuf[(1 << 20)], *iS, *iT, obuf[(1 << 20)], n     *oS = obuf, *oT = oS + (1 << 20) - 1, c, qu[55]; n int f, qr; n inline void flush(void) { n   return fwrite(obuf, 1, oS - obuf, stdout), oS = obuf, void(); n } n inline char getch(void) { n   return (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20), stdin), n                       (iS == iT ? EOF : *iS++)) n                    : *iS++); n } n inline void putch(char x) { n   *oS++ = x; n   if (oS == oT) flush(); n   return; n } n string getstr(void) { n   string s =   ; n   char c = getch(); n   while (c ==     || c ==   n  || c ==   r  || c ==   t  || c == EOF) n     c = getch(); n   while (!(c ==     || c ==   n  || c ==   r  || c ==   t  || c == EOF)) n     s.push_back(c), c = getch(); n   return s; n } n void putstr(string str, int begin = 0, int end = -1) { n   if (end == -1) end = str.size(); n   for (register int i = begin; i < end; i++) putch(str[i]); n   return; n } n template <typename T> n inline T read() { n   register T x = 0; n   for (f = 1, c = getch(); c <  0  || c >  9 ; c = getch()) n     if (c ==  - ) f = -1; n   for (x = 0; c <=  9  && c >=  0 ; c = getch()) x = x * 10 + (c & 15); n   return x * f; n } n template <typename T> n inline void write(const T& t) { n   register T x = t; n   if (!x) putch( 0 ); n   if (x < 0) putch( - ), x = -x; n   while (x) qu[++qr] = x % 10 +  0 , x /= 10; n   while (qr) putch(qu[qr--]); n   return; n } n struct Flusher_ { n   ~Flusher_() { flush(); } n } io_flusher_; n }  // namespace io n using io::getch; n using io::getstr; n using io::putch; n using io::putstr; n using io::read; n using io::write; n struct LCA { n   int lca, x, y; n }; n long long f[13][(1 << 13)]; n int n, m, q; n vector<pair<int, int> > edges; n vector<LCA> lca; n long long F(int p, int S) { n   if (~f[p][S]) return f[p][S]; n   S ^= 1 << p; n   int sp = 0; n   while (!(S >> sp & 1)) sp++; n   f[p][S ^ (1 << p)] = 0; n   for (register int i = S; i; i = (i - 1) & S) { n     if (!(i >> sp & 1)) continue; n     bool pass = false; n     for (vector<LCA>::iterator j = lca.begin(); j != lca.end(); j++) n       if (j->lca == p && (i >> j->x & 1) && (i >> j->y & 1)) pass = true; n     if (pass) continue; n     for (vector<LCA>::iterator j = lca.begin(); j != lca.end(); j++) n       if ((i >> j->lca & 1) && (!(i >> j->x & 1) || !(i >> j->y & 1))) n         pass = true; n     if (pass) continue; n     for (vector<pair<int, int> >::iterator j = edges.begin(); j != edges.end(); n          j++) n       if (j->first != p && j->second != p && n           ((i >> j->first & 1) ^ (i >> j->second & 1))) n         pass = true; n     if (pass) continue; n     bool choose = false; n     int ppp = 0; n     for (vector<pair<int, int> >::iterator j = edges.begin(); j != edges.end(); n          j++) n       if (j->first == p && (i >> j->second & 1)) n         choose ? pass = true : (choose = true, ppp = j->second); n       else if (j->second == p && (i >> j->first & 1)) n         choose ? pass = true : (choose = true, ppp = j->first); n     if (pass) continue; n     if (choose) n       f[p][S ^ (1 << p)] += F(ppp, i) * F(p, S ^ i ^ (1 << p)); n     else n       for (register int j = 0; j < n; j++) n         if (i >> j & 1) f[p][S ^ (1 << p)] += F(j, i) * F(p, S ^ i ^ (1 << p)); n   } n   return f[p][S ^ (1 << p)]; n } n int main() { n   memset(f, -1, sizeof(f)); n   n = read<int>(), m = read<int>(), q = read<int>(); n   while (m--) n     edges.push_back((pair<int, int>){read<int>() - 1, read<int>() - 1}); n   while (q--) { n     int a = read<int>() - 1, b = read<int>() - 1, c = read<int>() - 1; n     lca.push_back((LCA){c, a, b}); n   } n   for (register int i = 0; i < n; i++) f[i][1 << i] = 1; n   write(F(0, (1 << n) - 1)), putch(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   long long ar[n]; n   long long br[n]; n   for (auto x = 0; x < n; x++) { n     cin >> ar[x]; n     br[x] = ar[x]; n   } n   sort(br, br + n); n   long long m; n   cin >> m; n   while (m--) { n     long long pos, k; n     set<long long> s; n     cin >> k >> pos; n     long long bound = br[n - k]; n     vector<long long> q; n     for (int x = 0; x < n; x++) { n       if (bound <= ar[x]) { n         q.push_back(ar[x]); n       } n     } n     long long sub = q.size() - k; n     for (int x = q.size() - 1; x >= 0 && sub != 0; x--) { n       if (bound == q[x]) { n         q[x] = -1; n         sub--; n       } n       if (sub == 0) { n         break; n       } n     } n     for (int x = 0; x < q.size(); x++) { n       if (q[x] == -1) { n         continue; n       } n       pos--; n       if (pos == 0) cout << q[x] << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n, k; n   cin >> n >> k; n   if (n >= k) { n     cout << (k - 1) / 2 << endl; n   } else if (k - n > n) { n     cout <<  0  << endl; n   } else { n     cout << (n - (k - n) + 1) / 2 << endl; n   } n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k; n long long pow(long long a, int b) { n   if (b == 0) return 1; n   long long base = pow(a, b >> 1); n   base = base * base; n   if (b & 1) base = base * a; n   return base; n } n long long f(long long n) { n   if (n == 1) return 1; n   map<long long, int> factors; n   long long n_ = n; n   for (long long i = 2; i * i <= n_; i++) { n     while (n % i == 0) { n       factors[i]++; n       n /= i; n     } n   } n   if (n > 1) factors[n]++; n   long long ans = 1; n   for (pair<long long, int> p : factors) { n     ans *= pow(p.first, p.second) - pow(p.first, p.second - 1); n   } n   return ans; n } n int main() { n   scanf(  %lld %lld , &n, &k); n   for (int i = 0; i < (k + 1) / 2; i++) { n     n = f(n); n     if (n == 1) break; n   } n   printf( %lld n , n % 1000000007); n   return 0; n } n


#include <bits/stdc++.h> n int A[100020] = {0}; n int main() { n   int n, i, dis1, dis2 = 0, dis = 0, min; n   scanf( %d , &n); n   for (i = 1; i <= n; i++) { n     scanf( %d , &A[i]); n     if (min > A[i] || i == 1) min = A[i]; n   } n   for (i = 1; i <= n; i++) n     if (A[i] == min) { n       if (dis2 == 0) dis2 = i; n       dis1 = dis2; n       dis2 = i; n       if (dis > dis2 - dis1 || dis == 0) dis = dis2 - dis1; n     } n   printf( %d , dis); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string s, t; n   cin >> s; n   cin >> t; n   int sc[26] = {0}, tc[26] = {0}; n   for (int i = 0; i < n; i++) { n     sc[s[i] -  a ]++; n     tc[t[i] -  a ]++; n   } n   int flag = 1; n   for (int i = 0; i < 26; i++) { n     if (sc[i] == tc[i]) n       continue; n     else { n       cout << -1 << endl; n       flag = 0; n       break; n     } n   } n   if (flag == 1) { n     int k = 0, change[100005]; n     for (int i = 0; i < n; i++) n       if (s[i] == t[i]) n         continue; n       else n         for (int j = i + 1; j < n; j++) n           if (s[j] == t[i]) { n             while (j > i) { n               char temp = s[j]; n               s[j] = s[j - 1]; n               s[j - 1] = temp; n               change[k++] = j; n               j--; n             } n             break; n           } n     cout << k << endl; n     for (int i = 0; i < k; i++) cout << change[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int dblcmp(double x) { n   if (abs(x) < 1e-8) return 0; n   return (x > 0) ? 1 : -1; n } n inline double sqr(double x) { return x * x; } n const double pi = acos(-1.0); n struct point { n   double x, y; n   point() {} n   point(double _x, double _y) : x(_x), y(_y){}; n   void input() { scanf( %lf%lf , &x, &y); } n   void output() { printf( %.2f %.2f n , x, y); } n   bool operator==(point a) const { n     return dblcmp(a.x - x) == 0 && dblcmp(a.y - y) == 0; n   } n   bool operator<(point a) const { n     return dblcmp(a.x - x) == 0 ? dblcmp(y - a.y) < 0 : x < a.x; n   } n   double len() { return hypot(x, y); } n   double len2() { return x * x + y * y; } n   double distance(point p) { return hypot(x - p.x, y - p.y); } n   point add(point p) { return point(x + p.x, y + p.y); } n   point sub(point p) { return point(x - p.x, y - p.y); } n   point mul(double b) { return point(x * b, y * b); } n   point div(double b) { return point(x / b, y / b); } n   double dot(point p) { return x * p.x + y * p.y; } n   double det(point p) { return x * p.y - y * p.x; } n   double rad(point a, point b) { n     point p = *this; n     return fabs(atan2(fabs(a.sub(p).det(b.sub(p))), a.sub(p).dot(b.sub(p)))); n   } n   point trunc(double r) { n     double l = len(); n     if (!dblcmp(l)) return *this; n     r /= l; n     return point(x * r, y * r); n   } n   point rotleft() { return point(-y, x); } n   point rotright() { return point(y, -x); } n   point rotate(point p, double angle) { n     point v = this->sub(p); n     double c = cos(angle), s = sin(angle); n     return point(p.x + v.x * c - v.y * s, p.y + v.x * s + v.y * c); n   } n }; n struct line { n   point a, b; n   line() {} n   line(point _a, point _b) { n     a = _a; n     b = _b; n   } n   bool operator==(line v) { return (a == v.a) && (b == v.b); } n   line(point p, double angle) { n     a = p; n     if (dblcmp(angle - pi / 2) == 0) { n       b = a.add(point(0, 1)); n     } else { n       b = a.add(point(1, tan(angle))); n     } n   } n   line(double _a, double _b, double _c) { n     if (dblcmp(_a) == 0) { n       a = point(0, -_c / _b); n       b = point(1, -_c / _b); n     } else if (dblcmp(_b) == 0) { n       a = point(-_c / _a, 0); n       b = point(-_c / _a, 1); n     } else { n       a = point(0, -_c / _b); n       b = point(1, (-_c - _a) / _b); n     } n   } n   void input() { n     a.input(); n     b.input(); n   } n   void adjust() { n     if (b < a) swap(a, b); n   } n   double length() { return a.distance(b); } n   double angle() { n     double k = atan2(b.y - a.y, b.x - a.x); n     if (dblcmp(k) < 0) k += pi; n     if (dblcmp(k - pi) == 0) k -= pi; n     return k; n   } n   int relation(point p) { n     int c = dblcmp(p.sub(a).det(b.sub(a))); n     if (c < 0) return 1; n     if (c > 0) return 2; n     return 3; n   } n   bool pointonseg(point p) { n     return dblcmp(p.sub(a).det(b.sub(a))) == 0 && n            dblcmp(p.sub(a).dot(p.sub(b))) <= 0; n   } n   bool parallel(line v) { return dblcmp(b.sub(a).det(v.b.sub(v.a))) == 0; } n   int segcrossseg(line v) { n     int d1 = dblcmp(b.sub(a).det(v.a.sub(a))); n     int d2 = dblcmp(b.sub(a).det(v.b.sub(a))); n     int d3 = dblcmp(v.b.sub(v.a).det(a.sub(v.a))); n     int d4 = dblcmp(v.b.sub(v.a).det(b.sub(v.a))); n     if ((d1 ^ d2) == -2 && (d3 ^ d4) == -2) return 2; n     return (d1 == 0 && dblcmp(v.a.sub(a).dot(v.a.sub(b))) <= 0 || n             d2 == 0 && dblcmp(v.b.sub(a).dot(v.b.sub(b))) <= 0 || n             d3 == 0 && dblcmp(a.sub(v.a).dot(a.sub(v.b))) <= 0 || n             d4 == 0 && dblcmp(b.sub(v.a).dot(b.sub(v.b))) <= 0); n   } n   int linecrossseg(line v) { n     int d1 = dblcmp(b.sub(a).det(v.a.sub(a))); n     int d2 = dblcmp(b.sub(a).det(v.b.sub(a))); n     if ((d1 ^ d2) == -2) return 2; n     return (d1 == 0 || d2 == 0); n   } n   int linecrossline(line v) { n     if ((*this).parallel(v)) { n       return v.relation(a) == 3; n     } n     return 2; n   } n   point crosspoint(line v) { n     double a1 = v.b.sub(v.a).det(a.sub(v.a)); n     double a2 = v.b.sub(v.a).det(b.sub(v.a)); n     return point((a.x * a2 - b.x * a1) / (a2 - a1), n                  (a.y * a2 - b.y * a1) / (a2 - a1)); n   } n   double dispointtoline(point p) { n     return fabs(p.sub(a).det(b.sub(a))) / length(); n   } n   double dispointtoseg(point p) { n     if (dblcmp(p.sub(b).dot(a.sub(b))) < 0 || n         dblcmp(p.sub(a).dot(b.sub(a))) < 0) { n       return min(p.distance(a), p.distance(b)); n     } n     return dispointtoline(p); n   } n   point lineprog(point p) { n     return a.add(b.sub(a).mul(b.sub(a).dot(p.sub(a)) / b.sub(a).len2())); n   } n   point symmetrypoint(point p) { n     point q = lineprog(p); n     return point(2 * q.x - p.x, 2 * q.y - p.y); n   } n }; n int N; n line bas[110]; n point ret[110]; n int main() { n   scanf( %d , &N); n   if (N < 5) { n     puts( No solution ); n     return 0; n   } n   double minOO = 249.66 / tan(acos(-1.0) / N); n   double maxOO = 250.33 / tan(acos(-1.0) / N); n   int i; n   srand(23333); n   for (i = 1; i <= N; i++) { n     int factor = rand(); n     double len = (maxOO * factor + minOO * (32768 - factor)) / 32768; n     bas[i] = line(point(0, 0), n                   point(len * cos(2 * pi / N * i), len * sin(2 * pi / N * i))); n     bas[i].a = bas[i].a.rotate(bas[i].b, pi / 2); n   } n   for (i = 1; i <= N; i++) { n     ret[i] = bas[i].crosspoint(bas[i % N + 1]); n     printf( %.6f %.6f n , ret[i].x, ret[i].y); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k; n bool check(long long mid) { n   long long sum = (mid + k - 1) * (k - mid) / 2; n   return (sum >= n - 1); n } n int main() { n   scanf( %I64d%I64d , &n, &k); n   if (n == 1) { n     printf( 0 ); n     return 0; n   } n   long long l = 1, r = k - 1, mid; n   while (l < r) { n     mid = (l + r + 1) >> 1; n     if (check(mid)) n       l = mid; n     else n       r = mid - 1; n   } n   if ((l + k - 1) * (k - l) / 2 >= n - 1) n     printf( %I64d , k - l); n   else n     printf( -1 ); 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   ; n   int n, a = 0, b = 0; n   cin >> n; n   string str; n   cin >> str; n   for (int i = 0; i < n - 1; i++) { n     if (str[i] ==  S  && str[i + 1] ==  F ) n       a++; n     else if (str[i] ==  F  && str[i + 1] ==  S ) n       b++; n   } n   if (a > b) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1E5 + 10; n const int INF = 1E9 + 10; n int n; n int a[MAXN][4]; n int d[MAXN]; n int dis[MAXN], pre[MAXN]; n vector<int> lst[MAXN]; n int val[MAXN << 2]; n int choose(int l, int r) { n   return a[lst[l].back()][1] < a[lst[r].back()][1] ? l : r; n } n void build(int u, int l, int r) { n   if (l + 1 == r) { n     val[u] = l; n     return; n   } n   int m = l + r >> 1; n   build(u << 1, l, m); n   build(u << 1 | 1, m, r); n   val[u] = choose(val[u << 1], val[u << 1 | 1]); n } n int query(int u, int l, int r, int c) { n   if (r <= c) return val[u]; n   int m = l + r >> 1, ret = query(u << 1, l, m, c); n   if (m < c) ret = choose(ret, query(u << 1 | 1, m, r, c)); n   return ret; n } n void update(int u, int l, int r, int c) { n   if (l + 1 == r) return; n   int m = l + r >> 1; n   if (c < m) n     update(u << 1, l, m, c); n   else n     update(u << 1 | 1, m, r, c); n   val[u] = choose(val[u << 1], val[u << 1 | 1]); n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d%d%d%d , &a[i][0], &a[i][1], &a[i][2], &a[i][3]); n     d[i] = a[i][0]; n   } n   sort(d, d + n); n   int m = unique(d, d + n) - d; n   for (int i = 0; i < n; ++i) n     lst[lower_bound(d, d + m, a[i][0]) - d].push_back(i); n   a[n][1] = INF; n   a[n][2] = a[n][3] = 0; n   for (int i = 0; i < m; ++i) { n     lst[i].push_back(n); n     sort(lst[i].begin(), lst[i].end(), n          [](const int &l, const int &r) { return a[l][1] > a[r][1]; }); n   } n   build(1, 0, m); n   queue<int> Q; n   dis[n] = 0; n   for (int i = 0; i <= n; ++i) pre[i] = -1; n   Q.push(n); n   while (!Q.empty() && !~pre[n - 1]) { n     int u = Q.front(); n     Q.pop(); n     int v, r = upper_bound(d, d + m, a[u][2]) - d; n     while (r && a[lst[v = query(1, 0, m, r)].back()][1] <= a[u][3]) { n       dis[lst[v].back()] = dis[u] + 1; n       pre[lst[v].back()] = u; n       Q.push(lst[v].back()); n       lst[v].pop_back(); n       update(1, 0, m, v); n     } n   } n   if (~pre[n - 1]) { n     printf( %d n , dis[n - 1]); n     vector<int> ans; n     for (int p = n - 1; p < n; p = pre[p]) ans.push_back(p + 1); n     for (int i = ans.size() - 1; i >= 0; --i) n       printf( %d%c , ans[i],   n  [!!i]); n   } else n     puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int f[105][105]; n string sa[105], sb[105]; n void solve() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> sa[i]; n   } n   sort(sa + 1, sa + n + 1); n   for (int i = 1; i <= n; ++i) { n     cin >> sb[i]; n   } n   sort(sb + 1, sb + n + 1); n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= n; ++j) { n       f[i][j] = max(f[i - 1][j], f[i][j - 1]); n       if (sa[i] == sb[j]) f[i][j] = max(f[i][j], f[i - 1][j - 1] + 1); n     } n   } n   cout << n - f[n][n]; n } n int main() { solve(); } n


#include <bits/stdc++.h> n using namespace std; n using namespace std::chrono; n using ll = long long; n using ld = long double; n using pt = complex<ld>; n constexpr ld EPS = 1e-9; n ld cross(pt a, pt b) { return imag(conj(a) * b); } n ld cross(pt p, pt a, pt b) { return cross(a - p, b - p); } n int orientation(pt a, pt b, pt c) { n   ld orien = cross(b - a, c - a); n   return (orien > EPS) - (orien < -EPS); n } n bool lineSegmentIntersection(pt a, pt b, pt c, pt d) { n   if (orientation(a, b, c) == 0 && orientation(a, b, d) == 0) { n     ld dist = abs(a - b); n     return (abs(a - c) <= dist && abs(b - c) <= dist) || n            (abs(a - d) <= dist && abs(b - d) <= dist); n   } n   return orientation(a, b, c) * orientation(a, b, d) <= 0 && n          orientation(c, d, a) * orientation(c, d, b) <= 0; n } n struct seg { n   pt a, b; n   ll id; n   bool operator<(const seg& o) const { n     if (real(a) < real(o.a)) { n       ld s = cross(a, b, o.a); n       return (s > EPS || (abs(s) <= EPS && imag(a) < imag(o.a))); n     } else if (real(a) > real(o.a)) { n       ld s = cross(o.a, o.b, a); n       return (s < EPS || (abs(s) <= EPS && imag(a) < imag(o.a))); n     } n     return imag(a) < imag(o.a); n   } n }; n struct event { n   pt p; n   ll id, type; n   bool operator<(const event& o) const { n     if (real(p) != real(o.p)) return real(p) < real(o.p); n     if (type != o.type) return type > o.type; n     return imag(p) < imag(o.p); n   } n }; n bool lessPs(const pt& a, const pt& b) { n   if (real(a) != real(b)) return real(a) < real(b); n   return imag(a) < imag(b); n } n bool intersect(const seg& a, const seg& b) { n   return lineSegmentIntersection(a.a, a.b, b.a, b.b); n } n pair<int, int> intersect(const vector<seg>& s) { n   ll n = (ll)(s).size(); n   vector<event> e; n   e.reserve(2 * n); n   for (ll i = 0; i < n; i++) { n     e.push_back({s[i].a, i, 1}); n     e.push_back({s[i].b, i, -1}); n   } n   sort(begin(e), end(e)); n   set<seg> q; n   for (ll i = 0; i < n * 2; i++) { n     ll id = e[i].id; n     if (e[i].type == 1) { n       auto it = q.lower_bound(s[id]); n       if (it != q.end() && intersect(*it, s[id])) return {it->id, s[id].id}; n       if (it != q.begin() && intersect(*prev(it), s[id])) n         return {it->id, s[id].id}; n       q.insert(s[id]); n     } else { n       auto it = q.lower_bound(s[id]), next = it, prev = it; n       if (it != q.begin() && it != --q.end()) { n         ++next, --prev; n         if (intersect(*next, *prev)) return {next->id, prev->id}; n       } n       q.erase(it); n     } n   } n   return {-1, -1}; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   ll n; n   cin >> n; n   vector<pt> p(n), d(n); n   for (ll i = 0; i < n; i++) { n     ll x, y, dx, dy, s; n     cin >> x >> y >> dx >> dy >> s; n     p[i] = {(ld)x, (ld)y}; n     d[i] = {(ld)dx, (ld)dy}; n     d[i] /= abs(d[i]); n     d[i] *= s; n   } n   ld l = 0; n   ld r = 1e10 + 10; n   vector<seg> segs(n); n   for (ll i = 0; i < 100; i++) { n     ld mid = (l + r) / 2; n     for (ll j = 0; j < n; j++) { n       segs[j] = {p[j], p[j] + mid * d[j], j}; n       if (lessPs(segs[j].b, segs[j].a)) swap(segs[j].b, segs[j].a); n     } n     if (intersect(segs).first >= 0) { n       r = mid; n     } else { n       l = mid; n     } n   } n   if (r > 1e10) { n     cout <<  No show :(  << endl; n   } else { n     cout << fixed << setprecision(10) << l << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct Node { n   int len, link; n   int nxt[26]; n   long long val; n }; n struct Automaton { n   int sz, last; n   Node s[200100 * 10]; n   void init() { n     sz = last = 0; n     s[0].len = 0; n     s[0].link = -1; n     s[0].val = 0; n     memset(s[0].nxt, 0, sizeof(s[0].nxt)); n     ++sz; n   } n   void extend(int c, int cost) { n     int cur, p; n     if (s[last].nxt[c]) { n       cur = s[last].nxt[c]; n       if (s[cur].len == s[last].len + 1) { n         s[cur].val += cost; n         last = cur; n         return; n       } n       int clone = sz++; n       s[clone] = s[cur]; n       s[clone].len = s[last].len + 1; n       s[clone].val = cost; n       s[cur].link = clone; n       for (p = last; p != -1 && s[p].nxt[c] == cur; p = s[p].link) n         s[p].nxt[c] = clone; n       last = clone; n       return; n     } n     cur = sz++; n     s[cur].len = s[last].len + 1; n     s[cur].val = cost; n     for (p = last; p != -1 && !s[p].nxt[c]; p = s[p].link) s[p].nxt[c] = cur; n     if (p == -1) n       s[cur].link = 0; n     else { n       int q = s[p].nxt[c]; n       if (s[p].len + 1 == s[q].len) n         s[cur].link = q; n       else { n         int clone = sz++; n         s[clone].len = s[p].len + 1; n         memcpy(s[clone].nxt, s[q].nxt, sizeof(s[q].nxt)); n         s[clone].link = s[q].link; n         s[clone].val = 0; n         for (; p != -1 && s[p].nxt[c] == q; p = s[p].link) s[p].nxt[c] = clone; n         s[q].link = s[cur].link = clone; n       } n     } n     last = cur; n   } n   int cnt[10 * 200100], st[10 * 200100]; n   long long solve(int len) { n     int i, j; n     for (j = 0; j <= len; j++) cnt[j] = 0; n     for (j = 0; j < sz; j++) cnt[s[j].len]++; n     for (j = 1; j <= len; j++) cnt[j] += cnt[j - 1]; n     for (j = 0; j < sz; j++) st[cnt[s[j].len]--] = j; n     long long ret = 0; n     for (i = sz; i >= 1; i--) { n       int x = st[i]; n       if (ret < s[x].val * s[x].len) ret = s[x].val * s[x].len; n       int p = s[x].link; n       if (p != -1) s[p].val += s[x].val; n     } n     return ret; n   } n } sam; n string str[200100]; n int c[200100]; n int main() { n   int N, i, len = 0; n   scanf( %d , &N); n   for (i = (0); i < (N); i++) cin >> str[i]; n   for (i = (0); i < (N); i++) scanf( %d , &c[i]); n   sam.init(); n   for (i = (0); i < (N); i++) { n     sam.last = 0; n     for (int j = 0; j < str[i].length(); j++) { n       sam.extend(str[i][j] -  a , c[i]); n     } n     if (len < str[i].length()) len = str[i].length(); n   } n   long long ans = sam.solve(len); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t, n; n long double ang, ca, PI = acos(-1); n int main() { n   ; n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> t; n   while (t--) { n     cin >> n; n     ang = 2 * PI / (2 * n); n     ca = 0.5 / tan(ang / 2); n     cout << fixed << setprecision(10) << 2 * ca <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int h, m, s, t1, t2; n   cin >> h >> m >> s >> t1 >> t2; n   h %= 12; n   t1 %= 12; n   t2 %= 12; n   m /= 5; n   s /= 5; n   if (t1 > t2) swap(t1, t2); n   if (((h >= t1 && h < t2) + (m >= t1 && m < t2) + (s >= t1 && s < t2)) % 3 == n       0) { n     cout <<  YES ; n   } else n     cout <<  NO ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int key(int x); n int main() { n   int t; n   cin >> t; n   int str[t]; n   for (int u = 0; u < t; u++) { n     str[u] = key(u); n   } n   for (int u = 0; u < t; u++) cout << str[u] <<   n ; n   return 0; n } n int key(int x) { n   int n, k, d, mini = 1000, m = 0; n   cin >> n >> k >> d; n   int arr[n], c = 0; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   for (int j = 0; j < n - d + 1; j++) { n     for (int a = 0; a < d; a++) { n       m = 0; n       for (int b = 0; b <= a; b++) { n         if (arr[j + a] == arr[j + b]) n           m++; n         else n           continue; n       } n       if (m <= 1) c++; n     } n     mini = min(mini, c); n     c = 0; n   } n   return mini; n } n


#include <bits/stdc++.h> n int allocator_pos = 0; n char allocator_memory[(int)1e5]; n inline void *operator new(size_t n) { n   char *res = allocator_memory + allocator_pos; n   allocator_pos += n; n   assert(allocator_pos <= (int)1e5); n   return (void *)res; n } n inline void operator delete(void *) noexcept {} n template <class T = int> n inline T readInt(); n inline double readDouble(); n inline int readUInt(); n inline int readChar(); n inline void readWord(char *s); n inline bool readLine(char *s); n inline bool isEof(); n inline int getChar(); n inline int peekChar(); n inline bool seekEof(); n inline void skipBlanks(); n template <class T> n inline void writeInt(T x, char end = 0, int len = -1); n inline void writeChar(int x); n inline void writeWord(const char *s); n inline void writeDouble(double x, int len = 0); n inline void flush(); n static struct buffer_flusher_t { n   ~buffer_flusher_t() { flush(); } n } buffer_flusher; n static const int buf_size = 4096; n static unsigned char buf[buf_size]; n static int buf_len = 0, buf_pos = 0; n inline bool isEof() { n   if (buf_pos == buf_len) { n     buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin); n     if (buf_pos == buf_len) return 1; n   } n   return 0; n } n inline int getChar() { return isEof() ? -1 : buf[buf_pos++]; } n inline int peekChar() { return isEof() ? -1 : buf[buf_pos]; } n inline bool seekEof() { n   int c; n   while ((c = peekChar()) != -1 && c <= 32) buf_pos++; n   return c == -1; n } n inline void skipBlanks() { n   while (!isEof() && buf[buf_pos] <= 32U) buf_pos++; n } n inline int readChar() { n   int c = getChar(); n   while (c != -1 && c <= 32) c = getChar(); n   return c; n } n inline int readUInt() { n   int c = readChar(), x = 0; n   while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getChar(); n   return x; n } n template <class T> n inline T readInt() { n   int s = 1, c = readChar(); n   T x = 0; n   if (c ==  - ) n     s = -1, c = getChar(); n   else if (c ==  + ) n     c = getChar(); n   while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getChar(); n   return s == 1 ? x : -x; n } n inline double readDouble() { n   int s = 1, c = readChar(); n   double x = 0; n   if (c ==  - ) s = -1, c = getChar(); n   while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getChar(); n   if (c ==  . ) { n     c = getChar(); n     double coef = 1; n     while ( 0  <= c && c <=  9 ) x += (c -  0 ) * (coef *= 1e-1), c = getChar(); n   } n   return s == 1 ? x : -x; n } n inline void readWord(char *s) { n   int c = readChar(); n   while (c > 32) *s++ = c, c = getChar(); n   *s = 0; n } n inline bool readLine(char *s) { n   int c = getChar(); n   while (c !=   n  && c != -1) *s++ = c, c = getChar(); n   *s = 0; n   return c != -1; n } n static int write_buf_pos = 0; n static char write_buf[buf_size]; n inline void writeChar(int x) { n   if (write_buf_pos == buf_size) n     fwrite(write_buf, 1, buf_size, stdout), write_buf_pos = 0; n   write_buf[write_buf_pos++] = x; n } n inline void flush() { n   if (write_buf_pos) { n     fwrite(write_buf, 1, write_buf_pos, stdout), write_buf_pos = 0; n     fflush(stdout); n   } n } n template <class T> n inline void writeInt(T x, char end, int output_len) { n   if (x < 0) writeChar( - ), x = -x; n   char s[24]; n   int n = 0; n   while (x || !n) s[n++] =  0  + x % 10, x /= 10; n   while (n < output_len) s[n++] =  0 ; n   while (n--) writeChar(s[n]); n   if (end) writeChar(end); n } n inline void writeWord(const char *s) { n   while (*s) writeChar(*s++); n } n inline void writeDouble(double x, int output_len) { n   if (x < 0) writeChar( - ), x = -x; n   int t = (int)x; n   writeInt(t), x -= t; n   writeChar( . ); n   for (int i = output_len - 1; i > 0; i--) { n     x *= 10; n     t = std::min(9, (int)x); n     writeChar( 0  + t), x -= t; n   } n   x *= 10; n   t = std::min(9, (int)(x + 0.5)); n   writeChar( 0  + t); n } n #pragma GCC optimaze( O3,unroll-loops ) n #pragma GCC target( sse4,sse3,sse2,sse ) n using namespace std; n int a[20005], b[20005], n, m, p; n int dp1[3][20005], dp2[3][20005]; n int f(int x, int y) { n   int r = a[x] + b[y]; n   if (r < p) n     return r; n   else n     return r - p; n } n void get_ans(int x1, int y1, int x2, int y2) { n   if (x1 == x2) { n     for (int i = y1; i < y2; i++) writeChar( S ); n     return; n   } n   if (y1 == y2) { n     for (int i = x1; i < x2; i++) writeChar( C ); n     return; n   } n   int mid = (x1 + y1 + x2 + y2) / 2; n   dp1[0][x2] = f(n - x2, m - y2); n   int x = 0, y = 0, i1, i2; n   for (i1 = x2 + y2, i2 = x1 + y1; i1 > mid && i2 < mid; i1--, i2++) { n     for (int j = max(x1, i1 - y2); j <= min(x2, i1 - y1); j++) { n       int z = i1 - j; n       if (j != x1) n         dp1[x ^ 1][j - 1] = n             max(dp1[x ^ 1][j - 1], dp1[x][j] + f(n - j + 1, m - z)); n       if (z != y1) n         dp1[x ^ 1][j] = max(dp1[x ^ 1][j], dp1[x][j] + f(n - j, m - z + 1)); n       dp1[x][j] = 0; n     } n     x ^= 1; n     for (int j = max(x1, i2 - y2); j <= min(x2, i2 - y1); j++) { n       int z = i2 - j; n       if (j != x2) n         dp2[y ^ 1][j + 1] = max(dp2[y ^ 1][j + 1], dp2[y][j] + f(n - j, m - z)); n       if (z != y2) n         dp2[y ^ 1][j] = max(dp2[y ^ 1][j], dp2[y][j] + f(n - j, m - z)); n       dp2[y][j] = 0; n     } n     y ^= 1; n   } n   if (i1 > mid) { n     for (int j = max(x1, i1 - y2); j <= min(x2, i1 - y1); j++) { n       int z = i1 - j; n       if (j != x1) n         dp1[x ^ 1][j - 1] = n             max(dp1[x ^ 1][j - 1], dp1[x][j] + f(n - j + 1, m - z)); n       if (z != y1) n         dp1[x ^ 1][j] = max(dp1[x ^ 1][j], dp1[x][j] + f(n - j, m - z + 1)); n       dp1[x][j] = 0; n     } n     x ^= 1; n   } n   if (i2 < mid) { n     for (int j = max(x1, i2 - y2); j <= min(x2, i2 - y1); j++) { n       int z = i2 - j; n       if (j != x2) n         dp2[y ^ 1][j + 1] = max(dp2[y ^ 1][j + 1], dp2[y][j] + f(n - j, m - z)); n       if (z != y2) n         dp2[y ^ 1][j] = max(dp2[y ^ 1][j], dp2[y][j] + f(n - j, m - z)); n       dp2[y][j] = 0; n     } n     y ^= 1; n   } n   int posx = -1, tek = -1; n   for (int i = max(x1, mid - y2); i <= min(x2, mid - y1); i++) { n     if (tek < dp1[x][i] + dp2[y][i]) posx = i, tek = dp1[x][i] + dp2[y][i]; n     dp1[x][i] = 0, dp2[y][i] = 0; n   } n   if (x1 == 1 && y1 == 1 && x2 == n && y2 == m) { n     writeInt(tek); n     writeChar(  n ); n   } n   get_ans(posx, mid - posx, x2, y2); n   get_ans(x1, y1, posx, mid - posx); n   return; n } n int main() { n   n = readInt(); n   m = readInt(); n   p = readInt(); n   for (int i = 0; i < n; i++) { n     a[i] = readInt(); n     a[i] %= p; n   } n   for (int i = 0; i < m; i++) { n     b[i] = readInt(); n     b[i] %= p; n   } n   if (n == 1) { n     int ans = 0; n     for (int i = 0; i < m; i++) ans += f(0, i); n     writeInt(ans); n     writeChar(  n ); n     for (int i = 1; i < m; i++) writeChar( S ); n     exit(0); n   } n   if (m == 1) { n     int ans = 0; n     for (int i = 0; i < n; i++) ans += f(i, 0); n     writeInt(ans); n     writeChar(  n ); n     for (int i = 1; i < n; i++) writeChar( C ); n     exit(0); n   } n   get_ans(1, 1, n, m); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[200]; n   int t, n, x; n   for (int i = 0; i <= 100; i++) a[i] = 0; n   for (int i = 0; i <= 100; i++) n     for (int j = 0; j <= 100; j++) { n       t = 3 * i + 7 * j; n       if (t > 100) break; n       a[t] = 1; n     } n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> x; n     if (a[x] == 0) cout <<  NO  << endl; n     if (a[x] == 1) cout <<  YES  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class t> n inline t read(t &x) { n   x = 0; n   char c = getchar(); n   bool f = 0; n   while (!isdigit(c)) f |= c ==  - , c = getchar(); n   while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); n   if (f) x = -x; n   return x; n } n template <class t> n inline void write(t x) { n   if (x < 0) { n     putchar( - ), write(-x); n   } else { n     if (x > 9) write(x / 10); n     putchar( 0  + x % 10); n   } n } n const int N = 1e5 + 5, M = 1e4 + 5, NM = N * 4 + M, TR = NM << 2; n int n, m, pt[NM], pn; n double p[TR], ans; n struct tree { n   int x, h, l, r; n } a[N]; n struct mushroom { n   int x, v; n } b[M]; n void build(int x, int l, int r) { n   p[x] = 1; n   if (l == r) return; n   int mid = l + r >> 1; n   build(x << 1, l, mid); n   build(x << 1 | 1, mid + 1, r); n } n void up(int x, int l, int r, int L, int R, double v) { n   if (L <= l && r <= R) { n     p[x] *= v; n     return; n   } n   int mid = l + r >> 1; n   if (L <= mid) up(x << 1, l, mid, L, R, v); n   if (R > mid) up(x << 1 | 1, mid + 1, r, L, R, v); n } n double que(int x, int l, int r, int pos) { n   if (l == r) return p[x]; n   int mid = l + r >> 1; n   if (pos <= mid) return p[x] * que(x << 1, l, mid, pos); n   return p[x] * que(x << 1 | 1, mid + 1, r, pos); n } n signed main() { n   read(n); n   read(m); n   for (int i = 1; i <= n; i++) { n     read(a[i].x); n     read(a[i].h); n     read(a[i].l); n     read(a[i].r); n     pt[++pn] = a[i].x - a[i].h; n     pt[++pn] = a[i].x - 1; n     pt[++pn] = a[i].x + 1; n     pt[++pn] = a[i].x + a[i].h; n   } n   for (int i = 1; i <= m; i++) { n     read(b[i].x); n     read(b[i].v); n     pt[++pn] = b[i].x; n   } n   sort(pt + 1, pt + 1 + pn); n   pn = unique(pt + 1, pt + 1 + pn) - pt - 1; n   build(1, 1, pn); n   for (int i = 1; i <= n; i++) { n     up(1, 1, pn, lower_bound(pt + 1, pt + 1 + pn, a[i].x - a[i].h) - pt, n        lower_bound(pt + 1, pt + 1 + pn, a[i].x - 1) - pt, 1.0 - 0.01 * a[i].l); n     up(1, 1, pn, lower_bound(pt + 1, pt + 1 + pn, a[i].x + 1) - pt, n        lower_bound(pt + 1, pt + 1 + pn, a[i].x + a[i].h) - pt, n        1.0 - 0.01 * a[i].r); n   } n   for (int i = 1; i <= m; i++) n     ans += n         que(1, 1, pn, lower_bound(pt + 1, pt + 1 + pn, b[i].x) - pt) * b[i].v; n   printf( %.10lf , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 3e5 + 10; n const long long MAXE = 3e5 + 10; n const long long INF = 2e18 + 3; n long long n, m, k, ec; n long long from[2 * MAXE], to[2 * MAXE], prv[2 * MAXE], w[2 * MAXE], head[MAXN], n     sec[2 * MAXE]; n long long comp[MAXN], d[MAXN], ss[MAXN]; n bool portal[MAXN], mark[MAXN]; n set<pair<long long, long long>> st; n long long ans = 0; n void add_edge(long long u, long long v, long long c) { n   from[ec] = u, to[ec] = v, w[ec] = c, prv[ec] = head[u]; n   head[u] = ec++; n } n long long get_min() { n   pair<long long, long long> fr = *st.begin(); n   st.erase(st.begin()); n   return fr.second; n } n void update(long long v) { n   mark[v] = 1; n   for (long long e = head[v]; e != -1; e = prv[e]) { n     long long u = to[e], c = w[e]; n     if (!mark[u] && d[u] > w[e] + d[v]) { n       st.erase({d[u], u}); n       d[u] = d[v] + w[e]; n       st.insert({d[u], u}); n       ss[u] = ss[v]; n     } n   } n } n void dijk() { n   fill(d, d + MAXN, INF); n   memset(ss, -1, sizeof(ss)); n   for (long long i = 0; i < n; i++) n     if (portal[i]) mark[i] = 1, d[i] = 0, ss[i] = i; n   for (long long i = 0; i < n; i++) n     if (portal[i]) update(i); n   while (st.size()) update(get_min()); n } n bool cmp(long long e1, long long e2) { n   if (w[e1] != w[e2]) return w[e1] < w[e2]; n   return e1 < e2; n } n long long get_comp(long long v) { n   if (comp[v] == v) return v; n   return comp[v] = get_comp(comp[v]); n } n void merge(long long e) { n   if (get_comp(ss[to[e]]) == get_comp(ss[from[e]])) return; n   ans += w[e]; n   comp[get_comp(ss[to[e]])] = get_comp(ss[from[e]]); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n >> m; n   memset(head, -1, sizeof(head)); n   while (m--) { n     long long a, b, c; n     cin >> a >> b >> c; n     a--, b--; n     add_edge(a, b, c); n     add_edge(b, a, c); n   } n   cin >> k; n   while (k--) { n     long long temp; n     cin >> temp, temp--, portal[temp] = 1; n   } n   dijk(); n   ans = d[0]; n   iota(comp, comp + n, 0); n   iota(sec, sec + ec, 0); n   for (int i = 0; i < ec; i++) w[i] += d[from[i]] + d[to[i]]; n   sort(sec, sec + ec, cmp); n   for (long long e = 0; e < ec; e++) merge(sec[e]); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool hs(int mask, int i) { return mask & (1 << i); } n int dp[300000]; n void dfs2(vector<int> &adj, int i, int &c) { n   c++; n   dp[i] = 3; n   int u = adj[i]; n   if (dp[u] == 3) { n     return; n   } n   dfs2(adj, u, c); n } n void dfs(vector<int> &adj, int i, int &c) { n   dp[i] = 2; n   int u = adj[i]; n   if (dp[u] == 0) { n     dfs(adj, u, c); n   } else if (dp[u] == 2) { n     dfs2(adj, i, c); n   } n   dp[i] = 1; n } n int main() { n   int n, t; n   cin >> n; n   t = n; n   long long m = 1000000007; n   vector<int> adj; n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     a--; n     adj.push_back(a); n   } n   memset(dp, 0, sizeof(dp)); n   long long ans = 1, k = 1; n   vector<long long> v(200005); n   for (int i = 0; i < v.size(); i++) { n     v[i] = k; n     k = k * 2ll; n     k = k % m; n   } n   for (int i = 0; i < n; i++) { n     int c = 0; n     if (dp[i] == 0) { n       dfs(adj, i, c); n       t = t - c; n       if (c > 1) { n         ans = ans * (v[c] - 2ll); n         ans = ans % m; n       } n     } n   } n   ans = ans * v[t]; n   ans = ans % m; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-9; n const double PI = acos(-1.0); n const int MAXN = 100005; n const long long MOD = 1000000007; n void base() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n } n pair<int, int> arr[100005]; n int occ[100005]; n int main() { n   base(); n   int n, k, temp, need = 0; n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     cin >> temp; n     arr[i].second = temp; n     occ[temp]++; n   } n   for (int i = 0; i < n; i++) { n     cin >> temp; n     arr[i].first = temp; n   } n   for (int i = 1; i <= k; i++) { n     if (occ[i] == 0) need++; n   } n   sort(arr, arr + n); n   long long ans = 0; n   for (int i = 0; i < n; i++) { n     if (occ[arr[i].second] > 1 && need > 0) { n       occ[arr[i].second]--; n       need--; n       ans += (long long)arr[i].first; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   int n, x = 1, y = 1; n   cin >> n; n   while (n--) { n     cin >> s; n     if (s ==  ULDR ) n       x++, y++; n     else if (s ==  UR  || s ==  DL ) n       x++; n     else n       y++; n   } n   cout << 1LL * x * y << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T abs(T x) { n   return x > 0 ? x : -x; n } n int n; n int m; n int x, y; n int main() { n   scanf( %d%d , &x, &y); n   int ans = 0, d = 1, xx = 0, yy = 0; n   while (true) { n     if (yy == y && xx <= x && xx + d >= x) break; n     ans++; n     xx += d; n     if (xx == x && yy <= y && yy + d >= y) break; n     ans++; n     yy += d; n     d++; n     if (yy == y && xx - d <= x && xx >= x) break; n     ans++; n     xx -= d; n     if (xx == x && yy - d <= y && yy >= y) break; n     ans++; n     yy -= d; n     d++; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int getint() { n   int s = 0, o = 1; n   char c; n   for (c = getchar(); c <  0  || c >  9 ; c = getchar()) n     if (c ==  - ) o = -1; n   for (; c >=  0  && c <=  9 ; c = getchar()) s *= 10, s += c -  0 ; n   return s * o; n } n const int maxn = 30005; n int gem[maxn]; n int a[maxn]; n int dp[maxn][601], all, len, n, x; n inline void up(int &a, int b) { n   if (a < b) a = b; n } n int main(int argc, char const *argv[]) { n   n = getint(), len = getint(); n   for (int i = 0; i < n; i++) { n     x = getint(); n     gem[x]++; n     all = max(all, x); n   } n   int r = 0; n   dp[len][0 + 300] = gem[len] + 1; n   for (int i = 0; i <= all; ++i) n     for (int j = -300; j < 300; ++j) n       if (dp[i][j + 300]) { n         r = max(r, dp[i][j + 300] - 1); n         if (len + j > 0 && i + len + j - 1 <= all) n           up(dp[i + len + j - 1][j - 1 + 300], n              dp[i][j + 300] + gem[i + len + j - 1]); n         if (i + len + j <= all) n           up(dp[i + len + j][j + 300], dp[i][j + 300] + gem[i + len + j]); n         if (i + len + j + 1 <= all) n           up(dp[i + len + j + 1][j + 1 + 300], n              dp[i][j + 300] + gem[i + len + j + 1]); n       } n   printf( %d n , r); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline T read() { n   T f = 0, x = 0; n   char c = getchar(); n   while (!isdigit(c)) f = c ==  - , c = getchar(); n   while (isdigit(c)) x = x * 10 + c - 48, c = getchar(); n   return f ? -x : x; n } n namespace run { n inline char getc() { n   char c = getchar(); n   while (!isalpha(c)) c = getchar(); n   return c; n } n const int N = 2e5 + 9; n int head[N], nex[N], to[N], cnt, deg[N]; n inline void add(int u, int v) { n   deg[v]++, nex[++cnt] = head[u], head[u] = cnt, to[cnt] = v; n } n int n, m, bel[N], tot, dfn[N], num, dwn[N]; n inline void dfs(int u) { n   dfn[u] = ++num; n   for (int i = head[u]; i; i = nex[i]) dfs(to[i]); n   dwn[u] = num; n } n struct node { n   int x, l, r, v; n   explicit node() {} n   node(int _x, int _l, int _r, int _v) : x(_x), l(_l), r(_r), v(_v) {} n   inline bool operator<(const node &A) const { return x < A.x; } n } q[N << 1]; n namespace Seg { n int sum[N << 2], num[N << 2]; n inline void pushup(int k, int l, int r) { n   if (l == r) return num[k] = sum[k] > 0, void(); n   if (sum[k]) n     num[k] = r - l + 1; n   else n     num[k] = num[(k << 1)] + num[(k << 1 | 1)]; n } n inline void modify(int k, int l, int r, int _l, int _r, int v) { n   if (_l <= l && r <= _r) return sum[k] += v, pushup(k, l, r); n   if (_l <= ((l + r) >> 1)) modify((k << 1), l, ((l + r) >> 1), _l, _r, v); n   if (_r > ((l + r) >> 1)) n     modify((k << 1 | 1), ((l + r) >> 1) + 1, r, _l, _r, v); n   pushup(k, l, r); n } n }  // namespace Seg n inline int id(int x, int y) { return (x - 1) * m + y; } n int main() { n   n = read<int>(), m = read<int>(); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       char c = getc(); n       if (c ==  D ) { n         bel[id(i - 1, j)] = id(i, j), bel[id(i, j)] = id(i - 1, j); n         if (i > 2) add(id(i - 2, j), id(i, j)); n         if (i + 1 <= n) add(id(i + 1, j), id(i - 1, j)); n       } n       if (c ==  R ) { n         bel[id(i, j - 1)] = id(i, j), bel[id(i, j)] = id(i, j - 1); n         if (j > 2) add(id(i, j - 2), id(i, j)); n         if (j + 1 <= m) add(id(i, j + 1), id(i, j - 1)); n       } n     } n   for (int i = 1; i <= n * m; i++) n     if (!deg[i]) dfs(i); n   for (int i = 1; i <= n * m; i++) { n     int l = dfn[bel[i]], r = dwn[bel[i]]; n     q[++tot] = node(dfn[i], l, r, 1), q[++tot] = node(dwn[i] + 1, l, r, -1); n   } n   sort(q + 1, q + tot + 1); n   long long ans = 0; n   for (int i = 1, j, las = 0; i <= tot; i = j + 1) { n     j = i; n     while (j + 1 <= tot && q[j + 1].x == q[i].x) j++; n     ans += 1LL * (q[i].x - las) * Seg::num[1], las = q[i].x; n     for (int k = i; k <= j; k++) n       Seg::modify(1, 1, n * m, q[k].l, q[k].r, q[k].v); n   } n   printf( %lld n , ans >> 1); n   return 0; n } n }  // namespace run n int main() { return run::main(); } n


#include <bits/stdc++.h> n using namespace std; n int ans1 = 0, ans2 = 0, ans3 = 0, a[100]; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     if (i % 3 == 1) ans1 += a[i]; n     if (i % 3 == 2) ans2 += a[i]; n     if (i % 3 == 0) ans3 += a[i]; n   } n   if (ans1 >= ans2 && ans1 >= ans3) { n     cout <<  chest  << endl; n     return 0; n   } n   if (ans2 >= ans1 && ans2 >= ans3) { n     cout <<  biceps  << endl; n     return 0; n   } n   if (ans3 >= ans1 && ans3 >= ans2) { n     cout <<  back  << endl; n     return 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline const int getint() { n   int r = 0, k = 1; n   char c = getchar(); n   for (; c <  0  || c >  9 ; c = getchar()) n     if (c ==  - ) k = -1; n   for (; c >=  0  && c <=  9 ; c = getchar()) r = r * 10 + c -  0 ; n   return k * r; n } n const int N = 1e5 + 10; n char s[N]; n int n; n int main() { n   scanf( %s , s + 1); n   n = strlen(s + 1); n   int sum = 0, x = 0, y = 0, z = 0, need = 0; n   for (int i = (1); i <= (n); ++i) n     if (s[i] ==  ( ) n       ++x; n     else if (s[i] ==  ) ) n       ++y; n     else n       ++z; n   need = x - y - (z - 1); n   if (need <= 0 && z) { n     puts( -1 ); n     return 0; n   } n   int now = z; n   for (int i = (n); i >= (1); --i) { n     if (s[i] ==  ( ) n       ++sum; n     else if (s[i] ==  ) ) n       --sum; n     else { n       if (now == z) { n         sum -= need; n       } else { n         sum--; n       } n       --now; n     } n     if (sum > 0) { n       puts( -1 ); n       return 0; n     } n   } n   if (sum != 0) { n     puts( -1 ); n     return 0; n   } n   now = 0; n   for (int i = (1); i <= (n); ++i) { n     if (s[i] ==  # ) { n       ++now; n       if (now == z) n         printf( %d n , need); n       else n         puts( 1 ); n     } n   } n   return 0; n } n


#include<bits/stdc++.h> n #define inf 0x3f3f3f n using namespace std; n typedef long long ll; n const int maxn = 3e5+5; n const int mod = 1e9+7; n int a[maxn],b[maxn]; n int main() n { n  int T; n  cin>>T; n  while(T--){ n   int n; n   cin>>n; n   for(int i=1;i<=n;i++) cin>>a[i]; n   for(int j=1;j<=n;j++) cin>>b[j]; n   int cnt1=0,cnt2=0; n   vector<int> v1,v2; n   for(int i=1;i<=n;i++){ n    if(a[i]>b[i]){ n     cnt1+=a[i]-b[i];  n     for(int j=0;j<a[i]-b[i];j++) v1.push_back(i); n    } n    else{ n     cnt2+=b[i]-a[i]; n     for(int j=0;j<b[i]-a[i];j++) v2.push_back(i); n    } n   } n   if(cnt1!=cnt2){ n    cout<< -1 n ; n    continue; n   } n   cout<<v1.size()<<  n ; n   for(int i=0;i<v1.size();i++){ n    cout<<v1[i]<<   <<v2[i]<<  n ; n   } n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, n, m, z, ck = 0; n   cin >> n >> m >> z; n   for (i = 1; i <= z; i++) { n     if (n * i > z) n       break; n     else if ((n * i) % m == 0) { n       ck++; n     } n   } n   cout << ck << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1700; n int n, m, tim, res[N * N], num[N * N], a[N][N], s[N][N], id[N][N]; n bool ray[N][N]; n bool check(int x, int y) { n   return s[x + 3][y + 3] - s[x - 4][y + 3] - s[x + 3][y - 4] + n              s[x - 4][y - 4] <= n          15; n } n void dfs1(int x, int y) { n   if (id[x][y] || !a[x][y]) return; n   id[x][y] = *res; n   dfs1(x - 1, y); n   dfs1(x + 1, y); n   dfs1(x, y - 1); n   dfs1(x, y + 1); n } n void dfs2(int x, int y) { n   if (!a[x][y] || ray[x][y]) return; n   if (!check(x, y)) { n     if (num[id[x][y]] != tim) { n       num[id[x][y]] = tim; n       res[id[x][y]]++; n     } n     return; n   } n   ray[x][y] = true; n   dfs2(x - 1, y); n   dfs2(x + 1, y); n   dfs2(x, y - 1); n   dfs2(x, y + 1); n } n int main() { n   scanf( %d%d , &n, &m); n   n += 5; n   m += 5; n   for (int i = 6; i <= n; i++) n     for (int j = 6; j <= m; j++) scanf( %d , &a[i][j]); n   n += 5; n   m += 5; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j]; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (a[i][j] && !id[i][j]) { n         ++*res; n         dfs1(i, j); n       } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (a[i][j] && !ray[i][j] && check(i, j)) { n         ++tim; n         dfs2(i, j); n       } n   sort(res + 1, res + *res + 1); n   printf( %d n , *res); n   for (int i = 1; i <= *res; i++) printf( %d  , res[i]); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void join(vector<T>& arr, string sep) { n   bool first = true; n   for (auto t : arr) { n     if (first) { n       first = false; n       cout << t; n     } else { n       cout << sep << t; n     } n   } n   cout <<   n ; n } n struct Euler { n   vector<vector<pair<long long, long long>>> g; n   long long n; n   vector<long long> path; n   long long edge_count; n   Euler(long long n) : n(n) { n     g.resize(n); n     edge_count = 0; n   } n   void addEdge(long long u, long long v) { n     long long w = edge_count++; n     g[u].push_back({v, w}); n     g[v].push_back({u, w}); n   } n   bool compute() { n     int first = 0; n     while (first < n && g[first].empty()) first++; n     if (first == n) return true; n     long long v1 = -1, v2 = -1; n     for (long long u = 0; u < (long long)(n); ++u) { n       if (g[u].size() & 1) { n         return false; n       } n     } n     if (v1 != -1) { n       assert(v2 != -1); n     } n     vector<long long> visited(edge_count); n     vector<long long> s = {first}; n     while (!s.empty()) { n       long long u = s.back(); n       long long v; n       while (true) { n         if (g[u].empty()) { n           v = -1; n           path.push_back(u); n           s.pop_back(); n           break; n         } n         long long v = g[u].back().first; n         long long w = g[u].back().second; n         g[u].pop_back(); n         if (visited[w]) { n           continue; n         } n         visited[w] = true; n         s.push_back(v); n         break; n       } n     } n     if (v1 != -1) { n       for (long long i = 0; i < (long long)(path.size() - 1); ++i) { n         if ((path[i] == v1 && path[i + 1] == v2) || n             (path[i] == v2 && path[i + 1] == v1)) { n           vector<long long> res; n           for (long long j = (long long)(i + 1); j < (long long)(path.size()); n                ++j) { n             res.push_back(path[j]); n           } n           for (long long j = (long long)(1); j < (long long)(i + 1); ++j) { n             res.push_back(path[j]); n           } n           path = res; n           break; n         } n       } n     } n     for (long long u = 0; u < (long long)(n); ++u) { n       if (!g[u].empty()) { n         return false; n       } n     } n     return true; n   } n }; n long long getPref(long long c, long long i) { return ((1 << i) - 1) & c; } n struct PairHash { n   int operator()(const pair<long long, long long>& pp) const { n     const int p = 31; n     const int m = 1e9 + 9; n     long long l = pp.first; n     long long r = (pp.second * p) % m; n     return (l + r) % m; n   } n }; n void solve() { n   long long n; n   cin >> n; n   vector<pair<long long, long long>> colors(n); n   for (long long i = 0; i < (long long)(n); ++i) { n     long long a, b; n     cin >> a >> b; n     colors[i] = {a, b}; n   } n   vector<long long> res; n   for (long long i = (long long)(1); i < (long long)(2 * n + 1); ++i) { n     res.push_back(i); n   } n   long long lowest = 0; n   long long l = 1; n   long long r = 20; n   while (l <= r) { n     long long i = l + (r - l) / 2; n     unordered_map<pair<long long, long long>, n                   vector<pair<long long, long long>>, PairHash> n         nodes2Idx; n     Euler e(1 << i); n     for (long long j = 0; j < (long long)(n); ++j) { n       long long pref1 = getPref(colors[j].first, i); n       long long pref2 = getPref(colors[j].second, i); n       long long idx1 = 2 * j + 1; n       long long idx2 = 2 * j + 2; n       if (pref1 > pref2) { n         swap(pref1, pref2); n         swap(idx1, idx2); n       } n       nodes2Idx[{pref1, pref2}].push_back({idx1, idx2}); n       e.addEdge(pref1, pref2); n     } n     if (!e.compute()) { n       r = i - 1; n       continue; n     } n     l = i + 1; n     lowest = i; n     assert(e.path.size() == n + 1); n     for (long long j = 0; j < (long long)(n); ++j) { n       long long pref1 = e.path[j]; n       long long pref2 = e.path[j + 1]; n       bool swaped = false; n       if (pref1 > pref2) { n         swap(pref1, pref2); n         swaped = true; n       } n       auto it = nodes2Idx.find({pref1, pref2}); n       pair<long long, long long> idxPair = it->second.back(); n       it->second.pop_back(); n       long long idx1 = idxPair.first; n       long long idx2 = idxPair.second; n       if (swaped) swap(idx1, idx2); n       res[2 * j] = idx1; n       res[2 * j + 1] = idx2; n     } n   } n   cout << lowest <<   n ; n   join(res,    ); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, a[111000], s, ans[111000]; n int main() { n   cin >> n >> k; n   for (register int i = 1; i <= n; i++) { n     cin >> a[i]; n     s += a[i]; n   } n   if (s % k != 0) { n     cout <<  No ; n     return 0; n   } n   int t = s / k; n   int cnt = 0; n   for (register int i = 1; i <= n;) { n     int sum = 0, tmp = 0; n     while (sum < t) { n       sum += a[i]; n       i++; n       tmp++; n     } n     if (sum != t) { n       cout <<  No ; n       return 0; n     } n     ans[++cnt] = tmp; n   } n   cout <<  Yes  << endl; n   for (register int i = 1; i <= cnt; i++) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int w[100001]; n int main() { n   map<string, int> mp; n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> w[i]; n   } n   sort(w, w + n); n   string s; n   for (int i = 0; i < m; i++) { n     cin >> s; n     mp[s]++; n   } n   int a[101], k = 0; n   for (map<string, int>::iterator i = mp.begin(); i != mp.end(); i++) { n     a[k++] = (*i).second; n   } n   sort(a, a + k); n   long long s1 = 0, p = 0; n   for (int i = 0; i < k; i++) { n     s1 += a[k - i - 1] * w[i]; n     p += a[k - i - 1] * w[n - i - 1]; n   } n   cout << s1 <<     << p; n } n


#include <bits/stdc++.h> n using namespace std; n const int Max = 2e6 + 10; n const int Mod = 1e9 + 7; n const int MAX = 2e18; n int main() { n   long long int x, j = 0, mx = 0, mx2 = 0, cnt = 0; n   bool f = 0, f2 = 0, f3 = 0; n   string s; n   cin >> x >> s; n   long long int ar[x + 5]; n   memset(ar, 0, sizeof(ar)); n   ; n   for (int i = 0; i < x; i++) { n     if (s[i] ==  G ) { n       ar[j]++; n       f2 = 1; n       cnt++; n       if (f == 1) { n         f3 = 1; n       } n     } else { n       f = 1; n       if (i != x - 1) { n         j++; n       } n     } n   } n   if (f == 0) { n     cout << x << endl; n     ; n     return 0; n   } n   if (f2 == 0) { n     cout << 0 << endl; n     ; n     return 0; n   } n   if (f3 == 0) { n     cout << cnt << endl; n     ; n     return 0; n   } n   for (int i = 0; i < j + 1; i++) { n     if (ar[i + 1] == 0) { n       mx2 = max(mx2, ar[i]); n       ar[i] = 0; n       i++; n       continue; n     } n     mx2 = max(mx2, ar[i]); n     ar[i] = ar[i] + ar[i + 1]; n     mx = max(mx, ar[i]); n   } n   if (mx2 > mx) { n     if (mx2 < cnt) { n       cout << mx2 + 1 << endl; n       ; n     } else { n       cout << mx2 << endl; n       ; n     } n   } else if (cnt > mx) { n     cout << mx + 1 << endl; n     ; n   } else { n     cout << mx << endl; n     ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n; n   cin >> n; n   if (n <= 30) n     cout <<  NO n ; n   else { n     cout <<  YES n ; n     long long d = n - 30; n     long long a = 6, b = 10, c = 14; n     if (d == 6 || d == 10 || d == 14) n       cout <<  6 10 15   << d - 1 << endl; n     else n       cout <<  6 10 14   << d << endl; n   } n } n signed main() { n   long long t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long int; n const ll mod = 1000000007; n const ll M = 1000000000000000000ll; n inline ll add(ll a, ll b) { return ((a % mod + b % mod) % mod); } n inline ll sub(ll a, ll b) { return ((a % mod - b % mod + mod) % mod); } n inline ll mult(ll a, ll b) { return (((a % mod) * (b % mod)) % mod); } n inline ll power(ll n, ll x) { n   ll p = 1; n   while (x != 0) { n     if (x % 2 == 0) { n       n = mult(n, n); n       x = x / 2; n     } n     p = mult(p, n); n     x--; n   } n   return p; n } n inline ll recurmult(ll a, ll b) { n   ll r = 0; n   while (b) { n     if (b & 1) r = add(r, a); n     a = mult(2, a); n     b >>= 1; n   } n   return r % mod; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   ll n, ma = 0; n   cin >> n; n   ll arr[n + 1]; n   ll ans[n + 1]; n   for (ll i = 0; i < n; i++) cin >> arr[i]; n   ans[0] = arr[0]; n   ma = ans[0]; n   for (ll i = 1; i < n; i++) { n     ans[i] = ma + arr[i]; n     ma = max(ma, ans[i]); n   } n   for (ll i = 0; i < n; i++) cout << ans[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x1, x2, x3, n1, n2, n3; n   scanf( %d %d %d , &x1, &x2, &x3); n   n3 = (x1 - x2 + x3) / 2; n   n2 = x3 - n3; n   n1 = x1 - n3; n   if (n1 < 0 || n2 < 0 || n3 < 0 || 2 * (n1 + n2 + n3) != x1 + x2 + x3) n     printf( Impossible n ); n   else n     printf( %d %d %d n , n1, n2, n3); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct pp { n   long long int len, v; n }; n bool cmp(pp& a, pp& b) { n   if (a.v == b.v) return a.len > b.len; n   return a.v > b.v; n } n int main() { n   long long int n, k; n   cin >> n; n   cout << (n - 1) * n * (2 * n - 1) / 6 - 1 - 1 + n * (n - 1) / 2 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using db = double; n using pii = pair<int, int>; n using pll = pair<ll, ll>; n using pdd = pair<db, db>; n using vi = vector<int>; n using vl = vector<ll>; n using vd = vector<db>; n using vs = vector<string>; n using vii = vector<pii>; n using vll = vector<pll>; n using vdd = vector<pdd>; n template <class T> n bool ckmin(T& a, const T& b) { n   return (b < a) ? a = b, 1 : 0; n } n template <class T> n bool ckmax(T& a, const T& b) { n   return (a < b) ? a = b, 1 : 0; n } n const ll MOD = 1e9 + 7; n const ll MOD2 = 998244353; n const int kx[] = {0, 1, 0, -1}, ky[] = {1, 0, -1, 0}; n void fileIO(string filename) { n   freopen((filename +  .in ).c_str(),  r , stdin); n   freopen((filename +  .out ).c_str(),  w , stdout); n } n int solve(string s) { n   int n = (int)s.size(), tot = count((s).begin(), (s).end(),  1 ), cmin = tot, n       cur = 0; n   vi dp(n); n   for (int(i) = 0; i < n; ++i) { n     cur += s[i] ==  1 ; n     dp[i] = s[i] ==  0 ; n     if (i) dp[i] += min(dp[i - 1], cur - (s[i] ==  1 )); n     ckmin(cmin, dp[i] + tot - cur); n   } n   return cmin; n } n int main(void) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n, k, tot, ans = INT_MAX; n     cin >> n >> k; n     string ss; n     cin >> ss; n     tot = count((ss).begin(), (ss).end(),  1 ); n     vs s(k); n     vi cnt(k); n     for (int(i) = 0; i < n; ++i) s[i % k] += ss[i]; n     for (int(i) = 0; i < k; ++i) n       cnt[i] = count((s[i]).begin(), (s[i]).end(),  1 ); n     for (int(i) = 0; i < k; ++i) ckmin(ans, solve(s[i]) + tot - cnt[i]); n     cout << ans <<   n ; n   } n   cerr <<  Time elapsed:   << 1.0 * clock() / CLOCKS_PER_SEC <<  s n ; n } n


n #include<bits/stdc++.h> n  n  n using namespace std; n #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); n  n #define PB(x, v) x.push_back(v); n #define M_P(a, b) make_pair(a, b) n #define pll pair<ll, ll> n #define ll long long int n #define mll map<ll, ll> n #define vl vector<ll> n #define fa(x, v) for(auto x: v) n #define fr(i, a, b, step) for(auto i= a;i <=b; i+=step) n #define TEST  Int test; cin >> test; while(test--) n #define FTEST Int TesT; cin >> TesT; for(Int test = 1; test<=TesT; test++) n /**So..a**/ n #define B_ begin() n #define E_ end() n #define all(a) a.begin(), a.end() n #define rall(a) a.rbegin(), a.rend() n #define NL_   n  n #define F first n #define S second n #define FF first.first n #define FS first.second n #define SF second.first n #define SS second.second n #include <iomanip> n #define __lcm(a, b) (a/__gcd(a, b)*b) n #define PI acos(-1) n #define EXP 10e-6 n  ll prime(ll a,ll b){ n   ll ans=0; n    n    n    n    n   return ans; n  } n int main() n { n       n          n         ll n,m,k,i,j,sum=0,cnt=0,x; n            string s,ss,str,st; n          bool sign=1,ok=true,cheak=1; n          ll t,tc; n         ll a,b,c; n         ll ans=0; n            ok=1; n           sum=0; n            n           ll fac=1; n         cin>>t; n         while(t--) n         { n          cnt=0; n          ok=1;sign=0; n            int first=0; n            int p=0; n            int fst=0,scnd=0; n          cin>>n>>k; n           n           int mid=(n+1)/2; n             n            vector<ll>vv,v; n           for(i=1;i<=mid;i++){ n             n            vv.push_back(i); n              n     } n           for(i=mid+1;i<=n;i++){ n             n            v.push_back(i); n     } n     /* n     for(auto i:vv)cout<<i<<   ; n     cout<<endl; n     for(auto i:v)cout<<i<<   ; n     cout<<endl; n          */ n          if(k==0){ n           for(i=1;i<=n;i++)cout<<i<<   ; n           cout<<endl; n           continue; n    } n           n      if((k+k+1) > n)cout<<-1<<endl; n    else { n       n     for(i=1;i<=n;i++) n     { n           n      if(ok){ n          n       cout<<vv[first++]<<   ; n       ok=0; n       sign=1; n            fst++; n       continue; n      } n          if(sign){ n             n       ok=1; n       sign=0; n       cout<<v[p++]<<   ; n        scnd++; n       cnt++; n        if(cnt==k)break; n      } n     } n      n     for(i=fst;i<vv.size();i++)cout<<vv[i]<<   ; n     for(i=scnd;i<v.size();i++)cout<<v[i]<<   ; n      n      n     cout<<endl; n    } n     n     n   } n      n          n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void read(long long a = 0) { n   freopen( in ,  r , stdin); n   if (a) freopen( out ,  w , stdout); n } n int main() { n   long long n, m, k; n   cin >> n >> m >> k; n   long long done = 0; n   while (k--) { n     long long x, y; n     cin >> x >> y; n     long long mi = 1e15; n     mi = min(mi, x - 1); n     mi = min(mi, n - x); n     mi = min(mi, y - 1); n     mi = min(mi, m - y); n     done |= (mi <= 4); n   } n   if (done) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n const int inf = 1 << 30; n const long long INF = 1ll << 61; n using namespace std; n int n, m; n int c[1000000 + 55]; n int nnum[1000000 + 55]; n int aa[1000000 + 55]; n int sum[1000000 + 55]; n int len; n void init() { n   memset(c, 0, sizeof(c)); n   memset(aa, -1, sizeof(aa)); n } n bool input() { n   while (cin >> n >> m) { n     for (int i = 0; i < m; i++) cin >> nnum[i]; n     return false; n   } n   return true; n } n int lowbit(int x) { return x & (-x); } n void add(int i, int val) { n   while (i <= n) { n     c[i] += val; n     i += lowbit(i); n   } n } n int get_sum(int i) { n   int sum = 0; n   while (i > 0) { n     sum += c[i]; n     i -= lowbit(i); n   } n   return sum; n } n void binary_find(int pos) { n   for (int i = 0; i <= pos; i++) { n     int l = 1; n     int r = n; n     while (l <= r) { n       int mid = (l + r) >> 1; n       int ret = get_sum(mid); n       if (aa[mid] == -1) { n         if (ret >= nnum[i] - i) n           r = mid - 1; n         else n           l = mid + 1; n       } else if (ret == nnum[i] - i) { n         add(mid, -1); n         aa[mid] = -1; n         len--; n         break; n       } else if (ret > nnum[i] - i) n         r = mid - 1; n       else if (ret < nnum[i] - i) n         l = mid + 1; n     } n   } n } n void cal() { n   int q = n; n   len = 0; n   int cnt = 1; n   while (q--) { n     int type; n     cin >> type; n     if (type == -1) { n       if (len == 0) continue; n       if (nnum[0] > len) continue; n       int now = lower_bound(nnum, nnum + m, len) - nnum; n       binary_find(now); n     } else { n       aa[cnt] = type; n       add(cnt, 1); n       cnt++; n       len++; n     } n   } n   if (len <= 0) { n     puts( Poor stack! ); n     return; n   } n   for (int i = 1; i <= n; i++) n     if (aa[i] != -1) printf( %d , aa[i]); n   puts(  ); n } n void output() {} n int main() { n   while (true) { n     init(); n     if (input()) return 0; n     cal(); n     output(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int e, d, c, x, aux, aux2; n priority_queue<pair<long long int, long long int> > q; n void res(long long int n) { n   long long int k = n; n   e = 0; n   d = 1; n   while (k > 0) { n     d = d * 10 + 1; n     e++; n     k = k / 10; n   } n   c = (d - 1) / 10; n   if (c > n) { n     d = c; n     c = (d - 1) / 10; n     e--; n   } n } n void dis(long long v) { n   q.push(make_pair(0, v)); n   aux = q.top().second; n   while (aux != 0) { n     res(aux); n     aux2 = q.top().first; n     q.pop(); n     if (d - aux < aux) q.push(make_pair(aux2 - (e + 1), d - aux)); n     q.push(make_pair(aux2 - e, aux - c)); n     aux = q.top().second; n   } n   x = q.top().first; n } n int main() { n   long long int a; n   cin >> a; n   dis(a); n   cout << x * -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int a[111111], b[111111], ra[111111]; n set<pair<int, int> > s; n int main() { n   ios::sync_with_stdio(false); n   cin >> n; n   for (int i = 0, _n = (int)(n); i < _n; i++) cin >> a[i], a[i]--, ra[a[i]] = i; n   for (int i = 0, _n = (int)(n); i < _n; i++) cin >> b[i], b[i]--; n   for (int i = 0, _n = (int)(n); i < _n; i++) n     s.insert(pair<int, int>(ra[b[i]] - i, i)); n   for (int i = 0, _n = (int)(n); i < _n; i++) { n     int ans = 999999; n     auto x = s.upper_bound(pair<int, int>(-i, 0)); n     if (x != s.end()) ans = min(ans, abs(x->first + i)); n     if (x != s.begin()) x--, ans = min(ans, abs(x->first + i)); n     cout << ans << endl; n     x = s.lower_bound(pair<int, int>(ra[b[i]] - i, i)); n     s.erase(x); n     s.insert(pair<int, int>(x->first - n, i)); n   } n   cout << endl; n   { n     int _; n     cin >> _; n   } n   return 0; n } n


#include <bits/stdc++.h> n int x[100010]; n int main() { n   int a, b, c, i; n   scanf( %d%d%d , &a, &b, &c); n   for (i = 1; i <= a; i++) scanf( %d , &x[i]); n   int s = 0, t = 1; n   long long int count = 0; n   while (1) { n     if (t > a && s == 0) { n       printf( %I64d , count); n       return 0; n     } n     while (t <= a && s + x[t] <= b) s += x[t], t++; n     if (s < c) { n       count++; n       s = 0; n     } else { n       count += (s / c); n       s = s % c; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, t; n   cin >> n >> t; n   string s; n   cin >> s; n   for (long long int i = 0; i < t; i++) { n     for (long long int j = 0; j < n - 1; j++) { n       if (s[j] ==  B  && s[j + 1] ==  G ) { n         s[j] =  G ; n         s[j + 1] =  B ; n         j = j + 1; n       } n     } n   } n   for (long long int i = 0; i < n; i++) { n     cout << s[i]; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int inf = 0xfffffff; n const long long INF = 1ll << 61; n using namespace std; n int n, s, k; n int aa[100 + 55][100 + 55]; n int ans; n void init() { memset(aa, 0, sizeof(aa)); } n bool input() { n   while (scanf( %d %d %d , &n, &s, &k) == 3) { n     for (int i = 0; i < n; i++) n       for (int j = 0; j < s; j++) scanf( %d , &aa[i][j]); n     return false; n   } n   return true; n } n void cal() { n   ans = 11; n   if (n < s) { n     for (int i = 0; i < s; i++) n       for (int j = i + 1; j < s; j++) swap(aa[i][j], aa[j][i]); n     swap(n, s); n   } n   if (n <= k) { n     for (int i = 0; i < (1 << s); i++) { n       int sum = 0; n       for (int j = 0; j < n; j++) { n         int now = 0; n         for (int l = 0; l < s; l++) { n           if (i & (1 << l)) { n             if (!aa[j][l]) now++; n           } else { n             if (aa[j][l]) now++; n           } n         } n         sum += min(now, s - now); n       } n       ans = min(ans, sum); n     } n   } else { n     for (int i = 0; i < n; i++) { n       int sum = 0; n       for (int j = 0; j < n; j++) { n         int now = 0; n         for (int l = 0; l < s; l++) { n           if (aa[i][l] != aa[j][l]) now++; n         } n         sum += min(now, s - now); n       } n       ans = min(ans, sum); n     } n   } n } n void output() { n   if (ans <= k) n     cout << ans << endl; n   else n     puts( -1 ); n } n int main() { n   while (true) { n     init(); n     if (input()) return 0; n     cal(); n     output(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int number; n   cin >> number; n   long long ans = number; n   while (1) { n     int x = 100000000; n     for (int i = 2; i <= sqrt(number); i++) { n       if (number % i == 0) { n         x = min(x, i); n       } n     } n     if (x == 100000000) break; n     ans += number / x; n     number = number / x; n   } n   cout << ans + 1; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, sum; n   cin >> n; n   long long int arr[n]; n   sum = 0; n   for (long long int i = 0; i < n; i++) { n     cin >> arr[i]; n     sum += arr[i]; n   } n   sort(arr, arr + n); n   long long int curr = 0; n   long long int cnt = 0; n   long long int ind = n - 1; n   while (curr <= sum) { n     ++cnt; n     curr += arr[ind]; n     sum -= arr[ind]; n     --ind; n   } n   cout << cnt <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int T, n, x; n int main() { n   scanf( %d , &T); n   while (T--) { n     scanf( %d%d , &n, &x); n     printf( %d n , 2 * x); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, s[1000005], t[1000005]; n int bef[1000005][2]; n long long ss, st, cs, ct; n bool sw; n int main() { n   memset(bef, -1, sizeof(bef)); n   bef[0][0] = bef[0][1] = 0; n   scanf( %d , &n); n   for (int i = (1); i <= (n); i++) scanf( %d , &s[i]), ss += s[i]; n   for (int i = (1); i <= (n); i++) scanf( %d , &t[i]), st += t[i]; n   if (ss < st) { n     swap(ss, st); n     for (int i = (1); i <= (n); i++) swap(s[i], t[i]); n     sw = true; n   } n   int p = 0; n   for (int i = (1); i <= (n); i++) { n     ct += t[i]; n     while (p < n && cs + s[p + 1] <= ct) cs += s[++p]; n     long long d = ct - cs; n     assert(d >= 0 && d < n); n     if (bef[d][0] == -1) { n       bef[d][0] = p; n       bef[d][1] = i; n     } else { n       if (sw) { n         printf( %d n , i - bef[d][1]); n         for (int j = (bef[d][1] + 1); j <= (i); j++) n           printf( %d%c , j, j == i ?   n  :    ); n       } n       printf( %d n , p - bef[d][0]); n       for (int j = (bef[d][0] + 1); j <= (p); j++) n         printf( %d%c , j, j == p ?   n  :    ); n       if (!sw) { n         printf( %d n , i - bef[d][1]); n         for (int j = (bef[d][1] + 1); j <= (i); j++) n           printf( %d%c , j, j == i ?   n  :    ); n       } n       return 0; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 998244353; n int main() { n   long long n; n   cin >> n; n   map<long long, long long> mp; n   long long a[200005]; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     mp[a[i]] = i; n   } n   long long ans = 1, w = mp[a[0]]; n   for (int i = 0; i < n; i++) { n     if (i > w) { n       ans = (ans * 2) % M; n     } n     w = max(w, mp[a[i]]); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   cin >> n; n   int ans = 0; n   while (n % 3 == 0 || n % 6 == 0) { n     if (n % 6 == 0) { n       n /= 6; n       ans++; n     } else if (n % 3 == 0) { n       n /= 3; n       ans += 2; n     } n   } n   if (n != 1) { n     cout << -1 << endl; n     return; n   } n   cout << ans << endl; n } n int main() { n   int t = 1, i = 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 N = 1e5 + 9, inf = 1e18, mod = 1e9 + 7; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int t; n   cin >> t; n   while (t--) { n     int a, b, c, d, k; n     cin >> a >> b >> c >> d >> k; n     int x = (a + c - 1) / c; n     int y = k - x; n     if (y * d >= b) n       cout << x <<     << y <<   n ; n     else n       cout << -1 <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     string str; n     int j = 0; n     cin >> str; n     int len = str.length(); n     for (int i = 0; i < len - 1; i = i + 2) { n       cout << str[i]; n     } n     cout << str[len - 1]; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (b == 0) { n     return a; n   } n   return gcd(b, a % b); n } n long long mod = 1000000007; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   long long t; n   cin >> t; n   while (t--) { n     long long p, q; n     cin >> p >> q; n     std::vector<long long> factors; n     long long r = p; n     while (r % q == 0) { n       r /= q; n     } n     long long Q = q; n     long long i = 2; n     while (q > 1 and i * i <= Q) { n       if (q % i == 0) { n         factors.push_back(i); n         while (q % i == 0) { n           q /= i; n         } n       } n       i++; n     } n     if (q != 1) { n       factors.push_back(q); n     } n     std::vector<long long> v; n     for (auto it : factors) { n       long long P = p; n       while (P % Q == 0) { n         P /= it; n       } n       v.push_back(P); n     } n     std::cout << *max_element(v.begin(), v.end()) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, n, moves = 0, flag = 1, gears; n   cin >> n; n   cin >> gears; n   moves = n - gears; n   for (i = 1; i < n; i++) { n     cin >> gears; n     if (i % 2 == 1) n       gears = (gears + (n - moves)) % n; n     else n       gears = (gears + moves) % n; n     if (gears != i) { n       cout <<  No  << endl; n       return 0; n     } n   } n   cout <<  Yes  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[3000]; n bool apare[1010]; n int n, k, c; n int main() { n   ios_base ::sync_with_stdio(0); n   cin >> n >> k; n   while (k--) { n     cin >> c; n     apare[c] = 1; n   } n   queue<int> q; n   vector<int> lungimi; n   for (int i(0); i < 1010; i++) { n     if (!apare[i]) continue; n     int x(n - i + 1500); n     dp[x] = 1; n     q.push(x); n     lungimi.push_back(x - 1500); n   } n   while (!q.empty()) { n     int x(q.front()), t(dp[x]); n     q.pop(); n     for (auto i : lungimi) { n       if (x + i >= 0 && x + i < 3000 && !dp[x + i]) { n         dp[x + i] = 1 + t; n         q.push(x + i); n       } n     } n   } n   cout << (dp[1500] ? dp[1500] : -1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9; n using namespace std; n const int maxn = 404; n int n, m, k; n int s[103], t[103]; n int c[103][103], d[103][103], e[103][103], f[103][103]; n struct Edge { n   int u, v, c, w, next; n   Edge(int u, int v, int c, int w, int next) n       : u(u), v(v), c(c), w(w), next(next) {} n   Edge() {} n } edge[100005]; n int head[maxn], E; n void init() { n   memset(head, -1, sizeof(head)); n   E = 0; n } n void add(int s, int t, int c, int w) { n   edge[E] = Edge(s, t, c, w, head[s]); n   head[s] = E++; n   edge[E] = Edge(t, s, 0, -w, head[t]); n   head[t] = E++; n } n int S, T; n int pre[maxn], dis[maxn]; n bool vis[maxn]; n bool spfa(int s, int t, int n) { n   int i, u, v; n   for (i = 0; i <= n; i++) dis[i] = inf, pre[i] = -1, vis[i] = false; n   queue<int> q; n   vis[s] = true; n   dis[s] = 0; n   q.push(s); n   while (!q.empty()) { n     u = q.front(); n     q.pop(); n     vis[u] = false; n     for (i = head[u]; ~i; i = edge[i].next) { n       v = edge[i].v; n       if (edge[i].c && dis[v] > dis[u] + edge[i].w) { n         dis[v] = dis[u] + edge[i].w; n         pre[v] = i; n         if (!vis[v]) { n           vis[v] = true; n           q.push(v); n         } n       } n     } n   } n   if (dis[t] == inf) return 0; n   return 1; n } n int ans; n pair<int, int> mcmf(int s, int t, int n) { n   int aug, minc = 0, i, maxf = 0; n   while (spfa(s, t, n)) { n     aug = inf + 1; n     for (i = pre[t]; ~i; i = pre[edge[i].u]) aug = min(aug, edge[i].c); n     for (i = pre[t]; ~i; i = pre[edge[i].u]) { n       edge[i].c -= aug; n       edge[i ^ 1].c += aug; n     } n     maxf += aug; n     minc += dis[t] * aug; n   } n   return make_pair(maxf, minc); n } n int Map[55][55]; n void build(int m) { n   int i, j; n   init(); n   for (i = 0; i < n; i++) n     for (j = 0; j < n; j++) { n       if (Map[i][j]) { n         add(i, j, Map[i][j], 0); n         add(i, j, k, 1); n       } n     } n   add(n, 0, m, 0); n } n int main() { n   int i, j; n   scanf( %d%d , &n, &k); n   for (i = 0; i < n; i++) n     for (j = 0; j < n; j++) scanf( %d , &Map[i][j]); n   int l = 0, r = 1e9; n   while (l <= r) { n     int m = (l + r) >> 1; n     build(m); n     pair<int, int> t = mcmf(n, n - 1, n + 1); n     if (t.first == m && t.second <= k) { n       l = m + 1; n       ans = m; n     } else n       r = m - 1; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   string s; n   cin >> s; n   vector<int> way(s.size()); n   way[0] = 0; n   for (int i = 1; i < (int)s.size(); i++) { n     if (s[i] ==  0 ) n       way[i] = i; n     else n       way[i] = way[i - 1]; n   } n   int l = 0, r = n - 1; n   while (r - l > 1) { n     int m = (l + r) / 2; n     int cnt = k - 1; n     int now = 0; n     int last = 0; n     while (now < n && cnt > 0) { n       now += m; n       now = min(now, n - 1); n       now = way[now]; n       cnt--; n       last = max(last, now); n     } n     if (last == n - 1) { n       r = m; n     } else { n       l = m; n     } n   } n   cout << l <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   string s =   ; n   for (int i = 0; i < k; i++) s += char(i + 97); n   for (int i = 0; i < n - k; i++) { n     s += char(i % k + 97); n   } n   cout << s << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> v(n); n   for (int i = 0; i < n; i++) cin >> v[i]; n   int i = 0; n   vector<int> ans; n   ans.push_back(v[0]); n   ans.push_back(v[n - 1]); n   while (i < n - 3) { n     int k = v[i + 1]; n     int l = v[i + 2]; n     if (l >= k) { n       ans.push_back(l); n       i = i + 2; n     } else { n       ans.push_back(k); n       i++; n     } n   } n   int out = *min_element(ans.begin(), ans.end()); n   cout << out; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m; n struct pt { n   long long x, y; n   pt() {} n   pt(long long x, long long y) : x(x), y(y) {} n }; n vector<vector<long long>> used; n vector<vector<long long>> g; n void parasha(pt q, pt p, long long weight, deque<pt>& bfs, n              vector<vector<long long>>& w) { n   if (q.x < 0 || q.y < 0 || q.x >= n || q.y >= m) return; n   if (g[q.x][q.y] ==  * ) return; n   if (w[q.x][q.y] > w[p.x][p.y] + weight) { n     w[q.x][q.y] = w[p.x][p.y] + weight; n     if (weight == 1) n       bfs.push_back(q); n     else n       bfs.push_front(q); n   } n } n int32_t main() { n   deque<pt> bfs; n   cin >> n >> m; n   vector<vector<long long>> w(n, vector<long long>(m, 3e9)); n   g.assign(n, vector<long long>(m)); n   used.assign(n, vector<long long>(m, 0)); n   long long r, c; n   cin >> r >> c; n   --r; n   --c; n   long long x, y; n   cin >> x >> y; n   for (long long i = 0; i < n; ++i) { n     for (long long j = 0; j < m; ++j) { n       char x; n       cin >> x; n       g[i][j] = x; n     } n   } n   bfs.push_back(pt(r, c)); n   w[r][c] = 0; n   while (!bfs.empty()) { n     pt q = bfs.front(); n     bfs.pop_front(); n     if (used[q.x][q.y] == 1) { n       continue; n     } n     used[q.x][q.y] = 1; n     parasha(pt(q.x, q.y + 1), q, 0, bfs, w); n     parasha(pt(q.x + 1, q.y), q, 0, bfs, w); n     parasha(pt(q.x - 1, q.y), q, 0, bfs, w); n     parasha(pt(q.x, q.y - 1), q, 1, bfs, w); n   } n   long long ans = 0; n   for (long long i = 0; i < n; ++i) { n     for (long long j = 0; j < m; ++j) { n       if (w[i][j] <= x && w[i][j] - (c - j) <= y) ++ans; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n using lint = long long; n using pi = pair<lint, lint>; n const int MAXN = 100005; n int n, m, sum; n int cnt[MAXN]; n set<int> s[MAXN]; n int p[MAXN]; n vector<tuple<int, int, int>> dap; n void MOVE(int dst, int src, int v) { n   vector<int> mutation; n   for (auto &i : s[dst]) { n     if (s[src].find(i) == s[src].end()) { n       continue; n     } n     s[src].erase(i); n     mutation.push_back(i); n   } n   while (v--) { n     auto x = *s[src].begin(); n     s[src].erase(x); n     s[dst].insert(x); n     dap.emplace_back(src + 1, dst + 1, x); n   } n   for (auto &i : mutation) s[src].insert(i); n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 0; i < n; i++) { n     int x; n     scanf( %d , &x); n     sum += x; n     p[i] = i; n     for (int j = 0; j < x; j++) { n       int v; n       scanf( %d , &v); n       s[i].insert(v); n     } n   } n   for (int i = 0; i < sum; i++) { n     cnt[n - 1 - i % n]++; n   } n   sort(p, p + n, n        [&](const int &a, const int &b) { return s[a].size() < s[b].size(); }); n   int lx = -1, ly = 1e9; n   for (int i = 0; i < n; i++) { n     if (s[p[i]].size() < cnt[i]) { n       lx = i; n     } n     if (s[p[i]].size() > cnt[i]) ly = min(ly, i); n   } n   if (lx == -1) { n     puts( 0 ); n     return 0; n   } n   while (true) { n     while (lx >= 0 && s[p[lx]].size() == cnt[lx]) lx--; n     while (ly < n && s[p[ly]].size() == cnt[ly]) ly++; n     if (lx == -1) break; n     int thres0 = cnt[lx] - s[p[lx]].size(); n     int thres1 = s[p[ly]].size() - cnt[ly]; n     MOVE(p[lx], p[ly], min(thres0, thres1)); n   } n   printf( %d n , dap.size()); n   for (auto &i : dap) { n     int x, y, z; n     tie(x, y, z) = i; n     printf( %d %d %d n , x, y, z); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, p, su; n long long a[100005], b[100005]; n long double ex[100005]; n bool check(long double mid) { n   long double need = 0; n   for (int i = 0; i < n; i++) { n     long double ne = max(0.0L, a[i] * (mid - ex[i])); n     need += ne; n   } n   return (mid * p >= need); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> p; n   for (int i = 0; i < n; i++) { n     cin >> a[i] >> b[i]; n     su += a[i]; n   } n   if (p >= su) { n     cout << -1; n   } else { n     for (int i = 0; i < n; i++) { n       ex[i] = (b[i] * 1.0L) / a[i]; n     } n     long double l = 0; n     long double r = 1e18; n     for (int i = 0; i < 120; i++) { n       long double mid = (l + r) / 2; n       if (check(mid)) { n         l = mid; n       } else { n         r = mid; n       } n     } n     if (r > 1e18 - 100) { n       cout << -1; n     } else { n       cout << setprecision(9) << l; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int W, H, N, num; n char ch; n multiset<int> maxHorSize, maxVertSize; n set<int> horiz, vert; n long long max_area; n long long find_max(set<int> &setCut, char cut) { n   auto med = setCut.find(num); n   auto big = med; n   auto sml = med; n   ++big; n   --sml; n   if (cut ==  h ) { n     maxHorSize.erase(maxHorSize.find(*big - *sml)); n     maxHorSize.insert(*med - *sml); n     maxHorSize.insert(*big - *med); n   } else if (cut ==  v ) { n     maxVertSize.erase(maxVertSize.find(*big - *sml)); n     maxVertSize.insert(*med - *sml); n     maxVertSize.insert(*big - *med); n   } n   return (long long)(*maxHorSize.rbegin()) * (long long)(*maxVertSize.rbegin()); n } n int main() { n   scanf( %d%d%d , &W, &H, &N); n   horiz = {0, H}; n   vert = {0, W}; n   maxHorSize = {H}; n   maxVertSize = {W}; n   for (auto i = 1; i != N + 1 - 2 * (1 > N); i += 1 - 2 * (1 > N)) { n     cin >> ch >> num; n     if (ch ==  H ) { n       horiz.insert(num); n       max_area = find_max(horiz,  h ); n     } else if (ch ==  V ) { n       vert.insert(num); n       max_area = find_max(vert,  v ); n     } n     printf( %I64d n , max_area); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<pair<long long, long long> > S; n set<pair<long long, long long> >::iterator it; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t, n; n   for (cin >> t; t--;) { n     cin >> n; n     S.clear(); n     long long a = 1, b = 0, ans = 0, u; n     for (int i = 0; i < n; i++) { n       cin >> u; n       long long s = a * (1 - b), e = a * (u - 1 - b); n       if (a < 0) swap(s, e); n       while (!S.empty()) { n         pair<long long, long long> v = *S.begin(); n         if (v.first >= s) n           break; n         else { n           S.erase(S.begin()); n           if (v.second >= s) S.insert(pair<long long, long long>(s, v.second)); n         } n       } n       while (!S.empty()) { n         it = S.end(); n         it--; n         pair<long long, long long> v = *it; n         if (v.second > e) n           S.erase(it); n         else n           break; n         if (v.first <= e) S.insert(pair<long long, long long>(v.first, e)); n       } n       if (S.empty()) { n         if (a > 0) n           S.insert(pair<long long, long long>(a * (1 - b), a * (u - b))); n         else n           S.insert(pair<long long, long long>(a * (u - b), a * (1 - b))); n       } else n         ans++; n       a *= -1, b = u - b; n       if (u % 2 == 0) { n         it = S.upper_bound( n             pair<long long, long long>(a * (u / 2 - b), 1000000000000000000ll)); n         if (it == S.begin()) n           S.insert( n               pair<long long, long long>(a * (u / 2 - b), a * (u / 2 - b))); n         else { n           it--; n           pair<long long, long long> v = *it; n           if (v.first <= a * (u / 2 - b) && v.second >= a * (u / 2 - b)) { n             S.clear(); n             a = 1; n             b = 0; n             ans++; n           } n           S.insert( n               pair<long long, long long>(a * (u / 2 - b), a * (u / 2 - b))); n         } n       } n     } n     cout << n * 2 - ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int A[26] = {0}, count = 0; n   string s; n   getline(cin, s); n   for (int i = 1; i < s.size(); i += 3) { n     A[int(s[i]) - 97] = 1; n   } n   for (int i = 0; i < 26; i++) { n     if (A[i] == 1) { n       count++; n     } n   } n   cout << count; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,unroll-loops,fast-math ) n using namespace std; n long long poww(long long a, long long b, long long md) { n   return (!b ? 1 n              : (b & 1 ? a * poww(a * a % md, b / 2, md) % md n                       : poww(a * a % md, b / 2, md) % md)); n } n const int maxn = 2000 * 100 + 5; n const long long inf = 9223372036854775807; n const long long mod = 1e9 + 7; n const int lg = 20; n const int SQ = 6000; n const int sq = maxn / SQ + 2; n int cnt[sq][maxn], fen[sq][maxn], type[maxn], v[maxn], p[maxn], res, n, q, n     a[maxn], num[maxn], mark[maxn], ans2, ans3, ans, c[maxn]; n vector<int> comp; n unordered_map<int, int> to; n void add(int pos, int i, int val) { n   for (i++; i < maxn; i += i & -i) fen[pos][i] += val; n } n int get(int pos, int i) { n   res = 0; n   for (i++; i > 0; i -= i & -i) res += fen[pos][i]; n   return res; n } n void build() { n   for (int i = 1; i <= n; i++) { n     cnt[i / SQ][a[i]]++; n   } n   for (int i = 1; i <= n; i++) { n     if (mark[a[i]]) continue; n     mark[a[i]] = 1; n     for (int j = 1; j < sq; j++) { n       cnt[j][a[i]] += cnt[j - 1][a[i]]; n     } n   } n   for (int i = 0; i < sq; i++) { n     for (int j = 1; j <= (long long)(comp).size(); j++) { n       add(i, cnt[i][j], 1); n     } n   } n } n void del(int x) { n   for (int i = x / SQ; i < sq; i++) { n     add(i, cnt[i][a[x]], -1); n     add(i, --cnt[i][a[x]], 1); n   } n } n void Add(int x) { n   for (int i = x / SQ; i < sq; i++) { n     add(i, cnt[i][a[x]], -1); n     add(i, ++cnt[i][a[x]], 1); n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     comp.push_back(a[i]); n   } n   cin >> q; n   for (int i = 1; i <= q; i++) { n     cin >> type[i] >> v[i] >> p[i]; n     if (type[i] == 1) comp.push_back(v[i]); n     if (type[i] == 2) { n       if (v[i] > 3) { n         if (v[i] & 1) n           v[i] = 3; n         else n           v[i] = 2; n       } n     } n   } n   sort((comp).begin(), (comp).end()); n   comp.resize(unique((comp).begin(), (comp).end()) - comp.begin()); n   for (int i = 0; i < (long long)(comp).size(); i++) { n     to[comp[i]] = i + 1; n     num[i + 1] = comp[i]; n   } n   for (int i = 1; i <= n; i++) a[i] = to[a[i]]; n   for (int i = 1; i <= q; i++) { n     if (type[i] == 1) v[i] = to[v[i]]; n   } n   build(); n   int x, y, t, ct = 0; n   for (int i = 1; i <= q; i++) { n     ct += (type[i] == 2); n     if (type[i] == 1) { n       del(p[i]); n       a[p[i]] = v[i]; n       Add(p[i]); n       continue; n     } n     x = v[i], y = p[i]; n     if (x == 1) { n       cout << num[a[y]] <<   n ; n       continue; n     } n     ans = a[y]; n     if (y / SQ > 0) n       ans2 = cnt[y / SQ - 1][ans]; n     else n       ans2 = 0; n     for (int j = y - (y % SQ); j <= y; j++) { n       if (a[j] == a[y]) ans2++; n     } n     if (x == 2) { n       cout << ans2 <<   n ; n       continue; n     } n     if (y / SQ > 0) n       ans3 = get(y / SQ - 1, maxn / 2) - get(y / SQ - 1, ans2 - 1); n     else { n       ans3 = 0; n       for (int j = 1; j <= y; j++) { n         c[a[j]]++; n         if (c[a[j]] == ans2) ans3++; n       } n       for (int j = 1; j <= y; j++) c[a[j]]--; n       cout << ans3 <<   n ; n       continue; n     } n     t = y / SQ - 1; n     for (int j = y - (y % SQ); j <= y; j++) { n       cnt[t][a[j]]++; n       if (cnt[t][a[j]] == ans2) ans3++; n     } n     for (int j = y - (y % SQ); j <= y; j++) cnt[t][a[j]]--; n     cout << ans3 <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const long long mx = 1e5 + 5; n long long middle(long long a, long long b, long long c) { n   if ((a <= b && b <= c) || (c <= b && b <= a)) n     return b; n   else if ((b <= a && a <= c) || (c <= a && a <= b)) n     return a; n   else n     return c; n } n bool ispalindrom(string s) { n   transform(s.begin(), s.end(), s.begin(), ::tolower); n   return (s[0] == s[s.size() - 1] ? 1 : 0); n } n bool as_second(const pair<long long, long long> &a, n                const pair<long long, long long> &b) { n   return (a.second < b.second); n } n bool ds_first(const pair<long long, long long> &a, n               const pair<long long, long long> &b) { n   return (a.first > b.first); n } n bool ds_second(const pair<long long, long long> &a, n                const pair<long long, long long> &b) { n   return a.second > b.second; n } n template <typename KeyType, typename ValueType> n std::pair<KeyType, ValueType> get_max(const std::map<KeyType, ValueType> &x) { n   using pairtype = std::pair<KeyType, ValueType>; n   return *std::max_element(x.begin(), x.end(), n                            [](const pairtype &p1, const pairtype &p2) { n                              return p1.second < p2.second; n                            }); n } n static inline bool isvowel(char ch) { n   static const std::string vowels( aeiouEAIOU ); n   return vowels.end() != std::find(vowels.begin(), vowels.end(), ch); n } n template <typename Map> n bool map_compare(Map const &lhs, Map const &rhs) { n   return lhs.size() == rhs.size() && n          std::equal(lhs.begin(), lhs.end(), rhs.begin()); n } n long long nCr(long long n, long long k) { n   long long ans = 1; n   k = k > n - k ? n - k : k; n   long long j = 1; n   for (; j <= k; j++, n--) { n     if (n % j == 0) { n       ans *= n / j; n     } else if (ans % j == 0) { n       ans = ans / j * n; n     } else { n       ans = (ans * n) / j; n     } n   } n   return ans; n } n string str, str1, str2, str3, str4, str5, str6, str7; n char ch, ch1, ch2, ch3; n bool flag = true, flag1 = true, flag2 = true; n long long a, b, c, d, e, f, g, h, l, i, j, k, m, n, o, p, q, r, s, t, u, v, w, n     x, y, z, a1, b1, a2, b2, a3, b3, a4, b4, a5, b5, n     f1 = 0, f2 = 0, cnt = 0, cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0, sum = 0, n     sum1 = 0, sum2 = 0, sum3 = 0, ma = 0, ma1 = 0, mi = INT_MAX, mi1 = INT_MAX, n     temp = 0, temp1 = 0, temp2 = 0; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   vector<long long> v(n); n   for (long long i = 0; i < n; i++) { n     cin >> v[i]; n     sum += v[i]; n   } n   if (sum != 0) { n     cout <<  YES n1 n ; n     cout << 1 <<     << n << endl; n   } else { n     p = 0; n     for (long long i = 0; i < n; i++) { n       if (v[i] != 0) { n         p = i + 1; n         break; n       } n     } n     if (p == 0) { n       return cout <<  NO n  << endl, 0; n     } else { n       cout <<  YES n2 n ; n       cout << 1 <<     << p << endl; n       cout << p + 1 <<     << n << endl; n     } n   } n   return 0; n } n