#include <bits/stdc++.h> n using namespace std; n const long long INF = (1ll << 45); n long long bit[1000006]; n void update(long long from, long long val) { n   for (long long i = from; i < 1000006; i += i & -i) bit[i] += val; n } n long long query(long long from) { n   if (from == 0) return 0; n   long long cnt = 0; n   for (long long i = from; i > 0; i -= i & -i) cnt += bit[i]; n   return cnt; n } n long long query(long long l, long long r) { return query(r) - query(l - 1); } n struct Node { n   Node *lc, *rc; n   long long mx, tag; n   Node() : lc(NULL), rc(NULL), mx(-INF), tag(0) {} n   void pull() { mx = max(lc->mx, rc->mx); } n }; n const long long N = 1000002; n Node* Build(long long L, long long R) { n   Node* node = new Node(); n   if (L == R) { n     node->mx = -N + L; n     return node; n   } n   long long mid = (L + R) >> 1; n   node->lc = Build(L, mid); n   node->rc = Build(mid + 1, R); n   node->pull(); n   return node; n } n void push(Node* node, long long L, long long R) { n   if (L == R) node->tag = 0; n   if (node->tag == 0) return; n   node->lc->mx += node->tag; n   node->rc->mx += node->tag; n   node->lc->tag += node->tag; n   node->rc->tag += node->tag; n   node->tag = 0; n   return; n } n void modify(Node* node, long long L, long long R, long long l, long long r, n             long long val) { n   if (l > R || L > r) n     return; n   else if (l <= L && R <= r) { n     node->mx += val; n     node->tag += val; n     return; n   } n   push(node, L, R); n   long long mid = (L + R) >> 1; n   modify(node->lc, L, mid, l, r, val); n   modify(node->rc, mid + 1, R, l, r, val); n   node->pull(); n   return; n } n long long query(Node* node, long long L, long long R, long long l, n                 long long r) { n   if (l > R || L > r) n     return -INF; n   else if (l <= L && R <= r) n     return node->mx; n   push(node, L, R); n   long long mid = (L + R) >> 1; n   return max(query(node->lc, L, mid, l, r), query(node->rc, mid + 1, R, l, r)); n } n long long n, x[N][2]; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   Node* root = Build(1, N); n   string in; n   long long v1, v2; n   for (long long i = 1; i < n + 1; ++i) { n     cin >> in; n     if (in ==  ? ) { n       cin >> v1; n       cout << query(root, 1, N, 1, v1) + (N - v1) - query(v1 + 1, 1000006 - 1) n            <<   n ; n     } else if (in ==  + ) { n       cin >> v1 >> v2; n       x[i][0] = v1; n       x[i][1] = v2; n       modify(root, 1, N, 1, x[i][0], x[i][1]); n       update(v1, v2); n     } else if (in ==  - ) { n       cin >> v1; n       modify(root, 1, N, 1, x[v1][0], -x[v1][1]); n       update(x[v1][0], -x[v1][1]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1 << 28; n const long long LINF = 1ll << 61; n inline long long getnum() { n   register long long r = 0; n   register bool ng = 0; n   register char c; n   c = getchar(); n   while (c !=  -  && (c <  0  || c >  9 )) c = getchar(); n   if (c ==  - ) ng = 1, c = getchar(); n   while (c !=     && c !=   n ) r = r * 10 + c -  0 , c = getchar(); n   if (ng) r = -r; n   return r; n } n template <class T> n inline void putnum(T x) { n   if (x < 0) putchar( - ), x = -x; n   register short a[20] = {}, sz = 0; n   while (x > 0) a[sz++] = x % 10, x /= 10; n   if (sz == 0) putchar( 0 ); n   for (int i = sz - 1; i >= 0; i--) putchar( 0  + a[i]); n } n inline void putsp() { putchar(   ); } n inline void putendl() { putchar(  n ); } n int n, a[200111], p[200111], cnt[200111], mx = 1, ans[200111]; n bool f[200111]; n map<int, vector<int> > mp; n int gf(int x) { return x == p[x] ? x : p[x] = gf(p[x]); } n void un(int x, int y) { n   x = gf(x), y = gf(y); n   if (x == y) return; n   p[y] = x; n   cnt[x] += cnt[y]; n   mx = max(mx, cnt[x]); n } n int main() { n   n = getnum(); n   for (int i = 1; i <= n; i++) { n     p[i] = i; n     a[i] = getnum(); n     mp[a[i]].push_back(i); n     cnt[i] = 1; n   } n   for (map<int, vector<int> >::iterator it = --mp.end();; it--) { n     vector<int> &v = it->second; n     for (int i = 0; i < v.size(); i++) { n       f[v[i]] = 1; n       if (f[v[i] - 1]) un(v[i] - 1, v[i]); n       if (f[v[i] + 1]) un(v[i] + 1, v[i]); n       ans[mx] = max(ans[mx], it->first); n     } n     if (it == mp.begin()) break; n   } n   int res = ans[n]; n   for (int i = n; i >= 1; i--) { n     if (ans[i] != 0) res = ans[i]; n     ans[i] = res; n   } n   for (int i = 1; i <= n; i++) putnum(ans[i]), putsp(); n   return 0; n } n


#include <bits/stdc++.h> n int vi[60], ho[60]; n int main() { n   int n, k, i; n   int x, y; n   scanf( %d , &n); n   for (k = 1; k <= n * n; k++) { n     scanf( %d%d , &x, &y); n     if (vi[x] || ho[y]) continue; n     vi[x] = 1; n     ho[y] = 1; n     printf( %d  , k); n   } n } n


#include<bits/stdc++.h> n  n #define y1 dmytxdy n #define pb push_back n #define fi first n #define se second n #define mp make_pair n  n using namespace std; n  n typedef long long ll; n typedef unsigned long long ull; n typedef pair<int,int> pii; n typedef pair<ll,ll> pll; n typedef long double ld; n  n template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;} n template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;} n  n int readint(){ n  int x=0,f=1; char ch=getchar(); n  while(ch< 0 ||ch> 9 ){if(ch== - )f=-1;ch=getchar();} n  while(ch>= 0 &&ch<= 9 ){x=x*10+ch- 0 ;ch=getchar();} n  return x*f; n } n  n struct node{ n  int x,y,id; n  node(int x=0,int y=0,int id=0):x(x),y(y),id(id){} n }p[2005]; n  n int n,m; n int x[2005],y[2005],a[2005]; n bool vis[2005]; n  n ll operator*(pii x,pii y){return 1ll*x.fi*y.se-1ll*x.se*y.fi;} n  n int main(){ n  n=readint(); n  for(int i=1;i<=n;i++) x[i]=readint(),y[i]=readint(),a[i]=readint(); n  int pl=0,mina=1<<30; n  for(int i=1;i<=n;i++) if(a[i]!=i&&chkmin(mina,x[i])) pl=i; n  if(!pl){ n   printf( 0 n ); n   return 0; n  } n  for(int i=1;i<=n;i++) if(i!=pl&&a[i]!=i) p[++m]=node(x[i],y[i],i); n  for(int i=1;i<=m;i++) for(int j=i+1;j<=m;j++) if(mp(p[i].x-x[pl],p[i].y-y[pl])*mp(p[j].x-x[pl],p[j].y-y[pl])<0) swap(p[i],p[j]); n  vector<pii> ans(0); n  for(int i=1;i<m;i++){ n   for(int j=p[i].id,k=1;k<=n;j=a[j],k++) vis[j]=1; n   bool fl=vis[p[i+1].id]; n   for(int j=p[i].id,k=1;k<=n;j=a[j],k++) vis[j]=0; n   if(!fl) ans.pb(mp(p[i].id,p[i+1].id)),swap(a[p[i].id],a[p[i+1].id]); n  } n  for(int j=a[pl];j!=pl;j=a[j]) ans.pb(mp(pl,j)); n  printf( %d n ,ans.size()); n  for(auto r:ans) printf( %d %d n ,r.fi,r.se); n  return 0; n }


#include<bits/stdc++.h> n using namespace std; n int main() n { n     int tst,i,m,n; n     cin>>tst; n     while(tst--) n     { n         int ar[4]; n         cin>>ar[0]>>ar[1]>>ar[2]>>ar[3]; n         n=max(ar[2],ar[3]);m=max(ar[0],ar[1]); n         sort(ar,ar+4); n         ((n==ar[3]||n==ar[2])&&(m==ar[3] || m==ar[2]))?cout<< YES n :cout<< NO n ; n     } n }


