#include <bits/stdc++.h>   using namespace std;   template <typename T>   T sqr(T x) {     return x * x;   }   inline unsigned long long bit(int num) { return 1ull << num; }   long long FindXor(long long r) {     long long rem = r % 4;     switch (rem) {       case 0:         return r;       case 1:         return 1;       case 2:         return r + 1;       case 3:         return 0;     }   }   long long FindXor(long long l, long long r) {     return FindXor(r) ^ FindXor(l - 1);   }   int main() {     int n;     cin >> n;     long long res = 0;     for (int i = 0; i < int(n); ++i) {       long long x, m;       cin >> x >> m;       res ^= FindXor(x, x + m - 1);     }     cout << (res ?  tolik  :  bolik ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gi() {     char ch =  ! ;     int res = 0, f = 0;     while (ch <  0  || ch >  9 ) {       ch = getchar();       if (ch ==  - ) f = 1;     }     while (ch >=  0  && ch <=  9 ) res = res * 10 + ch -  0 , ch = getchar();     return f ? -res : res;   }   const int N = 1e5 + 7;   int n, Q, arr[N], cur[N];   double f[N][110], ans;   int main() {     n = gi();     for (int i = 1; i <= n; ++i) {       arr[i] = gi(), f[i][arr[i]] = 1, cur[i] = arr[i];       ans += f[i][0];     }     Q = gi();     for (int i = 1; i <= Q; ++i) {       int u = gi(), v = gi(), x = gi();       ans -= f[u][0];       for (int k = 1; k <= x; ++k) {         for (int j = 0; j <= arr[u]; ++j) {           if (j > cur[u])             f[u][j] = 0;           else {             f[u][j] = (cur[u] - j) / (double)cur[u] * f[u][j];             if (j + 1 <= cur[u])               f[u][j] += (j + 1) / (double)cur[u] * f[u][j + 1];           }         }         --cur[u];       }       cur[v] += x;       ans += f[u][0];       printf( %.10lf n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long int ar[100000], br[10000];     memset(br, 0, sizeof(br));     for (long long int i = 1; i <= n; i++) {       cin >> ar[i];       br[ar[i]]++;     }     sort(ar + 1, ar + n + 1);     if (n == 1) {       cout <<  YES  << endl;     } else if (ar[1] == ar[n]) {       cout <<  NO  << endl;     } else {       int f = 0;       sort(br + 1, br + 10000, greater<long long int>());       for (long int i = 1; i <= n; i++) {         if (br[i] > (n + 1) / 2) {           f = 1;         }       }       if (f == 0) {         cout <<  YES  << endl;       } else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class TH>   void _dbg(const char *sdbg, TH h) {     cerr << sdbg <<  =  << h <<   n ;   }   template <class TH, class... TA>   void _dbg(const char *sdbg, TH h, TA... a) {     while (*sdbg !=  , ) cerr << *sdbg++;     cerr <<  =  << h <<  , ;     _dbg(sdbg + 1, a...);   }   long long test;   long long n, maybe, maks = 1000000007;   void solve() {     cin >> n;     for (long long i = 1; i <= (n); ++i) {       long long a, b;       cin >> a >> b;       if (a != b) {         cout <<  rated ;         return;       }       if (maks < a) {         maybe = 1;       }       maks = min(maks, a);     }     if (maybe) {       cout <<  unrated ;     } else {       cout <<  maybe ;     }     return;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.precision(10);     cout << fixed;     test = 1;     while (test--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int x1, y1, x2, y2, x3, y3;     cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;     cout << 3 << endl;     cout << x2 - x1 <<     << y3 - y1 << endl;     cout << x1 - x2 <<     << y3 - y2 << endl;     cout << x2 - x3 <<     << y1 - y3 << endl;   }   void solveexpr(double a, double b, double c, double d, double e, double f) {     double determinant = a * d - b * c;     if (determinant != 0) {       double x = (e * d - b * f) / determinant;       double y = (a * f - e * c) / determinant;       printf( %0.0f %0.0f n , x, y);     }   }   void solve1() {     int x1, y1, x2, y2, x3, y3, x, y;     cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;     cout << 3 << endl;     int val1 = x1 + x2;     int val2 = y1 + y2;     x = val1 - x3;     y = val2 - y3;     cout << x <<     << y << endl;     val1 = x3 + x1;     val2 = y3 + y1;     x = val1 - x2;     y = val2 - y2;     cout << x <<     << y << endl;     val1 = x3 + x2;     val2 = y3 + y2;     x = val1 - x1;     y = val2 - y1;     cout << x <<     << y << endl;   }   int main() {     int t = 1;     while (t--) {       solve1();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s;     cin >> s;     long long n = s.length();     char ch =  z ;     for (long long i = 0; i < n; i++) {       if (ch < s[i])         cout <<  Ann n ;       else {         ch = s[i];         cout <<  Mike n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int abslt(int n) {     if (n < 0)       return -n;     else       return n;   }   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n + 1];       int i;       for (i = 1; i <= n; i++) cin >> arr[i];       arr[0] = arr[1];       arr[n + 1] = arr[n];       int mx = INT_MIN;       int mn = INT_MAX;       for (i = 1; i <= n; i++) {         if ((arr[i] != -1 && arr[i + 1] == -1) ||             (arr[i] != -1 && arr[i - 1] == -1)) {           mx = max(mx, arr[i]);           mn = min(mn, arr[i]);         }       }       int ans = (mn + mx) / 2;       if (mx == INT_MIN) {         cout << 0 <<     << 0 << endl;         continue;       }       int k = INT_MIN;       for (i = 1; i < n; i++) {         if (arr[i] == -1) arr[i] = ans;         if (arr[i + 1] == -1) arr[i + 1] = ans;         k = max(k, abslt(arr[i] - arr[i + 1]));       }       cout << k <<     << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s, cnt = 0;     cin >> n >> s;     int arr[100];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr, arr + n);     for (int i = 0; i < n - 1; i++) s -= arr[i];     if (s >= 0) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     long long int a, b, c;     cin >> q;     while (q--) {       cin >> a >> b >> c;       cout << (a + b + c) / 2 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 9;   struct node {     int id;     long long t;     bool operator<(const node &A) const { return id > A.id; }   } e[maxn];   bool cmp(node a, node b) { return a.t < b.t || a.t == b.t && a.id < b.id; }   long long ans[maxn];   int tr[maxn];   void update(int p, int v) {     while (p < maxn) tr[p] += v, p += p & -p;   }   int query(int p) {     int res = 0;     while (p > 0) {       res += tr[p];       p -= p & -p;     }     return res;   }   int main() {     int n;     long long p;     scanf( %d%lld , &n, &p);     for (int i = 1; i <= n; i++) e[i].id = i, scanf( %lld , &e[i].t);     sort(e + 1, e + 1 + n, cmp);     priority_queue<node> W;     queue<node> Q;     int ar = 1;     long long t = 0;     while (ar <= n || !Q.empty() || !W.empty()) {       if (Q.empty() && W.empty()) {         t = e[ar].t;         update(e[ar].id, 1);         Q.push(e[ar++]);       }       if (Q.empty() && !W.empty()) {         update(W.top().id, 1);         Q.push(W.top());         W.pop();       }       if (!Q.empty()) {         node tmp = Q.front();         Q.pop();         t += p;         ans[tmp.id] = t;         while (ar <= n && e[ar].t <= t) {           if (query(e[ar].id - 1) == 0)             update(e[ar].id, 1), Q.push(e[ar++]);           else             W.push(e[ar++]);         }         update(tmp.id, -1);         while (!W.empty() && query(W.top().id - 1) == 0) {           tmp = W.top();           W.pop();           update(tmp.id, 1);           Q.push(tmp);         }       }     }     for (int i = 1; i <= n; i++) {       printf( %lld%c , ans[i],    n [i == n]);     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, mon_cost;   vector<tuple<int, int, int>> friends;   const long long oo = 1LL << 60;   void solve() {     cin >> n >> m >> mon_cost;     friends.resize(n);     for (int i = 0; i < n; ++i) {       int x, k, num;       cin >> x >> k >> num;       int mask = 0;       for (int j = 0; j < num; ++j) {         int y;         cin >> y;         y--;         mask = mask | (1 << y);       }       friends[i] = tie(x, k, mask);     }     sort(friends.begin(), friends.end(),          [](tuple<int, int, int> lhs, tuple<int, int, int> rhs) {            return get<1>(lhs) < get<1>(rhs);          });     vector<vector<long long>> dp(2, vector<long long>(1 << m, oo));     int x, k, tasks;     tie(x, k, tasks) = friends[0];     dp[1][0] = 0;     dp[1][tasks] = x;     long long ans = oo;     for (int i = 0; i < n; ++i) {       int cur = i % 2;       int prev = cur ^ 1;       tie(x, k, tasks) = friends[i];       for (int mask = 0; mask < (1 << m); ++mask) {         dp[cur][mask | tasks] = min(dp[cur][mask | tasks], dp[prev][mask] + x);         dp[cur][mask] = min(dp[cur][mask], dp[prev][mask]);       }       long long val = dp[cur][(1 << m) - 1] + 1LL * k * mon_cost;       ans = min(ans, val);     }     if (ans < oo) {       cout << ans <<   n ;     } else {       cout << -1 <<   n ;     }   }   int main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   using vi = vector<int>;   using vvi = vector<vi>;   using ll = long long;   using vll = vector<ll>;   using vvll = vector<vll>;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   void solve() {     int n;     cin >> n;     vi a(n), b(n);     vector<pii> p, q;     for (int& x : a) cin >> x;     for (int& x : b) cin >> x;     if (n % 2 == 1) {       if (a[n / 2] != b[n / 2]) {         puts( No );         return;       }     }     for (int i = 0; i < n / 2; i++) {       p.push_back(make_pair(min(a[i], a[n - 1 - i]), max(a[i], a[n - 1 - i])));     }     for (int i = 0; i < n / 2; i++) {       q.push_back(make_pair(min(b[i], b[n - 1 - i]), max(b[i], b[n - 1 - i])));     }     sort(p.begin(), p.end());     sort(q.begin(), q.end());     if (p == q) {       puts( Yes );     } else {       puts( No );     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     while (n--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 1000 + 1000 + 1;     printf( %d n , n);     for (int i = (int)(1); i <= (int)(1000); ++i)       printf( %d %d %d %d n , i, 1, i, 2);     puts( 1 1 1 2 );     for (int i = (int)(1); i <= (int)(1000); ++i)       printf( %d %d %d %d n , i, 1, i, 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   long double x;   int a[5005];   int mem[5005][5005];   int lis(int ind, int ant) {     if (ind >= n) return 0;     if (mem[ind][ant] != -1) return mem[ind][ant];     int op1, op2;     op1 = op2 = 0;     if (ant <= a[ind]) op1 = lis(ind + 1, a[ind]) + 1;     op2 = lis(ind + 1, ant);     return mem[ind][ant] = max(op1, op2);   }   int main() {     ;     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     memset(mem, -1, sizeof mem);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i] >> x;     cout << n - lis(0, 0) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long bigmod(long long b, long long p, long long n) {     if (p == 0)       return 1;     else if (p % 2 == 0) {       long long half1 = bigmod(b, p / 2, n);       return ((half1 * half1) % n);     } else if (p % 2 == 1) {       long long p1 = b % n;       long long p2 = bigmod(b, p - 1, n);       return ((p1 * p2) % n);     }   }   long long pre11[1000010], pre21[1000010];   string s, s1;   const int p = 31;   const int m1 = 1e9 + 7;   long long MMI[1000010];   void com() {     MMI[0] = 1;     MMI[1] = bigmod(31, m1 - 2, m1);     for (long long i = 2; i <= s.size() + 3; i++)       MMI[i] = (MMI[i - 1] * MMI[1]) % m1;   }   void compute_hash() {     long long hash_value1 = 0, hash_value2 = 0;     long long p_pow1 = 1, p_pow2 = 1;     for (int i = 0; i < s.size(); i++) {       hash_value1 = (hash_value1 + (s[i] -  a  + 1) * p_pow1) % m1;       if (i < s1.size())         hash_value2 = (hash_value2 + (s1[i] -  a  + 1) * p_pow1) % m1;       p_pow1 = (p_pow1 * p) % m1;       pre11[i] = hash_value1;       if (i < s1.size()) pre21[i] = hash_value2;     }   }   void compute_hash2() {     long long hash_value1 = 0, hash_value2 = 0;     long long p_pow1 = 1, p_pow2 = 1;     for (int i = 0; i < s1.size(); i++) {       hash_value1 = (hash_value1 + (s1[i] -  a  + 1) * p_pow1) % m1;       p_pow1 = (p_pow1 * p) % m1;       pre21[i] = hash_value1;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> s >> s1;     com();     compute_hash();     vector<int> V;     for (int i = 0; i < s.size(); i++) {       long long p1, p2;       long long t1, t2;       if (i == 0) {         p2 = pre11[s.size() - 1] - pre11[0];         if (p2 < 0) p2 += m1;         p2 = ((p2 % m1) * MMI[i + 1]) % m1;         if (p2 == pre21[s1.size() - 1]) V.push_back(i + 1);       } else if (i == s.size() - 1) {         if (pre21[i - 1] == pre11[i - 1]) V.push_back(i + 1);       } else {         p2 = pre11[s.size() - 1] - pre11[i];         if (p2 < 0) p2 += m1;         p2 = ((p2 % m1) * MMI[i + 1]) % m1;         t2 = pre21[s1.size() - 1] - pre21[i - 1];         if (t2 < 0) t2 += m1;         t2 = ((t2 % m1) * MMI[i]) % m1;         if (p2 == t2 && pre21[i - 1] == pre11[i - 1]) V.push_back(i + 1);       }     }     cout << V.size() << endl;     for (int i = 0; i < V.size(); i++) cout << V[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int c, r;     cin >> c >> r;     bool flag = true;     for (int i = 1; i <= c; i++) {       if (i & 1) {         for (int j = 1; j <= r; j++) {           cout <<  # ;         }         cout << endl;       } else {         if (flag) {           for (int j = 1; j <= r - 1; j++) {             cout <<  . ;           }           cout <<  #  << endl;           flag = false;         } else {           cout <<  # ;           for (int j = 1; j <= r - 1; j++) {             cout <<  . ;           }           cout << endl;           flag = true;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int sMAX = 10010;   const int MAX = 114514;   const long long bMAX = 1919180;   int main() {     int t;     cin >> t;     while (t--) {       string zs;       cin >> zs;       int ans = zs.size() + 1;       int m[4] = {0, 0, 0, 0};       for (int i = 0; i < zs.size(); i++) {         m[zs[i] -  0 ] = i + 1;         if (m[1] && m[2] && m[3]) {           int gsb = min(m[1], m[2]);           ans = min(ans, max(m[1], max(m[2], m[3])) - min(gsb, m[3]) + 1);         }       }       if (ans == zs.size() + 1) {         cout << 0 << endl;       } else         cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int f[3001][3001], vis[3001][3001];   char s[3001][3001];   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1);     memset(f, 0x3f, sizeof(f));     f[0][1] = f[1][0] = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         f[i][j] = min(f[i - 1][j], f[i][j - 1]);         if (s[i][j] !=  a ) f[i][j]++;       }     int max0 = 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (f[i][j] <= k) max0 = max(max0, i + j);     for (int i = 2; i <= max0; i++) putchar( a );     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (i + j == max0 && f[i][j] <= k) vis[i][j] = 1;     if (max0 == 1) vis[0][1] = vis[1][0] = 1;     for (int kx = max0 + 1; kx <= n * 2; kx++) {       for (int i = 1; i < kx; i++)         if (i <= n && kx - i <= n)           vis[i][kx - i] = vis[i - 1][kx - i] | vis[i][kx - i - 1];       char minc =  z ;       for (int i = 1; i < kx; i++)         if (i <= n && kx - i <= n && vis[i][kx - i])           minc = min(minc, s[i][kx - i]);       for (int i = 1; i < kx; i++)         if (i <= n && kx - i <= n && s[i][kx - i] != minc) vis[i][kx - i] = 0;       putchar(minc);     }     putchar(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, pos, l, r;     while (cin >> n >> pos >> l >> r) {       if (l == 1 && r == n)         cout << 0 << endl;       else if (l == 1)         cout << (abs(r - pos) + 1) << endl;       else if (r == n)         cout << (abs(l - pos) + 1) << endl;       else if (pos < l || pos > r)         cout << (max(abs(r - pos), abs(l - pos)) + 2) << endl;       else         cout << (r - l + min(abs(r - pos), abs(l - pos)) + 2) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 786433, MAXN = 2000005, LOGN = 18, MAXM = 5005;   inline void S(int& n) {     n = 0;     int ch = getchar();     int sign = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) sign = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       n = (n << 3) + (n << 1) + ch -  0 , ch = getchar();     }     n = n * sign;   }   const int SHIFT = 30, ETF = MOD - 1, LIM = (int)1e9;   const long long int INF = (long long int)1e18 + 1;   const double PI = (double)acos(-1), EPSILON = 1e-10;   long long int recurse(long long int n) {     long long int group_size = 1, gcnt = 0;     long long int ans = 0;     while (n >= group_size) {       long long int temp = 1;       temp <<= gcnt;       ans += temp;       ans += gcnt * (group_size) / 2;       n -= group_size;       group_size <<= 1;       gcnt++;     }     if (n) {       long long int temp = 1;       ans += recurse(n - 1) + (temp << gcnt);     }     return ans;   }   int main() {     long long int n;     cin >> n;     cout << recurse(n - 1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   long long dp[21][2001];   long long fact[200001];   long long tcaf[200001];   int pow1(int n, int p) {     long long cur, res;     cur = n;     res = 1;     while (p) {       if (p & 1) {         res *= cur;         res %= MOD;       }       p /= 2;       cur *= cur;       cur %= MOD;     }     return res;   }   void init() {     fact[0] = tcaf[0] = 1;     for (int i = 1; i < 200001; i++) {       fact[i] = 1LL * fact[i - 1] * i % MOD;       tcaf[i] = pow1(fact[i], MOD - 2);     }   }   int ways(pair<int, int> p1, pair<int, int> p2) {     int n, m;     n = p2.first - p1.first;     m = p2.second - p1.second;     if (n < 0 || m < 0) return 0;     return 1LL * fact[n + m] * tcaf[n] % MOD * tcaf[m] % MOD;   }   long long calc(int s, int num, int tot) {     for (int i = 0; i < num; i++) s = (s + 1) / 2;     return 1LL * tot * s;   }   int main() {     init();     int n, m, k, s;     cin >> n >> m >> k >> s;     init();     vector<pair<int, int>> points(k + 1);     for (int i = 1; i <= k; i++) {       scanf( %d %d , &points[i].first, &points[i].second);       points[i].first--;       points[i].second--;     }     points.push_back({n - 1, m - 1});     sort(points.begin(), points.end());     dp[0][0] = 1;     for (int i = 1; i <= k + 1; i++) {       dp[0][i] = ways({0, 0}, points[i]);       for (int j = 1; j < i; j++) {         dp[0][i] -= 1LL * dp[0][j] * ways(points[j], points[i]), dp[0][i] %= MOD;       }     }     for (int i = 1; i <= 20; i++) {       for (int j = 1; j <= k + 1; j++) {         dp[i][j] = ways({0, 0}, points[j]);         for (int s = 1; s < j; s++) {           dp[i][j] -= 1LL * dp[i][s] * ways(points[s], points[j]) % MOD;           dp[i][j] %= MOD;         }         for (int s = i - 1; s >= 0; s--) dp[i][j] -= dp[s][j], dp[i][j] %= MOD;       }     }     long long res = 0;     long long tot = ways({0, 0}, {n - 1, m - 1});     for (int i = 0; i <= 20; i++) {       res += calc(s, i, dp[i][k + 1]);       res %= MOD;       tot -= dp[i][k + 1];     }     res += tot;     res *= pow1(ways({0, 0}, {n - 1, m - 1}), MOD - 2);     res %= MOD;     res = (res + MOD) % MOD;     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int a[100010];   int p[100010];   int cnt;   int ans;   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 2; i <= n; i++) {       p[++cnt] = (a[i] - a[i - 1] - 1);     }     sort(p + 1, p + cnt + 1);     for (int i = 1; i <= n - k; i++) {       ans += p[i];     }     printf( %d , ans + n);   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 3e5;   const int LG = 20;   struct Query {     int i, x, y;     bool operator<(Query q) const {       if (x != q.x) return x > q.x;       return i < q.i;     }   };   int N, Q;   Query query[MX + 10];   int A[MX + 10];   int dp[MX + 10][LG + 10];   int last[MX + 10];   void init() {}   void calc_dp() {     for (int i = 1; i <= N; i++) {       for (int b = 0; b < LG; b++) {         if (A[i] & (1 << b)) {           dp[i][b] = i;         } else {           for (int c = 0; c < LG; c++) {             if (~A[i] & (1 << c)) continue;             dp[i][b] = max(dp[i][b], dp[last[c]][b]);           }         }       }       for (int b = 0; b < LG; b++) {         if (~A[i] & (1 << b)) continue;         last[b] = i;       }     }   }   bool solve(int x, int y) {     for (int b = 0; b < LG; b++) {       if ((A[x] & (1 << b))) {       }       if ((A[x] & (1 << b)) && (dp[y][b] >= x)) {         return true;       }     }     return false;   }   int main() {     init();     scanf( %d%d , &N, &Q);     for (int i = 1; i <= N; i++) {       scanf( %d , &A[i]);     }     for (int q = 1; q <= Q; q++) {       scanf( %d%d , &query[q].x, &query[q].y);       query[q].i = q;     }     calc_dp();     for (int q = 1; q <= Q; q++) {       if (solve(query[q].x, query[q].y))         printf( Shi n );       else         printf( Fou n );     }   }


