#include <bits/stdc++.h>   using namespace std;   long long POW(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a;     if (b & 1) return (a * POW(a, b - 1)) % 1000000007;     long long t = POW(a, b / 2);     return (t * t) % 1000000007;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int dx[] = {0, -1, 1, 0}, dy[] = {1, 0, 0, -1};   int ddx[] = {0, 0, 1, 1, 1, -1, -1, -1}, ddy[] = {1, -1, 1, 0, -1, 1, 0, -1};   map<int, int> M;   map<int, int>::iterator it, it2;   int main() {     int n, q;     scanf( %d%d , &n, &q);     M[0] = 0;     M[1000000007] = 1000000007;     M[1] = n;     int ans = n;     while (q--) {       int l, r, k;       scanf( %d%d%d , &l, &r, &k);       if (k == 1) {         it = M.upper_bound(r);         it--;         while (it != M.begin()) {           it2 = it;           it--;           int L = it2->first, R = it2->second;           if (l <= R) {             M.erase(it2);             ans -= R - L + 1;           }           if (L <= r && R > r) {             M[r + 1] = R;             ans += R - r;           }           if (L < l && R >= l) {             M[L] = l - 1;             ans += l - L;           }           if (L <= l) break;         }       } else {         it = M.upper_bound(r);         it--;         int L = 1000000007, R = -1;         while (it != M.begin()) {           it2 = it;           it--;           if (it2->second < l) break;           L = min(L, it2->first), R = max(R, it2->second);           ans -= it2->second - it2->first + 1;           M.erase(it2);         }         M[min(l, L)] = max(r, R);         ans += max(r, R) - min(l, L) + 1;       }       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   #pragma GCC optimize  O3,no-stack-protector    using namespace std;   const int MAXN = 1e5 + 7;   vector<int> G[MAXN];   bool blo[MAXN];   short odw[MAXN];   bool tried[MAXN];   int n, m;   bool dfs(int v) {     if (blo[v] == true) return false;     odw[v] = 1;     for (auto w : G[v]) {       if (odw[w] == 0) {         if (dfs(w)) return true;       } else if (odw[w] == 1) {         for (int i = 1; i <= n; i++) {           if (odw[i] != 1) tried[i] = true;         }         return true;       }     }     odw[v] = 2;     return false;   }   bool check() {     for (int i = 1; i <= n; i++) {       odw[i] = 0;     }     for (int i = 1; i <= n; i++) {       if (!odw[i]) {         if (dfs(i)) return false;       }     }     return true;   }   inline double elapsed() { return clock() / (double)CLOCKS_PER_SEC; }   int main(int argc, char **argv) {     srand(15061994);     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       G[a].emplace_back(b);     }     vector<int> KAN;     for (int i = 1; i <= n; i++) {       KAN.push_back(i);     }     random_shuffle(KAN.begin(), KAN.end());     for (int i = 0; elapsed() <= 0.95 and i < int(KAN.size()); i++) {       blo[KAN[i]] = true;       if (!tried[KAN[i]] and check()) {         cout << KAN[i] <<   n ;         exit(0);       }       blo[KAN[i]] = false;     }     cout << -1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const int mod = 1e9 + 7;   long long power(int a, long long b) {     if (b == 0LL) return 1LL;     long long tmp = power(a, b / 2);     if (b & 1LL) return (tmp * tmp % mod) * a % mod;     return tmp * tmp % mod;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n;     cin >> n;     cout << 6 * power(4, (1LL << n) - 2) % mod;   }


