#include <cstdio> n #include <iostream> n #include <cstring> n #include <queue> n using namespace std; n const int M = 2005; n const int inf = 0x3f3f3f3f; n #define int long long n int read() n { n  int x=0,f=1;char c; n  while((c=getchar())< 0  || c> 9 ) {if(c== - ) f=-1;} n  while(c>= 0  && c<= 9 ) {x=(x<<3)+(x<<1)+(c^48);c=getchar();} n  return x*f; n } n int n,m,k,t,mx,a[M],b[M],d[M],del[M]; n int tot,S,T,f[M],dis[M],dp[55][55],pre[55][55]; n struct edge n { n  int v,c,next; n }e[2*M]; n void add(int u,int v,int c) n { n  e[++tot]=edge{v,c,f[u]},f[u]=tot; n  e[++tot]=edge{u,0,f[v]},f[v]=tot; n } n int bfs() n { n  for(int i=S;i<=T;i++) dis[i]=0; n  queue<int> q; n  q.push(S);dis[S]=1; n  while(!q.empty()) n  { n   int u=q.front();q.pop(); n   if(u==T) return 1; n   for(int i=f[u];i;i=e[i].next) n   { n    int v=e[i].v; n    if(e[i].c>0 && !dis[v]) n    { n     dis[v]=dis[u]+1; n     q.push(v); n    } n   } n  } n  return 0; n } n int dfs(int u,int ept) n { n  if(u==T) return ept; n  int flow=0,tmp=0; n  for(int i=f[u];i;i=e[i].next) n  { n   int v=e[i].v; n   if(e[i].c>0 && dis[v]==dis[u]+1) n   { n    tmp=dfs(v,min(e[i].c,ept)); n    if(!tmp) continue; n    ept-=tmp; n    e[i].c-=tmp; n    e[i^1].c+=tmp; n    flow+=tmp; n    if(!ept) break; n   } n  } n  return flow; n } n int get() n { n  S=0;T=2*n+1;tot=1; n  for(int i=S;i<=T;i++) f[i]=0; n  for(int i=1;i<=m;i++) n  { n   int u=a[i],v=b[i]; n   add(u+n,v,1);//x is in / x+n is out; n  } n  for(int i=1;i<=n;i++) n     { n         if(!del[i+n]) add(S,i+n,1); n         if(!del[i]) add(i,T,1); n     } n  int res=0; n  while(bfs()) res+=dfs(S,inf); n  return res; n } n void print(int x,int y) n { n  if(!x) return ; n  print(x-1,pre[x][y]); n  for(int i=pre[x][y]+1;i<=y;i++) n  { n   if(d[i]>n) printf( %lld  ,d[i]-n); n   else printf( %lld  ,-d[i]); n  } n  printf( 0  ); n } n signed main() n { n  n=read();m=read();k=read(); n  for(int i=1;i<=m;i++) n   a[i]=read(),b[i]=read(); n  mx=get(); n  for(int i=1;i<=mx;i++) n   for(int j=1;j<=2*n;j++) n    if(!del[j]) n    { n     del[j]=1; n     if(get()==mx-i)//we can delete j to reduce the maxmatch n     { n      d[++t]=j; n      break; n     } n     del[j]=0; n    } n  memset(dp,-0x3f,sizeof dp); n  dp[0][0]=0; n  for(int i=1;i<=k;i++) n  { n   int x=read(),y=read(); n   for(int j=0;j<=t;j++) n   { n    if(i-j>=n-mx) continue;//illegal n    for(int k=0;k<=j;k++)//we choose k now n     if(dp[i][j]<dp[i-1][j-k]+max(0ll,x-k*y)) n     { n      dp[i][j]=dp[i-1][j-k]+max(0ll,x-k*y); n      pre[i][j]=j-k; n     } n   } n  } n  int p=0; n  for(int i=0;i<=t;i++) n   if(dp[k][i]>dp[k][p]) n    p=i; n  printf( %lld n ,k+p); n  print(k,p); n } n


#include <bits/stdc++.h> n using namespace std; n long long int n, m, modu = 1e9 + 7, prod = 1, sum = 0; n long long int power(long long int x, long long int y) { n   if (y == 0) return 1; n   if (y & 1) return (x * power((x * x) % modu, y >> 1)) % modu; n   return power((x * x) % modu, y >> 1); n } n long long int combine(long long int n, long long int r) { n   long long int p1 = 1, p2 = 1; n   for (int i = 1; i <= n; i++) p1 = (p1 * i) % modu; n   for (int i = 1; i <= r; i++) p2 = (p2 * i) % modu; n   for (int i = 1; i <= (n - r); i++) p2 = (p2 * i) % modu; n   return (p1 * (power(p2, modu - 2))) % modu; n } n int main() { n   cin >> n >> m; n   int prev = 0; n   vector<int> aa; n   for (int i = 0; i < m; i++) { n     long long int x; n     cin >> x; n     aa.push_back(x); n   } n   sort(aa.begin(), aa.end()); n   for (int i = 0; i < m; i++) { n     long long int a = aa[i]; n     long long int c = a; n     a = a - prev - 1; n     if (a > 0) { n       sum += a; n       if (i > 0 && i <= m - 1) prod = (prod * power(2, a - 1)) % modu; n       prod = (prod * combine(sum, a)) % modu; n     } n     prev = c; n   } n   if (n - prev > 0) { n     sum += (n - prev); n     prod = (prod * (combine(sum, n - prev))) % modu; n   } n   cout << prod << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int mxN = 1000000; n int a[mxN]; n void solve() { n   int n, k; n   cin >> n >> k; n   int idx = ceil((double)n / 2); n   int sub = (n - idx) + 1; n   for (int i = 0; i < n * k; i++) { n     cin >> a[i]; n   } n   long long ans = 0, cnt = 0; n   for (int i = n * k - sub; cnt < k; i -= sub) { n     ans += a[i]; n     cnt++; n   } n   cout << ans <<   n ; n } n int main(void) { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline 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 << 3) + (x << 1) + (c ^ 48); n     c = getchar(); n   } n   return f == 1 ? x : -x; n } n inline void print(int x) { n   if (x < 0) putchar( - ), x = ~x + 1; n   if (x >= 10) print(x / 10); n   putchar((x % 10) | 48); n } n int n; n int c, d; n long long ans; n int t[100010]; n char tp[100010]; n int main() { n   n = read(); n   c = read(), d = read(); n   for (int i = 1; i <= n; ++i) { n     t[i] = read(); n     char c = getchar(); n     while (c !=  P  && c !=  W ) c = getchar(); n     tp[i] = c; n   } n   t[n + 1] = read(); n   tp[n + 1] =  A ; n   ans = 1ll * d * n; n   long long sum = 0; n   int last = t[n + 1]; n   for (int i = n; i >= 1; --i) { n     ans = min(ans, 1ll * c * (t[n + 1] - t[i]) + sum + 1ll * d * (i - 1)); n     if (tp[i - 1] == tp[i]) { n       sum += min(d, c * (last - t[i])); n     } else { n       last = t[i]; n     } n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /stack:200000000 ) n #pragma GCC optimize( Ofast,no-stack-protector ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n template <typename T> n void read(T &a) { n   T x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = (x << 1) + (x << 3) + (ch ^ 48); n     ch = getchar(); n   } n   a = x * f; n } n template <typename T> n void print(T x) { n   if (!x) return; n   if (x < 0) putchar( - ), x = -x; n   print(x / 10); n   putchar(x % 10 +  0 ); n } n template <typename T, typename... Args> n void read(T &t, Args &...args) { n   read(t); n   read(args...); n } n long long n, a[200005 << 1], res = 0, las[200005 << 1]; n map<long long, long long> mp; n signed main() { n   read(n); n   for (long long i = 1; i <= n; i++) read(a[i]), mp[a[i]]++; n   long long maxid, maxx = -1; n   for (map<long long, long long>::iterator it = mp.begin(); it != mp.end(); n        it++) { n     if (maxx < it->second) { n       maxx = it->second; n       maxid = it->first; n     } n   } n   for (map<long long, long long>::iterator it = mp.begin(); it != mp.end(); n        it++) { n     if (it->first == maxid) continue; n     long long sum = n; n     memset(las, -1, sizeof(las)); n     las[n] = 0; n     for (long long i = 1; i <= n; i++) { n       if (a[i] == it->first) sum--; n       if (a[i] == maxid) sum++; n       if (las[sum] != -1) n         res = max(res, i - las[sum]); n       else n         las[sum] = i; n     } n   } n   printf( %lld n , res); n   return 0; n } n