#include <bits/stdc++.h>   using namespace std;   long long int powmod(long long int a, long long int e) {     if (e == 0) return 1;     long long int x = powmod(a * a % 1000000007, e >> 1);     return e & 1 ? x * a % 1000000007 : x;   }   set<int> unvis;   set<pair<long long int, long long int> > forbid;   void dfs(int v) {     int ver = -1;     auto it = unvis.begin();     while (it != unvis.end()) {       ver = *it;       if (forbid.find({min(ver, v), max(ver, v)}) != forbid.end()) {         it++;         continue;       }       unvis.erase(it);       dfs(ver);       it = unvis.upper_bound(ver);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m, k;     cin >> n >> m >> k;     for (long long int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       forbid.insert({min(a, b), max(a, b)});     }     for (long long int i = 0; i < n - 1; i++) unvis.insert(i + 1);     dfs(0);     if (!unvis.empty()) {       cout <<  impossible ;       return 0;     }     int cnt = 0;     for (auto i : forbid) {       if (i.first == 0)         cnt++;       else         break;     }     for (long long int i = 1; i < n; i++) unvis.insert(i);     int conn = 0;     while (!unvis.empty()) {       int x = *unvis.begin();       unvis.erase(unvis.begin());       dfs(x);       conn++;     }     if (k >= conn and k <= n - 1 - cnt)       cout <<  possible ;     else       cout <<  impossible ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum_even = 0, sum_odd = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int val;       scanf( %d , &val);       if (val & 1) return puts( First ), 0;     }     puts( Second );   }


