#include <bits/stdc++.h>   using namespace std;   inline long long int c(long long int n, long long int i) {     if (i == 0)       return 1;     else if (i == 1)       return n;     else if (i == 2)       return (n * (n - 1)) / 2;     else if (i == 3)       return (n * (n - 1) * (n - 2)) / 6;     else if (i == 4)       return (n * (n - 1) * (n - 2) * (n - 3)) / 24;   }   int main() {     long long int d[5];     d[0] = 1;     d[1] = 0;     d[2] = 1;     d[3] = 2;     d[4] = 9;     long long int n, k;     cin >> n >> k;     long long int ans = 0;     for (long long int i = 0; i <= k; i++) ans += d[i] * c(n, i);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int f(int n) {     if (n < 10) {       return n;     }     int ans = 1;     while (n) {       if (n % 10 != 0) {         ans *= n % 10;       }       n /= 10;     }     return ans;   }   int g[1000005];   int cnt[10][1000005];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     for (int i = 1; i <= 1000000; i++) {       if (i < 10) {         g[i] = i;       } else {         g[i] = g[f(i)];       }       if (i <= 60) {       }       for (int j = 1; j <= 9; j++) {         cnt[j][i] = cnt[j][i - 1];       }       cnt[g[i]][i]++;     }     int T;     cin >> T;     while (T--) {       int l, r, k;       cin >> l >> r >> k;       cout << cnt[k][r] - cnt[k][l - 1] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int N = 100200;   struct Node {     int to, cost;   };   vector<Node> g[N];   int dist[105][N] = {}, arr[N] = {}, n, m, type[N] = {}, k, s, vis[N] = {};   void addedge(int u, int v, int cost) {     g[u].push_back((Node){v, cost});     g[v].push_back((Node){u, cost});   }   void bfs(int s, int n, int* d) {     queue<int> que;     memset(vis, 0, sizeof(vis));     int p, to, cost;     que.push(s);     vis[s] = 1;     while (!que.empty()) {       p = que.front();       que.pop();       const int sz = g[p].size();       for (int i = 0; i < sz; i++) {         to = g[p][i].to;         if (to > n - 1 || vis[to]) continue;         d[to] = d[p] + 1;         que.push(to);         vis[to] = 1;       }     }   }   int main(void) {     std::ios::sync_with_stdio(false);     cin >> n >> m >> k >> s;     for (int i = 0; i < n; i++) cin >> type[i];     int u, v;     for (int i = 0; i < m; i++) {       cin >> u >> v;       u--;       v--;       addedge(u, v, 1);     }     for (int i = 0; i < n; i++) {       addedge(n - 1 + type[i], i, 1);     }     for (int i = 1; i <= k; i++) {       bfs(n - 1 + i, n, dist[i]);     }     for (int i = 0; i < n; i++) {       int ans = 0;       for (int j = 1; j <= k; j++) arr[j] = dist[j][i] - 1;       sort(arr + 1, arr + k + 1);       for (int i = 1; i <= s; i++) ans += arr[i];       cout << ans <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long n, l, x, y, a[1 << 20];   set<long> has;   long hx, hy;   long ans;   long thx, thy;   void check(long ps) {     if (ps < 0 || ps > l) return;     hx = thx;     hy = thy;     if (has.find(ps + x) != has.end()) hx = 1;     if (has.find(ps + y) != has.end()) hy = 1;     if (has.find(ps - x) != has.end()) hx = 1;     if (has.find(ps - y) != has.end()) hy = 1;     if (hx && hy) ans = ps;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> l >> x >> y;     for (int i = 0; i < n; i++) {       cin >> a[i];       has.insert(a[i]);     }     hx = hy = 0;     for (int i = 0; i < n; i++) {       if (has.find(a[i] + x) != has.end()) hx = 1;       if (has.find(a[i] + y) != has.end()) hy = 1;       if (has.find(a[i] - x) != has.end()) hx = 1;       if (has.find(a[i] - y) != has.end()) hy = 1;     }     thx = hx;     thy = hy;     if (hx && hy) {       cout << 0 << endl;     } else {       ans = -1;       for (int i = 0; i < n; i++) {         check(a[i] - x);         check(a[i] + x);         check(a[i] - y);         check(a[i] + y);       }       if (ans >= 0)         cout << 1 << endl << ans << endl;       else {         cout << 2 << endl;         cout << x <<     << y << endl;       }     }     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int k;   bool debug = false;   int a[105];   int main() {     cin >> n;     for (int i = 0, x; i < n; i++) {       scanf( %d , &x);       a[x]++;     }     for (int i = 0; i < 105; i++) k += a[i] / 2;     printf( %d n , k / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n, m, a[1005], b[1005], ans;   bool c[1005], lol;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       lol = false;       fill(c, c + 1005, false);       cin >> n >> m;       for (int i = 0; i < n; ++i) {         cin >> a[i];         c[a[i]] = true;       }       for (int i = 0; i < m; ++i) {         cin >> b[i];         if (c[b[i]] == true) {           ans = b[i];           lol = true;         }       }       if (lol == true)         cout <<  YES n1   << ans <<   n ;       else         cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> adj[200003];   vector<pair<int, pair<int, int>>> edges;   vector<long long> len;   set<int> vertices;   void dijkstra(int start) {     set<int> vis;     priority_queue<pair<long long, int>, vector<pair<long long, int>>,                    greater<pair<long long, int>>>         pq;     pq.push(make_pair(0, start));     while (!pq.empty()) {       while (!pq.empty() && vis.find(pq.top().second) != vis.end()) pq.pop();       if (pq.empty()) break;       long long l = pq.top().first;       int v = pq.top().second;       pq.pop();       vis.insert(v);       if (l != 0) len.push_back(l);       for (int i = 0; i < adj[v].size(); i++) {         if (vis.find(adj[v][i].first) == vis.end()) {           pq.push(make_pair(l + 1ll * adj[v][i].second, adj[v][i].first));         }       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < m; i++) {       int a, b, w;       cin >> a >> b >> w;       edges.push_back(make_pair(w, make_pair(a, b)));     }     sort(edges.begin(), edges.end());     for (int i = 0; i < k && i < edges.size(); i++) {       vertices.insert(edges[i].second.first);       vertices.insert(edges[i].second.second);       adj[edges[i].second.first].push_back(           make_pair(edges[i].second.second, edges[i].first));       adj[edges[i].second.second].push_back(           make_pair(edges[i].second.first, edges[i].first));     }     for (int x : vertices) {       dijkstra(x);     }     sort(len.begin(), len.end());     cout << len[2 * k - 1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long int t;     cin >> t;     while (t--) {       long long int n, x, i;       cin >> n >> x;       long long int second = 0;       long long int a[n];       for (long long int i = 0; i < n; i++) {         cin >> a[i];       }       sort(a, a + n);       for (i = n - 1; i >= 0; i--) {         second += a[i];         if (second / (n - i) < x) break;       }       cout << n - (i + 1) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long n, k, l, a[1000010], m, p, q, b[1000010], d, c[1000010], f[1000010],       g[1000010], ans;   struct BIT {     long long a[1000010];     void clear() { memset(a, 0, sizeof(a)); }     void add(int x, long long v) {       for (; x <= 1000010 - 5; x += x & (-x)) a[x] = (a[x] + v + mod) % mod;     }     long long get(int x) {       long long ans = 0;       for (; x; x -= x & (-x)) ans = (ans + a[x]) % mod;       return ans;     }   } tr;   int main() {     scanf( %lld%lld%lld , &n, &l, &k);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]), b[i] = a[i];     sort(b + 1, b + n + 1);     d = unique(b + 1, b + n + 1) - b - 1;     for (int i = 1; i <= n; i++) a[i] = lower_bound(b + 1, b + d + 1, a[i]) - b;     m = l / n;     p = l % n;     if (!p) {       m--;       p += n;     }     q = max(0ll, m - k + 1);     q %= mod;     int cnt = 0;     for (int i = 1; i <= k - 1; i++)       for (int j = 1; j <= n; j++) c[++cnt] = a[j];     for (int i = 1; i <= p; i++) c[++cnt] = a[i];     for (int i = cnt - p + 1; i <= cnt; i++) f[i] = 1, tr.add(c[i], f[i]);     for (int i = k - 1; i; --i) {       for (int j = 1; j <= n; j++) {         int pos = (i - 1) * n + j;         f[pos] = (tr.get(1000010 - 5) - tr.get(c[pos] - 1) + mod) % mod;       }       for (int j = 1; j <= n; j++) {         int pos = (i - 1) * n + j;         if (pos + n <= cnt) tr.add(c[pos + n], -f[pos + n]);         tr.add(c[pos], f[pos]);       }     }     for (int i = max(cnt - p - m * n + 1, 1ll); i <= cnt; i++)       ans = (ans + f[i]) % mod;     memset(c, 0, sizeof(c));     tr.clear();     cnt = 0;     for (int i = 1; i <= k; i++)       for (int j = 1; j <= n; j++) c[++cnt] = a[j];     for (int i = cnt - n + 1; i <= cnt; i++) g[i] = 1, tr.add(c[i], g[i]);     for (int i = k - 1; i; --i) {       for (int j = 1; j <= n; j++) {         int pos = (i - 1) * n + j;         g[pos] = (tr.get(1000010 - 5) - tr.get(c[pos] - 1) + mod) % mod;       }       for (int j = 1; j <= n; j++) {         int pos = (i - 1) * n + j;         tr.add(c[pos + n], -g[pos + n]);         tr.add(c[pos], g[pos]);       }     }     long long tmp = 0;     for (int i = 1; i <= min(m, k - 1); i++) {       for (int j = 1; j <= n; j++) {         int pos = (k - i) * n + j;         tmp = (tmp + g[pos]) % mod;       }       ans = (ans + tmp) % mod;     }     tmp = 0;     for (int i = 1; i <= k; i++)       for (int j = 1; j <= n; j++) {         int pos = (i - 1) * n + j;         tmp = (tmp + g[pos]) % mod;       }     tmp = tmp * q % mod;     ans = (ans + tmp) % mod;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 1e6 + 5;   int n, q, m;   const int N = 105;   const int L = 1505;   char s[maxn];   int tr[maxn][30], tot = 0;   int fail[maxn], w[maxn];   vector<int> g[maxn];   void add(char *s, int id) {     int u = 0;     int n = strlen(s);     for (int i = 0; i < n; i++) {       int c = s[i] -  a ;       if (!tr[u][c]) tr[u][c] = ++tot;       u = tr[u][c];     }     w[id] = u;   }   struct bit_tree {     long long c[maxn], n;     void init(int x) { n = x; }     inline int lowbit(int x) { return x & (-x); }     inline void update(int x, int v) {       for (int i = x; i <= n; i += lowbit(i)) {         c[i] += v;       }     }     inline long long query(int x) {       long long ans = 0;       for (int i = x; i > 0; i -= lowbit(i)) ans += c[i];       return ans;     }   } T;   void ac() {     queue<int> q;     for (int i = 0; i < 26; i++) {       if (tr[0][i]) q.push(tr[0][i]), fail[tr[0][i]] = 0;     }     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 0; i < 26; i++) {         if (tr[u][i]) {           fail[tr[u][i]] = tr[fail[u]][i];           q.push(tr[u][i]);         } else {           tr[u][i] = tr[fail[u]][i];         }       }     }   }   int ins[maxn], out[maxn], cnt = 0;   int vis[maxn];   void dfs(int x) {     ins[x] = ++cnt;     for (int i : g[x]) dfs(i);     out[x] = cnt;   }   int main() {     cin >> q >> n;     for (int i = 1; i <= n; i++) {       cin >> s;       add(s, i);     }     ac();     for (int i = 1; i <= tot; i++) {       g[fail[i]].push_back(i);     }     dfs(0);     T.init(cnt);     for (int i = 1; i <= n; i++) {       vis[i] = 1;       T.update(ins[w[i]], 1);       T.update(out[w[i]] + 1, -1);     }     char c;     int id;     while (q--) {       cin >> c;       if (c ==  + ) {         cin >> id;         if (vis[id]) continue;         vis[id] = 1;         T.update(ins[w[id]], 1);         T.update(out[w[id]] + 1, -1);       } else if (c ==  - ) {         cin >> id;         if (!vis[id]) continue;         vis[id] = 0;         T.update(ins[w[id]], -1);         T.update(out[w[id]] + 1, +1);       } else {         cin >> s;         int m = strlen(s);         long long p = 0, ans = 0;         for (int i = 0; i < m; i++) {           p = tr[p][s[i] -  a ];           ans += T.query(ins[p]);         }         printf( %lld n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 7;   int n, m;   vector<int> d[MAXN];   int r[MAXN];   vector<pair<int, int> > g[MAXN];   inline void add_edge(int u, int v, int c) {     g[u].push_back(make_pair(c, v));     g[v].push_back(make_pair(c, u));   }   int col[MAXN];   inline bool dfs(int u, int c) {     if (col[u] != -1) return col[u] == c;     col[u] = c;     for (auto e : (g[u])) {       if (!dfs(e.second, c ^ e.first)) return 0;     }     return 1;   }   inline void read(int &x) {     x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     x *= f;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     read(n);     read(m);     for (int i = (1); i <= (n); ++i) read(r[i]);     for (int i = (1); i <= (m); ++i) {       int x;       read(x);       for (int j = (1); j <= (x); ++j) {         int p;         read(p);         d[p].push_back(i);       }     }     for (int i = (1); i <= (n); ++i) add_edge(d[i][0], d[i][1], r[i] ^ 1);     memset(col, -1, sizeof col);     bool ans = 1;     for (int i = 1; i <= m && ans; ++i)       if (col[i] == -1) ans &= dfs(i, 0);     cout << (ans ?  YES  :  NO ) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int arr[1000000];   int main() {     int n;     cin >> n;     long long int count = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     long long int Min = arr[0];     long long int Max = arr[0];     for (int i = 1; i < n; i++) {       if (arr[i] >= arr[i - 1])         Min = Max = arr[i];       else {         int j = i;         long long int mmin = arr[j - 1];         long long int mmax = arr[j - 1];         int c = 0;         while (arr[j - 1] > arr[j]) {           mmin = min(arr[j], mmin);           mmax = max(arr[j], mmax);           j++;           if (j == n) break;           c++;         }         count += mmax - mmin;         i += c;       }     }     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, k = 0, nod;     cin >> a;     for (int i = 2; i < a; i++) {       int b = a;       while (b != 0) {         k += b % i;         b /= i;       }     }     int b = a - 2;     for (int i = k; i > 0; i--)       if (k % i == 0 && b % i == 0) {         nod = i;         k /= nod;         b /= nod;         break;       }     cout << k <<  /  << b;   }


