#include <bits/stdc++.h> n using namespace std; n struct node { n   int x, y; n }; n vector<node> answer; n int dis[1000005], a[1000005], pre[1000005]; n bool prime[1000005]; n void getprime() { n   for (int i = 2; i < 1000005 - 5; i++) { n     if (!prime[i]) { n       for (int j = i * 2; j < 1000005 - 5; j += i) { n         prime[j] = true; n       } n     } n   } n   int maxx = 2; n   for (int i = 2; i < 1000005 - 5; i++) { n     if (prime[i] == false) maxx = i; n     pre[i] = maxx; n   } n } n int main() { n   getprime(); n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     dis[a[i]] = i; n   } n   int t = 0; n   for (int i = 1; i <= n; i++) { n     if (a[i] == i) continue; n     int j = dis[i]; n     while (j != i) { n       int k = pre[j - i + 1]; n       k = j - k + 1; n       node q; n       q.x = k, q.y = j; n       answer.push_back(q); n       swap(dis[a[j]], dis[a[k]]); n       swap(a[j], a[k]); n       j = k; n     } n   } n   printf( %d n , answer.size()); n   for (int i = 0; i < answer.size(); i++) { n     printf( %d %d n , answer[i].x, answer[i].y); n   } n } n


//#pragma comment(linker,  /STACK:102400000,102400000 ) n #include<bits/stdc++.h> n using namespace std; n typedef long long ll; n #define int ll n typedef pair<int,int>pii; n #define ff first n #define ss second n #define debug(x) std:: cerr << #x <<   =   << x << std::endl; n const int maxn=2010,inf=0x3f3f3f3f,mod=1000000007; n const ll INF=0x3f3f3f3f3f3f3f3f; n const double eps=1e-9; n //#define DEBUG//#define lowbit(x) ((x) & -(x))//<<setiosflags(ios::fixed)<<setprecision(9) n void read(){} n template<typename T,typename... T2>inline void read(T &x,T2 &... oth) { n  x=0; int ch=getchar(),f=0; n  while(ch< 0 ||ch> 9 ){if (ch== - ) f=1;ch=getchar();} n  while (ch>= 0 &&ch<= 9 ){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} n  if(f)x=-x; n  read(oth...); n } n ll a[maxn],dp[maxn][maxn]; n ll MAX[maxn][maxn],MIN[maxn][maxn]; n int s[maxn][maxn]; n signed main(signed argc, char const *argv[]) n { n  std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); n  #ifdef DEBUG n   freopen( input.in ,  r , stdin); n  // freopen( output.out ,  w , stdout); n  #endif n  int n; n  cin>>n; n  for(int i=1;i<=n;i++) n   cin>>a[i]; n  sort(a+1,a+n+1); n  memset(dp,INF,sizeof(dp)); n // memset(MIN,INF,sizeof(MIN)); n  for(int i=1;i<=n;i++) n  { n   dp[i][i]=0; n //  s[i][i]=i; n //  MAX[i][i]=MIN[i][i]=a[i]; n  } n  for(int len=2;len<=n;len++) n  { n   for(int l=1;l<=n-len+1;l++) n   { n    int r=l+len-1; n    dp[l][r]=min(dp[l][r-1],dp[l+1][r])+a[r]-a[l]; n //   fprintf(stderr, [%lld,%lld]=%lld n ,l,r,dp[l][r]); n //   for(int k=s[l][r-1];k<s[l+1][r];k++) n //   { n //    MAX[l][r]=max(MAX[l][k],MAX[k+1][r]); n //    MIN[l][r]=min(MIN[l][k],MIN[k+1][r]); n //    ll now=min(MAX[l][k]-MIN[k+1][r],a[r]-a[l]); n //    if(dp[l][r]>dp[l][k]+dp[k+1][r]+now) n //    { n //     dp[l][r]=dp[l][k]+dp[k+1][r]+now; n //     s[l][r]=k; n //    } n //   } n   } n  } n  cout<<dp[1][n]<<endl; n  return 0; n } n /* n  * 2021-04-16-23.54.07 n */ n  n


#include <bits/stdc++.h> n using namespace std; n long long ar[200004]; n long long prefix[200004]; n long long D[200004]; n void calc(long n) { n   D[n] = 0; n   long long mx = -1000000000000000000; n   for (long i = n - 1; i >= 1; i--) { n     D[i] = max(mx, prefix[i + 1] - D[i + 1]); n     mx = max(mx, D[i]); n   } n   std::cout << D[1] << endl; n } n int main() { n   std::ios::sync_with_stdio(false); n   ; n   long n; n   std::cin >> n; n   for (long i = 1; i <= n; i++) { n     std::cin >> ar[i]; n   } n   prefix[0] = 0; n   for (long i = 1; i <= n; i++) { n     prefix[i] = ar[i] + prefix[i - 1]; n   } n   calc(n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n, i, u; n   cin >> n >> u; n   long long int a[n + 2]; n   bool pos = false; n   double res = 0; n   for (i = 0; i < n + 1; ++i) { n     cin >> a[i]; n   } n   int j = 0; n   for (int i = 0; i < n - 2; i++) { n     j = max(j, i + 2); n     while (j + 1 < n && a[j + 1] - a[i] <= u) j++; n     if (a[j] - a[i] <= u) { n       res = max(res, (double(a[j] - a[i + 1])) / (double(a[j] - a[i]))); n       pos = true; n     } n   } n   if (pos) n     cout << fixed << setprecision(10) << res; n   else n     cout <<  -1 ; n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 99999; n int d[maxn], s[maxn]; n int n; n int m; n queue<int> q; n vector<pair<int, int> > p; n bool inq[maxn]; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     scanf( %d %d , &d[i], &s[i]), m += d[i]; n     if (d[i] == 1) q.push(i); n   } n   m /= 2; n   while (!q.empty()) { n     int x = q.front(); n     q.pop(); n     if (d[x] <= 0) continue; n     int y = s[x]; n     p.push_back(make_pair(x, y)); n     s[y] ^= x; n     d[y]--; n     if (d[y] == 1) q.push(s[x]); n   } n   printf( %d n , p.size()); n   for (int i = 0; i < p.size(); i++) printf( %d %d n , p[i].first, p[i].second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int a[200005]; n int b[200005]; n long long sum; n int res[200005]; n int ge[35]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]), sum += a[i]; n   for (int i = 1; i <= n; i++) scanf( %d , &b[i]), sum += b[i]; n   if (n == 1 && a[1] != b[1]) { n     puts( -1 ); n     return 0; n   } n   if (sum % (n * 2) != 0) { n     puts( -1 ); n     return 0; n   } n   sum = sum / n; n   sum = sum / 2; n   for (int i = 1; i <= n; i++) { n     int tmp = a[i] + b[i] - sum; n     if (tmp % n || tmp < 0) { n       puts( -1 ); n       return 0; n     } n     tmp = tmp / n; n     res[i] = tmp; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < 30; j++) { n       if (res[i] & (1 << j)) ge[j]++; n     } n   } n   for (int i = 1; i <= n; i++) { n     long long nowa = 0, nowb = 0; n     for (int j = 0; j < 30; j++) { n       if (res[i] & (1 << j)) { n         nowa += ge[j] * (1 << j); n         nowb += 1ll * n * (1 << j); n       } else { n         nowb += ge[j] * (1 << j); n       } n     } n     if (nowa != a[i] || nowb != b[i]) { n       puts( -1 ); n       return 0; n     } n   } n   for (int i = 1; i < n; i++) printf( %d  , res[i]); n   printf( %d n , res[n]); n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n #define endl   n  n #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); n #define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield); n const int mx=1e5+123; n int arr[mx]; n long long x,cnt; n int main() n { n     optimize(); n     int t; n     cin>>t; n     while(t--){ n         int n; n         cin>>n; n  n         int arr[n]; n         for(int i=0;i<n;i++)cin>>arr[i]; n         sort(arr,arr+n); n         int i=1,x=arr[1]-arr[0]; n         while(i<n){ n             if(arr[i]-arr[i-1]<x) n             x=arr[i]-arr[i-1]; n  n             if(arr[i]<=x)i++; n             else break; n         } n         cout<<i<<endl; n          n     } n  n  n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int q; n unsigned long long a, b, c; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> q; n   while (q--) { n     cin >> a >> b >> c; n     unsigned long long sum = a + b + c; n     cout << sum / 2 <<   n ; n     sum = 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n int a[5000], b[5000], n, m, i, j, k = 0; n int main() { n   scanf( %d%d , &n, &m); n   for (i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     b[i] = a[i]; n   } n   for (i = 0; i < n; i++) n     if (a[i] == b[i]) n       for (j = 0; j < n; j++) n         if (a[j] != b[i] && a[i] != b[j]) { n           int z = b[i]; n           b[i] = b[j]; n           b[j] = z; n           break; n         } n   for (i = 0; i < n; i++) n     if (a[i] != b[i]) ++k; n   printf( %d n , k); n   for (i = 0; i < n; i++) printf( %d %d n , a[i], b[i]); 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(nullptr); n   cout << fixed << setprecision(15); n   srand(42u); n   unsigned int n; n   unsigned int m; n   cin >> n >> m; n   cout << (min(n, m) & 1 ?  Akshat  :  Malvika ) << endl; n   return EXIT_SUCCESS; n } n