#include <bits/stdc++.h>   struct M {     int p, b;   };   struct F {     const int p, i;     int r, c;     F(int p, int t, int i) : p(p), i(i), r(p + t), c(0) {}     int t() { return r - p; }   };   void solve(std::vector<F> &fs, std::vector<M> &ms) {     std::multimap<int, int> ms_landed;     std::map<int, F *> fs_active;     {       std::vector<F *> fs_sort;       fs_sort.reserve(fs.size());       for (int i = 0; i < fs.size(); i++) fs_sort.push_back(&fs[i]);       std::sort(fs_sort.begin(), fs_sort.end(),                 [](const F *lhs, const F *rhs) { return lhs->p < rhs->p; });       fs_active.insert({fs_sort[0]->p, fs_sort[0]});       int curr = fs_sort[0]->r;       for (int i = 1; i < fs_sort.size(); i++) {         F &f = *fs_sort[i];         if (f.r > curr) {           int l = std::max(curr + 1, f.p);           curr = f.r;           fs_active.insert({l, &f});         }       }     }     auto update = [&](F &f, std::map<int, F *>::iterator &f_succ, const int &b) {       f.c++;       f.r += b;       while (f_succ != fs_active.end()) {         int l_succ = f_succ->first;         int r_succ = f_succ->second->r;         if (f.r < r_succ) {           if (f.r >= l_succ) {             f_succ = fs_active.insert(fs_active.erase(f_succ),                                       {f.r + 1, f_succ->second});           }           break;         }         f_succ = fs_active.erase(f_succ);       }     };     for (const M &m : ms) {       auto f_it = --fs_active.upper_bound(m.p);       const int l = f_it->first;       F &f = *f_it->second;       if (l <= m.p && m.p <= f.r) {         update(f, ++f_it, m.b);         auto m_it = ms_landed.lower_bound(l);         while (m_it != ms_landed.end()) {           M m{m_it->first, m_it->second};           if (l <= m.p && m.p <= f.r) {             update(f, f_it, m.b);             m_it = ms_landed.erase(m_it);           } else {             break;           }         }       } else {         ms_landed.insert({m.p, m.b});       }     }     for (F &f : fs) {       printf( %d %d n , f.c, f.t());     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     std::vector<F> fs;     fs.reserve(n);     std::vector<M> ms;     ms.reserve(m);     for (int i = 0; i < n; i++) {       int p, t;       scanf( %d%d , &p, &t);       fs.push_back({p, t, i});     }     for (int i = 0; i < m; i++) {       int p, b;       scanf( %d%d , &p, &b);       ms.push_back({p, b});     }     solve(fs, ms);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string text;   map<int, int> cache;   string to_bin(int v) {     string res =   ;     for (int i = 128; i >= 1; i /= 2) {       if (v - i >= 0) {         res +=  1 ;         v -= i;       } else {         res +=  0 ;       }     }     return move(res);   }   int reverse_bin(int v) {     if (cache.count(v)) {       return cache[v];     }     int res = 0;     string bin = to_bin(v);     for (int i = 0, k = 1; i < 8; ++i, k *= 2) {       if (bin[i] ==  1 ) {         res += k;       }     }     cache[res] = v;     cache[v] = res;     return res;   }   int intercal(int prev, int ch) {     int rprev = reverse_bin(prev);     int rch = reverse_bin(ch);     return (256 - rch + rprev) % 256;   }   int main() {     getline(cin, text);     cout << intercal(0, (int)text[0]) << endl;     for (int i = 1; i < text.size(); ++i) {       cout << intercal((int)text[i - 1], (int)text[i]) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, i, j, k, p, c, x, m, a, b, d, y, t;     cin >> t;     while (t--) {       cin >> n >> a >> b >> c >> d;       x = (a - b) * n;       y = (a + b) * n;       if ((y < (c - d)) || (x > (c + d)))         cout <<  No  << endl;       else         cout <<  Yes  << endl;     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 ]   #pragma GCC optimize( Ofast ]   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ]   using namespace std;   long long int n, k;   map<vector<pair<long long int, long long int>>, long long int> mp;   vector<pair<long long int, long long int>> get(long long int num) {     vector<pair<long long int, long long int>> pr;     for (long long int i = 2; i * i <= num; i++) {       long long int cnt = 0;       while (num % i == 0) {         cnt++;         num /= i;       }       if (cnt % k > 0) pr.push_back({i, cnt % k});     }     if (num > 1) {       pr.push_back({num, 1});       num /= num;     }     sort(pr.begin(), pr.end());     return pr;   }   signed main() {     cin >> n >> k;     vector<long long int> a(n);     for (long long int i = 0; i < n; i++) cin >> a[i];     mp[get(a[0])]++;     long long int ans = 0;     for (long long int i = 1; i < n; i++) {       long long int num = a[i];       auto pr = get(num);       vector<pair<long long int, long long int>> pr2;       for (auto& i : pr) {         if ((k - i.second) % k > 0) pr2.push_back({i.first, k - i.second});       }       ans += mp[pr2];       mp[pr]++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > g;   bool flag[100003];   int down[100003];   int max1[100003];   int max2[100003];   int up[100003];   void dfs(int x) {     flag[x] = true;     int i;     for (i = 0; i < g[x].size(); i++) {       if (!flag[g[x][i]]) {         dfs(g[x][i]);         if (down[g[x][i]] + 1 > max1[x]) {           max2[x] = max1[x];           max1[x] = down[g[x][i]] + 1;         } else if (down[g[x][i]] + 1 > max2[x])           max2[x] = down[g[x][i]] + 1;       }     }     down[x] = max1[x];   }   void dfs2(int x) {     flag[x] = true;     int i;     int res;     for (i = 0; i < g[x].size(); i++) {       if (!flag[g[x][i]]) {         if (down[g[x][i]] + 1 > max1[x] - 1)           res = max2[x];         else           res = max1[x];         up[g[x][i]] = max(up[x] + 1, res + 1);         dfs2(g[x][i]);       }     }   }   int n, m, d;   int main() {     scanf( %d %d %d , &n, &m, &d);     g.resize(n);     int x, y;     int i;     for (i = 0; i < n; i++) max1[i] = max2[i] = up[i] = down[i] = -2000000000;     for (i = 0; i < m; i++) {       scanf( %d , &x);       x--;       down[x] = 0;       up[x] = 0;       max1[x] = 0;     }     for (i = 0; i < n - 1; i++) {       scanf( %d %d , &x, &y);       x--;       y--;       g[x].push_back(y);       g[y].push_back(x);     }     dfs(0);     for (i = 0; i < n; i++) flag[i] = false;     dfs2(0);     int ans = 0;     for (i = 0; i < n; i++)       if (down[i] < d + 1 && up[i] < d + 1) ans++;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, flag = 0;   int matrix[2505][2505];   int parent[2505];   vector<int> graph[2505];   int vis[2505], num[2505];   struct Edge {     int u, v, w;     Edge() {}     Edge(int u, int v, int w) : u(u), v(v), w(w) {}   };   vector<Edge> edge;   bool cmp(const Edge &a, const Edge &b) { return a.w < b.w; }   void init() {     for (int i = 1; i <= 2505; i++) parent[i] = i;   }   void input() {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         scanf( %d , &matrix[i][j]);         if (i == j && matrix[i][j] != 0) flag = 1;         if (i > j && matrix[i][j] != matrix[j][i]) flag = 1;         if (i < j) edge.push_back(Edge(i, j, matrix[i][j]));       }     }   }   int findfather(int x) {     if (x == parent[x]) return x;     return parent[x] = findfather(parent[x]);   }   void Union(int x, int y) {     int rx = findfather(x);     int ry = findfather(y);     if (rx > ry) swap(rx, ry);     if (rx != ry) parent[ry] = rx;   }   void Krukal() {     sort(edge.begin(), edge.end(), cmp);     int cnt = 0;     for (int i = 0; i < edge.size(); i++) {       int u = edge[i].u;       int v = edge[i].v;       int ru = findfather(u);       int rv = findfather(v);       if (ru != rv) {         graph[u].push_back(v);         graph[v].push_back(u);         cnt++;         Union(u, v);       }       if (cnt == n - 1) break;     }   }   void dfs(int u, int fa, int tmp) {     vis[u] = 1;     for (int i = 0; i < graph[u].size(); i++) {       int k = graph[u][i];       if (vis[k]) continue;       if (k == fa) continue;       num[k] = max(tmp, matrix[u][k]);       dfs(k, u, num[k]);     }   }   int main() {     scanf( %d , &n);     init();     input();     if (flag) {       printf( NOT MAGIC n );       return 0;     }     Krukal();     for (int i = 1; i <= n; i++) {       memset(vis, 0, sizeof(vis));       dfs(i, -1, 0);       for (int j = i + 1; j <= n; j++) {         if (num[j] != matrix[i][j]) {           flag = 1;           break;         }       }       if (flag) break;     }     if (flag)       printf( NOT MAGIC n );     else       printf( MAGIC n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int already = 0;     int n, k;     cin >> n >> k;     int ans = 0;     for (int i = 0; i < k; ++i) {       int cnt;       cin >> cnt;       int first;       cin >> first;       if (first == 1) {         int good = 1;         already = 1;         --ans;         while (good < cnt) {           cin >> first;           if (first == good + 1) {             ++good;             already = good;             --ans;           } else {             ++good;             break;           }         }         ans += cnt;         while (good < cnt) {           cin >> first;           ++good;         }       } else {         ans += (cnt - 1);         for (int j = 1; j < cnt; ++j) cin >> first;       }     }     ans += (n - already);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t, x, y, p, q;   bool check(long long mid) {     long long pp = p * mid;     long long qq = q * mid;     if (pp - x < 0 || qq - y < 0) return false;     return (pp - x <= qq - y);   }   int main() {     scanf( %lld , &t);     while (t--) {       scanf( %lld %lld %lld %lld , &x, &y, &p, &q);       if (x * q == p * y) {         printf( 0 n );         continue;       }       long long lo = 1, hi = 2000000000;       while (lo + 1 < hi) {         long long mid = (lo + hi) / 2LL;         if (check(mid))           hi = mid;         else           lo = mid;       }       if (check(lo)) hi = lo;       if (check(hi))         printf( %lld n , hi * q - y);       else         printf( -1 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, i, x;     cin >> t;     while (t--) {       int angle;       cin >> angle;       x = 360 % (180 - angle);       if (x == 0) {         cout <<  YES  << endl;       } else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long M = 1e9 + 7;   const int N = 3e5 + 7;   const int K = 5e3 + 7;   int n, k;   int a[N];   int dp[K][K];   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     int top = (n + k - 1) / k;     int low = n / k;     int ctop = n % k;     int clow = k - ctop;     for (int i = 0; i < K; i++)       for (int j = 0; j < K; j++) dp[i][j] = -1;     dp[0][0] = 0;     for (int i = 0; i <= ctop; i++)       for (int j = 0; j <= clow; j++)         if (i || j) {           dp[i][j] = 2e9 + 7;           int pnt = i * top + j * low;           if (j) dp[i][j] = dp[i][j - 1] + a[pnt] - a[pnt - low + 1];           if (i)             dp[i][j] = min(dp[i][j], dp[i - 1][j] + a[pnt] - a[pnt - top + 1]);         }     cout << dp[ctop][clow];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int h1, t1, h2, t2, ansh, anst;     scanf( %2d:%2d , &h1, &t1);     scanf( %2d:%2d , &h2, &t2);     if (t1 < t2) {       h1--, t1 += 60;     }     anst = t1 - t2;     ansh = h1 - h2;     if (ansh < 0) ansh += 24;     printf( %02d:%02d n , ansh, anst);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 111, K = 26;   int n;   string name[MAX];   namespace G {   struct V : vector<int> {     V() : odw(false) {}     bool odw;     int wyj;   };   V g[K];   void krawedz(char a, char b) {     g[int(a) - int( a )].push_back(int(b) - int( a ));   }   int t = 0;   stack<int> stos;   void dfs(int v) {     g[v].odw = true;     for (int i = 0; i < ((int((g[v]).size()))); i++) {       int u = g[v][i];       if (!g[u].odw) dfs(u);     }     stos.push(v);     g[v].wyj = t++;   }   bool poprawne_sortowanie() {     for (int v = 0; v < (K); v++)       for (int i = 0; i < ((int((g[v]).size()))); i++) {         int u = g[v][i];         if (g[v].wyj < g[u].wyj) return false;       }     return true;   }   bool sortowanie_topologiczne() {     for (int i = 0; i < (K); i++)       if (!g[i].odw) dfs(i);     return poprawne_sortowanie();   }   void wypisz_sortowanie() {     assert((int((stos).size())) == 26);     while (!stos.empty()) {       cout << char(int( a ) + stos.top());       stos.pop();     }     cout <<   n ;   }   }  // namespace G   void wczytaj_dane() {     cin >> n;     for (int i = 0; i < (n); i++) cin >> name[i];   }   int roznica(const string& a, const string& b) {     int m = min((int((a).size())), (int((b).size())));     for (int i = 0; i < (m); i++)       if (a[i] != b[i]) return i;     return -1;   }   bool porownuj(const string& a, const string& b) {     int i = roznica(a, b);     if (i == -1) return (int((a).size())) < (int((b).size()));     G::krawedz(a[i], b[i]);     return true;   }   void zrob_test() {     wczytaj_dane();     for (int i = 0; i < (n - 1); i++)       if (!porownuj(name[i], name[i + 1])) {         cout <<  Impossible n ;         return;       }     if (G::sortowanie_topologiczne())       G::wypisz_sortowanie();     else       cout <<  Impossible n ;   }   int main() {     ios_base::sync_with_stdio(0);     zrob_test();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long Pow(int a, int b) {     long long ans = 1;     for (int i = 0; i < b; i++) {       ans = (ans * a) % 1000000007;     }     return ans;   }   int main() {     long long n, k;     cin >> n >> k;     cout << (Pow(n - k, n - k) * Pow(k, k - 1)) % 1000000007 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[200005];   int CR, n, k, sz[200005], target[200005], cented[200005];   void getsize(int now, int pre) {     sz[now] = (target[now] == 1);     for (int i = 0; i < v[now].size(); i++) {       int next = v[now][i];       if (next == pre || cented[next]) continue;       getsize(next, now);       sz[now] += sz[next];     }   }   int getcent(int now, int pre, int R) {     for (int i = 0; i < v[now].size(); i++) {       int next = v[now][i];       if (next == pre || cented[next]) continue;       if (sz[next] > sz[R] / 2) return getcent(next, now, R);     }     return now;   }   priority_queue<pair<int, int> > pq;   int centdfs(int now) {     getsize(now, -1);     int cc = getcent(now, -1, now);     cented[cc] = 1;     if (CR == -1) CR = cc;     return cc;   }   int gcnt = 0;   vector<int> tmp[200005];   void go(int now, int pre) {     if (target[now]) tmp[gcnt].push_back(now);     for (int i = 0; i < v[now].size(); i++) {       int next = v[now][i];       if (next == pre) continue;       go(next, now);     }   }   int main() {     CR = -1;     scanf( %d %d , &n, &k);     for (int a, b, i = 0; i < n - 1; i++) {       scanf( %d %d , &a, &b);       v[a].push_back(b);       v[b].push_back(a);     }     for (int i = 1; i <= k; i++) {       for (int t, j = 0; j < 2; j++) {         scanf( %d , &t);         target[t] = 1;       }     }     centdfs(1);     printf( 1 n%d n , CR);     for (int i = 0; i < v[CR].size(); i++) {       ++gcnt;       go(v[CR][i], CR);       if (tmp[gcnt].empty()) continue;       pq.push(make_pair((int)tmp[gcnt].size(), gcnt));     }     while (!pq.empty()) {       pair<int, int> p = pq.top();       pq.pop();       if ((int)pq.size() == 0) {         printf( %d %d %d n , tmp[p.second].back(), CR, CR);         break;       }       pair<int, int> p2 = pq.top();       pq.pop();       printf( %d %d %d n , tmp[p.second].back(), tmp[p2.second].back(), CR);       tmp[p.second].pop_back();       tmp[p2.second].pop_back();       if (--p.first != 0) {         pq.push(p);       }       if (--p2.first != 0) {         pq.push(p2);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100005;   vector<int> A, B[MAX], C, D;   int visited[MAX];   int n, m;   void DFS(int u) {     visited[u] = 1;     C.push_back(u);     for (int i = 0; i < B[u].size(); i++) {       int current = B[u][i];       if (visited[current] == 0) DFS(current);     }   }   int main() {     int n;     scanf( %d , &n);     A.clear();     for (int i = 0; i <= n; i++) visited[i] = 0;     string s;     for (int i = 0; i < n; i += 1) {       int val;       cin >> val;       A.push_back(val);     }     for (int i = 0; i < MAX; i++) B[i].clear();     for (int i = 0; i < n; i++) {       cin >> s;       for (int j = 0; j < n; j++) {         if (s[j] ==  1 ) {           B[i + 1].push_back(j + 1);           B[j + 1].push_back(i + 1);         }       }     }     for (int i = 1; i <= n; i++) {       C.clear();       D.clear();       if (visited[i] == 0) {         DFS(i);         for (int j = 0; j < C.size(); j++) {           D.push_back(A[C[j] - 1]);         }         sort(C.begin(), C.end());         sort(D.begin(), D.end());         for (int j = 0; j < C.size(); j++) {           A[C[j] - 1] = D[j];         }       }     }     for (int i = 0; i < A.size(); i++) printf( %d  , A[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, s, ans = 0, f[2 * 200005];   inline int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }   int main() {     scanf( %d%d%d , &n, &m, &s);     for (register int i = 1; i <= m + n; i++) f[i] = i;     for (register int i = 1; i <= s; i++) {       register int a, b;       scanf( %d%d , &a, &b), b += n;       f[find(b)] = find(a);     }     for (register int i = 1; i <= n + m; i++)       if (f[i] == i) ans++;     printf( %d , ans - 1);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3,  Ofast ,  inline )   const double eps = 1e-7;   const int maxn = 3e5 + 10;   const int prime[15] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37};   const int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};   int spgcd(int a, int b) {     while (b ^= a ^= b ^= a %= b)       ;     return a;   }   inline int mul(int a, int b, int p) { return (long long)a * b % p; }   template <typename T>   void scan(T &x) {     x = 0;     bool _ = 0;     T c = getchar();     _ = c == 45;     c = _ ? getchar() : c;     while (c < 48 || c > 57) c = getchar();     for (; c < 48 || c > 57; c = getchar())       ;     for (; c > 47 && c < 58; c = getchar()) x = (x << 3) + (x << 1) + (c & 15);     x = _ ? -x : x;   }   template <typename T>   void printn(T n) {     bool _ = 0;     _ = n < 0;     n = _ ? -n : n;     char snum[65];     int i = 0;     do {       snum[i++] = n % 10 + 48;       n /= 10;     } while (n);     --i;     if (_) putchar(45);     while (i >= 0) putchar(snum[i--]);   }   template <typename First, typename... Ints>   void scan(First &arg, Ints &...rest) {     scan(arg);     scan(rest...);   }   template <typename T>   void print(T n) {     printn(n);     putchar(10);   }   template <typename First, typename... Ints>   void print(First arg, Ints... rest) {     printn(arg);     putchar(32);     print(rest...);   }   using namespace std;   map<int, int> mp;   void solve() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int l, r;       cin >> l >> r;       mp[l]++, mp[r]--;     }     int ans = 0, id = 1;     int sum = 0;     for (auto i : mp) {       sum += i.second;       if (sum > ans) {         ans = sum;         id = i.first;       }     }     cout << id <<     << ans << endl;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int sz = (1 << 22);   bool ar[sz], us[2][sz];   int n, m, bg;   void dfs(int v, int t) {     us[t][v] = 1;     if (t == 0) {       if (us[1][bg ^ v] == 0) dfs(bg ^ v, 1);     } else {       if (ar[v] and us[0][v] == 0) dfs(v, 0);       for (int i = 0; i < n; i++) {         if (v & (1 << i)) {           int ne = v - (1 << i);           if (us[1][ne] == 0) dfs(ne, 1);         }       }     }   }   int main() {     int an = 0;     cin >> n >> m;     bg = (1 << n) - 1;     for (int a = 0; a < m; a++) {       int x;       scanf( %d , &x);       ar[x] = 1;     }     for (int a = 0; a < (1 << n); a++) {       if (ar[a] and us[0][a] == 0) {         dfs(a, 0), an++;       }     }     cout << an;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long a[50];   long long inv[50];   long long Finv[50];   long long n, s;   void init() {     inv[1] = 1;     for (int i = 2; i <= 50; i++) {       inv[i] = (mod - mod / i) * inv[mod % i] % mod;     }     Finv[0] = 1;     for (int i = 1; i <= 50; i++) {       Finv[i] = Finv[i - 1] % mod * inv[i] % mod;     }   }   long long C(long long n, long long m) {     if (n < 0 || m < 0 || m > n) return 0;     long long res = 1;     for (long long i = n; i > n - m; i--) {       res = (i % mod * res) % mod;     }     res = res % mod * Finv[m] % mod;     return res % mod;   }   int main() {     init();     cin >> n >> s;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     long long res = 0;     for (long long i = 0; i < (1ll << n); i++) {       long long tmp = s;       long long cnt = 0;       for (long long j = 0; j < n; j++) {         if ((1ll << j) & i) {           tmp -= a[j] + 1;           cnt++;         }       }       if (tmp < 0) continue;       if (cnt & 1) {         res = (((res - C(tmp + n - 1, n - 1)) % mod + mod) % mod) % mod;       } else {         res = (res + C(tmp + n - 1, n - 1) % mod) % mod;       }     }     cout << res << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   int sqrt_maxn = 505;   const int maxsqrt_n = 205;   const int maxn = 100005;   int a[maxn];   struct node {     int val;     node* next;     node* front;   };   node* front[maxsqrt_n];   node* rail[maxsqrt_n];   int dp[maxsqrt_n][maxn];   node* new_node() {     static node a[200005];     static int top = 0;     return &a[top++];   }   void insert_node(int x, int y) {     node* t = new_node();     t->val = y;     t->next = front[x];     if (front[x] != 0) front[x]->front = t;     t->front = 0;     front[x] = t;   }   void trans_inside(int x, int y) {     register int j = x / sqrt_maxn;     register int i;     register node* t1 = front[j];     for (i = j * sqrt_maxn; i <= x; i++) {       t1 = t1->next;     }     register node* t2 = t1;     for (; i <= y; i++) {       t2 = t2->next;     }     t1->front->next = t2;     t2->front->next = t2->next;     t2->next->front = t2->front;     t2->front = t1->front;     t2->next = t1;     t1->front = t2;   }   void trans(int x, int y) {     register int jx = x / sqrt_maxn;     register int i;     register node* t1 = front[jx];     for (i = jx * sqrt_maxn; i <= x; i++) {       t1 = t1->next;     }     int jy = y / sqrt_maxn;     register node* t2 = front[jy];     for (i = jy * sqrt_maxn; i <= y; i++) {       t2 = t2->next;     }     t1->front->next = t2;     t2->front->next = t2->next;     t2->next->front = t2->front;     t2->front = t1->front;     t2->next = t1;     t1->front = t2;     dp[jx][t2->val]++;     dp[jy][t2->val]--;     for (i = jx; i < jy; i++) {       t1 = front[i + 1]->next;       t2 = rail[i]->front;       t1->front->next = t2;       t2->front->next = t2->next;       t2->next->front = t2->front;       t2->front = t1->front;       t2->next = t1;       t1->front = t2;       dp[i + 1][t2->val]++;       dp[i][t2->val]--;     }   }   int calc_inside(int x, int y, int val) {     int j = x / sqrt_maxn;     int i;     node* t1 = front[j];     for (i = j * sqrt_maxn; i <= x; i++) {       t1 = t1->next;     }     register int ans = 0;     for (; i <= y; i++) {       if (t1->val == val) ans++;       t1 = t1->next;     }     if (t1->val == val) ans++;     return ans;   }   int calc(int x, int y, int val) {     int j = x / sqrt_maxn;     int i;     node* t1 = front[j];     for (i = j * sqrt_maxn; i <= x; i++) {       t1 = t1->next;     }     int ans = 0;     for (; t1->val != -2;) {       if (t1->val == val) ans++;       t1 = t1->next;     }     int jy = y / sqrt_maxn;     for (i = j + 1; i < jy; i++) {       ans += dp[i][val];     }     t1 = front[jy];     for (i = jy * sqrt_maxn; i <= y; i++) {       t1 = t1->next;       if (t1->val == val) ans++;     }     return ans;   }   int main() {     fprintf(stderr,  %d n , clock());     int n;     scanf( %d , &n);     int i;     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       a[i]--;     }     memset(dp, 0, sizeof(dp));     for (i = 0; i < n; i += sqrt_maxn) {       register int temp = i / sqrt_maxn;       front[temp] = 0;       int j;       insert_node(temp, -2);       rail[temp] = front[temp];       for (j = i + sqrt_maxn - 1; j >= i; j--) {         if (j >= n) continue;         insert_node(temp, a[j]);         dp[temp][a[j]]++;       }       insert_node(temp, -1);     }     int lastans = 0;     int q;     scanf( %d , &q);     for (i = 0; i < q; i++) {       int oper;       scanf( %d , &oper);       if (oper == 1) {         int x, y;         scanf( %d%d , &x, &y);         x = (x - 1 + lastans) % n;         y = (y - 1 + lastans) % n;         if (x > y) swap(x, y);         if (x == y) continue;         if (x / sqrt_maxn == y / sqrt_maxn) {           trans_inside(x, y);         } else {           trans(x, y);         }       } else {         int x, y, z;         scanf( %d%d%d , &x, &y, &z);         x = (x - 1 + lastans) % n;         y = (y - 1 + lastans) % n;         z = (z - 1 + lastans) % n;         if (x > y) swap(x, y);         if (x / sqrt_maxn == y / sqrt_maxn) {           lastans = calc_inside(x, y, z);         } else {           lastans = calc(x, y, z);         }         printf( %d n , lastans);       }     }     fprintf(stderr,  %d n , clock());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int M = 80;   const int N = 4100;   long long c[M][M], m;   struct Tree {     struct Node {       int ne, to;     } e[2 * N];     int vis[N], tot = 0, he[N], sz[N], mx[N], q[N], n, rp, mn;     long long step[M], f[N][M], g[N][M], tmp[M], ans[M];     void add(int x, int y) {       e[++tot].ne = he[x];       he[x] = tot;       e[tot].to = y;     }     void addedge(int x, int y) {       add(x, y);       add(y, x);     }     void dfs1(int x, int fa) {       int i, y;       sz[x] = 1;       mx[x] = 0;       for (i = he[x]; i; i = e[i].ne) {         y = e[i].to;         if ((!vis[y]) && (y != fa)) {           dfs1(y, x);           sz[x] += sz[y];           if (sz[y] > mx[x]) mx[x] = sz[y];         }       }     }     void dfsrt(int now, int x, int fa, int &rt) {       int i, y;       mx[x] = max(mx[x], sz[now] - sz[x]);       if (mx[x] < mn) {         mn = mx[x];         rt = x;       }       for (i = he[x]; i; i = e[i].ne) {         y = e[i].to;         if ((!vis[y]) && (y != fa)) dfsrt(now, y, x, rt);       }     }     void dfs2(int x, int fa) {       int i, y;       q[++rp] = x;       for (i = he[x]; i; i = e[i].ne) {         y = e[i].to;         if ((!vis[y]) && (y != fa)) dfs2(y, x);       }     }     void divide(int x) {       int rt, i, j, k, y;       mn = n;       dfs1(x, 0);       dfsrt(x, x, 0, rt);       vis[rt] = 1;       for (i = he[rt]; i; i = e[i].ne)         if (!vis[e[i].to]) divide(e[i].to);       vis[rt] = 0;       rp = 0;       dfs2(rt, 0);       memset(step, 0, sizeof(step));       for (i = he[rt]; i; i = e[i].ne) {         y = e[i].to;         if (!vis[y])           for (j = 0; j <= m - 2; j++)             step[j + 2] = (step[j + 2] + f[y][j]) % mod;       }       memset(f[rt], 0, sizeof(f[rt]));       f[rt][0] = 1;       for (i = 1; i <= m; i++)         for (j = 2; j <= i; j++)           f[rt][i] = (f[rt][i] + f[rt][i - j] * step[j]) % mod;       for (i = 2; i <= rp; i++) {         memset(tmp, 0, sizeof(tmp));         for (j = 2; j <= m; j++)           for (k = 0; k <= j - 2; k++)             tmp[j] = (tmp[j] + g[q[i]][k] * f[rt][j - k - 2]) % mod;         for (j = 2; j <= m; j++)           for (k = 0; k <= j - 2; k++)             f[q[i]][j] = (f[q[i]][j] + g[q[i]][k] * tmp[j - k]) % mod;       }       for (i = 1; i <= rp; i++) memset(g[q[i]], 0, sizeof(g[q[i]]));       g[x][0] = 1;       for (i = 1; i <= m; i++)         for (j = 1; j <= rp; j++)           for (k = he[q[j]]; k; k = e[k].ne) {             y = e[k].to;             if (!vis[y]) g[q[j]][i] = (g[q[j]][i] + g[y][i - 1]) % mod;           }     }     void solve() {       divide(1);       for (int i = 0; i <= m; i++)         for (int j = 1; j <= n; j++) ans[i] = (ans[i] + f[j][i]) % mod;     }   } tr1, tr2;   int main() {     int i, j, k, x, y;     long long out;     scanf( %d%d%d , &tr1.n, &tr2.n, &m);     for (i = 1; i < tr1.n; i++) {       scanf( %d%d , &x, &y);       tr1.addedge(x, y);     }     for (i = 1; i < tr2.n; i++) {       scanf( %d%d , &x, &y);       tr2.addedge(x, y);     }     for (i = 0; i <= m; i++) c[i][0] = 1;     for (i = 1; i <= m; i++)       for (j = 1; j <= i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;     tr1.solve();     tr2.solve();     out = 0;     for (i = 0; i <= m; i++)       out = (out + (c[m][i] * tr1.ans[i]) % mod * tr2.ans[m - i]) % mod;     printf( %I64d n , out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct trie {     struct tree {       long long al[26];       bool ex;     } nxt[100005];     long long cnt, dep[100005];     void insert(char *s) {       long long l = strlen(s), rt = 0;       for (register long long i = 0; i < l; i++) {         long long c = s[i] -  a ;         if (!nxt[rt].al[c]) nxt[rt].al[c] = ++cnt, dep[cnt] = dep[rt] + 1;         rt = nxt[rt].al[c];       }       nxt[rt].ex = 1;     }   } tr;   priority_queue<long long> q[100005];   long long n, ans = 0;   char s[100005];   template <typename T>   inline void read(T &x) {     T c = getchar(), f = 0;     for (; c < 48 || 57 < c; c = getchar())       if (c ==  - ) f = 1;     for (x = 0; 48 <= c && c <= 57; c = getchar())       x = (x << 3) + (x << 1) + (c ^ 48);     if (f) x = -x;   }   template <typename T>   inline void print(T x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) print(x / 10);     putchar(x % 10 + 48);   }   inline void merge(long long x, long long y) {     while (!q[y].empty()) q[x].push(q[y].top()), q[y].pop();   }   void dfs(long long x) {     for (register long long i = 0; i < 26; i++)       if (tr.nxt[x].al[i]) dfs(tr.nxt[x].al[i]);     for (register long long i = 0; i < 26; i++)       if (tr.nxt[x].al[i]) merge(x, tr.nxt[x].al[i]);     if (!x) return;     if (tr.nxt[x].ex)       ans += tr.dep[x], q[x].push(tr.dep[x]);     else       ans -= q[x].top() - tr.dep[x], q[x].pop(), q[x].push(tr.dep[x]);   }   signed main() {     scanf( %lld , &n);     for (register long long i = 1; i <= n; i++) scanf( %s , s), tr.insert(s);     dfs(0), printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, T, ans;   int t[N];   priority_queue<int> pq;   int main() {     scanf( %d%d , &n, &T);     for (int i = 1; i <= n; ++i) {       scanf( %d , &t[i]);       t[i] = t[i] > i ? t[i] - i : 0;     }     for (int i = 1; i <= n; ++i) {       pq.push(t[i]);       while ((long long)pq.top() + i >= T && !pq.empty()) {         pq.pop();       }       ans = max(ans, (int)pq.size());     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const char nl =   n ;   const int MX = 100001;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int t;     cin >> t;     for (int tt = 0; tt < (t); tt++) {       int n;       cin >> n;       for (int i = 0; i < (n); i++) cout <<  1  ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll INF = 1e18 + 1;   const ll mod = 1e9 + 7;   vector<vector<ll> > adj;   vector<ll> desc, max_n;   ll gmnc = INF;   void print_vec(vector<ll> vec) {     for (int i = 0; i < vec.size(); ++i) {       cout << vec[i] <<    ;     }     cout << endl;   }   ll desc_cnt(ll curr, ll par) {     ll cnt = 1;     for (auto it : adj[curr]) {       if (it != par) {         cnt += desc_cnt(it, curr);       }     }     desc[curr] = cnt;     return cnt;   }   void max_neigh_cnt(ll curr, ll par) {     ll mnc = -INF;     mnc = max(mnc, desc[1] - desc[curr]);     for (auto it : adj[curr]) {       if (it != par) {         mnc = max(mnc, desc[it]);       }     }     gmnc = min(gmnc, mnc);     max_n[curr] = mnc;     for (auto it : adj[curr]) {       if (it != par) {         max_neigh_cnt(it, curr);       }     }   }   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     ll t;     cin >> t;     while (t--) {       ll n;       cin >> n;       adj.clear();       desc.clear();       max_n.clear();       gmnc = INF;       adj.resize(n + 1);       desc.resize(n + 1);       max_n.resize(n + 1);       for (int i = 1; i <= n - 1; ++i) {         ll x, y;         cin >> x >> y;         adj[x].push_back(y);         adj[y].push_back(x);       }       desc_cnt(1, 1);       max_neigh_cnt(1, 1);       vector<ll> cn;       for (int i = 1; i <= n; ++i) {         if (max_n[i] == gmnc) {           cn.push_back(i);         }       }       pair<ll, ll> e1, e2;       if (cn.size() > 1) {         for (auto it : adj[cn[0]]) {           if (it != cn[1]) {             e1 = make_pair(cn[0], it);             e2 = make_pair(cn[1], it);             break;           }         }       } else {         e1 = make_pair(cn[0], adj[cn[0]][0]);         e2 = e1;       }       cout << e1.first <<     << e1.second << endl;       cout << e2.first <<     << e2.second << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   char s[400010];   int a[200];   vector<int> S;   vector<int> d, q;   int main() {     int n;     scanf( %d %s , &n, s);     for (int i = 0; i < n; i++) a[s[i]]++;     int p = 0;     for (int i = 0; i < 128; i++) {       if (a[i] % 2) p++, a[i]--, S.push_back(i);       if (a[i]) {         d.push_back(i);         q.push_back(a[i]);       }     }     if (p == 0) {       int cn = 0;       for (int i = 0; i < 128; i++) {         while (a[i]) s[cn++] = i, a[i] -= 2;       }       for (int i = 0; i < cn; i++) s[cn + i] = s[cn - i - 1];       s[n] =   0 ;       printf( 1 n%s n , s);     } else {       int Min = n;       for (int i = 1; i * i <= n; i++) {         if (n % i == 0) {           if (i % 2 && n / i >= p && (n / i - p) % 2 == 0) Min = min(Min, n / i);           if (n / i % 2 && i >= p && (i - p) % 2 == 0) Min = min(Min, i);         }       }       printf( %d n , Min);       int L = n / Min;       int pi = L / 2;       int now = 0;       for (int i = 0; i < Min; i++) {         int x = pi + i * L;         if (S.size() > i)           s[x] = S[i];         else {           while (!q[now]) now++;           s[x] = d[now];           S.push_back(d[now]);           S.push_back(d[now]);           q[now] -= 2;         }         for (int i = 0; i < L / 2; i++) {           while (!q[now]) now++;           s[x - i - 1] = d[now];           s[x + i + 1] = d[now];           q[now] -= 2;         }       }       for (int i = 0; i < n; i++) {         printf( %c , s[i]);         if (i % L == L - 1 && i != n - 1) printf(   );       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6, SZ = 800, INF = 1 << 29;   const long long LINF = (1LL << 60), mod = 1e9 + 7;   const long double eps = 1e-8, PI = acos(-1.0);   inline int dcmp(double x, double y = 0.0) { return abs(x - y) < eps; }   template <typename Type>   inline Type ru(Type &v) {     static char READ_DATA;     static int SIGNAL_INPUT = 1;     while ((READ_DATA = getchar()) <  0  || READ_DATA >  9 )       if (READ_DATA ==  - )         SIGNAL_INPUT = -1;       else if (READ_DATA == EOF)         return EOF;     v = READ_DATA -  0 ;     while ((READ_DATA = getchar()) >=  0  && READ_DATA <=  9 )       v = v * 10 + READ_DATA -  0 ;     v *= SIGNAL_INPUT;     return v;   }   template <typename A, typename B>   inline int ru(A &x, B &y) {     if (ru(x) == EOF) return EOF;     ru(y);     return 2;   }   template <typename A, typename B, typename C>   inline int ru(A &x, B &y, C &z) {     if (ru(x) == EOF) return EOF;     ru(y);     ru(z);     return 3;   }   long long gcd(long long a, long long b) {     a = abs(a);     b = abs(b);     while (b) {       a %= b;       swap(a, b);     }     return a;   }   const int maxn = 1e6 + 5;   int n, a[maxn], m, d[maxn], id[maxn];   int cmp(const int &i, const int &j) { return d[(i + 1) / 2] > d[(j + 1) / 2]; }   int main() {     ru(n);     for (int i = 1; i <= n; i++) {       ru(d[i]);     }     for (int i = 1; i < 2 * n; i += 2) {       a[++m] = i;     }     sort(a + 1, a + m + 1, cmp);     for (int i = 2; i <= m; i++) {       printf( %d %d n , a[i - 1], a[i]);     }     for (int i = 1; i <= n; i++) {       int j = (a[i] + 1) / 2;       if (i + d[j] - 1 <= m) {         printf( %d %d n , 2 * j, a[i + d[j] - 1]);         if (i + d[j] - 1 == m) {           a[++m] = 2 * j;         }       } else {         printf( %d %d n , 2 * j, a[i - d[j] + 1]);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int kq = 0;       vector<pair<int, int> > res;       int n, k;       cin >> n >> k;       vector<bool> used(2 * n + 1, false);       for (int i = 1; i <= k; i++) {         int u, v;         cin >> u >> v;         res.push_back({min(u, v), max(u, v)});         used[u] = true;         used[v] = true;       }       vector<int> conlai;       for (int i = 1; i <= 2 * n; i++) {         if (!used[i]) conlai.push_back(i);       }       int len = n - k;       for (int i = 0; i < len; i++) {         res.push_back({conlai[i], conlai[i + len]});       }       for (int i = 0; i < res.size(); i++) {         for (int j = i + 1; j < res.size(); j++) {           int a = (res[j].first - res[i].first) * (res[j].second - res[i].first);           int b =               (res[j].first - res[i].second) * (res[j].second - res[i].second);           if (a * b < 0) {             kq++;           }         }       }       cout << kq << endl;     }   }


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


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   const int maxn = 110;   int a[maxn];   int arr[maxn * maxn];   int cat[maxn * maxn][maxn];   map<set<int>, int> mp;   int top;   int recure(set<int> s) {     if (s.empty()) return 0;     if (mp.count(s)) return mp[s];     int d = *(--s.end());     int vis[maxn];     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= d; i++) {       set<int> res;       for (set<int>::iterator it = s.begin(); it != s.end(); it++) {         if (*it < i)           res.insert(*it);         else if (*it > i)           res.insert(*it - i);       }       vis[recure(res)] = 1;     }     int g;     for (int i = 0; i < maxn; i++)       if (!vis[i]) {         g = i;         break;       }     mp[s] = g;     return g;   }   int main() {     int n, Num = 0;     cin >> n;     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i < n; i++) {       long long num = 1ll * a[i];       for (int j = 2; 1ll * j * j <= num; j++) {         if (num % j) continue;         while (num % j == 0) num /= j;         arr[Num++] = j;       }       if (num > 1) {         arr[Num++] = (int)num;       }     }     sort(arr, arr + Num);     Num = unique(arr, arr + Num) - arr;     for (int i = 0; i < n; i++) {       long long num = 1ll * a[i];       for (int j = 2; 1ll * j * j <= num; j++) {         if (num % j) continue;         int cnt = 0;         while (num % j == 0) num /= j, cnt++;         int t = lower_bound(arr, arr + Num, j) - arr;         cat[t][cnt] = 1;       }       if (num > 1) {         int t = lower_bound(arr, arr + Num, (int)num) - arr;         cat[t][1] = 1;       }     }     int ok = 0;     for (int i = 0; i < Num; i++) {       set<int> res;       res.clear();       for (int j = 1; j < maxn; j++) {         if (cat[i][j]) res.insert(j);       }       ok ^= recure(res);     }     if (ok)       puts( Mojtaba );     else       puts( Arpa );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 505;   int n, now, siz[N], f[N];   bool vis[N];   vector<int> g, ans[N];   inline bool cmp(int x, int y) { return siz[x] < siz[y]; }   void divide(int l, int r) {     if (l > r) return;     cout << 1 << endl << 1 << endl << r - l + 1 << endl;     for (int i = l; i <= r; ++i) cout << g[i] <<    ;     cout << endl << now << endl;     int x, mid = (l + r) >> 1;     cin >> x;     if (!x) return;     if (l == r) return vis[g[l]] = 1, ans[now].push_back(g[l]);     divide(l, mid), divide(mid + 1, r);   }   int main() {     cin >> n, siz[1] = n;     for (int i = 2; i <= n; ++i) {       cout << 1 << endl << 1 << endl << n - 1 << endl;       for (int j = 2; j <= n; ++j) cout << j <<    ;       cout << endl << i << endl;       cin >> siz[i];     }     for (int i = 1; i <= n; ++i) f[i] = i;     sort(f + 1, f + n + 1, cmp);     for (int i = 1; i <= n; ++i) {       now = f[i];       divide(0, g.size() - 1);       for (unsigned i = 0; i < g.size(); ++i)         if (vis[g[i]]) g.erase(g.begin() + i--);       g.push_back(now);     }     cout <<  ANSWER  << endl;     for (int i = 1; i <= n; ++i)       for (int j : ans[i]) cout << i <<     << j << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   long long c[100006], freq[100006], people[100006], h[100006];   long long catche[5005][505];   long long dp(long long left, long long pep) {     if (left == 0 || pep == 0) return 0;     long long &ans = catche[left][pep];     if (ans != -1) return ans;     ans = 0;     for (long long j = 1; j <= min(left, k); j++) {       ans = max(ans, h[j] + dp(left - j, pep - 1));     }     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> k;     long long ans = 0;     long long i, j;     for (i = 1; i <= (n * k); i++) {       long long x;       cin >> x;       freq[x]++;     }     for (i = 1; i <= n; i++) {       long long x;       cin >> x;       people[x]++;     }     for (i = 1; i <= k; i++) {       cin >> h[i];     }     for (i = 1; i <= 100005; i++) {       if (!people[i]) {         continue;       }       for (j = 0; j <= freq[i]; j++) {         for (long long kk = 0; kk <= people[i]; kk++) {           catche[j][kk] = -1;         }       }       ans += dp(freq[i], people[i]);     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 100005;   void solve() {     long long int m, n;     cin >> n >> m;     long long int count = 0;     for (long long int i = 1; i <= n; i++) {       count += (m + i % 5) / 5;     }     cout << count << endl;     return;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool uin(T &a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <class T>   bool uax(T &a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   const int MAXN = 1100000;   vector<int> lft[MAXN], rgt[MAXN];   int leftf[MAXN], anyf[MAXN];   int lc[MAXN], rc[MAXN];   char s[10];   struct TNode {     int left, right;     int L, R;     int maxk;     TNode(int L = -1, int R = -1) : left(-1), right(-1), L(L), R(R), maxk(-1e9) {}   };   const int MAXT = 2100000;   TNode t[MAXT];   int tc = 0;   int buildTree(int L, int R) {     int node = tc++;     t[node] = TNode(L, R);     if (R - L == 1) return node;     int M = (L + R) / 2;     t[node].left = buildTree(L, M);     t[node].right = buildTree(M, R);     return node;   }   int getMax(int node, int L, int R) {     if (max(L, t[node].L) >= min(R, t[node].R)) return -1e9;     if (L <= t[node].L && t[node].R <= R) return t[node].maxk;     return max(getMax(t[node].left, L, R), getMax(t[node].right, L, R));   }   void setMax(int node, int i, int x) {     if (i >= t[node].R || i < t[node].L) return;     if (i == t[node].L && i + 1 == t[node].R) {       t[node].maxk = x;       return;     }     setMax(t[node].left, i, x);     setMax(t[node].right, i, x);     t[node].maxk = max(t[t[node].left].maxk, t[t[node].right].maxk);   }   bool buildAns(int l, int r) {     if (anyf[l] > r) return false;     for (int x : rgt[l]) {       if (x <= leftf[l]) return false;     }     if (leftf[l] == l) {       lc[l] = -1;       if (r == l) return true;       rc[l] = l + 1;       return buildAns(l + 1, r);     }     lc[l] = l + 1;     if (!buildAns(lc[l], leftf[l])) return false;     if (leftf[l] == r) return true;     rc[l] = leftf[l] + 1;     return buildAns(rc[l], r);   }   void print(int v) {     if (v == -1) return;     print(lc[v]);     printf( %d  , v + 1);     print(rc[v]);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(10);     cout << fixed;     int N, C;     scanf( %d%d , &N, &C);     bool ok = true;     int root = buildTree(0, N);     for (int i = 0; i < (int)(C); ++i) {       int x, y;       scanf( %d%d%s , &x, &y, s);       --x;       --y;       ok &= x < y;       if (s[0] ==  L )         lft[x].push_back(y);       else         rgt[x].push_back(y);     }     if (!ok) {       cout <<  IMPOSSIBLE n ;       return 0;     }     for (int i = (int)(N)-1; i >= 0; --i) {       leftf[i] = anyf[i] = i;       for (int x : lft[i]) {         uax(leftf[i], getMax(root, i, x + 1));       }       for (int x : rgt[i]) {         uax(anyf[i], getMax(root, i, x + 1));       }       uax(anyf[i], leftf[i]);       setMax(root, i, anyf[i]);     }     for (int i = 0; i < (int)(N); ++i) lc[i] = rc[i] = -1;     if (!buildAns(0, N - 1)) {       cout <<  IMPOSSIBLE n ;       return 0;     }     print(0);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt[15];   string a[100009];   const long long mod = 998244353LL;   int main() {     int i, len1, len2, n, j;     long long p, sum, val;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i];       reverse(a[i].begin(), a[i].end());       cnt[a[i].size()]++;     }     for (i = 1, val = 0; i <= n; i++) {       len2 = a[i].size();       for (len1 = 1; len1 <= 10; len1++) {         sum = 0;         if (len1 < len2) {           for (j = 0, p = 1; j < len1; j++) {             sum += p * (a[i][j] - 48);             p = (p * 10LL) % mod;             sum += p * (a[i][j] - 48);             p = (p * 10LL) % mod;           }           for (j = len1; j < len2; j++) {             sum += p * (a[i][j] - 48);             sum += p * (a[i][j] - 48);             p = (p * 10LL) % mod;           }         } else {           for (j = 0, p = 1; j < len2; j++) {             sum += p * (a[i][j] - 48);             p = (p * 10LL) % mod;             sum += p * (a[i][j] - 48);             p = (p * 10LL) % mod;           }         }         val += (sum % mod) * cnt[len1];         val %= mod;       }     }     cout << val <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, size_t N>   int SIZE(const T (&t)[N]) {     return N;   }   template <typename T>   int SIZE(const T(&t)) {     return t.size();   }   string to_string(char b) { return     + string({b}) +    ; }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(const string &t, int x1 = 0, int x2 = 1e9) {     string ret =   ;     for (int i = min(x1, SIZE(t)), _i = min(x2, SIZE(t) - 1); i <= _i; ++i) {       ret += t[i];     }     return     + ret +    ;   }   string to_string(const char *t) {     string ret(t);     return to_string(ret);   }   template <size_t N>   string to_string(const bitset<N> &t, int x1 = 0, int x2 = 1e9) {     string ret =   ;     for (int i = min(x1, SIZE(t)), _i = min(x2, SIZE(t) - 1); i <= _i; ++i) {       ret += t[i] +  0 ;     }     return     + ret +    ;   }   template <typename T, typename... Coords>   string to_string(const T(&t), int x1 = 0, int x2 = 1e9, Coords... C);   template <typename T, typename S>   string to_string(const pair<T, S>(&t)) {     return  (  + to_string(t.first) +  ,   + to_string(t.second) +  ) ;   }   template <typename T, typename... Coords>   string to_string(const T(&t), int x1, int x2, Coords... C) {     string ret =  [ ;     x1 = min(x1, SIZE(t));     auto e = begin(t);     advance(e, x1);     for (int i = x1, _i = min(x2, SIZE(t) - 1); i <= _i; ++i) {       ret += (i != x1 ?  ,   :   ) + to_string(*e, C...);       e = next(e);     }     return ret +  ] ;   }   void dbgm() { ; }   template <typename T, typename... S>   void dbgm(T t, S... s) {     cout << to_string(t) <<   |  ;     dbgm(s...);   }   void dbgs() { ; }   template <typename T, typename... S>   void dbgs(T t, S... s) {     cout << t <<    ;     dbgs(s...);   }   const long long N = 2e5 + 3, M = 1e9 + 7;   int v[N], h[N];   int main() {     int n, m;     cin >> n >> m;     for (int i = 1, _i = n; i <= _i; ++i) {       int x;       cin >> x;       v[i] = x;     }     sort(v + 1, v + 1 + n);     int pt = 0, hans = 0;     for (int i = 1, _i = m; i <= _i; ++i) {       int x1, x2, y;       cin >> x1 >> x2 >> y;       if (x1 == 1) {         if (x2 == 1e9) {           hans++;         } else {           h[++pt] = x2;         }       }     }     m = pt;     sort(h + 1, h + 1 + m, greater<int>());     int j = n;     int ans = 1e9;     for (int i = 1, _i = m + 1; i <= _i; ++i) {       while (v[j] > h[i]) {         --j;       }       ans = min(ans, j + max(i - 1, 0));     }     dbgs(ans + hans);   }


#include <bits/stdc++.h>   using namespace std;   ifstream fin( fisier.in );   ofstream fout( fisier.out );   int v[1000000], minl[1000000], minr[1000000];   int main() {     int n, i;     cin >> n;     for (i = 1; i <= n; ++i) cin >> v[i];     for (i = 1; i <= n; ++i) minl[i] = min(minl[i - 1] + 1, v[i]);     for (i = n; i >= 1; --i) minr[i] = min(minr[i + 1] + 1, v[i]);     int res = 0;     for (i = 1; i <= n; ++i) res = max(res, min(minr[i], minl[i]));     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dx[] = {1, 0, -1, 0};   long long dy[] = {0, 1, 0, -1};   long long gcd(long long x, long long y) {     if (y == 0)       return x;     else       return gcd(y, x % y);   }   long long expo(long long n, long long m, long long p) {     long long r = 1;     n = n % p;     while (m > 0) {       if (m % 2) r = (r * n) % p;       n = (n * n) % p;       m = m / 2;     }     return r % p;   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     long long tc = 1;     while (t--) {       long long n;       cin >> n;       if (n == 1) {         cout <<  1337  <<   n ;       } else if (n == 2) {         cout <<  11337  <<   n ;       } else if (n == 3) {         cout <<  111337  <<   n ;       } else {         long long m;         for (long long i = 1; i <= n; i++) {           long long x = (i * (i - 1)) / 2;           if (x > n) {             m = i - 1;             break;           }         }         long long r = n - (m * (m - 1)) / 2;         string ans;         ans.push_back( 1 );         ans.push_back( 3 );         ans.push_back( 3 );         while (r) {           ans.push_back( 7 );           r--;         }         m -= 2;         while (m) {           ans.push_back( 3 );           m--;         }         ans.push_back( 7 );         cout << ans <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, x, y, z, k, w, ans;   int A[400], B[400];   char c[2];   int main() {     scanf( %d , &n);     for (int i = (0); i < (n); i++) {       scanf( %s%d%d , &c, &x, &y);       if (c[0] ==  M ) {         for (int j = (x); j <= (y); j++) A[j]++;       } else {         for (int j = (x); j <= (y); j++) B[j]++;       }     }     for (int i = (1); i <= (366); i++) ans = max(ans, min(A[i], B[i]));     printf( %d n , ans * 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e9;   struct edge {     int u, v;     int flow;     int cost;     edge() {}     edge(int u, int v, int f, int c) : u(u), v(v), flow(f), cost(c) {}   };   struct MinCostMaxFlow {     int N;     vector<vector<int> > G;     vector<edge> E;     int numEdges;     vector<int> found, dad;     vector<int> dist;     MinCostMaxFlow(int N) : N(N), G(N), found(N), dist(N), dad(N), numEdges(0) {}     void addEdge(int from, int to, int capacity, int cost) {       G[from].push_back(numEdges++);       E.push_back(edge(from, to, capacity, cost));       G[to].push_back(numEdges++);       E.push_back(edge(to, from, 0, int(-1) * cost));     }     bool spfa(int s, int t) {       fill(dad.begin(), dad.end(), -1);       fill(dist.begin(), dist.end(), INF);       fill(found.begin(), found.end(), 0);       queue<int> Q;       dist[s] = 0;       Q.push(s);       found[s] = true;       while (!Q.empty()) {         int u = Q.front();         Q.pop();         if (u == t) continue;         for (int i = 0; i < G[u].size(); ++i) {           edge &pres = E[G[u][i]];           int v = pres.v;           if (pres.flow <= 0) continue;           if (dist[u] + pres.cost < dist[v]) {             dad[v] = G[u][i];             dist[v] = dist[u] + pres.cost;             if (!found[v]) Q.push(v), found[v] = true;           }         }         found[u] = false;       }       return (dad[t] != -1);     }     int dfs(int s, int t) {       int flow = INF;       for (int i = dad[t]; i != -1; i = dad[E[i].u]) {         if (E[i].flow < flow) flow = E[i].flow;       }       for (int i = dad[t]; i != -1; i = dad[E[i].u]) {         E[i].flow -= flow;         E[i ^ 1].flow += flow;       }       return flow;     }     pair<int, int> getMaxFlow(int s, int t) {       int totflow = 0;       int totcost = 0;       while (spfa(s, t)) {         int amt = dfs(s, t);         totflow += amt;         totcost += dist[t] * (int)amt;       }       return make_pair(totflow, totcost);     }   };   int main() {     int n, m;     cin >> n >> m;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     MinCostMaxFlow mcmf(n * 2 + m + 2);     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         mcmf.addEdge(i + 1, j + n + 1 + m, 1,                      (a[i] == a[j] ? 0 : __builtin_popcount(a[j])));       }     }     for (int i = 0; i < m; ++i) {       for (int j = 0; j < n; ++j) {         mcmf.addEdge(i + n + 1, j + n + m + 1, 1, __builtin_popcount(a[j]));       }       mcmf.addEdge(0, i + n + 1, 1, 0);     }     for (int i = 0; i < n; ++i) {       mcmf.addEdge(0, i + 1, 1, 0);       mcmf.addEdge(i + n + m + 1, n + m + n + 1, 1, 0);     }     pair<int, int> ret = mcmf.getMaxFlow(0, n + n + m + 1);     vector<int> who(n);     for (int i = 1; i <= n + m; ++i) {       for (int c : mcmf.G[i]) {         edge e = mcmf.E[c];         if (e.flow == 0 && e.v != 0) {           who[e.v - n - m - 1] = i - 1;           assert(e.u == i);         }       }     }     vector<int> last(n, -1);     vector<string> fans;     for (int i = 0; i < n; ++i) {       int f = who[i];       if (f >= n) {         stringstream ss;         ss << (char)(f - n +  a ) <<  =  << a[i] <<    ;         ss <<  print(  << (char)(f - n +  a ) <<  ) ;         string tmp;         ss >> tmp;         fans.push_back(tmp);         ss >> tmp;         fans.push_back(tmp);         last[i] = f - n;       } else {         if (a[who[i]] == a[i]) {           stringstream ss;           ss <<  print(  << (char)(last[who[i]] +  a ) <<  ) ;           string tmp;           ss >> tmp;           fans.push_back(tmp);         } else {           stringstream ss;           ss << (char)(last[who[i]] +  a ) <<  =  << a[i] <<    ;           ss <<  print(  << (char)(last[who[i]] +  a ) <<  ) ;           string tmp;           ss >> tmp;           fans.push_back(tmp);           ss >> tmp;           fans.push_back(tmp);         }         last[i] = last[who[i]];       }     }     cout << fans.size() <<     << ret.second <<   n ;     for (string t : fans) cout << t <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int l, r;     cin >> l >> r;     if (l == r) {       cout << l;       return 0;     }     cout <<  2  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-10;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int ax, ay, bx, by, cx, cy;     cin >> ax >> ay >> bx >> by >> cx >> cy;     complex<long double> a(ax, ay), b(bx, by), c(cx, cy);     long double d1 = abs(b - a), d2 = abs(c - b);     long double ang1 = arg(b - a), ang2 = arg(c - b);     cout << ((abs(d1 - d2) < EPS && abs(ang1 - ang2) > EPS) ?  Yes  :  No )          << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c;     cin >> a >> b >> c;     cout << (a / c + (a % c != 0)) * (b / c + (b % c != 0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void upmin(T &x, T y) {     y < x ? x = y : 0;   }   template <typename T>   inline void upmax(T &x, T y) {     x < y ? x = y : 0;   }   const long double pi = acos(-1);   const int oo = 1 << 30;   const long long OO = 1e18;   const int N = 1e5 + 100;   int gi() {     int w = 0;     bool q = 1;     char c = getchar();     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     if (c ==  - ) q = 0, c = getchar();     while (c >=  0  && c <=  9 ) w = w * 10 + c -  0 , c = getchar();     return q ? w : -w;   }   int w[N];   int p[N];   inline int phi(int n) {     int ans = n;     for (int i = 2; i <= n; i++)       if (!(n % i)) {         ans = ans / i * (i - 1);         while (!(n % i)) n /= i;       }     return ans;   }   inline int mul(int x, int y, int mod) {     return 1LL * x * y >= mod ? 1LL * x * y % mod + mod : x * y;   }   inline int qpow(int x, int y, int mod) {     int ans = 1;     while (y) {       if (y & 1) ans = mul(ans, x, mod);       x = mul(x, x, mod);       y >>= 1;     }     return ans;   }   int main() {     int n = gi(), i, Q, m, l, r, ans;     p[0] = gi();     for (m = 0; p[m] != 1; p[m + 1] = phi(p[m]), m++)       ;     p[m + 1] = 1;     for (i = 1; i <= n; i++) w[i] = gi();     Q = gi();     while (Q--) {       l = gi(), r = gi();       ans = 1;       for (i = min(r - l, m); ~i; i--) ans = qpow(w[i + l], ans, p[i]);       cout << ans % p[0] << endl;     }     return 0;   }


#include <bits/stdc++.h>   int a[100006];   int vis[100006];   int visyu[100006];   int main() {     int n, x;     scanf( %d%d , &n, &x);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       vis[a[i]]++;       if (vis[a[i]] == 2) {         printf( 0 n );         return 0;       }     }     int mans = -1;     for (int i = 1; i <= n; i++) {       visyu[a[i] & x]++;       if (visyu[a[i] & x] && vis[a[i] & x] && ((a[i] & x) != a[i])) {         printf( 1 n );         return 0;       } else if (visyu[a[i] & x] == 2) {         mans = 2;       }     }     printf( %d n , mans);   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void Read(T &cn) {     char c;     int sig = 1;     while (!isdigit(c = getchar()))       if (c ==  - ) sig = -1;     cn = c - 48;     while (isdigit(c = getchar())) cn = cn * 10 + c - 48;     cn *= sig;   }   template <typename T>   void Write(T cn) {     if (cn < 0) {       putchar( - );       cn = 0 - cn;     }     int wei = 0;     T cm = 0;     int cx = cn % 10;     cn /= 10;     while (cn) wei++, cm = cm * 10 + cn % 10, cn /= 10;     while (wei--) putchar(cm % 10 + 48), cm /= 10;     putchar(cx + 48);   }   template <typename T>   void Max(T &cn, T cm) {     cn = cn < cm ? cm : cn;   }   template <typename T>   void Min(T &cn, T cm) {     cn = cn < cm ? cn : cm;   }   struct qwe {     long long v, c;     void getit() {       Read(v);       Read(c);     }     inline friend bool operator<(qwe a, qwe b) {       return a.v == b.v ? a.c > b.c : a.v < b.v;     }   };   struct xian {     long long k, b;     long long suan(long long cn) { return (cn - b + k - 1) / k; }     void mk(long long cn, long long cm) {       k = cn;       b = cm;     }   };   qwe a[200100 + 1];   int n;   long long m;   int xu[200100 + 1], xlen;   long long f[200100 + 1], g[200100 + 1];   xian zhan[200100 + 1];   int l, r;   int jiao_z(long long cn, xian A, xian B) {     return cn * (A.k - B.k) <= (B.b - A.b);   }   int jiao(xian A, xian B, xian C) {     double db1 = (B.b - A.b), db2 = (C.b - B.b);     double dk1 = (A.k - B.k), dk2 = (B.k - C.k);     return db1 * dk2 >= db2 * dk1;   }   long long qiu(int cn, int cm) {     while (l < r && jiao_z(zhan[l].suan(cn), zhan[l], zhan[l + 1])) l++;     if (l > r) return -10000000000000000;     return -zhan[l].suan(cn) * (cm - zhan[l].k) - cn + zhan[l].b;   }   void zeng(int ck, long long cb) {     xian lin;     lin.mk(ck, cb);     while (l < r && jiao(zhan[r - 1], zhan[r], lin)) r--;     zhan[++r] = lin;   }   int main() {     Read(n);     Read(m);     for (int i = 1; i <= n; i++) a[i].getit();     sort(a + 1, a + n + 1);     xlen = 0;     for (int i = 1; i <= n; i++) {       if (a[i].v <= 0) continue;       while (xlen && a[xu[xlen]].c > a[i].c) xlen--;       xu[++xlen] = i;     }     for (int i = 1; i <= xlen; i++) a[i] = a[xu[i]];     n = xlen;     f[0] = 0;     a[0].v = a[0].c = 0;     l = 1;     r = 0;     f[1] = 0;     zeng(a[1].v, f[1]);     long long ans = (m + a[1].v - 1) / a[1].v;     for (int i = 2; i <= n; i++) {       f[i] = qiu(a[i].c, a[i].v);       zeng(a[i].v, f[i]);       Min(ans, (m - f[i] + a[i].v - 1) / a[i].v);     }     Write(ans);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 400010;   int c[maxn];   int ans[maxn];   void upd(int n, int k) {     n++;     while (n < maxn) c[n] += k, n += n & (-n);   }   int get(int n) {     n++;     int ans = 0;     while (n) ans += c[n], n -= n & (-n);     return ans;   }   int BS(int n) {     int l = 0, r = maxn - 1, mid;     while (l < r) {       mid = (l + r) / 2;       if (get(mid) >= n)         r = mid;       else         l = mid + 1;     }     return l;   }   int arr[maxn];   int a[maxn], b[maxn];   int main() {     int n, i, j, k;     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) cin >> b[i];     for (i = 0; i < n; i++) upd(i, 1);     for (i = 0; i < n; i++) {       arr[i] += get(a[i]) - 1;       upd(a[i], -1);     }     for (i = 0; i < n; i++) upd(i, 1);     for (i = 0; i < n; i++) {       arr[i] += get(b[i]) - 1;       upd(b[i], -1);     }     for (i = n - 1; i >= 0; i--) {       if (arr[i] <= n - i - 1)         ;       else {         arr[i] %= n - i;         if (i) arr[i - 1]++;       }     }     for (i = 0; i < n; i++) upd(i, 1);     for (i = 0; i < n; i++) ans[i] = BS(arr[i] + 1), upd(ans[i], -1);     for (i = 0; i < n; i++) cout << ans[i] <<    ;     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   class SegmentTree {    public:     SegmentTree(int _n) : n(_n), N(_n << 1), data(N, INT_MAX) {       h = 0;       while (1 << h <= N) {         ++h;       }     }     void build(vector<int>& nums) {       copy(nums.begin(), nums.end(), data.begin() + n);       for (int i = n - 1; i > 0; --i) {         data[i] = min(data[i << 1], data[i << 1 | 1]);       }     }     int get(int l, int r) {       l += n;       r += n;       int res = INT_MAX;       while (l <= r) {         if (l & 0x1) {           res = min(res, data[l++]);         }         if (!(r & 0x1)) {           res = min(res, data[r--]);         }         l >>= 1;         r >>= 1;       }       return res;     }       private:     int N;     int n;     int h;     vector<int> data;   };   class SuffixArray {    public:     SuffixArray(const string& s) : N(s.length()), st(N + 100) { build(s); }     const vector<int>& getSuffixArray() { return sa; }     const vector<int>& getIndexArray() { return indices; }     const vector<int>& getLcpArray() { return lcp; }     long long lcpOf(int l, int r) {       if (l == r) {         return N - l;       }       l = indices[l];       r = indices[r];       if (l > r) {         swap(l, r);       }       return st.get(l + 1, r);     }       private:     int N;     vector<int> sa;     vector<int> indices;     vector<int> lcp;     SegmentTree st;     struct Datum {      public:       Datum(int i = -1, int k0 = -1, int k1 = -1)           : index(i), key0(k0), key1(k1) {}       bool operator<(const Datum& other) const {         return key0 == other.key0 ? key1 < other.key1 : key0 < other.key0;       }       int index;       int key0;       int key1;     };     void build(const string& s) {       N = s.length();       sa.clear();       sa.resize(N, -1);       indices.clear();       indices.resize(N, -1);       vector<Datum> data(N);       for (int i = 0; i < N; ++i) {         data[i].index = i;         data[i].key0 = s[i];       }       auto update = [&](int gap) {         int idx = -1, preKey0 = -1, preKey1 = -1;         for (int i = 0; i < N; ++i) {           int key0 = data[i].key0, key1 = data[i].key1;           if (key0 != preKey0 || key1 != preKey1) {             data[i].key0 = ++idx;             preKey0 = key0;             preKey1 = key1;           } else {             data[i].key0 = idx;           }           indices[data[i].index] = i;         }         for (int i = 0; i < N; ++i) {           int j = data[i].index + gap;           if (j < N) {             data[i].key1 = data[indices[j]].key0;           } else {             data[i].key1 = -1;           }         }       };       sort(data.begin(), data.end());       int gap = 1;       update(gap);       while (gap <= N) {         sort(data.begin(), data.end());         update(gap <<= 1);       }       for (int i = 0; i < N; ++i) {         sa[i] = data[i].index;         indices[sa[i]] = i;       }       buildLcp(s);     }     void buildLcp(const string& s) {       lcp.clear();       lcp.resize(N, 0);       int len = 0;       for (int i = 0; i < N; ++i) {         int idx = indices[i];         if (idx == 0) {           lcp[idx] = 0;           len = 0;           continue;         }         int j = sa[idx - 1];         while (i + len < N && j + len < N && s[i + len] == s[j + len]) {           ++len;         }         lcp[idx] = len;         if (len > 0) {           --len;         }       }       st.build(lcp);     }   };   class Solution {    public:     Solution(const string& s)         : N(s.length()),           sfxArr(s),           lcp(N + 1000, make_pair(-1, -1)),           cnts(N + 1000, 0),           sums(N + 1000, 0LL),           S(s) {}     long long query(vector<int>& A, int n, vector<int>& B, int m) {       const auto& indices = sfxArr.getIndexArray();       auto cmp = [&](int l, int r) { return indices[l] < indices[r]; };       sort(A.begin(), A.begin() + n, cmp);       sort(B.begin(), B.begin() + m, cmp);       if (n > m) {         swap(A, B);         swap(n, m);       }       long long res = 0;       int size = 0;       long long sum = 0;       for (int i = 0, j = 0; i < n || j < m;) {         if (j == m) {           break;         }         if (i < n && indices[A[i]] <= indices[B[j]]) {           int len = 0;           int cnt = 0;           if (i == 0) {             len = N - A[i];             cnt = 0;           } else {             len = sfxArr.lcpOf(A[i - 1], A[i]);             cnt = 0;             while (size > 0) {               if (lcp[size - 1].first >= len) {                 sum -= 1LL * lcp[size - 1].first * lcp[size - 1].second;                 cnt += lcp[size - 1].second;                 --size;               } else {                 break;               }             }           }           if (cnt > 0) {             lcp[size].first = len;             lcp[size].second = cnt;             sum += 1LL * len * cnt;             cnts[size + 1] = cnts[size] + cnt;             sums[size + 1] = sum;             ++size;           }           lcp[size].first = N - A[i];           lcp[size].second = 1;           sum += N - A[i];           cnts[size + 1] = cnts[size] + 1;           sums[size + 1] = sum;           assert(cnts[size + 1] == i + 1);           ++size;           ++i;         } else {           if (i - 1 >= 0) {             int len = sfxArr.lcpOf(A[i - 1], B[j]);             auto it =                 lower_bound(lcp.begin(), lcp.begin() + size, make_pair(len, 0));             int idx = it - lcp.begin() - 1;             if (idx < 0) {               res += 1LL * len * i;             } else {               res += sums[idx + 1] + 1LL * len * (i - cnts[idx + 1]);             }           }           ++j;         }       }       size = 0;       sum = 0;       for (int i = n - 1, j = m - 1; i >= 0 || j >= 0;) {         if (j < 0) {           break;         }         if (i >= 0 && indices[A[i]] > indices[B[j]]) {           int len = 0;           int cnt = 0;           if (i == n - 1) {             len = N - A[i];             cnt = 0;           } else {             len = sfxArr.lcpOf(A[i + 1], A[i]);             cnt = 0;             while (size > 0) {               if (lcp[size - 1].first >= len) {                 sum -= 1LL * lcp[size - 1].first * lcp[size - 1].second;                 cnt += lcp[size - 1].second;                 --size;               } else {                 break;               }             }           }           if (cnt > 0) {             lcp[size].first = len;             lcp[size].second = cnt;             sum += 1LL * len * cnt;             cnts[size + 1] = cnts[size] + cnt;             sums[size + 1] = sum;             ++size;           }           lcp[size].first = N - A[i];           lcp[size].second = 1;           sum += N - A[i];           cnts[size + 1] = cnts[size] + 1;           sums[size + 1] = sum;           assert(cnts[size + 1] == n - i);           ++size;           --i;         } else {           if (i + 1 < n) {             int len = sfxArr.lcpOf(A[i + 1], B[j]);             auto it =                 lower_bound(lcp.begin(), lcp.begin() + size, make_pair(len, 0));             int idx = it - lcp.begin() - 1;             if (idx < 0) {               res += 1LL * len * (n - i - 1);             } else {               res += sums[idx + 1] + 1LL * len * (n - i - 1 - cnts[idx + 1]);             }           }           --j;         }       }       return res;     }       private:     int N;     string S;     SuffixArray sfxArr;     vector<pair<int, int>> lcp;     vector<int> cnts;     vector<long long> sums;     void check(vector<int>& A, int n, vector<int>& B, int m, long long res) {       long long ans = 0;       int N = S.length();       auto LCP = [&](int x, int y) {         int res = 0;         for (int i = x, j = y; i < N && j < N; ++i, ++j) {           if (S[i] == S[j]) {             ++res;           } else {             break;           }         }         return res;       };       for (int i = 0; i < n; ++i) {         for (int j = 0; j < m; ++j) {           int a = A[i], b = B[j];           ans += LCP(a, b);         }       }       if (ans != res) {         cout <<  ERROR: WA                <<   got   << res <<   but expected   << ans << endl;       }     }   };   void test() {     vector<string> ts = {{ adsfadfqiewruypzdjfquwieroyzsdf ,                            zduoifyqewrjhlzjkdhfvuioqerwy ,                            adsfuiaednbklzjdrfyquioerwyhadnfb ,  aaaaaaaaaaaaaaa ,                            axaaxadaxaacaaxxaad }};     cout <<  test   << endl;     for (auto s : ts) {       Solution sol(s);       int n = s.length();       vector<int> A(n);       iota(A.begin(), A.end(), 0);       vector<int> B(n);       iota(B.begin(), B.end(), 0);       sol.query(A, n, B, n);     }   }   int main(int argc, char** argv) {     ios::sync_with_stdio(false);     cin.tie(0);     int n, q;     cin >> n >> q;     string s;     cin >> s;     Solution sol(s);     vector<int> A(n + 100);     vector<int> B(n + 100);     int k, l;     while (q-- > 0) {       cin >> k >> l;       for (int i = 0; i < k; ++i) {         cin >> A[i];         --A[i];       }       for (int j = 0; j < l; ++j) {         cin >> B[j];         --B[j];       }       cout << sol.query(A, k, B, l) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, l, x, y;   long long a[100100];   int main() {     cin >> n >> l >> x >> y;     for (int i = 0; i < n; i++) cin >> a[i];     bool fx = false, fy = false;     for (int i = 0; i < n; i++) {       if (binary_search(a, a + n, a[i] + x)) {         fx = true;         break;       }     }     for (int i = 0; i < n; i++) {       if (binary_search(a, a + n, a[i] + y)) {         fy = true;         break;       }     }     if (fx && fy) {       printf( 0 n );       return 0;     }     if (fx && !fy) {       printf( 1 n );       cout << y << endl;       return 0;     }     if (!fx && fy) {       printf( 1 n );       cout << x << endl;       return 0;     }     for (int i = 0; i < n; i++) {       if (binary_search(a, a + n, a[i] + x + y)) {         printf( 1 n );         cout << a[i] + x << endl;         return 0;       }     }     for (int i = 0; i < n; i++) {       if (binary_search(a, a + n, a[i] + y - x)) {         if (a[i] + y > l && a[i] - x < 0) continue;         if (a[i] + y <= l) {           printf( 1 n );           cout << a[i] + y << endl;         } else {           printf( 1 n );           cout << a[i] - x << endl;         }         return 0;       }     }     printf( 2 n );     cout << x <<     << y << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 500010;   int n, m;   int seg[MAX];   int vis[MAX];   int p[MAX];   int in[MAX], out[MAX];   int aux = 0;   vector<int> adj[MAX];   set<int> s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int x, s;     cin >> x >> s;     if (!s) {       if (x == 1)         cout <<  0 0 n ;       else         cout <<  -1 -1 n ;       return 0;     }     if (9 * x < s) {       cout <<  -1 -1 n ;       return 0;     }     string sb;     int s1 = s;     for (int i = 1; i <= x; i++) {       if (s > 9)         sb +=  9 , s -= 9;       else if (i == x)         sb +=  0  + s;       else if (s > 1)         sb +=  0  + (s - 1), s = 1;       else         sb +=  0 ;     }     reverse(sb.begin(), sb.end());     cout << sb <<   n ;     string st;     for (int i = 1; i <= x; i++) {       if (s1 >= 9)         st +=  9 , s1 -= 9;       else         st += s1 +  0 , s1 = 0;     }     cout << st <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   long long n, k;   long long a[N];   bool check(long double x) {     long double ans1 = 0, ans2 = 0;     for (long long i = 0; i < n; i++) {       if (a[i] > x) ans1 += (long double)(a[i] - x);       if (x > a[i]) ans2 += (long double)(x - a[i]);     }     return ans1 * (100 - k) * 0.01 >= ans2;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (long long i = 0; i < n; i++) cin >> a[i];     long double l = *min_element(a, a + n), r = *max_element(a, a + n) + 1;     for (long long i = 0; i < 300; i++) {       long double mid = (l + r) / 2;       if (check(mid))         l = mid;       else         r = mid;     }     cout << fixed << setprecision(12);     cout << l <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100000];   int main() {     long long n;     long long cnt = 0;     scanf( %I64d , &n);     for (long long i = 0; i < n; i++) {       scanf( %I64d , &a[i]);       for (long long j = 0; j < i; j++)         if (a[j] > a[i]) cnt++;     }     cout << (cnt % 2 + (cnt / 2) * 4) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> v;   map<int, int> a, b;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     int m = n / 2;     if (n % 2 != 0) {       m++;     }     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       a[x]++;       if (x != y) {         b[y]++;       }       v.push_back(x);       v.push_back(y);     }     int ans = 1e9;     for (int i = 0; i < 2 * n; i++) {       int cur = v[i];       int cnt = a[cur];       int need = max(0, m - cnt);       if (b[cur] >= need) {         ans = min(ans, need);       }     }     if (ans == 1e9) {       cout << -1;       return 0;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int arr[n];     int count = 0;     int count1 = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] & 1) {         count++;       }     }     int f[n];     int sum = 0;     for (int i = 0; i < n; i++) {       f[i] = floor(double(arr[i]) / 2);       sum += f[i];     }     for (int i = 0; i < n; i++) {       if (sum == 0) break;       if (arr[i] & 1) {         sum++;         f[i]++;       }     }     for (int i = 0; i < n; i++) {       cout << f[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void io() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   long long I() {     long long a;     cin >> a;     return a;   }   void PV(vector<long long> v) {     for (long long i = 0; i < (long long)v.size(); i++) cout << v[i] <<    ;     cout <<   n ;   }   void PA(long long v[], long long n, long long x = 0) {     for (long long i = x; i < n + x; i++) cout << v[i] <<    ;     cout <<   n ;   }   void IA(long long a[], long long n, long long x = 0) {     for (long long i = x; i < n + x; i++) cin >> a[i];   }   const long long N = (2e5) + 7, N1 = 1e9 + 7, MOD = 1e9 + 7, INF = (1e17 + 7);   long long fact[N];   long long power(long long a, long long b) {     long long k = 1;     for (; b; b /= 2, a = a * a % MOD)       if (b % 2 == 1) k = k * a % MOD;     return k % MOD;   }   void pre() {     fact[0] = 1;     for (long long i = 1; i < N; i++) fact[i] = (fact[i - 1] * i) % N1;   }   void solve() {     long long n;     cin >> n;     long long ans = fact[2 * n] * (power(2, N1 - 2));     ans %= MOD;     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t1 = 1, x0 = 1;     pre();     cin >> t1;     while (t1--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   stack<int> sk;   int main() {     int T;     string s;     cin >> T;     while (T--) {       while (sk.size()) sk.pop();       cin >> s;       int cnt = 0;       for (int i = 0; i < s.size(); ++i) {         if (sk.empty()) {           sk.push(s[i] -  0 );           continue;         }         if (s[i] ==  0  && sk.top() == 1) {           cnt++;           sk.pop();         } else if (s[i] ==  1  && sk.top() == 0) {           cnt++;           sk.pop();         } else           sk.push(s[i] -  0 );       }       if (cnt % 2)         puts( DA );       else         puts( NET );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, j, k, chng_cnt;     cin >> n >> m;     int ara1[n + 1], ara2[n + 1], cnt[m + 1], maximizedMin;     memset(cnt, 0, sizeof(cnt));     memset(ara1, 0, sizeof(ara1));     memset(ara2, 0, sizeof(ara2));     for (i = 1; i <= n; i++) {       cin >> ara1[i];     }     maximizedMin = n / m;     for (i = 1; i <= n; i++) {       if (ara1[i] > m) {         ara2[i] = -1;       } else {         cnt[ara1[i]]++;         if (cnt[ara1[i]] <= maximizedMin) {           ara2[i] = ara1[i];         } else {           ara2[i] = -1;         }       }     }     chng_cnt = 0;     for (i = 1; i <= m; i++) {       if (cnt[i] < maximizedMin) {         for (j = 1; j <= n; j++) {           if (cnt[i] == maximizedMin) break;           if (ara2[j] == -1) {             ara2[j] = i;             cnt[i]++;             chng_cnt++;           }         }       }     }     for (i = 1; i <= n; i++) {       if (ara2[i] == -1) {         ara2[i] = ara1[i];       }     }     printf( %d %d n , maximizedMin, chng_cnt);     for (i = 1; i <= n; i++) {       if (i == n)         printf( %d n , ara2[i]);       else         printf( %d  , ara2[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1111;   const int M = 33333;   const int INF = 2e9 + 9;   int n, m;   int s, t;   int erased_edge;   struct Edge {     int u, v, c;     Edge() {}     Edge(int u, int v, int c) {       this->u = u;       this->v = v;       this->c = c;     }     int to(int node) { return u ^ node ^ v; }   } E[M];   vector<int> a[N];   vector<int> path;   vector<int> findPath() {     queue<int> Q;     vector<int> trace(n + 1, -1);     trace[t] = 0;     Q.push(t);     while (!Q.empty()) {       int u = Q.front();       Q.pop();       for (int e : a[u])         if (erased_edge != e) {           int v = E[e].to(u);           if (trace[v] != -1) continue;           trace[v] = e;           Q.push(v);         }     }     vector<int> ans;     if (trace[s] == -1) return ans;     for (int u = s; u != t; u = E[trace[u]].to(u)) {       ans.push_back(trace[u]);     }     return ans;   }   vector<int> solveOneEdge() {     int best = INF;     int ans = -1;     for (int e : path) {       erased_edge = e;       if (findPath().empty() && best > E[e].c) {         best = E[e].c;         ans = e;       }     }     vector<int> res;     res.push_back(best);     res.push_back(ans);     return res;   }   int timer = 0;   int parent_edge[N], parent_cost[N];   int num[N], low[N];   bool containST[N];   void dfs(int u) {     ;     num[u] = ++timer;     low[u] = INF;     containST[u] = u == t;     for (int e : a[u]) {       if (e == erased_edge || e == parent_edge[u]) continue;       int v = E[e].to(u);       if (num[v]) {         ;         low[u] = min(low[u], num[v]);       } else {         parent_edge[v] = e;         parent_cost[v] = E[e].c;         dfs(v);         low[u] = min(low[u], low[v]);         containST[u] |= containST[v];       }     }   }   vector<int> solveTwoEdge() {     int best = INF;     int ans1 = -1, ans2 = -1;     for (int e : path) {       erased_edge = e;       timer = 0;       fill(parent_edge + 1, parent_edge + n + 1, 0);       fill(num + 1, num + n + 1, 0);       fill(containST + 1, containST + n + 1, 0);       parent_edge[s] = -1;       ;       dfs(s);       for (int v = 1; v <= n; ++v)         if (v != s && low[v] >= num[v] && containST[v]) {           if (best > E[erased_edge].c + parent_cost[v]) {             best = E[erased_edge].c + parent_cost[v];             ans1 = erased_edge;             ans2 = parent_edge[v];           };           ;         }     }     vector<int> res;     res.push_back(best);     res.push_back(ans1);     res.push_back(ans2);     return res;   }   int main() {     ios_base ::sync_with_stdio(0);     cin >> n >> m;     cin >> s >> t;     for (int i = 1; i <= m; ++i) {       int u, v, c;       cin >> u >> v >> c;       E[i] = Edge(u, v, c);       a[u].push_back(i);       a[v].push_back(i);     }     ::path = findPath();     ;     if (::path.empty()) {       cout << 0 <<   n  << 0 <<   n ;       return 0;     }     vector<int> one = solveOneEdge();     vector<int> two = solveTwoEdge();     int mn = min(one[0], two[0]);     if (mn == INF) {       cout <<  -1 n ;       return 0;     }     if (one[0] < two[0]) {       cout << one[0] <<   n  << 1 <<   n  << one[1] <<   n ;       return 0;     }     cout << two[0] <<   n  << 2 <<   n  << two[1] <<     << two[2] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, k, n, arr[200010];     cin >> n;     for (i = 0; i < n; i++) cin >> arr[i];     long long sum = arr[n - 1];     for (i = n - 1; i > 0; i--) {       if (arr[i] <= arr[i - 1] && arr[i - 1] != 0) {         if (arr[i] == 0)           arr[i - 1] = arr[i];         else           arr[i - 1] = arr[i] - 1;       }       sum += arr[i - 1];     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int SIZE = 1e6 + 10;   const int INF = 2147483647;   template <class T>   void maa(T& x, T y) {     if (x < y) x = y;   }   template <class T>   void mii(T& x, T y) {     if (x > y) x = y;   }   int a[SIZE];   int record[SIZE][3], rn;   void update_answer(int ll, int rr, int cul) {     record[rn][0] = ll;     record[rn][1] = rr;     record[rn][2] = cul;     rn++;   }   int C, l[SIZE], r[SIZE], c[SIZE], cn, cc_pos[SIZE];   pair<int, int> cc[SIZE];   vector<pair<int, int> > qq;   int single_add[SIZE];   int kerker[SIZE];   set<pair<int, int> > singles;   pair<int, int> BIT[SIZE][2];   void ins(int x, int v) {     pair<int, int> me = make_pair(v, x);     for (; x < SIZE; x += x & -x) {       if (me > BIT[x][0]) {         if (BIT[x][0].second != me.second) {           BIT[x][1] = BIT[x][0];         }         BIT[x][0] = me;       } else if (me > BIT[x][1]) {         BIT[x][1] = me;       }     }   }   int qq_BIT(int x, int id) {     int res = 0;     for (; x; x -= x & -x) {       if (BIT[x][0].second != id)         res = max(res, BIT[x][0].first);       else         res = max(res, BIT[x][1].first);     }     return res;   }   void update_single(int id, int v) {     single_add[id] += v;     ins(cc_pos[id], single_add[id]);   }   int get_single_ma(int id) {     int it = upper_bound(cc + 1, cc + cn, make_pair(C - c[id], INF)) - cc - 1;     if (it) {       return qq_BIT(it, cc_pos[id]);     }     return 0;   }   pair<int, int> GP(int x, int y) {     if (x > y) return make_pair(y, x);     return make_pair(x, y);   }   int an[SIZE];   int main() {     int n;     scanf( %d%d , &(n), &(C));     vector<pair<int, int> > rain;     cn = 1;     for (int i = (1); i < (n + 1); ++i) {       scanf( %d%d%d , &(l[i]), &(r[i]), &(c[i]));       rain.push_back(make_pair(l[i], i));       rain.push_back(make_pair(r[i], -i));       cc[cn++] = make_pair(c[i], i);     }     sort(cc + 1, cc + cn);     for (int i = (1); i < (cn); ++i) cc_pos[cc[i].second] = i;     sort((rain).begin(), (rain).end());     rain.push_back(make_pair(2000000000, 0));     int(m);     scanf( %d , &m);     for (int i = 0; i < (m); ++i) {       int(x);       scanf( %d , &x);       qq.push_back(make_pair(x, i));     }     sort((qq).begin(), (qq).end());     map<pair<int, int>, int> pair_add;     set<int> now;     int zero = 0;     int pair_ma = 0;     if (rain[0].first) {       update_answer(0, rain[0].first, 0);       zero += rain[0].first;     }     for (int i = 0, j; i < 2 * n; i = j) {       for (j = i; j < 2 * n && rain[j].first == rain[i].first; j++) {         int id = rain[j].second;         if (id < 0) {           now.erase(-id);         } else {           now.insert(id);         }       }       if (((int)(now).size()) == 0) {         update_answer(rain[i].first, rain[j].first,                       zero + max(pair_ma, get_single_ma(0)));         zero += rain[j].first - rain[i].first;       } else if (((int)(now).size()) == 1) {         int me = *now.begin();         if (c[me] <= C) {           int v = single_add[me] + max(get_single_ma(me), kerker[me]);           update_answer(rain[i].first, rain[j].first, zero + v);           update_single(me, rain[j].first - rain[i].first);           maa(pair_ma, v + rain[j].first - rain[i].first);         }       } else if (((int)(now).size()) == 2) {         int me = *now.begin();         int you = *now.rbegin();         if (c[me] + c[you] <= C) {           update_answer(               rain[i].first, rain[j].first,               zero + single_add[me] + single_add[you] + pair_add[GP(me, you)]);           pair_add[GP(me, you)] += rain[j].first - rain[i].first;           maa(pair_ma, single_add[me] + single_add[you] + pair_add[GP(me, you)]);           maa(kerker[me], pair_add[GP(me, you)] + single_add[you]);           maa(kerker[you], pair_add[GP(me, you)] + single_add[me]);         }       }     }     {       int it = 0;       for (int i = 0; i < (rn); ++i) {         while (it < m &&                record[i][1] - record[i][0] + record[i][2] >= qq[it].first) {           an[qq[it].second] = record[i][0] + (qq[it].first - record[i][2]);           it++;         }       }     }     for (int i = 0; i < (m); ++i) printf( %d n , an[i]);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int test;     scanf( %d , &test);     while (test--) {       int fuck;       string str;       scanf( %d , &fuck);       cin >> str;       string ans =   ;       for (auto &x : str) {         if ((x -  0 ) % 2 == 1) {           ans += x;           if (ans.size() == 2) {             break;           }         }       }       if (ans.size() == 2) {         puts(ans.c_str());         continue;       }       puts( -1 );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, int> MP;   int Q = 1;   vector<pair<int, int> > adj[500005];   long long C[500005];   set<int> S;   int p[500005];   long long pw(int x) {     if (!x) return 1LL;     if (x & 1) return 2 * pw(x - 1) % 1000000007;     long long hf = pw(x / 2);     return hf * hf % 1000000007;   }   int par(int x) {     if (p[x] == x) return x;     return p[x] = par(p[x]);   }   int main() {     int N, M, K;     scanf( %d%d%d , &N, &M, &K);     long long X = (1LL << K);     for (int i = 1; i <= N; i++) scanf( %lld , &C[i]);     for (int i = 0; i < M; i++) {       int u, v;       scanf( %d%d , &u, &v);       long long x = C[u] ^ C[v];       int t = MP[x];       if (!t) {         MP[x] = Q;         adj[Q].push_back(pair<int, int>(u, v));         Q++;       } else {         adj[t].push_back(pair<int, int>(u, v));       }     }     int ans = 0;     for (int i = 1; i <= N; i++) p[i] = i;     for (int i = 1; i < Q; i++) {       int sz = N;       for (pair<int, int> j : adj[i]) {         int u = j.first, v = j.second;         S.insert(u);         S.insert(v);         if (par(u) != par(v)) {           sz--;           p[p[v]] = p[u];         }       }       ans = (ans + pw(sz)) % 1000000007;       while (S.size()) {         int now = *(S.begin());         p[now] = now;         S.erase(S.begin());       }     }     printf( %lld n ,            ((X - Q + 1) % 1000000007 * pw(N) % 1000000007 + ans) % 1000000007);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename L>   bool smax(T &x, L y) {     return x < y ? (x = y, true) : false;   }   struct Q {     int p, id;   };   int get(int, int);   void dfs(int);   void sack(int, bool);   const int MAXN = 1e5 + 15, LG = 20;   int h[MAXN], cnt[MAXN];   int st[MAXN], ft[MAXN], add[MAXN];   int ans[MAXN];   int par[LG][MAXN];   vector<int> adj[MAXN];   vector<Q> node[MAXN];   int n, m;   int32_t main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cerr <<  HELLO WORLD :) n ;     cin >> n;     for (int i = 1; i <= n; i++) {       int tmp;       cin >> tmp;       adj[tmp].push_back(i);     }     dfs(0);     cin >> m;     for (int i = 1; i <= m; i++) {       int p, v;       cin >> v >> p;       node[get(v, p)].push_back({p, i});     }     sack(0, 0);     for (int i = 1; i <= m; i++) cout << ans[i] <<    ;     return cout <<   n , false;   }   void dfs(int v) {     static int t = 0;     st[v] = t++;     add[st[v]] = v;     for (int i = 1; i < LG; i++) par[i][v] = par[i - 1][par[i - 1][v]];     for (auto u : adj[v]) {       h[u] = h[v] + 1;       par[0][u] = v;       dfs(u);     }     ft[v] = t;   }   int get(int v, int p) {     int u = v;     for (int i = LG - 1; ~i; i--)       if (p >> i & 1) u = par[i][u];     return u;   }   void sack(int v, bool keep) {     int id = -1, mx = -1;     for (auto u : adj[v])       if (smax(mx, ft[u] - st[u])) id = u;     for (auto u : adj[v])       if (u != id) sack(u, 0);     if (id != -1) sack(id, 1);     for (auto u : adj[v])       if (u != id)         for (int i = st[u]; i < ft[u]; i++) cnt[h[add[i]]]++;     cnt[h[v]]++;     if (v)       for (auto u : node[v]) ans[u.id] = cnt[h[v] + u.p] - 1;     if (!keep)       for (int i = st[v]; i < ft[v]; i++) cnt[h[add[i]]]--;   }