#include <bits/stdc++.h> n using namespace std; n constexpr int maxn = 1010; n int n; n bool e[maxn][maxn]; n pair<int, int> flip(int a, int b, bool inv) { n   int x = -1, y; n   for (int i = 0; i < n; i++) n     if (e[a][i] && e[b][i]) n       if (x == -1) n         x = i; n       else { n         y = i; n         break; n       } n   e[a][b] = e[b][a] = false; n   e[x][y] = e[y][x] = true; n   return inv ? make_pair(x, y) : make_pair(a, b); n } n vector<pair<int, int> > solve(bool inv) { n   memset(e, 0, sizeof(e)); n   for (int i = 0; i < n; i++) e[i][(i + 1) % n] = e[(i + 1) % n][i] = true; n   for (int i = 0, a, b; i < n - 3; i++) { n     cin >> a >> b; n     a--; n     b--; n     e[a][b] = e[b][a] = true; n   } n   vector<pair<int, int> > res; n   for (int i = 1; i < n;) { n     if (e[0][i]) { n       i++; n       continue; n     } n     int j; n     for (j = i + 1; e[0][j] == 0; j++) n       ; n     res.push_back(flip(i - 1, j, inv)); n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n; n   vector<pair<int, int> > a = solve(false), b = solve(true); n   cout << a.size() + b.size() << endl; n   for (int i = 0; i < (int)a.size(); i++) n     cout << a[i].first + 1 <<     << a[i].second + 1 << endl; n   for (int i = b.size() - 1; i >= 0; i--) n     cout << b[i].first + 1 <<     << b[i].second + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n std::ostream& operator<<(std::ostream& os, const std::vector<T>& input) { n   for (auto const& i : input) { n     os << i <<    ; n   } n   return os; n } n template <class T1, class T2> n std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& input) { n   os <<  (  << input.first <<  ,   << input.second <<  ) ; n   return os; n } n const int maxn = 1000; n int d[maxn], f[maxn]; n vector<int> E[maxn], node[maxn]; n void dfs(int u, int fa) { n   node[d[u]].push_back(u + 1); n   for (int v : E[u]) n     if (v != fa) { n       d[v] = d[u] + 1; n       f[v] = u; n       dfs(v, u); n     } n } n void solve() { n   int n, x, y; n   cin >> n; n   for (int i = 0; i < int(n); ++i) { n     node[i].clear(); n     E[i].clear(); n   } n   for (int i = 0; i < int(n - 1); ++i) { n     cin >> x >> y; n     x--, y--; n     E[x].push_back(y); n     E[y].push_back(x); n   } n   cout <<  ?   << n; n   for (int i = 0; i < int(n); ++i) cout <<     << i + 1; n   cout << endl; n   int root, dist; n   cin >> root >> dist; n   root--; n   d[root] = 0; n   dfs(root, -1); n   int l = 0, r = 0; n   for (int i = 0; i < int(n); ++i) r = max(r, d[i]); n   r++; n   int node_u, node_v; n   while (r - l > 1) { n     int m = (l + r) >> 1; n     cout <<  ?   << (node[m]).size() <<     << node[m] << endl; n     cin >> x >> y; n     x--; n     if (y == dist) { n       node_u = x + 1; n       l = m; n     } else { n       r = m; n     } n   } n   int lv = dist - l; n   if (lv == 0) { n     node_v = root + 1; n   } else { n     int w = node_u - 1; n     for (int i = 0; i < int(l - lv); ++i) { n       w = f[w]; n     } n     vector<int> tmp(0); n     for (int x : node[lv]) n       if (x != w + 1) tmp.push_back(x); n     cout <<  ?   << (tmp).size() <<     << tmp << endl; n     cin >> node_v >> y; n     assert(y == dist); n   } n   cout <<  !   << node_u <<     << node_v << endl; n   string ret; n   cin >> ret; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int cas = 1; n   cin >> cas; n   for (int ca = 0; ca < int(cas); ++ca) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct point { n   int x, y; n }; n int dist(const point &a, const point &b) { n   return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); n } n int main(int argc, char *argv[]) { n   point p[8]; n   int a[8] = {0, 1, 2, 3, 4, 5, 6, 7}; n   for (int i = 0; i < 8; i++) scanf( %d %d , &p[i].x, &p[i].y); n   bool found = false; n   do { n     int d = dist(p[a[0]], p[a[1]]); n     if (d != dist(p[a[0]], p[a[2]]) || d != dist(p[a[1]], p[a[3]]) || n         d != dist(p[a[2]], p[a[3]])) n       continue; n     if (2 * d != dist(p[a[0]], p[a[3]]) || 2 * d != dist(p[a[1]], p[a[2]])) n       continue; n     int d1 = dist(p[a[4]], p[a[5]]); n     int d2 = dist(p[a[4]], p[a[6]]); n     if (d1 != dist(p[a[6]], p[a[7]]) || d2 != dist(p[a[5]], p[a[7]])) continue; n     if (d1 + d2 != dist(p[a[5]], p[a[6]]) || d1 + d2 != dist(p[a[4]], p[a[7]])) n       continue; n     found = true; n     break; n   } while (next_permutation(a, a + 8)); n   if (found) { n     printf( YES n ); n     for (int i = 0; i < 4; i++) printf( %s%d , i > 0 ?     :   , a[i] + 1); n     printf(  n ); n     for (int i = 4; i < 8; i++) printf( %s%d , i > 4 ?     :   , a[i] + 1); n     printf(  n ); n   } else { n     printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 59; n int t[N]; n inline int read() { n   int s = 1, a = 0; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) s = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     a = a * 10 + ch -  0 ; n     ch = getchar(); n   } n   return s * a; n } n int main() { n   int n = read(), k = read(), m = read(), s = 0; n   for (int i = 1; i <= k; i++) t[i] = read(), s += t[i]; n   sort(t + 1, t + k + 1); n   long long res = 0; n   for (int i = 0; i <= n; i++) { n     long long tim = i * s, cur = i * (k + 1); n     if (tim > m) break; n     for (int j = 1; j <= k; j++) { n       if (tim + (n - i) * t[j] <= m) n         tim += (n - i) * t[j], cur += (n - i); n       else { n         while (tim + t[j] <= m) tim += t[j], cur++; n         break; n       } n     } n     res = max(res, cur); n   } n   return 0 * printf( %d n , res); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 7; n const int M = 23; n const int inf = 1e9 + 7; n const long long base = 1e18; n const double pi = acos(-1); n const double ep = 1e-9; n map<int, int> st; n int pre[1 << M]; n int cur[1 << M]; n int n; n int a[N]; n int main() { n   cin >> n; n   for (int i = 1; i < n + 1; i++) { n     cin >> a[i]; n     st[a[i]] = i - 1; n   } n   for (int mask = 0; mask < 1 << M; mask++) cur[mask] = inf; n   cur[1] = 1; n   for (int i = 2; i < n + 1; i++) { n     for (int mask = 0; mask < 1 << (i - 1); mask++) { n       pre[mask] = cur[mask]; n       cur[mask] = inf; n     } n     for (int mask = 0; mask < 1 << (i - 1); mask++) { n       if (pre[mask] >= inf) continue; n       bool check = false; n       for (int j = 0; j + 1 < i; j++) { n         if ((mask & (1 << j)) && st.count(a[i] - a[j + 1]) && n             (mask & (1 << st[a[i] - a[j + 1]]))) { n           check = true; n           break; n         } n       } n       if (!check) continue; n       for (int j = 0; j + 1 < i; j++) n         if (mask & (1 << (j))) { n           int nxt = mask ^ (1 << j) ^ (1 << (i - 1)); n           cur[nxt] = min(cur[nxt], pre[mask]); n         } n       int nxt = mask ^ (1 << (i - 1)); n       cur[nxt] = n           min(cur[nxt], pre[mask] + (pre[mask] == __builtin_popcount(mask))); n     } n   } n   int ans = inf; n   for (int mask = 0; mask < 1 << n; mask++) ans = min(ans, cur[mask]); n   if (ans == inf) ans = -1; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, r; n vector<pair<int, int> > pos, L, R; n vector<int> ans; n map<pair<int, int>, int> vis; n bool cmp(pair<int, int> a, pair<int, int> b) { n   return a.first + a.second < b.first + b.second; n } n int main() { n   cin >> n >> r; n   for (int i = 0; i < n; i++) { n     int x, y; n     cin >> x >> y; n     vis[{x, y}]++; n     if (y >= 0) n       pos.push_back({x, y}); n     else n       R.push_back({y, x}), L.push_back({x, y}); n   } n   sort(pos.begin(), pos.end()); n   sort(L.rbegin(), L.rend(), cmp); n   vector<pair<int, int> > aux; n   for (pair<int, int> x : pos) { n     while (aux.size() && r >= aux.back().first) { n       r += aux.back().second; n       aux.pop_back(); n     } n     if (r < x.first) { n       aux.push_back(x); n     } else { n       r += x.second; n     } n   } n   if (aux.size()) { n     cout <<  NO  << endl; n     return 0; n   } n   for (pair<int, int> x : L) { n     if (r < x.first) { n       cout <<  NO  << endl; n       return 0; n     } n     r += x.second; n   } n   if (r < 0) n     cout <<  NO  << endl; n   else n     cout <<  YES  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char* argv[]) { n   ios_base::sync_with_stdio(false); n   long long int N, M; n   cin >> N >> M; n   long long int max_n1; n   for (max_n1 = 1; (max_n1 * (max_n1 - 1)) / 2 + 1 <= N; max_n1 += 2) n     ; n   max_n1 -= 2; n   long long int max_n2; n   for (max_n2 = 0; (max_n2 * (max_n2 - 1)) / 2 + max_n2 / 2 <= N; max_n2 += 2) n     ; n   max_n2 -= 2; n   long long int max_n = max(max_n1, max_n2); n   vector<long long int> qs(M, 0); n   vector<long long int> ws(M, 0); n   for (int m = 0; m < M; ++m) cin >> qs[m] >> ws[m]; n   sort(ws.begin(), ws.end(), greater<long long int>()); n   max_n = min(max_n, (long long int)ws.size()); n   long long int res = 0; n   for (int i = 0; i < max_n; ++i) res += ws[i]; n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 111111; n int N; n char s[MAX]; n int f[MAX]; n int sum[MAX]; n bool match(int i, int j) { n   if (i < 1 || j < 1) return 0; n   if (s[i - 1] ==  ) ) n     return s[j - 1] ==  ( ; n   else n     return s[j - 1] ==  [ ; n } n int get(int i) { return f[i - 1] < N ? f[i - 1] : i; } n int main() { n   int i, j, k; n   while (cin >> s) { n     N = strlen(s); n     sum[0] = 0; n     for (i = 1; i <= N; ++i) sum[i] = sum[i - 1] + (s[i - 1] ==  ] ); n     memset(f, 127, sizeof f); n     for (i = 2; i <= N; ++i) { n       if (s[i - 1] ==  (  || s[i - 1] ==  [ ) continue; n       if (match(i, i - 1)) f[i] = get(i - 1); n       if (f[i - 1] < N && match(i, f[i - 1] - 1)) n         f[i] = min(f[i], get(f[i - 1] - 1)); n     } n     int ans = 0, ansi; n     for (i = 1; i <= N; ++i) n       if (f[i] < N && sum[i] - sum[f[i] - 1] > ans) { n         ans = sum[i] - sum[f[i] - 1]; n         ansi = i; n       } n     printf( %d n , ans, ansi); n     if (ans > 0) { n       for (i = f[ansi] - 1; i < ansi; ++i) putchar(s[i]); n     } n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int num; n   double w; n } point[1005]; n bool cmp(node a, node b) { n   if (fabs(a.w - b.w) < 0.0001) return a.num < b.num; n   return a.w > b.w; n } n int main() { n   int i, n, t1, t2, k, a, b; n   scanf( %d%d%d%d , &n, &t1, &t2, &k); n   for (i = 1; i <= n; i++) { n     scanf( %d%d , &a, &b); n     point[i].num = i; n     point[i].w = t1 * a * (1 - k * 0.01) + t2 * b; n     if (t1 * b * (1 - k * 0.01) + t2 * a > point[i].w) n       point[i].w = t1 * b * (1 - k * 0.01) + t2 * a; n   } n   sort(point + 1, point + 1 + n, cmp); n   for (i = 1; i <= n; i++) printf( %d %.2lf n , point[i].num, point[i].w); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<pair<int, int> > v; n   for (int i = 0; i < n; i++) { n     int a, b; n     cin >> a >> b; n     v.push_back(make_pair(a, b)); n   } n   int k; n   cin >> k; n   int i; n   for (i = 0; i < n; i++) { n     if (k >= v[i].first and k <= v[i].second) break; n   } n   cout << n - i << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   int a[n + 2][m + 2]; n   int counter = 1; n   for (int i = 1; i <= n; i += 2) { n     for (int j = 1; j <= m; j++) { n       if (n % 2 && i == n && j % 2 == 1) continue; n       a[i + (j % 2 == 1)][j] = counter; n       counter++; n     } n   } n   for (int i = 1; i <= n; i += 2) { n     for (int j = 1; j <= m; j++) { n       if (n % 2 && i == n && j % 2 == 0) continue; n       a[i + (j % 2 == 0)][j] = counter; n       counter++; n     } n   } n   bool res = true; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if ((i < n && abs(a[i][j] - a[i + 1][j]) <= 1) || n           (j < m && abs(a[i][j] - a[i][j + 1]) <= 1)) n         res = false; n     } n   } n   if (res) { n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= m; j++) { n         cout << a[i][j] <<    ; n       } n       cout <<   n ; n     } n   } else { n     cout << -1; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int minutes[n]; n   int result = -1; n   int lastN = 0; n   for (int i = 0; i < n; i++) { n     cin >> minutes[i]; n     if (i == 0 && minutes[0] > 15) { n       result = 15; n     } else if (result < 0 && minutes[i] - minutes[i - 1] > 15) { n       result = minutes[i - 1] + 15; n     } n   } n   if (result < 0) { n     result = minutes[n - 1] + 15; n   } n   if (result > 90) { n     result = 90; n   } n   cout << result; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k; n   cin >> k; n   if (k % 2 == 1) { n     cout << -1 << endl; n     return 0; n   } n   for (int i = 0; i < k; i++) { n     if (i > 0) cout << endl; n     for (int j = 0; j < k; j++) { n       for (int l = 0; l < k; l++) { n         int layer = min(j, min(l, min(k - j - 1, k - l - 1))); n         if (layer % 2 == i % 2) n           cout <<  w ; n         else n           cout <<  b ; n       } n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n  n using namespace std; n  n  n void dfs3(int v, vector<vector<int>> &graf, vector<int> &ways) { n     ways[v] = -1; n     for (auto el : graf[v]) { n         if (ways[el] != -1) { n             dfs3(el, graf, ways); n         } n     } n } n  n void dfs2(int v, vector<vector<int>> &graf,  vector<int> &ways) { n     ways[v] = 2; n     for (auto el : graf[v]) { n         if (ways[el] == 1) { n             dfs2(el, graf, ways); n         } n     } n } n  n void dfs(int v, vector<int> &vis, vector<int> &cycle, vector<vector<int>> &graf,  vector<int> &ways, vector<int> &progr) { n     if (progr[v] == 1) { n         cycle.push_back(v); n         ways[v] = -1; n     } else if (progr[v] == 2) { n         vis.push_back(v); n         ways[v] = 2; n     } else { n         progr[v] = 1; n         for (auto el : graf[v]) { n             dfs(el, vis, cycle, graf, ways, progr); n         } n         progr[v] = 2; n         ways[v] = 1; n     } n } n  n int main() n { n     ios::sync_with_stdio(false); n     int t; n     cin >> t; n     while (t--) { n         int n, m; n         cin >> n >> m; n         if (m == 0) { n             cout << 1 <<    ; n             for (int i = 1; i != n; i++) { n                 cout << 0 <<    ; n             } n         } else { n             vector<vector<int>> graf(n); n             vector<int> ways(n, 0); n             vector<int> progr(n, 0); n             // 1 - in progress, 0 - new, 2 - visited n             vector<int> cycle; n             vector<int> vis; n             for (int i = 0; i != m; i++) { n                 int s, f; n                 cin >> s >> f; n                 graf[s - 1].push_back(f - 1); n             } n             dfs(0, vis, cycle, graf, ways, progr); n             for (auto el : vis) { n                 dfs2(el, graf, ways); n             } n             for (auto el : cycle) { n                 dfs3(el, graf, ways); n             } n             for (auto el : ways) { n                 cout << el <<    ; n             } n         } n         cout <<   n ; n     } n     return 0; n } n


#include <bits/stdc++.h> n int main() { n   long long int l1, r1, l2, r2, k, l, r, t; n   scanf( %lld%lld%lld%lld%lld , &l1, &r1, &l2, &r2, &k); n   if (l1 > l2) n     l = l1; n   else n     l = l2; n   if (r1 > r2) n     r = r2; n   else n     r = r1; n   if ((k >= l) && (k <= r)) n     t = r - l; n   else n     t = r - l + 1; n   if (t < 0) n     t = 0; n   else n     t = t; n   printf( %lld , t); n   return 0; n } n