#include <bits/stdc++.h>   using namespace std;   long long bigmod(long long a, long long b) {     if (b == 0) return 1;     if (!(b & 1)) {       long long ret = bigmod(a, b / 2);       return ((ret % 1000000007) * (ret % 1000000007)) % 1000000007;     } else       return ((a % 1000000007) * (bigmod(a, b - 1) % 1000000007)) % 1000000007;   }   bool cmp(pair<int, int> p1, pair<int, int> p2) {     if (p1.first != p2.first) return p1.first < p1.first;     return p1.second < p2.second;   }   bool approximatelyEqual(float a, float b, float epsilon) {     return fabs(a - b) <= ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);   }   bool essentiallyEqual(float a, float b, float epsilon) {     return fabs(a - b) <= ((fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);   }   bool definitelyGreaterThan(float a, float b, float epsilon) {     return (a - b) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);   }   bool definitelyLessThan(float a, float b, float epsilon) {     return (b - a) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);   }   bool cmp1(pair<int, int> p1, pair<int, int> p2) {     return p1.second < p2.second;   }   bool cmp2(pair<int, int> p1, pair<int, int> p2) {     return p1.second > p2.second;   }   int main() {     int t, tc = 1, a, b, c, m, n, i, j, k, p, q;     char s[500000];     vector<pair<int, int> > u, v;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &c);       u.push_back(pair<int, int>(i, c));       v.push_back(pair<int, int>(i, c));     }     getchar();     scanf( %s , s);     sort(u.begin(), u.end(), cmp1);     k = 0, b = 0;     vector<int> ans;     stack<int> st;     int oc[200001] = {0};     int pp;     for (i = 0; s[i]; i++) {       if (s[i] ==  0 ) {         ans.push_back(u[k].first + 1);         st.push(k);         k++;       } else {         int xx = st.top();         st.pop();         ans.push_back(u[xx].first + 1);       }     }     for (i = 0; i < ans.size(); i++) {       i != ans.size() - 1 ? printf( %d  , ans[i]) : printf( %d n , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int II() {     int q;     scanf( %d , &q);     return q;   }   long long LII() {     long long q;     scanf( %lld , &q);     return q;   }   const long long Mx = 100005, K = 22;   long long step, jump;   long long Rank[K][Mx];   struct info {     long long tup[2], indx;     bool operator<(const info &a) const {       return (tup[0] == a.tup[0] ? tup[1] < a.tup[1] : tup[0] < a.tup[0]);     }   } ar[Mx];   info temp[Mx];   long long cnt[Mx];   void Counting_Sort(long long N) {     long long mi = -2;     memset(cnt, 0, sizeof(cnt));     for (long long i = 0; i < N; i++) {       cnt[ar[i].tup[1] - mi]++;     }     for (long long i = 1; i < Mx; i++) cnt[i] += cnt[i - 1];     for (long long i = N - 1; i >= 0; i--) {       temp[--cnt[ar[i].tup[1] - mi]] = ar[i];     }     for (long long i = 0; i < N; i++) ar[i] = temp[i];     memset(cnt, 0, sizeof(cnt));     for (long long i = 0; i < N; i++) {       cnt[ar[i].tup[0] - mi]++;     }     for (long long i = 1; i < Mx; i++) cnt[i] += cnt[i - 1];     for (long long i = N - 1; i >= 0; i--) {       temp[--cnt[ar[i].tup[0] - mi]] = ar[i];     }     for (long long i = 0; i < N; i++) ar[i] = temp[i];   }   void Build_Suffix_Array(string s) {     long long N = s.size();     for (long long i = 0; i < N; i++) {       Rank[0][i] = s[i];     }     step = 1, jump = 1;     for (step = 1, jump = 1; jump <= N; step++, jump <<= 1) {       for (long long i = 0; i < N; i++) {         ar[i].indx = i;         ar[i].tup[0] = Rank[step - 1][i];         ar[i].tup[1] = ((i + jump < N) ? Rank[step - 1][i + jump] : -1);       }       Counting_Sort(N);       Rank[step][ar[0].indx] = 0;       for (long long i = 1; i < N; i++) {         Rank[step][ar[i].indx] =             (ar[i].tup[0] == ar[i - 1].tup[0] && ar[i].tup[1] == ar[i - 1].tup[1])                 ? Rank[step][ar[i - 1].indx]                 : i;       }     }   }   vector<long long> LCP(long long N) {     vector<long long> ans(N, 0);     for (long long i = 1; i < N; i++) {       long long x = ar[i].indx, y = ar[i - 1].indx;       ans[i] = 0;       for (long long j = step - 1; j >= 0; j--) {         if (Rank[j][x] == Rank[j][y] && x < N && y < N) {           ans[i] += (1 << j);           x += (1 << j);           y += (1 << j);         }       }     }     return ans;   }   long long st[K][Mx];   void build(vector<long long> lcp) {     long long N = lcp.size();     for (long long i = 0; i < N; i++) {       st[0][i] = lcp[i];     }     for (long long k = 1; k < K; k++) {       for (long long i = 0; i < N; i++) {         long long next = i + (1 << k - 1);         if (next > N) continue;         st[k][i] = min(st[k - 1][i], st[k - 1][next]);       }     }   }   long long get(long long l, long long r) {     l++;     long long lg = log2(r - l + 1);     return min(st[lg][l], st[lg][r - (1 << lg) + 1]);   }   long long find_left(long long l, long long r, long long val) {     long long re = r, lo = l, hi = r;     while (lo < hi) {       long long mid = (lo + hi) / 2;       if (get(mid, r) >= val) {         re = mid;         hi = mid;       } else         lo = mid + 1;     }     return re;   }   pair<long long, long long> find_right(long long l, long long r, long long val) {     long long re = l, lo = l, hi = r;     while (lo < hi) {       long long mid = (lo + hi + 1) / 2;       if (get(l, mid) >= val) {         re = mid;         lo = mid;       } else         hi = mid - 1;     }     if (re == l) return {l, -1};     return {re, get(l, re)};   }   void reset() {     memset(ar, 0, sizeof(ar));     memset(st, 0, sizeof(st));     memset(Rank, 0, sizeof(Rank));   }   void solve() {     reset();     string s;     cin >> s;     long long N = s.size();     Build_Suffix_Array(s);     vector<long long> lcp = LCP((long long)s.size());     build(lcp);     long long ans = 0;     for (long long i = 0; i < N; i++) {       long long len = N - ar[i].indx;       long long cur = lcp[i] + 1;       while (cur <= len) {         long long RR = Rank[step - 1][ar[i].indx];         pair<long long, long long> pr = find_right(RR, N - 1, cur);         if (pr.second == -1) {           ans += len - cur + 1;           break;         } else {           long long q = pr.first - RR + 1;           long long qq = pr.second - cur + 1;           ans += (1LL * (q * (q + 1)) / 2 * qq);           cur = pr.second + 1;         }       }     }     cout << ans << endl;   }   int32_t main() {     long long tt;     tt = 1;     long long cas = 1;     while (tt--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int fact[100005];   bitset<100005> p;   int cnt[100005];   int best[100005];   int arr[100005];   int bestFactor(int n) {     if (fact[n] == 0) {       return n;     }     int curFactor = fact[n];     int bestChildFactor = bestFactor(n / curFactor);     if (best[curFactor] == -1) {       return bestChildFactor;     }     if (best[bestChildFactor] == -1) {       return curFactor;     }     if (cnt[best[curFactor]] > cnt[best[bestChildFactor]]) {       return curFactor;     }     return bestChildFactor;   }   void updateFactors(int n, int idx) {     if (fact[n] == 0) {       best[n] = idx;       return;     }     best[fact[n]] = idx;     return updateFactors(n / fact[n], idx);   }   int main() {     memset(best, -1, sizeof best);     p.set();     p[0] = p[1] = false;     for (int i = 2, to = sqrt(100005) + 1; i <= to; i++) {       if (p[i]) {         for (int j = i * i; j < 100005; j += i) {           if (fact[j] == 0) fact[j] = i;           p[j] = false;         }       }     }     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &arr[i]);       cnt[i] = 1;     }     updateFactors(arr[0], 0);     int maxi = 1;     for (int i = 1; i < n; i++) {       int bestFact = bestFactor(arr[i]);       if (best[bestFact] != -1) {         cnt[i] = cnt[best[bestFact]] + 1;         maxi = max(maxi, cnt[i]);       }       updateFactors(arr[i], i);     }     cout << maxi;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t = 1;     cin >> t;     while (t--) {       string n, k;       cin >> n >> k;       string A, B, C, other;       for (int i = 0; i < n.size(); i++) {         if (n[i] ==  a )           A.push_back( a );         else if (n[i] ==  b )           B.push_back( b );         else if (n[i] ==  c )           C.push_back( c );         else           other.push_back(n[i]);       }       sort(n.begin(), n.end());       sort(other.begin(), other.end());       if (A.size() == 0 || B.size() == 0 || C.size() == 0)         cout << n;       else {         if (k[0] ==  a ) {           if (k[1] ==  b )             cout << A << C << B;           else             cout << A << B << C;         } else {           cout << A << B << C;         }         if (other.size() != 0) cout << other;       }       cout <<   n ;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int main() {     int n;     cin >> n;     vector<long long> v(2 * n);     for (int i = 0; i < 2 * n; i++) cin >> v[i];     sort(v.begin(), v.end());     long long ans = (v[n - 1] - v[0]) * (v[2 * n - 1] - v[n]);     long long minx = 1e9 + 10;     for (int i = 0; i < n; i++) {       long long k = v[n + i - 1] - v[i];       minx = min(minx, k);     }     long long k = (v[2 * n - 1] - v[0]) * minx;     cout << (long long)min(ans, k);   }


#include <bits/stdc++.h>   using namespace std;   int facts[1002][3], v[1002];   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       cin >> facts[i][0] >> facts[i][1] >> facts[i][2];       if (facts[i][0] == 1) {         for (int j = facts[i][1]; j < facts[i][2]; ++j) v[j] = 1;       }     }     for (int i = 1; i <= m; ++i) {       bool verif = false;       if (facts[i][0] == 0) {         for (int j = facts[i][1]; j < facts[i][2]; ++j)           if (v[j] == 0) {             verif = true;             break;           }         if (verif == false) {           cout <<  NO  << endl;           return 0;         }       }     }     int y = n + 1;     cout <<  YES  << endl;     for (int i = 1; i <= n; ++i) {       if (v[i - 1] == 1)         cout << y <<    ;       else         cout << --y <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve(int cases) {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     int su = 0;     for (int i = 0; i < n; i++) su += a[i];     sort(a, a + n);     if (su == 0) {       cout <<  NO n ;       return;     }     cout <<  YES n ;     if (su > 0) {       for (int i = 0; i < n; i++) cout << a[n - 1 - i] <<    ;       cout <<   n ;       return;     }     for (int i = 0; i < n; i++) cout << a[i] <<    ;     cout <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int cases = 1;     int t = 1;     cin >> t;     while (t--) {       solve(cases++);     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int a, b, c;     cin >> a >> b >> c;     if (a + c <= b)       puts( 0 );     else {       int a2 = max(((a + b + c) >> 1) + 1, a);       a += c;       cout << a - a2 + 1 << endl;     }     return;   }   int main() {     int T;     cin >> T;     while (T--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int NN = 111 * 1000;   int n, a, d;   int t[NN], v[NN];   int main() {     ios::sync_with_stdio(false);     cin >> n >> a >> d;     for (int i = 0; i < n; i++) {       cin >> t[i] >> v[i];     }     double Max = -1.;     for (int i = 0; i < n; i++) {       double v2 = (double)v[i] * v[i];       double dx = v2 / a / 2.;       dx = min((double)d, dx);       double tl = sqrt(dx * 2. / a);       double tr = (d - dx) / v[i];       double t_cur = t[i] + tl + tr;       Max = max(Max, t_cur);       printf( %.16f n , Max);     }   }