/** n  *  created: 25/03/2021, 15:47:17 n  *  pause: 16:11 - 16:18 n **/ n  n #include <bits/stdc++.h> n  n using namespace std; n  n const int max_n = 200222, inf = 1000111222; n const int max_x = 2 * max_n; n  n vector<long long> all; n  n struct node { n     int cnt; n     long long sum, sum_l, sum_r; n  n     friend ostream& operator << (ostream &os, const node &nd) { n         os <<  (cnt =   << nd.cnt <<  , s =   << nd.sum <<  , sl =   << nd.sum_l <<  , sr =   << nd.sum_r <<  ) ; n         return os; n     } n }; n  n node combine(const node &a, const node &b) { n     return {a.cnt + b.cnt, n             a.sum + b.sum, n             a.sum_l + b.sum_l + a.sum * b.cnt, n             a.sum_r + b.sum_r + b.sum * a.cnt}; n } n  n struct segment_tree { n     node a[4 * max_x]; n  n     void build(int v, int l, int r, int cnt[]) { n         if (l == r) { n             a[v] = {cnt[l], cnt[l] * all[l], cnt[l] * all[l], cnt[l] * all[l]}; n             //cout << v <<  : [  << l <<     << r <<  ], nd =   << a[v] << endl; n             return; n         } n         int mid = (l + r) / 2; n         build(2 * v, l, mid, cnt); n         build(2 * v + 1, mid + 1, r, cnt); n         a[v] = combine(a[2 * v], a[2 * v + 1]); n         //cout << v <<  : [  << l <<     << r <<  ], nd =   << a[v] << endl; n     } n  n     void update(int v, int l, int r, int x, int value) { n         if (l == r) { n             a[v] = {value, value * all[l], value * all[l], value * all[l]}; n             return; n         } n         int mid = (l + r) / 2; n         if (x <= mid) { n             update(2 * v, l, mid, x, value); n         } else { n             update(2 * v + 1, mid + 1, r, x, value); n         } n         a[v] = combine(a[2 * v], a[2 * v + 1]); n     } n  n     node get_sum(int v, int tl, int tr, int l, int r) { n         if (tl == l && tr == r) { n             return a[v]; n         } n         int mid = (tl + tr) / 2; n         if (r <= mid) { n             return get_sum(2 * v, tl, mid, l, r); n         } else if (l > mid) { n             return get_sum(2 * v + 1, mid + 1, tr, l, r); n         } n         return combine(get_sum(2 * v, tl, mid, l, mid), get_sum(2 * v + 1, mid + 1, tr, mid + 1, r)); n     } n  n     long long get_sum_left(int v, int tl, int tr, int k) { n         if (tl == tr) { n             if (k == 1) { n                 return a[v].sum; n             } n             return 0; n         } n         int mid = (tl + tr) / 2; n         if (k <= a[2 * v].cnt) { n             return get_sum_left(2 * v, tl, mid, k); n         } n         return a[2 * v].sum + get_sum_left(2 * v + 1, mid + 1, tr, k - a[2 * v].cnt); n     } n  n     long long get_sum_right(int v, int tl, int tr, int k) { n         if (tl == tr) { n             if (k == 1) { n                 return a[v].sum; n             } n             return 0; n         } n         int mid = (tl + tr) / 2; n         if (k <= a[2 * v + 1].cnt) { n             return get_sum_right(2 * v + 1, mid + 1, tr, k); n         } n         return a[2 * v + 1].sum + get_sum_right(2 * v, tl, mid, k - a[2 * v + 1].cnt); n     } n  n     node get_node_left(int v, int tl, int tr, int k) { n         if (tl == tr) { n             return a[v]; n         } n         int mid = (tl + tr) / 2; n         if (k <= a[2 * v].cnt) { n             return get_node_left(2 * v, tl, mid, k); n         } n         return combine(a[2 * v], get_node_left(2 * v + 1, mid + 1, tr, k - a[2 * v].cnt)); n     } n  n     node get_node_right(int v, int tl, int tr, int k) { n         if (tl == tr) { n             return a[v]; n         } n         int mid = (tl + tr) / 2; n         if (k <= a[2 * v + 1].cnt) { n             return get_node_right(2 * v + 1, mid + 1, tr, k); n         } n         return combine(get_node_right(2 * v, tl, mid, k - a[2 * v + 1].cnt), a[2 * v + 1]); n     } n }; n  n int n, q, tp[max_n], cnt[max_x]; n long long a[max_n], b[max_n]; n segment_tree st; n  n int compress(long long x) { n     return lower_bound(all.begin(), all.end(), x) - all.begin(); n } n  n long long solve() { n     //cout <<  #  << st.a[1] << endl; n     long long res = st.a[1].sum_r - st.a[1].sum_l; n     const int k = st.a[1].cnt; n     if (k >= 3) { n         int pos = (k + 1) / 2 - 2; n         long long sr = st.get_sum_right(1, 0, all.size() - 1, pos + 1); n         long long sl = st.get_sum_left(1, 0, all.size() - 1, pos + 2); n         if (sr > sl) { n             int l = pos, r = k - 1; n             while (r - l > 1) { n                 int mid = (l + r) / 2; n                 long long sr = st.get_sum_right(1, 0, all.size() - 1, mid + 1); n                 long long sl = st.get_sum_left(1, 0, all.size() - 1, mid + 2); n                 if (sr > sl) { n                     l = mid; n                 } else { n                     r = mid; n                 } n             } n             int to = l; n             l = -1; n             r = pos; n             while (r - l > 1) { n                 int mid = (l + r) / 2; n                 long long sr = st.get_sum_right(1, 0, all.size() - 1, mid + 1); n                 long long sl = st.get_sum_left(1, 0, all.size() - 1, mid + 2); n                 if (sr > sl) { n                     r = mid; n                 } else { n                     l = mid; n                 } n             } n             int from = r; n             res -= st.get_node_right(1, 0, all.size() - 1, to + 1).sum_r; n             if (from) { n                 res += st.get_node_right(1, 0, all.size() - 1, from).sum_r; n             } n             res += st.get_node_left(1, 0, all.size() - 1, to + 2).sum_l; n             res -= st.get_node_left(1, 0, all.size() - 1, from + 1).sum_l; n             /*for (int i = from; i <= to; ++i) { n                 //res -= st.get_sum_right(1, 0, all.size() - 1, i + 1) - st.get_sum_left(1, 0, all.size() - 1, i + 2); n                 res += st.get_sum_left(1, 0, all.size() - 1, i + 2); n             }*/ n         } n     } n     return res; n } n  n int main() { n     //freopen( input.txt ,  r , stdin); n     //freopen( output.txt ,  w , stdout); n     scanf( %d%d , &n, &q); n     for (int i = 0; i < n; ++i) { n         scanf( %lld , &a[i]); n     } n     for (int i = 0; i < q; ++i) { n         scanf( %d%lld , &tp[i], &b[i]); n     } n     for (int i = 0; i < n; ++i) { n         all.push_back(a[i]); n     } n     for (int i = 0; i < q; ++i) { n         all.push_back(b[i]); n     } n     sort(all.begin(), all.end()); n     all.erase(unique(all.begin(), all.end()), all.end()); n     for (int i = 0; i < n; ++i) { n         cnt[compress(a[i])] = 1; n     } n     st.build(1, 0, all.size() - 1, cnt); n     printf( %lld n , solve()); n     for (int i = 0; i < q; ++i) { n         if (tp[i] == 1) { n             st.update(1, 0, all.size() - 1, compress(b[i]), 1); n         } else { n             st.update(1, 0, all.size() - 1, compress(b[i]), 0); n         } n         printf( %lld n , solve()); n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 10; n int a[MAXN], b[MAXN], pos[MAXN]; n map<int, int> zoom; n bool vis[MAXN]; n int main() { n   ios::sync_with_stdio(false); n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     b[i] = a[i]; n   } n   sort(b + 1, b + 1 + n); n   for (int i = 1; i <= n; i++) { n     zoom[b[i]] = i; n     b[i] = i; n   } n   for (int i = 1; i <= n; i++) { n     a[i] = zoom[a[i]]; n     pos[a[i]] = i; n   } n   vector<vector<int>> res; n   for (int i = 1; i <= n; i++) { n     if (!vis[pos[i]]) { n       vector<int> cur; n       for (int j = pos[i]; !vis[j]; j = pos[j]) { n         cur.push_back(j); n         vis[j] = true; n       } n       res.push_back(cur); n     } n   } n   cout << res.size() <<   n ; n   for (auto v : res) { n     cout << v.size() <<    ; n     for (auto x : v) { n       cout << x <<    ; n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q; n   cin >> q; n   double n; n   long int sum = 0; n   for (int i = 0; i < q; i++) { n     cin >> n; n     long long int a; n     for (int j = 0; j < n; j++) { n       cin >> a; n       sum += a; n     } n     cout << fixed << setprecision(0) << ceill((sum / n)) << endl; n     sum = 0; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e5 + 5, MOD = 1e9 + 7; n long long k, p, q; n string ans; n set<long long> s; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> k; n   if (k < 25) { n     cout << -1 << endl; n     return 0; n   } n   char str[5] = { a ,  e ,  i ,  o ,  u }; n   for (long long i = 1; i * i <= k; i++) { n     if (k % i == 0) { n       if (i >= 5 && k / i >= 5) { n         p = i; n         q = k / i; n         break; n       } n     } n   } n   if (p == 0 && q == 0) { n     cout << -1 << endl; n     return 0; n   } n   for (long long i = 0; i < p; i++) { n     for (long long j = 0; j < q; j++) cout << str[(i + j) % 5]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   long long a[100]; n   long long b[100]; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= m; i++) cin >> b[i]; n   long long ans = 1000000000000000000LL; n   for (int i = 1; i <= n; i++) { n     long long mn = -1000000000000000000LL; n     for (int j = 1; j <= m; j++) n       for (int k = 1; k <= n; k++) { n         if (k == i) continue; n         mn = max(mn, a[k] * b[j]); n       } n     ans = min(ans, mn); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n using ull = unsigned long long; n using ll = long long; n using ld = long double; n const int mod = 1e9 + 7; n const int inf = INT_MAX; n vector<string> l = { x^y^z ,  x^z^y ,  (x^y)^z ,  (x^z)^y , n                      y^x^z ,  y^z^x ,  (y^x)^z ,  (y^z)^x , n                      z^x^y ,  z^y^x ,  (z^x)^y ,  (z^y)^x }; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   ld x, y, z; n   cin >> x >> y >> z; n   if (x < 1 and y < 1 and z < 1) { n     ld ans = pow(x, pow(y, z)); n     int cur = 0; n     if (pow(x, pow(z, y)) > ans) { n       ans = pow(x, pow(z, y)); n       cur = 1; n     } n     if (pow(x, y * z) > ans) { n       ans = pow(x, y * z); n       cur = 2; n     } n     if (pow(y, pow(x, z)) > ans) { n       ans = pow(y, pow(x, z)); n       cur = 4; n     } n     if (pow(y, pow(z, x)) > ans) { n       ans = pow(y, pow(z, x)); n       cur = 5; n     } n     if (pow(y, x * z) > ans) { n       ans = pow(y, x * z); n       cur = 6; n     } n     if (pow(z, pow(x, y)) > ans) { n       ans = pow(z, pow(x, y)); n       cur = 8; n     } n     if (pow(z, pow(y, x)) > ans) { n       ans = pow(z, pow(y, x)); n       cur = 9; n     } n     if (pow(z, x * y) > ans) { n       ans = pow(z, x * y); n       cur = 10; n     } n     cout << l[cur] <<   n ; n     return 0; n   } n   ld ans = 0; n   int cur = 0; n   if (x < 1) n     ans = -1e18; n   else if (x == 1) n     ans = -1000; n   else n     ans = z * log(y) + log(log(x)); n   if (x > 1 and y * log(z) + log(log(x)) > ans) { n     ans = y * log(z) + log(log(x)); n     cur = 1; n   } n   if (x > 1 and log(y) + log(z) + log(log(x)) > ans) { n     ans = log(y) + log(z) + log(log(x)); n     cur = 2; n   } n   if (y == 1 and ans < -1000) { n     ans = -1000; n     cur = 4; n   } n   if (y > 1 and z * log(x) + log(log(y)) > ans) { n     ans = z * log(x) + log(log(y)); n     cur = 4; n   } n   if (y > 1 and x * log(z) + log(log(y)) > ans) { n     ans = x * log(z) + log(log(y)); n     cur = 5; n   } n   if (y > 1 and log(x) + log(z) + log(log(y)) > ans) { n     ans = log(x) + log(z) + log(log(y)); n     cur = 6; n   } n   if (z == 1 and ans < -1000) { n     ans = -1000; n     cur = 8; n   } n   if (z > 1 and y * log(x) + log(log(z)) > ans) { n     ans = y * log(x) + log(log(z)); n     cur = 8; n   } n   if (z > 1 and x * log(y) + log(log(z)) > ans) { n     ans = x * log(y) + log(log(z)); n     cur = 9; n   } n   if (z > 1 and log(x) + log(y) + log(log(z)) > ans) { n     ans = log(x) + log(y) + log(log(z)); n     cur = 10; n   } n   cout << l[cur]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t, n; n   string s; n   cin >> t; n   while (t--) { n     cin >> n >> s; n     long long ans = 0, o = 0, ans1 = 0; n     for (long long i = 0; i < n; i++) { n       if ((s[i] - 48) % 2 == 1) { n         ans = (ans * 10) + (s[i] - 48); n         ans1 += ans; n         if (ans1 % 2 == 0) { n           o = 1; n           break; n         } n       } n     } n     if (o == 0) n       cout << -1 <<   n ; n     else n       cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, j, pos, num[100005]; n   cin >> n; n   for (i = 1; i <= n; i++) scanf( %d , &num[i]); n   pos = upper_bound(num + 1, num + 1 + n, 5e5) - num; n   if (pos > n) n     cout << num[n] - 1 << endl; n   else if (pos <= 1) n     cout << 1e6 - num[1] << endl; n   else { n     cout << max((int)1e6 - num[pos], num[pos - 1] - 1) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int suspect[100000]; n int justify[100000]; n bool killer[100000]; n pair<int, int> a[100000]; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   int cnt = 0; n   for (int i = 0; i < n; i++) { n     killer[i] = false; n     char x; n     int k; n     scanf( %d , &k); n     if (k < 0) { n       x =  - ; n       k *= -1; n     } else n       x =  + ; n     k--; n     if (x ==  + ) { n       suspect[k]++; n       a[i].second = 1; n     } else { n       a[i].second = 0; n       justify[k]++; n       cnt++; n     } n     a[i].first = k; n   } n   int cntkiller = 0; n   for (int i = 0; i < n; i++) n     if (suspect[i] + cnt - justify[i] == m) { n       killer[i] = true; n       cntkiller++; n     } n   for (int i = 0; i < n; i++) { n     if (a[i].second == 1 && killer[a[i].first] && cntkiller == 1) n       printf( Truth n ); n     else if (a[i].second == 0 && killer[a[i].first] && cntkiller == 1) n       printf( Lie n ); n     else if (a[i].second == 1 && killer[a[i].first]) n       printf( Not defined n ); n     else if (a[i].second == 1 && !killer[a[i].first]) n       printf( Lie n ); n     else if (a[i].second == 0 && !killer[a[i].first]) n       printf( Truth n ); n     else n       printf( Not defined n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, i, j, k, l, a, b, c, d, m, s, f; n   cin >> n >> m; n   c = 0; n   for (i = 1; i <= n; i++) { n     c++; n     if (i % m == 0) { n       n++; n     } n   } n   cout << c << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int Dx[] = {1, -1, 0, 0}; n int Dy[] = {0, 0, 1, -1}; n double x, y, n, mn = 10000000.0, a, b, i; n bool ok(int m) { n   if (x * i > m * y) return 1; n   return 0; n } n int main() { n   cin >> x >> y >> n; n   for (i = 1; i <= n; i++) { n     int s = 0, e = 1e9; n     while (s < e) { n       int m = (e + s + 1) / 2; n       if (ok(m)) n         s = m; n       else n         e = m - 1; n     } n     double z = abs(x / y - s / i), zz = abs((s + 1) / i - x / y); n     if (z < mn) n       mn = z, a = s, b = i; n     else if (z == mn && s < a) n       a = s; n     if (zz < mn) n       mn = zz, a = s + 1, b = i; n     else if (zz == mn && s + 1 < a) n       a = s + 1; n   } n   cout << a <<  /  << b << endl; n   ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100100; n vector<int> v; n struct mmp { n   int to, next, len; n   mmp() {} n   mmp(int a, int b, int c) { to = a, next = b, len = c; } n } e[maxn << 1]; n int vis[maxn], st, ed, cnt, head[maxn], val[maxn], len; n void add(int u, int v, int len) { n   e[++cnt] = mmp(v, head[u], len); n   head[u] = cnt; n } n void add(int x) { n   for (int i = 0; i < (int)v.size(); i++) { n     x = min(x, x ^ v[i]); n   } n   if (x) v.push_back(x); n } n void dfs(int x, int now) { n   vis[x] = 1; n   for (int i = head[x]; i; i = e[i].next) { n     int to = e[i].to; n     if (vis[to]) n       add(val[to] ^ now ^ e[i].len); n     else { n       val[to] = now ^ e[i].len; n       dfs(to, val[to]); n     } n   } n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; i++) { n     scanf( %d%d%d , &st, &ed, &len); n     add(st, ed, len); n     add(ed, st, len); n   } n   dfs(1, 0); n   for (int i = 0; (int)i < v.size(); i++) { n     val[n] = min(val[n], val[n] ^ v[i]); n   } n   return 0 * printf( %d , val[n]); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, b; n   cin >> n >> b; n   vector<int> arr(n); n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   vector<int> s; n   for (int i = 0; i < n - 1; i++) { n     if (arr[i] <= b) { n       int m = INT_MIN; n       for (int j = i + 1; j < n; j++) m = max(m, arr[j]); n       if (arr[i] < m) s.push_back(b + (m - arr[i]) * (b / arr[i])); n     } n   } n   if (!s.empty()) n     cout << *max_element(s.begin(), s.end()) << endl; n   else n     cout << b << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int NMAX = 1000 + 5; n int n, m, W; n int w[NMAX]; n int b[NMAX]; n vector<int> graph[NMAX]; n int comp[NMAX]; n void dfs(int node, int cmp) { n   comp[node] = cmp; n   for (auto it : graph[node]) n     if (!comp[it]) dfs(it, cmp); n } n vector<pair<int, int> > groups[NMAX]; n int dp[NMAX][NMAX]; n int main() { n   cin >> n >> m >> W; n   for (int i = 1; i <= n; ++i) cin >> w[i]; n   for (int i = 1; i <= n; ++i) cin >> b[i]; n   for (int i = 1; i <= m; ++i) { n     int a, b; n     cin >> a >> b; n     graph[a].push_back(b); n     graph[b].push_back(a); n   } n   int cmp = 0; n   for (int i = 1; i <= n; ++i) n     if (!comp[i]) dfs(i, ++cmp); n   for (int i = 1; i <= n; ++i) groups[comp[i]].push_back(make_pair(w[i], b[i])); n   for (int i = 1; i <= cmp; ++i) { n     int sumW = 0; n     int sumB = 0; n     for (auto it : groups[i]) { n       sumW += it.first; n       sumB += it.second; n     } n     groups[i].push_back(make_pair(sumW, sumB)); n   } n   for (int i = 1; i <= cmp; ++i) { n     for (int j = 1; j <= W; ++j) { n       dp[i][j] = dp[i - 1][j]; n       for (auto it : groups[i]) n         if (j - it.first >= 0) n           dp[i][j] = max(dp[i][j], dp[i - 1][j - it.first] + it.second); n     } n   } n   cout << dp[cmp][W] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct pkt { n   int x, y; n }; n int main() { n   ios_base::sync_with_stdio(0); n   int n, m; n   cin >> n >> m; n   vector<string> p(n); n   for (int i = 0; i < n; ++i) cin >> p[i]; n   vector<vector<int> > a(n, vector<int>(m, -1)); n   for (int k = 0; k < n; ++k) { n     for (int l = 1; l < m; ++l) { n       if (p[k][l - 1] !=  . ) n         a[k][l] = l - 1; n       else n         a[k][l] = a[k][l - 1]; n     } n   } n   vector<vector<int> > b(n, vector<int>(m, -1)); n   for (int k = 0; k < n; ++k) { n     for (int l = m - 2; l >= 0; --l) { n       if (p[k][l + 1] !=  . ) n         b[k][l] = l + 1; n       else n         b[k][l] = b[k][l + 1]; n     } n   } n   vector<vector<int> > c(n, vector<int>(m, -1)); n   for (int l = 0; l < m; ++l) { n     for (int k = 1; k < n; ++k) { n       if (p[k - 1][l] !=  . ) n         c[k][l] = k - 1; n       else n         c[k][l] = c[k - 1][l]; n     } n   } n   vector<vector<int> > d(n, vector<int>(m, -1)); n   for (int l = 0; l < m; ++l) { n     for (int k = n - 2; k >= 0; --k) { n       if (p[k + 1][l] !=  . ) n         d[k][l] = k + 1; n       else n         d[k][l] = d[k + 1][l]; n     } n   } n   vector<vector<int> > L, P, G, D; n   L = a; n   P = b; n   G = c; n   D = d; n   int odp = 0, il = 0; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       if (p[i][j] ==  . ) continue; n       int dl = 1; n       pkt akt = {i, j}; n       vector<pkt> z; n       while (true) { n         pkt nast; n         if (p[akt.x][akt.y] ==  L ) n           nast = {akt.x, L[akt.x][akt.y]}; n         else { n           if (p[akt.x][akt.y] ==  R ) n             nast = {akt.x, P[akt.x][akt.y]}; n           else { n             if (p[akt.x][akt.y] ==  U ) n               nast = {G[akt.x][akt.y], akt.y}; n             else { n               if (p[akt.x][akt.y] ==  D ) nast = {D[akt.x][akt.y], akt.y}; n             } n           } n         } n         if (nast.x == -1 || nast.y == -1) break; n         ++dl; n         pkt le = {akt.x, L[akt.x][akt.y]}; n         pkt pr = {akt.x, P[akt.x][akt.y]}; n         if (le.x != -1 && le.y != -1) P[le.x][le.y] = pr.y; n         if (pr.x != -1 && pr.y != -1) L[pr.x][pr.y] = le.y; n         pkt go = {G[akt.x][akt.y], akt.y}; n         pkt dol = {D[akt.x][akt.y], akt.y}; n         if (dol.x != -1 && dol.y != -1) G[dol.x][dol.y] = go.x; n         if (go.x != -1 && go.y != -1) D[go.x][go.y] = dol.x; n         akt = nast; n         z.push_back(le); n         z.push_back(pr); n         z.push_back(go); n         z.push_back(dol); n       } n       if (dl > odp) { n         odp = dl; n         il = 1; n       } else { n         if (dl == odp) ++il; n       } n       for (int k = 0; k < z.size(); ++k) { n         if (z[k].x == -1 || z[k].y == -1) continue; n         L[z[k].x][z[k].y] = a[z[k].x][z[k].y]; n         P[z[k].x][z[k].y] = b[z[k].x][z[k].y]; n         G[z[k].x][z[k].y] = c[z[k].x][z[k].y]; n         D[z[k].x][z[k].y] = d[z[k].x][z[k].y]; n       } n     } n   } n   cout << odp <<     << il; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct pt { n   double x, y; n }; n pt a[1005]; n long long n; n double kv(double g) { return g * g; } n double dist(pt a, pt b) { return sqrt(kv(a.x - b.x) + kv(a.y - b.y)); } n double visina(pt a, pt b, pt c) { n   return abs((b.y - a.y) * c.x - (b.x - a.x) * c.y + b.x * a.y - b.y * a.x) / n          (dist(a, b)); n } n int main() { n   cout.precision(15); n   cout << fixed; n   cin >> n; n   for (long i = 0; i < n; i++) { n     cin >> a[i].x >> a[i].y; n   } n   double d = 1e17; n   for (long i = 0; i < n; i++) { n     pt x = a[i], y = a[(i + 1) % n], z = a[(i + 2) % n]; n     d = min(d, visina(x, y, z)); n     d = min(d, visina(y, z, x)); n     d = min(d, visina(z, x, y)); n   } n   cout << d / 2 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e6; n int pref[MAXN + 1]; n string S; n int n, k; n void fast_io() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n } n pair<int, int> query(int s) { n   int lo = s, hi = n; n   int res = -1; n   while (lo <= hi) { n     int mid = (lo + hi) >> 1; n     if (pref[mid] - pref[s - 1] >= k) n       res = mid, hi = mid - 1; n     else n       lo = mid + 1; n   } n   if (res == -1 or (pref[res] - pref[s - 1]) != k) return make_pair(-1, -1); n   pair<int, int> p = make_pair(res, -1); n   lo = res, hi = n; n   res = -1; n   while (lo <= hi) { n     int mid = (lo + hi) >> 1; n     if (pref[mid] - pref[s - 1] <= k) n       res = mid, lo = mid + 1; n     else n       hi = mid - 1; n   } n   p.second = res; n   return p; n } n int main() { n   fast_io(); n   cin >> k >> S; n   n = S.length(); n   S =  $  + S; n   for (int i = 1; i <= n; i++) { n     pref[i] = (S[i] -  0 ) + pref[i - 1]; n   } n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     pair<int, int> p = query(i); n     if (p.first == -1) continue; n     ans += (p.second - p.first + 1); n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void display(T a[], int size) { n   for (int i = 0; i < size; i++) { n     cout << a[i] <<    ; n   } n   cout << endl; n } n void display(vector<pair<int, int> > a) { n   for (int i = 0; i < a.size(); i++) { n     cout <<  (  << a[i].first <<  ,  << a[i].second <<  )  n          <<    ; n   } n   cout << endl; n } n void display(vector<int> a) { n   for (int i = 0; i < a.size(); i++) { n     cout << a[i]; n     if (i == a.size() - 1) n       cout << endl; n     else n       cout <<    ; n   } n } n template <typename T> n void initialise(T a[], T value, int length) { n   for (int i = 0; i < length; i++) a[i] = value; n } n template <typename T> n void initialise(vector<T>& a, T value) { n   for (int i = 0; i < a.size(); i++) a[i] = value; n } n bool compare(pair<int, int> a, pair<int, int> b) { n   if (a.first != b.first) n     return a.first < b.first; n   else n     return a.second < b.second; n } n int max(int a[], int n) { n   int max = -1000000000; n   for (int i = 0; i < n; i++) { n     if (a[i] > max) max = a[i]; n   } n   return max; n } n bool find(string a[], string s, int n) { n   int left = 0; n   int right = n - 1; n   while (left < right) { n     int mid = (left + right) / 2; n     if (s.compare(a[mid]) == 0) n       return true; n     else if (s.compare(a[mid]) < 0) { n       right = mid; n     } else { n       left = mid + 1; n     } n   } n   return false; n } n void factor(int a[], int base, int num, int n) { n   for (int i = n - 1; i >= 0; i--) { n     a[i] = num % base; n     num = num / base; n   } n } n int findLength(int n, int base) { n   int i = 0; n   while (n > 0) { n     i++; n     n = n / base; n   } n   return i; n } n int gcd(int a, int b) { n   while (a % b != 0 && b % a != 0) { n     if (b > a) { n       b = b % a; n     } else if (a > b) { n       a = a % b; n     } n   } n   if (a <= b) n     return a; n   else n     return b; n } n int main() { n   int n, m; n   cin >> n >> m; n   list<int> son[n]; n   for (int i = 0; i < m; i++) { n     int u, v; n     cin >> u >> v; n     son[u - 1].push_back(v - 1); n     son[v - 1].push_back(u - 1); n   } n   int side[n]; n   initialise(side, -1, n); n   for (int i = 0; i < n; i++) { n     if (side[i] != -1) continue; n     queue<int> q; n     q.push(i); n     side[i] = 0; n     while (!q.empty()) { n       int current = q.front(); n       q.pop(); n       for (auto fil : son[current]) { n         if (side[fil] == -1) { n           side[fil] = 1 - side[current]; n           q.push(fil); n         } else if (side[fil] == side[current]) { n           cout << -1 << endl; n           return 0; n         } else n           continue; n       } n     } n   } n   vector<int> zero; n   vector<int> one; n   for (int i = 0; i < n; i++) { n     if (side[i] == 0) n       zero.push_back(i + 1); n     else n       one.push_back(i + 1); n   } n   cout << zero.size() << endl; n   for (int i = 0; i < zero.size(); i++) { n     cout << zero[i]; n     if (i == zero.size() - 1) n       cout << endl; n     else n       cout <<    ; n   } n   cout << one.size() << endl; n   for (int i = 0; i < one.size(); i++) { n     cout << one[i]; n     if (i == one.size() - 1) n       cout << endl; n     else n       cout <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n long long ans = 0x3f3f3f3f3f3f, a[510]; n void calc(long long val) { n   if (!val) return; n   long long res = 0; n   for (int i = 1; i <= n; i++) { n     long long p = a[i] / val, q = a[i] % val; n     if (p < q) return; n     res += p - (p - q) / (val + 1); n   } n   ans = min(ans, res); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); n   sort(a + 1, a + 1 + n); n   for (long long i = 1; i * i <= a[1]; i++) n     calc(i), calc(a[1] / i), calc(a[1] / i - 1); n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T sqr(const T &a) { n   return a * a; n } n int a, b, x, ans; n int main() { n   scanf( %d%d , &a, &b); n   while (1) { n     ans += a; n     x += a; n     if (x / b == 0) break; n     a = x / b; n     x -= (x / b) * b; n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int z = 0, f = 0, n, a; n   cin >> n; n   while (n--) { n     cin >> a; n     a == 0 ? z++ : f++; n   } n   if (z > 0 && f > 8) { n     f -= f % 9; n     while (f--) cout <<  5 ; n     while (z--) cout <<  0 ; n     cout << endl; n   } else if (z > 0) n     cout <<  0 n ; n   else n     cout <<  -1 n ; n } n


