#include <bits/stdc++.h>   using namespace std;   vector<int> getPrimes(int n) {     vector<bool> sieve(n + 1, true);     sieve[0] = sieve[1] = false;     for (int i = 2; i * i <= n; i++)       if (sieve[i])         for (int j = i * i; j <= n; j += i) sieve[j] = false;     vector<int> primes;     for (int i = 2; i <= n; i++)       if (sieve[i]) primes.push_back(i);     return primes;   }   void storePrimes(int n, unordered_map<int, int> &m, vector<int> &primes) {     for (int p : primes) {       if (p * p > n) break;       while (n % p == 0) {         m[p]++;         n /= p;       }       if (n == 1) break;     }     if (n > 1) m[n]++;   }   void removePrimes(int n, unordered_map<int, int> &m, vector<int> &primes) {     for (int p : primes) {       if (p * p > n) break;       while (n % p == 0) {         m[p]--;         n /= p;       }       if (n == 1) break;     }     if (n > 1) m[n]--;   }   bool isAtleast(unordered_map<int, int> &m1, unordered_map<int, int> &m2) {     for (auto it = m2.begin(); it != m2.end(); it++) {       int num = it->first, freq = it->second;       if (m1.find(num) == m1.end() or m1[num] < freq) return false;     }     return true;   }   void printMap(unordered_map<int, int> &m) {     for (auto it = m.begin(); it != m.end(); it++)       cout << it->first <<  :   << it->second <<   n ;   }   long long int solve(int arr[], int n, int k) {     vector<int> primes = getPrimes(1000003);     unordered_map<int, int> mapK, currMap;     storePrimes(k, mapK, primes);     int i = 0, j = 0;     long long int count = 0;     while (j < n) {       storePrimes(arr[j], currMap, primes);       if (isAtleast(currMap, mapK)) {         while (i <= j and isAtleast(currMap, mapK)) {           count += (n - j);           removePrimes(arr[i], currMap, primes);           i++;         }       }       j++;     }     return count;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     long long int ans = solve(arr, n, k);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q, p, p1, maxi, a[1000000], idx;   stack<int> t, t1, id;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     maxi = -1;     id.push(0);     t.push(200000);     t1.push(-1);     for (int i = 1; i < n; i++) {       p = 0;       q = 5;       while (q == 5) {         idx = id.top();         p1 = t.top();         p = t1.top() + 1;         if (a[idx] > a[i] && p <= p1) {           q = 6;           t1.top() = p;           if (p > maxi) maxi = p;           id.push(i);           t.push(p);           t1.push(-1);         } else if (p1 == 200000) {           q = 7;           id.push(i);           t.push(200000);           t1.push(-1);         } else {           id.pop();           t.pop();           t1.pop();         }       }     }     printf( %d , maxi + 1);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int i, n, m;     cin >> n >> m;     vector<int> a(n + m);     for (i = 0; i < n + m; i++) {       cin >> a[i];     }     set<int> tax, per;     for (i = 0; i < n + m; i++) {       int t;       cin >> t;       if (t == 0) {         per.insert(a[i]);       } else {         tax.insert(a[i]);       }     }     map<int, int> ans;     for (auto cur : per) {       auto right = tax.upper_bound(cur);       auto left = --tax.upper_bound(cur);       if (left == tax.end()) {         ans[*right]++;       } else if (right == tax.end()) {         ans[*left]++;       } else {         int l = *left, r = *right;         if (cur - l <= r - cur) {           ans[l]++;         } else {           ans[r]++;         }       }     }     for (auto cur : tax) {       cout << ans[cur] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   auto fio = (ios::sync_with_stdio(0), cin.tie(0), cout.tie(0));   int32_t main() {     long long n;     cin >> n;     vector<long long> g(n);     for (long long& x : g) cin >> x;     vector<vector<long long>> idx(8192);     for (long long i = 0; i < n; i++) idx[g[i]].push_back(i);     vector<long long> mn(8192, n);     mn[0] = -1;     for (long long i = 0; i <= 5000; i++) {       if (idx[i].empty()) continue;       for (long long j = 0; j < 8192; j++) {         if (mn[j] <= mn[i ^ j] || mn[i ^ j] >= idx[i].back()) continue;         auto it = upper_bound(idx[i].begin(), idx[i].end(), mn[i ^ j]);         if (it != idx[i].end() && *it < mn[j]) mn[j] = *it;       }     }     cout << 8192 - count(mn.begin(), mn.end(), n) << endl;     for (long long i = 0; i < 8192; i++)       if (mn[i] != n) cout << i <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct _ {     _() { ios_base::sync_with_stdio(0); }   } _;   template <class T>   void PV(T a, T b) {     while (a != b) cout << *a++, cout << (a != b ?     :   n );   }   template <class T>   inline bool chmin(T &a, T b) {     return a > b ? a = b, 1 : 0;   }   template <class T>   inline bool chmax(T &a, T b) {     return a < b ? a = b, 1 : 0;   }   const int inf = 0x3f3f3f3f;   const int mod = int(1e9) + 7;   const int N = 3 * 111111;   int n, q;   int d[N];   int p[N];   int v[N];   void add(int first, int t) {     if (first == 0) return;     while (first <= n) {       v[first] += t;       first += first & (first ^ (first - 1));     }   }   int sum(int first) {     int r = 0;     while (first > 0) {       r += v[first];       first -= first & (first ^ (first - 1));     }     return r;   }   int main() {     cin >> n;     p[0] = 0, p[n + 1] = n + 1;     for (int i = 1; i <= n; i++) cin >> d[i], p[d[i]] = i;     for (int i = 1; i <= n; i++)       if (p[d[i] - 1] > i) add(d[i], 1);     cin >> q;     while (q--) {       int op, l, r, t;       cin >> op >> l >> r;       if (op == 1) {         cout << sum(r) - sum(l) + 1 << endl;       } else {         if (d[l] > d[r]) {           t = p[d[r] - 1];           if (l < t && t < r) add(d[r], 1);           t = p[d[r] + 1];           if (l < t && t < r) add(d[r] + 1, -1);           t = p[d[l] + 1];           if (l < t && t < r) add(d[l] + 1, 1);           t = p[d[l] - 1];           if (l < t && t < r) add(d[l], -1);           if (d[l] == d[r] + 1) add(d[l], -1);         } else if (d[l] < d[r]) {           t = p[d[l] - 1];           if (l < t && t < r) add(d[l], -1);           t = p[d[l] + 1];           if (l < t && t < r) add(d[l] + 1, 1);           t = p[d[r] + 1];           if (l < t && t < r) add(d[r] + 1, -1);           t = p[d[r] - 1];           if (l < t && t < r) add(d[r], 1);           if (d[l] == d[r] - 1) add(d[r], 1);         }         swap(d[l], d[r]);         p[d[l]] = l, p[d[r]] = r;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( popcnt )   using namespace std;   mt19937 bruh(chrono::steady_clock::now().time_since_epoch().count());   const long long N = 2e5 + 100;   const long long mod = 1e9 + 7;   const long long big = 1e17;   long long t, n, h;   long long a[N];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> t;     while (t--) {       cin >> n >> h;       for (int i = 1; i <= n; i++) cin >> a[i];       sort(a + 1, a + n + 1);       long long l = 1, r = 1e18, ans = h;       while (l <= r) {         long long m = (l + r) >> 1ll;         long long sum = 0, rtst = 0;         for (int i = 1; i <= n; i++) {           long long l = max(a[i] - 1ll, rtst), r = a[i] + m - 1;           sum = sum + (r - l);           rtst = r;         }         if (sum >= h)           r = m - 1ll, ans = m;         else           l = m + 1ll;       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int in(char &c) { return scanf( %c , &c); }   int in(char s[]) { return scanf( %s , s); }   int in(int &x) { return scanf( %d , &x); }   int in(long long &x) { return scanf( %lld , &x); }   int in(double &x) { return scanf( %lf , &x); }   int in(pair<int, int> &p) { return scanf( %d%d , &p.first, &p.second); }   int in(pair<long long, long long> &p) {     return scanf( %lld%lld , &p.first, &p.second);   }   int in(pair<double, double> &p) { return scanf( %lf%lf , &p.first, &p.second); }   int in(long double &a) { return scanf( %Lf , &a); }   int in(int &x, long long &y) { return scanf( %d%lld , &x, &y); }   int in(long long &x, int &y) { return scanf( %lld%d , &x, &y); }   int in(int &x, int &y) { return scanf( %d%d , &x, &y); }   int in(long long &x, long long &y) { return scanf( %lld%lld , &x, &y); }   int in(int &n, char s[]) { return scanf( %d%d , &n, s); }   int in(char a[], char b[]) { return scanf( %s%s , a, b); }   int in(double &x, double &y) { return scanf( %lf%lf , &x, &y); }   int in(int &x, int &y, int &z) { return scanf( %d%d%d , &x, &y, &z); }   int in(long long &x, long long &y, long long &z) {     return scanf( %lld%lld%lld , &x, &y, &z);   }   int in(double &x, double &y, double &z) {     return scanf( %lf%lf%lf , &x, &y, &z);   }   int in(int &x, int &y, int &z, int &k) {     return scanf( %d%d%d%d , &x, &y, &z, &k);   }   int in(long long &x, long long &y, long long &z, long long &k) {     return scanf( %lld%lld%lld%lld , &x, &y, &z, &k);   }   int in(double &x, double &y, double &z, double &k) {     return scanf( %lf%lf%lf%lf , &x, &y, &z, &k);   }   const int N = 3e5 + 10, M = 1e3 + 10, mod = 1e9 + 7;   const double eps = 1e-6, Pi = acos(-1.0);   int a[N], b[N], L[N], R[N], s[N];   vector<int> vc[N];   int check(int x, int y) { return (L[y] > R[x]); }   int query(int x, int p) {     x = max(0, x);     p = max(0, p);     int pos = upper_bound(vc[x].begin(), vc[x].end(), p) - vc[x].begin();     return pos;   }   int main() {     int T, t;     in(T);     t = T;     while (T--) {       int n;       in(n);       for (int i = 1; i <= n; i++) {         in(a[i]);         b[i] = a[i];       }       sort(b + 1, b + 1 + n);       int m = unique(b + 1, b + 1 + n) - b;       for (int i = 1; i <= n; i++)         a[i] = lower_bound(b + 1, b + m, a[i]) - b, s[a[i]]++,         vc[a[i]].push_back(i);       for (int i = n; i >= 1; i--) L[a[i]] = i;       for (int i = 1; i <= n; i++) s[i] += s[i - 1], R[a[i]] = i;       m--;       int l, r, ans = 0;       l = r = 1;       L[m + 1] = L[m];       R[m + 1] = R[m];       for (int i = 1; i <= m; i++) {         while (r <= m && check(r, r + 1)) r++;         int t = query(l - 1, L[l]) + (int)vc[r + 1].size() - query(r + 1, R[r]);         ans = max(ans, s[r] - s[l - 1] + t);         if (l == r) {           for (int j = 0; j < vc[l].size(); j++) {             ans = max(ans, (int)vc[l].size() + query(l - 1, vc[l][j]) - j);           }         }         ans = max(ans, s[r] - s[l - 1] + query(l - 1, L[l]));         if (r == m) break;         l = r + 1;         r++;       }       printf( %d n , n - ans);       for (int i = 1; i <= n; i++) s[i] = 0, vc[i].clear();     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     long long xa, ya, xb, yb, xc, yc;     cin >> xa >> ya >> xb >> yb >> xc >> yc;     long long s1 = (ya - yb) * (xa - xc);     long long s2 = (xa - xb) * (ya - yc);     if (s1 == s2) {       cout <<  TOWARDS ;       return 0;     }     if (s1 > s2)       cout <<  RIGHT ;     else       cout <<  LEFT ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int big = 0, small = 1000000000;     int a[1000];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > big) {         big = a[i];       }       if (a[i] < small) {         small = a[i];       }     }     cout << big - small + 1 - n;   }


