#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 1e18;   const int MAXN = 3e5 + 10;   const int MAXM = 1e4 + 500;   const int N = 5600 + 15;   const double EPS = 1e-9;   double len(complex<long long> a) {     return sqrt(a.real() * a.real() + a.imag() * a.imag());   }   long long sq(complex<long long> a) {     return a.real() * a.real() + a.imag() * a.imag();   }   complex<long long> perp(complex<long long> p) { return {-p.imag(), p.real()}; }   long long dotProduct(complex<long long> a, complex<long long> b) {     return (conj(a) * b).real();   }   long long crossProduct(complex<long long> a, complex<long long> b) {     return (conj(a) * b).imag();   }   long long orient(complex<long long> a, complex<long long> b,                    complex<long long> c) {     return crossProduct(b - a, c - a);   }   bool inDisk(complex<long long> a, complex<long long> b, complex<long long> p) {     return dotProduct(a - p, b - p) <= 0;   }   bool onSegment(complex<long long> a, complex<long long> b,                  complex<long long> p) {     return orient(a, b, p) == 0 && inDisk(a, b, p);   };   struct cmpX {     bool operator()(complex<long long> a, complex<long long> b) {       return make_pair(a.real(), a.imag()) < make_pair(b.real(), b.imag());     }   };   struct line {     complex<long long> v;     long long c;     line(complex<long long> v, long long c) : v(v), c(c) {}     line(long long a, long long b, long long c) : v({b, -a}), c(c) {}     line(complex<long long> p, complex<long long> q)         : v(q - p), c(crossProduct(v, p)) {}     long long side(complex<long long> p) { return crossProduct(v, p) - c; }     double dist(complex<long long> p) { return abs(side(p)) / len(v); }     line perpThrough(complex<long long> p) { return {p, p + perp(v)}; }     bool cmpProj(complex<long long> p, complex<long long> q) {       return dotProduct(v, p) < dotProduct(v, q);     }     line translate(complex<long long> t) { return {v, c + crossProduct(v, t)}; }     complex<long long> proj(complex<long long> p) {       return p - perp(v) * side(p) / sq(v);     }   };   double segPoint(complex<long long> a, complex<long long> b,                   complex<long long> p) {     if (a != b) {       line l(a, b);       if (l.cmpProj(a, p) && l.cmpProj(p, b)) return l.dist(p);     }     return min(abs(p - a), abs(p - b));   }   bool inAngle(complex<long long> a, complex<long long> b, complex<long long> c,                complex<long long> p) {     if (orient(a, b, c) < 0) swap(b, c);     return orient(a, b, p) >= 0 && orient(a, c, p) <= 0;   }   bool isInsidePol(vector<complex<long long> > &a, complex<long long> b) {     int n = a.size();     int pos = 0, neg = 0;     for (int i = 0; i < n - 1; i++) {       if (onSegment(a[i], a[(i + 1) % n], b)) return false;       line l(a[i], a[i + 1]);       if (l.side(b) > 0)         pos++;       else         neg++;     }     line l(a[n - 1], a[0]);     if (l.side(b) > 0)       pos++;     else       neg++;     return ((!pos && neg == n) || (!neg && pos == n));   }   long long i, j, k;   long long n, m, t;   long long binpow(long long val, long long deg) {     if (!deg) return 1;     if (deg & 1) return binpow(val, deg - 1) * val % MOD;     long long res = binpow(val, deg >> 1);     return (res * res) % MOD;   }   long long inv(long long a, long long m) { return binpow(a, m - 2); }   long long add(long long a, long long b) { return (a += b) < MOD ? a : a - MOD; }   long long mul(long long a, long long b) { return a * b % MOD; }   long long cleverMulMod(long long a, long long b) {     if (b == 0) return 0;     long long s = cleverMulMod(a, b / 2);     if (b % 2 == 1)       return (a % MOD + 2ll * (s % MOD)) % MOD;     else       return (2ll * (s % MOD)) % MOD;   }   class Matrix {    public:     vector<vector<long long> > A;     int dim;     Matrix(int n) : dim(n) { A.assign(n, vector<long long>(n)); }     vector<long long> &operator[](int n) { return A[n]; }   };   Matrix operator*(Matrix A, Matrix B) {     int n = A.dim;     Matrix C(n);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         for (int k = 0; k < n; k++) {           C[i][j] = add(C[i][j], mul(A[i][k], B[k][j]));         }     return C;   }   Matrix operator^(Matrix A, long long k) {     int n = A.dim;     Matrix R(n);     for (int i = 0; i < n; i++) R[i][i] = 1;     while (k > 0) {       if (k % 2) R = R * A;       A = A * A;       k /= 2;     }     return R;   }   long long first, second, need;   bool check(long long k) {     long long total = 2 * k * (k + 1) + 1;     k++;     if (k > first) {       total -= (k - first) * (k - first);     }     if (k > second) {       total -= (k - second) * (k - second);     }     if (k > n - first) {       total -= (k - (n - first)) * (k - (n - first));     }     if (k > n - second) {       total -= (k - (n - second)) * (k - (n - second));     }     if (k > first + second) {       total += (k - (first + second)) * (k - (first + second) + 1) / 2;     }     if (k + first > n + second) {       total += (k + first - n - second) * (k + first - n - second + 1) / 2;     }     if (k + first + second - n - n > 0) {       total +=           (k + first + second - n - n) * (k + first + second - n - n + 1) / 2;     }     if (k + second > n + first) {       total += (k + second - n - first) * (k + second - n - first + 1) / 2;     }     return total >= need;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> first >> second >> need;     n++;     long long left = 0, right = 1e9 + 3;     while (right - left > 1) {       long long mid = (right + left) / 2;       if (check(mid))         right = mid;       else         left = mid;     }     if (check(left)) right = left;     cout << right << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, long long> solve(long long n) {     if (!n) return {0, 0};     long long a = 1;     while ((a + 1) * (a + 1) * (a + 1) <= n) a++;     pair<int, long long> r1 = solve(n - a * a * a),                          r2 =                              solve((a * a * a) - 1 - (a - 1) * (a - 1) * (a - 1));     if (r1.first > r2.first) return {1 + r1.first, r1.second + a * a * a};     if (r1.first < r2.first)       return {1 + r2.first, r2.second + (a - 1) * (a - 1) * (a - 1)};     return {1 + r1.first,             max(a * a * a + r1.second, (a - 1) * (a - 1) * (a - 1) + r2.second)};   }   int main() {     long long n;     scanf( %lld , &n);     pair<int, long long> r = solve(n);     printf( %d %lld n , r.first, r.second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unordered_map<int, int> X, pre;   unordered_map<int, int>::iterator it;   int Find(int u) {     it = pre.find(u);     if (it == pre.end()) {       X[u] = 0;       return u;     }     int v = it->second;     int tmp = Find(v);     X[u] ^= X[v];     return pre[u] = tmp;   }   bool join(int a, int b, int x) {     int c = Find(a), d = Find(b);     if (c == d) return false;     pre[d] = c;     X[d] = X[a] ^ X[b] ^ x;     return true;   }   int main() {     int q, last = 0;     scanf( %d , &q);     while (q--) {       int tp, a, b;       scanf( %d%d%d , &tp, &a, &b);       a ^= last;       b ^= last;       if (a > b) swap(a, b);       b++;       if (tp == 1) {         int x;         scanf( %d , &x);         join(a, b, x ^ last);       } else {         if (Find(a) != Find(b))           last = -1;         else           last = X[a] ^ X[b];         printf( %d n , last);         last = abs(last);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int tc;     cin >> tc;     while (tc--) {       int test = 0;       int t[1005];       int n, x, nb1 = 0, nb2 = 0, i;       cin >> n >> x;       for (i = 0; i < n; i++) {         cin >> t[i];         if (t[i] % 2 == 0)           nb1++;         else           nb2++;       }       if (nb1 > 0 && x - nb1 > 0 && nb2 >= x - nb1 && (x - nb1) % 2 != 0)         cout <<  Yes  << endl;       else if (nb1 > 0 && x - nb1 + 1 > 0 && nb2 >= x - nb1 + 1 &&                (x - nb1 + 1) % 2 != 0)         cout <<  Yes  << endl;       else if (nb1 > 0 && x - nb1 <= 0 && nb2 >= 1)         cout <<  Yes  << endl;       else if (nb1 == 0 && x % 2 != 0 && nb2 >= x)         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   char a[55][55];   int n, m, x;   int dist(int p, int q, int r, int s) {     return (p - r) * (p - r) + (q - s) * (q - s);   }   int ok[128] = {}, appear[128] = {};   char s[1000000];   int main(void) {     scanf( %d%d%d , &n, &m, &x);     for (int i = 0; i < n; i++) scanf( %s , a[i]);     int S = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (a[i][j] ==  S ) {           S = 1;           for (int u = 0; u < n; u++)             for (int v = 0; v < m; v++)               if (dist(i, j, u, v) <= x * x) {                 ok[(int)a[u][v]] = 1;               }         } else           appear[(int)a[i][j]] = 1;     scanf( %d , &n);     scanf( %s , s);     int ans = 0, f = 0;     for (int i = 0; s[i]; i++)       if (s[i] >=  A  && s[i] <=  Z ) {         if (!S || !appear[s[i] + 32]) f = 1;         ans += !ok[s[i] + 32];       } else if (!appear[(int)s[i]])         f = 1;     if (f) ans = -1;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const long long ooo = 9223372036854775807ll;   const int _cnt = 1000 * 1000 + 7;   const int _p = 1000 * 1000 * 1000 + 7;   const int N = 300005;   const double PI = acos(-1.0);   const double eps = 1e-9;   int o(int x) { return x % _p; }   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a / gcd(a, b) * b; }   void file_put() {     freopen( filename.in ,  r , stdin);     freopen( filename.out ,  w , stdout);   }   int n, a[N], L, t;   long long ret = 0;   int main() {     scanf( %d , &n);     for (int i = (1); i <= (n); ++i) scanf( %d , &a[i]), ret += a[i];     for (int i = (1); i <= (n); ++i) {       if (a[i] >= 2)         t = ((a[i] >> 1) < (L) ? (a[i] >> 1) : (L)), a[i] -= t << 1, L -= t;       a[i] %= 3, L += a[i];     }     printf( %lld n , (ret - L) / 3);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> gr;   vector<long long> c;   vector<int> parent;   vector<int> size;   vector<char> used;   void make_set(int v) {     parent[v] = v;     size[v] = 1;   }   int find_set(int v) {     if (v == parent[v]) return v;     return parent[v] = find_set(parent[v]);   }   void union_sets(int a, int b) {     a = find_set(a);     b = find_set(b);     if (a != b) {       if (size[a] < size[b]) swap(a, b);       parent[b] = a;       size[a] += size[b];     }   }   long long binpow(long long a, int n) {     long long res = 1;     while (n) {       if (n & 1) {         res *= a;         res %= 1000000007;       }       a *= a;       a %= 1000000007;       n >>= 1;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     long long k;     cin >> n >> m >> k;     c.resize(n);     for (int i = 0; i < n; ++i) cin >> c[i];     vector<map<long long, int>> adjacent(n);     vector<pair<int, int>> edges(m);     parent.resize(m);     size.resize(m);     used.resize(m, 0);     for (int i = 0; i < m; ++i) {       make_set(i);       int a, b;       cin >> a >> b;       --a, --b;       edges[i].first = a;       edges[i].second = b;     }     for (int i = 0; i < m; ++i) {       int from = edges[i].first;       int to = edges[i].second;       long long xr = c[to] ^ c[from];       {         auto found = adjacent[from].find(xr);         if (found != adjacent[from].end()) {           union_sets(i, found->second);         } else {           adjacent[from][xr] = i;         }       }       {         auto found = adjacent[to].find(xr);         if (found != adjacent[to].end()) {           union_sets(i, found->second);         } else {           adjacent[to][xr] = i;         }       }     }     vector<set<int>> subgraphs(m);     for (int i = 0; i < m; ++i) {       int comp = find_set(i);       int from = edges[i].first;       int to = edges[i].second;       subgraphs[comp].insert(from);       subgraphs[comp].insert(to);     }     long long ans = binpow(2, n + k);     map<long long, long long> q;     for (int i = 0; i < m; ++i) {       int comp = find_set(i);       if (!used[comp]) {         used[comp] = 1;         int from = edges[i].first;         int to = edges[i].second;         long long xr = c[to] ^ c[from];         q[xr] += subgraphs[comp].size() - 1;       }     }     for (auto it = q.begin(); it != q.end(); ++it) {       ans -= binpow(2, n);       if (ans < 0) ans += 1000000007;       ans += binpow(2, n - it->second);       ans %= 1000000007;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[100005], b[100005];   int l[100005], r[100005];   using pii = pair<int, int>;   using ppi = pair<pii, int>;   int tr[100005 * 2];   int get(int k) {     int res = 0;     for (; k; k -= k & -k) res += tr[k];     return res;   }   void update(int k) {     for (; k <= m; k += k & -k) tr[k]++;   }   void calc(int *g, int *gg) {     vector<ppi> V;     for (int i = 1; i <= n; i++)       V.push_back(ppi(pii(min(a[i], b[i]), max(a[i], b[i])), i));     sort(V.begin(), V.end(), [](const ppi &x, const ppi &y) {       return x.first.second < y.first.second;     });     int cnt = 0;     memset(tr, 0, sizeof tr);     for (auto x : V) {       g[x.second] = cnt - get(x.first.first);       update(x.first.first);       cnt++;     }     reverse(V.begin(), V.end());     memset(tr, 0, sizeof tr);     cnt = 0;     for (auto x : V) {       gg[x.second] = cnt - get(x.first.second) + get(x.first.first);       update(x.first.first);       cnt++;     }     memset(tr, 0, sizeof tr);     for (auto x : V) update(x.first.second);     for (auto x : V) gg[x.second] += get(x.first.first);     return;   }   int main() {     scanf( %d , &n);     m = 2 * n;     for (int i = 1; i <= n; i++) scanf( %d %d , &a[i], &b[i]);     calc(l, r);     long long ans = 0;     for (int i = 1; i <= n; i++) {       int t = n - 1 - l[i] - r[i];       ans += 1ll * t * (l[i] + r[i]);     }     ans >>= 1;     for (int i = 1; i <= n; i++) ans += 1ll * l[i] * r[i];     ans = 1ll * n * (n - 1) * (n - 2) / 6 - ans;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %i , &n);     vector<pair<int, int>> tree(n);     for (int x = 0; x < n; x++) {       scanf( %i%i , &tree[x].first, &tree[x].second);     }     sort(tree.begin(), tree.end());     int current_day = 0;     for (int i = 0; i < n; i++) {       current_day =           (tree[i].second < tree[i].first && tree[i].second >= current_day)               ? tree[i].second               : tree[i].first;     }     printf( %i n , current_day);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   vector<string> ss;   double check(const string& x) {     double res = 0;     if (x.size() < 3) {       for (char c : x) {         res = res * 10 + (int)c -  0 ;       }       return res;     }     if (x[x.size() - 3] ==  . ) {       for (int i = 0; i < x.size() - 3; ++i) {         if (x[i] ==  . ) continue;         res = res * 10 + (int)x[i] -  0 ;       }       res += ((int)x[x.size() - 2] -  0 ) / 10.0;       res += ((int)x[x.size() - 1] -  0 ) / 100.0;       return res;     } else {       for (int i = 0; i < x.size(); ++i) {         if (x[i] ==  . ) continue;         res = res * 10 + (int)x[i] -  0 ;       }       return res;     }   }   int main(int argc, const char* argv[]) {     cin >> s;     for (int i = 0; i < s.size(); ++i) {       if (s[i] >=  0  && s[i] <=  9 ) {         for (int j = i; j < s.size(); ++j) {           if (j == s.size() - 1) {             ss.emplace_back(s.substr(i, j - i + 1));             i = j;             continue;           }           if (s[j] >=  a  && s[j] <=  z ) {             ss.emplace_back(s.substr(i, j - i));             i = j - 1;             break;           }         }       }     }     double ans = 0;     for (auto& x : ss) {       ans += check(x);     }     char sans[5000];     sprintf(sans,  %.2f , ans);     int len = (int)strlen(sans);     int cnt = (len - 3) % 3;     if (cnt == 0) cnt = 3;     for (int i = 0; i < cnt; ++i) putchar(sans[i]);     for (int i = cnt; i < len - 3; i += 3) {       if (cnt) putchar( . );       putchar(sans[i]);       putchar(sans[i + 1]);       putchar(sans[i + 2]);     }     if (sans[len - 1] !=  0  || sans[len - 2] !=  0 ) {       putchar( . );       putchar(sans[len - 2]);       putchar(sans[len - 1]);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000000000 )   using namespace std;   int n;   double a[500001], b[500001], p, q;   string st;   double calc(double y1) {     double y2 = 1.;     for (int i = 0; i < n; i++) {       y2 = min(y2, (1. - (a[i] * y1)) / b[i]);     }     double ret = p * y1 + q * y2;     return ret;   }   int main() {     cin >> n >> p >> q;     double maxi = 0;     for (int i = 0; i < n; i++) {       cin >> a[i] >> b[i];       maxi = max(a[i], maxi);     }     double l = 0, r = 1. / maxi;     for (int i = 0; i < 100; i++) {       double m1 = (fabs(l - r)) / 3;       double x1 = calc(l + m1), x2 = calc(r - m1);       if (x1 >= x2)         r = r - m1;       else         l = l + m1;     }     printf( %.10lf n , calc(l));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   vector<vector<int> > col;   vector<vector<int> > adj;   int color[N];   void dfs(int v, int p) {     set<int> st;     int toapply = 1;     for (int i = 0; i < col[v].size(); i++) {       int c = col[v][i];       if (color[c] != -1) st.insert(color[c]);     }     for (int i = 0; i < col[v].size(); i++) {       int c = col[v][i];       if (color[c] != -1) continue;       while (st.find(toapply) != st.end()) toapply++;       color[c] = toapply;       toapply++;     }     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (u == p) continue;       dfs(u, v);     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     col.resize(n + 5);     adj.resize(n + 5);     memset(color, -1, sizeof(color));     int mx = 1;     for (int i = 1; i <= n; i++) {       int s;       scanf( %d , &s);       mx = max(mx, s);       while (s--) {         int t;         scanf( %d , &t);         col[i].push_back(t);       }     }     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1, -1);     printf( %d n , mx);     for (int i = 1; i <= m; i++)       if (color[i] == -1) color[i] = 1;     for (int i = 1; i <= m; i++) printf( %d  , color[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 3e3 + 100;   const long long mod = 1e9 + 7;   const long long inf = 1e18;   long long n, dsu[maxn], sz[maxn], t[maxn], a[maxn], mx, s, ans;   pair<long long, pair<long long, long long> > e[maxn];   void init() {     mx = 0;     for (long long i = 1; i <= n; i++) {       dsu[i] = i;       sz[i] = 1;       t[i] = a[i] + sz[i];       mx = max(mx, t[i]);     }   }   long long root(long long v) {     if (dsu[v] == v) return v;     return root(dsu[v]);   }   bool Union(long long v, long long u) {     long long x = root(v), y = root(u);     if (x == y) return 1;     if (sz[x] < sz[y]) swap(x, y);     sz[x] += sz[y];     t[x] += t[y];     mx = max(mx, t[x]);     dsu[y] = x;     return 0;   }   bool isval(long long x) {     init();     for (long long i = 0; i < n - 1; i++) {       if (e[i].first < x) {         Union(e[i].second.first, e[i].second.second);       }     }     return (mx <= s);   }   int main() {     long long v, u, c;     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (long long i = 0; i < n - 1; i++) {       cin >> e[i].second.first >> e[i].second.second >> e[i].first;     }     for (long long i = 1; i <= n; i++) {       cin >> a[i];       s += a[i];     }     long long l = 0, r = 2e4, mid;     while (r - l > 1) {       mid = (l + r) / 2;       if (isval(mid))         l = mid;       else         r = mid;     }     cout << l;     return 0;   }