#include <bits/stdc++.h> n using namespace std; n int t, n; n string s; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> t; n   while (t--) { n     cin >> s; n     n = s.length(); n     int m = n, M = -1; n     for (int i = 0; i < n; i++) { n       if (s[i] ==  1 ) { n         m = min(m, i); n         M = max(M, i); n       } n     } n     if (m > M) { n       cout << 0 << endl; n     } else { n       int cnt = 0; n       for (int i = m; i < M; i++) { n         cnt += (s[i] ==  0 ); n       } n       cout << cnt << endl; n     } n   } n } n


#include <bits/stdc++.h> n using ll = long long; n using namespace std; n int n, m; n int const N = 3e5 + 2; n int const M = (1 << 21); n struct Triple { n   int fi; n   int se; n   int th; n   Triple(int f, int s, int t) : fi(f), se(s), th(t) {} n }; n struct Compare { n   bool operator()(const Triple& f, const Triple& g) { n     if (f.th != g.th) n       return (f.th < g.th); n     else n       return pair<int, int>{f.fi, f.se} < pair<int, int>{g.fi, g.se}; n   } n }; n vector<Triple> seg; n int t[M]; n int lazy[M]; n int const INF = 1e9; n void push(int v) { n   t[v * 2] += lazy[v]; n   lazy[v * 2] += lazy[v]; n   t[v * 2 + 1] += lazy[v]; n   lazy[v * 2 + 1] += lazy[v]; n   lazy[v] = 0; n } n int query(int v, int l, int r, int tl, int tr) { n   if (r < l) return INF; n   if (l == tl && r == tr) n     return t[v]; n   else { n     push(v); n     int mid = (tl + tr) / 2; n     int qw1 = query(v * 2, l, min(mid, r), tl, mid); n     int qw2 = query(v * 2 + 1, max(mid + 1, l), r, mid + 1, tr); n     return min(qw1, qw2); n   } n } n void update(int v, int l, int r, int tl, int tr, int val) { n   if (r < l) return; n   if (l == tl && r == tr) { n     t[v] += val; n     lazy[v] += val; n   } else { n     push(v); n     int mid = (tl + tr) >> 1; n     update(v << 1, l, min(mid, r), tl, mid, val); n     update((v << 1) + 1, max(mid + 1, l), r, mid + 1, tr, val); n     t[v] = min(t[v << 1], t[(v << 1) + 1]); n   } n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = (1); i <= (n); i++) { n     int l, r, w; n     scanf( %d %d %d , &l, &r, &w); n     seg.push_back(Triple({l, r, w})); n   } n   sort(seg.begin(), seg.end(), Compare()); n   int mu = 0; n   int lb = seg[0].th; n   int rb = seg[0].th; n   int ans = INF; n   for (int i = (1); i <= (n); i++) { n     update(1, seg[i - 1].fi, seg[i - 1].se - 1, 1, m - 1, 1); n     rb = seg[i - 1].th; n     while (query(1, 1, m - 1, 1, m - 1) > 0) { n       ans = min(ans, rb - lb); n       update(1, seg[mu].fi, seg[mu].se - 1, 1, m - 1, -1); n       mu++; n       if (mu != n) lb = seg[mu].th; n     } n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e5 + 11; n const long long mod = 1e9 + 7; n int n, m, k; n long long a[N], ans; n int par[N], sz[N]; n pair<long long, pair<int, int> > b[N]; n vector<pair<int, int> > v; n vector<int> cur; n bool u[N]; n int find_set(int v) { n   if (v == par[v]) return v; n   return par[v] = find_set(par[v]); n } n void union_sets(int a, int b) { n   a = find_set(a); n   b = find_set(b); n   if (a != b) { n     if (sz[a] < sz[b]) swap(a, b); n     par[b] = a; n     sz[a] += sz[b]; n   } n } n long long binpow(int n) { n   long long a = 2, res = 1; n   while (n) { n     if (n % 2 == 0) { n       n /= 2; n       a = (a * a) % mod; n     } else { n       n--; n       res = (res * a) % mod; n     } n   } n   return res; n } n int main() { n   cin >> n >> m >> k; n   for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]); n   for (int i = 1; i <= m; i++) { n     scanf( %d%d , &b[i].second.first, &b[i].second.second); n     b[i].first = a[b[i].second.first] ^ a[b[i].second.second]; n   } n   sort(b + 1, b + m + 1); n   int l = 0; n   int uniq = 0, comp; n   for (int i = 1; i <= m; i++) { n     if (b[i].first == b[i + 1].first) continue; n     comp = 0; n     for (int j = l + 1; j <= i; j++) v.push_back(b[j].second); n     for (auto i : v) { n       par[i.first] = i.first; n       par[i.second] = i.second; n       sz[i.first] = sz[i.second] = 1; n     } n     for (auto i : v) { n       if (!u[i.first]) cur.push_back(i.first); n       if (!u[i.second]) cur.push_back(i.second); n       u[i.first] = u[i.second] = true; n     } n     for (auto i : v) union_sets(i.first, i.second); n     for (auto i : cur) n       if (find_set(i) == i) comp++; n     ans = (ans + binpow(n - (int)cur.size() + comp)) % mod; n     for (auto i : cur) { n       u[i] = false; n     } n     cur.clear(); n     v.clear(); n     l = i; n     uniq++; n   } n   long long p = ((1ll << k) - uniq) % mod; n   p = (p * binpow(n)) % mod; n   ans = (ans + p) % mod; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 100100; n int N, M; n long long h[MAX_N], p[MAX_N]; n inline long long calc(long long start, long long from, long long to) { n   if (to <= start) return start - from; n   if (from >= start) return to - start; n   long long left = start - from, right = to - start; n   long long mn = min(left, right), mx = max(left, right); n   return 2 * mn + mx; n } n inline bool check(long long dist) { n   int firstTrack = 1, lastTrack; n   for (int i = 1; i <= N; i += 1) { n     if (abs(p[firstTrack] - h[i]) > dist) { n       continue; n     } n     lastTrack = firstTrack; n     while (lastTrack < M && n            calc(h[i], p[firstTrack], p[lastTrack + 1]) <= dist) { n       lastTrack += 1; n     } n     if (lastTrack == M) { n       return true; n     } n     firstTrack = lastTrack + 1; n   } n   return false; n } n int main() { n   cin >> N >> M; n   for (int i = 1; i <= N; i += 1) { n     cin >> h[i]; n   } n   for (int i = 1; i <= M; i += 1) { n     cin >> p[i]; n   } n   long long answer = -1; n   for (long long bit = (1LL << 40); bit > 0; bit /= 2) { n     if (!check(answer + bit)) { n       answer += bit; n     } n   } n   cout << answer + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n namespace in { n char buf[1 << 21], *p1 = buf, *p2 = buf; n inline int getc() { n   return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) n              ? EOF n              : *p1++; n } n template <typename T> n inline void read(T &t) { n   t = 0; n   int f = 0; n   char ch = getc(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = 1; n     ch = getc(); n   } n   while (isdigit(ch)) { n     t = t * 10 + ch - 48; n     ch = getc(); n   } n   if (f) t = -t; n } n template <typename T, typename... Args> n inline void read(T &t, Args &...args) { n   read(t); n   read(args...); n } n char getC() { n   char c = getc(); n   while (!isdigit(c) && !isalpha(c) && c !=  (  && c !=  )  && c !=  ? ) n     c = getc(); n   return c; n } n }  // namespace in n namespace out { n char buffer[1 << 21]; n int p1 = -1; n const int p2 = (1 << 21) - 1; n inline void flush() { fwrite(buffer, 1, p1 + 1, stdout), p1 = -1; } n inline void putc(const char &x) { n   if (p1 == p2) flush(); n   buffer[++p1] = x; n } n template <typename T> n void write(T x) { n   static char buf[15]; n   static int len = -1; n   if (x >= 0) { n     do { n       buf[++len] = x % 10 + 48, x /= 10; n     } while (x); n   } else { n     putc( - ); n     do { n       buf[++len] = -(x % 10) + 48, x /= 10; n     } while (x); n   } n   while (len >= 0) putc(buf[len]), --len; n } n void puts(char *str) { n   int now = 0; n   while (str[now] != 0) putc(str[now++]); n   putc(  n ); n } n }  // namespace out n namespace Game { n unsigned long long p1[64][3200], p2[64][3200]; n inline void make(unsigned long long arr[64][3200], int pos) { n   int th = std::min(63, pos); n   for (int i = 0; i <= th; i++) n     arr[i][(pos - i) >> 6] |= 1ull << ((pos - i) & 63); n } n void solve(int n, int m, int q, char *s1, char *s2, int *qx, int *qy, int *qlen, n            unsigned int *ans) { n   for (int i = 0; i < n; i++) n     if (s1[i] -  0 ) make(p1, i); n   for (int i = 0; i < m; i++) n     if (s2[i] -  0 ) make(p2, i); n   for (int i = 0; i < q; i++) { n     unsigned int res1 = 0, res2 = 0, res3 = 0, res4 = 0, res5 = 0, res6 = 0, n                  res7 = 0, res8 = 0; n     int x = qx[i], y = qy[i], l = qlen[i]; n     unsigned int block = l >> 6, c; n     unsigned long long *arr1 = p1[x & 63] + (x >> 6); n     unsigned long long *arr2 = p2[y & 63] + (y >> 6); n     for (c = 0; c + 8 < block; c += 8, arr1 += 8, arr2 += 8) { n       res1 += __builtin_popcountll(arr1[0] ^ arr2[0]); n       res2 += __builtin_popcountll(arr1[1] ^ arr2[1]); n       res3 += __builtin_popcountll(arr1[2] ^ arr2[2]); n       res4 += __builtin_popcountll(arr1[3] ^ arr2[3]); n       res5 += __builtin_popcountll(arr1[4] ^ arr2[4]); n       res6 += __builtin_popcountll(arr1[5] ^ arr2[5]); n       res7 += __builtin_popcountll(arr1[6] ^ arr2[6]); n       res8 += __builtin_popcountll(arr1[7] ^ arr2[7]); n     } n     int res = res1 + res2 + res3 + res4 + res5 + res6 + res7 + res8; n     for (; c < block; c++, arr1++, arr2++) n       res += __builtin_popcountll(arr1[0] ^ arr2[0]); n     ans[i] = res + __builtin_popcountll((arr1[0] ^ arr2[0]) & n                                         ((1ull << (l & 63)) - 1)); n     out::write(ans[i]); n     out::putc(  n ); n   } n } n void main() { n   char *s1 = new char[200000 + 1]; n   char *s2 = new char[200000 + 1]; n   int n, m; n   s1[n = 0] = in::getC(); n   while (isdigit(s1[n])) s1[++n] = in::getc(); n   s2[m = 0] = in::getC(); n   while (isdigit(s2[m])) s2[++m] = in::getc(); n   int q; n   in::read(q); n   unsigned int *anss = new unsigned int[q]; n   int *q_x = new int[q]; n   int *q_y = new int[q]; n   int *q_len = new int[q]; n   for (int i = 0; i < q; i++) in::read(q_x[i], q_y[i], q_len[i]); n   solve(n, m, q, s1, s2, q_x, q_y, q_len, anss); n } n }  // namespace Game n int main() { n   Game::main(); n   out::flush(); n   return 0; n } n


