#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using ui = unsigned int;   using pii = pair<int, int>;   using pll = pair<int, int>;   struct fast_ios {     fast_ios() {       ios::sync_with_stdio(false);       cin.tie(NULL);     }   } fast_ios_;   ll u, v, a;   int solve() {     cin >> u >> v;     if (u > v || (v - u) & 1) return puts( -1 ), 0;     if (u + v == 0) return puts( 0 ), 0;     if (u == v) return printf( 1 n%lld n , u), 0;     a = (v - u) / 2;     if (u & a) return printf( 3 n%lld %lld %lld n , u, a, a), 0;     return printf( 2 n%lld %lld n , u + a, a), 0;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t, n, m, u, v, q, k;   const int N = 3e5 + 500;   const int LN = 20;   const int SN = 331;   const long long mod = 1e9 + 7;   const long long INF = 1LL << 57;   long long arr[N], brr[N];   string str, ss;   vector<int> adj[N];   vector<int> idx[N];   int d[N];   int actuald[N];   bool can[N];   bool vis[N];   void dfs(int v, int p) {     if (d[v] == -1) d[v] = 0;     vis[v] = true;     for (int i = 0; i < adj[v].size(); ++i) {       int u = adj[v][i];       if (u == p || vis[u]) continue;       dfs(u, v);       if (actuald[u] != d[u]) {         can[idx[v][i]] = true;         actuald[v]++;         actuald[u]++;         actuald[v] %= 2;         actuald[u] %= 2;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     int has = -1, sum = 0;     for (int i = 1; i <= n; ++i) {       cin >> d[i];       if (d[i] == -1)         has = i;       else         sum += d[i];     }     for (int i = 1; i <= m; ++i) {       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);       idx[u].push_back(i);       idx[v].push_back(i);     }     if (sum % 2 == 1 && has == -1) {       cout << -1 <<   n ;       return 0;     }     if (sum % 2 == 1) d[has] = 1;     dfs(1, 0);     sum = 0;     for (int i = 1; i <= m; ++i) {       sum += can[i];     }     cout << sum <<   n ;     for (int i = 1; i <= m; ++i) {       if (can[i]) cout << i <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2000200;   bool Ch(int Ans);   int n, k;   int a[N];   int c[N];   int p[N];   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) scanf( %d , a + i), c[a[i]]++;     for (int i = 1; i < N; i++) p[i] = c[i] + p[i - 1];     sort(a + 1, a + n + 1);     for (int Ans = a[1]; Ans >= 1; Ans--)       if (Ch(Ans)) return cout << Ans, 0;     assert(0);   }   bool Ch(int Ans) {     if (Ans <= k + 1) return true;     for (int j = Ans + Ans; j <= N; j += Ans)       if (p[j - 1] - p[j - Ans + k]) return false;     return true;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v;   int n, m;   int f() {     int ans = 0;     for (int i = 0; i < n; i++) {       int a = 10;       for (int j = i; j < n; j++) {         for (int k = i; k <= j; k++) a = min(a, v[k]);         ans += a;       }     }     return ans;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       v.push_back(i);     }     sort(v.begin(), v.end());     int maxx = 0;     do {       maxx = max(maxx, f());     } while (next_permutation(v.begin(), v.end()));     int k = 0;     sort(v.begin(), v.end());     int c = 0;     do {       if (f() == maxx) c++;       if (c == m) {         for (auto i : v) cout << i <<    ;         break;       }     } while (next_permutation(v.begin(), v.end()));     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long powmod(long long a, long long b, long long p) {     if (b == 0) return 1;     if (b == 1) return a;     long long temp = powmod(a, b / 2, p);     temp *= temp;     temp %= p;     if (b % 2 == 0) return temp;     temp = temp * a;     temp %= p;     return temp;   }   void solve() {     int n, x, y, d;     cin >> n >> x >> y >> d;     if (abs(x - y) % d == 0) {       cout << abs(x - y) / d << endl;       ;       return;     }     long long ans = 1e18;     if (abs(y - 1) % d == 0) {       ans = (y - 1) / d;       ans += (x - 1 + d - 1) / d;     }     if ((n - y) % d == 0) {       long long ans2 = (n - y) / d;       ans2 += (n - x + d - 1) / d;       ans = min(ans, ans2);     }     if (ans > 1e10)       cout << -1 << endl;     else       cout << ans << endl;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long pw(long long x, long long p) {     if (p == 0) return 1;     long long t = pw(x, p / 2);     if (p % 2 == 0)       return (t * t) % 1000000007;     else       return (((t * t) % 1000000007) * x) % 1000000007;   }   const long long NN = 500007;   long long parent[NN], sizee[NN];   void make_set(long long v) {     parent[v] = v;     sizee[v] = 1;   }   long long find_set(long long v) {     if (v == parent[v]) return v;     return parent[v] = find_set(parent[v]);   }   void union_sets(long long a, long long b) {     a = find_set(a);     b = find_set(b);     if (a != b) {       if (sizee[a] < sizee[b]) swap(a, b);       parent[b] = a;       sizee[a] += sizee[b];     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     map<long long, long long> m;     long long i, n, M;     long long k;     cin >> n >> M >> k;     long long a[n + 1];     for (i = 1; i <= n; i++) cin >> a[i];     long long x, y, cur = 0, virus, pos;     vector<pair<long long, long long> > edges[M + 1];     while (M--) {       cin >> x >> y;       virus = a[x] ^ a[y];       if (m.find(virus) == m.end()) {         m.insert({virus, cur});         cur++;       }       pos = m.find(virus)->second;       edges[pos].push_back({x, y});     }     long long siz, comp;     long long unsafe = 0, temp;     for (i = 0; i < cur; i++) {       set<long long> SS;       for (auto &x : edges[i]) {         make_set(x.first), make_set(x.second);         SS.insert(x.first), SS.insert(x.second);       }       siz = SS.size();       comp = siz;       for (auto &x : edges[i]) {         if (find_set(x.first) != find_set(x.second))           comp--, union_sets(x.first, x.second);       }       temp = (pw(2, siz) - pw(2, comp) + 1000000007) % 1000000007;       unsafe = (unsafe + (temp * pw(2, n - siz)) % 1000000007) % 1000000007;     }     cout << ((pw(2, k) * pw(2, n)) % 1000000007 - unsafe + 1000000007) %                 1000000007          << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long f, n;     long double a, b, ans;     while (cin >> a >> b >> n) {       long flag = 0, i, j;       for (i = -1000; i <= 1000; i++) {         ans = 1;         f = 0;         for (j = 0; j < n; j++) {           ans *= i;           if (abs(ans) > 1000) {             f = 1;             break;           }         }         if (!f)           if (a * ans == b) {             flag = 1;             break;           }       }       if (flag)         cout << i << endl;       else         cout <<  No solution n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> x(n);     for (int i = 0; i < n; i++) cin >> x[i];     vector<int> ans(n + 1);     for (int i = 0; i < n; i++) {       int dominant = 0;       vector<int> m(n + 1);       for (int j = i; j < n; j++) {         m[x[j]]++;         if (m[x[j]] > m[dominant] or (m[x[j]] == m[dominant] and x[j] < dominant))           dominant = x[j];         ans[dominant]++;       }     }     for (int i = 1; i < n + 1; i++) cout << ans[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long nax = 105;   long long a[nax];   signed main() {     long long n, cnt0 = 0, cnt1 = 0;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] == 0)         cnt0++;       else         cnt1++;     }     if (cnt0 == n) {       cout << 0 << endl;       return 0;     } else if (cnt1 == n) {       cout << 1 << endl;       return 0;     }     long long idx = 0;     long long pdt = 1;     for (long long i = 1; i <= n; i++) {       if (a[i] == 1) {         if (idx == 0)           idx = i;         else {           long long temp = idx;           pdt *= i - temp;           idx = i;         }       }     }     cout << pdt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int y[50010] = {};   int t[50010] = {};   unordered_map<int, int> ha;   bool cmp(int x, int y) { return x > y; }   bool ff(int x) {     ha.clear();     for (int i = 1; i <= n; i++) y[i] = t[i];     for (int i = 1; i <= n; i++) {       if (y[i] <= x && ha[y[i]] == 0) {         ha[y[i]] = 1;       } else {         while (1) {           if (y[i] == 1) {             return 0;           }           if (ha.find(y[i] / 2) == ha.end() && (y[i] / 2) <= x) {             ha[y[i] / 2] = 1;             break;           } else             y[i] = y[i] / 2;         }       }     }     return 1;   }   void ans(int x) {     ha.clear();     for (int i = 1; i <= n; i++) y[i] = t[i];     for (int i = 1; i <= n; i++) {       if (y[i] <= x && ha[y[i]] == 0) {         ha[y[i]] = 1;         printf( %d  , y[i]);       } else {         while (1) {           if (ha.find(y[i] / 2) == ha.end() && (y[i] / 2) <= x) {             ha[y[i] / 2] = 1;             break;           } else             y[i] = y[i] / 2;         }         printf( %d  , y[i] / 2);       }     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &t[i]);     sort(t + 1, t + n + 1, cmp);     int l = 1;     int r = 1000000000;     while (l < r) {       int mid = (l + r) / 2;       if (ff(mid))         r = mid;       else         l = mid + 1;     }     ans(l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       int m;       cin >> n >> m;       int arr[n];       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       map<int, int> freq;       freq.clear();       for (int i = 0; i < m; i++) {         int curr;         cin >> curr;         freq[curr]++;       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++)           if (arr[j] > arr[j + 1] && freq[j + 1]) {             swap(arr[j], arr[j + 1]);           }       }       bool possible = true;       for (int i = 0; i < n - 1; i++) {         if (arr[i] > arr[i + 1]) {           possible = false;           break;         }       }       if (possible) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void maloosh_lazma() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int main() {     maloosh_lazma();     int n, k;     cin >> n >> k;     string s;     cin >> s;     int l, ll;     char q, qq;     for (int i = 0; i < k; i++) {       cin >> l >> ll >> q >> qq;       --l, --ll;       for (int j = l; j <= ll; j++) {         if (s[j] == q) s[j] = qq;       }     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     ;     int beauty[n];     for (int asdf = 0; asdf < n; asdf++) {       cin >> beauty[asdf];     };     map<int, long long int> occ;     long long int most = 0;     for (int i = 0; i < n; i++) {       int x = i - beauty[i];       if (!occ.count(x)) occ[x] = 0LL;       occ[x] = occ[x] + beauty[i];       if (occ[x] > most) most = occ[x];     }     cout << most;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const double PI = 3.1415926535897932384626433832795;   unsigned long long mod = 1000 * 1000 * 1000 + 7;   int INF = 1000 * 1000 * 1000;   vector<int> v;   class node {    public:     node() {       left = right = NULL;       addVal = 0;     }     int from, to;     int minVal, minPos, addVal;     node *left, *right;     void build(int i, int j) {       from = i;       to = j;       if (i == j) {         minVal = v[i];         minPos = i;       } else {         int mid = (i + j) / 2;         if (i <= mid) {           left = new node();           left->build(i, mid);         }         if (mid + 1 <= j) {           right = new node();           right->build(mid + 1, j);         }         if (left->minVal < right->minVal) {           minVal = left->minVal;           minPos = left->minPos;         } else {           minVal = right->minVal;           minPos = right->minPos;         }       }     }     pair<int, int> getMin(int i, int j) {       if (i <= from && to <= j) return make_pair(minVal + addVal, minPos);       if (i > to || j < from) return make_pair(INF, -1);       pair<int, int> r1 = left->getMin(i, j);       pair<int, int> r2 = right->getMin(i, j);       r1.first += addVal;       r2.first += addVal;       return min(r1, r2);     }     void add(int i, int j, int val) {       if (i <= from && to <= j) {         addVal += val;         return;       }       if (i > to || j < from) return;       left->add(i, j, val);       right->add(i, j, val);       return;     }   } * root;   int main() {     int n;     cin >> n;     v.resize(n);     for (int i = 0; i < n; i++) cin >> v[i];     root = new node();     root->build(0, n - 1);     queue<pair<int, int> > q;     q.push(make_pair(0, n - 1));     vector<pair<int, int> > res;     while (!q.empty()) {       pair<int, int> top = q.front();       q.pop();       pair<int, int> r = root->getMin(top.first, top.second);       for (int i = 0; i < r.first; i++)         res.push_back(make_pair(top.first, top.second));       root->add(top.first, top.second, -r.first);       if (top.first <= r.second - 1) q.push(make_pair(top.first, r.second - 1));       if (r.second + 1 <= top.second) q.push(make_pair(r.second + 1, top.second));     }     cout << res.size() << endl;     for (int i = 0; i < res.size(); i++)       cout << res[i].first + 1 <<     << res[i].second + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long t;     cin >> t;     while (t--) {       long long n, a, b;       cin >> n >> a >> b;       string s;       cin >> s;       for (long long i = 1; i < s.length() - 1; i++) {         if (s[i] ==  0 ) {           if (s[i + 1] ==  1  && s[i - 1] ==  1 ) s[i] =  1 ;         }       }       long long c = -1;       long long ans = 0;       vector<long long> v;       for (long long i = 0; i < s.length(); i++) {         char ch = s[i];         long long d = 0;         while (s[i] == ch && i < s.length()) {           i++;           d++;         }         i--;         ans += d * a;         if (ch ==  0 )           ans += (d + 1) * b;         else           ans += (d + 1) * 2 * b;         if (ch ==  0 ) v.push_back(d);         c++;       }       ans += c * (a - b);       long long p = v.size();       if (p > 2) {         for (long long i = 1; i < p - 1; i++) {           if (2 * a > b * (v[i] - 1)) {             ans -= 2 * a;             ans += b * (v[i] - 1);           }         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   vector<int> P;   vector<int> vis;   vector<vector<int> > C;   vector<int> lab, sz;   void getCycle() {     vis = vector<int>(N, 0);     lab = vector<int>(N, 0);     for (int i = 0; i < N; i++) {       if (vis[i]) continue;       C.push_back(vector<int>());       sz.push_back(0);       int u = i;       while (!vis[u]) {         vis[u] = 1;         lab[u] = C.size() - 1;         C.back().push_back(u);         sz.back()++;         u = P[u];       }     }   }   vector<int> tmp;   void mrg() {     printf( 1  );     for (int i = 1; i < N; i++) {       if (lab[i] != lab[0]) {         printf( %d  , i + 1);         tmp.clear();         tmp.push_back(0);         for (int j = 1; j < C[lab[i]].size(); j++) {           tmp.push_back(C[lab[i]][j]);         }         tmp.push_back(i);         for (int j = 1; j < C[lab[0]].size(); j++) {           tmp.push_back(C[lab[0]][j]);         }         C[lab[i]].clear();         for (int j = 0; j < tmp.size(); j++) {           lab[tmp[j]] = lab[0];         }         C[lab[0]] = tmp;         return;       }     }   }   void split() {     for (int i = 0; i < N; i++) {       if (sz[lab[i]] > 1) {         printf( %d  , i + 1);         int idx = 1;         for (int j = 1; j < C[lab[i]].size(); j++) {           if (C[lab[i]][idx] > C[lab[i]][j]) {             idx = j;           }         }         printf( %d  , C[lab[i]][idx] + 1);         tmp.clear();         tmp.push_back(C[lab[i]][idx]);         for (int j = 1; j < idx; j++) {           tmp.push_back(C[lab[i]][j]);         }         C.push_back(tmp);         sz.push_back(tmp.size());         for (int j = 0; j < tmp.size(); j++) lab[tmp[j]] = C.size() - 1;         tmp.clear();         for (int j = 0; j < C[lab[i]].size(); j++) {           if (lab[C[lab[i]][j]] == lab[i]) {             tmp.push_back(C[lab[i]][j]);           }         }         C[lab[i]] = tmp;         sz[lab[i]] = tmp.size();         return;       }     }   }   int main() {     scanf( %d , &N);     P.resize(N);     for (int i = 0; i < N; i++) {       scanf( %d , &P[i]);       P[i]--;     }     getCycle();     scanf( %d , &M);     M = N - M;     if (C.size() < M) {       printf( %d n , M - C.size());       for (int i = C.size(); i < M; i++) split();     } else {       printf( %d n , C.size() - M);       for (int i = C.size(); i > M; i--) mrg();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string p;     cin >> p;     bool yon;     for (int i = 0; i < p.length(); i++) {       if (p[i] ==  H  || p[i] ==  Q  || p[i] ==  9 ) {         yon = true;         break;       } else         yon = false;     }     if (yon)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   int mod = 1e6 + 3;   string mm(char c) {     if (c ==  > ) return  1000 ;     if (c ==  < ) return  1001 ;     if (c ==  + ) return  1010 ;     if (c ==  - ) return  1011 ;     if (c ==  . ) return  1100 ;     if (c ==  , ) return  1101 ;     if (c ==  [ ) return  1110 ;     if (c ==  ] ) return  1111 ;   }   long long pow2(long long a, long long b, long long c = 0) {     c = mod;     long long res = 1;     a %= c;     while (b) {       if (b & 1) res = (res * a) % c;       a = (a * a) % c;       b >>= 1;     }     return res;   }   int main() {     string tmp;     cin >> tmp;     string ans =   ;     for (auto &i : tmp) {       ans += mm(i);     }     int sz = ans.length();     int cnt = 0;     long long res = 0;     for (int i = sz - 1; i >= 0; i--) {       if (ans[i] ==  1 ) {         res += pow2(2, cnt);         res %= mod;       }       cnt++;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   class Sieve {    public:     vector<T> primes;     vector<bool> is_prime;     Sieve(int MAX = 1000000) {       is_prime.resize(MAX + 1, true);       is_prime[0] = is_prime[1] = false;       for (long long int i = 2; i * i <= MAX; i++)         if (is_prime[i])           for (long long int j = i * i; j <= MAX; j += i) is_prime[j] = false;       for (long long int i = 2; i <= MAX; i++)         if (is_prime[i]) primes.push_back(i);     }   };   template <typename T>   vector<vector<T>> matmul(const vector<vector<T>>& a,                            const vector<vector<T>>& b) {     int n = a.size(), m = b[0].size(), k = b.size();     vector<vector<T>> c(n, vector<T>(m));     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         for (int l = 0; l < k; l++) c[i][j] += (a[i][k] * b[k][j]);       }     }     return c;   }   template <typename T>   T extended_euclid(T a, T b, vector<T>& X) {     if (b == 0) {       X = {1, 0};       return a;     } else {       T g = extended_euclid(b, a % b, X);       vector<vector<T>> G = {{0LL, 1LL}, {1LL, -(a / b)}};       X = matmul<T>(G, X);       return g;     }   }   template <typename T>   bool isPrime(T n) {     if (n <= 1)       return false;     else if (n == 2 || n == 3)       return true;     else if (n % 2 == 0 || n % 3 == 0)       return false;     T x = 5;     T p = 2;     while (x * x <= n) {       if (n % x == 0) return true;       x += p;       p = 6 - p;     }     return true;   }   long long int binpow(long long int x, long long int n,                        long long int mod = 1000000007) {     long long int ans = 1;     x = x % mod;     while (n >= 1) {       if (n & 1) ans = (ans * x) % mod;       x = (x * x) % mod;       n >>= 1;     }     return ans;   }   long long int gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   template <typename T>   class Graph {    public:     int n;     vector<vector<T>> adj;     bool directed;     Graph(int n, bool directed = false) {       this->n = n;       adj.resize(n + 1);       this->directed = directed;     }     void add_edge(int u, int v) {       adj[u].push_back(v);       if (!directed) adj[v].push_back(u);     }     void add_edge(int u, int v, int w) {       adj[u].push_back({v, w});       if (!directed) adj[v].push_back({u, w});     }   };   class DisjointSets {    public:     int n;     vector<int> parent;     vector<int> rank;     vector<int> sz;     DisjointSets(int n, bool Rank = true) {       this->n = n;       parent.resize(n + 1, 0);       (Rank ? rank.resize(n + 1, 1) : sz.resize(n + 1, 1));     }     int find(int i) {       if (i != parent[i]) parent[i] = find(parent[i]);       return parent[i];     }     void UnionByRank(int i, int j) {       i = find(i);       j = find(j);       if (i == j) return;       if (rank[i] < rank[j]) swap(i, j);       parent[j] = i;       rank[i] += rank[j];     }     void UnionBySize(int i, int j) {       i = find(i);       j = find(j);       if (i == j) return;       if (sz[i] < sz[j]) swap(i, j);       parent[j] = i;       sz[i] += sz[j];     }   };   template <typename T>   class SegmentTree {    public:     vector<T> t;     int n, H;     void init(int n) {       this->n = n;       t.resize(2 * n);       this->H = sizeof(int) * 8 - __builtin_clz(n);     }     void build() {       for (int i = n - 1; i > 0; i--) t[i] = t[i << 1] + t[(i << 1) | 1];     }     void update(int pos, T val) {       for (t[pos += n] += val; pos > 1; pos >>= 1)         t[pos >> 1] = t[pos] + t[pos ^ 1];     }     T query(int l, int r) {       T res = 0;       for (l += n, r += n; l < r; l >>= 1, r >>= 1) {         if (l & 1) res += t[l++];         if (r & 1) res += t[--r];       }       return res;     }   };   bool isSubsequenceString(string x, string y) {     int i = 0, j = 0;     while (i < x.length() && j < y.length()) x[i] == y[j] ? i++, j++ : i++;     return (j == y.length());   }   int max(int a, int b, int c, int d) { return max(a, max(b, max(c, d))); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     vector<int> a(n), b(n);     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     int tx = 0, ty = 0;     for (int i = 0; i < n; i++) {       if (a[i] == 1 && b[i] == 0)         tx++;       else if (a[i] == 0 && b[i] == 1)         ty++;     }     if (tx > ty)       cout << 1 <<   n ;     else if (tx == 0)       cout <<  -1 n ;     else {       int dif = (ty + 1);       cout << ceil((double)dif / tx);     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using vl = vector<ll>;   using pll = pair<ll, ll>;   using vll = vector<pll>;   using MAP = map<ll, ll>;   using sl = set<ll>;   using sll = set<pll>;   using MAPs = map<ll, sl>;   using MAPv = map<ll, vl>;   const ll inf = LLONG_MAX;   const ll mod = 1e9 + 7;   const ll N = 2e5 + 5;   int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};   int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};   int n, a[N];   void MAIN() {     cin >> n;     vector<int> v;     for (int i = 0; i < n; i++) cin >> a[i], v.push_back(a[i]);     sort((v).begin(), (v).end());     int ind1 = 0, ind2 = 0, cnt = 0;     for (int i = 0; i < n; i++) {       if (a[i] != v[i]) {         cnt++;         if (!ind1)           ind1 = i;         else           ind2 = i;       }     }     if (cnt > 2) {       cout <<  NO n ;       return;     }     swap(a[ind1], a[ind2]);     for (int i = 0; i < n - 1; i++) {       if (a[i] > a[i + 1]) {         cout <<  NO n ;         return;       }     }     cout <<  YES n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t = 1;     while (t-- > 0) {       MAIN();     }   }


