#include <bits/stdc++.h> n using namespace std; n const int M = 1 << 13; n const int N = 13; n long long dp[M][N][2][2]; n bool used[M][N][2][2]; n vector<int> digits_hour, digits_minuts; n long long solve(int mask, int pos, bool flag1, bool flag2) { n   int h = digits_hour.size(); n   int min = digits_minuts.size(); n   if (pos == h + min) { n     return 1LL; n   } n   long long &ans = dp[mask][pos][flag1][flag2]; n   if (used[mask][pos][flag1][flag2]) { n     return ans; n   } n   used[mask][pos][flag1][flag2] = true; n   if (pos >= h) { n     for (int t = 0; t < 7; t++) { n       int el = 1 << t; n       if ((mask & el) == 0) { n         if (flag2 || digits_minuts[pos - h] >= t) { n           ans += solve(mask | el, pos + 1, flag1, n                        flag2 || (digits_minuts[pos - h] > t)); n         } n       } n     } n   } else { n     for (int t = 0; t < 7; t++) { n       int el = 1 << t; n       if ((mask & el) == 0) { n         if (flag1 || digits_hour[pos] >= t) { n           ans += n               solve(mask | el, pos + 1, flag1 || (digits_hour[pos] > t), flag2); n         } n       } n     } n   } n   return ans; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   int n, m; n   scanf( %d %d , &n, &m); n   n--, m--; n   if (n == 0) { n     digits_hour.push_back(0); n   } n   if (m == 0) { n     digits_minuts.push_back(0); n   } n   while (n) { n     digits_hour.push_back(n % 7); n     n /= 7; n   } n   reverse(digits_hour.begin(), digits_hour.end()); n   while (m) { n     digits_minuts.push_back(m % 7); n     m /= 7; n   } n   reverse(digits_minuts.begin(), digits_minuts.end()); n   printf( %lld n , solve(0, 0, false, false)); n   return 0; n } n


#include <bits/stdc++.h> n using std::map; n long long n; n long long p2[100005 * 2] = {1}; n long long fa[100005 * 2], size[100005 * 2], p[100005 * 2]; n long long vis[100005 * 2]; n map<long long, long long> mx, my; n long long cnt; n long long ans = 1; n long long getfa(long long x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); } n int main() { n   scanf( %I64d , &n); n   for (long long i = 1; i <= n * 2; i++) { n     fa[i] = i; n     size[i] = 1; n     p2[i] = (p2[i - 1] * 2) % ((int)1e9 + 7); n   } n   long long x, y, px, py, fx, fy; n   for (long long i = 1; i <= n; i++) { n     scanf( %I64d %I64d , &x, &y); n     if (mx.find(x) == mx.end()) { n       mx[x] = ++cnt; n     } n     if (my.find(y) == my.end()) { n       my[y] = ++cnt; n     } n     px = mx[x]; n     py = my[y]; n     fx = getfa(px); n     fy = getfa(py); n     if (fx == fy) { n       p[fx] = 1; n     } else { n       fa[fx] = fy; n       size[fy] += size[fx]; n       p[fy] |= p[fx]; n     } n     getfa(px); n   } n   for (long long i = 1; i <= cnt; i++) { n     long long fi = getfa(i); n     if (vis[fi]) continue; n     vis[fi] = 1; n     if (p[fi]) { n       ans *= p2[size[fi]]; n     } else { n       ans *= (p2[size[fi]] - 1); n     } n     ans %= ((int)1e9 + 7); n   } n   printf( %I64d n , ans); n } n


//愿你和你重要的人能够重逢！ n #include<bits/stdc++.h> n using namespace std; n template<typename T>inline void read(T &x) n { n  x=0;char c=getchar(),f=0; n  for(;c<48||c>57;c=getchar()) if(!(c^45)) f=1; n  for(;c>=48&&c<=57;c=getchar()) x=(x<<1)+(x<<3)+(c^48); n  f?x=-x:0; n } n long long l,r,st,t,x,y;set<long long>s; n int main() n { n  read(st),read(l),read(r),read(t),read(x),read(y); n  if(x>y) n  { n   if((x-y<2e18/t&&st-l>=t*(x-y))&&st+y<=r) puts( Yes ); n   else if(x-y<2e18/t&&st-l>=t*x-(t-1)*y) puts( Yes ); n   else puts( No ); n   return 0; n  } n  long long qwq=st,tp;qwq=l+(qwq-l)%x,t-=(st-qwq)/x; n  if(t<=0) return puts( Yes ),0;else if(qwq+y>r) return puts( No ),0; n  while(t>0) n  { n   qwq+=y;if(qwq>r) return puts( No ),0;else tp=qwq,qwq=l+(qwq-l)%x,t-=(tp-qwq)/x; n   if(t<=0) return puts( Yes ),0;else if(s.count(qwq)) return puts( Yes ),0;else s.insert(qwq); n  } n  return puts( Yes ),0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, x, maxi; n string s =  ABRACADABRA ; n int main() { n   cin >> n; n   maxi = 0; n   while (n--) { n     cin >> x; n     maxi = max(maxi, x); n   } n   cout << (maxi ^ x) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, w[200200], h[200200], W, a[200200], maxH, maxH2, id; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %d%d , &w[i], &h[i]); n     if (h[i] > maxH) { n       maxH = h[i]; n       id = i; n     } n     W += w[i]; n   } n   for (int i = 1; i <= n; ++i) { n     if (i != id) maxH2 = max(maxH2, h[i]); n   } n   for (int i = 1; i <= n; ++i) { n     if (h[i] == maxH) n       printf( %d  , maxH2 * (W - w[i])); n     else n       printf( %d  , maxH * (W - w[i])); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[4], i, j, min = 1000, x, y; n   for (i = 0; i < 4; i++) { n     cin >> a[i]; n     if (min > a[i]) min = a[i]; n   } n   cin >> x >> y; n   if (x >= min) { n     cout << 0; n     return 0; n   } else if (y < min) { n     cout << y - x + 1; n   } else { n     cout << min - x; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int power(long long int x, long long int y) { n   long long int one = 1; n   if (!y) n     return one; n   else if (y == 1) n     return x; n   else { n     long long int y1 = power(x, y >> 1); n     long long int y2 = y1 * y1; n     if (y & 1) n       return x * y2; n     else n       return y2; n   } n } n bool comp(pair<int, int> a, pair<int, int> b) { n   if (a.first != b.first) n     return a.first < b.first; n   else n     return a.second > b.second; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, mx; n   cin >> n >> mx; n   long long int a[n]; n   map<long long int, long long int> occ; n   for (int i = 0; i < n; i++) cin >> a[i], occ[a[i]]++; n   long long int allow = 8 * mx; n   allow /= n; n   if (allow > 20) { n     cout << 0; n     return 0; n   } n   long long int dis = power(2, allow); n   vector<pair<int, int> > give; n   for (auto v : occ) give.push_back(make_pair(v.first, v.second)); n   long long int n1 = give.size(); n   sort(give.begin(), give.end(), comp); n   long long int ans = INT_MAX; n   long long int presum[n1]; n   presum[0] = give[0].second; n   for (int i = 1; i < n1; i++) presum[i] = presum[i - 1] + give[i].second; n   if (n1 <= dis) { n     cout << 0; n     return 0; n   } n   for (int i = 0; i <= n1 - dis; i++) { n     int rem = 0; n     if (i == 0) n       rem = presum[i + dis - 1]; n     else n       rem = presum[i + dis - 1] - presum[i - 1]; n     if (n - rem < ans) ans = n - rem; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n const int MAX = 2e5 + 5; n const long long MAX2 = 11; n const long long MOD = 998244353; n const long long MOD2 = 1000000006; n const long long INF = 2e18; n const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0}; n const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0}; n const double pi = acos(-1); n const double EPS = 1e-9; n const int block = 316; n int n, q, push_front[MAX], le[MAX], ri[MAX], l[MAX], r[MAX], cl[MAX], jlh[MAX], n     cnt, a, b, len, id, ls; n long long hs[MAX], x[MAX], key, tmp, pj, t2; n bool z[MAX], st; n char c; n pair<long long, int> res; n inline pair<long long, int> f(int a, int b) { n   if (a > b) return {0, 0}; n   int len = b - a + 1; n   return {x[b] - x[a - 1] * hs[len], len}; n } n inline pair<long long, int> comp(int a, int b) { n   tmp = pj = st = 0; n   if (z[a]) { n     if (ri[a] - a + 1 & 1) ++pj; n     a = ri[a] + 1; n   } n   if (z[b]) { n     if (b - le[b] + 1 & 1) st = 1; n     b = le[b] - 1; n   } n   if (cl[a] == cl[b]) { n     tmp = l[a] + r[b] - jlh[cl[a]]; n     if (st) tmp *= key; n     return {tmp, 1 + pj + st}; n   } n   res = f(cl[a] + 1, cl[b] - 1); n   tmp = (l[a] * hs[res.second] + res.first) * key + r[b]; n   if (st) tmp *= key; n   return {tmp, cl[b] - cl[a] + 1 + pj + st}; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   key = 2000003153; n   cin >> n; n   hs[0] = 1; n   for (int i = 1; i <= n; ++i) { n     cin >> c, z[i] = (c ==  1 ), push_front[i] = push_front[i - 1] + z[i], n               hs[i] = hs[i - 1] * key; n     if (z[i]) { n       st ^= 1; n       if (le[i - 1]) n         le[i] = le[i - 1]; n       else n         le[i] = i; n     } else { n       if (st) { n         jlh[id] = cnt; n         x[id] = x[id - 1] * key + cnt; n         st = cnt = 0; n       } n       if (cnt == 0) ++id; n       ++cnt, r[i] = cnt; n       cl[i] = id; n     } n   } n   if (cnt) x[id] = x[id - 1] * key + cnt, jlh[id] = cnt; n   ls = id; n   cnt = 0; n   for (int i = n; i >= 1; --i) { n     if (z[i]) { n       if (ri[i + 1]) n         ri[i] = ri[i + 1]; n       else n         ri[i] = i; n     } else { n       if (cl[i] != ls) cnt = 0, ls = cl[i]; n       l[i] = ++cnt; n     } n   } n   cin >> q; n   while (q--) { n     cin >> a >> b >> len; n     if (push_front[a + len - 1] - push_front[a - 1] != n         push_front[b + len - 1] - push_front[b - 1]) { n       cout <<  No n ; n       continue; n     } n     if (push_front[a + len - 1] - push_front[a - 1] == 0 || n         push_front[a + len - 1] - push_front[a - 1] == len) { n       cout <<  Yes n ; n       continue; n     } n     if (comp(a, a + len - 1) == comp(b, b + len - 1)) n       cout <<  Yes n ; n     else n       cout <<  No n ; n   } n   return 0; n } n