#include <bits/stdc++.h> n using namespace std; n int adder[1234567], pre[1234567]; n int main() { n   std::ios::sync_with_stdio(false); n   long long n, k; n   cin >> n >> k; n   int i, l, r; n   l = 0; n   r = 0; n   string s; n   cin >> s; n   for (i = 1; i < n; i++) { n     if (r < i) { n       l = i; n       r = i; n       while (r < n && s[r] == s[r - l]) r++; n       pre[i] = r - l; n       r--; n       continue; n     } n     if (r - i + 1 > pre[i - l]) { n       pre[i] = pre[i - l]; n     } else { n       l = i; n       while (r < n && s[r] == s[r - l]) r++; n       pre[i] = r - l; n       r--; n     } n   } n   long long haha, haha1, endp; n   for (i = 1; i < n; i++) { n     haha = k * i; n     haha1 = (k + 1) * i; n     endp = i + pre[i]; n     if (haha > endp) continue; n     haha1 = min(haha1, n); n     haha1 = min(haha1, endp); n     adder[haha]++; n     adder[haha1 + 1]--; n   } n   if (k == 1) { n     adder[n]++; n   } n   for (i = 1; i <= n; i++) { n     adder[i] += adder[i - 1]; n     if (adder[i]) n       cout << 1; n     else n       cout << 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n FILE *stm; n const double PI = 22.0 / 7.0; n const long long MXN = 1e5 + 1; n const long long MNN = 1e3 + 1; n const long long MOD = 1e9 + 7; n const long long INF = 1e18; n bool srt(string a, string b) { return a.size() > b.size(); } n int gcd(int a, int b) { n   if (b == 0) n     return a; n   else n     gcd(b, a % b); n } n int lcm(int a, int b) { return (b / gcd(a, b)) * a; } n int main() { n   string first; n   cin >> first; n   int n = first.size(); n   int ctr = 0; n   int j = 0; n   while (first[j] ==  a  and j < n) { n     ctr++; n     j++; n   } n   if (ctr == n) { n     first[n - 1] =  z ; n   } else if (first[0] !=  a ) { n     for (int i = 0; i < n and first[i] !=  a ; i++) first[i] = first[i] - 1; n   } else if (first[0] ==  a ) { n     int i = 0; n     while (first[i] ==  a ) { n       i++; n     } n     for (; i < n and first[i] !=  a ; i++) first[i] = first[i] - 1; n   } n   cout << first << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int N = 100010; n const int M = 25; n long long dp[M][N]; n int cnt[N], a[N]; n long long cost, left, right; n void move(int nleft, int nright) { n   while (nleft < left) cost += cnt[a[--left]]++; n   while (nright > right) cost += cnt[a[++right]]++; n   while (nleft > left) cost -= --cnt[a[left++]]; n   while (nright < right) cost -= --cnt[a[right--]]; n } n void solve(int type, int l, int r, int opl, int opr) { n   if (l > r) return; n   long long mincost = LLONG_MAX; n   int mid = l + r >> 1, sit; n   for (int i = opl, sz = std::min(opr, mid - 1); i <= sz; ++i) { n     move(i + 1, mid); n     long long x = dp[type - 1][i] + cost; n     if (x < mincost) { n       mincost = x; n       sit = i; n     } n   } n   dp[type][mid] = mincost; n   solve(type, l, mid - 1, opl, sit); n   solve(type, mid + 1, r, sit, opr); n } n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n   } n   left = 1, right = 0; n   move(1, n); n   memset(dp[0], 0x3f, sizeof(dp[0])); n   dp[0][0] = 0; n   for (int i = 1; i <= k; ++i) { n     solve(i, 1, n, 0, n); n   } n   return printf( %I64d n , dp[k][n]), 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n string name; n string hostname; n string res; n int is_good(char c) { n   if (c -  a  >= 0 && c -  a  < 26) return 1; n   if (c -  A  >= 0 && c -  A  < 26) return 1; n   if (c -  0  >= 0 && c -  0  < 10) return 1; n   if (c ==  _ ) return 1; n   return 0; n } n int main() { n   cin >> s; n   int tk = 0; n   int cl1 = 0; n   int cl2 = 0; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  @ ) { n       if (tk != 0) { n         printf( NO n ); n         return 0; n       } n       tk = 1; n       cl1++; n       continue; n     } n     if (s[i] ==  / ) { n       cl2++; n       if (tk != 1) { n         printf( NO n ); n         return 0; n       } n       tk = 2; n       continue; n     } n     if (tk == 0) name += s[i]; n     if (tk == 1) hostname += s[i]; n     if (tk == 2) res += s[i]; n   } n   if (res ==    && cl2 != 0) { n     printf( NO n ); n     return 0; n   } n   if (name ==    || hostname ==   ) { n     printf( NO n ); n     return 0; n   } n   if (name.length() > 16 || hostname.length() > 32 || res.length() > 16) { n     printf( NO n ); n     return 0; n   } n   for (int i = 0; i < name.length(); i++) n     if (!is_good(name[i])) { n       printf( NO n ); n       return 0; n     } n   for (int i = 0; i < res.length(); i++) n     if (!is_good(res[i])) { n       printf( NO n ); n       return 0; n     } n   int tl = 0; n   for (int i = 0; i < hostname.length(); i++) n     if (hostname[i] ==  . ) { n       if (tl > 16 || tl == 0) { n         printf( NO n ); n         return 0; n       } n       tl = 0; n       continue; n     } else if (!is_good(hostname[i])) { n       printf( NO n ); n       return 0; n     } else n       tl++; n   if (tl > 16 || tl == 0) { n     printf( NO n ); n     return 0; n   } n   if (cl1 > 1 || cl2 > 1) { n     printf( NO n ); n     return 0; n   } n   printf( YES n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1005; n int main() { n   int i, j; n   int n, pare[maxn], mark[maxn]; n   while (scanf( %d , &n) != EOF) { n     memset(pare, 0, sizeof(pare)); n     memset(mark, 0, sizeof(mark)); n     for (i = 2; i <= n; i++) { n       scanf( %d , &pare[i]); n       mark[pare[i]] = 1; n     } n     for (i = n; i >= 2; i--) n       if (mark[i] == 0) { n         mark[pare[i]]++; n       } n     for (i = 1; i <= n; i++) { n       if (mark[i] != 0 && mark[i] < 4) break; n     } n     if (i == (n + 1)) n       printf( YES n ); n     else n       printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int k; n   cin >> k; n   k += 2000; n   cout << 2000 <<   n ; n   cout << -1 <<    ; n   for (int i = 0; i < 1999; i++) { n     if (k > 1000000) { n       cout << 1000000 <<    ; n       k -= 1000000; n     } else { n       cout << k <<    ; n       k = 0; n     } n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC optimize( Ofast ) n using namespace std; n void solve() { n   long long n; n   cin >> n; n   vector<long long> a(n), b(n); n   for (long long &i : a) cin >> i; n   for (long long &i : b) cin >> i; n   sort(a.begin(), a.end()); n   sort(b.begin(), b.end()); n   for (long long &i : a) cout << i <<    ; n   cout << endl; n   for (long long &i : b) cout << i <<    ; n   cout << endl; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(); n   cout.tie(); n   long long n = 1; n   cin >> n; n   while (n--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n namespace A { n int ch[10001000][2], fail[10001000], end[10001000], cnt; n inline int insert(char *s, int id, int *dis) { n   int len = strlen(s), rt = 0; n   for (int i = 0; i < len; ++i) { n     int d = s[i] -  a ; n     if (!ch[rt][d]) ch[rt][d] = ++cnt; n     rt = ch[rt][d]; n   } n   if (end[rt]) dis[end[rt]] = 1; n   end[rt] = id; n   return len; n } n void getfail(int dis[1600][1600]) { n   queue<int> q; n   if (ch[0][0]) q.push(ch[0][0]); n   if (ch[0][1]) q.push(ch[0][1]); n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (int k = 0; k <= 1; ++k) { n       if (!ch[u][k]) n         ch[u][k] = ch[fail[u]][k]; n       else { n         fail[ch[u][k]] = ch[fail[u]][k]; n         if (end[fail[ch[u][k]]]) { n           if (end[ch[u][k]]) n             dis[end[ch[u][k]]][end[fail[ch[u][k]]]] = 1; n           else n             end[ch[u][k]] = end[fail[ch[u][k]]]; n         } n         q.push(ch[u][k]); n       } n     } n   } n } n void match(char *s, int len, int *dis) { n   int rt = 0; n   for (int i = 0; i < len; ++i) { n     rt = ch[rt][s[i] -  a ]; n     if (end[rt]) dis[end[rt]] = 1; n   } n } n };  // namespace A n int n, st[1600], dis[1600][1600]; n char s[10001000]; n namespace D { n int S, T, tot = 1, fir[1600], nxt[1600 * 1600], to[1600 * 1600], n           val[1600 * 1600], dep[1600], cur[1600]; n queue<int> q; n inline void addE(int u, int v, int w) { n   nxt[++tot] = fir[u], fir[u] = tot, to[tot] = v, val[tot] = w; n   nxt[++tot] = fir[v], fir[v] = tot, to[tot] = u, val[tot] = 0; n } n inline bool bfs() { n   memset(dep, -1, sizeof dep); n   memcpy(cur, fir, sizeof fir); n   q.push(S), dep[S] = 1; n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (int i = fir[u], v; i; i = nxt[i]) { n       v = to[i]; n       if ((~dep[v]) || !val[i]) continue; n       dep[v] = dep[u] + 1, q.push(v); n     } n   } n   return (~dep[T]); n } n int dfs(int u, int now) { n   if (u == T || !now) return now; n   int res = 0; n   for (int &i = cur[u], v; i; i = nxt[i]) { n     v = to[i]; n     if (dep[v] != dep[u] + 1 || !val[i]) continue; n     int tmp = dfs(v, min(now, val[i])); n     if (!tmp) continue; n     res += tmp, now -= tmp, val[i] -= tmp, val[i ^ 1] += tmp; n     if (!now) break; n   } n   return res; n } n inline int dinic() { n   int res = 0, tmp; n   while (bfs()) n     while ((tmp = dfs(S, INF))) res += tmp; n   return res; n } n int mat[1600]; n bool vis[1600]; n void match(int u) { n   if (vis[u]) return; n   vis[u] = 1; n   for (int i = fir[u]; i; i = nxt[i]) n     if (!vis[to[i]] && to[i] <= 2 * n) vis[to[i]] = 1, match(mat[to[i]]); n } n void write() { n   for (int u = 1; u <= n; ++u) n     for (int i = fir[u]; i && !mat[u]; i = nxt[i]) n       if (!val[i] && to[i] <= 2 * n) mat[mat[u] = to[i]] = u; n   for (int u = 1; u <= n; ++u) n     if (!mat[u]) match(u); n   for (int i = 1; i <= n; ++i) { n     if (vis[i] && !vis[i + n]) printf( %d%c , i,    n [i == n]); n   } n } n }  // namespace D n using D::addE; n using D::dinic; n int main() { n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     scanf( %s , s + st[i]); n     st[i + 1] = A::insert(s + st[i], i, dis[i]) + st[i]; n   } n   A::getfail(dis); n   for (int i = 1; i <= n; ++i) A::match(s + st[i], st[i + 1] - st[i], dis[i]); n   for (int k = 1; k <= n; ++k) n     for (int i = 1; i <= n; ++i) n       for (int j = 1; j <= n; ++j) n         if (dis[i][k] && dis[k][j]) dis[i][j] = 1; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) n       if (dis[i][j]) D::S = 2 * n + 1, D::T = D::S + 1; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) n       if (dis[i][j] && i != j) addE(i, j + n, 1); n   for (int i = 1; i <= n; ++i) addE(D::S, i, 1), addE(i + n, D::T, 1); n   int res = dinic(); n   res = n - res; n   cout << res << endl; n   D::write(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j, k, t, cnt = 0, flag, cs = 1; n   pair<int, int> A[110]; n   scanf( %d %d , &j, &k); n   for (i = 0; i < j; i++) { n     scanf( %d , &A[i].first); n     A[i].second = i + 1; n   } n   sort(A, A + j); n   vector<int> v; n   int sum = 0; n   for (i = 0; i < j; i++) { n     sum += A[i].first; n     if (sum > k) break; n     cnt++; n     v.push_back(A[i].second); n   } n   cout << cnt << endl; n   if (cnt == 0) return 0; n   for (i = 0; i <= cnt - 2; i++) cout << v[i] <<    ; n   cout << v[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int d[1008][1008]; n int main() { n   int n, x1, x2, y1, y2; n   int di[] = {0, 0, 1, -1}; n   int dj[] = {1, -1, 0, 0}; n   cin >> n >> x1 >> y1 >> x2 >> y2; n   int i, j, k; n   d[n - y1][x1] = 1; n   queue<int> qi, qj, dist; n   qi.push(n - y1); n   qj.push(x1); n   dist.push(1); n   int ii, jj, D; n   while (!qi.empty()) { n     ii = qi.front(); n     jj = qj.front(); n     qi.pop(); n     qj.pop(); n     D = dist.front(); n     dist.pop(); n     int t1, t2; n     for (k = 0; k < 4; k++) { n       t1 = ii + di[k]; n       t2 = jj + dj[k]; n       if ((t1 == 0 || t1 == n || t2 == 0 || t2 == n) && d[t1][t2] == 0 && n           (t1 >= 0 && t1 <= n && t2 >= 0 && t2 <= n)) { n         d[t1][t2] = D + 1; n         qi.push(t1); n         qj.push(t2); n         dist.push(D + 1); n       } n     } n   } n   cout << d[n - y2][x2] - 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   using namespace std; n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   string b, b1, b2, e, e1, e2; n   cin >> b1 >> b2 >> e1 >> e2; n   swap(b2[0], b2[1]); n   swap(e2[0], e2[1]); n   b = b1 + b2; n   e = e1 + e2; n   b.erase(b.find( X ), 1); n   e.erase(e.find( X ), 1); n   if ((b + b).find(e) != string::npos) { n     cout <<  YES ; n   } else { n     cout <<  NO ; n   } n   return 0; n } n