#include <bits/stdc++.h> n const int md = 1e9 + 7; n int n, k, m, M, c; n struct mat { n   int A[256][256]; n   inline mat() { memset(A, 0, sizeof A); } n   inline int* operator[](const int& x) { return A[x]; } n   inline mat operator*(const mat& b) const { n     mat c; n     for (int i = 0; i <= M; ++i) n       for (int k = 0; k <= M; ++k) n         for (int j = 0; j <= M; ++j) n           c[i][j] = (c[i][j] + (long long)A[i][k] * b.A[k][j]) % md; n     return c; n   } n } A, B; n inline void pow(mat a, int b) { n   mat& ret = B; n   ret[0][0] = 1; n   for (; b; b >>= 1, a = a * a) n     if (b & 1) ret = ret * a; n } n int main() { n   scanf( %d%d%d , &n, &k, &m), M = (k + 1) << m, c = (1 << m) - 1; n   for (int i = 0; i <= k; ++i) { n     for (int j = 0; j <= c; ++j) A[i << m | j][i << m | ((j << 1) & c)] = 1; n     if (i != k) n       for (int j = 0; j <= c; ++j) n         A[i << m | j][(i + 1) << m | ((j << 1 | 1) & c)] = n             1 + __builtin_popcount(j); n   } n   pow(A, n); n   int ans = 0; n   for (int i = 0; i <= c; ++i) ans = (ans + B[0][k << m | i]) % md; n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int t_1 = -1, t_2 = -1; n   int c1 = 0, c2 = 0; n   int a = 0; n   for (int i = 0; i < n; ++i) { n     int t; n     cin >> t; n     if (t_1 == -1) { n       t_1 = t; n       c1++; n     } else if (t_1 == t) { n       c1++; n     } else if (t_2 == -1) { n       t_2 = t; n       c2++; n     } else if (t_2 == t) { n       c2++; n     } else { n       a = -1; n     } n   } n   if (n % 2 == 1) a = -1; n   if (c1 != c2) a = -1; n   if (a == -1) n     cout <<  NO  << endl; n   else n     cout <<  YES n  << t_1 <<     << t_2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using std::cerr; n using std::endl; n const int N = 2e5 + 233; n int n, m; n std::map<std::pair<int, int>, int> map; n std::vector<std::pair<int, int>> seg[N * 4]; n void insert(int p, int l, int r, std::pair<int, int> e, int L, int R) { n   if (l <= L && r >= R) return seg[p].push_back(e), void(); n   if (l <= ((L + R) >> 1)) insert((p << 1), l, r, e, L, ((L + R) >> 1)); n   if (r > ((L + R) >> 1)) n     insert(((p << 1) | 1), l, r, e, ((L + R) >> 1) + 1, R); n } n int fa[N], size[N], dis[N]; n int find(int x) { return x == fa[x] ? x : find(fa[x]); } n inline int get_dis(int x) { n   int ret = 0; n   while (x != fa[x]) { n     ret ^= dis[x]; n     x = fa[x]; n   } n   return ret; n } n struct Node { n   int x, y, s; n } stk[N]; n int top; n void divide(int p, int L, int R, int ok) { n   int top_ver = top; n   for (auto e : seg[p]) { n     int x = e.first, y = e.second; n     int u = find(x), v = find(y); n     int dis_x = get_dis(x), dis_y = get_dis(y); n     if (u != v) { n       if (size[u] < size[v]) std::swap(u, v); n       stk[++top] = {u, v, size[v]}; n       fa[u] = v, size[v] += size[u]; n       dis[u] = dis_x ^ dis_y ^ 1; n     } else { n       if ((dis_x ^ dis_y) == 0) { n         ok = 0; n         break; n       } n     } n   } n   if (!ok) { n     for (int i = L; i <= R; ++i) puts( NO ); n   } else if (L == R) { n     puts( YES ); n   } else { n     divide((p << 1), L, ((L + R) >> 1), ok); n     divide(((p << 1) | 1), ((L + R) >> 1) + 1, R, ok); n   } n   while (top > top_ver) { n     int x = stk[top].x, y = stk[top].y, s = stk[top].s; n     fa[x] = x, size[y] = s, dis[x] = 0; n     --top; n   } n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= m; ++i) { n     int x, y; n     scanf( %d %d , &x, &y); n     if (x > y) std::swap(x, y); n     std::pair<int, int> pair = {x, y}; n     if (map.find(pair) != map.end()) { n       insert(1, map[pair], i - 1, pair, 1, m); n       map.erase(pair); n     } else { n       map[pair] = i; n     } n   } n   for (auto w : map) { n     insert(1, w.second, m, w.first, 1, m); n   } n   for (int i = 1; i <= n; ++i) fa[i] = i, size[i] = 1; n   divide(1, 1, m, 1); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n template <typename T1, typename T2> n inline void chkmin(T1 &first, T2 second) { n   if (first > second) first = second; n } n template <typename T1, typename T2> n inline void chkmax(T1 &first, T2 second) { n   if (first < second) first = second; n } n template <typename T, typename U> n inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) { n   _out << _p.first <<     << _p.second; n   return _out; n } n template <typename T, typename U> n inline istream &operator>>(istream &_in, pair<T, U> &_p) { n   _in >> _p.first >> _p.second; n   return _in; n } n template <typename T> n inline ostream &operator<<(ostream &_out, const vector<T> &_v) { n   if (_v.empty()) { n     return _out; n   } n   _out << _v.front(); n   for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { n     _out <<     << *_it; n   } n   return _out; n } n template <typename T> n inline istream &operator>>(istream &_in, vector<T> &_v) { n   for (auto &_i : _v) { n     _in >> _i; n   } n   return _in; n } n template <typename T> n inline ostream &operator<<(ostream &_out, const set<T> &_s) { n   if (_s.empty()) { n     return _out; n   } n   _out << *_s.begin(); n   for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { n     _out <<     << *_it; n   } n   return _out; n } n template <typename T> n inline ostream &operator<<(ostream &_out, const multiset<T> &_s) { n   if (_s.empty()) { n     return _out; n   } n   _out << *_s.begin(); n   for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { n     _out <<     << *_it; n   } n   return _out; n } n template <typename T> n inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) { n   if (_s.empty()) { n     return _out; n   } n   _out << *_s.begin(); n   for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { n     _out <<     << *_it; n   } n   return _out; n } n template <typename T> n inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) { n   if (_s.empty()) { n     return _out; n   } n   _out << *_s.begin(); n   for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { n     _out <<     << *_it; n   } n   return _out; n } n template <typename T, typename U> n inline ostream &operator<<(ostream &_out, const map<T, U> &_m) { n   if (_m.empty()) { n     return _out; n   } n   _out <<  (  << _m.begin()->first <<  :   << _m.begin()->second <<  ) ; n   for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { n     _out <<  , (  << _it->first <<  :   << _it->second <<  ) ; n   } n   return _out; n } n template <typename T, typename U> n inline ostream &operator<<(ostream &_out, const unordered_map<T, U> &_m) { n   if (_m.empty()) { n     return _out; n   } n   _out <<  (  << _m.begin()->first <<  :   << _m.begin()->second <<  ) ; n   for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { n     _out <<  , (  << _it->first <<  :   << _it->second <<  ) ; n   } n   return _out; n } n const int MAXN = 2e5 + 1; n int n; n long long len; n int a[MAXN]; n int b[MAXN]; n int pref[MAXN * 3]; n int v[MAXN]; n long long get(int i) { n   int d = i / n; n   if (i < 0) --d; n   return len * d + a[i - d * n]; n } n bool check(int d) { n   for (int i = 0; i < n * 3; ++i) { n     pref[i] = 0; n   } n   int L = -n, R = 0; n   for (int i = 0; i < n; ++i) { n     v[i] = 0; n     while (abs(get(L) - b[i]) > d) { n       if (L > n * 2) return false; n       ++L; n     } n     chkmax(R, L); n     while (abs(get(R) - b[i]) <= d) { n       ++R; n     } n     if (R - L >= n) { n       pref[0]++; n       pref[n]--; n     } else { n       pref[L + n * 2 - i]++; n       pref[R + n * 2 - i]--; n     } n   } n   int b = 0; n   for (int i = 0; i < n * 3; ++i) { n     b += pref[i]; n     v[i % n] += b; n   } n   for (int i = 0; i < n; ++i) { n     if (v[i] == n) return true; n   } n   return false; n } n int main() { n   ios::sync_with_stdio(0); n   cin >> n >> len; n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n   } n   for (int i = 0; i < n; ++i) { n     cin >> b[i]; n   } n   sort(a, a + n); n   sort(b, b + n); n   int L = -1, R = len; n   while (R - L > 1) { n     int M = (L + R) >> 1; n     if (check(M)) { n       R = M; n     } else { n       L = M; n     } n   } n   cout << R << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, q, x; n   vector<int> v; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> x; n     v.push_back(x); n   } n   sort(v.begin(), v.end()); n   cin >> q; n   while (q--) { n     cin >> x; n     int ans = upper_bound(v.begin(), v.end(), x) - v.begin(); n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int p[100001], w[100001]; n bool combine(int x, int y) { n   while (p[x] != x) x = p[x] = p[p[x]]; n   while (p[y] != y) y = p[y] = p[p[y]]; n   if (x == y) return false; n   if (w[x] < w[y]) n     w[p[x] = y] += w[x]; n   else n     w[p[y] = x] += w[y]; n   return true; n } n int main() { n   int n, m, x, y, ans = 1; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) w[p[i] = i] = 1; n   while (m--) { n     scanf( %d%d , &x, &y); n     if (!combine(x, y)) ans = ans * 2 % 1000000009; n     printf( %d n , (ans + 1000000008) % 1000000009); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, x, y, z; n   cin >> a >> b >> c >> x >> y >> z; n   int ans; n   if ((a == 0 && b == 0 && c) || (x == 0 && y == 0 && z)) { n     ans = 0; n   } else if (a * y == b * x) { n     if (a * z == c * x && b * z == c * y) { n       ans = -1; n     } else { n       ans = 0; n     } n   } else { n     ans = 1; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 21; n string s; n long long heavy = 0, sol = 0; n int main() { n   cin >> s; n   for (int i = 0; i < s.size(); i++) { n     string temp = s.substr(i, 5); n     if (temp ==  heavy ) { n       heavy++; n       i += 4; n     } else if (temp ==  metal ) { n       sol += heavy; n       i += 4; n     } n   } n   printf( %I64d , sol); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void chmax(T &x, T &y) { n   if (x < y) swap(x, y); n } n template <class T> n inline void chmin(T &x, T &y) { n   if (x > y) swap(x, y); n } n const long long INF = 0x3f3f3f3f3f3f; n const long long MOD = 1e9 + 7; n const double EPS = 10e-10; n const long long P2LIM = (long long)2e18; n const long long maxN = 1e9 + 10; n void Solution() {} n long long countSC(long long N) { n   long long res = n       (long long)sqrt(N) + (long long)cbrt(N) - (long long)(sqrt(cbrt(N))); n   return res; n } n int32_t main() { n   long long tc; n   cin >> tc; n   while (tc--) { n     long long n; n     cin >> n; n     cout << countSC(n) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, tmp; n map<long long, int> b; n long long j = 1, c[33]; n void make_two_pow() { n   long long i = 2; n   while (j <= 32) { n     c[j++] = i; n     i *= 2; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> tmp; n     b[tmp]++; n   } n   make_two_pow(); n   long long ans = 0; n   for (auto& v : b) { n     bool flag = false; n     for (int i = 1; i < 33; i++) { n       tmp = b.count(c[i] - v.first); n       if (tmp) { n         if (b[c[i] - v.first] >= 2) { n           flag = true; n           break; n         } n         if (c[i] - v.first != v.first) { n           flag = true; n           break; n         } n       } n     } n     if (!flag) { n       ans += b[v.first]; n     } n   } n   cout << endl << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Max = 1e5 + 10; n int fw[Max][26]; n int bw[Max][26]; n int gs[Max][26]; n int ge[Max][26]; n int n; n int A[Max]; n int mex(vector<int> vec); n void CalcGS(int i, int c); n void CalcGE(int i, int c); n int mex(vector<int> vec) { n   sort(vec.begin(), vec.end()); n   if (vec[0] > 0) return 0; n   for (int i = 1; i < vec.size(); i++) n     if (vec[i] > vec[i - 1] + 1) return vec[i - 1] + 1; n   return vec.back() + 1; n } n int G(int l, int r) { n   if (l >= r) return 0; n   if ((r - l) == 1 || (r - l) == 2 && A[l + 1] == A[r + 1]) return 1; n   l++, r--; n   for (int ch = 0; ch < 26; ch++) { n     if (A[l] == ch && A[r] == ch) { n       CalcGS(l + 1, ch); n       CalcGS(r + 1, ch); n     } else if (A[r] == ch) { n       CalcGS(l, ch); n       CalcGS(r + 1, ch); n     } else if (A[l] == ch) { n       int lCh = bw[r][ch]; n       CalcGS(l + 1, ch); n       CalcGS(lCh + 1, ch); n       CalcGE(r, ch); n     } else { n       int lCh = bw[r][ch]; n       if (lCh < l) continue; n       CalcGS(l, ch); n       CalcGS(lCh + 1, ch); n       CalcGE(r, ch); n     } n   } n   vector<int> vec; n   for (int ch = 0; ch < 26; ch++) { n     int g = 0; n     if (A[l] == ch && A[r] == ch) { n       g = gs[l + 1][ch] ^ gs[r + 1][ch]; n     } else if (A[r] == ch) { n       g = gs[l][ch] ^ gs[r + 1][ch]; n     } else if (A[l] == ch) { n       int lCh = bw[r][ch]; n       g = gs[l + 1][ch] ^ gs[lCh + 1][ch] ^ ge[r][ch]; n     } else { n       int lCh = bw[r][ch]; n       if (lCh < l) continue; n       g = gs[l][ch] ^ gs[lCh + 1][ch] ^ ge[r][ch]; n     } n     vec.push_back(g); n   } n   return mex(vec); n } n void CalcGE(int i, int c) { n   if (ge[i][c] >= 0) return; n   if (A[i] == c) { n     ge[i][c] = 0; n     return; n   } n   int l = bw[i][c], r = i + 1; n   ge[i][c] = G(l, r); n } n void CalcGS(int i, int c) { n   if (gs[i][c] >= 0) return; n   CalcGS(fw[i - 1][c] + 1, c); n   if (A[i] == c) { n     gs[i][c] = 0 ^ gs[fw[i - 1][c] + 1][c]; n     return; n   } n   int g = G(i - 1, fw[i - 1][c]) ^ gs[fw[i - 1][c] + 1][c]; n   gs[i][c] = g; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   { n     string s; n     cin >> s; n     n = s.size(); n     for (int i = 0; i <= n; i++) n       for (int ch = 0; ch < 26; ch++) gs[i][ch] = ge[i][ch] = -1; n     for (int ch = 0; ch < 26; ch++) gs[0][ch] = gs[n + 1][ch] = 0; n     for (int i = 0; i < n; i++) A[i + 1] = s[i] -  a ; n     for (int ch = 0; ch < 26; ch++) { n       int lastChSeen = n + 1; n       for (int i = n; i--;) { n         fw[i + 1][ch] = lastChSeen; n         if (A[i + 1] == ch) lastChSeen = i + 1; n       } n       fw[0][ch] = lastChSeen; n       lastChSeen = 0; n       bw[0][ch] = lastChSeen; n       for (int i = 0; i < n; i++) { n         bw[i + 1][ch] = lastChSeen; n         if (A[i + 1] == ch) lastChSeen = i + 1; n       } n     } n   } n   int q; n   cin >> q; n   while (q--) { n     int l, r; n     cin >> l >> r; n     if (l == r) { n       cout <<  Alice n ; n       continue; n     } n     int g = G(l - 1, r + 1); n     if (g == 0) n       cout <<  Bob n ; n     else n       cout <<  Alice n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = 2 * acos(0.0); n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count()); n const string DIGITS =  0123456789 ; n const string ALPH =  abcdefghijklmnopqrstuvwxyz ; n template <class T0, class T1> n inline ostream &operator<<(ostream &out, pair<T0, T1> &a) { n   return out <<  {  << a.first <<  ,   << a.second <<  } ; n } n template <class T0, class T1> n inline istream &operator>>(istream &in, pair<T0, T1> &a) { n   return in >> a.first >> a.second; n } n template <class T0, class T1, class T2> n inline ostream &operator<<(ostream &out, tuple<T0, T1, T2> &a) { n   return out <<  {  << get<0>(a) <<  ,   << get<1>(a) <<  ,   << get<2>(a) n              <<  } ; n } n template <class T0, class T1, class T2, class T3> n inline ostream &operator<<(ostream &out, tuple<T0, T1, T2, T3> &a) { n   return out <<  {  << get<0>(a) <<  ,   << get<1>(a) <<  ,   << get<2>(a) n              <<  ,   << get<3>(a) <<  } ; n } n template <class T> n inline ostream &operator<<(ostream &out, vector<T> &a) { n   out <<  [ ; n   for (int i = 0; i < int(a.size()); ++i) n     out << a[i] << vector<string>{ ,  ,  ]   }[i + 1 == a.size()]; n   return out; n } n void smain(); n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cout << setprecision(12) << fixed; n   smain(); n   return 0; n } n const int L = 20; n vector<int> ts; n int used[L]; n int comp[L]; n vector<int> verts[L]; n set<int> g[L]; n vector<int> rg[L]; n void top_sort(int v) { n   used[v] = 1; n   for (int to : g[v]) { n     if (used[to] == 0) { n       top_sort(to); n     } n   } n   ts.push_back(v); n   used[v] = 2; n } n void inv_dfs(int v, int c) { n   used[v] = 1; n   comp[v] = c; n   verts[c].push_back(v); n   for (int to : rg[v]) { n     if (used[to] == 0) { n       inv_dfs(to, c); n     } n   } n   used[v] = 2; n } n const int N = 20; n int mat[N][N]; n int dp[1 << N]; n int mg[N]; n const int oo = 1e9 + 10; n int solve(set<int> &vr) { n   int edges = 0; n   for (int i = 0; i < int(N); ++i) { n     mg[i] = 0; n     for (int j = 0; j < int(N); ++j) { n       edges += mat[i][j]; n       if (mat[i][j]) mg[i] += 1 << j; n     } n   } n   for (int mask = 0; mask < int(1 << N); ++mask) { n     dp[mask] = oo; n   } n   dp[0] = 0; n   for (int mask = 0; mask < int(1 << N); ++mask) { n     for (int i = 0; i < int(N); ++i) n       if (!((mask >> i) & 1)) { n         int nmask = mask + (1 << i); n         int anti = ((1 << N) - 1) ^ nmask; n         int ed = __builtin_popcount(mask & mg[i]); n         dp[nmask] = min(dp[nmask], (dp[mask] + (ed != 0 && vr.count(i)))); n       } n   } n   return dp[(1 << N) - 1]; n } n void smain() { n   int t; n   cin >> t; n   while (t--) { n     ts.clear(); n     for (int i = 0; i < int(L); ++i) { n       comp[i] = 0; n       verts[i].clear(); n       used[i] = 0; n       rg[i].clear(); n       g[i].clear(); n     } n     int n; n     cin >> n; n     string a, b; n     cin >> a >> b; n     for (int i = 0; i < int(n); ++i) n       if (a[i] != b[i]) { n         g[a[i] -  a ].insert(b[i] -  a ); n       } n     vector<set<int>> t(L); n     for (int i = 0; i < int(L); ++i) { n       if (used[i]) continue; n       top_sort(i); n     } n     reverse(ts.begin(), ts.end()); n     for (int v = 0; v < int(L); ++v) { n       for (int to : g[v]) { n         rg[to].push_back(v); n       } n       used[v] = 0; n     } n     int cnt = 0; n     int ans = 0; n     for (auto v : ts) { n       if (used[v]) continue; n       inv_dfs(v, cnt++); n       if (verts[comp[v]].size() != 1) { n         for (int i = 0; i < int(N); ++i) { n           for (int j = 0; j < int(N); ++j) { n             mat[i][j] = 0; n           } n         } n         set<int> vr(verts[comp[v]].begin(), verts[comp[v]].end()); n         for (int v = 0; v < int(L); ++v) { n           for (int to : g[v]) { n             if (vr.count(v) && vr.count(to)) { n               mat[v][to] = 1; n             } n           } n         } n         ans += verts[comp[v]].size() - 1; n         ans += solve(vr); n       } n     } n     for (int v = 0; v < int(L); ++v) { n       for (int to : g[v]) { n         if (comp[v] != comp[to]) { n           t[comp[v]].insert(comp[to]); n         } n       } n     } n     for (int i = 0; i < int(cnt); ++i) { n       t[i].erase(i); n       if (t[i].empty()) continue; n       ans++; n       t[*t[i].begin()].insert(t[i].begin(), t[i].end()); n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n int nextInt() { n   int x; n   scanf( %d , &x); n   return x; n } n double nextDouble() { n   double x; n   scanf( %lf , &x); n   return x; n } n long long nextLong() { n   long long x; n   scanf( %I64d , &x); n   return x; n } n char nextChar() { n   char x; n   scanf( %c , &x); n   return x; n } n void newLine() { printf(  n ); } n long long powM(long long a, long long b, long long MOD) { n   long long x = 1, y = a; n   while (b > 0) { n     if (b % 2 == 1) { n       x = (x * y); n       if (x > MOD) x %= MOD; n     } n     y = (y * y); n     if (y > MOD) y %= MOD; n     b /= 2; n   } n   return x; n } n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } n int countSetBits(long long n) { n   int ans = 0; n   while (n != 0) { n     n -= (n & -n); n     ++ans; n   } n   return ans; n } n long long mod = 1000000007; n long long mod2 = 1000000009; n const int N = 1100; n const int M = 111; n const int LOG = 21; n const long long INF = 1e18; n const long double EPS = 1e-6; n const long double PI = 2 * acos(0); n using namespace std; n int a[N], b[N]; n int main() { n   int n = nextInt(); n   int m = nextInt(); n   int d = 0; n   bool ok = true; n   for (int i = 0; i < m; i++) { n     int x = nextInt(), y = nextInt(); n     a[x] += 1; n     a[y + 1] -= 1; n   } n   for (int i = 1; i <= n; i++) a[i] += a[i - 1]; n   for (int i = 1; i <= n; i++) { n     if (a[i] != 1) { n       cout << i <<     << a[i] << endl; n       ok = false; n       break; n     } n   } n   if (ok) puts( OK ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int qtable[9][9]; n int x_min[9]; n int x_max[9]; n int y_min[9]; n int y_max[9]; n int solve_problem() { n   int n, m, k, s; n   if (scanf( %d %d %d %d , &n, &m, &k, &s) != 4) return 1; n   fill(x_min, x_min + k, numeric_limits<int>::max()); n   fill(x_max, x_max + k, numeric_limits<int>::min()); n   fill(y_min, y_min + k, numeric_limits<int>::max()); n   fill(y_max, y_max + k, numeric_limits<int>::min()); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       int t; n       scanf( %d , &t); n       --t; n       int x = i + j; n       int y = i - j; n       if (x < x_min[t]) x_min[t] = x; n       if (x > x_max[t]) x_max[t] = x; n       if (y < y_min[t]) y_min[t] = y; n       if (y > y_max[t]) y_max[t] = y; n     } n   int prev_q = -1; n   for (int i = 0; i < s; i++) { n     int q; n     scanf( %d , &q); n     --q; n     if (i > 0) qtable[min(prev_q, q)][max(prev_q, q)] = 1; n     prev_q = q; n   } n   int result = 0; n   for (int i = 0; i < k; i++) n     for (int j = i; j < k; j++) n       if (qtable[i][j]) { n         int cand = abs(x_min[i] - x_max[j]); n         if (cand > result) result = cand; n         cand = abs(x_max[i] - x_min[j]); n         if (cand > result) result = cand; n         cand = abs(y_min[i] - y_max[j]); n         if (cand > result) result = cand; n         cand = abs(y_max[i] - y_min[j]); n         if (cand > result) result = cand; n       } n   printf( %d n , result); n   return 0; n } n int main() { n   solve_problem(); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:66777216 ) n using namespace std; n void sIO(); n void iIO(); n void fIO(string fn); n const long long INF = 1000000003LL; n const long long BI = (long long)1e18; n int n; n long long c, a[1111], b[1111], lg, l, r, m; n long long check(long long x) { n   long long ret = 0, cur; n   for (int i = 0; i < n; ++i) { n     cur = a[i] * x; n     if (cur > INF || cur < 0) return INF; n     ret += a[i] * x / b[i] + 1; n   } n   return min(ret, INF); n } n int main() { n   sIO(); n   scanf( %d %I64d , &n, &c); n   for (int i = 0; i < n; ++i) scanf( %I64d %I64d , a + i, b + i); n   if (check(BI) == c) { n     printf( -1 ); n     ; n     return 0; n   } n   l = 1; n   r = BI; n   while (r - l > 1) { n     m = (l + r) >> 1; n     if (check(m) < c) n       l = m; n     else n       r = m; n   } n   if (check(l) < c) ++l; n   if (check(l) != c) { n     printf( 0 ); n     return 0; n   } n   lg = l; n   l = 1; n   r = BI; n   while (r - l > 1) { n     m = (l + r) >> 1; n     if (check(m) > c) n       r = m; n     else n       l = m; n   } n   printf( %I64d , r - lg); n   return 0; n } n inline void sIO() {} n inline void iIO() { n   freopen( input.txt ,  r , stdin); n   freopen( output.txt ,  w , stdout); n } n inline void fIO(string fn) { n   freopen((fn +  .in ).c_str(),  r , stdin); n   freopen((fn +  .out ).c_str(),  w , stdout); n } n