#include <bits/stdc++.h>   using namespace std;   using ld = long double;   using ll = long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using vi = vector<int>;   const int oo = 1e9 + 7;   const ll loo = 1e18;   ll modpow(ll a, ll b) {     ll res = 1;     while (b) {       if (b & 1) res = res * a % oo;       a = a * a % oo;       b /= 2;     }     return res;   }   ll gcd(ll a, ll b) { return a == 0 ? b : gcd(b % a, a); }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int N = 5e5 + 7;   int n, k, m;   using point = complex<ll>;   point p[N];   ld dist[N];   vector<int> arms[N];   int gr[N];   int num;   ld cross(point a, point b) { return (conj(a) * b).imag(); }   ld dot(point a, point b) { return (conj(a) * b).real(); }   void input() {     map<pair<ll, ll>, int> id;     m = 0;     for (int i = 0; i < n; i++) {       ll a, b;       cin >> a >> b;       p[i] = point(a, b);       dist[i] = sqrt(dot(p[i], p[i]));       if (a == 0 && b == 0) continue;       ll g = gcd(abs(a), abs(b));       pair<ll, ll> ash = make_pair(a / g, b / g);       if (!id.count(ash)) id[ash] = m++;       arms[id[ash]].push_back(i);       gr[i] = id[ash];     }     for (int i = 0; i < m; i++) {       sort(begin(arms[i]), end(arms[i]),            [&](int i, int j) { return dist[i] < dist[j]; });     }   }   ld option1() {     priority_queue<pair<ld, int>> pq;     for (int i = 0; i < m; i++) {       for (int t = 0; t < min(k / 2, (int)arms[i].size()); t++) {         ld wei = (k - 2 * t - 1) * dist[arms[i][arms[i].size() - 1 - t]];         pq.push(make_pair(wei, arms[i][arms[i].size() - 1 - t]));       }     }     for (int i = 0; i < n; i++)       if (p[i] == point(0)) {         pq.push(make_pair(0, i));       }     ld ans = 0;     while (pq.size() && num < k) {       auto pp = pq.top();       pq.pop();       ans += pp.first;       num++;     }     return ans;   }   ld option2(int i, ld ans) {     int half = k / 2;     int s = num - half;     for (int t = 0; t < arms[i].size() - half; t++) {       ans += dist[arms[i][t]] * ((t + s) - (k - 1 - t - s));       if (t + 1 + num == k) break;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     input();     ld ans = option1();     if (num < k) {       ld res = 0;       for (int i = 0; i < m; i++)         if (2 * (n - arms[i].size()) <= k) {           res = max(res, option2(i, ans));         }       ans = res;     }     cout << setprecision(40) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Size = 1024;   const int mod = 998244353;   const int INF = 2147483647;   const int maxn = 1e5 + 15;   int a[maxn];   int main() {     int n, x, y, i, f, j;     scanf( %d%d%d , &n, &x, &y);     for (i = 1; n >= i; i++) {       scanf( %d , &a[i]);     }     for (i = 1; n >= i; i++) {       f = 0;       for (j = 1; x >= j && i - j >= 1; j++) {         if (a[i] < a[i - j])           continue;         else           f = 1;       }       for (j = 1; y >= j && i + j <= n; j++) {         if (a[i] < a[i + j])           continue;         else           f = 1;       }       if (f == 0) {         printf( %d n , i);         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long ans = 0;     for (int i = (0); i < (n); ++i) {       long long t, T, x, cost;       cin >> t >> T >> x >> cost;       if (t >= T) {         ans += cost + m * x;         continue;       }       long long aux1 = cost;       if (m > (T - t)) aux1 += m * x;       long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1;       aux2 *= cost;       ans += min(aux1, aux2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static const int INF = 500000000;   template <class T>   void debug(T a, T b) {     for (; a != b; ++a) cerr << *a <<    ;     cerr << endl;   }   int n, w, b;   const long long int mod = 1000000009;   int C[4005][4005];   int main() {     for (int i = 0; i < 4003; ++i) {       C[i][0] = 1;       for (int j = 0; j < i; ++j)         C[i][j + 1] = (C[i - 1][j + 1] + C[i - 1][j]) % mod;     }     cin >> n >> w >> b;     long long int res = 0;     for (int l = 1; l < n - 1; ++l)       for (int r = l + 1; r < n; ++r) {         int len = r - l, wlen = n - len;         if (b - len < 0 || w - wlen < 0) continue;         res += C[b - 1][b - len] * (long long int)C[w - 1][w - wlen] % mod;         res %= mod;       }     for (int i = 0; i < w; ++i) res = res * (i + 1) % mod;     for (int i = 0; i < b; ++i) res = res * (i + 1) % mod;     cout << res << endl;     return 0;   }


#include<bits/stdc++.h>   #define fo(i,a,b) for(int i=(a);i<=(b);++i)   #define fd(i,a,b) for(int i=(a);i>=(b);--i)   #define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)   using namespace std;   typedef long long ll;   const int maxn = 1e6 + 5;   const ll mod = 1e9 + 7;   int t, m, n, k;   vector<int>e[maxn];   int d[maxn], val[maxn];   void D() {    queue<int>q;    q.push(1);    while (!q.empty()) {     int u = q.front(); q.pop();     for (auto& v : e[u]) {      if (d[v] == -1) {       d[v] = d[u] + 1;       q.push(v);      }     }    }   }   int f(int u) {    if (val[u] != -1)return val[u];    val[u] = d[u];    for (auto& v : e[u]) {     if (d[v] > d[u])val[u] = min(val[u], f(v));     else val[u] = min(val[u], d[v]);    }    return val[u];   }   int main() {    IOS;    cin >> t;    while (t--) {     cin >> n >> m;     fo(i, 1, n)e[i].clear(), d[i] = val[i] = -1;     fo(i, 1, m) {      int u, v;      cin >> u >> v;      e[u].push_back(v);     }     d[1] = 0;     D();     fo(i, 1, n)cout << f(i) <<    ; cout << endl;    }    return 0;   }   /*      */