#include <bits/stdc++.h> n  n using namespace std; n  n typedef long long ll; n typedef pair<int, int> pll; n  n #define all(x)                      (x).begin(),(x).end() n #define X                           first n #define Y                           second n #define sep                             n #define endl                          n  n #define debug(x)                    cerr << #x <<  :   <<  x << endl; n  n const ll MAXN = 1e6 + 10; n const ll INF = 8e18; n const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9; n const ll LOG = 20; n  n int n, m, P[MAXN], H[MAXN], t_0, par[MAXN][LOG];  n vector<int> adj[MAXN]; n vector<pll> adj2[MAXN]; n vector<pair<int, pll>> edges, mst_edges; n set<int> un_vis; n ll ans; n bool w_0[MAXN][LOG]; n set<pll> used; n  n int Find(int v) { n  if (v == P[v]) return v; n  return P[v] = Find(P[v]); n } n  n inline bool Union(int v, int u, int w) { n  int pu = u, pv = v; n  v = Find(v), u = Find(u); n  if (v == u) return false; n  P[v] = u; n  ans += w; n  used.insert({pv, pu}); n  used.insert({pu, pv}); n  n  if (w == 0) t_0++; n  mst_edges.push_back({w, {pu, pv}}); n  return true; n } n  n void dfs(int v) { n  un_vis.erase(v); n   n  int lst = 0; n  while (true) { n   auto it = un_vis.upper_bound(lst); n   if (it == un_vis.end()) break; n   lst = *it; n   if (binary_search(all(adj[v]), lst)) continue; // n  n   Union(v, lst, 0); n   dfs(lst); n  } n } n  n void dfs2(int v, int p, int w) { n  par[v][0] = p; n  w_0[v][0] = (w == 0); n  n  for (pll e : adj2[v]) { n   int u = e.X, w = e.Y; n   if (u == p) continue; n   H[u] = H[v] + 1; n   dfs2(u, v, w); n  } n } n  n pair<int, bool> kth_par(int v, int k) { n  bool b = false; n  for (int i = LOG - 1; i >= 0; i--) n   if (k & (1 << i)) n    b |= w_0[v][i], v = par[v][i]; n  return {v, b}; n } n  n bool LCA(int u, int v) { n  if (H[v] < H[u]) swap(v, u); n  pair<int, bool> p = kth_par(v, H[v] - H[u]); n  v = p.X; n  bool b = p.Y; n  if (v == u) return b; n  n  for (int i = LOG - 1; i >= 0; i--) { n   if (par[v][i] != par[u][i]) { n    b |= w_0[v][i]; n    b |= w_0[u][i]; n    v = par[v][i]; n    u = par[u][i]; n   } n  } n   n  b |= w_0[v][0]; n  b |= w_0[u][0]; n  return b; n     n } n  n int main() { n  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); n  cin >> n >> m; n  int x = 0; n  n  for (int i = 0; i < m; i++) { n   int u, v, w; n   cin >> u >> v >> w; n   x ^= w; n   edges.push_back({w, {u, v}}); n   adj[v].push_back(u); n   adj[u].push_back(v); n  } n  n  for (int i = 1; i <= n; i++) { n   sort(all(adj[i])); n   un_vis.insert(i); n   P[i] = i;  n  }  n  n  while (!un_vis.empty()) dfs(*un_vis.begin()); n  n  sort(all(edges)); n  for (auto e : edges) Union(e.Y.X, e.Y.Y, e.X);  n  for (auto e : mst_edges) { n   adj2[e.Y.X].push_back({e.Y.Y, e.X}); n   adj2[e.Y.Y].push_back({e.Y.X, e.X}); n  } n  n  dfs2(1, 0, 1); n  for (int i = 1; i < LOG; i++) { n   for (int v = 1; v <= n; v++) { n    par[v][i] = par[par[v][i - 1]][i - 1]; n    w_0[v][i] = w_0[v][i - 1] | w_0[par[v][i - 1]][i - 1]; n   } n  } n  n  ll tot = 1ll * n * (n - 1) / 2 - m; n  if (tot == t_0) { n   for (pair<int, pll> et : edges) { n    pll e = et.Y; n    if (used.find(e) != used.end()) continue; n    bool b = LCA(e.X, e.Y); n    if (b) return cout << min(ans + et.X, ans + x) << endl, 0; n   } n    n   cout << ans + x << endl; n   return 0;  n  }  n  n  cout << ans << endl; n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n map<char, int> u; n int main() { n   cin >> s >> s; n   for (auto x : s) ++u[x]; n   if (u.size() == 1) return puts( Yes ), 0; n   for (auto& x : u) n     if (x.second >= 2) return puts( Yes ), 0; n   puts( No ); n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n int n, k; n int A[25], B[2]; n int fact[25]; n int mod(long long int a) { return (a % MOD + MOD) % MOD; } n int poww(int pw) { n   if (pw == 0) return 1; n   return 3 * poww(pw - 1); n } n int result = 0; n int precompute(int U1) { n   int ret = 0; n   int el = (n + 1) / 2, fl = n - el; n   int EL = (1 << el), FL = (1 << fl); n   map<pair<int, int>, int> store; n   int cnt, sum; n   for (int i = 0; i < FL; i++) { n     sum = cnt = 0; n     for (int bit = 0; bit < fl; bit++) { n       if (i & (1 << bit)) sum += A[el + bit], cnt++; n       if (sum > MOD) sum = MOD; n     } n     if (sum != MOD) store[pair<int, int>(sum, cnt)]++; n   } n   for (int i = 0; i < EL; i++) { n     sum = cnt = 0; n     for (int bit = 0; bit < el; bit++) { n       if (i & (1 << bit)) sum += A[bit], cnt++; n       if (sum > MOD) sum = MOD; n     } n     if (sum > U1) continue; n     for (int x = 0; x < fl + 1; x++) { n       pair<int, int> t = pair<int, int>(U1 - sum, x); n       if (store.count(t)) { n         int ff = mod((long long int)store[t] * fact[x + cnt]); n         ff = mod((long long int)ff * fact[n - x - cnt]); n         ret = mod(ret + ff); n       } n     } n   } n   result = mod(result - ret); n   return result; n } n int pc2(int U1, int U2) { n   int el = (n - 1) / 2, fl = n - el; n   int EL = poww(el), FL = poww(fl); n   precompute(U1); n   precompute(U2); n   if (U1 > U2) swap(U1, U2); n   U2 = U2 - U1; n   map<pair<pair<int, int>, int>, int> store; n   int sum1, sum2, ret = 0; n   int c1, c2; n   for (int i = 0; i < FL; i++) { n     sum1 = sum2 = c1 = c2 = 0; n     int t = i; n     for (int bit = 0; bit < fl; bit++) { n       if (t % 3 == 1) sum1 += A[el + bit], c1++; n       if (t % 3 == 2) sum2 += A[el + bit], c2++; n       t /= 3; n       if (sum1 > MOD) sum1 = MOD; n       if (sum2 > MOD) sum2 = MOD; n     } n     if (sum1 != MOD && sum2 != MOD) n       store[pair<pair<int, int>, int>(pair<int, int>(sum1, sum2), n                                       (c1 << 8) | c2)]++; n   } n   for (int i = 0; i < EL; i++) { n     sum1 = sum2 = c1 = c2 = 0; n     int t = i; n     for (int bit = 0; bit < el; bit++) { n       if (t % 3 == 1) sum1 += A[bit], c1++; n       if (t % 3 == 2) sum2 += A[bit], c2++; n       if (sum1 > MOD) sum1 = MOD; n       if (sum2 > MOD) sum2 = MOD; n       t /= 3; n     } n     if (sum1 > U1 || sum2 > U2) continue; n     for (int x = 0; x < fl + 1; x++) { n       for (int y = 0; y + x <= fl; y++) { n         if (x + y > fl) continue; n         pair<pair<int, int>, int> t = pair<pair<int, int>, int>( n             pair<int, int>(U1 - sum1, U2 - sum2), (x << 8) | y); n         if (store.count(t)) { n           int ff = store[t]; n           ff = mod((long long int)ff * fact[c1 + x]); n           ff = mod((long long int)ff * fact[c2 + y]); n           ff = mod((long long int)ff * fact[n - c1 - x - c2 - y]); n           ret = mod((long long int)ret + ff); n         } n       } n     } n   } n   result = mod((long long int)result + ret); n   return ret; n } n int main() { n   B[0] = B[1] = -1; n   fact[0] = 1; n   for (int i = 1; i < 25; i++) fact[i] = ((long long int)fact[i - 1] * i) % MOD; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> A[i]; n   } n   cin >> k; n   for (int i = 0; i < k; i++) cin >> B[i]; n   result = fact[n]; n   if (k == 1) n     precompute(B[0]); n   else if (k == 2) { n     pc2(B[0], B[1]); n   } n   cout << result << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   ; n   long long int T, N, X; n   cin >> T; n   while (T--) { n     cin >> N >> X; n     vector<bool> Pl(100100); n     for (long long int i = 0, P; i < N; i++) { n       cin >> P; n       Pl[P - 1] = true; n     } n     for (long long int i = 0; i < 100100; i++) { n       if (!Pl[i] && X > 0) { n         Pl[i] = true; n         X--; n       } n     } n     long long int Counter = 0; n     for (long long int i = 0; i < 100100; i++) { n       if (Pl[i]) n         Counter++; n       else n         break; n     } n     cout << Counter << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n set<pair<int, int> > second; n int arr[(int)(1e5) + 30]; n int main() { n   int n, m; n   int u, v; n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     cin >> u >> v; n     second.insert(make_pair(u, v)); n     second.insert(make_pair(v, u)); n   } n   for (int i = 0; i < n; i++) arr[i] = i + 1; n   int limit = 1000; n   while (limit--) { n     random_shuffle(arr, arr + n); n     arr[n] = arr[0]; n     for (int i = 0; i < m; i++) { n       if (second.find(make_pair(arr[i], arr[i + 1])) != second.end()) goto re; n     } n     for (int i = 0; i < m; i++) cout << arr[i] <<     << arr[i + 1] << endl; n     return 0; n   re:; n   } n   puts( -1 ); n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> v[100005]; n int a[100008]; n int b[100005]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &v[i].first); n     v[i].second = i; n   } n   sort(v, v + n); n   int val = 0; n   int qt = (n + 2) / 3; n   int cnt = 0; n   for (int i = 0; i < n; i++) { n     if (i < qt) { n       int idx = v[i].second; n       a[idx] = i; n       b[idx] = v[i].first - i; n     } else if (i < 2 * qt) { n       int idx = v[i].second; n       b[idx] = i; n       a[idx] = v[i].first - i; n     } else { n       int idx = v[i].second; n       b[idx] = n - 1 - i; n       a[idx] = v[i].first - b[idx]; n     } n   } n   puts( YES ); n   for (int i = 0; i < n; i++) { n     printf( %d  , a[i]); n   } n   puts(  ); n   for (int i = 0; i < n; i++) { n     printf( %d  , b[i]); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int h, m, m2; n   char c; n   scanf( %d %c %d , &h, &c, &m); n   scanf( %d , &m2); n   m2 += m; n   int h2 = (int)(m2 / 60); n   h2 += h; n   h2 %= 24; n   m2 = m2 % 60; n   if (h2 >= 0 && h2 <= 9) printf( 0 ); n   printf( %d: , h2); n   if (m2 >= 0 && m2 <= 9) printf( 0 ); n   printf( %d n , m2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18; n const int32_t M = 1e9 + 7; n const long long N = 1e6 + 5; n void no() { cout <<  0 0 0  << endl; } n void cpc() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(NULL); n } n void solve() { n   long long n; n   cin >> n; n   vector<long long> v(n); n   for (long long i = 0; i < n; i++) cin >> v[i]; n   long long j = n / 2 - 1; n   while (j >= 4 && v[j] <= v[j + 1]) j--; n   if (j < 4) { n     no(); n     return; n   } n   deque<long long> va; n   va.push_front(j); n   j--; n   while (j >= 0) { n     if (v[j] > v[j + 1]) va.push_front(j); n     j--; n   } n   va.push_front(-1); n   if (va.size() < 4) { n     no(); n     return; n   } n   long long a, b, c, d; n   a = va[0]; n   b = va[1]; n   c = -1; n   d = va[va.size() - 1]; n   long long dis = b - a; n   for (long long i = 0; i < n; i++) { n     if ((va[i] - b) > dis) { n       c = va[i]; n       break; n     } n   } n   if (c == -1 || (d - c) <= dis) { n     no(); n     return; n   } n   cout << b - a <<     << c - b <<     << d - c <<     << endl; n } n int32_t main() { n   cpc(); n   long long t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1e5 + 10, N = 2e4 + 10; n const int n = 1e5; n long long ans, s[M]; n int gcd(int x, int y) { n   int i = 0, j = 0; n   if (x == 0) return y; n   if (y == 0) return x; n   for (; 0 == (x & 1); i++) x >>= 1; n   for (; 0 == (y & 1); j++) y >>= 1; n   if (i > j) i = j; n   while (1) { n     if (x < y) x ^= y, y ^= x, x ^= y; n     if (0 == (x -= y)) return y << i; n     while (0 == (x & 1)) x >>= 1; n   } n } n int T, A, B, C; n int prime[N], cc[M], cnt; n bool vis[M]; n void init() { n   s[1] = 1; n   for (int i = 2; i <= n; i++) { n     if (!vis[i]) { n       prime[++cnt] = i; n       s[i] = 2; n       cc[i] = 1; n     } n     for (int j = 1, v; j <= cnt && i * prime[j] <= n; j++) { n       v = i * prime[j]; n       vis[v] = 1; n       if (!(i % prime[j])) { n         s[v] = s[i] / (cc[i] + 1) * (cc[i] + 2); n         cc[v] = cc[i] + 1; n         break; n       } n       s[v] = s[i] * s[prime[j]]; n       cc[v] = 1; n     } n   } n } n long long all(int a, int b, int c) { return s[a] * s[b] * s[c]; } n long long S(long long a) { return (a * (a - 1ll)) / 2ll; } n long long S2(long long a) { return (a * (a - 1ll) * (a - 2ll)) / 6ll * 4ll; } n long long calc1(int ab, int c) { return S(s[ab]) * s[c]; } n long long calc2(int a, int bc) { return s[a] * S(s[bc]); } n long long calc3(int abc) { return S(s[abc]) * 2ll + S2(s[abc]); } n long long calc4(int ab, int abc) { return (s[ab] - s[abc]) * S(s[abc]); } n long long calc5(int ab, int bc, int ac, int abc) { n   return (s[ab] - s[abc]) * (s[bc] - s[abc]) * (s[ac] - s[abc]); n } n int ab, bc, ac, abc; n long long solve() { n   return all(A, B, C) - calc1(ab, C) - calc2(A, bc) - calc2(B, ac) + n          calc4(ab, abc) + calc4(bc, abc) + calc4(ac, abc) - n          calc5(ab, bc, ac, abc) + calc3(abc); n } n int main() { n   init(); n   for (scanf( %d , &T); T--;) { n     scanf( %d%d%d , &A, &B, &C); n     ab = gcd(A, B), bc = gcd(B, C), ac = gcd(A, C); n     abc = gcd(A, bc); n     printf( %I64d n , solve()); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long t, d, ct, q, ans, l, m, r, n, mx, mn, i, j, k, x, y, z, s; n char ch; n string ss =   , str =   ; n long long a[200003], b[200003]; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(nullptr); n   s = k = d = l = mx = m = mn = r = q = i = j = z = x = y = ct = ans = 0; n   stack<long long> st; n   cin >> ss; n   n = ss.length(); n   long long dp[n + 2]; n   memset(dp, 0, sizeof(dp)); n   for (i = 0; i < n; i++) { n     if (ss[i] ==  ( ) { n       st.push(i); n       continue; n     } n     if (st.empty()) continue; n     long long lft = st.top(); n     st.pop(); n     if (lft) n       dp[i] = dp[lft - 1] + i - lft + 1; n     else n       dp[i] = i - lft + 1; n     mx = max(mx, dp[i]); n   } n   for (i = 0; i < n; i++) n     if (dp[i] == mx) ct++; n   if (!mx) return cout <<  0 1 , 0; n   cout << mx <<     << ct; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[200100]; n deque<int> Q; n bool cnt[10001000]; n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   for (int i = 0; i < n; i++) cin >> a[i], cnt[a[i]] = true; n   sort(a, a + n); n   int Min = a[0], Max = a[n - 1], Ans = 0; n   for (int i = Min; i <= 1e7; i++) { n     if (Q.size() && Q.front() < i - m) Q.pop_front(); n     if (i >= Min + m - 1) n       while (Q.size() >= k) Q.pop_back(), Ans++; n     if (cnt[i]) Q.push_back(i); n   } n   cout << Ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[1003]; n const int mod = 1000000007; n int comb[1005][1005], i, j; n int main() { n   int lim = 1002; n   for (i = 1; i <= lim; i++) comb[i][i] = comb[i][0] = 1; n   for (i = 2; i <= lim; i++) n     for (j = 1; j < i; j++) { n       long long aux = comb[i - 1][j] + comb[i - 1][j - 1]; n       aux %= mod; n       comb[i][j] = aux; n     } n   cin >> n; n   for (i = 1; i <= n; i++) cin >> a[i]; n   long long ans = 1; n   long long nr = a[1]; n   for (i = 2; i <= n; i++) { n     int en = a[i] - 1; n     ans = (1LL * ans * comb[en + nr][en]) % mod; n     nr += a[i]; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char buf[5000010], ch; n int a[5000010]; n int dc[] = {0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}; n int sd = 24 * 60 * 60; n int main() { n   int n, m, top = 1; n   int YY, MM, DD, hh, mm, ss; n   scanf( %d%d , &n, &m); n   getchar(); n   a[0] = 0xc0c0c0c0; n   while (gets(buf)) { n     sscanf(buf,  %d%c%d%c%d%c%d%c%d%c%d , &YY, &ch, &MM, &ch, &DD, &ch, &hh, n            &ch, &mm, &ch, &ss); n     int t = (dc[MM] + DD - 1) * sd + hh * 60 * 60 + mm * 60 + ss; n     a[top++] = t; n     t -= n - 1; n     int l = 0, r = top - 1; n     while (l < r - 1) { n       int mid = l + r >> 1; n       if (a[mid] < t) n         l = mid; n       else n         r = mid; n     } n     if (top - r >= m) { n       buf[19] = 0; n       printf( %s n , buf); n       return 0; n     } n   } n   printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   long long n; n   cin >> n; n   for (long long y = 2; y <= 10005; y++) { n     for (long long z = y + 1; z <= 10005; z++) { n       if (2 * y * z - n * y - n * z <= 0) continue; n       long long x = (n * y * z) / (2 * y * z - n * y - n * z); n       if ((n * y * z) % (2 * y * z - n * y - n * z) == 0 && x <= 1000000000 && n           x != y && x != z && y != z) { n         cout << x <<     << y <<     << z <<   n ; n         return 0; n       } n     } n   } n   cout << -1 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, x, y, ans; n string s; n int main() { n   cin >> n; n   cin >> s; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  U ) y++; n     if (s[i] ==  D ) y--; n     if (s[i] ==  L ) x--; n     if (s[i] ==  R ) x++; n   } n   if (y < 0) y *= (-1); n   if (x < 0) x *= (-1); n   ans = n - x - y; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, x, ans = 0; n int MUL(int u, int v) { return (int)((1LL * u * v) % (int)(1e9 + 7)); } n int main() { n   scanf( %d%d%d , &n, &m, &x); n   if (n > m) { n     cout << 0 << endl; n     return 0; n   } n   int dp[m + 10][n + 10][n + 10][2]; n   dp[m + 1][n][0][1] = 1; n   for (int i = m; i >= 1; i--) { n     for (int k = 0; k <= n; k++) { n       for (int ng = 0; ng <= n; ng++) { n         for (int pre = 0; pre <= 1; pre++) { n           int ans = 0; n           ans = (ans + dp[i + 1][k][ng + 1][pre || (i == x)]) % (int)(1e9 + 7); n           ans = (ans + dp[i + 1][k][ng][pre]) % (int)(1e9 + 7); n           ans = (ans + dp[i + 1][k + 1][ng - 1][pre]) % (int)(1e9 + 7); n           ans = (ans + dp[i + 1][k + 1][ng][pre || (i == x)]) % (int)(1e9 + 7); n           dp[i][k][ng][pre] = ans; n         } n       } n     } n   } n   int ans = dp[1][0][0][0]; n   for (int i = 1; i <= n; i++) ans = MUL(ans, i); n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int v, id; n   node(int _id) { n     id = _id; n     cin >> v; n   } n   bool operator<(const node& from) const { return v > from.v; } n }; n vector<node> Q; n bool IN[200005]; n int l[200005]; n int r[200005]; n int pt = 1, mx = 1; n void update(int x) { n   IN[x] = 1; n   if (IN[x - 1]) l[x] = l[x - 1]; n   if (IN[x + 1]) r[x] = r[x + 1]; n   r[l[x]] = r[x]; n   l[r[x]] = l[x]; n   mx = max(mx, r[x] - l[x] + 1); n } n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) Q.push_back(node(i)); n   for (int i = 1; i <= n; i++) l[i] = r[i] = i; n   sort(Q.begin(), Q.end()); n   int pt = 1; n   for (int i = 0; i < n; i++) { n     while (i < n and Q[i + 1].v == Q[i].v) update(Q[i++].id); n     update(Q[i].id); n     for (; pt <= mx; pt++) cout << Q[i].v <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n int n; n int main() { n   int i; n   long long ans, sumx, sumy, x, y; n   scanf( %d , &n); n   ans = sumx = sumy = 0; n   for (i = 0; i < n; i++) { n     scanf( %I64d%I64d , &x, &y); n     ans += (long long)x * x * n + y * y * n; n     sumx += x; n     sumy += y; n   } n   printf( %I64d , ans - sumx * sumx - sumy * sumy); n } n