#include <bits/stdc++.h>   using namespace std;   int n, d[128][128][8];   string s;   int main() {     ios::sync_with_stdio(0);     cin >> n >> s;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         for (int k = 0; k <= 4; k++) {           if (s[i - 1] ==  . ) continue;           if (!k) {             d[i][j][k] = 1;             continue;           }           if (i >= j) d[i][j][k] |= d[i - j][j][k - 1];           if (k == 4 && d[i][j][k]) {             cout <<  yes  << endl;             return 0;           }         }     cout <<  no  << endl;   }


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


#include <bits/stdc++.h>      using ll=long long;   #define MOD 1000000007      using namespace std;      void calc(double c, double m, double p, double v, double *exp, double prob, int n, int x){       if(x==1){           prob *= p;           *exp += prob*n;           return;       }       else if(x>1){           double prob1 = prob;           prob1 *= p;           *exp += prob1*n;           if(c>0){               double prob2 = prob;               prob2 *= c;               if(c-v>1e-7){                   calc(c-v, ((m==0)?(0):(m+(v/2))), ((m==0)?(p+v):(p+(v/2))), v, exp, prob2, n+1, x);               }               else{                   calc(0, ((m==0)?(0):(m+(c/2))), ((m==0)?(p+c):(p+(c/2))), v, exp, prob2, n+1, x-1);               }           }           if(m>0){               double prob3 = prob;               prob3 *= m;               if(m-v>1e-7){                   calc(((c==0)?(0):(c+(v/2))), m-v, ((c==0)?(p+v):(p+(v/2))), v, exp, prob3, n+1, x);               }               else{                   calc(((c==0)?(0):(c+(m/2))), 0, ((c==0)?(p+m):(p+(m/2))), v, exp, prob3, n+1, x-1);               }           }           return;       }       else return;   }      void solve() {       // Write your solution here       double c, m, p, v;       cin>>c>>m>>p>>v;       double exp = 0.0;       int n = 1;       int x=3;       calc(c, m, p, v, &exp, 1, 1, x);       cout<<setprecision(10)<<exp<<  n ;       return ;   }      int main() {       cin.tie(nullptr)->sync_with_stdio(false);          int t = 1;       cin >> t;  // Comment out if single test case       while (t--) {           solve();       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m;   long long sum = 0;   int main() {     scanf( %lld%lld , &n, &m);     long long max_add = (n - 1) * n / 2;     long long min_add;     if (n % 2) min_add = (n / 2 + 1) * (n / 2);     if (n % 2 == 0) {       long long a1 = (n / 2 + 1) * (n / 2) / 2;       long long a2 = (n / 2 - 1) * (n / 2) / 2;       min_add = a1 + a2;     }     for (int i = 1; i <= m; i++) {       long long x, d;       scanf( %lld%lld , &x, &d);       sum += x * n;       if (d >= 0)         sum += (long long)d * max_add;       else         sum += (long long)d * min_add;     }     double ans = sum / 1.0;     ans = ans / n;     printf( %.15lf , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4010;   long long O_O[N][N];   const long long mod = 1e9 + 7;   int main() {     int o_o;     memset(O_O, 0, sizeof(O_O));     O_O[0][0] = 1;     for (int i = 1; i <= 4000; ++i) {       if (i < 4000)         o_o = i;       else         o_o = 4000;       for (int j = 1; j <= o_o; ++j) {         O_O[i][j] =             ((long long)j * O_O[i - 1][j] % mod + O_O[i - 1][j - 1]) % mod;       }     }     int n;     cin >> n;     long long ans = 0;     for (int i = 1; i <= n; i++) {       ans = (ans + (O_O[n][i] * i) % mod) % mod;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 17;   int n, m, x, y, z, inf;   int bin[N], d[N][N], du[N], f[1 << N], q[N];   int main() {     for (register int i = 1; i <= 16; ++i) bin[i] = 1 << (i - 1);     int sum = 0;     scanf( %d , &n);     scanf( %d , &m);     memset(d, 60, sizeof(d));     inf = d[0][0];     for (register int i = 1; i <= m; ++i) {       scanf( %d%d%d , &x, &y, &z);       sum += z;       du[x]++;       du[y]++;       d[x][y] = d[y][x] = min(d[x][y], z);     }     for (register int k = 1; k <= n; ++k)       for (register int i = 1; i <= n; ++i)         for (register int j = 1; j <= n; ++j)           d[i][j] = min(d[i][j], d[i][k] + d[k][j]);     for (register int i = 2; i <= n; ++i)       if (du[i] && d[1][i] == inf) {         puts( -1 );         return 0;       }     int tot = 0;     for (register int i = 1; i <= n; ++i)       if (du[i] & 1) q[++tot] = i;     int max_statue = bin[tot + 1] - 1;     memset(f, 60, sizeof(f));     f[0] = 0;     for (register int p = 0; p < max_statue; ++p) {       for (register int i = 1; i <= tot; ++i)         if (!(bin[i] & p)) {           for (register int j = i + 1; j <= tot; ++j)             if (!(bin[j] & p))               f[p | bin[i] | bin[j]] =                   min(f[p | bin[i] | bin[j]], f[p] + d[q[i]][q[j]]);           break;         }     }     sum += f[max_statue];     printf( %d n , sum);     return 0;   }