#include <bits/stdc++.h>   int min(int a, int b) { return a > b ? b : a; }   int max(int a, int b) { return a < b ? b : a; }   int main() {     int n, a, b, c, d, i, pos;     int sum, next;     while (~scanf( %d , &n)) {       int ans = 0;       for (i = 1; i <= 4; i++) {         scanf( %d%d%d%d , &a, &b, &c, &d);         a = min(a, b);         b = max(a, b);         c = min(c, d);         d = max(c, d);         if (a + c <= n) {           ans = 1;           pos = i;           next = a;         }       }       if (ans)         printf( %d %d %d n , pos, next, n - next);       else         printf( -1 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long l, r, x, y;   unsigned long long gcd(unsigned long long a, unsigned long long b) {     while (b > 0) {       unsigned long long t = b;       b = a % b;       a = t;     }     return a;   }   int main() {     cin >> l >> r >> x >> y;     if (x == y) {       if (x >= l && x <= r) {         cout << 1;         return 0;       }     }     unsigned long long number = 0;     l = 1 + ((l - 1) / x);     l *= x;     for (unsigned long long i = l; i * i <= x * y; i += x) {       unsigned long long p = x * y / i;       if (p * i == x * y && p >= l && p <= r && i <= r) {         if (gcd(p, i) == x) {           number += 2;           if (i == p) number--;         }       }     }     cout << number;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     cin >> n;     getline(cin, s);     while (n--) {       getline(cin, s);       bool L = false, M = false;       if (s.length() < 5) {         cout <<  OMG>.< I don t know!  << endl;         continue;       }       if (s.substr(0, 5) ==  miao. ) {         M = true;       }       if (s.substr(s.length() - 5) ==  lala. ) {         L = true;       }       if (M && L) {         cout <<  OMG>.< I don t know!  << endl;       } else if (M) {         cout <<  Rainbow s  << endl;       } else if (L) {         cout <<  Freda s  << endl;       } else {         cout <<  OMG>.< I don t know!  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     t = 1;     while (t--) {       int n;       cin >> n;       int a[n + 1];       a[1] = 0;       for (int i = 2; i <= n; i++) cin >> a[i];       vector<int> v;       v.push_back(n);       n = a[n];       v.push_back(n);       while (n != 1) {         v.push_back(a[n]);         n = a[n];       }       reverse(v.begin(), v.end());       for (auto x : v) cout << x <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(false);     long long n;     cin >> n;     set<long long> s = {-2, -1};     vector<long long> arr(n, 0);     while (n--) {       long long x;       cin >> x;       --x;       if ((*prev(s.end())) > x && (*prev(prev(s.end()))) < x)         ++arr[(*prev(s.end()))];       if ((*prev(s.end())) < x) --arr[x];       s.insert(x);     }     cout << (max_element(arr.begin(), arr.end()) - arr.begin() + 1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int s[105], d[105], c[105];   int ans[105] = {0};   vector<pair<int, int>> v;   int main() {     int tc;     tc = 1;     while (tc--) {       int n, m;       cin >> n >> m;       int flag = 1;       for (int i = 1; i <= m; i++) {         cin >> s[i] >> d[i] >> c[i];         if (d[i] - s[i] < c[i]) flag = 0;         ans[d[i]] = m + 1;         v.push_back({i, d[i]});       }       if (flag == 0) {         cout << -1 <<   n ;         continue;       }       sort(v.begin(), v.end(), [](pair<int, int> &a, pair<int, int> &b) {         return a.second < b.second;       });       flag = 1;       for (int i = 0; i < m; i++) {         int now = v[i].first;         int cnt = 0;         for (int j = s[now]; j < d[now] and cnt < c[now]; j++) {           if (ans[j] == 0) {             ans[j] = now;             cnt++;           }         }         if (cnt < c[now]) {           flag = 0;           break;         }       }       if (flag == 0)         cout << -1 <<   n ;       else {         for (int i = 1; i <= n; i++) cout << ans[i] <<    ;         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int t, n, m, a[3005] = {0};   string ans[3005];   vector<pair<string, int> > v[3005];   map<string, int> mp;   map<int, string> mp1;   vector<string> v1[3005];   int F(int x, int vis[]) {     int i, i1, i2, idx;     for (i = 0; i < v1[x].size(); i++) {       string s = v1[x][i];       i1 = mp[s];       if (!vis[i1]) {         vis[i1] = 1;         if (a[i1] < 0 || F(a[i1], vis)) {           a[i1] = x;           ans[x] = s;           return 1;         }       }     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int i, j, k, x, y, vis[3005] = {0};     string s1, s2;     cin >> n;     int cc = 1;     memset(a, -1, sizeof a);     for (i = 0; i < n; i++) {       cin >> s1 >> s2;       string temp = s1.substr(0, 3), temp1 = s1.substr(0, 2) + s2[0];       if (mp[temp] == 0) mp[temp] = cc++;       if (mp[temp1] == 0) mp[temp1] = cc++;       v[mp[temp]].push_back({temp1, i});       mp1[mp[temp]] = temp;     }     for (i = 1; i < cc; i++) {       s2 = mp1[i];       if (v[i].size() == 1) {         k = v[i][0].second;         s1 = v[i][0].first;         v1[k].push_back(s1);         v1[k].push_back(s2);         continue;       }       for (j = 0; j < v[i].size(); j++) {         s1 = v[i][j].first;         k = v[i][j].second;         v1[k].push_back(s1);       }     }     m = mp.size();     for (i = 0; i < n; i++) {       for (j = 0; j < m + 2; j++) vis[j] = 0;       if (F(i, vis))         continue;       else {         cout <<  NO ;         return 0;       }     }     cout <<  YES n ;     for (i = 0; i < n; i++) cout << ans[i] <<   n ;     cerr <<   n           <<  Time elapsed :  << clock() * 1000.0 / CLOCKS_PER_SEC <<   ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, a[100100], sum = 0, Min = 1e6;   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       if (a[i] < 0 && k) a[i] *= -1, k--;       Min = min(Min, abs(a[i]));       sum += a[i];     }     if (k & 1) sum -= Min * 2;     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;   long long power(long long a, long long n) {     long long p = 1;     while (n > 0) {       if (n % 2) {         p = p * a;       }       n >>= 1;       a *= a;     }     return p;   }   long long power(long long a, long long n, long long mod) {     long long p = 1;     while (n > 0) {       if (n % 2) {         p = p * a;         p %= mod;       }       n >>= 1;       a *= a;       a %= mod;     }     return p % mod;   }   void swap(char *a, char *b) {     char temp = *a;     *a = *b;     *b = temp;   }   long long int nCr(int n, int r) {     long long int C[r + 1];     memset(C, 0, sizeof(C));     C[0] = 1;     for (int i = 1; i <= n; i++) {       for (int j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]);     }     return C[r];   }   long long int countDer(int n) {     int der[n + 1];     der[0] = 1;     der[1] = 0;     der[2] = 1;     for (int i = 3; i <= n; ++i) der[i] = (i - 1) * (der[i - 1] + der[i - 2]);     return der[n];   }   int digitsum(long long a) {     int ans = 0;     while (a > 0) {       ans = ans + a % 10;       a = a / 10;     }     return ans;   }   int count(long long a) {     int temp = 0;     while (a > 0) {       a = a / 10;       temp++;     }     return temp;   }   int main() {     int n;     cin >> n;     char s[n];     for (int i = 0; i < n; i++) cin >> s[i];     sort(s, s + n);     for (int i = 0; i < n; i++) cout << s[i];     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 1005, maxD = 10, oo = 1e9;   int Len, dp[maxN][maxN];   int t[maxN][maxN], s[maxN], tool[maxN];   int n, perm[maxN], cost[maxD], cnt[maxN][maxD], lost[maxN];   bool flag = 0;   inline void solve(int i, int j, int d) {     int jp = 0, sum = 0;     for (int d2 = 0; d2 < maxD; d2++) {       int td = cnt[j][d2];       int fl = (d + 1 + d2) >= 10;       jp += fl * td;       sum += td * cost[(d + 1 + d2) % 10];       td = cnt[n][d2] - cnt[j][d2];       if (d2 == 0 && d == 0 && flag) td -= lost[n] - lost[j];       fl = (d + d2) >= 10;       jp += fl * td;       sum += td * cost[(d + d2) % 10];     }     dp[i + 1][jp] = max(dp[i + 1][jp], dp[i][j] + sum);     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     string r;     cin >> r;     int sz = r.size();     for (int i = 0; i < sz; i++) {       if (r[i] ==  ? )         s[sz - i - 1] = -1;       else         s[sz - i - 1] = r[i] -  0 ;     }     Len = max(Len, sz);     cin >> n;     for (int i = 0; i < n; i++) {       string tmp;       cin >> tmp;       int cz = tmp.size();       for (int j = 0; j < cz; j++) t[i][cz - j - 1] = tmp[j] -  0 ;       Len = max(Len, cz);       tool[i] = cz;     }     for (int i = 0; i < maxD; i++) cin >> cost[i];     dp[0][0] = 0;     for (int j = 1; j <= n; j++) dp[0][j] = -oo;     for (int i = 1; i < maxN; i++)       for (int j = 0; j < maxN; j++) dp[i][j] = -oo;     for (int i = 0; i < n; i++) perm[i] = i;     for (int i = 0; i < Len; i++) {       for (int j = 1; j <= n; j++) {         for (int d = 0; d < maxD; d++) cnt[j][d] = cnt[j - 1][d];         int d = t[perm[j - 1]][i];         cnt[j][d]++;         lost[j] = lost[j - 1];         if (tool[perm[j - 1]] <= i) lost[j]++;       }       if (i >= sz) flag = true;       for (int j = 0; j <= n; j++) {         if (s[i] != -1)           solve(i, j, s[i]);         else {           int st = 0;           if (i == sz - 1) st = 1;           for (int d = st; d < maxD; d++) solve(i, j, d);         }       }       vector<int> vc;       for (int d = maxD - 1; d >= 0; d--)         for (int j = 0; j < n; j++)           if (t[perm[j]][i] == d) vc.push_back(perm[j]);       for (int j = 0; j < n; j++) perm[j] = vc[j];     }     int ans = 0;     for (int j = 0; j <= n; j++) ans = max(ans, dp[Len][j] + j * cost[1]);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e6 + 7;   const int INF = 0x7fffffff;   long long c[maxn], s[maxn];   long long a[maxn], num[maxn];   int main() {     long long n, x, y;     while (cin >> n >> x >> y) {       long long ans = n * x;       memset(num, 0, sizeof(num));       for (int i = 1; i <= n; i++) {         cin >> a[i];         num[a[i]]++;       }       c[0] = s[0] = 0;       for (int i = 1; i <= 2e6; i++) {         c[i] = c[i - 1] + num[i];         s[i] = s[i - 1] + i * num[i];       }       long long p = (x + y - 1) / y;       for (int i = 2; i <= 1e6; i++) {         long long cur = 0;         for (int j = i; j <= 1e6 + i && cur < ans; j += i) {           int l = j - i, r = j;           int k = r - p;           k = max(k, l);           long long temp = (c[r] - c[k]) * j - (s[r] - s[k]);           cur += temp * y;           cur += (c[k] - c[l]) * x;         }         ans = min(ans, cur);       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct st {     int x, y;     bool operator<(const st o) const { return y < o.y || (y == o.y && x < o.x); }   };   long long a[1000000][2];   long long n, m, x, y;   long long M[1000000][2];   int main() {     cin >> n >> m;     cin >> M[0][0] >> M[0][1];     for (int i = 0; i < (int)(n); i++) {       for (int j = 0; j < (int)(2); j++) {         cin >> a[i][j];       }     }     for (int i = 1; i < 2 * n; i++) {       for (int j = 0; j < (int)(2); j++) {         M[i][j] = 2 * (a[(i - 1) % n][j]) - M[i - 1][j];       }     }     cout << M[m % (2 * n)][0] <<     << M[m % (2 * n)][1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c, d, n;   int main() {     while (~scanf( %I64d%I64d%I64d%I64d%I64d , &n, &a, &b, &c, &d)) {       long long mi = min(b - c, min(a - d, a + b - c - d)),                 ma = max(b - c, max(a - d, a + b - c - d));       long long num1 = min(n - ma, n), num2 = max(1 - mi, (long long)1), ans = 0;       ;       if (num1 < num2)         ans = 0;       else         ans = num1 - num2 + 1;       printf( %I64d n , n * ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int binarySearch(int arr[], int l, int r, int x) {     while (l <= r) {       int m = l + (r - l) / 2;       if (arr[m] == x) return m;       if (arr[m] < x)         l = m + 1;       else         r = m - 1;     }     return -1;   }   bool isprime(int n) {     if (n <= 1) return false;     for (int i = 2; i < n; i++)       if (n % i == 0) return false;     return true;   }   long long int factorial(int n) {     if (n == 0) return 1;     return n * factorial(n - 1);   }   int countDigit(long long n) {     int count = 0;     while (n != 0) {       n = n / 10;       ++count;     }     return count;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int v1, v2, t, d, sum = 0;     cin >> v1 >> v2 >> t >> d;     for (int i = 0; i < t; i++) sum += min(v2 + (t - 1 - i) * d, v1 + i * d);     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)(1e5 + 1e1);   const double PI = acos(-1.0);   long long a, m, t;   int main() {     cin >> m >> a;     if (a == 0 && m > 1) {       cout <<  No solution ;       return 0;     }     cout << a;     for (int i = 1; i < m; i++) cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     bool ok[999];     memset(ok, false, sizeof(ok));     ok[ A ] = true;     ok[ H ] = true;     ok[ I ] = true;     ok[ M ] = true;     ok[ O ] = true;     ok[ T ] = true;     ok[ U ] = true;     ok[ V ] = true;     ok[ W ] = true;     ok[ X ] = true;     ok[ Y ] = true;     static char s[199919];     scanf( %s , s + 1);     int n = strlen(s + 1);     bool flag = true;     for (int i = 1, j = n; i <= j; ++i, --j)       if (s[i] != s[j] || !ok[s[i]]) flag = false;     printf( %s n , flag ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   int dx[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};   int dy[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   long long to_int(string s) {     long long ans = 0;     for (int i = 0; i < s.size(); i++) {       ans = ans * 10 + (s[i] - 48);     }     return ans;   }   int l[100001];   int r[100001];   int a[100001];   int main() {     fast();     int d1, d2, d3, ans = 0;     cin >> d1 >> d2 >> d3;     if (d2 < d1) swap(d2, d1);     ans += d1;     ans += min(d3, d1 + d2);     ans += min(d2, d3 + d1);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-7;   const long long MOD = 1000000007LL;   const int INF = 0x3f3f3f3f;   const int _NAN = -0x3f3f3f3f;   const double EULC = 0.5772156649015328;   const int NIL = -1;   template <typename T>   void read(T &x) {     x = 0;     char ch = getchar();     long long f = 1;     while (!isdigit(ch)) {       if (ch ==  - ) f *= -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch - 48;       ch = getchar();     }     x *= f;   }   const int maxn = 2e5 + 10;   int arr[maxn];   int main(void) {     ios::sync_with_stdio(false);     int n;     while (cin >> n) {       if (~n & 1) {         cout <<  NO n ;         continue;       }       for (int i = 1; i <= n; ++i) {         if (i & 1) {           arr[i] = 2 * i - 1;           arr[i + n] = 2 * i;         } else {           arr[i] = 2 * i;           arr[i + n] = 2 * i - 1;         }       }       cout <<  YES n ;       for (int i = 1; i <= 2 * n; ++i)         cout << arr[i] << (i == 2 * n ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     string s;     cin >> s;     long long o = 0;     long long z = 0;     for (long long i = 0; i < n; i++)       if (s[i] ==  n )         o++;       else if (s[i] ==  z )         z++;     while (o--) cout << 1 <<    ;     while (z--) cout << 0 <<    ;   }   int main() {     long long t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   int add(int a, int b) {     a += b;     if (a >= MOD) a -= MOD;     if (a < 0) a += MOD;     return a;   }   int mul(int a, int b) { return a * 1ll * b % MOD; }   int binpow(int a, int b) {     int res = 1;     while (b) {       if (b & 1) res = mul(res, a);       a = mul(a, a);       b >>= 1;     }     return res;   }   vector<int> pr;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<int> c(n);     for (int i = 0; i < int(n); i++) cin >> c[i];     sort(c.begin(), c.end(), greater<int>());     pr.push_back(0);     for (int i = 0; i < int(n); i++) {       pr.push_back(add(pr.back(), c[i]));     }     int invn = binpow(n, MOD - 2);     for (int k = 1; k <= n; ++k) {       int ans = 0;       for (int i = 0, j = 0; i < n; i += k, ++j) {         ans = add(ans, mul(j, add(pr[min(n, i + k)], -pr[i])));       }       cout << mul(ans, invn) <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, cnt = 0;   long long a[623456], b[623456], v[9999999];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       v[a[i]] = 1;     }     for (int i = 1; i <= n; i++) {       cin >> b[i];       v[b[i]] = 1;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         long long x = a[i] ^ b[j];         if (v[x]) {           cnt++;         }       }     }     if (cnt % 2 == 0)       cout <<  Karen ;     else       cout <<  Koyomi ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200010;   struct Node {     long long dis, mxdis;     int id;     bool operator<(const Node &rhs) const {       if (dis == rhs.dis) return mxdis < rhs.mxdis;       return dis < rhs.dis;     }   } p[MAXN];   struct NO {     long long dis, mxdis;     int id;     NO(long long x, long long y, int z) {       dis = x, mxdis = y;       id = z;     }     bool operator<(const NO &rhs) const { return mxdis > rhs.mxdis; }   };   priority_queue<NO> q;   long long l[MAXN], r[MAXN];   struct Node1 {     long long val;     int id;     bool operator<(const Node1 &rhs) const { return val < rhs.val; }   } a[MAXN];   int ans[MAXN];   int main() {     int n, m, i;     while (scanf( %d%d , &n, &m) == 2) {       for (i = 0; i < n; i++) {         scanf( %lld%lld , &l[i], &r[i]);         if (i > 0) {           p[i].dis = l[i] - r[i - 1];           p[i].mxdis = r[i] - l[i - 1];           p[i].id = i;         }       }       sort(p + 1, p + n);       for (i = 0; i < m; i++) {         scanf( %lld , &a[i].val);         a[i].id = i;       }       sort(a, a + m);       int left = 1;       while (!q.empty()) q.pop();       int ok = 1;       if (n > m + 1) {         printf( No n );         continue;       }       for (i = 0; i < m; i++) {         while (a[i].val >= p[left].dis && left < n) {           q.push(NO(p[left].dis, p[left].mxdis, p[left].id));           left++;         }         if (!q.empty()) {           NO x = q.top();           q.pop();           if (x.mxdis >= a[i].val)             ans[x.id] = a[i].id + 1;           else {             ok = 0;             break;           }         }       }       if (ok && q.empty() && left == n) {         printf( Yes n );         for (i = 1; i < n; i++) printf( %d%c , ans[i], (i == n - 1) ?   n  :    );       } else         printf( No n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T modpow(T base, T exp) {     T result = 1;     while (exp > 0) {       if (exp & 1) result = (result * base);       base = (base * base);       exp >>= 1;     }     return result;   }   int main() {     queue<string> poss;     long long int n, q;     string x, y, poss1;     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> q;     map<string, vector<string> > m;     for (long long int(i) = (0); (i) < (q); (i)++) {       cin >> x >> y;       m[y].push_back(x);     }     map<string, vector<string> >::iterator it;     it = m.begin();     if ((*it).first !=  a ) {       cout << 0 << endl;       return 0;     } else {       for (long long int(i) = (0); (i) < (m[ a ].size()); (i)++)         poss.push((m[ a ])[i]);       int cnt = 2;       while (cnt != n) {         while ((poss.front()).length() != cnt + 1) {           string c = (poss.front()).substr(0, 1);           if (m.find(c) != m.end()) {             string str = poss.front();             poss.pop();             str = str.substr(1, str.length() - 1);             for (long long int(j) = (0); (j) < (m[c].size()); (j)++)               poss.push(m[c][j] + str);           } else             poss.pop();           if (poss.empty()) {             cout <<  0  << endl;             return 0;           }         }         cnt++;       }     }     cout << poss.size() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int arr[100005];   map<long long int, int> m;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %I64d , &arr[i]);     }     for (int i = 1; i <= n; i++) {       arr[i] += arr[i - 1];       m[arr[i]]++;     }     int maxVal = 0;     for (int i = 1; i <= n; i++) {       maxVal = max(maxVal, m[arr[i - 1]]);     }     printf( %d , n - maxVal);   }


