// n //  main.cpp n //  D - Epic Transformation n // n //  Created by LiZnB on 2021/3/25. n // n #include <cstdio> n #include <cstring> n #include <algorithm> n  n #define ls tree[pos].l n #define rs tree[pos].r n using namespace std; n  n const int INF = 0x3f3f3f3f; n const int N = 200000 + 10; n  n int arr[N]; n  n struct Node { n     int l, r; n     long long val; n     int real; n }; n  n Node max(Node a, Node b) { n     if (a.val > b.val) return a; n     return b; n } n  n struct Tree { n     Node tree[N * 4]; n      n     void Built(int L, int R, int pos) { n         ls = L; n         rs = R; n         if (L == R) { n             tree[pos].val = arr[L]; n             tree[pos].real = L; n             return; n         } n         int m = L + (R - L) / 2; n         Built(L, m, pos << 1); n         Built(m + 1, R, pos << 1 | 1); n         if (tree[pos << 1].val > tree[pos << 1 | 1].val) { n             tree[pos].val = tree[pos << 1].val; n             tree[pos].real = tree[pos << 1].real; n         } else { n             tree[pos].val  = tree[pos << 1 | 1].val; n             tree[pos].real = tree[pos << 1 | 1].real; n         } n     } n      n     void Modify(int pos, int p, long long val) { n         if (rs == p && ls == p) { n             tree[pos].val += val; n             return; n         } n         int m = ls + (rs - ls) / 2; n         if (p <= m) Modify(pos << 1, p, val); n         if (p > m) Modify(pos << 1 | 1, p, val); n         if (tree[pos << 1].val > tree[pos << 1 | 1].val) { n             tree[pos].val = tree[pos << 1].val; n             tree[pos].real = tree[pos << 1].real; n         } else { n             tree[pos].val  = tree[pos << 1 | 1].val; n             tree[pos].real = tree[pos << 1 | 1].real; n         } n  n     } n      n     Node Query(int pos, int L, int R) { n         if (ls >= L && rs <= R) { n             return tree[pos]; n         }; n         int m = ls + (rs - ls) / 2; n         Node ans; n         ans.val = -INF; n         if (m >= L) { n             ans = max(Query(pos << 1, L, R), ans); n         } n         if (m < R) { n             ans = max(Query(pos << 1 | 1, L, R), ans); n         } n         if (tree[pos << 1].val > tree[pos << 1 | 1].val) { n             tree[pos].val = tree[pos << 1].val; n             tree[pos].real = tree[pos << 1].real; n         } else { n             tree[pos].val  = tree[pos << 1 | 1].val; n             tree[pos].real = tree[pos << 1 | 1].real; n         } n  n         return ans; n     } n      n } T; n int d[N]; n int main() { n     int t; n     scanf( %d , &t); n     while (t--) { n         int n; n         scanf( %d , &n); n         for (int i = 1; i <= n; i++) { n             scanf( %d , &d[i]); n         } n         sort(d + 1, d + n + 1); n         int p = 1; n         arr[1] = 1; n         for (int i = 2; i <= n; i++) { n             if (d[i - 1] != d[i]) { n                 p++; n                 arr[p] = 1; n             } n             else { n                 arr[p]++; n             } n         } n         T.Built(1, p, 1); n         int ans = n; n         for (int i = 1; i <= n; i++) { n             Node f1 = T.Query(1, 1, p); n             T.Modify(1, f1.real, -f1.val); n             Node f2 = T.Query(1, 1, p); n             T.Modify(1, f1.real, f1.val); n              n             if (f1.val == 0 || f2.val == 0) break; n             T.Modify(1, f1.real, -1); n             T.Modify(1, f2.real, -1); n             ans -= 2; n         } n         printf( %d n , ans); n     } n      n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, type[100001], a[100001], lead[100001], cur[100001]; n bool vs[100001]; n void input() { n   scanf( %d , &n); n   for (int i = 1, _b = n; i <= _b; i++) scanf( %d , &type[i]); n   int x; n   memset(lead, 0, sizeof(lead)); n   memset(a, 0, sizeof(a)); n   for (int i = 1, _b = n; i <= _b; i++) { n     scanf( %d , &x); n     a[x] = i; n     lead[x]++; n   } n } n void dfs(int i) { n   vs[i] = true; n   if (type[i]) { n     cur[i] = 1; n     return; n   } n   if (lead[a[i]] != 1 && !type[a[i]]) return; n   if (!vs[a[i]]) dfs(a[i]); n   if (cur[a[i]]) cur[i] = cur[a[i]] + 1; n } n void process() { n   memset(vs, false, sizeof(vs)); n   memset(cur, 0, sizeof(cur)); n   for (int i = 0, _b = n; i <= _b; i++) n     if (lead[i] != 1 && !type[i]) vs[i] = true; n   for (int i = 1, _b = n; i <= _b; i++) { n     if (!vs[i]) dfs(i); n   } n   int ans = 0; n   int st = 0; n   for (int i = 1, _b = n; i <= _b; i++) { n     if (ans < cur[i]) { n       ans = cur[i]; n       st = i; n     } n   } n   cout << ans << endl; n   while (!type[st]) { n     printf( %d  , st); n     st = a[st]; n   } n   cout << st; n } n int main() { n   input(); n   process(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct stra { n   int x, y, z; n } arr[100000]; n bool cmp(stra a, stra b) { return a.x > b.x; } n bool cmp1(stra a, stra b) { return a.y < b.y; } n int n, k = 1, g = 1; n int main() { n   std::ios::sync_with_stdio(false); n   cin >> n; n   for (int i = 0; i <= n - 1; i++) { n     cin >> arr[i].x; n     arr[i].y = i; n   } n   sort(arr, arr + n, cmp); n   arr[0].z = 1; n   for (int i = 1; i <= n - 1; i++) { n     if (arr[i - 1].x != arr[i].x) { n       k = i + 1; n       arr[i].z = k; n     } else { n       arr[i].z = k; n     } n   } n   sort(arr, arr + n, cmp1); n   for (int i = 0; i <= n - 1; i++) { n     cout << arr[i].z <<    ; n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n const long long N = 1e6 + 10; n const long double eps = 1e-9; n const long long inf = 1e18; n long long a[N], b[N], c[N], d[N]; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, k; n   long long m; n   cin >> n >> m >> k; n   long long a[m]; n   for (long long i = 0; i < m; ++i) cin >> a[i]; n   long long s = 0, i = 0, j = 0, k1 = k; n   while (j < m) { n     while (a[j] <= k1 + i) j++; n     if (i == j) { n       s--; n       k1 = ((a[j] - i) / k) * k; n       if ((a[j] - i) % k) k1 += k; n     } n     i = j; n     s++; n   } n   cout << s; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double b[10], a[10], c[10] = {500, 1000, 1500, 2000, 2500}; n double Max(double x, double y) { return x > y ? x : y; } n int main() { n   int n, m1, m2, m3, m4, m5, i, j, k; n   while (~scanf( %lf , &a[0])) { n     for (i = 1; i < 5; i++) scanf( %lf , &a[i]); n     for (i = 0; i < 5; i++) scanf( %lf , &b[i]); n     double ans = 0; n     for (i = 0; i < 5; i++) { n       ans += n           Max(0.3 * c[i], (1 - (a[i] * 1.0 / (250 * 1.0))) * c[i] - 50 * b[i]); n     } n     int x, y; n     scanf( %d %d , &x, &y); n     ans += x * 100; n     ans -= y * 50; n     printf( %.0lf n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void s() { puts( Stannis ); } n void d() { puts( Daenerys ); } n int main() { n   int n, k; n   scanf( %d %d , &n, &k); n   int odd = 0; n   int even = 0; n   long long tot = 0; n   for (int i = 0; i < n; i++) { n     int x; n     scanf( %d , &x); n     if (x % 2 == 0) n       even++; n     else n       odd++; n     tot += (long long)x; n   } n   int move = n - k; n   if (n == k) { n     if (tot % 2LL == 0) { n       d(); n     } else { n       s(); n     } n   } else { n     if (move % 2 == 1) { n       if (move < odd && move < even) { n         s(); n       } else { n         if (move / 2 >= odd) { n           d(); n         } else { n           if (move / 2 >= even && ((move - even) + odd) % 2 == 0) { n             d(); n           } else { n             s(); n           } n         } n       } n     } else { n       if (move < odd && move < even) { n         d(); n       } else { n         if (move / 2 >= even && ((move - even) + odd) % 2 == 1) { n           s(); n         } else { n           d(); n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 201110; n int lab[N], val[N]; n vector<int> gr[N]; n map<string, int> mp; n int n, m, q; n int root(int u) { n   if (lab[u] < 0) n     return u; n   else n     return lab[u] = root(lab[u]); n } n void join(int type, int u, int v) { n   if (lab[u] < lab[v]) { n     lab[u] += lab[v]; n     lab[v] = u; n     for (int i = 0; i < gr[v].size(); i++) { n       gr[u].push_back(gr[v][i]); n       val[gr[v][i]] *= type; n     } n     gr[v].clear(); n   } else { n     lab[v] += lab[u]; n     lab[u] = v; n     for (int i = 0; i < gr[u].size(); i++) { n       gr[v].push_back(gr[u][i]); n       val[gr[u][i]] *= type; n     } n     gr[u].clear(); n   } n } n string read() { n   char ch; n   string ans =   ; n   while (ch = getchar()) { n     if ( a  <= ch && ch <=  z ) break; n   } n   ans = ans + ch; n   while (ch = getchar()) { n     if (ch <  a  || ch >  z ) break; n     ans = ans + ch; n   } n   return ans; n } n int main() { n   scanf( %d%d%d , &n, &m, &q); n   int k = 0; n   string st; n   int type, u, v; n   for (int i = 1; i <= n; i++) { n     val[i] = 1; n     gr[i].push_back(i); n     st = read(); n     mp[st] = i; n   } n   memset(lab, 255, sizeof(lab)); n   for (int i = 1; i <= m; i++) { n     scanf( %d , &type); n     st = read(); n     u = mp[st]; n     st = read(); n     v = mp[st]; n     if (root(u) != root(v)) { n       if ((val[u] == val[v] && type == 1) || (val[u] != val[v] && type == 2)) n         join(1, root(u), root(v)); n       else n         join(-1, root(u), root(v)); n       puts( YES ); n     } else { n       if ((val[u] != val[v] && type == 1) || (val[u] == val[v] && type == 2)) n         puts( NO ); n       else n         puts( YES ); n     } n   } n   for (int i = 1; i <= q; i++) { n     st = read(); n     u = mp[st]; n     st = read(); n     v = mp[st]; n     if (root(u) != root(v)) n       printf( 3 n ); n     else { n       if (val[u] == val[v]) n         printf( 1 n ); n       else n         printf( 2 n ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 50; n deque<int> dq; n bool is[N], can[N]; n vector<vector<int> > adj(N); n int n, m, d, cur, mx, ans[N], x; n void dfs(int u, int p) { n   ans[u] = ans[p] + 1; n   can[u] &= (ans[u] <= d); n   if (ans[u] > mx && is[u]) mx = ans[u], x = u; n   for (auto v : adj[u]) n     if (v != p) dfs(v, u); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m >> d; n   ans[0] = -1; n   memset(can, 1, sizeof can); n   for (int i = 0; i < m; i++) cin >> x, is[x] = 1; n   for (int i = 1, u, v; i < n; i++) { n     cin >> u >> v; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   dq.push_front(x); n   while (dq.size()) { n     int now = dq.front(); n     dfs(now, 0); n     dq.pop_front(); n     if (now != x) dq.push_front(x); n   } n   int s = 0; n   for (int i = 1; i <= n; i++) s += can[i]; n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n const int MAXN = 100000; n int n; n int x[MAXN]; n int ret[MAXN]; n bool used[MAXN + 1]; n void run() { n   scanf( %d , &n); n   for (int i = (0); i < (n); ++i) scanf( %d , &x[i]); n   memset(ret, -1, sizeof(ret)); n   memset(used, false, sizeof(used)); n   for (int i = (0); i < (n); ++i) n     if (1 <= x[i] && x[i] <= n && !used[x[i]]) ret[i] = x[i], used[x[i]] = true; n   int at = 1; n   for (int i = (0); i < (n); ++i) n     if (ret[i] == -1) { n       while (used[at]) ++at; n       ret[i] = at++; n     } n   for (int i = (0); i < (n); ++i) { n     if (i != 0) printf(   ); n     printf( %d , ret[i]); n   } n   puts(  ); n } n int main() { n   run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T gcd(T a, T b) { n   if (a < 0) return gcd(-a, b); n   if (b < 0) return gcd(a, -b); n   return (b == 0) ? a : gcd(b, a % b); n } n template <class T> n inline T lcm(T a, T b) { n   if (a < 0) return lcm(-a, b); n   if (b < 0) return lcm(a, -b); n   return a * (b / gcd(a, b)); n } n template <class T> n inline T sqr(T x) { n   return x * x; n } n template <class T> n T power(T N, T P) { n   return (P == 0) ? 1 : N * power(N, P - 1); n } n long long toInt64(string s) { n   long long r = 0; n   istringstream sin(s); n   sin >> r; n   return r; n } n double LOG(long long N, long long B) { return (log10l(N)) / (log10l(B)); } n string itoa(long long a) { n   if (a == 0) return  0 ; n   string ret; n   for (long long i = a; i > 0; i = i / 10) ret.push_back((i % 10) + 48); n   reverse(ret.begin(), ret.end()); n   return ret; n } n vector<string> token(string a, string b) { n   const char *q = a.c_str(); n   while (count(b.begin(), b.end(), *q)) q++; n   vector<string> oot; n   while (*q) { n     const char *e = q; n     while (*e && !count(b.begin(), b.end(), *e)) e++; n     oot.push_back(string(q, e)); n     q = e; n     while (count(b.begin(), b.end(), *q)) q++; n   } n   return oot; n } n template <class T> n inline T __cin() { n   T ret; n   cin >> ret; n   return ret; n } n int isvowel(char s) { n   s = tolower(s); n   if (s ==  a  || s ==  e  || s ==  i  || s ==  o  || s ==  u ) return 1; n   return 0; n } n int isupper(char s) { n   if (s >=  A  and s <=  Z ) return 1; n   return 0; n } n int Set(int N, int pos) { return N = N | (1 << pos); } n int reset(int N, int pos) { return N = N & ~(1 << pos); } n int check(int N, int pos) { return (N & (1 << pos)); } n int toggle(int N, int pos) { n   if (check(N, pos)) return N = reset(N, pos); n   return N = Set(N, pos); n } n void pbit(int N) { n   printf( ( ); n   for (int i = 10; i >= 0; i--) { n     bool x = check(N, i); n     cout << x; n   } n   puts( ) ); n } n int main() { n   int n = 9; n   cin >> n; n   long long ans = -1; n   for (int i = max(n - 100, 1); i <= n; i++) { n     for (int j = max(n - 100, 1); j <= n; j++) { n       for (int k = max(n - 100, 1); k <= n; k++) { n         long long lc = lcm((long long)i, lcm((long long)j, (long long)k)); n         ans = max(ans, lc); n       } n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, j, line[35], column[35], var, count; n   cin >> n; n   for (i = 1; i <= n; ++i) line[i] = column[i] = 0; n   for (i = 1; i <= n; ++i) n     for (j = 1; j <= n; ++j) { n       cin >> var; n       line[i] += var; n       column[j] += var; n     } n   count = 0; n   for (i = 1; i <= n; ++i) n     for (j = 1; j <= n; ++j) { n       if (column[i] > line[j]) count++; n     } n   cout << count; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const int N = 1020; n int main() { n   int n; n   cin >> n; n   if (n % 2 == 0) { n     cout << -1 << endl; n   } else { n     cout << 0; n     for (int i = 1; i < n; i++) { n       cout <<     << i; n     } n     cout << endl; n     cout << 0; n     for (int i = 1; i < n; i++) { n       cout <<     << i; n     } n     cout << endl; n     cout << 0; n     for (int i = 1; i < n; i++) { n       cout <<     << (i + i) % n; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int min(int a, int b) { n   if (a <= b) { n     return a; n   } else { n     return b; n   } n } n int max(int a, int b) { n   if (a >= b) { n     return a; n   } else { n     return b; n   } n } n int main() { n   int l, r, a; n   cin >> l >> r >> a; n   int MAX, MIN; n   int count; n   MAX = max(l, r); n   MIN = min(l, r); n   MIN += a; n   if (MIN > MAX) { n     count = (2 * MAX) + ((MIN - MAX) / 2) * 2; n   } else { n     count = MIN * 2; n   } n   cout << count << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 3; n int n; n vector<int> G[N]; n int h[N], cnt[N]; n int res = 0; n void dfs(int u, int p) { n   cnt[h[u]]++; n   for (int v : G[u]) n     if (v != p) { n       h[v] = h[u] + 1; n       dfs(v, u); n     } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 1; i <= n - 1; ++i) { n     int x; n     cin >> x; n     G[x].push_back(i + 1); n   } n   h[1] = 1; n   dfs(1, 0); n   for (int i = 1; i <= n; ++i) res += (cnt[i] % 2); n   cout << res; n } n