#include <bits/stdc++.h>   using namespace std;   int a, ta, b, tb, hh, mm, res1, res2;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> a >> ta >> b >> tb;     char tmp;     cin >> hh >> tmp >> mm;     hh -= 5;     mm += hh * 60;     if (mm - tb >= 0) res1 = (mm - tb) / b + 1;     mm += ta;     mm = min(mm, (24 - 5) * 60);     mm--;     res2 = mm / b + 1;     cout << res2 - res1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int maxl[300005][20], minl[300005][20];   int vis[2 * 300005];   int a[300005];   int lmax[300005], lmin[300005], rmax[300005], rmin[300005];   int min(int a, int b) {     if (a > b) return b;     return a;   }   int max(int a, int b) {     if (a > b) return a;     return b;   }   void S_table(int n) {     int l = int(log((double)n) / log(2.0));     for (int j = 1; j <= l; j++) {       for (int i = 1; i + (1 << (j - 1)) - 1 <= n; ++i) {         maxl[i][j] = max(maxl[i][j - 1], maxl[i + (1 << (j - 1))][j - 1]);         minl[i][j] = min(minl[i][j - 1], minl[i + (1 << (j - 1))][j - 1]);       }     }   }   int w[300005];   int rmq(int l, int r) {     int k = w[r - l + 1];     int a1 = max(maxl[l][k], maxl[r - (1 << k) + 1][k]);     return a1;   }   void init(void) {     int i;     for (i = 1; i <= 300002; i++) {       int k = int(log((double)(i)) / log(2.0));       w[i] = k;     }   }   int rmq1(int l, int r) {     int k = w[r - l + 1];     int a2 = min(minl[l][k], minl[r - (1 << k) + 1][k]);     return a2;   }   struct pi {     int a, b;   } pp[300005];   int cmp(pi a, pi b) { return a.a < b.a; }   long long dfs(int x, int y) {     if (x == y) return 1;     if (y - x == 1) {       if (abs(pp[y].b - pp[x].b) == 1) return 3;       return 2;     }     long long s = 0;     s = dfs(x, (x + y) / 2);     s += dfs((x + y) / 2 + 1, y);     int mid = (x + y) / 2;     int i;     lmin[mid + 1] = 1000000000;     lmax[mid + 1] = -1000000000;     for (i = mid; i >= x; i--) {       lmin[i] = min(lmin[i + 1], pp[i].b);       lmax[i] = max(lmax[i + 1], pp[i].b);     }     rmin[mid] = 1000000000;     rmax[mid] = -1000000000;     for (i = mid + 1; i <= y; i++) {       rmin[i] = min(rmin[i - 1], pp[i].b);       rmax[i] = max(rmax[i - 1], pp[i].b);     }     for (i = mid; i >= x; i--) {       int a, b;       a = lmax[i];       b = lmin[i];       if (a - b + 1 > mid - i + 1) {         int p = a - b + 1 - (mid - i + 1);         if (p <= y - mid) {           if (rmax[mid + p] < a && rmin[mid + p] > b) {             s++;           }         }       }     }     for (i = mid + 1; i <= y; i++) {       int a, b;       a = rmax[i];       b = rmin[i];       if (a - b + 1 > i - mid) {         int p = a - b + 1 - (i - mid);         if (p <= mid - x + 1) {           if (lmax[mid - p + 1] < a && lmin[mid - p + 1] > b) {             s++;           }         }       }     }     int ss, tt;     ss = mid + 1;     tt = mid + 1;     for (i = mid; i >= x; i--) {       int a = lmax[i];       int b = lmin[i];       while (tt <= y && rmin[tt] >= b) {         vis[rmax[tt] - tt + 300005]++;         tt++;       }       while (ss <= y && rmax[ss] < a) {         vis[rmax[ss] - ss + 300005]--;         ss++;       }       if (tt <= ss) continue;       int p = vis[lmin[i] - i + 300005];       if (p > 0) s += p;     }     ss = mid;     tt = mid;     for (i = mid + 1; i <= y; i++) {       vis[rmax[i] - i + 300005] = 0;     }     for (i = mid + 1; i <= y; i++) {       int a = rmax[i];       int b = rmin[i];       while (tt >= x && lmin[tt] >= b) {         vis[lmax[tt] + tt]++;         tt--;       }       while (ss >= x && lmax[ss] < a) {         vis[lmax[ss] + ss]--;         ss--;       }       if (tt >= ss) continue;       int p = vis[rmin[i] + i];       if (p > 0) s += p;     }     for (i = x; i <= mid; i++) {       vis[lmax[i] + i] = 0;     }     return s;   }   int main() {     int i, n;     init();     cin >> n;     for (i = 1; i <= n; i++) {       int a, b;       scanf( %d%d , &a, &b);       pp[a].b = b;     }     for (i = 1; i <= n; i++) {       maxl[i][0] = pp[i].b;       minl[i][0] = pp[i].b;     }     S_table(n);     cout << dfs(1, n) << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n, p, a[100000], sum = 0;     cin >> n >> p;     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];       sum %= p;     }     sum = (sum + p - (a[0] % p)) % p;     int cur = a[0] % p, ans = cur + sum;     for (int i = 1; i < n - 1; ++i) {       cur = (cur + a[i]) % p, sum = (sum + p - (a[i] % p)) % p;       ans = max(ans, cur + sum);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   long long w, m, k;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());     cin >> w >> m >> k;     long long aa = 0;     int nc = 0;     while (aa < m) aa = aa * 10 + 9, ++nc;     long long m2 = m;     while (w) {       if ((aa - m + 1) <= w / k / nc) {         w = w - k * (aa - m + 1) * nc;         ++nc;         m = aa + 1;         aa = aa * 10 + 9;       } else {         m = m + w / k / nc;         break;       }     }     cout << m - m2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x;   vector<int> w;   vector<int> v;   bool volt[1111];   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x;       v.push_back(x);     }     reverse(v.begin(), v.end());     for (int i = 0; i < v.size(); i++) {       if (volt[v[i]] == false) {         w.push_back(v[i]);         volt[v[i]] = true;       }     }     reverse(w.begin(), w.end());     cout << w.size() << endl;     for (int i = 0; i < w.size(); i++) {       cout << w[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2005;   int n, m;   int a[maxn];   int cnt[maxn], vis[maxn];   int ans2 = 0;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int ans1 = n / m;     int p = n % m;     for (int i = 1; i <= n; i++) {       if (a[i] > m) continue;       if (cnt[a[i]] >= ans1) continue;       cnt[a[i]]++;       vis[i] = 1;     }     for (int i = 1; i <= n; i++) {       if (vis[i]) continue;       int Ans1 = 1e9, Ans2 = 1e9;       for (int j = 1; j <= m; j++) {         if (cnt[j] < Ans2) Ans2 = cnt[j], Ans1 = j;       }       if (Ans2 == ans1) continue;       ans2++;       cnt[Ans1]++, a[i] = Ans1;     }     cout << ans1 <<     << ans2 << endl;     for (int i = 1; i <= n; i++) cout << a[i] <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i = 0, j = 0, cs = 0, in;     int n;     cin >> n;     vector<int> v;     int sum = 0, s = 0;     for (int i = 1; i < n; i++) {       cout <<  ?   << i <<     << n <<   n ;       int x;       cin >> x;       if (i > 1) {         v.push_back(sum - x - s);         s += v.back();       } else         sum = x;     }     cout <<  ?   << 1 <<     << n - 1 <<   n ;     int x;     cin >> x;     cout <<  !  ;     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;     cout << x - s <<     << sum - x <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5;   int N, M, A[MAXN + 10], ans[MAXN + 10];   int main() {     int i, j;     scanf( %d%d , &N, &M);     long long sum = 0;     for (i = 1; i <= M; i++) scanf( %d , &A[i]), sum += A[i];     if (sum < N) return !printf( -1 );     int last = 987654321;     for (i = M; i >= 1; i--) {       int t = min(N - A[i] + 1, last - 1);       if (t <= 0) return !printf( -1 );       ans[i] = t;       last = t;     }     int start = 1;     for (i = 1; i <= M; i++) {       if (start >= ans[i]) break;       ans[i] = start;       start = A[i] + ans[i];     }     for (i = 1; i <= M; i++) printf( %d  , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   int n;   double p[100008];   struct Tprogram {     void open() {       freopen( 1.in ,  r , stdin);       freopen( 1.out ,  w , stdout);     }     void close() {}     void init() {       scanf( %d , &n);       for (int i = 0; i <= n; i++) scanf( %lf , &p[i]);     }     void work() {       double ans = 0;       for (int i = 0; i <= n >> 1; i++)         for (int j = (n >> 1) + 1; j <= n; j++)           ans = ((p[i] * (2 * j - n) + p[j] * (n - 2 * i)) / (2 * j - 2 * i) > ans                      ? (p[i] * (2 * j - n) + p[j] * (n - 2 * i)) / (2 * j - 2 * i)                      : ans);       printf( %.10lf n , ans);     }   } Program;   int main() {     Program.init();     Program.work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int m;     cin >> n >> m;     vector<int> zahlen(n);     for (int i = 0; i < n; i++) cin >> zahlen[i];     for (int i = 0; i < m; i++) {       int l, r, x;       cin >> l >> r >> x;       l--;       x--;       r--;       int tr = zahlen[x];       int count = 0;       for (int i = l; i <= r; i++) {         if (zahlen[i] < tr) count++;       }       if ((l + count) == x)         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   using vi = vector<int>;   using vll = vector<ll>;   using vii = vector<ii>;   const ll MOD = 998244353;   const ll INF = 1e15 + 9;   const int MAXN = 1000006;   int n, m, a[MAXN], p[MAXN], b[MAXN];   int rev[MAXN];   vi pos[MAXN];   vll sum[MAXN];   ll dp[MAXN], negsum[MAXN];   inline ll isum(int val, int R) {     int index =         lower_bound(pos[val].begin(), pos[val].end(), R) - pos[val].begin();     return sum[val][index];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int i = 1; i <= n; ++i) {       cin >> p[i];     }     cin >> m;     for (int i = 1; i <= m; ++i) {       cin >> b[i];     }     a[n + 1] = n + 1;     b[m + 1] = n + 1;     ++n, ++m;     for (int i = 0; i <= m; ++i) {       sum[2 * i + 1] = sum[2 * i] = vll(1);     }     for (int i = 0; i <= n; ++i) {       int bi = lower_bound(b, b + m, a[i]) - b;       a[i] = 2 * bi - (b[bi] != a[i]);       pos[a[i]].push_back(i);       ll prevsum = sum[a[i]].back();       sum[a[i]].push_back(prevsum + max(p[i], 0));       negsum[i + 1] = negsum[i] + min(p[i], 0);     }     for (int i = 1; i <= n; ++i) {       if (a[i] & 1) {         dp[i] = INF;         continue;       }       auto it = lower_bound(pos[a[i] - 2].begin(), pos[a[i] - 2].end(), i);       if (it == pos[a[i] - 2].begin()) {         dp[i] = INF;         continue;       }       --it;       dp[i] = dp[*it] + isum(a[i] - 1, i) + isum(a[i], i) + negsum[i] -               negsum[*it + 1];       it = lower_bound(pos[a[i]].begin(), pos[a[i]].end(), i);       if (it != pos[a[i]].begin()) {         --it;         dp[i] = min(dp[i], dp[*it] + negsum[i + 1] - negsum[*it + 1]);       }     }     if (dp[n] >= INF / 2) {       cout <<  NO n ;     } else {       cout <<  YES n  << dp[n] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, a, b, ans;   vector<long long> v[100005];   vector<long long> res;   long long cost(long long num) {     res.clear();     long long sum = 0;     long long need = num - v[0].size();     for (long long i = 1; i <= 100000; i++) {       for (long long j = 0; j < v[i].size(); j++) {         if (v[i].size() - j >= num) {           need--;           sum += v[i][j];         } else           res.push_back(v[i][j]);       }     }     sort(res.begin(), res.end());     for (long long i = 1; i <= need; i++) {       sum += res[i - 1];     }     return sum;   }   int main() {     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       scanf( %lld%lld , &a, &b);       v[a].push_back(b);     }     for (long long i = 1; i <= 100000; i++) sort(v[i].begin(), v[i].end());     long long l = v[0].size(), r = n, m1, m2;     ans = min(cost(l), cost(r));     while (l + 2 < r) {       m1 = l + (r - l) / 3;       m2 = r - (r - l) / 3;       long long a1 = cost(m1);       long long a2 = cost(m2);       if (a1 > a2)         l = m1, ans = min(ans, a2);       else         r = m2, ans = min(ans, a1);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Container>   void print(Container& container) {     auto Start = container.begin(), End = container.end();     while (Start != End) cout << *(Start++) <<    ;     cout <<   n ;   }   const int N = 5e2 + 1;   int dp[2][N][N], a[N];   inline void solve() {     int n, m, b, mod;     cin >> n >> m >> b >> mod;     for (int i = 1; i <= n; ++i) cin >> a[i];     dp[0][0][0] = 1;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j <= m; ++j) {         for (int k = 0; k <= b; ++k) {           dp[i & 1][j][k] = dp[i & 1 ^ 1][j][k];           if (j && k >= a[i]) dp[i & 1][j][k] += dp[i & 1][j - 1][k - a[i]];           dp[i & 1][j][k] %= mod;         }       }     }     int ans = 0;     for (int k = 0; k <= b; ++k) ans = (ans + dp[n & 1][m][k]) % mod;     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int T = 1;     while (T--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s1, s2;     getline(cin, s1);     getline(cin, s2);     sort(s1.begin(), s1.end());     sort(s2.begin(), s2.end());     int j(0);     for (int i = 0; i < s1.size(); i++) {       while (s2[j] ==    ) j++;       while (s1[i] ==    ) i++;       if (s1[i] == s2[j]) j++;       if (j == s2.size()) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<int> list;       int maxx, ma;       for (int i = 0; i < n; i++) {         int u;         cin >> u;         list.push_back(u);       }       int u1, u2, u3;       int flag;       for (int i = 1; i < n - 1; i++) {         flag = 0;         for (int j = 0; j < i; j++) {           if (list[i] > list[j]) {             flag = 1;             u1 = j;             break;           }         }         for (int j = i + 1; j < n; j++) {           if (list[i] > list[j]) {             if (flag == 1) {               flag = 2;               u2 = j;               break;             } else {               break;             }           }         }         if (flag == 2) {           u3 = i;           break;         }       }       if (flag == 2) {         cout <<  YES  << endl;         cout << u1 + 1 <<     << u3 + 1 <<     << u2 + 1 << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int DEBUG = 0;   bool isss(vector<int> s1, vector<int> s2) {     int si1, si2;     si1 = s1.size();     si2 = s2.size();     for (int i = 0; i < si1; i++) {       bool ttt = false;       for (int j = 0; j < si2; j++) {         if (s1[i] == s2[j]) {           ttt = true;         }       }       if (!ttt) return false;     }     return true;   }   int main(int argc, char **argv) {     DEBUG = (argc >= 2) ? atoi(argv[1]) : 0;     int n;     cin >> n;     int m[n];     vector<int> a[n];     for (int i = 0; i < n; i++) {       cin >> m[i];       for (int j = 0; j < m[i]; j++) {         int tmp;         cin >> tmp;         a[i].push_back(tmp);       }     }     bool isp[n];     for (int i = 0; i < n; i++) isp[i] = true;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i != j) {           if (isss(a[i], a[j])) {             isp[j] = false;           }         }       }     }     for (int i = 0; i < n; i++)       if (isp[i])         cout <<  YES  << endl;       else         cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = (long long)1e5 + 10;   vector<long long> G[MAXN];   pair<long long, long long> p;   vector<long long> v;   long long n, x, y, k, ans, sum, flag;   string s;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> y;       v.push_back(x);       v.push_back(y);     }     cin >> k;     long long i = 0;     while (!flag) {       if (v[i] < k) {         i++;       } else {         flag = 1;         i--;       }     }     cout << n - (i + 1) / 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, i, j, k;     cin >> n;     vector<string> v;     vector<pair<int, string> > v1;     for (i = 0; i < n; i++) {       string s;       cin >> s;       v.push_back(s);       v1.push_back(make_pair(s.length(), s));     }     sort(v1.begin(), v1.end());     int flag = 1;     for (i = n - 1; i >= 0; i--) {       pair<int, string> temp = v1[i];       string s = temp.second;       for (j = 0; j < i; j++) {         pair<int, string> temp1 = v1[j];         string s1 = temp1.second;         if (s.length() != s1.length()) {           if (s.find(s1) != std::string::npos)             continue;           else {             flag = 0;             break;           }         } else {           if (s != s1) {             flag = 0;             break;           }         }       }       if (flag == 0) break;     }     if (flag == 0)       cout <<  NO n ;     else {       cout <<  YES n ;       for (i = 0; i < n; i++) cout << v1[i].second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i, sum = 0, x, count = 0;     cin >> n;     long long int a[n];     for (i = 0; i < n; i++) {       cin >> a[i];       sum = sum + a[i];     }     sort(a, a + n);     if (sum % 2 == 0) {       cout << sum;       return 0;     } else {       for (i = 0; i < n; i++) {         x = sum - a[i];         if (x % 2 == 0) {           cout << x;           return 0;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   bool m(int i, int j) { return (i % 10) > (j % 10); }   int main() {     int x, y;     cin >> y >> x;     vector<int> vi;     int i = 0, j = 0;     int k = 0;     for (i = 0; i < y; i++) {       cin >> j;       k += (j % 10);       vi.push_back(j);     }     sort(vi.begin(), vi.begin() + y, m);     for (i = 0; i < y && x > 0; i++) {       k = (10 - (vi[i] % 10));       if (x >= k && (vi[i] + k) <= 100) {         x -= k;         vi[i] += k;       }     }     for (i = 0; i < y && x > 0; i++) {       while ((vi[i] < 100) && (x >= 10)) {         vi[i] += 10;         x -= 10;       }     }     k = 0;     for (i = 0; i < y; i++) k += vi[i] / 10;     cout << k <<    ;     return EXIT_SUCCESS;   }


