#include <bits/stdc++.h>   using namespace std;   map<string, string> a;   map<string, int> b;   string s, g, p;   int main() {     int n, q;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s;       int l = s.length();       for (int j = 0; j < l; j++) {         for (int k = 1; j + k <= l; k++) {           string c = s.substr(j, k);           if (a[c] != s) {             b[c]++;             a[c] = s;           }         }       }     }     cin >> q;     for (int h = 0; h < q; h++) {       cin >> p;       if (b[p] == 0) {         cout << b[p] <<                  <<  -  << endl;       } else {         cout << b[p] <<     << a[p] << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, s = 19, i, sum, j, l;   int main() {     cin >> n;     for (i = 1; i < n; i++) {       s += 9;       l = s;       while (l) {         sum += (l % 10);         l /= 10;       }       if (sum != 10) i--;       sum = 0;     }     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   using ll = long long;   using llu = long long unsigned;   using ld = long double;   const ld EPS = 1e-9;   inline int cmp(ld first, ld second = 0, ld tol = EPS) {     return (first <= second + tol) ? (first + tol < second) ? -1 : 0 : 1;   }   const int MOD = 1;   inline int mod(ll first, int m = MOD) { return (int)(((first % m) + m) % m); }   const int N = 2e5 + 10;   int n, m;   ll first[N], chg[N], one[N];   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) scanf( %lld , &first[i]);     ll base = 0;     for (int i = 1; i < m; i += 2) {       base += abs(first[i] - first[i - 1]);       if (i < m - 1) base += abs(first[i] - first[i + 1]);     }     for (int i = 0; i < m; i++) {       if (i < m - 1) {         if (first[i + 1] > first[i]) {           chg[first[i]]--;           one[first[i]] += first[i] - 1;         }         if (first[i + 1] < first[i]) {           chg[first[i]]++;           ll dBef = abs(first[i] - (first[i + 1] + 1));           ll dNow = abs(1 - (first[i + 1] + 1));           one[first[i]] += (dNow - dBef);         }       }       if (i) {         if (first[i - 1] > first[i]) {           chg[first[i]]--;           one[first[i]] += first[i] - 1;         }         if (first[i - 1] < first[i]) {           chg[first[i]]++;           ll dBef = abs(first[i] - (first[i - 1] + 1));           ll dNow = abs(1 - (first[i - 1] + 1));           one[first[i]] += (dNow - dBef);         }       }     }     for (int i = 1; i <= n; i++) {       printf( %lld  , base);       base -= one[i];       base += chg[i] + one[i + 1];     }     putchar(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXV = 600, MAXE = 70000, inf = 1000000000;   int N, Count;   int G[MAXV], Queue[MAXV], Dist[MAXV], Pre[MAXV], Last[MAXV];   int Data[MAXE], Weight[MAXE], Cost[MAXE], Next[MAXE];   bool Flag[MAXV];   int Calc(int X) {     if (!X) return 0;     return Calc(X / 2) + X % 2;   }   void Add(int Number, int V1, int V2, int W, int C) {     Data[Number] = V2;     Weight[Number] = W;     Cost[Number] = C;     Next[Number] = G[V1];     G[V1] = Number;   }   void Connect(int V1, int V2, int W, int C) {     Add(Count++, V1, V2, W, C);     Add(Count++, V2, V1, 0, -C);   }   int SPFA(int S, int T) {     for (int i = 0; i <= T; i++) Dist[i] = inf;     Dist[S] = 0;     memset(Flag, 0, sizeof(Flag));     Queue[0] = S;     int F = 0, R = 1;     while (F != R) {       int V = Queue[F++];       if (F == MAXV) F = 0;       int P = G[V];       Flag[V] = false;       while (P != -1) {         int U = Data[P];         if (Weight[P] && Dist[V] + Cost[P] < Dist[U]) {           Dist[U] = Dist[V] + Cost[P];           Pre[U] = P;           if (!Flag[U]) Flag[Queue[R++] = U] = true;           if (R == MAXV) R = 0;         }         P = Next[P];       }     }     if (Dist[T] == inf) return -1;     int V = T;     while (V != S) {       Weight[Pre[V]]--;       Weight[Pre[V] ^ 1]++;       int U = Data[Pre[V] ^ 1];       if (U <= N && V > N) Last[V - N - 1] = U;       V = U;     }     return Dist[T];   }   int main() {     int M;     cin >> N >> M;     int A[250];     for (int i = 0; i < N; i++) cin >> A[i];     int S = N * 2 + 1, T = N * 2 + 2;     Count = 0;     for (int i = 0; i <= T; i++) G[i] = -1;     for (int i = 0; i < N; i++) Connect(S, i, 1, 0);     Connect(S, N, M, 0);     for (int i = 0; i < N; i++)       for (int j = i + 1; j < N; j++)         if (A[i] == A[j])           Connect(i, N + j + 1, 1, 0);         else           Connect(i, N + j + 1, 1, Calc(A[j]));     for (int i = 0; i < N; i++) Connect(N, N + i + 1, 1, Calc(A[i]));     for (int i = 1; i <= N; i++) Connect(N + i, T, 1, 0);     int Ans = 0, Tmp;     while (Tmp = SPFA(S, T), Tmp != -1) Ans += Tmp;     int Total = N;     for (int i = 0; i < N; i++)       if (Last[i] == N || A[Last[i]] != A[i]) Total++;     cout << Total <<     << Ans << endl;     int Number = 0, Var[250];     for (int i = 0; i < N; i++)       if (Last[i] == N) {         Var[i] = Number++;         printf( %c=%d nprint(%c) n , Var[i] + 97, A[i], Var[i] + 97);       } else if (A[i] == A[Last[i]]) {         Var[i] = Var[Last[i]];         printf( print(%c) n , Var[i] + 97);       } else {         Var[i] = Var[Last[i]];         printf( %c=%d nprint(%c) n , Var[i] + 97, A[i], Var[i] + 97);       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n == 0) {       cout <<  O-|-OOOO  << endl;       return 0;     }     while (n != 0) {       int k = n % 10;       if (k >= 5) {         cout <<  -O| ;         k -= 5;       } else         cout <<  O-| ;       int i = 0;       for (; i < k; i++) cout <<  O ;       cout <<  - ;       i++;       for (; i < 5; i++) cout <<  O ;       cout << endl;       n /= 10;     }   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     int n;     cin >> n;     int x;     cin >> x;     int a[n];     int pp[100005] = {0};     for (int i = 0; i < n; i++) {       cin >> a[i];       pp[a[i]]++;     }     long long c = 0;     for (int i = 0; i < n; i++) {       if (((a[i] ^ x) < 100005) && pp[a[i] ^ x]) {         c += pp[a[i] ^ x];       }     }     if (x == 0)       cout << (c - n) / 2 <<   n ;     else       cout << c / 2 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     int a[t + 10];     for (int i = 0; i < t; i++) {       long int b, p, f, c, h, c1 = 0, c2 = 0;       cin >> b >> p >> f;       cin >> h >> c;       b = b / 2;       if (b == 0) {         cout << 0 << endl;         continue;       }       if (h > c) {         if (b >= p) {           c1 += (p * h);           b -= p;           if (f >= b) {             c1 += b * c;           } else {             c1 += f * c;           }         } else {           c1 += b * h;         }       } else {         if (b >= f) {           b -= f;           c1 += c * f;           if (b > p) {             c1 += p * h;           } else {             c1 += b * h;           }         } else {           c1 += b * c;         }       }       cout << c1 << endl;       c1 = 0;     }   }


#include <bits/stdc++.h>   using namespace std;   int b[600][600], n, m, q, row[600];   int main() {     ios::sync_with_stdio(false);     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         int x;         scanf( %d , &x);         b[i][j] = x;       }     int ans = 0;     for (int i = 1; i <= n; i++) {       int len = 0;       int maxlen = 0;       for (int j = 1; j <= m; j++) {         if (b[i][j])           len++;         else           len = 0;         maxlen = max(len, maxlen);       }       row[i] = maxlen;     }     while (q--) {       int i, j;       scanf( %d%d , &i, &j);       b[i][j] ^= 1;       int len = 0;       int maxlen = 0;       for (j = 1; j <= m; j++) {         if (b[i][j])           len++;         else           len = 0;         maxlen = max(len, maxlen);       }       row[i] = maxlen;       int ans = 0;       for (int ii = 1; ii <= n; ii++) {         ans = max(ans, row[ii]);       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100500;   int a[maxn];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     long long k;     cin >> n >> k;     long long sm = 0;     priority_queue<pair<int, int> > pq;     for (int i = 0; i < n; ++i) {       cin >> a[i];       sm += a[i];       pq.push({-a[i], i});     }     if (sm < k) return cout << -1 <<   n , 0;     if (sm == k) return 0;     long long it = 0, lft = n;     while (true) {       assert(!pq.empty());       auto u = pq.top();       u.first += it;       lft = (int)pq.size();       if (lft * -1LL * u.first > k) break;       pq.pop();       while (pq.top().first + it == u.first) pq.pop();       k -= lft * -1LL * u.first;       it += u.first * -1LL;     }     for (int i = 0; i < n; ++i) a[i] = 0;     it += k / lft;     k %= lft;     while (!pq.empty()) {       a[pq.top().second] = (pq.top().first + it) * -1LL;       pq.pop();     }     queue<int> q;     for (int i = 0; i < n; ++i)       if (a[i]) q.push(i);     while (k--) {       auto u = q.front();       q.pop();       a[u]--;       if (a[u]) q.push(u);     }     while (!q.empty()) {       cout << q.front() + 1 <<    ;       q.pop();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double tt, anstt;   long long ansp, answ, tod[2000000], x1, x2, t1, t2, t0, ps;   int main() {     cin >> t1 >> t2 >> x1 >> x2 >> t0;     if (t1 == t2 && t1 == t0)       cout << x1 <<     << x2 << endl;     else {       tod[0] = x2;       ps = 0;       for (int i = 1; i <= x1; i++) {         long fl = 0;         while ((i * t1 + ps * t2) < (i + ps) * t0) {           ++ps;           fl = 1;           if (ps > x2) break;         }         tod[i] = ps;       }       anstt = 10000000;       for (int i = 0; i <= x1; i++) {         if (tod[i] <= x2) {           tt = i * t1 + tod[i] * t2;           tt = tt * 1.0 / (i + tod[i]);           anstt = min(anstt, tt);         }       }       anstt += 1e-8;       answ = -1;       for (int i = 0; i <= x1; i++) {         if (tod[i] <= x2) {           tt = i * t1 + tod[i] * t2;           tt = tt * 1.0 / (i + tod[i]);           if (tt < anstt) {             if (answ < i + tod[i]) {               answ = i + tod[i];               ansp = i;             }           }         }       }       cout << ansp <<     << tod[ansp] << endl;     }     cin.get();     cin.get();     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); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = ((res % p) * (x % p)) % p;       y = y >> 1;       x = ((x % p) * (x % p)) % p;     }     return res % p;   }   long long raichu(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = ((res) * (x));       y = y >> 1;       x = ((x) * (x));     }     return res;   }   bool isprime(long long n) {     if (n < 2)       return false;     else if (n == 2)       return true;     else if (n % 2 == 0)       return false;     else {       long long z = sqrt(n);       for (int i = 0; i < z - 1; i++)         if (n % (i + 2) == 0) return false;       return true;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tests = 1, Tests;     Tests = tests;     while (tests--) {       int n, l, r, x;       cin >> n >> l >> r >> x;       vector<int> c(n);       for (int i = 0; i < n; i++) cin >> c[i];       vector<int> tmp;       sort(c.begin(), c.end());       int ans = 0;       for (int i = 0; i < (1 << n); i++) {         tmp.clear();         int sum = 0;         for (int j = 0; j < n; j++) {           if ((i >> j) & 1) {             tmp.push_back(c[j]);             sum += c[j];           }         }         if ((int)tmp.size() >= 2 && sum >= l && sum <= r &&             tmp[(int)tmp.size() - 1] - tmp[0] >= x) {           ans++;         }       }       cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int a, b;     node(int a = 0, int b = (int)1e9) : a(a), b(b) {}     int get(int x) { return a * x + b; }   };   struct Zwei {     vector<node> st;     vector<int> a;     int n;     void add(int pos) { a.push_back(pos); }     void update() {       sort(a.begin(), a.end());       a.resize(unique(a.begin(), a.end()) - a.begin());       n = (int)a.size();       st.resize(n << 2 | 1);     }     void modify(int id, int l, int r, node val) {       int mid = l + r >> 1;       if (st[id].get(a[mid]) > val.get(a[mid])) swap(st[id], val);       if (l == r) return;       if (st[id].get(a[l]) > val.get(a[l])) modify(id << 1, l, mid, val);       if (st[id].get(a[r]) > val.get(a[r])) modify(id << 1 | 1, mid + 1, r, val);     }     int get(int id, int l, int r, int v) {       int ans = st[id].get(v);       if (l == r) assert(a[l] == v);       if (l == r) return ans;       int mid = l + r >> 1;       if (v <= a[mid]) return min(ans, get(id << 1, l, mid, v));       return min(ans, get(id << 1 | 1, mid + 1, r, v));     }     int get(int v) {       if (!n) return (int)1e9;       return get(1, 0, n - 1, v);     }     void modify(node val) {       if (!n) return;       modify(1, 0, n - 1, val);     }   };   struct Eins {     vector<Zwei> st;     int n;     Eins(int n) : n(n) { st.resize(n << 2 | 1); }     void build(int id, int l, int r) {       st[id].update();       if (l == r) return;       int mid = l + r >> 1;       build(id << 1, l, mid);       build(id << 1 | 1, mid + 1, r);     }     void add(int id, int l, int r, int L, int R, int v) {       if (L <= l && r <= R) {         st[id].add(v);         return;       }       int mid = l + r >> 1;       if (L <= mid) add(id << 1, l, mid, L, R, v);       if (R > mid) add(id << 1 | 1, mid + 1, r, L, R, v);     }     void modify(int id, int l, int r, int pos, node val) {       st[id].modify(val);       if (l == r) return;       int mid = l + r >> 1;       if (pos <= mid)         modify(id << 1, l, mid, pos, val);       else         modify(id << 1 | 1, mid + 1, r, pos, val);     }     int get(int id, int l, int r, int L, int R, int v) {       if (L <= l && r <= R) return st[id].get(v);       int mid = l + r >> 1;       int ans = (int)1e9 + 1;       if (L <= mid) ans = min(ans, get(id << 1, l, mid, L, R, v));       if (R > mid) ans = min(ans, get(id << 1 | 1, mid + 1, r, L, R, v));       return ans;     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<int> a(n + 1);     vector<int> t(n + 1);     for (int i = 1; i <= n; i++) {       cin >> a[i];       t[i] = t[i - 1] + a[i];     }     int q;     cin >> q;     vector<pair<int, int>> Query;     Eins Tree(n);     while (q--) {       int x, y;       cin >> x >> y;       Query.emplace_back(x, y);       Tree.add(1, 1, n, y - x + 1, y, y - x);     }     Tree.build(1, 1, n);     for (int i = 1; i <= n; i++)       Tree.modify(1, 1, n, i, node(-a[i], a[i] * i - t[i]));     for (auto& x : Query) {       cout << Tree.get(1, 1, n, x.second - x.first + 1, x.second,                        x.second - x.first) +                   t[x.second]            <<   n ;     }   }