#include <bits/stdc++.h>   long long mod = 1000000007;   using namespace std;   int n, m;   long long b;   struct node {     int money, monitors, pre;     vector<int> G;   } a[202];   bool cmp(node x, node y) { return x.monitors > y.monitors; }   long long dp[2][1 << 20];   int setbit(int x, int pos) { return x | (1 << pos); }   bool checkbit(int x, int pos) { return x & (1 << pos); }   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   int has[25];   int main() {     int i, j, fl, test, index, mask, cnt = 0;     scanf( %d%d%lld , &n, &m, &b);     for (i = 0; i < n; i++) {       scanf( %d%d%d , &a[i].money, &a[i].monitors, &j);       while (j--) {         scanf( %d , &fl);         fl--;         a[i].pre = setbit(a[i].pre, fl);         a[i].G.push_back(fl);         if (has[fl] == 0) {           cnt++;           has[fl] = 1;         }       }     }     if (cnt < m) {       printf( -1 n );       return 0;     }     sort(a, a + n, cmp);     int tmask, touse;     for (index = n; index >= 0; index--) {       for (mask = 0; mask < (1 << m); mask++) {         touse = index % 2;         if (mask == (1 << m) - 1) {           dp[touse][mask] = 0ll;           continue;         }         if (index == n) {           dp[touse][mask] = -2;           continue;         }         int i;         long long op1, op2 = a[index].money, op3;         op1 = dp[(touse + 1) % 2][mask];         if (mask == 0) op2 += a[index].monitors * b;         tmask = mask;         tmask = tmask | a[index].pre;         op3 = dp[(touse + 1) % 2][tmask];         if (op1 == -2 && op3 == -2)           dp[touse][mask] = -2;         else if (op1 != -2 && op3 != -2)           dp[touse][mask] = min(op1, op2 + op3);         else if (op1 == -2)           dp[touse][mask] = op2 + op3;         else           dp[touse][mask] = op1;       }     }     long long ans = dp[0][0];     if (ans == -2)       printf( -1 n );     else       printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Number {     array<int, 4> x = {{0, 0, 0, 0}};     Number() {}     Number(int a) {       if (a != -1) x[a]++;     }     long double log_value() const {       if (x[0] > 0) return -INFINITY;       return x[2] * log(2L) + x[3] * log(3L);     }     int mod() const {       long long result = 1;       for (int i = 0; i < 4; i++)         for (int j = 0; j < x[i]; j++) result = (result * i) % (int)(1e9 + 7);       return result;     }     bool is_zero() const { return x[0] > 0; }   };   bool operator<(const Number& a, const Number& b) {     return a.log_value() < b.log_value();   }   Number operator*(const Number& a, const Number& b) {     Number result;     for (int i = 0; i < 4; i++) result.x[i] = a.x[i] + b.x[i];     return result;   }   Number operator/(const Number& a, const Number& b) {     Number result;     for (int i = 0; i < 4; i++) result.x[i] = a.x[i] - b.x[i];     return result;   }   template <typename T>   using Matrix = vector<vector<T>>;   template <typename T>   Matrix<T> matrix(int R, int C, T x = T()) {     return Matrix<T>(R, vector<T>(C, x));   }   struct RangeProduct {     int N;     Matrix<int> grid;     Matrix<Number> hprod;     Matrix<Number> vprod;     bool valid(int r, int c) { return 0 <= r && r < N && 0 <= c && c < N; }     RangeProduct(int N, Matrix<int> grid) : N(N), grid(grid) {       hprod = matrix<Number>(N + 1, N + 1);       vprod = matrix<Number>(N + 1, N + 1);       for (int r = 0; r < N; r++)         for (int c = 0; c < N; c++) {           hprod[r][c + 1] = hprod[r][c] * Number(grid[r][c]);           vprod[r + 1][c] = vprod[r][c] * Number(grid[r][c]);         }     }     Number hquery(int r, int c, int radius) {       int c1 = c - radius, c2 = c + radius;       if (!valid(r, c1) || !valid(r, c2)) return Number(0);       return hprod[r][c2 + 1] / hprod[r][c1];     }     Number vquery(int r, int c, int radius) {       int r1 = r - radius, r2 = r + radius;       if (!valid(r1, c) || !valid(r2, c)) return Number(0);       return vprod[r2 + 1][c] / vprod[r1][c];     }     Number cross(int r, int c, int radius) {       return hquery(r, c, radius) * vquery(r, c, radius) / Number(grid[r][c]);     }     Number max_cross(int r, int c) {       int a = 0, b = N;       while (a < b) {         int mid = (a + b + 1) / 2;         if (cross(r, c, mid).is_zero())           b = mid - 1;         else           a = mid;       }       return cross(r, c, a);     }   };   Number solve(int N, Matrix<int> grid) {     RangeProduct rp(N, grid);     Number result(0);     for (int r = 0; r < N; r++)       for (int c = 0; c < N; c++) result = max(result, rp.max_cross(r, c));     return result;   }   Matrix<int> rotate(int N, const Matrix<int>& grid, int shift) {     auto ngrid = matrix<int>(N, N);     for (int r = 0; r < N; r++)       for (int c = 0; c < N; c++)         if ((r + c) % 2 == shift)           ngrid[(r + c) / 2][(r - c + N) / 2] = grid[r][c];     return ngrid;   }   int main() {     int N;     cin >> N;     auto grid = matrix<int>(N, N);     for (int i = 0; i < N; i++) {       string s;       cin >> s;       for (int j = 0; j < N; j++) grid[i][j] = s[j] -  0 ;     }     auto rgrid0 = rotate(N, grid, 0);     auto rgrid1 = rotate(N, grid, 1);     Number answer = max({solve(N, grid), solve(N, rgrid0), solve(N, rgrid1)});     cout << answer.mod() << endl;   }