#include <bits/stdc++.h>   using namespace std;   long long a[(20ll + (long long)2e5)], b[(20ll + (long long)2e5)],       c[(20ll + (long long)2e5)], *d[(20ll + (long long)2e5)],       e[(20ll + (long long)2e5)];   int main() {     long long n;     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       a[i] *= i * (n - i + 1);       b[i] = a[i];     }     for (long long i = 1; i <= n; i++) {       scanf( %lld , &c[i]);       d[i] = &b[i];     }     sort(d + 1, d + n + 1, [](long long* l, long long* r) { return *l < *r; });     sort(c + 1, c + 1 + n, greater<long long>());     for (long long i = 1; i <= n; i++) {       *d[i] = c[i];     }     long long s = 0, mod = 998244353ll;     for (long long i = 1; i <= n; i++)       s = (s + (a[i] % mod * (b[i] % mod)) % mod) % mod;     printf(          %lld            n ,         s);     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   struct Tree {     int n;     vector<long long> t;     vector<int> mx;     vector<int> val;     vector<int> weights;     void add_val(int v, int l, int r, int now) {       t[v] = weights[v] * (long long)now;       mx[v] = now;       val[v] = now;     }     void push(int v, int l, int r) {       if (val[v] == -1) return;       int m = (l + r) / 2;       add_val(2 * v, l, m, val[v]);       add_val(2 * v + 1, m, r, val[v]);       val[v] = -1;     }     void relax(int v) {       t[v] = t[2 * v] + t[2 * v + 1];       mx[v] = max(mx[2 * v], mx[2 * v + 1]);       weights[v] = weights[2 * v] + weights[2 * v + 1];     }     void build(vector<int>& a, vector<int>& w, int v, int l, int r) {       if (r - l == 1) {         t[v] = a[l] * (long long)w[l];         mx[v] = a[l];         weights[v] = w[l];         return;       }       int m = (l + r) / 2;       build(a, w, 2 * v, l, m);       build(a, w, 2 * v + 1, m, r);       relax(v);     }     Tree(vector<int>& a, vector<int>& w)         : n(a.size()), t(4 * n), val(4 * n, -1), weights(4 * n), mx(4 * n) {       build(a, w, 1, 0, n);     }     long long get_sum(int l, int r, int vt, int lt, int rt) {       if (l >= rt || lt >= r) {         return 0;       }       if (l <= lt && rt <= r) {         return t[vt];       }       push(vt, lt, rt);       int mt = (lt + rt) / 2;       auto first = get_sum(l, r, 2 * vt, lt, mt);       auto second = get_sum(l, r, 2 * vt + 1, mt, rt);       relax(vt);       return first + second;     }     long long get_sum(int l, int r) { return get_sum(l, r, 1, 0, n); }     void change_max(int l, int r, int now, int vt, int lt, int rt) {       if (l >= rt || lt >= r) {         return;       }       int mt = (lt + rt) / 2;       if (l <= lt && rt <= r) {         if (mx[vt] < now) {           add_val(vt, lt, rt, now);           return;         }         if (rt - lt == 1) return;         push(vt, lt, rt);         if (mx[2 * vt] < now) {           add_val(2 * vt, lt, mt, now);           change_max(l, r, now, 2 * vt + 1, mt, rt);         } else {           change_max(l, r, now, 2 * vt, lt, mt);         }         relax(vt);         return;       }       push(vt, lt, rt);       change_max(l, r, now, 2 * vt, lt, mt);       change_max(l, r, now, 2 * vt + 1, mt, rt);       relax(vt);     }     void change_max(int l, int r, int now) { change_max(l, r, now, 1, 0, n); }     int get_pos(int val, int vt, int lt, int rt) {       if (rt - lt == 1) {         return (t[vt] >= val ? lt : -1);       }       push(vt, lt, rt);       int mt = (lt + rt) / 2;       if (mx[2 * vt] >= val) {         return get_pos(val, 2 * vt, lt, mt);       }       return get_pos(val, 2 * vt + 1, mt, rt);     }     int get_pos(int val) { return get_pos(val, 1, 0, n); }     void print(int vt, int lt, int rt) {       if (rt - lt == 1) {         cout << mx[vt] <<    ;         return;       }       push(vt, lt, rt);       int mt = (lt + rt) / 2;       print(2 * vt, lt, mt);       print(2 * vt + 1, mt, rt);       relax(vt);     }     void print() {       cout <<  FXS n ;       print(1, 0, n);       cout <<   n ;     }   };   void add(int& first, int second) {     first += second;     if (first >= INF) {       first -= INF;     }     if (first < 0) {       first += INF;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, k, L;     cin >> n >> k >> L;     set<int> xs;     set<int> ys;     vector<int> color(n);     vector<pair<int, int>> points(n);     map<int, vector<int>> ymp;     for (int i = 0; i < n; ++i) {       int c, first, second;       cin >> first >> second >> c;       --c;       color[i] = c;       points[i] = {first, second};       ymp[second].push_back(i);       xs.insert(first);       ys.insert(second);     }     ys.insert(L);     map<int, int> nx;     vector<int> xval;     int now = 0;     for (int first : xs) {       nx[first] = now++;       xval.push_back(first);     }     int res = 0;     vector<pair<int, int>> xcur;     vector<multiset<int>> allx(k);     int y_prev = 0;     for (int y_up : ys) {       vector<int> fx;       vector<int> lens;       map<int, int> posq;       int pr = 0;       for (auto t : xcur) {         lens.push_back(xval[t.first] - pr + 1);         posq[t.first] = lens.size() - 1;         pr = xval[t.first] + 1;       }       lens.push_back(L - pr);       vector<int> color_count(k, 0);       int exist_colors = 0;       int rt = 0;       while (rt < (int)xcur.size() && exist_colors < k) {         int c = xcur[rt].second;         ++color_count[c];         exist_colors += (color_count[c] == 1);         ++rt;       }       if (exist_colors == k) {         fx.push_back(xval[xcur[rt - 1].first]);       }       for (int lt = 0; lt < (int)xcur.size(); ++lt) {         int c = xcur[lt].second;         --color_count[c];         exist_colors -= (color_count[c] == 0);         while (rt < (int)xcur.size() && exist_colors < k) {           int c = xcur[rt].second;           ++color_count[c];           exist_colors += (color_count[c] == 1);           ++rt;         }         if (exist_colors == k) {           fx.push_back(xval[xcur[rt - 1].first]);         } else           break;       }       while (fx.size() < lens.size()) {         fx.push_back(L);       }       Tree tree(fx, lens);       pr = 0;       for (int y_down : ys) {         if (y_down == y_up) break;         int dy = y_down - pr + 1;         int ddy = y_up - y_prev;         add(res, ddy * (long long)dy % INF *                      ((L * (long long)L - tree.get_sum(0, fx.size())) % INF) %                      INF);         for (auto ind : ymp[y_down]) {           int first = nx[points[ind].first];           int c = color[ind];           allx[c].erase(allx[c].find(first));         }         vector<pair<int, pair<int, int>>> queries;         for (auto ind : ymp[y_down]) {           int first = nx[points[ind].first];           int c = color[ind];           int x_ind =               upper_bound(xcur.begin(), xcur.end(), make_pair(first, INF)) -               xcur.begin() - 1;           auto it = allx[c].lower_bound(first);           int prv = 0, nxt;           if (it != allx[c].end()) {             nxt = xval[*it];           } else {             nxt = L;           }           it = allx[c].upper_bound(first);           if (it != allx[c].begin()) {             prv = posq[*(--it)] + 1;           }           prv = max(prv, tree.get_pos(xval[first]));           queries.push_back({x_ind, {prv, nxt}});         }         sort(queries.rbegin(), queries.rend());         for (auto t : queries) {           int x_ind = t.first;           int prv = t.second.first;           int nxt = t.second.second;           tree.change_max(prv, x_ind + 1, nxt);         }         pr = y_down + 1;       }       for (auto ind : ymp[y_up]) {         xcur.push_back({nx[points[ind].first], color[ind]});       }       sort(xcur.begin(), xcur.end());       for (int i = 0; i < k; ++i) {         allx[i].clear();       }       for (auto t : xcur) {         allx[t.second].insert(t.first);       }       y_prev = y_up;     }     cout << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 1e3 + 10, K = 10 + 2, E = -(1e8 + 10);   long long dp[N][N][K][2];   int n, m, kk;   string s, t;   void read_input() {     cin >> n >> m >> kk;     cin >> s >> t;   }   void solve() {     s =  *  + s, t =  *  + t;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         for (int k = 1; k <= kk; k++) {           dp[i][j][k][1] = (s[i] == t[j] ? 1 + max(dp[i - 1][j - 1][k][1],                                                    dp[i - 1][j - 1][k - 1][0])                                          : 0);           dp[i][j][k][0] =               max({dp[i - 1][j][k][0], dp[i][j - 1][k][0], dp[i][j][k][1]});         }     cout << dp[n][m][kk][0];   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     read_input(), solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   long long pows(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   long long powm(long long x, long long y, long long m = 998244353) {     x = x % m;     long long res = 1;     while (y) {       if (y & 1) res = res * x;       res %= m;       y = y >> 1;       x = x * x;       x %= m;     }     return res;   }   long long modInverse(long long a, long long m) { return powm(a, m - 2, m); }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, i, j, k, x, y, z, t, e, f, p, q, g, l, r, w, h,         count1 = 0, prod = 1, a, b, c, d, index, x1, x2, y1, y2, diff, ans = 0,         sum = 0, sum1 = 0, sum2 = 0, flag = 0, flag1 = 0, flag2 = 0;     string s, s1, s2;     cin >> n >> k;     set<long long> st;     vector<pair<long long, long long>> v(n);     for (i = 0; i < n; i++) {       cin >> v[i].first;       v[i].second = i + 1;     }     sort(v.begin(), v.end(), greater<pair<long long, long long>>());     vector<long long> v1(n + 1);     for (i = k + 1; i <= k + n; i++) {       st.insert(i);     }     for (i = 0; i < n; i++) {       p = *st.lower_bound(v[i].second);       v1[v[i].second] = p;       st.erase(p);       ans += (p - v[i].second) * v[i].first;     }     cout << ans <<   n ;     for (i = 1; i <= n; i++) {       cout << v1[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 5e9;   long long w[20], s[20], m;   bool solve(int bm) {     long long l = 0, r = m;     for (int i = 0; i < 14; ++i) {       if (bm % 3 == 0)         l += w[i];       else if (bm % 3 == 1)         r += w[i];       bm /= 3;     }     return l == r;   }   void special4() {     while (m > 0) {       if (m % 4 == 2) {         cout <<  NO n ;         exit(0);       }       if (m % 4 == 3) {         m += 4;       }       m /= 4;     }     cout <<  YES n ;   }   int main() {     w[0] = 1;     cin >> w[1] >> m;     if (w[1] <= 3) {       cout <<  YES n ;       return 0;     }     for (int i = 2; i < 20; ++i) {       w[i] = w[i - 1] * w[1];       if (w[i] > inf) w[i] = 0;     }     if (w[1] == 4) {       special4();       return 0;     }     for (int bm = 0; bm < (int)5e6; ++bm) {       if (solve(bm)) {         cout <<  YES n ;         return 0;       }     }     cout <<  NO n ;   };


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, b;     cin >> n >> b;     int a[n], maxx = b;     for (int x = 0; x < n; x++) cin >> a[x];     for (int x = 0; x < n; x++) {       for (int y = x + 1; y < n; y++)         maxx = max(maxx, (b / a[x]) * a[y] + (b % a[x]));     }     cout << maxx;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int n, k;   vector<vector<long long>> adj, leaf;   vector<long long> level, par, out;   vector<long long> counti;   void dfs(int src, int lvl, int p = -1) {     int child = 0;     level[src] = lvl;     for (auto it : adj[src]) {       if (it == p) continue;       par[it] = src;       child++;       dfs(it, lvl + 1, src);     }     if (!child) leaf.push_back({src, lvl, 0});     out[src] = child;   }   class comp {    public:     bool operator()(vector<long long> a, vector<long long> b) {       return a[1] - a[2] < b[1] - b[2];     }   };   void solve() {     cin >> n >> k;     adj.resize(n);     for (int i = 0, x, y; i < n - 1; i++) {       cin >> x >> y;       x--, y--;       adj[x].push_back(y);       adj[y].push_back(x);     }     level.resize(n);     par.resize(n);     out.resize(n);     dfs(0, 0);     vector<long long> total(n, 0);     priority_queue<vector<long long>, vector<vector<long long>>, comp> pq;     for (auto it : leaf) pq.push(it);     long long ans = 0;     while (!pq.empty() && k--) {       auto f = pq.top();       pq.pop();       long long node = f[0];       ans += f[1] - total[node];       if (node) {         total[par[node]] += f[2] + 1;         --out[par[node]];         if (!out[par[node]]) {           pq.push({par[node], f[1] - 1, total[par[node]]});         }       }     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 77, L = 17;   int n, q, tim = 1, root = 1;   int b[N], d[N], Par[N][L], St[N], En[N];   long long S[N << 2], lz[N << 2];   inline void Shift(int l, int r, int id) {     long long x = lz[id];     lz[id] = 0;     S[id] += (r - l) * x;     if (r - l > 1) lz[id << 1] += x, lz[id << 1 ^ 1] += x;   }   void Add(int ql, int qr, int x, int l = 1, int r = n + 1, int id = 1) {     Shift(l, r, id);     if (qr <= l || r <= ql) return;     if (ql <= l && r <= qr) {       lz[id] += x;       Shift(l, r, id);       return;     }     int mid = ((l + r) >> 1);     Add(ql, qr, x, l, mid, id << 1);     Add(ql, qr, x, mid, r, id << 1 ^ 1);     S[id] = S[id << 1] + S[id << 1 ^ 1];   }   long long Get(int ql, int qr, int l = 1, int r = n + 1, int id = 1) {     Shift(l, r, id);     if (qr <= l || r <= ql) return 0;     if (ql <= l && r <= qr) return S[id];     int mid = ((l + r) >> 1);     return Get(ql, qr, l, mid, id << 1) + Get(ql, qr, mid, r, id << 1 ^ 1);   }   vector<int> a[N];   void dfs(int v = 1) {     St[v] = tim++;     for (int i = 1; i < L; ++i) Par[v][i] = Par[Par[v][i - 1]][i - 1];     for (int u : a[v]) {       if (u == Par[v][0]) continue;       Par[u][0] = v;       d[u] = d[v] + 1;       dfs(u);     }     En[v] = tim;   }   inline bool isPar(int v, int u) { return St[v] <= St[u] && En[u] <= En[v]; }   inline int GetPar(int v, int k) {     for (int i = 0; i < L; ++i)       if (k & (1 << i)) v = Par[v][i];     return v;   }   inline int GetLca(int v, int u) {     if (d[v] < d[u]) swap(v, u);     v = GetPar(v, d[v] - d[u]);     if (v == u) return v;     for (int i = L - 1; i >= 0; --i)       if (Par[v][i] != Par[u][i]) v = Par[v][i], u = Par[u][i];     return Par[v][0];   }   inline int GetLca(int r, int v, int u) {     int t = GetLca(v, u);     if (isPar(r, t)) return t;     if (isPar(r, u) || isPar(r, v)) return r;     if (!isPar(t, r)) return t;     int x = GetLca(r, v);     int y = GetLca(r, u);     return (d[x] > d[y] ? x : y);   }   inline void Update(int r, int v, int u, int x) {     int t = GetLca(r, v, u);     if ((!isPar(t, r))) {       Add(St[t], En[t], x);       return;     }     Add(1, n + 1, x);     if (r == t) return;     int p = GetPar(r, d[r] - d[t] - 1);     Add(St[p], En[p], -x);   }   inline long long GetSum(int r, int v) {     if (!isPar(v, r)) return Get(St[v], En[v]);     long long res = Get(1, n + 1);     if (r == v) return res;     int p = GetPar(r, d[r] - d[v] - 1);     res -= Get(St[p], En[p]);     return res;   }   int main() {     scanf( %d %d , &n, &q);     for (int i = 1; i <= n; ++i) scanf( %d , b + i);     for (int v, u, i = 1; i < n; ++i)       scanf( %d %d , &v, &u), a[v].push_back(u), a[u].push_back(v);     d[1] = 1;     dfs();     for (int i = 1; i <= n; ++i) Add(St[i], St[i] + 1, b[i]);     while (q--) {       int tp, v, u, x;       scanf( %d %d , &tp, &v);       if (tp == 1) {         root = v;       } else if (tp == 2) {         scanf( %d %d , &u, &x);         Update(root, v, u, x);       } else {         printf( %lld n , GetSum(root, v));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int Pow(long long int a, long long int b, long long int md,                     long long int ans = 1) {     for (; b; b >>= 1, a = a * a % md)       if (b & 1) ans = ans * a % md;     return ans % md;   }   const long long int MAXK = 1e6 + 10;   const long long int MAXN = 2e3 + 10;   const long long int INF = 8e18;   const long long int MOD = 1e9 + 7;   long long int dp[MAXN][MAXN], fact[MAXK], inv[MAXK], ans = 0, n, m, k;   long long int add(long long int x, long long int y) { return (x + y) % MOD; }   long long int mul(long long int x, long long int y) { return x * y % MOD; }   long long int C(long long int x, long long int y) {     if (y > x) return 0;     return fact[x] * inv[y] % MOD * inv[x - y] % MOD;   }   int main() {     scanf( %lld%lld%lld , &n, &m, &k);     if (m == 1) return !printf( %lld n , Pow(k, n, MOD));     fact[0] = inv[0] = 1;     for (long long int i = 1; i < MAXK; i++) {       fact[i] = fact[i - 1] * i % MOD;       inv[i] = Pow(fact[i], MOD - 2, MOD);     }     dp[0][0] = 1;     for (long long int i = 1; i <= n; i++) {       for (long long int j = 1; j <= i; j++) {         dp[i][j] = j * (dp[i - 1][j] + dp[i - 1][j - 1]) % MOD;       }     }     for (long long int i = 1; i <= n; i++) {       for (long long int j = 0; j <= i; j++) {         ans = add(ans, mul(Pow(j, n * (m - 2) % MOD, MOD),                            mul(dp[n][i] * dp[n][i] % MOD,                                mul(C(k - i, i - j), mul(C(k, i), C(i, j))))));       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   #define pb push_back   #define speed ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)   using namespace std;   typedef long long ll;   typedef long double ld;   typedef vector <ll> vll;   typedef pair<ll,ll> pll;   typedef vector <pair<ll,ll>> vpll;   typedef vector <vll> vvll;      const ll N=1e5+1;   ll t,n,k;      int main()   {       speed;       cin>>t;       while(t--)       {           cin>>n>>k;           vll ans;           cout<<n-(k+1)/2<<  n ;           for(int i=(k+1)/2;i<=n;i++)               if(i!=k)                   cout<<i<<   ;           cout<<  n ;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[200010];   long long vis[200100];   long long x, n, k, sum, y;   string s;   long long dfs(long long x, long long k, long long y) {     if (x == y) return k;     return dfs(a[x], k + 1, y);   }   long long poww(long long ba) {     if (ba == 0) return 1;     if (ba == 1) return 3;     if (ba % 2 == 0) return poww(ba / 2) * poww(ba / 2);     return poww(ba / 2) * poww(ba / 2) * 3;   }   int main() {     long long q;     cin >> q;     while (q--) {       cin >> n;       for (int i = 1; i <= n; i++) {         cin >> a[i];       }       for (int i = 1; i <= n; i++) {         cout << dfs(a[i], 0, i) + 1 <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1010;   string s[maxn];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> s[i];     int ans = 6, cnt;     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         cnt = 0;         for (int k = 0; k < 6; k++)           if (s[i][k] != s[j][k]) cnt++;         ans = min(ans, (cnt + 1) / 2 - 1);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int t;     long long s, a, b, c;     scanf( %d , &t);     while (t--) {       scanf( %I64d %I64d %I64d %I64d , &s, &a, &b, &c);       printf( %I64d n , s / c + s / c / a * b);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int i, j;     cin >> s;     for (i = 0; i < s.size(); i++)       if (s[i] ==  . ) break;     if (s[i - 1] ==  9 ) {       cout <<  GOTO Vasilisa. ;       return 0;     }     if (s[i + 1] >=  5 ) s[i - 1]++;     for (j = 0; j < i; j++) cout << s[j];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, k, n2;     long long dip, cert, losers;     cin >> n >> k;     dip = n / (2 * (k + 1));     cert = k * dip;     losers = n - dip - cert;     cout << dip <<     << cert <<     << losers;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int a[25], b[25];   int dp[1 << 24];   int main() {     int n, k;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     scanf( %d , &k);     for (int i = 1; i <= k; i++) scanf( %d , &b[i]);     dp[0] = 1;     for (int i = 1; i < (1 << n); i++) {       int sum = 0, ans = 0;       for (int j = 0; j < n; j++) {         if ((i >> j) & 1) {           sum += a[j];           ans = (ans + dp[i ^ (1 << j)]) % mod;           if (sum > 1e9) sum = 1e9 + 1;         }       }       bool ok = 1;       for (int j = 1; j <= k; j++) {         if (sum == b[j]) ok = 0;       }       if (!ok) continue;       dp[i] = (dp[i] + ans) % mod;     }     printf( %d n , dp[(1 << n) - 1]);   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long x, long long y) {     if (x == 0) return y;     return gcd(y % x, x);   }   int main() {     int t;     long long r, b, k;     scanf( %d , &t);     while (t--) {       scanf( %I64d%I64d%I64d , &r, &b, &k);       long long Gcd = gcd(r, b);       r /= Gcd;       b /= Gcd;       if (r <= (k - 1) * b + 1 && b <= (k - 1) * r + 1)         printf( OBEY n );       else         printf( REBEL n );     }   }


#include <bits/stdc++.h>   using namespace std;   long long a[1000000], prime[1000000];   vector<long long> v[3000000];   int main() {     ios::sync_with_stdio(false);     cin.tie(), cout.tie();     long long e;     for (long long i = 3; i * i <= 1000000; i += 2)       if (a[i] == 0)         for (long long j = i * i; j <= 1000000; j = j + (i * 2)) a[j] = 1;     prime[0] = 2;     for (long long i = 3, j = 1; i <= 1000000; i += 2)       if (a[i] == 0) {         prime[j++] = i;         e = j;       }     long long n;     cin >> n;     long long b, c = 0, d = 1, f = 0, g = 0, h;     for (long long i = 0; i < n; i++) {       cin >> b;       for (long long j = 0;; j++) {         c = 0;         if (prime[j] > sqrt(b)) {           break;         }         if (b % prime[j] == 0) {           while (b % prime[j] == 0) {             c++;             b /= prime[j];           }         }         v[prime[j]].push_back(c);         g = max(g, prime[j]);       }       if (b > 1) {         g = max(g, b);         v[b].push_back(1);       }     }     for (long long i = 0; i < 210000; i++) {       long long y = prime[i];       if (v[y].size() == n - 1) {         sort(v[y].begin(), v[y].end());         long long x = v[y][0];         d = d * (pow(y, x));       }       if (v[y].size() == n) {         sort(v[y].begin(), v[y].end());         long long x = v[y][1];         d = d * (pow(y, x));       }     }     cout << d << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       long long n, k, s;       cin >> n >> k >> s;       if (s >= k && s <= k * (n - 1)) {         long long step = s / k;         long long x = s - k * step;         long long last = 1, fact = 1;         cout <<  YES  << endl;         for (int i = 0; i < k; i++) {           long long tmp = step;           if (x) {             tmp++;             x--;           }           last += tmp * fact;           cout << last <<    ;           fact *= -1;         }         cout << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5023;   int grundy[N], canCut[N], mex[N];   void init() {     memset(grundy, 0, sizeof(grundy));     memset(canCut, 0, sizeof(canCut));     for (int i = 1; i < N; i++) {       for (int j = 0; j < i; j++) {         mex[grundy[max(0, j - 1)] ^ grundy[max(0, i - j - 2)]] = i;       }       for (int j = 0;; j++) {         if (mex[j] != i) {           grundy[i] = j;           break;         }       }     }   }   bool firstWin(int x, int n) {     int sg = 0, len = 0;     for (int i = 0; i < n; i++) {       if (canCut[i] && abs(x - i) > 1) {         len++;       } else {         sg ^= grundy[len];         len = 0;       }     }     return sg == 0;   }   int main() {     string s;     while (cin >> s) {       init();       int n = s.size();       for (int i = 1; i + 1 < n; i++) {         if (s[i - 1] == s[i + 1]) canCut[i] = 1;       }       int ans = -1;       for (int i = 0; i < n; i++) {         if (canCut[i] && firstWin(i, n)) {           ans = i + 1;           break;         }       }       if (ans == -1)         printf( Second n );       else         printf( First n%d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     map<int, int> mp;     vector<int> ans;     int a;     for (int i = 0; i < n; i++) {       scanf( %d , &a);       mp[a] = 1;     }     n = m;     for (int i = 1; i <= n; i++) {       if (i > m) break;       if (mp[i] == 0) {         if (i <= m) {           ans.push_back(i);           m -= i;         }       }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int n, cnt, T;   vector<int> g[128];   void input(int x) {     if (g[x].size()) return;     if (cnt == 16) {       g[x].push_back(1), g[x].push_back(1);       return;     }     cnt++;     printf( ? %d n , x);     fflush(stdout);     int nw, y;     scanf( %d , &nw);     while (nw--) {       scanf( %d , &y);       g[x].push_back(y);     }     return;   }   void solve() {     cnt = 0;     for (int i = 0; i < 128; i++) g[i].clear();     cin >> n;     input(1);     if (g[1].size() == 2) {       printf( ! 1 n );       fflush(stdout);       return;     }     deque<int> q;     q.push_back(1);     int nw = 1;     while (g[nw].size() != 1) {       for (int i = 0; i < g[nw].size(); i++)         if (g[g[nw][i]].size() == 0) {           nw = g[nw][i];           break;         }       q.push_front(nw);       input(nw);       if (g[nw].size() == 2) {         cout <<  !   << nw << endl;         fflush(stdout);         return;       }     }     nw = 1;     while (g[nw].size() != 1) {       for (int i = 0; i < g[nw].size(); i++)         if (g[g[nw][i]].size() == 0) {           nw = g[nw][i];           break;         }       q.push_back(nw);       input(nw);       if (g[nw].size() == 2) {         cout <<  !   << nw << endl;         fflush(stdout);         return;       }     }     nw = q[q.size() / 2];     int dep = q.size() / 2;     vector<int> pa;     if (q.size() != 1) {       pa.push_back(q[q.size() / 2 - 1]);       pa.push_back(q[q.size() / 2 + 1]);     }     int couter = 0;     while (dep != n - 3 && dep != n - 1) {       vector<int> maybe;       input(nw);       if (g[nw].size() == 2) {         cout <<  !   << nw << endl;         fflush(stdout);         return;       }       for (int i = 0; i < g[nw].size(); i++) {         bool ok = 1;         for (int j = 0; j < pa.size(); j++)           if (pa[j] == g[nw][i]) ok = 0;         if (ok) maybe.push_back(g[nw][i]);       }       dep++;       pa.clear();       couter = couter * 10 + maybe.size();       if (maybe.size() == 1) {         pa.push_back(nw);         nw = maybe[0];         continue;       }       int nwchk = maybe[0];       for (int i = 0; i < dep - 2; i++) {         input(nwchk);         if (g[nwchk].size() == 2) {           cout <<  !   << nwchk << endl;           fflush(stdout);           return;         }         for (int j = 0; j < g[nwchk].size(); j++)           if (g[g[nwchk][j]].size() == 0) nwchk = g[nwchk][j];       }       input(nwchk);       if (g[nwchk].size() == 2) {         cout <<  !   << nwchk << endl;         fflush(stdout);         return;       }       pa.push_back(nw);       if (g[nwchk].size() == 1)         nw = maybe[1];       else         nw = maybe[0];     }     if (dep == n - 1) {       cout <<  !   << nw << endl;       fflush(stdout);       return;     }     input(nw);     vector<int> maybe;     for (int i = 0; i < g[nw].size(); i++) {       maybe.push_back(g[nw][i]);       input(g[nw][i]);       if (g[g[nw][i]].size() == 2) {         cout <<  !   << g[nw][i] << endl;         fflush(stdout);         return;       }     }     for (int i = 0; i < maybe.size(); i++)       for (int j = 0; j < g[maybe[i]].size(); j++) {         input(g[maybe[i]][j]);         if (g[g[maybe[i]][j]].size() == 2) {           cout <<  !   << g[maybe[i]][j] << endl;           fflush(stdout);           return;         }       }     if (T == 7) {       cout <<  !   << couter;       fflush(stdout);       exit(0);     }     cout <<  ! -1 n ;     fflush(stdout);     return;   }   int main() {     cin >> T;     while (T--) solve();   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int INF = 1000000000;   const ll LINF = 1001002003004005006ll;   int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};   template <class T>   bool chmax(T &a, const T &b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <class T>   bool chmin(T &a, const T &b) {     if (b < a) {       a = b;       return true;     }     return false;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (int i = 0; i < (int)v.size(); i++)       os << v[i] << (i + 1 == (int)v.size() ?    :    );     return os;   }   template <typename T>   istream &operator>>(istream &is, vector<T> &v) {     for (T &x : v) is >> x;     return is;   }   signed main() {     int n;     cin >> n;     vector<int> bx;     for (int i = 0; i < (n); i++) {       cout <<  ?   << 0 <<     << i << endl;       int x;       cin >> x;       bx.push_back(x);     }     vector<int> px;     for (int i = 0; i < (n); i++) {       cout <<  ?   << i <<     << 0 << endl;       int x;       cin >> x;       px.push_back(x);     }     int cnt = 0;     vector<int> print_res;     for (int i = 0; i < (n); i++) {       bool f = true;       vector<int> b;       for (auto x : bx) b.push_back(x ^ i);       auto v = b;       sort(begin(v), end(v));       for (int j = 0; j < (n); j++)         if (v[j] != j) f = false;       if (!f) continue;       vector<int> p;       for (auto x : px) p.push_back(x ^ b[0]);       for (int j = 0; j < (n); j++)         if (p[b[j]] != j) f = false;       if (!f) continue;       cnt++;       print_res = p;     }     cout <<  !  << endl;     cout << cnt << endl;     cout << print_res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > h;   vector<vector<long long> > g;   long long p[500001][21];   long long volume[500001];   long long n, dt, ans, s, f;   void dfs(long long v, long long m) {     p[v][0] = m;     for (long long i = 0; i < g[v].size(); i++) {       long long k = g[v][i];       if (k != m) {         volume[k] = volume[v] + 1;         dfs(k, v);       }     }   }   void prepare() {     for (long long i = 0; i <= 500000; i++)       for (long long k = 1; k <= 20; k++) p[i][k] = -1;     dfs(1, -1);     for (long long k = 1; k <= 20; k++)       for (long long i = 1; i <= 500000; i++)         if (p[i][k - 1] != -1) p[i][k] = p[p[i][k - 1]][k - 1];     ans = 1;     cout << ans <<    ;     s = 1;     f = 2;   }   long long kanst(long long v, long long k) {     while (k > 0) {       long long k0 = log2(k);       v = p[v][k0];       k -= 1 << k0;     }     return v;   }   long long lca(long long a, long long b) {     if (a == b) return a;     if (volume[b] > volume[a]) swap(a, b);     a = kanst(a, volume[a] - volume[b]);     if (a == b) return a;     for (long long j = 20; j >= 0; j--) {       if (p[a][j] != p[b][j]) {         a = p[a][j];         b = p[b][j];       }     }     return p[a][0];   }   int main() {     cin >> n;     g.resize(200001);     vector<long long> d;     d.resize(n + 1);     for (long long i = 2; i <= n; i++) {       long long a;       cin >> a;       d[i] = i;       g[i].push_back(a);       g[a].push_back(i);     }     prepare();     for (long long k = 3; k <= n; k++) {       if (volume[s] + volume[k] - 2 * volume[lca(s, k)] > ans) {         ans = volume[s] + volume[k] - 2 * volume[lca(s, k)];         f = k;       }       if (volume[f] + volume[k] - 2 * volume[lca(f, k)] > ans) {         ans = volume[f] + volume[k] - 2 * volume[lca(f, k)];         s = k;       }       cout << ans <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   char s[5005], t[5005];   long long DP[5005][5005];   int main(int argc, char** argv) {     scanf( %s%s , s, t);     int lens = strlen(s);     int lent = strlen(t);     long long ans = 0;     for (int i = 1; i <= lens; i++) {       for (int j = 1; j <= lent; j++) {         DP[i][j] = DP[i][j - 1];         if (s[i - 1] == t[j - 1])           DP[i][j] = (DP[i][j] + DP[i - 1][j - 1] + 1) % mod;       }       ans = (ans + DP[i][lent]) % mod;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using ::std::cin;   using ::std::cout;   using ::std::endl;   using ::std::multiset;   using ::std::pair;   using ::std::vector;   int main() {     ::std::ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     vector<pair<int, int>> tr;     for (int i = 0; i < m; ++i) {       int t, r;       cin >> t >> r;       while (!tr.empty() && tr.back().second <= r) tr.pop_back();       tr.push_back({t, r});     }     tr.push_back({-1, 0});     multiset<int> s;     for (int i = 0; i < tr[0].second; ++i) s.insert(a[i]);     for (int i = 0; i < static_cast<int>(tr.size()); ++i) {       for (int j = tr[i].second - 1; j >= tr[i + 1].second; --j) {         if (tr[i].first == 2) {           a[j] = *s.begin();           s.erase(s.begin());         } else {           a[j] = *--s.end();           s.erase(--s.end());         }       }     }     for (int x : a) cout << x <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 500010;   int ans[N];   void solve() {     int n;     cin >> n;     int d = 0;     for (int i = 0; i <= 30; i++) {       ans[i] = (1 << i);     }     int sum = 0;     for (int i = 0; i <= 30; i++) {       sum += ans[i];       if (sum >= n) {         d = i;         break;       }     }     int extra = sum - n;     for (int i = d; i >= 1; i--) {       long long need = (ans[i] - ans[i - 1] + 0ll) * (d - i + 1ll);       if (extra > need) {         extra -= need;         for (int j = d; j >= i; j--) ans[j] = ans[i - 1];       } else {         int dv = (extra / (d - i + 1));         int c = (extra % (d - i + 1));         for (int j = d; j >= i; j--) ans[j] -= dv;         for (int j = i; j < i + c; j++) ans[j]--;         break;       }     }     cout << d <<   n ;     for (int i = 1; i <= d; i++) cout << ans[i] - ans[i - 1] <<    ;     cout <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tt;     cin >> tt;     while (tt--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   const double PI = 3.1415926535897932384626;   const int KL = 1e6;   const long long MOD = 1e9 + 7;   using namespace std;   void show(complex<double> a) {     cout << fixed << setprecision(10) << a.real() <<   +   << a.imag() <<  i           << endl;   }   complex<double> rot(complex<double> a, complex<double> o, double alpha) {     return (a - o) * polar(1.0, alpha * PI / 180.0) + o;   }   complex<double> intersection(complex<double> a, complex<double> b, double h) {     double m = (a.imag() - b.imag()) / (a.real() - b.real());     double p = a.imag() - m * a.real();     complex<double> ret((h - p) / m, h);     return ret;   }   double h, w;   double alpha;   int main() {     cin >> w >> h >> alpha;     if (w < h) swap(h, w);     if (alpha >= 90) alpha = 180 - alpha;     double wt = sqrt(w * w + h * h);     if (alpha == 0) {       cout << fixed << setprecision(10) << w * h << endl;       return 0;     }     complex<double> a(-w / 2.0, h / 2.0);     complex<double> b(w / 2.0, h / 2.0);     complex<double> d(w / 2.0, -h / 2.0);     complex<double> o(0, 0);     double mx_angle = 2 * abs(arg(b)) * 180.0 / PI;     if (alpha >= mx_angle) {       cout << fixed << setprecision(10) << h * h / sin(alpha * PI / 180.0)            << endl;       return 0;     }     complex<double> a1 = rot(a, o, alpha);     complex<double> b1 = rot(b, o, alpha);     complex<double> c1 = rot(d, o, alpha);     complex<double> A = intersection(a1, b1, h / 2);     complex<double> B = intersection(b1, c1, h / 2);     double d1 = A.real() - a.real();     double d2 = b.real() - B.real();     double wt1 = d1 / cos(alpha * PI / 180.0);     double wt2 = d2 / sin(alpha * PI / 180.0);     double area =         d1 * wt1 * sin(alpha * PI / 180.0) + d2 * wt2 * cos(alpha * PI / 180.0);     double ans = w * h - area;     cout << fixed << setprecision(10) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   struct SFountain {     size_t beauty;     size_t price;     SFountain() = default;     SFountain(size_t b, size_t p) : beauty(b), price(p) {}     static bool less_price(const SFountain &lhs, const SFountain &rhs) {       return lhs.price < rhs.price;     }     static bool less_beauty(const SFountain &lhs, const SFountain &rhs) {       return lhs.beauty < rhs.beauty;     }   };   size_t maxSum(const std::vector<SFountain> &fountains, size_t max_price) {     if (fountains.size() < 2) return 0;     size_t max_beauty_total = 0;     size_t max_beauty = 0;     std::vector<SFountain> x;     for (const SFountain &fountain : fountains) {       auto upper = std::upper_bound(x.begin(), x.end(),                                     SFountain(0, max_price - fountain.price),                                     SFountain::less_price);       if (upper != x.begin()) {         --upper;         max_beauty_total =             std::max(max_beauty_total, fountain.beauty + upper->beauty);       }       if (max_beauty < fountain.beauty) {         max_beauty = fountain.beauty;         x.push_back(fountain);       }     }     return max_beauty_total;   }   int main() {     size_t n, c, d, maxC = 0, maxD = 0;     std::cin >> n >> c >> d;     std::vector<SFountain> coins;     std::vector<SFountain> diamonds;     coins.reserve(n);     diamonds.reserve(n);     for (size_t i = 0; i < n; ++i) {       SFountain fountain;       char price_type;       std::cin >> fountain.beauty >> fountain.price >> price_type;       if (price_type ==  C  && fountain.price <= c) {         coins.push_back(fountain);         maxC = std::max(maxC, fountain.beauty);       } else if (price_type ==  D  && fountain.price <= d) {         diamonds.push_back(fountain);         maxD = std::max(maxD, fountain.beauty);       }     }     std::sort(coins.begin(), coins.end(), SFountain::less_price);     std::sort(diamonds.begin(), diamonds.end(), SFountain::less_price);     size_t maxMixed = !coins.empty() && !diamonds.empty() ? maxC + maxD : 0;     std::cout << std::max(std::max(maxSum(coins, c), maxSum(diamonds, d)),                           maxMixed)               << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 0, -1, 1, -1, -1, 1, 1};   int dy[] = {-1, 1, 0, 0, -1, 1, -1, 1};   bool mark[100007];   long long int n, in = -1, prime[100007];   void seive() {     prime[++in] = 2;     for (long long int i = 3; i * i < 100007; i += 2) {       if (mark[i] == 0)         for (long long int j = i * i; j < 100007; j += 2 * i) mark[j] = 1;     }     for (long long int i = 3; i < 100007; i += 2) {       if (mark[i] == 0) prime[++in] = i;     }   }   int main() {     seive();     cin >> n;     long long int c, div = 1;     for (long long int i = 0; i <= in; i++) {       if (n % prime[i] == 0) {         c = 1;         while (n % prime[i] == 0) {           n /= prime[i];           c++;         }         div *= c;       }     }     if (n > 2) div *= 2;     cout << div << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[200001];   vector<int> G[200001];   int res[200001];   vector<int> divisor;   vector<int> now;   int gcd(int x, int y) {     if (y == 0) return x;     return gcd(y, x % y);   }   void dfs(int v, int p) {     for (int i = 0; i < G[v].size(); i++) {       if (p != G[v][i]) {         res[G[v][i]] = gcd(res[v], a[G[v][i]]);         dfs(G[v][i], v);       }     }   }   void dfs2(int v, int p, int dist) {     for (int i = 0; i < divisor.size(); i++) {       now[i] += (a[v] % divisor[i] == 0);       if (now[i] >= dist) {         res[v] = max(res[v], divisor[i]);       }     }     for (int i = 0; i < G[v].size(); i++) {       if (p != G[v][i]) {         dfs2(G[v][i], v, dist + 1);       }     }     for (int i = 0; i < divisor.size(); i++) {       now[i] -= (a[v] % divisor[i] == 0);     }   }   int main(void) {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     for (int i = 0; i < n - 1; i++) {       int f, t;       scanf( %d%d , &f, &t);       f--;       t--;       G[f].push_back(t);       G[t].push_back(f);     }     int tmp = a[0];     a[0] = 0;     dfs(0, -1);     a[0] = tmp;     for (int i = 1; i * i <= a[0]; i++) {       if (a[0] % i == 0) {         divisor.push_back(i);         divisor.push_back(a[0] / i);         if (i * i == a[0]) {           divisor.pop_back();         }       }     }     sort(divisor.begin(), divisor.end());     now.resize(divisor.size());     dfs2(0, -1, 0);     for (int i = 0; i < n; i++) {       printf( %d%c , res[i], i + 1 == n ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;      #define int long long      void solve()   {       int n, m, k;       cin >> n >> m >> k;       vector<tuple<int, int, int>> edges(m + 2), edges_large, edges_small;       vector<int> values;       for (int i = 1; i <= m; i++)       {           int a, b, c;           cin >> a >> b >> c;           edges[i] = {a, b, c};           if (c > k)               edges_large.push_back(edges[i]);           else               edges_small.push_back(edges[i]);           values.push_back(c);       }       sort(values.begin(), values.end());       vector<int> fa(n + 2);       for (int i = 1; i <= n; i++)           fa[i] = i;       function<int(int)> find = [&](int x) -> int {           return x == fa[x] ? x : fa[x] = find(fa[x]);       };       int tot = 1;       function<void(int, int)> merge = [&](int x, int y) -> void {           x = find(x);           y = find(y);           if (x != y)               fa[x] = y, tot++;       };       for (auto [u, v, w] : edges_small)           merge(u, v);       int flag = tot == n;       if (flag)       {           int i = lower_bound(values.begin(), values.end(), k) - values.begin();           int j = i - 1;           int ans = 1e18;           if (i >= 0 && i < m)               ans = min(ans, abs(k - values[i]));           if (j >= 0 && j < m)               ans = min(ans, abs(k - values[j]));           cout << ans << endl;       }       else       {           int ans = 0;           vector<pair<int, pair<int, int>>> ve;           for (auto [x, y, z] : edges_large)               ve.push_back({z, {x, y}});           sort(ve.begin(), ve.end());           for (int i = 0; i < ve.size(); i++)           {               auto [w, pr] = ve[i];               auto [u, v] = pr;               if (find(u) != find(v))                   merge(u, v), ans += w - k;               if (tot == n)                   break;           }           cout << ans << endl;       }   }      signed main()   {       ios::sync_with_stdio(false);          int t;       cin >> t;       while (t--)       {           solve();       }   }


#include <bits/stdc++.h>   using namespace std;   long long int visited[100001];   vector<long long int> adj[100001];   long long int sum = 0;   void dfs(long long int s) {     if (visited[s] == 1) {       return;     }     sum++;     visited[s] = 1;     for (auto u : adj[s]) {       dfs(u);     }   }   long long int binpow(long long int x, long long int n) {     if (n == 0) return 1;     long long u = binpow(x, n / 2);     u = (u * u);     if (n % 2 == 1) u = (u * x);     return u;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, m;     cin >> n >> m;     while (m--) {       long long int x, y;       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     memset(visited, 0, sizeof(visited));     ;     long long int ans = 1;     for (long long int i = 1; i <= n; i++) {       if (visited[i] == 0) {         sum = 0;         dfs(i);         long long int y = sum - 1;         long long int r = binpow(2, y);         ans = ans * r;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dp[10010], leftx[10010], rightx[10010], l[5010], r[5010];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n, x;     cin >> n >> x;     vector<int> ry;     for (int i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       l[i] = a;       r[i] = b;       ry.push_back(a);       ry.push_back(b);     }     ry.push_back(x);     sort(ry.begin(), ry.end());     set<int> rt;     for (auto val : ry) {       rt.insert(val);     }     ry.clear();     for (auto val : rt) {       ry.push_back(val);     }     int ind = -1;     for (int i = 0; i < ry.size(); i++) {       if (ry[i] == x) ind = i;     }     for (int i = 0; i < ry.size(); i++) dp[i] = 1e18;     for (int i = 0; i < ry.size(); i++) {       if (ry[i] == x) dp[i] = 0;     }     for (int i = 0; i <= n; i++) {       if (i) {         for (int j = 0; j < ry.size(); j++) {           long long val = 0;           if (ry[j] < l[i - 1] || ry[j] > r[i - 1])             val = min(abs(l[i - 1] - ry[j]), abs(r[i - 1] - ry[j]));           dp[j] = min(leftx[j] + ry[j] + val, rightx[j] - ry[j] + val);         }       }       leftx[0] = dp[0] - ry[0];       for (int j = 1; j < ry.size(); j++)         leftx[j] = min(leftx[j - 1], dp[j] - ry[j]);       rightx[ry.size() - 1] = dp[ry.size() - 1] + ry[ry.size() - 1];       for (int j = (int)ry.size() - 2; j >= 0; j--)         rightx[j] = min(rightx[j + 1], dp[j] + ry[j]);     }     long long mini = 1e18;     for (int j = 0; j < ry.size(); j++) mini = min(mini, dp[j]);     cout << mini <<   n ;   }


#include <bits/stdc++.h>   bool chCount[26];   int main() {     int n, m;     std::cin >> n >> m;     int max = -1;     for (; n >= 1; --n) {       int min = 1000000000 + 10;       for (int i = 0; i < m; ++i) {         int x;         std::cin >> x;         min = std::min(x, min);       }       max = std::max(min, max);     }     std::cout << max;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int a, m;     cin >> a >> m;     a %= m;     map<int, bool> vis;     while (!vis[a]) {       vis[a] = true;       if (!a) {         cout <<  Yes n ;         return 0;       }       a *= 2;       a %= m;     }     cout <<  No n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nMax = 100007;   int parent[nMax];   vector<int> g[nMax];   bool used[nMax];   void dfs(int root, int parent, int& cnt, int b, bool& bad) {     if (root == b) {       bad = true;     }     used[root] = true;     ++cnt;     for (int i = 0; i < g[root].size(); ++i) {       int to = g[root][i];       if (used[to] == false && to != parent) dfs(to, root, cnt, b, bad);     }   }   int main() {     int n, pos;     scanf( %d%d , &n, &pos);     for (int i = 0; i < n; ++i) {       int a;       scanf( %d , &a);       parent[i] = a - 1;       if (a != 0) {         g[i].push_back(a - 1);         g[a - 1].push_back(i);       }     }     --pos;     int h = 1;     int t = pos;     while (parent[t] != -1) {       ++h;       t = parent[t];     }     vector<int> c;     for (int i = 0; i < n; ++i) {       int cnt = 0;       bool bad = false;       if (used[i] == false) {         dfs(i, -1, cnt, pos, bad);         if (!bad) c.push_back(cnt);       }     }     int to = (int)pow(2.0, (int)c.size());     set<int> s;     set<int>::iterator it;     for (int i = 1; i < to + 1; ++i) {       int t = i, sum = 0;       for (int j = 0; j < c.size(); ++j) {         if (t & 1) sum += c[j];         t >>= 1;       }       s.insert(sum);     }     set<int> ans;     ans.insert(h);     for (it = s.begin(); it != s.end(); ++it) ans.insert(*it + h);     for (it = ans.begin(); it != ans.end(); ++it) cout << *it << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 1;   const int size = 1 << 8, M = 1e6 + 10;   int n, q, w[N], head[N], ne[N], cnt;   void add(int f, int t) {     w[++cnt] = t;     ne[cnt] = head[f];     head[f] = cnt;   }   int fa[N], a[N], h[N];   void dfs(int x) {     for (int i = head[x]; i; i = ne[i]) {       int v = w[i];       if (fa[v]) continue;       fa[v] = x;       h[v] = h[x] + 1;       dfs(v);     }   }   int ance[N], go[M][2], id, dp[N][size];   void trie(int x) {     for (int i = 15, p = 1; i >= 0; i--) {       int w = x >> i & 1;       if (!go[p][w]) go[p][w] = ++id;       p = go[p][w];     }   }   int query(int x) {     int ans = 0;     for (int i = 15, p = 1; i >= 0; i--) {       int w = x >> i & 1;       if (go[p][w ^ 1])         ans |= (1 << i), p = go[p][w ^ 1];       else         p = go[p][w];     }     return ans;   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i < n; ++i) {       int u, v;       scanf( %d%d , &u, &v);       add(u, v);       add(v, u);     }     fa[1] = h[1] = 1;     dfs(1);     fa[1] = 0;     for (int i = 1; i <= n; ++i) {       for (; id; id--) go[id][0] = go[id][1] = 0;       id = 1;       int p = i;       for (int j = 0; p && j < size; j++, p = fa[p]) trie(a[p] ^ (h[i] - h[p]));       ance[i] = p;       for (int j = 0; j < size; j++) dp[i][j] = query(j << 8);     }     for (int i = 1; i <= q; ++i) {       int u, v;       scanf( %d%d , &u, &v);       int p = v, dep = 0, ans = 0;       for (; h[p] - size >= h[u]; p = ance[p], dep++) ans = max(ans, dp[p][dep]);       for (; h[p] >= h[u]; p = fa[p]) ans = max(ans, a[p] ^ (h[v] - h[p]));       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int n = 10000;   long long qm[6][n + 2];   void ask(int i, long long b) {     int j = min(b, (long long)n);     vector<long long> v;     long long r = qm[i - 1][j];     for (int s = 1; s <= j; ++s) {       v.push_back(r + b);       ++r;       r += qm[i - 1][min(r + j, (long long)n)];       if (r > (long long)2e18) break;     }     printf( %d n , int(v.size()));     for (auto t : v) printf( %lld  , t);     cout << endl;     int t;     cin >> t;     if (t == -1) exit(0);     if (t == 0) ask(i - 1, b);     r = qm[i - 1][j];     for (int s = 1; s <= j; ++s) {       ++r;       --t;       if (!t) ask(i - 1, r + b);       r += qm[i - 1][min(r + j, (long long)n)];     }   }   int main() {     for (int i = 1; i <= 4; ++i) {       for (int j = 1; j <= n; ++j) {         long long r = qm[i - 1][j];         for (int s = 1; s <= j; ++s) {           ++r, r += qm[i - 1][min(r + j, (long long)n)];           if (r > (long long)2e18) break;         }         qm[i][j] = r;       }     }     ask(5, 1);   }


#include <bits/stdc++.h>   using namespace std;   void swap(int &a, int &b) {     int temp;     temp = a;     a = b;     b = temp;   }   void printarr(int a[], int n) {     for (int i = 0; i < 2 * n; i++) cout << a[i] <<    ;     cout << endl;   }   int main() {     long long int n, k, v;     cin >> n;     int a[2 * n], i, j, count = 0;     for (i = 0; i < 2 * n; i++) cin >> a[i];     for (i = 0; i < 2 * n; i += 2) {       if (a[i] != a[i + 1]) {         j = a[i];         for (k = i + 1; k < 2 * n; k++) {           if (j == a[k]) {             v = k;             while (v > i + 1) {               count++;               swap(a[v], a[v - 1]);               v--;             }           }         }       }     }     cout << count;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int add(int a, int b) { return a + b - (a + b >= MOD) * MOD; }   int mult(int a, int b) { return ((long long)a * b) % MOD; }   int n, h, w;   char s[500013];   int dX[200], dY[200];   int diffx, diffy;   int maxx, minx;   int maxy, miny;   int hasx_[1000013], hasy_[1000013];   int& hasx(int i) { return hasx_[i + 500000]; }   int& hasy(int i) { return hasy_[i + 500000]; }   void calc() {     int x = 0, y = 0;     for (int i = 0; i < n; i++) {       x += dX[s[i]];       y += dY[s[i]];       maxx = max(maxx, x);       minx = min(minx, x);       maxy = max(maxy, y);       miny = min(miny, y);       if (!hasx(x)) hasx(x) = i + 1;       if (!hasy(y)) hasy(y) = i + 1;     }     diffx = x;     diffy = y;   }   int main() {     dX[ U ] = -1;     dX[ D ] = 1;     dY[ L ] = -1;     dY[ R ] = 1;     scanf( %d%d%d %s , &n, &h, &w, &s);     calc();     if (maxx - minx + 1 <= h && maxy - miny + 1 <= w && diffx == 0 && diffy == 0)       return printf( -1 n ), 0;     int bot = -1, top = h;     int lef = -1, rig = w;     int x = 0, y = 0;     int step = 0;     int ans = 0;     while (top > bot + 1 && rig > lef + 1) {       int tryt = 1e9;       if (x + top - 1 + maxx >= h) tryt = hasx(h - (top + x - 1));       int tryb = 1e9;       if (x + bot + 1 + minx <= -1) tryb = hasx(-1 - (bot + x + 1));       int tryr = 1e9;       if (y + rig - 1 + maxy >= w) tryr = hasy(w - (rig + y - 1));       int tryl = 1e9;       if (y + lef + 1 + miny <= -1) tryl = hasy(-1 - (lef + y + 1));       if (min(min(tryt, tryb), min(tryr, tryl)) < 1e7) {         if (tryt < min(tryb, min(tryr, tryl))) {           int cur = mult(rig - lef - 1, mult(step, n) + tryt);           ans = add(ans, cur);           top -= 1;         } else if (tryb < min(tryt, min(tryr, tryl))) {           int cur = mult(rig - lef - 1, mult(step, n) + tryb);           ans = add(ans, cur);           bot += 1;         } else if (tryr < min(tryt, min(tryb, tryl))) {           int cur = mult(top - bot - 1, mult(step, n) + tryr);           ans = add(ans, cur);           rig -= 1;         } else if (tryl < min(tryt, min(tryb, tryr))) {           int cur = mult(top - bot - 1, mult(step, n) + tryl);           ans = add(ans, cur);           lef += 1;         }       } else {         x += diffx;         y += diffy;         step += 1;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   inline void R(int &xx) {     xx = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 )       xx = xx + xx + (xx << 3) + ch - 48, ch = getchar();   }   inline void R(long long &xx) {     xx = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 )       xx = xx + xx + (xx << 3) + ch - 48, ch = getchar();   }   int n, prime[100011], tot;   bool f[100011], u[100011];   vector<pair<int, int> > ans;   vector<int> tmp;   inline void init() {     for (int i = 2; i <= n; i++) {       if (!f[i]) prime[++tot] = i;       for (int j = 1; j <= tot && i * prime[j] < 100011; j++) {         f[i * prime[j]] = 1;         if (!(i % prime[j])) break;       }     }   }   int main() {     R(n);     init();     for (int i = tot; i >= 1; i--) {       int pr = prime[i];       tmp.clear();       for (int j = pr; j <= n; j += pr)         if (!u[j]) tmp.push_back(j);       if (tmp.size() & 1) swap(tmp[1], tmp[tmp.size() - 1]);       for (int t = 0; t < ((int)tmp.size() - 1); t += 2) {         ans.push_back(make_pair(tmp[t], tmp[t + 1]));         u[tmp[t]] = u[tmp[t + 1]] = 1;       }     }     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++)       printf( %d %d n , ans[i].first, ans[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> b, c;   long long s[1000000];   long long d[1000000];   int F(long long x) {     vector<long long> a = b;     a.push_back(x);     sort(a.rbegin(), a.rend());     long long n = a.size();     s[0] = 0;     for (int i = 1; i <= n; ++i) {       s[i] = s[i - 1] + a[i - 1];       d[i] = -1;     }     int y = 1;     int pos = a.size() - 1;     while (pos >= 0 && y <= n) {       if (a[pos] > y && pos + 1 > y) {         d[y] = pos + 1;         ++y;         continue;       }       --pos;     }     for (long long i = 1; i <= n; ++i) {       if (d[i] == -1) {         d[i] = s[n] - s[i];         continue;       }       d[i] = (d[i] - i) * i + s[n] - s[d[i]];     }     if (s[n] > n * (n - 1)) {       return -1;     }     for (long long k = 1; k < n; ++k) {       if (s[k] > k * (k - 1) + d[k]) {         if (a[k - 1] > x) {           return -1;         }         return 1;       }     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     int n;     cin >> n;     int t = 0;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       b.push_back(x);       t += x;       t %= 2;     }     for (int i = 0; i <= n + 2; ++i) {       if (i % 2 == t) {         c.push_back(i);       }     }     int l = -1;     int r = c.size();     int pos = -1;     while (r - l > 1) {       int m = (l + r) / 2;       if (F(c[m]) == 1) {         r = m;         continue;       }       if (F(c[m]) == -1) {         l = m;         continue;       }       pos = m;       break;     }     if (pos == -1) {       cout << -1;       return 0;     }     l = -1;     r = pos + 1;     while (r - l > 1) {       int m = (l + r) / 2;       if (F(c[m]) == 0) {         r = m;       } else {         l = m;       }     }     int pos1 = r;     l = pos - 1;     r = c.size();     while (r - l > 1) {       int m = (l + r) / 2;       if (F(c[m]) == 0) {         l = m;       } else {         r = m;       }     }     for (int i = pos1; i <= l; ++i) {       cout << c[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 10;   const int MN = 1e5 + 10;   int n, a[MN << 1], b[MN << 1];   struct cmp {     bool operator()(const int &x, const int &y) {       if (a[x] + b[x] != a[y] + b[y]) return a[x] + b[x] > a[y] + b[y];       return x > y;     }   };   set<int, cmp> S;   int main() {     ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     long long ans = 0;     for (int i = 0; i < n; ++i) {       cin >> a[2 * i] >> b[2 * i] >> a[2 * i + 1] >> b[2 * i + 1];       int x = a[2 * i] + b[2 * i], y = a[2 * i + 1] + b[2 * i + 1];       if (a[2 * i] > b[2 * i + 1] || b[2 * i] > a[2 * i + 1]) {         if (x >= y)           S.insert(2 * i), S.insert(2 * i + 1);         else {           if (a[2 * i] > b[2 * i + 1])             ans += a[2 * i] - b[2 * i + 1];           else             ans += a[2 * i + 1] - b[2 * i];         }       }     }     bool turn = false;     while (!S.empty()) {       int x = *S.begin();       S.erase(S.begin());       if (!turn)         ans += a[x];       else         ans -= b[x];       turn = !turn;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     x = 0;     char c = getchar(), f = 0;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) f = 1;     for (; c >=  0  && c <=  9 ; c = getchar())       x = (x << 1) + (x << 3) + (c ^ 48);     if (f) x = -x;   }   const int P = 1e9 + 7;   int n, D, dp[3005][3005], s[3005][3005], res;   struct edge {     int to, nxt;   } e[3005];   int et, head[3005], iv[3005];   inline int ksm(int x, int q = P - 2) {     int r = 1;     for (; q; q >>= 1, x = 1ll * x * x % P)       if (q & 1) r = 1ll * r * x % P;     return r;   }   inline void adde(int x, int y) { e[++et] = (edge){y, head[x]}, head[x] = et; }   inline void dfs(int x) {     for (int i = 1; i <= n + 1; i++) dp[x][i] = 1;     for (int i = head[x]; i; i = e[i].nxt) {       dfs(e[i].to);       for (int j = 1; j <= n + 1; j++)         dp[x][j] = 1ll * dp[x][j] * s[e[i].to][j] % P;     }     for (int i = 1; i <= n + 1; i++) s[x][i] = (s[x][i - 1] + dp[x][i]) % P;   }   inline int inv(int x) { return x < 0 ? P - iv[-x] : iv[x]; }   int main() {     read(n), read(D);     for (int i = 2, f; i <= n; i++) read(f), adde(f, i);     iv[1] = 1;     for (int i = 2; i <= n + 1; i++) iv[i] = 1ll * iv[P % i] * (P - P / i) % P;     dfs(1);     for (int i = 1, w = 1; i <= n + 1;          (res += 1ll * w * s[1][i] % P) %= P, w = 1, i++)       for (int j = 1; j <= n + 1; j++)         if (i ^ j) w = 1ll * w * (D - j) % P * inv(i - j) % P;     return printf( %d n , (res + P) % P), 0;   }


#include <bits/stdc++.h>   using namespace std;   const int SIZE = 20 + 5;   const int Mod = 1e9 + 7;   int inv[SIZE], n;   long long a[SIZE], m, ans;   inline long long read() {     char ch = getchar();     long long f = 1, x = 0;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline int Qpow(int b, int p) {     long long ans = 1, t = b;     for (; p; p >>= 1, t = t * t % Mod)       if (p & 1) ans = ans * t % Mod;     return ans % Mod;   }   inline int C(long long y, int x) {     if (y < 0 || x < 0 || y < x) return 0;     y %= Mod;     if (y == 0 || x == 0) return 1;     int ans = 1;     for (int i = 0; i < x; i++) ans = (long long)ans * (y - i) % Mod;     for (int i = 1; i <= x; i++) ans = (long long)ans * inv[i] % Mod;     return ans;   }   int main() {     for (int i = 1; i <= 20; i++) inv[i] = Qpow(i, Mod - 2);     std::cin >> n >> m;     for (int i = 1; i <= n; i++) a[i] = read();     for (int x = 0; x < (1 << n); x++) {       if (!x)         ans = (ans + C(n + m - 1, n - 1)) % Mod;       else {         long long t = n + m;         int p = 0;         for (int i = 0; i < n; i++) {           if (x >> i & 1) {             p++;             t -= a[i + 1];           }         }         t -= p + 1;         if (p & 1)           ans = (ans - C(t, n - 1)) % Mod;         else           ans = (ans + C(t, n - 1)) % Mod;       }     }     printf( %lld , (ans + Mod) % Mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 1e5 + 5;   int n;   int M[9][2] = {{0, 0},  {-1, -1}, {1, 1},  {0, 1}, {1, 0},                  {0, -1}, {-1, 0},  {1, -1}, {-1, 1}};   int compute(vector<int> Arr, int A0, int A1, int val) {     Arr[0] = A0;     Arr[1] = A1;     int d = Arr[1] - Arr[0];     int ans = val;     for (int i = 2; i < n; i++) {       if (d + Arr[i - 1] != Arr[i]) {         if (d + Arr[i - 1] != Arr[i] + 1) {           if (d + Arr[i - 1] != Arr[i] - 1) {             return -1;           } else {             Arr[i]--;             ans++;           }         } else {           Arr[i]++;           ans++;         }       }     }     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int val;     cin >> n;     vector<int> A;     for (int i = 0; i < n; cin >> val, A.push_back(val), i++)       ;     int ans = -1;     for (int i = 0; i < 9; i++) {       int num =           compute(A, A[0] + M[i][0], A[1] + M[i][1], abs(M[i][0]) + abs(M[i][1]));       if (num != -1) {         if (ans == -1)           ans = num;         else           ans = min(ans, num);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const int N = 200100;   char a[N], b[N];   int cnt[330];   int main() {     int la, lb, i;     long long ans = 0;     scanf( %s%s , a, b);     la = strlen(a), lb = strlen(b);     for (i = 0; i < lb - la; i++) cnt[b[i]]++;     for (i = 0; i < la; i++) {       cnt[b[lb - la + i]]++;       if (a[i] ==  0 )         ans += cnt[ 1 ];       else         ans += cnt[ 0 ];       cnt[b[i]]--;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> arr(n);     vector<pair<int, int>> sorted_arr(n);     for (int i = 0; i < n; i++) {       cin >> arr[i];       sorted_arr[i] = {arr[i], i};     }     sort(sorted_arr.begin(), sorted_arr.end());     vector<int> pos(n);     for (int i = 0; i < n; i++) {       pos[i] = sorted_arr[i].second;     }     vector<int> next(n), prev(n);     next[n - 1] = n;     for (int i = n - 2; i >= 0; i--) {       int j = i + 1;       while (j < n && arr[i] > arr[j]) {         j = next[j];       }       next[i] = j;     }     prev[0] = -1;     for (int i = 1; i < n; i++) {       int j = i - 1;       while (j >= 0 && arr[i] > arr[j]) {         j = prev[j];       }       prev[i] = j;     }     int ans = 0;     for (int i = 1; i < n - 1; i++) {       if (i - prev[i] < next[i] - i) {         for (int j = prev[i] + 1; j < i; j++) {           int k = pos[arr[i] - arr[j] - 1];           if (i < k && k < next[i]) ans++;         }       } else {         for (int j = next[i] - 1; j > i; j--) {           int k = pos[arr[i] - arr[j] - 1];           if (prev[i] < k && k < i) ans++;         }       }     }     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     solve();     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   long long s(long long x) {     long long ans = 0;     while (x) ans += x % 10, x /= 10;     return ans;   }   long long solve(long long x) { return x * x + s(x) * x - n; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     long long sq = sqrt(n);     int i;     for (i = sq - 1000000; i <= sq + 1000000; i++) {       if (i > 0)         if (solve(i) == 0) {           cout << i <<   n ;           return 0;         }     }     cout << -1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double y111, y222, yw, xb, yb, r;   double ASIN(double w) {     if (w < -1.0) w = -1.0;     if (w > 1.0) w = 1.0;     return asin(w);   }   int main() {     cin >> y111 >> y222 >> yw >> xb >> yb >> r;     y111 += 1E-9;     y222 -= 1E-9;     double st = yw - r;     double plo = 2 * st - y111, phi = 2 * st - y222;     if (plo > phi) swap(plo, phi);     double D = sqrt(((xb) * (xb)) + ((plo - yb) * (plo - yb)));     double ang = ASIN(r / D);     complex<double> dir = complex<double>(0, plo) - complex<double>(xb, yb);     dir *= polar(1.0, -ang);     double ty = yb + (fabs(xb / dir.real())) * dir.imag();     if (ty < phi - r + 1E-9) {       double X = xb + ((st - yb) / dir.imag()) * dir.real();       printf( %.18lf n , X);     } else       puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double sn = 1e-6;   int n, k;   char arr[55][10];   string s[55];   string res[55];   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n - k + 1; i++) {       scanf( %s , arr[i]);       string st(arr[i]);       s[i] = st;     }     string val =  Aa ;     for (int i = 0; i < n - k + 1; i++) {       if (s[i] ==  NO ) {         if (res[i] !=   ) {           res[i + k - 1] = res[i];           continue;         }         res[i] = val;         res[i + k - 1] = val;         val[1] = val[1] + 1;         if (val[1] >  z ) {           val[0] = val[0] + 1;           val[1] =  a ;         }       }     }     for (int i = 0; i < n; i++) {       if (res[i] ==   ) {         res[i] = val;         val[1] = val[1] + 1;         if (val[1] >  z ) {           val[0] = val[0] + 1;           val[1] =  a ;         }       }     }     for (int i = 0; i < n; i++) {       printf( %s , res[i].c_str());       if (i != n - 1) printf(   );     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string x;     cin >> x;     int y;     if (x.size() == 1) {       y = x[0] -  0 ;       if (!(y % 4))         cout << 4;       else         cout << 0;       return 0;     }     y = x[x.size() - 1] -  0  + ((x[x.size() - 2] -  0 ) * 10);     if (!(y % 4))       cout << 4;     else       cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int min(int a, int b) {     if (a < b)       return a;     else       return b;   }   int main() {     int n, a, b, c, j;     bool t = false;     cin >> n;     for (int i = 0; i < (4); ++i) {       cin >> a >> b;       if (a < 1 || b < 1)         c = n + 1;       else         c = min(a, b);       cin >> a >> b;       if (a < 1 || b < 1)         j = n + 1;       else         j = min(a, b);       if (n >= c + j) {         t = true;         a = i + 1;         break;       }     }     if (t)       cout << a <<     << c <<     << n - c;     else       cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 102;   double dp[N][N][N][3];   int vis[N][N][N][3];   double call(int r, int s, int p, int id) {     if (id == 0) {       if (r == 0) return 0;       if (s + p == 0) return 1;     } else if (id == 1) {       if (s == 0) return 0;       if (r + p == 0) return 1;     } else {       if (p == 0) return 0;       if (r + s == 0) return 1;     }     if (vis[r][s][p][id] == 1) return dp[r][s][p][id];     vis[r][s][p][id] = 1;     double ret = 0;     double total = ((r + s + p - 1) * (r + s + p)) / 2;     double pr = ((r * (r - 1)) / 2) / total;     double ps = ((s * (s - 1)) / 2) / total;     double pp = ((p * (p - 1)) / 2) / total;     double prs = (r * s) / total;     double prp = (r * p) / total;     double psp = (s * p) / total;     double prob = pr + ps + pp;     if (r >= 1 and s >= 1) ret = ret + prs * call(r, s - 1, p, id);     if (r >= 1 and p >= 1) ret = ret + prp * call(r - 1, s, p, id);     if (s >= 1 and p >= 1) ret = ret + psp * call(r, s, p - 1, id);     return dp[r][s][p][id] = ret / (1 - prob);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     int r, s, p;     cin >> r >> s >> p;     cout << fixed << setprecision(9) << call(r, s, p, 0) <<              << call(r, s, p, 1) <<     << call(r, s, p, 2) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.141592653589793238;   long long powmod(long long a, long long b) {     long long res = 1;     a %= 1000000007;     for (; b; b >>= 1) {       if (b & 1) res = res * a % 1000000007;       a = a * a % 1000000007;     }     return res;   }   long long fac[1000005];   void factorial(int mx) {     fac[0] = 1ll;     for (int i = 1; i <= mx; i++) {       fac[i] = fac[i - 1] * (long long)i;       fac[i] %= 1000000007;     }   }   int main() {     factorial(1000005 - 5);     int n, m, vol, type;     long long ans, cnt = 1ll;     scanf( %d , &n);     scanf( %d , &m);     vector<vector<int> > vec(m);     for (int i = 0; i < n; i++) {       scanf( %d , &vol);       while (vol--) {         scanf( %d , &type);         vec[type - 1].push_back(i);       }     }     for (int i = 0; i < m; i++) sort(vec[i].begin(), vec[i].end());     sort(vec.begin(), vec.end());     ans = 1ll;     for (int i = 1; i <= m - 1; i++) {       if (vec[i] == vec[i - 1])         ans *= ++cnt;       else         cnt = 1;       ans %= 1000000007;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int ti = 0; ti < t; ti++) {       int n, k;       cin >> n >> k;       vector<int> arr(n);       for (int i = 0; i < n; i++) cin >> arr[i];       sort(arr.begin(), arr.end());       vector<int> weights(k);       for (int i = 0; i < k; i++) cin >> weights[i];       sort(weights.begin(), weights.end());       long long total = 0;       for (int i = n - 1; i >= n - k; i--) {         total += arr[i];       }       int w = 0;       for (int i = k - 1; i >= 0; i--) {         if (weights[i] <= 1) break;         total += arr[w];         w += weights[i] - 1;       }       for (int i = 0; i < k; i++) {         if (weights[i] > 1) break;         total += arr[n - 1 - i];       }       cout << total << endl;     }     return 0;   }


#include <bits/stdc++.h>   long long ago;   using namespace std;   template <class T = long long int>   T nxt() {     T x;     cin >> x;     return x;   }   long long int pw(long long int a, long long int b, long long int mod) {     if (!b) return 1;     if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;     return pw(a * a % mod, b / 2, mod) % mod;   }   const long long int N = 1000 + 10;   const long long int INF = 8e18;   const long long int MOD = 1e9 + 7;   long long int n, m, mark[N];   double dist[N], S[N], Z[N];   vector<pair<long long int, double>> adj[N];   priority_queue<pair<double, long long int>, vector<pair<double, long long int>>,                  greater<pair<double, long long int>>>       pq;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cout << setprecision(15) << fixed;     cin >> n;     for (long long int i = 1; i <= n; i++) {       for (long long int j = 1; j <= n; j++) {         long long int p = nxt();         if (i == j || p == 0) continue;         adj[j].emplace_back(i, double(p) / 100);       }     }     fill(Z, Z + N, 1.0);     fill(dist, dist + N, INF);     dist[n] = 0;     pq.push({0, n});     while (!pq.empty()) {       long long int u = pq.top().second;       pq.pop();       if (mark[u]) continue;       mark[u] = 1;       for (auto [v, p] : adj[u]) {         if (mark[v]) continue;         S[v] += Z[v] * p * (dist[u] + 1);         Z[v] *= (1 - p);         dist[v] = (S[v] + Z[v]) / (1 - Z[v]);         pq.push({dist[v], v});       }     }     cout << dist[1] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int n;     cin >> n >> s;     vector<int> vec;     for (int i = 0; i < s.length(); ++i) {       if (s[i] ==  B ) {         int res = 0;         while (i < s.length() && s[i] ==  B ) {           ++res;           ++i;         }         vec.push_back(res);         continue;       }     }     cout << vec.size() <<   n ;     for (int i = 0; i < (int)vec.size(); ++i) {       cout << vec[i] <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 1e5;   struct NOOD {     int flag;     int l;     int r;     int v;   } num[MaxN + 5];   int ans[MaxN + 5], p[MaxN + 5];   bool ok[MaxN + 5], flag;   int Max;   int n, m;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d%d , &num[i].flag, &num[i].l, &num[i].r, &num[i].v);     }     for (int i = 1; i <= n; i++) ans[i] = -100000000;     for (int i = m; i >= 1; i--) {       if (num[i].flag == 1) {         for (int j = num[i].l; j <= num[i].r; j++) ans[j] -= num[i].v;       } else {         for (int j = num[i].l; j <= num[i].r; j++) {           if (ok[j] && ans[j] < num[i].v) continue;           ans[j] = num[i].v;           ok[j] = 1;         }       }     }     for (int i = 1; i <= n; i++) p[i] = ans[i];     for (int i = 1; i <= m; i++) {       if (num[i].flag == 1) {         for (int j = num[i].l; j <= num[i].r; j++) p[j] += num[i].v;       } else {         Max = -100000000;         for (int j = num[i].l; j <= num[i].r; j++) Max = max(Max, p[j]);         if (Max != num[i].v) flag = 1;       }     }     if (flag)       printf( NO n );     else {       printf( YES n );       for (int i = 1; i <= n; i++) printf( %d  , ans[i]);       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   long long solve() {     long long n, i, j, k;     cin >> n >> k;     long long arr[n];     for (i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     j = 0;     for (i = 0; i < n && arr[i] < 0; i += k) j += 2 * abs(arr[i]);     for (i = n - 1; i >= 0 && arr[i] > 0; i -= k) j += 2 * arr[i];     j -= max(abs(arr[0]), abs(arr[n - 1]));     return j;   }   int main() {     long long t;     cin >> t;     while (t--) cout << solve() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string a, b, tem;     scanf( %d , &n);     a =  <3 ;     for (int i = 0, j = 0; i < n; ++i) {       cin >> tem;       a += tem;       a +=  <3 ;     }     cin >> b;     int len1 = a.length(), po1 = 0, po2 = 0;     int len2 = b.length();     while (1) {       if (po1 == len1) {         printf( yes n );         return 0;       }       if (po2 == len2) {         printf( no n );         return 0;       }       if (a[po1] == b[po2]) po1++;       po2++;     }   }