#include<bits/stdc++.h>   #define int long long   using namespace std;   const int N=1e5+5;   #define pb push_back   int n,m,t;   int i,j,k;   int a[N];   int b[N],c[N];   vector<int> ans;   vector<int>v[N];   int vis[N];       signed main()   {       int t;       cin>>t;       while(t--){        int n;     cin>>n;     int m=(n-1);     int f=sqrt(2*m+1);    // cout<<f<<endl;     if(f<3) cout<<0<<endl;     else cout<<(f-1)/2<<endl;    }       return 0;   }


#include <bits/stdc++.h>   const int MAXA = 5005;   const int MAXN = 2016;   int array[MAXN]{};   long long diffr[MAXA]{};   long long suffx[MAXA]{};   long double total;   long long Ans = 0;   int N;   int main() {     scanf( %d , &N);     for (int i = 0; i < N; ++i) scanf( %d , &array[i]);     total = N * (N - 1) >> 1;     std::sort(array, array + N);     for (int i = 0; i < N; ++i)       for (int j = i + 1; j < N; ++j) ++diffr[array[j] - array[i]];     for (int i = 5000; i >= 0; --i) suffx[i] = suffx[i + 1] + diffr[i];     for (int i = 1; i <= 5000; ++i)       for (int j = 1; i + j <= 5000; ++j)         Ans += diffr[i] * diffr[j] * suffx[i + j + 1];     std::cout << std::setprecision(9) << Ans / total / total / total <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     const long long MOD = 1000000009;     int n, m;     cin >> n >> m;     long long ret = 1;     long long x = 1;     for (int i = 0; i < (int)(m); i++) x = x * 2 % MOD;     x = (x - 1 + MOD) % MOD;     for (int i = 0; i < (int)(n); i++) {       ret = ret * x % MOD;       if (--x < 0) x = 0;     }     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<long long, long long>;   const long long INF = 2e18;   template <class A, class B>   ostream &operator<<(ostream &os, const pair<A, B> &p) {     os <<  (  << p.first <<  ,   << p.second <<  ) ;     return os;   }   template <class A>   ostream &operator<<(ostream &os, const vector<A> &v) {     os <<  { ;     for (long long i = 0; i < (long long)v.size(); i++)       if (i == 0)         os << v[i];       else         os <<  ,   << v[i];     os <<  } ;     return os;   }   void dprint(string s) { cout <<   n ; }   template <class T, class... U>   void dprint(string s, T t, U... u) {     long long w = s.find( , );     cout <<  [  << s.substr(0, w) <<  :   << t <<  ]  ;     dprint(s.substr(w + 2, (long long)s.size() - w - 1), u...);   }   const long long N = 1e6 + 5;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     vector<pair<char, long long>> v;     for (long long i = 0; i < (long long)(s).size();) {       char c = s[i];       long long cnt = 0;       while (s[i] == c and i < (long long)(s).size()) cnt++, i++;       v.push_back({c, cnt});     }     if ((long long)(v).size() % 2) {       bool ok = 1;       for (long long i = 0; i < (long long)(v).size() / 2; i++) {         if (v[i].first == v[(long long)(v).size() - 1 - i].first and             v[i].second + v[(long long)(v).size() - 1 - i].second >= 3)           ;         else           ok = 0;       }       if (v[(long long)(v).size() / 2].second == 1) ok = 0;       if (ok)         cout << v[(long long)(v).size() / 2].second + 1;       else         cout << 0;     } else {       cout << 0;     }     return 0;   }


#include <bits/stdc++.h>   std::mt19937 rng(       (int)std::chrono::steady_clock::now().time_since_epoch().count());   using namespace std;   long long mod = (998244353LL);   inline long long Mod(long long a, long long b) { return (a % b); }   inline long long poww(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return res;   }   long long gcd(long long a, long long b) {     while (b) {       a %= b, swap(a, b);     }     return a;   }   void read(vector<int> &w, int n) {     w.resize(n);     for (int i = 0; i < n; i++) cin >> w[i];   }   void print(vector<int> &w) {     for (int i = 0; i < (int)(w).size(); i++) {       if (i == (int)(w).size() - 1)         cout << w[i] <<   n ;       else         cout << w[i] <<    ;     }   }   int prodmod(vector<int> w);   int summod(vector<int> w);   int n, m, q, k, v[200010];   string second;   pair<int, int> w[200010];   vector<pair<int, int>> grafo[200010];   long long dist[200010][20][2];   void solve() {     priority_queue<vector<long long>, vector<vector<long long>>,                    greater<vector<long long>>>         pq;     pq.push({0, 1, 0, 0});     dist[1][0][0] = 0;     while (!pq.empty()) {       auto curr = pq.top();       pq.pop();       long long d = curr[0], x = curr[1], q = curr[2], flag = curr[3];       if (d > dist[x][q][flag]) continue;       for (auto v : grafo[x]) {         int T = (v.second != flag);         int qq = q + T, flag2 = v.second;         if (qq < 20 and             dist[v.first][qq][flag2] >                 dist[x][q][flag] + 1 + (1LL * T) * (1LL << (1LL * q))) {           dist[v.first][qq][flag2] =               dist[x][q][flag] + 1 + (1LL * T) * (1LL << (1LL * q));           pq.push({dist[v.first][qq][flag2], v.first, qq, flag2});         }       }     }   }   pair<int, int> dist2[200010][2];   const int inf = 0x3f3f3f3f;   int32_t main() {     memset(dist, inf, sizeof dist);     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 1, a, b; i <= m; i++) {       cin >> a >> b;       grafo[a].push_back({b, 0});       grafo[b].push_back({a, 1});     }     solve();     long long ans = inf;     for (int i = 0; i < 20; i++) ans = min({ans, dist[n][i][0], dist[n][i][1]});     if (ans != inf)       cout << ans % mod <<   n , exit(0);     else {       for (int i = 0; i < 200010; i++) dist2[i][0] = dist2[i][1] = {inf, inf};       priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> pq;       pq.push({0, 0, 1, 0});       dist2[1][0] = {0, 0};       while (!pq.empty()) {         auto curr = pq.top();         pq.pop();         int inv = curr[0], d = curr[1], x = curr[2], flag = curr[3];         if (pair<int, int>(inv, d) > dist2[x][flag]) continue;         for (auto v : grafo[x]) {           pair<int, int> novo = {inv + (v.second != flag), d + 1};           if (novo < dist2[v.first][v.second]) {             dist2[v.first][v.second] = novo;             pq.push({inv + (v.second != flag), d + 1, v.first, v.second});           }         }       }       pair<int, int> curr = min(dist2[n][0], dist2[n][1]);       int ans = curr.second, pot = 1LL;       for (int i = 0; i < curr.first; i++) {         ans += pot;         ans %= mod;         pot *= 2LL;         pot %= mod;       }       cout << ans % mod <<   n ;     }   }   int summod(vector<int> w) {     int curr = 0;     for (int i = 0; i < (int)(w).size(); i++) {       curr = (curr + w[i]) % mod;       if (curr < 0) curr += mod;     }     return curr;   }   int prodmod(vector<int> w) {     int curr = 1;     for (int i = 0; i < (int)(w).size(); i++) {       if (w[i] >= mod) w[i] %= mod;       curr = (curr * w[i]) % mod;       if (curr < 0) curr += mod;     }     return curr;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   vector<int> v[maxn];   int vos[maxn];   int ans;   void dfs(int now, int pre) {     if (vos[now]) {       ans = 0;       return;     }     vos[now] = 1;     for (int i = 0; i < v[now].size(); i++) {       if (v[now][i] != pre) {         dfs(v[now][i], now);       }     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     int a, b;     for (int i = 0; i < m; i++) {       scanf( %d%d , &a, &b);       v[a].push_back(b);       v[b].push_back(a);     }     memset(vos, 0, sizeof(vos));     int sum = 0;     for (int i = 1; i <= n; i++) {       if (vos[i]) continue;       ans = 1;       dfs(i, 0);       sum += ans;     }     printf( %d n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007LL;   int n, k;   string s;   long long A[30];   long long ans, aux;   int last[30];   int main() {     cin >> n >> k >> s;     memset(last, -1, sizeof(last));     int m = s.length();     ans = 1LL;     for (int i = 0; i < m; i++) {       aux = ans;       ans = (2 * ans + MOD - A[s[i] -  a ]) % MOD;       A[s[i] -  a ] = aux;       last[s[i] -  a ] = i;     }     for (int j = 0; j < n; j++) {       int mini = (1 << 30);       int let;       for (int i = 0; i < k; i++) {         if (last[i] < mini) {           mini = last[i];           let = i;         }       }       aux = ans;       ans = (2 * ans + MOD - A[let]) % MOD;       A[let] = aux;       last[let] = m + j;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   char x[1500001];   int k, i, starti, fini;   bool start, finish, found[500001];   int main() {     while (cin.getline(x, 1500001)) {       k++;       found[k] = false;       int a = strlen(x);       for (i = 0; i < a; i++) {         if (x[i] !=     && x[i] !=  #  && !found[k]) break;         if (x[i] ==  # ) {           found[k] = true;           break;         }       }       if (found[k]) {         if (!found[k - 1] && k != 1) cout <<   n ;         cout << x <<   n ;       } else {         int p = strlen(x);         for (i = 0; i < p; i++) {           if (x[i] ==    ) {             continue;           } else             cout << x[i];         }       }     }     if (!found[k]) cout <<   n ;   }