#include <bits/stdc++.h>   using namespace std;   string solve() {     int a, b, n;     string number =   ;     cin >> a >> b >> n;     bool added;     added = false;     a *= 10;     for (int j = 1; j < 11; j++) {       if (a % b == 0) {         added = true;         break;       }       a++;     }     if (!added) return  -1 ;     number = to_string(a);     for (int i = 0; i < n - 1; i++) number +=  0 ;     return number;   }   int main(void) { cout << solve() <<   n ; }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[3003];   int cost[3003], par[3003];   bool vis[3003];   map<pair<int, int>, bool> mark;   void path(int x, int y) {     if (x == y) return;     cost[x] = 0;     path(par[x], y);   }   void dfs(int u) {     vis[u] = true;     for (int v : adj[u]) {       if (vis[v]) {         if (par[u] != v) {           cost[v] = 0;           if (!mark[{u, v}]) {             path(u, v);             mark[{u, v}] = mark[{v, u}] = true;           }         }       } else         par[v] = u, dfs(v);     }   }   void bfs(int src) {     queue<int> q;     q.push(src);     while (q.size()) {       int u = q.front();       q.pop();       for (int v : adj[u]) {         if (cost[v] == -1) {           cost[v] = cost[u] + 1;           q.push(v);         }       }     }   }   int main() {     int n, x, y;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     memset(cost, -1, sizeof cost);     par[1] = 1;     dfs(1);     memset(vis, false, sizeof vis);     for (int i = 1; i <= n; i++) {       if (cost[i] == 0) bfs(i);     }     for (int i = 1; i <= n; i++) cout << cost[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   long long a[200010];   vector<int> v[70];   int main() {     int i, j, n;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %lld , &a[i]);       for (j = 1; j < 63; j++) {         if (a[i] % (1LL << j)) {           v[j].push_back(i);           break;         }       }     }     int ans = 0, tmp = 0;     for (i = 1; i < 63; i++) {       if (ans < v[i].size()) {         ans = v[i].size();         tmp = i;       }     }     printf( %d n , n - ans);     for (i = 1; i < 63; i++) {       if (i == tmp) continue;       for (auto j : v[i]) printf( %lld  , a[j]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char a[100010];   vector<int> qe[710000];   map<pair<int, int>, int> dp;   long long hehe[20];   long long find(int x, int y) {     int k = y, n = 1;     while (k) {       n++;       k /= 10;     }     return hehe[n] * x + y;   }   int get(char a[], int n) {     int ans = 0;     for (int i = 0; i < n; i++) {       ans = ans * 27 + a[i] -  a  + 1;     }     return ans;   }   int getans(int x, int y, int n1, int n2) {     int ans = 78974453;     int ll, rr, l, r;     for (int i = 0; i < qe[x].size(); i++) {       l = qe[x][i];       r = l + n1;       int p = int(lower_bound(qe[y].begin(), qe[y].end(), l) - qe[y].begin());       if (p < qe[y].size()) {         rr = qe[y][p] + n2;         if (r > rr) rr = r;         ans = min(ans, rr - l);       }       p--;       if (p >= 0) {         rr = qe[y][p] + n2;         if (r > rr) rr = r;         ans = min(ans, rr - qe[y][p]);       }     }     return ans;   }   int main() {     int n, i, j, k, m;     int x, y;     char s1[5], s2[5];     hehe[1] = 1;     for (i = 2; i <= 15; i++) hehe[i] = hehe[i - 1] * 10;     scanf( %s , a);     n = strlen(a);     for (i = 0; i < n; i++) {       for (j = 1; j < 5; j++) {         if (j + i > n) break;         k = get(a + i, j);         qe[k].push_back(i);       }     }     scanf( %d , &m);     while (m--) {       scanf( %s%s , s1, s2);       int xx = strlen(s1);       int yy = strlen(s2);       x = get(s1, xx);       y = get(s2, yy);       if (qe[x].size() > qe[x].size() ||           (qe[x].size() == qe[y].size() && x > y)) {         swap(x, y);         swap(xx, yy);       }       int &ans = dp[pair<int, int>(x, y)];       if (!ans) ans = getans(x, y, xx, yy);       printf( %d n , ans == 78974453 ? -1 : ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p[100];   queue<int> q;   int main() {     ios::sync_with_stdio(false);     int n, m, k, t;     cin >> n >> m >> k;     for (int i = 0; i < k; ++i) cin >> p[i];     for (int i = 0; i < m * n; ++i) {       cin >> t;       q.push(t);     }     int an = 0;     for (int i = 0; i < m * n; ++i) {       for (int j = 0; j < k; ++j) {         if (p[j] == q.front())           for (int h = j; h > 0; --h) {             swap(p[h], p[h - 1]);             an++;           }       }       an++;       q.pop();     }     cout << an;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const string alf =  abcdefghijklmnopqrstuvwxyz ;   const int hashP = 239017;   const int N = 1e5 + 10;   const int MOD = 1e9 + 7;   const int MOD2 = 998244353;   const int INF = 1e9;   const long long INF2 = 1e18;   template <typename T>   bool umn(T &a, T b) {     return (a > b ? (a = b, 1) : 0);   }   template <typename T>   bool umx(T &a, T b) {     return (a < b ? (a = b, 1) : 0);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     string s = to_string(n);     long long dl = s.size();     long long ans = 0;     for (long long mask = 1; mask <= (1 << dl); mask++) {       long long ch = 0;       vector<long long> a;       for (int i = 0; i < dl; i++) {         long long c = (mask >> i) & 1;         a.push_back(c);       }       reverse(a.begin(), a.end());       for (int i = 0; i < dl; i++) {         ch *= 10;         long long c = a[i];         ch += c;       }       if (n >= ch) ans++;     }     cout << ans - 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2e9;   FILE* stream;   mt19937 rng(1337);   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < int(n); i++) {       cin >> a[i];     }     vector<int> b(n);     for (int i = 0; i < int(n); i++) {       if (i % 2) {         b[i] = a[i - 1];       } else {         b[i] = -a[i + 1];       }     }     for (int i = 0; i < int(n); i++) cout << b[i] <<    ;     cout << endl;     return;   }   signed main() {     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m, a[4005], b[4005];     bitset<4005> adj[4005];     cin >> n >> m;     vector<int> tam(n + 1);     for (int i = 0; i < m; i++) {       cin >> a[i] >> b[i];       adj[a[i]][b[i]] = 1;       adj[b[i]][a[i]] = 1;       tam[a[i]]++;       tam[b[i]]++;     }     int res = 1e9;     for (int i = 0; i < m; i++) {       for (int j = i + 1; j < m; j++) {         vector<int> v = {a[i], b[i], a[j], b[j]};         sort(v.begin(), v.end());         v.erase(unique(v.begin(), v.end()), v.end());         if (v.size() != 3) continue;         if (adj[v[0]][v[1]] && adj[v[1]][v[2]] && adj[v[2]][v[0]]) {           res = min(res, tam[v[0]] + tam[v[1]] + tam[v[2]] - 6);         }       }     }     if (res == 1e9)       cout << -1 <<   n ;     else       cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);   #define FF first   #define SS second   #define pb push_back   #define sz(x) (int)x.size()   #define oo 1e9   #define eps 1e-9   #define PI acos(-1.0)   #define lb lower_bound   #define ub upper_bound   #define all(a) (a).begin(), (a).end()   #define log2i(x) (64 - __builtin_clzll(1ll*(x)) - 1)   #define INF 0x7f7f7f7f   typedef long long ll;   typedef unsigned long long ull;   typedef pair<int, int> ii;   typedef pair<ii, ii> Li;   const int N = 2e5+7, M=100+7;   const int MOD = 1e9+7;   const int base=30;      int n, m, k, t;      int fac[N]{1}, invf[N]{1};      int add(int a, int b) {       a+=b; if(a>MOD) a-=MOD;       return a;   }   int mul(int a, int b) {return (1LL*a*b)%MOD;}   void gcd(int a, int b, int &x, int &y) {       if(!b) {x=1, y=0; return;}       int tx, ty; gcd(b, a%b, tx, ty);       x=ty, y=tx-(a/b)*ty;   }   int inv(int a) {       int x, y; gcd(a, MOD, x, y);       return (x%MOD+MOD)%MOD;   }   int nCk(int n, int k) {       if(n<k||k<0) return 0;       return mul(fac[n], mul(invf[n-k], invf[k]));   }      signed main() {       //freopen( test.inp ,  r , stdin);       //freopen( test.out ,  w , stdout);       //fastIO;       scanf( %d , &t);       for(int i=1;i<N;i++) {           fac[i]=mul(fac[i-1], i);           invf[i]=inv(fac[i]);       }       while(t--) {           scanf( %d%d%d , &n, &m, &k);           int r=min(1-m, k-n), ans=nCk(n, n/2);           if(n&1) ans=mul(ans, 2); ans=mul(ans, r);           for(int pos, neg, i=r+1; i<=r+n;i++) {               pos=max(0, m+i-1), neg=max(0, n-k+i);               int tmp=n-pos-neg;               if(tmp<0) break;               ans=add(ans, nCk(tmp, n/2-pos));               if(n&1) ans=add(ans, nCk(tmp, n/2-neg));           }           printf( %d n , ans);       }       return 0;   }   /* stuff you should look for       - int overflow, array   bounds       - special cases (n=1?)       - do smth instead of do nothing and stay organized       - WRITE STUFF DOWN       - DONT JUST STICK ON ONE APPROACH   */