#include <bits/stdc++.h>   using namespace std;   struct IO {     char buf[(1 << 20)], *p1, *p2;     char pbuf[(1 << 20)], *pp;     IO() : p1(buf), p2(buf), pp(pbuf) {}     inline char gc() {       return getchar();       if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, (1 << 20), stdin);       return p1 == p2 ?     : *p1++;     }     inline bool blank(char ch) {       return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ;     }     template <class T>     inline void read(T &x) {       register double tmp = 1;       register bool sign = 0;       x = 0;       register char ch = gc();       for (; !(ch >=  0  && ch <=  9 ); ch = gc())         if (ch ==  - ) sign = 1;       for (; (ch >=  0  && ch <=  9 ); ch = gc()) x = x * 10 + (ch -  0 );       if (ch ==  . )         for (ch = gc(); (ch >=  0  && ch <=  9 ); ch = gc())           tmp /= 10.0, x += tmp * (ch -  0 );       if (sign) x = -x;     }     inline void read(char *s) {       register char ch = gc();       for (; blank(ch); ch = gc())         ;       for (; !blank(ch); ch = gc()) *s++ = ch;       *s = 0;     }     inline void read(char &c) {       for (c = gc(); blank(c); c = gc())         ;     }     template <class t>     inline void write(t x) {       if (x < 0)         putchar( - ), write(-x);       else {         if (x > 9) write(x / 10);         putchar( 0  + x % 10);       }     }   } io;   const int mod = 1e9 + 7;   const int mo = 998244353;   const int N = 5e5 + 5;   int n, m, a[N], b[N], c[N], stak[N], gs, ans;   inline int get(int l, int r) {     int top = 0;     for (int i = (l); i <= (r); i++) {       if (a[i] < a[l] || a[i] > a[r]) continue;       if (!top || a[i] >= stak[top])         stak[++top] = a[i];       else {         int p = upper_bound(stak + 1, stak + top + 1, a[i]) - stak;         stak[p] = a[i];       }     }     return top;   }   int main() {     io.read(n), io.read(m);     for (int i = (1); i <= (n); i++) io.read(a[i]), a[i] = a[i] - i + 1;     for (int i = (1); i <= (n); i++) b[i] = a[i];     a[++n] = 2e9, b[n] = 2e9;     sort(b + 1, b + n + 1);     gs = unique(b + 1, b + n + 1) - b - 1;     for (int i = (1); i <= (n); i++)       a[i] = lower_bound(b + 1, b + gs + 1, a[i]) - b;     for (int i = (1); i <= (m); i++) io.read(b[i]);     for (int i = (2); i <= (m); i++)       if (a[b[i - 1]] > a[b[i]]) ans = -1;     if (ans == -1) return puts( -1 ), 0;     b[0] = 0, b[m + 1] = n;     ans = 0;     for (int i = (0); i <= (m); i++)       ans += b[i + 1] - b[i] + 1 - get(b[i], b[i + 1]);     io.write(ans), puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxN = 1e6;   int n, k, a[mxN], l[mxN];   struct dsu {     int p[mxN], ld[mxN], lb[mxN];     void init() {       iota(p, p + n, 0);       iota(lb, lb + n, 0);     }     int find(int x) { return x == p[x] ? x : (p[x] = find(p[x])); }     void join(int x, int y) {       x = find(x), y = find(y);       p[x] = y;       lb[y] = lb[x];       ld[y] += ld[x];     }     void upd(int i, int j) {       i = find(i);       ++ld[i];       if (j < n) --ld[j];       while (ld[i] >= 0 && lb[i]) join(lb[i] - 1, i);     }     void upd2(int i) {       if (i < k) return;       int j = find(i - k + 1);       while (lb[j] > i - k) join(lb[j] - 1, j);     }     int qry() { return ld[find(0)]; }   } d;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (int i = 0; i < n; ++i) cin >> a[i];     d.init();     for (int i = 0; i < n; ++i) {       d.upd2(i);       l[i] = i - 1;       while (l[i] >= 0 && a[l[i]] < a[i]) {         l[i] = l[l[i]];       }       d.upd(l[i] + 1, i + 1);       if (i >= k - 1) cout << d.qry() <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   void result() {     set<int> s;     s.insert(0);     int i = 1;     while (i * i <= n) {       int d = n / i;       s.insert(d);       s.insert(n / d);       i++;     }     cout << s.size() <<   n ;     for (auto v : s) {       cout << v <<    ;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       cin >> n;       result();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)2E9;   const long long LINF = (long long)9E18;   const long double PI = acos(-1.0);   const long double EPS = 1E-11;   template <typename T>   inline T sqr(const T x) {     return x * x;   }   template <typename T>   T gcd(T a, T b) {     return (b == 0) ? a : gcd(b, a % b);   }   template <typename T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <typename T>   T mod(T a, T b) {     a %= b;     if (a < 0) a += b;     return a;   }   template <typename T>   inline T rad(const T x) {     return x * PI / 180;   }   template <typename T>   inline string toString(T x) {     ostringstream oss;     oss << x;     return oss.str();   }   inline long long toInt(const string& st) {     istringstream istringstream(st);     long long x;     istringstream >> x;     return x;   }   inline long double toDouble(const string& st) {     istringstream istringstream(st);     long double x;     istringstream >> x;     return x;   }   inline string toLower(string st) {     for (int i = 0; i < (((int)(st).size())); ++i) st[i] = tolower(st[i]);     return st;   }   inline string toUpper(string st) {     for (int i = 0; i < (((int)(st).size())); ++i) st[i] = toupper(st[i]);     return st;   }   const int dx[] = {-1, 0, 0, 1};   const int dy[] = {0, -1, 1, 0};   int DEBUG = false;   const char DEBUG_PARAM[] =  __LOCAL_TESTING ;   const int MAXCLOCK = 100;   int aClock[MAXCLOCK], mClock[MAXCLOCK], nClock = 0, iClock = 0;   inline void tick(int maxTime = 10000) {     if (DEBUG) {       mClock[nClock] = maxTime;       aClock[nClock++] = clock();     }   }   inline void untick(string name =  Execution Time ) {     if (DEBUG) {       int numClock = clock() - aClock[--nClock];       cout <<  @   << name <<  : [             << (int)((double)(numClock) / CLOCKS_PER_SEC * 1000) <<   ms] ;       if (numClock > (int)(mClock[nClock]))         cout <<   [TLE] ;       else if (numClock > (int)(mClock[nClock] * 0.9))         cout <<   [almost TLE] ;       cout << endl;     }   }   const char IN[] =  _.in ;   const char OUT[] =  _.out ;   int ntest = 1, test = 1;   int N;   inline void run() {     for (test = 1; test <= ntest; ++test) {       tick((int)2E3);       cin >> N;       if (N == 1) {         cout <<  a  << endl <<  a  << endl <<  b  << endl <<  b  << endl;       } else {         if (N & 1) {           int N2 = N / 2;           for (int i = (1); i <= (N2); ++i) {             if (i & 1) {               cout <<  aa ;             } else {               cout <<  bb ;             }           }           cout <<  c  << endl;           for (int i = (1); i <= (N2); ++i) {             if (i & 1) {               cout <<  bb ;             } else {               cout <<  aa ;             }           }           cout <<  c  << endl <<  d ;           for (int i = (1); i <= (N2); ++i) {             if (i & 1) {               cout <<  ee ;             } else {               cout <<  ff ;             }           }           cout << endl <<  d ;           for (int i = (1); i <= (N2); ++i) {             if (i & 1) {               cout <<  ff ;             } else {               cout <<  ee ;             }           }           cout << endl;         } else {           int N2 = N / 2;           for (int i = (1); i <= (N2); ++i) {             if (i & 1) {               cout <<  aa ;             } else {               cout <<  bb ;             }           }           cout << endl <<  c ;           for (int i = (1); i <= (N2 - 1); ++i) {             if (i & 1) {               cout <<  dd ;             } else {               cout <<  ee ;             }           }           cout <<  f  << endl <<  c ;           for (int i = (1); i <= (N2 - 1); ++i) {             if (i & 1) {               cout <<  gg ;             } else {               cout <<  hh ;             }           }           cout <<  f  << endl;           for (int i = (1); i <= (N2); ++i) {             if (i & 1) {               cout <<  ii ;             } else {               cout <<  kk ;             }           }           cout << endl;         }       }       untick( #  + toString(test));     }   }   int main(int argc, char* argv[]) {     if (argc > 1 && strcmp(argv[1], DEBUG_PARAM) == 0) {       DEBUG = true;     }     if (DEBUG) {       tick((int)1E4);       freopen(IN,  r , stdin);     }     run();     if (DEBUG) {       untick( TOTAL );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sub_tern(int c, int a) {     int temp_c;     int temp_a;     int diff;     long sum = 0;     int three_power = 1;     while (c > 0 || a > 0) {       temp_c = c % 3;       c = c / 3;       temp_a = a % 3;       a = a / 3;       diff = temp_c - temp_a;       if (diff < 0) {         diff += 3;       }       sum += (long)diff * (long)three_power;       three_power *= 3;     }     return sum;   }   int main() {     int a;     int c;     cin >> a >> c;     if (a == c) {       cout <<  0 n ;       return 0;     }     cout << sub_tern(c, a) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n, m;     while (cin >> n >> m) {       long c = 0;       if (n * 2 >= m) {         for (int i = 0; i < m; i++) {           cout << i + 1 <<    ;         }       } else {         c = 1;         for (int i = 2 * n + 1; i <= m; i++) {           cout << i <<     << c <<    ;           c++;         }         for (int i = c; i <= 2 * n; i++) {           cout << i <<    ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long labs(long long a) { return a < 0 ? (-a) : a; }   long long max(long long a, long long b) { return a > b ? a : b; }   long long min(long long a, long long b) { return a < b ? a : b; }   template <typename T>   struct Point {     T x, y;     Point() {}     Point(T xx, T yy) : x(xx), y(yy) {}   };   template <typename T>   bool operator<(const Point<T> &p1, const Point<T> &p2) {     return p1.x < p2.x || p1.x == p2.x && p1.y < p2.y;   }   char c =  a  - 1;   char NextChar() {     c++;     if (c >  z ) c =  a ;     return c;   }   vector<vector<char> > v;   int main() {     int n;     cin >> n;     if (n == 2) {       cout <<  aa  << endl;       cout <<  bb  << endl;       cout <<  cc  << endl;       cout <<  dd  << endl;       return 0;     }     v.assign(4, vector<char>(n));     v[2][0] = v[3][0] = NextChar();     for (int(i) = 0; (i) < (n - 1); (i)++) {       if (i % 2 == 0) {         v[0][i] = v[0][i + 1] = NextChar();         v[1][i] = v[1][i + 1] = NextChar();       } else {         v[2][i] = v[2][i + 1] = NextChar();         v[3][i] = v[3][i + 1] = NextChar();       }     }     if (n % 2 == 0) {       v[2][n - 1] = v[3][n - 1] = NextChar();     } else {       v[0][n - 1] = v[1][n - 1] = NextChar();     }     for (int(i) = 0; (i) < (4); (i)++) {       for (int(j) = 0; (j) < (n); (j)++) {         cout << v[i][j];       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     if (c ==  - ) f = -1, c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return f * x;   }   const int maxn = 40 + 7;   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   int n, m, cur, cnt;   bitset<100000> b[41];   map<string, int> hh;   int g[maxn][maxn];   int dp1[(1 << 20) + 7], dp2[(1 << 20) + 7];   inline void max(int &x, int y) {     if (x < y) x = y;   }   int main() {     n = read(), m = read();     string name;     for (int i = 1; i <= n; ++i) {       int op = read();       if (op == 1)         ++cur;       else {         cin >> name;         if (hh.count(name) == 0) hh[name] = ++cnt;         b[hh[name]][cur] = 1;       }     }     for (int i = 1; i <= m; ++i) {       for (int j = i + 1; j <= m; ++j) {         if ((b[i] & b[j]).count()) g[i - 1][j - 1] = g[j - 1][i - 1] = 1;       }     }     int n2 = m / 2, n1 = m - n2;     for (int i = 0; i < n1; ++i) dp1[1 << i] = 1;     for (int s = 3; s < 1 << n1; ++s) {       for (int i = 0; i < n1; ++i)         if (s >> i & 1) {           int f = 1;           for (int j = 0; j < n1; ++j)             if ((s >> j & 1) && g[i][j]) f = 0;           max(dp1[s], dp1[s ^ (1 << i)] + f);         }     }     for (int i = 0; i < n2; ++i) dp2[1 << i] = 1;     for (int s = 3; s < 1 << n2; ++s) {       for (int i = 0; i < n2; ++i)         if (s >> i & 1) {           int f = 1;           for (int j = 0; j < n2; ++j)             if ((s >> j & 1) && g[n1 + i][n1 + j]) f = 0;           max(dp2[s], dp2[s ^ (1 << i)] + f);         }     }     int ans = 0;     for (int s = 0; s < 1 << n1; ++s) {       int s2 = (1 << n2) - 1;       for (int i = 0; i < n1; ++i)         if (s >> i & 1) {           for (int j = 0; j < n2; ++j)             if ((s2 >> j & 1) && g[i][n1 + j]) s2 ^= 1 << j;         }       max(ans, dp1[s] + dp2[s2]);     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   int q, n, a[505];   int main() {     cin >> q;     while (q--) {       cin >> n;       for (int i = 1; i <= n; i++) cin >> a[i];       bool pd = 1;       for (int i = 1; i < n; i++) {         int xx = a[i] + 1;         if (xx > n) xx = 1;         if (xx != a[i + 1]) {           pd = 0;           break;         }       }       if (pd) {         cout <<  YES  << endl;         continue;       }       pd = 1;       for (int i = 1; i < n; i++) {         int xx = a[i] - 1;         if (xx == 0) xx = n;         if (xx != a[i + 1]) {           pd = 0;           break;         }       }       if (pd)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include<bits/stdc++.h>   #define ll long long int   #define mod 1000000007   using namespace std;      int main()   {       int t;       cin>>t;       while(t--)       {          int n;          cin>>n;          int A[n];          for(int i=0;i<n;i++)          {              cin>>A[i];          }          bool flag=true;          for(int i=0;i<n;i++) if(A[i]!=i+1) {flag=false; break;}          if(flag) cout<< 0 <<endl;          else if((A[0]==1)||(A[n-1]==n)) cout<< 1 <<endl;          else if((A[0]==n)&&(A[n-1]==1)) cout<< 3 <<endl;          else cout<< 2 <<endl;       }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n;     cin >> k;     if (n < k) {       cout << -1;       return 0;     }     if (k == 1) {       if (n == 1)         cout <<  a ;       else         cout << -1;       return 0;     }     if (k == 2) {       for (int i = 0; i < n >> 1; i++) cout <<  ab ;       if (n & 1) cout <<  a ;       return 0;     } else {       string temp =  cdefghijklmnopqrstuvwxyz ;       for (int i = 0; i < (n - k + 2) >> 1; i++) cout <<  ab ;       if ((n - k + 2) & 1) cout <<  a ;       for (int j = 0; j < (k - 2); j++) cout << temp[j];     }     cout << endl;     return 0;   }