#include <bits/stdc++.h> n using namespace std; n int dp[1000000], arr[1000000]; n int main() { n   int fi = 1, se = 1; n   int n; n   cin >> n; n   int last = 20; n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     arr[i] = x; n     if (i == 1) { n       cout << 20 <<   n ; n       dp[i] = 20; n       continue; n     } n     while (arr[fi] + 90 <= arr[i]) fi++; n     while (arr[se] + 1440 <= arr[i]) se++; n     dp[i] = 20 + dp[i - 1]; n     dp[i] = min(dp[i], dp[fi - 1] + 50); n     dp[i] = min(dp[i], dp[se - 1] + 120); n     cout << dp[i] - last <<   n ; n     last = dp[i]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int fr[300005], v[300005]; n int main() { n   int n, i, x, sol = 0, pos1, pos2, cate = 0; n   cin >> n; n   for (i = 1; i <= n; ++i) { n     cin >> v[i]; n     x = v[i]; n     ++fr[x]; n     if (fr[x] == 1) ++cate; n     if (cate == 1 && fr[x] == 1) pos1 = i; n     if (cate == 2 && fr[x] == 1) sol = max(sol, i - pos1), pos2 = i; n     if (cate >= 2) { n       if (v[pos1] == v[i]) n         sol = max(sol, i - pos2); n       else n         sol = max(sol, i - pos1); n     } n   } n   cout << sol <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   int t[4] = {1, 1, 2, 1}; n   getline(cin, s); n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  h  && t[0]) { n       t[0]--; n     } else if (s[i] ==  e  && t[1] && !t[0]) { n       t[1]--; n     } else if (s[i] ==  l  && !t[1] && t[2]) { n       t[2]--; n     } else if (s[i] ==  o  && !t[2] && t[3]) { n       t[3]--; n     } n   } n   if (!(t[0] + t[1] + t[2] + t[3])) { n     cout <<  YES  << endl; n   } else { n     cout <<  NO  << endl; n   } n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     int n, k; n     scanf( %d %d , &n, &k); n     int div = n / k; n     int mod = n % k; n     for (int i = 0; i < k; i++) { n       for (int j = 1; j <= div; j++) { n         printf( %c , ( a  + i)); n       } n       if (mod) { n         printf( %c , ( a  + i)); n         mod--; n       } n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n void err() { std::cout << std::endl; } n template <typename T, typename... Args> n void err(T a, Args... args) { n   std::cout << a <<    ; n   err(args...); n } n using namespace std; n const int mod = 998244353; n const int inf = 1 << 30; n const int maxn = 200000 + 5; n const int maxq = 3000 + 5; n long long qpow(long long x, long long n) { n   long long r = 1; n   while (n > 0) { n     if (n & 1) r = r * x % mod; n     n >>= 1; n     x = x * x % mod; n   } n   return r; n } n long long inv(int x) { return qpow(x, mod - 2); } n void add(long long& x, long long y) { n   x += y; n   if (x >= mod) x -= mod; n } n int n, m, a[maxn], w[maxn]; n long long f[maxq][maxq]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , a + i); n   int sa = 0, sb = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %d , w + i); n     if (a[i]) n       sa += w[i]; n     else n       sb += w[i]; n   } n   f[0][0] = 1; n   for (int i = 0; i < m; i++) { n     for (int j = 0; j <= i; j++) { n       int a = sa + j, b = sb - (i - j); n       long long fm = inv(a + b); n       add(f[i + 1][j + 1], f[i][j] * a % mod * fm % mod); n       add(f[i + 1][j], f[i][j] * b % mod * fm % mod); n     } n   } n   long long ea = 0, eb = 0; n   for (int i = 0; i <= m; i++) { n     ; n     add(ea, f[m][i] * (sa + i) % mod); n     add(eb, f[m][i] * (sb - (m - i)) % mod); n   }; n   long long iva = inv(sa), ivb = inv(sb); n   for (int i = 1; i <= n; i++) { n     if (a[i]) { n       printf( %lld n , 1ll * w[i] * iva % mod * ea % mod); n     } else { n       printf( %lld n , 1ll * w[i] * ivb % mod * eb % mod); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long double a[(1000000)], x[(1000000)]; n long double b[(1000000)], y[(1000000)]; n int n, A, B; n long double ans; n const long double inf = 3e9; n bool check(double t) { n   int k = B; n   long double cnt = inf * inf; n   for (int i = A; i > 0; i--) { n     while (k && y[k] >= x[i]) { n       cnt = min(cnt, y[k] + t * b[k]); n       k--; n     } n     if (x[i] + t * a[i] >= cnt) return true; n   } n   return false; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     double P, V; n     scanf( %lf%lf , &P, &V); n     if (V < 0.) { n       B++; n       y[B] = P; n       b[B] = V; n     } else { n       A++; n       x[A] = P; n       a[A] = V; n     } n   } n   double l = 0., r = inf; n   ans = -1; n   for (int T = 0; T < 100; T++) { n     double mid = (l + r) / 2.; n     if (check(mid)) { n       ans = mid; n       r = mid; n     } else n       l = mid; n   } n   if (ans < 0.) n     puts( -1 ); n   else { n     cout.precision(10); n     cout << fixed; n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 55; n int n, a[maxn]; n long long k; n long long f[maxn]; n int main() { n   scanf( %d %I64d , &n, &k); n   f[0] = f[1] = 1; n   for (int i = 2; i <= n; i++) f[i] = f[i - 1] + f[i - 2]; n   for (int i = 1; i <= n;) { n     if (f[n - i] >= k) { n       a[i] = i; n       i++; n     } else { n       k -= f[n - i]; n       a[i] = i + 1; n       a[i + 1] = i; n       i += 2; n     } n   } n   for (int i = 1; i <= n; i++) printf( %d  , a[i]); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, k; n     cin >> n >> k; n     if (k >= n) n       cout << abs(n - k) << endl; n     else { n       if (n % 2 == 0) { n         if (k % 2 == 1) n           cout << 1 << endl; n         else n           cout << 0 << endl; n       } else if (n % 2 == 1) { n         if (k % 2 == 0) n           cout << 1 << endl; n         else n           cout << 0 << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool marked[100000 + 2]; n vector<int> prime; n int ase[100000 + 2], num[100000 + 2]; n bool isPrime(int n) { n   if (n < 2) return false; n   if (n == 2) return true; n   if (n % 2 == 0) return false; n   return marked[n] == false; n } n void sieve(int n) { n   for (int i = 3; i * i <= n; i += 2) { n     if (marked[i] == false) { n       for (int j = i * i; j <= n; j += i + i) { n         marked[j] = true; n       } n     } n   } n   prime.push_back(2); n   for (int i = 3; i <= n; i += 2) { n     if (!marked[i]) { n       prime.push_back(i); n     } n   } n } n vector<pair<int, int> > ans; n void correct(int x) { n   if (num[x] == x) { n     return; n   } n   int j = ase[x]; n   int k = j - *(upper_bound(prime.begin(), prime.end(), j - x + 1) - 1) + 1; n   int a; n   a = num[j], num[j] = num[k], num[k] = a; n   ase[num[k]] = k, ase[num[j]] = j; n   ans.push_back(pair<int, int>(k, j)); n   correct(x); n } n int main(int argc, char** argv) { n   sieve(100000); n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &num[i]); n     ase[num[i]] = i; n   } n   getchar(); n   for (int i = 1; i <= n; i++) { n     correct(i); n   } n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); ++i) { n     cout << ans[i].first <<     << ans[i].second << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n int calc(long long a, long long n) { n   long long res = 1; n   while (n > 0) { n     if (n & 1) res = (res * a) % MOD; n     a = (a * a) % MOD; n     n /= 2; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(0); n   long long n; n   cin >> n; n   long long x = calc(2, n); n   cout << x * (x + 1) / 2 % MOD; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 2 * 1e9; n const double EPS = 1e-9; n const int MaxN = 100000 + 5; n const int MaxM = 2 * 100000 + 5; n int N, M, S, L, Dist[MaxN]; n typedef struct Node { n   int idx; n   Node(void) {} n   Node(int _idx) { idx = _idx; } n   inline bool operator<(const Node &NewNode) const { n     return Dist[idx] > Dist[NewNode.idx]; n   } n }; n typedef struct Edge { n   int idx, Weight; n   Edge(void) {} n   Edge(int _idx, int _Weight) { n     idx = _idx; n     Weight = _Weight; n   } n }; n vector<Edge> E[MaxM]; n inline void Dijkstra(int Start) { n   for (int i = 0; i < N; i++) Dist[i] = INF; n   priority_queue<Node> PQ; n   PQ.push(Node(Start)); n   Dist[Start] = 0; n   while (!PQ.empty()) { n     Node CurrNode = PQ.top(); n     PQ.pop(); n     for (vector<Edge>::iterator it = E[CurrNode.idx].begin(); n          it != E[CurrNode.idx].end(); it++) { n       Node NextNode = Node((*it).idx); n       int Weight = (*it).Weight; n       if (Dist[CurrNode.idx] + Weight < Dist[NextNode.idx]) { n         Dist[NextNode.idx] = Dist[CurrNode.idx] + Weight; n         PQ.push(NextNode); n       } n     } n   } n } n vector<pair<pair<int, int>, int> > Edges; n int main(void) { n   scanf( %d %d %d , &N, &M, &S); n   S--; n   for (int i = 0; i < M; i++) { n     int idx, idy, Weight; n     scanf( %d %d %d , &idx, &idy, &Weight); n     idx--; n     idy--; n     E[idx].push_back(Edge(idy, Weight)); n     E[idy].push_back(Edge(idx, Weight)); n     Edges.push_back(make_pair(make_pair(idx, idy), Weight)); n   } n   scanf( %d , &L); n   Dijkstra(S); n   int Sol = 0; n   for (int i = 0; i < N; i++) n     if (Dist[i] == L) Sol++; n   for (int i = 0; i < M; i++) { n     int idx = Edges[i].first.first, idy = Edges[i].first.second, n         Weight = Edges[i].second; n     int Pos1 = -1, Pos2 = -1; n     if ((Dist[idx] < L) && (L < Dist[idx] + Weight) && n         (L <= Dist[idy] + Dist[idx] + Weight - L)) n       Pos1 = L - Dist[idx]; n     if ((Dist[idy] < L) && (L < Dist[idy] + Weight) && n         (L <= Dist[idx] + Dist[idy] + Weight - L)) n       Pos2 = Dist[idy] + Weight - L; n     if (Pos1 >= 0) Sol++; n     if ((Pos2 >= 0) && (Pos2 != Pos1)) Sol++; n   } n   printf( %d n , Sol); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   set<char> s; n   char a[100005]; n   s.insert( A ); n   s.insert( H ); n   s.insert( I ); n   s.insert( M ); n   s.insert( O ); n   s.insert( T ); n   s.insert( U ); n   s.insert( V ); n   s.insert( W ); n   s.insert( X ); n   s.insert( Y ); n   scanf( %s , &a); n   int n = strlen(a); n   for (int i = 0; i < n; i++) { n     if (s.find(a[i]) == s.end() || a[i] != a[n - 1 - i]) { n       cout <<  NO ; n       return 0; n     } n   } n   cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long power(long long a, long long b) { n   long long x = 1; n   a = a % 1000000007ULL; n   while (b) { n     if (b & 1) x = (x * a) % 1000000007ULL; n     a = (a * a) % 1000000007ULL; n     b >>= 1; n   } n   return x; n } n inline long long inv(long long a) { return power(a, 1000000007ULL - 2); } n long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; } n const int N = 1e5 + 5; n string s; n vector<int> v[12]; n int n; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> s; n   n = s.size(); n   for (int i = 0; i < n; i++) { n     v[s[i] -  0 ].push_back(i); n   } n   if (n < 2) { n     cout <<  -1 n ; n     return 0; n   } n   if (n == 2) { n     if (v[0].size() > 0 && v[5].size() > 0) { n       if (s[0] ==  5 ) n         cout <<  0 n ; n       else n         cout <<  1 n ; n       return 0; n     } n     if (v[2].size() > 0 && v[5].size() > 0) { n       if (s[0] ==  2 ) n         cout <<  0 n ; n       else n         cout <<  1 n ; n       return 0; n     } n     if (v[7].size() > 0 && v[5].size() > 0) { n       if (s[0] ==  7 ) n         cout <<  0 n ; n       else n         cout <<  1 n ; n       return 0; n     } n     cout <<  -1 n ; n     return 0; n   } n   int ans = 10000; n   if (v[0].size() > 1) { n     int x = v[0].size(); n     ans = min(ans, abs(n - 1 - v[0][x - 1]) + abs(n - 2 - v[0][x - 2])); n   } n   if (v[2].size() > 0 && v[5].size() > 0) { n     int x = v[2].size(); n     int y = v[5].size(); n     x = v[2][x - 1]; n     y = v[5][y - 1]; n     if (n != 3 || v[0].size() == 0) { n       int tmp = 0; n       string sss = s; n       for (int i = y; i < n - 1; i++) { n         sss[i] = sss[i + 1]; n         tmp++; n       } n       sss[n - 1] =  5 ; n       for (int j = n - 2; j > -1; j--) { n         if (sss[j] ==  2 ) { n           x = j; n           break; n         } n       } n       for (int i = x; i < n - 2; i++) { n         sss[i] = sss[i + 1]; n         tmp++; n       } n       sss[n - 2] =  2 ; n       if (sss[0] ==  0 ) { n         for (int j = 0; j < n; j++) { n           if (sss[j] ==  0 ) tmp++; n         } n       } n       ans = min(tmp, ans); n     } n   } n   if (v[7].size() > 0 && v[5].size() > 0) { n     int x = v[7].size(); n     int y = v[5].size(); n     x = v[7][x - 1]; n     y = v[5][y - 1]; n     if (n != 3 || v[0].size() == 0) { n       int tmp = 0; n       string sss = s; n       for (int i = y; i < n - 1; i++) { n         sss[i] = sss[i + 1]; n         tmp++; n       } n       sss[n - 1] =  5 ; n       for (int j = n - 2; j > -1; j--) { n         if (sss[j] ==  7 ) { n           x = j; n           break; n         } n       } n       for (int i = x; i < n - 2; i++) { n         sss[i] = sss[i + 1]; n         tmp++; n       } n       sss[n - 2] =  7 ; n       if (sss[0] ==  0 ) { n         for (int j = 0; j < n; j++) { n           if (sss[j] ==  0 ) tmp++; n         } n       } n       ans = min(tmp, ans); n     } n   } n   if (v[5].size() > 0 && v[0].size() > 0) { n     int x = v[5].size(); n     int y = v[0].size(); n     x = v[5][x - 1]; n     y = v[0][y - 1]; n     if (n != 3 || v[0].size() == 1) { n       int tmp = 0; n       string sss = s; n       for (int i = y; i < n - 1; i++) { n         sss[i] = sss[i + 1]; n         tmp++; n       } n       sss[n - 1] =  0 ; n       for (int j = n - 2; j > -1; j--) { n         if (sss[j] ==  5 ) { n           x = j; n           break; n         } n       } n       for (int i = x; i < n - 2; i++) { n         sss[i] = sss[i + 1]; n         tmp++; n       } n       sss[n - 2] =  5 ; n       if (sss[0] ==  0 ) { n         for (int j = 0; j < n; j++) { n           if (sss[j] ==  0 ) tmp++; n         } n       } n       ans = min(tmp, ans); n     } n   } n   if (ans == 10000) { n     cout <<  -1 n ; n     return 0; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int p[400050]; n int ran[400050]; n int find_set(int a) { return p[a] == a ? a : (p[a] = find_set(p[a])); } n int unite(int a, int b) { n   int x = find_set(a); n   int y = find_set(b); n   if (x == y) return -1; n   if (ran[x] < ran[y]) { n     p[x] = y; n   } else { n     p[y] = x; n     if (ran[x] == ran[y]) ran[x]++; n   } n   return 0; n } n pair<int, pair<int, int> > ed[400050]; n int viz[200050]; n int main() { n   int n, m; n   int s, t, ds, dt; n   int di = 0, dii = 0; n   int tes = 0; n   scanf( %d %d , &n, &m); n   for (int i = 0; i < m; i++) { n     int a, b; n     scanf( %d %d , &a, &b); n     ed[i] = make_pair(0, make_pair(a, b)); n   } n   scanf( %d %d %d %d , &s, &t, &ds, &dt); n   for (int i = 0; i < m; i++) { n     if ((ed[i].second.first == s && ed[i].second.second == t) || n         (ed[i].second.second == s && ed[i].second.first == t)) { n       ed[i] = make_pair(2, make_pair(ed[i].second.first, ed[i].second.second)); n     } else if (ed[i].second.first == s || ed[i].second.second == s) { n       ed[i] = make_pair(1, make_pair(ed[i].second.first, ed[i].second.second)); n       viz[ed[i].second.first] |= 1; n       viz[ed[i].second.second] |= 1; n     } else if (ed[i].second.first == t || ed[i].second.second == t) { n       ed[i] = make_pair(1, make_pair(ed[i].second.first, ed[i].second.second)); n       viz[ed[i].second.first] |= 2; n       viz[ed[i].second.second] |= 2; n     } n   } n   sort(ed, ed + m); n   for (int i = 0; i <= n; i++) { n     p[i] = i; n     ran[i] = 1; n   } n   int i; n   for (i = 0; i < m; i++) { n     if (ed[i].first) break; n     if (find_set(ed[i].second.first) != find_set(ed[i].second.second)) { n       tes++; n       unite(ed[i].second.first, ed[i].second.second); n       ed[i] = make_pair(-1, make_pair(ed[i].second.first, ed[i].second.second)); n     } n   } n   for (int j = i; j < m; j++) { n     int q = (ed[j].second.first == s || ed[j].second.first == t) n                 ? ed[j].second.second n                 : ed[j].second.first; n     if (ed[j].first == 2) break; n     if (viz[q] == 3) continue; n     if (find_set(ed[j].second.first) != find_set(ed[j].second.second)) { n       if (ed[j].second.first == s || ed[j].second.second == s) { n         if (di == ds) continue; n         di++; n       } n       if (ed[j].second.first == t || ed[j].second.second == t) { n         if (dii == dt) continue; n         dii++; n       } n       tes++; n       unite(ed[j].second.first, ed[j].second.second); n       ed[j] = make_pair(-1, make_pair(ed[j].second.first, ed[j].second.second)); n     } n   } n   for (int j = i; j < m; j++) { n     if (find_set(ed[j].second.first) != find_set(ed[j].second.second)) { n       if (ed[j].second.first == s || ed[j].second.second == s) { n         if (di == ds) continue; n         di++; n       } n       if (ed[j].second.first == t || ed[j].second.second == t) { n         if (dii == dt) continue; n         dii++; n       } n       tes++; n       unite(ed[j].second.first, ed[j].second.second); n       ed[j] = make_pair(-1, make_pair(ed[j].second.first, ed[j].second.second)); n     } n   } n   if (tes != n - 1) { n     printf( No n ); n   } else { n     printf( Yes n ); n     for (int i = 0; i < m; i++) { n       if (ed[i].first == -1) n         printf( %d %d n , ed[i].second.first, ed[i].second.second); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long t = 1, T; n void print2d(vector<vector<long long>> &v) { n   for (long long i = 0; i < v.size(); i++) { n     for (long long x : v[i]) { n       cout << x <<    ; n     } n     cout <<   n ; n   } n } n void print(vector<long long> &a) { n   for (long long x : a) { n     cout << x <<    ; n   } n   cout <<   n ; n   return; n } n long long fun(long long x, long long y) { return x * x + y * y; } n void solve() { n   long long n; n   cin >> n; n   vector<long long> a(n, 0); n   vector<long long> freq(n + 1, 0); n   long long x; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     freq[a[i]]++; n   } n   set<long long> v; n   for (long long i = 0; i < n; i++) { n     for (long long j = i + 1; j < n; j++) { n       v.insert(a[i] + a[j]); n     } n   } n   long long ans = 0; n   for (long long sum : v) { n     long long i, j; n     if (sum & 1) { n       i = sum / 2; n       j = i + 1; n     } else n       i = j = sum / 2; n     long long rep = 0; n     while (i >= 1 && j <= n) { n       if (i == j) { n         rep += freq[i] / 2; n         i--; n         j++; n       } else { n         rep += min(freq[i], freq[j]); n         i--; n         j++; n       } n     } n     ans = max(ans, rep); n   } n   cout << ans <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> t; n   T = t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n int battle(std::string player1, std::string player2) { n   if (player1 == player2) { n     return 0; n   } n   if (player1 ==  rock ) { n     if (player2 ==  scissors ) { n       return 1; n     } else { n       return -1; n     } n   } n   if (player1 ==  paper ) { n     if (player2 ==  rock ) { n       return 1; n     } else { n       return -1; n     } n   } n   if (player1 ==  scissors ) { n     if (player2 ==  paper ) { n       return 1; n     } else { n       return -1; n     } n   } n } n int main(int argc, char const *argv[]) { n   std::string fyodor, matroskin, sharic; n   std::cin >> fyodor >> matroskin >> sharic; n   std::string winner =  ? ; n   if (battle(fyodor, matroskin) == 1) { n     if (battle(fyodor, sharic) == 1) { n       winner =  F ; n     } n   } else if (battle(fyodor, matroskin) == -1) { n     if (battle(matroskin, sharic) == 1) { n       winner =  M ; n     } n   } else { n     if (battle(sharic, fyodor) == 1) { n       winner =  S ; n     } n   } n   std::cout << winner <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n void io() {} n long long fast_exp(long long base, int exp, int m) { n   long long res = 1; n   while (exp > 0) { n     if (exp % 2 == 1) { n       res = (res * base) % m; n     } n     base = (base * base) % m; n     exp /= 2; n   } n   return res % m; n } n long long arr[200005]; n long long val[200005]; n long long siz[200005]; n map<long long, long long> mp; n long long ans, cnt, tmp; n long long vis[200005]; n vector<long long> adj[200005]; n long long dp[2001][2001]; n long long n, m, k; n int main() { n   io(); n   ios ::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t = 0; n   cin >> arr[0] >> arr[1] >> arr[2]; n   sort(arr, arr + 3); n   if (arr[2] - arr[1] - arr[0] < 0) { n     cout << 0 <<   n ; n     return 0; n   } n   cout << arr[2] - arr[1] - arr[0] + 1 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int a, b; n vector<int> undiradj[100001]; n vector<int> diradj[100001]; n vector<int> dirjda[100001]; n stack<int> s; n bool vis[100001]; n vector<int> scc[100001]; n bool isinscc[100001]; n bool hascycle; n void dfs(int node) { n   if (!vis[node]) { n     vis[node] = true; n     for (int i = 0; i < diradj[node].size(); i++) { n       dfs(diradj[node][i]); n     } n     s.push(node); n   } n } n void sfd(int node, int con) { n   if (!vis[node]) { n     vis[node] = true; n     scc[con].push_back(node); n     for (int i = 0; i < dirjda[node].size(); i++) { n       sfd(dirjda[node][i], con); n     } n   } n } n int undirdfs(int node) { n   if (!vis[node]) { n     if (isinscc[node]) hascycle = true; n     int cnt = 0; n     vis[node] = true; n     for (int i = 0; i < undiradj[node].size(); i++) { n       cnt += undirdfs(undiradj[node][i]); n     } n     cnt++; n     return cnt; n   } n   return 0; n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     cin >> a >> b; n     undiradj[a].push_back(b); n     undiradj[b].push_back(a); n     diradj[a].push_back(b); n     dirjda[b].push_back(a); n   } n   for (int i = 1; i <= n; i++) { n     vis[i] = false; n   } n   for (int i = 1; i <= n; i++) { n     if (!vis[i]) { n       dfs(i); n     } n   } n   for (int i = 1; i <= n; i++) { n     vis[i] = false; n   } n   int cc = 0; n   while (!s.empty()) { n     int curnode = s.top(); n     s.pop(); n     if (!vis[curnode]) { n       sfd(curnode, cc); n       if (scc[cc].size() > 1) { n         for (int i = 0; i < scc[cc].size(); i++) { n           isinscc[scc[cc][i]] = true; n         } n       } n       cc++; n     } n   } n   for (int i = 1; i <= n; i++) { n     vis[i] = false; n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     if (!vis[i]) { n       hascycle = false; n       int v = undirdfs(i); n       if (hascycle) n         ans += v; n       else n         ans += (v - 1); n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string s =   ; n   int r = 1; n   while (s.size() < 1050) { n     int k = r; n     string t =   ; n     while (k > 0) { n       t = char((k % 10) +  0 ) + t; n       k = k / 10; n     } n     s = s + t, r++; n   } n   cout << s[n - 1]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n; n   long int a = 0, b = 0, c = 0; n   for (int i = 0; i < n; i++) { n     cin >> k; n     a = a + k; n   } n   for (int i = 0; i < n - 1; i++) { n     cin >> k; n     b = b + k; n   } n   for (int i = 0; i < n - 2; i++) { n     cin >> k; n     c = c + k; n   } n   cout << a - b << endl << b - c; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   int n, m; n   cin >> n >> m; n   if (n == 1 || m == 1) n     cout << max(n, m); n   else if (m == 2 && n % 4) n     cout << n + 2 - (n & 1); n   else if (n == 2 && m % 4) n     cout << m + 2 - (m & 1); n   else n     cout << (n * m) - ((n * m) / 2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 998244353; n long long binpow(long long a, long long p) { n   return p ? binpow(a * a % mod, p >> 1) * (p & 1 ? a : 1) % mod : 1; n } n long long bininv(long long a) { return binpow(a, mod - 2); } n set<int> solved; n map<long long, vector<long long> > mp; n vector<vector<long long> > C; n int k, kk; n long long m, invm; n long long fact[35000]; n long long ifact[35000]; n struct FFT { n   int n; n   vector<long long> w; n   vector<long long> inv; n   void set(int _n = (1 << 14)) { n     n = _n; n     inv.resize(n); n     inv[0] = 0; n     for (int i = 1, j = 0; i < n; i++) { n       int bit = (n >> 1); n       while (bit & j) { n         j ^= bit; n         bit >>= 1; n       } n       j ^= bit; n       inv[i] = j; n     } n     w.resize(n); n     long long step = binpow(3, (mod - 1) / n); n     w[0] = 1; n     for (int i = 1; i < n; i++) { n       w[i] = w[i - 1] * step % mod; n     } n   } n   void fft(vector<long long>& a) { n     for (int i = 0; i < n; i++) { n       if (i < inv[i]) { n         swap(a[i], a[inv[i]]); n       } n     } n     for (int len = 2; len <= n; len <<= 1) { n       for (int i = 0; i < n; i += len) { n         int i1 = i, i2 = i + (len >> 1); n         int wind = 0, wstep = (n / len); n         for (; i2 < i + len; i1++, i2++, wind += wstep) { n           long long x = a[i1], y = a[i2] * w[wind] % mod; n           a[i1] = (x + y) % mod; n           a[i2] = (x - y + mod) % mod; n         } n       } n     } n   } n   void ifft(vector<long long>& a) { n     fft(a); n     reverse(a.begin() + 1, a.end()); n     long long invn = binpow(n, mod - 2); n     for (int i = 0; i < n; i++) { n       a[i] = (a[i] * invn) % mod; n     } n   } n   void do_calculation(vector<long long> a, vector<long long> b, n                       vector<long long>& to) { n     fft(a); n     fft(b); n     for (int i = 0; i < n; i++) { n       to[i] = a[i] * b[i] % mod; n     } n     ifft(to); n     for (int i = k + 1; i < n; i++) { n       to[i] = 0; n     } n   } n } fft; n void prec() { n   fact[0] = ifact[0] = 1; n   for (int i = 1; i < 35000; i++) { n     fact[i] = fact[i - 1] * i % mod; n     ifact[i] = binpow(fact[i], mod - 2); n   } n } n void calc(long long n) { n   if (solved.count(n)) return; n   if (n == 1) { n     vector<long long> tmp(k + 1, invm); n     tmp[0] = 1; n     for (int i = 0; i < k + 1; i++) { n       tmp[i] = tmp[i] * ifact[i] % mod; n     } n     while (tmp.size() < kk) { n       tmp.push_back(0); n     } n     mp[1] = tmp; n   } else if (n & 1) { n     calc(n - 1); n     mp[n] = vector<long long>(kk, 0); n     fft.do_calculation(mp[1], mp[n - 1], mp[n]); n     mp[n][0] = 1; n   } else { n     calc(n / 2); n     mp[n] = vector<long long>(kk, 0); n     fft.do_calculation(mp[n / 2], mp[n / 2], mp[n]); n     mp[n][0] = 1; n   } n   solved.insert(n); n } n void solve(int test_ind) { n   int st = clock(); n   prec(); n   long long n; n   cin >> n >> m >> k; n   kk = 1; n   while (kk < k) { n     kk <<= 1; n   } n   kk <<= 1; n   fft.set(kk); n   invm = bininv(m); n   calc(n); n   cout << mp[n][k] * fact[k] % mod << endl; n } n int main() { n   int t = 1; n   for (int i = 0; i < t; i++) { n     solve(i); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n unsigned long long dsum(unsigned long long n) { n   unsigned long long res = 0; n   while (n) { n     res += n % 10; n     n /= 10; n   } n   return res; n } n int main() { n   unsigned long long n, s; n   cin >> n >> s; n   unsigned long long dif = n - dsum(n); n   if (dif < s) n     cout << 0 << endl; n   else { n     unsigned long long l = 1, h = n; n     while (h - l > 0) { n       unsigned long long mid = l + (h - l) / 2; n       unsigned long long x = dsum(mid); n       dif = mid - x; n       if (dif < s) { n         l = mid + 1; n       } else n         h = mid; n     } n     if (n - dsum(l) >= s) l--; n     cout << n - l << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b; n   cin >> a >> b; n   int n = sqrt(a); n   if ((n * (n + 1)) <= b) n     cout <<  Vladik  << endl; n   else n     cout <<  Valera  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long _gcd(long long x, long long y) { return (!y ? x : _gcd(y, x % y)); } n long long _lcm(long long x, long long y) { return x / _gcd(x, y) * y; } n int main() { n   std::ios_base::sync_with_stdio(0); n   long long n; n   string s; n   cin >> n >> s; n   long long a = 0, b = 0, ans = 0; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  ) ) n       a++; n     else n       b++; n   } n   if (n % 2 || a != b) return cout << -1 <<   n , 0; n   a = 0, b = 0; n   int inx1 = 0, inx2 = 0; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  ( ) { n       a++; n       inx1 = i; n     } else { n       b++; n       inx2 = i; n     } n     if (a == b) { n       if (inx2 < inx1) ans += a * 2; n       a = 0; n       b = 0; n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n int main() { n   char x[101], y[101], z[101]; n   int len; n   scanf( %s%s , x, y); n   len = strlen(x); n   for (int i = 0; i < len; i++) { n     z[i] = y[i]; n   } n   int flag = 1; n   for (int i = 0; i < len; i++) { n     if (y[i] > x[i]) { n       flag = 0; n       printf( -1 n ); n       break; n     } n   } n   if (flag == 1) printf( %s , y); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline bool cmax(T &x, T y) { n   return x < y ? x = y, 1 : 0; n } n template <typename T> n inline bool cmin(T &x, T y) { n   return y < x ? x = y, 1 : 0; n } n const int _ = 2e5 + 55, __ = 5e5 + 55; n int N; n long long a[_], b[_]; n char ans[__]; n int n, cnt; n bool check() { n   for (int i(1), I(N); i <= I; ++i) n     if (b[i] <= 0) return 0; n   return 1; n } n bool up() { n   for (int i(1), I(N - 1); i <= I; ++i) n     if (b[i + 1] <= b[i]) return 0; n   return 1; n } n bool down() { n   for (int i(1), I(N - 1); i <= I; ++i) n     if (b[i] <= b[i + 1]) return 0; n   return 1; n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0); n   cin >> N; n   for (int i(1), I(N); i <= I; ++i) cin >> a[i]; n   for (int i(1), I(N); i <= I; ++i) cin >> b[i]; n   if (N == 1) return printf(a[1] == b[1] ?  SMALL n0 n  :  IMPOSSIBLE n ), 0; n   if (N == 2) { n     long long x(b[1]), y(b[2]), s(0); n     while (x && y) { n       if (y == a[1]) swap(x, y); n       if (x == a[1] && y >= a[2] && (y - a[2]) % x == 0) { n         s += (y - a[2]) / x, y = a[2]; n         break; n       } n       if (y == a[2]) swap(x, y); n       if (x == a[2] && y >= a[1] && (y - a[1]) % x == 0) { n         s += (y - a[1]) / x, y = a[1], swap(x, y); n         break; n       } n       if (x > y) swap(x, y); n       s += y / x, y %= x; n     } n     if (x != a[1] || y != a[2]) n       return printf( IMPOSSIBLE n ), 0; n     else if (s > 2e5) n       return printf( BIG n%lld n , s), 0; n   } n   while (check()) { n     int flg = 1; n     for (int i(1), I(N); i <= I; ++i) n       if (a[i] != b[i]) { n         flg = 0; n         break; n       } n     if (!flg) { n       flg = 2; n       for (int i(1), I(N); i <= I; ++i) n         if (a[i] != b[N - i + 1]) { n           flg = 0; n           break; n         } n     } n     if (flg) { n       if (flg == 2 && cnt <= 2e5) ans[++n] =  R ; n       if (cnt <= 2e5) { n         printf( SMALL n%d n , n); n         for (int i(n), I(1); i >= I; --i) putchar(ans[i]); n         putchar(  n ); n       } else n         printf( BIG n%d n , cnt); n       return 0; n     } else if (up()) { n       ++cnt; n       if (cnt <= 2e5) ans[++n] =  P ; n       for (int i(N), I(2); i >= I; --i) b[i] -= b[i - 1]; n     } else if (down()) { n       ++cnt; n       if (cnt <= 2e5) ans[++n] =  R , ans[++n] =  P ; n       reverse(b + 1, b + N + 1); n       for (int i(N), I(2); i >= I; --i) b[i] -= b[i - 1]; n     } else n       break; n   } n   printf( IMPOSSIBLE n ); n   return 0; n } n