#include <bits/stdc++.h>   const int inf = 0xfffffff;   const long long INF = 1ll << 61;   using namespace std;   int num[1000000 + 5];   int b[1000000 + 5];   int c[1000000 + 5];   int n;   int ans;   void init() {     memset(num, 0, sizeof(num));     memset(b, 0, sizeof(b));     memset(c, 0, sizeof(c));     ans = 0;   }   bool input() {     while (scanf( %d , &n) == 1) {       return false;     }     return true;   }   void cal() {     n++;     for (int i = 2; i <= n; i++) {       scanf( %d , &num[i]);       b[i] = 1;       c[i] = 0;       int j = i;       if (ans < b[j]) ans = b[j];       while (num[j] != 1) {         if (ans < b[j]) ans = b[j];         if (ans < b[num[j]]) ans = b[num[j]];         if (b[num[j]] < b[j]) {           b[num[j]] = b[j];           c[num[j]] = 1;         } else if (c[num[j]] == 1 && b[num[j]] == b[j]) {           b[num[j]] = b[j] + 1;           c[num[j]] = 0;         } else if (c[num[j]] == 0 && b[num[j]] == b[j]) {           c[num[j]] = 1;           break;         } else           break;         if (ans < b[num[j]]) ans = b[num[j]];         j = num[j];       }       printf( %d%c , ans, i == 1 ?   n  :    );     }   }   void output() {}   int main() {     while (true) {       init();       if (input()) return 0;       cal();       output();     }   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const int N = 100000 + 5;   long long q;   long long tree[4000005], lazy[4000005];   long long ti[1000005], di[1000005];   void lazify(long long s, long long e, long long i) {     if (lazy[i]) {       tree[i] += lazy[i];       if (s != e) {         lazy[2 * i] += lazy[i];         lazy[2 * i + 1] += lazy[i];       }       lazy[i] = 0;     }   }   void upd(long long l, long long r, long long s, long long e, long long i,            long long x) {     lazify(s, e, i);     if (s > r || e < l) return;     if (s >= l && e <= r) {       lazy[i] += x;       lazify(s, e, i);       return;     }     long long mid = (s + e) >> 1;     upd(l, r, s, mid, 2 * i, x);     upd(l, r, mid + 1, e, 2 * i + 1, x);     tree[i] = min(tree[2 * i], tree[2 * i + 1]);   }   long long pquery(long long l, long long r, long long s, long long e,                    long long i) {     if (s > r || e < l) return 1e18;     lazify(s, e, i);     if (s >= l && e <= r) return tree[i];     long long mid = (s + e) >> 1;     return min(pquery(l, r, s, mid, 2 * i), pquery(l, r, mid + 1, e, 2 * i + 1));   }   void build(long long l, long long r, long long i) {     if (l == r) {       tree[i] = -l;       return;     }     long long mid = (l + r) >> 1;     build(l, mid, 2 * i);     build(mid + 1, r, 2 * i + 1);     tree[i] = min(tree[2 * i], tree[2 * i + 1]);   }   long long get(long long t) {     long long x = pquery(t, t, 1, 1000000, 1);     long long y = pquery(1, t - 1, 1, 1000000, 1);     y = min(y, 0ll);     return x - y + 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     build(1, 1000000, 1);     cin >> q;     for (int i = 1; i <= q; i++) {       char c;       long long in;       cin >> c;       if (c ==  + ) {         cin >> ti[i] >> di[i];         upd(ti[i], 1000000, 1, 1000000, 1, di[i]);       } else if (c ==  - ) {         cin >> in;         upd(ti[in], 1000000, 1, 1000000, 1, -di[in]);       } else if (c ==  ? ) {         cin >> in;         cout << get(in) << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1E6 + 5, INF = 1E9 + 7;   int m, n, ans = INF;   mt19937 mt(133769420);   int ask(int u, int v) {     cout <<  ?   << u <<     << v << endl;     int ret;     cin >> ret;     return ret;   }   int rand(int l, int r) {     uniform_int_distribution<int> uni(l, r);     return uni(mt);   }   void solve(int u, int d, int l, int r) {     if (u > d) {       return;     }     int m = rand(u, d);     pair<int, int> mi = {INF, 0};     for (int i = l; i <= r; i++) {       mi = min(mi, {ask(m, i), i});     }     ans = min(ans, mi.first);     solve(u, m - 1, l, mi.second);     solve(m + 1, d, mi.second, r);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> m >> n;     solve(1, m, 1, n);     cout <<  !   << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     long long t, n, x;     cin >> t;     for (int i = 0; i < t; i++) {       cin >> n >> x;       cout << x * 2 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + c -  0 ;       c = getchar();     }     return x * f;   }   int w, h, n, l, r;   char opt[3];   set<int> a, b;   multiset<int> f, g;   int main() {     w = read(), h = read(), n = read();     a.insert(0), b.insert(0);     a.insert(w), b.insert(h);     f.insert(w), g.insert(h);     for (int i = 1; i <= n; i++) {       scanf( %s , opt + 1);       int x = read();       if (opt[1] ==  V ) {         r = (*a.lower_bound(x));         l = (*(--a.lower_bound(x)));         f.erase(f.find(r - l));         f.insert(r - x), f.insert(x - l);         a.insert(x);       } else {         r = (*b.lower_bound(x));         l = (*(--b.lower_bound(x)));         g.erase(g.find(r - l));         g.insert(r - x), g.insert(x - l);         b.insert(x);       }       printf( %I64d n , 1LL * (*(--f.end())) * (*(--g.end())));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, tot, len[(int)(3e3 + 4)];   pair<int, int> bound[(int)(3e3 + 4)];   string s;   vector<int> poz, ans[3000004];   void fail();   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> k;     cin >> s;     for (int i = s.size() - 1; i >= 0; --i)       if (s[i] ==  R ) {         len[poz.size()] = (s.size() - poz.size()) - i - 1;         tot += len[poz.size()];         poz.push_back(i);       }     if (k > tot) fail();     int p = 0;     while (p < poz.size() && !len[p]) ++p;     bound[p] = {1, len[p]};     tot -= len[p];     for (int i = p + 1; i < poz.size(); ++i) {       int l, r, dist, ramas;       dist = dist = poz[i - 1] - poz[i] - 1;       l = max(1, bound[i - 1].first + 1 - dist);       tot -= len[i];       if (k - tot - len[i] + 1 >= l)         bound[i] = {k - tot - len[i] + 1, k - tot};       else if (l + len[i] - 1 <= k)         bound[i] = {l, l + len[i] - 1};       else         fail();     }     for (int i = 0; i < poz.size(); ++i) {       int p = poz[i];       while (bound[i].first <= bound[i].second) {         ans[bound[i].first].push_back(p + 1);         ++p;         ++bound[i].first;       }     }     for (int i = 1; i < k + 1; ++i) {       printf( %d  , ans[i].size());       for (auto it : ans[i]) printf( %d  , it);       printf(  n );     }     return 0;   }   void fail() {     cout << -1;     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   int SquareRoot(int n) {     int l = 1, r = n + 1;     while (l < r) {       int mid = (l + r) / 2;       if (n / mid < mid) {         r = mid;       } else {         l = mid + 1;       }     }     --l;     if (l * l == n) {       return l;     }     return -1;   }   int GCD(int a, int b) {     while (b > 0) {       int t = a % b;       a = b;       b = t;     }     return a;   }   int main() {     int a = 0, b = 0;     scanf( %d%d , &a, &b);     int a2 = a * a;     int b2 = b * b;     bool found = false;     for (int i = a - 1; i > 0; --i) {       int j = SquareRoot(a2 - i * i);       if (j < 0) {         continue;       }       int gcd = GCD(i, j);       int i_norm = i / gcd;       int j_norm = j / gcd;       int squ = i_norm * i_norm + j_norm * j_norm;       if (b2 % squ != 0) {         continue;       }       int mul = SquareRoot(b2 / squ);       if (mul < 0) {         continue;       }       found = true;       int i2 = i_norm * mul;       int j2 = j_norm * mul;       if (i2 == j) {         continue;       }       printf( YES n );       printf( 0 0 n );       printf( %d %d n , i, j);       printf( %d %d n , -j2, i2);       break;     }     if (!found) {       printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int inf = 0x3f3f3f3f;   const ll INF = 0x3f3f3f3f3f3f3f3fLL;   const int MAXN = 1e6 + 5;   int arr[MAXN], n;   ll fun(ll x) {     if (x == 1) return INF;     ll sum = 0, y = 0;     for (int i = 0; i < n; i++) {       y += arr[i];       y %= x;       sum += min(y, x - y);     }     return sum;   }   int main() {     std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     ll sum = 0, ans = INF;     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i], sum += arr[i];     if (sum < 2) {       cout << -1 <<   n ;       return 0;     }     for (ll i = 2; i * i <= sum; i++) {       if (sum % i == 0) ans = min(ans, fun(i));       while (sum % i == 0) sum /= i;     }     ans = min(ans, fun(sum));     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   using LL = int64_t;   using pii = pair<int, int>;   const double PI = 2 * asin(1);   int g_n;   string g_s;   vector<int> vi_in;   vector<LL> vll_sum;   void pretreat() {}   void input() {     vi_in.clear(), vi_in.resize(g_n + 1);     vll_sum.clear(), vll_sum.resize(g_n + 1);     for (int i = 1, t; i <= g_n; ++i) {       scanf(  %d , &vi_in[i]);     }     cin >> g_s;     g_s =     + g_s;   }   void solve() {     LL mx = 0, sum = 0;     for (int i = 1; i <= g_n; ++i) {       if (g_s[i] ==  B ) {         vll_sum[i] = vll_sum[i - 1] + vi_in[i];         mx = max(mx, vll_sum[i]);       } else {         vll_sum[i] = vll_sum[i - 1];       }     }     sum = 0;     for (int i = 1; i <= g_n; ++i) {       if (g_s[i] ==  A ) {         sum += vi_in[i];         mx = max(mx, sum + (vll_sum[g_n] - vll_sum[i]));       }     }     sum = 0;     for (int i = g_n; i > 0; --i) {       if (g_s[i] ==  A ) {         sum += vi_in[i];         mx = max(mx, sum + vll_sum[i]);       }     }     cout << mx << endl;   }   int main() {     pretreat();     int t;     while (cin >> g_n) {       input();       solve();     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   template <class T, class U>   inline void Max(T &a, U b) {     if (a < b) a = b;   }   template <class T, class U>   inline void Min(T &a, U b) {     if (a > b) a = b;   }   inline void add(int &a, int b) {     a += b;     while (a >= 1000003) a -= 1000003;   }   int pow(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = ans * (long long)a % 1000003;       a = (long long)a * a % 1000003;       b >>= 1;     }     return ans;   }   int f[700005], inv[700005], M;   int main() {     int T = 100, j, k, i, ca = 0, m, n;     scanf( %d%d , &n, &m);     M = n + m;     f[0] = 1;     for (int i = 1; i < M; i++) f[i] = f[i - 1] * (long long)i % 1000003;     inv[M - 1] = pow(f[M - 1], 1000003 - 2);     for (int i = M - 1 - 1; i >= 0; i--)       inv[i] = inv[i + 1] * (long long)(i + 1) % 1000003;     long long ans = 0;     for (int i = 1; i < n + 1; i++) {       ans += 1LL * f[i + m - 1] * inv[i] % 1000003;     }     ans %= 1000003;     printf( %d n , ans * inv[m - 1] % 1000003);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   int main() {     long long n, res = 0, i;     cin >> n;     long long ans = (n * (n + 1)) / 2;     if (ans % 2 == 0)       cout << 0 << endl;     else       cout << 1 << endl;     ans = ans / 2;     for (i = n; i >= 1; i--) {       res += i;       if (res > ans) break;       v.push_back(i);     }     res -= i;     if (res < ans) v.push_back(ans - res);     int sz = v.size();     cout << sz <<    ;     for (int i = 0; i < sz; i++) cout << v[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   int a[maxn];   int n;   int vis[maxn];   vector<int> ans;   int main() {     memset(vis, 0, sizeof(vis));     ans.clear();     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     int cnt = 0;     int ma = 0;     for (int i = 1; i <= n; i++) {       int l, r;       for (l = i - 1; l >= 1; l--) {         if (a[l] % a[i] != 0) break;       }       for (r = i + 1; r <= n; r++) {         if (a[r] % a[i] != 0) break;       }       l++, r--;       if (r - l == ma)         ans.push_back(l);       else if (r - l > ma) {         ans.clear();         ma = r - l;         ans.push_back(l);       }       i = r;     }     sort(ans.begin(), ans.end());     cout << ans.size() <<     << ma << endl;     for (int i = 0; i < ans.size(); i++) {       cout << ans[i];       if (i != ans.size() - 1) cout <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long x, a, b, i, f = 1, pa, push_back;     vector<pair<long long, long long> > v(n);     vector<long long> ch;     cin >> x;     cin >> a >> b;     pa = a, push_back = b;     if (a + b == 7) f = 0;     for (i = 1; i < n; i++) {       cin >> a >> b;       if (f == 1) {         if (a + b != 7) {           if (a == pa || a == 7 - pa || a == push_back || a == 7 - push_back) {             if (b == pa || b == 7 - pa || b == push_back || b == 7 - push_back) {               f = 1;             } else               f = 0;           } else             f = 0;         } else           f = 0;       }       pa = a, push_back = b;     }     if (f == 1) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     ;     int n, m;     cin >> n >> m;     int dem = 0;     if (m % n != 0) {       cout << -1;       return 0;     }     int sum = m / n;     while (sum % 2 == 0) {       sum /= 2;       dem++;     }     while (sum % 3 == 0) {       sum /= 3;       dem++;     }     if (sum == 1)       cout << dem;     else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void dfs(long long a, vector<long long>& d, vector<vector<long long>>& adj,            vector<long long>& vis, long long dist) {     d[a] = dist;     vis[a]++;     for (auto b : adj[a]) {       if (!vis[b]) {         dfs(b, d, adj, vis, dist + 1);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n, a, b, da, db;       cin >> n >> a >> b >> da >> db;       vector<vector<long long>> adj(n + 1);       for (long long i = 0; i < n - 1; i++) {         long long u, v;         cin >> u >> v;         adj[u].push_back(v);         adj[v].push_back(u);       }       if (da * 2 >= db) {         cout <<  Alice n ;         continue;       }       vector<long long> d(n + 1);       vector<long long> vis(n + 1);       dfs(b, d, adj, vis, 0);       if (d[a] <= da) {         cout <<  Alice n ;         continue;       }       long long mx = 0;       for (long long i = 1; i < n + 1; i++) {         mx = max(mx, d[i]);       }       vector<long long> d2(n + 1);       vector<long long> vis2(n + 1);       for (long long i = 1; i < n + 1; i++) {         if (d[i] == mx) {           dfs(i, d2, adj, vis2, 0);           break;         }       }       long long mx2 = 0;       for (long long i = 1; i < n + 1; i++) {         mx2 = max(mx2, d2[i]);       }       long long di = mx2;       if (di > 2 * da)         cout <<  Bob n ;       else         cout <<  Alice n ;     }     return 0;   }