#include <iostream> n #include <cmath> n using namespace std; n int t, n, a[105]; n int main(){ n  cin>>t; n  while(t--){ n   cin>>n; n   int suc = 0; n   for(int i=0; i<n; i++) n    cin>>a[i]; n   for(int i=0; i<n; i++){ n    int k = (int)sqrt((double)a[i]); n    if(k*k != a[i]){ n     suc = 1; n     break; n    } n   } n   if(suc) n    cout<< YES <<endl; n   else n    cout<< NO <<endl; n  } n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2600, MAXL = 10000 * 5 + 10, MAXALP = 26; n int n, f[MAXN][MAXN], cnt[MAXALP], p[MAXN][MAXN]; n char str[MAXL]; n pair<int, int> Tohka; n string Houki; n void Print(const pair<int, int> &a, int res) { n   if (res <= 0) return; n   if (p[a.first][a.second] == -1) n     Print(make_pair(a.first - 1, a.second), res); n   else if (p[a.first][a.second] == 1) n     Print(make_pair(a.first, a.second + 1), res); n   else { n     Print(make_pair(a.first - 1, a.second + 1), n           res - 2 + (a.first == a.second)); n     if (res <= 100) Houki += str[a.first]; n   } n } n int main() { n   scanf( %s , str + 1); n   n = strlen(str + 1); n   if (n >= 2600) { n     for (int i = 1; i <= n; ++i) ++cnt[str[i] -  a ]; n     for (int i = 0; i < MAXALP; ++i) n       if (cnt[i] >= 100) { n         for (int j = 0; j < 100; ++j) printf( %c ,  a  + i); n         exit(0); n       } n   } n   for (int i = 1; i <= n; ++i) n     for (int j = n; j >= i; --j) { n       f[i][j] = f[i - 1][j], p[i][j] = -1; n       if (f[i][j] < f[i][j + 1]) f[i][j] = f[i][j + 1], p[i][j] = 1; n       if (str[i] == str[j] && f[i][j] < f[i - 1][j + 1] + 1) n         f[i][j] = f[i - 1][j + 1] + 1, p[i][j] = 0; n       if (f[i][j] * 2 - (i == j) > n           f[Tohka.first][Tohka.second] * 2 - (Tohka.first == Tohka.second)) n         Tohka = make_pair(i, j); n     } n   Print(Tohka, n         f[Tohka.first][Tohka.second] * 2 - (Tohka.first == Tohka.second)); n   string rev = n       Houki.substr(0, Houki.size() - (Tohka.first == Tohka.second && n                                       f[Tohka.first][Tohka.second] * 2 - n                                               (Tohka.first == Tohka.second) <= n                                           100)); n   reverse(rev.begin(), rev.end()); n   Houki += rev; n   cout << Houki << endl; n   fclose(stdin); n   fclose(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 5; n int ls[N << 2], rs[N << 2], rt[N << 2], sum[N << 2]; n int rcnt; n void update(int &rt, int l, int r, int pos) { n   if (rt == 0) rt = ++rcnt; n   if (l == r) { n     sum[rt]++; n     return; n   } n   int mid = (l + r) >> 1; n   if (pos <= mid) { n     update(ls[rt], l, mid, pos); n   } else { n     update(rs[rt], mid + 1, r, pos); n   } n   sum[rt] = sum[ls[rt]] + sum[rs[rt]]; n } n int query(int &rt, int l, int r, int ql, int qr) { n   if (rt == 0) return 0; n   if (ql <= l && qr >= r) return sum[rt]; n   int mid = (l + r) >> 1, res = 0; n   if (ql <= mid) res += query(ls[rt], l, mid, ql, qr); n   if (qr > mid) res += query(rs[rt], mid + 1, r, ql, qr); n   return res; n } n int n, k; n struct node { n   int x, r, f; n   bool operator<(const node &z) const { return r > z.r; } n } a[N]; n const int low = 1000000000; n int main() { n   scanf( %d %d , &n, &k); n   for (int i = 1; i <= n; ++i) { n     scanf( %d %d %d , &a[i].x, &a[i].r, &a[i].f); n   } n   sort(a + 1, a + n + 1); n   long long ans = 0; n   for (int i = 1; i <= n; ++i) { n     for (int j = a[i].f - k; j <= a[i].f + k; ++j) { n       if (j < 1 || j > 10000) continue; n       ans += query(rt[j], 1, low, max(1, a[i].x - a[i].r), n                    min(low, a[i].x + a[i].r)); n     } n     update(rt[a[i].f], 1, low, a[i].x); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long double EPS = 1e-12; n const int N = 100000 + 10; n long double sqr(long double x) { return x * x; } n struct PT { n   long double x, y; n   PT(long double x = 0, long double y = 0) : x(x), y(y) {} n   void in() { n     double xx, yy; n     scanf( %lf%lf , &xx, &yy); n     x = xx, y = yy; n   } n } P[N]; n bool operator<(const PT& p1, const PT& p2) { n   if (fabs(p1.x - p2.x) > EPS) return p1.x < p2.x; n   return p1.y + EPS < p2.y; n } n bool operator==(const PT& p1, const PT& p2) { n   return fabs(p1.x - p2.x) < EPS && fabs(p1.y - p2.y) < EPS; n } n PT operator+(PT p1, PT p2) { return PT(p1.x + p2.x, p1.y + p2.y); } n PT operator-(PT p1, PT p2) { return PT(p1.x - p2.x, p1.y - p2.y); } n PT operator*(PT p, long double c) { return PT(p.x * c, p.y * c); } n PT operator/(PT p, long double c) { return PT(p.x / c, p.y / c); } n long double dis(PT p) { return sqrt(sqr(p.x) + sqr(p.y)); } n long double dis2(PT p) { return sqr(p.x) + sqr(p.y); } n long double dis2(PT p1, PT p2) { return sqr(p1.x - p2.x) + sqr(p1.y - p2.y); } n long double dis(PT p1, PT p2) { return sqrt(dis2(p1, p2)); } n long double vect(PT p1, PT p2) { return p1.x * p2.y - p2.x * p1.y; } n long double scal(PT p1, PT p2) { return p1.x * p2.x + p1.y * p2.y; } n long double getAngle(PT p) { return atan2(p.y, p.x); } n long double vect(PT p, PT p1, PT p2) { return vect(p1 - p, p2 - p); } n long double scal(PT p, PT p1, PT p2) { return scal(p1 - p, p2 - p); } n long double getAngle(PT p, PT p1, PT p2) { n   return acos(scal(p, p1, p2) / dis(p, p1) / dis(p, p2)); n } n long double disToLineSgn(PT p, PT p1, PT p2) { n   return vect(p, p1, p2) / dis(p1, p2); n } n long double r[N]; n PT P1, P2; n vector<pair<long double, long double> > vec[2]; n int main() { n   P1.in(), P2.in(); n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     P[i].in(); n     double rr; n     scanf( %lf , &rr); n     r[i] = rr; n   } n   PT M = (P1 + P2) / 2; n   long double a = dis(P1, P2) / 2; n   int flg = 0; n   for (int i = 0; i < n; i++) { n     long double d = disToLineSgn(P[i], P1, P2); n     long double l2 = dis2(M, P[i]); n     long double p = l2 - sqr(a) - sqr(r[i]); n     long double A = 4 * (sqr(d) - sqr(r[i])); n     long double B = -4 * d * p; n     long double C = sqr(p) - 4 * sqr(a * r[i]); n     long double D = B * B - 4 * A * C; n     if (D < EPS) continue; n     long double x1 = (-B - sqrt(D)) / (2 * A), x2 = (-B + sqrt(D)) / (2 * A); n     if (x2 < EPS) n       vec[0].push_back(pair<long double, long double>(-x2, -x1)); n     else if (x1 > -EPS) n       vec[1].push_back(pair<long double, long double>(x1, x2)); n     else { n       flg = 1; n       vec[0].push_back(pair<long double, long double>(0, -x1)); n       vec[1].push_back(pair<long double, long double>(0, x2)); n     } n   } n   if (!flg) return printf( %.10lf n , (double)a), 0; n   for (int i = 0; i < 2; i++) sort(vec[i].begin(), vec[i].end()); n   long double ans = 1e60; n   for (int i = 0; i < 2; i++) { n     long double prv = EPS * 2; n     for (auto it : vec[i]) { n       if (it.first < prv - EPS) n         prv = max(prv, it.second); n       else { n         ans = min(ans, prv); n         break; n       } n     } n     ans = min(ans, prv); n   } n   printf( %.10lf n , (double)sqrt(sqr(ans) + sqr(a))); n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n const double eps = 1e-12; n const int inf = 2000000000; n const long long int infLL = (long long int)2e18; n long long int MOD = 1000000007; n int MOD1 = 1000000007; n int MOD2 = 1000000009; n inline bool checkBit(long long int n, long long int i) { n   return n & (1LL << i); n } n inline long long int setBit(long long int n, long long int i) { n   return n | (1LL << i); n   ; n } n inline long long int resetBit(long long int n, long long int i) { n   return n & (~(1LL << i)); n } n int dx[] = {0, 0, +1, -1}; n int dy[] = {+1, -1, 0, 0}; n inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } n inline bool isLeapYear(long long int year) { n   return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0); n } n inline void normal(long long int &a) { n   a %= MOD; n   (a < 0) && (a += MOD); n } n inline long long int modMul(long long int a, long long int b) { n   a %= MOD, b %= MOD; n   normal(a), normal(b); n   return (a * b) % MOD; n } n inline long long int modAdd(long long int a, long long int b) { n   a %= MOD, b %= MOD; n   normal(a), normal(b); n   return (a + b) % MOD; n } n inline long long int modSub(long long int a, long long int b) { n   a %= MOD, b %= MOD; n   normal(a), normal(b); n   a -= b; n   normal(a); n   return a; n } n inline long long int modPow(long long int b, long long int p) { n   long long int r = 1LL; n   while (p) { n     if (p & 1) r = modMul(r, b); n     b = modMul(b, b); n     p >>= 1LL; n   } n   return r; n } n inline long long int modDiv(long long int a, long long int b) { n   return modMul(a, modPow(b, MOD - 2)); n } n bool comp(const pair<long long int, pair<long long int, long long int> > &p1, n           const pair<long long int, pair<long long int, long long int> > &p2) { n   return p1.first > p2.first; n } n bool comp1(const pair<long long int, long long int> &p1, n            const pair<long long int, long long int> &p2) { n   if (p1.first == p2.first) { n     return p1.second > p2.second; n   } n   return p1.first < p2.first; n } n long long int converter(string a) { n   long long int i, mul = 1, r, t, ans = 0LL; n   if (a.length() == 0) return 0; n   for (i = a.length() - 1; i >= 0; i--) { n     t = a[i] -  0 ; n     r = t % 10; n     ans += (mul * r); n     mul = mul * 10; n   } n   return ans; n } n int msb(unsigned x) { n   union { n     double a; n     int b[2]; n   }; n   a = x; n   return (b[1] >> 20) - 1023; n } n const int MAX = (int)2e5 + 5; n const int sz = (int)5e5 + 5; n int on[MAX], a[MAX], n, big[sz], cnt[sz]; n long long int ans, tot; n void process() { n   int i, j; n   for (i = 2; i < sz; ++i) { n     if (big[i]) continue; n     for (j = i; j < sz; j += i) { n       big[j] = i; n     } n   } n } n long long int cal(long long int val) { return (val * (val - 1)) / 2LL; } n void doo(int val, int pass) { n   vector<int> store; n   while (val > 1) { n     int p = big[val]; n     store.push_back(p); n     while (val % p == 0) val = val / p; n   } n   int nn = store.size(), i, j; n   for (i = 1; i < (1 << nn); ++i) { n     long long int now = 1LL; n     for (j = 0; j < nn; ++j) { n       if (i & (1 << j)) now *= store[j]; n     } n     if (pass == 1) { n       if (__builtin_popcountll(i) & 1) n         ans += cnt[now]; n       else n         ans -= cnt[now]; n       cnt[now]++; n     } else { n       cnt[now]--; n       if (__builtin_popcountll(i) & 1) n         ans -= cnt[now]; n       else n         ans += cnt[now]; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int q, i, x; n   process(); n   ans = 0LL; n   cin >> n >> q; n   for (i = 1; i <= n; ++i) cin >> a[i]; n   for (i = 1; i <= q; ++i) { n     cin >> x; n     if (on[x] == true) n       doo(a[x], -1), --tot, on[x] = false; n     else { n       doo(a[x], 1), ++tot, on[x] = true; n     } n     cout << cal(tot) - ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int num = 0; n   int a[100]; n   int i = 0; n   int m = 0; n   int yushu; n   char hex[16] = { 0 ,  1 ,  2 ,  3 ,  4 ,  5 ,  6 ,  7 , n                    8 ,  9 ,  A ,  B ,  C ,  D ,  E ,  F }; n   scanf( %d , &num); n   if (num == 0) { n     printf( 1 n ); n     return 0; n   } n   while (num > 0) { n     yushu = num % 16; n     a[i++] = yushu; n     num = num / 16; n   } n   int output = 0; n   for (i = i - 1; i >= 0; i--) { n     m = a[i]; n     if (hex[m] ==  0 ) output++; n     if (hex[m] ==  4 ) output++; n     if (hex[m] ==  6 ) output++; n     if (hex[m] ==  8 ) output += 2; n     if (hex[m] ==  9 ) output++; n     if (hex[m] ==  A ) output++; n     if (hex[m] ==  B ) output += 2; n     if (hex[m] ==  D ) output++; n   } n   printf( %d n , output); n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = (int)1e9; n const int mod = inf + 7; n const double eps = 1e-9; n const double pi = acos(-1.0); n int n, ind = -1; n int a[100100], b[100100]; n pair<int, int> c[100100]; n int v[100100], pos[100100]; n vector<pair<int, int> > ans; n bool is_happy(int x) { n   if (x == 0) return true; n   int c = x % 10; n   if (c != 4 && c != 7) return false; n   return is_happy(x / 10); n } n void sw(int x, int y) { n   if (x == y) return; n   ans.push_back(make_pair(x, y)); n   swap(a[x], a[y]); n   pos[a[x]] = x; n   pos[a[y]] = y; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     scanf( %d , a + i); n     b[i] = a[i]; n     c[i] = make_pair(a[i], i); n     if (is_happy(a[i])) ind = i; n   } n   sort(b, b + n); n   bool ok = 1; n   for (int i = 0; i < n; i++) ok &= (a[i] == b[i]); n   if (ok) { n     printf( 0 n ); n     return 0; n   } n   if (ind == -1) { n     if (ok) n       printf( 0 n ); n     else n       printf( -1 n ); n     return 0; n   } n   sort(c, c + n); n   for (int i = 0; i < n; i++) a[c[i].second] = i; n   for (int i = 0; i < n; i++) pos[a[i]] = i; n   int x = a[ind]; n   for (int i = 0; i < n; i++) { n     if (i == x) continue; n     if (a[i] == i) continue; n     int target = pos[i]; n     sw(ind, i); n     ind = i; n     sw(ind, target); n     ind = target; n   } n   printf( %d n , (int)ans.size()); n   for (__typeof(ans.begin()) it = ans.begin(); it != ans.end(); it++) { n     printf( %d %d n , it->first + 1, it->second + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100010], b[100010], ja[100010]; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     ja[a[i]] = i; n   } n   for (int i = 2; i <= n; i++) { n     if (ja[i] > ja[i - 1]) n       b[i] = 1; n     else n       b[i] = 0; n   } n   int ad = 0; n   for (int i = 1; i <= n; i++) { n     int j = i; n     while (b[j] == 1) j++; n     ad = max(ad, j - i + 1); n     i = j; n   } n   cout << n - ad << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 80005, maxe = 3000005, maxs = 80005, INF = 0x3f3f3f3f; n int n, q, N, m, S, T, a[maxn]; n struct event { n   int x, l, r, f; n   event(int _x = 0, int _l = 0, int _r = 0, int _f = 0) n       : x(_x), l(_l), r(_r), f(_f) {} n   bool operator<(const event &b) const { n     return x < b.x || x == b.x && f > b.f; n   } n } E[maxs]; n int son[maxe], nxt[maxe], lnk[maxn], flw[maxe], cap[maxe], tot = 1; n inline void add(int x, int y, int f) { n   son[++tot] = y; n   nxt[tot] = lnk[x]; n   lnk[x] = tot; n   flw[tot] = 0; n   cap[tot] = f; n   son[++tot] = x; n   nxt[tot] = lnk[y]; n   lnk[y] = tot; n   flw[tot] = 0; n   cap[tot] = 0; n } n int d[maxn], que[maxn], pos[maxn]; n bool bfs() { n   memset(d, 63, sizeof(d)); n   int hed = 0, til = 1; n   que[1] = S; n   d[S] = 0; n   while (hed != til) { n     int x = que[++hed]; n     for (int j = lnk[x]; j; j = nxt[j]) n       if (d[son[j]] == INF && flw[j] < cap[j]) n         d[que[++til] = son[j]] = d[x] + 1; n   } n   return d[T] != INF; n } n int dfs(int x, int flow) { n   if (x == T || flow == 0) return flow; n   int res = 0, f; n   for (int &j = pos[x]; j; j = nxt[j]) n     if (d[son[j]] == d[x] + 1 && n         (f = dfs(son[j], min(flow, cap[j] - flw[j]))) > 0) { n       flw[j] += f; n       flw[j ^ 1] -= f; n       res += f; n       flow -= f; n       if (flow == 0) break; n     } n   return res; n } n int dinic() { n   int ans = 0; n   while (bfs()) { n     memcpy(pos, lnk, sizeof(lnk)); n     ans += dfs(S, INF); n   } n   return ans; n } n int ls[maxs], rs[maxs], Rx, Ry; n void build(int &x, int l, int r, int d) { n   x = ++N; n   if (l == r) { n     if (d) n       add(x, T, 1); n     else n       add(S, x, 1); n     return; n   } n   int mid = l + r >> 1; n   build(ls[x], l, mid, d); n   build(rs[x], mid + 1, r, d); n   if (d) n     add(x, ls[x], INF), add(x, rs[x], INF); n   else n     add(ls[x], x, INF), add(rs[x], x, INF); n } n void qry(int x, int l, int r, int ql, int qr, int z, int d) { n   if (ql <= l && r <= qr) { n     if (d) n       add(z, x, INF); n     else n       add(x, z, INF); n     return; n   } n   if (qr < l || r < ql) return; n   int mid = l + r >> 1; n   qry(ls[x], l, mid, ql, qr, z, d); n   qry(rs[x], mid + 1, r, ql, qr, z, d); n } n void cover(int x, int l, int r) { n   for (int i = l; i <= r; i++) a[i] = x; n } n void work(int x, int l, int r) { n   for (int i = l, j = l; i <= r; i = j) { n     while (j <= r && a[i] == a[j]) j++; n     N++; n     qry(Rx, 1, n, a[i] + 1, x, N, 0); n     qry(Ry, 1, n, i, j - 1, N, 1); n   } n } n int main() { n   scanf( %d%d , &n, &q); n   for (int i = 1; i <= q; i++) { n     int x, y, xx, yy; n     scanf( %d%d%d%d , &x, &y, &xx, &yy); n     E[++m] = event(x - 1, y, yy, 0); n     E[++m] = event(xx, y, yy, 1); n   } n   S = ++N; n   T = ++N; n   build(Rx, 1, n, 0); n   build(Ry, 1, n, 1); n   sort(E + 1, E + 1 + m); n   for (int i = 1; i <= m; i++) n     if (E[i].f) n       cover(E[i].x, E[i].l, E[i].r); n     else n       work(E[i].x, E[i].l, E[i].r); n   work(n, 1, n); n   printf( %d , dinic()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double EPS = 1e-8; n const int N = 1e5 + 10; n int n, q; n int sgn(long double x) { return x < -EPS ? -1 : x > EPS; } n struct Point { n   Point() {} n   long double x, y; n   Point(long double x, long double y) : x(x), y(y) {} n   void read() { cin >> x >> y; } n   Point operator-(const Point& p) { return Point(x - p.x, y - p.y); } n   long double operator*(const Point& p) { return x * p.x + y * p.y; } n   long double operator^(const Point& p) { return x * p.y - y * p.x; } n   long double length() { return hypotl(x, y); } n } poly[N]; n using Vec = Point; n long double getIntersection(Point p, Vec v, Point q, Vec w) { n   return (w ^ (p - q)) / (v ^ w); n } n long double work(Point p, Vec v) { n   long double ret = 0; n   vector<pair<long double, int> > pos; n   for (int i = 1; i <= n; i++) { n     int s1 = sgn(v ^ (poly[i] - p)); n     int s2 = sgn(v ^ (poly[i + 1] - p)); n     if (s1 == s2) continue; n     long double o = getIntersection(p, v, poly[i], poly[i + 1] - poly[i]); n     if (s1 > s2) n       pos.push_back({o, s1 && s2 ? 2 : 1}); n     else n       pos.push_back({o, s1 && s2 ? -2 : -1}); n   } n   sort(pos.begin(), pos.end()); n   int flag = 0; n   for (int i = 0; i + 1 < pos.size(); i++) { n     flag += pos[i].second; n     if (flag) ret += pos[i + 1].first - pos[i].first; n   } n   return ret * v.length(); n } n int main() { n   ios ::sync_with_stdio(false); n   cin >> n >> q; n   for (int i = 1; i <= n; i++) poly[i].read(); n   poly[n + 1] = poly[1]; n   while (q--) { n     Point a, b; n     a.read(); n     b.read(); n     cout << fixed << setprecision(20) << work(a, b - a) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int test; n   cin >> test; n   while (test--) { n     int i, n, k; n     string s; n     cin >> n; n     cin >> s; n     vector<pair<string, int> > ans; n     for (i = 0; i < n; i++) { n       string sl = s.substr(0, i); n       string sr = s.substr(i, n - i); n       if (i % 2 != n % 2) reverse(sl.begin(), sl.end()); n       ans.push_back(make_pair(sr + sl, i + 1)); n     } n     sort(ans.begin(), ans.end()); n     cout << ans[0].first << endl << ans[0].second << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string n, m; n   int w = 0, b[10000]; n   cin >> n; n   for (int i = 0; i < n.length(); i++) { n     if (n.substr(i, 1) ==  r ) cout << i + 1 << endl; n   } n   for (int i = n.length() - 1; i >= 0; i--) { n     if (n.substr(i, 1) ==  l ) cout << i + 1 << endl; n   } n   cin >> n; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n unsigned int max_ID(long long int a[], long long int b[], unsigned int n) { n   unsigned int max_ID; n   unsigned long long int max; n   max_ID = 0; n   max = pow(a[0] - b[0], 2); n   for (unsigned int i = 1; i < n; i++) { n     if (pow(a[i] - b[i], 2) > max) { n       max_ID = i; n       max = pow(a[i] - b[i], 2); n     } n   } n   return max_ID; n } n int main() { n   unsigned int n, k1, k2, ID; n   unsigned long long int sum = 0; n   cin >> n >> k1 >> k2; n   long long int a[n], b[n]; n   for (unsigned int i = 0; i < n; i++) cin >> a[i]; n   for (unsigned int i = 0; i < n; i++) cin >> b[i]; n   while (k1 > 0 || k2 > 0) { n     ID = max_ID(a, b, n); n     if (pow((a[ID] - 1) - b[ID], 2) < pow(a[ID] - b[ID], 2)) { n       if (k1 > 0) { n         a[ID]--; n         k1--; n         continue; n       } n     } n     if (pow(a[ID] - (b[ID] + 1), 2) < pow(a[ID] - b[ID], 2)) { n       if (k2 > 0) { n         b[ID]++; n         k2--; n         continue; n       } n     } n     if (pow(a[ID] - (b[ID] - 1), 2) < pow(a[ID] - b[ID], 2)) { n       if (k2 > 0) { n         b[ID]--; n         k2--; n         continue; n       } n     } n     if (pow((a[ID] + 1) - b[ID], 2) < pow(a[ID] - b[ID], 2)) { n       if (k1 > 0) { n         a[ID]++; n         k1--; n         continue; n       } n     } n     if (pow(a[ID] - b[ID], 2) == 0) { n       if (k1 > 0) { n         a[ID]++; n         k1--; n       } else if (k2 > 0) { n         b[ID]++; n         k2--; n       } n     } n   } n   for (unsigned int i = 0; i < n; i++) { n     sum += pow(a[i] - b[i], 2); n   } n   cout << sum; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace chrono; n template <class T> n void Swap(T& a, T& b) { n   a ^= b; n   b ^= a; n   a ^= b; n } n template <class type> n void show(type name) { n   for (auto& nm : name) cerr << nm <<    ; n   cerr <<   n ; n } n using lng = long long; n using ivec = vector<int>; n const int mxn = 10; n int check(ivec& nums, int n) { n   int ans = 1e9; n   for (int i = 0; i < (1 << (int)nums.size()); ++i) { n     int cnt = 0; n     for (int j = 0; j < (int)nums.size(); ++j) { n       if ((i & (1 << j)) > 0) cnt += ceil(pow(3, nums[j])); n     } n     if (cnt >= n) ans = min(ans, cnt); n   } n   return ans; n } n int main() { n   int q, n; n   cin >> q; n   while (q--) { n     cin >> n; n     ivec nums(min(n, mxn) + 1); n     iota(begin(nums), end(nums), 0); n     cout << check(nums, n) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   string s; n   cin >> s; n   int c[2]; n   c[0] = c[1] = 0; n   const int m[] = {2, 1}; n   for (int i = 0; i < s.size(); i++) { n     int d = s[i] -  0 ; n     cout << ((c[d]++ * m[d]) % 4) + 1 <<     << d + 1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void __p(T a) { n   cout << a; n } n template <typename T, typename F> n void __p(pair<T, F> a) { n   cout <<  { ; n   __p(a.first); n   cout <<  , ; n   __p(a.second); n   cout <<  } n ; n } n template <typename T> n void __p(std::vector<T> a) { n   cout <<  { ; n   for (auto it = a.begin(); it < a.end(); it++) n     __p(*it), cout <<  ,} n [it + 1 == a.end()]; n } n template <typename T, typename... Arg> n void __p(T a1, Arg... a) { n   __p(a1); n   __p(a...); n } n template <typename Arg1> n void __f(const char *name, Arg1 &&arg1) { n   cout << name <<   :  ; n   __p(arg1); n   cout <<   n ; n } n template <typename Arg1, typename... Args> n void __f(const char *names, Arg1 &&arg1, Args &&...args) { n   int bracket = 0, i = 0; n   for (;; i++) n     if (names[i] ==  ,  && bracket == 0) n       break; n     else if (names[i] ==  ( ) n       bracket++; n     else if (names[i] ==  ) ) n       bracket--; n   const char *comma = names + i; n   cout.write(names, comma - names) <<   :  ; n   __p(arg1); n   cout <<   |  ; n   __f(comma + 1, args...); n } n void setIO(string s =   ) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin.exceptions(cin.failbit); n   if (((int)(s).size())) { n     freopen((s +  .in ).c_str(),  r , stdin); n     freopen((s +  .out ).c_str(),  w , stdout); n   } n } n const int dx[] = {1, 0, 0, -1}; n const int dy[] = {0, -1, 1, 0}; n const char C[] = { D ,  L ,  R ,  U }; n signed main() { n   setIO(); n   int n, m, K; n   cin >> n >> m >> K; n   if (K & 1) return cout <<  IMPOSSIBLE , 0; n   char a[n][m]; n   int dis[n][m]; n   int si = -1, sj = -1; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       cin >> a[i][j]; n       dis[i][j] = 1e9; n       if (a[i][j] ==  X ) { n         si = i, sj = j; n         dis[si][sj] = 0; n       } n     } n   } n   priority_queue<pair<int, array<int, 2> > > q; n   q.push({0, {si, sj}}); n   while (((int)(q).size())) { n     int res = -q.top().first, i = q.top().second[0], j = q.top().second[1]; n     q.pop(); n     if (res != dis[i][j]) continue; n     for (int k = 0; k < 4; ++k) { n       int ni = i + dx[k], nj = j + dy[k]; n       if (ni >= 0 && ni < n && nj >= 0 && nj < m && a[ni][nj] !=  * ) { n         if (dis[ni][nj] > dis[i][j] + 1) { n           dis[ni][nj] = dis[i][j] + 1; n           q.push({-dis[ni][nj], {ni, nj}}); n         } n       } n     } n   } n   int i = si, j = sj; n   string ans; n   for (int x = K - 1; x >= 0; --x) { n     for (int k = 0; k < 4; ++k) { n       int ni = i + dx[k], nj = j + dy[k]; n       if (ni >= 0 && ni < n && nj >= 0 && nj < m && a[ni][nj] !=  * ) { n         if (dis[ni][nj] <= x) { n           i = ni, j = nj; n           ans.push_back(C[k]); n           break; n         } n       } n     } n   } n   if (((int)(ans).size()) < K) { n     return cout <<  IMPOSSIBLE , 0; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   while (cin >> n) { n     vector<string> v(n); n     string s; n     for (int i = 0; i < n; ++i) { n       cin >> v[i]; n       for (int j = 0; j < v[i].size(); ++j) { n         if (v[i][j] >=  A  && v[i][j] <=  Z ) v[i][j] = v[i][j] -  A  +  a ; n       } n     } n     cin >> s; n     string ans = s; n     for (int j = 0; j < s.size(); ++j) { n       if (s[j] >=  A  && s[j] <=  Z ) s[j] = s[j] -  A  +  a ; n     } n     char lovable; n     cin >> lovable; n     if (lovable >=  A  && lovable <=  Z ) lovable = lovable -  A  +  a ; n     vector<pair<int, int> > segments; n     for (int i = 0; i < n; ++i) n       for (int j = 0; j + v[i].size() <= s.size(); ++j) n         if (s.substr(j, v[i].size()) == v[i]) n           segments.push_back(make_pair(j, j + v[i].size() - 1)); n     sort(segments.begin(), segments.end()); n     vector<pair<int, int> > final_segments; n     for (int i = 0; i < segments.size();) { n       pair<int, int> curr = segments[i]; n       int j = i; n       while (j < segments.size() && segments[j].first <= curr.second) { n         curr.second = max(curr.second, segments[j].second); n         ++j; n       } n       final_segments.push_back(curr); n       i = j; n     } n     for (int i = 0; i < final_segments.size(); ++i) { n       for (int j = final_segments[i].first; j <= final_segments[i].second; n            ++j) { n         char c = ans[j]; n         if (c >=  A  && c <=  Z ) c = c -  A  +  a ; n         if (c == lovable) { n           char c_inv; n           for (int i = 0; i < 26; ++i) { n             if ( a  + i != lovable) { n               c_inv =  a  + i; n               break; n             } n           } n           if (ans[j] >=  A  && ans[j] <=  Z ) n             ans[j] = c_inv -  a  +  A ; n           else n             ans[j] = c_inv; n         } else { n           if (ans[j] >=  A  && ans[j] <=  Z ) n             ans[j] = lovable -  a  +  A ; n           else n             ans[j] = lovable; n         } n       } n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n struct heap { n   int heapsize; n   int arr[100009]; n }; n void max_heapify(struct heap *c, int i, int *array) { n   if (c->heapsize == 0) return; n   int smallest, tmp; n   if (((2 * i) <= c->heapsize) && (array[c->arr[2 * i]] > array[c->arr[i]])) n     smallest = 2 * i; n   else n     smallest = i; n   if (((2 * i + 1) <= c->heapsize) && n       (array[c->arr[2 * i + 1]] > array[c->arr[smallest]])) n     smallest = 2 * i + 1; n   if (smallest == i) return; n   tmp = c->arr[i]; n   c->arr[i] = c->arr[smallest]; n   c->arr[smallest] = tmp; n   max_heapify(c, smallest, array); n   return; n }; n int extract_max(struct heap *c, int *array) { n   if (c->heapsize == 0) return 0; n   int max; n   max = c->arr[1]; n   c->arr[1] = c->arr[c->heapsize]; n   (c->heapsize)--; n   max_heapify(c, 1, array); n   return max; n }; n void insert(struct heap *c, int *array, int key) { n   int tmp; n   c->heapsize = c->heapsize + 1; n   c->arr[c->heapsize] = key; n   int j = c->heapsize; n   while (j > 1) { n     if (array[c->arr[j]] > array[c->arr[j / 2]]) { n       tmp = c->arr[j]; n       c->arr[j] = c->arr[j / 2]; n       c->arr[j / 2] = tmp; n       j = j / 2; n     } else n       return; n   } n   return; n }; n int main() { n   int n, i, j, tmp; n   scanf( %d , &n); n   int array[n + 5]; n   struct heap aux; n   aux.heapsize = 0; n   char a[n + 5]; n   for (i = 1; i <= n; i++) { n     scanf( %d , &array[i]); n     a[i] = 48; n   } n   for (i = 1; i <= n; i++) { n     if (array[i] != 0) { n       insert(&aux, array, i); n     } else if (array[i] == 0) { n       j = 3; n       while (j--) { n         tmp = extract_max(&aux, array); n         if (tmp > 0) a[tmp] = 49; n       } n       aux.heapsize = 0; n     } n   } n   int count = 0; n   for (i = 1; i <= n; i++) { n     if (array[i] > 0 && a[i] == 49) { n       count = count + 1; n       if (count % 3 == 1) n         printf( pushStack n ); n       else if (count % 3 == 2) n         printf( pushQueue n ); n       else if (count % 3 == 0) n         printf( pushFront n ); n     } else if (array[i] > 0 && a[i] == 48) n       printf( pushBack n ); n     else if (array[i] == 0) { n       if (count == 0) n         printf( 0 n ); n       else if (count == 1) { n         printf( 1 popStack n ); n         count = count - 1; n       } else if (count == 2) { n         printf( 2 popStack popQueue n ); n         count = count - 2; n       } else if (count >= 3) { n         printf( 3 popStack popQueue popFront n ); n         count = count - 3; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e3 + 10; n const long long mod = 1e9 + 7; n const long long inf = 1e18 + 10; n long long n, L, k; n string s, ans[N]; n int ptr; n void doIt(int l, int r) { n   if (l + 1 == r) { n     while (ans[l].size() < L) ans[l] += s[ptr], ptr++; n     return; n   } n   char last = s[ptr]; n   while (1) { n     for (int i = l; i < r; i++) { n       if (s[ptr] != last) { n         doIt(i, r); n         return; n       } n       if (ans[i].size() == L) return; n       ans[i] += s[ptr]; n       last = s[ptr]; n       ptr++; n     } n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> L >> k >> s; n   sort(s.begin(), s.end()); n   doIt(0, k); n   for (int i = 0; i < n; i++) n     while (ans[i].size() < L) ans[i] += s[ptr], ptr++; n   sort(ans, ans + n); n   for (int i = 0; i < n; i++) cout << ans[i] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int l[100100]; n int d[100100]; n map<int, vector<int> > p; n int cntd[202] = {0}; n int main(int argc, char** argv) { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> l[i]; n   for (int i = 0; i < n; i++) cin >> d[i]; n   for (int i = 0; i < n; i++) { n     cntd[d[i]]++; n     p[l[i]].push_back(d[i]); n   } n   int sumcnt = 0; n   int sumval = 0; n   int ans = 1e9; n   int m = n; n   for (map<int, vector<int> >::reverse_iterator it = p.rbegin(); it != p.rend(); n        it++) { n     int j = 0; n     for (int i = 0; i < it->second.size(); i++) { n       cntd[it->second[i]]--; n     } n     j = 0; n     int need = m - (2 * (it->second.size())) + 1; n     int deleted = 0; n     while (j <= 201 && need > 0) { n       if (cntd[j] != 0) { n         deleted += ((min(need, cntd[j])) * j); n         need -= min(need, cntd[j]); n       } n       j++; n     } n     ans = min(ans, sumval + deleted); n     m -= it->second.size(); n     for (int i = 0; i < it->second.size(); i++) { n       sumval += (it->second[i]); n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n const long long infl = 2e18; n const long long infi = 1e9; n const long long mod = 1000000007; n auto clk = clock(); n mt19937_64 rang( n     chrono::high_resolution_clock::now().time_since_epoch().count()); n long long rng(long long lim) { n   uniform_int_distribution<long long> uid(0, lim - 1); n   return uid(rang); n } n long long powm(long long a, long long b) { n   long long res = 1; n   a %= mod; n   while (b) { n     if (b & 1) res = (res * a) % mod; n     a = (a * a) % mod; n     b >>= 1; n   } n   return res; n } n const long long N = 55; n long long dp[N][N][N][4]; n vector<long long> sg[4]; n long long knap[4][N][N * N]; n long long fact[N]; n long long inpe[N]; n long long answ[N][N][N * N]; n struct base { n   long double x, y; n   base() { x = y = 0; } n   base(long double _x, long double _y) { x = _x, y = _y; } n   base(long double _x) { x = _x, y = 0; } n   void operator=(long double _x) { x = _x, y = 0; } n   long double real() { return x; } n   long double imag() { return y; } n   base operator+(const base& b) { return base(x + b.x, y + b.y); } n   void operator+=(const base& b) { x += b.x, y += b.y; } n   base operator*(const base& b) { n     return base(x * b.x - y * b.y, x * b.y + y * b.x); n   } n   void operator*=(const base& b) { n     long double p = x * b.x - y * b.y, q = x * b.y + y * b.x; n     x = p, y = q; n   } n   void operator/=(long double k) { x /= k, y /= k; } n   base operator-(const base& b) { return base(x - b.x, y - b.y); } n   void operator-=(const base& b) { x -= b.x, y -= b.y; } n   base conj() { return base(x, -y); } n   base operator/(long double k) { return base(x / k, y / k); } n   void Print() { cerr << x <<   +   << y <<  i n ; } n }; n long double PI = 2.0 * acosl(0.0); n const long long MAXN = 14; n const long long maxn = (1 << MAXN); n base W[maxn], invW[maxn], P1[maxn], Q1[maxn]; n void precompute_powers() { n   for (long long i = 0; i < maxn / 2; i++) { n     long double ang = (2 * PI * i) / maxn; n     long double _cos = cos(ang), _sin = sin(ang); n     W[i] = base(_cos, _sin); n     invW[i] = base(_cos, -_sin); n   } n } n void fft(vector<base>& a, bool invert) { n   long long n = (long long)a.size(); n   for (long long i = 1, j = 0; i < n; ++i) { n     long long bit = n >> 1; n     for (; j >= bit; bit >>= 1) j -= bit; n     j += bit; n     if (i < j) swap(a[i], a[j]); n   } n   for (long long len = 2; len <= n; len <<= 1) { n     for (long long i = 0; i < n; i += len) { n       long long ind = 0, add = maxn / len; n       for (long long j = 0; j < len / 2; ++j) { n         base u = a[i + j], n              v = (a[i + j + len / 2] * (invert ? invW[ind] : W[ind])); n         a[i + j] = (u + v); n         a[i + j + len / 2] = (u - v); n         ind += add; n       } n     } n   } n   if (invert) n     for (long long i = 0; i < n; ++i) a[i] /= n; n } n void mul_big_mod(vector<long long>& a, vector<long long>& b, long long mod) { n   long long n1 = a.size(), n2 = b.size(); n   long long final_size = a.size() + b.size() - 1; n   long long n = 1; n   while (n < final_size) n <<= 1; n   vector<base> P(n), Q(n); n   long long SQRTMOD = (long long)sqrt(mod) + 10; n   for (long long i = 0; i < n1; i++) n     P[i] = base(a[i] % SQRTMOD, a[i] / SQRTMOD); n   for (long long i = 0; i < n2; i++) n     Q[i] = base(b[i] % SQRTMOD, b[i] / SQRTMOD); n   fft(P, 0); n   fft(Q, 0); n   base A1, A2, B1, B2, X, Y; n   for (long long i = 0; i < n; i++) { n     X = P[i]; n     Y = P[(n - i) % n].conj(); n     A1 = (X + Y) * base(0.5, 0); n     A2 = (X - Y) * base(0, -0.5); n     X = Q[i]; n     Y = Q[(n - i) % n].conj(); n     B1 = (X + Y) * base(0.5, 0); n     B2 = (X - Y) * base(0, -0.5); n     P1[i] = A1 * B1 + A2 * B2 * base(0, 1); n     Q1[i] = A1 * B2 + A2 * B1; n   } n   for (long long i = 0; i < n; i++) P[i] = P1[i], Q[i] = Q1[i]; n   fft(P, 1); n   fft(Q, 1); n   a.resize(final_size); n   for (long long i = 0; i < final_size; i++) { n     long long x = (long long)(P[i].real() + 0.5); n     long long y = (long long)(P[i].imag() + 0.5) % mod; n     long long z = (long long)(Q[i].real() + 0.5); n     a[i] = (x + ((y * SQRTMOD + z) % mod) * SQRTMOD) % mod; n   } n } n void solve() { n   precompute_powers(); n   fact[0] = 1; n   for (long long i = 1; i < N; i++) fact[i] = (fact[i - 1] * i) % mod; n   dp[0][0][0][0] = 1; n   for (long long i = 0; i <= 50; i++) n     for (long long j = 0; j <= 50; j++) n       for (long long k = 0; k <= 50; k++) { n         for (long long l = 0; l <= 3; l++) n           if (l != 1) { n             dp[i + 1][j][k][1] += dp[i][j][k][l]; n             dp[i + 1][j][k][1] %= mod; n           } n         for (long long l = 0; l <= 3; l++) n           if (l != 2) { n             dp[i][j + 1][k][2] += dp[i][j][k][l]; n             dp[i][j + 1][k][2] %= mod; n           } n         for (long long l = 0; l <= 3; l++) n           if (l != 3) { n             dp[i][j][k + 1][3] += dp[i][j][k][l]; n             dp[i][j][k + 1][3] %= mod; n           } n       } n   long long n, t; n   cin >> n >> t; n   for (long long i = 1; i <= n; i++) { n     long long ti, gi; n     cin >> ti >> gi; n     sg[gi].push_back(ti); n   } n   for (long long j = 1; j <= 3; j++) { n     knap[j][0][0] = 1; n     for (long long i : sg[j]) { n       for (long long l = ((long long)sg[j].size()) - 1; l >= 0; l--) n         for (long long k = t - i; k >= 0; k--) { n           knap[j][l + 1][k + i] += knap[j][l][k]; n           knap[j][l + 1][k + i] %= mod; n         } n     } n   } n   for (long long i = 1; i <= 3; i++) n     for (long long j = 0; j <= ((long long)sg[i].size()); j++) n       for (long long k = 0; k <= t; k++) n         knap[i][j][k] = (knap[i][j][k] * fact[j]) % mod; n   long long ans = 0; n   if (((long long)sg[1].size()) > ((long long)sg[3].size())) { n     swap(sg[1], sg[3]); n     swap(knap[1], knap[3]); n   } n   if (((long long)sg[2].size()) > ((long long)sg[3].size())) { n     swap(sg[2], sg[3]); n     swap(knap[2], knap[3]); n   } n   vector<long long> ho1(t + 1), ho2(t + 1), res; n   for (long long i = 0; i <= ((long long)sg[1].size()); i++) { n     for (long long j = 0; j <= ((long long)sg[2].size()); j++) { n       ho1.resize(t + 1); n       for (long long k = 0; k <= t; k++) { n         ho1[k] = knap[1][i][k]; n         ho2[k] = knap[2][j][k]; n       } n       mul_big_mod(ho1, ho2, mod); n       for (long long k = 0; k <= t; k++) answ[i][j][k] = ho1[k]; n     } n   } n   for (long long i = 0; i <= ((long long)sg[1].size()); i++) { n     for (long long j = 0; j <= ((long long)sg[2].size()); j++) { n       for (long long k = 0; k <= ((long long)sg[3].size()); k++) { n         for (long long l = 0; l <= t; l++) { n           long long o = t - l; n           long long te = n               dp[i][j][k][0] + dp[i][j][k][1] + dp[i][j][k][2] + dp[i][j][k][3]; n           te = (te * answ[i][j][l]) % mod; n           ans = (ans + te * knap[3][k][o]) % mod; n         } n       } n     } n   } n   cout << ans <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   srand(chrono::high_resolution_clock::now().time_since_epoch().count()); n   cout << fixed << setprecision(10); n   long long t = 1; n   for (long long i = 1; i <= t; i++) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int mod = 1e9 + 7; n void solve() { n   long long int a, s; n   cin >> a >> s; n   vector<long long int> b; n   while (s) { n     long long int x = a % 10; n     long long int y = s % 10; n     if (y >= x) { n       b.push_back(y - x); n     } else { n       s /= 10; n       y += 10 * (s % 10); n       if (y > x && y <= 18 && y >= 10) { n         b.push_back(y - x); n       } else { n         cout << -1 <<   n ; n         return; n       } n     } n     s /= 10; n     a /= 10; n   } n   if (a) { n     cout << -1 <<   n ; n     return; n   } n   while (b.back() == 0) b.pop_back(); n   reverse((b).begin(), (b).end()); n   for (long long int x : b) cout << x; n   cout <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int T = 1; n   cin >> T; n   for (long long int i = 1; i <= T; i++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int T; n   cin >> T; n   while (T--) { n     int n, p; n     scanf( %d%d , &n, &p); n     for (int i = 0; i < n; i++) printf( %d %d n , i + 1, (i + 1) % n + 1); n     for (int i = 0; i < n; i++) printf( %d %d n , i + 1, (i + 2) % n + 1); n     int k = 3; n     while (p) { n       for (int i = 0; i < n && p + 0; i++) { n         p--; n         printf( %d %d n , i + 1, (i + k) % n + 1); n       } n       k++; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, p; n   cin >> n >> m; n   if (n < m) n     p = n; n   else n     p = m; n   if (p % 2 == 0) n     cout <<  Malvika ; n   else n     cout <<  Akshat ; n   return 0; n } n