#include<bits/stdc++.h> n #define N 200100 n #define ll long long n using namespace std; n const ll inf=9223372036854775807; n ll n,m; n ll T; n ll a[N]; n ll maxx=-inf; n ll ans; n ll anss; n int main(){ n  cin>>T; n  while(T--){ n   ans=0; n   maxx=-inf; n   cin>>n; n   scanf( %lld ,&a[1]); n   for(int i=2;i<=n;i++){ n    scanf( %lld ,&a[i]); n    //maxx=max(maxx,abs(a[i]-a[i-1])); n    ans+=abs(a[i]-a[i-1]); n   } n   anss=ans; n   anss=min(anss,ans-abs(a[2]-a[1])); n   anss=min(anss,ans-abs(a[n]-a[n-1])); n   for(int i=2;i<=n-1;i++){ n    anss=min(anss,ans-abs(a[i+1]-a[i])-abs(a[i-1]-a[i])+abs(a[i-1]-a[i+1])); n    //anss=min(anss,ans-abs(a[i-1]-a[i])+abs(a[i-1]-a[i+1])); n   } n   cout<<anss<<endl; n  } n  return 0; 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 / gcd(a, b) * b; } n long long n, s1, v1, s2, v2; n long long i, j, k, ans, p, q, m, num; n inline long long cal_1() { return i * v1 + (n - i * s1) / s2 * v2; } n inline long long cal_2() { return i * v2 + (n - i * s2) / s1 * v1; } n inline long long maxn(long long a, long long b) { n   if (a > b) n     return a; n   else n     return b; n } n int main() { n   cin >> n >> v1 >> v2 >> s1 >> s2; n   m = lcm(s1, s2); n   num = n / m; n   if (num > 0) num--; n   if (v1 * s2 >= v2 * s1) { n     num = m / s1 * num; n     p = (n - num * s1) / s2; n     ans = num * v1 + p * v2; n     if (s1 >= s2) { n       for (i = num; i * s1 <= n; i++) ans = maxn(ans, cal_1()); n     } else { n       for (i = p; i >= 0; i--) ans = maxn(ans, cal_2()); n     } n   } else { n     num = m / s2 * num; n     p = (n - num * s2) / s1; n     ans = num * v2 + p * v1; n     if (s2 >= s1) { n       for (i = num; i * s2 <= n; i++) ans = maxn(ans, cal_2()); n     } else { n       for (i = p; i >= 0; i--) ans = maxn(ans, cal_1()); n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n pair<int, int> arr[100000 + 5]; n int main() { n   cin >> n; n   int L = 0, R = 0; n   for (int i = 1; i <= n; i++) { n     cin >> arr[i].first >> arr[i].second; n     L += arr[i].first; n     R += arr[i].second; n   } n   int ans = abs(L - R); n   int id = 0; n   for (int i = 1; i <= n; i++) { n     if (ans < abs(L - R + 2 * (arr[i].second - arr[i].first))) { n       ans = abs(L - R + 2 * (arr[i].second - arr[i].first)); n       id = i; n     } n   } n   cout << id << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, p; n long long w, d; n int main() { n   cin >> n >> p >> w >> d; n   long long x, y = -1, z = -1; n   for (long long i = p / w; i >= max(p / w - d, (long long)0); i--) { n     x = i; n     if (p - x * w >= 0 && (p - x * w) % d == 0) { n       y = (p - x * w) / d; n     } n     if (n - x - y >= 0) { n       z = n - x - y; n     } n     if (y != -1 && z != -1) break; n   } n   if (y != -1 && z != -1 && x + y + z == n) n     cout << x <<     << y <<     << z << endl; n   else n     cout << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n #define pb push n #define speed ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) n using namespace std; n typedef long long ll; n typedef long double ld; n typedef vector <ll> vll; n typedef pair<ll,ll> pll; n typedef vector <pair<ll,ll>> vpll; n typedef vector <vll> vvll; n ll n; n  n int get(int x,int y) n { n     int val; n     cout<< ?  <<x<<   <<y<<endl; n     cin>>val; n     return val; n } n  n int main() n { n     speed; n     cin>>n; n     ll l,h,m,midx,i; n     midx=get(1,n); n      n     if(midx>1 && get(1,midx)==midx) n     { n         l=1; n         h=midx-1; n          n         while(l<h) n         { n             m=(l+h+1)/2; n             i=get(m,midx); n             if(i==midx) n                 l=m; n             else  n                 h=m-1; n         } n         cout<< !  <<l<<endl; n     } n     else n     { n         l=midx+1; n         h=n; n          n         while(l<h) n         { n             m=(l+h)/2; n             i=get(midx,m); n             if(i!=midx) n                 l=m+1; n             else n                 h=m; n         } n         cout<< !  <<l<<endl; n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   a %= b; n   return gcd(b, a); n } n long long power(long long x, long long y, long long md = 1000000007) { n   long long res = 1; n   x %= md; n   while (y > 0) { n     if (y & 1) res = (res * x) % md; n     x = (x * x) % md; n     y = y >> 1; n   } n   return res % md; n } n bool sortbysec(const pair<long long, long long> &a, n                const pair<long long, long long> &b) { n   return (a.second < b.second); n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   long long sum = 0, arr[n]; n   for (long long i = 0; i < n; i++) { n     cin >> arr[i]; n     sum += arr[i]; n   } n   if (arr[0] > sum / 2) { n     cout << 1 <<   n ; n     cout << 1 <<   n ; n     return 0; n   } n   long long sum1 = arr[0]; n   std::vector<long long> v; n   v.push_back(1); n   for (long long i = 1; i < n; i++) { n     if (arr[0] >= (2 * arr[i])) { n       sum1 += arr[i]; n       v.push_back(i + 1); n     } n   } n   if (sum1 > (sum / 2)) { n     cout << v.size() <<   n ; n     for (long long j = 0; j < v.size(); j++) { n       cout << v[j] <<    ; n     } n     cout <<   n ; n   } else { n     cout << 0 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-8; n bool check(int n, int l, int v1, int v2, int k, double mid) { n   double t0 = (l - v2 * mid) / (v1 - v2); n   if (t0 < -eps) return 0; n   double tb = mid - t0; n   if (tb < -eps) return 0; n   double tback = (v2 - v1) * tb / (v2 + v1) + tb; n   if (tback + eps < tb) return 0; n   return (n - 1) / k * tback + tb < mid + eps && n          (n - 1) / k * (tb - tback) * v2 + tb * v2 < l + eps; n } n int main() { n   int n, l, v1, v2, k; n   scanf( %d%d%d%d%d , &n, &l, &v1, &v2, &k); n   double ll = 0, rr = 1. * l / v1; n   for (int i = 1; i <= 100000; i++) { n     double mid = (ll + rr) / 2; n     if (check(n, l, v1, v2, k, mid)) n       rr = mid; n     else n       ll = mid; n   } n   printf( %.10f , ll); n } n