#include <bits/stdc++.h> n template <typename T> n class IntegerIterator n     : public std::iterator<std::input_iterator_tag, T, std::ptrdiff_t, T*, T> { n  public: n   explicit IntegerIterator(int value) : value(value) {} n   IntegerIterator& operator++() { n     ++value; n     return *this; n   } n   IntegerIterator operator++(int) { n     IntegerIterator copy = *this; n     ++value; n     return copy; n   } n   IntegerIterator& operator--() { n     --value; n     return *this; n   } n   IntegerIterator operator--(int) { n     IntegerIterator copy = *this; n     --value; n     return copy; n   } n   T operator*() const { return value; } n   bool operator==(IntegerIterator rhs) { return value == rhs.value; } n   bool operator!=(IntegerIterator rhs) { return !(*this == rhs); } n  n  private: n   T value; n }; n template <typename T> n class IntegerRange { n  public: n   IntegerRange(T begin, T end) : begin_(begin), end_(end) {} n   IntegerIterator<T> begin() const { return IntegerIterator<T>(begin_); } n   IntegerIterator<T> end() const { return IntegerIterator<T>(end_); } n  n  private: n   T begin_; n   T end_; n }; n template <typename T> n class ReversedIntegerRange { n  public: n   ReversedIntegerRange(T begin, T end) : begin_(begin), end_(end) {} n   std::reverse_iterator<IntegerIterator<T>> begin() const { n     return std::reverse_iterator<IntegerIterator<T>>( n         IntegerIterator<T>(begin_)); n   } n   std::reverse_iterator<IntegerIterator<T>> end() const { n     return std::reverse_iterator<IntegerIterator<T>>(IntegerIterator<T>(end_)); n   } n  n  private: n   T begin_; n   T end_; n }; n template <typename T> n IntegerRange<T> range(T to) { n   ; n   return IntegerRange<T>(0, to); n } n template <typename T> n IntegerRange<T> range(T from, T to) { n   ; n   return IntegerRange<T>(from, to); n } n template <typename T> n IntegerRange<T> inclusiveRange(T to) { n   ; n   return IntegerRange<T>(0, to + 1); n } n template <typename T> n IntegerRange<T> inclusiveRange(T from, T to) { n   ; n   return IntegerRange<T>(from, to + 1); n } n template <typename T> n ReversedIntegerRange<T> downrange(T from) { n   ; n   return ReversedIntegerRange<T>(from, 0); n } n template <typename T> n ReversedIntegerRange<T> downrange(T from, T to) { n   ; n   return ReversedIntegerRange<T>(from, to); n } n template <typename T> n ReversedIntegerRange<T> inclusiveDownrange(T from) { n   ; n   return ReversedIntegerRange<T>(from + 1, 0); n } n template <typename T> n ReversedIntegerRange<T> inclusiveDownrange(T from, T to) { n   ; n   return ReversedIntegerRange<T>(from + 1, to); n } n template <typename R> n void sort(R& range) { n   std::sort(range.begin(), range.end()); n } n template <typename R, typename Comp> n void sort(R& range, Comp comp) { n   std::sort(range.begin(), range.end(), comp); n } n template <typename R> n void reverse(R& range) { n   std::reverse(range.begin(), range.end()); n } n template <typename R, typename T> n auto lower_bound(const R& range, const T& value) -> decltype(range.begin()) { n   return std::lower_bound(range.begin(), range.end(), value); n } n template <typename R, typename T, typename Comp> n auto lower_bound(const R& range, const T& value, Comp comp) n     -> decltype(range.begin()) { n   return std::lower_bound(range.begin(), range.end(), value, comp); n } n template <typename R, typename T> n auto upper_bound(const R& range, const T& value) -> decltype(range.begin()) { n   return std::upper_bound(range.begin(), range.end(), value); n } n template <typename R, typename T, typename Comp> n auto upper_bound(const R& range, const T& value, Comp comp) n     -> decltype(range.begin()) { n   return std::upper_bound(range.begin(), range.end(), value, comp); n } n template <typename R> n auto min_element(const R& range) -> decltype(range.begin()) { n   return std::min_element(range.begin(), range.end()); n } n template <typename R> n auto max_element(const R& range) -> decltype(range.begin()) { n   return std::max_element(range.begin(), range.end()); n } n template <typename R> n bool next_permutation(R& range) { n   return std::next_permutation(range.begin(), range.end()); n } n template <typename T> n void unique(std::vector<T>& range) { n   range.erase(std::unique(range.begin(), range.end()), range.end()); n } n template <typename R> n R sorted(R range) { n   sort(range); n   return range; n } n template <typename R, typename Comp> n R sorted(R range, Comp comp) { n   sort(range, comp); n   return range; n } n template <typename R> n R reversed(R range) { n   reverse(range); n   return range; n } n template <typename T> n T gcd(T a, T b) { n   while (b) { n     T tmp = a % b; n     a = b; n     b = tmp; n   } n   return a; n } n using namespace std; n class TaskC { n  public: n   void solve(std::istream& in, std::ostream& out) { n     int n; n     in >> n; n     vector<int> v(n); n     for (int i : range(26)) { n       in >> v[i]; n     } n     auto x = solve(v); n     out << x.first <<   n  << x.second; n   } n   pair<int, string> solve(vector<int> v) { n     int cntOdd = 0; n     char odd; n     for (int i : range(v.size())) { n       if (v[i] % 2 == 1) { n         ++cntOdd; n         odd =  a  + i; n       } n     } n     if (cntOdd > 1) { n       return {0, go(v)}; n     } n     if (cntOdd == 1) { n       int g = 0; n       for (int i : range(v.size())) { n         g = gcd(g, v[i]); n       } n       auto r = go(v, 2 * g); n       r = r + odd + reversed(r); n       string res; n       for (int i = 0; i < g; ++i) { n         res += r; n       } n       return {g, res}; n     } n     int g = 0; n     for (int i : range(v.size())) { n       g = gcd(g, v[i]); n     } n     assert(g % 2 == 0); n     string r = go(v, g); n     r = r + reversed(r); n     string res; n     for (int i = 0; i < g / 2; ++i) { n       res += r; n     } n     return {g, res}; n   } n   string go(vector<int> v, int del = 1) { n     string res; n     for (int i : range(v.size())) { n       res += string(v[i] / del, char( a  + i)); n     } n     return res; n   } n }; n int main() { n   std::ios_base::sync_with_stdio(false); n   TaskC solver; n   std::istream& in(std::cin); n   std::ostream& out(std::cout); n   in.tie(0); n   out << std::fixed; n   out.precision(20); n   solver.solve(in, out); n   return 0; n } n