#include <bits/stdc++.h> n const double EPS = 0.0000000001; n const long long mod1 = 998244353; n const long long mod2 = 1000000007; n const long long mod3 = 1000000009; n const long long mod4 = 228228227; n const long long inf = 100000000000000; n using namespace std; n signed main() { n   long long t; n   cin >> t; n   for (long long q = 0; q < t; q++) { n     long long n, a, b; n     cin >> n >> a >> b; n     vector<long long> v(n); n     for (long long i = 0; i < n; i++) cin >> v[i]; n     sort(v.begin(), v.end()); n     long long dp[n]; n     dp[0] = v[0]; n     for (long long i = 1; i < n; i++) { n       dp[i] = inf; n       if ((i - b) == -1) { n         dp[i] = v[i]; n       } n       if ((i - b) >= 0) dp[i] = dp[i - b] + v[i]; n       dp[i] = min(dp[i], dp[i - 1] + v[i]); n     } n     for (long long i = n - 1; i >= 0; i--) { n       if (dp[i] <= a) { n         cout << i + 1 << endl; n         break; n       } n     } n     if (dp[0] > a) cout << 0 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1000000007; n class Triplet { n  public: n   long long x; n   long long y; n   long long gcd; n }; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n Triplet extendedEuclid(long long a, long long b) { n   if (b == 0) { n     Triplet ans; n     ans.gcd = a; n     ans.x = 1; n     ans.y = 0; n     return ans; n   } n   Triplet smallAns = extendedEuclid(b, a % b); n   Triplet ans; n   ans.gcd = smallAns.gcd; n   ans.x = smallAns.y; n   ans.y = smallAns.x - (a / b) * smallAns.y; n   return ans; n } n long long modulo(long long a, long long m) { n   Triplet ans = extendedEuclid(a, m); n   return ans.x; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     long long n, a; n     cin >> n >> a; n     long long arr[n]; n     long long maxi = 0; n     bool found = false; n     for (long long i = 0; i < n; i++) { n       cin >> arr[i]; n       if (found) continue; n       if (a % arr[i] == 0) { n         if (a / arr[i] == 1) { n           found = true; n           maxi = arr[i]; n         } n       } n       maxi = max(maxi, arr[i]); n     } n     if (found) { n       cout <<  1 n ; n       continue; n     } else { n       if (maxi > a) { n         cout <<  2 n ; n         continue; n       } else { n         long long ans = (a / maxi); n         if (a % maxi != 0) ans++; n         cout << ans << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int q; n   cin >> q; n   while (q--) { n     long long pos; n     cin >> pos; n     if (pos == 1) { n       cout << 1 << endl; n       continue; n     } n     long long total = 0; n     long long ant = 0; n     long long desloc = 1; n     long long vezes = 1; n     while (true) { n       ant += desloc; n       if (total + ant > pos) break; n       total += ant; n       vezes++; n       if (vezes == 10 or vezes == 100 or vezes == 1000 or vezes == 10000 or n           vezes == 100000 or vezes == 1000000 or vezes == 10000000) n         desloc++; n     } n     if (total == pos) { n       cout << (vezes - 1) % 10 << endl; n     } else { n       bool ok = false; n       for (int j = vezes;; j++) { n         for (int i = 1; i <= vezes; i++) { n           long long digitos = log10(i) + 1; n           if (total + digitos < pos) { n             total += digitos; n           } else { n             string base = to_string(i); n             for (long long i = 0; i < base.size(); i++) { n               if (i + 1LL + total == pos) { n                 ok = true; n                 cout << base[i] << endl; n                 break; n               } n             } n           } n           if (ok) break; n         } n         if (ok) break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, x; n long long f[1510], g[1510]; n long long sum[1510]; n int main() { n   memset(f, 0, sizeof(f)); n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &x); n     sum[0] = x; n     for (int j = 1; j < m; ++j) { n       scanf( %d , &x); n       sum[j] = sum[j - 1] + x; n     } n     if (i == 0) { n       for (int j = 0; j < m; ++j) f[j] = sum[j]; n     } else if ((i & 1) == 1) { n       long long cm = f[m - 1]; n       for (int j = m - 2; j >= 0; --j) { n         g[j] = sum[j] + cm; n         cm = max(cm, f[j]); n       } n       for (int j = 0; j < m - 1; ++j) f[j] = g[j]; n     } else { n       long long cm = f[0]; n       for (int j = 1; j < m; ++j) { n         g[j] = sum[j] + cm; n         cm = max(cm, f[j]); n       } n       for (int j = 1; j < m; ++j) f[j] = g[j]; n     } n   } n   long long ans = -9999999999999999ll; n   if ((n & 1) == 0) { n     for (int i = 0; i < m - 1; ++i) ans = max(f[i], ans); n   } else { n     for (int i = 1; i < m; ++i) ans = max(f[i], ans); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool yes(int a, int b, bool vis[10]) { n   long long int temp = a; n   while (temp > 0) { n     int r = temp % 10; n     if (vis[r] == true) { n       return true; n     } n     temp /= 10; n   } n   return false; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int n; n   cin >> n; n   bool vis[10]; n   for (int i = 0; i <= 9; i++) { n     vis[i] = false; n   } n   long long int temp = n; n   while (n > 0) { n     int r = n % 10; n     vis[r] = true; n     n /= 10; n   } n   n = temp; n   long long int cnt = 0; n   for (long long int i = 1; i * i <= n; i++) { n     if (n % i == 0) { n       if (yes(i, n, vis)) { n         cnt++; n       } n       if (i * i != n) { n         if (yes(n / i, n, vis)) { n           cnt++; n         } n       } n     } n   } n   cout << cnt <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 14, M = 1 << N; n int n, p[M]; n char s[N][N]; n vector<long long> f[M][N]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) scanf( %s , s[i]); n   for (int i = 1; i < 1 << n; ++i) { n     p[i] = p[i >> 1] + (i & 1); n     for (int j = 0; j < n; ++j) n       if (i >> j & 1) f[i][j].resize(1 << (p[i] - 1)); n   } n   for (int i = 0; i < n; ++i) f[1 << i][i][0] = 1; n   for (int i = 1; i < 1 << n; ++i) n     for (int j = 0; j < n; ++j) n       if (i >> j & 1) n         for (int k = 0; k < n; ++k) n           if (!(i >> k & 1)) { n             int x = s[j][k] ==  1 , y = i | (1 << k), z = x << p[i] >> 1; n             for (int t = 0; t < 1 << (p[i] - 1); ++t) n               f[y][k][t | z] += f[i][j][t]; n           } n   for (int i = 0; i < 1 << n >> 1; ++i) { n     long long x = 0; n     for (int j = 0; j < n; ++j) x += f[(1 << n) - 1][j][i]; n     printf( %lld  , x); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n queue<int> que; n int n, k; n int main() { n   while (cin >> n >> k) { n     if (k == 0) { n       cout << 1; n       for (int i = 2; i < 2 * n + 1; i++) cout <<     << i; n       cout << endl; n       continue; n     } n     cout << k + 1; n     for (int i = 1; i < 2 * n + 1; i++) n       if (i != k + 1) que.push(i); n     while (!que.empty()) { n       cout <<     << que.front(); n       que.pop(); n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int arr[100000]; n int brr[100000]; n int crr[100000]; n int main() { n   int n, l; n   cin >> n >> l; n   int flag = 0; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   for (int j = 0; j < n; j++) cin >> brr[j]; n   for (int i = 0; i < n; i++) { n     crr[arr[i]] = 1; n   } n   int s = arr[0]; n   int x; n   int fans = 1; n   int z = 1; n   if ((l - arr[n - 1] - 1) + (arr[0] - 0 + 1) == brr[1] - brr[0]) { n     s = arr[n - 1]; n     for (int i = 1; i < n; i++) { n       int diff = brr[i] - brr[i - 1]; n       s = (diff + s) % l; n       if (crr[s] == 0) { n         fans = 0; n         break; n       } n     } n     if (fans == 1) flag = 1; n   } n   z = 1; n   while (z < n && flag == 0) { n     int f2 = 1; n     int f3 = 1; n     while (z < n) { n       if (arr[z] - arr[z - 1] == brr[1] - brr[0]) { n         f2 = 0; n         break; n       } n       z++; n     } n     if (f2 == 0) { n       s = arr[z - 1]; n       for (int i = 1; i < n && f3; i++) { n         int diff = brr[i] - brr[i - 1]; n         s = (diff + s) % l; n         if (crr[s] == 0) { n           f3 = 0; n           break; n         } n       } n       if (f3) { n         z = n; n         flag = 1; n       } n     } n     z++; n   } n   if (n == 1) n     cout <<  YES ; n   else if (flag == 1) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5000 * 100 + 5; n int n, m, a, b, c, av, bv, cv, t, h[N], cnt, par[N], y, ans[N], cntA, col, n     ca[N], o, uwu; n vector<int> adj[N], pa; n bool mark[N], vis[N], flag2, g[N]; n void bfs(int v) { n   queue<int> q; n   par[v] = -1; n   q.push(v); n   flag2 = false; n   while (q.size() && !flag2) { n     v = q.front(); n     q.pop(); n     for (auto u : adj[v]) n       if (!par[u]) { n         par[u] = v, q.push(u); n         if (adj[u].size() % 3 == 1 && !flag2) y = u, flag2 = true; n       } n   } n } n void dfs3(int v, int co, int p = -1) { n   pa.push_back(v); n   if (!flag2) n     for (auto u : adj[v]) n       if (u == bv && u != p) { n         for (auto i : pa) vis[i] = true; n         flag2 = true, uwu++; n       } n   for (auto u : adj[v]) n     if (u != p && !flag2 && ca[u] == co) dfs3(u, co, v), pa.pop_back(); n } n void dfs(int v) { n   ca[v] = col; n   for (auto u : adj[v]) n     if (!ca[u] && u != bv) dfs(u); n } n void dfs2(int v, int p = -1) { n   ans[cntA++] = v; n   g[v] = true; n   int l = 0; n   bool flag = false; n   for (auto u : adj[v]) n     if (h[u] > h[l] && u != p) { n       l = u; n     } n   if (!cnt && l) n     for (int i = 0; i < cntA; i++) { n       if (l == ans[i]) flag = true; n       if (flag) mark[ans[i]] = true, cnt++; n     } n   for (auto u : adj[v]) n     if (!cnt && !h[u] && adj[u].size() % 3 == 2) n       h[u] = h[v] + 1, dfs2(u, v), ans[--cntA] = 0; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   cin >> t; n   for (o = 1; o <= t; o++) { n     cin >> n >> m; n     for (int i = 0, v, u; i < m; i++) { n       cin >> v >> u; n       adj[v].push_back(u); n       adj[u].push_back(v); n     } n     for (int i = 1; i <= n; i++) { n       if (adj[i].size() % 3 == 0) n         a++, av = i; n       else if (adj[i].size() % 3 == 1) n         b++, bv = i; n       else n         c++, cv = i; n     } n     if (a) { n       if (n == 1) n         cout <<  NO n ; n       else { n         cout <<  YES n  << n - 1 <<   n ; n         for (int i = 1; i <= n; i++) n           if (i != av) cout << i <<    ; n       } n     } else if (b > 1) { n       bfs(bv); n       while (par[y] != -1) mark[y] = true, y = par[y], cntA++; n       mark[y] = true, cntA++; n       if (cntA == n) n         cout <<  NO n ; n       else { n         cout <<  YES n  << n - cntA <<   n ; n         for (int i = 1; i <= n; i++) n           if (!mark[i]) cout << i <<    ; n         cout <<   n ; n       } n     } else { n       fill(h, h + n + 1, 0); n       cnt = 0; n       for (int i = 1; i <= n; i++) n         if (!g[i] && adj[i].size() % 3 == 2) h[i] = 1, cntA = 0, dfs2(i); n       if (cnt == n) n         cout <<  NO n ; n       else if (cnt) { n         cout <<  YES n  << n - cnt <<   n ; n         for (int i = 1; i <= n; i++) n           if (!mark[i]) cout << i <<    ; n         cout <<   n ; n       } else if (!cnt) { n         bool flag = true; n         if (b != 1) flag = false; n         if (adj[bv].size() < 4) flag = false; n         if (flag) { n           cntA = 0, flag2 = false, col = 1; n           fill(vis, vis + n + 1, false); n           fill(h, h + n + 1, 0); n           uwu = 0; n           for (int i = 1; i <= n; i++) { n             if (i != bv && !ca[i]) dfs(i), col++; n           } n           for (int i = 1; i < col && uwu < 2; i++) { n             cntA = 0, flag2 = false, pa.clear(); n             dfs3(bv, i); n           } n           cnt = 0; n           for (int i = 1; i <= n; i++) { n             if (vis[i]) cnt++; n           } n           if (cnt == n || uwu != 2) n             cout <<  NO n ; n           else { n             cout <<  YES n  << n - cnt <<   n ; n             for (int i = 1; i <= n; i++) n               if (!vis[i]) cout << i <<    ; n             cout <<   n ; n           } n         } else n           cout <<  NO n ; n       } n     } n     for (int i = 0; i <= n; i++) n       adj[i].clear(), h[i] = par[i] = 0, vis[i] = mark[i] = false, ans[i] = 0, n                       g[i] = false, ca[i] = 0; n     a = b = c = av = bv = cv = 0, cnt = 0, y = 0, flag2 = false, cntA = 0; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } n int lcm(int a, int b) { return a * (b / gcd(a, b)); } n int cx[] = {-1, 1, 0, 0, 1, 1, -1, -1}; n int cy[] = {0, 0, -1, 1, -1, 1, -1, 1}; n bool is_possible(long long left, long long rigth) { n   if (left <= rigth) return true; n   return false; n } n int main() { n   ios::sync_with_stdio(0); n   int n; n   long long l = -2 * 1000000000, number, r = 2 * 1000000000; n   string option, answer; n   cin >> n; n   for (int i = (0), _b = ((n)-1); i <= _b; i++) { n     cin >> option >> number >> answer; n     if (option ==  >= ) { n       if (answer ==  Y ) n         l = max(l, number); n       else n         r = min(r, number - 1); n     } else if (option ==  <= ) { n       if (answer ==  Y ) n         r = min(r, number); n       else n         l = max(l, number + 1); n     } else if (option ==  > ) { n       if (answer ==  Y ) n         l = max(l, number + 1); n       else n         r = min(r, number); n     } else { n       if (answer ==  Y ) n         r = min(r, number - 1); n       else n         l = max(l, number); n     } n     if (!is_possible(l, r)) { n       cout <<  Impossible  << endl; n       return 0; n     } n   } n   cout << r << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n const long long INF = 0x3f3f3f3f3f3f3f3f; n const long long llinf = LLONG_MAX; n const int inf = INT_MAX; n const int nmax = 1e6 + 5; n const int mod = 1e9 + 7; n using namespace std; n int i, ans, x; n string s; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cerr.tie(0); n   cout.tie(0); n   cin >> s; n   for (i = 0; i < s.size(); i++) { n     if (s[i] ==  M ) n       x++; n     else if (x) n       ans = max(ans + 1, x); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[100100]; n bool c; n int main() { n   cin >> n; n   if (n == 1 || n == 2) { n     cout << 0; n     return 0; n   } n   for (int i = 1; i <= n; i++) cin >> a[i]; n   vector<int> cch; n   vector<int> chh; n   vector<int> aas; n   aas.push_back(a[1]); n   aas.push_back(a[2]); n   aas.push_back(a[3]); n   cch = aas; n   sort(cch.begin(), cch.end()); n   chh = cch; n   reverse(chh.begin(), chh.end()); n   if ((aas != cch) && (aas != chh)) { n     cout << 3 << endl; n     cout << 1 <<     << 2 <<     << 3; n     return 0; n   } n   if (a[1] < a[2] || a[2] < a[3]) c = true; n   if (a[1] == a[2] && a[2] == a[3]) { n     int q = 4; n     while (a[q] == a[3]) q++; n     if (q == n) { n       cout << 0; n       return 0; n     } n     if (a[3] < a[q]) c = true; n   } n   for (int i = 4; i <= n; i++) { n     if (((a[i] < a[i - 1]) && c) || ((a[i] > a[i - 1]) && (!c))) { n       cout << 3 << endl << 1 <<     << i - 1 <<     << i; n       return 0; n     } n   } n   cout << 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, lst[3], mx[2]; n long long ans, pos[300005]; n char color; n inline char get() { n   char in = getchar(); n   while (in !=  R  && in !=  G  && in !=  B ) { n     in = getchar(); n   } n   return in; n } n inline void did(int opt, int nowpos) { n   if (lst[opt] != 0) { n     ans += pos[nowpos] - pos[lst[opt]]; n     mx[opt] = n         (mx[opt] > pos[nowpos] - pos[lst[opt]] ? mx[opt] n                                                : pos[nowpos] - pos[lst[opt]]); n   } n   lst[opt] = nowpos; n } n inline void did2(int nowpos) { n   if (lst[2] != 0) { n     ans += (0 < pos[nowpos] - pos[lst[2]] - mx[0] - mx[1] n                 ? 0 n                 : pos[nowpos] - pos[lst[2]] - mx[0] - mx[1]); n   } n   lst[2] = nowpos; n   mx[0] = 0; n   mx[1] = 0; n } n int main() { n   scanf( %d , &n); n   for (register int i = 1; i <= n; i++) { n     scanf( %d , &pos[i]); n     color = get(); n     switch (color) { n       case  R : n         did(0, i); n         break; n       case  B : n         did(1, i); n         break; n       case  G : n         did(0, i); n         did(1, i); n         did2(i); n         break; n     } n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n string s[6], S; n bool F; n int main() { n   cin >> S; n   for (int i = 1; i <= 5; ++i) cin >> s[i]; n   for (int i = 1; i <= 5; ++i) n     if (s[i][0] == S[0] || s[i][1] == S[1]) F = 1; n   puts(F ?  YES  :  NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX_A = 1e7; n const int N = 500000; n bool sieve[MX_A + 1]; n pair<int, int> pr[MX_A + 1]; n int a1[N], a2[N], arr[N]; n void handleven(int i) { n   int num = arr[i]; n   while (num % 2 == 0) num /= 2; n   if (num != 1) { n     a1[i] = 2; n     a2[i] = num; n   } else { n     a1[i] = a2[i] = -1; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   for (int i = 2; i <= MX_A; i++) { n     if (sieve[i]) continue; n     for (int j = i; j <= MX_A; j += i) { n       if (!pr[j].second) { n         if (!pr[j].first) { n           pr[j].first = i; n         } else { n           pr[j].second = i; n         } n       } n       sieve[j] = true; n     } n   } n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   for (int i = 0; i < n; i++) { n     int num = arr[i]; n     if (arr[i] % 2 == 0) { n       while (num % 2 == 0) num /= 2; n       if (num != 1) { n         a1[i] = 2; n         a2[i] = num; n       } else { n         a1[i] = a2[i] = -1; n       } n     } else if (pr[arr[i]].second) { n       a1[i] = pr[arr[i]].first; n       a2[i] = pr[arr[i]].second; n     } else { n       a1[i] = a2[i] = -1; n     } n   } n   for (int i = 0; i < n; i++) { n     cout << a1[i] <<    ; n   } n   cout <<   n ; n   for (int i = 0; i < n; i++) { n     cout << a2[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int OO = 2e9; n const int MOD = 1e9 + 7; n const double Pi = 3.141592653589793; n const int N = 3e5 + 5; n long long c[N], v[N], g[N], a[N], n, k, s, t, m = 0, mx = 0, mn = -1, res = OO; n bool check(long long cap) { n   long long time = 0; n   for (int i = (int)1; i <= (int)m; i++) { n     if (a[i] > cap) return false; n     long long y = max(0LL, min(a[i], cap - a[i])), x = a[i] - y; n     time += 2LL * x + y; n   } n   return (time <= t); n } n int main() { n   cin >> n >> k >> s >> t; n   if (s > t) { n     cout << -1; n     return 0; n   } n   for (int i = (int)1; i <= (int)n; i++) scanf( %i%i , &v[i], &c[i]); n   for (int i = (int)1; i <= (int)k; i++) scanf( %i , &g[i]); n   g[++k] = s; n   g[++k] = 0; n   sort(g + 1, g + k + 1); n   for (int i = (int)2; i <= (int)k; i++) n     a[++m] = g[i] - g[i - 1], mx = max(mx, a[m]); n   long long l = mx, r = s * 2, mid; n   while (l <= r) { n     mid = (l + r) >> 1; n     if (check(mid)) n       mn = mid, r = mid - 1; n     else n       l = mid + 1; n   } n   for (int i = (int)1; i <= (int)n; i++) n     if (c[i] >= mn) res = min(res, v[i]); n   if (res == OO) n     cout << -1; n   else n     cout << res; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n bool chkmax(T &x, T y) { n   return x < y ? x = y, true : false; n } n template <typename T> n bool chkmin(T &x, T y) { n   return x > y ? x = y, true : false; n } n int readint() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n const int cys = 998244353; n int n, k; n long long mod(long long x) { return x >= cys ? x - cys : x; } n namespace task1 { n long long d[2025][2025]; n void work() { n   d[0][0] = 1; n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j <= n; j++) { n       d[i][j] = d[i - 1][j]; n       if (j >= i) d[i][j] = mod(d[i][j] + d[i][j - i]); n     } n   } n   long long ans = 0; n   for (int i = 1; i <= n; i++) ans = mod(ans + d[n][i]); n   printf( %lld n , ans); n } n }  // namespace task1 n namespace task2 { n long long d[2025][2025], f[2025][2025]; n void work() { n   d[0][0] = 1; n   for (int i = n; i >= 1; i--) n     for (int j = 0; j <= n / i; j++) n       for (int k = 0; k <= n; k++) n         if (j && k >= i * j) d[j][k] = mod(d[j][k] + d[j - 1][k - i * j]); n   long long ans = 0; n   for (int i = 1; i <= n; i++) n     for (int j = 0; j <= n; j++) ans = mod(ans + d[i][j]); n   printf( %lld n , ans); n } n }  // namespace task2 n namespace taskg3 { n vector<int> a; n map<vector<int>, bool> bk; n int ans; n bool check(vector<int> x) { n   vector<int> tmp(0); n   for (int i = 0; i < x.size(); i++) n     for (int j = 0; j < x[i]; j++) tmp.push_back(i + 1); n   int sum = 0; n   for (int i = 0; i < tmp.size(); i++) sum += tmp[i] * (tmp.size() - i); n   return sum <= n; n } n vector<int> getans(vector<int> x) { n   sort(x.begin(), x.end()); n   int lst = 0; n   vector<int> ret(0); n   for (int i = 1; i < x.size(); i++) n     if (x[i] != x[i - 1]) ret.push_back(i - lst), lst = i; n   ret.push_back(x.size() - lst); n   return ret; n } n bool dfs(int now, int sum) { n   if (now >= 1) { n     if (!check(a)) return 0; n     vector<int> tmp = a; n     for (int i = 1; i <= k - 3; i++) tmp = getans(tmp); n     sort(tmp.begin(), tmp.end()); n     if (!bk.count(tmp)) bk[tmp] = 1, ans++; n   } n   int g = now ? a[now - 1] : 64; n   for (int i = 1; i <= g && i <= 64 - sum; i++) { n     a.push_back(i); n     if (!dfs(now + 1, sum + i)) { n       a.pop_back(); n       break; n     } n     a.pop_back(); n   } n   return 1; n } n void work() { n   ans = 0; n   dfs(0, 0); n   printf( %d n , ans); n } n }  // namespace taskg3 n int main() { n   n = readint(); n   k = readint(); n   if (k >= 20) n     printf( 1 n ); n   else if (k == 1) n     task1::work(); n   else if (k == 2) n     task2::work(); n   else n     taskg3::work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = INT_MAX; n void solve() { n   long long n; n   cin >> n; n   vector<long long> a(n); n   vector<long long> first(n, INF); n   vector<long long> last(n, -INF); n   for (long long i = 0; i < n; ++i) { n     cin >> a[i]; n     --a[i]; n     first[a[i]] = min(first[a[i]], i); n     last[a[i]] = max(last[a[i]], i); n   } n   sort(a.begin(), a.end()); n   a.erase(unique(a.begin(), a.end()), a.end()); n   long long now = 0; n   long long mx = 0; n   long long ans = 0; n   n = a.size(); n   for (long long i = 0; i < n; ++i) { n     if (i) { n       if (first[a[i]] > mx) n         ++now; n       else n         now = 1; n       mx = last[a[i]]; n       ans = max(ans, now); n     } else { n       now = 1; n       mx = max(mx, last[a[i]]); n       ans = max(ans, now); n     } n   } n   cout << a.size() - ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long q; n   cin >> q; n   while (q--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const long long INF = 1e15; n class LazySegmentTree { n  private: n   int n; n   vector<pair<long long, int>> node; n   vector<long long> lazy; n  n  public: n   LazySegmentTree(vector<long long> v) { n     n = 1; n     while (n < v.size()) n *= 2; n     node.resize(2 * n - 1, make_pair(-INF, 0)); n     lazy.resize(2 * n - 1, 0); n     for (int i = 0; i < v.size(); i++) node[i + n - 1] = make_pair(v[i], i); n     for (int i = n - 2; i >= 0; i--) n       node[i] = max(node[2 * i + 1], node[2 * i + 2]); n   } n   void eval(int k, int l, int r) { n     if (lazy[k] != 0) { n       node[k].first += lazy[k]; n       if (r - l > 1) { n         lazy[2 * k + 1] += lazy[k]; n         lazy[2 * k + 2] += lazy[k]; n       } n       lazy[k] = 0; n     } n   } n   void add(int a, int b, long long x, int k = 0, int l = 0, int r = -1) { n     if (r < 0) r = n; n     eval(k, l, r); n     if (b <= l || r <= a) return; n     if (a <= l && r <= b) { n       lazy[k] += x; n       eval(k, l, r); n     } else { n       add(a, b, x, 2 * k + 1, l, (r + l) / 2); n       add(a, b, x, 2 * k + 2, (r + l) / 2, r); n       node[k] = max(node[2 * k + 1], node[2 * k + 2]); n     } n   } n   pair<long long, int> getMax(int a, int b, int k = 0, int l = 0, int r = -1) { n     if (r < 0) r = n; n     eval(k, l, r); n     if (b <= l || r <= a) return make_pair(-INF, 0); n     if (a <= l && r <= b) { n       return node[k]; n     } n     pair<long long, int> vl, vr; n     vl = getMax(a, b, 2 * k + 1, l, (l + r) / 2); n     vr = getMax(a, b, 2 * k + 2, (l + r) / 2, r); n     return max(vl, vr); n   } n }; n int main() { n   cin.tie(0); n   ios::sync_with_stdio(false); n   int N; n   cin >> N; n   vector<long long> X(N), Y(N), C(N); n   for (int i = 0; i < (N); ++i) cin >> X[i] >> Y[i] >> C[i]; n   vector<long long> v; n   map<long long, int> mp; n   map<int, long long> rev; n   for (int i = 0; i < N; i++) { n     v.push_back(X[i]); n     v.push_back(Y[i]); n   } n   sort(v.begin(), v.end()); n   v.erase(unique(v.begin(), v.end()), v.end()); n   for (int i = 0; i < v.size(); i++) { n     mp[v[i]] = i; n     rev[i] = v[i]; n   } n   int V = v.size(); n   vector<vector<int>> rig(V), lef(V); n   for (int i = 0; i < N; i++) { n     lef[mp[min(X[i], Y[i])]].push_back(i); n     rig[mp[max(X[i], Y[i])]].push_back(i); n   } n   vector<long long> input(V, 0); n   for (int i = 0; i < (N); ++i) input[V - 1] += C[i]; n   for (int i = V - 2; i >= 0; i--) { n     input[i] = input[i + 1]; n     for (auto ng : rig[i + 1]) input[i] -= C[ng]; n   } n   for (int i = 0; i < V; i++) input[i] -= rev[i]; n   LazySegmentTree seg(input); n   vector<int> del(N, 0); n   long long ans = 0; n   int x = 2000000000; n   int y = x; n   for (int i = 0; i < V; i++) { n     auto f = seg.getMax(i, V); n     long long val = f.first; n     if (ans < val + rev[i]) { n       ans = val + rev[i]; n       x = rev[i]; n       y = rev[f.second]; n     } n     for (auto n : lef[i]) { n       if (del[n]) continue; n       del[n] = 1; n       seg.add(mp[max(X[n], Y[n])], V, -C[n]); n     } n   } n   cout << ans << endl; n   cout << min(x, y) <<     << min(x, y) <<     << max(y, x) <<     << max(y, x) n        << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100010; n int inf = 1e9; n int mod = 1e9 + 7; n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, m, k; n   cin >> n >> m >> k; n   int L[n], R[n]; n   for (int i = 0; i < n; i++) cin >> L[i] >> R[i]; n   map<int, vector<int>> start, end; n   set<int> line; n   for (int i = 0; i < n; i++) { n     start[L[i]].push_back(i); n     end[R[i]].push_back(i); n     line.insert(L[i]); n     line.insert(R[i]); n   } n   set<int> s; n   int prev = 0; n   int dp[1 << 8]; n   map<int, int> order[2 * n + 1]; n   int cnt = 0; n   int ans = 0; n   memset(dp, 0, sizeof(dp)); n   for (int cur : line) { n     for (int u : start[cur]) s.insert(u); n     cnt++; n     vector<int> val; n     int e = 0; n     for (int u : s) { n       order[cnt][u] = e++; n       val.push_back(u); n     } n     vector<int> temp(1 << 8, 0); n     for (int i = 0; i < (1 << (int)val.size()); i++) { n       int bit = 0; n       int y = 0, z = 0; n       for (int j = 0; j < (int)val.size(); j++) { n         if ((i >> j) & 1) { n           int x = val[j]; n           if (order[cnt - 1].find(x) != order[cnt - 1].end()) { n             bit |= (1 << order[cnt - 1][x]); n             y ^= 1; n           } n           z ^= 1; n         } n       } n       temp[i] = dp[bit]; n       temp[i] += y * (cur - prev - 1); n       temp[i] += z; n       ans = max(ans, temp[i]); n     } n     vector<int> f, b; n     for (int u : end[cur]) { n       b.push_back(u); n       s.erase(s.find(u)); n     } n     for (int u : s) { n       f.push_back(u); n     } n     memset(dp, 0, sizeof(dp)); n     for (int i = 0; i < (1 << (int)f.size()); i++) { n       int bit = 0; n       for (int k = 0; k < (int)f.size(); k++) { n         if ((i >> k) & 1) { n           bit |= (1 << order[cnt][f[k]]); n         } n       } n       int x = bit; n       for (int j = 0; j < (1 << (int)b.size()); j++) { n         bit = x; n         for (int k = 0; k < (int)b.size(); k++) { n           if ((j >> k) & 1) { n             bit |= (1 << order[cnt][b[k]]); n           } n         } n         dp[x] = max(dp[x], temp[bit]); n       } n     } n     prev = cur; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, len; n char p[1000]; n int done[1000]; n long long ans = 0; n long long p2[1000]; n int main() { n   int i, j; n   scanf( %s , p); n   p2[0] = 1; n   for (i = 1; i <= 200; ++i) p2[i] = (p2[i - 1] * 2) % 1000000007; n   len = strlen(p); n   for (i = 0; i < len; ++i) done[i] = p[len - i - 1] -  0 ; n   for (i = 0; i < len; ++i) { n     ans = (ans * 2) % 1000000007; n     if (done[i] == 1) ans = (ans + p2[i] * p2[i]) % 1000000007; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool sortbysec(const pair<int, bool> &a, const pair<int, bool> &b) { n   return (a.first < b.first || (a.first == b.first && a.second < b.second)); n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int n; n   cin >> n; n   int res = n; n   vector<pair<int, bool> > a(n); n   for (int i = 0; i < n; i++) { n     cin >> a[i].first; n     a[i].second = 0; n   } n   sort(a.begin(), a.end()); n   vector<pair<int, bool> >::iterator it = a.begin(); n   for (int i = 0; i < a.size() - 1; i++) { n     for (int j = i + 1; j < a.size(); j++) { n       if (a[i].first < a[j].first && !a[j].second) { n         a[j].second = 1; n         res--; n         break; n       } n     } n   } n   cout << res <<   n ; n   return EXIT_SUCCESS; n } n