#include <bits/stdc++.h>   using namespace std;   int n;   int ar[50][50];   int dp[51][51];   bool leaf[50];   vector<int> adj[50];   vector<int> adjw[50];   vector<int> leafs;   int bad;   vector<int> pos;   int go(int rem, int now) {     if (rem == 0) {       return 0;     }     if (dp[rem][now] != -1) {       return dp[rem][now];     }     int low = 0;     int high = 12500000;     while (low < high) {       int mid = (low + high + 1) / 2;       int temp = rem;       for (int i = 0; i < n; i++) {         if (!leaf[i] || i == now) {           continue;         }         int cur = 0;         while (temp > 0 && ar[now][i] + go(rem - cur - 1, i) >= mid) {           cur++;           temp--;         }       }       if (temp == 0) {         low = mid;       } else {         high = mid - 1;       }     }     dp[rem][now] = low;     return low;   }   void dfs(int now, int from) {     if (leaf[now]) {       leafs.push_back(now);     }     for (int i = 0; i < pos.size(); i++) {       if (now == pos[i]) {         bad++;       }     }     for (int i = 0; i < adj[now].size(); i++) {       int to = adj[now][i];       if (to != from) {         dfs(to, now);       }     }   }   void dfs(int now, int from, int root, int dist) {     ar[root][now] = dist;     for (int i = 0; i < adj[now].size(); i++) {       int to = adj[now][i];       if (to != from) {         dfs(to, now, root, dist + adjw[now][i]);       }     }   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     int maxw = 0;     for (int i = 1; i < n; i++) {       int a, b, w;       cin >> a >> b >> w;       a--;       b--;       adj[a].push_back(b);       adj[b].push_back(a);       adjw[a].push_back(w);       adjw[b].push_back(w);     }     for (int i = 0; i < n; i++) {       dfs(i, -1, i, 0);     }     for (int i = 0; i <= 50; i++) {       for (int j = 0; j <= 50; j++) {         dp[i][j] = -1;       }     }     for (int i = 0; i < n; i++) {       leaf[i] = adj[i].size() == 1;     }     int start, m;     cin >> start >> m;     start--;     for (int i = 0; i < m; i++) {       int x;       cin >> x;       x--;       pos.push_back(x);     }     int ans = 12500000;     for (int i = 0; i < adj[start].size(); i++) {       leafs.clear();       leafs.resize(0);       bad = 0;       dfs(adj[start][i], start);       if (bad == 0) {         continue;       }       int low = 0;       int high = 1250000;       while (low < high) {         int mid = (low + high + 1) / 2;         int temp = bad;         for (int z = 0; z < leafs.size(); z++) {           int cl = leafs[z];           if (cl == start) {             continue;           }           int cur = 0;           while (temp > 0 && ar[start][cl] + go(m - cur - 1, cl) >= mid) {             cur++;             temp--;           }         }         if (temp == 0) {           low = mid;         } else {           high = mid - 1;         }       }       ans = min(ans, low);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   const int maxn = 5e5 + 5;   int n, k;   vector<ii> g[maxn];   ll dp[maxn][2];   void solve(int u, int par) {     for (ii e : g[u]) {       int v = e.first;       ll w = e.second;       if (v - par) {         solve(v, u);       }     }     ll tot0 = 0;     vector<ll> pot;     for (ii e : g[u]) {       int v = e.first;       ll w = e.second;       if (v - par) {         tot0 += dp[v][0];         pot.emplace_back(w + dp[v][1] - dp[v][0]);       }     }     sort(pot.begin(), pot.end());     reverse(pot.begin(), pot.end());     dp[u][0] = dp[u][1] = tot0;     for (int i = 0; i < k and i < pot.size() and pot[i] > 0; i++) {       dp[u][0] += pot[i];     }     for (int i = 0; i < k - 1 and i < pot.size() and pot[i] > 0; i++) {       dp[u][1] += pot[i];     }   }   int main(int argc, char const *argv[]) {     int tc;     scanf( %d , &tc);     while (tc--) {       scanf( %d %d , &n, &k);       for (int i = 1; i <= n; i++) {         g[i].clear();       }       for (int i = 1; i < n; i++) {         int u, v, w;         scanf( %d %d %d , &u, &v, &w);         g[u].emplace_back(v, w);         g[v].emplace_back(u, w);       }       solve(1, -1);       printf( %lld n , dp[1][0]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[101] = {         0,     };     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int t;       scanf( %d , &t);       for (int j = 0; j < t; j++) {         int tmp;         scanf( %d , &tmp);         arr[tmp]++;       }     }     for (int i = 1; i <= 100; i++) {       if (arr[i] == n) printf( %d  , i);     }   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 200015;   const int nil = 100005;   int n;   set<pair<int, int> > S;   set<pair<int, int> > T;   int w[Maxn];   vector<pair<int, int> > cand[Maxn];   pair<int, int> res[Maxn];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       S.insert(pair<int, int>(x, y));     }     for (int i = 1; i <= n; i++) scanf( %d , &w[i]);     for (set<pair<int, int> >::iterator it = S.begin(); it != S.end(); it++) {       pair<int, int> p = *it;       if (S.find(pair<int, int>(p.first + 1, p.second)) == S.end() &&           S.find(pair<int, int>(p.first, p.second + 1)) == S.end()) {         cand[p.second - p.first + nil].push_back(p);         T.insert(p);       }     }     for (int i = n; i >= 1; i--) {       int diag = w[i] + nil;       if (cand[diag].empty()) {         printf( NO n );         return 0;       }       pair<int, int> p = cand[diag].back();       cand[diag].pop_back();       res[i] = p;       pair<int, int> u = pair<int, int>(p.first - 1, p.second);       if (S.find(u) != S.end() && T.find(u) == T.end()) {         cand[u.second - u.first + nil].push_back(u);         T.insert(u);       }       u = pair<int, int>(p.first, p.second - 1);       if (S.find(u) != S.end() && T.find(u) == T.end()) {         cand[u.second - u.first + nil].push_back(u);         T.insert(u);       }     }     printf( YES n );     for (int i = 1; i <= n; i++) printf( %d %d n , res[i].first, res[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base ::sync_with_stdio(false);     ;     cin.tie(NULL);     ;     long long int t = 1;     while (t--) {       long long int n;       cin >> n;       pair<long long int, long long int> tree[n];       long long int i, j, k;       map<pair<long long int, long long int>, long long int> mp;       for (i = 0; i < n; i++) {         cin >> j >> k;         tree[i].first = j;         tree[i].second = k;       }       list<long long int> l;       for (i = 0; i < n; i++) {         if (tree[i].first == 1) l.push_back(i);       }       vector<pair<long long int, long long int> > edges;       while (!l.empty()) {         long long int node = l.front();         l.pop_front();         if (tree[node].first == 0) continue;         long long int xors = tree[node].second;         tree[xors].first--;         tree[xors].second ^= node;         edges.push_back({node, xors});         if (tree[xors].first == 1) l.push_back(xors);       }       cout << edges.size() << endl;       for (auto x : edges) cout << x.first <<     << x.second << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-5;   const int p = 131;   const int inf = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const int N = 1e6 + 10;   long long Hash[N], fac[N];   char s[N], ss[N];   long long get(int l, int r) {     return (Hash[r] - Hash[l - 1] * fac[r - l + 1] % mod + mod) % mod;   }   void run() {     scanf( %s %s , s + 1, ss + 1);     int len1 = strlen(s + 1);     int len2 = strlen(ss + 1);     fac[0] = 1;     int n0 = 0, n1 = 0;     for (int i = 1; i <= len1; i++) {       n0 += (s[i] ==  0 );       n1 += (s[i] ==  1 );     }     for (int i = 1; i <= len2; i++) {       Hash[i] = (Hash[i - 1] * p % mod + ss[i] -  a  + 1) % mod;       fac[i] = fac[i - 1] * p % mod;     }     int res = 0;     for (int l0 = 1, l1; l0 < len2; l0++) {       if (l0 * n0 >= len2) break;       if ((len2 - l0 * n0) % n1) continue;       l1 = (len2 - l0 * n0) / n1;       long long hash0 = -1, hash1 = -1;       int idx = 1;       int flag = 1;       for (int j = 1; j <= len1; j++) {         if (s[j] ==  1 ) {           if (hash1 == -1) {             hash1 = get(idx, idx + l1 - 1);           } else if (hash1 != get(idx, idx + l1 - 1)) {             flag = 0;             break;           }           idx += l1;         } else {           if (hash0 == -1) {             hash0 = get(idx, idx + l0 - 1);           } else if (hash0 != get(idx, idx + l0 - 1)) {             flag = 0;             break;           }           idx += l0;         }         if (~hash0 && ~hash1 && hash0 == hash1) {           flag = 0;           break;         }       }       if (flag) res++;     }     printf( %d n , res);   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     char ch = getchar();     int fh = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) fh = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     x *= fh;   }   struct shj {     int we, l, r, fh;   } t[100010 * 6];   struct pte {     int l0, r0, l1, r1;   } g[100010];   struct teache {     int l, r;   } v[100010];   multiset<int> nl, nr;   int T1, T2, m, n, x, y, b1[100010], b2[100010], num, nt, anx = -1, any = -1,                                                            no[100010];   bool ans = 1, v1[100010];   vector<int> e[100010];   bool c1(const shj &a, const shj &b) {     if (a.we != b.we) return a.we < b.we;     return a.fh > b.fh;   }   void dfs(int no, int bi) {     b1[no] = bi;     b2[no] = num;     v1[no] = 0;     for (unsigned i = 0; i < e[no].size(); i++) {       if (v1[e[no][i]])         dfs(e[no][i], bi ^ 1);       else if (b1[no] == b1[e[no][i]])         ans = 0;     }   }   int main() {     read(T1);     read(T2);     read(n);     read(m);     for (int i = 1; i <= n; i++) {       read(v[i].l);       read(v[i].r);     }     for (int i = 1; i <= m; i++) {       read(x);       read(y);       e[x].push_back(y);       e[y].push_back(x);     }     for (int i = 1; i <= n; i++) v1[i] = 1;     for (int i = 1; i <= n; i++)       if (v1[i]) {         num++;         dfs(i, 0);       }     if (!ans) {       puts( IMPOSSIBLE );       return 0;     }     for (int i = 1; i <= num; i++) {       g[i].l0 = g[i].l1 = 0;       g[i].r0 = g[i].r1 = 1e9;     }     for (int i = 1; i <= n; i++) {       if (b1[i] == 0) {         g[b2[i]].l0 = max(g[b2[i]].l0, v[i].l);         g[b2[i]].r0 = min(g[b2[i]].r0, v[i].r);       } else {         g[b2[i]].l1 = max(g[b2[i]].l1, v[i].l);         g[b2[i]].r1 = min(g[b2[i]].r1, v[i].r);       }     }     for (int i = 1; i <= num; i++)       if (g[i].l0 > g[i].r0 || g[i].l1 > g[i].r1) {         puts( IMPOSSIBLE );         return 0;       }     for (int i = 1; i <= num; i++) {       pte no = g[i];       if (no.l0 > no.l1) {         swap(no.l0, no.l1);         swap(no.r0, no.r1);       }       t[++nt] = (shj){no.l0, no.l1, no.r1, 1};       t[++nt] = (shj){no.l1, no.l1, no.r1, -1};       if (no.r0 >= no.r1) {         t[++nt] = (shj){no.l1, no.l0, no.r0, 1};         t[++nt] = (shj){no.r1 + 1, no.l0, no.r0, -1};         t[++nt] = (shj){no.r1 + 1, no.l1, no.r1, 1};         t[++nt] = (shj){no.r0 + 1, no.l1, no.r1, -1};       } else {         t[++nt] = (shj){no.l1, no.l0, no.r1, 1};         t[++nt] = (shj){no.r0 + 1, no.l0, no.r1, -1};         t[++nt] = (shj){no.r0 + 1, no.l0, no.r0, 1};         t[++nt] = (shj){no.r1 + 1, no.l0, no.r0, -1};       }     }     sort(t + 1, t + nt + 1, c1);     for (int l = 1, r = 0; l <= nt; l = r + 1) {       while (t[r + 1].we == t[l].we && r + 1 <= nt) {         r++;         if (t[r].fh == 1) {           nl.insert(t[r].l);           nr.insert(t[r].r);         } else {           auto i = nl.find(t[r].l);           nl.erase(i);           auto j = nr.find(t[r].r);           nr.erase(j);         }       }       if (nl.size() == num) {         auto i = nl.end();         i--;         int al = (*i), ar = (*(nr.begin())), sl = t[l].we, sr = t[r + 1].we - 1;         if (al + sl > T2 || ar + sr < T1 || al > ar || sl > sr) continue;         if (al + sl >= T1) {           anx = sl;           any = al;         } else {           if (ar + sr <= T2) {             anx = sr;             any = ar;           } else {             if (al + sr > T2) {               anx = T1 - al;               any = al;             } else {               anx = sr;               any = T2 - sr;             }           }         }       }     }     if (anx == -1 && any == -1) {       puts( IMPOSSIBLE );       return 0;     }     puts( POSSIBLE );     printf( %d %d n , anx, any);     for (int i = 1; i <= num; i++)       if (anx <= g[i].r0 && anx >= g[i].l0 && any <= g[i].r1 && any >= g[i].l1)         no[i] = 0;       else         no[i] = 1;     for (int i = 1; i <= n; i++)       if (no[b2[i]] == b1[i])         putchar( 1 );       else         putchar( 2 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int vis[maxn], son[maxn], f[maxn], sum, root, ans[maxn];   vector<int> g[maxn];   void getroot(int x, int fa) {     son[x] = 1;     f[x] = 0;     for (int i = 0; i < g[x].size(); i++) {       int v = g[x][i];       if (v == fa || vis[v]) continue;       getroot(v, x);       son[x] += son[v];       f[x] = max(f[x], son[v]);     }     f[x] = max(f[x], sum - son[x]);     if (f[x] < f[root]) root = x;   }   void work(int x, int fa, int dep) {     ans[x] = dep;     vis[x] = 1;     for (int i = 0; i < g[x].size(); i++) {       int v = g[x][i];       if (vis[v]) continue;       sum = son[v], root = 0;       getroot(v, x);       work(root, x, dep + 1);     }   }   int main(void) {     int n;     while (~scanf( %d , &n) && n) {       for (int i = 1; i <= n; i++) g[i].clear();       int a, b;       for (int i = 0; i < n - 1; i++) {         scanf( %d %d , &a, &b);         g[a].push_back(b);         g[b].push_back(a);       }       f[0] = sum = n;       getroot(1, 0);       work(root, 0, 0);       for (int i = 1; i <= n; i++) {         printf( %c  , ans[i] +  A );       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using vi = vector<int>;   struct ele {     int value, jj, index;   };   bool ordena(ele a, ele b) { return a.value < b.value; }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int k, n;     cin >> k;     vector<ele> arr;     for (int i = 0; i < k; i++) {       int v[200010], sum = 0;       cin >> n;       for (int j = 0; j < n; j++) {         cin >> v[j];         sum += v[j];       }       for (int j = 0; j < n; j++) {         ele myele;         myele.value = sum - v[j];         myele.jj = j;         myele.index = i;         arr.push_back(myele);       }     }     sort(arr.begin(), arr.end(), ordena);     for (int i = 0; i < arr.size() - 1; i++) {       if (arr[i].value == arr[i + 1].value && arr[i].index != arr[i + 1].index) {         cout <<  YES  <<   n ;         cout << arr[i].index + 1 <<     << arr[i].jj + 1 <<   n ;         cout << arr[i + 1].index + 1 <<     << arr[i + 1].jj + 1 <<   n ;         return 0;       }     }     cout <<  NO  <<   n ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   signed main() {     int n, a, b;     cin >> n >> a >> b;     string s;     cin >> s;     vector<int> dp(n + 1, INT_MAX);     vector<vector<int> > lcp(n, vector<int>(n));     for (int i = n - 1; i >= 0; --i) {       for (int j = n - 1; j >= 0; --j) {         if (s[i] == s[j]) {           if (i == n - 1 || j == n - 1) {             lcp[i][j] = 1;           } else {             lcp[i][j] = 1 + lcp[i + 1][j + 1];           }         }       }     }     dp[0] = 0;     for (int i = 0; i < n; ++i) {       dp[i + 1] = min(dp[i + 1], dp[i] + a);       for (int j = 0; j < i; ++j) {         int k = min(lcp[i][j], i - j);         dp[i + k] = min(dp[i + k], dp[i] + b);       }     }     cout << dp[n];   }