#include <bits/stdc++.h>   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   using namespace std;   vector<long long int> v, v2, v3;   vector<long long int>::iterator it1, it2;   int ar[200];   int main() {     long long int tcase = 1;     while (tcase--) {       long long int n, k, a, ans = 0;       scanf( %lld %lld , &n, &k);       for (int i = 0; i < n; i++) {         scanf( %lld , &a);         ar[a % k]++;       }       ans += ar[0] / 2;       ar[0] = 0;       for (int i = 1; i <= (k / 2) + 1; i++) {         if (ar[i]) {           if (ar[k - i] && i != (k - i)) {             ans += min(ar[i], ar[k - i]);             ar[i] = ar[k - i] = 0;           } else if (ar[k - i] && (i == k - i)) {             ans += ar[i] / 2;             ar[i] = 0;           }         }       }       printf( %lld n , 2 * ans);     }   }


#include <bits/stdc++.h>   template <typename T>   inline void read(T& x) {     T res = 0, flag = 1;     char ch;     ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while (isdigit(ch)) {       res = res * 10 + ch - 48;       ch = getchar();     }     x = res * flag;   }   const int N = 100000 + 1;   int n, k, x;   bool vis[N], pre[N], suf[N];   int main() {     read(n), read(k);     long long ans = n * 3 - 2;     for (int i = 1; i <= k; ++i) {       read(x);       if (!vis[x]) --ans;       vis[x] = 1;       if (vis[x - 1] && !pre[x]) --ans, pre[x] = 1;       if (vis[x + 1] && !suf[x]) --ans, suf[x] = 1;     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[1 << 16], *S, *T;     if (S == T) {       T = (S = buf) + fread(buf, 1, 1 << 16, stdin);       if (T == S) return EOF;     }     return *S++;   }   inline int read() {     int x = 0, f = 1;     char ch = gc();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = gc();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = gc();     return x * f;   }   int n, K, m, c[100010 + 500010][2], v[100010 + 500010], fa[100010 + 500010],       mn[100010 + 500010], ans[100010], cc[100010], q[100010];   bool rev[100010 + 500010];   struct edge {     int x, y;   } e[500010];   inline bool cmp(edge a, edge b) { return a.y < b.y; }   struct query {     int l, r, id;     friend bool operator<(query a, query b) { return a.r < b.r; }   } qq[100010];   inline void add(int x, int val) {     for (; x <= n; x += x & -x) cc[x] += val;   }   inline int ask(int x) {     int res = 0;     for (; x; x -= x & -x) res += cc[x];     return res;   }   inline bool isroot(int x) { return x != c[fa[x]][0] && x != c[fa[x]][1]; }   inline void update(int p) {     int l = c[p][0], r = c[p][1];     mn[p] = p;     if (v[mn[l]] < v[mn[p]]) mn[p] = mn[l];     if (v[mn[r]] < v[mn[p]]) mn[p] = mn[r];   }   inline void pushdown(int p) {     if (!rev[p]) return;     rev[p] = 0;     swap(c[p][0], c[p][1]);     rev[c[p][0]] ^= 1;     rev[c[p][1]] ^= 1;   }   inline void rotate(int x) {     int y = fa[x], z = fa[y], l = x == c[y][1], r = l ^ 1;     if (!isroot(y)) c[z][y == c[z][1]] = x;     fa[c[x][r]] = y;     fa[y] = x;     fa[x] = z;     c[y][l] = c[x][r];     c[x][r] = y;     update(y);     update(x);   }   inline void splay(int x) {     int top = 0;     q[++top] = x;     for (int xx = x; !isroot(xx); xx = fa[xx]) q[++top] = fa[xx];     while (top) pushdown(q[top--]);     while (!isroot(x)) {       int y = fa[x], z = fa[y];       if (!isroot(y)) {         if (x == c[y][1] ^ y == c[z][1])           rotate(x);         else           rotate(y);       }       rotate(x);     }   }   inline void access(int x) {     int y = 0;     while (x) {       splay(x);       c[x][1] = y;       update(x);       y = x;       x = fa[x];     }   }   inline void makeroot(int x) {     access(x);     splay(x);     rev[x] ^= 1;   }   inline int find(int x) {     access(x);     splay(x);     while (c[x][0]) x = c[x][0];     return x;   }   inline void link(int x, int y) {     makeroot(x);     fa[x] = y;   }   inline void cut(int x, int y) {     makeroot(x);     access(y);     splay(y);     c[y][0] = fa[x] = 0;     update(y);   }   inline int qmin(int x, int y) {     makeroot(x);     access(y);     splay(y);     return mn[y];   }   inline void ins(int id) {     int x = e[id].x, y = e[id].y;     if (find(x) != find(y)) {       link(x, id + n), link(id + n, y), add(n - x + 1, 1);       return;     }     int z = qmin(x, y);     if (v[z] >= v[id + n]) return;     cut(z, e[z - n].x);     cut(z, e[z - n].y);     add(n - v[z] + 1, -1);     link(x, id + n);     link(id + n, y);     add(n - x + 1, 1);   }   int main() {     n = read();     K = read();     m = read();     v[0] = 0x3f3f3f3f;     for (int i = 1; i <= m; ++i) {       e[i].x = read();       e[i].y = read();       if (e[i].x > e[i].y) swap(e[i].x, e[i].y);     }     sort(e + 1, e + m + 1, cmp);     int Q = read();     for (int i = 1; i <= m; ++i) v[i + n] = e[i].x;     for (int i = 1; i <= n; ++i) v[i] = 0x3f3f3f3f;     for (int i = 1; i <= Q; ++i) qq[i].l = read(), qq[i].r = read(), qq[i].id = i;     sort(qq + 1, qq + Q + 1);     int now = 1;     for (int i = 1; i <= Q; ++i) {       while (now <= m && e[now].y <= qq[i].r) ins(now), ++now;       ans[qq[i].id] = qq[i].r - qq[i].l + 1 - ask(n - qq[i].l + 1);     }     for (int i = 1; i <= Q; ++i) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(long long y) {     for (long long x = 2; x * x <= y; x++) {       if (y % x == 0) return 0;     }     return 1;   }   int main() {     std::cin.tie(0);     std::ios::sync_with_stdio(false);     long long n, x, y;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> y >> x;       if (y - x == 1 && check(x + y)) {         cout <<  Yes  << endl;       } else {         cout <<  No  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int a[N], b[N], seg[4 * N], lazy[4 * N], n, diff[N];   void update(int sq, int eq, int val, int id = 1, int s = 1, int e = n) {     if (lazy[id] != 0) {       seg[id] = lazy[id];       if (s != e) lazy[id * 2] = lazy[id * 2 + 1] = lazy[id];       lazy[id] = 0;     }     if (s > eq || e < sq) return;     if (s >= sq && e <= eq) {       seg[id] = val;       if (s != e) lazy[id * 2] = lazy[id * 2 + 1] = val;       return;     }     int mid = (s + e) / 2;     update(sq, eq, val, id * 2, s, mid);     update(sq, eq, val, id * 2 + 1, mid + 1, e);   }   int query(int idx, int id = 1, int s = 1, int e = n) {     if (lazy[id] != 0) {       seg[id] = lazy[id];       if (s != e) lazy[id * 2] = lazy[id * 2 + 1] = lazy[id];       lazy[id] = 0;     }     if (s == e) return seg[id];     int mid = (s + e) / 2;     if (idx <= mid)       return query(idx, id * 2, s, mid);     else       return query(idx, id * 2 + 1, mid + 1, e);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int m;     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 1; i <= m; i++) {       int t;       cin >> t;       if (t == 2) {         int x;         cin >> x;         int cur = query(x);         if (cur == 0)           cout << b[x] <<   n ;         else           cout << a[x + diff[cur]] <<   n ;       } else {         int x, y, k;         cin >> x >> y >> k;         diff[i] = x - y;         update(y, y + k - 1, i);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5;   int c[4][11][11][maxn + 5];   char s[maxn + 50];   char t[15];   int n;   int getnum(char c) {     if (c ==  A ) return 0;     if (c ==  T ) return 1;     if (c ==  G ) return 2;     if (c ==  C ) return 3;   }   int lowbit(int x) { return x & (-x); }   void add(int *c, int k, int x) {     for (int i = k; i <= n; i += lowbit(i)) {       c[i] += x;     }   }   int query(int *c, int k) {     int ans = 0;     for (int i = k; i; i -= lowbit(i)) ans += c[i];     return ans;   }   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (int ch = 0; ch < 4; ++ch)       for (int i = 1; i <= 10; ++i)         for (int j = 1; j <= i; ++j)           for (int k = j; k <= n; k += i)             if (getnum(s[k]) == ch) {               add(c[ch][i][j], (k - j) / i + 1, 1);             }     int q;     scanf( %d , &q);     while (q--) {       int op, x, l, r;       char ch;       scanf( %d , &op);       if (op == 1) {         scanf( %d %c , &x, &ch);         int id = getnum(s[x]);         for (int i = 1; i <= 10; ++i) {           int j = x % i;           if (j == 0) j = i;           add(c[id][i][j], (x - j) / i + 1, -1);         }         s[x] = ch;         id = getnum(s[x]);         for (int i = 1; i <= 10; ++i) {           int j = x % i;           if (j == 0) j = i;           add(c[id][i][j], (x - j) / i + 1, 1);         }       }       if (op == 2) {         scanf( %d%d%s , &l, &r, t + 1);         int len = strlen(t + 1);         int ans = 0;         for (int k = 1; k <= len && k <= r - l + 1; ++k) {           int id = getnum(t[k]);           int i = len;           int j = (l + k - 1) % i;           if (j == 0) j = i;           ans += query(c[id][i][j], (r - j) / i + 1) -                  query(c[id][i][j], (l + k - 1 - j) / i);         }         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct laptop {     long long p, b, ind;     laptop() {}     laptop(long long a, long long b, long long c) : p(a), b(b), ind(c) {}     bool operator<(const laptop& o) const {       return ((long double)o.b * p > (long double)b * o.p);     }   };   int n, k;   vector<laptop> laptops;   bool check(long long q) {     priority_queue<laptop> pq;     for (auto& x : laptops) {       pq.push(x);     }     laptop here(0, 1, 1);     for (int i = 0; i < k; ++i) {       laptop u = pq.top();       pq.pop();       here.p = i;       if (here < u) {         return false;       }       u.p += q;       pq.push(u);     }     return true;   }   long long bs() {     const long long THIGH = 2000000000001LL;     long long lo = 0, hi = THIGH;     while (lo < hi) {       long long m = (lo + hi) / 2;       if (check(m)) {         hi = m;       } else {         lo = m + 1;       }     }     if (lo == THIGH) return -1;     return lo;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     cin >> n >> k;     laptops.resize(n);     for (int i = 0; i < n; ++i) {       cin >> laptops[i].p;       laptops[i].ind = i;     }     for (int i = 0; i < n; ++i) {       cin >> laptops[i].b;     }     cout << bs() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long m, n, a, b, c, ans, ar[1000001], k, paths[200010], visit[200010],       ans1, dp[400010], t, er[200110];   bool boo;   bool compare(long long a, long long b) {     if (a >= b) return 1;     return 0;   }   int main() {     string s;     std::ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (long long i = 0; i < n; i++) {       cin >> a;       er[i] = a;       a %= m;       ar[a]++;     }     for (long long i = 0; i < m; i++) {       if (ar[i] >= 2) {         cout << 0;         return 0;       }     }     ans = 1;     sort(er, er + n);     for (long long i = n - 1; i >= 0; i--) {       for (long long j = 0; j < i; j++) {         ans *= (er[i] - er[j]) % m;         ans %= m;       }     }     cout << ans % m;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005];   int themax(int b[], int k) {     int sum = b[0];     for (int z = 1; z < k; z++) {       sum += (b[z] + 1);     }     return sum;   }   int main() {     int n, x, max = 0, min = 0;     cin >> n >> x;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     max = themax(a, n);     if (x == max)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e4 + 10;   const int maxk = 2e4 + 10;   const int inf = 0x3f3f3f3f;   int n, m, k;   bool g[maxn][maxn];   struct Block {     int l, r, b, t;   };   Block b[maxk];   int bnum;   bool vis[maxk];   int d[maxk];   int res;   int start, stop;   void bfs() {     memset(d, 0, sizeof d);     res = inf;     queue<int> q;     q.push(start);     while (q.size()) {       int u = q.front();       q.pop();       vis[u] = true;       if (u == stop) {         res = min(d[u], res);         continue;       } else if (b[u].b >= n - 1 || b[u].r >= m - 1) {         res = min(d[u] + 1, res);         continue;       }       for (int i = 0; i < bnum; i++) {         if (vis[i]) continue;         if (b[u].t > b[i].b + 2 && (b[u].l > b[i].r + 2 || b[u].r < b[i].l - 2))           continue;         if (b[u].b < b[i].t - 2 && (b[u].l > b[i].r + 2 || b[u].r < b[i].l - 2))           continue;         vis[i] = true;         d[i] = d[u] + 1;         q.push(i);       }     }   }   bool dvis[maxn][maxn];   void dfs(int r, int c, int bnum) {     if (dvis[r][c]) return;     if (r == 1 && c == 1) start = bnum;     if (r == n && c == m) stop = bnum;     dvis[r][c] = 1;     b[bnum].l = min(b[bnum].l, c);     b[bnum].r = max(b[bnum].r, c);     b[bnum].b = max(b[bnum].b, r);     b[bnum].t = min(b[bnum].t, r);     if (r > 1 && g[r - 1][c]) dfs(r - 1, c, bnum);     if (r < n && g[r + 1][c]) dfs(r + 1, c, bnum);     if (c > 1 && g[r][c - 1]) dfs(r, c - 1, bnum);     if (c < m && g[r][c + 1]) dfs(r, c + 1, bnum);   }   int main() {     memset(g, 0, sizeof g);     scanf( %d%d%d , &n, &m, &k);     for (int i = 0; i < k; i++) {       int r, c;       scanf( %d%d , &r, &c);       g[r][c] = 1;     }     bnum = 0;     start = stop = -1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (g[i][j] && !dvis[i][j]) {           b[bnum].r = b[bnum].l = j;           b[bnum].b = b[bnum].t = i;           dfs(i, j, bnum);           bnum++;         }       }     }     bfs();     if (res < inf)       printf( %d n , res);     else       printf( -1 n );   }


