#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 5, MOD = 1e9 + 7; n char s[N], buf[1 << 20]; n int ppp, qqq; n inline char gc() { n   if (ppp == qqq) ppp = 0, qqq = fread(buf, 1, 1 << 20, stdin); n   return buf[ppp++]; n } n inline void rs() { n   char x; n   int t = 0; n   while ((x = getchar()) <  a  || x >  z ) n     ; n   s[++t] = x; n   while ((x = getchar()) >=  a  && x <=  z ) s[++t] = x; n } n inline int rd() { n   char x; n   while ((x = getchar()) <  0  || x >  9 ) n     ; n   int t = x -  0 ; n   while ((x = getchar()) >=  0  && x <=  9 ) t = t * 10 + x -  0 ; n   return t; n } n int bg[N], nx[N * 2], to[N * 2], tl, hs1[N], hs2[N], p29[N], pinv[N], lg2[N]; n inline void add(int x, int y) { n   nx[++tl] = bg[x]; n   bg[x] = tl; n   to[tl] = y; n } n inline int qpow(int x, int y) { n   int ret = 1; n   while (y) { n     if (y & 1) ret = 1ll * ret * x % MOD; n     x = 1ll * x * x % MOD; n     y >>= 1; n   } n   return ret; n } n int dep[N], mxd[N], son[N], top[N], up[N], dw[N], fa[N][20], num[N], dfn; n void dfs1(int now, int f, int depth) { n   dep[now] = depth; n   fa[now][0] = f; n   mxd[now] = depth; n   for (int i = 1; i < 20; i++) { n     if (!fa[fa[now][i - 1]][i - 1]) break; n     fa[now][i] = fa[fa[now][i - 1]][i - 1]; n   } n   hs1[now] = (hs1[f] + 1ll * (s[now] -  a ) * p29[depth - 1]) % MOD; n   hs2[now] = (29ll * hs2[f] + s[now] -  a ) % MOD; n   for (int i = bg[now]; i; i = nx[i]) { n     int aim = to[i]; n     if (aim == f) continue; n     dfs1(aim, now, depth + 1); n     if (mxd[aim] > mxd[son[now]]) son[now] = aim; n     mxd[now] = max(mxd[now], mxd[aim]); n   } n } n void dfs2(int now, int tp) { n   top[now] = tp, num[now] = ++dfn; n   if (now == tp) { n     int len = mxd[now] - dep[now], tmp = now; n     for (int i = 0; i <= len; i++) dw[dfn + i] = tmp, tmp = son[tmp]; n     tmp = now; n     for (int i = 0; i <= len; i++) up[dfn + i] = tmp, tmp = fa[tmp][0]; n   } n   if (son[now]) dfs2(son[now], tp); n   for (int i = bg[now]; i; i = nx[i]) { n     int aim = to[i]; n     if (aim == fa[now][0] || aim == son[now]) continue; n     dfs2(aim, aim); n   } n } n inline int lca(int x, int y) { n   if (dep[x] < dep[y]) swap(x, y); n   int i, dt = dep[x] - dep[y]; n   for (i = 0; i < dt; i++) { n     if ((1 << i) > dt) break; n     if ((1 << i) & dt) x = fa[x][i]; n   } n   if (x == y) return x; n   for (i = 19; i >= 0; i--) { n     if (fa[x][i] == fa[y][i]) continue; n     x = fa[x][i], y = fa[y][i]; n   } n   return fa[x][0]; n } n inline int kth_anc(int x, int k) { n   if (k == 0) return x; n   x = fa[x][lg2[k]], k -= 1 << lg2[k]; n   int tp = top[x], dt = dep[x] - dep[tp] - k; n   if (dt >= 0) n     return dw[num[tp] + dt]; n   else n     return up[num[tp] - dt]; n } n int main() { n   int n = rd(), q, i; n   rs(); n   for (i = 1; i < n; i++) { n     int x = rd(), y = rd(); n     add(x, y), add(y, x); n   } n   p29[0] = pinv[0] = 1, lg2[0] = -1; n   for (i = 1; i <= n; i++) { n     p29[i] = 1ll * p29[i - 1] * 29 % MOD, pinv[i] = qpow(p29[i], MOD - 2); n     lg2[i] = lg2[i >> 1] + 1; n   } n   dfs1(1, 0, 1); n   dfs2(1, 1); n   q = rd(); n   for (i = 1; i <= q; i++) { n     int a = rd(), b = rd(), c = rd(), d = rd(); n     int ac1 = lca(a, b), ac2 = lca(c, d); n     int len1 = dep[a] + dep[b] - dep[ac1] * 2 + 1, n         len2 = dep[c] + dep[d] - dep[ac2] * 2 + 1; n     int dis1 = dep[a] - dep[ac1] + 1, dis2 = dep[c] - dep[ac2] + 1; n     int l = 1, r = min(len1, len2), ans = 0; n     while (l <= r) { n       int mid = (l + r) >> 1; n       int h1 = 0, h2 = 0; n       if (mid > dis1) { n         int rem = mid - dis1; n         int lf = n             1ll * (hs1[a] - hs1[fa[ac1][0]] + MOD) * pinv[dep[ac1] - 1] % MOD; n         int rp = kth_anc(b, dep[b] - dep[ac1] - rem); n         int rt = (0ll + hs2[rp] - n                   1ll * hs2[ac1] * p29[dep[rp] - dep[ac1]] % MOD + MOD) % n                  MOD; n         h1 = (1ll * lf * p29[rem] + rt) % MOD; n       } else { n         int lp = kth_anc(a, mid - 1); n         h1 = 1ll * (hs1[a] - hs1[fa[lp][0]] + MOD) * pinv[dep[lp] - 1] % MOD; n       } n       if (mid > dis2) { n         int rem = mid - dis2; n         int lf = n             1ll * (hs1[c] - hs1[fa[ac2][0]] + MOD) * pinv[dep[ac2] - 1] % MOD; n         int rp = kth_anc(d, dep[d] - dep[ac2] - rem); n         int rt = (0ll + hs2[rp] - n                   1ll * hs2[ac2] * p29[dep[rp] - dep[ac2]] % MOD + MOD) % n                  MOD; n         h2 = (1ll * lf * p29[rem] + rt) % MOD; n       } else { n         int lp = kth_anc(c, mid - 1); n         h2 = 1ll * (hs1[c] - hs1[fa[lp][0]] + MOD) * pinv[dep[lp] - 1] % MOD; n       } n       if (h1 == h2) n         ans = mid, l = mid + 1; n       else n         r = mid - 1; n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n vector<int> v; n int main(int argc, char const *argv[]) { n   cin >> s; n   int n = s.size(); n   sort(s.begin(), s.end()); n   for (int i = 0; i < n; i++) { n     if (s[i] >  0 ) { n       swap(s[0], s[i]); n       break; n     } n   } n   string q; n   cin >> q; n   for (int i = 0; i < n; i++) { n     if (q.size() != s.size() or q[i] != s[i]) { n       cout <<  WRONG_ANSWER  << endl; n       return 0; n     } n   } n   cout <<  OK  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int arr[105]; n   int n; n   cin >> n; n   for (int x = 0; x < n; x++) { n     cin >> arr[x]; n   } n   sort(arr, arr + n); n   for (int x = 0; x < n; x++) { n     cout << arr[x] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n using uint = unsigned int; n using ll = long long; n using ull = unsigned long long; n using pii = pair<int, int>; n template <typename T1, typename T2> n ostream &operator<<(ostream &out, const pair<T1, T2> &item) { n   out <<  (  << item.first <<  ,   << item.second <<  ) ; n   return out; n } n template <typename T> n ostream &operator<<(ostream &out, const vector<T> &v) { n   for (const auto &item : v) out << item <<    ; n   return out; n } n int n, lpd[5100000]; n int last[5100000][8]; n int st[15][2 * 200010]; n void update(int p, int nr, int pos) { n   if (st[nr][p += n] >= pos) return; n   for (st[nr][p] = pos; p > 1; p >>= 1) n     st[nr][p >> 1] = max(st[nr][p], st[nr][p ^ 1]); n } n int query(int nr, int l, int r) { n   int res; n   for (res = -1, l += n, r += n; l < r; l >>= 1, r >>= 1) { n     if (l & 1) res = max(res, st[nr][l++]); n     if (r & 1) res = max(res, st[nr][--r]); n   } n   return res; n } n void process(int a, int i) { n   int p, e; n   vector<int> d; n   while (a > 1) { n     for (e = 0, p = lpd[a]; a % p == 0; ++e) a /= p; n     if (e & 1) d.push_back(p); n   } n   int n = d.size(); n   for (int cfg = 0; cfg < (1 << n); ++cfg) { n     int j, val, s; n     for (s = 0, val = 1, j = 0; j < n; ++j) n       if (cfg & (1 << j)) val *= d[j], ++s; n     for (int nr = 0; nr <= 7; ++nr) update(i, n - s + nr, last[val][nr]); n     last[val][n - s] = i; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   int i, q, a, l, r, ans; n   for (i = 1; i < 5100000; ++i) lpd[i] = i; n   for (i = 2; i < 5100000; ++i) { n     if (lpd[i] != i) continue; n     for (ll j = 1LL * i * i; j < 5100000; j += i) lpd[j] = min(lpd[j], i); n   } n   cin >> n >> q; n   memset(st, -1, sizeof st); n   memset(last, -1, sizeof last); n   for (i = 0; i < n; ++i) { n     cin >> a; n     process(a, i); n   } n   while (q--) { n     cin >> l >> r; n     for (ans = 0; ans <= 14; ++ans) n       if (query(ans, l - 1, r) >= l - 1) { n         cout << ans <<   n ; n         break; n       } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef bool mat[55][55][35]; n mat adja, adjb; n char a[55], b[55], x[55], y[55], z[55]; n int dp[55][55], k; n inline void upd(int &u, int v) { u = min(u, v); } n inline void work(char *str, int n, mat adj) { n   memset(adj, false, 55 * 55 * 35); n   for (int i = 0; i < n; i++) adj[i][i][str[i] -  a ] = true; n   for (int len = 1; len < n; len++) { n     for (int l = 0; l + len < n; l++) { n       int r = l + len; n       for (int p = l; p < r; p++) { n         for (int i = 0; i < k; i++) n           adj[l][r][x[i] -  a ] |= n               adj[l][p][y[i] -  a ] & adj[p + 1][r][z[i] -  a ]; n       } n     } n   } n } n int main() { n   scanf( %s%s%d , a, b, &k); n   int n = strlen(a), m = strlen(b); n   for (int i = 0; i < k; i++) scanf( %*c%c%*c%*c%c%c , x + i, y + i, z + i); n   work(a, n, adja); n   work(b, m, adjb); n   memset(dp, 0x3f, sizeof(dp)); n   dp[0][0] = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       for (int t = 0; t < 26; t++) { n         for (int u = i; u < n; u++) { n           for (int v = j; v < m; v++) { n             if (adja[i][u][t] && adjb[j][v][t]) n               upd(dp[u + 1][v + 1], dp[i][j] + 1); n           } n         } n       } n     } n   } n   printf( %d n , dp[n][m] == 0x3f3f3f3f ? -1 : dp[n][m]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int P1, P2, P3, T1, T2; n int interval(int r, int l) { n   int t = l - r; n   int sum = 0; n   if (t > T1) { n     sum = T1 * P1; n     t = t - T1; n     if (t > T2) { n       sum = T2 * P2 + sum; n       t = t - T2; n       sum = sum + t * P3; n     } else { n       sum = sum + t * P2; n     } n   } else n     sum = P1 * t; n   return sum; n } n int main() { n   int n; n   cin >> n >> P1 >> P2 >> P3 >> T1 >> T2; n   int left[n], right[n]; n   for (int i = 0; i < n; i++) { n     cin >> left[i] >> right[i]; n   } n   int sum = 0; n   for (int i = 0;; i++) { n     sum = sum + P1 * (right[i] - left[i]); n     if (i == n - 1) n       break; n     else { n       sum = sum + interval(right[i], left[i + 1]); n     } n   } n   cout << sum; n } n