#include <iostream> n #include <cstdio> n  n using namespace std; n  n #define MAXN 200005 n  n int t, n; n int a[MAXN]; n int pre[MAXN], suf[MAXN]; n bool pre_ok[MAXN], suf_ok[MAXN]; n bool ans; n int main() n { n     //freopen( CF#696D.in ,  r , stdin); n     scanf( %d , &t); n     while(t --) n     { n         ans = true; n         scanf( %d , &n); n         pre_ok[0] = suf_ok[n + 1] = true; n         suf[n + 1] = 0; n         for(int i = 1;i <= n;i ++) scanf( %d , a + i); n  n         for(int i = 1;i < n;i ++) n         { n             pre[i] = a[i] - pre[i - 1]; n             pre_ok[i] = pre_ok[i - 1]; n             if(pre[i] < 0) { n                 pre[i] = 0; n                 pre_ok[i] = ans = false; n             } n         } n         if(a[n] != pre[n - 1]) pre_ok[n] = ans = false; n         for(int i = n;i > 1;i --) n         { n             suf[i] = a[i] - suf[i + 1]; n             suf_ok[i] = suf_ok[i + 1]; n             if(suf[i] < 0) { n                 suf[i] = 0; n                 suf_ok[i] = ans = false; n             } n         } n         if(a[1] != suf[2]) suf_ok[1] = ans = false; n         for(int i = 1;i < n;i ++) n         { n             if(pre_ok[i - 1] && suf_ok[i + 2] && a[i + 1] - pre[i - 1] >= 0 && a[i] - suf[i + 2] == a[i + 1] - pre[i - 1]) ans = true; n         } n         if(ans) printf( YES n ); n         else printf( NO n ); n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int c, v, m, l, a, i = 1, x; n   cin >> c >> v >> m >> a >> l; n   x = v; n   while (x < c) x += min(v + i * a - l, m - l), i++; n   cout << i << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1005; n int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}; n int dy[] = {0, 0, 1, -1, 1, -1, 1, -1}; n string toBinary(int x) { n   string ret =   ; n   while (x) { n     ret = (x & 1 ?  1  :  0 ) + ret; n     x >>= 1; n   } n   while (((int)(ret).size()) < 8) { n     ret =  0  + ret; n   } n   return ret; n } n int toDec(string x) { n   int ret = 0, val = 1; n   for (int i = 7; i >= 0; --i) { n     if (x[i] ==  1 ) ret += val; n     val <<= 1; n   } n   return ret; n } n string second; n vector<int> s1; n int main() { n   getline(cin, second); n   s1.push_back(0); n   for (int i = 0; i < (((int)(second).size()) - 1); ++i) { n     string temp = toBinary(second[i]); n     reverse(temp.begin(), temp.end()); n     s1.push_back(toDec(temp)); n   } n   for (int i = 0; i < (((int)(second).size())); ++i) { n     string temp = toBinary(second[i]); n     reverse(temp.begin(), temp.end()); n     int res = toDec(temp); n     printf( %d n , (s1[i] - res + 256) & 255); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5010; n int dp[maxn][maxn], sa[maxn], sb[maxn]; n char a[maxn], b[maxn]; n void gao(char *p, char *q, int n, int m) { n   memset(dp, 0, sizeof(dp)); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) n       if (p[i] == q[j]) dp[i][j] = max(dp[i - 1][j - 1] + 1, dp[i][j]); n } n int main() { n   scanf( %s%s , a + 1, b + 1); n   int n = strlen(a + 1), m = strlen(b + 1); n   gao(a, a, n, n); n   for (int i = 1; i <= n; ++i) sa[i] = 1; n   for (int i = 1; i <= m; ++i) sb[i] = 1; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) n       if (i != j) sa[i] = max(sa[i], dp[i][j] + 1); n   gao(b, b, m, m); n   for (int i = 1; i <= m; ++i) n     for (int j = 1; j <= m; ++j) n       if (i != j) sb[i] = max(sb[i], dp[i][j] + 1); n   gao(a, b, n, m); n   int ans = -1; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) n       if (dp[i][j] >= sa[i] && dp[i][j] >= sb[j]) n         if (max(sa[i], sb[j]) != 0 && (ans < 0 || ans > max(sa[i], sb[j]))) n           ans = max(sa[i], sb[j]); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, V[171]; n void cauta(int p) { n   vector<pair<int, int> > Queries; n   int res, st = 2, dr = n; n   for (int m = dr; m >= st; --m) { n     cout <<  ?  ; n     for (int i = 1; i <= n; ++i) { n       if (i != p) n         cout <<  1  ; n       else n         cout << n - m + 2 <<    ; n     } n     cout <<   n ; n     cout.flush(); n     cin >> res; n     if (res == 0) { n       V[p] = m; n     } else { n       if (V[res]) { n         V[p] = V[res] - 1 + m - n; n       } else if (res != p) n         Queries.push_back({res, n - m + 1}); n     } n   } n   if (!V[p]) V[p] = 1; n   for (auto it : Queries) V[it.first] = it.second + V[p]; n } n int gaseste(int dif) { n   cout <<  ?  ; n   for (int i = 1; i < n; ++i) { n     if (dif > 0) n       cout <<  1  ; n     else n       cout << -dif + 1 <<    ; n   } n   if (dif > 0) n     cout << dif + 1 <<   n ; n   else n     cout <<  1 n ; n   cout.flush(); n   int rep = 0; n   cin >> rep; n   return rep; n } n void solve() { n   cin >> n; n   int v, st = 0, dr = 0; n   for (int i = -n + 1; i < n; ++i) { n     if (!i) continue; n     v = gaseste(i); n     V[v] = i; n     if (!v) { n       if (i > 0 && !dr) dr = i; n     } n     if (v && i < 0 && !st) st = -i; n   } n   V[n] = st + 1; n   for (int i = 1; i < n; ++i) V[i] += V[n]; n   cout <<  !  ; n   for (int i = 1; i <= n; ++i) { n     cout << V[i] <<    ; n     V[i] = 0; n   } n   cout <<   n ; n   cout.flush(); n } n int main() { n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   int te = 1; n   while (te--) solve(); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5e3 + 7; n const int maxa = 1e5 + 7; n int dp[maxn][maxn]; n int num[maxn], n; n int get_ans() { n   memset(dp, 0, sizeof(dp)); n   int max_mod[7], max_num[maxa]; n   memset(max_mod, 0, sizeof(max_mod)); n   memset(max_num, 0, sizeof(max_num)); n   int ans = 0; n   for (int i = 0; i <= n; ++i) { n     for (int j = 0; j <= n; ++j) { n       if (i == j) continue; n       if (j < i) { n         dp[i][j] = dp[j][i]; n         max_mod[num[j] % 7] = max(max_mod[num[j] % 7], dp[i][j]); n         if (j != 0) max_num[num[j]] = max(max_num[num[j]], dp[i][j]); n       } else { n         dp[i][j] = dp[i][0] + 1; n         dp[i][j] = max(max_mod[num[j] % 7] + 1, dp[i][j]); n         dp[i][j] = max(max_num[num[j] + 1] + 1, dp[i][j]); n         dp[i][j] = max(max_num[num[j] - 1] + 1, dp[i][j]); n         max_mod[num[j] % 7] = max(max_mod[num[j] % 7], dp[i][j]); n         max_num[num[j]] = max(max_num[num[j]], dp[i][j]); n       } n       if (i != 0 && j != 0) ans = max(ans, dp[i][j]); n     } n     memset(max_mod, 0, sizeof(max_mod)); n     for (int j = 1; j <= n; ++j) { n       max_num[num[j]] = 0; n     } n   } n   return ans; n } n int main() { n   while (cin >> n) { n     for (int i = 1; i <= n; ++i) { n       scanf( %d , num + i); n     } n     int ans = get_ans(); n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(fast - math) n using namespace std; n long long powmod(long long a, long long b, long long mod) { n   if (b == 0 || a == 1) { n     if (mod == 1) n       return 0; n     else n       return 1; n   } n   if (b % 2 == 0) { n     long long k = powmod(a, b / 2, mod); n     return (k * k) % mod; n   } else { n     long long k = powmod(a, b / 2, mod); n     return ((k * k) % mod * a) % mod; n   } n } n long long gcd(long long a, long long b) { n   if (a == 0) return b; n   if (b == 0) return a; n   if (a > b) n     return gcd(a % b, b); n   else n     return gcd(b % a, a); n } n int prime(int p) { n   for (int i = 2; i * i <= p; i++) { n     if (p % i == 0 && i < p) return i; n   } n   return 1; n } n long long sqr(long long i) { return i * i; } n void r(long long &a) { cin >> a; } n void r(long double &a) { cin >> a; } n void r(long long &a, long long &b) { cin >> a >> b; } n void r(long double &a, long double &b) { cin >> a >> b; } n void r(long long &a, long long &b, long long &c) { cin >> a >> b >> c; } n void r(long double &a, long double &b, long double &c) { cin >> a >> b >> c; } n void r(long long &a, long long &b, long long &c, long long &d) { n   cin >> a >> b >> c >> d; n } n void r(long double &a, long double &b, long double &c, long double &d) { n   cin >> a >> b >> c >> d; n } n void r(long long &a, long long &b, long long &c, long long &d, long long &e) { n   cin >> a >> b >> c >> d >> e; n } n void r(long double &a, long double &b, long double &c, long double &d, n        long double &e) { n   cin >> a >> b >> c >> d >> e; n } n void r(long long &a, long long &b, long long &c, long long &d, long long &e, n        long long &f) { n   cin >> a >> b >> c >> d >> e >> f; n } n void r(long double &a, long double &b, long double &c, long double &d, n        long double &e, long double &f) { n   cin >> a >> b >> c >> d >> e >> f; n } n void r(vector<long long> &a) { n   for (long long i = 0; i < a.size(); i++) r(a[i]); n } n void r(vector<vector<long long>> &a) { n   for (long long i = 0; i < a.size(); i++) r(a[i]); n } n void w(long long a) { cout << a <<   n ; } n void w(int a) { cout << a <<   n ; } n void w(long double a) { cout << a <<   n ; } n void w(char a) { cout << a; } n void w(long long a, long long b) { cout << a <<     << b <<   n ; } n void w(long double a, long double b) { cout << a <<     << b <<   n ; } n void w(long long a, long long b, long long c) { n   cout << a <<     << b <<     << c <<   n ; n } n void w(long double a, long double b, long double c) { n   cout << a <<     << b <<     << c <<   n ; n } n void w(long long a, long long b, long long c, long long d) { n   cout << a <<     << b <<     << c <<     << d <<   n ; n } n void w(long double a, long double b, long double c, long double d) { n   cout << a <<     << b <<     << c <<     << d <<   n ; n } n void w(vector<long long> a) { n   for (long long i = 0; i < a.size(); i++) cout << a[i] <<    ; n   cout <<   n ; n } n void w(vector<vector<long long>> a) { n   for (long long i = 0; i < a.size(); i++) w(a[i]); n   cout <<   n ; n } n void r(pair<long long, long long> &a) { cin >> a.first >> a.second; } n void w(pair<long long, long long> a) { n   cout << a.first <<     << a.second <<   n ; n } n void r(vector<pair<long long, long long>> &a) { n   for (long long i = 0; i < a.size(); i++) r(a[i]); n } n void w(vector<pair<long long, long long>> a) { n   for (long long i = 0; i < a.size(); i++) w(a[i]); n   cout <<   n ; n } n void r(string &a) { cin >> a; } n void r(char &a) { cin >> a; } n void w(string a) { cout << a <<   n ; } n void sort(vector<long long> &a) { sort(a.begin(), a.end()); } n void sort(vector<pair<long long, long long>> &a) { sort(a.begin(), a.end()); } n void rev(vector<long long> &a) { reverse(a.begin(), a.end()); } n void rev(vector<pair<long long, long long>> &a) { reverse(a.begin(), a.end()); } n void rev(string &a) { reverse(a.begin(), a.end()); } n long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n void solve(int ppppppppp = 1) { n   long long n, k; n   r(n, k); n   long long pow1 = 1; n   for (long long i = 0; i < k; i++) pow1 *= 10; n   w(lcm(pow1, n)); n   return; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int tututu; n   tututu = 1; n   for (long long qwerty = 0; qwerty < tututu; qwerty++) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n const int INF = 1000000000; n const int MOD = 1073741824; n const int M = INF; n const double RRR = 180.0 / PI; n vector<vector<pair<int, int> > > g; n vector<int> used; n void dfs(int v, int l, int r) { n   used[v] = 1; n   for (int i = 0; i < g[v].size(); i++) { n     if (g[v][i].second >= l && g[v][i].second <= r) { n       continue; n     } n     int to = g[v][i].first; n     if (!used[to]) { n       dfs(to, l, r); n     } n   } n } n int main() { n   double TIME_START = clock(); n   int n, m; n   cin >> n >> m; n   used.resize(n); n   g.resize(n); n   int a, b; n   for (int i = 0; i < m; i++) { n     cin >> a >> b; n     a--; n     b--; n     g[a].push_back(make_pair(b, i)); n     g[b].push_back(make_pair(a, i)); n   } n   int k; n   cin >> k; n   int l, r; n   for (int i = 0; i < k; i++) { n     cin >> l >> r; n     l--; n     r--; n     int col = 0; n     used.assign(n, 0); n     for (int i = 0; i < n; i++) { n       if (!used[i]) { n         col++; n         dfs(i, l, r); n       } n     } n     cout << col << endl; n   } n   fprintf(stderr,   n n%.15lf n n , n           (double)(clock() - TIME_START) / CLOCKS_PER_SEC); n   return 0; n } n