#include <bits/stdc++.h> n using namespace std; n void frepn() { n   freopen( n          n        .in , n        r , stdin); n   freopen( n          n        .out , n        w , stdout); n } n const int N = 50500; n const long long INF = (1e17) + 777; n const int mod = (1e9) + 7; n int n, a[N], k, t; n int ans, ans2, ans3, ans4; n int main() { n   ios_base::sync_with_stdio(0); n   ; n   cin >> n >> k >> t; n   ans = k * t; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     ans4 += a[i]; n   } n   sort(a + 1, a + 1 + n); n   for (int i = n - k; i <= n; i++) { n     ans2 += a[i]; n   } n   for (int i = 1; i <= n - k; i++) { n     ans3 += a[i]; n   } n   if (ans2 < ans) n     cout << ans4; n   else n     cout << ans3 + ans; n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n typedef long long ll; n const int MAXN=1e9+1; n const ll mod=1e9+7; n  n int main(){ n     ios_base::sync_with_stdio(false); n     cin.tie(NULL); n     cout.tie(NULL);  n     int n,m,k; n     cin>>n>>m>>k; n     int hori[n][m-1]; n     for(int i=0;i<n;i++){ n         for(int j=0;j<m-1;j++){ n             cin>>hori[i][j]; n         } n     } n     int verti[n-1][m]; n     for(int i=0;i<n-1;i++){ n         for(int j=0;j<m;j++){ n             cin>>verti[i][j]; n         } n     } n     if(k%2!=0){ n         for(int i=0;i<n;i++){ n             for(int j=0;j<m;j++)cout<< -1  ; n             cout<<endl; n         } n         return 0; n     } n     k/=2; n     int dp[n][m][k+1]; n     for(int i=0;i<n;i++){ n         for(int j=0;j<m;j++){ n             for(int step=0;step<=k;step++)dp[i][j][step]=MAXN; n         } n     } n     for(int i=0;i<n;i++){ n         for(int j=0;j<m;j++)dp[i][j][0]=0; n     } n     for (int step = 0; step < k; step++) { n             for (int i = 0; i < n; i++) { n                 for (int j = 0; j < m; j++) { n                     if (i > 0) dp[i - 1][j][step + 1] = min(dp[i - 1][j][step + 1], dp[i][j][step] + verti[i-1][j]); n                     if (i < n - 1) dp[i + 1][j][step + 1] = min(dp[i + 1][j][step + 1], dp[i][j][step] + verti[i][j]); n                     if (j > 0) dp[i][j - 1][step + 1] = min(dp[i][j - 1][step + 1], dp[i][j][step] + hori[i][j-1]); n                     if (j < m - 1) dp[i][j + 1][step + 1] = min(dp[i][j + 1][step + 1], dp[i][j][step] + hori[i][j]); n                 } n             } n         } n     for(int i=0;i<n;i++){ n         for(int j=0;j<m;j++){ n             cout<<(2*dp[i][j][k])<<   ; n         } n         cout<<endl; n     } n      n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void rd(T &x) { n   x = 0; n   char c = getchar(); n   int f = 1; n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (isdigit(c)) x = x * 10 -  0  + c, c = getchar(); n   x *= f; n } n const int N = 110; n int Sqr(int x) { return x * x; } n int sum[N][N][N]; n int n, m; n int vis[N][N], f[N][N]; n int dp(int l, int r) { n   if (l + 1 >= r) return 0; n   if (vis[l][r]) return f[l][r]; n   vis[l][r] = 1; n   int res = 0; n   for (int k = l + 1; k < r; ++k) { n     res = max(res, Sqr(sum[k][l][r]) + dp(l, k) + dp(k, r)); n   } n   return f[l][r] = res; n } n int main() { n   rd(n), rd(m); n   for (int i = 1; i <= n; ++i) { n     int t, l, r; n     rd(t); n     while (t--) { n       rd(l), rd(r); n       for (int j = l; j <= r; ++j) sum[j][l - 1][r + 1]++; n     } n   } n   for (int i = 1; i <= m; ++i) { n     for (int j = i - 1; j >= 0; --j) n       for (int k = i + 1; k <= m + 1; ++k) n         sum[i][j][k] += n             sum[i][j + 1][k] + sum[i][j][k - 1] - sum[i][j + 1][k - 1]; n   } n   printf( %d , dp(0, m + 1)); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n #pragma GCC optimization( unroll-loops ) n long long int power(long long int x, long long int n) { n   long long int result = 1; n   while (n) { n     if (n % 2 == 1) result = result * x; n     n = n / 2; n     x = x * x; n   } n   return result; n } n long long int gcd(long long int a, long long int b) { n   if (!b) return a; n   return gcd(b, a % b); n } n long long int lcm(long long int a, long long int b) { n   return (a * b) / gcd(a, b); n } n long long int BS(long long int a[], long long int s, long long int n, n                  long long int val) { n   long long int mid, beg = s, end = n - 1; n   while (beg <= end) { n     mid = (beg + end) / 2; n     if (val == a[mid]) { n       break; n     } else if (val > a[mid]) { n       beg = mid + 1; n     } else { n       end = mid - 1; n     } n   } n   return mid; n } n inline long long int mul(long long int x, long long int y, long long int m) { n   long long int z = 1LL * x * y; n   if (z >= m) { n     z %= m; n   } n   return z; n } n long long int powmod(long long int x, long long int y, long long int m) { n   long long int r = 1; n   while (y) { n     if (y & 1) { n       r = mul(r, x, m); n     } n     y >>= 1; n     x = mul(x, x, m); n   } n   return r; n } n using namespace std; n void start() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n } n int main() { n   start(); n   long long int n; n   cin >> n; n   long long int a[n], b[n]; n   for (long long int i = 0; i < n; i++) cin >> a[i] >> b[i]; n   long long int khatam = 0; n   for (long long int i = 0; i < n; i++) { n     if (a[i] != b[i]) { n       khatam = 1; n       break; n     } n   } n   if (khatam) { n     cout <<  rated n ; n     return 0; n   } n   long long int khatam1 = 0; n   for (long long int i = 1; i < n; i++) { n     if (b[i] > b[i - 1]) { n       khatam1 = 1; n       break; n     } n   } n   if (khatam1) n     cout <<  unrated ; n   else n     cout <<  maybe ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, s = 0; n   bool kt; n   cin >> n >> m; n   char a[n][m]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> a[i][j]; n     } n   } n   for (int i = 0; i < n; i++) { n     kt = true; n     for (int j = 0; j < m; j++) { n       if (a[i][j] ==  S ) { n         kt = false; n         break; n       } n     } n     if (kt == true) n       for (int j = 0; j < m; j++) a[i][j] =  1 ; n   } n   for (int j = 0; j < m; j++) { n     kt = true; n     for (int i = 0; i < n; i++) { n       if (a[i][j] ==  S ) { n         kt = false; n         break; n       } n     } n     if (kt == true) n       for (int i = 0; i < n; i++) a[i][j] =  1 ; n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (a[i][j] ==  1 ) s++; n     } n   } n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n int n, ans, len; n int a[2333]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   a[0] = 0; n   a[n + 1] = 1001; n   for (int i = 1; i <= n + 1; i++) { n     if (a[i] == a[i - 1] + 1) n       len++; n     else { n       ans = max(ans, len - 1); n       len = 0; n     } n   } n   ans = max(ans, len - 1); n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[8][8], n, m, u, v, k = INT_MAX; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   cin >> n >> m; n   for (long long i = 0; i < m; i++) { n     cin >> u >> v; n     a[u][v] = 1; n     a[v][u] = 1; n   } n   if (n <= 6) n     cout << m <<   n ; n   else { n     for (long long i = 1; i <= 7; i++) { n       for (long long j = i + 1; j <= 7; j++) { n         long long c = 0; n         for (long long l = 1; l <= 7; l++) n           if (a[i][l] == 1 && a[j][l] == 1) ++c; n         k = min(k, c); n       } n     } n     cout << m - k <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 9; n int n, p, q; n string s, t, a, b; n int c[2005], d[2005], h[2005], invH[2005], k[2005], invK[2005]; n vector<pair<int, int>> memo; n int mul(int aa, int bb) { return ((long long)aa * bb) % MOD; } n int add(int aa, int bb) { return (aa + bb) % MOD; } n int sub(int aa, int bb) { return (aa - bb + MOD) % MOD; } n int modpow(int num, int pi) { n   int res = 1; n   while (pi > 0) { n     if (pi & 1) res = mul(res, num); n     num = mul(num, num); n     pi >>= 1; n   } n   return res; n } n pair<int, int> getHash(int lo, int hi) { n   return make_pair(mul(sub(c[hi], c[lo]), invH[lo]), n                    mul(sub(d[hi], d[lo]), invK[lo])); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> s >> a >> b; n   n = s.size(); n   p = a.size(); n   q = b.size(); n   h[0] = invH[0] = 1; n   k[0] = invK[0] = 1; n   for (int i = 1; i <= n; i++) { n     h[i] = mul(h[i - 1], 31); n     invH[i] = modpow(h[i], MOD - 2); n     k[i] = mul(k[i - 1], 53); n     invK[i] = modpow(k[i], MOD - 2); n   } n   for (int i = 0; i < n; i++) { n     c[i + 1] = add(c[i], mul(h[i], s[i])); n     d[i + 1] = add(d[i], mul(k[i], s[i])); n   } n   pair<int, int> x = make_pair(0, 0); n   for (int i = 0; i < p; i++) { n     x.first = add(x.first, mul(h[i], a[i])); n     x.second = add(x.second, mul(k[i], a[i])); n   } n   pair<int, int> y = make_pair(0, 0); n   for (int i = 0; i < q; i++) { n     y.first = add(y.first, mul(h[i], b[i])); n     y.second = add(y.second, mul(k[i], b[i])); n   } n   for (int i = 0; i < n - p + 1; i++) { n     for (int j = i + max(0, p - q); j < n - q + 1; j++) { n       if (x == getHash(i, i + p) && y == getHash(j, j + q)) { n         memo.push_back(getHash(i, j + q)); n       } n     } n   } n   sort(memo.begin(), memo.end()); n   int ans = unique(memo.begin(), memo.end()) - memo.begin(); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n long long a, b, x, vx, vy; n map<long long, long long> mo; n map<long long, long long>::iterator it; n map<pair<long long, long long>, long long> ex; n map<pair<long long, long long>, long long>::iterator ti; n int main() { n   scanf( %d%I64d%I64d , &n, &a, &b); n   for (int i = 0; i < n; i++) { n     scanf( %I64d%I64d%I64d , &x, &vx, &vy); n     mo[vy - a * vx]++; n     ex[make_pair(vx, vy)]++; n   } n   long long ans = 0; n   for (it = mo.begin(); it != mo.end(); it++) { n     long long tmp = it->second; n     ans += tmp * (tmp - 1); n   } n   for (ti = ex.begin(); ti != ex.end(); ti++) { n     long long tmp = ti->second; n     ans -= tmp * (tmp - 1); n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(2) n using namespace std; n const int N = 5005; n int n, m; n double ans, F[N][N]; n bool vis[N][N]; n double cal(double b, double x, double y, double ps) { n   return (1 - b) * ps * x + min(1 - ps, ps * b + (1 - ps) * (1 - y)); n } n double f(int a, int b, int fl) { n   if (!b) return 1; n   if (!a) return 1 / (double)(b + 1); n   if (vis[a][b]) return F[a][b]; n   double res = 1 / (double)(b + 1); n   vis[a][b] = 1; n   double y = f(b, a - 1, 0), x = 1 - f(b - 1, a, 0); n   return F[a][b] = n              max(res, cal(1 / (double)(b + 1), x, y, n                           y * (double)(b + 1) / (1 + y * (double)(b + 1)))); n } n int main() { n   int i, j; n   cin >> n >> m, ans = f(n, m, 0); n   printf( %.9lf %.9lf , ans, 1 - ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n; n   cin >> n; n   vector<long long int> v(n), vv; n   for (int i = 0; i < n; i++) cin >> v[i]; n   long long int mx = *max_element(v.begin(), v.end()); n   int len = 0, fg = 0; n   for (long long int i = 0; i < n; i++) { n     if (v[i] == mx) { n       long long int j = i; n       while (v[j] == mx && j <= n - 1) j++; n       vv.push_back(j - i); n       i = j; n     } n   } n   sort(vv.begin(), vv.end()); n   cout << vv[vv.size() - 1]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 100000 + 2; n const int MAX_M = 100000 + 2; n int weight[MAX_N]; n struct Edge { n   int v, x; n } E[MAX_M * 10]; n int tot; n template <int N> n struct AdjList { n   int l[N]; n   inline void addEdge(int u, int v) { n     E[tot] = (Edge){v, l[u]}; n     l[u] = tot++; n   } n   void init() { memset(l, -1, sizeof l); } n }; n AdjList<MAX_N> adj; n namespace BCC { n const int N = MAX_N; n const int M = MAX_M; n set<int> p2c[N]; n set<pair<int, int> > c2e[N]; n map<pair<int, int>, int> e2c; n pair<int, int> S[M], tmp; n int cut[N], dep[N], low[N], ori[N + N]; n int *l; n Edge *E; n int n, bcc_cnt, top; n void dfs(int u, int D, int ind); n void Pop(pair<int, int> y); n int rebuild(AdjList<N + N> &adj); n void init(int _n, int *_l, Edge *_E) { n   n = _n; n   l = _l; n   E = _E; n   for (int i = 0; i < n; i++) dep[i] = cut[i] = -1; n   for (int i = 0; i < n; i++) p2c[i].clear(), c2e[i].clear(); n   e2c.clear(); n   bcc_cnt = top = 0; n   for (int i = 0; i < n; i++) n     if (dep[i] == -1) { n       dfs(i, 0, -1); n     } n } n void dfs(int u, int D, int ind) { n   dep[u] = low[u] = D; n   int child = 0; n   for (int i = l[u]; ~i; i = E[i].x) { n     if (ind == (i ^ 1)) continue; n     int v = E[i].v; n     S[top++] = {u, v}; n     if (dep[v] >= 0) { n       if (dep[v] > dep[u]) top--; n       low[u] = min(low[u], dep[v]); n       continue; n     } n     child++; n     dfs(v, D + 1, i); n     low[u] = min(low[u], low[v]); n     if (low[v] >= dep[u]) { n       cut[u] = 1; n       Pop(pair<int, int>(u, v)); n     } n   } n   if (child == 1 && ind < 0) cut[u] = -1; n } n void Pop(pair<int, int> y) { n   do { n     tmp = S[--top]; n     p2c[tmp.first].insert(bcc_cnt); n     p2c[tmp.second].insert(bcc_cnt); n     if (tmp.first > tmp.second) swap(tmp.first, tmp.second); n     c2e[bcc_cnt].insert(tmp); n     e2c[tmp] = bcc_cnt; n   } while (top && S[top] != y); n   bcc_cnt++; n } n int rebuild(AdjList<N + N> &adj) { n   int c = bcc_cnt; n   for (int i = 0; i < n; i++) n     if (cut[i] != -1) { n       cut[i] = c++; n       ori[c - 1] = i; n     } n   adj.init(); n   set<int>::iterator it; n   for (int u = 0; u < n; u++) { n     if (cut[u] == -1) continue; n     for (it = p2c[u].begin(); it != p2c[u].end(); it++) { n       adj.addEdge(cut[u], *it); n       adj.addEdge(*it, cut[u]); n     } n   } n   return c; n } n };  // namespace BCC n namespace Solve { n const int N = MAX_N + MAX_N; n const int inf = 1e9; n AdjList<N> adj2; n multiset<int> value[N]; n int n, m; n int dep[N], top[N], fa[N], heavy[N], siz[N]; n int ID[N]; n int *l; n Edge *E; n void Label(int u, int anc); n void dfs(int u); n int query(int a, int b); n struct segTree { n   int Min[N << 1]; n   inline int getID(int l, int r) { return l + r | l != r; } n   void up(int l, int r) { n     int mid = l + r >> 1; n     Min[getID(l, r)] = min(Min[getID(l, mid)], Min[getID(mid + 1, r)]); n   } n   void build(int l, int r) { n     int o = getID(l, r); n     if (l == r) { n       if (value[l].empty()) { n         puts( empty bug ); n         Min[o] = inf; n       } else { n         Min[o] = *value[l].begin(); n       } n     } else { n       int mid = l + r >> 1; n       build(l, mid); n       build(mid + 1, r); n       up(l, r); n     } n   } n   void update(int l, int r, int ql, int preValue, int nowValue) { n     if (l == r) { n       auto it = value[l].lower_bound(preValue); n       if (it == value[l].end()) { n         puts( delete bug ); n         return; n       } n       value[l].erase(it); n       value[l].insert(nowValue); n       Min[getID(l, r)] = *value[l].begin(); n     } else { n       int mid = l + r >> 1; n       if (ql <= mid) n         update(l, mid, ql, preValue, nowValue); n       else n         update(mid + 1, r, ql, preValue, nowValue); n       up(l, r); n     } n   } n   int getMin(int l, int r, int ql, int qr) { n     if (ql <= l && r <= qr) { n       return Min[getID(l, r)]; n     } n     int mid = l + r >> 1; n     if (qr <= mid) return getMin(l, mid, ql, qr); n     if (ql > mid) return getMin(mid + 1, r, ql, qr); n     return min(getMin(l, mid, ql, qr), getMin(mid + 1, r, ql, qr)); n   } n } segs; n void dfs(int u) { n   siz[u] = 1; n   heavy[u] = -1; n   for (int i = l[u], v; ~i; i = E[i].x) { n     v = E[i].v; n     if (fa[u] != v) { n       dep[v] = dep[u] + 1; n       fa[v] = u; n       dfs(v); n       siz[u] += siz[v]; n       if (heavy[u] == -1 || siz[heavy[u]] < siz[v]) { n         heavy[u] = v; n       } n     } n   } n } n void Label(int u, int anc) { n   ID[u] = m++; n   top[u] = anc; n   if (~heavy[u]) Label(heavy[u], anc); n   for (int i = l[u], v; ~i; i = E[i].x) { n     v = E[i].v; n     if (v != fa[u] && v != heavy[u]) { n       Label(v, v); n     } n   } n } n int query(int a, int b) { n   int ret = inf; n   while (top[a] != top[b]) { n     if (dep[top[a]] < dep[top[b]]) { n       swap(a, b); n     } n     ret = min(ret, segs.getMin(0, m - 1, ID[top[a]], ID[a])); n     a = fa[top[a]]; n   } n   if (dep[a] < dep[b]) { n     swap(a, b); n   } n   ret = min(ret, segs.getMin(0, m - 1, ID[b], ID[a])); n   if (b < BCC::bcc_cnt && fa[b] != -1) { n     ret = min(ret, weight[BCC::ori[fa[b]]]); n   } n   return ret; n } n void init(int _n, Edge *_E, int _m) { n   n = _n; n   for (int u = 0; u < n; u++) value[u].clear(); n   l = adj2.l; n   E = _E; n   dep[0] = -1; n   fa[0] = -1; n   m = 0; n   dfs(0); n   Label(0, 0); n   for (int u = 0; u < _m; u++) { n     if (BCC::cut[u] == -1) { n       value[ID[*BCC::p2c[u].begin()]].insert(weight[u]); n     } else { n       value[ID[BCC::cut[u]]].insert(weight[u]); n       value[ID[fa[BCC::cut[u]]]].insert(weight[u]); n     } n   } n   segs.build(0, m - 1); n } n void modify(int u, int pre, int now) { n   if (u >= BCC::bcc_cnt && fa[u] != -1) { n     modify(fa[u], pre, now); n   } n   segs.update(0, m - 1, ID[u], pre, now); n } n void gao(int q) { n   char op; n   int a, b, w, x, y; n   while (q--) { n     scanf(  %c %d %d , &op, &a, &b); n     if (op ==  C ) { n       a--; n       x = BCC::cut[a]; n       if (x == -1) { n         if (BCC::p2c[a].size() != 1) { n           puts( build bug ); n         } n         x = *BCC::p2c[a].begin(); n       } n       modify(x, weight[a], b); n       weight[a] = b; n     } else { n       a--; n       b--; n       if (a == b) { n         printf( %d n , weight[a]); n         continue; n       } n       x = BCC::cut[a]; n       y = BCC::cut[b]; n       if (x == -1) { n         if (BCC::p2c[a].size() != 1) { n           puts( build bug ); n         } n         x = *BCC::p2c[a].begin(); n       } n       if (y == -1) { n         if (BCC::p2c[b].size() != 1) { n           puts( build bug ); n         } n         y = *BCC::p2c[b].begin(); n       } n       printf( %d n , query(x, y)); n     } n   } n } n };  // namespace Solve n int main() { n   int n, m, q, u, v, w; n   scanf( %d%d%d , &n, &m, &q); n   for (int i = 0; i < n; i++) { n     scanf( %d , weight + i); n   } n   tot = 0; n   adj.init(); n   for (int i = 0; i < m; i++) { n     scanf( %d%d , &u, &v); n     u--; n     v--; n     adj.addEdge(u, v); n     adj.addEdge(v, u); n   } n   BCC::init(n, adj.l, E); n   int bcc_cnt = BCC::rebuild(Solve::adj2); n   Solve::init(bcc_cnt, E, n); n   Solve::gao(q); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using pii = pair<int, int>; n const int MOD = 1e9 + 7; n int n; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed; n   cin >> n; n   int dp[] = {1, 0}; n   for (int i = 1; i < n; i++) dp[i % 2] = (dp[i % 2] + dp[1 - i % 2] + 1) % MOD; n   cout << (dp[0] + dp[1]) % MOD << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long n, i = 0, j, k = 0, l = 0, m = 10e9, a = 0, b = 0, c, sum = 0, n                x = 0, y = 0, z = 0; n   cin >> n; n   long long arr[n + 1]; n   for (i = 1; i <= n; i++) { n     cin >> arr[i]; n     arr[i] = arr[i] / max(i - 1, n - i); n   } n   for (i = 1; i <= n; i++) { n     l = arr[i]; n     m = min(m, l); n   } n   cout << m; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int n, m, i, j, q = 0; n   string s, k, p =  go ; n   cin >> n >> s; n   vector<string> st(100); n   st[0] =  ogo ; n   for (i = 1; i < 100; i++) { n     st[i] = st[i - 1] + p; n   } n   for (i = 0; i < n; i++) { n     j = n - i; n     q = 0; n     for (j = n - i; j >= 3; j--) { n       k = s.substr(i, j); n       if (binary_search(st.begin(), st.end(), k)) { n         i = i + j - 1; n         cout <<  *** ; n         q = 1; n         break; n       } n     } n     if (q == 0) cout << s[i]; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 60; n const int A = 26; n const int INF = 1000000001; n char G[MAX + 2][MAX + 3]; n int D[MAX + 2][MAX + 2]; n bool ok[A + 1]; n pair<int, int> S, T; n vector<char> ans; n vector<int> K; n int n, m, k; n inline int con(char c) { return  a  <= c && c <=  z  ? c -  a  : A; } n vector<pair<int, int> > Q; n int dx[] = {1, -1, 0, 0}; n int dy[] = {0, 0, 1, -1}; n bool vis[A + 1][A + 1][A + 1][A + 1]; n void bfs() { n   sort((K).begin(), (K).end()); n   K.erase(unique((K).begin(), (K).end()), K.end()); n   if (K.back() == A) K.pop_back(); n   if (K.size() > k || K.empty()) return; n   if (vis[K[0]][K.size() > 1 ? K[1] : A][K.size() > 2 ? K[2] : A] n          [K.size() > 3 ? K[3] : A]) n     return; n   vis[K[0]][K.size() > 1 ? K[1] : A][K.size() > 2 ? K[2] : A] n      [K.size() > 3 ? K[3] : A] = true; n   for (int i = 0; i < K.size(); ++i) ok[K[i]] = true; n   for (int i = 0; i <= n + 1; ++i) memset(D[i], -1, sizeof(int) * (m + 2)); n   Q.clear(); n   Q.push_back(T); n   D[T.first][T.second] = 0; n   for (int foo = 0; foo < Q.size(); ++foo) { n     pair<int, int> v = Q[foo]; n     if (v == S) break; n     for (int foo = 0; foo < 4; ++foo) { n       int i = v.first + dx[foo]; n       int j = v.second + dy[foo]; n       if (ok[con(G[i][j])] && D[i][j] == -1) { n         D[i][j] = D[v.first][v.second] + 1; n         Q.push_back(make_pair(i, j)); n       } n     } n   } n   for (int i = 0; i < K.size(); ++i) ok[K[i]] = false; n   int d = INF; n   for (int foo = 0; foo < 4; ++foo) { n     int i = S.first + dx[foo]; n     int j = S.second + dy[foo]; n     if (D[i][j] != -1) d = min(d, D[i][j]); n   } n   if (d > ans.size()) return; n   int com = 0; n   int index = 0; n   vector<char> tmp; n   tmp.reserve(d); n   vector<pair<int, int> > V[2]; n   bool now = false; n   V[0].push_back(S); n   while (d) { n     int best = 200; n     for (int i = 0; i < K.size(); ++i) n       for (__typeof((V[now]).begin()) u = (V[now]).begin(); u != (V[now]).end(); n            ++u) n         for (int foo = 0; foo < 4; ++foo) { n           int x = u->first + dx[foo]; n           int y = u->second + dy[foo]; n           if (G[x][y] == K[i] +  a  && D[x][y] == d) { n             best = K[i]; n             goto out; n           } n         } n   out: n     tmp.push_back(best +  a ); n     if (!com) { n       if (tmp.back() < ans[index]) n         com = -1; n       else if (tmp.back() > ans[index]) n         com = 1; n     } n     ++index; n     V[!now].clear(); n     for (__typeof((V[now]).begin()) u = (V[now]).begin(); u != (V[now]).end(); n          ++u) n       for (int foo = 0; foo < 4; ++foo) { n         int x = u->first + dx[foo]; n         int y = u->second + dy[foo]; n         if (G[x][y] == best +  a  && D[x][y] == d) { n           V[!now].push_back(make_pair(x, y)); n           D[x][y] = -1; n         } n       } n     --d; n     now = !now; n   } n   if (tmp.size() < ans.size() || com == -1) ans = tmp; n } n void solve(int x, int i) { n   if (x >= k) { n     vector<int> tmpK = K; n     bfs(); n     K = tmpK; n     return; n   } n   if (i == A) return; n   solve(x, i + 1); n   for (; i < A; ++i) { n     K.push_back(i); n     solve(x + 1, i + 1); n     K.pop_back(); n   } n } n int main(int argc, char *argv[]) { n   scanf( %d %d %d , &n, &m, &k); n   ans.resize(n * m + 10); n   for (int i = 0; i <= n + 1; ++i) memset(G[i],  $ , m + 2); n   for (int i = 1; i <= n; ++i) scanf( %s , G[i] + 1); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) n       if (G[i][j] ==  S ) n         S = make_pair(i, j); n       else if (G[i][j] ==  T ) n         T = make_pair(i, j); n   if (abs(S.first - T.first) + abs(S.second - T.second) == 1) return 0; n   for (int xs = S.first - 1; xs <= S.first + 1; ++xs) n     for (int ys = S.second - 1; ys <= S.second + 1; ++ys) n       if (abs(xs - S.first) + abs(ys - S.second) == 1) n         for (int xt = T.first - 1; xt <= T.first + 1; ++xt) n           for (int yt = T.second - 1; yt <= T.second + 1; ++yt) n             if (abs(xt - T.first) + abs(yt - T.second) == 1) { n               K.clear(); n               K.push_back(con(G[xs][ys])); n               K.push_back(con(G[xt][yt])); n               if (K[0] == K[1]) K.pop_back(); n               solve(K.size(), 0); n             } n   if (ans.size() == n * m + 10) { n     printf( -1 n ); n     return 0; n   } n   for (__typeof((ans).begin()) i = (ans).begin(); i != (ans).end(); ++i) n     printf( %c , *i); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char inp[2000]; n int toNum(char x) { n   if (x >=  0  && x <=  9 ) return x -  0 ; n   return 10 + x -  A ; n } n char toChar(int x) { n   if (x < 10) return  0  + x; n   return  A  + (x - 10); n } n long long ato10(int a) { n   int len = strlen(inp); n   int lw = 0; n   while (lw < len && inp[lw] ==  0 ) lw++; n   if (lw >= len) return 0; n   long long ret = 0; n   for (int i = lw; i < len; i++) { n     ret = ret * a + toNum(inp[i]); n   } n   return ret; n } n char pI[] = { I ,  X ,  C ,  M }; n char pV[] = { V ,  L ,  D }; n int main() { n   int a, b; n   gets(inp); n   bool iR = false; n   int len = strlen(inp); n   for (int i = 0; i < len; i++) { n     if (inp[i] ==  R ) iR = true; n   } n   if (!iR) n     sscanf(inp,  %d%d , &a, &b); n   else n     sscanf(inp,  %d , &a); n   gets(inp); n   long long number = ato10(a); n   if (!iR) { n     string ret =   ; n     if (number == 0) n       ret =  0 ; n     else { n       while (number) { n         ret = toChar(number % b) + ret; n         number /= b; n       } n     } n     printf( %s n , ret.c_str()); n   } else { n     int idx = 0; n     string ret =   ; n     while (number) { n       int tdec = number % 10; n       number /= 10; n       if (tdec <= 3) n         for (int t = 0; t < tdec; t++) ret = pI[idx] + ret; n       else if (tdec == 4) { n         ret = pV[idx] + ret; n         ret = pI[idx] + ret; n       } else if (tdec == 5) n         ret = pV[idx] + ret; n       else if (tdec <= 8) { n         tdec -= 5; n         for (int t = 0; t < tdec; t++) ret = pI[idx] + ret; n         ret = pV[idx] + ret; n       } else { n         ret = pI[idx + 1] + ret; n         ret = pI[idx] + ret; n       } n       idx++; n     } n     printf( %s n , ret.c_str()); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int k; n long long int ways(long long int n) { n   long long int calc, ways = 0; n   for (int k = 2; k <= 10000000; k++) { n     calc = n / (1ll * k * k * k); n     ways += calc; n     if (calc == 0) { n       break; n     } n   } n   return ways; n } n long long int binarysearch(long long int low, long long int high) { n   long long int temp = high; n   while (low <= high) { n     long long int mid = low + (high - low) / 2; n     long long int x = ways(mid); n     if (x > k) n       high = mid - 1; n     else if (x < k) n       low = mid + 1; n     else if (x == k) { n       temp = min(temp, mid); n       high = mid - 1; n     } n   } n   return temp; n } n int main() { n   scanf( %lld , &k); n   long long int MAX = 10 * k; n   long long int ans = binarysearch(8, MAX); n   if (ans == MAX) ans = -1; n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n namespace whatever { n const long long inf = 1000000000000000001ll; n template <typename type> n type read() { n   char ch = getchar(); n   while (!isdigit(ch)) ch = getchar(); n   type value = ch -  0 ; n   ch = getchar(); n   while (isdigit(ch)) { n     value = value * 10 + ch -  0 ; n     ch = getchar(); n   } n   return value; n } n int n; n string f[201]; n char result[202]; n int fail[201]; n int match(const string &str, int l) { n   int cnt = 0; n   int cur = 0; n   for (char ch : str) { n     while (cur && ch != result[cur + 1]) cur = fail[cur]; n     if (ch == result[cur + 1]) ++cur; n     if (cur == l) { n       ++cnt; n       cur = fail[cur]; n     } n   } n   return cnt; n } n long long count(int l) { n   static long long cnt[201]; n   int i; n   for (i = 0; i <= n && (i < 2 || int(f[i - 2].size()) <= l); ++i) n     cnt[i] = match(f[i], l); n   if (i <= n) { n     long long span_cnt[2]; n     span_cnt[i % 2] = match( n         f[i - 2].substr(f[i - 2].size() - l + 1) + f[i - 1].substr(0, l - 1), n         l); n     span_cnt[1 - i % 2] = match( n         f[i - 2].substr(f[i - 2].size() - l + 1) + f[i - 2].substr(0, l - 1), n         l); n     do { n       cnt[i] = cnt[i - 2] + cnt[i - 1] + span_cnt[i % 2]; n       if (cnt[i] >= inf) return inf; n     } while (++i <= n); n   } n   return cnt[n]; n } n void insert(int l, char ch) { n   result[l] = ch; n   if (l == 1) return; n   int cur = fail[l - 1]; n   while (cur && ch != result[cur + 1]) cur = fail[cur]; n   if (ch == result[cur + 1]) ++cur; n   fail[l] = cur; n } n void run() { n   n = read<int>(); n   long long k = read<long long>() + 1; n   int m = read<int>(); n   f[0] =  0 ; n   f[1] =  1 ; n   int last = n; n   for (int i = 2; i <= n; ++i) n     if (int(f[i - 2].size()) <= m) n       f[i] = f[i - 2] + f[i - 1]; n     else { n       last = i - 1; n       break; n     } n   cerr <<  last:   << last << endl; n   fail[1] = 0; n   for (int i = 1; i <= m; ++i) { n     if (f[last].substr(f[last].size() - i + 1) == n         string(result + 1, result + i)) { n       if (--k == 0) break; n     } n     insert(i,  0 ); n     long long cnt = count(i); n     if (cnt >= k) n       putchar( 0 ); n     else { n       k -= cnt; n       insert(i,  1 ); n       putchar( 1 ); n     } n   } n   putchar(  n ); n } n }  // namespace whatever n int main() { whatever::run(); } n