#include <bits/stdc++.h>   using namespace std;   int a, s, d[10004][2], f, g, h, j, k, l, i, n, m;   string x, z;   set<string> q;   bool chk(int idx, int dis) {     for (int i = idx; i < idx + dis; i++) {       if (x[i] != x[i + dis]) return true;     }     return false;   }   int main() {     cin >> x;     n = x.size();     if (n >= 7) {       d[n - 2][0] = 1;       z = z + x[n - 2] + x[n - 1];       q.insert(z);     }     if (n >= 8) {       d[n - 3][1] = 1;       z = x[n - 3] + z;       q.insert(z);     }     for (i = n - 4; i >= 5; i--) {       d[i][0] = d[i + 2][1];       if (chk(i, 2)) d[i][0] |= d[i + 2][0];       if (d[i][0]) {         z =   ;         z = z + x[i] + x[i + 1];         q.insert(z);       }       d[i][1] = d[i + 3][0];       if (chk(i, 3)) d[i][1] |= d[i + 3][1];       if (d[i][1]) {         z =   ;         z = z + x[i] + x[i + 1] + x[i + 2];         q.insert(z);       }     }     cout << q.size() << endl;     for (set<string>::iterator it = q.begin(); it != q.end(); it++) {       cout << *it << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   bool IsPrime(int x) {     for (int i = 2; i * i <= x; i++)       if (x % i == 0) return false;     return true;   }   int modpow(int w, int p, int m) {     if (p == 0) return 1;     int x = modpow(w, p / 2, m);     x = 1LL * x * x % m;     if (p & 1) x = 1LL * x * w % m;     return x;   }   int main() {     int L, x, p;     scanf( %d%d , &L, &x);     p = L + 1;     if ((x == 2) || !IsPrime(p)) {       puts( -1 );       return 0;     }     if (L == 1) {       printf( %d n , x - 1);       return 0;     }     for (int b = x - 1; b > 1; b--) {       if (modpow(b, L, p) != 1) continue;       if (b % p == 0) continue;       long long t = 0, r = 1, n = 0, x, d;       while (1) {         t = t + 1;         x = r * b;         d = x / p;         r = x % p;         n = n * b + d;         if (r == 1) break;         if (t > p / 2) {           printf( %d n , b);           return 0;         }       }       if (t == L) {         printf( %d n , b);         return 0;       }     }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long n, a[100009], m = 0;     cin >> n;     for (long i = long(0); i < long(n); i++) {       cin >> a[i];       m = max(m, a[i]);     }     long c = 0, q = 0;     for (long i = long(0); i < long(n); i++) {       if (a[i] == m)         c++;       else {         q = max(q, c);         c = 0;       }     }     q = max(q, c);     cout << q <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct dat {     int L, R, V;   } a[100005];   int N, M;   bool cmp(dat a, dat b) {     if (a.L != b.L) return a.L < b.L;     if (a.R != b.R) return a.R < b.R;     return a.V < b.V;   }   int ans[100005], s[100005];   void build(int k) {     int last = 0;     for (int i = (1), _b = (M); i <= _b; i++)       if (a[i].V >> k & 1) {         for (int j = (max(last + 1, a[i].L)), _b = (a[i].R); j <= _b; j++)           ans[j] |= (1 << k);         last = max(last, a[i].R);       }     memset(s, 0, sizeof s);     for (int i = (1), _b = (N); i <= _b; i++)       s[i] = s[i - 1] + (!(ans[i] >> k & 1));     for (int i = (1), _b = (M); i <= _b; i++)       if (!(a[i].V >> k & 1))         if (s[a[i].R] == s[a[i].L - 1]) {           cout <<  NO n ;           exit(0);         }   }   int main(void) {     cin >> N >> M;     for (int i = (1), _b = (M); i <= _b; i++) cin >> a[i].L >> a[i].R >> a[i].V;     sort(a + 1, a + M + 1, cmp);     for (int i = (0), _b = (29); i <= _b; i++) build(i);     cout <<  YES n ;     for (int i = (1), _b = (N); i <= _b; i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     long long int a, b;     cin >> a >> b;     long long int sumo = 0, sume = 0;     for (int i = 1;; i++) {       sumo = i * i;       if (sumo > a) {         cout <<  Vladik  << endl;         break;       }       sume = i * (i + 1);       if (sume > b) {         cout <<  Valera  << endl;         break;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 155;   int n;   int a[N], b[N], A, B;   int main() {     scanf( %d , &n);     a[0] = 1;     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= A; j++) b[j + 1] = (b[j + 1] + a[j]) % 2;       B = max(B, A + 1);       swap(A, B);       for (int j = 0; j <= A; j++) swap(a[j], b[j]);     }     printf( %d n , A);     for (int i = 0; i <= A; i++) printf( %d%c , a[i], i == A ?   n  :    );     printf( %d n , B);     for (int i = 0; i <= B; i++) printf( %d%c , b[i], i == B ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int N = 1E6 + 7;   int n;   int id[N], x[N], y[N];   bool cmp(int a, int b) {     if (x[a] < x[b]) return true;     if (x[a] > x[b]) return false;     if (x[a] % 2 == 1)       return y[a] < y[b];     else       return y[a] > y[b];   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d , &x[i], &y[i]);       x[i] /= 1000;       y[i] /= 1000;       id[i] = i;     }     sort(id, id + n, cmp);     for (int i = 0; i < n; i++) {       printf( %d  , id[i] + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg, typename... Args>   inline void input(Arg& arg, Args&... args) {     cin >> arg;     (void)(int[]){0, (void(cin >> args), 0)...};   }   template <typename Arg, typename... Args>   inline void printErr(Arg&& arg, Args&&... args) {     cerr << arg;     (void)(int[]){0, (void(cerr <<                                     <<   033[1;41m                                  <<  ,                                  <<   033[0m                                  <<     << args),                       0)...};     cerr <<   n ;   };   template <class T, class... U>   void dbg(const char* sdbg, T h, U... a) {     cerr <<   033[1;31m           <<  Debug:            <<   033[0m ;     cerr << sdbg;     cerr <<              <<   033[1;41m           <<  =           <<   033[0m           <<    ;     printErr(h, a...);   }   template <class S, class T>   ostream& operator<<(ostream& os, const pair<S, T>& p) {     return os <<  pair(  << p.first <<   033[1;31m                <<  ,                 <<   033[0m  << p.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& p) {     os <<   033[1;32m         <<  vector[          <<   033[0m ;     for (auto& it : p)       os << it <<   033[1;31m           <<  ,            <<   033[0m ;     return os <<   033[1;32m                <<  ]                <<   033[0m ;   }   template <class T>   ostream& operator<<(ostream& os, const set<T>& p) {     os <<   033[1;32m         <<  set[  ;     for (auto& it : p)       os << it <<   033[1;31m           <<  ,            <<   033[0m ;     return os <<   033[1;32m                <<  ]                <<   033[0m ;   }   template <class S, class T>   ostream& operator<<(ostream& os, const map<S, T>& p) {     os <<   033[1;32m         <<  map[          <<   033[0m ;     for (auto& it : p)       os << it <<   033[1;31m           <<  ,            <<   033[0m ;     return os <<   033[1;32m                <<  ]                <<   033[0m ;   }   template <class T>   void dbgIter(const char* sdbg, T a, T b) {     cerr <<   033[1;31m           <<  Debug:            <<   033[0m ;     cerr << sdbg;     cerr <<   033[1;31m           <<   =            <<   033[0m ;     cerr <<  [ ;     for (T i = a; i != b; ++i) {       if (i != a) cerr <<  ,  ;       cerr << *i;     }     cerr <<  ] n ;   }   template <typename T>   using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>;   template <typename T>   using max_heap = priority_queue<T>;   template <typename T, typename S>   inline bool contains(map<T, S> map1, S value1) {     return map1.find(value1) != map1.end();   }   template <typename T, typename S>   inline bool contains(T container1, S value1) {     return container1.find(value1) != container1.end();   }   class DisjoinSetUnion {    public:     int32_t p[1010];     DisjoinSetUnion() { iota(begin(p), end(p), 0); }     int32_t root1(int32_t t_v) {       return (p[t_v] == t_v) ? t_v : (p[t_v] = root1(p[t_v]));     }     void union1(int32_t t_a, int32_t t_b) { p[root1(t_a)] = root1(t_b); }   };   int32_t n, m;   void solve() {     cin >> n >> m;     int32_t v1, v2;     DisjoinSetUnion dsu;     for (int64_t(i) = (0); (i) < (m); ++(i)) {       cin >> v1 >> v2;       dsu.union1(v1, v2);     }     for (int64_t(i) = (2); (i) <= (n); ++(i))       if (dsu.root1(i) != dsu.root1(1)) {         cout <<  no n ;         return;       }     if ((n - 1) == m)       cout <<  yes n ;     else       cout <<  no n ;   }   int32_t main() {     std::ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cout.precision(20);     cout << fixed;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 500002;   long long a[maxn];   int n, k, d;   void enter() {     cin >> n >> k >> d;     for (int i = (1), _b = (n + 1); i < _b; ++i) cin >> a[i];   }   int seg[4 * maxn];   void update(int l, int r, int st, int q) {     if (l == r)       seg[st] = 1;     else {       int mid = (l + r) >> 1;       if (mid >= q)         update(l, mid, st * 2, q);       else         update(mid + 1, r, st * 2 + 1, q);       seg[st] = max(seg[st * 2], seg[st * 2 + 1]);     }   }   int _get(int l, int r, int u, int v, int st) {     if (u <= l && r <= v)       return seg[st];     else if (l > v || r < u)       return 0;     else {       int mid = (l + r) >> 1;       return max(_get(l, mid, u, v, st * 2), _get(mid + 1, r, u, v, st * 2 + 1));     }   }   void solve() {     sort(a + 1, a + n + 1);     update(0, n, 1, 0);     for (int i = (1), _b = (n + 1); i < _b; ++i) {       int pos = lower_bound(a + 1, a + n + 1, a[i] - d) - a;       if (pos <= i - k + 1) {         if (_get(0, n, pos - 1, i - k, 1) == 1) {           if (i == n) {             cout <<  YES ;             exit(0);           } else             update(0, n, 1, i);         }       }     }     cout <<  NO ;   }   int main() {     enter();     solve();   }


