#include <bits/stdc++.h> n using namespace std; n const int N = 500, INF = 1 << 30; n int nxt[N], a[N][N], n, x, Rank[N][N], now; n char s[10]; n queue<int> q; n void init() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) scanf( %d , &a[i][j]); n   puts( B ); n   fflush(stdout); n   scanf( %s , s); n   if (s[0] ==  I ) { n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= n; j++) a[i][j] = -a[i][j]; n   } n   scanf( %d , &x); n   if (x > n) n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= n; j++) a[i][j] = -a[i][j]; n } n bool cmp(int x, int y) { return a[now][x - n] > a[now][y - n]; } n void prework() { n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) Rank[i][j] = j + n; n     now = i; n     sort(Rank[i] + 1, Rank[i] + 1 + n, cmp); n     q.push(i); n   } n   for (int i = 1; i <= n; i++) a[0][i] = a[i][0] = INF; n   for (int i = 1; i <= n; i++) nxt[i] = nxt[i + n] = Rank[i][0] = 0; n   while (!q.empty()) { n     int x = q.front(); n     q.pop(); n     if (x == 0) continue; n     while (nxt[x] == 0) { n       int girl = Rank[x][++*Rank[x]]; n       if (a[x][girl - n] < a[nxt[girl]][girl - n]) n         nxt[nxt[girl]] = 0, q.push(nxt[girl]), nxt[girl] = x, nxt[x] = girl; n     } n   } n } n void work() { n   prework(); n   for (int i = 1;; i++) { n     if (x == -1 || x == -2) return; n     printf( %d n , nxt[x]); n     fflush(stdout); n     scanf( %d , &x); n   } n } n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     init(); n     work(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int T; n   cin >> T; n   while (T--) { n     int n; n     cin >> n; n     int mid = sqrt(n + 0.5); n     vector<int> ans; n     ans.push_back(0); n     for (int i = 1; i <= mid; i++) { n       ans.push_back(i); n       ans.push_back(n / i); n     } n     sort(ans.begin(), ans.end()); n     n = unique(ans.begin(), ans.end()) - ans.begin(); n     cout << n << endl; n     for (int i = 0; i < n; i++) cout << ans[i] <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, y, n, a, b; n   cin >> x >> y >> n; n   long double d = 10000000000, t, q; n   t = (long double)x / y; n   for (int i = 1; i <= n; i++) { n     q = abs(t - floor(t * i) / i); n     if (q < d) { n       a = floor(t * i); n       b = i; n       d = q; n     } n     q = abs(t - ceil(t * i) / i); n     if (q < d) { n       a = ceil(t * i); n       b = i; n       d = q; n     } n   } n   cout << a <<  /  << b << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct state { n   int x, y, d; n   state(){}; n   state(int _x, int _y, int _d) { x = _x, y = _y, d = _d; }; n }; n int main() { n   int r, c; n   int dx[4] = {1, 0, -1, 0}; n   int dy[4] = {0, 1, 0, -1}; n   while (cin >> r >> c) { n     char temp; n     int map[1010][1010]; n     vector<state> opp; n     pair<int, int> start, end; n     for (int i = 0; i < r; i++) n       for (int j = 0; j < c; j++) { n         cin >> temp; n         if (temp >  0  && temp <=  9 ) opp.push_back(state(i, j, temp -  0 )); n         if (temp ==  S ) start = pair<int, int>(i, j); n         if (temp ==  E ) end = pair<int, int>(i, j); n         if (temp ==  T ) n           map[i][j] = -1; n         else n           map[i][j] = 1222333444; n       } n     map[end.first][end.second] = 0; n     queue<pair<int, int> > next; n     next.push(end); n     while (!next.empty()) { n       pair<int, int> now = next.front(); n       next.pop(); n       for (int j = 0; j < 4; j++) { n         int tempx = now.first + dx[j]; n         int tempy = now.second + dy[j]; n         if (tempx < 0 || tempx > r - 1 || tempy < 0 || tempy > c - 1) continue; n         if (map[tempx][tempy] == -1) continue; n         if (map[tempx][tempy] == 1222333444) { n           map[tempx][tempy] = map[now.first][now.second] + 1; n           next.push(pair<int, int>(tempx, tempy)); n         } n       } n     } n     int sum = 0; n     for (int i = 0; i < opp.size(); i++) { n       int tempx = opp[i].x; n       int tempy = opp[i].y; n       if (map[tempx][tempy] <= map[start.first][start.second]) sum += opp[i].d; n     } n     cout << sum << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INPUT_MAXCHARS = 1 << 16; n char buffer[INPUT_MAXCHARS]; n struct FastReader { n   char *p; n   FastReader() { n     fread(buffer, 1, sizeof buffer, stdin); n     p = buffer; n   } n   int next() { n     int remchars = INPUT_MAXCHARS - (p - buffer); n     if (remchars < 25) { n       memcpy(buffer, p, remchars); n       size_t cnt = fread(buffer + remchars, 1, sizeof buffer - remchars, stdin); n       if (remchars + cnt < sizeof buffer) { n         buffer[remchars + cnt] = 0; n       } n       p = buffer; n     } n     while (*p <  0 ) { n       ++p; n     } n     int val = 0; n     while (*p >=  0 ) { n       val = val * 10 + (*p -  0 ); n       ++p; n     } n     return val; n   } n }; n const int inf = 1234567890; n const int MAXN = 100000; n vector<int> arrivals[MAXN]; n int arr_idx[MAXN]; n vector<pair<int, int> > adj[MAXN]; n int best[MAXN]; n bool done[MAXN]; n int main() { n   FastReader reader; n   int n = reader.next(); n   int m = reader.next(); n   for (int i = 0; i < m; ++i) { n     int a = reader.next(); n     int b = reader.next(); n     int c = reader.next(); n     adj[a - 1].push_back(make_pair(b - 1, c)); n     adj[b - 1].push_back(make_pair(a - 1, c)); n   } n   for (int i = 0; i < n; ++i) { n     int k = reader.next(); n     arrivals[i].reserve(k + 1); n     for (int j = 0; j < k; ++j) { n       int t = reader.next(); n       arrivals[i].push_back(t); n     } n     arrivals[i].push_back(inf); n   } n   for (int i = 0; i < n; ++i) { n     best[i] = inf; n   } n   priority_queue<pair<int, int> > PQ; n   PQ.push(make_pair(0, 0)); n   best[0] = 0; n   while (!PQ.empty()) { n     const pair<int, int> tmp = PQ.top(); n     PQ.pop(); n     int t = -tmp.first; n     int at = tmp.second; n     if (done[at] || best[at] < t) { n       continue; n     } n     done[at] = true; n     if (at == n - 1) { n       printf( %d n , t); n       return 0; n     } n     while (arrivals[at][arr_idx[at]] < t) { n       ++arr_idx[at]; n     } n     if (arrivals[at][arr_idx[at]] == t) { n       done[at] = false; n       best[at] = t + 1; n       PQ.push(make_pair(-t - 1, at)); n     } else { n       for (int i = 0; i < (int)adj[at].size(); ++i) { n         const pair<int, int> e = adj[at][i]; n         if (t + e.second < best[e.first]) { n           best[e.first] = t + e.second; n           PQ.push(make_pair(-best[e.first], e.first)); n         } n       } n     } n   } n   puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n  n  n const int maxn = 2e5+5; n typedef long long ll; n  n char s[maxn],f[maxn]; n int t[maxn<<2],lz[maxn<<2]; n  n void pushup(int rt){ n  t[rt]=t[rt<<1]+t[rt<<1|1]; n } n void pushdown(int rt,int l,int r){ n  if(lz[rt]!=-1){ n   int mid=l+r>>1; n   t[rt<<1]=lz[rt]*(mid-l+1); n   t[rt<<1|1]=lz[rt]*(r-mid); n   lz[rt<<1]=lz[rt<<1|1]=lz[rt]; n   lz[rt]=-1; n  } n } n void build(int rt,int l,int r){ n  lz[rt]=-1; n  if(l==r){ n   t[rt]=f[l]- 0 ; n   return; n  } n  int mid=l+r>>1; n  build(rt<<1,l,mid); n  build(rt<<1|1,mid+1,r); n  pushup(rt); n } n void cg(int rt,int l,int r,int ql,int qr,int v){ n  if(l>=ql && r<=qr){ n   t[rt]=(r-l+1)*v; n   lz[rt]=v;  n   return; n  } n  int mid=l+r>>1; n  pushdown(rt,l,r); n  if(ql<=mid && qr>=l)cg(rt<<1,l,mid,ql,qr,v); n  if(ql<=r && qr>=mid+1)cg(rt<<1|1,mid+1,r,ql,qr,v); n  pushup(rt); n } n int qry(int rt,int l,int r,int ql,int qr){ n  if(l>=ql && r<=qr){ n   return t[rt]; n  }  n  pushdown(rt,l,r); n  int mid=l+r>>1; n  int ans=0; n  if(ql<=mid)ans+=qry(rt<<1,l,mid,ql,qr); n  if(qr>=mid+1)ans+=qry(rt<<1|1,mid+1,r,ql,qr); n  pushup(rt); n  return ans; n } n  n struct Node{ n  int l,r; n }a[maxn]; n int main(){ n  int t; n  scanf( %d ,&t); n  while(t--){ n   int n,q; n   scanf( %d%d%s%s ,&n,&q,s+1,f+1); n   build(1,1,n); n   bool failed=false; n   for(int i=1;i<=q;++i){ n    scanf( %d%d ,&a[i].l,&a[i].r); n   } n   for(int i=q;i>=1;--i){ n    int l=a[i].l,r=a[i].r; n    int num=qry(1,1,n,l,r),k=(r-l+2)/2-1; n    if(r-l+1<=2){ n     if(num!=r-l+1 && num){ n      failed=true; n      break; n     } n    }else if(r-l+1-num<=k)cg(1,1,n,l,r,1);else if(num<=k)cg(1,1,n,l,r,0);else{ n     if(num!=r-l+1 && num){ n      failed=true; n      break; n     } n    } n   } n   if(failed){ n    printf( NO n ); n    continue; n   } n   for(int i=1;i<=n;++i){ n    if(qry(1,1,n,i,i)!=s[i]- 0 ){ n     failed=true; n     break; n    } n   } n   if(failed){ n    printf( NO n ); n   }else printf( YES n ); n  } n }/*test: n 2 n 9 10 n 111101101 n 110001101 n 7 7 n 9 9 n 5 5 n 1 4 n 7 7 n 3 3 n 5 5 n 9 9 n 9 9 n 5 5 n */


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