#include <bits/stdc++.h> n using namespace std; n int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; n int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; n const double PI = acos(-1.0); n const double EPS = 1e-6; n const int MOD = (int)1e9 + 7; n const int maxn = (int)2e5 + 5; n int cnt[maxn]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, m, i, j; n   cin >> n >> m; n   set<int> s; n   for (i = 1; i <= (m); i++) { n     int x; n     cin >> x; n     cnt[x]++; n     s.insert(x); n     if ((int)s.size() == n) { n       cout <<  1 ; n       for (j = 1; j <= (n); j++) { n         cnt[j]--; n         if (cnt[j] == 0) s.erase(j); n       } n     } else n       cout <<  0 ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long two(int x) { return 1LL << x; } n int get(long long p, int i) { return (p >> (i - 1)) & 1; } n long long count(int n, int k, long long pre) { n   long long ret = 0; n   bool rev = true, inv = true; n   for (int i = 1; i + i <= n; i++) { n     if (i <= k && n - i + 1 <= k && get(pre, i) != get(pre, n - i + 1)) n       rev = false; n     if (rev) n       if (n - 2 * i == 0) n         ret += two(max(0, i - k)); n       else if (n - 2 * i == 1) n         ret += two(max(0, i + 1 - k)); n       else if ((i >= k || !get(pre, i + 1)) && n                (n - i - 1 >= k || get(pre, n - i))) n         ret += two(max(0, n - i - 1 - k - (k <= i))); n     if (i <= k && n - i + 1 <= k && get(pre, i) == get(pre, n - i + 1)) n       inv = false; n     if (inv) n       if (n - 2 * i == 0) n         ret += two(max(0, i - k)); n       else if (n - 2 * i == 1) { n         if (i >= k || !get(pre, i + 1)) ret += two(max(0, i - k)); n       } else if ((i >= k || !get(pre, i + 1)) && n                  (n - i - 1 >= k || !get(pre, n - i))) n         ret += two(max(0, n - i - 1 - k - (k <= i))); n   } n   return ret; n } n int main() { n   int n; n   long long m; n   cin >> n >> m; n   if (m >= count(n, 1, 0LL)) { n     cout << -1 << endl; n     return 0; n   } n   long long pre = 0; n   for (int i = 2; i <= n; i++) { n     long long tmp = count(n, i, pre); n     if (m >= tmp) { n       m -= tmp; n       pre += two(i - 1); n     } n   } n   for (int i = 1; i <= n; i++) cout << get(pre, i); n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)2e5 + 50, LOGN = 17; n const int INF = (int)1e9; n int n, k; n int ord[N], in[N], tim = 0; n char las[N]; n int lc[N], rc[N]; n int res[N]; n string str; n void dfs(int v) { n   if (lc[v] != -1) dfs(lc[v]); n   ord[tim] = v; n   in[v] = tim++; n   if (rc[v] != -1) dfs(rc[v]); n } n void solve(int v, int& rem) { n   int la = -1; n   int cur = v; n   for (int i = 0; i < (rem); ++i) { n     if (cur == -1) break; n     if (las[cur] !=     && las[cur] > str[cur]) { n       la = i; n     } n     cur = lc[cur]; n   } n   cur = v; n   vector<int> vs; n   for (int i = 0; i < (la + 1); ++i) { n     res[cur] = 1; n     rem--; n     vs.push_back(cur); n     cur = lc[cur]; n   } n   while (!vs.empty()) { n     if (rc[vs.back()] != -1) solve(rc[vs.back()], rem); n     vs.pop_back(); n   } n } n void print_ans(int v) { n   if (lc[v] != -1) print_ans(lc[v]); n   cout << str[v]; n   if (res[v]) cout << str[v]; n   if (rc[v] != -1) print_ans(rc[v]); n } n int pos[256]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n >> k; n   cin >> str; n   for (int i = 0; i < (n); ++i) { n     cin >> lc[i] >> rc[i]; n     lc[i]--, rc[i]--; n   } n   dfs(0); n   fill(pos, pos + 256, INF); n   for (int i = n - 1; i >= 0; i--) { n     pos[str[ord[i]]] = i; n     char f =    ; n     for (char c =  a ; c <=  z ; c++) { n       if (c != str[ord[i]] && pos[f] > pos[c]) f = c; n     } n     las[ord[i]] = f; n   } n   solve(0, k); n   assert(k >= 0); n   print_ans(0); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   vector<int> a(n); n   for (size_t i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort(a.begin(), a.end(), greater<int>()); n   int x = a[0], y = 0; n   for (size_t i = 0; i < n - 1; i++) { n     if (x % a[i] != 0 || a[i] == a[i + 1]) { n       y = a[i]; n       break; n     } n   } n   cout << x <<     << y; n } n