#include<bits/stdc++.h> n #define int long long n using namespace std; n const int mod=1e9+7; n const int N=3e5+100; n int fa[N]; n //并查集,表示i的祖父fa[i] n int begi; n //记录可以随意放的点的位置(只有一个) n int n,m; n int a[N],b[N],c[N],in[N],ans[N]; n //a[i]和b[i]表示i必须在a[i]的左边，b[i]的右边 n //c[i]表示在缩成一个点的一段中的开头(b[i]的限制中能无限制的放位置) n //in[i]表示入度,ans[i]表示答案 n vector<int>g[N],h[N]; n //h[i]存储i必须在h[i][1..n]左边 n //g[i]表示缩点之后i必须在g[i][1..n]左边 n bool vis[N]; n //判断序列是否合法 n int find(int x)//并查集搜爸爸 n { n  if(fa[x]==x)return x; n  return fa[x]=find(fa[x]); n } n signed main() n { n  scanf( %lld%lld ,&n,&m); n  for(int i=1;i<=n;i++) n  fa[i]=i;  n  for(int i=1;i<=n;i++)  n  { n   int x,y; n   scanf( %lld ,&x); n   if(x==0)begi=i;//储存无限制放的点的位置 n     else h[x].push_back(i);//记录顺序 n  } n  while(m--)//判能否组成序列 n  { n   int x,y; n   scanf( %lld%lld ,&x,&y); n //  cout<<x<<   <<y<<endl;  n   a[x]=y; n   b[y]=x; n   x=find(x),y=find(y); n  // cout<<x<<   <<y<<endl; n   if(x==y)//如果成环 n   { n    puts( 0 ); n    return 0; n   } n   fa[x]=y;//合并 n   //无义，相当于把两个集合合并，用来判环后就没用了 n   //如果一个集合内的元素互相指向，就矛盾了 n  }  n  for(int i=1;i<=n;i++) n  { n   if(b[i]==0)c[find(i)]=i; n   //缩点，也就是把一段互相关联的区间缩成一个点去做 n   //c[find(i)]也就是这一段区间的开头 n   //也就是说这一个开头不受这一段区间内的点的限制 n   //反而这个点可以限制这个区间内的其他点 n   for(int j=0;j<h[i].size();j++) n   { n    int x=h[i][j]; n    if(find(i)!=find(x)) n       { n        g[find(i)].push_back(find(x)); n     //因为把一段缩成一个点 n     //所以需要把这一段区间内的点的限制关系都转移到这一个点上 n        in[find(x)]++; n     //这一个点的入度(做拓扑排序) n       } n   } n  } n  queue<int>q; n  //拓扑排序专属队列 n  q.push(find(begi)); n  //从无限制的点开始 n  int ct=0; n  while(!q.empty()) n  { n   int x=q.front(); n   q.pop(); n   int t=c[x]; n   //找到缩点 n   while(t)//把这缩点里面的一个区间记录到答案内 n   { n    ans[++ct]=t; n    t=a[t]; n   } n   for(int i=0;i<g[x].size();i++)//拓扑排序pd操作 n   { n    int y=g[x][i]; n    in[y]--; n    if(in[y]==0)q.push(y);  n   }  n  } n  if(ct!=n)//如果答案数不等于n,就相当于不合法 n  { n   puts( 0 ); n   return 0; n  } n  vis[begi]=1; n  //判断序列前后关系是否合法 n  //因为begi没有限制，所以第一个判 n  for(int i=1;i<=n;i++) n  //按答案顺序说 n  { n   if(vis[ans[i]]==0)//如果按照限制关系还没被判断(就相当于i要在j的左边，可j先比i出现了) n        n    return puts( 0 ),0;  n   for(int j=0;j<h[ans[i]].size();j++)//类似拓扑，把能在接下来队列里的点判为1 n        vis[h[ans[i]][j]]=1; n  } n  for(int i=1;i<=n;i++)//输出 n  { n   printf( %lld  ,ans[i]); n  } n  return 0; n }  n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   t = 1; n   while (t--) { n     long long int n; n     cin >> n; n     long long int arr[n + 1]; n     long long int ans[n + 1]; n     unordered_map<long long int, long long int> mp; n     arr[0] = 0; n     for (__typeof(n + 1) i = (1) - ((1) > (n + 1)); n          i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) { n       cin >> arr[i]; n       mp[arr[i]] = 1; n     } n     long long int p = 0; n     for (__typeof(n + 1) i = (1) - ((1) > (n + 1)); n          i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) { n       if (arr[i] != arr[i - 1]) { n         ans[i] = arr[i - 1]; n         mp[arr[i - 1]] = 1; n         continue; n       } n       while (mp[p]) { n         p++; n       } n       ans[i] = p; n       mp[p] = 1; n     } n     for (__typeof(n + 1) i = (1) - ((1) > (n + 1)); n          i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) n       cout << ans[i] <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long pw(long long base, long long e) { n   return e ? pw(base * base, e / 2) * (e % 2 ? base : 1) : 1; n } n const int maxn = 1e6 + 10, mod = 1e9 + 7, maxlg = 21, lim = 1e6; n const long long INF = 1e9; n long long fen[maxn]; n vector<int> r[maxn]; n int n; n int ans[maxn]; n pair<int, int> a[maxn]; n vector<pair<int, int> > query[maxn]; n void update(int ind) { n   for (; ind < maxn; ind += ind & -ind) { n     fen[ind]++; n   } n } n int get(int ind) { n   long long res = 0; n   for (; ind; ind -= ind & -ind) { n     res += fen[ind]; n   } n   return res; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int q, cnt, m; n   cin >> n >> q; n   for (int i = 0; i < n; i++) { n     cin >> a[i].first >> a[i].second; n     r[a[i].second].push_back(a[i].first); n   } n   for (int j = 0; j < q; j++) { n     cin >> m; n     int prev, cur; n     prev = 0; n     while (m--) { n       cin >> cur; n       if (cur - prev > 1) { n         query[cur - 1].push_back({prev + 1, j}); n       } n       prev = cur; n     } n     if (lim > prev) { n       query[lim].push_back({prev + 1, j}); n     } n   } n   for (int i = 1; i <= lim; i++) { n     if (r[i].size()) { n       for (auto l : r[i]) { n         update(l); n       } n     } n     if (query[i].size()) { n       int val = get(i); n       for (auto d : query[i]) { n         ans[d.second] += val - get(d.first - 1); n       } n     } n   } n   for (int i = 0; i < q; i++) { n     cout << n - ans[i] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int k, d, sk, t; n void sp(int t) { n   for (int j = 0; j < k; j++) { n     d = k / 2 + j % 2; n     sk = j % 2; n     if (t % 2 == 0) { n       while (d > sk) { n         if (d % 2 == 0) { n           printf( bb ); n         } else { n           printf( ww ); n         } n         d--; n       } n     } else { n       while (d > sk) { n         if (d % 2 == 0) { n           printf( ww ); n         } else { n           printf( bb ); n         } n         d--; n       } n     } n     printf(  n ); n   } n   printf(  n ); n } n int main() { n   scanf( %d , &k); n   if (k % 2 == 1) { n     printf( %d n , -1); n   } else { n     for (int i = 0; i < k / 2; i++) { n       t = k / 2 + i % 2; n       sp(t); n       sp(t); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long n; n   cin >> n; n   long long sumx = 0; n   long long sumy = 0; n   for (long long i = 0; i < n; i++) { n     long long a, b; n     cin >> a >> b; n     sumx += a; n     sumy += b; n   } n   for (long long i = 0; i < n; i++) { n     long long a, b; n     cin >> a >> b; n     sumx += a; n     sumy += b; n   } n   cout << sumx / n <<     << sumy / n <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     long long arr[n + 5], mx = 0, mn = INT_MIN; n     for (int i = 0; i < n; i++) cin >> arr[i]; n     if (arr[n - 1] > 0) n       arr[n] = -1; n     else n       arr[n] = 1; n     bool p = false, o = false; n     long long sum = 0; n     for (int i = 0; i <= n; i++) { n       if (arr[i] > 0) { n         if (o) { n           sum += mn; n           mn = INT_MIN; n         } n         p = true; n         o = false; n         mx = max(mx, arr[i]); n       } else { n         if (p) { n           sum += mx; n           mx = 0; n         } n         o = true; n         p = false; n         mn = max(mn, arr[i]); n       } n     } n     cout << sum << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct SegmentTreeLazy { n   typedef long long T; n   const T inf = (T)1e18; n   const T not_found = -2; n   SegmentTreeLazy(vector<T> &v) { n     n = static_cast<int>(v.size()); n     int pow2 = 1; n     while (pow2 < n) pow2 <<= 1; n     mx.resize(2 * pow2, -inf); n     mn.resize(2 * pow2, inf); n     change.resize(2 * pow2); n     mode.resize(2 * pow2); n     build(v, 1, 0, n); n   } n   int query_zero_idx(int L, int R) { return query_zero_idx(1, 0, n, L, R); } n   void set(int L, int R, T x) { update(Mode::assign, 1, 0, n, L, R, x); } n   void inc(int L, int R, T x) { update(Mode::increment, 1, 0, n, L, R, x); } n  n  private: n   int n; n   enum class Mode { increment, assign }; n   vector<T> mx; n   vector<T> mn; n   vector<T> change; n   vector<Mode> mode; n   inline int left(int p) { return p << 1; } n   inline int right(int p) { return (p << 1) + 1; } n   void build(vector<T> &v, int pos, int lo, int hi) { n     if (lo + 1 < hi) { n       int mid = lo + (hi - lo) / 2; n       build(v, left(pos), lo, mid); n       build(v, right(pos), mid, hi); n       mx[pos] = max(mx[left(pos)], mx[right(pos)]); n       mn[pos] = min(mn[left(pos)], mn[right(pos)]); n     } else { n       mx[pos] = mn[pos] = v[lo]; n     } n   } n   T query_zero_idx(int pos, int lo, int hi, int L, int R) { n     if (R <= lo or hi <= L) return not_found; n     if (L <= lo and hi <= R) { n       if (mx[pos] < 0 or mn[pos] > 0) n         return not_found; n       else if (mx[pos] == 0 and mn[pos] == 0) n         return lo; n       else if (lo + 1 == hi) n         return -1; n     } n     propagate(pos, lo, hi); n     int mid = lo + (hi - lo) / 2; n     int idx = query_zero_idx(left(pos), lo, mid, L, R); n     if (idx != not_found) return idx; n     return query_zero_idx(right(pos), mid, hi, L, R); n   } n   void update(Mode m, int pos, int lo, int hi, int L, int R, T x) { n     if (R <= lo or hi <= L) { n       return; n     } n     if (L <= lo and hi <= R) { n       if (m == Mode::assign) { n         mx[pos] = x; n         mn[pos] = x; n         change[pos] = x; n         mode[pos] = Mode::assign; n       } else { n         mx[pos] += x; n         mn[pos] += x; n         change[pos] += x; n       } n     } else { n       propagate(pos, lo, hi); n       int mid = lo + (hi - lo) / 2; n       update(m, left(pos), lo, mid, L, R, x); n       update(m, right(pos), mid, hi, L, R, x); n       mx[pos] = max(mx[left(pos)], mx[right(pos)]); n       mn[pos] = min(mn[left(pos)], mn[right(pos)]); n     } n   } n   void propagate(int pos, int lo, int hi) { n     if (mode[pos] == Mode::assign or change[pos]) { n       int mid = lo + (hi - lo) / 2; n       update(mode[pos], left(pos), lo, mid, lo, mid, change[pos]); n       update(mode[pos], right(pos), mid, hi, mid, hi, change[pos]); n       change[pos] = 0; n       mode[pos] = Mode::increment; n     } n   } n }; n void solve() { n   int n, q, p; n   long long sum = 0, x; n   cin >> n >> q; n   vector<long long> diff, v; n   diff.reserve(n); n   for (int i = 0; i < n; ++i) { n     cin >> x; n     v.push_back(x); n     diff.push_back(x - sum); n     sum += x; n   } n   SegmentTreeLazy st(diff); n   int king = st.query_zero_idx(0, n); n   for (int i = 0; i < q; ++i) { n     cin >> p >> x; n     p -= 1; n     st.inc(p, p + 1, x - v[p]); n     st.inc(p + 1, n, v[p] - x); n     v[p] = x; n     if (king == st.not_found or king >= p) { n       king = st.query_zero_idx(p, n); n     } n     cout << king + 1 <<   n ; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 4e5; n vector<long long> coords; n vector<pair<pair<long long, bool>, pair<long long, long long> > > sweep; n map<long long, long long> ind; n struct nodo { n   int may, pos; n }; n struct segTree { n   int n, h, d[N]; n   nodo t[N << 1]; n   void init() { n     h = sizeof(int) * 8 - __builtin_clz(n); n     for (long long i = 0; i < n; i++) t[i + n].pos = i; n   } n   void apply(int p, int v) { n     t[p].may = t[p].may + v; n     if (p < n) d[p] += v; n   } n   void push(int p) { n     for (int s = h; s > 0; s--) { n       int i = p >> s; n       if (d[i] != 0) { n         apply(i << 1, d[i]); n         apply(i << 1 | 1, d[i]); n         d[i] = 0; n       } n     } n   } n   void build(int p) { n     while (p > 1) { n       p >>= 1; n       if (t[p << 1].may > t[p << 1 | 1].may) { n         t[p].pos = t[p << 1].pos; n         t[p].may = t[p << 1].may + d[p]; n       } else { n         t[p].may = t[p << 1 | 1].may + d[p]; n         t[p].pos = t[p << 1 | 1].pos; n       } n     } n   } n   void upd(int l, int r, int v) { n     l += n, r += n; n     int l0 = l, r0 = r; n     push(l); n     push(r - 1); n     for (; l < r; l >>= 1, r >>= 1) { n       if (l & 1) apply(l++, v); n       if (r & 1) apply(--r, v); n     } n     build(l0); n     build(r0 - 1); n   } n   pair<long long, long long> que() { n     int l = 0, r = n; n     nodo ans; n     ans.may = -1; n     l += n, r += n; n     push(l); n     push(r - 1); n     for (; l < r; l >>= 1, r >>= 1) { n       if (l & 1) { n         if (t[l].may > ans.may) { n           ans = t[l]; n         } n         l++; n       } n       if (r & 1) { n         if (t[r - 1].may > ans.may) { n           ans = t[r - 1]; n         } n         r--; n       } n     } n     return make_pair(ans.may, ans.pos); n   } n } st; n int main() { n   int n; n   cin >> n; n   for (long long i = 0; i < n; i++) { n     int x1, y1, x2, y2; n     cin >> x1 >> y1 >> x2 >> y2; n     sweep.push_back(make_pair(make_pair(x1, 0), make_pair(y1, y2))); n     sweep.push_back(make_pair(make_pair(x2, 1), make_pair(y1, y2))); n     coords.push_back(y1); n     coords.push_back(y2); n   } n   sort((sweep).begin(), (sweep).end()); n   sort((coords).begin(), (coords).end()); n   coords.resize(unique((coords).begin(), (coords).end()) - coords.begin()); n   int i = 0; n   for (long long y : coords) ind[y] = i++; n   st.n = (coords).size(); n   st.init(); n   for (auto elem : sweep) { n     long long x = elem.first.first; n     long long y1 = elem.second.first; n     long long y2 = elem.second.second; n     bool t = elem.first.second; n     if (!t) { n       st.upd(ind[y1], ind[y2] + 1, +1); n       pair<long long, long long> cur = st.que(); n       if (cur.first >= n - 1) { n         cout << x <<     << coords[cur.second] << endl; n         return 0; n       } n     } else { n       st.upd(ind[y1], ind[y2] + 1, -1); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3E4 + 5; n const int M = 500; n int n, d, a[N], x, ans, r, L, w, f[N][M * 2 + 5]; n int main() { n   cin >> n >> L; n   for (int i = 1; i <= n; i++) scanf( %d , &r), a[r]++; n   memset(f, -10, sizeof(f)); n   f[L][M] = a[L]; n   for (int i = 1; i <= r; i++) n     for (int j = L - M; j <= L + M; j++) n       if ((w = f[i][j - L + M]) >= 0) { n         ans = max(ans, w); n         for (int k = j - 1; k <= j + 1; k++) n           if (k > 0 && (x = i + k) <= r) { n             f[x][k - L + M] = max(f[x][k - L + M], w + a[x]); n           } n       } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<int, char> > vec[103]; n bool dp[103][103][2][300]; n bool declared[103][103][2][300]; n bool f(int u1, int u2, int turn, char round) { n   if (declared[u1][u2][turn][round]) return dp[u1][u2][turn][round]; n   if (turn == 1) { n     for (int i = 0; i < vec[u1].size(); i++) { n       int v = vec[u1][i].first; n       char c = vec[u1][i].second; n       if (c >= round && f(v, u2, 0, c) == false) { n         declared[u1][u2][turn][round] = 1; n         return dp[u1][u2][turn][round] = 1; n       } n     } n     declared[u1][u2][turn][round] = 1; n     return dp[u1][u2][turn][round] = 0; n   } else { n     for (int i = 0; i < vec[u2].size(); i++) { n       int v = vec[u2][i].first; n       char c = vec[u2][i].second; n       if (c >= round && f(u1, v, 1, c) == false) { n         declared[u1][u2][turn][round] = 1; n         return dp[u1][u2][turn][round] = 1; n       } n     } n     declared[u1][u2][turn][round] = 1; n     return dp[u1][u2][turn][round] = 0; n   } n   return 0; n } n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int u, v; n     char c; n     cin >> u >> v >> c; n     vec[u].push_back({v, c}); n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       if (f(i, j, 1,  a ) == 1) n         cout <<  A ; n       else n         cout <<  B ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mx = 223456; n long long n, a[mx], b[mx], sum1, sum2, ca, cb; n int32_t main() { n   cin >> n; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (long long i = 0; i < n; i++) { n     cin >> b[i]; n   } n   sort(a, a + n); n   sort(b, b + n); n   ca = n - 1; n   cb = n - 1; n   for (long long i = 0; i < n * 2; i++) { n     long long y = 0; n     if (i % 2 == 0) { n       if (ca >= 0 && cb >= 0) { n         if (a[ca] > b[cb]) { n           sum1 += a[ca]; n           ca--; n         } else { n           cb--; n         } n         y = 1; n       } n       if (ca < 0 && y == 0) { n         cb--; n         y = 1; n       } n       if (cb < 0 && y == 0) { n         sum1 += a[ca]; n         ca--; n         y = 1; n       } n     } else { n       if (ca >= 0 && cb >= 0) { n         if (a[ca] < b[cb]) { n           sum2 += b[cb]; n           cb--; n         } else { n           ca--; n         } n         y = 1; n       } n       if (cb < 0 && y == 0) { n         ca--; n         y = 1; n       } n       if (ca < 0 && y == 0) { n         sum2 += b[cb]; n         cb--; n         y = 1; n       } n     } n   } n   cout << sum1 - sum2; n   return 0; n } n