#include <bits/stdc++.h> n const long long N = 2e5 + 17; n using namespace std; n long long i, mn, ans = 0, als = 0, v, ii, r4 = 0, r1, r2, r3, mx, p, q, d, l, r, n                  m, n, k, j; n string d1, d3, d2, s; n char kl, km, mk, lk; n double fg; n int inout() { n   freopen( input.txt ,  r , stdin); n   freopen( output.txt ,  w , stdout); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   cin >> n >> q; n   map<long long, long long> mp; n   while (q--) { n     cin >> r1 >> r2 >> r3; n     als = 0; n     ii = 0; n     for (i = 1; i <= n; i++) { n       if (r1 >= mp[i]) als++; n       if (als == r2) break; n     } n     if (als == r2) { n       for (i = 1; i <= n && r2; i++) { n         if (r1 >= mp[i]) { n           mp[i] = r1 + r3; n           ii += i; n           r2--; n         } n       } n       cout << ii <<   n ; n     } else n       cout <<  -1  n            <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 51; n int n, x; n int res[MAXN]; n inline int read() { n   register int num = 0, neg = 1; n   register char ch = getchar(); n   while (!isdigit(ch) && ch !=  - ) { n     ch = getchar(); n   } n   if (ch ==  - ) { n     neg = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     num = (num << 3) + (num << 1) + (ch -  0 ); n     ch = getchar(); n   } n   return num * neg; n } n inline void calc1(int n) { n   if (n <= 0) { n     return; n   } n   int x = 31 - __builtin_clz(n); n   reverse(res + (1 << x + 1) - n - 1, res + n + 1); n   calc1((1 << x + 1) - n - 2); n } n inline void solve1() { n   if (n & 1) { n     return (void)puts( NO ); n   } n   puts( YES ); n   for (register int i = 1; i <= n; i++) { n     res[i] = i; n   } n   calc1(n); n   for (register int i = 1; i <= n; i++) { n     printf( %d  , res[i]); n   } n   puts(  ); n } n inline void solve2() { n   if (n == 3 || n == 5 || n == (n & -n)) { n     return (void)puts( NO ); n   } n   puts( YES ); n   for (register int i = 1; i <= n; i++) { n     res[i] = i; n   } n   if (n & 1) { n     printf( 3 6 1 5 7 2 4  ); n     for (register int i = 8; i <= n; i += 2) { n       swap(res[i], res[i ^ 1]); n     } n     for (register int i = 8; i <= n; i++) { n       printf( %d  , res[i]); n     } n   } else { n     for (register int i = 2; i <= n - 3; i += 2) { n       swap(res[i], res[i + 1]); n     } n     swap(res[1], res[n - 1]), swap(res[n], res[n - 2]); n     for (register int i = 1; i <= n; i++) { n       printf( %d  , res[i]); n     } n   } n   puts(  ); n } n int main() { n = read(), solve1(), solve2(); } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   long long sum = 0, sum2 = 0; n   scanf( %d , &n); n   int nav[200005]; n   for (int i = 0; i < n; i++) scanf( %d , &nav[i]), sum += nav[i]; n   for (int i = 0; i < n; i++) { n     sum2 += nav[i]; n     if (sum2 >= (sum + 1) / 2) { n       printf( %d , i + 1); n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 998244353, N = 3e5 + 6; n long long n, k, t; n void solve() { n   cin >> n >> k; n   long long t = 1; n   while (t * 10 <= n) t *= 10; n   while (k > 1) { n     t = 1; n     while (t * 10 <= n) t *= 10; n     while (n - t < k - 1) t /= 10; n     cout << t <<    ; n     n -= t; n     k--; n   } n   cout << n; n } n int main() { n   long long tt = 1; n   cin >> tt; n   while (tt--) { n     solve(); n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   int sa = 0, sb = 0; n   int ca, cb; n   char* c; n   int i = 0; n   scanf( %d , &n); n   c = (char*)malloc(sizeof(char) * n); n   while (n--) { n     scanf( %d %d , &ca, &cb); n     if (sb + cb > sa + 500) { n       sa = sa + ca; n       c[i++] =  A ; n     } else { n       sb += cb; n       c[i++] =  G ; n     } n   } n   c[i] =   0 ; n   if (abs(sb - sa) <= 500) n     printf( %s n , c); n   else n     printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void pause() {} n bool sortbysecdesc(const pair<int, int> &a, const pair<int, int> &b) { n   return a.second > b.second; n } n int rec(int n, int i, int a[], int c) { n   c++; n   if (n == i) return c; n   rec(a[n - 1], i, a, c); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     int n, a[1005], c = 0; n     cin >> n; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n     } n     sort(a, a + n); n     for (int i = n - 1; i >= 0; i--) { n       c++; n       if (c == a[i]) { n         cout << c; n         break; n       } else if (c > a[i]) { n         cout << c - 1; n         break; n       } n     } n     cout <<   n ; n   } n   pause(); n } n