#include <bits/stdc++.h>   using namespace std;   const int T = 1 << 19;   struct nod {     int best = 0, best2 = 0;     int pref0 = 0, pref1 = 0, suf0 = 0, suf1 = 0;     int pref01 = 0, pref10 = 0, suf01 = 0, suf10 = 0;     int cnt0 = 0, cnt1 = 0;   };   void umax(int &a, int b) { a = max(a, b); }   nod merge(nod a, nod b) {     nod c;     c.cnt0 = a.cnt0 + b.cnt0;     c.cnt1 = a.cnt1 + b.cnt1;     c.best = max({a.best, b.best, a.suf01 + b.pref1, a.suf0 + b.pref01});     c.best2 = max({a.best2, b.best2, a.suf10 + b.pref0, a.suf1 + b.pref10});     c.suf0 = (b.cnt1 == 0 ? b.suf0 + a.suf0 : b.suf0);     c.suf1 = (b.cnt0 == 0 ? b.suf1 + a.suf1 : b.suf1);     c.pref0 = (a.cnt1 == 0 ? a.pref0 + b.pref0 : a.pref0);     c.pref1 = (a.cnt0 == 0 ? a.pref1 + b.pref1 : a.pref1);     c.pref01 = (a.cnt1 == 0 ? a.cnt0 + b.pref01 : a.pref01);     if (a.pref01 == a.cnt0 + a.cnt1) umax(c.pref01, a.pref01 + b.pref1);     umax(c.pref01, max(c.pref0, c.pref1));     c.pref10 = (a.cnt0 == 0 ? a.cnt1 + b.pref10 : a.pref10);     if (a.pref10 == a.cnt0 + a.cnt1) umax(c.pref10, a.pref10 + b.pref0);     umax(c.pref10, max(c.pref0, c.pref1));     c.suf01 = (b.cnt0 == 0 ? b.cnt1 + a.suf01 : b.suf01);     if (b.suf01 == b.cnt0 + b.cnt1) umax(c.suf01, b.suf01 + a.suf0);     umax(c.suf01, max(c.suf0, c.suf1));     c.suf10 = (b.cnt1 == 0 ? b.cnt0 + a.suf10 : b.suf10);     if (b.suf10 == b.cnt0 + b.cnt1) umax(c.suf10, b.suf10 + a.suf1);     umax(c.suf10, max(c.suf0, c.suf1));     return c;   }   nod t[T + T];   bool tag[T + T];   int n, m;   char s[T];   void odwroc(int v) {     swap(t[v].best, t[v].best2);     swap(t[v].cnt0, t[v].cnt1);     swap(t[v].pref01, t[v].pref10);     swap(t[v].suf01, t[v].suf10);     swap(t[v].pref0, t[v].pref1);     swap(t[v].suf0, t[v].suf1);   }   void push(int v) {     if (!tag[v]) return;     for (auto u : {2 * v, 2 * v + 1}) {       tag[u] ^= 1;       odwroc(u);     }     tag[v] = 0;   }   void invert(int x, int y, int v = 1, int l = 0, int r = T - 1) {     if (x <= l && r <= y) {       tag[v] ^= 1;       odwroc(v);       return;     }     push(v);     int m = (l + r) / 2;     if (x <= m) invert(x, y, 2 * v, l, m);     if (m < y) invert(x, y, 2 * v + 1, m + 1, r);     t[v] = merge(t[2 * v], t[2 * v + 1]);   }   nod query(int x, int y, int v = 1, int l = 0, int r = T - 1) {     if (x <= l && r <= y) {       return t[v];     }     push(v);     nod res;     int m = (l + r) / 2;     if (x <= m) res = merge(res, query(x, y, 2 * v, l, m));     if (m < y) res = merge(res, query(x, y, 2 * v + 1, m + 1, r));     return res;   }   int main() {     scanf( %d%d , &n, &m);     scanf( %s , s + 1);     for (int i = 1; i <= n; ++i) {       int v = i + T;       t[v].best = 1;       if (s[i] ==  > )         t[v].pref0 = t[v].suf0 = t[v].pref01 = t[v].pref10 = t[v].suf01 =             t[v].suf10 = t[v].cnt0 = t[v].best2 = 1;       else         t[v].pref1 = t[v].suf1 = t[v].pref01 = t[v].pref10 = t[v].suf01 =             t[v].suf10 = t[v].cnt1 = t[v].best2 = 1;     }     for (int i = T - 1; 1 <= i; --i) t[i] = merge(t[2 * i], t[2 * i + 1]);     while (m--) {       int a, b;       scanf( %d%d , &a, &b);       invert(a, b);       printf( %d n , query(a, b).best);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned long long y = 0;     unsigned int x = 0;     int i;     string s;     cin >> s;     if (s.length() > 19)       printf( BigInteger n );     else if (s.length() > 10) {       y = 0;       for (i = 0; i < s.length(); i++) {         if (y > 0) y *= 10;         y += s[i] -  0 ;       }       if (y > 9223372036854775807)         printf( BigInteger n );       else         printf( long n );     } else if (s.length() > 5) {       y = 0;       for (i = 0; i < s.length(); i++) {         if (y > 0) y *= 10;         y += s[i] -  0 ;       }       if (y > 2147483647)         printf( long n );       else         printf( int n );     } else if (s.length() > 3) {       y = 0;       for (i = 0; i < s.length(); i++) {         if (y > 0) y *= 10;         y += s[i] -  0 ;       }       if (y > 32767)         printf( int n );       else         printf( short n );     } else if (s.length() > 0) {       y = 0;       for (i = 0; i < s.length(); i++) {         if (y > 0) y *= 10;         y += s[i] -  0 ;       }       if (y > 127)         printf( short n );       else         printf( byte n );     } else       printf( byte n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, a, sum = 0, p = 0, res = 0;     map<long long, long long> m;     cin >> n;     m[0] = 1;     for (long long i = 1; i <= n; i++) {       cin >> a;       sum += a;       p = max(p, m[sum]);       res += i - p;       m[sum] = i + 1;     }     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   int lo[N];   int n, r[N], lb[N], rb[N], i, j, k;   struct ST {     pair<int, int> f[20][N];     function<pair<int, int>(pair<int, int>, pair<int, int>)> uni;     void ini(int* a) {       for (int i = 1; i <= n * 3; ++i) f[0][i] = {a[i], i};       for (int i = 1; (1 << i) <= n * 3; ++i)         for (int j = 1; j + (1 << i) - 1 <= n * 3; ++j)           f[i][j] = uni(f[i - 1][j], f[i - 1][j + (1 << i - 1)]);     }     inline pair<int, int> ask(int x, int y) {       int l = lo[y - x + 1];       return uni(f[l][x], f[l][y - (1 << l) + 1]);     }   } ss[2];   int anc[2][20][N];   inline int calc(int x, int y) {     int x1, y1, step = 0, x2, y2;     x1 = ss[0].ask(x, y).second;     y1 = ss[1].ask(x, y).second;     for (int i = 19; i >= 0; --i) {       x2 = anc[0][i][x1];       y2 = anc[1][i][y1];       if (rb[y2] - lb[x2] + 1 >= n ||           (lb[x2] < x && ss[1].ask(lb[x2], x - 1).first > y) ||           (y < rb[y2] && ss[0].ask(y + 1, rb[y2]).first < x))         continue;       step += 1 << i;       x1 = x2;       y1 = y2;     }     x1 = lb[x1];     y1 = rb[y1];     ++step;     return y1 - x1 + 1 >= n ? step : calc(x1, y1) + step;   }   int main() {     for (i = 2; i < N; ++i) lo[i] = lo[i >> 1] + 1;     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (i = 1; i <= n; ++i) cin >> r[i], r[i + n] = r[i + n * 2] = r[i];     for (i = 1; i <= n * 3; ++i)       lb[i] = max(1, i - r[i]), rb[i] = min(n * 3, i + r[i]);     ss[0].uni = [&](pair<int, int> a, pair<int, int> b) { return min(a, b); };     ss[1].uni = [&](pair<int, int> a, pair<int, int> b) { return max(a, b); };     ss[0].ini(lb);     ss[1].ini(rb);     for (i = 1; i <= n * 3; ++i)       anc[0][0][i] = ss[0].ask(lb[i], rb[i]).second,       anc[1][0][i] = ss[1].ask(lb[i], rb[i]).second;     for (k = 0; k < 2; ++k)       for (i = 1; i < 20; ++i)         for (j = 1; j <= n * 3; ++j)           anc[k][i][j] = anc[k][i - 1][anc[k][i - 1][j]];     for (i = n + 1; i <= n * 2; ++i) cout << (n == 1 ? 0 : calc(i, i)) <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Fast() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   int gcd(int a, int b) {     if (b == 0) return a;     gcd(b, a % b);   }   int lcm(int a, int b) { return a * b / gcd(a, b); }   int main() {     Fast();     string s;     cin >> s;     int cnt = 0;     while (s.size() >= 2) {       int n = 0;       for (int i = 0; i < s.length(); i++) n += s[i] -  0 ;       s = to_string(n);       cnt++;     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int inf = 0x7fffffff;   const int maxn = 505;   const long long mod = 1e9 + 7;   long long dp[maxn][maxn];   int n;   int main() {     ios::sync_with_stdio(false);     cin >> n;     dp[1][1] = dp[1][0] = 1;     for (int i = 2; i <= n; i++) {       for (int j = 0; j <= n; j++) {         for (int k = 0; k + j <= n; k++) {           long long x = (dp[i - 1][j] * dp[i - 1][k]) % mod;           dp[i][k + j] += x * (2 * (k + j) + 1);           dp[i][k + j] %= mod;           dp[i][k + j + 1] = (dp[i][k + j + 1] + x) % mod;           dp[i][k + j - 1] += x * (k + j) * (k + j - 1);           dp[i][k + j - 1] %= mod;         }       }     }     cout << dp[n][1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> primes;   int prime_marker[1000000];   void PrecomputePrimes() {     const int MAX_PRIME = 1000000;     for (int i = 2; i * i < MAX_PRIME; ++i) {       for (int j = i; i * j < MAX_PRIME; ++j) {         prime_marker[i * j] = 1;       }     }     for (int i = 2; i < MAX_PRIME; ++i) {       if (prime_marker[i]) continue;       primes.push_back(i);     }   }   vector<int64_t> prime_factors;   vector<int> factor_max_power;   void ComputePrimeFactors(int64_t val) {     for (int i = 0; i < primes.size(); ++i) {       if (val % primes[i] == 0) {         prime_factors.push_back(primes[i]);         factor_max_power.push_back(0);         while (val % primes[i] == 0) {           val /= primes[i];           factor_max_power.back()++;         }       }     }     if (val > 1000000) {       prime_factors.push_back(val);       factor_max_power.push_back(1);     }   }   vector<int64_t> arr;   vector<int> cofactor_power;   void ComputeCofactorPower(int64_t val) {     cofactor_power.resize(prime_factors.size());     for (int i = 0; i < prime_factors.size(); ++i) {       cofactor_power[i] = 0;       if (val % prime_factors[i] == 0) {         while (val % prime_factors[i] == 0) {           val /= prime_factors[i];           cofactor_power[i]++;         }       }     }   }   vector<int> basis;   void InitializeBasis() {     basis.resize(prime_factors.size());     basis[0] = 1;     for (int i = 1; i < prime_factors.size(); ++i) {       basis[i] = basis[i - 1] * (factor_max_power[i - 1] + 1);     }   }   void MapToIndices(int hash, vector<int>* indices) {     for (int i = basis.size() - 1; i >= 0; --i) {       (*indices)[i] = hash / basis[i];       hash -= (*indices)[i] * basis[i];     }   }   int IndicesToHash(const vector<int>& indices) {     int hash = 0;     for (int i = 0; i < indices.size(); ++i) {       hash += indices[i] * basis[i];     }     return hash;   }   vector<vector<int>> hash_indices;   void InitHashIndices(int max_hash) {     hash_indices.resize(max_hash, vector<int>(basis.size()));     for (int i = 0; i < max_hash; ++i) {       MapToIndices(i, &hash_indices[i]);     }   }   struct DpState {     int length = 100000;     int64_t cost = 0;     int parent;     bool is_chosen = false;     DpState(int length, int64_t cost, int parent, bool is_chosen)         : length(length), cost(cost), parent(parent), is_chosen(is_chosen) {}     DpState() {}     bool operator<(const DpState& other) const {       if (length == other.length) return cost < other.cost;       return length < other.length;     }   };   DpState dp[1003][7000];   void UpdateDP(int cur, int hash, const vector<int>& indices) {     if (cur == 0) {       if (hash == 0) {         dp[cur][hash] = DpState{0, 0, -1, false};         return;       }       bool is_divisible = true;       for (int i = 0; i < indices.size(); ++i) {         if (indices[i] > cofactor_power[i]) {           is_divisible = false;           break;         }       }       if (is_divisible) {         dp[cur][hash] = DpState{1, arr[cur], -1, true};       }       return;     }     vector<int> prev_indices(indices.size());     for (int i = 0; i < indices.size(); ++i) {       prev_indices[i] = max(0, indices[i] - cofactor_power[i]);     }     int prev_hash = IndicesToHash(prev_indices);     DpState state1 = {dp[cur - 1][prev_hash].length + 1,                       dp[cur - 1][prev_hash].cost + arr[cur], prev_hash, true};     DpState state2 = {dp[cur - 1][hash].length, dp[cur - 1][hash].cost, hash,                       false};     if (state1 < state2) {       dp[cur][hash] = state1;     } else {       dp[cur][hash] = state2;     }   }   int main() {     int n;     int64_t k;     PrecomputePrimes();     scanf( %d , &n);     cin >> k;     int64_t val;     for (int i = 0; i < n; ++i) {       cin >> val;       arr.push_back(val);     }     if (k == 1) {       int lowest_index = 0;       for (int i = 1; i < n; ++i) {         if (arr[i] < arr[lowest_index]) lowest_index = i;       }       printf( 1 n%d n , lowest_index + 1);       return 0;     }     ComputePrimeFactors(k);     InitializeBasis();     int max_hash = basis.back() * (factor_max_power.back() + 1);     InitHashIndices(max_hash);     for (int i = 0; i < n; ++i) {       ComputeCofactorPower(arr[i]);       for (int hash = 0; hash < max_hash; ++hash) {         UpdateDP(i, hash, hash_indices[hash]);       }     }     int cur_hash = max_hash - 1;     if (dp[n - 1][cur_hash].length >= 100000) {       printf( -1 n );       return 0;     }     printf( %d n , dp[n - 1][cur_hash].length);     for (int i = n - 1; i >= 0; --i) {       if (dp[i][cur_hash].is_chosen) {         printf( %d  , i + 1);       }       cur_hash = dp[i][cur_hash].parent;     }     printf(  n );     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   vector<long long> per, obs;   long long n, k, p;   bool check(long long t) {     long long i = 0;     for (long long j = 0; j <= obs.size() - 1; j++) {       if (abs(per[i] - obs[j]) + abs(p - obs[j]) <= t) {         i++;         if (i == n) return 1;       }     }     return 0;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     t = 1;     for (long long test = 1; test <= t; test++) {       cin >> n >> k >> p;       per.resize(n);       obs.resize(k);       for (long long i = 0; i <= n - 1; i++) cin >> per[i];       for (long long i = 0; i <= k - 1; i++) cin >> obs[i];       sort(per.begin(), per.end());       sort(obs.begin(), obs.end());       long long ans = 1e10, st = 0, end = 1e10;       while (st <= end) {         long long mid = (st + end) >> 1;         if (check(mid)) {           ans = min(ans, mid);           end = mid - 1;         } else           st = mid + 1;       }       cout << ans;     }     return 0;   }