#include <bits/stdc++.h>   using namespace std;   bool vis[100001];   int pi[100001];   int level[100001];   list<int> adj[100001];   void dfs(int s) {     vis[s] = 1;     bool flag = 1;     for (list<int>::iterator it = adj[s].begin(); it != adj[s].end(); ++it)       if (!vis[*it]) {         level[*it] = level[s] + 1;         pi[*it] = s;         dfs(*it);         flag = 0;       }     if (flag) {       int least = s;       stack<int> stk;       for (list<int>::iterator it = adj[s].begin(); it != adj[s].end(); ++it)         if (level[least] > level[(*it)]) least = *it;       while (s != least) {         stk.push(s);         s = pi[s];       }       stk.push(s);       cout << stk.size() <<   n ;       while (!stk.empty()) {         cout << stk.top() <<    ;         stk.pop();       }       exit(0);     }   }   int main() {     int n, m, k, i, l, r;     cin >> n >> m >> k;     for (i = 1; i <= m; ++i) {       cin >> l >> r;       adj[l].push_back(r);       adj[r].push_back(l);     }     pi[1] = -1;     dfs(1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename tn>   void read(tn &a) {     tn x = 0, f = 1;     char c =    ;     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     a = x * f;   }   const int N = 101000;   long long lim[8], lm[8];   int n;   struct point {     long long x, y, z;     long long getval(int k) {       return x * (k & 1 ? -1 : 1) + y * (k >> 1 & 1 ? -1 : 1) +              z * (k >> 2 & 1 ? -1 : 1);     }   } p[N], ans;   bool chk(int tag, long long *lim) {     long long l[4] = {(-lim[7] + 1 - 3 * tag) >> 1, (-lim[6] + 1 - tag) >> 1,                       (-lim[5] + 1 - tag) >> 1, (-lim[3] + 1 - tag) >> 1};     long long r[4] = {(lim[0] - 3 * tag) >> 1, (lim[1] - tag) >> 1,                       (lim[2] - tag) >> 1, (lim[4] - tag) >> 1};     long long a = l[1], b = l[2], c = l[3];     for (int i = 0; i < 4; i++)       if (r[i] < l[i]) return 0;     if (a + b + c > r[0]) return 0;     if (a + b + c < l[0]) {       a = min(r[1], l[0] - b - c);       b = min(r[2], l[0] - a - c);       c = min(r[3], l[0] - a - b);     }     if (a + b + c < l[0]) return 0;     ans = {b + c + tag, a + c + tag, a + b + tag};     return 1;   }   bool check(long long len) {     memcpy(lm, lim, sizeof(lm));     for (int i = 0; i < 8; i++) lm[i] += len;     if (chk(0, lm)) return 1;     if (chk(1, lm)) return 1;     return 0;   }   int main() {     int T;     read(T);     while (T--) {       read(n);       for (int i = 1; i <= n; i++) read(p[i].x), read(p[i].y), read(p[i].z);       memset(lim, 63, sizeof(lim));       for (int i = 1; i <= n; i++)         for (int j = 0; j < 8; j++) lim[j] = min(lim[j], p[i].getval(j));       long long l = -1, r = 4e18l + 1;       while (l + 1 < r) {         long long mid = l + r >> 1;         if (check(mid))           r = mid;         else           l = mid;       }       check(r);       cout << ans.x <<     << ans.y <<     << ans.z <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 7;   long long arr[maxn];   int vis[maxn];   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n;       if (n == 1) {         printf( YES n );         continue;       }       scanf( %d , &n);       n *= 4;       for (int i = 1; i <= n; i++) {         scanf( %lld , &arr[i]);       }       sort(arr + 1, arr + n + 1);       long long aver;       int mark = 1;       for (int i = 1, j = n - 1; i <= j; i += 2, j -= 2) {         if (arr[i] != arr[i + 1] || arr[j] != arr[j + 1]) {           mark = 0;           break;         }         if (i == 1) {           aver = arr[i] * arr[j];         } else if (arr[i] * arr[j] != aver) {           mark = 0;           break;         }       }       if (mark) {         printf( YES n );       } else {         printf( NO n );       }     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   long long dp[N][2];   struct segment {     int l, r;   };   auto cmp = [](segment& s1, segment& s2) {     if (s1.r != s2.r)       return s1.r < s2.r;     else       return s1.l > s2.l;   };   void solve() {     int n, m;     cin >> n >> m;     long long p[n + 2];     for (int i = 1; i <= n; i++) cin >> p[i];     p[0] = -1e10;     p[n + 1] = 1e10;     sort(p, p + n + 2);     vector<segment> s;     for (int i = 1; i <= m; i++) {       int l, r;       cin >> l >> r;       if (lower_bound(p, p + n + 2, l) != upper_bound(p, p + n + 2, r)) continue;       s.push_back((segment){l, r});     }     sort(s.begin(), s.end(), cmp);     for (int i = 1; i < s.size(); i++) {       if (s[i - 1].l >= s[i].l || s[i - 1].r == s[i].r)         s.erase(s.begin() + i), i--;     }     long long dp[n + 2][2];     for (int i = 1; i <= n + 1; i++) dp[i][0] = dp[i][1] = 1e15;     dp[0][0] = dp[0][1] = 0;     int now = 0;     for (int i = 1; i < n + 2; i++) {       vector<long long> l, r;       l.push_back(p[i - 1]);       while (now < s.size() && s[now].r < p[i]) {         l.push_back(s[now].l);         r.push_back(s[now].r);         now++;       }       r.push_back(p[i]);       for (int j = 0; j < l.size(); j++) {         dp[i][0] =             min(dp[i][0], dp[i - 1][0] + (l[j] - p[i - 1]) + 2 * (p[i] - r[j]));         dp[i][1] =             min(dp[i][1], dp[i - 1][0] + (l[j] - p[i - 1]) + (p[i] - r[j]));         dp[i][0] = min(dp[i][0],                        dp[i - 1][1] + 2 * (l[j] - p[i - 1]) + 2 * (p[i] - r[j]));         dp[i][1] =             min(dp[i][1], dp[i - 1][1] + 2 * (l[j] - p[i - 1]) + (p[i] - r[j]));       }     }     cout << min(dp[n + 1][0], dp[n + 1][1]) << endl;   }   int main() {     int T;     cin >> T;     while (T--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   inline long long int rand(long long int x, long long int y) {     ++y;     return (rng() % (y - x)) + x;   }   string to_string(char c) {     string second(1, c);     return second;   }   string to_string(bool b) { return (b ?  true  :  false ); }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto &x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   void degug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void degug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     degug_out(T...);   }   long long int n, fac[(300006)], dp[(300006)];   const long long int MOD = 998244353;   vector<long long int> v[(300006)];   void fact() {     fac[0] = fac[1] = 1;     for (long long int i = 2; i <= n; ++i) {       fac[i] = (i * fac[i - 1]) % MOD;     }     return;   }   void dfs(long long int x, long long int p) {     long long int ans = 1;     long long int child = 1;     for (auto i : v[x])       if (i != p) {         child++;         dfs(i, x);         ans *= dp[i];         ans %= MOD;       }     ans *= fac[child - 1];     ans %= MOD;     if (x != 1) ans *= child;     ans %= MOD;     return void(dp[x] = ans);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     fact();     for (long long int i = 0; i < (long long int)n - 1; ++i) {       long long int a, b;       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     dfs(1, 1);     cout << (dp[1] * n) % MOD;   }