#include <bits/stdc++.h> n using namespace std; n int xx[8] = {0, 0, 1, -1, 1, -1, 1, -1}; n int yy[8] = {-1, 1, 0, 0, 1, -1, -1, 1}; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long int n; n   cin >> n; n   bool flag = true; n   vector<long long int> v(n); n   for (long long int i = 0; i < n; i++) cin >> v[i]; n   long long int pos1 = -1, pos2 = -1; n   for (long long int i = 0; i < n; i++) { n     if (v[i] == 1) { n       pos1 = i; n       break; n     } n   } n   if (pos1 == -1) { n     cout <<  0 ; n     return 0; n   } n   for (int j = n - 1; j >= 0; j--) { n     if (v[j] == 1) { n       pos2 = j; n       break; n     } n   } n   long long int c = 1, ans = 1; n   if (pos1 == pos2) { n     cout << 1 <<   n ; n     return 0; n   } else { n     for (long long int i = pos1; i < pos2 + 1; i++) { n       if (v[i] == 0) { n         c++; n       } else { n         ans *= c; n         c = 1; n       } n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int c, v0, v1, a, l; n   cin >> c >> v0 >> v1 >> a >> l; n   int d = 1; n   int r = v0; n   int tmp = v0; n   while (1) { n     if (r >= c) break; n     tmp = tmp + a; n     if (tmp > v1) tmp = v1; n     r += (tmp - l); n     d++; n   } n   cout << d << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2010; n int n, a[N], m; n double f[N][N], p, ans; n inline int read() { n   int x = 0; n   char ch = getchar(); n   while (!isdigit(ch)) ch = getchar(); n   while (isdigit(ch)) x = (x << 3) + (x << 1) + ch - 48, ch = getchar(); n   return x; n } n int main() { n   scanf( %d%lf%d , &n, &p, &m); n   f[0][0] = 1; n   for (int i = 1; i <= m; i++) { n     f[i][0] = (1 - p) * f[i - 1][0]; n     for (int j = 1; j <= n - 1; j++) n       f[i][j] = f[i - 1][j] * (1 - p) + f[i - 1][j - 1] * p; n     f[i][n] = f[i - 1][n] + f[i - 1][n - 1] * p; n   } n   for (int i = 1; i <= n; i++) ans += f[m][i] * i; n   printf( %lf , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2200; n char s[MAXN], t[MAXN]; n int l[MAXN], r[MAXN]; n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     int n, k, m = 0; n     scanf( %d%d%s , &n, &k, s + 1); n     for (int i = 1; i < k; i++) t[2 * i - 1] =  ( , t[2 * i] =  ) ; n     for (int i = 2 * k - 1; i < k + n / 2; i++) t[i] =  ( ; n     for (int i = k + n / 2; i <= n; i++) t[i] =  ) ; n     for (int i = 1; i <= n; i++) n       if (s[i] != t[i]) { n         int k; n         for (int j = i + 1; j <= n; j++) n           if (s[j] == t[i]) { n             k = j; n             break; n           } n         l[++m] = i; n         r[m] = k; n         reverse(s + i, s + k + 1); n       } n     printf( %d n , m); n     for (int i = 1; i <= m; i++) printf( %d %d n , l[i], r[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:256000000 ) n using namespace std; n long long mulmod(long long a, long long b, long long MOD) { n   if (b == 0) return 0; n   long long res = mulmod(a, b >> 1, MOD); n   res += res; n   res %= MOD; n   return (b & 1) ? (a + res) % MOD : res; n } n int main() { n   ios::sync_with_stdio(0); n   long long t1, t2, x1, x2, t0; n   cin >> t1 >> t2 >> x1 >> x2 >> t0; n   long long ans1 = 3000000000000ll, ans2 = 1, ii = 0, jj = 0; n   if (t1 == t0) { n     if (t2 == t0) { n       cout << x1 <<     << x2 << endl; n       return 0; n     } else { n       cout << x1 <<     << 0 << endl; n       return 0; n     } n   } n   if (t2 == t0) { n     cout << 0 <<     << x2 << endl; n     return 0; n   } n   if (t0 <= t1) { n     ii = x1; n     jj = 0; n     ans1 = x1 * t1; n     ans2 = x1; n   } n   if (t0 <= t2 && n       (ans1 == 3000000000000ll || (t2 < t1 || (t2 == t1 && x2 > x1)))) { n     ii = 0; n     jj = x2; n     ans1 = x2 * t2; n     ans2 = x2; n   } n   for (long long i = 0; i <= x1; i++) { n     long long j = (i * (t0 - t1)) / (t2 - t0); n     if ((i * (t0 - t1)) % (t2 - t0) != 0) { n       j++; n     } n     if (i == 0 && j == 0) continue; n     if (j < 0 || j > x2) { n       continue; n     } n     if (ans1 * (i + j) > (i * t1 + j * t2) * ans2) { n       ans1 = (i * t1 + j * t2); n       ans2 = (i + j); n       ii = i; n       jj = j; n     } else { n       if (ans1 * (i + j) == (i * t1 + j * t2) * ans2 && ans2 < (i + j)) { n         ans1 = (i * t1 + j * t2); n         ans2 = (i + j); n         ii = i; n         jj = j; n       } n     } n   } n   cout << ii <<     << jj << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, k; n   cin >> n >> k; n   map<long long, long long> row, col; n   row.clear(); n   col.clear(); n   long long aRow = 0, aCol = 0, res = n * n; n   while (k--) { n     long long x, y; n     cin >> x >> y; n     if (!row[x] && !col[y]) { n       row[x] = 1; n       col[y] = 1; n       res -= (2 * n - 1 - aRow - aCol); n       aRow++; n       aCol++; n       cout << res; n     } else if (row[x] && col[y]) { n       cout << res; n     } else if (row[x]) { n       res -= (n - aRow); n       col[y] = 1; n       aCol++; n       cout << res; n     } else if (col[y]) { n       res -= (n - aCol); n       row[x] = 1; n       aRow++; n       cout << res; n     } n     if (k) n       cout <<    ; n     else n       cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int l, r; n   cin >> l >> r; n   int a{r}, b{max(r / 2 + 1, l)}; n   cout << a % b <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int t{1}; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, d, start = 0; n   cin >> n >> d; n   vector<string> s(d); n   for (string &e : s) cin >> e; n   vector<int> win(d); n   for (int i = 0; i < s.size(); i++) { n     string q = s[i]; n     if (q.find( 0 ) <= q.length()) { n       win[start]++; n     } else { n       start++; n     } n   } n   sort(win.begin(), win.end(), greater<int>()); n   cout << win[0] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n struct arra { n   long long int d = 0, idx; n } arr[200008]; n bool comp(struct arra a, struct arra b) { return a.d > b.d; } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long n, k, a, temp, ans; n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     cin >> a; n     arr[a].d++; n     arr[a].idx = a; n   } n   sort(arr, arr + 200005, comp); n   long long int l = 1, r = 200008, mid; n   while (l <= r) { n     mid = (l + r) / 2; n     temp = 0; n     for (int i = 0; i < n; i++) { n       temp += arr[i].d / mid; n     } n     if (temp >= k) { n       ans = mid; n       l = mid + 1; n     } else n       r = mid - 1; n   } n   vector<long long> v; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < arr[i].d / ans; j++) { n       v.push_back(arr[i].idx); n     } n   } n   for (int i = 0; i < k; i++) cout << v[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool solve(int cn) { n   int n, k; n   cin >> n >> k; n   vector<int> soldiers(n); n   for (int i = (0); i < (n); i++) cin >> soldiers[i]; n   soldiers.push_back(1 << 30); n   int coins = 0; n   while (soldiers[0] < k) { n     coins++; n     for (int i = (0); i < (n); i++) { n       while (soldiers[i] == soldiers[i + 1]) i++; n       soldiers[i]++; n     } n   } n   cout << coins << endl; n   return 0; n } n int main() { n   int cases = 1 << 30; n   if (!cases) cin >> cases; n   for (int cn = 1; cn <= cases && solve(cn); ++cn) n     ; n   return 0; n } n


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