#include <iostream>   #include<bits/stdc++.h>   #include<vector>   #define fo(i,n) for(long long i=0;i<n;i++)   #define ll long long int   #define inf 999999999999999999   #define pb push_back   #define fi first   #define se second   #define vi vector<ll>   #define vii vector<vector<ll>>   #define pi pair<ll,ll>   #define mp make_pair   #define MOD 1000000007   #define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)   #define fio ios_base::sync_with_stdio(false);cin.tie(0);   using namespace std;   //cerr<<   n  <<  Time elapsed :  << clock() * 1000.0 / CLOCKS_PER_SEC <<   ms n  ;   //freopen( explicit.in ,  r , stdin);   //freopen( explicit.out ,  w , stdout);       void SieveOfEratosthenes()    {        bool prime[10000001];       memset(prime, true, sizeof(prime));             for (ll p=2; p*p<=10000000; p++)        {            if (prime[p] == true)            {                // Update all multiples of p greater than or                 // equal to the square of it                // numbers which are multiple of p and are                // less than p^2 are already been marked.                 for (ll i=p*p; i<=10000000; i += p) {                   prime[i] = false;                }           }        }     }    ll binpow(ll a, ll b) {       ll res = 1;       while (b > 0) {           if (b & 1)               res = (res * a);           a = (a * a);           b >>= 1;       }       return res;   }   ll gcd(ll a,ll b)   {       if(b%a==0)          return a;       return gcd(b%a,a);   }   ll power(ll x,ll y,ll p)    {        ll r = 1;            x = x % p;       while (y > 0) {           if (y & 1)                r = (r * x) % p;           y = y >> 1;            x = (x * x) % p;        }        return r;    }     ll modInverse(ll n, ll p)    {        return power(n, p - 2, p);    }        ll nCrModP(ll n,ll r, ll p)    {        ll fac[100005];       if (r == 0)            return 1;             return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;    }   int32_t main()    {       fio       ll j,i,n,t,l,s,r,c,h,k,m,maxi,d,a,b,x;       cin>>t;       string w;       for(i=0;i<t;i++)       {           cin>>a>>b>>c;           s=0;           for(j=0;j<c;j++)           {               s=s*10+1;           }           l=s;           while(true)           {               x=s;               d=0;               while(x!=0)               {                   x=x/10;                   d++;               }               if(d==a)                   break;               s=s*2;           }           m=s;           s=l;           while(true)           {               x=s;               d=0;               while(x!=0)               {                   x=x/10;                   d++;               }               if(d==b)                   break;               s=s*3;           }           cout<<m<<   <<s<<endl;           // cout<<__gcd(m,s)<<endl;       }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5;   int n, can_win[MAXN + 5], can_lose[MAXN + 5];   struct game {     long long s, e;   } a[MAXN + 5];   bool get_win(long long s, long long e) {     assert(s <= e);     if (e % 2 == 1) {       if (s % 2 == 1)         return 0;       else         return 1;     } else {       if (s * 2 > e) {         if (s % 2 == 1)           return 1;         else           return 0;       } else if (s * 4 > e) {         return 1;       } else {         return get_win(s, e / 4);       }     }   }   bool get_lose(long long s, long long e) {     if (s * 2 > e) {       return 1;     } else {       return get_win(s, e / 2);     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) cin >> a[i].s >> a[i].e;     can_lose[0] = 1;     for (int i = 1; i <= n; ++i) {       if (can_lose[i - 1] && can_win[i - 1]) {         cout << 1 <<     << 1 << endl;         return 0;       }       if (!can_lose[i - 1] && !can_win[i - 1]) {         cout << 0 <<     << 0 << endl;         return 0;       }       if (can_lose[i - 1]) {         can_win[i] = get_win(a[i].s, a[i].e);         can_lose[i] = get_lose(a[i].s, a[i].e);       } else {         can_win[i] = (!get_win(a[i].s, a[i].e));         can_lose[i] = (!get_lose(a[i].s, a[i].e));       }     }     cout << can_win[n] <<     << can_lose[n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int maxN = 100000;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     int n, m;     cin >> n >> m;     int ok = 1;     for (int i = 0; i < n; i++) {       for (int k = 0; k < m; k++) {         char c;         cin >> c;         if (c !=  B  && c !=  W  && c !=  G ) ok = 0;       }     }     cout << (ok ?  #Black&White  :  #Color ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct READ {     int d1, d2, d3;     READ(int d1 = -1, int d2 = -1, int d3 = -1) : d1(d1), d2(d2), d3(d3) {}     template <class T>     operator T() {       T tmp;       this->read(tmp);       return tmp;     }     template <class T>     void read(T& t) {       cin >> t;     }     template <class T>     void read(vector<T>& cont) {       assert(d1 != -1);       cont.resize(d1);       READ r(d2, d3);       for (int i = 0; i < d1; ++i) r.read(cont[i]);     }     template <class T1, class T2>     void read(pair<T1, T2>& x) {       read(x.first);       read(x.second);     }   };   vector<pair<int, int>> solve(int n, int k) {     int64_t combs = (int64_t)k * (k - 1);     if (combs < n) return {};     vector<pair<int, int>> result;     for (int diff = 1;; diff += 1) {       for (int x = 1; x <= k; ++x) {         result.emplace_back(x, (x + diff - 1) % k + 1);         if (result.size() >= n) return result;       }     }   }   int main(int argc, char* argv[]) {     int n = READ();     int k = READ();     vector<pair<int, int>> result = solve(n, k);     if (result.empty()) {       cout <<  NO  << endl;     } else {       cout <<  YES  << endl;       for (auto& p : result) {         cout << p.first <<     << p.second << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( O0 )   #pragma GCC optimize( O1 )   template <typename T>   void vec_SUN(vector<T> &Vec) {     vector<T> X;     X = Vec;     sort(X.begin(), X.end());     X.resize(unique(X.begin(), X.end()) - X.begin());     for (auto &u : Vec) u = lower_bound(X.begin(), X.end(), u) - X.begin() + 1;   }   template <typename T>   void arr_SUN(T *A, int n) {     vector<T> B(n);     for (int i = 0; i < n; i++) B[i] = A[i];     sort(B.begin(), B.end());     B.resize(unique(B.begin(), B.end()) - B.begin());     for (int i = 0; i < n; i++)       A[i] = lower_bound(B.begin(), B.end(), A[i]) - B.begin() + 1;   }   template <typename T>   void vec_012(vector<T> &A, int n) {     A.resize(n);     for (int i = 0; i < n; i++) A[i] = (T)i;   }   template <typename T>   void arr_012(T *A, int n) {     for (int i = 0; i < n; i++) A[i] = (T)i;   }   template <typename T>   void vec_123(vector<T> &A, int n) {     A.resize(n);     for (int i = 0; i < n; i++) A[i] = (T)(i + 1);   }   template <typename T>   void arr_123(T *A, int n) {     for (int i = 0; i < n; i++) A[i] = (T)(i + 1);   }   template <typename T>   void arr_equal(T *A, T *P, int n) {     for (int i = 0; i < n; i++) P[i] = A[i];   }   template <typename T>   void setTOvec(set<T> &S, vector<T> &V) {     V.resize(S.size());     int i = 0;     for (auto it = S.begin(); it != S.end(); it++) V[i++] = *it;   }   const int N = 1e5 + 5;   struct X {     int A[N];     int s = 0;     void add(int x) { A[s++] = x; }     void del() { s--; }     void print() {       cout << 0 <<    ;       for (int i = s - 1; i >= 0; i--) cout << A[i] <<    ;     }   };   bitset<N> M;   int n;   bool f(X &ANS, int s) {     if (s == 0 && ANS.s == n) {       ANS.print();       return true;     }     if (M[s]) return false;     M[s] = true;     ANS.add(s);     if (f(ANS, s / 2)) return true;     if (f(ANS, (s + n) / 2)) return true;     ANS.del();     M[s] = false;     return false;   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     X ANS;     if (n % 2 == 1)       cout << -1;     else       f(ANS, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937_64 rang(       chrono::high_resolution_clock::now().time_since_epoch().count());   const int M = 1e9 + 7;   long long power(long long x, long long y) {     long long v = 1;     while (y > 0) {       if (y & 1) v = v * x;       y = y >> 1;       x = x * x;     }     return v;   }   bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); }   long long ceil(long long a, long long b) { return (a + b - 1) / b; }   void _print(long long t) { cerr << t; }   void _print(int t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long t) { cerr << t; }   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<  , ;     _print(p.second);     cerr <<  } ;   }   template <class T>   void _print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   void init() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   void solve() {     int n;     cin >> n;     vector<int> a(n + 1);     for (int i = 1; i <= n; i++) cin >> a[i];     vector<int> pos(n + 1);     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       pos[x] = i;     };     ;     for (int i = 1; i <= n; i++) a[i] = pos[a[i]];     ;     int c = 1;     for (int i = 2; i <= n; i++) {       if (a[i] > a[i - 1])         c++;       else         break;     }     cout << n - c;   }   int main() {     init();     long long test = 1;     while (test--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int a, b, x, y, ans;     scanf( %d %d , &a, &b);     ans = a;     while (a >= b) {       x = a / b;       ans = ans + x;       y = a % b;       a = x + y;     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[102];   char miao[] =  miao. ;   char lala[] =  lala. ;   int check(char* a) {     int res = 0;     int k = strlen(a);     if (k < 5) return 0;     if (strncmp(a, miao, 5) == 0) res += 2;     if (strncmp(a + k - 5, lala, 5) == 0) res += 1;     return res;   }   int main() {     int n, i, res;     cin >> n;     cin.getline(str, 101);     for (i = 0; i < n; i++) {       cin.getline(str, 101);       res = check(str);       if (res == 1)         cout <<  Freda s n ;       else if (res == 2)         cout <<  Rainbow s n ;       else         cout <<  OMG>.< I don t know! n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double esp = 1e-11;   const long double PI = acos((long double)-1);   const long long int INF = 0x3f3f3f3fll;   const int MOD = 1000000007ll;   const int maxn = 200001;   int inv[maxn], pin_inv[maxn], pin[maxn];   void initCab(int N) {     inv[0] = pin[0] = pin_inv[0] = inv[1] = pin[1] = pin_inv[1] = 1;     for (int x = 2; x <= N; x++) {       inv[x] = (long long int)(MOD - MOD / x) * inv[MOD % x] % MOD;       pin[x] = (long long int)pin[x - 1] * x % MOD;       pin_inv[x] = (long long int)pin_inv[x - 1] * inv[x] % MOD;     }   }   long long int Cab(int n, int m) {     return (long long int)pin[n] * pin_inv[m] % MOD * pin_inv[n - m] % MOD;   }   long long int m[maxn], ans[10];   int main() {     initCab(maxn - 1);     int n;     scanf( %d , &n);     for (int x = 1; x <= n; x++) scanf( %d , &m[x]);     int f = 1;     if (n % 2 == 0) {       for (int x = 1; x < n; x++)         if (x & 1)           m[x] = (m[x] + m[x + 1]) % MOD;         else           m[x] = (m[x] - m[x + 1]) % MOD;       n--;       f = 0;     }     int time = (n - 1) / 4 * 4;     for (int x = 1; x <= n - time; x++) {       ans[x] = 0;       for (int y = 1; y <= time + 1; y++)         if (y & 1) {           ans[x] = (ans[x] + m[x + y - 1] * Cab(time / 2, y / 2)) % MOD;         }     }     n -= time;     while (n > 1) {       for (int x = 1; x < n; x++) {         if (f & 1)           ans[x] = (ans[x] + ans[x + 1]) % MOD;         else           ans[x] = (ans[x] - ans[x + 1]) % MOD;         f ^= 1;       }       n--;     }     ans[1] = (ans[1] % MOD + MOD) % MOD;     printf( %I64d n , ans[1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int dx[] = {0, 1, -1, 0, 1, -1, -1, 1};   const long long int dy[] = {-1, 0, 0, 1, 1, 1, -1, -1};   long long int gcd(long long int x, long long int y) {     return (y != 0 ? gcd(y, x % y) : x);   }   long long int lcm(long long int x, long long int y) {     return (x / gcd(x, y) * y);   }   long long int limak;   long long int pos;   char matei[300010];   vector<pair<long long int, pair<long long int, long long int> > > v;   long long int n;   bool compare(pair<long long int, pair<long long int, long long int> > a,                pair<long long int, pair<long long int, long long int> > b) {     return a.second.first > b.second.first;   }   long long int solve() {     pos = 1;     memset(matei, 0, sizeof matei);     priority_queue<pair<long long int, long long int>,                    vector<pair<long long int, long long int> >,                    greater<pair<long long int, long long int> > >         pq;     int idx;     long long int melhorPos = 300000000;     for (idx = 0; idx < n; idx++) {       if (v[idx].second.first <= limak || v[idx].first == 0) break;       pq.push(make_pair(v[idx].second.second - v[idx].second.first + 1,                         v[idx].first));       matei[v[idx].first] = 1;       pos++;     }     melhorPos = pos;     long long int precisa, id;     while (!pq.empty()) {       precisa = pq.top().first;       id = pq.top().second;       pq.pop();       if (precisa > limak) break;       limak -= precisa;       pos--;       for (idx = idx; idx < n; idx++) {         if (v[idx].second.first <= limak) break;         if (!matei[v[idx].first] && v[idx].first != 0) {           pq.push(make_pair(v[idx].second.second - v[idx].second.first + 1,                             v[idx].first));           matei[v[idx].first] = 1;           pos++;         }       }       if (pos < melhorPos) melhorPos = pos;     }     return melhorPos;   }   int main() {     cin >> n;     long long int t, w;     for (int i = 0; i < n; i++) {       cin >> t >> w;       if (i == 0) limak = t;       v.push_back(make_pair(i, make_pair(t, w)));     }     sort(v.begin(), v.end(), compare);     cout << solve() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 512;   const int INF = 0x3f3f3f3f;   long long dis[MAXN][MAXN], a[MAXN], ans[MAXN];   bool in[MAXN];   int n;   void Floyd() {     for (int k = n; k >= 1; k--) {       int t = a[k];       in[t] = 1;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           dis[i][j] = min(dis[i][j], dis[i][t] + dis[t][j]);           if (in[i] && in[j]) ans[k] += dis[i][j];         }       }     }     for (int i = 1; i <= n; i++) printf( %lld  , ans[i]);     puts(  );   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         scanf( %lld , &dis[i][j]);       }     }     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);     }     Floyd();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 200005;   const int Maxl = 20;   int table[Maxl][Maxn];   int tableor[Maxl][Maxn];   int numlog[Maxn];   int n, a[Maxn];   void buildTable() {     numlog[1] = 0;     for (int i = 2; i <= n; i++) {       numlog[i] = numlog[i >> 1] + 1;     }     for (int i = 0; i <= numlog[n]; i++) {       int curlen = 1 << i;       for (int j = 1; (j + curlen - 1) <= n; j++) {         if (i == 0) {           table[i][j] = j;           continue;         } else {           if (a[table[i - 1][j]] >= a[table[i - 1][j + (curlen >> 1)]]) {             table[i][j] = table[i - 1][j];           } else {             table[i][j] = table[i - 1][j + (curlen >> 1)];           }         }       }     }   }   void buildTableOr() {     for (int i = 0; i <= numlog[n]; i++) {       int curlen = 1 << i;       for (int j = 1; (j + curlen - 1) <= n; j++) {         if (i == 0) {           tableor[i][j] = a[j];           continue;         } else {           tableor[i][j] = tableor[i - 1][j] | tableor[i - 1][j + (curlen >> 1)];         }       }     }   }   int getMaxIndex(int l, int r) {     int curlog = numlog[r - l + 1];     if (a[table[curlog][l]] >= a[table[curlog][r - (1 << curlog) + 1]]) {       return table[curlog][l];     } else {       return table[curlog][r - (1 << curlog) + 1];     }   }   int RMQ(int l, int r) { return a[getMaxIndex(l, r)]; }   int getOr(int l, int r) {     int curlog = numlog[r - l + 1];     return (tableor[curlog][l] | tableor[curlog][r - (1 << curlog) + 1]);   }   int binary_search(int gst, int st, int end, int cur_or) {     while (st + 1 < end) {       int mid = (st + end) / 2;       int g = getOr(gst, mid);       if (g > cur_or)         end = mid;       else         st = mid;     }     int g = getOr(gst, end);     if (g == cur_or)       return end;     else {       return st;     }   }   int get() {     int ret = 0;     for (int i = 1; i <= n; i++) {       int cur_or = a[i];       int M = a[i];       for (int j = i; j <= n; j++) {         cur_or |= a[j];         M = max(M, a[j]);         if (cur_or > M) {           ret++;         }       }     }     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     buildTable();     buildTableOr();     long long ans = 0;     for (int i = n; i >= 1; i--) {       int cur_or = a[i];       int st = i;       int end = binary_search(i, i, n, cur_or);       int idx = getMaxIndex(st, end);       if (a[idx] < cur_or) {         ans += (long long)end - st + 1;       } else {         ans += (long long)idx - st;       }       while (end <= n) {         st = end + 1;         if (st > n) break;         cur_or = cur_or | a[st];         end = binary_search(i, st, n, cur_or);         idx = getMaxIndex(st, end);         if (a[idx] < cur_or)           ans += (long long)end - st + 1;         else           ans += (long long)idx - st;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 30;   int n, in[100010], cnt, dyn[100010];   void check() {     if (cnt < 2) {       printf( %d n , cnt);       exit(0);     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &in[i]);     for (int i = n - 1; i >= 0; i--) dyn[i] = dyn[i + 1] + (in[i] == 0 ? 1 : 0);     if (n == 2) {       if (in[0] == 0 && in[1] != 0)         printf( 1 n );       else         printf( 0 n );       return 0;     }     if (dyn[0] > 1) {       int ans = INF;       if (dyn[0] == n) ans = min(ans, 0);       if (dyn[1] >= n - 2) ans = min(ans, n - 1 - dyn[1]);       if (dyn[2] == n - 2) ans = min(ans, n - 2);       if (ans < 2)         printf( %d n , ans);       else         printf( 2 n );       return 0;     }     bool t = true;     for (int i = 2; i < n; i++)       if (in[i] * in[i - 2] != in[i - 1] * in[i - 1]) t = false;     if (t) {       printf( 0 n );       return 0;     }     if (n == 3) {       if (in[1] == 0) goto l;     }     t = true;     for (int i = 2; i < n; i++)       if (in[i] * in[1] != in[2] * in[i - 1]) t = false;     if (t) {       printf( 1 n );       return 0;     }   l:;     cnt = 0;     for (int i = 1; i < n; i++) {       if (in[i] * in[0] != in[1] * in[i - 1]) {         cnt++;         if (i < n - 1 && in[i + 1] * in[0] != in[1] * in[i - 1]) cnt++;         i++;       }     }     check();     cnt = 0;     for (int i = 1; i < n; i++) {       if (in[i] * in[1] != in[2] * in[i - 1]) {         cnt++;         if (i < n - 1 && in[i + 1] * in[1] != in[2] * in[i - 1]) cnt++;         i++;       }     }     check();     cnt = 0;     for (int i = 1; i < n; i++) {       if (in[i] * in[0] != in[2] * in[i - 1]) {         cnt++;         if (i < n - 1 && in[i + 1] * in[0] != in[2] * in[i - 1]) cnt++;         i++;       }     }     check();     printf( 2 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, x, y, c = 0, d = 0;     cin >> n;     long long m = n;     while (n--) {       scanf( %lld %lld , &x, &y);       if (x > 0) c++;       if (x < 0) d++;     }     if (c == m - 1 || d == m - 1 || c == m || d == m)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int M = 1e5 + 50;   map<int, int> vis, cnt;   int main() {     int n;     long long ans = 0;     scanf( %lld , &n);     for (int i = 0; i < n; i++) {       int ch, tmp;       scanf( %d , &ch);       if (!vis[ch]) {         vis[ch] = 1;         cnt[ch] = vis.size() - 1;         tmp = vis.size() - 1;       } else {         tmp = vis.size() - cnt[ch];         cnt[ch] = vis.size();       }       ans += 1ll * tmp;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5010;   int f[MAXN];   string s;   int l;   int ans[MAXN];   int help[MAXN];   int nim[MAXN];   int start[MAXN];   void init() {     f[0] = 0;     f[1] = 1;     for (int i = 2; i <= l; ++i) {       memset(nim, 0, sizeof(nim));       nim[f[i - 2] ^ f[0]] = 1;       for (int j = 2; j <= i - 1; ++j) nim[f[i - j - 1] ^ f[j - 2]] = 1;       for (int j = 0;; ++j)         if (nim[j] == 0) {           f[i] = j;           break;         }     }   }   int main() {     cin >> s;     l = s.size();     init();     int top = 0;     for (int i = 1; i < l - 1; ++i)       if (s[i - 1] == s[i + 1]) ans[++top] = i;     int cnt = 0;     if (top >= 1) {       help[1] = 1;       start[1] = ans[1];       cnt = 1;     }     for (int i = 2; i <= top; ++i)       if (ans[i] == ans[i - 1] + 1)         help[cnt]++;       else {         cnt++;         help[cnt] = 1;         start[cnt] = ans[i];       }     int out = 0;     for (int i = 1; i <= cnt; ++i) out = out ^ f[help[i]];     if (!out)       cout <<  Second  << endl;     else {       cout <<  First  << endl;       for (int j = 1; j <= cnt; ++j) {         if (help[j] == 1) {           if (!out ^ f[help[j]]) {             cout << start[j] + 1 << endl;             return 0;           }         }         if (!(out ^ f[help[j]] ^ f[help[j] - 2])) {           cout << start[j] + 1 << endl;           return 0;         }         for (int k = 2; k <= help[j] - 1; ++k)           if (!(out ^ f[help[j]] ^ f[help[j] - k - 1] ^ f[k - 2])) {             cout << start[j] + k << endl;             return 0;           }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int skip_classes[501][501], dp[501][501], N, M, K;   vector<int> timings[501];   vector<string> grid(501);   void preprocess() {     for (long long int i = 1; i <= N; i++) {       int total_classes_on_day_i = timings[i].size();       for (int skip = 0; skip <= K; skip++) {         skip_classes[i][skip] = INT_MAX;         int to_attend = total_classes_on_day_i - skip;         if (to_attend <= 0)           skip_classes[i][skip] = 0;         else           for (int j = to_attend - 1; j < timings[i].size(); j++) {             skip_classes[i][skip] =                 (skip_classes[i][skip] <=                          timings[i][j] - timings[i][j - to_attend + 1] + 1                      ? skip_classes[i][skip]                      : timings[i][j] - timings[i][j - to_attend + 1] + 1);           }       }     }     return;   }   long long int solve_for(long long int day, long long int can_skip) {     if (can_skip < 0) return INT_MAX;     if (day == 0) return 0;     if (dp[day][can_skip] != -1) return dp[day][can_skip];     long long int ans = INT_MAX, current_ans;     for (long long int i = 0; i <= can_skip; i++) {       current_ans = solve_for(day - 1, can_skip - i) + skip_classes[day][i];       ans = (ans <= current_ans ? ans : current_ans);     }     return dp[day][can_skip] = ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(dp, -1, sizeof dp);     cin >> N >> M >> K;     for (long long int i = 1; i <= N; i++) {       cin >> grid[i];       for (int j = 0; j < grid[i].size(); j++) {         if (grid[i][j] ==  1 ) timings[i].push_back(j + 1);       }     }     preprocess();     long long int ans = solve_for(N, K);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> years;     int curr = 1;     for (int i = 1; i <= n; ++i) {       int x;       cin >> x;       if (x == curr) {         ++curr;         years.push_back(2000 + i);       }     }     cout << years.size() << endl;     for (int year : years) {       cout << year <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, k, a[100005];   bool pos(int len) {     set<pair<int, int> > ms;     for (int i = 1; i <= n; i++) {       ms.insert(make_pair(a[i], i));       if (i >= len) {         auto it = ms.begin();         int mn = (*it).first;         it = ms.end();         it--;         int mx = (*it).first;         if (mx - mn <= k) return 1;         ms.erase(make_pair(a[i - len + 1], i - len + 1));       }     }     return 0;   }   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     int hi = n, lo = 1;     while (hi > lo) {       int mid = (hi + lo + 1) / 2;       if (pos(mid))         lo = mid;       else         hi = mid - 1;     }     int len = hi;     vector<int> ans;     set<pair<int, int> > ms;     for (int i = 1; i <= n; i++) {       ms.insert(make_pair(a[i], i));       if (i >= len) {         auto it = ms.begin();         int mn = (*it).first;         it = ms.end();         it--;         int mx = (*it).first;         if (mx - mn <= k) ans.push_back(i - len + 1), ans.push_back(i);         ms.erase(make_pair(a[i - len + 1], i - len + 1));       }     }     printf( %d %d n , hi, (int)ans.size() / 2);     for (int i = 0; i < ans.size(); i += 2) printf( %d %d n , ans[i], ans[i + 1]);   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   int cnt[10];   int ans[5], id[5];   int main() {     int n, s;     scanf( %d%d , &n, &s);     int a;     for (int i = 0; i < n; i++) {       scanf( %d , &a);       cnt[a]++;     }     int A, B, C, mx = 0x3f3f3f3f;     for (int i = s / n; i >= 0; i--) {       id[0] = i;       A = cnt[3] * id[0];       for (int j = (s - A) / (cnt[4] + cnt[5]); j >= i; j--) {         id[1] = j;         B = cnt[4] * id[1];         C = s - A - B;         id[2] = C / cnt[5];         if (C % cnt[5]) continue;         int tmp = abs(A - B) + abs(B - C);         if (tmp >= mx && B <= C) break;         if (tmp < mx) {           ans[0] = id[0];           ans[1] = id[1];           ans[2] = id[2];           mx = tmp;         }       }     }     if (mx == 0x3f3f3f3f)       puts( -1 );     else       printf( %d %d %d n , ans[0], ans[1], ans[2]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, ans = 0;     cin >> n;     string x;     cin >> x;     for (long long int i = 0; i < x.length(); i++) {       if (x[i] ==  0  || x[i] ==  2  || x[i] ==  4  || x[i] ==  6  ||           x[i] ==  8 ) {         ans += (i + 1);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int r, c, d[1020][1020], used[1020][1020];   string s[1020];   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   long long ans = 0;   bool ok(int x, int y) {     return x >= 0 && x < r && y >= 0 && y < c && s[x][y] !=  T ;   }   void bfs(int x, int y) {     used[x][y] = 1;     queue<pair<int, int> > q;     q.push(make_pair(x, y));     d[x][y] = 0;     while (q.empty() == false) {       int xk = q.front().first, yk = q.front().second;       q.pop();       for (int i = 0; i < 4; i++) {         int xx = xk + dx[i];         int yy = yk + dy[i];         if (ok(xx, yy) == true && used[xx][yy] == 0) {           used[xx][yy] = 1;           d[xx][yy] = d[xk][yk] + 1;           q.push(make_pair(xx, yy));         }       }     }   }   int main() {     scanf( %d %d , &r, &c);     int sx, sy, ex, ey;     for (int i = 0; i < r; i++) {       cin >> s[i];       for (int j = 0; j < c; j++) {         if (s[i][j] ==  S ) {           sx = i;           sy = j;           s[i][j] =  0 ;         } else if (s[i][j] ==  E ) {           ex = i;           ey = j;           s[i][j] =  0 ;         }       }     }     bfs(ex, ey);     int need = d[sx][sy];     for (int i = 0; i < r; i++) {       for (int j = 0; j < c; j++) {         if (s[i][j] ==  T  && i == sx && j == sy) continue;         int add = (int)(s[i][j] -  0 );         if (d[i][j] <= need && d[i][j] != 0) {           ans += add;         }       }     }     printf( %lld , ans);     return 0;   }