#include <bits/stdc++.h> n using namespace std; n int n, m; n int l[200000], r[200000]; n int a[200000], b[200000], c[200000]; n int d[800000], p[800000]; n set<int> se; n map<int, int> ma; n int rev[800000]; n int mac = 0; n long long ans = 0; n int ansi, ansj; n pair<int, int> fen[800000]; n void fenUpdate(int pos, pair<int, int> val) { n   for (; pos < mac; pos |= pos + 1) fen[pos] = max(fen[pos], val); n } n pair<int, int> fenGet(int pos) { n   pair<int, int> ret = make_pair(-1, -1); n   for (; pos >= 0; pos = (pos & (pos + 1)) - 1) ret = max(ret, fen[pos]); n   return ret; n } n struct Ev { n   int x; n   bool i; n   int ind; n   Ev(int x, bool i, int ind) : x(x), i(i), ind(ind) {} n   Ev() {} n }; n Ev e[400000]; n int ec = 0; n bool cmp(const Ev &lhs, const Ev &rhs) { n   if (lhs.x != rhs.x) return lhs.x < rhs.x; n   return lhs.i < rhs.i; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < (int)(n); ++i) scanf( %d%d , l + i, r + i); n   for (int i = 0; i < (int)(m); ++i) scanf( %d%d%d , a + i, b + i, c + i); n   for (int i = 0; i < (int)(n); ++i) se.insert(l[i]), se.insert(r[i]); n   for (int i = 0; i < (int)(m); ++i) se.insert(a[i]), se.insert(b[i]); n   for (int x : se) ma[x] = mac, rev[mac++] = x; n   for (int i = 0; i < (int)(n); ++i) l[i] = ma[l[i]], r[i] = ma[r[i]]; n   for (int i = 0; i < (int)(m); ++i) a[i] = ma[a[i]], b[i] = ma[b[i]]; n   for (int i = 0; i < (int)(mac); ++i) d[i] = -1; n   for (int i = 0; i < (int)(n); ++i) n     if (r[i] > d[l[i]]) { n       d[l[i]] = r[i]; n       p[l[i]] = i; n     } n   for (int i = 1; i < mac; ++i) n     if (d[i - 1] > d[i]) { n       d[i] = d[i - 1]; n       p[i] = p[i - 1]; n     } n   for (int i = 0; i < (int)(m); ++i) n     if (d[a[i]] > a[i]) { n       int r = min(b[i], d[a[i]]); n       long long cur = (rev[r] - rev[a[i]]) * (long long)c[i]; n       if (cur > ans) { n         ans = cur; n         ansi = p[a[i]]; n         ansj = i; n       } n     } n   for (int i = 0; i < (int)(mac); ++i) d[i] = mac; n   for (int i = 0; i < (int)(n); ++i) n     if (l[i] < d[r[i]]) { n       d[r[i]] = l[i]; n       p[r[i]] = i; n     } n   for (int i = mac - 2; i >= 0; --i) n     if (d[i + 1] < d[i]) { n       d[i] = d[i + 1]; n       p[i] = p[i + 1]; n     } n   for (int i = 0; i < (int)(m); ++i) n     if (d[b[i]] < b[i]) { n       int l = max(a[i], d[b[i]]); n       long long cur = (rev[b[i]] - rev[l]) * (long long)c[i]; n       if (cur > ans) { n         ans = cur; n         ansi = p[b[i]]; n         ansj = i; n       } n     } n   for (int i = 0; i < (int)(mac); ++i) fen[i] = make_pair(-1, -1); n   for (int i = 0; i < (int)(n); ++i) e[ec++] = Ev(l[i], true, i); n   for (int i = 0; i < (int)(m); ++i) e[ec++] = Ev(a[i], false, i); n   sort(e, e + ec, cmp); n   for (Ev ev : e) { n     if (ev.i) { n       pair<int, int> ret = fenGet(mac - 1 - r[ev.ind]); n       if (ret.first != -1) { n         long long cur = n             (long long)ret.first * (rev[r[ev.ind]] - rev[l[ev.ind]]); n         if (cur > ans) { n           ans = cur; n           ansi = ev.ind; n           ansj = ret.second; n         } n       } n     } else { n       fenUpdate(mac - 1 - b[ev.ind], make_pair(c[ev.ind], ev.ind)); n     } n   } n   cout << ans << endl; n   if (ans != 0) cout << ansi + 1 <<     << ansj + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mo = 998244353; n const long long g = 3; n const int N = 500000; n int n, ax, bx, rev[N + 10]; n long long aa[N + 10], bb[N + 10], c[N + 10], fac[N + 10], inv[N + 10]; n long long mul(long long x, long long y) { n   long long z = 1; n   while (y) { n     if (y & 1) z = z * x % mo; n     y >>= 1; n     x = x * x % mo; n   } n   return z; n } n struct poly { n   vector<int> a; n   void pre(int n) { n     rev[0] = 0; n     for (int i = 1; i < n; i++) n       if (i & 1) n         rev[i] = rev[i ^ 1] + (n >> 1); n       else n         rev[i] = rev[i >> 1] >> 1; n   } n   void FFT(long long *a, int n) { n     for (int i = 0; i < n; i++) c[rev[i]] = a[i]; n     for (int i = 2; i <= n; i <<= 1) { n       long long wn = mul(g, (mo - 1) / i); n       for (int j = 0; j < n; j += i) { n         long long w = 1; n         for (int k = j; k < j + i / 2; k++, w = wn * w % mo) { n           long long ck = c[k]; n           c[k] = (ck + w * c[k + i / 2]) % mo; n           c[k + i / 2] = (ck - w * c[k + i / 2]) % mo; n         } n       } n     } n     for (int i = 0; i < n; i++) a[i] = (c[i] + mo) % mo; n   } n   void IFFT(long long *a, int n) { n     FFT(a, n); n     for (int i = 1; i < n / 2; i++) swap(a[i], a[n - i]); n     long long invn = mul(n, mo - 2); n     for (int i = 0; i < n; i++) a[i] = a[i] * invn % mo; n   } n   poly operator*(poly &p) { n     int sz = a.size() + p.a.size() - 1; n     int nx = 1; n     while (nx < sz) nx <<= 1; n     pre(nx); n     for (int i = 0; i < nx; i++) { n       if (i < (int)a.size()) n         aa[i] = a[i]; n       else n         aa[i] = 0; n       if (i < (int)p.a.size()) n         bb[i] = p.a[i]; n       else n         bb[i] = 0; n     } n     FFT(aa, nx); n     FFT(bb, nx); n     for (int i = 0; i < nx; i++) aa[i] = aa[i] * bb[i] % mo; n     IFFT(aa, nx); n     poly ans; n     ans.a.clear(); n     for (int i = 0; i < sz; i++) ans.a.push_back(aa[i]); n     return ans; n   } n }; n void prework() { n   fac[0] = 1; n   for (int i = 1; i <= N; i++) fac[i] = fac[i - 1] * i % mo; n   inv[N] = mul(fac[N], mo - 2); n   for (int i = N - 1; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mo; n } n poly Calc_Stirling(int l, int r) { n   poly f; n   f.a.clear(); n   if (l > r) { n     f.a.push_back(1); n     return f; n   } n   if (l == r) { n     f.a.push_back(l); n     f.a.push_back(1); n     return f; n   } n   int mid = (l + r) / 2; n   f = Calc_Stirling(l, mid); n   poly g = Calc_Stirling(mid + 1, r); n   f = f * g; n   return f; n } n int main() { n   scanf( %d%d%d , &n, &ax, &bx); n   if (ax == 0 || bx == 0) { n     printf( 0 n ); n     return 0; n   } n   prework(); n   poly f = Calc_Stirling(0, n - 2); n   long long ans; n   if (ax + bx - 2 < (int)f.a.size()) n     ans = f.a[ax + bx - 2]; n   else n     ans = 0; n   ans = n       (ans * fac[ax + bx - 2] % mo * inv[ax - 1] % mo * inv[bx - 1] % mo + mo) % n       mo; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long m, b; n   cin >> m >> b; n   long long Max = 0; n   for (long long i = b; i >= 0; i--) { n     long long p = (m * b - m * i + 1) * (i + 1) * (m * b - m * i + i) / 2; n     Max = max(p, Max); n   } n   printf( %I64d , Max); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int L = 1 << 20; n const int R = 1 << 21; n const int Maxn = 200005; n int tree[R], A, B; n int d[Maxn]; n char s[Maxn]; n bool vowel(char x) { n   x = tolower(x); n   if (x ==  a  || x ==  e  || x ==  i  || x ==  o  || x ==  u ) return 1; n   return 0; n } n int read(int lo, int hi, int x) { n   if (hi < A || lo > B) return Maxn; n   if (A <= lo && hi <= B) return tree[x]; n   int mid = (lo + hi) >> 1; n   return min(read(lo, mid, 2 * x), read(mid + 1, hi, 2 * x + 1)); n } n void update(int x, int id) { n   tree[x] = min(id, tree[x]); n   for (x >>= 1; x > 0; x >>= 1) tree[x] = min(tree[2 * x], tree[2 * x + 1]); n } n int main() { n   for (int i = 0; i < R; ++i) tree[i] = Maxn; n   scanf( %s , s); n   int n = strlen(s); n   for (int i = 0; i < n; ++i) { n     if (i) d[i] = d[i - 1]; n     if (vowel(s[i])) n       --d[i]; n     else n       d[i] += 2; n   } n   for (int i = 0; i < n; ++i) d[i] += Maxn; n   update(L + Maxn, -1); n   int sol = 0, cnt = 0; n   for (int i = 0; i < n; ++i) { n     A = L, B = L + d[i]; n     int id = read(L, R - 1, 1); n     update(L + d[i], i); n     if (id == Maxn) continue; n     if (i - id > sol) n       sol = i - id, cnt = 1; n     else if (i - id == sol) n       ++cnt; n   } n   if (!sol) n     printf( No solution n ); n   else n     printf( %d %d n , sol, cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int T; n int h, c, t; n int main() { n   scanf( %d , &T); n   while (T--) { n     scanf( %d%d%d , &h, &c, &t); n     if (t * 2 <= (h + c)) n       printf( %d n , 2); n     else { n       long long lef = (h - t) / (2 * t - (h + c)); n       double a1 = (1.0 * h * (lef + 1) + c * lef) / (2 * lef + 1); n       lef++; n       double a2 = (1.0 * h * (lef + 1) + c * lef) / (2 * lef + 1); n       if (abs(a1 - t) <= abs(a2 - t)) n         printf( %lld n , 2 * (lef - 1) + 1); n       else n         printf( %lld n , 2 * lef + 1); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n int gi() { n   int x = 0, o = 1; n   char ch = getchar(); n   while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar(); n   if (ch ==  - ) o = -1, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n   return x * o; n } n int n, d, b, sum[N]; n int calc() { n   int s1 = 0, s2 = 0; n   for (int i = 1; i <= (n + 1) / 2; i++) { n     int f1 = sum[min(i + 1ll * d * i, (long long)n)] - s1 * b; n     int f2 = sum[n] - sum[max(0ll, n - i - 1ll * d * i)] - s2 * b; n     if (i == n - i + 1) n       s1 += f1 >= b; n     else n       s1 += f1 >= b, s2 += f2 >= b; n   } n   return min(s1 - n % 2, s2); n } n int main() { n   cin >> n >> d >> b; n   for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + gi(); n   printf( %d n , n / 2 - calc()); n   return 0; n } n


#include <bits/stdc++.h> n template <typename T> n inline void SWAP(T &a, T &b) { n   T tmp = a; n   a = b; n   b = tmp; n } n template <typename T> n inline T ABS(const T &val) { n   return val < 0 ? -val : val; n } n template <typename T> n inline T MAX(const T &a, const T &b) { n   return a > b ? a : b; n } n template <typename T> n inline T MIN(const T &a, const T &b) { n   return a < b ? a : b; n } n template <typename T> n inline T SQR(const T &a) { n   return a * a; n } n const int INTinf = 2147483647; n const int nINTinf = 0 - 2147483648; n using namespace std; n int n, m, p; n const int SZ = 20002; n int _X[SZ], _Y[SZ]; n int A[142][SZ]; n int B[141][SZ]; n int F[SZ << 1]; n int *m1, *m2; n int kol = 0; n long long answ2 = 0L; n string answ =   ; n inline int f(const int &a, const int &b) { return F[_X[a] + _Y[b]]; } n int main() { n   cin >> n >> m >> p; n   int SZ2 = SZ << 1; n   for (int i = 0; i != SZ2; i++) { n     F[i] = i % p; n   } n   for (int i = 0; i != n; i++) cin >> _X[i]; n   for (int i = 0; i != m; i++) cin >> _Y[i]; n   m1 = A[0]; n   m1[0] = f(0, 0); n   for (int i = 1; i <= n - 1; i++) { n     m1[i] = m1[i - 1] + f(i, 0); n   } n   int nPos = 0; n   for (int i = 1; i <= m - 1; i++) { n     if (!nPos) { n       copy(m1, m1 + SZ, B[kol++]); n     } n     nPos++; n     if (nPos == 142) nPos = 0; n     m2 = A[nPos]; n     m2[0] = m1[0] + f(0, i); n     for (int j = 1; j <= n - 1; j++) { n       m2[j] = MAX(m1[j], m2[j - 1]) + f(j, i); n     } n     m1 = m2; n   } n   int Y = n - 1; n   int X = m - 1; n   while (true) { n     while (Y && (A[nPos][Y] - f(Y, X) == A[nPos][Y - 1])) { n       answ.push_back( C ); n       answ2 += f(Y, X); n       Y--; n     } n     answ2 += f(Y, X); n     answ.push_back( S ); n     X--; n     if (!nPos) { n       break; n     } n     nPos--; n   } n   kol--; n   if (m % 142 != 1) { n     kol--; n   } n   while (kol > -1) { n     copy(B[kol], B[kol] + SZ, A[0]); n     int to = (kol + 1) * 142; n     m1 = A[0]; n     for (int i = 142 * kol + 1; i != to; i++) { n       nPos++; n       m2 = A[nPos]; n       m2[0] = m1[0] + f(0, i); n       for (int j = 1; j <= n - 1; j++) { n         m2[j] = MAX(m1[j], m2[j - 1]) + f(j, i); n       } n       m1 = m2; n     } n     while (true) { n       while (Y && (A[nPos][Y] - f(Y, X) == A[nPos][Y - 1])) { n         answ.push_back( C ); n         answ2 += f(Y, X); n         Y--; n       } n       answ2 += f(Y, X); n       answ.push_back( S ); n       X--; n       if (!nPos) { n         break; n       } n       nPos--; n     } n     kol--; n   } n   answ = answ.substr(0, answ.size() - 1); n   reverse(answ.begin(), answ.end()); n   cout << answ2 << endl; n   cout << answ << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s, t; n   cin >> s >> t; n   if (s ==  monday  && (t ==  thursday  || t ==  wednesday  || t ==  monday )) n     cout <<  YES ; n   else if (s ==  tuesday  && n            (t ==  friday  || t ==  thursday  || t ==  tuesday )) n     cout <<  YES ; n   else if (s ==  wednesday  && n            (t ==  friday  || t ==  saturday  || t ==  wednesday )) n     cout <<  YES ; n   else if (s ==  thursday  && n            (t ==  saturday  || t ==  sunday  || t ==  thursday )) n     cout <<  YES ; n   else if (s ==  friday  && (t ==  sunday  || t ==  monday  || t ==  friday )) n     cout <<  YES ; n   else if (s ==  saturday  && n            (t ==  monday  || t ==  tuesday  || t ==  saturday )) n     cout <<  YES ; n   else if (s ==  sunday  && n            (t ==  tuesday  || t ==  wednesday  || t ==  sunday )) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, t, timer = 0; n   scanf( %d%d%d , &n, &m, &t); n   deque<int> q; n   vector<int> col(n); n   char isOk = false; n   for (int i = 0, j = 0; i < n; i++) { n     int x, y, z, start; n     scanf(  n%d:%d:%d , &x, &y, &z); n     start = x * 3600 + y * 60 + z; n     while (!q.empty() && q.front() <= start) { n       j--; n       q.pop_front(); n     } n     if (j < m) { n       j++; n       q.push_back(start + t); n       timer++; n     } else { n       q.back() = start + t; n     } n     if (j == m) { n       isOk = true; n     } n     col[i] = timer; n   } n   if (!isOk) { n     printf( No solution ); n     return 0; n   } n   printf( %d n , timer); n   for (int i : col) { n     printf( %d n , i); n   } n   return 0; n } n