#include <iostream> n #include <vector> n #include <set> n #include <algorithm> n using namespace std; n typedef long long ll; n typedef pair<ll, ll> P; n const int maxn = 105; n int n, m, k; n vector<set<int>> mp(maxn); n vector<int> g, ans; n int vis[maxn], pre[maxn], pres[maxn][maxn*maxn]; n ll dp[maxn][maxn*maxn]; n P query[maxn]; n int c = 0; n bool found(int u, int t){ n     vis[u] = t; n     for(set<int>::iterator i = mp[u].begin(); i != mp[u].end(); i++){ n         int v = *i; n         if(vis[v] == t)    continue; n         vis[v] = t; n         if(pre[v] == 0 || found(pre[v], t)){ n             pre[v] = u; n             return true; n         } n     } n     return false; n } n int main(){ n  scanf( %d%d%d , &n, &m, &k); n  for(int i = 1; i <= m; i++){ n   int u, v; n   scanf( %d%d , &u, &v); n   mp[u].insert(v+n); n  } n  for(int i = 1; i <= k; i++){ n   scanf( %lld%lld , &query[i].first, &query[i].second); n  } n  for(int i = 1; i <= n; i++){ n   if(found(i, i)) c++;  n  } n  for(int i = c; i >= 1; i--){ n   if(i == 1)  n    int a = 1; n   int now; n   static vector<set<int>> _mp; n   _mp = mp; n    n   for(int j = 1; j <= n; j++){ n    int cnt = 0; n    mp = _mp; n    mp[j].clear(); n    if(i == 1 && j == 1){ n     int a = 1; n    } n    for(int i = 1; i <= 2*n; i++) vis[i] = pre[i] = 0; n    for(int k = 1; k <= n; k++){ n     if(found(k, k)) cnt++;  n    } n    if(cnt < i) now = j; n    mp = _mp, cnt = 0; n    for(int k = 1; k <= n; k++){ n     mp[k].erase(j+n); n    } n    for(int i = 1; i <= 2*n; i++) vis[i] = pre[n+i] = 0; n    for(int k = 1; k <= n; k++){ n     if(found(k, k)) cnt++;  n    } n    if(cnt < i) now = -j; n   } n   mp = _mp; n   if(now < 0){ n    for(int k = 1; k <= n; k++){ n     mp[k].erase(-now+n); n    } n   }else{ n    mp[now].clear(); n   } n   g.push_back(now); n  } n  reverse(g.begin(), g.end()); n  for(int i = 0; i <= c; i++) dp[0][i] = -1e9-7; n  dp[0][c] = 0; n  for(int i = 0; i < k; i++){ n   for(int j = 0; j <= c; j++) dp[i+1][j] = -1e9-7; n   for(int j = 0; j <= c; j++){ n    if(dp[i][j] == -1e18-7) continue; n    for(int h = 0; h <= j; h++){ n     if(i + 1 + h >= n) break; n     int t = j - h; n     ll add = max(0ll, query[i+1].first - t * query[i+1].second); n     if(dp[i+1][h] < dp[i][j] + add){ n      dp[i+1][h] = dp[i][j] + add; n      pres[i+1][h] = j; n     } n    } n   } n  } n  int index = max_element(dp[k], dp[k]+c+1) - dp[k]; n  for(int i = k; i >= 1; i--){ n   int cnt = pres[i][index]; n   ans.push_back(0); n   for(int j = index; j < cnt; j++){ n    ans.push_back(g.back());  n    g.pop_back();  n   } n   index = cnt; n  } n  printf( %d n , ans.size()); n  for(int i = ans.size() - 1; i >= 0; i--){ n   printf( %d  , ans[i]); n  } n  return 0; n }