#include <bits/stdc++.h>   using namespace std;   char s[200005];   char x[26];   int n, m;   char a, b;   int main() {     while (scanf( %d%d , &n, &m) != EOF) {       for (int i = 0; i < 26; i++) x[i] = i +  a ;       getchar();       scanf( %s , s);       getchar();       for (int i = 0; i < m; i++) {         scanf( %c , &a);         getchar();         scanf( %c , &b);         getchar();         if (a == b) continue;         for (int j = 0; j < 26; j++) {           if (x[j] == a) {             x[j] = b;             continue;           }           if (x[j] == b) {             x[j] = a;             continue;           }         }       }       int k;       for (int i = 0; i < n; i++) {         k = s[i] -  a ;         printf( %c , x[k]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string ch, t;     int n, s, i;     bool ok1 = 0, ok2 = 0;     scanf( %d %d , &n, &s);     if (9 * n >= s) {       if (n == 1 && s == 0) {         cout << 0 <<     << 0 << endl;       } else if (s == 0) {         cout << -1 <<     << -1 << endl;       } else {         while (n--) {           ch += min(9, s) +  0 ;           t = ch;           s -= 9;           if (s < 0) s = 0;         }         reverse(t.begin(), t.end());         if (t[0] ==  0 ) {           t[0] =  1 ;           for (i = 1; i < t.size(); i++) {             if (t[i] >  0 ) {               t[i] = t[i] - 1;               break;             }           }         }         cout << t <<     << ch << endl;       }     } else {       cout << -1 <<     << -1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 1000000007;   long long n, k;   long long a[100050];   long long cnt[100050];   map<long long, long long> dict;   long long f[100050];   long long fac[100000 + 50], ifac[100000 + 50];   long long pwk[100050];   long long ksm(long long a, long long x = M - 2) {     long long ret = 1;     for (; x; x >>= 1, a = a * a % M)       if (x & 1) ret = ret * a % M;     return ret;   }   long long C(long long n, long long m) {     if (m < 0 || m > n) return 0;     return fac[n] * ifac[m] % M * ifac[n - m] % M;   }   void prepare() {     fac[0] = 1;     for (int i = 1; i <= 100000; i++) fac[i] = fac[i - 1] * i % M;     ifac[100000] = ksm(fac[100000]);     for (int i = 100000 - 1; i >= 0; i--) ifac[i] = ifac[i + 1] * (i + 1) % M;   }   int main() {     ios_base::sync_with_stdio(false);     prepare();     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       dict[a[i]]++;     }     cnt[0] = k;     for (auto y : dict)       if (y.first != -1) cnt[y.second]++, cnt[0]--;     int r = 0;     if (dict.find(-1) != dict.end()) r = dict[-1];     for (int i = 1; i < n; i++) {       f[i + 1] = ksm(M + i - n) *                  ((k - 1) * i % M * f[i - 1] % M +                   ((M + 2 - k) * i % M - n + M) * f[i] % M + i * k % M) %                  M;     }     long long invpwkr = ksm(ksm(k, r));     pwk[0] = 1;     for (int i = 1; i <= n; i++) pwk[i] = pwk[i - 1] * (k - 1) % M;     long long ans = (M - (f[0] * (k - 1) + f[n]) % M) % M;     for (int i = 0; i <= n; i++)       if (cnt[i] != 0) {         for (int j = 0; j <= r; j++)           ans = (ans +                  C(r, j) * f[i + j] % M * cnt[i] % M * invpwkr % M * pwk[r - j]) %                 M;       }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   deque<char> D;   int main() {     int n;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < n; i++)       if (D.size() % 2 == 0 || D.back() != s[i]) D.push_back(s[i]);     if (D.size() % 2 == 1) D.pop_back();     cout << n - D.size() << endl;     for (int i = 0; i < D.size(); i++) cout << D[i];     cout << endl;     return 0;   }


#include <bits/stdc++.h>   int const MAX = 1e5 + 5;   int a[MAX], need[MAX];   bool has[MAX], pos[MAX];   int main() {     int n, num = 0;     scanf( %d , &n);     memset(has, false, sizeof(has));     memset(pos, false, sizeof(pos));     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       if (!has[a[i]] && a[i] <= n)         has[a[i]] = true;       else         pos[i] = true;     }     int cnt = 0;     for (int i = 1; i <= n; i++)       if (!has[i]) need[cnt++] = i;     int idx = 0;     for (int i = 0; i < n; i++)       if (pos[i]) a[i] = need[idx++];     for (int i = 0; i < n - 1; i++) printf( %d  , a[i]);     printf( %d n , a[n - 1]);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100003;   pair<int, int> t[4 * maxn];   int psh[maxn];   void update(int v, int l, int r, int q) {     if (l == r) return void(t[v] = psh[q] ? make_pair(1, 0) : make_pair(0, 1));     int m = (l + r) / 2;     if (q <= m) update(v * 2, l, m, q);     if (q > m) update(v * 2 + 1, m + 1, r, q);     int u = min(t[v * 2].first, t[v * 2 + 1].second);     t[v] = make_pair(t[v * 2].first + t[v * 2 + 1].first - u,                      t[v * 2].second + t[v * 2 + 1].second - u);   }   int get_ans(int v, int l, int r, int c) {     if (!t[v].first) return -1;     if (l == r) return psh[l];     int m = (l + r) / 2;     if (t[v * 2 + 1].first - c > 0)       return get_ans(v * 2 + 1, m + 1, r, c);     else       return get_ans(v * 2, l, m, c - t[v * 2 + 1].first + t[v * 2 + 1].second);   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       int q, t, num;       scanf( %d %d , &q, &t);       if (t == 1) {         scanf( %d , &num);         psh[q] = num;       }       update(1, 1, n, q);       printf( %d n , get_ans(1, 1, n, 0));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> tree[3005];   int p[3005][3005];   long long sz[3005][3005];   long long dfs(int root, int cur) {     sz[root][cur] = 1;     for (int nxt : tree[cur]) {       if (!sz[root][nxt]) {         sz[root][cur] += dfs(root, nxt);         p[root][nxt] = cur;       }     }     return sz[root][cur];   }   long long dp[3005][3005];   long long f(int a, int b) {     long long& ret = dp[a][b];     if (~ret) return ret;     ret = 0;     if (a == b) return ret;     return ret = sz[b][a] * sz[a][b] + max(f(a, p[a][b]), f(p[b][a], b));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     memset(dp, -1, sizeof(dp));     cin >> n;     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       tree[a].push_back(b);       tree[b].push_back(a);     }     for (int i = 1; i <= n; i++) dfs(i, i);     long long ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) ans = max(ans, f(i, j));     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int d1, d2, d3;   int r;   int main() {     cin >> d1 >> d2 >> d3;     r = d1 + d2 + d3;     r = min(r, d1 + d1 + d2 + d2);     r = min(r, d1 + d3 + d1 + d3);     r = min(r, d2 + d3 + d2 + d3);     cout << r <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int n, m;       cin >> n >> m;       long long int s = 0, x, y, i, j;       vector<long long int> a, b;       for (i = 0; i < n; i++) {         cin >> x;         if (x < 0)           a.push_back(x);         else           b.push_back(x);       }       sort(a.begin(), a.end());       sort(b.begin(), b.end());       if (a.size() > 0 && b.size() > 0) {         if (abs(a[0]) > b[b.size() - 1]) {           s += abs(a[0]);           for (i = m; i < a.size(); i += m) s += abs(2 * a[i]);           for (i = b.size() - 1; i >= 0; i -= m) s += (2 * b[i]);         } else {           s += b[b.size() - 1];           for (i = b.size() - 1 - m; i >= 0; i -= m) s += (2 * b[i]);           for (i = 0; i < a.size(); i += m) s += abs(2 * a[i]);         }       } else if (a.size() > 0) {         s += abs(a[0]);         for (i = m; i < a.size(); i += m) s += abs(2 * a[i]);       } else {         s += b[b.size() - 1];         for (i = b.size() - 1 - m; i >= 0; i -= m) s += (2 * b[i]);       }       cout << s << endl;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int i, j, count, n, a[5001], flag[5001];     scanf( %d , &n);     count = 0;     memset(flag, 0, sizeof(int) * 5001);     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       if (a[i] > n)         count++;       else if (flag[a[i]] == 1)         count++;       else         flag[a[i]] = 1;     }     printf( %d n , count);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     vector<int> v(n);     int mx = 0;     for (int i = 0; i < n; i++) {       cin >> v[i];       mx = max(mx, v[i]);     }     int count = 1, l = 0;     for (int i = 0; i < n; i++) {       if (i && v[i] == v[i - 1] && v[i] == mx)         count++;       else {         l = max(count, l);         count = 1;       }       if (i == n - 1) l = max(count, l);     }     cout << l << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   multiset<int> a, b;   int c[300010], d[300010];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> c[i] >> d[i];       a.insert(c[i]);       b.insert(d[i]);     }     int ans = 0;     for (int i = 1; i <= n; i++) {       a.erase(a.find(c[i]));       b.erase(b.find(d[i]));       ans = max(ans, *b.begin() - *a.rbegin());       a.insert(c[i]);       b.insert(d[i]);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, sx, ex;   char s[1010];   int main() {     scanf( %d%d%s , &n, &k, s);     for (int i = 0; i < n; i++) {       if (s[i] ==  G ) sx = i;       if (s[i] ==  T ) ex = i;     }     if (sx > ex) swap(sx, ex);     if ((ex - sx) % k != 0)       printf( NO n );     else {       bool f = 1;       for (int i = sx + k; i < ex; i += k) {         if (s[i] ==  # ) f = 0;       }       if (f)         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       string s;       cin >> s;       vector<long long> cnt(26);       for (auto u : s) ++cnt[u -  a ];       long long ans = 0;       for (long long period = 1; period <= n; ++period) {         if (k % period) continue;         for (long long times = 1; times <= n; ++times) {           long long length = 0;           for (long long c = 0; c < 26; ++c) length += cnt[c] / times;           if (length < period) continue;           ans = max(ans, period * times);         }       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long s = 0, w = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s * w;   }   void put1() { puts( Yes ); }   void put2() { puts( No ); }   void put3() { puts( -1 ); }   long long qp(long long a, long long b, long long p) {     long long ans = 1;     while (b) {       if (b & 1) {         ans = (ans * a) % p;         --b;       }       a = (a * a) % p;       b >>= 1;     }     return ans % p;   }   const unsigned long long base = 2333;   const unsigned long long pp = 19260811;   const unsigned long long ppp = 999998639;   const int manx = 2e5 + 5;   const int mo = 998244353;   map<long long, long long> dp;   long long a[manx];   vector<long long> q;   int main() {     long long n = read();     long long ma = 0, ans = 0;     for (int i = 1; i <= n; i++) {       a[i] = read();       dp[a[i]] = max(dp[a[i] - 1] + 1, dp[a[i]]);       if (dp[a[i]] > ans) ans = dp[a[i]], ma = a[i];     }     for (int i = n; i >= 1; i--)       if (a[i] == ma) q.push_back(i), ma--;     reverse(q.begin(), q.end());     cout << q.size() << endl;     for (auto x : q) cout << x <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long a, b, c;     cin >> a >> b;     c = a + b;     string s = to_string(a);     string x = to_string(b);     string y = to_string(c);     string e =   , f =   , g =   ;     for (int i = 0; i < s.size(); i++) {       if (s[i] !=  0 ) {         e += s[i];       }     }     for (int i = 0; i < x.size(); i++) {       if (x[i] !=  0 ) {         f += x[i];       }     }     for (int i = 0; i < y.size(); i++) {       if (y[i] !=  0 ) {         g += y[i];       }     }     long long m, n, p;     m = stoi(e);     n = stoi(f);     p = stoi(g);     if (m + n == p)       cout <<  YES n ;     else       cout <<  NO n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<int> Tmp, Trans;   int dp[(500 + 5)][(500 + 5)], n, m, A[(500 + 5)], B[(500 + 5)];   int from[(500 + 5)][(500 + 5)][2], rkA[(500 + 5)], rkB[(500 + 5)];   int trans[(500 + 5)][(500 + 5)];   int getrk(int x) {     int TP = 0;     for (set<int>::iterator i = Trans.begin(); i != Trans.end(); ++i) {       ++TP;       if (*i == x) return TP;     }     return -1;   }   void output(int x, int y) {     if (y == 0 || x == 0) return;     output(from[x][y][0], from[x][y][1]);     cout << B[y] <<    ;   }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> A[i];       Tmp.insert(A[i]);     }     cin >> m;     for (int i = 1; i <= m; ++i) {       cin >> B[i];       if (Tmp.find(B[i]) != Tmp.end()) Trans.insert(B[i]);     }     for (int i = 1; i <= n; ++i) {       if (Trans.find(A[i]) != Trans.end())         rkA[i] = getrk(A[i]);       else         rkA[i] = 0;     }     for (int i = 1; i <= m; ++i) {       if (Trans.find(B[i]) != Trans.end())         rkB[i] = getrk(B[i]);       else         rkB[i] = 0;     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= (int)Trans.size(); ++j) {         trans[i][j] = max(trans[i - 1][j], (rkA[i] == j) * i);       }     }     for (int x = 1; x <= n; ++x) {       for (int i = 1; i <= m; ++i) {         if (A[x] != B[i]) continue;         for (int k = 0; k < i; ++k) {           if (rkB[k] >= rkB[i]) continue;           if (dp[trans[x - 1][rkB[k]]][k] + 1 > dp[x][i]) {             dp[x][i] = dp[trans[x - 1][rkB[k]]][k] + 1;             from[x][i][0] = trans[x - 1][rkB[k]];             from[x][i][1] = k;           }         }       }     }     int Ans = 0, x, y, z;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         if (A[i] == B[j] && dp[i][j] > Ans) {           Ans = dp[i][j];           x = i, y = j;         }       }     }     cout << Ans << endl;     if (Ans != 0) output(x, y);   }