#include <bits/stdc++.h> n using namespace std; n struct LCA { n   int logn; n   vector<int> depth; n   vector<vector<int> > lca; n   vector<vector<int> > *edges; n   LCA(int n, vector<vector<int> > *edges) { n     logn = log(n) / log(2) + 1; n     depth.resize(n + 1, 0); n     lca.resize(n + 1, vector<int>(logn, 0)); n     this->edges = edges; n     build(); n   } n   void dfs(int u, int p) { n     lca[u][0] = p; n     for (int i = 1; i < logn; i++) { n       lca[u][i] = lca[lca[u][i - 1]][i - 1]; n     } n     depth[u] = depth[p] + 1; n     for (auto &v : (*edges)[u]) { n       if (p != v) { n         dfs(v, u); n       } n     } n   } n   int parent(int v, int h) { n     for (int i = logn - 1; i >= 0; i--) { n       if (h & (1 << i)) { n         v = lca[v][i]; n       } n     } n     return v; n   } n   int lessParent(int u, int p) { return parent(u, depth[u] - depth[p] - 1); } n   int get(int u, int v) { n     if (depth[u] > depth[v]) { n       swap(u, v); n     } n     int h = depth[v] - depth[u]; n     v = parent(v, h); n     if (u == v) { n       return u; n     } n     for (int i = logn - 1; i >= 0; i--) { n       if (lca[u][i] != lca[v][i]) { n         u = lca[u][i]; n         v = lca[v][i]; n       } n     } n     return lca[u][0]; n   } n   void build() { dfs(1, 0); } n } * lca; n struct GraphBuilder { n   enum DIRECT { n     UP = 0, n     DOWN, n   }; n   int n; n   int k; n   vector<vector<int> > *e; n   vector<pair<int, int> > edges; n   set<pair<int, int> > cache; n   vector<vector<int> > addedVertices; n   vector<vector<int> > deletedVertices; n   LCA *lca; n   struct Node { n     int id; n     Node *leftChild; n     Node *rightChild; n     Node(int v, Node *l, Node *r) { n       id = v; n       leftChild = l; n       rightChild = r; n     } n   }; n   vector<pair<Node *, Node *> > root; n   GraphBuilder(int m, vector<vector<int> > *e) { n     k = 2 * m - 1; n     n = 2 * m - 1; n     this->e = e; n     lca = new LCA(e->size() - 1, e); n     addedVertices.resize(e->size()); n     deletedVertices.resize(e->size()); n     for (int i = 0; i < m; i++) { n       for (int j = 0; j < 2; j++) { n         int u, v; n         scanf( %d %d , &u, &v); n         int p = lca->get(u, v); n         if (u != p) { n           addedVertices[u].push_back((i << 1) | j); n           deletedVertices[lca->lessParent(u, p)].push_back((i << 1) | j); n         } n         if (v != p) { n           addedVertices[v].push_back((i << 1) | j); n           deletedVertices[lca->lessParent(v, p)].push_back((i << 1) | j); n         } n       } n     } n     root.resize(e->size(), {0, 0}); n     dfs(1, 0); n   } n   void dfs(int u, int p) { n     for (auto &v : (*e)[u]) { n       if (v != p) { n         dfs(v, u); n         root[u].first = merge(root[u].first, root[v].first, DOWN); n         root[u].second = merge(root[u].second, root[v].second, UP); n       } n     } n     for (auto &x : addedVertices[u]) { n       if (root[u].first) { n         add(x, root[u].first->id); n       } n       int a = 0; n       root[u].first = addVertex(0, n, root[u].first, (x ^ 1), DOWN); n       if (root[u].second) { n         add(root[u].second->id, (x ^ 1)); n       } n       root[u].second = addVertex(0, n, root[u].second, x, UP); n     } n     for (auto &x : deletedVertices[u]) { n       root[u].first = delVertex(0, n, root[u].first, (x ^ 1), DOWN); n       root[u].second = delVertex(0, n, root[u].second, x, UP); n       if (root[u].first) { n         add(x, root[u].first->id); n       } n       if (root[u].second) { n         add(root[u].second->id, (x ^ 1)); n       } n     } n   } n   void add(int u, int v) { edges.push_back({u, v}); } n   void addEdge(Node *p, int direct) { n     if (direct == DOWN) { n       if (p->leftChild) { n         add(p->id, p->leftChild->id); n       } n       if (p->rightChild) { n         add(p->id, p->rightChild->id); n       } n     } else { n       if (p->leftChild) { n         add(p->leftChild->id, p->id); n       } n       if (p->rightChild) { n         add(p->rightChild->id, p->id); n       } n     } n   } n   Node *addVertex(int l, int r, Node *p, int v, int direct) { n     if (!p) { n       p = new Node(0, 0, 0); n     } n     if (l == r) { n       return new Node(v, 0, 0); n     } else { n       int mid = (l + r) >> 1; n       Node *newNode = new Node(++k, p->leftChild, p->rightChild); n       if (v <= mid) { n         newNode->leftChild = addVertex(l, mid, p->leftChild, v, direct); n       } else { n         newNode->rightChild = addVertex(mid + 1, r, p->rightChild, v, direct); n       } n       addEdge(newNode, direct); n       return newNode; n     } n   } n   Node *delVertex(int l, int r, Node *p, int v, int direct) { n     if (l == r) { n       return 0; n     } else { n       int mid = (l + r) >> 1; n       Node *newNode = new Node(++k, p->leftChild, p->rightChild); n       if (v <= mid) { n         newNode->leftChild = delVertex(l, mid, p->leftChild, v, direct); n       } else { n         newNode->rightChild = delVertex(mid + 1, r, p->rightChild, v, direct); n       } n       if (!newNode->leftChild && !newNode->rightChild) { n         return 0; n       } n       addEdge(newNode, direct); n       return newNode; n     } n   } n   Node *merge(Node *p1, Node *p2, int direct) { n     if (!p1 || !p2) { n       return p1 ? p1 : p2; n     } else { n       Node *left = merge(p1->leftChild, p2->leftChild, direct); n       Node *right = merge(p1->rightChild, p2->rightChild, direct); n       Node *newNode = new Node(++k, left, right); n       addEdge(newNode, direct); n       return newNode; n     } n   } n }; n struct SAT { n   int n; n   vector<int> st; n   vector<int> mark; n   vector<int> group; n   vector<vector<int> > edges; n   vector<vector<int> > revEdges; n   SAT(int n, vector<pair<int, int> > &e) { n     this->n = n + 1; n     mark.resize(n + 1, 0); n     group.resize(n + 1, 0); n     edges.resize(n + 1); n     revEdges.resize(n + 1); n     for (auto &p : e) { n       addEdge(p.first, p.second); n     } n   } n   void addEdge(int u, int v) { n     edges[u].push_back(v); n     revEdges[v].push_back(u); n   } n   void dfs1(int u) { n     mark[u] = 1; n     for (auto &v : edges[u]) { n       if (mark[v] == 0) { n         dfs1(v); n       } n     } n     st.push_back(u); n   } n   void dfs2(int u, int k) { n     group[u] = k; n     for (auto &v : revEdges[u]) { n       if (group[v] == 0) { n         dfs2(v, k); n       } n     } n   } n   void solve() { n     for (int i = 0; i < n; i++) { n       if (mark[i] == 0) { n         dfs1(i); n       } n     } n     int k = 0; n     for (int i = st.size() - 1; i >= 0; i--) { n       int u = st[i]; n       if (group[u] == 0) { n         k++; n         dfs2(u, k); n       } n     } n   } n   void answer(int m) { n     for (int i = 0; i < 2 * m; i += 2) { n       if (group[i] == group[i | 1]) { n         printf( NO ); n         return; n       } n     } n     printf( YES n ); n     for (int i = 0; i < 2 * m; i += 2) { n       printf( %d n , (group[i] > group[i | 1]) ? 1 : 2); n     } n   } n   void print() { n     cout <<   nst n ; n     for (int x : st) { n       cout << x <<     << group[x] <<   n ; n     } n     cout <<   n ; n     for (int i = 0; i < n; i++) { n       cout << i <<   :  ; n       for (int j : edges[i]) { n         cout << j <<    ; n       } n       cout <<   n ; n     } n   } n }; n int main() { n   int n; n   scanf( %d , &n); n   vector<vector<int> > edges(n + 1); n   for (int i = 1; i < n; i++) { n     int u, v; n     scanf( %d %d , &u, &v); n     edges[u].push_back(v); n     edges[v].push_back(u); n   } n   int m; n   scanf( %d , &m); n   GraphBuilder builder(m, &edges); n   SAT solver(builder.k, builder.edges); n   solver.solve(); n   solver.answer(m); n } n