#include <bits/stdc++.h>   const int maxn = 2e5 + 10;   int N;   int A[maxn];   long long Q[maxn];   long long sum1[maxn];   long long sum2[maxn];   double X(int i) { return i; }   double Y(int i) { return i * sum1[i] - sum2[i]; };   double slope(int i, int j) { return (Y(i) - Y(j)) / (X(i) - X(j)); }   long long Calc(int i, int j) {     return sum2[j] - sum2[i] - 1ll * i * (sum1[j] - sum1[i]);   }   int main() {     scanf( %d , &N);     for (register int i = 1; i <= N; i++) {       scanf( %d , &A[i]);       sum1[i] = sum1[i - 1] + A[i];       sum2[i] = sum2[i - 1] + 1ll * A[i] * i;     }     int tail = 0;     long long Ans = 0;     for (register int j = 1; j <= N; j++) {       long long k = sum1[j];       int l = 0, r = tail;       while (l < r) {         int mid = l + r >> 1;         if (slope(Q[mid], Q[mid + 1]) > k)           l = mid + 1;         else           r = mid;       }       int i = Q[r];       Ans = std::max(Ans, Calc(i, j));       while (tail >= 1 && slope(Q[tail], Q[tail - 1]) < slope(Q[tail], j)) tail--;       Q[++tail] = j;     }     printf( %I64d n , Ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, res;   int check(int a, int b) { return a < b; }   int main() {     scanf( %d%d , &a, &b);     if (a == b) {       printf( infinity );       return 0;     }     res = 0;     a -= b;     if (a < 0) {       printf( 0 );       return 0;     }     for (int i = 1; i * i <= a; i++)       if (!(a % i)) {         res += check(b, i);         if (i * i != a) res += check(b, a / i);       }     printf( %d , res);   }