#include <bits/stdc++.h>   using namespace std;   const int mn = 2005;   vector<int> g[mn], G[mn];   int dfn[mn], low[mn], times;   int stk[mn], top, bel[mn], cnt, siz[mn], fa[mn];   int rt, maxs;   bool ins[mn], vis[mn][mn], flg[mn], chn[mn], tmp[mn], leav[mn];   void dfs1(int s, int f) {     dfn[s] = low[s] = ++times, stk[++top] = s, ins[s] = 1;     int m = g[s].size();     for (int i = 0; i < m; i++) {       int t = g[s][i];       if (t == f) continue;       if (!dfn[t])         dfs1(t, s), low[s] = min(low[s], low[t]);       else if (ins[s])         low[s] = min(low[s], dfn[t]);       if (low[t] > dfn[s]) {         ++cnt;         while (stk[top] != t)           ins[stk[top]] = 0, bel[stk[top--]] = cnt, ++siz[cnt];         bel[t] = cnt, ins[t] = 0, --top, ++siz[cnt];       }     }   }   void dfs2(int s, int d) {     if (d > maxs) rt = s, maxs = d;     int m = G[s].size();     flg[s] = 1;     for (int i = 0; i < m; i++) {       int t = G[s][i];       if (!flg[t]) dfs2(t, d + 1);     }   }   void dfs3(int s, int f, int d) {     int m = G[s].size();     fa[s] = f;     bool flg = 0;     for (int i = 0; i < m; i++) {       int t = G[s][i];       if (t != f) dfs3(t, s, d + 1), flg = 1;     }     leav[s] = flg ^ 1;     if (!flg && d > maxs) {       memset(tmp, 0, sizeof tmp), maxs = d;       while (s) tmp[s] = 1, s = fa[s];     }   }   int main() {     int n, m, a, b, blk = 0, ans = 0;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++)       scanf( %d%d , &a, &b), g[a].push_back(b), g[b].push_back(a);     for (int i = 1; i <= n; i++)       if (!dfn[i]) {         dfs1(i, 0), ++blk, ++cnt;         while (top) bel[stk[top]] = cnt, ins[stk[top]] = 0, --top, ++siz[cnt];       }     for (int i = 1; i <= n; i++) {       int siz = g[i].size();       for (int j = 0; j < siz; j++) {         int t = g[i][j];         if (bel[i] != bel[t] && !vis[bel[i]][bel[t]])           vis[bel[i]][bel[t]] = vis[bel[t]][bel[i]] = 1,           G[bel[i]].push_back(bel[t]), G[bel[t]].push_back(bel[i]);       }     }     for (int i = 1; i <= cnt; i++) {       ans += siz[i] - 1;       if (!flg[i]) {         maxs = 0, dfs2(i, 1), maxs = 0, dfs3(rt, 0, 1);         for (int i = 1; i <= cnt; i++) chn[i] |= tmp[i];       }     }     for (int i = 1; i <= cnt; i++) {       int s = i, d = 0;       if (leav[s]) continue;       while (!chn[s]) chn[s] = 1, s = fa[s], ++d;       ans += d;     }     printf( %d n , ans + blk - 1);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 101;   int a[N];   int n;   int main() {     int i, t;     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     t = a[0];     a[0] = a[n - 1];     a[n - 1] = t;     for (i = 0; i < n; i++) cout << a[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC_OPTIMAZE( ofast )   using namespace std;   signed main() {     long long n;     cin >> n;     vector<long long> arr(n);     for (long long i = 0; i < n; i++) {       cin >> arr[i];       arr[i]--;     }     long long cnt = 0, pos = 0;     while (pos < n) {       cnt++;       long long mx = pos;       while (pos < n && pos <= mx) {         mx = max(mx, arr[pos]);         pos++;       }     }     cout << cnt << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     vector<vector<int> > T(n);     for (int i = 0; i < n - 1; ++i) {       int a, b;       cin >> a >> b;       --a;       --b;       T[a].push_back(b);       T[b].push_back(a);     }     vector<bool> odw(n, false);     stack<int> S;     vector<double> odl(n);     odw[0] = true;     S.push(0);     odl[0] = 1;     double odp = 0.0;     while (!S.empty()) {       int akt = S.top();       S.pop();       odp += 1.0 / odl[akt];       for (int i = 0; i < T[akt].size(); ++i) {         if (!odw[T[akt][i]]) {           odw[T[akt][i]] = true;           S.push(T[akt][i]);           odl[T[akt][i]] = odl[akt] + 1;         }       }     }     cout.precision(10);     cout << odp;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     a = abs(a), b = abs(b);     if (a < b) swap(a, b);     return b ? gcd(b, a % b) : a;   }   long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   long long fast_pow(long long x, long long exp, long long mod) {     long long ret = 1;     while (exp) {       if (exp & 1) ret = (ret * x) % mod;       x = (x * x) % mod;       exp >>= 1;     }     return ret;   }   const int dx[] = {0, 0, -1, 1};   const int dy[] = {-1, 1, 0, 0};   const int inf = (int)1e9 + 5;   vector<vector<int> > adj;   vector<int> v;   priority_queue<int> q;   map<int, int> mp;   set<int> st;   long long x, y, z;   int32_t main(void) {     ios_base::sync_with_stdio(false), cin.tie(nullptr);     cin >> x >> y >> z;     if (x > y) swap(x, y);     cout << (x + y) / z <<    ;     x %= z;     y %= z;     if (x + y >= z)       cout << min(x - ((x + y) - z), y - ((x + y) - z));     else       cout << 0;     return 0;   }