#include <bits/stdc++.h> n using namespace std; n unordered_map<long long, vector<long long>> m3; n vector<long long int> v; n long long a; n int dfs(long long i, long long p) { n   long long k, k1, j, t; n   k = -1; n   k1 = 0; n   for (j = 0; j < m3[i].size(); j++) { n     long long d = m3[i][j]; n     if (d != p) { n       t = dfs(d, i); n       if (t == 1) { n         if (v[d] != v[i]) { n           k1 = -1; n         } n       } else { n         k1 = -1; n       } n     } n   } n   if (k1 == 0) { n     return 1; n   } n   return -1; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   long long i, j, b, n, x, y, z, t, k, sum, sum1; n   vector<long long int> v1, v2, v3, v4; n   string s, s1, s2; n   unordered_map<long long, long long> m1, m2, m7; n   unordered_map<long long, vector<long long>> m; n   t = 1; n   while (t--) { n     cin >> n; n     for (i = 0; i < n - 1; i++) { n       cin >> a >> b; n       m3[a].push_back(b); n       m3[b].push_back(a); n     } n     a = 0; n     v.push_back(0); n     for (i = 0; i < n; i++) { n       cin >> j; n       v.push_back(j); n     } n     j = 1; n     x = -1; n     for (i = 1; i <= n; i++) { n       for (k = 0; k < m3[i].size(); k++) { n         if (v[i] != v[m3[i][k]]) { n           x = i; n           y = m3[i][k]; n           break; n         } n       } n     } n     if (x == -1) { n       cout <<  YES  << endl; n       cout << 1; n       return 0; n     } n     for (j = 0; j < m3[x].size(); j++) { n       i = dfs(m3[x][j], x); n       if (i == -1) break; n     } n     if (i == 1) { n       cout <<  YES  << endl; n       cout << x; n       return 0; n     } n     x = y; n     for (j = 0; j < m3[x].size(); j++) { n       i = dfs(m3[x][j], x); n       if (i == -1) break; n     } n     if (i == 1) { n       cout <<  YES  << endl; n       cout << y; n       return 0; n     } n     cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   long long t = 1; n   while (t--) { n     long long n, d; n     cin >> n >> d; n     vector<long long> temp(n); n     vector<long long> temp2(n); n     for (long long i = 0; i < n; i++) { n       cin >> temp[i]; n     } n     for (long long i = 0; i < n; i++) { n       cin >> temp2[i]; n     } n     long long i = 0; n     long long j = n - 1; n     if (d == 1) { n       cout << 1 << endl; n       continue; n     } n     long long score = temp[d - 1] + temp2[0]; n     long long ans = d; n     while (i < d - 1) { n       if (temp[i] + temp2[j] <= score) { n         ans--; n         i++; n         j--; n       } else { n         i++; n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ifstream ff( file.txt ); n   int n, k; n   cin >> n >> k; n   string s1; n   cin >> s1; n   n = s1.length(); n   if (k == 0) { n     cout << s1 << endl; n     return 0; n   } n   int j = 0; n   bool b1 = false, b2 = false; n   for (int i = 0; i < n - 2; i++) { n     j++; n     if ((i + 1) % 2 != 0 && s1.substr(i, 3) ==  447 ) { n       b1 = true; n       break; n     } else if ((i + 1) % 2 != 0 && s1.substr(i, 3) ==  477 ) { n       b2 = true; n       break; n     } n   } n   if (b1 == false && b2 == false) { n     j++; n   } n   if (b2 == true) { n     j--; n   } n   for (int i = 0; i < j; i++) { n     if (s1.substr(i, 2) ==  47 ) { n       if ((i + 1) % 2 == 1) { n         s1[i] =  4 ; n         s1[i + 1] =  4 ; n       } else { n         s1[i] =  7 ; n         s1[i + 1] =  7 ; n       } n       k--; n     } n     if (k == 0) { n       cout << s1 << endl; n       return 0; n     } n   } n   if (b1 == true) { n     if (k % 2 != 0) { n       if (j % 2 == 0) { n         s1[j] =  4 ; n       } else { n         s1[j] =  7 ; n       } n     } n   } n   if (b2 == true) { n     if (k % 2 != 0) { n       if (j % 2 == 0) { n         s1[j + 1] =  4 ; n       } else { n         s1[j + 1] =  7 ; n       } n     } n   } n   cout << s1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int get() { n   int x = 0; n   char s = getchar(); n   while (s <  0  || s >  9 ) s = getchar(); n   while (s >=  0  && s <=  9 ) n     x = (x << 3) + (x << 1) + (s ^ 48), s = getchar(); n   return x; n } n int Min(const int x, const int y) { n   if (x < y) return x; n   return y; n } n const int M = 1e5 + 5, mo = 1e9 + 7; n int n, m, head[M], cntedge, vis[M], dfn[M], low[M], tot, cntscc, scc[M], siz[M], n     dep[M], f[M][17], w[M]; n vector<int> G[M]; n stack<int> st; n struct edge { n   int to, nxt; n   edge() {} n   edge(const int T, const int NX) { to = T, nxt = NX; } n } e[M << 1]; n void add(const int u, const int v) { n   e[++cntedge] = edge(v, head[u]), head[u] = cntedge; n } n int pow(int x, int k) { n   int ans = 1; n   while (k) { n     if (k & 1) ans = 1ll * ans * x % mo; n     x = 1ll * x * x % mo; n     k >>= 1; n   } n   return ans; n } n void tarjan(const int u, const int fa) { n   dfn[u] = low[u] = ++tot; n   vis[u] = 1; n   st.push(u); n   int v; n   for (int i = head[u]; i; i = e[i].nxt) { n     v = e[i].to; n     if (v == fa || vis[v] == 2) continue; n     if (!vis[v]) tarjan(v, u); n     low[u] = Min(low[u], low[v]); n   } n   if (dfn[u] == low[u]) { n     ++cntscc; n     do { n       v = st.top(), st.pop(); n       scc[v] = cntscc; n       vis[v] = 2; n       ++siz[cntscc]; n     } while (v ^ u); n   } n } n void dfs(const int x, const int fa) { n   dep[x] = dep[fa] + 1; n   f[x][0] = fa; n   w[x] = w[fa] + (siz[x] > 1); n   for (int i = 1; i < 17; ++i) f[x][i] = f[f[x][i - 1]][i - 1]; n   for (int i = 0; i < G[x].size(); ++i) n     if (G[x][i] ^ fa) dfs(G[x][i], x); n } n void adjust(int &u, const int val) { n   for (int i = 16; i >= 0; --i) n     if (dep[f[u][i]] >= val) u = f[u][i]; n } n int lca(int u, int v) { n   if (dep[u] > dep[v]) n     adjust(u, dep[v]); n   else if (dep[u] < dep[v]) n     adjust(v, dep[u]); n   if (u == v) return u; n   for (int i = 16; i >= 0; --i) n     if (f[u][i] ^ f[v][i]) u = f[u][i], v = f[v][i]; n   return f[u][0]; n } n int main() { n   n = get(), m = get(); n   for (int u, v; m--;) { n     u = get(), v = get(); n     add(u, v), add(v, u); n   } n   for (int i = 1; i <= n; ++i) n     if (!dfn[i]) tarjan(i, 0); n   for (int i = 1; i <= n; ++i) n     for (int j = head[i]; j; j = e[j].nxt) n       if (scc[i] ^ scc[e[j].to]) G[scc[i]].push_back(scc[e[j].to]); n   dfs(1, 0); n   for (int q = get(), u, v, x, k; q--;) { n     u = scc[get()], v = scc[get()], x = lca(u, v); n     k = w[u] + w[v] - (w[x] << 1) + (siz[x] > 1); n     printf( %d n , pow(2, k)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct st { n   int t, x, id; n }; n const int INF = 1000 * 1000 * 1000; n bool operator<(const st &a, const st &b) { n   return a.x < b.x || a.x == b.x && a.t < b.t; n } n int main() { n   st st_inf; n   st_inf.x = INF; n   st_inf.t = INF; n   st_inf.id = INF; n   int N, M; n   queue<st> ost; n   cin >> N >> M; n   st r; n   for (int i = 0; i < N; ++i) { n     scanf( %d%d , &r.t, &r.x); n     r.id = i; n     ost.push(r); n   } n   int OST = N; n   int BUS = 0; n   vector<st> bus; n   long long int T = 0; n   vector<long long int> R(100005); n   while (BUS || OST) { n     while (OST && BUS < M) { n       st t = ost.front(); n       T = max(T, (long long int)t.t); n       bus.push_back(t); n       ost.pop(); n       OST--; n       BUS++; n     } n     sort(bus.begin(), bus.end()); n     queue<st> w; n     int y = 0; n     while (y < bus.size() && bus[y].t != INF) { n       w.push(bus[y]); n       y++; n     } n     BUS = 0; n     int L = 0; n     bus.clear(); n     while (!w.empty()) { n       int X; n       X = w.front().x; n       int cnt_v = 1; n       R[w.front().id] = T + (X - L); n       w.pop(); n       while (!w.empty()) { n         if (w.front().x == X) { n           R[w.front().id] = T + (X - L); n           w.pop(); n           cnt_v++; n         } else { n           break; n         } n       } n       T += (X - L) + (int)(cnt_v / 2) + 1; n       L = X; n       if (w.empty()) { n         T += L; n       } n     } n   } n   for (int i = 0; i < N; ++i) { n     cout << R[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long sq(long long k) { return k * k; } n long long knan(long long k, long long n) { n   if (n == 1) n     return k; n   else if (n == 0) n     return 1; n   else { n     if (n % 2 == 0) n       return sq(knan(k, n / 2)) % 1000000007; n     else n       return (k * knan(k, n - 1)) % 1000000007; n   } n } n int main() { n   string s; n   int p[4], n; n   for (int i = 0; i < 4; i++) p[i] = 0; n   cin >> n; n   cin >> s; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  A ) p[0]++; n     if (s[i] ==  T ) p[1]++; n     if (s[i] ==  C ) p[2]++; n     if (s[i] ==  G ) p[3]++; n   } n   int max(0), brmax(0); n   for (int i = 0; i < 4; i++) n     if (p[i] > max) max = p[i]; n   for (int i = 0; i < 4; i++) n     if (p[i] == max) brmax++; n   cout << knan(brmax, n) % 1000000007 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t; n   cin >> t; n   while (t--) { n     long long int n, k; n     cin >> n >> k; n     long long int a, b, c, d; n     cin >> a >> b; n     cin >> c >> d; n     if (a > c || (a == c && b > d)) { n       swap(a, c); n       swap(b, d); n     } n     long long int per = max(0LL, c - b); n     long long int capacity = max(b, d) - a; n     long long int current = max(0LL, min(b, d) - c); n     capacity = capacity - current; n     k = max(0LL, k - n * current); n     if (k == 0) { n       cout << 0 << endl; n       continue; n     } n     long long int ans = 0; n     ans += per; n     long long int num = min(k, capacity); n     ans += num; n     k -= num; n     n--; n     if (k == 0) { n       cout << ans << endl; n       continue; n     } n     if (per + capacity >= 2 * capacity) { n       ans += 2 * k; n     } else { n       long long int divi = min(k / capacity, n); n       ans += (per + capacity) * (divi); n       k -= divi * capacity; n       if (divi == n || k >= capacity) { n         ans += 2 * k; n       } else { n         if (k + per < 2 * k) n           ans += k + per; n         else n           ans += 2 * k; n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void rd(T &x) { n   char ch; n   x = 0; n   bool fl = false; n   while (!isdigit(ch = getchar())) (ch ==  - ) && (fl = true); n   for (x = (ch ^  0 ); isdigit(ch = getchar()); x = x * 10 + (ch ^  0 )) n     ; n   (fl == true) && (x = -x); n } n template <class T> n inline void ot(T x) { n   x / 10 ? ot(x / 10) : putchar(x % 10 +  0 ); n } n template <class T> n inline void prt(T a[], int st, int nd) { n   for (register int i = st; i <= nd; ++i) printf( %lld  , a[i]); n   putchar(  n ); n } n namespace Miracle { n const int N = 1e5 + 10; n const int mod = 1e9 + 7; n int n; n long long qm(long long x, long long y) { n   long long ret = 1; n   while (y) { n     if (y & 1) ret = ret * x % mod; n     x = x * x % mod; n     y >>= 1; n   } n   return ret; n } n long long jie[N], inv[N]; n long long m25[N], i26[N]; n int iv; n int exi[N]; n int ans[450][N]; n int cnt; n long long C(int n, int m) { n   if (n < 0 || m < 0 || n < m) return 0; n   return jie[n] * inv[m] % mod * inv[n - m] % mod; n } n char s[N]; n int main() { n   jie[0] = 1; n   for (register int i = 1; i <= N - 5; ++i) jie[i] = jie[i - 1] * i % mod; n   inv[N - 5] = qm(jie[N - 5], mod - 2); n   for (register int i = N - 6; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % mod; n   int m, t; n   iv = qm(26, mod - 2); n   m25[0] = 1, i26[0] = 1; n   for (register int i = 1; i <= N - 5; ++i) n     m25[i] = m25[i - 1] * 25 % mod, i26[i] = i26[i - 1] * iv % mod; n   rd(t); n   scanf( %s , s + 1); n   m = strlen(s + 1); n   int op; n   while (t--) { n     rd(op); n     if (op == 1) { n       scanf( %s , s + 1); n       m = strlen(s + 1); n     } else { n       rd(n); n       if (!exi[m]) { n         exi[m] = ++cnt; n         for (register int i = m; i <= N - 5; ++i) { n           ans[cnt][i] = ((long long)ans[cnt][i - 1] + n                          C(i - 1, m - 1) * m25[i - m] % mod * i26[i] % mod) % n                         mod; n         } n       } n       long long now = qm(26, n) * ans[exi[m]][n] % mod; n       printf( %lld n , now); n     } n   } n   return 0; n } n }  // namespace Miracle n signed main() { n   Miracle::main(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, b, m; n int a[100009], sum[100009]; n map<int, int> h; n int main() { n   cin >> b >> m >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     sum[i] = (sum[i - 1] + a[i]) % (b - 1); n   } n   long long zero = 0, t = 0; n   for (int i = 1; i <= n; i++) { n     if (a[i] == 0) n       t++; n     else { n       zero += 1ll * t * (t + 1) / 2; n       t = 0; n     } n   } n   if (t) zero += 1ll * t * (t + 1) / 2; n   if (m == 0) { n     cout << zero << endl; n     return 0; n   } n   long long ans = 0; n   h[0]++; n   for (int i = 1; i <= n; i++) { n     int t = ((sum[i] - m) % (b - 1) + (b - 1)) % (b - 1); n     ans += h[t]; n     h[sum[i]]++; n   } n   if (m == b - 1) ans -= zero; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int c(int x) { n   int rev = 0; n   int tambah = 1; n   while (x != 0) { n     int temp = x % 10; n     if (temp == 4 || temp == 7) { n       rev += (tambah * (temp)); n       tambah *= 10; n     } n     x /= 10; n   } n   return rev; n } n int main() { n   int a, b; n   scanf( %d %d , &a, &b); n   a++; n   while (c(a) != b) { n     a++; n   } n   printf( %d n , a); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD(1000000007); n const int INF((1 << 30) - 1); n const int MAXN(55); n int a[MAXN]; n string b[MAXN]; n string gen(int x) { n   string ret =   ; n   if (x < 26) n     ret +=  A ; n   else n     ret +=  B ; n   ret += ( a  + x % 26); n   return ret; n } n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n - k + 1; i++) { n     string s; n     cin >> s; n     a[i] = (s ==  YES ); n   } n   int now = 0; n   for (int i = 0; i < k; i++) b[i] = gen(now++); n   if (a[0] == 0) b[k - 1] = b[0]; n   for (int i = 1; i <= n - k; i++) { n     if (a[i] == 1) n       b[i + k - 1] = gen(now++); n     else n       b[i + k - 1] = b[i]; n   } n   for (int i = 0; i < n; i++) cout << b[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 15; n int k, n, m, x, y, ans; n int dz[6] = {0, 0, 0, 0, 1, -1}; n int dx[6] = {0, 0, 1, -1, 0, 0}; n int dy[6] = {1, -1, 0, 0, 0, 0}; n char plt[N][N][N]; n bool mark[N][N][N]; n bool isval(int a, int b, int c) { n   if (a < k && a >= 0 && b < n && b >= 0 && c < m && c >= 0 && n       plt[a][b][c] ==  . ) { n     return true; n   } n   return false; n } n void dfs(int a, int b, int c) { n   mark[a][b][c] = true; n   ans++; n   for (int i = 0; i < 6; i++) { n     if (isval(a + dz[i], b + dx[i], c + dy[i]) && n         !mark[a + dz[i]][b + dx[i]][c + dy[i]]) { n       dfs(a + dz[i], b + dx[i], c + dy[i]); n     } n   } n   return; n } n int main() { n   cin >> k >> n >> m; n   for (int i = 0; i < k; i++) { n     for (int j = 0; j < n; j++) { n       for (int l = 0; l < m; l++) { n         cin >> plt[i][j][l]; n       } n     } n   } n   cin >> x >> y; n   x--; n   y--; n   dfs(0, x, y); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using vi = vector<int>; n using vvi = vector<vi>; n int main() { n   int N; n   cin >> N; n   vvi tree(N); n   for (int i = 0; i < N - 1; ++i) { n     int a, b; n     cin >> a >> b; n     a--; n     b--; n     tree[a].push_back(b); n     tree[b].push_back(a); n   } n   int min = 0, max = 0; n   vi min_v(N), max_v(N); n   for (int i = 0; i < N; ++i) min_v[i] = max_v[i] = i; n   vi degree(N); n   queue<int> q; n   for (int u = 0; u < N; ++u) n     if ((degree[u] = tree[u].size()) == 1) q.push(u); n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     int n = tree[u][0]; n     for (int v : tree[u]) n       if (degree[v] > 0) n = v; n     if (min_v[u] == u) { n       swap(min_v[u], min_v[n]); n       min += 2; n     } n     if (degree[n] > 0) { n       degree[u] = 0; n       if (--degree[n] == 1) q.push(n); n     } n   } n   cout << min << endl; n   for (int u = 0; u < N; ++u) cout << min_v[u] + 1 <<    ; n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n inline void file() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n } n int main() { n   char b[10000]; n   int a; n   cin >> a; n   int c = 0; n   for (int i = 0; i < a; ++i) { n     cin >> b[0] >> b[1] >> b[2]; n     if (b[0] ==  -  and b[1] ==  -  or b[2] ==  -  and b[1] ==  - ) n       c--; n     else n       c++; n   } n   cout << c; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1000005]; n int main() { n   int t, n; n   cin >> t; n   while (t--) { n     cin >> n; n     int g = 0, s = 0, b = 0; n     int m = n / 2; n     for (int i = 1; i <= n; i++) { n       cin >> a[i]; n     } n     int i = 1; n     while (a[i] == a[1] && i <= m) { n       i++; n       g++; n     } n     int j = i; n     while (a[i] == a[j] && i <= m) { n       i++; n       s++; n     } n     while (s <= g && i <= m) { n       int k = i; n       while (a[i] == a[k] && i <= m) { n         s++; n         i++; n       } n     } n     while (a[i] != a[m + 1] && i <= m) { n       b++; n       i++; n     } n     if (g >= s || g >= b) { n       cout <<  0 0 0 n ; n       continue; n     } n     cout << g <<     << s <<     << b <<     << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 500; n char s[N]; n int son[N][26]; n int fail[N], pos[N]; n int n, m; n int cnt; n inline void insert(char s[], int n, int id) { n   int i, cur = 0; n   for (i = 1; i <= n; i++) { n     if (!son[cur][s[i] -  a ]) son[cur][s[i] -  a ] = ++cnt; n     cur = son[cur][s[i] -  a ]; n   } n   pos[id] = cur; n } n queue<int> Q; n inline void build() { n   int i; n   for (i = 0; i <= 25; i++) n     if (son[0][i]) Q.push(son[0][i]); n   while (!Q.empty()) { n     int x = Q.front(); n     Q.pop(); n     for (i = 0; i <= 25; i++) n       if (!son[x][i]) n         son[x][i] = son[fail[x]][i]; n       else n         fail[son[x][i]] = son[fail[x]][i], Q.push(son[x][i]); n   } n } n struct Edge { n   int to, nxt; n }; n Edge e[N << 1]; n int lst[N]; n inline void add(int u, int v) { n   static int cnt = 0; n   e[++cnt] = (Edge){v, lst[u]}, lst[u] = cnt; n } n int dfn[N], low[N]; n inline void dfs(int x) { n   static int idx = 0; n   int i; n   dfn[x] = ++idx; n   for (i = lst[x]; ~i; i = e[i].nxt) dfs(e[i].to); n   low[x] = idx; n } n int C[N]; n inline void update(int x, int delta) { n   while (x <= cnt + 1) C[x] += delta, x += ((x) & -(x)); n } n inline int query(int x) { n   int res = 0; n   while (x > 0) res += C[x], x -= ((x) & -(x)); n   return res; n } n int del[N]; n int main() { n   int i; n   scanf( %d%d , &m, &n); n   for (i = 1; i <= n; i++) scanf(  %s  , s + 1), insert(s, strlen(s + 1), i); n   build(); n   for (i = 0; i <= cnt; i++) lst[i] = -1; n   for (i = 1; i <= cnt; i++) add(fail[i], i); n   dfs(0); n   for (i = 1; i <= n; i++) update(dfn[pos[i]], 1), update(low[pos[i]] + 1, -1); n   while (m--) { n     scanf(  %s  , s), n = strlen(s + 1); n     if (s[0] ==  ? ) { n       int cur = 0, ans = 0; n       for (i = 1; i <= n; i++) { n         if (!son[cur][s[i] -  a ]) n           cur = fail[cur]; n         else n           cur = son[cur][s[i] -  a ]; n         ans += query(dfn[cur]); n       } n       printf( %d n , ans); n     } else { n       int id = 0; n       for (i = 1; i <= n; i++) id = (id << 1) + (id << 3) + (s[i] ^ 48); n       if (s[0] ==  - ) { n         if (!del[id]) n           update(dfn[pos[id]], -1), update(low[pos[id]] + 1, 1), del[id] = 1; n       } else if (del[id]) n         update(dfn[pos[id]], 1), update(low[pos[id]] + 1, -1), del[id] = 0; n     } n   } n   return 0; n } n


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