#include <cstdio>   #include <cstring>   #include <iostream>   #include <vector>   #include <cmath>   #include <cstdlib>   #include <ctime>   #include <algorithm>   #include <string>   #include <map>   #define ll long long   #define ls id << 1   #define rs id << 1 | 1   #define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))   #define memarray(array, value) memset(array, value, sizeof(array))   #define fillarray(array, value, begin, end) fill((array) + (begin), (array) + (end) + 1, value)   #define fillvector(v, value) fill((v).begin(), (v).end(), value)   #define pb(x) push_back(x)   #define st(x) (1LL << (x))   #define pii pair<int, int>   #define mp(a, b) make_pair((a), (b))   #define Flush fflush(stdout)   #define vecfirst (*vec.begin())   #define veclast (*vec.rbegin())   #define vecall(v) (v).begin(), (v).end()   #define vecupsort(v) (sort((v).begin(), (v).end()))   #define vecdownsort(v, type) (sort(vecall(v), greater<type>()))   #define veccmpsort(v, cmp) (sort(vecall(v), cmp))   using namespace std;   const int N = 500050;   const int inf = 0x3f3f3f3f;   const ll llinf = 0x3f3f3f3f3f3f3f3f;   const int mod = 998244353;   const int MOD = 1e9 + 7;   const double PI = acos(-1.0);   clock_t TIME__START, TIME__END;   void program_end()   {   #ifdef ONLINE       printf(  n nTime used: %.6lf(s) n , ((double)TIME__END - TIME__START) / 1000);       system( pause );   #endif   }   int n;   int ask1(int x, int y)   {       printf( 1 %d %d n , x, y), Flush;       int ret;       scanf( %d , &ret);       return ret;   }   int ask2(int x, const vector<int> &vec)   {       printf( 2 %d %d , x, (int)vec.size());       for (auto i : vec)           printf(  %d , i);       putchar(  n ), Flush;       int ret;       scanf( %d , &ret);       return ret;   }   int ans[105][105];   vector<int> e;      vector<int> mergesort(int l, int r)   {       vector<int> ret;       if (l == r)       {           ret.push_back(l);           return ret;       }       int mid = (l + r) >> 1;       auto vl = mergesort(l, mid);       auto vr = mergesort(mid + 1, r);       int i = 0, j = 0;       while (i < (int)vl.size() && j < (int)vr.size())       {           int r = ask1(vl[i], vr[j]);           if (r == 1)           {               ret.push_back(vl[i]);               i++;           }           else           {               ret.push_back(vr[j]);               j++;           }       }       while (i < (int)vl.size())           ret.push_back(vl[i]), i++;       while (j < (int)vr.size())           ret.push_back(vr[j]), j++;       return ret;   }      void work1()   {       e.clear();       e = mergesort(0, n - 1);       for (int i = 0; i < (int)e.size(); ++i)           for (int j = i; j < (int)e.size(); ++j)               ans[e[i]][e[j]] = 1;   }      inline void solve()   {       memarray(ans, 0);       scanf( %d , &n);       work1();       int u = n - 1, p = n - 2;   #ifdef VINGYING       printf( Hamiton:  );       for (auto i : e)           cout << i <<    ;       putchar(  n );   #endif       while (u >= 0 && p >= 0)       {           vector<int> v;           for (int i = 0; i <= p; ++i)               v.push_back(e[i]);           int r = ask2(e[u], v);           if (r == 1)               p--;           if (p < 0)           {               ans[e[u]][e[0]]=1;               break;           }           if (r == 0)           {               ans[e[u]][e[p+1]]=1;               u--;               if (p==u)p--;               if (p < 0)            {                ans[e[u]][e[0]]=1;                break;            }           }       }       for(int k=0;k<n;k++)        for(int i=0;i<n;i++)         for(int j=0;j<n;j++)          ans[i][j]=(ans[i][j]||(ans[i][k]&&ans[k][j]));       printf( 3 n );       for (int i = 0; i < n; ++i, putchar(  n ))           for (int j = 0; j < n; ++j)               printf( %d , ans[i][j]);       Flush;       int resp;       scanf( %d ,&resp);       if(resp==-1)exit(0);   }      int main()   {       TIME__START = clock();       int Test = 1;       scanf( %d , &Test);       while (Test--)       {           solve();           // if (Test)           //     putchar(  n );       }       TIME__END = clock();       program_end();       return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   template <class T>   inline void checkmin(T &a, T b) {     if (a > b) a = b;   }   template <class T>   inline void checkmax(T &a, T b) {     if (a < b) a = b;   }   const int oo = 1 << 30;   const double eps = 1e-7;   const int N = 512;   const int M = 1;   const long long P = 10000000097ll;   int sgn(double x) { return (x > eps) - (x < -eps); }   int fcmp(double a, double b) { return sgn(a - b); }   double sqr(double x) { return x * x; }   struct Point {     double x, y;     Point() {}     Point(double a, double b) : x(a), y(b) {}     Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); }     Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); }     Point operator*(double d) const { return Point(x * d, y * d); }     double operator*(const Point &p) const { return x * p.y - y * p.x; }     Point operator/(double d) const { return Point(x / d, y / d); }     double norm() const { return sqrt(x * x + y * y); }     Point rot(double alpha) const {       return Point(x * cos(alpha) - y * sin(alpha),                    x * sin(alpha) + y * cos(alpha));     }     void cin() { scanf( %lf %lf , &x, &y); }     void cout(char *s =  p =  ) const { printf( %s %f %f , s, x, y); }   };   struct Line {     Point a, b;     Line() {}     Line(const Point &p, const Point &q) : a(p), b(q) {}     bool para(const Line &lin) const {       Point u, v;       u = b - a;       v = lin.b - lin.a;       return sgn(u * v) == 0;     }     bool l_to_s(const Line &seg) const {       return sgn((b - a) * (seg.a - a)) * sgn((b - a) * (seg.b - a)) < 0;     }     bool s_to_s(const Line &seg) const {       return l_to_s(seg) && seg.l_to_s(*this);     }     Point l_on_l(const Line &lin) const {       double s1, s2;       s1 = (lin.a - a) * (lin.b - a);       s2 = (lin.b - b) * (lin.a - b);       return (a * s2 + b * s1) / (s1 + s2);     }     int l_to_p(const Point &p) const { return sgn((b - a) * (p - a)); }   };   Point ar[N][5];   Point br[N][5];   Point tmple[2][N];   Point *x, *y;   double h, f;   int n;   double ans;   double area(Point *p, int pn) {     int i, j, k;     double ans = 0;     for (i = 1; i < pn; i++) ans += (p[i] - p[0]) * (p[i + 1] - p[0]);     if (pn < -11) {       for (i = 0; i < (pn); i++) printf( %.3f %.3f-->  , p[i].x, p[i].y);       puts(  );     }     return ans;   }   void read() {     int i, j, k;     double a, b;     double fix, low;     ans = 0;     scanf( %d , &n);     scanf( %lf %lf , &h, &f);     fix = f / (f - h);     low = (f + h) / (f - h);     for (i = 0; i < (n); i++) {       scanf( %lf %lf , &a, &b);       ar[i][0] = Point(a * fix, 0);       ar[i][1] = Point(b * fix, 0);       ar[i][2] = Point(b, h);       ar[i][3] = Point(a, h);       ar[i][4] = ar[i][0];       br[i][0] = Point(a * fix, 0);       br[i][1] = Point(b * fix, 0);       br[i][2] = Point(b * low, h);       br[i][3] = Point(a * low, h);       br[i][4] = br[i][0];       ans += area(ar[i], 4) + area(br[i], 4);     }   }   void cut(Point *p) {     int xn, yn;     int i, j, k;     int ii, jj;     Line lin, seg;     for (i = 0; i < (n); i++) {       for (j = 0; j < (5); j++) x[j] = p[j];       xn = 4;       for (j = 0; j < (4); j++) {         lin = Line(ar[i][j], ar[i][j + 1]);         yn = 0;         for (ii = 1; ii <= xn; ii++) {           seg = Line(x[ii - 1], x[ii]);           if (lin.l_to_s(seg)) y[yn++] = lin.l_on_l(seg);           if (lin.l_to_p(x[ii]) >= 0) y[yn++] = x[ii];         }         y[yn] = y[0];         swap(x, y);         swap(xn, yn);       }       ans -= area(x, xn);     }   }   void sub() {     int i, j, k;     x = tmple[0];     y = tmple[1];     for (i = 0; i < (n); i++) cut(br[i]);   }   int main() {     int T, _ = 0;     read();     sub();     printf( %.6f n , ans);     return 0;   }