#include <bits/stdc++.h> n int CH, NEG; n template <typename TP> n inline void read(TP& ret) { n   ret = NEG = 0; n   while (CH = getchar(), CH <  ! ) n     ; n   if (CH ==  - ) NEG = true, CH = getchar(); n   while (ret = ret * 10 + CH -  0 , CH = getchar(), CH >  ! ) n     ; n   if (NEG) ret = -ret; n } n int n, data[200010LL], id[200010LL], rank[200010LL], val[200010LL]; n inline bool cmp(const int& a, const int& b) { return data[a] < data[b]; } n int main() { n   int m, i, p, q, l, d, r; n   bool unord; n   read(n), read(m); n   unord = false, data[0] = -2000000001LL; n   for (i = (1); i <= (n); i++) n     if (read(data[i]), id[i] = i, data[i - 1] > data[i]) unord = true; n   if (unord) std::sort(id + 1, id + n + 1, cmp); n   for (i = (1); i <= (n); i++) rank[id[i]] = i, val[i] = data[id[i]]; n   val[n + 1] = 2000000001LL; n   while (m-- > 0) { n     read(p), read(l), p = rank[p]; n     q = std::upper_bound(val, val + n + 2, val[p] + l) - val - 1; n     l -= val[q] - val[p], p = q, d = -1; n     while (true) { n       if (d == 1) n         q = std::upper_bound(val + 1, val + n + 2, val[p] + l * d) - val - 1; n       else n         q = std::lower_bound(val + 1, val + n + 2, val[p] + l * d) - val; n       if (p == q) break; n       if (r = std::abs(val[p] - val[q]), (l / r) & 1) p = q, d = -d; n       l %= r; n     } n     printf( %d n , id[p]); n   } n   getchar(), getchar(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long s[100001]; n int main() { n   int n, c = 1; n   long long sum = 0; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> s[i]; n   sort(s, s + n); n   sum += s[0]; n   for (int i = 1; i < n; i++) { n     if (sum <= s[i]) { n       c++; n       sum += s[i]; n     } n   } n   cout << c; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, k, tlen = 0, dir, i; n   string temp; n   cin >> n >> m >> k; n   cin >> temp >> temp; n   if (temp ==  head ) n     dir = -1; n   else n     dir = 1; n   cin >> temp; n   if (m < k) n     m = 1; n   else n     m = n; n   for (i = 0; i < temp.size(); ++i) { n     if (k == 1) n       dir = 1; n     else if (k == n) n       dir = -1; n     k += dir; n     if (temp[i] !=  1 ) { n       if (k == m) { n         cout <<  Controller   << i + 1; n         return 0; n       } n     } else { n       if (dir == -1) n         m = n; n       else n         m = 1; n     } n   } n   cout <<  Stowaway ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> factors(long long n) { n   vector<long long> first; n   long long tem = 1; n   for (long long x = 2; x * x <= n; x++) { n     while (n % x == 0) { n       first.push_back(x); n       n /= x; n     } n   } n   if (n > 1) first.push_back(n); n   return first; n } n long long stringToint(string str) { n   int num = stoi(str); n   return num; n } n int hamming(int a, int b) { return __builtin_popcount(a ^ b); } n bool cmp(int a, int b) { return a > b; } n void reset() { n   for (int i = 0; i < 200000 + 100; i++) { n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int n, d; n   while (cin >> n >> d) { n     int m; n     cin >> m; n     for (int i = 0, x, y; i < m; i++) { n       cin >> x >> y; n       if (abs(x - y) >= 0 && abs(x - y) <= d && x + y <= n + n - d && n           x + y >= d && (x + y != 0 || x - y != 0)) n         cout <<  YES n ; n       else n         cout <<  NO n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int gcd(long long int a, long long int b) { n   return b ? gcd(b, a % b) : a; n } n long long int lcm(long long int a, long long int b) { n   return a * b / gcd(a, b); n } n int n, cnt[100010]; n int main() { n   scanf( %d , &n); n   set<int> s; n   for (int i = 0; i < n; i++) { n     int x; n     scanf( %d , &x); n     s.insert(x); n     auto itr = s.find(x); n     itr++; n     if (itr == s.end()) n       cnt[x]--; n     else { n       x = *itr; n       itr++; n       if (itr == s.end()) cnt[x]++; n     } n   } n   int ans = 1; n   for (int i = 1; i <= n; i++) n     if (cnt[i] > cnt[ans]) ans = i; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[200200]; n int main() { n   int i, j; n   scanf( %d , &n); n   for (i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   for (i = 1; i < n; i++) { n     if (a[i] % 2) { n       a[i] = 1; n       if (a[i + 1] == 0) { n         cout <<  NO ; n         return 0; n       } else { n         a[i + 1]--; n       } n     } n   } n   if (a[n] % 2) { n     cout <<  NO ; n     return 0; n   } n   cout <<  YES ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100000 + 10; n const int M = 1000000007; n const double PI = atan(1) * 4; n const int oo = 1000000000; n long long A, B, n, x; n long long pw(long long x, long long p) { n   if (!p) return 1; n   long long d = pw(x, p / 2); n   d = (d * d) % M; n   if (p % 2) d = (d * x) % M; n   assert(x <= M); n   assert(d <= M); n   return d; n } n int main() { n   cin >> A >> B >> n >> x; n   if (A == 1) return cout << (n % M * B % M + x) % M, 0; n   long long one = x * pw(A, n) % M; n   long long dom = pw(A, n) - 1; n   long long den = pw(A - 1, M - 2); n   cout << (one + B * ((dom * den) % M) % M) % M << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = M_PI; n const int INF = -1 * 1e9; n const long long limit = 1 * 1e12; n const int MOD1 = 1e9 + 711; n const int MOD2 = 1e9 + 933; n const int MOD3 = 1e9 + 993; n const int maxn = 1e6 + 100; n int main() { n   cout.tie(0); n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   int n; n   cin >> n; n   vector<int> a(n), b(n); n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n     b[i] = a[i]; n   } n   sort(b.begin(), b.end()); n   int cnt = 0; n   for (int i = 0; i < n; ++i) { n     if (a[i] != b[i]) { n       ++cnt; n     } n   } n   if (cnt <= 2) { n     cout <<  YES ; n   } else { n     cout <<  NO ; n   } n   cerr <<   n nTime elapsed:   << 1.0 * clock() / CLOCKS_PER_SEC <<   s. n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long ax, ay, bx, by, cx, cy; n int solve(long long x2, long long y2) { n   if (cx == 0 && cy == 0) { n     if (x2 == 0 && y2 == 0) return 1; n     return 0; n   } else if (cx == 0) { n     long long g, h; n     g = x2 / cy; n     h = y2 / cy; n     if (g * cy == x2 && h * cy == y2) return 1; n     return 0; n   } else if (cy == 0) { n     long long g, h; n     g = x2 / cx; n     h = y2 / cx; n     if (g * cx == x2 && h * cx == y2) return 1; n     return 0; n   } else { n     long long a, b; n     if ((cx * cy + cx * cx) == 0) return 0; n     b = (x2 * cy - y2 * cx) / (cy * cy + cx * cx); n     a = (x2 - b * cy) / cx; n     if (b * (cy * cy + cx * cx) == (x2 * cy - y2 * cx) && n         (a * cx == x2 - b * cy)) { n       return 1; n     } n     return 0; n   } n   return 0; n } n int main() { n   scanf( %lld%lld , &ax, &ay); n   scanf( %lld%lld , &bx, &by); n   scanf( %lld%lld , &cx, &cy); n   if (solve(bx - ax, by - ay)) { n     puts( YES ); n     return 0; n   } n   if (solve(bx + ax, by + ay)) { n     puts( YES ); n     return 0; n   } n   if (solve(bx - ay, by + ax)) { n     puts( YES ); n     return 0; n   } n   if (solve(bx + ay, by - ax)) { n     puts( YES ); n     return 0; n   } n   puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int g[100100]; n int suff[100100]; n char S[1024]; n set<int> crim; n char T[100100]; n int R[100100], neg[100100]; n int main() { n   int n, m, tot = 0; n   scanf( %d , &n); n   scanf( %d , &m); n   for (int i = 0; i < n; i++) { n     scanf( %s , S); n     int l = strlen(S); n     char sign = S[0]; n     int pos = 1, num = 0; n     while (pos < l) { n       num = num * 10 + S[pos] -  0 ; n       pos++; n     } n     num--; n     if (S[0] ==  + ) n       g[num]++; n     else { n       tot++; n       neg[num]++; n     } n     T[i] = S[0]; n     R[i] = num; n   } n   for (int i = 0; i < n; i++) { n     g[i] += tot; n     g[i] -= neg[i]; n   } n   for (int i = 0; i < n; i++) { n     if (g[i] == m) crim.insert(i); n   } n   int prob = crim.size(); n   for (int i = 0; i < n; i++) { n     if (T[i] ==  + ) { n       if (crim.find(R[i]) == crim.end()) { n         puts( Lie ); n       } else { n         if (prob == 1) n           puts( Truth ); n         else n           puts( Not defined ); n       } n     } else { n       if (crim.find(R[i]) == crim.end()) { n         puts( Truth ); n       } else { n         if (prob == 1) n           puts( Lie ); n         else n           puts( Not defined ); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int su[3000000]; n vector<int> vec; n int vv[3000010]; n int main() { n   memset(su, 0, sizeof(su)); n   memset(vv, 0, sizeof(vv)); n   vec.push_back(2); n   for (int i = 3; i <= 2750131; i++) { n     for (int j = 0; j < vec.size(); j++) { n       if (vec[j] * vec[j] > i) break; n       if (i % vec[j] == 0) { n         su[i] = i / vec[j]; n         break; n       } n     } n     if (su[i] == 0) vec.push_back(i); n   } n   int n; n   scanf( %d , &n); n   int h_sum = 2 * n; n   for (int i = 1; i <= 2 * n; i++) { n     int x; n     scanf( %d , &x); n     vv[x]++; n   } n   for (int i = 2750131; i >= 2; i--) { n     while (su[i] && vv[i]) { n       printf( %d  , i); n       vv[i]--; n       vv[su[i]]--; n       h_sum -= 2; n     } n   } n   for (int i = 2750131; i >= 2; i--) { n     if (h_sum == 0) break; n     while (vv[i]) { n       int k = lower_bound(vec.begin(), vec.end(), i) - vec.begin() + 1; n       printf( %d  , k); n       vv[i]--; n       vv[k]--; n       h_sum -= 2; n       if (h_sum == 0) break; n     } n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   int n; n   cin >> n; n   vector<pair<int, int>> d(n); n   for (auto &i : d) cin >> i.first, i.second = &i - &d[0] + 1; n   sort(d.begin(), d.end()); n   vector<pair<int, int>> e; n   vector<int> a; n   a.push_back(2 * d.back().second - 1); n   for (int i = 1; i < d.back().first; ++i) a.push_back(-1); n   a.push_back(2 * d.back().second); n   int l = 0, r = a.size() - 1; n   d.pop_back(); n   while (!d.empty()) { n     auto p = d.back(); n     d.pop_back(); n     if (a[l + 1] == -1) { n       ++l; n       a[l] = 2 * p.second - 1; n       if (p.first == r - l + 1) { n         ++r; n         a.push_back(2 * p.second); n       } else { n         e.push_back({l + p.first - 1, 2 * p.second}); n       } n     } else { n       ++r; n       a.push_back(2 * p.second); n       e.push_back({r - p.first + 1, 2 * p.second - 1}); n     } n   } n   for (size_t i = 1; i < a.size(); ++i) cout << a[i - 1] <<     << a[i] <<   n ; n   for (auto &i : e) cout << a[i.first] <<     << i.second <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int count, i, a, x, max, tc; n   scanf( %d , &tc); n   for (int j = 0; j < tc; j++) { n     count = 0, max = 0; n     scanf( %d , &x); n     char s[x]; n     scanf( %s , s); n     for (i = x - 1; i >= 0; i--) { n       if (s[i] ==  P ) { n         count += 1; n       } else { n         if (count > max) { n           max = count; n         } n         count = 0; n       } n     } n     printf( %d n , max); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 23e4 + 5; n int sum[M], n, fen[M]; n int Get(int p) { n   int u = p; n   int ans = 0; n   for (; p > 0; p -= p & -p) ans += fen[p]; n   for (u++; u < M; u += u & -u) fen[u]++; n   return ans; n } n int get(int p) { n   int cur = 0; n   for (int i = 17; ~i; i--) { n     int d = cur + (1 << i); n     if (fen[d] <= p) p -= fen[d], cur = d; n   } n   int u = cur; n   for (u++; u < M; u += u & -u) fen[u]--; n   return cur; n } n int32_t main() { n   scanf( %d , &n); n   int t = 2; n   while (t--) { n     memset(fen, 0, sizeof fen); n     for (int i = 0; i < n; i++) { n       int x; n       scanf( %d , &x); n       sum[i] += x - Get(x); n     } n   } n   int sb = 0; n   for (int i = n - 1; ~i; i--) { n     sum[i] += sb; n     int k = sum[i] % (n - i); n     sb = (sum[i] - k) / (n - i); n     sum[i] = k; n   } n   for (int i = 1; i < M; i++) fen[i] = i & -i; n   for (int i = 0; i < n; i++) printf( %d  , get(sum[i])); n   return printf(  n ), 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n long long pos = -1; n const long long N = 5005; n long long gundy[N]; n long long mex[N]; n void game() { n   long long len = s.length(); n   long long totXo = 0; n   gundy[0] = 0; n   for (long long i = 1; i < N; i++) { n     for (long long j = 0; j < N; j++) mex[j] = 0; n     for (long long j = 0; j < i; j++) { n       long long l = max(0LL, j - 1); n       long long r = max(0LL, i - j - 2); n       long long xo = gundy[l] ^ gundy[r]; n       if (xo < N) mex[xo] = 1; n     } n     long long gv = 0; n     while (gv < N && mex[gv] == 1) gv++; n     gundy[i] = gv; n   } n   for (long long i = 1; i < len - 1; i++) { n     if (s[i - 1] == s[i + 1]) { n       long long j = i; n       while (j + 2 < len && s[j] == s[j + 2]) j++; n       totXo ^= gundy[j - i + 1]; n       i = j + 1; n     } n   } n   if (totXo == 0) n     cout <<  Second  n          <<   n ; n   else { n     cout <<  First  n          <<   n ; n     for (long long i = 1; i < len - 1; i++) { n       if (s[i - 1] == s[i + 1]) { n         long long j = i; n         while (j + 2 < len && s[j] == s[j + 2]) j++; n         long long span = j - i + 1; n         long long remXo = totXo ^ gundy[span]; n         for (long long k = 0; k < span; k++) { n           long long l = max(0LL, k - 1LL); n           long long r = max(0LL, span - k - 2LL); n           long long xo = gundy[l] ^ gundy[r] ^ remXo; n           if (xo == 0) { n             pos = i + k + 1; n             cout << pos <<   n ; n             return; n           } n         } n         i = j + 1; n       } n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   cin >> s; n   game(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   long long a = 0; n   long long ret = 0; n   long long x = n; n   while (x >= 10) { n     a = a * 10 + 9; n     ret += 9; n     x /= 10; n   } n   long long y = n - a; n   while (y) { n     ret += y % 10; n     y /= 10; n   } n   cout << ret << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     long long int n, z = 0, o = 0; n     cin >> n; n     string s; n     cin >> s; n     if (n == 1) { n       cout << s << endl; n       continue; n     } n     for (long long int i = 0; i < n; i++) { n       if (s[i] ==  0 ) n         z++; n       else n         break; n     } n     z++; n     for (long long int i = n - 1; i >= 0; i--) { n       if (s[i] ==  1 ) n         o++; n       else n         break; n     } n     if (o + z == n + 1) { n       cout << s << endl; n       continue; n     } n     while (z) { n       cout <<  0 ; n       z--; n     } n     while (o) { n       cout <<  1 ; n       o--; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int S = 100003; n const int MOD = 1e9 + 7; n const double pi = 2 * acos(0.0); n inline int _Int() { n   int x; n   scanf( %d , &x); n   return x; n } n inline long long _LLi() { n   long long x; n   scanf( %lld , &x); n   return x; n } n void pruts() { n   puts( NO ); n   exit(EXIT_SUCCESS); n } n int dirX[] = {1, 0, -1, 0, 1, -1, 1, -1}; n int dirY[] = {0, 1, 0, -1, 1, -1, -1, 1}; n int rX[] = {1, 1, 2, 2, -1, -1, -2, -2}; n int rY[] = {2, -2, 1, -1, 2, -2, 1, -1}; n template <class T> n T tri_Area(T x1, T y1, T x2, T y2, T x3, T y3) { n   return abs(x1 * (y2 - y3) - y1 * (x2 - x3) + (x2 * y3 - x3 * y2)); n }; n template <class T> n T Distance(T x1, T y1, T x2, T y2) { n   return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); n }; n template <class T> n T bigMod(T n, T p, T m) { n   if (p == 0) return 1; n   if (p & 1) return (n * bigMod(n, p - 1, m)) % m; n   T x = bigMod(n, p / 2, m); n   return (x * x) % m; n }; n int sset(int N, int pos) { return N = N | (1 << pos); } n bool check(int N, int pos) { return (bool)(N & (1 << pos)); } n int reset(int N, int pos) { return N = N & ~(1 << pos); } n void Hunger() { n   int a = _Int(); n   int b = _Int(); n   if (!a && !b) pruts(); n   puts((abs(a - b) <= 1) ?  YES  :  NO ); n } n int main() { n   Hunger(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k, A, B, ans = 0; n long long fmin() { n   long long pros = (n - (n / k)) * A; n   if (B < pros) { n     n = n / k; n     return B; n   } else { n     n = n / k; n     return pros; n   } n } n int main() { n   cin >> n; n   cin >> k; n   cin >> A; n   cin >> B; n   if (k == 1) { n     cout << (n - 1) * A; n     return 0; n   } n   while (n != 1) { n     if (n >= k) { n       if (n % k == 0) { n         ans += fmin(); n       } else { n         long long t = (n % k); n         n = n - t; n         ans += (A * t); n       } n     } else { n       ans = ans + (n - 1) * A; n       n = 1; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long s = 0, t = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) t = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) n     s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar(); n   return s * t; n } n const int N = 1e5 + 5; n const long long inf = 0x3f3f3f3f3f3f3f3f; n int n, top, Len = 1, s[N], nxt[N]; n long long K, w[N], g[N], pre[N], suf[N]; n vector<int> G[N]; n long long a[N << 2], b[N << 2], d[N << 2], res[N << 2]; n void Init(int x, long long t) { b[x] += t, res[x] -= t, d[x] += t; } n void Pushdown(int x) { n   if (!d[x]) return; n   Init(x << 1, d[x]), Init(x << 1 | 1, d[x]), d[x] = 0; n } n long long Calc(int x, int l, int r, long long t) { n   if (l == r) return a[x] - t; n   int mid = (l + r) >> 1; n   Pushdown(x); n   if (b[x << 1] < t) return min(Calc(x << 1, l, mid, t), res[x]); n   return min(a[x << 1] - t, Calc(x << 1 | 1, mid + 1, r, t)); n } n void Build(int x, int l, int r) { n   if (l == r) { n     a[x] = b[x] = suf[l]; n     return; n   } n   int mid = (l + r) >> 1; n   Build(x << 1, l, mid), Build(x << 1 | 1, mid + 1, r); n   a[x] = min(a[x << 1], a[x << 1 | 1]), b[x] = min(b[x << 1], b[x << 1 | 1]); n   res[x] = Calc(x << 1 | 1, mid + 1, r, b[x << 1]); n } n void Upd(int x, int l, int r, int ql, int qr, long long t) { n   if (ql <= l && r <= qr) { n     Init(x, t); n     return; n   } n   int mid = (l + r) >> 1; n   Pushdown(x); n   if (ql <= mid) Upd(x << 1, l, mid, ql, qr, t); n   if (qr > mid) Upd(x << 1 | 1, mid + 1, r, ql, qr, t); n   b[x] = min(b[x << 1], b[x << 1 | 1]), n   res[x] = Calc(x << 1 | 1, mid + 1, r, b[x << 1]); n } n int Find(int x, int l, int r, long long t) { n   if (l == r) return l; n   int mid = (l + r) >> 1; n   Pushdown(x); n   return a[x << 1 | 1] <= t ? Find(x << 1 | 1, mid + 1, r, t) n                             : Find(x << 1, l, mid, t); n } n int Solve(int x, int l, int r, long long &t) { n   if (l == r) { n     int tp = a[x] - t <= K ? l : 0; n     return t = min(t, b[x]), tp; n   } n   int mid = (l + r) >> 1; n   Pushdown(x); n   if (b[x << 1] < t) { n     if (res[x] <= K) return Solve(x << 1 | 1, mid + 1, r, t = b[x << 1]); n     int tp = Solve(x << 1, l, mid, t); n     return t = min(t, b[x]), tp; n   } else { n     int tp = a[x << 1] <= K + t ? Find(x << 1, l, mid, K + t) : 0; n     return max(tp, Solve(x << 1 | 1, mid + 1, r, t)); n   } n } n void DFS(int x) { n   s[++top] = x; n   if (nxt[x] <= n) Upd(1, 1, n, nxt[x] - 1, n, pre[x] - pre[nxt[x]]); n   if (x <= n) { n     int l = 2, r = top - 1, res = 1; n     while (l <= r) { n       int mid = (l + r) >> 1; n       if (pre[s[mid]] - pre[x] > K) n         res = mid, l = mid + 1; n       else n         r = mid - 1; n     } n     int lim = s[res] - 1; n     if (x > 1) Upd(1, 1, n, 1, x - 1, inf); n     Upd(1, 1, n, lim, n, -inf); n     long long tp = inf; n     int pos = Solve(1, 1, n, tp); n     if (x > 1) Upd(1, 1, n, 1, x - 1, -inf); n     Upd(1, 1, n, lim, n, inf); n     Len = max(Len, pos - x + 1); n   } n   for (auto y : G[x]) DFS(y); n   if (nxt[x] <= n) Upd(1, 1, n, nxt[x] - 1, n, pre[nxt[x]] - pre[x]); n   top--; n } n int main() { n   n = read(), K = read(); n   for (int i = 1; i < n; i++) w[i] = read(); n   for (int i = 1; i <= n; i++) g[i] = read(); n   for (int i = 2; i <= n; i++) { n     pre[i] = pre[i - 1] + w[i - 1] - g[i - 1]; n     suf[i] = suf[i - 1] + w[i - 1] - g[i]; n   } n   for (int i = n; i >= 1; i--) { n     while (top && pre[s[top]] <= pre[i]) top--; n     nxt[i] = top ? s[top] : n + 1, s[++top] = i; n     G[nxt[i]].push_back(i); n   } n   nxt[n + 1] = n + 1, top = 0; n   Build(1, 1, n), DFS(n + 1), printf( %d , Len); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const double EPS = 1e-9; n const int INF = 1 << 29; n int main() { n   int x1, y1, x2, y2; n   cin >> x1 >> y1 >> x2 >> y2; n   int x, y; n   cin >> x >> y; n   int dx = abs(x1 - x2), dy = abs(y1 - y2); n   if (dx % x || dy % y) { n     puts( NO ); n     return 0; n   } n   int t = dx / x - dy / y; n   if (t & 1) { n     puts( NO ); n   } else { n     puts( YES ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a, s, d[100002], f, g, h, j, k, l, i, n, m; n string x; n int main() { n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> d[i]; n   } n   for (i = 0; i < n; i++) { n     scanf(  n ); n     getline(cin, x); n     for (a = 0; a < x.size(); a++) { n       if (x[a] ==  a ) d[i]--; n       if (x[a] ==  e ) d[i]--; n       if (x[a] ==  i ) d[i]--; n       if (x[a] ==  o ) d[i]--; n       if (x[a] ==  u ) d[i]--; n       if (x[a] ==  y ) d[i]--; n     } n     if (d[i] != 0) { n       cout <<  NO ; n       return 0; n     } n   } n   cout <<  YES ; n } n