#include <bits/stdc++.h> n int main() { n   int n, k; n   scanf( %d %d , &n, &k); n   while (k > 0) { n     if (n % 10 == 0) n       n /= 10; n     else n       n--; n     k--; n   } n   printf( %d , n); n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, s, tmp1, tmp2; n vector<long long> ans; n vector<vector<long long>> g(100000); n bool vs[2][100000]; n bool vs1[100000] = {0}, rc[100000] = {0}; n bool a = false, w = false, d = false, t = false; n long long cnt = 0; n void hasc(long long v) { n   vs1[v - 1] = true; n   rc[v - 1] = true; n   for (auto el : g[v - 1]) { n     if (!vs1[el - 1]) n       hasc(el); n     else if (rc[el - 1]) { n       d = true; n     } n   } n   rc[v - 1] = false; n } n void dfs(long long v) { n   ans.push_back(v); n   vs[a][v - 1] = true; n   if (a && !(g[v - 1].size())) { n     w = 1; n     return; n   } n   a = !a; n   for (auto el : g[v - 1]) n     if (!vs[a][el - 1] && !w) { n       dfs(el); n     } n   a = !a; n   if (w) return; n   ans.pop_back(); n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> tmp1; n     for (int j = 0; j < tmp1; j++) { n       cin >> tmp2; n       g[i].push_back(tmp2); n     } n   } n   cin >> s; n   dfs(s); n   hasc(s); n   if (w) { n     cout <<  Win  << endl; n     for (auto el : ans) cout << el <<    ; n     cout << endl; n   } else if (d) { n     cout <<  Draw  << endl; n   } else n     cout <<  Lose  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<pair<int, int> > > Adj; n vector<int> Col; n bool DFS(int u, int f) { n   Col[u] = 1 + f; n   bool pos = 0; n   for (auto i : Adj[u]) { n     if (Col[i.first]) { n       if ((f ^ i.second) == Col[i.first] - 1) n         continue; n       else n         return 1; n     } n     pos |= DFS(i.first, f ^ i.second); n   } n   return pos; n } n template <typename T> n T fast_exp(T base, T power, T M = 0) { n   if (M) base %= M; n   T result = 1; n   while (power) { n     if (power & 1) result *= base; n     power >>= 1; n     base *= base; n     if (M) { n       base %= M; n       result %= M; n     } n   } n   return result; n } n long long Calc(string S, int lA, int lB) { n   Adj.clear(); n   Col.clear(); n   Adj.resize(lA + lB + 1); n   Col.resize(lA + lB + 1); n   for (int x = 0; x < lA; x++) { n     Adj[x].push_back({lA - x - 1, 0}); n     Adj[lA - x - 1].push_back({x, 0}); n   } n   for (int x = 0; x < lB; x++) { n     Adj[lA + x].push_back({lA + lB - x - 1, 0}); n     Adj[lA + x].push_back({lA + lB - x - 1, 0}); n   } n   for (int x = 0; x < lA; x++) { n     if (S[x] ==  ? ) continue; n     if (x < lA - lB) { n       Adj[x].push_back({lA + lB, S[x] -  0 }); n       Adj[lA + lB].push_back({x, S[x] -  0 }); n     } else { n       Adj[x].push_back({lB + x, S[x] -  0 }); n       Adj[lB + x].push_back({x, S[x] -  0 }); n     } n   } n   Adj[lA + lB].push_back({lA, 1}); n   Adj[lA].push_back({lA + lB, 1}); n   int cnt = 0; n   for (int x = 0; x < lA + lB + 1; x++) { n     if (Col[x]) continue; n     if (DFS(x, 0)) return 0; n     cnt++; n   } n   return fast_exp<long long>(2, cnt - 1, 998244353); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   string S; n   cin >> S; n   long long ans = 0; n   int lA = S.size(); n   for (int lB = 1; lB < lA; lB++) { n     ans += Calc(S, lA, lB); n     ans %= 998244353; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N; n char s[1005], z[1005]; n int solve1() { n   int ans = 0; n   int lz, rz, ls, rs; n   lz = ls = 0; n   rz = rs = N - 1; n   while (ls <= rs) { n     if (z[rz] >= s[rs]) n       rz--, rs--; n     else n       ans++, lz++, rs--; n   } n   return ans; n } n int solve2() { n   int ans = 0; n   int lz, rz, ls, rs; n   lz = ls = 0; n   rz = rs = N - 1; n   while (ls <= rs) { n     if (z[rz] > s[rs]) n       ans++, rz--, rs--; n     else n       lz++, rs--; n   } n   return ans; n } n int main() { n   scanf( %d%s%s , &N, s, z); n   sort(s, s + N); n   sort(z, z + N); n   printf( %d n%d , solve1(), solve2()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int rd() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); n   return x * f; n } n const int N = 100009; n int n, m, o, a[N], pre[N], suf[N], numq, tr[N]; n long long ans[N]; n set<int> s[N]; n struct node { n   int opt, x, y, v, id; n   inline bool operator<(const node& rhs) const { return x < rhs.x; } n } p[N * 7], q[N * 7]; n int suf_(int v, int x) { return *s[v].upper_bound(x); } n int pre_(int v, int x) { n   set<int>::iterator it = s[v].lower_bound(x); n   --it; n   return *it; n } n void link(int x, int y) { n   ++o, p[o].opt = 0, p[o].x = x, p[o].y = pre[x], p[o].v = pre[x] - x, n        p[o].id = 0; n   pre[x] = y; n   ++o, p[o].opt = 0, p[o].x = x, p[o].y = pre[x], p[o].v = x - pre[x], n        p[o].id = 0; n } n void add(int x, int d) { n   if (!x) return; n   for (int i = x; i <= n; i += i & -i) tr[i] += d; n } n int ask(int x) { n   int res = 0; n   for (int i = x; i > 0; i -= i & -i) res += tr[i]; n   return res; n } n void clear(int x) { n   if (!x) return; n   for (int i = x; i <= n; i += i & -i) tr[i] = 0; n } n void cdq(int l, int r) { n   if (l == r) return; n   int mid = (l + r) >> 1; n   cdq(l, mid), cdq(mid + 1, r); n   for (int i = mid + 1, j = l; i <= r; ++i) { n     if (!p[i].opt) continue; n     for (; j <= mid && p[j].x <= p[i].x; ++j) n       if (!p[j].opt) add(p[j].y, p[j].v); n     ans[p[i].id] += ask(n) - ask(p[i].y - 1); n   } n   for (int i = l; i <= mid; ++i) n     if (!p[i].opt) clear(p[i].y); n   merge(p + l, p + mid + 1, p + mid + 1, p + r + 1, q + l); n   for (int i = l; i <= r; ++i) p[i] = q[i]; n } n signed main() { n   n = rd(), m = rd(); n   for (int i = 1; i <= n; ++i) a[i] = rd(), s[a[i]].insert(i); n   for (int i = 1; i <= n; ++i) s[i].insert(0), s[i].insert(n + 1); n   for (int i = 1; i <= n; ++i) n     pre[i] = pre_(a[i], i), suf[i] = suf_(a[i], i), ++o, p[o].opt = 0, n     p[o].x = i, p[o].y = pre[i], p[o].v = i - pre[i], p[o].id = 0; n   for (int i = 1; i <= m; ++i) { n     int opt = rd(), x = rd(), y = rd(); n     if (opt == 2) n       ++o, ++numq, p[o].opt = 1, p[o].x = y, p[o].y = x, p[o].id = numq; n     else { n       if (y == a[x]) continue; n       int P = pre_(y, x), S = suf_(y, x); n       s[y].insert(x), s[a[x]].erase(x), a[x] = y; n       if (suf[x] != n + 1) link(suf[x], pre[x]); n       if (pre[x]) suf[pre[x]] = suf[x]; n       if (S != n + 1) link(S, x); n       if (P) suf[P] = x; n       link(x, P); n       suf[x] = S; n     } n   } n   cdq(1, o); n   for (int i = 1; i <= numq; ++i) printf( %lld n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> adj[1100]; n int need[1100]; n bool visit[1100]; n vector<pair<int, int> > vec; n int exist[1100]; n void bfs(int st) { n   queue<pair<int, int> > q; n   memset(visit, 0, sizeof visit); n   q.push({st, 0}); n   while (!q.empty()) { n     int u = q.front().first; n     int c = q.front().second; n     q.pop(); n     if (visit[u]) continue; n     visit[u] = 1; n     if (need[u]) vec.push_back({c, u}); n     for (auto v : adj[u]) n       if (!visit[v]) q.push({v, c + 1}); n   } n   sort(vec.begin(), vec.end()); n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     for (int i = 1; i <= n; ++i) adj[i].clear(); n     for (int i = 0; i < n - 1; ++i) { n       int a, b; n       scanf( %d%d , &a, &b); n       adj[a].push_back(b); n       adj[b].push_back(a); n     } n     int k; n     scanf( %d , &k); n     memset(need, 0, sizeof need); n     for (int i = 0; i < k; ++i) { n       int x; n       scanf( %d , &x); n       need[x] = 1; n     } n     scanf( %d , &k); n     memset(exist, 0, sizeof exist); n     int y; n     for (int i = 0; i < k; ++i) { n       scanf( %d , &y); n       exist[y] = 1; n     } n     vec.clear(); n     cout <<  B   << y << endl; n     int st; n     cin >> st; n     bfs(st); n     cout <<  A   << vec[0].second << endl; n     cin >> y; n     if (exist[y]) n       cout <<  C   << vec[0].second << endl; n     else n       cout <<  C -1  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N; n pair<int, int> P[105]; n int main() { n   cin >> N; n   for (int i = 1; i <= N; i++) cin >> P[i].first >> P[i].second; n   int K; n   cin >> K; n   for (int i = 1; i <= N; i++) n     if (K >= P[i].first && K <= P[i].second) { n       cout << N - i + 1 <<   n ; n       return 0; n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300005; n const long long int inf = 1e18; n long long int a[N]; n long long int b[N]; n long long int dp[N][3]; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     scanf( %d , &n); n     for (int i = 1; i <= n; i++) scanf( %lld %lld , &a[i], &b[i]); n     dp[1][0] = 0; n     dp[1][1] = b[1]; n     dp[1][2] = 2 * b[1]; n     for (int i = 2; i <= n; i++) { n       dp[i][0] = dp[i][1] = dp[i][2] = inf; n       for (int j = 0; j <= 2; j++) { n         for (int k = 0; k <= 2; k++) { n           if (a[i - 1] + j == a[i] + k) continue; n           dp[i][k] = min(dp[i][k], dp[i - 1][j] + k * b[i]); n         } n       } n     } n     printf( %lld n , min(dp[n][0], min(dp[n][1], dp[n][2]))); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)1e7 + 2; n const int M = (int)5e5 + 2; n const int mod = (int)1e9 + 7; n int mu[N], cnt[N]; n int n, mx, x, p[M]; n long long res; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   if (fopen( test  n              .inp , n              r )) { n     freopen( n          test  n          .inp , n          r , stdin); n     freopen( n          test  n          .out , n          w , stdout); n   } n   cin >> n; n   p[0] = 1; n   for (int i = 1; i <= n; ++i) { n     cin >> x; n     mx = max(mx, x); n     ++cnt[x]; n     p[i] = 2ll * p[i - 1] % mod; n   } n   mu[1] = 1; n   fill(mu + 2, mu + mx + 1, -1); n   int s; n   for (int i = 2; i <= mx; ++i) { n     s = cnt[i]; n     for (int j = 2 * i; j <= mx; j += i) mu[j] -= mu[i], s += cnt[j]; n     if (mu[i] != 0) n       res = (res + 1ll * (p[s] - 1) * (-mu[i]) * (n - s) % mod) % mod; n   } n   res += mod; n   cout << res % mod; n } n