#include <bits/stdc++.h>   int n, c;   void p(int a) {     if (a <= n) {       c++;       p(a * 10);       p(a * 10 + 1);     }   }   int main() {     std::cin >> n;     p(1);     std::cout << c;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200100;   const int M = 2 * N;   const long long MOD1 = 98764321261LL;   const long long MOD = 998244353LL;   inline int lowbit(int x) { return x & (-x); }   struct fenwick {     long long a[N];     int n;     void init(int n) {       for (int i = 0; i <= n; ++i) a[i] = 0;       this->n = n;     }     void add(int x, long long v) {       for (int i = x; i <= n; i += lowbit(i)) a[i] += v;     }     long long query(int x) {       long long ret = 0;       for (int i = x; i; i ^= lowbit(i)) ret += a[i];       return ret;     }     void rangeadd(int l, int r, long long v) {       add(l, v);       add(r + 1, -v);     }     long long rangequery(int l, int r) {       l = max(l, 1);       r = min(r, n);       if (r < l) return 0;       long long ret = query(r);       ret -= query(l - 1);       return ret;     }   };   inline long long powmod(long long x, long long y, long long MOD) {     long long ret = 1;     while (y) {       if (y & 1LL) ret = ret * x % MOD;       x = x * x % MOD;       y = y >> 1;     }     return ret;   }   struct graph {     int head[N], next[M], to[M];     int tot;     inline void init(int n) {       for (int i = 0; i <= n; ++i) head[i] = -1;       tot = 0;     }     inline void addedge(int x, int y) {       to[tot] = y;       next[tot] = head[x];       head[x] = tot;       ++tot;     }   };   struct point {     long long x, y;     point() {}     point(long long x, long long y) : x(x), y(y) {}     void read() { scanf( %lld%lld , &x, &y); }     point operator+(const point &rhs) const {       return point(x + rhs.x, y + rhs.y);     }     point operator-(const point &rhs) const {       return point(x - rhs.x, y - rhs.y);     }     long long operator^(const point &rhs) const { return x * rhs.y - y * rhs.x; }     bool operator<(const point &rhs) const {       if (y != rhs.y) return y < rhs.y;       return x < rhs.x;     }   };   long long phi(long long x) {     long long res = x;     for (long long i = 2; i * i <= x; ++i) {       if (x % i == 0) {         res = res / i * (i - 1);         while (x % i == 0) x /= i;       }     }     if (x > 1) res = res / x * (x - 1);     return res;   }   int n, m;   int ans;   int a[N], b[N], deg[N];   graph G;   void dfs(int x, int p) {     a[x] = 1;     b[x] = 0;     int chcnt = 0;     int maxa = -1;     int maxb = -1;     for (int i = G.head[x]; i != -1; i = G.next[i]) {       int y = G.to[i];       if (y == p) continue;       dfs(y, x);       int temp;       if (maxa != -1) {         temp = a[maxa] + a[y] + deg[x] - 2;         ans = max(ans, temp);         temp = a[maxa] + b[y] + deg[x] - 2;         ans = max(ans, temp);       }       if (maxb != -1) {         temp = b[maxb] + b[y] + deg[x] - 2;         ans = max(ans, temp);         temp = b[maxb] + b[y] + 1;         ans = max(ans, temp);         temp = b[maxb] + a[y] + deg[x] - 2;         ans = max(ans, temp);       }       a[x] = max(a[x], b[y] + 1);       b[x] = max(b[x], a[y] + deg[x] - 1 - (p != 0));       b[x] = max(b[x], b[y] + deg[x] - 1 - (p != 0));       if (maxa == -1 || a[y] > a[maxa]) maxa = y;       if (maxb == -1 || b[y] > b[maxb]) maxb = y;     }     ans = max(ans, a[x]);     ans = max(ans, b[x] + (p != 0));   }   int main() {     int cases = 1;     for (int iii = 1; iii <= cases; ++iii) {       scanf( %d , &n);       G.init(n);       for (int i = 1; i < n; ++i) {         int x, y;         scanf( %d%d , &x, &y);         G.addedge(x, y);         G.addedge(y, x);         ++deg[x];         ++deg[y];       }       ans = 0;       dfs(1, 0);       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   void prt(long x) { cerr << x; }   void prt(long long x) { cerr << x; }   void prt(unsigned x) { cerr << x; }   void prt(unsigned long x) { cerr << x; }   void prt(unsigned long long x) { cerr << x; }   void prt(float x) { cerr << x; }   void prt(double x) { cerr << x; }   void prt(long double x) { cerr << x; }   void prt(char x) { cerr <<      << x <<     ; }   void prt(const char *x) { cerr <<     << x <<    ; }   void prt(const string &x) { cerr <<     << x <<    ; }   void prt(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void prt(const pair<T, V> &x) {     cerr <<  { ;     prt(x.first);     cerr <<  , ;     prt(x.second);     cerr <<  } ;   }   template <typename T>   void prt(const T &x) {     long long f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), prt(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     prt(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   void err(istream_iterator<string> it) {}   template <typename T, typename... brgs>   void err(istream_iterator<string> it, T a, brgs... args) {     cerr << *it <<   =   << a << endl;     err(++it, args...);   }   long long kadane(long long *a, long long n) {     long long max_so_far = INT_MIN, max_ending_here = 0;     for (__typeof(n) i = (0); i != (n); i += 1 - 2 * ((0) > (n))) {       max_ending_here += a[i];       max_so_far = max(max_so_far, max_ending_here);       if (max_ending_here < 0) max_ending_here = 0;     }     return max_so_far;   }   void solve() {     long long n;     cin >> n;     double ans = 1.0 / tan(3.1415926535897932384626 / (2 * n));     cout << fixed;     cout << setprecision(10) << ans << endl;     return;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > ed[200005];   int n, m, k;   unsigned long long Hash[200005];   unsigned long long H = 1e9 + 7;   unsigned long long a[10][10];   unsigned long long sum;   long long ans = 0;   void dfs(int kk1, unsigned long long s) {     if (kk1 == k) {       if (s == sum) {         ans += 1;       }       return;     }     for (int i = 0; i < kk1 + 1; i++) {       dfs(kk1 + 1, s + a[kk1 + 1][i]);     }   }   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     cin >> n >> m >> k;     for (int i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       ed[u].push_back(make_pair(w, v));     }     for (int i = 1; i <= n; i++) {       sort(ed[i].begin(), ed[i].end());     }     Hash[1] = 1;     sum = 1;     for (int i = 2; i <= n; i++) {       Hash[i] = Hash[i - 1] * H;       sum += Hash[i];     }     for (int i = 1; i <= n; i++) {       int tp = ed[i].size();       for (int j = 0; j < tp; j++) {         int tpp = ed[i][j].second;         a[tp][j] += Hash[tpp];       }     }     dfs(1, a[1][0]);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int compare(const void *a, const void *b) {     int A = *((int *)a);     int B = *((int *)b);     return B - A;   }   int main() {     long long a[200000], b, c = 0, d, f = 0, i, j, k, n, m, p = 0, q = 0, r,                             t = 0, l, mid = 0, sum = 0, x, y, s = 0;     string ch[3000][2];     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     i = 0;     j = n - 1;     while (i <= j) {       c++;       if (c % 2 != 0) {         if (a[i] > a[j]) {           s = s + a[i];           i++;         } else {           s = s + a[j];           j--;         }       } else {         if (a[i] > a[j]) {           f = f + a[i];           i++;         } else {           f = f + a[j];           j--;         }       }     }     cout << s <<     << f;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n + 2];     vector<int> s;     s.push_back(n);     for (int i = 2; i < n + 1; i++) cin >> arr[i];     arr[1] = 0;     int k = n;     while (k > 0) {       s.push_back(arr[k]);       k = arr[k];     }     for (int i = s.size() - 2; i > -1; i--) {       cout << s[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)1e6;   vector<int> g[MAXN + 1];   pair<int, int> arr[MAXN + 1];   int k;   void dfs(int nod, int par, int lvl) {     arr[nod] = {2 * MAXN, 0};     for (auto it : g[nod]) {       if (it != par) {         dfs(it, nod, lvl + 1);         if (lvl >= arr[it].first) {           arr[nod].first = min(arr[nod].first, arr[it].first);           arr[nod].second += arr[it].second;         }       }     }     if (g[nod].size() == 0) {       arr[nod] = {lvl - k, 1};     }   }   int dp[MAXN + 1];   void dfs1(int nod, int par, int lvl) {     dp[nod] = (g[nod].size() == 0);     for (auto it : g[nod]) {       if (it != par) {         dfs1(it, nod, lvl + 1);         int cur = arr[nod].second;         if (lvl >= arr[it].first) {           cur -= arr[it].second;         }         dp[nod] = max(dp[nod], cur + dp[it]);       }     }   }   int main() {     int i, n, x, y;     ios::sync_with_stdio(false);     cin >> n >> k;     for (i = 2; i <= n; i++) {       cin >> x;       g[x].push_back(i);     }     dfs(1, 0, 1);     dfs1(1, 0, 1);     cout << dp[1];     return 0;   }