#include <iostream>   using namespace std;   typedef long long ll;      int main() {    int t; cin >> t; while (t--) {     ll n, m, x; cin >> n >> m >> x; x--;     ll j = x / n, i = x % n;     cout << i * m + j + 1 <<   n ;    }    cin.ignore(2); return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, mp[5][1000050];   int sta[20], cnt[20], tot;   char s[1000050];   int f[1000050][20], ans;   void init() {     for (int i = 0; i < (1 << n); i++) {       sta[++tot] = i;       int u = i;       while (u) {         cnt[tot] += ((u % 2) ^ 0);         u >>= 1;       }     }   }   int change(int id, int y) {     int ans = 0, status = sta[id];     for (int i = n; i >= 1; i--, status >>= 1) ans += ((status % 2) ^ mp[i][y]);     return ans;   }   void dp() {     init();     memset(f, 0x3f, sizeof f);     for (int i = 1; i <= tot; i++) f[1][i] = change(i, 1);     for (int i = 2; i <= m; i++)       for (int j = 1; j <= tot; j++)         for (int k = 1; k <= tot; k++) {           int a = sta[j], b = sta[k];           int last = a % 2 + b % 2, now, flag = 1;           a >>= 1;           b >>= 1;           for (int l = n - 1; l >= 1; l--) {             now = a % 2 + b % 2;             a >>= 1;             b >>= 1;             if ((last + now) % 2 == 0) flag = 0;             last = now;           }           if (flag) f[i][j] = min(f[i][j], f[i - 1][k] + change(j, i));         }   }   int main() {     scanf( %d%d , &n, &m);     if (min(n, m) >= 4) {       printf( -1 );       return 0;     }     if (n == 1) {       printf( 0 );       return 0;     }     for (int i = 1; i <= n; i++) {       scanf( %s , s + 1);       for (int j = 1; j <= m; j++) mp[i][j] = s[j] -  0 ;     }     dp();     ans = n * m;     for (int i = 1; i <= tot; i++) ans = min(ans, f[m][i]);     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const long long INF = 1e9;   const int MX = 2e5 + 10;   const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0};   template <class T>   using V = vector<T>;   template <class T>   bool ckmin(T& a, const T& b) {     return a > b ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   long long cdiv(long long a, long long b) {     return a / b + ((a ^ b) > 0 && a % b);   }   mt19937 rng(chrono::system_clock::now().time_since_epoch().count());   long long random(long long a, long long b) { return a + rng() % (b - a + 1); }   void IO() {}   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     IO();     int N;     cin >> N;     vector<int> a(N);     for (int i = (0); i < (N); ++i) cin >> a[i];     int cnt[101];     fill(cnt, cnt + 101, 0);     int mx = 0, D;     for (auto x : a) {       cnt[x]++;       if (ckmax(mx, cnt[x])) D = x;     }     int ans = 0;     for (int V = (1); V < (101); ++V)       if (V != D) {         vector<int> v(N);         for (int i = (0); i < (N); ++i) {           if (a[i] == D)             v[i] = 1;           else if (a[i] == V)             v[i] = -1;           else             v[i] = 0;         }         unordered_map<int, int> pre;         int s = 0;         for (int i = (0); i < (N); ++i) {           s += v[i];           pre[s] = INF;         }         pre[0] = -1;         for (int i = (0); i < (N); ++i) {           if (i) v[i] += v[i - 1];           ckmax(ans, i - pre[v[i]]);           if (pre[v[i]] == INF) pre[v[i]] = i;         }       }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, j, k, m;   int a[100010];   long long f[110][100010], n;   long long dfs(int n, long long m) {     if (!n) return m;     if (m < 100010 && f[n][m] >= 0) return f[n][m];     long long A = dfs(n - 1, m) - dfs(n - 1, m / a[n]);     if (m < 100010) f[n][m] = A;     return A;   }   int main() {     scanf( %I64d%d , &n, &m);     for (i = 1; i <= m; i++) scanf( %d , &a[i]);     sort(a + 1, a + m + 1);     memset(f, 255, sizeof(f));     printf( %I64d n , dfs(m, n));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     string s, t;     cin >> s >> t;     int sum1 = 0, sum2 = 0, sum3 = 0;     for (int i = 0; i < 2 * n; i++) {       if (s[i] ==  1  && t[i] ==  1 ) {         sum3++;         continue;       }       sum1 += (s[i] ==  1 );       sum2 += (t[i] ==  1 );     }     if (sum3 % 2) {       if (sum1 + 1 == sum2 || sum1 + 2 == sum2) {         cout <<  Draw n ;       } else {         cout << ((sum1 >= sum2) ?  First  :  Second ) <<   n ;       }     } else {       if (sum1 == sum2 || sum1 + 1 == sum2) {         cout <<  Draw n ;       } else {         cout << ((sum1 > sum2) ?  First  :  Second ) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ni() {     int a;     scanf( %d , &a);     return a;   }   double nf() {     double a;     scanf( %lf , &a);     return a;   }   char sbuf[100005];   string ns() {     scanf( %s , sbuf);     return sbuf;   }   long long nll() {     long long a;     scanf( %lld , &a);     return a;   }   template <class T>   void out(T a, T b) {     bool first = true;     for (T i = a; i != b; ++i) {       if (!first) printf(   );       first = false;       cout << *i;     }     printf(  n );   }   template <class T>   void outl(T a, T b) {     for (T i = a; i != b; ++i) {       cout << *i <<   n ;     }   }   int n, m;   int ans[100005];   int main() {     int i, j, k;     vector<pair<pair<int, int>, int> > v;     n = ni();     for (i = (0); i < (((n))); ++i) {       int a = ni();       int b = ni();       v.push_back(make_pair(make_pair(a, b), i));     }     sort((v).begin(), (v).end());     reverse((v).begin(), (v).end());     vector<pair<int, int> > s;     vector<int> sa;     for (i = (0); i < (((v.size()))); ++i) {       pair<int, int> last = make_pair(-1, -1);       pair<int, int> vv = v[i].first;       int aa = 1;       while (s.size()) {         if (s.back().first >= vv.first + vv.second)           break;         else {           if (last.second == -1 || last.first + last.second <= s.back().first)             aa += sa.back();           if (vv.first + vv.second >= s.back().first + s.back().second) {             last = s.back();             s.pop_back();             sa.pop_back();           } else             break;         }       }       s.push_back(vv);       sa.push_back(aa);       ans[v[i].second] = aa;     }     out(ans, ans + n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 0x3f3f3f3f;   const double EPS = 1e-6;   const double PI = acos(-1.0);   string second;   int ch = 0;   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> second;     for (int i = 0; second[i]; i++) {       while (ch != second[i] + 1) {         ch--;         cout <<  ... n.X. n... n ;         if (ch < 0) ch = 255;       }       cout <<  .X. n.X. n... n ;       ch--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, a[N];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + n + 1);     if (a[n] >= a[n - 1] + a[n - 2])       cout <<  NO ;     else {       cout <<  YES n ;       cout << a[n] <<    ;       for (int i = n - 2; i >= 1; i--) cout << a[i] <<    ;       cout << a[n - 1];     }     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 4e5 + 5, MAXLOG = 20, MAXS = MAXN * 50;   template <typename _T>   void read(_T &x) {     x = 0;     char s = getchar();     int f = 1;     while (s >  9  || s <  0 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = (x << 3) + (x << 1) + (s -  0 ), s = getchar();     }     x *= f;   }   template <typename _T>   void write(_T x) {     if (x < 0) {       putchar( - );       x = (~x) + 1;     }     if (9 < x) {       write(x / 10);     }     putchar(x % 10 +  0 );   }   template <typename _T>   _T MAX(const _T a, const _T b) {     return a > b ? a : b;   }   template <typename _T>   _T MIN(const _T a, const _T b) {     return a < b ? a : b;   }   struct edge {     int to, nxt;   } Graph[MAXN << 1];   int f[MAXN][MAXLOG];   bool s[MAXS];   int lch[MAXS], rch[MAXS];   int dp[MAXN], seq[MAXN], ID;   int ch[MAXN][26], fa[MAXN], mx[MAXN], head[MAXN], rot[MAXN], fir[MAXN];   int N, lg2, rt, lst, tot, cnt, siz;   char S[MAXN];   void upt(const int x) { s[x] = s[lch[x]] | s[rch[x]]; }   void copy(int a, int b) {     fa[a] = fa[b], mx[a] = mx[b], memcpy(ch[a], ch[b], sizeof ch[b]);   }   void addEdge(const int from, const int to) {     Graph[++cnt].to = to, Graph[cnt].nxt = head[from];     head[from] = cnt;   }   void expand(const char c) {     int x = c -  a , p = lst, cur = ++tot;     mx[cur] = mx[lst] + 1, lst = cur;     while (p && !ch[p][x]) ch[p][x] = cur, p = fa[p];     if (!p) {       fa[cur] = rt;       return;     }     int q = ch[p][x];     if (mx[q] == mx[p] + 1) {       fa[cur] = q;       return;     }     int nq = ++tot;     copy(nq, q);     mx[nq] = mx[p] + 1, fa[q] = fa[cur] = nq;     while (p && ch[p][x] == q) ch[p][x] = nq, p = fa[p];   }   void update(int &u, const int l, const int r, const int pos) {     if (!u) u = ++siz;     if (l == r) {       s[u] = true;       return;     }     int mid = l + r >> 1;     if (pos <= mid)       update(lch[u], l, mid, pos);     else       update(rch[u], mid + 1, r, pos);     upt(u);   }   bool query(const int u, const int l, const int r, const int segL,              const int segR) {     if (!u) return false;     if (segL <= l && r <= segR) return s[u];     int mid = l + r >> 1, ret = false;     if (segL <= mid) ret |= query(lch[u], l, mid, segL, segR);     if (mid < segR) ret |= query(rch[u], mid + 1, r, segL, segR);     return ret;   }   int merg(int u, int v) {     if (!u || !v) return u + v;     int cur = ++siz;     lch[cur] = merg(lch[u], lch[v]);     rch[cur] = merg(rch[u], rch[v]);     s[cur] = s[u] | s[v];     return cur;   }   void DFS(const int u) {     seq[++ID] = u;     for (int i = head[u], v; i; i = Graph[i].nxt) {       DFS(v = Graph[i].to);       rot[u] = merg(rot[u], rot[v]);       fir[u] = MIN(fir[u], fir[v]);     }   }   int main() {     rt = lst = ++tot;     memset(fir, 0x3f, sizeof fir);     read(N), scanf( %s , S + 1);     for (int i = 1; i <= N; i++)       expand(S[i]), update(rot[lst], 1, N, i), fir[lst] = i;     for (int i = 2; i <= tot; i++) addEdge(fa[i], i);     DFS(rt);     lg2 = log2(tot);     for (int i = 1; i <= tot; i++) f[i][0] = fa[i];     for (int j = 1; j <= lg2; j++)       for (int i = 1; i <= tot; i++) f[i][j] = f[f[i][j - 1]][j - 1];     for (int i = tot, u, p; i; i--) {       u = p = seq[i];       for (int k = lg2; ~k; k--)         if (f[p][k] > rt &&             !query(rot[f[p][k]], 1, N, fir[u] - mx[u] + mx[f[p][k]], fir[u] - 1))           p = f[p][k];       p = fa[p];       dp[p] = MAX(dp[p], dp[u] + 1);     }     write(dp[rt]), putchar(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, result = 0;     {       cin >> n;       float init = sqrt(n);       if (init == floor(init))         cout << init * 4 << endl;       else {         int init2 = floor(init);         n = n - init2 * init2;         result = init2 * 4;         if (n > init2) {           int temp1 = n / 2;           result = result + (temp1 + 1) * 2 - temp1 * 2;           int temp2 = n - n / 2;           result = result + (temp2 + 1) * 2 - temp2 * 2;         } else           result = result + (n + 1) * 2 - n * 2;         cout << result << endl;       }     }     return 0;   }