#include <bits/stdc++.h> n using namespace std; n unordered_map<string, int> M; n vector<string> WHAT; n vector<int> LEFT, RIGHT; n int check(int v, int place) { n   vector<int> V = {v}; n   for (int i = 0; i < (int)WHAT.size(); i++) { n     if (WHAT[i][0] ==  0  or WHAT[i][0] ==  1 ) n       V.push_back(WHAT[i][place] -  0 ); n     else { n       int left = V[LEFT[i]], right = V[RIGHT[i]]; n       if (WHAT[i] ==  AND ) V.push_back(left & right); n       if (WHAT[i] ==  OR ) V.push_back(left | right); n       if (WHAT[i] ==  XOR ) V.push_back(left ^ right); n     } n   } n   int sum = 0; n   for (int i = 1; i < (int)V.size(); i++) sum += V[i]; n   return sum; n } n int main() { n   ios_base::sync_with_stdio(0); n   int n, m; n   cin >> n >> m; n   LEFT.resize(n); n   RIGHT.resize(n); n   for (int i = 0; i < n; i++) { n     string var, bs, left, op, right; n     cin >> var >> bs >> left; n     M[var] = i + 1; n     if (not(left[0] ==  0  or left[0] ==  1 )) { n       cin >> op >> right; n       int noleft = (left ==  ? ) ? 0 : M[left]; n       int noright = (right ==  ? ) ? 0 : M[right]; n       WHAT.push_back(op); n       LEFT[i] = noleft; n       RIGHT[i] = noright; n     } else { n       WHAT.push_back(left); n     } n   } n   string resmin =   ; n   string resmax =   ; n   for (int i = 0; i < m; i++) { n     int w0 = check(0, i); n     int w1 = check(1, i); n     if (w1 > w0) n       resmax +=  1 ; n     else n       resmax +=  0 ; n     if (w1 < w0) n       resmin +=  1 ; n     else n       resmin +=  0 ; n   } n   cout << resmin <<   n  << resmax <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   const int N = 8; n   std::string pokemons[] = { vaporeon ,  jolteon ,  flareon ,  espeon , n                              umbreon ,   leafeon ,  glaceon ,  sylveon }; n   int n; n   scanf( %d n , &n); n   std::string hidden; n   std::cin >> hidden; n   std::string output =   ; n   for (int p = 0; p < N; p++) { n     std::string current = pokemons[p]; n     if (current.size() != n) { n       continue; n     } n     bool possible = 1; n     for (int q = 0; q < n; q++) { n       if (hidden[q] !=  .  && hidden[q] != current[q]) { n         possible = 0; n         break; n       } n     } n     if (possible) { n       output = current; n       break; n     } n   } n   std::cout << output << std::endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long n, m; n   while (cin >> n >> m) { n     long long a[100100], b[101000], p, x, i, j, mm, l, r, cc = 0, pp, y, m1, n                                                           qq = 0; n     l = 1; n     r = n + 1; n     while (l <= r) { n       x = (l + r) / 2; n       mm = 1; n       pp = 0; n       while (1) { n         if (x / mm == 0) { n           break; n         } n         pp += x / mm; n         mm *= m; n       } n       if (n > pp) n         l = x + 1; n       else n         r = x - 1; n     } n     cout << l <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, i, n = 0, j = 0; n   cin >> a >> b; n   int k = sqrt(a); n   if (a == b) { n     cout <<  infinity  << endl; n   } else n     ; n   if (a != b) { n     for (i = 1; i * i <= a; i++) { n       if ((a - b) % i == 0 && i > b) n++; n       if ((a - b) % i == 0 && (a - b) / i > b && i != (a - b) / i) n++; n     } n     cout << n << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 6e5 + 10; n int n, k, l[maxn][2]; n int fa[maxn], sz[maxn]; n string s; n int get_fa(int x) { n   if (x == fa[x]) return x; n   return fa[x] = get_fa(fa[x]); n } n int calc(int x) { n   int y; n   if (x <= k) n     y = x + k; n   else n     y = x - k; n   x = get_fa(x), y = get_fa(y); n   if (x == 0 || y == 0) return sz[x + y]; n   return min(sz[x], sz[y]); n } n void merge_dis(int x, int y) { n   x = get_fa(x); n   y = get_fa(y); n   if (y == 0) { n     swap(x, y); n   } n   fa[y] = x; n   if (x != 0) sz[x] += sz[y]; n } n int main() { n   scanf( %d%d , &n, &k); n   cin >> s; n   for (int i = 1; i <= (int)3e5; i++) n     fa[i] = i, fa[i + k] = i + k, sz[i + k] = 1; n   for (int i = 1, c; i <= k; i++) { n     scanf( %d , &c); n     for (int j = 0, x; j < c; j++) { n       scanf( %d , &x); n       if (l[x][0] == 0) n         l[x][0] = i; n       else n         l[x][1] = i; n     } n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     if (l[i][1] == 0) { n       int x = l[i][0]; n       if (x) { n         ans -= calc(x); n         if (s[i - 1] ==  1 ) n           fa[get_fa(x + k)] = 0; n         else n           fa[get_fa(x)] = 0; n         ans += calc(x); n       } n     } else { n       int x = l[i][0], y = l[i][1]; n       if (s[i - 1] ==  1 ) { n         if (get_fa(x) != get_fa(y)) { n           ans -= calc(x); n           ans -= calc(y); n           merge_dis(x, y); n           merge_dis(x + k, y + k); n           ans += calc(x); n         } n       } else { n         if (get_fa(x + k) != get_fa(y)) { n           ans -= calc(x); n           ans -= calc(y); n           merge_dis(x + k, y); n           merge_dis(x, y + k); n           ans += calc(x); n         } n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename t> n t in(t q) { n   cin >> q; n   return q; n } n template <typename T> n ostream &operator<<(ostream &os, const vector<T> &v) { n   os <<  [ ; n   for (int i = 0; i < ((int)(v).size()); ++i) { n     os << v[i]; n     if (i != ((int)(v).size()) - 1) os <<  , ; n   } n   os <<  ] ; n   return os; n } n template <typename T, typename S> n ostream &operator<<(ostream &os, const map<T, S> &v) { n   for (auto it : v) os <<  (  << it.first <<  :  << it.second <<  ) ; n   return os; n } n template <typename T, typename S> n ostream &operator<<(ostream &os, const pair<T, S> &v) { n   os <<  (  << v.first <<  ,  << v.second <<  ) ; n   return os; n } n const long double PI = acosl(-1); n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count()); n inline int rand(int l, int r) { n   return uniform_int_distribution<int>(l, r)(rng); n } n inline long long rand(long long l, long long r) { n   return uniform_int_distribution<long long>(l, r)(rng64); n } n using namespace std; n const int N = 200005, M = 1005; n const long long MOD = 1e9 + 7; n const int OO = 1e9; n int a[11][11]; n void solve() { n   int n; n   cin >> n; n   for (int i = 0; i <= n; i++) { n     a[i][1] = 1; n     a[1][i] = 1; n   } n   for (int i = 2; i <= n; i++) { n     for (int j = 2; j <= n; j++) { n       a[i][j] = a[i - 1][j]; n       a[i][j] += a[i][j - 1]; n     } n   } n   cout << a[n][n] <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   solve(); n   cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = (1LL << 21) + 10; n int N, T, len, Imakf, bits[MAXN]; n long long a[MAXN], b[MAXN]; n char tem[MAXN]; n void fi(const char* tem) { n   if (!strlen(tem)) return; n   char A[50]; n   const char B[4] = { . ,  i ,  n , 0}, C[5] = { . ,  o ,  u ,  t , 0}; n   sprintf(A,  %s%s , tem, B); n   freopen(A,  r , stdin); n   sprintf(A,  %s%s , tem, C); n   freopen(A,  w , stdout); n } n void fwt(long long* A, int type) { n   for (int mid = 1; mid < len; mid <<= 1) { n     for (int j = 0; j < len; j += (mid << 1)) { n       for (int k = 0; k < mid; k++) { n         A[j + k + mid] += type * A[j + k]; n       } n     } n   } n } n int main() { n   fi(  ); n   scanf( %d , &N); n   len = 1LL << N, Imakf = len - 1; n   for (int i = 0; i < len; i++) bits[i] = bits[i >> 1] + (i & 1); n   scanf( %s , tem); n   for (int i = 0; i < len; i++) n     a[i] = (long long)(tem[i] -  0 ) << ((long long)bits[i] << 1); n   fwt(a, 1); n   scanf( %s , tem); n   for (int i = 0; i < len; i++) n     b[i] = (long long)(tem[i] -  0 ) << ((long long)bits[i] << 1); n   fwt(b, 1); n   for (int i = 0; i < len; i++) b[i] = (b[i] * a[i]); n   fwt(b, -1); n   for (int i = 0; i < len; i++) n     printf( %lld , ((long long)b[i] >> ((long long)bits[i] << 1)) & 3); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long r, m, n, x, y, a[5000005], b[5000005]; n long long fb(long long i, long long j, long long p) { n   if (p < b[i]) return i - 1; n   if (p >= b[j]) return j; n   long long mid = (i + j) / 2; n   if (b[mid] >= p && b[mid + 1] < p) return mid; n   if (b[mid] > p) n     return fb(i, mid, p); n   else n     return fb(mid + 1, j, p); n } n long long fb2(long long i, long long j, long long p) { n   if (p < a[i]) return i - 1; n   if (p >= a[j]) return j; n   long long mid = (i + j) / 2; n   if (a[mid] >= p && a[mid + 1] < p) return mid; n   if (a[mid] > p) n     return fb2(i, mid, p); n   else n     return fb2(mid + 1, j, p); n } n int main() { n   ios_base::sync_with_stdio(0); n   long long k = 0, t = 0, z = 1e7, l = 0, i, j; n   cin >> n >> x >> y >> t; n   string s; n   cin >> s; n   z = 0; n   for (i = n - 1; i >= 0; i--) { n     l = l + x; n     if (s[i] ==  w ) l = l + y; n     l++; n     b[z++] = l; n     if (l > t) break; n   } n   l = 0; n   for (i = 0; i < n; i++) { n     if (s[i] ==  w ) l = l + y; n     l++; n     a[i] = l; n     if (l > t) break; n     l = l + x; n   } n   sort(a, a + i); n   sort(b, b + z); n   long long sa = i; n   l = 0; n   r = 0; n   i = 0; n   for (i = 0; i < sa; i++) { n     l = a[i]; n     if (l > t) break; n     m = t - l - i * x; n     if (m > 0) { n       j = fb(0, z - 1, m) + 1; n       r = max(r, i + j + 1); n     } else n       r = max(r, i + 1); n   } n   for (i = 0; i < z; i++) b[i] += a[0]; n   for (i = 1; i < sa; i++) a[i] = a[i] - a[0] - x; n   for (i = 0; i < z; i++) { n     l = b[i]; n     if (l > t) break; n     m = t - l - (i + 2) * x; n     if (m > 0) { n       j = fb2(1, sa - 1, m); n       r = max(r, i + j + 2); n     } else n       r = max(r, i + 2); n   } n   r = min(r, n); n   cout << r; n   ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> graph[300005]; n long long col[300005]; n long long ans, r, b; n pair<long long, long long> dfs(long long x, long long p = -1) { n   long long a1, b1; n   a1 = 0; n   b1 = 0; n   if (col[x] == 1) a1++; n   if (col[x] == 2) b1++; n   for (long long i = 0; i < graph[x].size(); i++) { n     if (graph[x][i] == p) continue; n     auto temp = dfs(graph[x][i], x); n     if (temp.first == r && temp.second == 0) ans++; n     if (temp.first == 0 && temp.second == b) ans++; n     a1 += temp.first; n     b1 += temp.second; n   } n   return {a1, b1}; n } n signed main() { n   long long t, i, j, a, n, a1, a2, b1, b2; n   cin >> n; n   b = 0; n   r = 0; n   ans = 0; n   for (i = 1; i <= n; i++) { n     cin >> j; n     col[i] = j; n     if (j == 1) r++; n     if (j == 2) b++; n   } n   for (i = 0; i < n - 1; i++) { n     cin >> a1 >> b1; n     graph[a1].push_back(b1); n     graph[b1].push_back(a1); n   } n   dfs(1); n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int t; n string s; n int main() { n   cin >> t; n   while (t--) { n     cin >> s; n     int n = s.size(); n     int ans = n + 1, l = 0, c[4] = {0}; n     for (int i = 0; i < n; i++) { n       c[s[i] -  0 ]++; n       while (c[1] > 0 && c[2] > 0 && c[3] > 0) { n         ans = min(i - l + 1, ans); n         c[s[l++] -  0 ]--; n       } n     } n     if (ans == n + 1) n       cout << 0 << endl; n     else n       cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int tt; n   cin >> tt; n   while (tt--) { n     int n, Q; n     cin >> n >> Q; n     string s; n     cin >> s; n     vector<int> pre(n, 0); n     pre[0] = s[0] ==  +  ? 1 : -1; n     for (int i = 1; i < n; ++i) { n       pre[i] = pre[i - 1] + (s[i] ==  +  ? 1 : -1) * ((i % 2) ? -1 : 1); n     } n     while (Q--) { n       int l, r; n       cin >> l >> r; n       --l, --r; n       int sum = pre[r] - (l ? pre[l - 1] : 0); n       if (sum == 0) { n         cout << 0; n       } else if ((r - l + 1) % 2 == 1) { n         cout << 1; n       } else { n         cout << 2; n       } n       cout <<   n ; n     } n   } n } n


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