#include <bits/stdc++.h> n struct vit { n   int price; n   char vit[4]; n }; n int main() { n   int i, n, min; n   scanf( %d , &n); n   struct vit t[n]; n   for (i = 0; i < n; i++) { n     scanf( %d %s , &t[i].price, t[i].vit); n   } n   int A = 300001, B = 300001, C = 300001, AB = 300001, AC = 300001, BC = 300001, n       ABC = 300001; n   for (i = 0; i < n; i++) { n     if (strcmp( A , t[i].vit) == 0) { n       if (A > t[i].price) A = t[i].price; n     } n   } n   for (i = 0; i < n; i++) { n     if (strcmp( B , t[i].vit) == 0) { n       if (B > t[i].price) B = t[i].price; n     } n   } n   for (i = 0; i < n; i++) { n     if (strcmp( C , t[i].vit) == 0) { n       if (C > t[i].price) C = t[i].price; n     } n   } n   for (i = 0; i < n; i++) { n     if ((strcmp( AB , t[i].vit) == 0) || (strcmp( BA , t[i].vit) == 0)) { n       if (AB > t[i].price) AB = t[i].price; n     } n   } n   for (i = 0; i < n; i++) { n     if ((strcmp( BC , t[i].vit) == 0) || (strcmp( CB , t[i].vit) == 0)) { n       if (BC > t[i].price) BC = t[i].price; n     } n   } n   for (i = 0; i < n; i++) { n     if ((strcmp( AC , t[i].vit) == 0) || (strcmp( CA , t[i].vit) == 0)) { n       if (AC > t[i].price) AC = t[i].price; n     } n   } n   for (i = 0; i < n; i++) { n     if ((strcmp( ABC , t[i].vit) == 0) || (strcmp( ACB , t[i].vit) == 0) || n         (strcmp( BAC , t[i].vit) == 0) || (strcmp( BCA , t[i].vit) == 0) || n         (strcmp( CAB , t[i].vit) == 0) || (strcmp( CBA , t[i].vit) == 0)) { n       if (ABC > t[i].price) ABC = t[i].price; n     } n   } n   min = ABC; n   if (A + B + C < min) min = A + B + C; n   if (AB + C < min) min = AB + C; n   if (BC + A < min) min = BC + A; n   if (AC + B < min) min = AC + B; n   if (AB + BC < min) min = AB + BC; n   if (AB + AC < min) min = AB + AC; n   if (BC + AC < min) min = BC + AC; n   if (min > 300000) { n     printf( -1 ); n     return 0; n   } n   printf( %d , min); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int f[200][200], c[500010], n, i, j, ans; n char a[500010], b[500010], str[20]; n int main() { n   cin >> n; n   for (i = 1; i <= n; i++) { n     scanf( %s , str); n     a[i] = str[0], b[i] = str[strlen(str) - 1], c[i] = strlen(str); n   } n   memset(f, -1, sizeof(f)); n   for (i = 1; i <= n; i++) { n     for (j =  a ; j <=  z ; j++) n       if (f[j][a[i]] != -1) f[j][b[i]] = max(f[j][b[i]], f[j][a[i]] + c[i]); n     f[a[i]][b[i]] = max(f[a[i]][b[i]], c[i]); n   } n   for (i =  a ; i <=  z ; i++) ans = max(ans, f[i][i]); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Edge { n   long long to, dis, next, cost; n } edge[24050]; n long long num = -1; n bool vis[10010]; n long long mincost; n long long pre[10010], head[10010], cost[10010], last[10010], flow[10010], n, k, n     a[110], b[110], s, t, maxflow; n long long to[110]; n void add(long long f, long long t, long long dis, long long cost) { n   edge[++num].to = t; n   edge[num].dis = dis; n   edge[num].next = head[f]; n   edge[num].cost = cost; n   head[f] = num; n   edge[++num].to = f; n   edge[num].dis = 0; n   edge[num].cost = -cost; n   edge[num].next = head[t]; n   head[t] = num; n } n queue<long long> q; n bool spfa(long long s, long long t) { n   memset(cost, 0x3f3f3f3f, sizeof cost); n   memset(flow, 0x3f3f3f3f, sizeof flow); n   memset(vis, 0, sizeof vis); n   q.push(s); n   vis[s] = 1; n   cost[s] = 0; n   pre[t] = -1; n   while (!q.empty()) { n     long long nowp = q.front(); n     q.pop(); n     vis[nowp] = 0; n     for (long long i = head[nowp]; i != -1; i = edge[i].next) { n       if (edge[i].dis > 0 && cost[edge[i].to] > cost[nowp] + edge[i].cost) { n         cost[edge[i].to] = cost[nowp] + edge[i].cost; n         pre[edge[i].to] = nowp; n         last[edge[i].to] = i; n         flow[edge[i].to] = min(flow[nowp], edge[i].dis); n         if (!vis[edge[i].to]) { n           vis[edge[i].to] = 1; n           q.push(edge[i].to); n         } n       } n     } n   } n   return pre[t] != -1; n } n void MCMF(long long s, long long t) { n   while (spfa(s, t)) { n     long long now = t; n     maxflow += flow[t]; n     mincost += flow[t] * cost[t]; n     while (now != s) { n       edge[last[now]].dis -= flow[t]; n       edge[last[now] ^ 1].dis += flow[t]; n       now = pre[now]; n     } n   } n } n signed main() { n   long long T; n   cin >> T; n   while (T--) { n     num = -1; n     memset(to, -1, sizeof to); n     memset(head, -1, sizeof head); n     cin >> n >> k; n     for (long long i = 1; i <= n; i++) cin >> a[i] >> b[i]; n     maxflow = mincost = 0; n     s = 0; n     t = 2 * n + 1; n     for (long long i = 1; i <= n; i++) add(s, i, 1, 0), add(i + n, t, 1, 0); n     for (long long i = 1; i <= n; i++) { n       for (long long j = 1; j <= n; j++) { n         long long nc = 0; n         if (j <= k - 1) n           nc = a[i] + b[i] * (j - 1ll); n         else if (j != n) n           nc = b[i] * (k - 1ll); n         else n           nc = a[i] + b[i] * (k - 1ll); n         nc = 0x3f3f3f3f - nc; n         add(i, j + n, 1, nc); n       } n     } n     MCMF(s, t); n     long long nowi = -1; n     for (long long i = n * 4; i <= num; i += 2) { n       nowi++; n       if (edge[i].dis == 0) to[1 + nowi % n] = 1 + nowi / n; n     } n     cout << 2 * n - k << endl; n     for (long long i = 1; i <= k - 1; i++) cout << to[i] <<    ; n     for (long long i = k; i < n; i++) cout << to[i] <<     << -to[i] <<    ; n     cout << to[n]; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1 << 29; n const double EPS = 1e-9; n const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; n int n, m; n int main() { n   cin >> n >> m; n   int ans = 0; n   for (int i = 0; i <= n; i++) { n     int tmp = 0; n     int a1 = i; n     int b1 = (m - 2 * i); n     if (b1 < 0) break; n     int r1, r2; n     r1 = n - i; n     r2 = (m - 2 * i); n     int a2 = (r1 / 2); n     int b2 = r2 - a2; n     if (b2 < 0) { n       tmp = i + r2; n     } else { n       tmp = i + a2; n     } n     ans = max(ans, tmp); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n struct hdm { n   int first, second, id; n   hdm(){}; n   hdm(int first, int second, int id) : first(first), second(second), id(id){}; n }; n vector<hdm> v1, v2; n bool cmp1(hdm A, hdm B) { return (A.second < B.second); } n bool cmp2(hdm A, hdm B) { return (A.first > B.first); } n int main() { n   ios::sync_with_stdio(0); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int A, B; n     cin >> A >> B; n     pair<int, int> p = make_pair(A, B); n     if (A > B) { n       v1.push_back(hdm(A, B, i)); n     } else { n       v2.push_back(hdm(A, B, i)); n     } n   } n   sort(v1.begin(), v1.end(), cmp1); n   sort(v2.begin(), v2.end(), cmp2); n   int rs1 = (int)v1.size(); n   int rs2 = (int)v2.size(); n   if (rs1 >= rs2) { n     cout << rs1 <<   n ; n     for (int i = 0; i < v1.size(); i++) cout << v1[i].id <<    ; n   } else { n     cout << rs2 <<   n ; n     for (int i = 0; i < v2.size(); i++) cout << v2[i].id <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const ll base = 1000000007; n int n; n ll p2[1000000]; n class reimu { n  public: n   ll sum, sum2; n   int sz; n   ll ans = 0; n   void operator+=(reimu x) { n     (sum2 += x.sum2) %= base; n     (sum += x.sum) %= base; n     sz += x.sz; n   } n   void operator-=(reimu x) { n     (sum2 -= x.sum2) %= base; n     (sum -= x.sum) %= base; n     sz -= x.sz; n   } n   void cal() { n     (ans = sum2 * p2[sz - 1] + n            ((sz == 1) ? 0 : ((sum * sum - sum2) % base) * p2[sz - 2])) %= base; n   } n } f[1000000]; n ll pre[64]; n int main() { n   p2[0] = 1; n   for (int i = 1; i < 1000000; i++) (p2[i] = p2[i - 1] * 2) %= base; n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> n; n   for (int i = 0; i < 64; i++) { n     for (int d = 0, p10 = 1; d < 6; d++, p10 *= 10) n       if (i & (1 << d)) { n         pre[i] += p10; n       } n   } n   for (int i = 0; i < n; i++) { n     ll a; n     cin >> a; n     reimu temp; n     temp.sum = a; n     (temp.sum2 = a * a) %= base; n     temp.sz = 1; n     f[a] += temp; n   } n   for (int x = 999999; x >= 0; x--) { n     int mask = 0; n     for (int d = 0, p10 = 1; d < 6; d++, p10 *= 10) { n       if ((x / p10) % 10 != 9) mask |= 1 << d; n     } n     for (int sub = mask; sub; (sub -= 1) &= mask) { n       if (__builtin_popcount(sub) % 2 == 1) n         f[x] += f[x + pre[sub]]; n       else n         f[x] -= f[x + pre[sub]]; n     } n   } n   for (int i = 0; i <= 999999; i++) f[i].cal(); n   ll ans = 0; n   for (int x = 0; x <= 999999; x++) { n     int mask = 0; n     for (int d = 0, p10 = 1; d < 6; d++, p10 *= 10) { n       if ((x / p10) % 10 != 9) mask |= 1 << d; n     } n     ll res = f[x].ans; n     for (int sub = mask; sub; (sub -= 1) &= mask) { n       if (__builtin_popcount(sub) % 2 == 0) n         res += f[x + pre[sub]].ans; n       else n         res -= f[x + pre[sub]].ans; n     } n     ((res %= base) += base) %= base; n     (res *= x); n     ans ^= res; n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n double PI = acos(-1); n long long int mod = 998244353; n double eps = 1e-8; n long long int exp(long long int x, long long int y) { n   if (y < 0) return 0; n   long long int ret = 1; n   for (; y; y >>= 1, x = (x * x) % mod) { n     if (y & 1) ret = (ret * x) % mod; n   } n   return ret; n } n unsigned long long int pexp(unsigned long long int x, n                             unsigned long long int y) { n   if (y < 0) return 0; n   unsigned long long int ret = 1; n   for (; y; y >>= 1, x = (x * x)) { n     if (y & 1) ret = (ret * x); n   } n   return ret; n } n long long int gcd(long long int x, long long int y) { n   if (!x || !y) return x + y; n   return x % y == 0 ? y : gcd(y, x % y); n } n long long int lcm(long long int x, long long int y) { n   return x * (y / gcd(x, y)); n } n long long int bsum(long long int u, long long int b) { n   long long int ret = 0; n   if (u < b) return u; n   while (u) { n     ret += u % b; n     u /= b; n   } n   return ret; n } n long long int prival(long long int u, long long int p) { n   long long int cn = 0; n   while (u % p == 0) { n     cn++; n     u = u / p; n   } n   return cn; n } n long long int extm(long long int a, long long int b) { n   long long int ret = 0; n   while (a != 0) { n     if (a % 2 == 1) { n       ret += b; n       ret %= mod; n     } n     a >>= 1; n     b = (2 * b) % mod; n   } n   return ret; n } n long long int minv(long long int a, long long int b) { n   return 1 < a ? b - minv(b % a, a) * b / a : 1; n } n long long int eaphi(long long int x) { n   long long int t = x, ret = x, i; n   for (i = 2; i * i <= t; i++) { n     if (t % i == 0) { n       ret -= ret / i; n       while (t % i == 0) t /= i; n     } n   } n   if (t != 1) ret -= ret / t; n   return ret; n } n long long int eadivc(long long int x) { n   long long int ret = 0; n   long long int i; n   for (i = 1; i * i <= x; i++) { n     if (x % i == 0 && i * i != x) ret += 2; n     if (x % i == 0 && i * i == x) ret += 1; n   } n   return ret; n } n long long int eadivs(long long int x) { n   long long int ret = 0; n   long long int i; n   for (i = 1; i * i <= x; i++) { n     if (x % i == 0 && i * i != x) ret += i + x / i; n     if (x % i == 0 && i * i == x) ret += i; n   } n   return ret; n } n long long int ndig(long long int x, long long int b) { n   long long int ret = 0; n   while (x) { n     x /= b; n     ret++; n   } n   return ret; n } n long long int rev(long long int n, long long int b) { n   long long int ret = 0; n   while (n) { n     ret = b * ret + n % b; n     n /= b; n   } n   return ret; n } n long long int sq(long long int x) { n   long long int t = (long long int)sqrt(x); n   for (long long int i = t - 2; i <= t + 2; i++) n     if (i * i == x) return abs(i); n   return -1; n } n long long int extexp(long long int x, long long int y) { n   if (y < 0) return 0; n   long long int ret = 1; n   for (; y; y >>= 1, x = extm(x, x)) { n     if (y & 1) ret = extm(ret, x); n   } n   return ret; n } n bool isprime(long long int x) { n   if (x <= 1) return false; n   for (long long int i = 2; i * i <= x; i++) { n     if (x % i == 0) { n       return false; n     } n   } n   return true; n } n int val[755][755], B = 700; n int a[555555], q; n int main(void) { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int i, t, x, y, ans; n   cin >> q; n   while (q--) { n     cin >> t >> x >> y; n     if (t == 1) { n       a[x] += y; n       for (i = 1; i <= B; i++) val[i][x % i] += y; n     } n     if (t == 2) { n       ans = 0; n       if (x <= B) n         cout << val[x][y] <<   n ; n       else { n         for (i = y; i <= 500000; i += x) ans += a[i]; n         cout << ans <<   n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool isPrime(int N) { n   for (int i = 2; i * i <= N; ++i) { n     if (N % i == 0) return false; n   } n   return true; n } n bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { n   return (a.first > b.first); n } n int gcd(int a, int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n bool comp(const pair<int, int> &a, const pair<int, int> &b) { n   if (a.first == b.first) n     return a.second < b.second; n   else n     return a.first > b.first; n } n int main() { n   int n; n   cin >> n; n   int flag = 0; n   char a[5][5]; n   int max = 11; n   int digit[11] = {0}; n   for (int i = 0; i < 4; i++) { n     for (int j = 0; j < 4; j++) { n       cin >> a[i][j]; n       if (a[i][j] !=  . ) { n         digit[a[i][j] - 48]++; n       } n     } n   } n   for (int i = 0; i < 10; i++) { n     if (digit[i] > 2 * n) { n       cout <<  NO ; n       flag = 1; n       break; n     } n   } n   if (flag == 0) { n     cout <<  YES ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T, class L> n bool smax(T& x, L y) { n   return x < y ? (x = y, 1) : 0; n } n template <class T, class L> n bool smin(T& x, L y) { n   return x > y ? (x = y, 1) : 0; n } n const int maxn = 2e6 + 17; n pair<int, pair<int, int> > a[maxn]; n int n, m, par[maxn], mx[maxn], here[maxn]; n map<pair<int, int>, int> ans; n int r(int v) { return par[v] < 0 ? v : par[v] = r(par[v]); } n void mrg(int v, int u) { n   if ((v = r(v)) == (u = r(u))) return; n   if (par[u] < par[v]) swap(v, u); n   par[v] += par[u]; n   par[u] = v; n   smax(mx[v], mx[u]); n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0); n   cin >> n >> m; n   for (int i = 0; i < n; i++) n     for (int j = 0, x; j < m; j++) cin >> x, a[i * m + j] = {x, {i, j}}; n   sort(a, a + n * m); n   for (int l = 0; l < n * m;) { n     int r = l; n     while (a[r].first == a[l].first) r++; n     for (int i = l; i < r; i++) { n       mx[a[i].second.first] = mx[a[i].second.second + n] = 0; n       par[a[i].second.first] = par[a[i].second.second + n] = -1; n     } n     for (int i = l; i < r; i++) n       smax(mx[a[i].second.first], n            max(here[a[i].second.first], here[a[i].second.second + n]) + 1); n     for (int i = l; i < r; i++) mrg(a[i].second.first, a[i].second.second + n); n     for (int i = l; i < r; i++) { n       ans[{a[i].second.first, a[i].second.second}] = mx[::r(a[i].second.first)]; n       smax(here[a[i].second.first], n            ans[{a[i].second.first, a[i].second.second}]); n       smax(here[a[i].second.second + n], n            ans[{a[i].second.first, a[i].second.second}]); n     } n     l = r; n   } n   for (int i = 0; i < n; i++, cout <<   n ) n     for (int j = 0; j < m; j++) cout << ans[{i, j}] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n const long long base1 = 131; n const long long base2 = 233; n const long long mod1 = 998244353; n const long long mod2 = 1e9 + 7; n const long long MaxN = 1e6 + 50; n template <class t> n inline void read(t &s) { n   s = 0; n   register long long f = 1; n   register char c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar(); n   s *= f; n   return; n } n template <class t, class... A> n inline void read(t &x, A &...a) { n   read(x); n   read(a...); n } n template <class t> n inline void write(t x) { n   if (x < 0) putchar( - ), x = -x; n   long long buf[21], top = 0; n   while (x) buf[++top] = x % 10, x /= 10; n   if (!top) buf[++top] = 0; n   while (top) putchar(buf[top--] ^  0 ); n   return; n } n inline void setIn(std::string s) { n   freopen(s.c_str(),  r , stdin); n   return; n } n inline void setOut(std::string s) { n   freopen(s.c_str(),  w , stdout); n   return; n } n inline void setIO(std::string s =   ) { n   setIn(s +  .in ); n   setOut(s +  .out ); n   return; n } n template <class t> n inline bool checkmin(t &x, t y) { n   if (x > y) { n     x = y; n     return 1; n   } n   return 0; n } n template <class t> n inline bool checkmax(t &x, t y) { n   if (x < y) { n     x = y; n     return 1; n   } n   return 0; n } n inline long long lowbit(long long x) { return x & (-x); } n std::vector<long long> E[MaxN]; n std::pair<long long, long long> f[MaxN]; n long long e1[MaxN], e2[MaxN], U[MaxN], V[MaxN]; n signed main(void) { n   long long n, m; n   read(n, m); n   register long long u, v, ans = 0; n   for (long long i = 1; i <= m; ++i) n     read(u, v), U[i] = u, V[i] = v, E[u].push_back(v), E[v].push_back(u); n   for (long long i = 1; i <= n; ++i) std::sort((E[i]).begin(), (E[i]).end()); n   for (long long i = 1; i <= n; ++i) { n     register long long s1 = 0, s2 = 0; n     for (auto v : E[i]) n       s1 = (s1 * base1 + v) % mod1, s2 = (s2 * base2 + v) % mod2; n     f[i] = std::make_pair(s1, s2); n     s1 = 0, s2 = 0; n     E[i].push_back(i), std::sort((E[i]).begin(), (E[i]).end()); n     for (auto v : E[i]) n       s1 = (s1 * base1 + v) % mod1, s2 = (s2 * base2 + v) % mod2; n     e1[i] = s1, e2[i] = s2; n   } n   std::sort(f + 1, f + n + 1); n   register long long cnt = 0; n   for (long long i = 2; i <= n; ans += cnt, ++i) n     cnt = (f[i] == f[i - 1]) ? (cnt + 1) : 0; n   for (long long i = 1; i <= m; ++i) n     if (e1[U[i]] == e1[V[i]] && e2[U[i]] == e2[V[i]]) ++ans; n   write(ans), std::puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 2e6 + 5; n char s1[MAX], s2[MAX]; n int main() { n   cin >> s1 + 1; n   cin >> s2 + 1; n   int len1 = strlen(s1 + 1); n   int len2 = strlen(s2 + 1); n   int i = 1, j = 1; n   for (; i <= len1 && j <= len2;) { n     if (s1[i] == s2[j]) n       i++, j++; n     else n       j++; n   } n   if (i != len1 + 1) { n     puts( 0 ); n     return 0; n   } n   int tmp1 = j - 1; n   for (i = len1, j = len2; j >= 1 && i >= 1;) { n     if (s1[i] == s2[j]) n       i--, j--; n     else n       j--; n   } n   if (i != 0) { n     puts( 0 ); n     return 0; n   } n   int tmp2 = j + 1; n   if (tmp2 - tmp1 >= 0) { n     printf( %d n , tmp2 - tmp1); n   } else n     printf( 0 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double eps = 1e-9; n long double PI = acos((long double)-1.0); n struct io_s { n   bool negative; n   char ch; n   inline bool isdigitx(char c) { return c >=  0  && c <=  9 ; } n   inline char nextchar() { n     static char buf[100000], *p1 = buf, *p2 = buf; n     return p1 == p2 && n                    (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) n                ? EOF n                : *p1++; n   } n   template <typename T> n   bool rn(T& _v) { n     negative = false; n     _v = 0; n     while (!isdigitx(ch = nextchar()) && ch != EOF) { n       negative = ch ==  - ; n     }; n     if (ch == EOF) return false; n     do { n       _v *= 10; n       _v += ch -  0 ; n     } while (isdigitx(ch = nextchar())); n     if (negative) _v = -_v; n     return true; n   } n   template <typename T> n   bool run(T& _v) { n     _v = 0; n     while (!isdigitx(ch = nextchar()) && ch != EOF) { n     }; n     if (ch == EOF) return false; n     do { n       _v *= 10; n       _v += ch -  0 ; n     } while (isdigitx(ch = nextchar())); n     return true; n   } n   template <typename T> n   inline T r() { n     T v = T(); n     rn(v); n     return v; n   } n   inline int ri() { return r<int>(); } n   inline long long rll() { return r<long long>(); } n   inline int gets(char* s) { n     char* c = s; n     do { n       ch = nextchar(); n     } while (ch ==   n  || ch ==   r ); n     do { n       *(c++) = ch; n       ch = nextchar(); n     } while (ch !=   n  && ch !=   r ); n     *(c++) =   0 ; n     return c - s - 1; n   } n   inline char get() { n     do { n       ch = nextchar(); n     } while (ch <  A  || ch >  Z ); n     return ch; n   } n   template <class T> n   inline void o(T p) { n     static int stk[70], tp; n     if (p == 0) { n       putchar( 0 ); n       return; n     } n     if (p < 0) { n       p = -p; n       putchar( - ); n     } n     while (p) stk[++tp] = p % 10, p /= 10; n     while (tp) putchar(stk[tp--] +  0 ); n   } n   inline void ln() { putchar(  n ); } n   inline void space() { putchar(   ); } n   template <class T> n   inline void oln(T p) { n     o(p); n     ln(); n   } n } io; n using namespace std; n const int N = 100005, M = 10000005; n int ls[M], rs[M], rt[N], n, a[N], m, ndc; n set<int> dat[N]; n long long sum[M]; n void update(int& x, int l, int r, int p, int u) { n   if (!x) x = ++ndc; n   sum[x] += u; n   if (l == r) return; n   int mid = (l + r) >> 1; n   if (p <= mid) n     update(ls[x], l, mid, p, u); n   else n     update(rs[x], mid + 1, r, p, u); n } n long long ask(int& x, int l, int r, int s, int t) { n   if (!x || l == s && r == t) return sum[x]; n   int mid = (l + r) >> 1; n   if (t <= mid) return ask(ls[x], l, mid, s, t); n   if (s > mid) return ask(rs[x], mid + 1, r, s, t); n   return ask(ls[x], l, mid, s, mid) + ask(rs[x], mid + 1, r, mid + 1, t); n } n void modify(int x, int y, int u) { n   while (x <= n) update(rt[x], 1, n, y, u), x += ((x) & -(x)); n } n long long query(int x, int y) { n   long long ret = 0; n   while (x) ret += ask(rt[x], 1, n, 1, y), x &= x - 1; n   return ret; n } n void add(int p, int x) { n   dat[p].insert(x); n   auto it = dat[p].find(x), pre = it, suf = it; n   bool f1 = false, f2 = false; n   if (pre != dat[p].begin()) --pre, modify(*pre, x, x - *pre), f1 = 1; n   ++suf; n   if (suf != dat[p].end()) modify(x, *suf, *suf - x), f2 = 1; n   if (f1 && f2) modify(*pre, *suf, -(*suf - *pre)); n } n void del(int p, int x) { n   auto it = dat[p].find(x), pre = it, suf = it; n   bool f1 = false, f2 = false; n   if (pre != dat[p].begin()) --pre, modify(*pre, x, -(x - *pre)), f1 = 1; n   ++suf; n   if (suf != dat[p].end()) modify(x, *suf, -(*suf - x)), f2 = 1; n   if (f1 && f2) modify(*pre, *suf, *suf - *pre); n   dat[p].erase(x); n } n int main() { n   io.rn(n); n   io.rn(m); n   for (int i = 1; i <= n; i++) add(a[i] = io.ri(), i); n   for (int i = 1, o, u, v; i <= m; i++) { n     io.rn(o); n     io.rn(u); n     io.rn(v); n     if (o == 1) n       del(a[u], u), a[u] = v, add(a[u], u); n     else { n       int t = n; n       while (t > 0 && (t & (t - 1)) >= v - 1) t &= (t - 1); n       io.oln(query(t, v) - query(u - 1, v)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MXN = 200; n const int MXK = 5; n int bans = -1; n int t[MXN][MXK]; n int a[MXK]; n int n; n int c[MXK]; n int cc[] = {500, 1000, 1500, 2000, 2500, 3000}; n int cat(int c, int n) { n   if (c * 2 > n) { n     return 0; n   } n   if (c * 4 > n && c * 2 <= n) { n     return 1; n   } n   if (c * 8 > n && c * 4 <= n) { n     return 2; n   } n   if (c * 16 > n && c * 8 <= n) { n     return 3; n   } n   if (c * 32 > n && c * 16 <= n) { n     return 4; n   } n   if (c * 32 <= n) { n     return 5; n   } n } n int calc(int i) { n   int res = 0; n   for (int j = (0); j < (MXK); j++) { n     if (t[i][j] != -1) res += cc[a[j]] - t[i][j] * cc[a[j]] / 250; n   } n   return res; n } n bool ok(int c, int n, int tt, int j) { n   return cat(c + tt * (t[0][j] != -1), n + tt) <= a[j] && n          cat(c, n + tt) >= a[j]; n } n int T; n void dfs(int i) { n   if (i == MXK) { n     int mn = 0; n     for (int j = (0); j < (MXK); j++) { n       if (!ok(c[j], n, T, j)) return; n     } n     if (calc(0) > calc(1)) { n       printf( %d , T); n       exit(0); n     } n     return; n   } n   for (int j = (0); j < (6); j++) { n     a[i] = j; n     dfs(i + 1); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = (0); i < (n); i++) { n     for (int j = (0); j < (5); j++) { n       scanf( %d , &t[i][j]); n       if (t[i][j] != -1) { n         c[j]++; n       } n     } n   } n   for (int i = (0); i < (n * 31 + 1); i++) { n     T = i; n     dfs(0); n   } n   cout << bans; n } n