#include <bits/stdc++.h>   using namespace std;   void solve();   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t = 1;     cin >> t;     while (t--) solve();   }   void solve() {     long long n;     cin >> n;     string a, b;     cin >> a >> b;     string c = a, d = b;     sort(c.begin(), c.end());     sort(d.begin(), d.end());     if (c != d) {       cout << -1 <<   n ;       return;     }     long long ans[n], mx = n;     for (long long l = 0; l < n; l++)       for (long long k = 0; k < n; k++) {         ans[l] = n;         long long i = l, j = k;         while (j != n && b[j] != a[i]) j++;         if (j != n) {           ans[l]--;           i++;           j++;         }         while (i != n && j != n) {           while (i != n && j != n && a[i] != b[j]) i++;           if (i != n) ans[l]--, j++, i++;         }         mx = min(ans[l], mx);       }     cout << mx <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 305;   int c[N], a[N], d[N];   bool cmp(int first, int second) {     if (a[first] != a[second]) return a[first] < a[second];     return first > second;   }   inline int lowbit(int first) { return first & -first; }   int query(int first) {     int res = 0;     for (int i = first; i; i -= lowbit(i)) res += c[i];     return res;   }   void modify(int first, int v) {     for (int i = first; i < N; i += lowbit(i)) c[i] += v;   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n, m;       scanf( %d%d , &n, &m);       for (int i = 1; i <= m; ++i) scanf( %d , &a[i]), d[i] = i, c[i] = 0;       sort(d + 1, d + m + 1, cmp);       long long res = 0;       for (int i = 1; i <= m; ++i) {         res += query(d[i]);         modify(d[i], 1);       }       printf( %lld n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, m, q;     cin >> n >> m >> q;     vector<vector<pair<int, int>>> pos(n, vector<pair<int, int>>(m));     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         pos[i][j] = {i, j};       }     }     vector<vector<int>> val(n, vector<int>(m, 0));     for (int i = 0; i < q; ++i) {       int t;       cin >> t;       if (t == 1) {         int r;         cin >> r;         --r;         auto tmp = pos[r][0];         for (int i = 1; i < m; ++i) {           pos[r][i - 1] = pos[r][i];         }         pos[r][m - 1] = tmp;       } else if (t == 2) {         int c;         cin >> c;         --c;         auto tmp = pos[0][c];         for (int i = 1; i < n; ++i) {           pos[i - 1][c] = pos[i][c];         }         pos[n - 1][c] = tmp;       } else {         int r, c, x;         cin >> r >> c >> x;         --r, --c;         auto p = pos[r][c];         val[p.first][p.second] = x;       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cout << val[i][j] <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int N, K;   int gru0[] = {0, 1, 2};   int gru1[] = {0, 1, 0, 1, 2};   int grundy(int x) {     if (K) {       if (x < 5) {         return gru1[x];       } else if (x & 1) {         return 0;       } else {         return grundy(x / 2) == 1 ? 2 : 1;       }     } else {       return x <= 2 ? x : !(x & 1);     }   }   int main() {     if (fopen( input.txt ,  r )) {       freopen( input.txt ,  r , stdin);     }     ios::sync_with_stdio(false);     cin >> N >> K;     K %= 2;     int ans = 0;     for (int i = 0, x; i < N; i++) {       cin >> x;       ans ^= grundy(x);     }     cout << (ans ?  Kevin  :  Nicky ) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int h, m, n;     cin >> h >> m >> n;     int* id = new int[n];     int* hash = new int[n];     int* hsh = new int[h];     int nc = 0;     int res = 0;     char z;     int i, j, k, l;     for (i = 0; i < h; i++) {       hsh[i] = 0;     }     for (i = 0; i < n; i++) {       cin >> z;       if (z ==  + ) {         cin >> id[nc] >> hash[nc];         int chash = hash[nc];         while (hsh[chash] == 1) {           res++;           chash = (chash + m) % h;         }         hsh[chash] = 1;         hash[nc] = chash;         nc++;       } else {         int cid;         cin >> cid;         for (j = 0; j < nc; j++) {           if (id[j] == cid) {             hsh[hash[j]] = 0;             break;           }         }       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int P = 1e9 + 7, INF = 0x3f3f3f3f;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long qpow(long long a, long long n) {     long long r = 1 % P;     for (a %= P; n; a = a * a % P, n >>= 1)       if (n & 1) r = r * a % P;     return r;   }   long long inv(long long first) {     return first <= 1 ? 1 : inv(P % first) * (P - P / first) % P;   }   inline int rd() {     int first = 0;     char p = getchar();     while (p <  0  || p >  9 ) p = getchar();     while (p >=  0  && p <=  9 ) first = first * 10 + p -  0 , p = getchar();     return first;   }   const int N = 1e6 + 10;   int n;   long long k;   char s[N], t[N];   int main() {     scanf( %d%lld%s%s , &n, &k, s + 1, t + 1);     long long ans = 0, tot = 1, INF = 1e15;     for (int i = 1; i <= n; ++i) {       tot <<= 1;       if (s[i] ==  b ) --tot;       if (t[i] ==  a ) --tot;       ans += min(k, tot);       tot = min(tot, INF);     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long dp[int(1e5 + 2)][2];   int a[int(1e5 + 2)];   vector<int> v[2];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int mod = 998244353;     int t;     cin >> t;     while (t--) {       v[0].clear();       v[1].clear();       for (int i = 0; i < int(1e5 + 2); i++) dp[i][0] = dp[i][1] = 0;       int n;       cin >> n;       for (int i = 0; i < n; i++) cin >> a[i];       long long ans = 0;       for (int i = n - 1; i >= 0; i--) {         int one = i % 2;         dp[a[i]][one] = 1;         v[one].push_back(a[i]);         for (auto x : v[1 - one]) {           int k = a[i] / x;           if (a[i] % x != 0) k++;           int x_ = a[i] / k;           if (dp[x_][one] == 0) v[one].push_back(x_);           dp[x_][one] += dp[x][1 - one];           ans = (ans + (i + 1) * dp[x][1 - one] * (k - 1)) % mod;           dp[x][1 - one] = 0;         }         v[1 - one].clear();       }       cout << ans <<   n ;     }   }


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


#include <bits/stdc++.h>   using namespace std;   const long long M = 998244353;   long long power(long long a, long long b, long long m) {     long long res = 1;     a %= m;     while (b) {       if (b & 1LL) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, m, k;     cin >> n >> m >> k;     m = power(m, M - 2, M);     vector<vector<long long>> dp(k + 1, vector<long long>(k + 1, 0));     for (long long i = 0; i <= k; ++i) {       for (long long j = 0; j <= k; ++j) {         long long N = n - k + i, K = j;         if (N <= 0 || K == 0) {           dp[i][j] = 0;           continue;         }         if (K == 1) {           dp[i][j] = N * m % M;           continue;         }         if (i > 0)           dp[i][j] =               (dp[i][j - 1] - dp[i - 1][j - 1] * (1 - m + M) % M + M) % M * N % M;       }     }     cout << dp[k][k] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T min_(T a, T b) {     return (a < b ? a : b);   }   template <class T>   T max_(T a, T b) {     return (a > b ? a : b);   }   const int MAX_N = 1e5 + 1;   vector<pair<unsigned long long, unsigned long long> > notes;   int main(int argc, char *argv[]) {     std::ios::sync_with_stdio(false);     cin.tie(0);     int days, nnotes;     cin >> days >> nnotes;     notes.resize(nnotes);     int day, h;     int max_h = 0;     for (int i = 0; i < nnotes; ++i) {       cin >> day >> h;       max_h = max(max_h, h);       notes[i] = {day, h};     }     int new_h;     int day1, day2, h1, h2;     day1 = notes[0].first;     if (day1 != 1) {       h1 = notes[0].second;       new_h = h1 + day1 - 1;       max_h = max(max_h, new_h);     }     for (int i = 0; i < nnotes; ++i) {       day1 = notes[i].first;       h1 = notes[i].second;       if (i == nnotes - 1) {         day2 = days;         new_h = h1 + (day2 - day1);         max_h = max(max_h, new_h);         break;       }       day2 = notes[i + 1].first;       h2 = notes[i + 1].second;       int ddiff = day2 - day1;       int hdiff = abs(h2 - h1);       if (hdiff > ddiff) {         cout <<  IMPOSSIBLE n ;         return 0;       } else {         if (h1 < h2) {           day1 = day1 + hdiff;           ddiff = day2 - day1;           h1 = h2;         } else if (h1 > h2) {           day2 = day2 - hdiff;           ddiff = day2 - day1;           h2 = h1;         }         new_h = h1 + (ddiff / 2);         max_h = max(max_h, new_h);       }     }     cout << max_h <<   n ;     return 0;   }


#include <bits/stdc++.h>   const int N = 500054;   const double eps = 3e-10;   inline void up(double &x, const double y) { x < y ? x = y : 0.; }   inline void down(double &x, const double y) { x > y ? x = y : 0.; }   inline double max(const double x, const double y) { return x < y ? y : x; }   struct quadratic {     double A, B, C;     quadratic(double A_ = 0., double B_ = 0., double C_ = 0.)         : A(A_), B(B_), C(C_) {}     inline double operator()(double x) const { return (A * x + B) * x + C; }     inline std::pair<double, double> root(double y) const {       if ((((A) <= (0) + eps) && ((A) >= (0) - eps)))         return std::pair<double, double>((y - C) / B, NAN);       double b = -.5 * B / A, d = b * b + (y - C) / A;       return ((d) < (0) - eps) ? std::pair<double, double>(NAN, NAN)                                : (d = sqrt(max(d, 0.)),                                   std::pair<double, double>(b - d, b + d));     }     inline std::pair<double, double> range(double x_min, double x_max) const {       assert(x_min <= x_max);       std::pair<double, double> ret = std::minmax((*this)(x_min), (*this)(x_max));       double mid = -.5 * B / A;       if ((((A) <= (0) + eps) && ((A) >= (0) - eps)) || mid < x_min ||           x_max < mid)         ;       else         mid = (*this)(mid), down(ret.first, mid), up(ret.second, mid);       return ret;     }   };   struct vec2 {     double x, y;     vec2(double x0 = 0., double y0 = 0.) : x(x0), y(y0) {}     vec2 *read() {       scanf( %lf%lf , &x, &y);       return this;     }     inline vec2 operator-() const { return vec2(-x, -y); }     inline vec2 operator+(const vec2 &B) const { return vec2(x + B.x, y + B.y); }     inline vec2 operator-(const vec2 &B) const { return vec2(x - B.x, y - B.y); }     inline vec2 operator*(double k) const { return vec2(x * k, y * k); }     inline vec2 operator/(double k) const { return *this * (1.0 / k); }     inline double operator*(const vec2 &B) const { return x * B.x + y * B.y; }     inline double operator^(const vec2 &B) const { return x * B.y - y * B.x; }     inline double norm2() const { return x * x + y * y; }     inline double norm() const { return sqrt(x * x + y * y); }     inline bool operator<(const vec2 &B) const {       return ((x) < (B.x) - eps) || ((x) <= (B.x) + eps) && ((y) < (B.y) - eps);     }     inline bool operator==(const vec2 &B) const {       return (((x) <= (B.x) + eps) && ((x) >= (B.x) - eps)) &&              (((y) <= (B.y) + eps) && ((y) >= (B.y) - eps));     }   };   int n, m, sr = 0;   vec2 p[N], unit[N];   double C[N], co[N], u;   double st[N];   quadratic f[N];   std::pair<double, double> rg[N];   inline int pred(int x) { return (x ? x : n) - 1; }   inline int succ(int x) { return ++x == n ? 0 : x; }   void append(double len, int i1, double s1, int i2, double s2) {     if (s1 < 0) s1 += C[n];     if (s2 < 0) s2 += C[n];     st[sr + 1] = st[sr] + len;     vec2 O = (p[i1] + unit[i1] * s1) - (p[i2] + unit[i2] * s2),          v = unit[i1] - unit[i2];     f[sr++] = quadratic(v.norm2(), v * O * 2., O.norm2());   }   namespace seg {   int n;   bool danger;   std::pair<double, double> a[N];   inline void reset() { n = 0, danger = false; }   inline void insert(double L, double R) {     assert(L <= R);     int Li = L / u, Ri = R / u;     L -= Li * u, R -= Ri * u;     if (Li == Ri)       a[n++] = std::pair<double, double>(L, R);     else if (Li + 1 == Ri && L > R)       a[n++] = std::pair<double, double>(L, u),       a[n++] = std::pair<double, double>(0, R);     else       danger = true;   }   bool exist() {     if (danger) return false;     int i;     double k = 0;     std::sort(a, a + n);     for (i = 0; i < n; ++i) {       if (k < a[i].first) return true;       up(k, a[i].second);     }     return ((k) < (u)-eps);   }   }  // namespace seg   inline bool check(double lim) {     int i;     double L, R, x1, x2;     seg::reset();     for (i = 0; i < sr; ++i) {       if (L = st[i], R = st[i + 1], (((L) <= (R) + eps) && ((L) >= (R)-eps)))         continue;       if (lim <= rg[i].first)         seg::insert(L, R);       else if (lim < rg[i].second) {         std::tie(x1, x2) = f[i].root(lim), x1 += L, x2 += L;         if (!(L <= x1 && x1 <= R)) std::swap(x1, x2);         if (L <= x2 && x2 <= R)           f[i].C >= lim          ? seg::insert(L, x1),               seg::insert(x2, R) : seg::insert(x1, x2);         else           f[i].C >= lim ? seg::insert(L, x1) : seg::insert(x1, R);       }     }     return seg::exist();   }   int main() {     int i, j;     double L, R, M;     scanf( %d%d , &n, &m);     for (i = 0; i < n; ++i) p[i].read();     p[n] = *p;     for (i = 0; i < n; ++i)       L = (p[i] - p[i + 1]).norm(), C[i + 1] = C[i] + L,       unit[i] = (p[i + 1] - p[i]) / L;     u = C[n] / m;     for (i = 0; i < n; ++i) co[i] = fmod(C[i] + C[n] - u, C[n]);     j = pred(std::min_element(co, co + n) - co);     for (i = 0; i < n; ++i) {       for (L = C[i]; C[i] <= co[succ(j)] && co[succ(j)] < C[i + 1];            j = succ(j), L = co[j])         append(co[succ(j)] - L, i, L - C[i], j, L - co[j]);       append(C[i + 1] - L, i, L - C[i], j, L - co[j]);     }     for (i = 0; i < sr; ++i) rg[i] = f[i].range(0, st[i + 1] - st[i]);     {       vec2 *_1, *_2;       std::tie(_1, _2) = std::minmax_element(p, p + n), R = (*_1 - *_2).norm();     }     for (L = 0.; L + eps < R;) M = (L + R) * .5, check(M * M) ? R = M : L = M;     printf( %.10lg n , (L + R) * .5);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     vector<pair<int, int>> ans;     for (int c = 1; c < k; c++) {       int r = 0;       int C = c;       while (ans.size() < n) {         ans.emplace_back(r + 1, C + 1);         if (C == k - 1) break;         r++, C++;       }       r = k - 1;       C = k - c - 1;       while (ans.size() < n) {         ans.emplace_back(r + 1, C + 1);         if (C == 0) break;         r--, C--;       }     }     if (ans.size() != n) {       cout <<  NO  << endl;       return (0);     }     cout <<  YES  << endl;     for (auto pp : ans) cout << pp.first <<     << pp.second <<   n ;     return (0);   }