#include <bits/stdc++.h>   const int MAX = 20;   const double PI = std::acos(-1.0);   struct comp {     double real, imag;     explicit comp(double real = 0, double imag = 0) : real(real), imag(imag) {}     comp operator+(const comp &c) const {       return comp(real + c.real, imag + c.imag);     }     comp operator-(const comp &c) const {       return comp(real - c.real, imag - c.imag);     }     comp operator*(const comp &c) const {       return comp(real * c.real - imag * c.imag, real * c.imag + imag * c.real);     }     comp operator*(const double &c) const { return comp(real * c, imag * c); }   };   comp w[2][1 << MAX];   void init() {     for (int i = 0; i < 1 << MAX; ++i) {       double angle = 1.0 * i / (1 << (MAX - 1)) * PI;       for (int type = -1; type <= 1; type += 2)         w[!~type][i] = comp(cos(angle), type * sin(angle));     }   }   void FFT(std::vector<comp> &a, int len, int type) {     for (int i = 1, j = 0; i < len - 1; ++i) {       for (int s = len; j ^= s >>= 1, ~j & s;)         ;       if (i < j) std::swap(a[i], a[j]);     }     for (int i = 2, d = 1; i <= len; i <<= 1, ++d)       for (int j = 0; j < len; j += i) {         auto u = a.begin() + j;         for (int k = 0; k < i / 2; ++k) {           comp s = u[k];           comp t = w[type][k << (MAX - d)] * u[k + i / 2];           u[k] = s + t, u[k + i / 2] = s - t;         }       }     if (type == 0) return;     double inv = 1.0 / len;     for (int i = 0; i < len; ++i) a[i] = a[i] * inv;   }   const int LEN = 1 << 18;   using ll = long long;   ll ans[LEN], tmp[LEN];   void solve(const std::vector<int> &a, const std::vector<int> &b, int coe,              int dir) {     std::vector<comp> a1(LEN), a2(LEN);     for (auto u : a) {       a1[u].real += 1;     }     for (auto u : b) {       a2[u].real += 1;     }     FFT(a1, LEN, 0);     FFT(a2, LEN, 0);     for (int i = 0; i < LEN; ++i) {       a1[i] = a1[i] * a2[i];     }     FFT(a1, LEN, 1);     memset(tmp, 0, sizeof(tmp));     if (dir == 0) {       for (int i = 1; i < LEN; ++i) {         tmp[i] = tmp[i - 1] + ll(std::round(a1[i - 1].real));       }     } else {       for (int i = LEN - 2; i >= 0; --i) {         tmp[i] = tmp[i + 1] + ll(std::round(a1[i].real));       }     }     for (int i = 0; i < LEN; ++i) {       ans[i] += coe * tmp[i];     }   }   int main() {     init();     int n, m;     int test;     scanf( %d%d%d , &n, &m, &test);     std::vector<int> a(n), b(m);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);     }     for (int i = 0; i < m; ++i) {       scanf( %d , &b[i]);     }     solve(a, b, 1, 1);     solve(a, b, -1, 0);     std::vector<int> mina(n - 1), minb(m - 1);     for (int i = 0; i < n - 1; ++i) {       mina[i] = std::min(a[i], a[i + 1]);     }     for (int i = 0; i < m - 1; ++i) {       minb[i] = std::min(b[i], b[i + 1]);     }     solve(mina, b, -1, 1);     solve(a, minb, -1, 1);     std::vector<int> maxa(n - 1), maxb(m - 1);     for (int i = 0; i < n - 1; ++i) {       maxa[i] = std::max(a[i], a[i + 1]);     }     for (int i = 0; i < m - 1; ++i) {       maxb[i] = std::max(b[i], b[i + 1]);     }     solve(maxa, b, 1, 0);     solve(a, maxb, 1, 0);     solve(mina, minb, 1, 1);     solve(maxa, maxb, -1, 0);     while (test--) {       int x;       scanf( %d , &x);       printf( %lld n , ans[x]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long a[n], b[n];     long long i;     for (i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(a, a + n);     long long count = 0;     for (i = 0; i < n; i++) {       if (a[i] != b[i]) {         count++;       }     }     if (count == 2 || count == 0) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   struct Arc {     int f, s, prev;   } arr[400005];   Arc nbr[400005];   Arc br[400005];   int beg[400005];   int kol = 0;   void add_arc(int f, int s) {     arr[kol].f = f;     arr[kol].s = s;     arr[kol].prev = beg[f];     beg[f] = kol++;     arr[kol].f = s;     arr[kol].s = f;     arr[kol].prev = beg[s];     beg[s] = kol++;   }   int pos[1 << 19];   int lev[1 << 19];   int llv[1 << 19];   int tin[1 << 19];   int tout[1 << 19];   int base[1 << 19];   int t = 0, ff = 0, q = 0;   void DFS(int v, int p = -1) {     tout[v] = tin[v] = ++t;     for (int i = beg[v]; i != -1; i = arr[i].prev) {       if (arr[i].s != p) {         if (!tin[arr[i].s]) {           DFS(arr[i].s, v);           if (tout[arr[i].s] <= tin[v]) {             tout[v] = min(tout[v], tout[arr[i].s]);             nbr[ff++] = arr[i];           } else {             br[q++] = arr[i];           }         } else {           tout[v] = min(tout[v], tout[arr[i].s]);         }       }     }   }   void DFS2(int v, int lv = 0, int p = -1) {     tin[v] = t;     llv[v] = lv;     lev[t] = lv;     pos[t++] = v;     for (int i = beg[v]; i != -1; i = arr[i].prev) {       if (arr[i].s != p) {         DFS2(arr[i].s, lv + 1, v);         lev[t] = lv;         pos[t++] = v;       }     }   }   int get_base(int v) {     if (base[v] == v) {       return v;     } else {       return base[v] = get_base(base[v]);     }   }   void merge_base(int a, int b) {     if (rand() & 1) {       base[get_base(a)] = get_base(b);     } else {       base[get_base(b)] = get_base(a);     }   }   void build_tree() {     for (int i = (1 << 18) - 1; i; --i) {       if (lev[i + i] < lev[i + i + 1]) {         lev[i] = lev[i + i];         pos[i] = pos[i + i];       } else {         lev[i] = lev[i + i + 1];         pos[i] = pos[i + i + 1];       }     }   }   int get_min(int l, int r) {     l = tin[l];     r = tin[r];     if (l > r) {       swap(l, r);     }     ++r;     int best = lev[l], bv = pos[l];     while (r - l > 1) {       if (!(l & 1)) {         if (lev[l + 1] < best) {           best = lev[l + 1];           bv = pos[l + 1];         }       }       if (r & 1) {         if (lev[r - 1] < best) {           best = lev[r - 1];           bv = pos[r - 1];         }       }       l >>= 1;       r >>= 1;     }     return bv;   }   int main() {     memset(beg, -1, sizeof beg);     int n, m, k;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; ++i) {       int f, s;       scanf( %d%d , &f, &s);       --f;       --s;       add_arc(f, s);     }     DFS(0);     for (int i = 0; i < n; ++i) {       base[i] = i;     }     for (int i = 0; i < ff; ++i) {       merge_base(nbr[i].s, nbr[i].f);     }     memset(beg, -1, sizeof beg);     memset(tin, -1, sizeof tin);     for (int i = 0; i < q; ++i) {       add_arc(get_base(br[i].f), get_base(br[i].s));     }     t = 1 << 18;     DFS2(get_base(0));     build_tree();     scanf( %d , &k);     for (int i = 0; i < k; ++i) {       int f, s;       scanf( %d%d , &f, &s);       --f;       --s;       f = get_base(f);       s = get_base(s);       int ret = llv[f] + llv[s] - 2 * llv[get_min(f, s)];       printf( %d n , ret);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   map<long long, long long> f;   int main() {     int q;     scanf( %d , &q);     while (q--) {       long long u, v;       int t, w;       scanf( %d %lld %lld , &t, &u, &v);       if (t == 1) {         scanf( %d , &w);         while (u != v) {           if (u < v) swap(u, v);           f[u] += w;           u >>= 1;         };       } else {         long long ans = 0;         while (u != v) {           if (u < v) swap(u, v);           ans += f[u];           u >>= 1;         };         cout << ans << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 7;   int n, a[N], cnt[N], lim = 0, mx = 0, fa[N];   long long ans = 0;   inline int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }   inline void merge(int u, int v, long long w) {     if (cnt[u] && cnt[v]) {       u = find(u), v = find(v);       if (u != v) {         ans += 1ll * w * (cnt[v] + cnt[u] - 1);         fa[u] = v;         cnt[v] = 1;       }     }   }   int main() {     scanf( %d , &n);     cnt[0] = 1;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       cnt[a[i]]++;       mx = max(mx, a[i]);       ans -= a[i];     }     lim = 1 << 32 - __builtin_clz(mx);     for (int i = 0; i <= lim - 1; i++) fa[i] = i;     for (int i = lim - 1; ~i; i--) {       for (int j = i; j; j = (j - 1) & i) {         if (cnt[j] && cnt[i ^ j]) merge(j, i ^ j, i);       }       merge(i, 0, i);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct vac {     int l, r, cost, duration;     vac() : cost(-1) {}     vac(int l, int r, int cost) : l(l), r(r), cost(cost), duration(r - l + 1) {}   };   vector<vector<vac> > lifes(200001, vector<vac>(0)),       deaths(200001, vector<vac>(0));   vector<vac> cheapest(200001);   int min1(int x, int y) {     if (x == -1) return y;     if (y == -1) return x;     return min(x, y);   }   int main() {     int n, x;     cin >> n >> x;     int minAns = -1;     for (int i = 0; i < n; i++) {       int l, r, cost;       cin >> l >> r >> cost;       lifes[l].push_back(vac(l, r, cost));       deaths[r].push_back(vac(l, r, cost));     }     for (int i = 0; i < lifes.size(); i++) {       for (int j = 0; j < lifes[i].size(); j++) {         int d = lifes[i][j].duration;         if (d > x) continue;         if (cheapest[x - d].cost != -1)           minAns = min1(minAns, cheapest[x - d].cost + lifes[i][j].cost);       }       for (int j = 0; j < deaths[i].size(); j++) {         int d = deaths[i][j].duration;         cheapest[d].cost = min1(cheapest[d].cost, deaths[i][j].cost);       }     }     cout << minAns << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> arr(n);     for (auto &i : arr) cin >> i;     int maxx = 0;     for (auto i : arr) maxx = max(maxx, i);     cout << (maxx xor arr.back());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N, i, j, p = 0, q = 0, ans = 0;     cin >> N;     for (i = 0; i < N; i++) {       cin >> j;       if (q < j)         p++;       else         p = 1;       q = j;       ans = max(ans, p);     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10, InfI = INT_MAX, Mod = 998244353;   const long long InfL = LONG_LONG_MAX;   int n, m, sqn;   vector<int> adj[N];   vector<int> ind;   bool vis[N] = {}, indpen[N] = {};   int ent[N], par[N], back_edge[N], back_min[N];   int dfstimer = 0, idma = 1;   void dfs(int x) {     vis[x] = 1;     ent[x] = dfstimer++;     int back_edg = 0, back_mi = x;     bool pen = 1;     for (int v : adj[x]) {       if (!vis[v]) {         par[v] = x;         dfs(v);       } else if (ent[v] < ent[x]) {         back_edg++;         back_mi = (ent[v] < ent[back_mi]) ? v : back_mi;       }       if (indpen[v]) pen = 0;     }     back_edge[x] = back_edg;     back_min[x] = back_mi;     idma = (back_edg > back_edge[idma]) ? x : idma;     if (back_edg < sqn - 1 && pen) {       ind.push_back(x);       indpen[x] = 1;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     sqn = ceil(sqrt(1.0 * n));     for (int i = 1; i <= m; i++) {       int a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     back_edge[1] = 0;     dfs(1);     if (back_edge[idma] >= sqn - 1) {       cout << 2 << endl;       vector<int> path;       int j = idma;       path.push_back(j);       while (j != back_min[idma]) {         j = par[j];         path.push_back(j);       }       cout << path.size() << endl;       for (int i : path) cout << i <<    ;       return 0;     }     cout << 1 << endl;     for (int i = 0; i < sqn; i++) cout << ind[i] <<    ;   }


#include <bits/stdc++.h>   const double eps = 1e-9;   const int int_inf = 2000000000;   const long long i64_inf = 1000000000000000000LL;   const double pi = acos(-1.0);   using namespace std;   int wa[1000010];   int wb[1000010];   int a[1000100];   int b[1000100];   int la, lb;   int res = 0;   int main() {     memset(wa, -1, sizeof(wa));     memset(wb, -1, sizeof(wb));     cin >> la >> lb;     for (int i = 0; i < (int)la; i++) scanf( %d , &a[i]), wa[a[i]] = i;     for (int i = 0; i < (int)lb; i++) scanf( %d , &b[i]), wb[b[i]] = i;     int first = wb[a[0]], last = first, len = 1;     if (first != -1) {       for (int i = 1; i < (int)la; i++) {         if (wb[a[i]] == -1) break;         if (first <= last)           if (wb[a[i]] > last || wb[a[i]] < first) {             last = wb[a[i]];             len++;             continue;           } else             break;         if (wb[a[i]] > last && wb[a[i]] < first) {           last = wb[a[i]];           len++;           continue;         } else           break;       }     } else       len = 0;     res = max(res, len);     for (int i = 1; i < (int)la; i++) {       if (len == 0) {         if (wb[a[i]] == -1) continue;         first = last = wb[a[i]];         len = 1;       } else {         len--;         first = wb[a[i]];         if (first == -1) {           len = 0;           continue;         }       }       int j = (i + len) % la;       while (j != i) {         if (wb[a[j]] == -1) break;         if (first <= last)           if (wb[a[j]] > last || wb[a[j]] < first) {             last = wb[a[j]];             len++;             j = (j + 1) % la;             continue;           } else             break;         if (wb[a[j]] > last && wb[a[j]] < first) {           last = wb[a[j]];           len++;           j = (j + 1) % la;           continue;         } else           break;       }       res = max(res, len);     }     cout << res << endl;     return 0;   }