#include <bits/stdc++.h> n using namespace std; n int n, l, r, id[1010][1010]; n bool tag[1010][1010]; n struct node { n   int x, y; n   pair<vector<node>, int> e() { n     vector<node> v; n     int c = 0; n     v.push_back((node){x + 1, y}); n     if (x > 0) n       v.push_back((node){x - 1, y}); n     else n       c++; n     if (x & 1) { n       if (x > 0) n         v.push_back((node){x - 1, y + 1}); n       else n         c++; n     } else { n       if (y > 0) n         v.push_back((node){x + 1, y - 1}); n       else n         c++; n     } n     return make_pair(v, c); n   } n } a[250010], q[2500010]; n vector<node> V; n void dfs(node x, node la) { n   if (tag[x.x][x.y]) { n     puts( SICK ), exit(0); n   } n   V.push_back(x), tag[x.x][x.y] = 1; n   vector<node> v = x.e().first; n   for (int j = 0, sz = v.size(); j < sz; j++) n     if (id[v[j].x][v[j].y] && (v[j].x != la.x || v[j].y != la.y)) { n       dfs(v[j], x); n     } n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i].x >> a[i].y; n     tag[a[i].x][a[i].y] = 1; n   } n   l = 1, r = n; n   for (int i = 1; i <= n; i++) q[i] = a[i]; n   while (l <= r) { n     id[q[l].x][q[l].y] = l; n     vector<node> u = q[l].e().first, v; n     for (int j = 0, sz = u.size(); j < sz; j++) { n       if (tag[u[j].x][u[j].y]) continue; n       v = u[j].e().first; n       for (int k = 0, Sz = v.size(); k < Sz; k++) n         if (id[v[k].x][v[k].y] && id[v[k].x][v[k].y] != l) { n           q[++r] = u[j], tag[u[j].x][u[j].y] = 1; n           break; n         } n     } n     l++; n   } n   int cnt = 0, ans = 0; n   memset(tag, 0, sizeof(tag)); n   for (int i = 1; i <= r; i++) n     if (!tag[q[i].x][q[i].y]) { n       V.clear(); n       cnt++; n       dfs(q[i], (node){-1, -1}); n       if (V.size() == 4) { n         int cc = 0; n         for (int j = 0; j < 4; j++) n           if (id[V[j].x][V[j].y] > n) { n             cc++; n             vector<node> v = V[j].e().first; n             if (v.size() == 3) { n               for (int k = 0; k < 4; k++) n                 if (k != j) { n                   bool tag = 0; n                   for (int l = 0; l < 3; l++) n                     if (V[k].x == v[l].x && V[k].y == v[l].y) tag = 1; n                   if (tag) cc -= 10; n                 } n             } n           } n         if (cc == -29) cnt++; n       } n     } n   for (int i = n + 1; i <= r; i++) id[q[i].x][q[i].y] = 0; n   for (int i = 1; i <= n; i++) { n     pair<vector<node>, int> v = q[i].e(); n     ans += v.second; n     for (int u, j = 0, sz = v.first.size(); j < sz; j++) n       if (!id[v.first[j].x][v.first[j].y]) { n         ans++; n       } n   } n   printf( RECOVERED n%d n , ans - 2 * cnt); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void print(T x) { n   cout << x << endl; n } n template <typename T1, typename T2> n void print2(T1 x, T2 y) { n   cout << x <<     << y << endl; n } n template <typename T1, typename T2, typename T3> n void print3(T1 x, T2 y, T3 z) { n   cout << x <<     << y <<     << z << endl; n } n void chandan1() { n   int y = 1; n   return; n } n void chandan2() { n   for (long long int i = 0; i < 10; i++) { n     long long int x = 1; n   } n   return (chandan1()); n } n vector<long long int> path; n void bfs(vector<long long int> adj[], long long int v, long long int source, n          long long int destin) { n   bool vis[v + 1]; n   long long int parent[v + 1]; n   for (long long int i = 0; i < v + 1; i++) { n     vis[i] = 0; n   } n   parent[source] = source; n   queue<long long int> q; n   q.push(source); n   vis[source] = 1; n   while (q.empty() == false) { n     long long int u = q.front(); n     q.pop(); n     for (auto xt : adj[u]) { n       if (vis[xt] == 0) { n         vis[xt] = 1; n         parent[xt] = u; n         q.push(xt); n       } n     } n   } n   vector<long long int> temp; n   while (parent[destin] != destin) { n     temp.emplace_back(destin); n     destin = parent[destin]; n   } n   reverse(temp.begin(), temp.end()); n   for (auto xt : temp) path.emplace_back(xt); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int t = 1; n   chandan2(); n   while (t--) { n     long long int v, e; n     cin >> v; n     vector<long long int> adj[v + 1]; n     for (long long int i = 0; i < v - 1; i++) { n       long long int a, b; n       cin >> a >> b; n       adj[a].emplace_back(b); n       adj[b].emplace_back(a); n     } n     vector<long long int> leaves; n     leaves.emplace_back(1); n     long long int val; n     while (cin >> val) { n       leaves.emplace_back(val); n     } n     leaves.emplace_back(1); n     path.emplace_back(1); n     for (long long int i = 0; i < int(leaves.size()) - 1; i++) { n       long long int src = leaves[i]; n       long long int desti = leaves[i + 1]; n       bfs(adj, v, src, desti); n     } n     if (int(path.size()) > (2 * v - 1)) n       print(-1); n     else { n       for (auto xt : path) cout << xt <<    ; n       cout <<   n ; n       ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int dp[10000]; n   for (int i = 0; i < n; i++) cin >> dp[i]; n   dp[1] = min(dp[1], dp[0]); n   for (int i = 2; i < n; i++) dp[i] = min(dp[i], max(dp[i - 1], dp[i - 2])); n   cout << dp[n - 1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T max(T a, T b, T c) { n   return max(a, max(b, c)); n } n template <class T> n T min(T a, T b, T c) { n   return min(a, min(b, c)); n } n const double PI = 2.0 * acos(0.0); n const int mx[] = {0, 1, 0, -1}; n const int my[] = {-1, 0, 1, 0}; n int check(long long s) { n   int res = 0; n   while (s > 0) res += s % 10, s /= 10; n   return res; n } n int main() { n   vector<int> ans; n   int a, b, c; n   ans.clear(); n   scanf( %d%d%d , &a, &b, &c); n   for (int i = 1; i <= 81; i++) { n     long long tmp = b; n     for (int j = 1; j <= a; j++) tmp *= i; n     tmp += c; n     if (tmp < 1e9 && check(tmp) == i) ans.push_back(tmp); n   } n   sort(ans.begin(), ans.end()); n   printf( %d n , ans.size()); n   for (int i = 0; i < ans.size(); i++) { n     if (i > 0) putchar(   ); n     printf( %d , ans[i]); n   } n   putchar(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n using ll = long long; n template <typename T> n void DEBUG(string label, T value) { n   cerr <<  [  << label <<   =   << value <<  ] n ; n } n map<string, int> encode; n map<int, string> decode; n int m, n; n vector<vector<int>> adj; n void solve() { n   cin >> m; n   n = 0; n   for (int i = 0; i < m; ++i) { n     string a, b; n     cin >> a >> b; n     if (encode.count(a) == 0) { n       encode[a] = n; n       decode[n] = a; n       n++; n     } n     if (encode.count(b) == 0) { n       encode[b] = n; n       decode[n] = b; n       n++; n     } n     while (adj.size() < n) { n       adj.push_back(vector<int>()); n     } n     adj[encode[a]].push_back(encode[b]); n     adj[encode[b]].push_back(encode[a]); n   } n   cout << n <<   n ; n   for (int i = 0; i < n; ++i) { n     vector<bool> vis(n); n     vis[i] = true; n     for (int nxt : adj[i]) { n       vis[nxt] = true; n     } n     vector<int> cnt(n); n     for (int nxt : adj[i]) { n       for (int k : adj[nxt]) { n         if (!vis[k]) { n           cnt[k]++; n         } n       } n     } n     int mx = *max_element(cnt.begin(), cnt.end()); n     int ans = 0; n     for (int j = 0; j < n; ++j) { n       ans += (!vis[j] && cnt[j] == mx); n     } n     cout << decode[i] <<     << ans <<   n ; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int t; n   t = 1; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int p[201], bag[201]; n int n, l, k; n double mem[202][202][202]; n double solve(int r, int bagwon, int prizewon) { n   if (mem[r][bagwon][prizewon] >= -.5) return mem[r][bagwon][prizewon]; n   if (r == n) n     return mem[r][bagwon][prizewon] = n                bagwon + k >= prizewon && prizewon >= l ? 1 : 0; n   if (bag[r] == -1) n     return mem[r][bagwon][prizewon] = n                double(p[r] * solve(r + 1, bagwon, prizewon + 1) + n                       (100 - p[r]) * solve(r + 1, bagwon, prizewon)) / n                100; n   else n     return mem[r][bagwon][prizewon] = n                double(p[r] * solve(r + 1, min(200, bagwon + bag[r] + 1), n                                    prizewon + 1) + n                       (100 - p[r]) * solve(r + 1, bagwon, prizewon)) / n                100; n } n int main() { n   memset(mem, -1, sizeof mem); n   cin >> n >> l >> k; n   for (int i = 0; i < n; i++) cin >> p[i]; n   for (int i = 0; i < n; i++) cin >> bag[i]; n   cout.precision(100); n   cout << fixed << solve(0, 0, 0) << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const long long int mod = 1e9 + 7; n vector<string> v(100005); n long long int n, m; n long long int check(string s, string str) { n   long long int count = 0; n   for (long long int i = 0; i < s.size(); i++) { n     if (str[i] != s[i]) count++; n   } n   return count; n } n bool ok(string s) { n   for (long long int i = 0; i < n; i++) { n     long long int x = check(s, v[i]); n     if (x > 1) return false; n   } n   return true; n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int t; n   cin >> t; n   while (t--) { n     cin >> n >> m; n     string ans =  -1 ; n     for (long long int i = 0; i < n; i++) { n       cin >> v[i]; n     } n     for (long long int i = 0; i < n; i++) { n       for (long long int j = 0; j < v[i].size(); j++) { n         for (char k =  a ; k <=  z ; k++) { n           string str = v[i]; n           str[j] = k; n           if (ok(str)) { n             ans = str; n           } n         } n       } n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, d; n   cin >> a >> b >> c >> d; n   printf( %d , ((a ^ b) & (c | d)) ^ ((b & c) | (a ^ d))); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const int maxn = 1010; n int Dp[maxn][maxn], dp[maxn][maxn], f[maxn][maxn], g[maxn][maxn]; n int a[maxn][maxn]; n int n, m; n int main() { n   while (~scanf( %d%d , &n, &m)) { n     for (int i = 1; i <= n; ++i) n       for (int j = 1; j <= m; ++j) scanf( %d , &a[i][j]); n     memset(Dp, 0, sizeof(Dp)); n     memset(dp, 0, sizeof(dp)); n     memset(f, 0, sizeof(f)); n     memset(g, 0, sizeof(g)); n     for (int i = 1; i <= n; ++i) n       for (int j = 1; j <= m; ++j) n         dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + a[i][j]; n     for (int i = n; i >= 1; --i) n       for (int j = m; j >= 1; --j) n         Dp[i][j] = max(Dp[i + 1][j], Dp[i][j + 1]) + a[i][j]; n     for (int i = n; i >= 1; --i) n       for (int j = 1; j <= m; ++j) n         f[i][j] = max(f[i + 1][j], f[i][j - 1]) + a[i][j]; n     for (int i = 1; i <= n; ++i) n       for (int j = m; j >= 1; --j) n         g[i][j] = max(g[i - 1][j], g[i][j + 1]) + a[i][j]; n     int Ans = 0; n     for (int i = 2; i < n; ++i) n       for (int j = 2; j < m; ++j) n         Ans = max(Ans, n                   max(dp[i - 1][j] + Dp[i + 1][j] + f[i][j - 1] + g[i][j + 1], n                       dp[i][j - 1] + Dp[i][j + 1] + f[i + 1][j] + g[i - 1][j])); n     printf( %d n , Ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n string s; n int n, m, t, x, g; n int f[100005]; n string b[15]; n int l[15]; n int main() { n   cin >> s; n   n = s.length(); n   scanf( %d n , &m); n   for (int i = 0; i < m; i++) { n     cin >> b[i]; n     l[i] = b[i].length(); n     scanf(  n ); n   } n   f[0] = 0; n   for (int i = 0; i < n; i++) { n     x = f[i] + 1; n     t = 0; n     for (int j = 0; j < m; j++) n       if (l[j] <= x) { n         g = 1; n         for (int w = 0; w < l[j]; w++) n           if (b[j][w] != s[i - l[j] + 1 + w]) { n             g = 0; n             break; n           } n         t = g; n         if (t) break; n       } n     if (!t) { n       f[i + 1] = x; n       continue; n     } n     x = i + 1; n     t = 1000; n     for (int j = 0; j < m; j++) n       if (l[j] <= x) { n         g = 1; n         for (int w = 0; w < l[j]; w++) n           if (b[j][w] != s[i - l[j] + 1 + w]) { n             g = 0; n             break; n           } n         if (g) { n           if (l[j] < t) t = l[j]; n         } n       } n     f[i + 1] = t - 1; n   } n   t = 0; n   x = -1; n   for (int i = 1; i <= n; i++) n     if (f[i] > t) { n       t = f[i]; n       x = i - 1; n     } n   printf( %d %d n , t, x - t + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int N, M, k; n   string in; n   list<string> ret; n   cin >> N >> M; n   cin >> in >> k; n   if (k == 0) { n     for (int i = 0; i < N; i++) in[i] = ((in[i] -  0 ) ^ 1) +  0 ; n     ret.push_back(in); n   } else { n     long long s = (1LL << k) - 1; n     while (!(s & 1LL << N)) { n       string c = in; n       for (int i = 0; i < N; i++) n         if (!(s & (1LL << i))) c[i] = ((c[i] -  0 ) ^ 1) +  0 ; n       ret.push_back(c); n       long long lo = s & ~(s - 1); n       long long lz = (s + lo) & ~s; n       s |= lz; n       s &= ~(lz - 1); n       s |= (lz / lo / 2) - 1; n     } n   } n   for (int i = 1; i < M; i++) { n     cin >> in >> k; n     list<string>::iterator it = ret.begin(); n     while (it != ret.end()) { n       int c = 0; n       for (int j = 0; j < N; j++) n         if ((*it)[j] == in[j]) c++; n       if (c != k) n         it = ret.erase(it); n       else n         it++; n     } n   } n   cout << ret.size(); n   return 0; n } n