#include <bits/stdc++.h>   using namespace std;   int n, m, c, l, r, cp, cm;   string s;   int main() {     cin >> n >> s;     for (int i = 0; i < n; i++) {       l = i - 1;       r = i;       cp = 1;       cm = 1;       while (l >= 0 && s[l] !=  L ) {         cp += (s[l] ==  R );         l--;       }       while (r < n - 1 && s[r] !=  R ) {         cm += (s[r] ==  L );         r++;       }       cout << max(cp, cm) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   struct node;   struct node {     node* arr[26];     int val;     node();     void insert(char ch[], int l, int pos);     void win();     void lose();   };   node::node() {     val = 0;     for (int i = 0; i < 26; i++) arr[i] = 0;   }   void node::insert(char ch[], int l, int pos) {     if (pos == l)       return;     else {       int index = ch[pos] -  a ;       if (arr[index] == 0) {         arr[index] = new node();         arr[index]->insert(ch, l, pos + 1);       } else {         arr[index]->insert(ch, l, pos + 1);       }     }   }   void node::win() {     int ind = 0;     for (int i = 0; i < 26; i++) {       if (arr[i] != 0) {         arr[i]->win();         ind = ind | arr[i]->val;       }     }     val = !ind;   }   void node::lose() {     int ind = 1;     int leaf = 1;     for (int i = 0; i < 26; i++) {       if (arr[i] != 0) {         leaf = 0;         arr[i]->lose();         ind = ind & arr[i]->val;       }     }     if (leaf)       val = leaf;     else       val = !ind;   }   int main() {     int n, k;     scanf( %d %d , &n, &k);     node* root = new node();     char ch[100000];     for (int i = 0; i < n; i++) {       scanf( %s , ch);       int l = strlen(ch);       root->insert(ch, l, 0);     }     int ind = 0;     for (int i = 0; i < 26; i++) {       if (root->arr[i] != 0) {         root->arr[i]->win();         ind = ind | root->arr[i]->val;       }     }     int w = ind;     ind = 0;     for (int i = 0; i < 26; i++) {       if (root->arr[i] != 0) {         root->arr[i]->lose();         ind = ind | !root->arr[i]->val;       }     }     int l = ind;     if (w & l) {       printf( First n );     } else if (w & !l) {       if (k & 1)         printf( First n );       else         printf( Second n );     } else       printf( Second n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char a, b;     cin >> a >> b;     int n;     cin >> n;     n = n % 4;     if (n == 0) {       cout <<  undefined ;       return 0;     }     int arr[] = {118, 60, 94, 62};     int arr2[] = {118, 62, 94, 60};     int i = 0;     for (i = 0; i < 4; i++) {       if (a == arr[i]) break;     }     char c = arr[i];     for (int j = 1; j <= n; j++) {       i = (i + 1) % 4;       c = arr[i];     }     int k = 0;     for (k = 0; k < 4; k++) {       if (a == arr2[k]) break;     }     char d = arr[k];     for (int j = 1; j <= n; j++) {       k = (k + 1) % 4;       d = arr2[k];     }     if (c == b && d == b)       cout <<  undefined ;     else if (c == b)       cout <<  cw ;     else       cout <<  ccw ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const long long INFL = 1e18 + 123;   const double PI = atan2(0, -1);   mt19937 tw(960172);   long long rnd(long long x, long long y) {     static uniform_int_distribution<long long> d;     return d(tw) % (y - x + 1) + x;   }   int cross(int x1, int y1, int x2, int y2) { return x1 * y2 - y1 * x2; }   bool inside(int x, int y, vector<pair<int, int> > poly) {     int s1 = 0, s2 = 0;     for (int i = 0; i < ((int)(poly).size()); ++i) {       int next = (i + 1) % ((int)(poly).size());       int tmp = cross(poly[i].first - x, poly[i].second - y, poly[next].first - x,                       poly[next].second - y);       s1 += tmp;       s2 += abs(tmp);     }     return abs(s1) == s2;   }   void solve() {     vector<pair<int, int> > poly[2];     for (int i = 0; i < 2; ++i) {       for (int j = 0; j < 4; ++j) {         int x, y;         cin >> x >> y;         poly[i].push_back({x, y});       }     }     for (int x = -150; x <= 150; ++x) {       for (int y = -150; y <= 150; ++y) {         if (inside(x, y, poly[0]) && inside(x, y, poly[1])) {           cout <<  YES n ;           return;         }       }     }     cout <<  NO n ;   }   int main() {     cerr << fixed << setprecision(15);     cout << fixed << setprecision(15);     ios::sync_with_stdio(false);     int tests = 1;     for (int it = 1; it <= tests; ++it) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int n, i, k = 0;   int main() {     cin >> s;     for (i = 0; i < s.size(); i++) {       while (s[i] == s[i + 1] && s.size()) {         s.erase(i, 2);         i--;         k++;       }     }     if (k % 2 != 0)       cout <<  YES  << endl;     else if (k % 2 == 0)       cout <<  No  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 100;   vector<int> ans;   set<pair<int, int>> add[MAX], rem[MAX], cur;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       add[x].insert({y, i});       rem[y + 1].insert({y, i});     }     for (int i = 1; i < MAX; i++) {       for (auto p : rem[i]) {         cur.erase(p);       }       for (auto p : add[i]) {         cur.insert(p);       }       while (cur.size() > k) {         set<pair<int, int>>::iterator it;         it = prev(cur.end());         ans.push_back((*it).second);         cur.erase(it);       }     }     cout << ans.size() << endl;     for (int x : ans) {       cout << x <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n], b[n], min, count = 0;       for (int i = 0; i < n; i++) {         cin >> a[i];         b[i] = a[i];       }       sort(b, b + n);       min = b[0];       for (int i = 0; i < n; i++) {         if (a[i] % min == 0 || a[i] == b[i]) {           count++;         } else           break;       }       if (count == n)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long n;     cin >> n;     long long ans = 0;     for (long long i = 1; i < n; i++) {       if (n % i == 0) {         ans++;       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   vector<pair<int, int> > v;   struct Node {     Node *left, *right;     int val;     int lazy;     Node() {       left = right = NULL;       val = 0;       lazy = 0;     }   };   inline void refresh(Node*& root, int x, int y) {     if (root->lazy != 0 && root->val != (y - x + 1)) {       root->val = 1LL * (y - x + 1) * root->lazy;       if (x == y) {         root->lazy = 0;         return;       }       if (root->left == NULL) {         root->left = new Node();       }       if (root->right == NULL) {         root->right = new Node();       }       root->left->lazy = root->lazy;       root->right->lazy = root->lazy;       root->lazy = 0;     }   }   inline void update(Node*& root, int x, int y, int b, int e, int val) {     refresh(root, x, y);     if (x > e || y < b || (root->val == y - x + 1)) {       return;     }     int mid = (x + y) / 2;     if (x >= b && y <= e) {       root->lazy = val;       refresh(root, x, y);       return;     }     if (root->left == NULL) {       root->left = new Node();     }     if (root->right == NULL) {       root->right = new Node();     }     update(root->left, x, mid, b, e, val);     update(root->right, mid + 1, y, b, e, val);     root->val = root->left->val + root->right->val;   }   int query(Node*& root, int x, int y, int b, int e) {     if (root == NULL || x > e || y < b) {       return 0;     }     refresh(root, x, y);     if (x >= b && y <= e) {       return root->val;     }     int mid = (x + y) / 2;     int L = query(root->left, x, mid, b, e);     int R = query(root->right, mid + 1, y, b, e);     return L + R;   }   vector<pair<int, int> > Q[N];   int ans[N];   int main() {     Node* root = new Node();     int n;     scanf( %d , &n);     ;     for (int i = 0; i < n; i++) {       int x, y;       scanf( %d , &x);       ;       scanf( %d , &y);       ;       v.push_back(make_pair(x, y));     }     int q;     scanf( %d , &q);     ;     for (int i = 0; i < q; i++) {       int x, y;       scanf( %d%d , &x, &y);       Q[x].push_back(make_pair(y, i));     }     for (int i = v.size() - 1; i >= 0; i--) {       update(root, 1, 1000000007, v[i].first,              min(v[i].first + v[i].second - 1, 1000000007), 1);       for (auto x : Q[i + 1]) {         int a = i;         int b = x.first;         int len = v[b - 1].first - v[a].first;         ans[x.second] =             len - query(root, 1, 1000000007, v[a].first, v[b - 1].first - 1);       }     }     int y;     for (int i = 0; i < q; i++) {       printf( %d n , ans[i]);     }   }