#include <cstdio> n #include <cassert> n #include <utility> n #include <functional> n #define X first n #define Y second n const int mod = 998244353; n template<int k> n struct node{ n   node <k-1>* chd[2]; n   int cnt; n   int lazy; n   int has[2]; n   int get_cnt(){ n     assert(this!=NULL); n     return cnt; n   } n   int get_has(int d){ n     assert(this!=NULL); n     push(); n     assert(has[d]<(1<<(k+1))); n     return has[d]; n   } n   node():chd{NULL, NULL}, has{0, 0}, cnt(0),lazy(0){}; n   node(node<k-1>* l,node <k-1>* r):chd{l,r},cnt(0),lazy(0),has{0,0}{ n     if(l){ n       cnt+=l->get_cnt(); n       has[0]|=l->get_has(0)|(1<<k); n       has[1]|=l->get_has(1); n     } n     if(r){ n       cnt+=r->get_cnt(); n       has[0]|=r->get_has(0); n       has[1]|=r->get_has(1)|(1<<k); n     } n     assert(has[0]<(1<<(k+1))); n     assert(has[1]<(1<<(k+1))); n   } n   void push(){ n     assert(lazy<(1<<(k+1))); n     if(!lazy) return; n     if(lazy&(1<<k)){ n       std::swap(chd[0],chd[1]); n       if((has[0]^has[1])&(1<<k)){ n  has[0]^=(1<<k); n  has[1]^=(1<<k); n       } n       lazy^=(1<<k); n     } n     int flip=(has[0]^has[1])&lazy; n     has[0]^=flip; n     has[1]^=flip; n     if(chd[0]) chd[0]->lazy^=lazy; n     if(chd[1]) chd[1]->lazy^=lazy; n     lazy=0; n     assert(has[0]<(1<<(k+1))); n     assert(has[1]<(1<<(k+1))); n   } n }; n  n template<> n struct node<-1>{ n   int lazy; n   node():lazy(0){ n   } n   int get_cnt(){ n     assert(this!=NULL); n     return 1; n   } n   int get_has(int d){ n     assert(this!=NULL); n     return 0; n   } n }; n  n template<int k> n node<k>* create(int x){ n   if(x&(1<<k)){ n     return new node<k>(NULL,create<k-1>(x)); n   }else{ n     return new node<k>(create<k-1>(x),NULL); n   } n } n template<> node<-1>*create(int x) n { n     return new node<-1>(); n } n template<int k> std::pair <node<k - 1>*, node< k - 1>*> destruct(node <k>*a) n { n   assert(a!=NULL); n     a -> push(); n     auto res = std::make_pair(a -> chd[0], a -> chd[1]); n     delete a; n     return res; n } n template <int k> node <k>* join(node<k -1>* l, node <k - 1>* r) n { n     if(l == NULL && r == NULL) n     { n         return NULL; n     } n     return new node<k>(l, r); n } n template<int k> node<k>* merge(node<k> *a, node<k> *b) n { n     if(!a) n     { n         return b; n     } n     if(!b) n     { n         return a; n     } n     auto aa = destruct(a); n     auto bb = destruct(b); n     node <k - 1> *l = merge<k - 1>(aa.X, bb.X); n     node <k - 1> *r = merge<k - 1>(aa.Y, bb.Y); n     return join<k>(l, r); n } n template<>node<-1>* merge(node<-1>*a, node<-1>* b) n { n     if(!a) n     { n         return b; n     } n     if(!b) n     { n         return a; n     } n     delete b; n     return a; n } n template<int k> n std::pair<node<k>*,node<k>*> split(node<k>* a,int thres){ n   if(a==NULL){ n     return {NULL,NULL}; n   } n   if(thres<=0) return {NULL,a}; n   if(thres>=(1<<(k+1))) return {a,NULL}; n   assert(k>=0); n   auto aa =destruct(a); n   if(thres<(1<<k)){ n     node<k-1>* l,*r; n     std::tie(l,r)=split<k-1>(aa.first,thres); n     return std::make_pair(join<k>(l,NULL),join<k>(r,aa.second)); n   }else if(thres>(1<<k)){ n     node<k-1>* l,*r; n     std::tie(l,r)=split<k-1>(aa.second, thres-(1<<k)); n     return std::make_pair(join<k>(aa.first,l),join<k>(NULL,r)); n   }else{ n     return std::make_pair(join<k>(aa.first,NULL),join<k>(NULL,aa.second)); n   } n } n  n template<> n std::pair<node<-1>*,node<-1>*> split<-1>(node<-1>* a,int thres){ n   assert(0); n } n template<int k> node<k>* update(node<k> *a, int val) n { n     if(a == NULL) return NULL; n     a -> push(); n   assert(val<(1<<(k+1))); n     if((val & a -> has[0] & a -> has[1]) == 0) n     { n         a -> lazy ^= (val & a ->has[0]); n         return a; n     } n     node<k - 1>*l, *r; n     std::tie(l, r) = destruct(a); n     l = update<k - 1>(l, val & ~(1 << k)); n     r = update<k - 1>(r, val & ~(1 << k)); n     if(val & (1 << k)) n     { n         return join<k>(NULL, merge<k - 1>(l, r)); n     } n     else n     { n         return join<k>(l, r); n     } n } n template<>node<-1>*update(node<-1>*a, int val) n { n     return a; n } n  n int main() n { n   //  ifstream cin( input1.txt.4c ); n //    ios_base::sync_with_stdio(0); n   //  cin.tie(0); n     //cout.tie(0); n     node<19>* root = NULL; n     int n, q; n     //cin >> n >> q; n     scanf( %d %d , &n, &q); n    // printf( A n ); n     for(int i = 0; i< n; i++) n     { n         int a; n         scanf( %d , &a); n       //  root = create<19> (a); n         root = merge(root, create<19>(a)); n     } n     while(q--) n     { n         int t, l, r; n         scanf( %d%d%d , &t, &l, &r); n         node<19>*left, *right; n         std::tie(left, root) = split(root, l); n         std::tie(root, right) = split(root, r + 1); n         if(t == 4) n         { n             if(root) n             { n                 printf( %d n , root -> cnt); n                // return 0; n             } n             else n             { n                 printf( 0 n ); n                 //return 0; n             } n         } n         else n         { n             int x; n             scanf( %d , &x); n             if(root != NULL) n             { n                 if(t == 1) n                 { n                     root -> lazy ^= ((1 << 20) - 1); n                     root = update(root, x ^ ((1 << 20) - 1)); n                     root -> lazy ^= ((1 << 20) - 1); n                 } n                 else if(t == 2) n                 { n                     root = update(root, x); n                 } n                 else n                 { n                     root -> lazy ^=x; n                 } n             } n         } n         root = merge(root, left); n         root = merge(root, right); n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long double a, b, c; n   cin >> a >> b >> c; n   vector<int_fast64_t> am; n   int_fast64_t k = 1, max = pow(10, 9); n   int_fast64_t f = pow(k, a) * b + c; n   while (k <= 81 && f <= max) { n     int_fast64_t sum = 0, n = f; n     while (f != 0) { n       sum += f % 10; n       f /= 10; n     } n     if (sum == k) am.emplace_back(n); n     k++; n     f = pow(k, a) * b + c; n   } n   cout << am.size() <<   n ; n   for (int_fast64_t i = 0; i < am.size(); i++) { n     cout << am[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n using lli = int64_t; n const int maxN = 100010; n vector<int> adj[maxN]; n int input[maxN]; n bool visited[maxN]; n int cost = INT_MAX; n void dfs(int node) { n   visited[node] = true; n   cost = min(cost, input[node]); n   for (auto child : adj[node]) { n     if (!visited[child]) { n       dfs(child); n     } n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int T = 1; n   for (int t = 1; t <= T; t++) { n     int n, m; n     cin >> n >> m; n     for (int i = 1; i <= n; i++) { n       cin >> input[i]; n     } n     for (int i = 1; i <= m; i++) { n       int u, v; n       cin >> u >> v; n       adj[u].push_back(v); n       adj[v].push_back(u); n     } n     int64_t total_cost = 0; n     for (int i = 1; i <= n; i++) { n       cost = input[i]; n       if (!visited[i]) { n         dfs(i); n         total_cost += cost; n       } n     } n     cout << total_cost <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int SIZE = 200010; n const long long INF = 1e17; n const long long INF_half = 1e16 + 1e10; n struct data { n   long long v, c; n   data(long long _v = 0, long long _c = 0) : v(_v), c(_c) {} n   bool operator<(const data& b) const { n     return c < b.c || (c == b.c && v > b.v); n   } n   void scan() { scanf( %I64d%I64d , &v, &c); } n } a[SIZE]; n long long S; n struct Line { n   long long x, y; n   long long v; n   Line(long long _x = 0, long long _y = 0, long long _v = 0) n       : x(_x), y(_y), v(_v) {} n   long long inter(const Line& b) { n     long long ll, rr; n     ll = b.x; n     rr = (INF - b.y) / b.v + b.x; n     while (ll < rr) { n       long long mm = (ll + rr) >> 1; n       if (b.y + (mm - b.x) * b.v >= y + (mm - x) * v) n         rr = mm; n       else n         ll = mm + 1; n     } n     if (rr == (INF - b.y) / b.v + b.x) return INF; n     return ll; n   } n } ss[SIZE]; n long long over_pos[SIZE]; n int sn; n void add_line(pair<long long, long long> st, long long v) { n   if (st.second >= INF) return; n   if (sn == 0) { n     ss[sn++] = Line(st.first, st.second, v); n   } else { n     Line now = Line(st.first, st.second, v); n     while (sn > 1) { n       long long tmp = ss[sn - 2].inter(now); n       if (tmp == INF) return; n       if (tmp <= over_pos[sn - 1]) { n         if (tmp == over_pos[sn - 1] && tmp < ss[sn - 1].inter(now)) break; n         sn--; n       } else n         break; n     } n     over_pos[sn] = ss[sn - 1].inter(now); n     if (over_pos[sn] < INF) ss[sn++] = now; n   } n } n pair<long long, long long> get_time(long long t) { n   int ll = 0, rr = sn - 1; n   while (ll < rr) { n     int mm = (ll + rr) >> 1; n     if (ss[mm].y + (over_pos[mm + 1] - 1 - ss[mm].x) * ss[mm].v < t) n       ll = mm + 1; n     else n       rr = mm; n   } n   if (ss[ll].y >= t) return make_pair(ss[ll].x, ss[ll].y - t); n   long long need = (t - ss[ll].y + ss[ll].v - 1) / ss[ll].v; n   return make_pair(ss[ll].x + need, ss[ll].y + ss[ll].v * need - t); n } n int main() { n   int n; n   scanf( %d%I64d , &n, &S); n   for (int i = 0; i < (n); ++i) { n     a[i].scan(); n   } n   sort(a, a + n); n   long long now = a[0].v; n   add_line(make_pair(0LL, 0LL), a[0].v); n   for (int i = 1; i < n; i++) { n     if (a[i].v <= now) continue; n     pair<long long, long long> t = get_time(a[i].c); n     add_line(t, a[i].v); n     now = max(now, a[i].v); n   } n   pair<long long, long long> an = get_time(S); n   printf( %I64d n , an.first); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int max(int a, int b) { n   if (a > b) n     return a; n   else n     return b; n } n int main() { n   long int x, y, z, w, mx; n   cin >> x >> y >> z >> w; n   mx = max(w, max(z, max(x, y))); n   if (mx == w) { n     cout << (mx - z) <<     << (mx - y) <<     << (mx - x); n   } else if (mx == z) { n     cout << (mx - w) <<     << (mx - y) <<     << (mx - x); n   } else if (mx == y) { n     cout << (mx - z) <<     << (mx - w) <<     << (mx - x); n   } else { n     cout << (mx - z) <<     << (mx - y) <<     << (mx - w); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, f1; n   int b[100005], i, j; n   scanf( %d%d , &n, &m); n   map<int, int> Q, q; n   for (i = 1; i <= n; i++) { n     scanf( %d , &f1); n     q[f1]++; n     Q[f1] = i; n   } n   for (i = 1; i <= m; i++) { n     scanf( %d , &b[i]); n   } n   int flag = 0, f = 0; n   for (i = 1; i <= m; i++) { n     if (q[b[i]] == 0) { n       f = 1; n       break; n     } n     if (q[b[i]] >= 2) { n       flag = 1; n       q[b[i]]--; n     } n   } n   if (f == 1) n     printf( Impossible n ); n   else if (flag == 1) n     printf( Ambiguity n ); n   else { n     printf( Possible n ); n     for (i = 1; i <= m; i++) { n       if (i == 1) { n         printf( %d , Q[b[i]]); n       } else n         printf(  %d , Q[b[i]]); n     } n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 100; n char s[N]; n int n, m, t[N]; n int a[N * 4], b[N * 4], ab[N * 4], ba[N * 4], aba[N * 4], tag[N * 4]; n void pushup(int now) { n   a[now] = max(a[(now << 1)], a[(now << 1 | 1)]); n   b[now] = min(b[(now << 1)], b[(now << 1 | 1)]); n   ab[now] = max(ab[(now << 1)], n                 max(ab[(now << 1 | 1)], a[(now << 1)] - 2 * b[(now << 1 | 1)])); n   ba[now] = max(ba[(now << 1)], n                 max(ba[(now << 1 | 1)], a[(now << 1 | 1)] - 2 * b[(now << 1)])); n   aba[now] = max(max(aba[(now << 1)], aba[(now << 1 | 1)]), n                  max(ab[(now << 1)] + a[(now << 1 | 1)], n                      ba[(now << 1 | 1)] + a[(now << 1)])); n } n void build(int now, int l, int r) { n   if (l + 1 == r) { n     a[now] = b[now] = t[l]; n     ab[now] = ba[now] = -t[l]; n     return; n   } n   int mid = (l + r) >> 1; n   build((now << 1), l, mid); n   build((now << 1 | 1), mid, r); n   pushup(now); n } n void down(int now, int val) { n   a[now] += val; n   b[now] += val; n   ab[now] -= val; n   ba[now] -= val; n   tag[now] += val; n } n void pushdown(int now) { n   down((now << 1), tag[now]); n   down((now << 1 | 1), tag[now]); n   tag[now] = 0; n } n void Insert(int now, int l, int r, int a, int b, int val) { n   if (a <= l && b >= r - 1) { n     down(now, val); n     return; n   } n   int mid = (l + r) >> 1; n   pushdown(now); n   if (a < mid) Insert((now << 1), l, mid, a, b, val); n   if (b >= mid) Insert((now << 1 | 1), mid, r, a, b, val); n   pushup(now); n } n int main() { n   int x, y, z; n   scanf( %d%d , &n, &m); n   n = n * 2 - 2; n   scanf( %s , s + 1); n   for (int i = 1; i <= n; ++i) n     if (s[i] ==  ( ) n       t[i] = t[i - 1] + 1; n     else n       t[i] = t[i - 1] - 1; n   build(1, 1, n + 1); n   printf( %d n , aba[1]); n   for (int i = 0; i < m; ++i) { n     scanf( %d%d , &x, &y); n     if (x > y) swap(x, y); n     if (s[x] ==  ( ) n       z = -2; n     else n       z = 2; n     Insert(1, 1, n + 1, x, y - 1, z); n     swap(s[x], s[y]); n     printf( %d n , aba[1]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e9 + 1; n const long double pi = 3.1415926535897; n void solve() { n   int n, ans(0); n   cin >> n; n   int a[n], b[5001] = {0}; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (b[a[i]] == 0) b[a[i]] = 1; n   } n   for (int i = 1; i < n + 1; i++) n     if (!b[i]) ans++; n   cout << ans; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   while (t--) { n     solve(); n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, x = 0, i, j; n   vector<pair<int, int> > v; n   map<int, vector<int> > mp; n   map<int, vector<int> >::iterator it; n   scanf( %d %d , &n, &m); n   for (i = 0; i < m; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     x--; n     y--; n     mp[x].push_back(y); n   } n   for (it = mp.begin(); it != mp.end(); it++) n     sort(it->second.begin(), it->second.end()); n   v.push_back(make_pair(0, 0)); n   for (it = mp.begin(); it != mp.end(); it++) { n     vector<pair<int, int> > w; n     if (x < it->first) { n       int y = v[0].first; n       v.clear(); n       v.push_back(make_pair(y, n - 1)); n     } n     for (i = 0, j = 0; i < v.size() && j < it->second.size();) { n       if (v[i].second < it->second[j]) { n         w.push_back(make_pair(v[i].first, it->second[j] - 1)); n         while (i < v.size() && v[i].second < it->second[j]) i++; n         if (i < v.size()) { n           v[i].first = max(v[i].first, it->second[j] + 1); n           if (v[i].first > v[i].second) i++; n         } n       } else if (v[i].first > it->second[j]) { n         j++; n       } else { n         if (v[i].first != it->second[j]) n           w.push_back(make_pair(v[i].first, it->second[j] - 1)); n         if (v[i].second != it->second[j]) { n           v[i].first = it->second[j] + 1; n         } else { n           i++; n         } n         j++; n       } n     } n     if (i < v.size()) w.push_back(make_pair(v[i].first, n - 1)); n     if (w.size() == 0) { n       puts( -1 ); n       return 0; n     } n     v.swap(w); n     x = it->first + 1; n   } n   if (x == n && v.back().second != n - 1) { n     puts( -1 ); n   } else { n     printf( %d n , (n - 1) * 2); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int marcg[112], marcb[112], n, m, b, g, xi; n int main() { n   scanf( %d %d , &n, &m); n   scanf( %d , &b); n   for (int i = 0; i < b; i++) { n     scanf( %d , &xi); n     marcb[xi] = 1; n   } n   scanf( %d , &g); n   for (int i = 0; i < g; i++) { n     scanf( %d , &xi); n     marcg[xi] = 1; n   } n   int mud = 1; n   while (mud != 0) { n     mud = 0; n     for (int i = 0; i < n * m; i++) { n       if (marcg[i % m] == marcb[i % n]) continue; n       marcg[i % m] = 1; n       marcb[i % n] = 1; n       mud = 1; n     } n   } n   int ok = 0; n   for (int i = 0; i < m; i++) { n     if (marcg[i] == 0) ok = 1; n   } n   if (ok != 0) { n     printf( No n ); n     return 0; n   } n   for (int i = 0; i < n; i++) { n     if (marcb[i] == 0) ok = 1; n   } n   if (ok != 0) { n     printf( No n ); n     return 0; n   } n   printf( Yes n ); n } n