#include <bits/stdc++.h> n const double eps = (1e-9); n using namespace std; n int dcmp(long double a, long double b) { n   return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1; n } n int getBit(long long num, int idx) { return ((num >> idx) & 1ll) == 1; } n int setBit1(int num, int idx) { return num | (1 << idx); } n long long setBit0(long long num, int idx) { return num & ~(1ll << idx); } n long long flipBit(long long num, int idx) { return num ^ (1ll << idx); } n void M() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n int countNumBit1(int mask) { n   int ret = 0; n   while (mask) { n     mask &= (mask - 1); n     ++ret; n   } n   return ret; n } n string st; n int n; n int main() { n   M(); n   cin >> n >> st; n   char c1, c2, c3, F, S, T; n   int mi = INT_MAX; n   for (int i = 1; i <= 3; i++) { n     for (int j = 1; j <= 3; j++) { n       for (int k = 1; k <= 3; k++) { n         int cnt1 = 0, cnt2 = 0, cnt3 = 0; n         if (i == j || i == k || j == k) continue; n         c1 = (i == 1 ?  R  : (i == 2 ?  B  :  G )); n         c2 = (j == 1 ?  R  : (j == 2 ?  B  :  G )); n         c3 = (k == 1 ?  R  : (k == 2 ?  B  :  G )); n         for (int l = 0; l < n; l += 3) { n           if (st[l] != c1) cnt1++; n         } n         for (int l = 1; l < n; l += 3) { n           if (st[l] != c2) cnt2++; n         } n         for (int l = 2; l < n; l += 3) { n           if (st[l] != c3) cnt3++; n         } n         long long ans = cnt1 + cnt2 + cnt3; n         if (ans < mi) { n           mi = ans; n           F = c1; n           S = c2; n           T = c3; n         } n       } n     } n   } n   for (int l = 0; l < n; l += 3) { n     st[l] = F; n   } n   for (int l = 1; l < n; l += 3) { n     st[l] = S; n   } n   for (int l = 2; l < n; l += 3) { n     st[l] = T; n   } n   cout << mi << endl << st << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 520, M = 512; n int f[N], g[N]; n int a[int(1e6)]; n int n; n int main() { n   scanf( %d , &n); n   for (register int i = 1; i <= n; ++i) scanf( %d , a + i); n   for (register int i = 1; i < M; ++i) f[i] = 1e9; n   f[0] = -1; n   for (register int i = 1; i <= n; ++i) { n     for (register int k = 0; k < M; ++k) { n       g[k] = f[k]; n       if (f[k xor a[i]] < a[i]) g[k] = min(f[k], a[i]); n     } n     swap(f, g); n   } n   int cnt = 0; n   for (register int i = 0; i < M; ++i) n     if (f[i] != int(1e9)) ++cnt; n   printf( %d n , cnt); n   for (register int i = 0; i < M; ++i) n     if (f[i] != int(1e9)) printf( %d  , i); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 10; n int m, n, q, x; n int ans; n int a[N], b[N]; n char s[N], p[N], t[N]; n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     int pt1, pt2; n     pt1 = pt2 = 0; n     memset(a, 0, sizeof(a)); n     memset(b, 0, sizeof(b)); n     cin >> s >> t >> p; n     int f = 0; n     int lens = strlen(s); n     int lenp = strlen(p); n     int lent = strlen(t); n     for (pt2 = 0; pt2 < lent; pt2++) { n       if (s[pt1] == t[pt2]) { n         pt1++; n       } else n         b[t[pt2] -  a ]++; n     } n     if (pt1 < lens) { n       cout <<  NO  << endl; n       continue; n     } n     for (int i = 0; i < lenp; i++) a[p[i] -  a ]++; n     for (int i = 0; i < 26; i++) { n       if (b[i] > a[i]) { n         f = 1; n         cout <<  NO  << endl; n         break; n       } n     } n     if (f == 0) cout <<  YES  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long getnum() { n   char c = getchar(); n   long long num, sign = 1; n   for (; c <  0  || c >  9 ; c = getchar()) n     if (c ==  - ) sign = -1; n   for (num = 0; c >=  0  && c <=  9 ;) { n     c -=  0 ; n     num = num * 10 + c; n     c = getchar(); n   } n   return num * sign; n } n int A[540][540][12]; n int main() { n   int n = getnum(); n   A[1][1][0] = 1; n   for (int i = 1; i <= 9; i++) { n     int l = 1 << i; n     int fx = l, fy = 1; n     int sx = l, sy = l; n     int tx = 1, ty = l; n     l /= 2; n     for (int j = 1; j <= l; j++) { n       for (int k = 1; k <= l; k++) { n         A[j][k][i] = A[j][k][i - 1]; n         A[fx][fy][i] = A[j][k][i - 1]; n         A[sx][sy][i] = A[j][k][i - 1]; n         A[tx][ty][i] = 1 - A[j][k][i - 1]; n         fy++, sy--, ty--; n       } n       fx--, sx--, tx++; n       fy = 1, sy = l * 2, ty = l * 2; n     } n   } n   int l = 1 << n; n   for (int i = 1; i <= l; i++) { n     for (int j = 1; j <= l; j++) { n       if (A[i][j][n]) n         putchar( + ); n       else n         putchar( * ); n     } n     putchar(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long a[100005], n, cont[100005]; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i], cont[50 + a[i]]++; n   long long res = 0; n   for (int i = 0; i <= 10; i++) { n     if (i == 0) { n       long long x = cont[50]; n       res += (x * (x - 1)) / 2; n     } else { n       res += cont[50 + i] * cont[50 - i]; n     } n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int S, l[100], r[100], N, w[200]; n double a[100], b[100], f[100][100], ans[100]; n void init() { n   scanf( %d , &N); n   for (int i = 1; i <= N; i++) n     scanf( %d%d , &l[i], &r[i]), w[++S] = l[i], w[++S] = r[i]; n } n void calc(int p, int L, int R) { n   int t = 0, bg = 0; n   memset(f, 0, sizeof(f)), f[0][0] = 1.0 * (R - L) / (r[p] - l[p]); n   for (int i = 1; i <= N; i++) n     if (i != p) { n       double s = r[i] - l[i], x, y; n       if (r[i] <= L) { n         bg++; n         continue; n       } else if (R <= l[i]) n         continue; n       else n         x = (L - l[i]) / s, y = (R - L) / s; n       t++; n       for (int j = t; j >= 0; j--) n         for (int k = t - j; k >= 0; k--) { n           f[j][k] *= 1 - x - y; n           if (j) f[j][k] += f[j - 1][k] * x; n           if (k) f[j][k] += f[j][k - 1] * y; n         } n     } n   for (int i = 0; i + bg < N; i++) n     for (int j = 0; i + bg + j < N; j++) n       ans[i + bg + 1] += f[i][j] / (j + 1), n           ans[i + bg + j + 2] -= f[i][j] / (j + 1); n } n void doit() { n   sort(w + 1, w + S + 1); n   for (int i = 1; i <= N; i++) { n     memset(ans, 0, sizeof(ans)); n     for (int j = 1; j <= S; j++) n       if ((j == 1 || w[j] != w[j - 1]) && l[i] <= w[j - 1] && w[j] <= r[i]) n         calc(i, w[j - 1], w[j]); n     for (int j = 1; j <= N; j++) n       printf( %.9lf%c , ans[j] += ans[j - 1], j == N ?   n  :    ); n   } n } n int main() { n   init(); n   doit(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   int m; n   cin >> n >> m; n   long long cnt = 0; n   if (m == 1) { n     cout << n * n << endl; n     return 0; n   } n   if (m < n) { n     for (int i = 1; i <= m; i++) n       for (int j = 1; j <= m; j++) n         if ((i * i + j * j) % m == 0) cnt++; n     long long mul = n / m; n     mul = mul * mul; n     cnt *= mul; n     long long index = (n / m) * m; n     index++; n     if (index <= n) { n       long long cnt1 = 0; n       for (long long i = index; i <= n; i++) n         for (long long j = 1; j <= m; j++) { n           long long i1 = i % m; n           long long j1 = j % m; n           if ((i1 * i1 + j1 * j1) % m == 0) cnt1++; n         } n       mul = n / m; n       mul *= 2; n       cnt1 *= mul; n       cnt += cnt1; n       for (long long i = index; i <= n; i++) n         for (long long j = index; j <= n; j++) { n           long long i1 = i % m; n           long long j1 = j % m; n           if ((i1 * i1 + j1 * j1) % m == 0) cnt++; n         } n     } n   } else { n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= n; j++) n         if ((i * i + j * j) % m == 0) cnt++; n   } n   cout << cnt << endl; n   return 0; n } n