#include <bits/stdc++.h>   using namespace std;   struct str {     int q, cost;     str(int _q = 0, int _cost = 0) {       q = _q;       cost = _cost;     }     bool operator<(const str &two) const { return cost > two.cost; }   };   struct edge {     int u, v, cost;     edge(int _u = 0, int _v = 0, int _cost = 0) { u = _u, v = _v, cost = _cost; }   };   vector<str> adj[(100000 + 10)];   int n, m, s;   int len;   int u, v, cost;   int dis[(100000 + 10)];   vector<edge> all;   int main() {     cin >> n >> m >> s;     for (int i = 0; i < m; i++) {       cin >> u >> v >> cost;       all.push_back(edge(u, v, cost));       adj[u].push_back(str(v, cost));       adj[v].push_back(str(u, cost));     }     cin >> len;     for (int i = 1; i <= n; i++) dis[i] = 1000000000;     dis[s] = 0;     priority_queue<str> pq;     pq.push(str(s, 0));     while (!pq.empty()) {       str v = pq.top();       pq.pop();       int node = v.q;       for (int i = 0; i < adj[node].size(); i++) {         int u = adj[node][i].q;         int cost = adj[node][i].cost;         if (dis[node] + cost < dis[u]) {           dis[u] = dis[node] + cost;           pq.push(str(u, dis[u]));         }       }     }     int out = 0;     for (int i = 1; i <= n; i++)       if (dis[i] == len) out++;     int one, two;     for (int i = 0; i < all.size(); i++) {       u = all[i].u;       v = all[i].v;       cost = all[i].cost;       if (dis[u] < len && len < dis[u] + cost &&           cost - (len - dis[u]) + dis[v] > len)         out++;       if (dis[v] < len && len < dis[v] + cost &&           cost - (len - dis[v]) + dis[u] > len)         out++;       if (dis[v] < len && dis[u] < len && dis[u] + dis[v] + cost == 2 * len)         out++;     }     cout << out << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int d4x[4] = {1, 0, -1, 0};   int d4y[4] = {0, 1, 0, -1};   int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1};   int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};   const long long oo = 1e18;   const long long maxN = 1e6;   const int N = 105;   long long a[N];   void solve() {     int n;     long long h;     cin >> n >> h;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + 1 + n);     auto ok = [&](long long x) -> bool {       long long ans = 0;       for (int i = 1; i <= n; i++) {         if (i < n)           ans += min(a[i + 1] - a[i], x);         else           ans += x;         if (ans >= h) return true;       }       return false;     };     long long L = 1, R = h, ans = 0;     while (L <= R) {       long long mid = (L + R) >> 1;       if (ok(mid)) {         ans = mid;         R = mid - 1;       } else         L = mid + 1;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tc = 1, ddd = 0;     cin >> tc;     while (tc--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long int arr[500005], sum[500005];   bool vis[100005];   map<long long int, long long int> hola;   map<pair<long long int, long long int>, long long int> con;   vector<pair<long long int, long long int>> conn;   int main() {     long long int n, maxi = INT_MIN;     cin >> n;     for (long long int i = 0; i < n; i++) {       cin >> arr[i];       hola[arr[i]]++;     }     for (long long int i = 0; i < n; i++) {       if (hola[arr[i]] > maxi) maxi = hola[arr[i]];     }     cout << maxi;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 1000000000;   const int MAX = 5000;   const int MOD = 1000000007;   int C[MAX][MAX];   int CL[MAX];   int main() {     int n;     cin >> n;     C[0][0] = 1;     for (int i = (1); i < (n + 1); ++i) {       C[i][0] = 1;       for (int j = (1); j < (n + 1); ++j) {         C[i][j] = C[i - 1][j] + C[i - 1][j - 1];         if (C[i][j] >= MOD) C[i][j] -= MOD;       }     }     CL[0] = 1;     for (int i = (1); i < (n + 1); ++i) {       CL[i] = 0;       for (int j = (1); j < (i + 1); ++j) {         long long c = C[i - 1][j - 1];         c *= CL[i - j];         c %= MOD;         CL[i] += c;         if (CL[i] >= MOD) CL[i] -= MOD;       }     }     long long res = 0;     for (int i = (1); i < (n + 1); ++i) {       long long c = C[n][i];       int m = n - i;       c *= CL[m];       c %= MOD;       res += c;       if (res >= MOD) res -= MOD;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1E-8;   const int dx4[4] = {1, 0, 0, -1};   const int dy4[4] = {0, -1, 1, 0};   const int inf = 0x3f3f3f3f;   const int N = 2E5 + 7;   int tree[2][N];   int a[N], p[N];   int n;   long long k;   int lowbit(int x) { return x & (-x); }   void update(int o, int x, int delta) {     if (!o) x = n - x + 1;     for (int i = x; i <= n; i += lowbit(i)) tree[o][i] += delta;   }   int Hash(int x) { return lower_bound(p + 1, p + n + 1, x) - p; }   int Sum(int o, int x) {     if (!o) x = n - x + 1;     int res = 0;     for (int i = x; i >= 1; i -= lowbit(i)) res += tree[o][i];     return res;   }   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i], p[i] = a[i];     sort(p + 1, p + n + 1);     long long total = 0;     for (int i = n; i >= 1; i--) {       int x = Hash(a[i]);       a[i] = x;       total += Sum(1, a[i] - 1);       update(1, a[i], 1);     }     int r = 1;     long long ans = 0;     for (int l = 1; l <= n; l++) {       total += Sum(0, a[l] + 1) + Sum(1, a[l] - 1);       update(0, a[l], 1);       while ((r <= l || total > k) && r <= n) {         total -= Sum(0, a[r] + 1) + Sum(1, a[r] - 1);         update(1, a[r], -1);         r++;       }       ans += n - r + 1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 25, M = 300005;   int n, a[N][N];   long long f[M], g[N][M], d[N][M], dp[N][M];   map<long long, long long> mp;   string st;   inline int bp(int x) { return __builtin_popcount(x); }   void dfs(int p, int s, int x, long long m) {     if (s == n) {       long long w = 0;       for (int i = 0; i < (1 << n); i++) {         if ((n + bp(i)) & 1)           w -= d[x][i];         else           w += d[x][i];       }       mp[m] = w;       return;     }     if (s + p > n) return;     for (int i = 0; i < (1 << n); i++) d[x + 1][i] = d[x][i] * g[p][i];     dfs(p, s + p, x + 1, m * 10 + p);     dfs(p + 1, s, x, m);   }   long long ch(int x) {     vector<int> v;     int s = 0;     for (int i = 0; i < n; i++) {       if (x >> i & 1)         s++;       else {         v.push_back(s + 1);         s = 0;       }     }     sort(v.begin(), v.end());     long long y = 0;     for (auto i : v) y = y * 10 + i;     return y;   }   int main() {     ios::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> st;       for (int j = 0; j < n; j++) a[i][j] = (st[j] ==  1 );     }     for (int i = 0; i < n; i++) dp[i][1 << i] = 1;     for (int i = 1; i < (1 << n); i++) {       for (int j = 0; j < n; j++) {         if (dp[j][i]) {           g[bp(i)][i] += dp[j][i];           for (int k = 0; k < n; k++)             if (!(i >> k & 1) && a[j][k]) dp[k][i | (1 << k)] += dp[j][i];         }       }     }     for (int i = 1; i <= n; i++)       for (int j = 0; j < n; j++)         for (int s = 0; s < (1 << n); s++)           if (s >> j & 1) g[i][s] += g[i][s ^ (1 << j)];     for (int i = 0; i < (1 << n); i++) d[0][i] = 1;     dfs(1, 0, 0, 0);     for (int i = 0; i < (1 << (n - 1)); i++) f[i] = mp[ch(i)];     for (int i = 0; i < n - 1; i++)       for (int j = 0; j < (1 << (n - 1)); j++)         if (!(j >> i & 1)) f[j] -= f[j ^ (1 << i)];     for (int i = 0; i < (1 << (n - 1)); i++) printf( %lld  , f[i]);     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int a[n], i, s = 0;     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       s = s + a[i];     }     if (s == 0)       printf( EASY n );     else       printf( HARD n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, t, x, y, ed, pt, bcc, done, cnt, cycl;   int qd[400005], qn[400005], l[400005], v[400005], w[400005], vv[400005],       d[400005], AP[400005], p[400005], vis[400005];   int col[400005], par[400005], L[400005], C[400005], cc[400005], vc[400005],       pp[400005];   vector<int> P;   void bd(int x, int y) { qd[++ed] = y, qn[ed] = l[x], l[x] = ed; }   void dfs(int x, int y) {     int c = 0;     v[x] = w[x] = ++t;     p[x] = y;     for (int i = l[x]; i; i = qn[i])       if (!v[qd[i]]) {         dfs(qd[i], x);         w[x] = min(w[x], w[qd[i]]);         ++c;         if ((y >= 0 && w[qd[i]] >= v[x]) || (y < 0 && c > 1)) AP[x] = 1;       } else if (qd[i] != y)         w[x] = min(w[x], v[qd[i]]);   }   void color(int x, int y) {     vis[x] = 1;     for (int i = l[x]; i; i = qn[i]) {       if (col[i ^ 1]) continue;       if (p[x] == -1 || (AP[x] && w[qd[i]] >= v[x])) {         col[i] = col[i ^ 1] = ++bcc;         color(qd[i], bcc);       } else {         col[i] = col[i ^ 1] = y;         if (!vis[qd[i]]) color(qd[i], y);       }     }   }   void cyc(int x, int p) {     vv[x] = 1;     par[x] = p;     for (int i = (l[x]); i; i = qn[i])       if (qd[i] != p) {         if (!vv[qd[i]])           cyc(qd[i], x);         else if (vv[qd[i]] == 1 && !cycl) {           int t = x;           while (1) {             C[cycl++] = t;             cc[t] = 1;             if (t == qd[i]) break;             t = par[t];           }         }       }     vv[x] = 2;   }   void shoot(int x, int p) {     if (done) return;     vc[x] = 1;     pp[x] = p;     for (int i = (l[x]); i; i = qn[i])       if (!vc[qd[i]] && !done) {         if (p == -1 && cc[qd[i]]) continue;         if (cc[qd[i]]) {           done = 1;           pp[qd[i]] = x;           pt = qd[i];         } else           shoot(qd[i], x);       }   }   void print() {     printf( %d , P.size());     for (int i = (0); i < (P.size()); i++) printf(  %d , P[i]);     puts(  );   }   void doit(int y, int j) {     P.clear();     for (int k = y; k != j; k = (k + 1 == cycl ? 0 : k + 1))       P.push_back(C[k] + 1);     P.push_back(C[j] + 1);     print();     P.clear();     for (int k = y; k != j; k = (k == 0 ? cycl - 1 : k - 1))       P.push_back(C[k] + 1);     P.push_back(C[j] + 1);     print();   }   struct edge {     int x, y, c;     bool operator<(edge const &T) const { return c < T.c; }   };   edge E[400005];   int main() {     scanf( %d%d , &n, &m);     ed = 1;     for (int i = (0); i < (m); i++) {       scanf( %d%d , &x, &y), --x, --y;       bd(x, y), bd(y, x);     }     for (int i = (0); i < (n); i++)       if (!v[i]) dfs(i, -1);     for (int i = (0); i < (n); i++)       if (!vis[i]) color(i, -1);     memset(l, 0, sizeof(l));     for (int i = (2); i <= (ed); i++) {       E[i - 2].x = qd[i];       E[i - 2].y = qd[i ^ 1];       E[i - 2].c = col[i];     }     int Edges = ed - 1;     sort(E, E + Edges);     int ptr = 0;     for (int bb = (1); bb <= (bcc); bb++) {       ed = cnt = 0;       while (ptr < Edges && E[ptr].c == bb) {         bd(E[ptr].x, E[ptr].y);         ++d[E[ptr].x];         L[cnt++] = E[ptr].x;         ++ptr;       }       if (cnt < 4) goto AFTER;       cycl = 0;       cyc(L[0], -1);       for (int j = (0); j < (cycl); j++)         if (d[C[j]] > 2) {           for (int k = (l[C[j]]); k; k = qn[k]) {             int y = qd[k];             if (!cc[y]) continue;             if (y == C[(j + 1) % cycl] || y == C[(j + cycl - 1) % cycl]) continue;             puts( YES );             printf( 2 %d %d n , y + 1, C[j] + 1);             int ty = y;             for (int k = (0); k < (cycl); k++)               if (C[k] == ty) y = k;             doit(y, j);             return 0;           }           done = 0;           shoot(C[j], -1);           if (done) {             puts( YES );             for (int k = (0); k < (cycl); k++)               if (C[k] == pt) y = k;             doit(y, j);             P.clear();             while (1) {               P.push_back(pt + 1);               if (pt == C[j]) break;               pt = pp[pt];             }             print();             return 0;           }         }     AFTER:       for (int i = (0); i < (cnt); i++)         vv[L[i]] = vc[L[i]] = cc[L[i]] = l[L[i]] = d[L[i]] = 0;     }     puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 1000 + 10;   const int mod = 1e9 + 7;   int a[3][6];   int vis[100];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++)       for (int j = 0; j < 6; j++) cin >> a[i][j];     for (int i = 0; i < n; i++) {       for (int k = 0; k < 6; k++) {         vis[a[i][k]] = 1;         for (int j = 0; j < n; j++) {           if (i == j) continue;           for (int l = 0; l < 6; l++) {             vis[a[i][k] * 10 + a[j][l]] = 1;           }         }       }     }     for (int i = 1; i < 100; i++) {       if (!vis[i]) {         cout << i - 1 << endl;         break;       }     }   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long tt = 1;     cin >> tt;     while (tt--) {       string t, s, ans;       bool f = 0;       cin >> t;       long long n = t.size();       vector<long long> a(26), b(26), c(26);       for (long long i = n - 1; i >= 0; --i) {         if (a[t[i] -  a ] == 0) s = t[i] + s;         a[t[i] -  a ]++;       }       long long sz = 0;       for (long long i = 0; i < s.size(); ++i) {         if (a[s[i] -  a ] % (i + 1)) {           f = 1;           break;         }         b[s[i] -  a ] = a[s[i] -  a ] / (i + 1);         sz += b[s[i] -  a ];       }       if (!f) {         vector<string> st(sz);         long long id = 0;         for (long long i = 0; i < s.size(); ++i) {           st[i] = string(t, id, sz);           id += sz, sz -= b[s[i] -  a ];         }         ans = st[0];         for (long long i = 0; i < st.size() - 1; ++i) {           string cnt;           for (long long j = 0; j < st[i].size(); ++j) {             if (st[i][j] != s[i]) cnt = cnt + st[i][j];           }           if (cnt != st[i + 1]) {             f = 1;             break;           }         }       }       if (f)         cout << -1 <<   n ;       else         cout << ans <<     << s <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, q, a[int(2e5)], sz;   set<pair<int, int> > st;   int main() {     cin >> n >> k >> q;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     for (int i = 0; i < q; ++i) {       int x, y;       cin >> x >> y;       if (x == 1) {         st.insert(make_pair(a[y - 1], y));         sz++;         if (sz > k) {           st.erase(st.begin());           sz--;         }       } else {         if (st.find(make_pair(a[y - 1], y)) != st.end()) {           cout <<  YES n ;         } else {           cout <<  NO n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) { return a > b ? a : b; }   long long min(long long a, long long b) { return a < b ? a : b; }   double max(double a, double b) { return a > b ? a : b; }   double min(double a, double b) { return a < b ? a : b; }   long long modd(long long a) {     if (a < 0LL) return a * -1LL;     return a;   }   double modd(double a) {     if (a < 0.0) return a * -1.0;     return a;   }   long long modulo(long long a) { return a % 1000000007LL; }   long long power(long long k, long long p) {     if (p == 0) return 1LL;     long long P = power(k, p / 2LL);     P = (P * P) % 1000000007LL;     if (p % 2 == 1) P = (P * k) % 1000000007LL;     return P;   }   struct p_str {     long long val, idx;     char ch;   };   bool comp(p_str& a, p_str& b) { return a.val < b.val; }   void solve() {     string s;     cin >> s;     long long m;     cin >> m;     long long b[m];     for (long long i = 0; i < m; i++) {       cin >> b[i];     }     long long cnt[26];     memset(cnt, 0, sizeof(cnt));     for (long long i = 0; i < s.length(); i++) {       cnt[s[i] -  a ]++;     }     char t[m];     long long i_cnt = 26;     while (1) {       bool f = 1;       long long mn_i = -1;       for (long long i = 0; i < m; i++) {         if (b[i] == 0) {           mn_i = i;           f = 0;           break;         }       }       if (f) {         break;       }       vector<long long> zero_pos;       for (long long i = 0; i < m; i++) {         if (b[i] == 0) {           zero_pos.push_back(i);         }       }       long long c = zero_pos.size();       i_cnt--;       while (i_cnt >= 0 && cnt[i_cnt] < c) {         i_cnt--;       }       for (long long i = 0; i < zero_pos.size(); i++) {         t[zero_pos[i]] = (char)(i_cnt +  a );       }       for (long long j = 0; j < zero_pos.size(); j++) {         long long pos = zero_pos[j];         for (long long i = 0; i < m; i++) {           if (b[i] > 0) {             b[i] -= modd(i - pos);           }         }         b[pos] = -1;       }     }     for (long long i = 0; i < m; i++) {       cout << t[i];     }     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n <= 2)       cout <<  -1 ;     else if (n == 3)       cout <<  210 ;     else {       int mod = 1;       for (int i = 1; i < n; ++i) mod = (mod * 10) % 210;       if (n > 3) cout <<  1 ;       for (int i = 0; i < n - 4; ++i) cout <<  0 ;       if (210 - mod < 100) cout <<  0 ;       cout << 210 - mod;     }   }