#include <bits/stdc++.h> n using namespace std; n char arr[500001]; n char inv(char temp) { n   if (temp ==  0 ) return  1 ; n   return  0 ; n } n string invert(string temp) { n   int n = temp.length(); n   if (n % 2 == 1) { n     for (int i = 1; i < n; i += 2) temp[i] = inv(temp[i]); n   } else { n     for (int i = 1; i < n / 2; i += 2) temp[i] = inv(temp[i]); n     for (int i = n - 2; i >= n / 2; i -= 2) temp[i] = inv(temp[i]); n   } n   return temp; n } n int main() { n   string ans =   , cur; n   int n, a, b, c, i, j, temp = 1; n   long long res = 0; n   cin >> n; n   cin >> arr[0]; n   cur = arr[0]; n   for (i = 1; i < n; i++) { n     cin >> arr[i]; n     if (arr[i] != arr[i - 1]) { n       temp++; n       cur += arr[i]; n     } else { n       if (temp <= 2) n         ans += cur; n       else { n         res = fmax(res, (cur.length() - 1) / 2); n         ans += invert(cur); n       } n       temp = 1; n       cur = arr[i]; n     } n   } n   if (temp <= 2) n     ans += cur; n   else { n     ans += invert(cur); n     res = fmax(res, (cur.length() - 1) / 2); n   } n   cout << res << endl; n   for (i = 0; i < ans.size(); i++) cout << ans[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n long long i, j; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, d; n   cin >> n >> d; n   string s; n   cin >> s; n   long long p = 0, tot = 0; n   while (1) { n     long long f = 0; n     for (i = min(p + d, n - 1); i > p; i--) { n       if (s[i] ==  1 ) { n         tot++; n         p = i; n         f = 1; n         break; n       } n     } n     if (f == 0) { n       cout << -1 << endl; n       return 0; n     } n     if (p == n - 1) { n       cout << tot << endl; n       return 0; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int A[n + 1], S[n + 1], S1[n + 3]; n   A[0] = 0; n   for (int i = 1; i <= n; i++) { n     cin >> A[i]; n   } n   S[0] = 0; n   for (int i = 1; i <= n; i++) { n     S[i] = S[i - 1] + A[i]; n   } n   string st; n   cin >> st; n   S1[n + 1] = 0; n   S1[n + 2] = 0; n   for (int i = n; i > 0; i--) { n     S1[i] = S1[i + 1] + (st[i - 1] -  0 ) * A[i]; n   } n   int ans = -1; n   for (int i = n; i > 0; i--) { n     int aux; n     if (st[i - 1] ==  1 ) { n       ans = max(ans, S1[i + 1] + S[i - 1]); n     } n   } n   cout << max(ans, S1[1]) << endl; n   return 0; n } n