#include <bits/stdc++.h> n #pragma g++ opitmize(3) n #pragma g++ opitmize(2) n #pragma g++ opitmize( fast ) n #pragma g++ opitmize( inline ) n using namespace std; n int n, m, head[400010], k = -1, vis[400010], h[400010], tot = 1; n long long a[400010], f[400010], f1; n struct node { n   int to, nt, fg; n } edge[1000010]; n inline void add(int u, int v, int fg) { n   edge[++k].nt = head[u]; n   head[u] = k; n   edge[k].to = v; n   edge[k].fg = fg; n } n inline long long fr_dfs(int u, int fa) { n   long long tmp = 0, t = 0; n   vis[u] = 1; n   for (register int i = head[u]; ~i; i = edge[i].nt) { n     int v = edge[i].to; n     if (v == fa) continue; n     if (vis[v]) continue; n     tmp = fr_dfs(v, u); n     t += tmp; n     f[(i / 2) + 1] += tmp * edge[i ^ 1].fg; n   } n   if (a[u] < 0) { n     long long hhd = a[u]; n     a[u] = 0; n     return t + hhd; n   } n   return t; n } n inline void sc_dfs(int u, int fa, long long &flow) { n   if (a[u] > 0) { n     flow += a[u]; n     a[u] = 0; n   } n   vis[u] = 1; n   for (register int i = head[u]; ~i; i = edge[i].nt) { n     int v = edge[i].to; n     if (v == fa || vis[v]) continue; n     f[(i / 2) + 1] += (flow * edge[i].fg); n     sc_dfs(v, u, flow); n     f[(i / 2) + 1] += (flow * edge[i ^ 1].fg); n   } n } n int main() { n   memset(head, -1, sizeof(head)); n   scanf( %d , &n); n   for (register int i = 1; i <= n; i++) scanf( %lld , &a[i]), f1 += a[i]; n   int u, v; n   scanf( %d , &m); n   for (register int i = 1; i <= m; i++) { n     scanf( %d%d , &u, &v); n     add(u, v, -1); n     add(v, u, 1); n   } n   if (f1 != 0) { n     printf( Impossible n ); n     return 0; n   } n   memset(vis, 0, sizeof(vis)); n   a[1] += fr_dfs(1, 0); n   h[1] = 1; n   for (register int i = 1; i <= n; i++) { n     if (!vis[i]) { n       a[i] += fr_dfs(i, 0); n       h[++tot] = i; n     } n   } n   memset(vis, 0, sizeof(vis)); n   for (register int i = 1; i <= tot; i++) { n     sc_dfs(h[i], 0, a[h[i]]); n   } n   for (register int i = 1; i <= n; i++) { n     if (a[i]) { n       printf( Impossible n ); n       return 0; n     } n   } n   printf( Possible n ); n   for (register int i = 1; i <= m; i++) printf( %lld n , f[i]); n   return 0; n } n