#include <bits/stdc++.h>   using namespace std;   int cho[30];   char str[1005];   int main() {     int a, b, ans = 0;     cin >> a >> b;     for (int i = 0; i < a; i++) {       cin >> str[i];       cho[str[i] - 96]++;     }     int tot = b;     for (int i = 1; i <= 26; i++) {       if (tot == 0) {         break;       } else if (tot != 0 && cho[i] >= 1) {         if (cho[i - 1] != -1) {           ans += i;           tot--;           cho[i] = -1;         }       }     }     if (tot == 0)       cout << ans << endl;     else if (tot > 0)       cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, ans, tot;   int b[200010], rt[200010];   struct nu {     int val, id;   } a[200010];   char s[200010];   struct node {     int ls, rs, sum;   } tree[200010 * 20];   inline bool cmp(const nu &x, const nu &y) {     if (x.val == y.val)       return x.id < y.id;     else       return x.val > y.val;   }   inline void insert(int num, int &x, int l, int r) {     tree[++tot] = tree[x];     x = tot;     ++tree[x].sum;     if (l == r) return;     int mid = (l + r) >> 1;     if (num <= mid)       insert(num, tree[x].ls, l, mid);     else       insert(num, tree[x].rs, mid + 1, r);   }   inline void prework() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       scanf( %d , &a[i].val), a[i].id = i, b[i] = a[i].val;     sort(a + 1, a + 1 + n, cmp);     tot = 0;     for (int i = 1; i <= n; i++) {       rt[i] = rt[i - 1];       insert(a[i].id, rt[i], 1, n);     }   }   inline int query(int i, int j, int k, int l, int r) {     if (l == r) return l;     int tp = tree[tree[j].ls].sum - tree[tree[i].ls].sum;     int mid = (l + r) >> 1;     if (k <= tp)       return query(tree[i].ls, tree[j].ls, k, l, mid);     else       return query(tree[i].rs, tree[j].rs, k - tp, mid + 1, r);   }   inline void mainwork() {     scanf( %d , &m);     int k, pos;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &k, &pos);       ans = query(rt[0], rt[k], pos, 1, n);       printf( %d n , b[ans]);     }   }   inline void print() {}   int main() {     int t = 1;     for (int i = 1; i <= t; i++) {       prework();       mainwork();       print();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100010], b[100010];   int main() {     int t;     cin >> t;     while (t--) {       int n;       int flag = 1;       long long min = 1e9 + 1;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> a[i];         b[i] = a[i];         if (min > a[i]) min = a[i];       }       sort(b, b + n);       for (int i = 0; i < n; i++) {         if (a[i] != b[i]) {           if (a[i] % min != 0) {             flag = 0;             break;           }         }       }       if (flag)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     set<int> set;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int put;       scanf( %d , &put);       set.insert(put);     }     vector<int> arr(set.size());     copy(set.begin(), set.end(), arr.begin());     sort(arr.begin(), arr.end());     int consq = 0;     int iter = arr.size();     for (int i = 1; i < iter; i++) {       if (arr[i - 1] == arr[i] - 1) {         consq++;       } else {         consq = 0;       }       if (consq == 2) {         printf( YES n );         return 0;       }     }     printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct _ {     int a, b, c, d, id;     bool operator<(const _ &ob) const { return b < ob.b; }   } a[200010];   struct __ {     int val, id;     bool operator<(const __ &ob) const { return val < ob.val; }   };   struct event {     int x, y, depth, id;   };   queue<event> q;   set<int> ss;   multiset<__> s[200010];   _ min_[800010];   int val[200010], tx, ty, n, anss[200010], ans;   int fa[200010];   void pushup(int rt) { min_[rt] = min(min_[rt << 1], min_[rt << 1 | 1]); }   void update(_ tar, int l, int r, int rt) {     if (l == r) {       min_[rt] = tar;       return;     }     int m = l + r >> 1;     if (tar.a <= m)       update(tar, l, m, rt << 1);     else       update(tar, m + 1, r, rt << 1 | 1);     pushup(rt);   }   _ query(int L, int R, int l, int r, int rt) {     if (L <= l && r <= R) return min_[rt];     int m = l + r >> 1;     _ ans;     ans.b = 1234567890;     if (m >= L) ans = min(ans, query(L, R, l, m, rt << 1));     if (m < R) ans = min(ans, query(L, R, m + 1, r, rt << 1 | 1));     return ans;   }   void bfs(int x, int y, int depth, int id) {     if (id == n) {       ans = depth;       anss[depth] = id;       return;     }     _ t = query(1, x, 1, n << 1, 1);     while (t.b <= y) {       s[t.a].erase(s[t.a].begin());       if (s[t.a].empty())         update((_){t.a, 1234567890, 0, 0, 0}, 1, n << 1, 1);       else         update(a[s[t.a].begin()->id - 1], 1, n << 1, 1);       q.push((event){t.c, t.d, depth + 1, t.id});       fa[t.id] = id;       t = query(1, x, 1, n << 1, 1);     }   }   void bbfs(int x, int y, int depth, int id) {     q.push((event){x, y, depth, id});     event t;     while (!q.empty()) {       t = q.front();       q.pop();       bfs(t.x, t.y, t.depth, t.id);       if (ans) return;     }   }   int main() {     memset(min_, 63, sizeof(min_));     memset(val, 63, sizeof(val));     scanf( %d , &n);     int i;     for (i = 0; i < n; i++) {       scanf( %d%d%d%d , &a[i].a, &a[i].b, &a[i].c, &a[i].d);       ss.insert(a[i].a);       ss.insert(a[i].c);     }     set<int>::iterator it;     for (it = ss.begin(), i = 1; it != ss.end(); it++, i++) {       val[i] = *it;     }     for (i = 0; i < n; i++) {       a[i].a = lower_bound(val + 1, val + 1 + (n << 1), a[i].a) - val;       a[i].c = lower_bound(val + 1, val + 1 + (n << 1), a[i].c) - val;       a[i].id = i + 1;     }     tx = a[n - 1].c;     ty = a[n - 1].d;     if (*ss.begin()) {       printf( -1 n );       return 0;     }     int t;     for (i = 0; i < n; i++) {       t = query(a[i].a, a[i].a, 1, n << 1, 1).b;       if (a[i].b < t) update(a[i], 1, n << 1, 1);       s[a[i].a].insert((__){a[i].b, i + 1});     }     bbfs(1, 0, 0, -1);     if (!ans)       printf( -1 n );     else {       for (i = ans; i; i--) {         anss[i - 1] = fa[anss[i]];       }       printf( %d n , ans);       for (i = 1; i <= ans; i++) {         printf( %d  , anss[i]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int seg[800005], lazy[800005];   void push(long long int v) {     if (lazy[v] == 0) return;     seg[2 * v] |= lazy[v];     seg[2 * v + 1] |= lazy[v];     lazy[2 * v] = lazy[v];     lazy[2 * v + 1] = lazy[v];     lazy[v] = 0;     return;   }   void update(long long int v, long long int tl, long long int tr,               long long int l, long long int r, long long int val) {     if (tl > r || tr < l) return;     push(v);     if (tl == l && tr == r) {       lazy[v] = val;       seg[v] = val;       return;     } else if (tl >= l && tr <= r) {       lazy[v] = val;       seg[v] |= val;       return;     }     long long int tm = (tl + tr) / 2;     update(2 * v, tl, tm, l, r, val);     update(2 * v + 1, tm + 1, tr, l, r, val);     seg[v] = (seg[2 * v] & seg[2 * v + 1]);     return;   }   long long int query(long long int v, long long int tl, long long int tr,                       long long int l, long long int r) {     if (tl > r || tr < l) return (1LL << 40) - 1;     push(v);     if (tl >= l && tr <= r) {       return seg[v];     }     long long int tm = (tl + tr) / 2;     return (query(2 * v, tl, tm, l, r) & query(2 * v + 1, tm + 1, tr, l, r));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tests = 1;     while (tests--) {       long long int i, j, n, m;       cin >> n >> m;       vector<long long int> l(m), r(m), q(m);       vector<vector<long long int>> cnt(n + 2, vector<long long int>(31, 0));       for (long long int i = 0; i <= m - 1; i++) {         cin >> l[i] >> r[i] >> q[i];         for (long long int j = 0; j <= 30; j++) {           if (q[i] & (1 << j)) cnt[l[i]][j]++, cnt[r[i] + 1][j]--;         }       }       for (long long int i = 1; i <= n; i++) {         for (long long int j = 0; j <= 30; j++) cnt[i][j] += cnt[i - 1][j];       }       for (long long int i = 1; i <= n; i++) {         long long int val = 0;         for (long long int j = 0; j <= 30; j++) {           if (cnt[i][j] > 0) val |= (1 << j);         }         update(1, 1, n, i, i, val);       }       bool check = true;       for (long long int i = 0; i <= m - 1; i++) {         long long int val = query(1, 1, n, l[i], r[i]);         if (val != q[i]) {           check = false;           break;         }       }       if (!check) {         cout <<  NO ;         return 0;       }       cout <<  YES             <<   n ;       for (long long int i = 1; i <= n; i++) {         cout << query(1, 1, n, i, i) <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int nax = 107;   int n, m;   char wcz[nax][nax];   int oj[nax];   int fin(int v) {     if (oj[v] != v) oj[v] = fin(oj[v]);     return oj[v];   }   void uni(int v, int u) { oj[fin(v)] = fin(u); }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %s , wcz[i] + 1);     for (int i = 1; i <= n + m; i++) oj[i] = i;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (wcz[i][j] ==  # ) uni(i, n + j);       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (wcz[i][j] ==  .  && fin(i) == fin(n + j)) {           printf( No n );           return 0;         }       }     }     printf( Yes n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 5;   long long n, m;   long long a[N], ans[N];   set<long long> active;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       active.insert(i);     }     cin >> m;     while (m--) {       long long type;       cin >> type;       if (type == 1) {         long long p, x;         cin >> p >> x;         auto it = active.lower_bound(p);         if (it != active.end()) {           long long idx = *it;           ans[idx] += x;           long long diff = 0;           while (idx <= n && ans[idx] >= a[idx]) {             diff = ans[idx] - a[idx];             ans[idx + 1] += diff;             ans[idx] = a[idx];             active.erase(idx);             idx++;           }         }       } else {         long long k;         cin >> k;         cout << ans[k] <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int max_n = 22, inf = 1111111111;   int n, m, dp[1 << max_n], a[max_n][max_n], nmask[max_n][max_n],       res[max_n][max_n];   string s[max_n];   bool get_bit(int x, int poz) { return (bool)(x & (1 << poz)); }   int main() {     cin >> n >> m;     for (int i = 0; i < n; ++i) {       cin >> s[i];     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cin >> a[i][j];       }     }     for (int poz = 0; poz < n; ++poz) {       for (int i = 0; i < m; ++i) {         int mx = 0;         for (int j = 0; j < n; ++j) {           if (s[poz][i] == s[j][i]) {             res[poz][i] += a[j][i];             mx = max(mx, a[j][i]);             nmask[poz][i] |= (1 << j);           }         }         res[poz][i] -= mx;       }     }     dp[0] = 0;     for (int mask = 1; mask < (1 << n); ++mask) {       int poz;       for (int i = 0; i < n; ++i) {         if (get_bit(mask, i)) {           poz = i;         }       }       dp[mask] = inf;       for (int i = 0; i < m; ++i) {         dp[mask] = min(dp[mask], a[poz][i] + dp[mask ^ (1 << poz)]);         dp[mask] = min(dp[mask], res[poz][i] + dp[mask ^ (mask & nmask[poz][i])]);       }     }     cout << dp[(1 << n) - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1100;   int n, a[maxn], ans, t;   void go(int lim) {     int ret = 0;     for (int i = 1; i <= n; i++)       ret +=           min(abs(a[i] - lim), min(abs(a[i] - (lim + 1)), abs(a[i] - (lim - 1))));     if (ret < ans) ans = ret, t = lim;   }   int main() {     scanf( %d , &n);     ans = INT_MAX;     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= 100; i++) go(i);     printf( %d %d n , t, ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long arr[500005];   long long brr[500005];   long long total[500005];   int n, r;   bool fnc(long long mid, long long k) {     for (int i = 1; i <= n; i++) brr[i] = 0;     long long d = 0;     for (int i = 1; i <= n; i++) {       d += brr[i];       if (total[i] + d < mid) {         long long x = (mid - (total[i] + d));         d += x;         int j = min(i + 2 * r + 1, n + 1);         brr[j] -= x;         k -= x;         if (k < 0) return 0;       }     }     return 1;   }   int main() {     long long k;     scanf( %d %d %I64d , &n, &r, &k);     for (int i = 1; i <= n; i++) scanf( %I64d , &arr[i]);     for (int i = 1; i <= n; i++) {       if (r == 0) {         brr[i] += arr[i];         brr[i + 1] -= arr[i];       } else {         int j = max(i - r, 1);         brr[j] += arr[i];         j = min(i + r + 1, n + 1);         brr[j] -= arr[i];       }     }     long long d = 0;     for (int i = 1; i <= n; i++) {       d += brr[i];       total[i] = d;     }     long long mn = total[1];     for (int i = 2; i <= n; i++) mn = min(total[i], mn);     long long l = 0, h = 4000000000000000000;     long long ans = mn;     while (l <= h) {       long long mid = (l + h) / 2;       bool flag = fnc(mid, k);       if (flag) {         ans = mid;         l = mid + 1;       } else         h = mid - 1;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   using cat = long long;   struct group {     char c;     int l, r;     group operator+(int x) const { return {c, l + x, r + x}; }     group operator-(int x) const { return {c, l - x, r - x}; }   };   void apply(vector<group>& gA, vector<group>& gB, int prefA, int prefB,              vector<group>& gA_nw, vector<group>& gB_nw) {     for (int i = 0; i < prefA; i++) gB_nw.push_back(gA[i]);     for (int i = 0; i < prefB; i++) gA_nw.push_back(gB[i]);     if (gB_nw.empty() || gB_nw.back().c != gB[prefB].c) {       int dl = -gB[prefB].l + (gB_nw.empty() ? 0 : gB_nw.back().r);       for (int i = prefB; i < (int)gB.size(); i++) gB_nw.push_back(gB[i] + dl);     } else {       gB_nw.back().r += gB[prefB].r - gB[prefB].l;       if (prefB + 1 < (int)gB.size()) {         int dl = -gB[prefB + 1].l + gB_nw.back().r;         for (int i = prefB + 1; i < (int)gB.size(); i++)           gB_nw.push_back(gB[i] + dl);       }     }     gB_nw[0].l = 0;     if (gA_nw.empty() || gA_nw.back().c != gA[prefA].c) {       int dl = -gA[prefA].l + (gA_nw.empty() ? 0 : gA_nw.back().r);       for (int i = prefA; i < (int)gA.size(); i++) gA_nw.push_back(gA[i] + dl);     } else {       gA_nw.back().r += gA[prefA].r - gA[prefA].l;       if (prefA + 1 < (int)gA.size()) {         int dl = -gA[prefA + 1].l + gA_nw.back().r;         for (int i = prefA + 1; i < (int)gA.size(); i++)           gA_nw.push_back(gA[i] + dl);       }     }     gA_nw[0].l = 0;   }   void finish_ops(vector<group> gA, vector<group> gB,                   vector<pair<int, int> >& ans, int sw) {     for (int i = 0; i < (int)gA.size(); i++) gA[i].r -= gA[i].l;     for (int i = 0; i < (int)gB.size(); i++) gB[i].r -= gB[i].l;     for (int i = 1; i < (int)gA.size(); i++) {       if (sw == 0)         ans.push_back({gA[i - 1].r, gB[i - 1].r});       else         ans.push_back({gB[i - 1].r, gA[i - 1].r});       gA[i].r += gB[i - 1].r;       gB[i].r += gA[i - 1].r;     }   }   int decode(char c, int l) {     if (c >=  0  && c <=  9 ) return c -  0 ;     if (c ==  h ) return l / 2;     if (c ==  H ) return l / 2 + 1;     return -1;   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(10);     string S[2];     cin >> S[0] >> S[1];     bool ans_found = false;     vector<pair<int, int> > ans;     string ops[] = { 01 ,  10 ,  hh ,  hH ,  Hh ,  HH ,  h0 ,  H0 ,  0h ,  0H };     for (int k = 0; k < 2; k++) {       string A = S[k], B = S[1 - k];       bool sw = k;       A +=  a ;       B +=  b ;       vector<group> gA, gB;       for (int i = 0; i < (int)A.length(); i++)         if (i == 0 || A[i - 1] != A[i]) {           int l = i, r = i;           while (r < (int)A.length() && A[r] == A[i]) r++;           gA.push_back({A[i], l, r});         }       for (int i = 0; i < (int)B.length(); i++)         if (i == 0 || B[i - 1] != B[i]) {           int l = i, r = i;           while (r < (int)B.length() && B[r] == B[i]) r++;           gB.push_back({B[i], l, r});         }       if (gA.size() == gB.size() && (!ans_found || gA.size() - 1 < ans.size())) {         ans = vector<pair<int, int> >();         finish_ops(gA, gB, ans, sw);         ans_found = true;       }       int op_id[2];       for (op_id[0] = 0; op_id[0] < 6; op_id[0]++) {         int prefA0 = decode(ops[op_id[0]][0], gA.size()),             prefB0 = decode(ops[op_id[0]][1], gB.size());         if (prefA0 >= (int)gA.size() || prefB0 >= (int)gB.size()) continue;         vector<group> gA_nw0, gB_nw0;         apply(gA, gB, prefA0, prefB0, gA_nw0, gB_nw0);         if (gA_nw0.size() == gB_nw0.size() &&             (!ans_found || gA_nw0.size() < ans.size())) {           ans = vector<pair<int, int> >(1);           if (sw == 0)             ans[0] = {prefA0 ? gA[prefA0 - 1].r : 0,                       prefB0 ? gB[prefB0 - 1].r : 0};           else             ans[0] = {prefB0 ? gB[prefB0 - 1].r : 0,                       prefA0 ? gA[prefA0 - 1].r : 0};           finish_ops(gA_nw0, gB_nw0, ans, sw);           ans_found = true;         }         for (op_id[1] = 0; op_id[1] < 6; op_id[1]++) {           int prefA1 = decode(ops[op_id[1]][0], gA_nw0.size()),               prefB1 = decode(ops[op_id[1]][1], gB_nw0.size());           if (prefA1 >= (int)gA_nw0.size() || prefB1 >= (int)gB_nw0.size())             continue;           vector<group> gA_nw1, gB_nw1;           apply(gA_nw0, gB_nw0, prefA1, prefB1, gA_nw1, gB_nw1);           if (gA_nw1.size() == gB_nw1.size() &&               (!ans_found || gA_nw1.size() + 1 < ans.size())) {             ans = vector<pair<int, int> >(2);             if (sw == 0) {               ans[0] = {prefA0 ? gA[prefA0 - 1].r : 0,                         prefB0 ? gB[prefB0 - 1].r : 0};               ans[1] = {prefA1 ? gA_nw0[prefA1 - 1].r : 0,                         prefB1 ? gB_nw0[prefB1 - 1].r : 0};             } else {               ans[0] = {prefB0 ? gB[prefB0 - 1].r : 0,                         prefA0 ? gA[prefA0 - 1].r : 0};               ans[1] = {prefB1 ? gB_nw0[prefB1 - 1].r : 0,                         prefA1 ? gA_nw0[prefA1 - 1].r : 0};             }             finish_ops(gA_nw1, gB_nw1, ans, sw);             ans_found = true;           }         }       }     }     cout << ans.size() <<   n ;     for (auto it = ans.begin(); it != ans.end(); it++)       cout << it->first <<     << it->second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2123456789;   int a, b, c;   int n, m, k;   int x, y;   string s;   int start[500];   int target[500];   vector<pair<int, int> > ops;   int calendar[] = {0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};   int search(int base, int val) {     for (int i = base; i <= n; i++)       if (start[i] == val) return i;   }   int rotate(int s, int e) {     int rotations = 0;     if (s == e) return 0;     for (int i = s; i < e; i++) {       rotations++;       ops.push_back(make_pair(i, i + 1));       int tmp = start[i];       start[i] = start[i + 1];       start[i + 1] = tmp;     }     for (int i = e - 1; i > s; i--) {       rotations++;       ops.push_back(make_pair(i - 1, i));       int tmp = start[i - 1];       start[i - 1] = start[i];       start[i] = tmp;     }     return rotations;   }   int main() {     cin >> n;     int ans = 0;     for (int i = 1; i <= n; i++) cin >> target[i];     for (int i = 1; i <= n; i++) cin >> start[i];     for (int i = 1; i <= n; i++) {       int pos = search(i, target[i]);       ans += rotate(i, pos);     }     cout << ans << endl;     for (int i = 0; i < ops.size(); i++)       cout << ops[i].first <<     << ops[i].second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long int m, b, i, x, curr, ma = 0, tot, j;     cin >> m >> b;     for (i = 0; i <= b; i++) {       x = m * (b - i);       tot = 0;       for (j = i; j >= 0; j--) {         curr = x * (x + 1);         curr /= 2;         curr += (x + 1) * j;         tot += curr;       }       ma = max(tot, ma);     }     cout << ma;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class ST {    private:     vector<long long> st;     int n;     int left(int p) { return p << 1; }     int right(int p) { return left(p) + 1; }     int query(int p, int L, int R, int i) {       if (L > i) return 0;       if (R <= i) return st[p];       return query(left(p), L, (L + R) >> 1, i) +              query(right(p), ((L + R) >> 1) + 1, R, i);     }     int update(int p, int L, int R, int idx) {       if (L > idx || R < idx) return st[p];       if (L == R) {         return ++st[p];       }       return st[p] = update(left(p), L, (L + R) >> 1, idx) +                      update(right(p), ((L + R) >> 1) + 1, R, idx);     }       public:     ST(int _n) {       n = _n;       st.assign(4 * n, 0);     }     int query(int i) {       int ret = query(1, 0, n - 1, i);       update(i);       return ret;     }     void update(int idx) { update(1, 0, n - 1, idx); }   };   int main() {     int n;     map<long long, long long> mp;     long long ans = 0;     scanf( %I64d , &n);     vector<long long> vec(n), vec2(n);     for (long long i = 0; i < n; i++) scanf( %I64d , &vec[i]), vec2[i] = vec[i];     ST st(n);     sort(vec2.begin(), vec2.end());     for (long long i = 0; i < n; i++) mp[vec2[i]] = i;     for (long long i = 0; i < n - 1; i++) {       long long q = st.query(mp[vec[i]]);       ans += (i - q) * (mp[vec[i]] - q);     }     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, x, y, b;       cin >> n >> x >> y;       b = n;       int t = y - x, i, k;       for (i = n - 1; i >= 1; i--) {         if (t % i == 0) break;       }       n = n - (i - 1) - 2;       k = t / i;       int c = x / k;       c = min(c, n);       n = n - c;       if (x - c * k == 0) c--;       i = 0;       while (i < b) {         cout << (x - c * k) + i * k <<    ;         i++;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int T;     cin >> T;     while (T--) {       long long n, k;       cin >> n >> k;       long long res = 0;       while (n > 0) {         res += n % k;         n -= n % k;         if (n == 0) break;         res++;         n /= k;       }       cout << res <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     string str;     cin >> n;     cin >> str;     int len = n - 11;     int coun = 0, cou = 0;     for (int j = 0; j < len + 1; j++) {       if (str[j] ==  8 ) coun = 1, cou++;       ;     }     if (cou > len / 2)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:268435456 )   using namespace std;   template <typename T>   T sqr(const T &x) {     return x * x;   }   template <typename T>   T my_abs(const T &x) {     return x < 0 ? -x : x;   }   const int INF = (int)1e9;   const long long LINF = (long long)6e18;   const long long INF64 = LINF;   const long long INFLL = LINF;   const long double EPS = 1e-8;   const long double PI = 3.1415926535897932384626433832795;   const long double ME = 1e-5;   const long long MOD = (int)1e9 + 7;   const long long MOD2 = (int)1e9 + 21;   const int dx[] = {-1, 0, 1, 0};   const int dy[] = {0, 1, 0, -1};   const int SQN = 400;   const int LOGN = 20;   const int N = (int)1e5 + 10;   const int M = (int)1e5 + 10;   map<string, int> hosts;   map<string, int> paths;   map<int, set<int>> nums;   string oh[N];   char buf[100];   pair<vector<int>, int> a[N];   void solve() {     int n;     scanf( %d n , &n);     int idx_host = 0, idx_path = 0;     for (int i = 0; i < int(n); ++i) {       scanf( %s n , buf);       string s = string(buf);       string h =   ;       int cnt = 0;       int pos = 0;       while (pos < int(s.size())) {         if (s[pos] ==  / ) {           cnt++;         }         if (cnt == 3) {           break;         }         h.push_back(s[pos++]);       }       string p =   ;       while (pos < int(s.size())) {         p.push_back(s[pos++]);       }       if (!hosts.count(h)) {         oh[idx_host] = h;         hosts[h] = idx_host++;       }       if (!paths.count(p)) {         paths[p] = idx_path++;       }       nums[hosts[h]].insert(paths[p]);     }     int idx = 0;     for (auto it = nums.begin(); it != nums.end(); ++it) {       a[idx].first.resize(int(it->second.size()));       a[idx].second = it->first;       int pos = 0;       for (auto i = it->second.begin(); i != it->second.end(); ++i) {         a[idx].first[pos++] = *i;       }       idx++;     }     sort(a, a + idx);     vector<vector<int>> ans;     ans.push_back(vector<int>());     for (int i = 1; i < int(idx); ++i) {       bool ok = true;       if (int(a[i].first.size()) != int(a[i - 1].first.size())) {         ok = false;       } else {         for (int j = 0; j < int(int(a[i].first.size())); ++j) {           if (a[i].first[j] != a[i - 1].first[j]) {             ok = false;             break;           }         }       }       if (ok) {         if (int(ans.back().size()) == 0) {           ans.back().push_back(a[i - 1].second);         }         ans.back().push_back(a[i].second);       } else {         if (int(ans.back().size()) != 0) {           ans.push_back(vector<int>());         }       }     }     if (int(ans.back().size()) == 0) {       ans.pop_back();     }     printf( %d n , ans.size());     for (int i = 0; i < int(int(ans.size())); ++i) {       for (int j = 0; j < int(int(ans[i].size())); ++j) {         printf( %s  , oh[ans[i][j]].c_str());       }       printf(  n );     }   }   int main() {     srand((unsigned int)time(NULL));     cout << setprecision(10) << fixed;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, k, par[N], siz[N];   bool inv[N];   multiset<int> S;   struct dist {     int val, id;   };   dist tab[N];   bool cmp(dist x, dist y) { return x.val < y.val; }   int Find(int x) {     if (par[x] != x) par[x] = Find(par[x]);     return par[x];   }   void Union(int x, int y) {     x = Find(x);     y = Find(y);     par[x] = y;     S.erase(S.find(siz[x]));     S.erase(S.find(siz[y]));     siz[y] += siz[x];     S.insert(siz[y]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &tab[i].val);       tab[i].id = i;     }     sort(tab + 1, tab + n + 1, cmp);     int ans = 0, ile = 0;     multiset<int>::iterator low, high;     for (int i = 1; i <= n; i++) {       int x = tab[i].id;       inv[x] = 1;       S.insert(1);       siz[x] = 1;       par[x] = x;       if (inv[x - 1]) Union(x - 1, x);       if (inv[x + 1]) Union(x + 1, x);       low = S.begin();       high = S.end();       high--;       if (*high == *low) {         if (ile < S.size()) {           ile = S.size();           ans = tab[i].val + 1;         }       }     }     printf( %d , ans);     return 0;   }