#include <bits/stdc++.h> n template <typename T, typename S> n inline bool upmin(T& a, const S& b) { n   return a > b ? a = b, 1 : 0; n } n template <typename T, typename S> n inline bool upmax(T& a, const S& b) { n   return a < b ? a = b, 1 : 0; n } n using namespace std; n const int dx[4] = {-1, 0, 1, 0}; n const int dy[4] = {0, 1, 0, -1}; n const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; n const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1}; n inline bool is_down(char x) { return ( a  <= x && x <=  z ); } n inline bool is_upper(char x) { return ( A  <= x && x <=  Z ); } n inline bool is_digit(char x) { return ( 0  <= x && x <=  9 ); } n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = 10 * x + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n inline long long readll() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = 10 * x + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; } n long long power(long long x, long long y) { n   long long t = 1; n   for (; y; y >>= 1, x = x * x % (1000000007)) n     if (y & 1) t = t * x % (1000000007); n   return t; n } n long long n, k; n int main() { n   n = read(); n   k = read(); n   string s, t; n   cin >> s; n   cin >> t; n   long long cnt = 1, ans = 0; n   for (int i = 0; i <= n - 1; i++) { n     cnt = (cnt - 1) * 2 + (t[i] -  a ) - (s[i] -  a ) + 1; n     if (cnt >= k) { n       ans += (n - i) * k; n       break; n     } else { n       ans += cnt; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const int MAXN = 1e6; n int solve(int a, int b, int c) { n   if (b < a) swap(a, b); n   int dis = b - a; n   int statr = 1; n   int all = dis * 2; n   int res = 0; n   if (a - dis >= 1 || c > 2 * dis) return -1; n   if (c > dis) res = c - dis; n   if (c <= dis) res = c + dis; n   return res; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     int a, b, c; n     cin >> a >> b >> c; n     cout << solve(a, b, c) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, q; n   cin >> n >> m; n   if (m) n     q = min(m, n - m); n   else n     q = 1; n   cout << q << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, mn = 200, c = 0, x, y, i; n int main() { n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> x >> y; n     mn = min(mn, y); n     c += x * mn; n   } n   cout << c; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5; n int n; n pair<int, int> Cd[N + 10]; n int cop[2 * N + 10], lnk[2 * N + 10]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) n     scanf( %d , &Cd[i].first), Cd[i].second = i * 2 - 1; n   sort(Cd + 1, Cd + 1 + n); n   int L = 1, R = n, LEN = Cd[n].first; n   cop[1] = Cd[n].second; n   cop[++LEN] = Cd[n].second + 1; n   int I = n - 1; n   for (int i = n - 1, j = 2; i >= 1 && j <= Cd[n].first; I = --i, j++) { n     int u = Cd[i].second, v = u + 1; n     cop[j] = u; n     lnk[u] = -1; n     if (j + Cd[i].first > LEN) { n       LEN++; n       cop[LEN] = v; n       lnk[v] = -1; n     } else n       lnk[v] = j + Cd[i].first - 1; n   } n   for (int i = I; i >= 1; i--) { n     int u = Cd[i].second, v = u + 1; n     if (Cd[i].first == 1) { n       lnk[u] = lnk[v] = -1; n       printf( %d %d n , cop[1], u); n       printf( %d %d n , u, v); n     } else { n       lnk[u] = 1; n       lnk[v] = 1 + (Cd[i].first - 2); n     } n   } n   for (int i = 2; i <= LEN; i++) printf( %d %d n , cop[i], cop[i - 1]); n   for (int i = 1; i <= 2 * n; i++) n     if (lnk[i] > 0) printf( %d %d n , i, cop[lnk[i]]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef pair<long long, long long> ll; n typedef vector<long long> vl; n typedef vector<ll> vll; n typedef vector<vl> vvl; n template <typename T> n ostream &operator<<(ostream &o, vector<T> v) { n   if (v.size() > 0) o << v[0]; n   for (unsigned i = 1; i < v.size(); i++) o <<     << v[i]; n   return o <<   n ; n } n template <typename U, typename V> n ostream &operator<<(ostream &o, pair<U, V> p) { n   return o <<  (  << p.first <<  ,   << p.second <<  )  ; n } n template <typename T> n istream &operator>>(istream &in, vector<T> &v) { n   for (unsigned i = 0; i < v.size(); i++) in >> v[i]; n   return in; n } n template <typename T> n istream &operator>>(istream &in, pair<T, T> &p) { n   in >> p.first; n   in >> p.second; n   return in; n } n int main() { n   std::ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cout.precision(20); n   long long k, b, n; n   cin >> k >> b >> n; n   vl a(n); n   cin >> a; n   map<long long, long long> ma; n   ma[0]++; n   long long tot = 0; n   long long ans = 0; n   long long z = 0; n   for (long long i = (0); i < (long long)n; i++) { n     tot += a[i]; n     tot %= (k - 1); n     if (a[i] == 0) n       z++; n     else n       z = 0; n     long long tmp = (tot + k - 1 - b) % (k - 1); n     if (b == k - 1 or b == 0) { n       if (b == 0) n         ans += z; n       else n         ans += ma[tmp] - z; n     } else n       ans += ma[tmp]; n     ma[tot]++; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,avx ) n using namespace std; n const int MAXSIZE = 10000020; n int bufpos; n char buf[MAXSIZE]; n void init() { n   buf[fread(buf, 1, MAXSIZE, stdin)] =   0 ; n   bufpos = 0; n } n int readint() { n   int val = 0; n   for (; !isdigit(buf[bufpos]); bufpos++) n     ; n   for (; isdigit(buf[bufpos]); bufpos++) val = val * 10 + buf[bufpos] -  0 ; n   return val; n } n char readchar() { n   for (; isspace(buf[bufpos]); bufpos++) n     ; n   return buf[bufpos++]; n } n int readstr(char *s) { n   int cur = 0; n   for (; isspace(buf[bufpos]); bufpos++) n     ; n   for (; !isspace(buf[bufpos]); bufpos++) s[cur++] = buf[bufpos]; n   s[cur] =   0 ; n   return cur; n } n char bf[1 << 25], st[20], *w = bf; n void flush() { n   fwrite(bf, 1, w - bf, stdout); n   w = bf; n } n inline void pc(register char c) { *w++ = c; } n void print(register int n) { n   register char *t = st; n   do { n     *t++ = n % 10 + 48; n   } while (n /= 10); n   while (t-- > st) pc(*t); n } n int n, q, fa[66666], aa[66666], kh[66666], a[66666], p[66666], fp[66666], n     siz[66666], ck, pa[66666]; n vector<int> edge[66666]; n int dd[66666]; n void dfs(int u) { n   siz[u] = 1; n   p[++ck] = u; n   fp[u] = ck; n   pa[ck] = fp[fa[u]]; n   dd[ck] = dd[pa[ck]] + 1; n   for (auto v : edge[u]) { n     dfs(v); n     siz[u] += siz[v]; n   } n } n int main() { n   init(); n   n = readint(); n   q = readint(); n   for (int i = 1; i <= n; ++i) { n     aa[i] = readint(); n   } n   for (int i = 2; i <= n; ++i) { n     fa[i] = readint(); n     edge[fa[i]].push_back(i); n   } n   dfs(1); n   for (int i = 1; i <= n; ++i) { n     a[fp[i]] = aa[i]; n     kh[i] = -50001; n   } n   for (int i = 1; i <= q; ++i) { n     int x = readint(); n     int y = siz[x]; n     x = fp[x]; n     int pp = i + 1, gg = y >> 3, *jj = kh + x, *diao = dd + x, *aa = a + x; n     int ans = 0, cnt = 0; n     for (int j = 0; j < gg; ++j, jj += 8, diao += 8, aa += 8) { n       int w; n       w = jj[0] + aa[0] < pp, jj[0] = w ? i : jj[0], ans += w * diao[0], n       cnt += w; n       w = jj[1] + aa[1] < pp, jj[1] = w ? i : jj[1], ans += w * diao[1], n       cnt += w; n       w = jj[2] + aa[2] < pp, jj[2] = w ? i : jj[2], ans += w * diao[2], n       cnt += w; n       w = jj[3] + aa[3] < pp, jj[3] = w ? i : jj[3], ans += w * diao[3], n       cnt += w; n       w = jj[4] + aa[4] < pp, jj[4] = w ? i : jj[4], ans += w * diao[4], n       cnt += w; n       w = jj[5] + aa[5] < pp, jj[5] = w ? i : jj[5], ans += w * diao[5], n       cnt += w; n       w = jj[6] + aa[6] < pp, jj[6] = w ? i : jj[6], ans += w * diao[6], n       cnt += w; n       w = jj[7] + aa[7] < pp, jj[7] = w ? i : jj[7], ans += w * diao[7], n       cnt += w; n     } n     gg <<= 3; n     for (int j = gg; j < y; ++j) { n       int w; n       w = jj[j - gg] + aa[j - gg] < pp, jj[j - gg] = w ? i : jj[j - gg], n       ans += w * diao[j - gg], cnt += w; n       ; n     } n     ans = ans - cnt * dd[x]; n     print(ans); n     pc(   ); n     print(cnt); n     pc(  n ); n   } n   flush(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   vector<int> a(n); n   priority_queue<pair<int, int>, vector<pair<int, int>>, n                  greater<pair<int, int>>> n       pq; n   long long sum = 0; n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n     sum += a[i] / 10; n     pq.push(pair<int, int>(10 - (a[i] % 10), i)); n   } n   while (!pq.empty()) { n     pair<int, int> t = pq.top(); n     pq.pop(); n     int val = t.first; n     int ind = t.second; n     sum -= a[ind] / 10; n     a[ind] += val; n     sum += a[ind] / 10; n     if (a[ind] <= 100 && k >= val) { n       k -= val; n       pq.push(pair<int, int>(10 - (a[ind] % 10), ind)); n     } else { n       sum -= a[ind] / 10; n       a[ind] -= val; n       sum += a[ind] / 10; n     } n     if (k < 0) break; n   } n   cout << sum; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100100; n int main() { n   string s, ans; n   cin >> s; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  . ) ans +=  0 ; n     if (s[i] ==  - ) { n       i++; n       if (s[i] ==  . ) n         ans +=  1 ; n       else n         ans +=  2 ; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int l = s.length(); n   int ans = ((l + 1) * 26) - l; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 mt_rand(time(0)); n const int N = 3e5 + 5; n int q, n, s[N], maks[N], dp[N]; n map<int, int> mapa[N]; n int main() { n   scanf( %d , &q); n   while (q--) { n     scanf( %d , &n); n     for (int i = 0; i < n; i++) scanf( %d , &s[i]); n     for (int i = 0; i < n; i++) { n       maks[i] = -1; n       mapa[i].clear(); n       dp[i] = 0; n     } n     mapa[0][s[0]] = 0; n     for (int i = 1; i < n; i++) { n       if (mapa[i - 1].count(s[i])) { n         int pos = mapa[i - 1][s[i]]; n         maks[i] = pos; n         swap(mapa[i], mapa[pos - 1]); n         if (pos > 0) mapa[i][s[pos - 1]] = pos - 1; n       } n       mapa[i][s[i]] = i; n     } n     long long ans = 0; n     for (int i = 1; i < n; i++) { n       if (maks[i] == -1) n         dp[i] = 0; n       else if (maks[i] == 0) n         dp[i] = 1; n       else n         dp[i] = 1 + dp[maks[i] - 1]; n       ans += dp[i]; n     } n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int MAXN = 1e5 + 5; n ll x; n string s; n int ans[MAXN]; n void init() { n   ; n   ; n } n void solve(int casei) { n   ll n = s.length(); n   s =  #  + s; n   for (int i = 1; i <= n; ++i) { n     ans[i] = -1; n   } n   for (int i = 1; i <= n; ++i) { n     if (s[i] ==  0 ) { n       if (i + x <= n) ans[i + x] = 0; n       if (i - x >= 1) ans[i - x] = 0; n     } n   } n   for (int i = 1; i <= n; ++i) { n     if (s[i] ==  1 ) { n       bool flg = false; n       if (i + x <= n && ans[i + x] != 0) ans[i + x] = 1, flg = true; n       if (i - x >= 1 && ans[i - x] != 0) ans[i - x] = 1, flg = true; n       if (flg == false) { n         cout <<  -1 n ; n         return; n       } n     } n   } n   for (int i = 1; i <= n; ++i) { n     if (ans[i] == -1) ans[i] = 1; n   } n   for (int i = 1; i <= n; ++i) cout << ans[i]; n   cout << endl; n } n int main() { n   int Case = 1; n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> Case; n   for (int casei = 1; casei <= Case; ++casei) { n     cin >> s >> x; n     init(); n     solve(casei); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100010; n int v[N]; n int n, k; n int main() { n   scanf( %d %d , &n, &k); n   n--; n   for (int i = 1; i <= n; ++i) scanf( %d , v + i), v[i] += v[i - 1]; n   int ans = 0x3F3F3F3F; n   for (int i = k; i <= n; ++i) ans = min(ans, v[i] - v[i - k]); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int a, b, c, l, ans; n long long int rec(long long int A, long long int B, long long int C, n                   long long int L) { n   if (A < B + C) { n     return 0; n   } n   long long int d = min(L, A - B - C); n   return ((d + 1) * (d + 2)) / 2; n } n int main() { n   while (cin >> a >> b >> c >> l) { n     ans = (l + 3) * (l + 2) * (l + 1); n     ans /= 6; n     for (long long int i = 0; i <= l; i++) { n       ans -= rec(a + i, b, c, l - i); n       ans -= rec(b + i, a, c, l - i); n       ans -= rec(c + i, a, b, l - i); n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n std::istream& operator>>(std::istream& i, pair<T, U>& p) { n   i >> p.first >> p.second; n   return i; n } n template <typename T> n std::istream& operator>>(std::istream& i, vector<T>& t) { n   for (auto& v : t) { n     i >> v; n   } n   return i; n } n template <typename T, typename U> n std::ostream& operator<<(std::ostream& o, const pair<T, U>& p) { n   o << p.first <<     << p.second; n   return o; n } n template <typename T> n std::ostream& operator<<(std::ostream& o, const vector<T>& t) { n   if (t.empty()) o <<   n ; n   for (size_t i = 0; i < t.size(); ++i) { n     o << t[i] <<    n [i == t.size() - 1]; n   } n   return o; n } n template <typename T> n using minheap = priority_queue<T, vector<T>, greater<T>>; n template <typename T> n using maxheap = priority_queue<T, vector<T>, less<T>>; n template <typename T> n bool in(T a, T b, T c) { n   return a <= b && b < c; n } n unsigned int logceil(int first) { n   return 8 * sizeof(int) - __builtin_clz(first); n } n namespace std { n template <typename T, typename U> n struct hash<pair<T, U>> { n   hash<T> t; n   hash<U> u; n   size_t operator()(const pair<T, U>& p) const { n     return t(p.first) ^ (u(p.second) << 7); n   } n }; n }  // namespace std n template <typename T, typename F> n T bsh(T l, T h, const F& f) { n   T r = -1, m; n   while (l <= h) { n     m = (l + h) / 2; n     if (f(m)) { n       l = m + 1; n       r = m; n     } else { n       h = m - 1; n     } n   } n   return r; n } n template <typename F> n double bshd(double l, double h, const F& f, double p = 1e-9) { n   unsigned int r = 3 + (unsigned int)log2((h - l) / p); n   while (r--) { n     double m = (l + h) / 2; n     if (f(m)) { n       l = m; n     } else { n       h = m; n     } n   } n   return (l + h) / 2; n } n template <typename T, typename F> n T bsl(T l, T h, const F& f) { n   T r = -1, m; n   while (l <= h) { n     m = (l + h) / 2; n     if (f(m)) { n       h = m - 1; n       r = m; n     } else { n       l = m + 1; n     } n   } n   return r; n } n template <typename F> n double bsld(double l, double h, const F& f, double p = 1e-9) { n   unsigned int r = 3 + (unsigned int)log2((h - l) / p); n   while (r--) { n     double m = (l + h) / 2; n     if (f(m)) { n       h = m; n     } else { n       l = m; n     } n   } n   return (l + h) / 2; n } n template <typename T> n T gcd(T a, T b) { n   if (a < b) swap(a, b); n   return b ? gcd(b, a % b) : a; n } n template <typename T> n class vector2 : public vector<vector<T>> { n  public: n   vector2() {} n   vector2(size_t a, size_t b, T t = T()) n       : vector<vector<T>>(a, vector<T>(b, t)) {} n }; n template <typename T> n class vector3 : public vector<vector2<T>> { n  public: n   vector3() {} n   vector3(size_t a, size_t b, size_t c, T t = T()) n       : vector<vector2<T>>(a, vector2<T>(b, c, t)) {} n }; n template <typename T> n class vector4 : public vector<vector3<T>> { n  public: n   vector4() {} n   vector4(size_t a, size_t b, size_t c, size_t d, T t = T()) n       : vector<vector3<T>>(a, vector3<T>(b, c, d, t)) {} n }; n template <typename T> n class vector5 : public vector<vector4<T>> { n  public: n   vector5() {} n   vector5(size_t a, size_t b, size_t c, size_t d, size_t e, T t = T()) n       : vector<vector4<T>>(a, vector4<T>(b, c, d, e, t)) {} n }; n template <unsigned int N> n class Field { n   inline unsigned int pow(unsigned int a, unsigned int p) { n     unsigned int r = 1, e = a; n     while (p) { n       if (p & 1) { n         r = ((unsigned long long)r * e) % N; n       } n       e = ((unsigned long long)e * e) % N; n       p >>= 1; n     } n     return r; n   } n   inline unsigned int inv(unsigned int a) { return pow(a, N - 2); } n  n  public: n   inline Field(int first = 0) : v(first) {} n   inline Field<N> pow(int p) { return (*this) ^ p; } n   inline Field<N> operator^(int p) { return {(int)pow(v, (unsigned int)p)}; } n   inline Field<N>& operator+=(const Field<N>& o) { n     if ((long long)v + o.v >= N) n       v += o.v - N; n     else n       v += o.v; n     return *this; n   } n   inline Field<N>& operator-=(const Field<N>& o) { n     if (v < o.v) n       v -= o.v - N; n     else n       v -= o.v; n     return *this; n   } n   inline Field<N>& operator*=(const Field<N>& o) { n     v = (unsigned long long)v * o.v % N; n     return *this; n   } n   inline Field<N>& operator/=(const Field<N>& o) { return *this *= inv(o.v); } n   inline Field<N> operator+(const Field<N>& o) const { n     Field<N> r{*this}; n     return r += o; n   } n   inline Field<N> operator-(const Field<N>& o) const { n     Field<N> r{*this}; n     return r -= o; n   } n   inline Field<N> operator*(const Field<N>& o) const { n     Field<N> r{*this}; n     return r *= o; n   } n   inline Field<N> operator/(const Field<N>& o) const { n     Field<N> r{*this}; n     return r /= o; n   } n   inline Field<N> operator-() { n     if (v) n       return {(int)(N - v)}; n     else n       return {0}; n   }; n   inline Field<N>& operator++() { n     ++v; n     if (v == N) v = 0; n     return *this; n   } n   inline Field<N> operator++(int) { n     Field<N> r{*this}; n     ++*this; n     return r; n   } n   inline Field<N>& operator--() { n     --v; n     if (v == -1) v = N - 1; n     return *this; n   } n   inline Field<N> operator--(int) { n     Field<N> r{*this}; n     --*this; n     return r; n   } n   inline bool operator==(const Field<N>& o) const { return o.v == v; } n   inline bool operator!=(const Field<N>& o) const { return o.v != v; } n   inline explicit operator unsigned int() const { return v; } n   inline static vector<Field<N>> fact(int t) { n     vector<Field<N>> F(t + 1, 1); n     for (int i = 2; i <= t; ++i) { n       F[i] = F[i - 1] * i; n     } n     return F; n   } n   inline static vector<Field<N>> invfact(int t) { n     vector<Field<N>> F(t + 1, 1); n     Field<N> X{1}; n     for (int i = 2; i <= t; ++i) { n       X = X * i; n     } n     F[t] = 1 / X; n     for (int i = t - 1; i >= 2; --i) { n       F[i] = F[i + 1] * (i + 1); n     } n     return F; n   } n  n  private: n   unsigned int v; n }; n template <unsigned int N> n istream& operator>>(std::istream& is, Field<N>& f) { n   unsigned int v; n   is >> v; n   f = v; n   return is; n } n template <unsigned int N> n ostream& operator<<(std::ostream& os, const Field<N>& f) { n   return os << (unsigned int)f; n } n template <unsigned int N> n Field<N> operator+(int i, const Field<N>& f) { n   return Field<N>(i) + f; n } n template <unsigned int N> n Field<N> operator-(int i, const Field<N>& f) { n   return Field<N>(i) - f; n } n template <unsigned int N> n Field<N> operator*(int i, const Field<N>& f) { n   return Field<N>(i) * f; n } n template <unsigned int N> n Field<N> operator/(int i, const Field<N>& f) { n   return Field<N>(i) / f; n } n struct Ring { n   static int div(int p, int q, int N) { n     long long t = 0, nt = 1, r = N, nr = q; n     while (nr) { n       long long q = r / nr; n       t -= q * nt; n       r -= q * nr; n       swap(t, nt); n       swap(r, nr); n     } n     t = (t < 0) ? t + N : t; n     r = (r < 0) ? r + N : r; n     if (gcd(p, N) % r) { n       return 0; n     } n     return (int)(((long long)t * (long long)p / r) % N); n   } n }; n template <typename T> n struct Fenwick { n   explicit Fenwick(unsigned int N = 0, T t = T()) n       : N(1u << logceil(N)), F(this->N, t), t(t) {} n   explicit Fenwick(const vector<T>& A, T t = T()) n       : N(1u << logceil(A.size())), F(A), t(t) { n     F.resize(N); n     fill(F.begin() + A.size(), F.end(), t); n     for (int i = 0; i < N; i++) { n       int j = i + lsb(i + 1); n       if (j < N) F[j] += F[i]; n     } n   } n   void add(int i, T v) { n     while (i <= N) { n       F[i] += v; n       i += lsb(i + 1); n     } n   } n   T sum(int i) const { n     T sum(t); n     while (i) { n       sum += F[i - 1]; n       i -= lsb(i); n     } n     return sum; n   } n   T range(int i, int j) const { n     j++; n     T s(t); n     while (j > i) { n       s += F[j - 1]; n       j -= lsb(j); n     } n     while (i > j) { n       s -= F[i - 1]; n       i -= lsb(i); n     } n     return s; n   } n   T get(int i) const { return range(i, i); } n   void set(int i, T v) { add(i, v - get(i)); } n   constexpr int lsb(int i) const { return i & -i; } n   unsigned int N; n   vector<T> F; n   T t; n }; n template <typename T> n struct Fenwick2 { n   explicit Fenwick2(unsigned int N = 0, T t = T()) n       : N(1u << logceil(N)), F(this->N, this->N, t), t(t) {} n   void add(int first, int second, T v) { n     while (first <= N) { n       int z = second; n       while (z <= N) { n         F[first][z] += v; n         z += lsb(z + 1); n       } n       first += lsb(first + 1); n     } n   } n   T sum(int first, int second) { n     T sum(t); n     while (first <= N) { n       int z = second; n       while (z <= N) { n         sum += F[first][z]; n         z -= lsb(z + 1); n       } n       first -= lsb(first + 1); n     } n     return sum; n   } n   T range(int x1, int y1, int x2, int y2) { n     T ans = sum(x2, y2); n     if (x1) ans -= sum(x1 - 1, y2); n     if (y1) ans -= sum(x2, y1 - 1); n     if (x1 && y1) ans += sum(x1 - 1, y1 - 1); n     return ans; n   } n   constexpr int lsb(int i) const { return i & -i; } n   unsigned int N; n   vector2<T> F; n   T t; n }; n class LittleElephantAndRetroStrings { n  public: n   void solve(istream& cin, ostream& cout) { n     int N, K; n     cin >> N >> K; n     string S; n     cin >> S; n     vector2<Field<1000000007>> D(2, N - K + 1, 0); n     vector<Field<1000000007>> X(N + 1, 1), R(N + 1, 1); n     vector<int> W(N + 1, 0); n     Field<1000000007> half = Field<1000000007>{1} / 2; n     for (int r = 0; r < 2; ++r) { n       char z = r ?  B  :  W ; n       for (int i = 0; i < N; ++i) { n         W[i + 1] = W[i] + (S[i] == z); n         X[i + 1] = X[i]; n         R[i + 1] = R[i]; n         if (S[i] ==  X ) { n           X[i + 1] += X[i]; n           R[i + 1] *= half; n         } n       } n       Fenwick<Field<1000000007>> F(N, 0), G(N, 0); n       Field<1000000007> f = 0, g = 0; n       for (int i = 0; i + K <= N; ++i) { n         if (W[i + K] == W[i]) { n           D[r][i] = X[i]; n           D[r][i] -= f; n           D[r][i] -= X[i] * g; n         } n         if (i - K >= 0) { n           f -= D[r][i - K]; n           g += D[r][i - K] * R[i]; n         } n         f += D[r][i]; n       } n       for (int i = 0; i + K <= N; ++i) D[r][i] *= R[i + K]; n       if (r) n         for (int i = 1; i + K <= N; ++i) D[1][i] += D[1][i - 1]; n       else n         reverse(S.begin(), S.end()); n     } n     Field<1000000007> ans = 0; n     for (int i = 0; i <= N - 2 * K; ++i) { n       ans += D[0][i] * D[1][N - 2 * K - i]; n     } n     cout << ans * X[N] << endl; n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   LittleElephantAndRetroStrings solver; n   std::istream& in(std::cin); n   std::ostream& out(std::cout); n   solver.solve(in, out); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b; n long long res = 0LL; n int mod = 1000000007; n int main() { n   cin >> a >> b; n   cout << (((((((((a * (a + 1)) / 2 % mod) * (b % mod)) % mod) + a) % mod) % n              mod) * n             ((b * (b - 1)) / 2 % mod)) % n            mod) n        << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; n const long long linf = 4000000000000000000LL; n const long long inf = 998244353; n const long double pi = 3.1415926535; n long long maximum(long long x, long long y) { n   if (x > y) return x; n   return y; n } n long long minimum(long long x, long long y) { n   if (x < y) return x; n   return y; n } n void pv(vector<int> a) { n   for (auto& x : a) cout << x <<    ; n   cout <<   n ; n } n void pv(vector<long long> a) { n   for (auto& x : a) cout << x <<    ; n   cout <<   n ; n } n void pv(vector<vector<int> > a) { n   for (int i = (0); i < (a.size()); ++i) { n     cout << i <<   n ; n     pv(a[i]); n     cout <<   n ; n   } n } n void pv(vector<vector<long long> > a) { n   for (int i = (0); i < (a.size()); ++i) { n     cout << i <<   n ; n     pv(a[i]); n   } n   cout <<   n ; n } n void pv(vector<string> a) { n   for (auto& x : a) cout << x <<   n ; n   cout <<   n ; n } n int modInverse(int a, int m) { n   int m0 = m; n   int y = 0, x = 1; n   if (m == 1) return 0; n   while (a > 1) { n     int q = a / m; n     int t = m; n     m = a % m, a = t; n     t = y; n     y = x - q * y; n     x = t; n   } n   if (x < 0) x += m0; n   return x; n } n long long power(long long x, long long y) { n   long long k = 1 << 30; n   long long z = 1; n   while (k != 0) { n     z *= z; n     z %= inf; n     if (y >= k) { n       z *= x; n       z %= inf; n       y -= k; n     } n     k >>= 1; n   } n   return z; n } n long double area(pair<int, int> x, pair<int, int> y, pair<int, int> z) { n   return ((long long)x.second * y.first + (long long)y.second * z.first + n           (long long)z.second * x.first - (long long)x.first * y.second - n           (long long)y.first * z.second - (long long)z.first * x.second) / n          2.0; n } n bool clockwise(pair<int, int> x, pair<int, int> y, pair<int, int> z) { n   return area(x, y, z) > 0; n } n struct point { n   long double x, y; n }; n long double area(point x, point y, point z) { n   return (x.y * y.x + y.y * z.x + z.y * x.x - x.x * y.y - y.x * z.y - n           z.x * x.y) / n          2.0; n } n bool clockwise(point x, point y, point z) { return area(x, y, z) > 0; } n int gcd(int a, int b) { n   if (a > b) swap(a, b); n   if (a == 0) return b; n   return gcd(a, b % a); n } n int popcount(int a) { n   int count = 0; n   while (a != 0) { n     count += (a % 2); n     a >>= 1; n   } n   return count; n } n long long choose(long long n, long long r) { n   long long p = 1, k = 1; n   if (n - r < r) r = n - r; n   if (r != 0) { n     while (r) { n       p *= n; n       k *= r; n       long long m = gcd(p, k); n       p /= m; n       k /= m; n       n--; n       r--; n     } n   } else n     p = 1; n   return p; n } n vector<long long> prefix_hash(string& a, vector<long long>& powers) { n   int n = int(a.size()); n   vector<long long> prefix(n + 1); n   for (int i = (0); i < (n); ++i) n     prefix[i + 1] = (prefix[i] + powers[i] * (a[i] -  a  + 1)) % inf; n   return prefix; n } n void setIO(string second) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n } n int n; n vector<vector<int> > adj; n vector<int> v; n void dfs(int i, int p) { n   v[i] = 1; n   for (auto& x : adj[i]) { n     if (x != p) dfs(x, i); n   } n } n int main() { n   setIO( test3 ); n   cin >> n; n   adj.resize(n); n   for (int i = (0); i < (n); ++i) { n     int a; n     cin >> a; n     adj[--a].push_back(i); n     adj[i].push_back(a); n   } n   int ans = 0; n   v.resize(n); n   for (int i = (0); i < (n); ++i) { n     if (!v[i]) { n       ans++; n       dfs(i, -1); n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[5050][5050], q[5050][5050]; n int ans[5050], len; n char s[5050]; n void init() { n   for (int i = 0; i < len; i++) { n     int l = 0; n     while (i - l >= 0 && i + l < len && s[i - l] == s[i + l]) n       dp[i - l][i + l] = 1, l++; n     l = 0; n     while (i - l >= 0 && i + 1 + l < len && s[i - l] == s[i + l + 1]) n       dp[i - l][i + l + 1] = 1, l++; n   } n } n void solve() { n   for (int t = 0; t < len; t++) { n     for (int j = 0; j + t < len; j++) { n       if (!dp[j][j + t]) continue; n       int mid; n       if (t % 2 == 0) n         mid = (j + j + t) / 2 - 1; n       else n         mid = (j + j + t) / 2; n       if (mid < j) n         q[j][j + t] = 1; n       else n         q[j][j + t] = q[j][mid] + 1; n       ans[q[j][j + t]]++; n     } n   } n } n int main() { n   scanf( %s , s); n   len = strlen(s); n   memset(dp, 0, sizeof(dp)), memset(ans, 0, sizeof(ans)), n       memset(q, 0, sizeof(q)); n   init(); n   solve(); n   for (int i = len - 1; i >= 1; i--) ans[i] += ans[i + 1]; n   for (int i = 1; i <= len; i++) { n     if (i == 1) n       printf( %d , ans[i]); n     else n       printf(  %d , ans[i]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int x = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) n     x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); n   return x * f; n } n int n, a, b, ans, ansa[1000000], ansb[1000000], cnta, cntb; n bool flag[1000000]; n bool check(int k) { n   int w = a; n   cnta = cntb = 0; n   for (int i = 1; i <= k; i++) n     if (w >= i) n       ansa[++cnta] = i, w -= i; n     else n       break; n   ansa[cnta + 1] = k + 1; n   for (int i = cnta; i >= 1; i--) { n     if (!w) break; n     while (w && ansa[i] + 1 < ansa[i + 1]) ansa[i]++, w--; n   } n   if (b >= 1ll * k * (k + 1) / 2 - (a - w)) n     return 1; n   else n     return 0; n } n int main() { n   a = read(), b = read(); n   n = sqrt((a + b) * 2ll) + 2; n   int l = 0, r = n; n   while (l <= r) { n     int mid = l + r >> 1; n     if (check(mid)) n       ans = mid, l = mid + 1; n     else n       r = mid - 1; n   } n   int w = a; n   cnta = cntb = 0; n   for (int i = 1; i <= ans; i++) n     if (w >= i) n       ansa[++cnta] = i, w -= i; n     else n       break; n   ansa[cnta + 1] = ans + 1; n   for (int i = cnta; i >= 1; i--) { n     if (!w) break; n     while (w && ansa[i] + 1 < ansa[i + 1]) ansa[i]++, w--; n   } n   printf( %d n , cnta); n   for (int i = 1; i <= cnta; i++) printf( %d  , ansa[i]), flag[ansa[i]] = 1; n   cout << endl; n   printf( %d n , ans - cnta); n   for (int i = 1; i <= ans; i++) n     if (!flag[i]) printf( %d  , i); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2010; n int n, ans; n double x[maxn], y[maxn]; n int main() { n   scanf( %d , &n); n   for (int i = 1, a, b, c; i <= n; i++) { n     scanf( %d %d %d , &a, &b, &c); n     x[i] = 1.0 * a * c / (a * a + b * b); n     y[i] = 1.0 * b * c / (a * a + b * b); n   } n   for (int i = 1; i <= n; i++) { n     vector<double> V; n     int cnt = 0; n     for (int j = i + 1; j <= n; j++) { n       if (abs(x[i] - x[j]) > 1e-12) n         V.push_back((y[i] - y[j]) / (x[i] - x[j])); n       else if (abs(y[i] - y[j]) < 1e-12) n         cnt++; n       else n         V.push_back(1e18); n     } n     ans += cnt * (n - i - cnt); n     sort(V.begin(), V.end()); n     for (int j = 0, k; j < V.size(); j = k) { n       for (k = j; k < V.size() && abs(V[j] - V[k]) < 1e-12; k++) n         ; n       ans += (k - j) * (k - j - 1) / 2; n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n int map[55][55]; n int to[55][55][4][2]; n int rx[] = {0, -1, 0, 1}; n int ry[] = {1, 0, -1, 0}; n struct node { n   int x, y, dp, cp; n }; n int main() { n   memset(map, 0, sizeof(map)); n   int n, m, step, i, j; n   char str[55]; n   node now; n   now.x = 1, now.y = 1; n   now.dp = 0, now.cp = 1; n   scanf( %d %d , &n, &step); n   scanf( %s , str + 1); n   m = strlen(str + 1); n   for (i = 1; i <= m; i++) map[1][i] = str[i] -  0 ; n   for (i = 2; i <= n; i++) { n     for (j = 1; j <= m; j++) scanf( %1d , &map[i][j]); n   } n   for (i = 1; i <= n; i++) n     for (j = 1; j <= m; j++) { n       if (map[i][j] == 0) continue; n       for (int dir = 0; dir < 4; dir++) { n         int x = i; n         int y = j; n         while (1) { n           x += rx[dir]; n           y += ry[dir]; n           if (map[x][y] != map[i][j]) { n             x -= rx[dir]; n             y -= ry[dir]; n             break; n           } n         } n         to[i][j][dir][0] = x; n         to[i][j][dir][1] = y; n       } n     } n   for (i = 0; i < step; i++) { n     int x = to[now.x][now.y][now.dp][0]; n     int y = to[now.x][now.y][now.dp][1]; n     now.x = x, now.y = y; n     now.x = to[x][y][(now.dp + now.cp + 4) % 4][0]; n     now.y = to[x][y][(now.dp + now.cp + 4) % 4][1]; n     x = now.x + rx[now.dp]; n     y = now.y + ry[now.dp]; n     if (map[x][y]) { n       now.x = x, now.y = y; n     } else { n       if (now.cp == 1) { n         now.cp = -1; n       } else { n         now.cp = 1; n         now.dp = (now.dp - 1 + 4) % 4; n       } n     } n   } n   printf( %d n , map[now.x][now.y]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool si[1000007]; n int x0 = 1000007; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int x2; n   cin >> x2; n   si[0] = si[1] = false; n   for (int i = 2; i < 1000007; i++) { n     si[i] = true; n   } n   for (int i = 2; i < 1000007; i++) { n     if (si[i]) { n       for (int j = i * 2; j < 1000007; j += i) { n         si[j] = false; n       } n     } n   } n   int lp = 0; n   for (int i = 2; i <= sqrt(x2); i++) { n     if (x2 % i == 0) { n       if (si[i]) lp = max(lp, i); n       if (si[x2 / i]) lp = max(lp, x2 / i); n     } n   } n   for (int x1 = (x2 / lp - 1) * lp + 1; x1 <= x2; x1++) { n     for (int i = 2; i <= sqrt(x1); i++) { n       if (x1 % i == 0) { n         if (si[i]) { n           if (((x1 / i - 1) * i + 1) >= 3) x0 = min(x0, (x1 / i - 1) * i + 1); n         } n         if (si[x1 / i]) { n           if (((i - 1) * (x1 / i) + 1) >= 3) n             x0 = min(x0, (i - 1) * (x1 / i) + 1); n         } n       } n     } n   } n   cout << x0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   string s; n   int n; n   cin >> s; n   n = s.size(); n   s = s +  b ; n   for (int i = 0; i < n; i++) { n     cout << (s[i] != s[i + 1] ? 1 : 0) <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int N; n   cin >> N; n   vector<int> a(N); n   for (int i = 0; i < N; ++i) { n     scanf( %d , &a[i]); n   } n   sort(a.begin(), a.end()); n   int res = 0; n   for (int i = 0; i <= N; ++i) { n     if (a[i] == a[i + 1]) { n       ++res; n       ++i; n     } n   } n   cout << res / 2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool bi[12][12]; n int main() { n   int a, b, c, d, e, x, y, z, n, k, N, M; n   scanf( %d %d , &N, &M); n   scanf( %d %d , &z, &k); n   for (a = 0; a < z; a++) { n     scanf( %d %d , &x, &y); n     bi[x][y] = true; n   } n   z = 0; n   for (a = 1; a <= N; a++) { n     for (b = 1; b <= M; b++) { n       for (c = a; c <= N; c++) { n         for (d = b; d <= M; d++) { n           e = 0; n           for (x = a; x <= c; x++) { n             for (y = b; y <= d; y++) n               if (bi[x][y]) e++; n           } n           if (e >= k) z++; n         } n       } n     } n   } n   cout << z << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long int mx = 0, n; n   cin >> n; n   vector<long int> vec; n   for (int i = 0; i < n; i++) { n     long int x; n     cin >> x; n     vec.push_back(x); n   } n   if (vec.size() == 1) { n     cout <<  1  << endl; n     return 0; n   } n   for (int i = 0; i < n; i++) { n     long int len = 1, temp = vec[i]; n     for (int j = i + 1; j < n; j++) { n       if (vec[j] >= temp) { n         temp = vec[j]; n         len++; n       } else { n         break; n       } n     } n     mx = max(mx, len); n   } n   cout << mx << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } n long long power(long long x, long long y, long long p) { n   long long res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = ((res % p) * (x % p)) % p; n     y = y >> 1; n     x = ((x % p) * (x % p)) % p; n   } n   return res % p; n } n long long raichu(long long x, long long y) { n   long long res = 1; n   while (y > 0) { n     if (y & 1) res = ((res) * (x)); n     y = y >> 1; n     x = ((x) * (x)); n   } n   return res; n } n bool isprime(long long n) { n   if (n < 2) n     return false; n   else if (n == 2) n     return true; n   else if (n % 2 == 0) n     return false; n   else { n     long long z = sqrt(n); n     for (int i = 0; i < z - 1; i++) n       if (n % (i + 2) == 0) return false; n     return true; n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int tests = 1, Tests; n   Tests = tests; n   while (tests--) { n     int n; n     long long A; n     cin >> n >> A; n     vector<int> d(n); n     for (int i = 0; i < n; i++) cin >> d[i]; n     long long sum = 0; n     for (int i = 0; i < n; i++) sum += d[i]; n     for (int i = 0; i < n; i++) { n       long long mi = 1, ma = d[i]; n       long long left = A - (sum - d[i]); n       if (left > 1) { n         mi = left; n       } n       left = A - (n - 1); n       if (left < d[i]) { n         ma = left; n       } n       cout << d[i] - (ma - mi + 1) <<    ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c; n   scanf( %d%d%d , &a, &b, &c); n   for (int i = 1, _b = a; i <= _b; i++) { n     int j = a / i; n     if (b % i == 0 && c % j == 0 && b / i == c / j) { n       printf( %d n , 4 * (i + j + b / i)); n       return 0; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int tt = 1; n   while (tt--) { n     int n; n     cin >> n; n     int a[n - 1]; n     cout <<  ? 2 3  << endl << endl; n     int m; n     cin >> m; n     for (int i = 0; i < n - 1; i++) { n       cout <<  ?   << 1 <<     << i + 2 << endl << endl; n       cin >> a[i]; n     } n     int b[n]; n     for (int i = 2; i < n; i++) b[i] = a[i - 1] - a[i - 2]; n     b[1] = m - b[2]; n     b[0] = a[0] - b[1]; n     cout <<  !  ; n     for (int i = 0; i < n; i++) cout << b[i] <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100 + 5; n double p[N]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> p[i]; n   sort(p + 1, p + n + 1); n   reverse(p + 1, p + n + 1); n   double one = 0, none = 1; n   for (int i = 1; i <= n; i++) { n     double nw = one * (1 - p[i]) + p[i] * none; n     if (nw > one) { n       one = nw; n       none *= (1 - p[i]); n     } else n       break; n   } n   cout << setprecision(9) << one << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long a[200001]; n long b[200001]; n long n; n int main() { n   cin >> n; n   int k = 1; n   for (int i = 1; i <= n; i++) { n     cin >> a[k]; n     if (a[k] != 0) k++; n   } n   k = 1; n   for (int i = 1; i <= n; i++) { n     cin >> b[k]; n     if (b[k] != 0) k++; n   } n   long j = 1; n   while (b[1] != a[j]) { n     j++; n   } n   for (int i = 2; i <= n - 1; i++) { n     j++; n     if (j == n) j = 1; n     if (b[i] != a[j]) { n       cout <<  No  << endl; n       return 0; n     } n   } n   cout <<  Yes  << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O2 ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n const int MAX = 1e6 + 5; n const long long MOD = 1000000007; n struct state { n   int len, link, cnt; n   int nx[26]; n } st[MAX << 1]; n int id, last, cur; n vector<int> v[MAX]; n inline void sa_init() { n   st[0].link = -1; n   memset(st[0].nx, 0, sizeof st[0].nx); n   id = last = st[0].cnt = 0; n } n inline void sa_extend(int c) { n   int clone; n   st[last].nx[c] = cur = ++id; n   st[cur].len = st[last].len + 1; n   v[st[cur].len].push_back(cur); n   st[cur].cnt = 1; n   int p = last; n   while (1) { n     if ((p = st[p].link) == -1) { n       st[cur].link = 0; n       break; n     } n     if (st[p].nx[c]) { n       int q = st[p].nx[c]; n       if (st[p].len + 1 == st[q].len) n         st[cur].link = q; n       else { n         clone = ++id; n         st[clone] = st[q]; n         st[clone].cnt = 0; n         st[clone].len = st[p].len + 1; n         v[st[clone].len].push_back(clone); n         st[q].link = st[cur].link = clone; n         while (p != -1 && st[p].nx[c] == q) { n           st[p].nx[c] = clone; n           p = st[p].link; n         } n       } n       break; n     } else n       st[p].nx[c] = cur; n   } n   last = cur; n   return; n } n inline int lcs(string &s, string &t) { n   sa_init(); n   for (char c : s) sa_extend(c -  a ); n   int best = 0, len = 0; n   cur = 0; n   for (char c : t) { n     c -=  a ; n     while (cur && !st[cur].nx[c]) cur = st[cur].link, len = st[cur].len; n     if (st[cur].nx[c]) { n       cur = st[cur].nx[c]; n       best = max(best, ++len); n     } n   } n   return best; n } n bool vis[MAX << 1]; n vector<int> del; n inline int solve(string &s) { n   int n = s.size(), ans = 0, len = 0; n   del.clear(); n   s += s; n   cur = 0; n   for (char c : s) { n     c -=  a ; n     while (cur && !st[cur].nx[c]) cur = st[cur].link, len = st[cur].len; n     if (st[cur].nx[c]) { n       cur = st[cur].nx[c], ++len; n       if (len == n) { n         if (!vis[cur]) ans += st[cur].cnt, vis[cur] = 1, del.push_back(cur); n         --len; n         if (len == st[st[cur].link].len) cur = st[cur].link; n       } n     } n   } n   for (int i : del) vis[i] = 0; n   return ans; n } n string s; n int q; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   sa_init(); n   cin >> s; n   for (char c : s) sa_extend(c -  a ); n   for (int i = s.size(); i >= 1; --i) n     for (int j : v[i]) st[st[j].link].cnt += st[j].cnt; n   cin >> q; n   while (q--) { n     cin >> s; n     cout << solve(s) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int n; n const int MAXN = 2e5; n pair<ll, int> arr[MAXN]; n ll sum[MAXN]; n ll ans = 1e18; n void init() { ans = 1e18; } n void input() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> arr[i].first; n   } n   for (int j = 0; j < n; j++) { n     cin >> arr[j].second; n   } n   sort(arr, arr + n); n } n void make_sum() { n   sum[0] = arr[0].second; n   for (int i = 1; i < n; i++) { n     sum[i] = sum[i - 1] + arr[i].second; n   } n   ans = sum[n - 1]; n } n void solve() { n   for (int i = 0; i < n; i++) { n     ans = min(ans, max(arr[i].first, sum[n - 1] - sum[i])); n     if (ans == 3) { n     } n   } n } n void output() { cout << ans << endl; } n int main() { n   int number_of_testcases = 1; n   cin >> number_of_testcases; n   while (number_of_testcases--) { n     init(); n     input(); n     make_sum(); n     solve(); n     output(); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n unsigned long long int fibonocci(unsigned long long int n) { n   unsigned long long int f, f1, f2, i; n   f1 = 1; n   f2 = 2; n   i = 2; n   while (1) { n     f = f1 + f2; n     if (f > n) { n       return i - 1; n     } n     f1 = f2; n     f2 = f; n     i++; n   } n } n int main() { n   unsigned long long int n, i, x; n   cin >> n; n   if (n == 2) { n     cout << 1; n     return 0; n   } n   x = fibonocci(n); n   cout << x; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   register int s = 0, f = 0; n   register char ch = getchar(); n   while (!isdigit(ch)) { n     f |= (ch ==  - ); n     ch = getchar(); n   } n   while (isdigit(ch)) { n     s = (s << 1) + (s << 3) + (ch ^ 48); n     ch = getchar(); n   } n   return f ? -s : s; n } n inline void write(int x) { n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   if (x > 9) { n     write(x / 10); n   } n   putchar(x % 10 +  0 ); n } n long long a[1005], n, ans; n signed main() { n   cin >> n; n   for (auto i = 1; i <= n; i += 1) { n     cin >> a[i]; n   } n   for (auto i = 1; i <= n; i += 2) { n     long long sum = 0; n     long long mn = a[i] - 1; n     for (auto j = i + 1; j <= n; j += 2) { n       sum += a[j - 1]; n       sum -= a[j]; n       if (sum < 0) { n         ans += min(a[j] + sum + 1, mn + 1); n         break; n       } else { n         ans += min(a[j], max(0LL, mn - sum + 1)); n         if (j == i + 1) { n           mn = min(a[i], sum); n         } else { n           mn = min(mn, sum); n         } n       } n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int h[15][15]; n int dist[15][15]; n double expect[15][15]; n unordered_map<int, pair<int, int> > dist2pos; n int main() { n   for (int i = 0; i < 10; i++) n     for (int j = 0; j < 10; ++j) cin >> h[i][j]; n   for (int i = 0; i < 10; ++i) n     for (int j = 0; j < 10; ++j) { n       if (i % 2 == 0) { n         dist[i][j] = i + j + 9 * i; n       } else { n         dist[i][j] = i + 9 - j + 9 * i; n       } n       dist2pos[dist[i][j]] = make_pair(i, j); n     } n   bool left = true; n   expect[0][0] = 0.0; n   int x = 0, y = 1; n   while (true) { n     double e = 0.0; n     if (dist[x][y] < 6) { n       for (int dice = 1; dice <= dist[x][y]; ++dice) { n         int xx = dist2pos[dist[x][y] - dice].first; n         int yy = dist2pos[dist[x][y] - dice].second; n         e += (1.0 / 6.0) * (expect[xx][yy] + 1); n       } n       e += (6 - dist[x][y]) / 6.0; n       e /= (dist[x][y] / 6.0); n       expect[x][y] = e; n     } else { n       for (int dice = 1; dice <= min(6, dist[x][y]); ++dice) { n         int xx = dist2pos[dist[x][y] - dice].first; n         int yy = dist2pos[dist[x][y] - dice].second; n         double next_e; n         if (h[xx][yy] == 0) { n           next_e = expect[xx][yy]; n         } else { n           int xxx = xx - h[xx][yy]; n           int yyy = yy; n           next_e = min(expect[xx][yy], expect[xxx][yyy]); n         } n         e = e + (1.0 / 6.0) * next_e; n       } n       e += 1.0; n       expect[x][y] = e; n     } n     if (x == 9 && y == 0) break; n     auto p = dist2pos[dist[x][y] + 1]; n     x = p.first; n     y = p.second; n   } n   cout << fixed << setprecision(6) << expect[9][0] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     long long n, sum = 0; n     cin >> n; n     string arr; n     string brr; n     cin >> arr >> brr; n     for (int i = 0; i < n; i++) { n       if (brr[i] ==  0 ) { n         continue; n       } n       if (arr[i] ==  0 ) { n         sum++; n         arr[i] =  2 ; n         continue; n       } n       if (i == 0 && arr[1] ==  1 ) { n         sum++; n         arr[1] =  2 ; n         continue; n       } n       if (i == 0 && arr[1] !=  1 ) { n         continue; n       } n       if (arr[i - 1] ==  1 ) { n         sum++; n         arr[i - 1] =  2 ; n         continue; n       } n       if (i == n - 1) { n         break; n       } n       if (arr[i + 1] ==  1 ) { n         sum++; n         arr[i + 1] =  2 ; n       } n     } n     cout << sum << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int nums[200]; n int arr[200][200]; n int counter; n int line; n int main() { n   int n; n   cin >> n; n   line = 0; n   counter = 0; n   int sum = 0; n   int nums[200]; n   int arr[200][200]; n   memset(arr, 0, sizeof arr); n   memset(nums, 0, sizeof nums); n   while (sum + (++counter) <= n) { n     sum += counter; n   } n   cout << counter << endl; n   counter--; n   int i; n   int ct = counter; n   int j; n   arr[0][0] = 1; n   arr[1][0] = 1; n   for (i = 1; i <= counter; i++) { n     arr[i][i] = arr[i - 1][i - 1] + ct; n     ct = ct - 1; n     arr[i + 1][i] = arr[i][i]; n   } n   for (i = 0; i <= counter; i++) { n     for (int j = i + 1; j < counter; j++) { n       arr[i][j] = arr[i][j - 1] + 1; n       arr[j + 1][i] = arr[i][j]; n     } n   } n   for (i = 0; i <= counter; i++) { n     for (j = 0; j < counter; j++) { n       cout << arr[i][j] <<    ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<long long, long long> A[300005]; n long long B[300005]; n int main() { n   long long n; n   scanf( %lld , &n); n   for (long long i = 1; i <= n; ++i) { n     scanf( %lld , &A[i].first); n     A[i].second = i; n   } n   sort(A + 1, A + n + 1); n   long long val = 1; n   for (long long i = 1; i <= n; ++i) { n     val = max(val, A[i].first); n     B[A[i].second] = val; n     val++; n   } n   for (long long i = 1; i <= n; ++i) { n     printf( %lld  , B[i]); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int T, n; n   cin >> T; n   while (T--) { n     cin >> n; n     long long ans = 0; n     for (int i = 1; i <= n / 2; i++) { n       ans += i * 1ll * i; n     } n     cout << ans * 8 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:10000000000 ) n #pragma GCC optimize( O3 ) n using namespace std; n const int MOD = 1000000007; n const int INF = 1000000007LL; n const long long INF2 = 1000000007LL * 1000000007LL; n const long double EPS = 1e-9; n const int SIZE = 3010; n mt19937 rng(time(0)); n uniform_int_distribution<int> uid(-1000000000, 1000000000); n struct fenwick { n   int n; n   vector<int> a; n   fenwick() {} n   fenwick(int n_) { n     n = n_; n     a.resize(n, 0); n   } n   int query(int r) { n     if (r < 0) return 0; n     int sum = 0; n     for (int i = r; i >= 0; i = (i & (i + 1)) - 1) sum += a[i]; n     return sum; n   } n   int query(int l, int r) { return query(r) - query(l - 1); } n   void increase(int ind, int val = 1) { n     for (int i = ind; i < n; i = i | (i + 1)) a[i] += val; n   } n }; n int a[SIZE][SIZE], n, m; n int zl[SIZE][SIZE], zr[SIZE][SIZE], zld[SIZE][SIZE]; n int get_num_diag(int i, int j) { n   int num = i + j; n   return num; n } n vector<vector<pair<int, int> > > endColumn; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   string s; n   cin >> n >> m; n   endColumn.resize(n + m + 10); n   for (int i = 1; i <= n; ++i) { n     cin >> s; n     for (int j = 1; j <= m; ++j) { n       a[i][j] = s[j - 1] ==  z ; n       if (a[i][j]) zl[i][j] = a[i][j] + zl[i][j - 1]; n     } n   } n   for (int i = n; i >= 1; --i) { n     for (int j = m; j >= 1; --j) { n       if (a[i][j]) { n         zr[i][j] = a[i][j] + zr[i][j + 1]; n         zld[i][j] = a[i][j] + zld[i + 1][j - 1]; n         endColumn[j + zr[i][j] - 1].push_back({i, j}); n       } n     } n   } n   vector<fenwick> f(n + m + 10, fenwick(n + 10)); n   long long ans = 0; n   for (int j = m; j >= 1; --j) { n     for (auto& j : endColumn[j]) { n       int i2 = j.first, j2 = j.second; n       f[i2 + j2].increase(i2); n     } n     for (int i = 1; i <= n; ++i) { n       if (!a[i][j]) continue; n       int len = min(zl[i][j], zld[i][j]) - 1; n       long long rs = f[i + j].query(i, i + len); n       ans += rs; n     } n   } n   cout << ans; n   return 0; n } n