#include <bits/stdc++.h> n int a[5][100005]; n int b[100005][5]; n int main() { n   int n, m; n   std::cin >> n >> m; n   if (n == 1 && m == 1) n     std::cout <<  YES n1 n ; n   else if (n == 3 && m == 3) { n     std::cout <<  YES n ; n     std::cout <<  5 1 9 n7 6 4 n2 8 3 n ; n   } else if (std::max(n, m) <= 3) { n     std::cout <<  NO n ; n   } else if (m == 4 || n == 4) { n     std::cout <<  YES n ; n     if (m == 4) { n       for (int i = 0; i < n; i++) { n         if (i % 2 == 1) { n           std::cout << i * 4 + 2 <<     << i * 4 + 4 <<     << i * 4 + 1 <<     n                     << i * 4 + 3 <<   n ; n         } else { n           std::cout << i * 4 + 3 <<     << i * 4 + 1 <<     << i * 4 + 4 <<     n                     << i * 4 + 2 <<   n ; n         } n       } n     } else if (n == 4) { n       for (int j = 1; j <= m; j++) { n         if (j % 2 == 1) { n           a[3][j] = j + 2 * m; n           a[2][j] = j; n           a[1][j] = j + 3 * m; n           a[0][j] = j + m; n         } else { n           a[0][j] = j + 2 * m; n           a[1][j] = j; n           a[2][j] = j + 3 * m; n           a[3][j] = j + m; n         } n       } n       for (int i = 0; i < n; i++) { n         for (int j = 1; j <= m; j++) { n           std::cout << a[i][j] <<    ; n         } n         std::cout <<   n ; n       } n     } n   } else { n     std::cout <<  YES n ; n     if (m > 4) { n       for (int i = 0; i < n; i++) { n         int offset = i * m; n         if (i % 2 == 0) { n           for (int j = 1; j < std::ceil(m / 2.0); j++) { n             std::cout << offset + j <<     << offset + j + std::ceil(m / 2.0) n                       <<    ; n           } n           if (m % 2 == 0) n             std::cout << offset + std::ceil(m / 2.0) <<     << offset + m n                       <<   n ; n           else n             std::cout << offset + std::ceil(m / 2.0) <<   n ; n         } else { n           for (int j = 1; j < std::ceil(m / 2.0); j++) { n             std::cout << offset + j + (m / 2) <<     << offset + j <<    ; n           } n           if (m % 2 == 0) n             std::cout << offset + m <<     << offset + std::ceil(m / 2.0) n                       <<   n ; n           else n             std::cout << offset + m <<   n ; n         } n       } n     } else { n       for (int j = 0; j < m; j++) { n         int offset = j; n         if (j % 2 == 0) { n           for (int i = 0; i < std::ceil(n / 2.0); i++) { n             b[2 * i][j] = offset + 1 + i * m; n             b[2 * i + 1][j] = offset + 1 + i * m + std::ceil(n / 2.0) * m; n           } n         } else { n           for (int i = 0; i < std::ceil(n / 2.0); i++) { n             b[2 * i][j] = offset + 1 + i * m + (n / 2) * m; n             b[2 * i + 1][j] = offset + 1 + i * m; n           } n         } n       } n       for (int i = 0; i < n; i++) { n         for (int j = 0; j < m; j++) { n           std::cout << b[i][j] <<    ; n         } n         std::cout <<   n ; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e6 + 5; n int n, k; n int v[MAXN], c[MAXN], a[MAXN]; n double f[MAXN]; n int rv[MAXN][20], rc[MAXN][20]; n inline int GetV(int l, int r) { n   int x = log2(r - l + 1); n   return max(rv[l][x], rv[r + 1 - (1 << x)][x]); n } n inline int GetC(int l, int r) { n   int x = log2(r - l + 1); n   return min(rc[l][x], rc[r + 1 - (1 << x)][x]); n } n inline int Cal(int pos) { n   if (100 * v[pos] > c[pos]) return c[pos]; n   int left = pos, right = n, t; n   while (left <= right) { n     int mid = (left + right) >> 1; n     if (GetV(pos, mid) * 100 <= GetC(pos, mid)) { n       t = mid; n       left = mid + 1; n     } else n       right = mid - 1; n   } n   int ans = GetV(pos, t) * 100; n   if (t < n) ans = max(ans, GetC(pos, t + 1)); n   return ans; n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; ++i) scanf( %d , &v[i]); n   for (int i = 1; i <= n; ++i) scanf( %d , &c[i]); n   for (int i = 1; i <= n; ++i) rv[i][0] = v[i], rc[i][0] = c[i]; n   int lgn = log2(n); n   for (int j = 1; j <= lgn; ++j) { n     int last = n + 1 - (1 << j); n     for (int i = 1; i <= last; ++i) { n       rv[i][j] = max(rv[i][j - 1], rv[i + (1 << (j - 1))][j - 1]); n       rc[i][j] = min(rc[i][j - 1], rc[i + (1 << (j - 1))][j - 1]); n     } n   } n   for (int i = 1; i <= n; ++i) a[i] = Cal(i); n   f[0] = 1.0 * k / (n - k + 1); n   for (int i = 1; i <= n - k + 1; ++i) n     f[i] = f[i - 1] * (n - i - k + 2) / (n - i + 1); n   sort(a + 1, a + n + 1); n   double ans = 0; n   for (int i = 1; i <= n - k + 1; ++i) ans += a[i] * f[i]; n   cout << fixed << setprecision(9) << ans << endl; n   return 0; n } n