#include <bits/stdc++.h> n int main() { n   int N, L, i, count = 0, vivos = 0; n   int vet[1000000]; n   scanf( %d , &N); n   for (i = N - 1; i >= 0; i--) { n     scanf( %d , &vet[i]); n   } n   for (i = 0; i < N; i++) { n     if (count == 0) { n       count = vet[i]; n       vivos++; n     } else { n       count--; n       if (vet[i] > count) { n         count = vet[i]; n       } n       if (count == 0) { n         count = vet[i]; n       } n     } n   } n   printf( %d n , vivos); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int q, n, m; n   cin >> q; n   while (q--) { n     cin >> n >> m; n     string s; n     cin >> s; n     long long int a[n + 1], b[n + 1], zero = 0, one = 0; n     a[0] = 0; n     b[0] = 0; n     for (long long int i = 0; i < n; i++) { n       if (s[i] ==  0 ) { n         zero++; n       } else { n         one++; n       } n       a[i + 1] = zero; n       b[i + 1] = one; n     } n     set<long long int> se; n     long long int f = 1; n     for (long long int i = 0; i < n; i++) { n       long long int a1 = m + i - 2 * a[i]; n       long long int k = (zero - one); n       if (k == 0) { n         if (a1 == 0) f = 0; n       } else if (a1 % k == 0) { n         long long int a2 = a1 / k; n         long long int len = n * a2 + i; n         if (len >= 0) se.insert(len); n       } n     } n     if (f) { n       cout << se.size() << endl; n     } else { n       cout << -1 << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int t; n   cin >> t; n   while (t--) { n     string ch; n     cin >> ch; n     long long int ans = 0; n     int x = 0, y = 0; n     set<pair<pair<int, int>, pair<int, int>>> s; n     pair<int, int> prev = {0, 0}; n     for (int i = 0; i < (int)ch.size(); i++) { n       if (ch[i] ==  N ) n         y++; n       else if (ch[i] ==  S ) n         y--; n       else if (ch[i] ==  W ) n         x--; n       else n         x++; n       bool check = false; n       if (s.count({prev, {x, y}}) || s.count({{x, y}, prev})) n         ans++; n       else { n         s.insert({prev, {x, y}}); n         s.insert({{x, y}, prev}); n         ans += 5; n       } n       prev = {x, y}; n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include<bits/stdc++.h> n #define max(a,b) ((a)>(b)?(a):(b)) n using namespace std; n int n,m,k,x,y,z,dp[500039],l[500039],r[500039],now,a[500039],siz[500039],g[500039],f[500039]; n void work(int n){ n  for(int i=1;i<=n;i++) n   scanf( %d ,&a[i]),siz[a[i]]++,l[a[i]]=l[a[i]]?l[a[i]]:i,r[a[i]]=i; n  for(int i=1;i<=n;i++) n   if(l[i]) n    g[l[i]]=i; n } n int main(){ n  register int i,j; n  scanf( %d ,&n); n  work(n); n   n  for(i=n;i;i--){ n   dp[i]=dp[i+1];f[a[i]]++; n   if(g[i]) dp[i]=max(dp[i],dp[r[g[i]]+1]+siz[g[i]]); n   else dp[i]=max(dp[i],f[a[i]]); n  } n  cout<<n-dp[1]<<endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k, x, y, z, A[(1 << 17)], B[(1 << 17)], C[(1 << 17)], n     mmp[(1 << 17)], Comb[18][18]; n long long O[(1 << 17)], Ans[4][(1 << 17)], S[4][(1 << 17)]; n long long powmod(long long x, long long y = 998244353 - 2, n                  long long p = 998244353) { n   x %= p; n   y = (y % (p - 1) + (p - 1)) % (p - 1); n   long long ans = 1; n   while (y) { n     if (y & 1) ans = ans * x % p; n     x = x * x % p; n     y >>= 1; n   } n   return ans; n } n signed main() { n   scanf( %lld%lld%lld%lld%lld , &n, &k, &x, &y, &z); n   for (long long i = 0; i < n; i++) { n     scanf( %lld%lld%lld , &A[i], &B[i], &C[i]); n     B[i] ^= A[i]; n     C[i] ^= A[i]; n   } n   for (long long i = 0; i <= k; i++) n     for (long long j = 0; j <= i; j++) n       Comb[i][j] = !j ? 1 : Comb[i - 1][j - 1] + Comb[i - 1][j]; n   mmp[0] = 1; n   for (long long i = 1; i <= k; i++) { n     mmp[i] = 1 - (i % 2); n     for (long long j = 0; j < i; j++) mmp[i] -= Comb[i][j] * mmp[j]; n   } n   for (long long b1 = 0; b1 < 2; b1++) n     for (long long b2 = 0; b2 < 2; b2++) { n       memset(O, 0, sizeof O); n       for (long long i = 0; i < n; i++) O[(B[i] * b1) ^ (C[i] * b2)]++; n       for (long long i = 1; i < (1 << k); i *= 2) n         for (long long j = 0; j < (1 << k); j += i + i) n           for (long long k = j; k < j + i; k++) O[k] = (O[k] + O[k + i]); n       for (long long i = 0; i < (1 << k); i++) n         O[i] *= mmp[__builtin_popcount(i)], O[i]; n       for (long long i = 1; i < (1 << k); i *= 2) n         for (long long j = 0; j < (1 << k); j += i + i) n           for (long long k = j; k < j + i; k++) O[k + i] = (O[k + i] + O[k]); n       memcpy(Ans[b1 * 2 + b2], O, sizeof O); n     } n   S[0][1] = x - y - z; n   S[1][1] = x - y + z; n   S[2][1] = x + y - z; n   S[3][1] = x + y + z; n   for (long long i = 0; i < 4; i++) { n     S[i][0] = 1; n     for (long long j = 2; j <= n; j++) n       S[i][j] = S[i][j - 1] * S[i][1] % 998244353; n   } n   for (long long i = 0; i < (1 << k); i++) { n     long long _00 = Ans[0][i], _01 = Ans[1][i], _10 = Ans[2][i], n               _11 = Ans[3][i]; n     long long __00 = (_01 + _10 + _11 - _00) / 2; n     long long __11 = _11 - __00; n     long long __01 = _10 - __00; n     long long __10 = _01 - __00; n     O[i] = S[0][__11] * S[1][__10] % 998244353 * S[2][__01] % 998244353 * n            S[3][__00] % 998244353; n   } n   long long tot = 0; n   for (long long i = 0; i < n; i++) tot ^= A[i]; n   for (long long i = 1; i < (1 << k); i *= 2) n     for (long long j = 0; j < (1 << k); j += i + i) n       for (long long k = j; k < j + i; k++) { n         long long A = O[k], B = O[k + i]; n         O[k] = (A + B); n         O[k + i] = (A - B); n       } n   long long r = powmod(1 << k); n   for (long long i = 0; i < (1 << k); i++) n     printf( %lld  , n            (O[i ^ tot] % 998244353 * r % 998244353 + 998244353) % 998244353); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, arr[1042], cc[1042]; n vector<pair<int, int> > path; n vector<pair<int, int> > ans; n map<pair<long long, long long>, pair<int, int> > m; n long long base = 1031, mod = 1000000007LL, mod2 = 1000000009LL; n long long pows[1042] = {1}; n pair<long long, long long> h(int a[]) { n   long long ret = 0, ret2 = 0; n   for (int i = 0; i < n; i++) { n     ret *= base; n     ret2 *= base; n     ret += a[i]; n     ret2 += a[i]; n     ret %= mod; n     ret2 %= mod2; n   } n   return make_pair(ret, ret2); n } n bool ok() { n   if (m.find(h(arr)) != m.end()) { n     return 1; n   } n   return 0; n   for (int i = 1; i <= n; i++) { n     if (arr[i - 1] != i) { n       return 0; n     } n   } n   return 1; n } n bool f = 0; n void get(int ck) { n   if (ans.size()) { n     return; n   } n   if (ck == 2) { n     if (ok()) { n       ans = path; n       ans.push_back(m[h(arr)]); n     } n     return; n   } n   for (int s = 0; s < n; s++) { n     if (s != 0 && abs(arr[s] - arr[s - 1]) == 1 && s != 1 && n         abs(arr[s - 2] - arr[s - 1]) == 1) { n       continue; n     } n     for (int f = s; f < n; f++) { n       if (f != n - 1 && abs(arr[f] - arr[f + 1]) == 1 && f != n - 2 && n           abs(arr[f + 1] - arr[f + 2]) == 1) { n         continue; n       } n       path.push_back(make_pair(s, f)); n       reverse(arr + s, arr + f + 1); n       get(ck + 1); n       reverse(arr + s, arr + f + 1); n       path.pop_back(); n       if (ans.size()) { n         return; n       } n     } n   } n } n long long ss[1042], ff[1042], revHs[1042][1042]; n long long ss2[1042], ff2[1042], revHs2[1042][1042]; n long long pows2[1042]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   pows[0] = 1; n   pows2[0] = 1; n   for (int i = 1; i <= n; i++) { n     pows[i] = pows[i - 1] * base % mod; n     pows2[i] = pows2[i - 1] * base % mod2; n   } n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     cc[i] = i + 1; n   } n   ss[0] = 0; n   ss2[0] = 0; n   for (int i = 1; i <= n; i++) { n     ss[i] = ss[i - 1] + i * pows[n - i]; n     ss2[i] = ss2[i - 1] + i * pows2[n - i]; n     ss[i] %= mod; n     ss2[i] %= mod2; n   } n   ff[n - 1] = 0; n   ff2[n - 1] = 0; n   for (int i = n - 2; i >= 0; i--) { n     ff[i] = ff[i + 1] + (i + 2) * pows[n - i - 2]; n     ff2[i] = ff2[i + 1] + (i + 2) * pows2[n - i - 2]; n     ff[i] %= mod; n     ff2[i] %= mod2; n   } n   for (int s = 0; s < n; s++) { n     revHs[s][s] = s + 1; n     revHs2[s][s] = s + 1; n     for (int f = s + 1; f < n; f++) { n       revHs[s][f] = revHs[s][f - 1] + (f + 1) * pows[f - s]; n       revHs2[s][f] = revHs2[s][f - 1] + (f + 1) * pows2[f - s]; n       revHs[s][f] %= mod; n       revHs2[s][f] %= mod2; n     } n   } n   for (int s = 0; s < n; s++) { n     for (int f = s; f < n; f++) { n       long long c = ss[s] + revHs[s][f] * pows[n - f - 1] + ff[f]; n       long long c2 = ss2[s] + revHs2[s][f] * pows2[n - f - 1] + ff2[f]; n       c %= mod; n       c2 %= mod2; n       m[make_pair(c, c2)] = make_pair(s, f); n     } n   } n   get(0); n   reverse(ans.begin(), ans.end()); n   path = ans; n   int kk = 0; n   for (int j = 0; j < path.size(); j++) { n     if (path[j].first == path[j].second) { n       continue; n     } n     kk++; n   } n   cout << kk <<   n ; n   for (int j = 0; j < path.size(); j++) { n     if (path[j].first == path[j].second) { n       continue; n     } n     cout << path[j].first + 1 <<     << path[j].second + 1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5 + 100000; n int n, m, len_behind, len_front; n struct TREE { n   int fg; n   int M11[3]; n } T[maxn * 4]; n inline int L(int &x) { return x << 1; } n inline int R(int &x) { return x << 1 | 1; } n void f_maintain(int root, int len) { n   int a = L(root), b = R(root), lena = (len + 1) >> 1, lenb = len >> 1; n   T[root].M11[0] = T[a].M11[0]; n   if (T[root].M11[0] == lena) T[root].M11[0] += T[b].M11[0]; n   T[root].M11[1] = T[b].M11[1]; n   if (T[root].M11[1] == lenb) T[root].M11[1] += T[a].M11[1]; n   T[root].M11[2] = max(T[a].M11[2], T[b].M11[2]); n   T[root].M11[2] = max(T[root].M11[2], T[L(root)].M11[1] + T[R(root)].M11[0]); n } n void f_build(int root, int le, int ri) { n   T[root].fg = -1; n   T[root].M11[0] = T[root].M11[1] = T[root].M11[2] = ri - le + 1; n   if (le == ri) return; n   int mid = (le + ri) >> 1; n   f_build(L(root), le, mid); n   f_build(R(root), mid + 1, ri); n } n void f_giveson(int fg, int son, int len) { n   T[son].fg = fg; n   T[son].M11[0] = T[son].M11[1] = T[son].M11[2] = fg * len; n } n void f_pushdown(int root, int len) { n   if (len == 1) return; n   int a = L(root), b = R(root), lena = (len + 1) >> 1, lenb = len >> 1; n   if (T[root].fg != -1) { n     f_giveson(T[root].fg, a, lena); n     f_giveson(T[root].fg, b, lenb); n     T[root].fg = -1; n   } n } n void f_update(int root, int le, int ri, int Mle, int Mri, int fg) { n   if (Mle <= le && ri <= Mri) { n     f_giveson(fg, root, ri - le + 1); n     return; n   } n   f_pushdown(root, ri - le + 1); n   int mid = (le + ri) >> 1; n   if (Mle <= mid) f_update(L(root), le, mid, Mle, Mri, fg); n   if (Mri > mid) f_update(R(root), mid + 1, ri, Mle, Mri, fg); n   f_maintain(root, ri - le + 1); n } n int f_query(int root, int le, int ri, int x) { n   if (le == ri) return le; n   f_pushdown(root, ri - le + 1); n   int mid = (le + ri) >> 1; n   if (T[L(root)].M11[2] >= x) n     return f_query(L(root), le, mid, x); n   else if (T[L(root)].M11[1] + T[R(root)].M11[0] >= x) n     return mid - T[L(root)].M11[1] + 1; n   return f_query(R(root), mid + 1, ri, x); n } n int one[2][105]; n int main() { n   char ss[33]; n   while (scanf( %d %d %d %d , &n, &len_behind, &len_front, &m) + 1) { n     f_build(1, 1, n); n     memset(one, -1, sizeof one); n     int e, t, newlen, leaveid; n     for (e = 1; e <= m; e++) { n       scanf( %d , &t); n       if (t == 1) { n         scanf( %d , &newlen); n         if ((T[1].M11[0] == n && n >= newlen) || n             (T[1].M11[0] >= newlen + len_front)) { n           puts( 0 ); n           f_update(1, 1, n, 1, newlen, 0); n           one[0][e] = 1; n           one[1][e] = newlen; n           continue; n         } n         if (T[1].M11[2] >= newlen + len_behind + len_front) { n           int x = f_query(1, 1, n, newlen + len_behind + len_front); n           printf( %d n , x - 1 + len_behind); n           f_update(1, 1, n, x + len_behind, x + len_behind + newlen - 1, 0); n           one[0][e] = x + len_behind; n           one[1][e] = x + len_behind + newlen - 1; n           continue; n         } n         if (T[1].M11[1] >= newlen + len_behind) { n           int x = n + 1 - T[1].M11[1]; n           printf( %d n , x - 1 + len_behind); n           f_update(1, 1, n, x + len_behind, x + len_behind + newlen - 1, 0); n           one[0][e] = x + len_behind; n           one[1][e] = x + len_behind + newlen - 1; n           continue; n         } n         puts( -1 ); n       } else { n         scanf( %d , &leaveid); n         if (one[0][leaveid] != -1) { n           f_update(1, 1, n, one[0][leaveid], one[1][leaveid], 1); n           one[0][leaveid] = one[1][leaveid] = -1; n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool SR(int &x) { return scanf( %d , &x) == 1; } n bool SR(long long &x) { return scanf( %lld , &x) == 1; } n bool SR(double &x) { return scanf( %lf , &x) == 1; } n bool SR(char *s) { return scanf( %s , s) == 1; } n bool RI() { return true; } n template <typename I, typename... T> n bool RI(I &x, T &...tail) { n   return SR(x) && RI(tail...); n } n void SP(const int x) { printf( %d , x); } n void SP(const long long x) { printf( %lld , x); } n void SP(const double x) { printf( %.16lf , x); } n void SP(const char *s) { printf( %s , s); } n void PL() { puts(  ); } n template <typename I, typename... T> n void PL(const I x, const T... tail) { n   SP(x); n   if (sizeof...(tail)) putchar(   ); n   PL(tail...); n } n const int maxn = 3e3 + 3; n const int second = 200; n struct Node { n   static Node mem[maxn], *pmem; n   int dep; n   Node *fail, *to[2]; n   int who; n   Node() : dep(-1), fail(0), to{NULL, NULL}, who(-1) {} n   Node(int _d, int _w) : dep(_d), fail(0), to{NULL, NULL}, who(_w) {} n } Node::mem[maxn], *Node::pmem = Node::mem; n struct AC { n   AC() { root = new (Node::pmem++) Node(-1, -1); } n   Node *root; n   void add(const string &s, int id) { n     Node *pt = root; n     for (int i = 0; i < int(((int)(s).size())); i++) { n       if (!pt->to[s[i] -  a ]) n         pt->to[s[i] -  a ] = new (Node::pmem++) Node(1 + pt->dep, -1); n       pt = pt->to[s[i] -  a ]; n     } n     pt->who = id; n   } n   void build() { n     queue<Node *> q; n     q.push(root); n     root->fail = root; n     while (((int)(q).size())) { n       Node *pt = q.front(); n       q.pop(); n       for (int i = 0; i < int(2); i++) n         if (pt->to[i]) q.push(pt->to[i]); n       if (pt->dep == -1) { n         for (int i = 0; i < int(2); i++) n           if (pt->to[i]) pt->to[i]->fail = root; n         for (int i = 0; i < int(2); i++) n           if (!pt->to[i]) pt->to[i] = root; n       } else { n         for (int i = 0; i < int(2); i++) n           if (pt->to[i]) { n             Node *&cur = pt->to[i]->fail; n             for (cur = pt->fail; cur != root && !cur->to[i]; cur = cur->fail) n               ; n             if (cur->to[i]) cur = cur->to[i]; n           } n         for (int i = 0; i < int(2); i++) n           if (!pt->to[i]) { n             Node *&cur = pt->to[i]; n             for (cur = pt->fail; cur != root && !cur->to[i]; cur = cur->fail) n               ; n             if (cur->to[i]) cur = cur->to[i]; n           } n       } n     } n   } n } ac; n int n, m; n string s[maxn]; n void read() { n   RI(n, m); n   for (int i = 0; i < int(m); i++) { n     static char in[maxn]; n     RI(in); n     s[i] = in; n   } n } n const int MOD = 1e9 + 7; n string os[maxn]; n int sig; n int f[maxn][maxn]; n int _c[2][maxn][maxn / second + 1]; n int (*prv)[maxn / second + 1], (*cur)[maxn / second + 1]; n int big; n int om; n void build() { n   om = m; n   for (int i = 0; i < int(m); i++) os[i] = s[i]; n   sort(s, s + m); n   m = unique(s, s + m) - s; n   sort(s, s + m, [&](const string &a, const string &b) { n     return make_pair(((int)(a).size()), a) > make_pair(((int)(b).size()), b); n   }); n   for (big = 0; big < m && ((int)(s[big]).size()) > second; big++) n     ; n   for (int i = 0; i < int(m); i++) ac.add(s[i], i); n   ac.build(); n   sig = Node::pmem - Node::mem; n } n int ans[maxn]; n void sol_big() { n   for (int i = 0; i < int(sig); i++) f[1][i] = Node::mem[i].to[0] - Node::mem; n   for (int i = 0; i < int(sig); i++) f[2][i] = Node::mem[i].to[1] - Node::mem; n   for (int i = (3); i <= int(n); i++) n     for (int j = 0; j < int(sig); j++) f[i][j] = f[i - 2][f[i - 1][j]]; n   prv = _c[0]; n   cur = _c[1]; n   for (int i = 0; i < int(sig); i++) n     for (int j = 0; j < int(big); j++) { n       Node *pt = Node::mem + i; n       for (pt = pt->to[0]; pt->who != j && pt->dep != -1; pt = pt->fail) n         ; n       prv[i][j] = (pt->who == j); n     } n   for (int i = 0; i < int(sig); i++) n     for (int j = 0; j < int(big); j++) { n       Node *pt = Node::mem + i; n       for (pt = pt->to[1]; pt->who != j && pt->dep != -1; pt = pt->fail) n         ; n       cur[i][j] = (pt->who == j); n     } n   for (int _ = (3); _ <= int(n); _++) { n     static int tmp[maxn][maxn / second + 1]; n     auto &m1 = cur, &m2 = prv; n     for (int i = 0; i < int(sig); i++) n       for (int j = 0; j < int(big); j++) n         tmp[i][j] = m1[i][j] + m2[f[_ - 1][i]][j]; n     for (int i = 0; i < int(sig); i++) n       for (int j = 0; j < int(big); j++) n         if (tmp[i][j] >= MOD) tmp[i][j] -= MOD; n     swap(prv, cur); n     for (int i = 0; i < int(sig); i++) n       for (int j = 0; j < int(big); j++) cur[i][j] = tmp[i][j]; n   } n   for (int i = 0; i < int(big); i++) ans[i] = cur[0][i]; n } n string h[maxn], t[maxn]; n int ap[maxn][maxn]; n void merge(const string &p, const string &q, int res[]) { n   for (int i = 0; i < int(((int)(p).size())); i++) { n     Node *pt = ac.root; n     for (int j = (i); j <= int(((int)(p).size()) - 1); j++) n       pt = pt->to[p[j] -  a ]; n     for (int j = 0; j < int(((int)(q).size())); j++) { n       pt = pt->to[q[j] -  a ]; n       if (big <= pt->who && pt->who < m && n           pt->dep == (((int)(p).size()) - i) + j) n         res[pt->who]++; n     } n   } n   for (int i = (big); i <= int(m - 1); i++) n     if (res[i] >= MOD) res[i] -= MOD; n } n void sol_small() { n   h[1] =  a ; n   h[2] =  b ; n   for (int i = (3); i <= int(15); i++) h[i] = h[i - 1] + h[i - 2]; n   for (int i = (1); i <= int(15); i++) t[i] = h[i]; n   if (n <= 15) { n     for (int j = (big); j <= int(m - 1); j++) n       for (size_t o = h[n].find(s[j]); ~o; o = h[n].find(s[j], o + 1)) ans[j]++; n   } else { n     for (int i = (14); i <= int(15); i++) n       for (int j = (big); j <= int(m - 1); j++) n         for (size_t o = h[i].find(s[j]); ~o; o = h[i].find(s[j], o + 1)) n           ap[i][j]++; n     for (int i = (14); i <= int(15); i++) n       h[i].resize(second), t[i].erase(t[i].begin(), t[i].end() - second); n     for (int i = (16); i <= int(n); i++) { n       for (int j = (big); j <= int(m - 1); j++) n         ap[i][j] = ap[i - 1][j] + ap[i - 2][j]; n       for (int j = (big); j <= int(m - 1); j++) n         if (ap[i][j] >= MOD) ap[i][j] -= MOD; n       h[i] = h[i - 1]; n       t[i] = t[i - 2]; n       merge(t[i - 1], h[i - 2], ap[i]); n     } n     for (int i = (big); i <= int(m - 1); i++) ans[i] = ap[n][i]; n   } n } n void sol() { n   sol_big(); n   sol_small(); n   for (int i = 0; i < int(om); i++) { n     int id = lower_bound(s, s + m, os[i], n                          [&](const string &a, const string &b) { n                            return make_pair(((int)(a).size()), a) > n                                   make_pair(((int)(b).size()), b); n                          }) - n              s; n     PL(ans[id]); n   } n } n int main() { n   read(); n   build(); n   sol(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string zbor1, zbor2; n   cin >> zbor1; n   int n, i, j; n   n = zbor1.length(); n   if (n < 10) { n     cout <<  NO ; n     return 0; n   } n   for (i = n - 1; i >= n - 10; i--) { n     zbor2 = zbor2 + zbor1[i]; n   } n   if (zbor2 ==  SECROFEDOC ) { n     cout <<  YES ; n     return 0; n   } n   zbor2.clear(); n   for (i = 0; i < 10; i++) { n     zbor2 = zbor2 + zbor1[i]; n   } n   if (zbor2 ==  CODEFORCES ) { n     cout <<  YES ; n     return 0; n   } n   for (i = 0; i < 10; i++) { n     zbor2.clear(); n     for (j = 0; j <= i; j++) { n       zbor2 = zbor2 + zbor1[j]; n     } n     for (j = n - 9 + i; j < n; j++) { n       zbor2 = zbor2 + zbor1[j]; n     } n     if (zbor2 ==  CODEFORCES ) { n       cout <<  YES ; n       return 0; n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int abs(long long int a, long long int b) { n   if (a < b) { n     return -1 * (a - b); n   } n   return (a - b); n } n bool comp(long long int a, long long int b) { n   if (a > b) { n     return true; n   } n   return false; n } n int main() { n   int n, a, b; n   cin >> n >> a >> b; n   vector<long long int> v; n   for (int i = 0; i < n; i++) { n     long long int t; n     cin >> t; n     v.push_back(t); n   } n   sort(v.begin(), v.end(), comp); n   long long int ans = abs(v[n - b], v[n - b - 1]); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, i, j; n   int max = INT_MIN; n   cin >> n; n   int a[n]; n   int b[n]; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (j = n - 1; j >= 0; j--) { n     if (a[j] <= max) { n       b[j] = max + 1 - a[j]; n     } else { n       b[j] = 0; n     } n     if (max < a[j]) { n       max = a[j]; n     } n   } n   for (i = 0; i < n; i++) { n     cout << b[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1E9 + 7, INF = 2E18 + 5; n const double PI = 2 * acos(0.0); n const long double EPS = 1.0E-14; n long long arr[1000005], arrFreq[1000005], arrAns[1000005]; n vector<long long> vec; n int main() { n   long long n, m, lcm = 1, sz = 0; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     scanf( %lld , &arr[i]); n     if (arr[i] <= m) { n       arrFreq[arr[i]]++; n     } n   } n   for (int i = 1; i <= m; i++) { n     if (!arrFreq[i]) continue; n     for (int j = i; j <= m; j += i) { n       arrAns[j] += arrFreq[i]; n     } n   } n   for (int i = 1; i <= m; i++) { n     if (arrAns[i] > sz) { n       sz = arrAns[i]; n       lcm = i; n     } n   } n   for (int i = 0; i < n; i++) { n     if (lcm % arr[i] == 0) { n       vec.push_back(i + 1); n     } n   } n   cout << lcm <<     << vec.size() <<   n ; n   for (int i = 0; i < vec.size(); i++) { n     printf( %lld  , vec[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1500010; n int n, cnt, ans; n int a[N], bug[N], v[N]; n map<pair<int, int>, int> vis; n bool check(int i) { n   if (!(i & 1)) { n     if (i < n) n       return a[i - 1] < a[i] && a[i + 1] < a[i]; n     else n       return a[i - 1] < a[i]; n   } else if (i > 1 && i < n) n     return a[i - 1] > a[i] && a[i + 1] > a[i]; n   else if (i == 1) n     return a[i + 1] > a[i]; n   else n     return a[i - 1] > a[i]; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= n; i += 2) { n     if (i == 1 && a[i] >= a[i + 1]) { n       if (!v[i]) bug[++cnt] = i, v[i] = 1; n       if (!v[i + 1]) bug[++cnt] = i + 1, v[i + 1] = 1; n     } else if (i == n && a[i] >= a[i - 1]) { n       if (!v[i]) bug[++cnt] = i, v[i] = 1; n       if (!v[i - 1]) bug[++cnt] = i - 1, v[i - 1] = 1; n     } else if (i > 1 && i < n) { n       if (a[i] >= a[i + 1] && a[i] >= a[i - 1]) { n         if (!v[i]) bug[++cnt] = i, v[i] = 1; n         if (!v[i + 1]) bug[++cnt] = i + 1, v[i + 1] = 1; n         if (!v[i - 1]) bug[++cnt] = i - 1, v[i - 1] = 1; n       } else { n         if (a[i] >= a[i + 1]) { n           if (!v[i]) bug[++cnt] = i, v[i] = 1; n           if (!v[i + 1]) bug[++cnt] = i + 1, v[i + 1] = 1; n         } n         if (a[i] >= a[i - 1]) { n           if (!v[i]) bug[++cnt] = i, v[i] = 1; n           if (!v[i - 1]) bug[++cnt] = i - 1, v[i - 1] = 1; n         } n       } n     } n   } n   if (cnt > 6) { n     puts( 0 ); n     return 0; n   } n   for (int i = 1; i <= cnt; i++) n     for (int j = 1; j <= n; j++) { n       if (a[j] == a[bug[i]]) continue; n       swap(a[j], a[bug[i]]); n       bool fl = 1; n       for (int k = 1; k <= cnt; k++) n         if (!check(bug[k])) fl = 0; n       if (!check(j)) fl = 0; n       if (fl) { n         pair<int, int> p = make_pair(min(bug[i], j), max(bug[i], j)); n         if (!vis[p]) { n           ans++; n           vis[p] = 1; n         } n       } n       swap(a[j], a[bug[i]]); n     } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1100000; n int n, m; n char a[MAXN], b[MAXN]; n int s[MAXN], t[MAXN]; n inline int id(int x, int y) { n   if (x < 1 || x > n || y < 1 || y > m) return 0; n   return (x - 1) * m + y; n } n bool check(int k) { n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) n       if (i - k >= 1 && i + k <= n && j - k >= 1 && j + k <= m && n           s[id(i + k, j + k)] - s[id(i - k - 1, j + k)] - n                   s[id(i + k, j - k - 1)] + s[id(i - k - 1, j - k - 1)] == n               0) n         b[id(i, j)] =  X ; n       else n         b[id(i, j)] =  . ; n   } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       t[id(i, j)] = t[id(i - 1, j)] + t[id(i, j - 1)] - t[id(i - 1, j - 1)] + n                     (b[id(i, j)] ==  X ); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       int l1 = max(i - k, 1), r1 = min(i + k, n); n       int l2 = max(j - k, 1), r2 = min(j + k, m); n       if (a[id(i, j)] ==  X  && t[id(r1, r2)] - t[id(l1 - 1, r2)] - n                                         t[id(r1, l2 - 1)] + n                                         t[id(l1 - 1, l2 - 1)] == n                                     0) n         return 0; n     } n   return 1; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %s , a + (i - 1) * m + 1); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       s[id(i, j)] = s[id(i - 1, j)] + s[id(i, j - 1)] - s[id(i - 1, j - 1)] + n                     (a[id(i, j)] !=  X ); n   int l = 0, r = min(n, m); n   while (l < r) { n     int mid = l + r + 1 >> 1; n     if (check(mid)) n       l = mid; n     else n       r = mid - 1; n   } n   printf( %d n , l); n   check(l); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) putchar(b[id(i, j)]); n     putchar(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n deque<int> A, B; n long long p, i, j, k, n, m, aux; n long long fact(int a) { n   long long f = 1; n   int i; n   for (int i = (int)(1); i <= (int)(a); ++i) f *= i; n   return f; n } n int main(void) { n   cin >> p; n   cin >> n; n   for (int i = (int)(1); i <= (int)(n); ++i) { n     cin >> aux; n     A.push_back(aux); n   } n   cin >> n; n   for (int i = (int)(1); i <= (int)(n); ++i) { n     cin >> aux; n     B.push_back(aux); n   } n   long long step(0); n   long long stari = fact(p + 1); n   while (step <= stari) { n     if (A.empty()) return cout << step <<     << 2, 0; n     if (B.empty()) return cout << step <<     << 1, 0; n     ++step; n     int x = A.front(); n     A.pop_front(); n     int y = B.front(); n     B.pop_front(); n     if (x < y) { n       B.push_back(x); n       B.push_back(y); n     } else { n       A.push_back(y); n       A.push_back(x); n     } n   } n   cout <<  -1 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int a[(int)(2 * 1e5 + 10)]; n long long pa[(int)(2 * 1e5 + 10)]; n long long sa[(int)(2 * 1e5 + 10)]; n int main() { n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     pa[i] = 1ll * a[i] + pa[i - 1]; n   } n   for (int i = n; i >= 1; --i) { n     sa[i] = 1ll * a[i] + sa[i + 1]; n   } n   int x = n; n   long long mx = 0; n   int i = 1; n   while (i <= n) { n     if (i < x) { n       if (pa[i] > sa[x]) n         --x; n       else if (pa[i] < sa[x]) n         ++i; n       else n         mx = max(mx, pa[i]), ++i, --x; n     } else n       break; n   } n   cout << mx << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1000 + 3][1000 + 3]; n int used[1000 + 3][1000 + 3]; n int n; n void dfs(int x, int y) { n   used[x][y] = 1; n   for (int i = 0; i <= 1001; i++) { n     if (!used[x][i] && a[x][i]) dfs(x, i); n   } n   for (int i = 0; i <= 1001; i++) { n     if (!used[i][y] && a[i][y]) dfs(i, y); n   } n } n int main() { n   cin >> n; n   int tmp1, tmp2; n   for (int i = 0; i < n; i++) { n     cin >> tmp1 >> tmp2; n     a[tmp1][tmp2] = 1; n   } n   int ans = 0; n   for (int i = 0; i <= 1001; i++) { n     for (int j = 0; j <= 1001; j++) { n       if (a[i][j] && !used[i][j]) { n         dfs(i, j); n         ans++; n       } n     } n   } n   cout << --ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace io { n string separator =    ; n } n template <typename T> n inline void write(T x) { n   cout << x << io::separator; n } n template <typename T, typename... Args> n inline void write(T x, Args... args) { n   write(x); n   write(args...); n } n inline void writeln() { cout <<   n ; } n template <typename... Args> n inline void writeln(Args... args) { n   write(args...); n   writeln(); n } n template <typename T> n inline void read(T& x) { n   cin >> x; n } n template <typename T, typename... Args> n inline void read(T& x, Args&... args) { n   cin >> x; n   read(args...); n } n template <typename T> n inline void writec(T x) { n   for (auto i = x.begin(); i != x.end(); i++) write(*i); n   writeln(); n } n template <typename TL, typename TR> n inline TL GCD(TL a, TR b) { n   TL c; n   while (b) { n     c = b; n     b = a % b; n     a = c; n   } n   return a; n } n template <typename TL, typename TR> n inline TL LCM(TL a, TR b) { n   return a / GCD(a, b) * b; n } n template <typename TL, typename TR> n inline TL MAX(TL a, TR b) { n   return a > b ? a : b; n } n template <typename T, typename... Args> n inline T MAX(T a, Args... args) { n   return MAX(a, MAX(args...)); n } n template <typename TL, typename TR> n inline TL MIN(TL a, TR b) { n   return a < b ? a : b; n } n template <typename T, typename... Args> n inline T MIN(T a, Args... args) { n   return MIN(a, MIN(args...)); n } n inline int64_t fac(int16_t n) { n   static vector<int64_t> f(1, 1); n   for (auto i = f.size(); i <= n; i++) f.push_back(f.back() * i); n   return f[n]; n } n inline int64_t suma(int32_t a1, int32_t d, int32_t n) { n   return n * (2 * a1 + (n - 1) * d) / 2; n } n inline int32_t factor(int32_t n) { n   static vector<int32_t> d(2, 2), prime; n   if (n + 1 > d.size()) { n     int32_t np = d.size() - 1; n     int32_t nn = d.size(); n     while (n > nn - 1) nn *= 2; n     nn--; n     d.resize(nn + 1); n     for (auto i = 2; i <= nn; i++) { n       if (!d[i]) { n         d[i] = i; n         prime.push_back(i); n       } n       int64_t x; n       for (int32_t j = 0; prime[j] <= d[i] && j < prime.size() && n                           (x = (int64_t)i * prime[j]) <= nn; n            j++) n         d[x] = prime[j]; n     } n   } n   return d[n]; n } n inline bool isprime(int32_t n) { return (factor(n) == n); } n inline int32_t prime(int32_t n) { n   static vector<int32_t> p(1, 2); n   if (n + 1 > p.size()) { n     int32_t np = p.size() - 1; n     int32_t nn = p.size(); n     while (n > nn - 1) nn *= 2; n     factor(nn * (log(nn) + log(log(nn)))); n     nn--; n     p.resize(nn + 1); n     int32_t x = p[np] + 1; n     for (auto i = np + 1; i <= nn; i++) { n       while (!isprime(x)) x++; n       p[i] = x++; n     } n   } n   return p[n]; n } n int32_t MOD = 1e9 + 7; n inline int32_t SUM(int32_t x, int32_t y) { return (x + y) % MOD; } n inline int32_t MUL(int32_t x, int32_t y) { return (int64_t)x * y % MOD; } n inline int32_t POW(int32_t x, int32_t n) { n   int32_t y = 1; n   while (n) { n     if (n % 2) y = MUL(y, x); n     x = MUL(x, x); n     n /= 2; n   } n   return y; n } n inline int32_t INV(int32_t x) { return POW(x, MOD - 2); } n inline int32_t DIV(int32_t x, int32_t y) { return MUL(x, INV(y)); } n inline int32_t P(int32_t l, int32_t r) { n   int32_t x = 1; n   for (auto i = l; i <= r; i++) x = MUL(x, i); n   return x; n } n inline int32_t FAC(int32_t n) { return P(2, n); } n inline int32_t C(int32_t n, int32_t k) { return DIV(P(k + 1, n), P(2, n - k)); } n void solve(); n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   solve(); n } n inline void solve() { n   int16_t n; n   read(n); n   vector<int16_t> r(n); n   for (auto i = r.begin(); i != r.end(); i++) read(*i); n   int16_t mn = (*min_element(r.begin(), r.end())); n   int16_t mx = (*max_element(r.begin(), r.end())); n   int16_t s = 0; n   for (auto i : r) s += i - mn; n   s -= mx - mn; n   while (s < mx - mn && mn != 0) { n     s += n - 1; n     mn--; n   } n   s += mx - mn; n   if (!mn) { n     s = 0; n     for (auto i : r) s += i; n   } n   (s); n   string ans0(n,  0 ); n   string ans = ans0; n   writeln(mn); n   if (mn) { n     writeln(s / 2); n     if (s % 2) { n       int16_t i = 0; n       for (auto i_ = 3; i_--;) { n         while (r[i] == mn) i++; n         ans[i] =  1 ; n         r[i]--; n         i++; n       } n       writeln(ans); n       s -= 3; n     } n     for (auto i_ = s / 2; i_--;) { n       int16_t mxi = distance(r.begin(), max_element(r.begin(), r.end())); n       int16_t i = 0; n       while (r[i] == mn || i == mxi) i++; n       ans = ans0; n       ans[i] = ans[mxi] =  1 ; n       r[i]--; n       r[mxi]--; n       writeln(ans); n     } n   } else { n     writeln(s); n     for (auto i = 0; i <= n - 1; i++) { n       ans = ans0; n       ans[i] = ans[(i + 1) % n] =  1 ; n       for (auto i_ = r[i]; i_--;) writeln(ans); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename a> n void SWAP(a &b, a &c) { n   a d = b; n   b = c; n   c = d; n } n long long power(long long a, long long b) { n   long long result = 1; n   while (b) { n     if (b & 1) result = a * result; n     a *= a; n     b >>= 1; n   } n   return result; n } n long long gcd(long long a, long long b) { n   while (b) { n     a = a % b; n     SWAP(a, b); n   } n   return a; n } n long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); } n int main() { n   long long n, k; n   scanf( %lld %lld , &n, &k); n   long long h[n]; n   long long sum = 0, ans = LLONG_MAX, index = 1; n   for (long long i = 0; i < n; i++) { n     scanf( %lld , &h[i]); n     sum += h[i]; n     if (i + 1 >= k) { n       if (ans > sum) { n         index = i - k + 2; n         ans = sum; n       } n       sum -= h[i - k + 1]; n     } n   } n   printf( %lld n , (index)); n   return 0; n } n