#include <bits/stdc++.h>   char s[101];   char t[10] =  ><+-.,[] ;   int c[10] = {8, 9, 10, 11, 12, 13, 14, 15};   void func() {     int n = strlen(s), i, j, ans = 0;     const int mod = 1000003;     for (i = 0; i < n; i++) {       for (j = 0; j < 8; j++) {         if (t[j] == s[i]) {           ans = (ans * 16 + c[j]) % mod;           break;         }       }     }     printf( %d n , ans);   }   int main(int argc, char **argv) {     while (scanf( %s , s) == 1) {       func();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int i = 1; i <= t; i++) {       int x1, x2, y1, y2;       string arr[8];       for (int i = 0; i < 8; i++) cin >> arr[i];       bool check = 0;       for (int i = 0; i < 8; i++) {         for (int j = 0; j < 8; j++) {           if (arr[i][j] ==  K  && check == 0) {             check = 1;             x1 = j;             y1 = i;           } else if (arr[i][j] ==  K ) {             x2 = j;             y2 = i;           }         }       }       if ((x1 == x2 && abs(y1 - y2) == 4) || (y1 == y2 && abs(x1 - x2) == 4))         cout <<  YES ;       else if (abs(x1 - x2) == 4 && abs(y1 - y2) == 4)         cout <<  YES ;       else         cout <<  NO ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     int n, m, k;     cin >> n >> m >> k;     vector<int> p(n);     for (int i = 0; i < n; ++i) cin >> p[i];     vector<int> s(n);     for (int i = 0; i < n; ++i) cin >> s[i];     vector<int> c(k);     for (int i = 0; i < k; ++i) cin >> c[i];     vector<vector<int>> schools(m + 1, vector<int>());     for (int i = 0; i < n; ++i) {       schools[s[i]].push_back(p[i]);     }     int ans = 0;     for (int i = 0; i < k; ++i) {       int cur = c[i];       int school = s[cur - 1];       int power = p[cur - 1];       vector<int> ss = schools[school];       sort(ss.rbegin(), ss.rend());       if (ss[0] != power) ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1010;   const double oo = 1E7, eps = 1E-7;   struct point {     double x, y;   } P[maxn];   int n;   double ansl, ansr;   point operator+(point a, point b) { return (point){a.x + b.x, a.y + b.y}; }   point operator-(point a, point b) { return (point){a.x - b.x, a.y - b.y}; }   double operator*(point a, point b) { return a.x * b.x + a.y * b.y; }   double operator/(point a, point b) { return a.x * b.y - b.x * a.y; }   double get(point A, point B) {     double a, b, c, res;     a = A.y - B.y;     b = B.x - A.x;     c = A / B;     if (a)       res = (-c - b * P[1].y) / a;     else       res = oo;     return res;   }   int main() {     int i, j;     double x, sita;     scanf( %d , &n);     scanf( %lf%lf , &P[n].x, &P[n].y);     for (i = 1; i < n; ++i) scanf( %lf%lf , &P[i].x, &P[i].y);     ansl = min(P[1].x, P[n].x), ansr = max(P[1].x, P[n].x);     for (i = 2; i < n; ++i) {       j = i + 1;       x = get(P[i], P[j]);       sita = (P[1].y - P[i].y) * (P[j].x - P[i].x);       if (sita > (P[j].y - P[i].y) * (ansl - P[i].x)) ansl = max(ansl, x);       if (sita > (P[j].y - P[i].y) * (ansr - P[i].x)) ansr = min(ansr, x);     }     if (ansr >= ansl)       printf( %.0lf , floor(ansr) - floor(ansl - eps));     else       printf( 0 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int a[100001] = {0};   long long int d[100001] = {0};   long long int vis[100001] = {0};   long long int cons[100001] = {0};   vector<long long int> vec[100001];   void dfs(long long int x, long long int p) {     vis[x] = 1;     if (a[x] == 1) {       if (a[p] == 1) {         cons[x] = cons[p] + 1;       } else {         cons[x] = 1;       }       d[x] = max(d[p], cons[x]);     } else {       cons[x] = 0;       d[x] = d[p];     }     for (long long int i = 0; i < vec[x].size(); i++) {       if (vis[vec[x][i]] == 1)         continue;       else {         dfs(vec[x][i], x);       }     }   }   signed main() {     long long int n, m;     cin >> n >> m;     for (long long int i = 0; i < n; i++) cin >> a[i + 1];     for (long long int i = 0; i < n - 1; i++) {       long long int x, y;       cin >> x >> y;       vec[x].push_back(y);       vec[y].push_back(x);     }     dfs(1, 0);     long long int count = 0;     for (long long int i = 2; i <= n; i++) {       if (vec[i].size() == 1 && d[i] <= m) count++;     }     cout << count;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int res = 0;     int neg;     while (true) {       char ch = getchar();       if (ch >=  0  && ch <=  9  || ch ==  - ) {         if (ch ==  - )           neg = -1;         else           neg = 1, res = ch -  0 ;         break;       }     }     while (true) {       char ch = getchar();       if (ch >=  0  && ch <=  9 )         res *= 10, res += ch -  0 ;       else         break;     }     return res * neg;   }   const int maxn = 100020;   const int MOd = 1e7;   int a, L, R, st[maxn], at;   bool flag, used[maxn];   vector<pair<int, pair<int, int> > > w[maxn];   vector<pair<int, int> > w2[maxn];   int dfs(int n, int back, int sz) {     int ret = 1;     st[++at] = n;     for (int i = 0; i < w[n].size(); i++)       if (w[n][i].first != back && !used[w[n][i].first]) {         int t = dfs(w[n][i].first, n, sz);         w[n][i].second.second = t;         ret += t;       }     for (int i = 0; i < w[n].size(); i++)       if (w[n][i].first == back) w[n][i].second.second = sz - ret;     return ret;   }   vector<int> Cw[maxn];   int ans1, ans2, sz[maxn];   void center(int n, int back, int szz) {     at = 0;     dfs(n, 0, szz);     int C = n;     for (int i = 1; i <= at; i++) {       int t = st[i];       int c = 0;       for (int j = 0; j < w[t].size(); j++)         if (w[t][j].second.second > szz / 2) {           c = 1;           break;         }       if (!c) C = t;     }     Cw[back].push_back(C);     sz[C] = szz;     used[C] = 1;     for (int i = 0; i < w[C].size(); i++)       if (!used[w[C][i].first]) center(w[C][i].first, C, w[C][i].second.second);   }   int N, T;   pair<int, int> segment[maxn * 3];   pair<int, pair<int, int> > st2[maxn];   void dfss(int &n, int &back, int der, int s) {     st2[++at].first = n;     st2[at].second.first = der;     st2[at].second.second = s + s - der;     pair<int, int> t;     t.first = -1e9;     t.second = 0;     int l = L - der, r = R - der;     if (l < N && 0 <= l) {       if (r > N - 1) r = N - 1;       for (l += N, r += N; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1) {         if (l & 1) t = max(t, (segment[l]));         if (~r & 1) t = max(t, (segment[r]));       }     }     if (t.first + s + s - der >= 0) {       ans1 = n;       ans2 = t.second;       flag = 1;       return;     }     for (int i = 0; i < w2[n].size() && !flag; i++)       if (w2[n][i].first != back && !used[w2[n][i].first])         dfss(w2[n][i].first, n, der + 1, s + w2[n][i].second);   }   void calc(int &C) {     N = 1;     while (N < sz[C]) N <<= 1;     for (int i = 1; i < N + N; i++) segment[i] = pair<int, int>(-1e9, 0);     for (int k = N; k; k >>= 1) segment[k] = pair<int, int>(0, C);     for (int i = 0; i < w2[C].size(); i++)       if (!used[w2[C][i].first]) {         at = 0;         dfss(w2[C][i].first, C, 1, w2[C][i].second);         if (flag) return;         for (int i = 1; i <= at; i++) {           pair<int, pair<int, int> > &t = st2[i];           int k = t.second.first + N;           if (segment[k].first < t.second.second) {             segment[k] = pair<int, int>(t.second.second, t.first);             for (k >>= 1; k; k >>= 1)               segment[k] = max(segment[k + k], segment[k + k + 1]);           }         }       }     used[C] = 1;     for (int i = 0; i < Cw[C].size(); i++) {       calc(Cw[C][i]);       if (flag) return;     }   }   bool f(int n) {     for (int i = 1; i <= a; i++)       for (int j = 0; j < w[i].size(); j++)         w2[i][j].second = (w[i][j].second.first >= n);     flag = 0;     memset(used, 0, sizeof(used));     calc(Cw[0][0]);     return flag;   }   int main() {     scanf( %d %d %d , &a, &L, &R);     for (int i = 1, j, k, t; i < a; i++) {       scanf( %d %d %d , &j, &k, &t);       w[j].push_back(pair<int, pair<int, int> >(k, pair<int, int>(t, 0)));       w[k].push_back(pair<int, pair<int, int> >(j, pair<int, int>(t, 0)));       w2[j].push_back(pair<int, int>(k, 0));       w2[k].push_back(pair<int, int>(j, 0));     }     center(1, 0, a);     int t = -1;     for (int k = 29; k >= 0; k--)       if (f(t + (1 << k))) t += 1 << k;     printf( %d %d n , ans1, ans2);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   long long read() {     long long x = 0, f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     return x * f;   }   void write(long long x) {     if (x < 0) x = -x, putchar( - );     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   void writeln(long long x) {     write(x);     puts(  );   }   const int N = 500000;   int E[N], X[N], R[N], D[N];   int u[N], v[N];   bool b[N];   int i, m, n, t, w, x, y, S_E;   inline void A_E(int x, int y) {     S_E++, E[S_E] = y, X[S_E] = R[x], R[x] = S_E, D[x]++;     return;   }   inline int O_E(int x) { return ((x - 1) ^ 1) + 1; }   inline void dfs(int x) {     for (int i = R[x]; R[x] = X[i], i != 0; i = R[x])       if (!b[i]) {         b[i] = true, b[O_E(i)] = true;         dfs(E[i]);         w++, u[w] = x, v[w] = E[i];       }     return;   }   int main() {     n = read(), m = read();     for (i = 1; i <= m; i++) {       x = read(), y = read();       A_E(x, y), A_E(y, x);     }     for (i = 1; i <= n; i++)       if (D[i] & 1)         if (t)           m++, A_E(i, t), A_E(t, i), t = 0;         else           t = i;     if (m & 1) m++, A_E(1, 1), A_E(1, 1);     writeln(m);     dfs(1);     for (i = w; i > 0; i--)       if (!(i & 1))         printf( %d %d n , u[i], v[i]);       else         printf( %d %d n , v[i], u[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int a[100005];     cin >> n;     int fa = 1;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] != i) {         fa = 0;       }     }     if (fa == 1) {       cout <<  0 ;     } else {       int ji = n - 1;       while (a[ji] < a[ji + 1]) {         ji--;       }       cout << ji;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9, MOD = 1e9 + 7, N = 1e5 + 1, M = 20;   void setIO(string name =   ) {     ios::sync_with_stdio(false);     cin.tie(0);     if (name.size()) {       freopen((name +  .in ).c_str(),  r , stdin);       freopen((name +  .out ).c_str(),  w , stdout);     }   }   int n, m, a[N], s, pxor[1000001], ans[N];   void pre() {     pxor[0] = 0;     for (int i = 1; i < 1000001; i++) pxor[i] = pxor[i - 1] ^ i;   }   string bit(int j) {     string ans;     for (int i = 0; i < M; i++) {       ans += (j & 1) +  0 ;       j >>= 1;     }     reverse(ans.begin(), ans.end());     return ans;   }   struct node1 {     int mx = -INF;     node1 *nxt[2]{};   };   struct node2 {     int mn = INF;     node2 *nxt[2]{};   };   node1 *rt1 = new node1();   node2 *rt2 = new node2();   void insert1(node1 *o, int i) {     string s = bit(pxor[i]);     for (char c : s) {       if (!o->nxt[c -  0 ]) o->nxt[c -  0 ] = new node1();       o = o->nxt[c -  0 ];       o->mx = max(o->mx, i);     }   }   void insert2(node2 *o, int i) {     string s = bit(pxor[i]);     for (char c : s) {       if (!o->nxt[c -  0 ]) o->nxt[c -  0 ] = new node2();       o = o->nxt[c -  0 ];       o->mn = min(o->mn, i);     }   }   void insert(int i) {     insert1(rt1, i);     insert2(rt2, i - 1);   }   int get1(node1 *o, int i) {     string s = bit(pxor[i]);     int ans = 0, shift = M - 1;     for (char c : s) {       int tmp = 1 ^ (c -  0 );       if (o->nxt[tmp] && o->nxt[tmp]->mx > i) {         o = o->nxt[tmp];         ans += (1 << shift);       } else if (o->nxt[1 ^ tmp] && o->nxt[1 ^ tmp]->mx > i) {         o = o->nxt[tmp ^ 1];       } else         return 0;       shift--;     }     return ans;   }   int get2(node2 *o, int i) {     string s = bit(pxor[i]);     int ans = 0, shift = M - 1;     for (char c : s) {       int tmp = 1 ^ (c -  0 );       if (o->nxt[tmp] && o->nxt[tmp]->mn < i) {         o = o->nxt[tmp];         ans += (1 << shift);       } else if (o->nxt[1 ^ tmp] && o->nxt[1 ^ tmp]->mn < i) {         o = o->nxt[tmp ^ 1];       } else         return 0;       shift--;     }     return ans;   }   int get(int i) { return max(get1(rt1, i - 1), get2(rt2, i)); }   void clearall(node1 *o) {     o->mx = -INF;     if (o->nxt[0] && o->nxt[0]->mx != -INF) clearall(o->nxt[0]);     if (o->nxt[1] && o->nxt[1]->mx != -INF) clearall(o->nxt[1]);   }   void clearall(node2 *o) {     o->mn = INF;     if (o->nxt[0] && o->nxt[0]->mn != INF) clearall(o->nxt[0]);     if (o->nxt[1] && o->nxt[1]->mn != INF) clearall(o->nxt[1]);   }   void init() {     clearall(rt1);     clearall(rt2);   }   struct query {     int l, r, id, bl;     query(int ll, int rr, int i) : l(ll), r(rr), id(i), bl(l / s) {}     bool operator<(const query &other) const {       return make_pair(bl, r) < make_pair(other.bl, other.r);     }   };   query make_query(int ll, int rr, int i) { return query(ll, rr, i); }   vector<query> qry;   signed main() {     setIO();     pre();     cin >> n >> m;     s = ceil(sqrt(n));     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) {       int l, r;       cin >> l >> r;       qry.push_back(make_query(l - 1, r - 1, i));     }     sort(qry.begin(), qry.end());     for (int i = 0, j = 0; i < m; i = j) {       while (j < m && qry[j].bl == qry[i].bl) j++;       int lmx = 0, mid = j, right, nowmx = 0;       for (int k = i; k < j; k++) right = lmx = max(lmx, qry[k].l);       for (int k = i; k < j; k++)         if (qry[k].r > lmx) {           mid = k;           break;         }       init();       for (int k = mid; k < j; k++) {         ans[qry[k].id] = nowmx;         while (right <= qry[k].r) {           insert(a[right]);           nowmx = ans[qry[k].id] = max(ans[qry[k].id], get(a[right]));           right++;         }         for (int l = lmx; l >= qry[k].l; l--) {           ans[qry[k].id] = max(ans[qry[k].id], get(a[l]));         }       }       for (int k = i; k < j; k++) {         init();         for (int l = min(qry[k].r, lmx); l >= qry[k].l; l--) {           insert(a[l]);           ans[qry[k].id] = max(ans[qry[k].id], get(a[l]));         }       }     }     for (int i = 0; i < m; i++) cout << ans[i] <<   n ;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:65777216 )   using namespace std;   char s[1111][1111];   int n, m;   int best;   int now;   int v[1111][1111];   vector<pair<int, int> > c;   bool u[1111][1111];   void dfs(int x, int y) {     if (u[x][y]) return;     u[x][y] = true;     for (int dx(-1); dx < (2); dx++)       for (int dy(-1); dy < (2); dy++) {         int nx = dx + x;         int ny = dy + y;         if (nx >= 0 && nx < n && ny >= 0 && ny < m)           if (s[nx][ny] ==  0 )             dfs(nx, ny);           else             c.push_back(pair<int, int>(nx, ny));         else           c.push_back(pair<int, int>(-1, -1));       }   }   int startx, starty;   int dfs2(int x, int y, int prevx = -1, int prevy = -1) {     if (x == startx && y == starty && prevx != -1) return 0;     int res = 1;     for (int dx(-1); dx < (2); dx++)       for (int dy(-1); dy < (2); dy++)         if (abs(dx) + abs(dy) == 1) {           int nx = x + dx;           int ny = y + dy;           if (nx >= 0 && nx < n && ny >= 0 && ny < m && v[nx][ny] == v[x][y])             if (nx != prevx || ny != prevy) {               res += dfs2(nx, ny, x, y);               if (prevx == -1) return res;             }         }     return res;   }   int main() {     cin >> n >> m;     for (int i(0); i < (n); i++) scanf(  %s , s[i]);     for (int i(1); i < (n); i++)       for (int j(1); j < (m); j++)         if (s[i][j] ==  1  && s[i][j - 1] ==  1  && s[i - 1][j - 1] ==  1  &&             s[i - 1][j] ==  1 )           best = 4;     for (int i(0); i < (n); i++)       for (int j(0); j < (m); j++)         if (s[i][j] ==  0  && !u[i][j]) {           c.clear();           dfs(i, j);           now++;           bool good = 1;           int num = 0;           for (int k(0); k < (c.size()); k++)             if (c[k].first == -1) {               good = 0;               break;             } else if (v[c[k].first][c[k].second] != now)               v[c[k].first][c[k].second] = now, num++;           for (int k(0); k < (c.size()); k++) {             int num = 0;             for (int dx(-1); dx < (2); dx++)               for (int dy(-1); dy < (2); dy++)                 if (abs(dx) + abs(dy) == 1) {                   int nx = c[k].first + dx;                   int ny = c[k].second + dy;                   if (nx >= 0 && nx < n && ny >= 0 && ny < m && s[nx][ny] ==  1 )                     if (v[nx][ny] == now) num++;                 }             if (num != 2) {               good = 0;               break;             }           }           if (good && num > 4) {             startx = c[0].first;             starty = c[0].second;             if (dfs2(c[0].first, c[0].second) == num) best = max(best, num);           }         }     cout << best << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string l, r;     cin >> l >> r;     vector<stack<int>> l_array;     vector<stack<int>> r_array;     for (int i = 0; i < 27; i++) {       stack<int> buf;       l_array.push_back(buf);       r_array.push_back(buf);     }     for (int i = 0; i < n; i++) {       if (l[i] ==  ? ) {         l_array[26].push(i);       } else {         l_array[l[i] -  a ].push(i);       }       if (r[i] ==  ? ) {         r_array[26].push(i);       } else {         r_array[r[i] -  a ].push(i);       }     }     vector<pair<int, int>> answer;     for (int i = 0; i < 26; i++) {       while (!l_array[i].empty() && !r_array[i].empty()) {         answer.push_back(make_pair(l_array[i].top(), r_array[i].top()));         l_array[i].pop();         r_array[i].pop();       }       while (!l_array[i].empty() && !r_array[26].empty()) {         answer.push_back(make_pair(l_array[i].top(), r_array[26].top()));         l_array[i].pop();         r_array[26].pop();       }       while (!r_array[i].empty() && !l_array[26].empty()) {         answer.push_back(make_pair(l_array[26].top(), r_array[i].top()));         l_array[26].pop();         r_array[i].pop();       }     }     while (!l_array[26].empty() && !r_array[26].empty()) {       answer.push_back(make_pair(l_array[26].top(), r_array[26].top()));       l_array[26].pop();       r_array[26].pop();     }     int count = answer.size();     cout << count << endl;     for (int i = 0; i < count; i++) {       cout << answer[i].first + 1 <<     << answer[i].second + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, z, x, c, sum, a[101][101], us[101][101];   char cc, stl;   set<long long> s;   void dfs(long long i, long long j) {     if (a[i][j] == 0 || us[i][j] == 1 || i > n || j > m || i < 1 || j < 1) return;     us[i][j] = 1;     if (s.count(a[i][j]) == 0) sum++, s.insert(a[i][j]);     if (a[i][j] == stl -  A  + 1) {       dfs(i + 1, j);       dfs(i - 1, j);       dfs(i, j + 1);       dfs(i, j - 1);     }   }   int main() {     cin >> n >> m >> stl;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> cc;         if (cc !=  . ) a[i][j] = cc -  A  + 1;         if (cc == stl) z = i, x = j;       }     }     s.insert((int)stl -  A  + 1);     dfs(z, x);     cout << sum <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int okX[] = {0, 0, 0, 1, 1, 2, 2, 2};   const int okY[] = {0, 1, 2, 0, 2, 0, 1, 2};   const int n = 8;   void normalize(int a[n]) {     vector<int> v(a, a + n);     sort(v.begin(), v.end());     map<int, int> m;     for (int i = 0; i < v.size(); ++i)       if (!m.count(v[i])) m.insert(make_pair(v[i], m.size()));     for (int i = 0; i < 8; ++i) a[i] = m[a[i]];   }   int main() {     int x[n], y[n];     for (int i = 0; i < n; ++i) cin >> x[i] >> y[i];     normalize(x);     normalize(y);     bool used[n];     memset(used, false, sizeof(used));     for (int i = 0; i < 8; ++i) {       bool ok = false;       for (int j = 0; j < 8; ++j)         if (x[i] == okX[j] && y[i] == okY[j] && !used[j])           ok = true, used[j] = true;       if (!ok) {         printf( ugly n );         return 0;       }     }     printf( respectable n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool is_prime[100000];   void gen_is_primes(int n);   void gen_prime_groups(int n, vector<bool>& to_match,                         list<int>& candidate_primes,                         list<pair<int, int> >& groups);   void gen_prime_groups(int n, int p, vector<bool>& to_match,                         list<pair<int, int> >& groups);   void gen_unmatched_multiples(int n, int i, vector<bool>& to_match,                                list<int>& unmatched_multiples);   void gen_even_groups(vector<bool>& to_match, list<pair<int, int> >& groups);   void gen_is_primes(int n) {     fill_n(is_prime, n, true);     is_prime[0] = false;     is_prime[1] = false;     for (int i = 2; i <= n / 2; i++) {       if (is_prime[i]) {         for (int j = 2 * i; j <= n; j += i) {           is_prime[j] = false;         }       }     }   }   void gen_prime_groups(int n, vector<bool>& to_match,                         list<int>& candidate_primes,                         list<pair<int, int> >& groups) {     for (list<int>::iterator i = candidate_primes.begin();          i != candidate_primes.end(); i++) {       gen_prime_groups(n, *i, to_match, groups);     }   }   void gen_prime_groups(int n, int p, vector<bool>& to_match,                         list<pair<int, int> >& groups) {     list<int>* unmatched_multiples = new list<int>();     gen_unmatched_multiples(n, p, to_match, *unmatched_multiples);     for (list<int>::iterator it = unmatched_multiples->begin();          it != unmatched_multiples->end(); it++) {       int curr = *it;       int curr_partner = *(++it);       to_match[curr] = false;       to_match[curr_partner] = false;       groups.push_back(make_pair(curr, curr_partner));     }     delete unmatched_multiples;   }   void gen_unmatched_multiples(int n, int i, vector<bool>& to_match,                                list<int>& unmatched_multiples) {     for (int curr_multiple = i; curr_multiple <= n; curr_multiple += i) {       if (to_match[curr_multiple]) {         unmatched_multiples.push_back(curr_multiple);       }     }     if (unmatched_multiples.size() % 2 != 0) {       unmatched_multiples.remove(2 * i);     }   }   void gen_even_groups(vector<bool>& to_match, list<pair<int, int> >& groups) {     list<int> unmatched;     for (vector<bool>::iterator i = to_match.begin(); i != to_match.end(); i++) {       if (*i) {         int i_index = i - to_match.begin();         unmatched.push_back(i_index);       }     }     if (unmatched.size() % 2 != 0) {       unmatched.erase(unmatched.begin());     }     for (list<int>::iterator i = unmatched.begin(); i != unmatched.end(); i++) {       int curr = *i;       int curr_partner = *(++i);       groups.push_back(make_pair(curr, curr_partner));     }   }   int main() {     int n;     cin >> n;     gen_is_primes(n);     vector<bool> to_match(n, false);     for (int i = 2; i <= n; i++) {       to_match[i] = !is_prime[i] || (i <= n / 2);     }     list<int>* candidate_primes = new list<int>;     for (int i = n / 2; i >= 3; i--) {       if (is_prime[i]) {         candidate_primes->push_back(i);       }     }     list<pair<int, int> >* groups = new list<pair<int, int> >;     gen_prime_groups(n, to_match, *candidate_primes, *groups);     gen_even_groups(to_match, *groups);     cout << groups->size() << endl;     for (list<pair<int, int> >::iterator it = groups->begin();          it != groups->end(); it++) {       cout << it->first <<     << it->second << endl;     }     delete groups;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma )   #pragma GCC optimize( unroll-loops )   using namespace std;   long long MOD9 = 998244353;   long long MOD = 1000000007;   double eps = 1e-12;   void solve() {     int n;     cin >> n;     vector<pair<int, int> > v(n);     for (int i = 0; i < n; i++) cin >> v[i].first >> v[i].second;     sort((v).begin(), (v).end());     int p = 0, c = 0;     for (int i = 1; i < n; i++) {       if (v[i].second < v[p].second)         c++;       else         p = i;     }     cout << c <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     { solve(); }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, d1, d2;   bool d[400001];   int a[200001];   int nextprime(int x) {     for (int i = x + 1; i <= 2 * n; ++i)       if (d[i]) return i;     return 2 * n + 1000000;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     int x;     for (int i = 1; i <= n; ++i) {       cin >> x;       d1 += x == 1;       d2 += x == 2;     }     memset(d, sizeof(d), 0);     for (int i = 2; i <= 2 * n; ++i) {       bool f = 1;       for (int j = 2; j * j <= i; ++j)         if (i % j == 0) {           f = 0;           break;         }       d[i] = f;     }     int prime = 0;     int t = n;     while (n > 0) {       int tmp = nextprime(prime);       while (tmp - prime >= 2 && d2 > 0 && n > 0) prime += 2, d2--, a[n] = 2, n--;       while (tmp - prime >= 1 && d1 > 0 && n > 0) prime += 1, d1--, a[n] = 1, n--;       while (tmp - prime >= 1 && d1 == 0 && d2 > 0)         prime += 2, d2--, a[n] = 2, n--;     }     for (int i = t; i > 0; --i) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   long long pwr(long long base, long long p, long long mod = (1000000007LL)) {     long long ans = 1;     while (p) {       if (p & 1) ans = (ans * base) % mod;       base = (base * base) % mod;       p /= 2;     }     return ans;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   const double eps = 1e-7;   struct PT {     double x, y;     PT() {}     PT(double x, double y) : x(x), y(y) {}     bool operator<(const PT &rhs) const {       return make_pair(y, x) < make_pair(rhs.y, rhs.x);     }     bool operator==(const PT &rhs) const {       return make_pair(y, x) == make_pair(rhs.y, rhs.x);     }   };   double cross(PT p, PT q) { return p.x * q.y - p.y * q.x; }   double area2(PT a, PT b, PT c) {     return cross(a, b) + cross(b, c) + cross(c, a);   }   void ConvexHull(vector<PT> &pts) {     sort(pts.begin(), pts.end());     pts.erase(unique(pts.begin(), pts.end()), pts.end());     vector<PT> up, dn;     for (int i = 0; i < pts.size(); i++) {       while (up.size() > 1 && area2(up[up.size() - 2], up.back(), pts[i]) > eps)         up.pop_back();       while (dn.size() > 1 && area2(dn[dn.size() - 2], dn.back(), pts[i]) < -eps)         dn.pop_back();       up.push_back(pts[i]);       dn.push_back(pts[i]);     }     pts = dn;     for (int i = (int)up.size() - 2; i >= 1; i--) pts.push_back(up[i]);   }   vector<PT> arr;   set<PT> banned;   int main() {     int n1, n2;     scanf( %d%d , &n1, &n2);     int X, Y;     scanf( %d%d , &X, &Y);     while (n1--) {       int x, y;       scanf( %d%d , &x, &y);       banned.insert(PT(x, y));       arr.push_back(PT(x, y));     }     int max_x = -1, max_y = -1;     while (n2--) {       int x, y;       scanf( %d%d , &x, &y);       arr.push_back(PT(x, y));       max_x = max(max_x, x);       max_y = max(max_y, y);     }     arr.push_back(PT(0, max_y));     arr.push_back(PT(max_x, 0));     arr.push_back(PT(0, 0));     ConvexHull(arr);     for (auto it : arr)       if (banned.find(it) != banned.end()) {         printf( Max );         return 0;       }     printf( Min );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     short n;     int n1, n2;     bool state = false;     char handle[11];     cin >> n;     for (short i = 0; i < n; i++) {       cin >> handle;       cin >> n1;       cin >> n2;       if (n1 >= 2400 && n2 > n1) state = true;     }     if (state)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000 * 1000 * 1000 + 7;   const double EPS = 1e-9;   int bit_count(int first) {     return first == 0 ? 0 : 1 + bit_count(first & (first - 1));   }   inline int low_bit(int first) { return first & -first; }   inline int sign(double first) {     return first < -EPS ? -1 : first > EPS ? 1 : 0;   }   inline int sign(int first) { return (first > 0) - (first < 0); }   int nextComb(int first) {     if (!first) {       fprintf(stderr,  nextComb(0) called n );       return ((1 << 30) - 1 + (1 << 30));     }     int smallest = first & -first;     int ripple = first + smallest;     int ones = first ^ ripple;     ones = (ones >> 2) / smallest;     return ripple | ones;   }   template <class T>   inline T gcd(T a, T b) {     a = abs(a);     b = abs(b);     while (b) {       int r = a % b;       a = b;       b = r;     }     return a;   }   template <class T>   inline T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   inline int getInt() {     int a;     return scanf( %d , &a) ? a : (fprintf(stderr,  trying to read n ), -1);   }   inline double getDouble() {     double a;     return scanf( %lf , &a) ? a : (fprintf(stderr,  trying to read n ), -1.0);   }   inline double myRand() {     return ((double)rand() / RAND_MAX) + ((double)rand() / RAND_MAX / RAND_MAX);   }   const int N = 109;   int s, c;   int Left[N], Right[N];   vector<pair<int, pair<int, int> > > getOptions(int n) {     vector<pair<int, pair<int, int> > > ret;     for (int i = (int)0; i < (int)s; ++i) {       if (Left[i] == -1) {         int L = c - n / 2, R = c + (n - 1) / 2, cost = 0;         for (int j = L; j <= R; ++j) cost += abs(c - i) + abs(c - j);         ret.push_back(make_pair(cost, pair<int, int>(i, L)));       } else {         int L = Left[i] - n, R = Left[i] - 1, cost = 0;         if (L >= 0) {           for (int j = L; j <= R; ++j) cost += abs(c - i) + abs(c - j);           ret.push_back(make_pair(cost, pair<int, int>(i, L)));         }         L = Right[i] + 1;         R = Right[i] + n;         cost = 0;         if (R < s) {           for (int j = L; j <= R; ++j) cost += abs(c - i) + abs(c - j);           ret.push_back(make_pair(cost, pair<int, int>(i, L)));         }       }     }     return ret;   }   void update(int first, int a, int b) {     if (Left[first] == -1) {       Left[first] = a;       Right[first] = b;     } else {       if (a < Left[first]) Left[first] = a;       if (b > Right[first]) Right[first] = b;     }   }   void myCode() {     int n = getInt();     s = getInt();     c = s / 2;     for (int i = (int)0; i < (int)s; ++i) Left[i] = Right[i] = -1;     for (int i = (int)0; i < (int)n; ++i) {       int first = getInt();       if (first > s) {         printf( -1 n );         continue;       }       vector<pair<int, pair<int, int> > > a = getOptions(first);       if (a.empty()) {         printf( -1 n );         continue;       }       sort((a).begin(), (a).end());       printf( %d %d %d n , a[0].second.first + 1, a[0].second.second + 1,              a[0].second.second + first);       update(a[0].second.first, a[0].second.second,              a[0].second.second + first - 1);     }   }   int main() {     srand(time(NULL));     myCode();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int graph[27];   int grapht[27];   vector<bool> used(27, false);   vector<bool> opened(27, false);   string result;   void dfs(int node) {     used[node] = true;     opened[node] = true;     if (graph[node] == -1) {       result += (node +  a );       opened[node] = false;       return;     }     if (opened[graph[node]]) {       cout <<  NO ;       exit(0);     }     dfs(graph[node]);     opened[node] = false;     result += (node +  a );   }   void dfsn(int node) {     opened[node] = true;     if (graph[node] != -1) {       if (opened[graph[node]]) {         cout <<  NO ;         exit(0);       }       dfsn(graph[node]);     }     opened[node] = false;   }   set<int> letter;   int main() {     int n;     cin >> n;     fill(graph, graph + 27, -1);     fill(grapht, grapht + 27, -1);     while (n--) {       string s;       cin >> s;       for (int i = 0; i < s.size() - 1; i++) {         int b = s[i] -  a ;         int e = s[i + 1] -  a ;         if ((graph[b] != -1 && graph[b] != e) ||             (grapht[e] != -1 && grapht[e] != b)) {           cout <<  NO ;           exit(0);         }         graph[b] = e;         grapht[e] = b;       }       for (auto i = s.begin(); i != s.end(); i++) {         letter.insert(*i -  a );       }     }     for (int i = 0; i < 27; i++) {       dfsn(i);     }     for (int i = 26; i >= 0; i--) {       if (letter.find(i) != letter.end() && grapht[i] == -1) {         dfs(i);       }     }     reverse(result.begin(), result.end());     cout << result;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<ll, ll>;   const ll MOD = 1e9 + 7, N = 1e5 + 10;   void test() {     ll n;     cin >> n;     vector<ll> a(n);     for (ll i = 0; i < n; i++) {       cin >> a[i];     }     vector<ll> ans;     sort(a.begin(), a.end());     ll l = 0, h = n - 1;     while (l < h) {       ans.push_back(a[l]);       ans.push_back(a[h]);       l++, h--;     }     if (l == h) ans.push_back(a[l]);     reverse(ans.begin(), ans.end());     for (ll i = 0; i < n; i++) {       cout << ans[i] <<    n [i == n - 1];     }     return;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     ll tt = 1;     cin >> tt;     for (ll i = 0; i < tt; i++) test();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int N = 1e4 + 10;   int main() {     string str;     cin >> str;     cout << str[0];     int flag = 0;     for (int i = 1; i < str.length(); i++) {       if (!(i + 2 >= str.length() || flag == 1)) {         if (str.substr(i, 2) ==  at ) {           cout <<  @ ;           i++;           flag = 1;           continue;         }       }       if (i + 3 < str.length()) {         if (str.substr(i, 3) ==  dot ) {           cout <<  . ;           i += 2;           continue;         }       }       cout << str[i];     }     return 0;   }


#include<bits/stdc++.h>   #define mod 998244353   using namespace std;   int n, A[2], f[200010], pw2;   int powmod(int x, int y){    int ans = 1;    for(;y;y >>= 1, x = 1ll * x * x % mod)     if(y & 1)ans = 1ll * x * ans % mod;    return ans;   }   int main(){    scanf( %d , &n);    A[0] = 1;    A[1] = 0;    pw2 = powmod(2, mod - 2);    for(int i = 1; i <= n; i++){     A[0] = 1ll * A[0] * pw2 % mod;     A[1] = 1ll * A[1] * pw2 % mod;     f[i] = A[!(i & 1)];     A[i & 1] += f[i];    }    printf( %d n , f[n]);   }