/*       Washief Hossain Mugdho       20 December 2020       Codeforces 691F   */      #include <bits/stdc++.h>   #define ull unsigned long long   #define ll long long   #define pb push_back   #define mp make_pair   #define fr first   #define sc second   #define fastio ios_base::sync_with_stdio(0)   #define untie cin.tie(0)   #define ms(a, b) memset(a, b, sizeof a)   using namespace std;      void run_tests()   {       string s;       cin >> s;       vector<int> bam(2 * s.size() + 1, 0);       vector<int> dan(2 * s.size() + 1, 0);       int pos = s.size();       for (auto c : s)       {           if (c ==  0 )               dan[pos++]++;           else               bam[pos--]++;       }       pos = s.size();       while (bam[pos] + dan[pos])       {           if (dan[pos] && (!bam[pos] || bam[pos + 1]))           {               dan[pos++]--;               cout << 0;           }           else           {               bam[pos--]--;               cout << 1;           }       }       cout << endl;   }      int main()   {       fastio;       untie;   #ifdef LOCAL_OUTPUT       freopen(LOCAL_OUTPUT,  w , stdout);   #endif   #ifdef LOCAL_INPUT       freopen(LOCAL_INPUT,  r , stdin);   #endif          int tc;       cin >> tc;       while (tc--)           run_tests();   }


#include <bits/stdc++.h>   using namespace std;   long long cnt[19], val[19];   void init() {     cnt[1] = 9, cnt[2] = 9, cnt[3] = 90;     val[1] = 1, val[2] = 10, val[3] = 100;     long long t = 100;     for (int i = 4; i <= 19; i++)       cnt[i] = t * 9, t *= 10, val[i] = val[i - 1] * 10;   }   long long cal(long long a) {     long long bit = 0, tmp, p = a;     while (p) {       tmp = p;       p /= 10;       bit++;     }     long long ans = 0;     for (int i = 1; i <= bit - 1; i++) {       ans += cnt[i];     }     if (bit > 2)       ans += cnt[bit] / 9 * (tmp - 1);     else       ans += tmp - 1;     long long maxn;     long long minn = tmp;     for (int i = 1; i < bit; i++) {       minn *= 10;     }     minn += tmp;     maxn = a;     int mowei = a % 10;     if (mowei >= tmp)       maxn = maxn - mowei + tmp;     else if (maxn - 10 >= tmp * val[bit])       maxn = maxn - 10 - mowei + tmp;     else       return ans;     maxn = (maxn - tmp * val[bit]) / 10;     return maxn + 1 + ans;   }   int main() {     long long l, r;     while (~scanf( %I64d%I64d , &l, &r)) {       init();       long long a = cal(l), b = cal(r);       if (l < 10) a = l;       if (r < 10) b = r;       long long ans = b - a;       long long tmp1 = l % 10, tmp2;       while (l) {         tmp2 = l;         l /= 10;       }       if (tmp1 == tmp2) ans++;       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Display(vector<double> row) {     for (int i = 0; i < row.size(); i++) cout << row[i] <<    ;     cout << endl;   }   void Display(vector<vector<double> > matrix) {     for (int i = 0; i < matrix.size(); i++) Display(matrix[i]);     cout << endl;   }   vector<vector<double> > New(int n, int m, double x = 0.0) {     return vector<vector<double> >(n, vector<double>(m, x));   }   vector<vector<double> > Ident(int n) {     vector<vector<double> > Res = New(n, n);     for (int i = 0; i < n; i++) Res[i][i] = 1.0;     return Res;   }   void Multy(vector<vector<double> >& C, vector<vector<double> > A,              vector<vector<double> > B) {     assert(A[0].size() == B.size());     assert(A.size() == C.size());     assert(B[0].size() == C[0].size());     for (int i = 0; i < C.size(); i++)       for (int j = 0; j < C[0].size(); j++) C[i][j] = 0.0;     for (int i = 0; i < C.size(); i++)       for (int j = 0; j < C[0].size(); j++)         for (int k = 0; k < A[0].size(); k++) C[i][j] += A[i][k] * B[k][j];   }   const int N = 100100;   const int M = 4 * N;   const double Eps = 1e-6;   int n;   int a[N];   int b[N];   vector<vector<double> > Tree[M];   bool isZero(double x) { return abs(x) < Eps; }   void Merge(int Node) {     Multy(Tree[Node], Tree[(Node << 1)], Tree[(Node << 1 | 1)]);   }   void Build(int Node = 1, int L = 1, int R = n) {     Tree[Node] = New(2, 2);     if (L == R) {       int i = L;       Tree[Node][0][0] = 0.0;       Tree[Node][0][1] = 1.0 * (a[i] - b[i]) / a[i];       Tree[Node][1][0] = 1.0;       Tree[Node][1][1] = 1.0 * b[i] / a[i];       return;     }     Build((Node << 1), L, ((L + R) >> 1));     Build((Node << 1 | 1), ((L + R) >> 1) + 1, R);     Merge(Node);   }   void Update(int i, int Node = 1, int L = 1, int R = n) {     if (L == R) {       Tree[Node][0][0] = 0.0;       Tree[Node][0][1] = 1.0 * (a[i] - b[i]) / a[i];       Tree[Node][1][0] = 1.0;       Tree[Node][1][1] = 1.0 * b[i] / a[i];       return;     }     if (i <= ((L + R) >> 1))       Update(i, (Node << 1), L, ((L + R) >> 1));     else       Update(i, (Node << 1 | 1), ((L + R) >> 1) + 1, R);     Merge(Node);   }   void Query(vector<vector<double> >& Res, int i, int j, int Node = 1, int L = 1,              int R = n) {     if (i <= L && R <= j) return Multy(Res, Res, Tree[Node]);     if (j < L || R < i) return;     Query(Res, i, j, (Node << 1), L, ((L + R) >> 1));     Query(Res, i, j, (Node << 1 | 1), ((L + R) >> 1) + 1, R);   }   int main() {     int q;     cin >> n >> q;     for (int i = 1; i <= n; i++) scanf( %d%d , a + i, b + i);     Build();     while (q--) {       int T;       scanf( %d , &T);       if (T == 1) {         int i, x, y;         scanf( %d%d%d , &i, &x, &y);         a[i] = x;         b[i] = y;         Update(i);       } else {         int L, R;         scanf( %d%d , &L, &R);         vector<vector<double> > Res = Ident(2);         Query(Res, L, R);         double Ans = 1.0 / Res[1][1];         if (Ans != Ans) Ans = 0.0;         printf( %.10f n , Ans);       }     }   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, a[500050], R[500050];   int main() {     n = read();     for (int i = 1; i <= n; i++) {       a[i] = read();       if (i <= n - i + 1) R[i] = n - i + 1, R[n - i + 1] = i;     }     int cnt = 0;     for (int i = 1; i <= n - i + 1; i++) {       cnt++;       if (cnt & 1) swap(a[i], a[R[i]]);     }     for (int i = 1; i <= n; i++) printf( %d  , a[i]);   }


#include <bits/stdc++.h>   using namespace std;   string s;   void rev() {     for (int i = 0; i < s.size(); i++)       if (s[i] ==  L )         s[i] =  R ;       else         s[i] =  L ;   }   vector<int> v;   int k[2000011];   const int delta = 1000005;   bool verify(int nr) {     memset(k, 0, sizeof(k));     int now = 0;     k[now + delta]++;     for (int i = 0; i < v.size(); i++) {       now = min(nr - 1, now + v[i]);       k[now + delta]++;     }     if (k[now + delta] > 1) return false;     return true;   }   int i, sum, mx, l, r, mid, ans;   int main(void) {     cin >> s;     if (s[s.size() - 1] ==  R ) rev();     for (i = 0; i < s.size(); i++) {       if (s[i] ==  R )         v.push_back(1);       else         v.push_back(-1);       sum += v[i];       mx = max(mx, sum);     }     if (verify(mx + 2)) {       cout << 1;       return 0;     }     l = 1;     r = mx;     while (l <= r) {       mid = (l + r) / 2;       if (verify(mid) == true) {         ans = mid;         l = mid + 1;       } else         r = mid - 1;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 2;   long long n, a[maxn], k, ans[maxn];   long long Check(long long m) {     long long res = 0, l, r, mid;     for (int i = 1; i <= n; i++) {       l = 1;       r = a[i];       while (l <= r) {         mid = (l + r) / 2;         if (a[i] - 3 * mid * (mid + 1) - 1 >= m)           l = mid + 1;         else           r = mid - 1;       }       ans[i] = r;       res += r;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     long long l = -4e18, r = 4e18, mid;     while (l <= r) {       mid = (l + r) / 2;       if (Check(mid) >= k)         l = mid + 1;       else         r = mid - 1;     }     long long sum = Check(l);     for (int i = 1; i <= n; i++)       if (sum < k && ans[i] < a[i] &&           a[i] - 3 * (ans[i] + 1) * (ans[i] + 2) - 1 == l - 1) {         sum++;         ans[i]++;       }     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int k;   bool debug = false;   int f[100005];   int ff(int x) {     while (x != f[x]) x = f[x];     return x;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) f[i] = i;     int a, b;     long long ans = 1;     for (int i = 0; i < m; i++) {       scanf( %d%d , &a, &b);       int fa = ff(a), fb = ff(b);       if (fa == fb) {         ans = ans * 2 % 1000000009;       } else {         f[fa] = fb;       }       printf( %I64d n , ans - 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int nn, n, b, q;   vector<pair<int, int> > d;   int main() {     d.push_back(make_pair(0, 0));     scanf( %d%d%d , &n, &b, &q), nn = n;     d.push_back(make_pair(b, n));     for (int i = 1; i <= q; i++)       scanf( %d%d , &b, &n), d.push_back(make_pair(b, n));     sort(d.begin(), d.end());     for (int i = 1; i <= q; i++)       if (d[i].second > d[i + 1].second ||           d[i + 1].second - d[i].second > d[i + 1].first - d[i].first)         return printf( unfair n ), 0;     for (int k = 0; k < 32; k++) {       int res = 0;       for (int i = 1; i <= q + 1; i++) {         int cnt = 0;         for (int j = d[i - 1].first + 1; j <= d[i].first; j++)           cnt += bool((1 << (j % 5)) & k);         res += min(cnt, d[i].second - d[i - 1].second);       }       if (res < nn / 5 * __builtin_popcount(k)) return printf( unfair n ), 0;     }     printf( fair n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 0;   const int LOGN = 0;   const int MOD = 1e9 + 7;   const int INF = 1e9 + 10;   long long N, Q;   long long x;   long long f(long long x) {     if (x & 1) return (x + 1) >> 1;     long long id = N - (x >> 1);     while (!(id & 1)) id >>= 1;     id >>= 1;     return N - id;   }   void read() {     cin >> N >> Q;     while (Q--) {       cin >> x;       cout << f(x) <<   n ;     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     read();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long GCD(long long a, long long b) {     if (b) return GCD(b, a % b);     return a;   }   bool u1[10];   bool u2[10];   int main() {     long long n, m, v;     vector<long long> a, b;     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (long long i = 0; i < n; i++) {       cin >> v;       a.push_back(v);       u1[v] = true;     }     for (long long i = 0; i < m; i++) {       cin >> v;       b.push_back(v);       u2[v] = true;     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     for (long long i = 1; i <= 9; i++) {       if (u1[i] && u2[i]) {         cout << i;         return 0;       }     }     if (a[0] < b[0]) {       cout << a[0] << b[0];     } else       cout << b[0] << a[0];   }