#include <bits/stdc++.h> n using namespace std; n bool v[1005][1005][4][3]; n char grid[1005][1005]; n int dx[] = {1, -1, 0, 0}; n int dy[] = {0, 0, 1, -1}; n int n, m; n int xx, yy; n bool dfs(int x, int y, int dir, int turns) { n   if (x < 0 || x == n || y < 0 || y == m || turns > 2 || grid[x][y] ==  * ) n     return false; n   if (v[x][y][dir][turns]) return false; n   v[x][y][dir][turns] = true; n   if (x == xx && y == yy) return true; n   bool can = false; n   for (int i = 0; i < 4; i++) n     can |= dfs(x + dx[i], y + dy[i], i, turns + (i != dir)); n   return can; n } n int main() { n   cin >> n >> m; n   pair<int, int> second, t; n   for (int i = 0; i < n; i++) { n     scanf( %s , grid[i]); n     for (int j = 0; j < m; j++) { n       if (grid[i][j] ==  S ) n         second = make_pair(i, j); n       else if (grid[i][j] ==  T ) n         t = make_pair(i, j); n     } n   } n   xx = t.first, yy = t.second; n   if (dfs(second.first, second.second, 0, 0) || n       dfs(second.first, second.second, 1, 0) || n       dfs(second.first, second.second, 2, 0) || n       dfs(second.first, second.second, 3, 0)) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 300000; n vector<long long> st; n void add(vector<long long>& st, int x, long long inc) { n   while (x < st.size()) { n     st[x] += inc; n     x |= x + 1; n   } n } n long long sum(const vector<long long>& st, int x) { n   long long s = 0; n   while (x >= 0) { n     s += st[x]; n     x = (x & (x + 1)) - 1; n   } n   return s; n } n void insert(int l, int r, long long p) { n   add(st, r + 1, -p); n   add(st, l, p); n } n int n, m, k; n int l[maxn], r[maxn]; n long long d[maxn]; n pair<int, int> a[maxn]; n long long p[maxn]; n int main() { n   cin >> n >> m >> k; n   st.resize(n + 3); n   for (int i = 1; i <= n; i++) scanf( %I64d , &p[i]); n   for (int i = 1; i <= m; i++) { n     scanf( %d%d%I64d , &l[i], &r[i], &d[i]); n   } n   for (int i = 1; i <= k; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     a[i] = make_pair(x, -1); n     a[i + k] = make_pair(y + 1, 1); n   } n   sort(a + 1, a + 1 + 2 * k); n   int sta = 1, tot = 0; n   for (int i = 1; i <= m; i++) { n     while (sta <= 2 * k && a[sta].first == i) tot -= a[sta++].second; n     insert(l[i], r[i], d[i] * tot); n   } n   for (int i = 1; i <= n; i++) printf( %I64d  , sum(st, i) + p[i]); n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O2 ) n using namespace std; n void dfs(long long int par, long long int node, n          vector<pair<long long int, string>> adj[], n          vector<long long int> &nodes, vector<bool> &visited) { n   visited[node] = true; n   nodes.push_back(node); n   for (auto child : adj[node]) { n     if (!visited[abs(child.first)]) { n       dfs(node, abs(child.first), adj, nodes, visited); n     } n   } n } n void dfs2(long long int par, long long int node, string role, n           vector<pair<long long int, string>> adj[], bool &ok, n           vector<bool> &visited2, long long int &cnt, vector<string> &cr) { n   for (auto child : adj[node]) { n     if (child.first > 0) { n       if (visited2[node] && (!visited2[child.first])) { n         visited2[child.first] = true; n         if (cr[node] ==  imposter ) { n           string childRole = n               child.second ==  imposter  ?  crewmate  :  imposter ; n           cr[child.first] = childRole; n           dfs2(node, child.first, childRole, adj, ok, visited2, cnt, cr); n         } else { n           string childRole = n               child.second ==  imposter  ?  imposter  :  crewmate ; n           cr[child.first] = childRole; n           dfs2(node, child.first, childRole, adj, ok, visited2, cnt, cr); n         } n       } else if ((!visited2[node]) && visited2[child.first]) { n         visited2[node] = true; n         if (cr[child.first] ==  imposter ) { n           string childRole = n               child.second ==  imposter  ?  crewmate  :  imposter ; n           cr[node] = childRole; n         } else { n           string childRole = n               child.second ==  imposter  ?  imposter  :  crewmate ; n           cr[node] = childRole; n         } n       } else if (visited2[child.first] && visited2[node]) { n         if (cr[child.first] ==  imposter ) { n           if (cr[node] ==  imposter  && child.second ==  imposter ) { n             ok = false; n             return; n           } else if (cr[node] ==  crewmate  && child.second ==  crewmate ) { n             ok = false; n             return; n           } n         } else { n           if (cr[node] ==  imposter  && child.second ==  crewmate ) { n             ok = false; n             return; n           } else if (cr[node] ==  crewmate  && child.second ==  imposter ) { n             ok = false; n             return; n           } n         } n       } n       if (!ok) { n         return; n       } n     } n   } n   for (auto child : adj[node]) { n     if (child.first < 0) { n       if ((!visited2[abs(child.first)]) && visited2[node] == true) { n         dfs2(node, abs(child.first),  imposter , adj, ok, visited2, cnt, cr); n       } n     } n     if (!ok) { n       return; n     } n   } n   for (auto child : adj[node]) { n     if (child.first > 0) { n       if (visited2[node] && (!visited2[child.first])) { n         visited2[child.first] = true; n         if (cr[node] ==  imposter ) { n           string childRole = n               child.second ==  imposter  ?  crewmate  :  imposter ; n           cr[child.first] = childRole; n           dfs2(node, child.first, childRole, adj, ok, visited2, cnt, cr); n         } else { n           string childRole = n               child.second ==  imposter  ?  imposter  :  crewmate ; n           cr[child.first] = childRole; n           dfs2(node, child.first, childRole, adj, ok, visited2, cnt, cr); n         } n       } else if (visited2[child.first] && visited2[node]) { n         if (cr[child.first] ==  imposter ) { n           if (cr[node] ==  imposter  && child.second ==  imposter ) { n             ok = false; n             return; n           } else if (cr[node] ==  crewmate  && child.second ==  crewmate ) { n             ok = false; n             return; n           } n         } else { n           if (cr[node] ==  imposter  && child.second ==  crewmate ) { n             ok = false; n             return; n           } else if (cr[node] ==  crewmate  && child.second ==  imposter ) { n             ok = false; n             return; n           } n         } n       } n     } n     if (!ok) { n       return; n     } n   } n } n void answerNikalBc(long long int t1) { n   long long int n, m; n   cin >> n >> m; n   map<pair<long long int, long long int>, string> mp; n   vector<pair<long long int, string>> adj[n + 1]; n   bool ok = true; n   for (long long int i = 1; i <= m; i++) { n     long long int u, v; n     string s; n     cin >> u >> v >> s; n     if (mp.find({u, v}) == mp.end()) { n       adj[u].push_back({v, s}); n       adj[v].push_back({-1 * u, s}); n       mp[{u, v}] = s; n     } else { n       if (mp[{u, v}] == s) { n         continue; n       } else { n         ok = false; n       } n     } n   } n   if (!ok) { n     cout << -1 <<   n ; n     return; n   } n   long long int ans = 0; n   vector<bool> visited(n + 1, false); n   vector<bool> visited2(n + 1, false); n   vector<string> childRole(n + 1,  imposter ); n   for (long long int i = 1; i <= n; i++) { n     if (!visited[i]) { n       vector<long long int> nodes; n       dfs(-1, i, adj, nodes, visited); n       bool init = false; n       long long int cnt1 = 0, cnt2 = 0; n       for (long long int j = 0; j < nodes.size(); j++) { n         if (!visited2[nodes[j]]) { n           if (!init) { n             visited2[nodes[j]] = true; n             childRole[nodes[j]] =  imposter ; n             dfs2(-1, nodes[j],  imposter , adj, ok, visited2, cnt1, childRole); n             init = true; n           } else { n             dfs2(-1, nodes[j],  imposter , adj, ok, visited2, cnt1, childRole); n           } n         } n       } n       for (auto a : nodes) { n         visited2[a] = false; n       } n       for (auto a : nodes) { n         if (childRole[a] ==  imposter ) { n           cnt1++; n         } n       } n       init = false; n       for (long long int j = 0; j < nodes.size(); j++) { n         if (!visited2[nodes[j]]) { n           if (!init) { n             visited2[nodes[j]] = true; n             childRole[nodes[j]] =  crewmate ; n             dfs2(-1, nodes[j],  crewmate , adj, ok, visited2, cnt2, childRole); n             init = true; n           } else { n             dfs2(-1, nodes[j],  crewmate , adj, ok, visited2, cnt2, childRole); n           } n         } n       } n       for (auto a : nodes) { n         if (childRole[a] ==  imposter ) { n           cnt2++; n         } n       } n       if (!ok) { n         cout << -1 <<   n ; n         return; n       } n       ans += (max(cnt1, cnt2)); n     } n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int t; n   t = 1; n   cin >> t; n   for (long long int i = 1; i <= t; i++) { n     answerNikalBc(t); n   } n   cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000 * 100 + 10; n int a[MAXN], b[MAXN]; n int dp[MAXN][310]; n vector<int> vec1[MAXN], vec[MAXN]; n long long n, m, second, E; n bool ok(int k) { n   long long need = second; n   for (int i = k - 1; i < n; i++) n     if (dp[i][k] < m) need = min(need, (long long)(i + 1 + dp[i][k] + 1)); n   need += k * E; n   if (need <= second) return true; n   return false; n } n int bs(int s, int e) { n   if (e - s <= 1) return s; n   int m = (s + e) / 2; n   return ok(m) ? bs(m, e) : bs(s, m); n } n int main() { n   cin >> n >> m >> second >> E; n   for (int i = 0; i < n; i++) cin >> a[i], vec1[a[i]].push_back(i); n   for (int i = 0; i < m; i++) cin >> b[i], vec[b[i]].push_back(i); n   for (int i = 0; i < MAXN; i++) vec[i].push_back(m); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < 301; j++) dp[i][j] = m; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < min(min((int)m, i + 1), 300) + 1; j++) { n       if (j == 0) n         dp[i][j] = -1; n       else if (i == 0) n         dp[i][j] = n             vec[a[i]][lower_bound(vec[a[i]].begin(), vec[a[i]].end(), 0) - n                       vec[a[i]].begin()]; n       else n         dp[i][j] = n             min(dp[i - 1][j], n                 (dp[i - 1][j - 1] >= m) n                     ? (int)m n                     : vec[a[i]] n                          [(int)(lower_bound(vec[a[i]].begin(), vec[a[i]].end(), n                                             dp[i - 1][j - 1] + 1) - n                                 vec[a[i]].begin())]); n     } n   cout << bs(0, min({(int)m, (int)n, 300}) + 1) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int readInt() { n   char c; n   int tmp = 0, x = 1; n   c = getchar(); n   while (c >  9  || c <  0 ) { n     if (c ==  - ) x = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     tmp = tmp * 10 + c -  0 ; n     c = getchar(); n   } n   return tmp * x; n } n const int maxN = 2000 + 10; n const int maxM = 100000 + 10; n int Head[maxN], eg[maxM << 1], nxt[maxM << 1], tot = 1; n void addEdge(int u, int v) { n   eg[++tot] = v; n   nxt[tot] = Head[u]; n   Head[u] = tot; n   eg[++tot] = u; n   nxt[tot] = Head[v]; n   Head[v] = tot; n } n bool isbri[maxM << 2]; n int dfn[maxN], low[maxN], dfsclock = 0; n void tarjan(int v, int InEdge) { n   dfn[v] = low[v] = ++dfsclock; n   for (int i = Head[v]; i; i = nxt[i]) { n     int u = eg[i]; n     if (!dfn[u]) { n       tarjan(u, i); n       low[v] = min(low[v], low[u]); n       if (low[u] > dfn[v]) isbri[i] = isbri[i ^ 1] = true; n     } else if (i != (InEdge ^ 1)) n       low[v] = min(low[v], dfn[u]); n   } n } n int bccno[maxN], num = 0, bccsiz[maxN]; n void dfs(int v) { n   bccno[v] = num; n   bccsiz[num]++; n   for (int i = Head[v]; i; i = nxt[i]) { n     int u = eg[i]; n     if (!bccno[u] && !isbri[i]) dfs(u); n   } n } n vector<int> g[maxN]; n void new_addEdge(int u, int v) { n   g[u].push_back(v); n   g[v].push_back(u); n } n bool vis[maxN], isLeaf[maxN]; n int tmp = 0, tmpmax = -1, tmpleaf = 0, Leaf[maxN], siz[maxN], rot[maxN], n     cnt = 0, Fa[maxN], Belong[maxN]; n void predfs(int v, int fa) { n   siz[v] = 1; n   Fa[v] = fa; n   Belong[v] = cnt; n   if ((int)g[v].size() == 0 || (int)g[v].size() == 1) n     Leaf[cnt]++, isLeaf[v] = true; n   for (int i = 0; i < (int)g[v].size(); i++) { n     int u = g[v][i]; n     if (u != fa) predfs(u, v), siz[v] += siz[u]; n   } n } n void FindLongest(int v, int fa, int D, int lev) { n   if (tmp < D) tmp = D, tmpmax = v, tmpleaf = lev; n   for (int i = 0; i < (int)g[v].size(); i++) { n     int u = g[v][i]; n     if (u != fa) FindLongest(u, v, D + (!isLeaf[u]), lev + isLeaf[u]); n   } n } n int FindDiameter(int v) { n   tmp = 0, tmpmax = -1; n   for (int i = 0; i < (int)g[v].size(); i++) { n     int u = g[v][i]; n     FindLongest(u, v, 1, 0); n   } n   if (!(~tmpmax)) return 0; n   int vv = tmpmax; n   tmp = 0, tmpmax = -1, tmpleaf = 0; n   FindLongest(vv, -1, 1, isLeaf[vv]); n   return tmp - tmpleaf; n } n int n, m; n int main() { n   n = readInt(), m = readInt(); n   int u, v; n   for (int i = 1; i <= m; i++) { n     u = readInt(), v = readInt(); n     addEdge(u, v); n   } n   for (int i = 1; i <= n; i++) { n     if (!dfn[i]) tarjan(i, 0); n   } n   for (int i = 1; i <= n; i++) { n     if (!bccno[i]) { n       num++; n       dfs(i); n     } n   } n   for (int i = 2; i <= tot; i += 2) { n     if (bccno[eg[i]] != bccno[eg[i ^ 1]]) { n       new_addEdge(bccno[eg[i]], bccno[eg[i ^ 1]]); n     } n   } n   int ans = 0; n   for (int i = 1; i <= num; i++) ans += bccsiz[i] - 1; n   cnt = 0; n   for (int i = 1; i <= num; i++) { n     if (!Belong[i]) cnt++, rot[cnt] = i, predfs(i, -1); n   } n   ans += cnt - 1; n   for (int i = 1; i <= cnt; i++) { n     int d = FindDiameter(rot[i]); n     ans += siz[rot[i]] - d - Leaf[i]; n   } n   printf( %d n , ans); n   return 0; n } n