#include <bits/stdc++.h> n using namespace std; n priority_queue<int> lott; n int main() { n   long long int xm, find = 0; n   cin >> xm; n   lott.push(100); n   lott.push(20); n   lott.push(10); n   lott.push(5); n   lott.push(1); n   while (xm) { n     while (lott.top() <= xm) { n       find++; n       xm -= lott.top(); n     } n     lott.pop(); n   } n   cout << find << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long m[4], x, y, a; n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL), cout.tie(NULL); n   for (long long i = 0; i < 10; ++i) { n     cout << i << i << i << i << endl; n     cin >> x >> y; n     if (x == 1) m[a++] = i; n   } n   for (long long i = 0; i < 24; ++i) { n     next_permutation(m, m + 4); n     for (long long i = 0; i < 4; ++i) cout << m[i]; n     cout << endl; n     cin >> x >> y; n     if (x == 4) return cout << endl, 0; n   } n } n


#include <bits/stdc++.h> n using namespace std; n char str[200010]; n int tim[200010]; n int main() { n   memset(tim, 0x3f, sizeof(tim)); n   int n, k; n   scanf( %d %d , &n, &k); n   scanf( %s , str); n   for (int i = 0; i < n; i++) n     if (str[i] == str[(i + 1) % n] || str[i] == str[(i - 1 + n) % n]) n       tim[i] = 0; n   for (int i = 0; i < 2 * n; i++) n     tim[i % n] = min(tim[i % n], tim[(i - 1 + n) % n] + 1); n   for (int i = 2 * n - 1; i >= 0; i--) n     tim[i % n] = min(tim[i % n], tim[(i + 1) % n] + 1); n   for (int i = 0; i < n; i++) n     if (min(tim[i], k) & 1) n       printf( %c ,  W  +  B  - str[i]); n     else n       printf( %c , str[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s1, s2, virus; n pair<int, int> dp[105][105][105]; n int l1, l2, lvirus; n string ans =   ; n int pi[105]; n void pf(string s) { n   memset(pi, 0, sizeof(pi)); n   int n = (int)s.length(); n   for (int i = 1; i < n; ++i) { n     int j = pi[i - 1]; n     while (j > 0 && s[i] != s[j]) j = pi[j - 1]; n     if (s[i] == s[j]) ++j; n     pi[i] = j; n   } n } n int main() { n   cin >> s1 >> s2 >> virus; n   l1 = s1.length(); n   l2 = s2.length(); n   lvirus = virus.length(); n   int i, j, k; n   for (i = 1; i <= l1; i++) { n     for (j = 1; j <= l2; j++) { n       for (k = 0; k < lvirus; k++) { n         if (dp[i][j][k].first <= dp[i - 1][j][k].first) { n           dp[i][j][k].first = dp[i - 1][j][k].first; n           dp[i][j][k].second = 1; n         } n         if (dp[i][j][k].first <= dp[i][j - 1][k].first) { n           dp[i][j][k].first = dp[i][j - 1][k].first; n           dp[i][j][k].second = 2; n         } n         if (s1[i - 1] == s2[j - 1]) { n           if (k != 0 && s1[i - 1] == virus[k - 1]) { n             if (dp[i][j][k].first < dp[i - 1][j - 1][k - 1].first + 1) { n               dp[i][j][k].first = dp[i - 1][j - 1][k - 1].first + 1; n               dp[i][j][k].second = 3; n             } n           } n           int z = k; n           if (s1[i - 1] != virus[z]) { n             char c = virus[z]; n             virus[z] = s1[i - 1]; n             pf(virus); n             int v = pi[z]; n             if (dp[i][j][v].first < dp[i - 1][j - 1][z].first + 1) { n               dp[i][j][v].first = dp[i - 1][j - 1][z].first + 1; n               dp[i][j][v].second = 10 + z; n             } n             virus[z] = c; n           } n         } n       } n     } n   } n   int mx = 0, cur = -1; n   for (i = 0; i < lvirus; i++) { n     if (mx <= dp[l1][l2][i].first) { n       cur = i; n       mx = dp[l1][l2][i].first; n     } n   } n   if (mx == 0) { n     cout << 0; n     return 0; n   } n   i = l1; n   j = l2; n   while (i != 0 && j != 0) { n     if (dp[i][j][cur].second == 1) { n       i--; n       continue; n     } n     if (dp[i][j][cur].second == 2) { n       j--; n       continue; n     } n     if (dp[i][j][cur].second == 3) { n       ans = s1[i - 1] + ans; n       i--; n       j--; n       cur--; n       continue; n     } n     ans = s1[i - 1] + ans; n     cur = dp[i][j][cur].second - 10; n     i--; n     j--; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, i; n   cin >> n >> k; n   if (k == 1 || k == n) { n     cout << 3 * n << endl; n     return 0; n   } else { n     int sum = 0; n     if (k & 1) { n       if (k >= n / 2 + 1) { n         k = n - k + 1; n       } n     } else { n       if (k > n / 2) { n         k = n - k + 1; n       } n     } n     int cnt = 0; n     for (i = k; i >= 1; i--) { n       if (cnt == 1) { n         sum += 4; n       } else { n         sum += 3; n       } n       cnt++; n     } n     sum--; n     sum += k; n     for (i = k + 1; i <= n; i++) { n       sum += 3; n     } n     sum--; n     cout << sum << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Edge { n   int u, v; n }; n const int MAXN = 2e5 + 5; n int p[MAXN]; n vector<Edge> edges; n vector<int> G[MAXN]; n bool va[MAXN], vb[MAXN]; n int find(int x) { return x == p[x] ? x : p[x] = find(p[x]); } n int main() { n   memset(va, 0, sizeof(va)); n   memset(vb, 0, sizeof(vb)); n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) p[i] = i; n   while (m--) { n     int u, v; n     scanf( %d%d , &u, &v); n     edges.push_back((Edge){u, v}); n   } n   int s, t, ds, dt; n   scanf( %d%d%d%d , &s, &t, &ds, &dt); n   vector<Edge> g; n   bool ok = 0; n   for (int i = 0; i < edges.size(); i++) { n     int u = edges[i].u, v = edges[i].v; n     bool flag = 0; n     if (u == s || u == t) G[u].push_back(v), flag = 1; n     if (v == s || v == t) G[v].push_back(u), flag = 1; n     if (flag) continue; n     u = find(u), v = find(v); n     if (u != v) { n       p[v] = u; n       g.push_back((Edge){edges[i].u, edges[i].v}); n     } n   } n   for (int i = 0; i < G[s].size(); i++) va[G[s][i]] = 1; n   for (int i = 0; i < G[t].size(); i++) vb[G[t][i]] = 1; n   int as = 0, at = 0; n   for (int i = 0; i < G[s].size(); i++) { n     if (as > ds) break; n     if (G[s][i] == t) { n       ok = 1; n       continue; n     } n     if (vb[G[s][i]]) continue; n     int u = find(s), v = find(G[s][i]); n     if (u != v) { n       as++; n       p[u] = v; n       g.push_back((Edge){s, G[s][i]}); n     } n   } n   for (int i = 0; i < G[s].size(); i++) { n     if (as >= ds) break; n     if (G[s][i] == t) { n       ok = 1; n       continue; n     } n     int u = find(s), v = find(G[s][i]); n     if (u != v) { n       as++; n       p[u] = v; n       g.push_back((Edge){s, G[s][i]}); n     } n   } n   for (int i = 0; i < G[t].size(); i++) { n     if (at > dt) break; n     if (G[t][i] == s) { n       ok = 1; n       continue; n     } n     int u = find(t), v = find(G[t][i]); n     if (u != v) { n       at++; n       p[u] = v; n       g.push_back((Edge){t, G[t][i]}); n     } n   } n   int u = find(s), v = find(t); n   if (u != v) { n     if (ok) { n       g.push_back((Edge){s, t}); n       as++; n       at++; n     } else { n       puts( No ); n       return 0; n     } n   } n   if (as > ds || at > dt) n     puts( No ); n   else { n     puts( Yes ); n     for (int i = 0; i < g.size(); i++) { n       printf( %d %d n , g[i].u, g[i].v); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dept[105], lend[105]; n int main() { n   int n, m, a, b, c, sum = 0; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; ++i) { n     scanf( %d%d%d , &a, &b, &c); n     lend[b] += c; n     dept[a] += c; n   } n   for (int i = 1; i <= n; ++i) { n     if (lend[i] < dept[i]) sum += dept[i] - lend[i]; n   } n   cout << sum; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int vis[601], co[601], fa[601], d[601]; n int zb(int o, int l, int r) { n   int ans1 = 0, ans2 = 0; n   int sz = 0; n   for (int i = l; i <= r; i++) n     if (!vis[i]) sz++; n   if (sz > 0) { n     printf( ? %d n , sz + 1); n     for (int i = l; i <= r; i++) n       if (!vis[i]) printf( %d  , i); n     printf( %d n , o); n     fflush(stdout); n     scanf( %d , &ans1); n   } n   if (sz > 1) { n     printf( ? %d n , sz); n     for (int i = l, ok = 0; i <= r; i++) n       if (!vis[i]) printf(!ok ? ok = 1,  %d  :   %d , i); n     printf(  n ); n     fflush(stdout); n     scanf( %d , &ans2); n   } n   return ans1 - ans2; n } n int nx(int o) { n   if (!zb(o, 1, n)) return 0; n   int l = 1, r = n; n   while (l != r) { n     int mid = l + r >> 1; n     if (zb(o, l, mid)) n       r = mid; n     else n       l = mid + 1; n   } n   return l; n } n void dfs(int u) { n   for (;;) { n     int v = nx(u); n     if (!v) break; n     vis[v] = 1; n     co[v] = co[u] ^ 1; n     fa[v] = u; n     d[v] = d[u] + 1; n     dfs(v); n   } n } n int zb2(int o, int l, int r, int* wd) { n   int ans1 = 0, ans2 = 0; n   int sz = 0; n   for (int i = l; i <= r; i++) n     if (wd[i] != o) sz++; n   if (sz > 0) { n     printf( ? %d n , sz + 1); n     for (int i = l; i <= r; i++) n       if (wd[i] != o) printf( %d  , wd[i]); n     printf( %d n , o); n     fflush(stdout); n     scanf( %d , &ans1); n   } n   if (sz > 1) { n     printf( ? %d n , sz); n     for (int i = l, ok = 0; i <= r; i++) n       if (wd[i] != o) printf(!ok ? ok = 1,  %d  :   %d , wd[i]); n     printf(  n ); n     fflush(stdout); n     scanf( %d , &ans2); n   } n   return ans1 - ans2; n } n int nx2(int o, int* wd) { n   if (!zb2(o, 1, wd[0], wd)) return 0; n   int l = 1, r = wd[0]; n   while (l != r) { n     int mid = l + r >> 1; n     if (zb2(o, l, mid, wd)) n       r = mid; n     else n       l = mid + 1; n   } n   return wd[l]; n } n int ld[601], rd[601]; n int dd[601]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) n     if (!vis[i]) vis[i] = 1, co[i] = 0, dfs(i); n   for (int i = 1; i <= n; i++) n     if (co[i]) n       rd[++rd[0]] = i; n     else n       ld[++ld[0]] = i; n   for (int i = 1; i <= ld[0]; i++) { n     int u = ld[i], v; n     if (v = nx2(u, ld)) { n       for (; u != v;) { n         if (d[u] > d[v]) n           dd[++dd[0]] = u, u = fa[u]; n         else n           dd[++dd[0]] = v, v = fa[v]; n       } n       dd[++dd[0]] = u; n       printf( N %d n , dd[0]); n       for (int i = 1; i <= dd[0]; i++) n         printf( %d%c , dd[i], i == dd[0] ?   n  :    ); n       return 0; n     } n   } n   for (int i = 1; i <= rd[0]; i++) { n     int u = rd[i], v; n     if (v = nx2(u, rd)) { n       for (; u != v;) { n         if (d[u] > d[v]) n           dd[++dd[0]] = u, u = fa[u]; n         else n           dd[++dd[0]] = v, v = fa[v]; n       } n       dd[++dd[0]] = u; n       printf( N %d n , dd[0]); n       for (int i = 1; i <= dd[0]; i++) n         printf( %d%c , dd[i], i == dd[0] ?   n  :    ); n       return 0; n     } n   } n   printf( Y %d n , ld[0]); n   for (int i = 1; i <= ld[0]; i++) n     printf( %d%c , ld[i], i == ld[0] ?   n  :    ); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10; n char ch[N]; n int a[N]; n int main() { n   int n; n   cin >> n; n   stack<int> st; n   for (int i = 1; i <= n * 2; i++) { n     scanf(  %c , ch + i); n     if (ch[i] ==  + ) { n       st.push(i); n     } else { n       if (st.empty()) { n         puts( NO ); n         return 0; n       } n       scanf( %d , a + i); n       a[st.top()] = a[i]; n       st.pop(); n     } n   } n   set<int> tmp; n   for (int i = 1; i <= n * 2; i++) { n     if (ch[i] ==  + ) { n       tmp.insert(a[i]); n     } else { n       if (*tmp.begin() != a[i]) { n         puts( NO ); n         return 0; n       } n       tmp.erase(tmp.begin()); n     } n   } n   puts( YES ); n   for (int i = 1; i <= n * 2; i++) { n     if (ch[i] ==  + ) printf( %d  , a[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double esp = 0.00000001; n const int N = 60; n const int PSize = 100; n const double PCross = 0.3; n const double PMuta = 0.05; n int a[200010], t[200010]; n int n, T; n vector<int> res; n bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } n bool ok(int k, vector<pair<int, int> > e) { n   if (k > e.size()) return false; n   int ans = 0; n   sort(e.begin(), e.end(), cmp); n   for (int i = 0; i < k; i++) ans += e[i].second; n   if (ans > T) return false; n   res.clear(); n   for (int i = 0; i < k; i++) res.push_back(e[i].first); n   return true; n } n int main() { n   cin >> n >> T; n   for (int i = 0; i < n; i++) cin >> a[i] >> t[i]; n   int l = 0, r = n; n   while (l < r) { n     int mid = (l + r + 1) >> 1; n     vector<pair<int, int> > e; n     for (int i = 0; i < n; i++) n       if (a[i] >= mid) e.push_back(make_pair(i, t[i])); n     if (ok(mid, e)) n       l = mid; n     else n       r = mid - 1; n   } n   cout << l << endl << res.size() << endl; n   for (int i = 0; i < res.size(); i++) { n     if (i) cout <<    ; n     cout << res[i] + 1; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void err(istream_iterator<string> it) {} n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cout << *it <<   =   << a <<   n ; n   err(++it, args...); n } n const int MOD = 1e9 + 7, N = 2e5 + 5, B = 32; n vector<int> g[N]; n vector<int> inv(N); n map<pair<int, int>, int> mp; n map<int, vector<int>> mpans; n void dfs(int u, int p) { n   for (auto v : g[u]) { n     if (v == p) continue; n     if (mp[{u, v}]) inv[v] += 1; n     dfs(v, u); n     inv[u] += inv[v]; n   } n } n void dfs1(int u, int p, int temp) { n   mpans[temp].push_back(u); n   for (auto v : g[u]) { n     if (v == p) continue; n     int v1; n     if (mp[{u, v}]) n       v1 = -1; n     else n       v1 = 1; n     dfs1(v, u, temp + v1); n   } n } n void solve() { n   int n; n   cin >> n; n   for (int i = 1; i < n; i++) { n     int x, y; n     cin >> x >> y; n     mp[{x, y}] = 0; n     mp[{y, x}] = 1; n     g[x].push_back(y); n     g[y].push_back(x); n   } n   dfs(1, 0); n   dfs1(1, 0, inv[1]); n   auto xx = *mpans.begin(); n   cout << xx.first <<   n ; n   sort(xx.second.begin(), xx.second.end()); n   for (auto r : xx.second) cout << r <<    ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9 + 7; n const int N = 1e6 + 5; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i <= 2 * n; i++) { n     for (int j = 0; j < 2 * abs(n - i); j++) cout <<    ; n     int cnt = 0; n     for (int j = 0; j <= 2 * n - 2 * abs(n - i); j++) { n       if (j != 0) cout <<    ; n       cout << cnt; n       if (j >= n - abs(n - i)) n         cnt--; n       else n         cnt++; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct station { n   int p, x, dir; n   station() {} n   station(int pp, int xx, int dirr) { n     p = pp; n     x = xx; n     dir = dirr; n   } n }; n bool cmp(station a, station b) { n   if (a.x != b.x) return a.x < b.x; n   return a.dir == 1; n } n int d, n, m; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> d >> n >> m; n   vector<station> v; n   for (int i = 0; i < m; i++) { n     int x, p; n     cin >> x >> p; n     v.push_back(station(p, x, 1)); n     v.push_back(station(p, min(d, x + n), -1)); n   } n   v.push_back(station(0, 0, 1)); n   v.push_back(station(0, n, -1)); n   sort(v.begin(), v.end(), cmp); n   long long last = 0; n   long long res = 0; n   multiset<long long> s; n   s.insert(0); n   long long mx = 0; n   for (int i = 1; i < v.size(); i++) { n     long long cur = (long long)v[i].x; n     long long mn = *s.begin(); n     res += (cur - last) * mn; n     if (cur - last > n || s.size() == 0) return cout << -1, 0; n     if (v[i].dir == 1) { n       s.insert(v[i].p); n     } else { n       s.erase(s.find(v[i].p)); n     } n     last = cur; n   } n   (last == d) ? cout << res : cout << -1; n   return 0; n } n