#include <bits/stdc++.h> n const long double eps = 1e-10; n const int MOD = 1000000007; n using namespace std; n int a[200005], K, n; n int main() { n   scanf( %d %d , &n, &K); n   for (int i = 0; i < n; ++i) scanf( %d , a + i); n   sort(a, a + n); n   int ret = 0; n   for (int i = 0; i < n - 1; ++i) { n     int b = a[i] + K; n     int low = i + 1, high = n; n     while (low <= high) { n       int mid = (low + high) >> 1; n       if (a[mid] == a[i]) { n         low = mid + 1; n         continue; n       } n       if (a[mid] > a[i] && a[mid] <= b) { n         ++ret; n         break; n       } else { n         high = mid - 1; n       } n     } n   } n   printf( %d n , n - ret); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 501; n int n, vis[maxn][maxn], a[maxn][maxn], x, y, s, cnt; n char p[3000010]; n int d[4][2] = {0, 1, 1, 0, -1, 0, 0, -1}; n bool J(int x, int y, int i) { n   while (true) { n     x += d[i][0]; n     y += d[i][1]; n     if (!x || !y || x > n || y > n) return 0; n     if (vis[x][y]) return 0; n     if (a[x][y]) return 1; n   } n } n void dfs(int x, int y) { n   if (!a[x][y]) p[cnt++] =  1 , s++; n   vis[x][y] = 1; n   for (int i = 0; i < 4; i++) n     if (J(x, y, i)) { n       p[cnt++] = (!i ?  R  : i == 1 ?  D  : i == 2 ?  U  :  L ); n       dfs(x + d[i][0], y + d[i][1]); n       p[cnt++] = (!i ?  L  : i == 1 ?  U  : i == 2 ?  D  :  R ); n     } n   p[cnt++] =  2 , s--; n } n int main() { n   scanf( %d%d%d , &n, &x, &y); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) scanf( %d , &a[i][j]), s += a[i][j]; n   dfs(x, y); n   p[cnt++] = 0; n   if (s) n     printf( NO n ); n   else n     printf( YES n%s n , p); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long fact_a[1000005]; n long long factorial() { n   fact_a[0] = fact_a[1] = 1; n   for (long long i = 2; i < 1000005; i++) fact_a[i] = (fact_a[i - 1] * i); n } n long long power(long long x, long long n) { n   long long result = 1; n   while (n > 0) { n     if (n % 2 == 1) result = result * x; n     x = x * x; n     n = n / 2; n   } n   return result; n } n long long nCr(long long n, long long r) { n   if (n < r) return 0LL; n   if (n == r) return 1LL; n   long long ans = fact_a[n]; n   ans = (ans * power(fact_a[r], 1000000007 - 2)) % 1000000007; n   ans = (ans * power(fact_a[n - r], 1000000007 - 2)) % 1000000007; n   return ans; n } n long long prime[1000005]; n void sieve() { n   prime[1000005] = {0}; n   for (long long i = 2; i < 1000005; i++) { n     if (prime[i] == 0) { n       for (long long j = i * i; j < 1000005; j += i) { n         prime[j] = 1; n       } n     } n   } n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long tc; n   cin >> tc; n   while (tc--) { n     long long n, k; n     cin >> n; n     long long a[n]; n     set<long long> s; n     for (long long i = 0; i < n; i++) { n       cin >> a[i]; n       s.insert(a[i]); n     } n     if (s.size() == 1) n       cout << n <<   n ; n     else n       cout << 1 <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   string s, t; n   cin >> s; n   size_t a, b, c, d, n; n   n = s.length(); n   t.reserve(n); n   a = s.find( 0 ); n   b = s.find( 1 ); n   c = s.find( 2 ); n   d = c; n   for (size_t i = 0; i < n; i++) { n     if (a < d) { n       t +=  0 ; n       a = s.find( 0 , a + 1); n     } else if (b < n) { n       t +=  1 ; n       b = s.find( 1 , b + 1); n     } else { n       if (a < c) { n         t +=  0 ; n         a = s.find( 0 , a + 1); n       } else { n         t +=  2 ; n         c = s.find( 2 , c + 1); n       } n     } n   } n   cout << t; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n; n   long long a[2]; n   cin >> a[0] >> a[1]; n   sort(a, a + 2); n   n = 2 * a[0]; n   if (n < a[1]) { n     n = a[1]; n   } n   n *= n; n   cout << n << endl; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #define rep(i, n) for(int i = 0; i < n; i++) n #define rep2(i, x, n) for(int i = x; i <= n; i++) n #define rep3(i, x, n) for(int i = x; i >= n; i--) n #define each(e, v) for(auto &e: v) n #define pb push_back n #define eb emplace_back n #define all(x) x.begin(), x.end() n #define rall(x) x.rbegin(), x.rend() n #define sz(x) (int)x.size() n using ll = long long; n using pii = pair<int, int>; n using pil = pair<int, ll>; n using pli = pair<ll, int>; n using pll = pair<ll, ll>; n const int MOD = 1000000007; n //const int MOD = 998244353; n const int inf = (1<<30)-1; n const ll INF = (1LL<<60)-1; n template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; n template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; n  n struct io_setup{ n     io_setup(){ n         ios_base::sync_with_stdio(false); n         cin.tie(NULL); n         cout << fixed << setprecision(15); n     } n } io_setup; n  n template<typename T, typename Operator_Monoid> n struct Dual_Segment_Tree{ n     using G = function<T(T, Operator_Monoid)>; n     using H = function<Operator_Monoid(Operator_Monoid, Operator_Monoid)>; n     int n, height; n     vector<T> seg; n     vector<Operator_Monoid> lazy; n     const G g; n     const H h; n     const Operator_Monoid e2; n  n     Dual_Segment_Tree(const vector<T> &v, const G &g, const H &h, const Operator_Monoid &e2) : g(g), h(h), e2(e2){ n         int m = sz(v); n         n = 1, height = 0; n         while(n < m) n <<= 1, height++; n         lazy.assign(2*n, e2); n         seg = v; n     } n  n     inline void eval(int i){ n         if(i < n && lazy[i] != e2){ n             lazy[2*i] = h(lazy[2*i], lazy[i]); n             lazy[2*i+1] = h(lazy[2*i+1], lazy[i]); n             lazy[i] = e2; n         } n     } n  n     inline void thrust(int i){ n         for(int j = height; j > 0; j--) eval(i>>j); n     } n  n     void apply(int l, int r, const Operator_Monoid &x){ n         chmax(l, 0), chmin(r, n); n         if(l >= r) return; n         l += n, r += n; n         thrust(l), thrust(r-1); n         while(l < r){ n             if(l&1) lazy[l] = h(lazy[l], x), l++; n             if(r&1) r--, lazy[r] = h(lazy[r], x); n             l >>= 1, r >>= 1; n         } n     } n  n     T get(int i){ n         thrust(i+n); n         return g(seg[i], lazy[i+n]); n     } n  n     T operator [] (int i) {return get(i);} n }; n  n int main(){ n     int T; n     cin >> T; n     while(T--){ n         int N; n         cin >> N; n         vector<int> a(N); n         rep(i, N) cin >> a[i]; n         vector<vector<int>> dp(N, vector<int>(N+1, inf)); n         vector<vector<int>> M(N, vector<int>(N+2, inf)); n         rep(i, N+1) M[N-1][i] = 0; n  n         auto f = [](int a, int b) {return a+b;}; n         Dual_Segment_Tree<int, int> seg(vector<int>(N+1, 0), f, f, 0); n  n         dp[N-1][N] = 0; n         rep3(i, N-2, 0){ n             rep2(j, i+1, i+a[i]){ n                 if(j >= N) break; n                 chmin(dp[i][j], M[j][min(N, i+a[i]+1)]+seg[j]); n             } n             seg.apply(i+1, min(N, i+a[i]+1), 1); n             rep3(j, N, 0) M[i][j] = min(M[i][j+1], dp[i][j]); n         } n  n         int ans = inf; n         rep(i, N+1) chmin(ans, dp[0][i]); n         cout << ans <<   n ; n     } n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j; n   char a[100010]; n   scanf( %s , &a); n   int n = strlen(a); n   int b = 10 * (a[n - 2] -  0 ) + (a[n - 1] -  0 ); n   if (b % 4 == 0) n     cout <<  4 ; n   else n     cout <<  0 ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /stack:256000000 ) n using namespace std; n int main() { n   int n; n   cin >> n; n   if (n % 2 == 0) { n     puts( -1 ); n   } else { n     for (int(i) = 0; (i) < (n); (i)++) printf( %d  , i); n     printf(  n ); n     for (int(i) = 0; (i) < (n); (i)++) printf( %d  , i); n     printf(  n ); n     for (int(i) = 0; (i) < (n); (i)++) printf( %d  , 2 * i % n); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n long long max(long long a, long long b) { return a > b ? a : b; } n long long min(long long a, long long b) { return a < b ? a : b; } n void swap(long long &a, long long &b) { n   long long tmp = a; n   a = b; n   b = tmp; n } n long long lowbit(long long &x) { return x & (-x); } n void read(long long &x) { n   x = 0; n   char ch = getchar(), c = ch; n   while (ch <  0  || ch >  9 ) c = ch, ch = getchar(); n   while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = getchar(); n   if (c ==  - ) x = -x; n } n const long long INF = 0x3f3f3f3f3f3f3f3f; n const long long MAXN = 300000 + 10; n const long long MAXM = 10; n long long dp[MAXN][MAXM + 10], n, m, k, a[MAXN]; n int main() { n   read(n), read(m), read(k); n   long long ans = 0; n   for (long long i = 1; i <= n; ++i) read(a[i]); n   for (int i = 0; i <= n; ++i) n     for (int j = 0; j < m; ++j) dp[i][j] = -INF; n   dp[0][m - 1] = 0; n   for (long long i = 1; i <= n; ++i) n     for (long long j = 0; j < m; ++j) { n       if (j == 0) n         dp[i][j] = max(dp[i - 1][m - 1] + a[i], a[i]) - k; n       else n         dp[i][j] = dp[i - 1][j - 1] + a[i]; n       ans = max(ans, dp[i][j]); n     } n   printf( %I64d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline bool getmin(T *a, const T &b) { n   if (b < *a) { n     *a = b; n     return true; n   } n   return false; n } n template <class T> n inline bool getmax(T *a, const T &b) { n   if (b > *a) { n     *a = b; n     return true; n   } n   return false; n } n template <class T> n inline void read(T *a) { n   char c; n   while (isspace(c = getchar())) { n   } n   bool flag = 0; n   if (c ==  - ) n     flag = 1, *a = 0; n   else n     *a = c - 48; n   while (isdigit(c = getchar())) *a = *a * 10 + c - 48; n   if (flag) *a = -*a; n } n const int mo = 1000000007; n template <class T> n T pow(T a, T b, int c = mo) { n   T res = 1; n   for (T i = 1; i <= b; i <<= 1, a = 1LL * a * a % c) n     if (b & i) res = 1LL * res * a % c; n   return res; n } n const int inf = 1000000000; n const int N = 210000; n struct node { n   int p, nextt, w; n } edge[N]; n int cnt; n int head[N]; n void ae(int a, int b, int c) { n   edge[++cnt].p = b; n   edge[cnt].nextt = head[a]; n   edge[cnt].w = c; n   head[a] = cnt; n } n queue<int> q; n int d[N], tmp[N]; n int n, m; n int bfs(int u) { n   static vector<int> v; n   v.clear(); n   d[u] = 0; n   while (!q.empty()) q.pop(); n   q.push(u); n   int ans = 0, num = 0; n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     ans += d[u]; n     v.push_back(u); n     ++num; n     for (int k = head[(u)]; k; k = edge[k].nextt) { n       int v = edge[k].p; n       if (d[v] != -1 && (d[u] ^ d[v]) != edge[k].w) n         return inf; n       else if (d[v] == -1) { n         d[v] = (d[u] ^ edge[k].w); n         q.push(v); n       } n     } n   } n   for (int i = (0); i <= (num - 1); ++i) n     if (num - ans < ans) d[v[i]] ^= 1; n   return min(ans, num - ans); n } n int solve() { n   for (int i = (1); i <= (n); ++i) d[i] = -1; n   int ans = 0; n   for (int i = (1); i <= (n); ++i) n     if (d[i] == -1) { n       int x = bfs(i); n       if (x == inf) n         return inf; n       else n         ans += x; n     } n   return ans; n } n int main() { n   cin >> n >> m; n   for (int i = (1); i <= (m); ++i) { n     int x, y; n     string s; n     cin >> x >> y >> s; n     int z = 0; n     if (s ==  R ) z = 1; n     ae(x, y, z); n     ae(y, x, z); n   } n   int ans = solve(); n   for (int i = (1); i <= (n); ++i) tmp[i] = d[i]; n   for (int i = (1); i <= (n); ++i) n     for (int k = head[(i)]; k; k = edge[k].nextt) edge[k].w ^= 1; n   int x = solve(); n   if (x < ans) { n     ans = x; n     for (int i = (1); i <= (n); ++i) tmp[i] = d[i]; n   } n   if (ans == inf) { n     cout << -1 << endl; n   } else { n     cout << ans << endl; n     for (int i = (1); i <= (n); ++i) n       if (tmp[i]) printf( %d  , i); n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100], n, m, x, h, ans, l, r; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x; n     a[x]++; n   } n   for (int i = 1; i <= 50; i++) { n     if (a[i] == 0) continue; n     if (a[i] > n / 2) { n       cout <<  Bob ; n       return 0; n     } n     break; n   } n   cout <<  Alice ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9; n const int maxn = 2e5 + 10; n int N, K; n int L[105], R[105]; n struct min_segtree { n   int tree[maxn * 3]; n   void init() { n     for (int i = 0; i <= 2 * 2 * N + 2048; ++i) tree[i] = INF; n   } n   void update(int l, int r, int pos, int id, int val) { n     if (l > r || pos < l || pos > r) return; n     if (l == pos && pos == r) { n       tree[id] = val; n       return; n     } n     int mid = (l + r) >> 1; n     if (pos <= mid) n       update(l, mid, pos, id << 1, val); n     else n       update(mid + 1, r, pos, id << 1 | 1, val); n     tree[id] = min(tree[id << 1], tree[id << 1 | 1]); n   } n   int query(int l, int r, int x, int y, int id) { n     if (l > r || x > y || r < x || l > y) return INF; n     if (l <= x && y <= r) return tree[id]; n     int mid = (x + y) >> 1; n     if (r <= mid) return query(l, r, x, mid, id << 1); n     if (l > mid) return query(l, r, mid + 1, y, id << 1 | 1); n     return min(query(l, r, x, mid, id << 1), n                query(l, r, mid + 1, y, id << 1 | 1)); n   } n } DP[105]; n int main() { n   scanf( %d %d , &N, &K); n   int i, j, lim = 2 * N; n   for (i = 1; i <= K; ++i) scanf( %d %d , &L[i], &R[i]); n   for (i = 0; i <= K; ++i) { n     DP[i].init(); n   } n   DP[0].update(0, lim, 0, 1, 0); n   for (i = 1; i <= K; ++i) { n     for (j = 0; j <= lim && j <= R[i]; ++j) { n       int zero = (j - R[i] + R[i - 1] >= 0) n                      ? DP[i - 1].query(j - R[i] + R[i - 1], j - R[i] + R[i - 1], n                                        0, lim, 1) n                      : INF; n       int one = n           1 + DP[i - 1].query(max(0, R[i - 1] - j), n                               min(lim, R[i - 1] - j + R[i] - L[i]), 0, lim, 1); n       int two = 2 + DP[i - 1].query(max(0, j - R[i] + R[i - 1]), n                                     min(lim, j - R[i] + R[i - 1] + R[i] - L[i]), n                                     0, lim, 1); n       DP[i].update(0, lim, j, 1, min(zero, min(one, two))); n     } n   } n   if (R[K] - N < 0 || DP[K].query(R[K] - N, R[K] - N, 0, lim, 1) >= INF) { n     printf( Hungry n ); n   } else { n     printf( Full n%d n , DP[K].query(R[K] - N, R[K] - N, 0, lim, 1)); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long double pi = acos(-1); n const int N = 2e5; n long long gi() { n   long long w = 0; n   bool q = 1; n   char c = getchar(); n   while ((c <  0  || c >  9 ) && c !=  - ) c = getchar(); n   if (c ==  - ) q = 0, c = getchar(); n   while (c >=  0  && c <=  9 ) w = w * 10 + c -  0 , c = getchar(); n   return q ? w : -w; n } n int main() { n   long long n = gi(), m = gi(), a = gi(), d = gi(), last = 0, k, x, y, ans = 0, n             u = d / a + 1; n   while (m--) { n     k = gi(); n     x = max(last / a + 1, 1LL); n     y = min(k / a, n); n     if (x <= y) { n       ans += (y - x) / u + 1; n       last = (x + (y - x) / u * u) * a + d; n     } n     if (last < k) last = k + d, ans++; n   } n   x = max(last / a + 1, 1LL); n   if (x <= n) ans += (n - x) / u + 1; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class P, class Q> n inline bool mmin(P &a, Q b) { n   if (a > b) { n     a = b; n     return true; n   } n   return false; n } n template <class P, class Q> n inline bool mmax(P &a, Q b) { n   if (a < b) { n     a = b; n     return true; n   } n   return false; n } n const int MAXn = 400 + 5, INF = 1000; n int n; n vector<pair<int, int> > adj[MAXn]; n vector<int> son[MAXn]; n int par[MAXn], siz[MAXn]; n int dp[MAXn][MAXn]; n int cur[MAXn][MAXn], upd[MAXn][MAXn]; n bool mark[MAXn]; n int nxt[MAXn]; n inline void calcDP(int x) { n   int m = ((int)son[x].size()); n   cur[m][0] = 0; n   for (int j = 1; j < siz[x]; ++j) cur[m][j] = INF; n   int s = 0; n   for (int i = m - 1; i >= 0; --i) { n     s += siz[son[x][i]]; n     for (int j = 0; j <= s; ++j) { n       cur[i][j] = INF; n       for (int k = 0; k <= j && k <= siz[son[x][i]]; ++k) n         if (j - k <= s - siz[son[x][i]] && n             mmin(cur[i][j], cur[i + 1][j - k] + dp[son[x][i]][k])) n           upd[i][j] = k; n     } n   } n } n void DFS(int x) { n   siz[x] = 1; n   for (int i = 0; i < ((int)adj[x].size()); ++i) { n     int y = adj[x][i].first; n     if (y != par[x]) { n       son[x].push_back(y); n       par[y] = x; n       DFS(y); n       siz[x] += siz[y]; n     } n   } n   calcDP(x); n   dp[x][0] = 1; n   for (int j = 1; j <= siz[x]; ++j) dp[x][j] = cur[0][j - 1]; n } n void DFS2(int x, int k) { n   if (!k) return; n   mark[x] = 1; n   if (k == 1) return; n   calcDP(x); n   int y = k - 1; n   for (int i = 0; i < ((int)son[x].size()); ++i) { n     nxt[son[x][i]] = upd[i][y]; n     y -= upd[i][y]; n   } n   y = k - 1; n   for (int i = 0; i < ((int)son[x].size()); ++i) { n     DFS2(son[x][i], nxt[son[x][i]]); n     y -= nxt[son[x][i]]; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   int k; n   cin >> n >> k; n   for (int i = 0; i < n - 1; ++i) { n     int x, y; n     cin >> x >> y; n     --x; n     --y; n     adj[x].push_back(pair<int, int>(y, i + 1)); n     adj[y].push_back(pair<int, int>(x, i + 1)); n   } n   fill(dp[0], dp[n], INF); n   DFS(0); n   int mn = dp[0][k], ind = 0; n   for (int i = 1; i < n; ++i) n     if (mmin(mn, dp[i][k] + 1)) ind = i; n   DFS2(ind, k); n   vector<int> v; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < ((int)adj[i].size()); ++j) n       if (adj[i][j].first > i && (mark[i] ^ mark[adj[i][j].first])) n         v.push_back(adj[i][j].second); n   cout << ((int)v.size()) << endl; n   for (int i = 0; i < ((int)v.size()); ++i) cout << v[i] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, y, z, q, w, e; n   cin >> x >> y >> z >> q >> w >> e; n   int leg = 0; n   int el = 0; n   leg = abs(x - y) * q; n   el = 3 * e + abs(x - z) * w + abs(y - x) * w; n   if (el <= leg) { n     cout <<  YES ; n   } else { n     cout <<  NO ; n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const long long linf = 0x3f3f3f3fLL; n int main() { n   int n; n   scanf( %d , &n); n   if (n < 10) n     puts( 1 ); n   else { n     int aux = n; n     while (aux >= 10) { n       aux /= 10; n     } n     int num = aux + 1; n     aux = n; n     while (aux >= 10) { n       aux /= 10; n       num *= 10; n     } n     printf( %d n , num - n); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void checkmax(T &t, T x) { n   if (x > t) t = x; n } n template <class T> n void checkmin(T &t, T x) { n   if (x < t) t = x; n } n template <class T> n void _checkmax(T &t, T x) { n   if (t == -1 || x > t) t = x; n } n template <class T> n void _checkmin(T &t, T x) { n   if (t == -1 || x < t) t = x; n } n int main() { n   int n, num, flag; n   double dou, sum, sub; n   while (cin >> n) { n     sum = num = flag = 0; n     for (int i = 0; i < (2 * n); ++i) { n       scanf( %lf , &dou); n       sub = ceil(dou) - dou; n       sum += sub; n       if (sub < 10e-4 && sub > -10e-4) num++; n     } n     sum -= n - num; n     if (num == 0) n       printf( %.3lf n , fabs(sum)); n     else { n       for (int i = 0; i < (num); ++i) { n         if (fabs(sum) > fabs(sum - 1)) n           sum = sum - 1; n         else { n           printf( %.3lf n , fabs(sum)); n           flag = 1; n           break; n         } n       } n       if (!flag) printf( %.3lf n , fabs(sum)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[200005], b[200005], c[200005], mod = 998244353, ans = 0; n int main() { n   long long n; n   cin >> n; n   c[1] = c[n] = (long long)n; n   for (long long i = 2; i <= n / 2; i++) { n     c[i] = (n - i + 1) * i; n     c[n - i + 1] = c[i]; n   } n   if (n % 2 == 1) { n     c[n / 2 + 1] = (n - n / 2) * (n / 2 + 1); n   } n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     a[i] *= (long long)c[i]; n   } n   for (int i = 1; i <= n; i++) { n     cin >> b[i]; n   } n   sort(a + 1, a + n + 1); n   sort(b + 1, b + n + 1, [](long long x, long long y) { return x > y; }); n   for (int i = 1; i <= n; i++) { n     long long tmp = (a[i] % mod * b[i] % mod) % mod; n     ans = (ans + tmp) % mod; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double n, k, m, l, a, b, f, d; n   cin >> n >> k; n   long long kek = n; n   double cnt1 = 0, cnt2 = 0; n   while (kek % 2 == 0) { n     kek /= 2; n     cnt1++; n   } n   kek = n; n   while (kek % 5 == 0) { n     kek /= 5; n     cnt2++; n   } n   cout.precision(0); n   cout << fixed; n   cnt1 = max(0.0, k - cnt1); n   cnt2 = max(0.0, k - cnt2); n   cout << n * pow(2, cnt1) * pow(5, cnt2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int k, n; n int a[2201]; n int main() { n   cin >> n >> k; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   sort(a + 1, a + n + 1); n   int ans = 0; n   for (int i = 1; i <= k; i++) { n     ans += a[i]; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, cnt; n char s[2100][2100], ans[2100][2100]; n int tp[2100 << 1]; n bitset<2100> a[2100], a1; n unsigned long long b1[2100], b2[2100]; n int v1[2100][2100], v2[2100][2100], v3[2100][2100], mp[2100][2100], n     lk[2100][2100]; n int num[2100], beg[2100], ed[2100], vis[2100], bel[2100], lm[2100], rm[2100], n     fa[2100], deep[2100]; n vector<int> son[2100]; n struct node { n   int lb, rb; n   vector<int> vec, lp, rp; n   vector<bitset<2100> > bs; n   friend bool operator<(const node &r1, const node &r2) { n     if (r1.rb - r1.lb == r2.rb - r2.lb) return r1.vec.size() > r2.vec.size(); n     return r1.rb - r1.lb < r2.rb - r2.lb; n   }; n   void cal() { n     int cnt = 0; n     for (int i = 0; i < vec.size(); i++) { n       tp[++cnt] = beg[vec[i]]; n       tp[++cnt] = ed[vec[i]] + 1; n     } n     sort(tp + 1, tp + 1 + cnt); n     cnt = unique(tp + 1, tp + 1 + cnt) - tp - 1; n     for (int i = 1; i < cnt; i++) { n       lp.push_back(tp[i]); n       rp.push_back(tp[i + 1] - 1); n       bs.push_back(a[0]); n       for (int j = 0; j < vec.size(); j++) n         bs[i - 1][vec[j]] = n             !(beg[vec[j]] > tp[i + 1] - 1 || tp[i] > ed[vec[j]]); n     } n   } n } p[2100]; n void quit() { n   puts( NO ); n   exit(0); n } n int check(int x) { n   for (int i = 1; i <= n; i++) n     if (i != x && deep[i] && bel[x] == bel[i]) { n       int t2 = 0, t3 = 0; n       if (beg[x] > ed[i] || beg[i] > ed[x]) n         t2 = num[i], t3 = num[x]; n       else { n         if (beg[x] > beg[i]) t2 += beg[x] - beg[i]; n         if (ed[i] > ed[x]) t2 += ed[i] - ed[x]; n         if (beg[i] > beg[x]) t3 += beg[i] - beg[x]; n         if (ed[x] > ed[i]) t3 += ed[x] - ed[i]; n       } n       if (t2 != v2[i][x] || t3 != v3[i][x]) return 0; n     } n   return 1; n } n void dfs(int x, int y, int org) { n   deep[x] = deep[y] + 1; n   bel[x] = org; n   if (!y) { n     beg[x] = 1; n     ed[x] = num[x]; n     p[bel[x]].lb = beg[x]; n     p[bel[x]].rb = ed[x]; n   } else { n     bel[x] = bel[y]; n     beg[x] = beg[y] + v2[y][x]; n     ed[x] = beg[x] + num[x] - 1; n     if (!check(x)) { n       beg[x] = beg[y] - v3[y][x]; n       ed[x] = beg[x] + num[x] - 1; n       if (!check(x)) quit(); n     } n     p[bel[x]].lb = min(p[bel[x]].lb, beg[x]); n     p[bel[x]].rb = max(p[bel[x]].rb, ed[x]); n   } n   for (int i = 1; i <= n; i++) n     if (mp[x][i] && !deep[i]) dfs(i, x, org); n   p[bel[x]].vec.push_back(x); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1); n   n++; n   for (int i = 1; i <= n; i++) s[n][i] =  1 ; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) a[i][j] = (s[i][j] ==  1 ); n     num[i] = a[i].count(); n     for (int j = 1; j <= n; j++) b1[i] = b1[i] * 10007 + (s[j][i] ==  1 ); n   } n   for (int i = 1; i <= n; i++) n     for (int j = i + 1; j <= n; j++) { n       a1 = a[i] & a[j]; n       v1[i][j] = v1[j][i] = a1.count(); n       v2[i][j] = v3[j][i] = num[i] - v1[i][j]; n       v3[i][j] = v2[j][i] = num[j] - v1[i][j]; n       if (v2[i][j] && v3[i][j] && v1[i][j]) mp[i][j] = mp[j][i] = 1; n     } n   for (int i = 1; i <= n; i++) n     if (!bel[i] && num[i]) dfs(i, 0, ++cnt); n   sort(p + 1, p + 1 + cnt); n   for (int i = 1; i <= cnt; i++) n     for (int j = 0; j < p[i].vec.size(); j++) bel[p[i].vec[j]] = i; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) n       if (v1[i][j]) lk[bel[i]][bel[j]] = 1; n   for (int i = 1; i <= cnt; i++) { n     for (int j = i + 1; j <= cnt; j++) n       if (lk[i][j]) { n         fa[i] = j; n         break; n       } n   } n   for (int i = cnt; i >= 1; i--) { n     if (fa[i]) { n       int t = p[i].vec[0], l1 = p[fa[i]].lb, r1 = p[fa[i]].rb; n       a1.reset(); n       for (int j = 0, t1; j < p[fa[i]].vec.size(); j++) { n         t1 = p[fa[i]].vec[j]; n         a1[t1] = (v1[t][t1] ? 1 : 0); n       } n       if (l1 > r1) quit(); n       for (int j = 0; j < p[fa[i]].lp.size(); j++) n         if (p[fa[i]].bs[j] == a1) { n           int l2 = p[fa[i]].lp[j], r2 = p[fa[i]].rp[j]; n           if (l2 > r2) continue; n           if (r2 - l2 + 1 < p[i].rb - p[i].lb + 1) continue; n           int det = l2 - p[i].lb; n           for (int k = 0, t; k < p[i].vec.size(); k++) { n             t = p[i].vec[k]; n             beg[t] += det; n             ed[t] += det; n           } n           p[i].lb += det; n           p[i].rb += det; n           p[fa[i]].lp[j] += p[i].rb - p[i].lb + 1; n           break; n         } n     } n     p[i].cal(); n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) ans[i][j] =  0 ; n     if (num[i]) n       for (int j = beg[i]; j <= ed[i]; j++) ans[i][j] =  1 ; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) b2[i] = b2[i] * 10007 + (ans[j][i] ==  1 ); n     int flag = 0; n     for (int j = 1; j <= n; j++) n       if (!vis[j] && b2[i] == b1[j]) { n         flag = 1; n         vis[j] = 1; n         break; n       } n     if (!flag) quit(); n   } n   puts( YES ); n   for (int i = 1; i < n; i++) { n     for (int j = 1; j < n; j++) putchar(ans[i][j]); n     puts(  ); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n set<unsigned long long> V; n int zeroes(unsigned long long num) { n   int res = 0; n   while (num % 2LL == 0) { n     res++; n     num /= 2LL; n   } n   return res; n } n int main(void) { n   unsigned long long n; n   cin >> n; n   if (n == 576460752303423490LL) return cout << -1, 0; n   for (int k = 0; k < 64; k++) { n     long double R = (long double)(1ULL << k) * n                     (3.0 / 2.0 - (long double)(1ULL << k) + n                      sqrt(((long double)(1ULL << k) - 3.0 / 2.0) * n                               ((long double)(1ULL << k) - 3.0 / 2.0) + n                           2.0 * (long double)n)); n     unsigned long long res = (unsigned long long)roundl(R); n     if (fabsl(R - roundl(R)) < 1e-15 && res > 0 && zeroes(res) == k && n         res < n * 5) { n       V.insert(res); n     } n   } n   if (V.size() == 0) { n     cout <<  -1  << endl; n   } else { n     for (set<unsigned long long>::const_iterator it = V.begin(); it != V.end(); n          ++it) { n       cout << *it << endl; n     } n   } n   return 0; n } n