#include <bits/stdc++.h>   using namespace std;   const int N = (int)3e3;   int p[N], n, m, deg[N], d[N];   char a[N][N];   vector<int> adj[N];   queue<int> q;   bool visited[N];   int findSet(int u) { return p[u] == u ? p[u] : p[u] = findSet(p[u]); }   void unionSet(int u, int v) {     int x = findSet(u), y = findSet(v);     p[x] = y;   }   int main() {     scanf( %d %d n , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %s n , a[i] + 1);       p[i] = i;     }     for (int i = 1; i <= m; ++i) p[n + i] = n + i;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (a[i][j] ==  = ) unionSet(i, n + j);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         if (a[i][j] ==  > )           adj[findSet(n + j)].push_back(findSet(i)), deg[findSet(i)]++;         else if (a[i][j] ==  < )           adj[findSet(i)].push_back(findSet(n + j)), deg[findSet(n + j)]++;       }     bool ans = 1;     for (int i = 1; i <= n + m; ++i)       if (deg[findSet(i)] == 0 && !visited[findSet(i)]) {         d[findSet(i)] = 1;         visited[findSet(i)] = 1;         q.push(findSet(i));       }     while (!q.empty()) {       int u = q.front();       q.pop();       for (int v : adj[u])         if (!visited[v]) {           d[v] = max(d[v], d[u] + 1);           deg[v]--;           if (deg[v] == 0) {             q.push(v);             visited[v] = 1;           }         }     }     for (int i = 1; i <= n + m; ++i)       if (!visited[findSet(i)]) {         ans = 0;         break;       }     if (ans) {       printf( Yes n );       for (int i = 1; i <= n; ++i) printf( %d  , d[findSet(i)]);       printf(  n );       for (int i = 1; i <= m; ++i) printf( %d  , d[findSet(n + i)]);       printf(  n );     } else       printf( No n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int howfar(const std::string& s) {     const int N = s.length();     int r(0);     int d(1);     for (int i = 0; i != N; ++i) {       switch (s[i]) {         case  F :           r += d;           break;         case  T :           d = -d;           break;         default:           assert(0);       }     }     return abs(r);   }   char invert(char c) { return c ==  T  ?  F  :  T ; }   int solve(const std::string& s, int n) {     const int N = s.length();     if (n > 0 && n % 2 == 0) {       int rm(-10000);       std::string sm;       std::string s2 = s;       for (int i1 = 0; i1 != N; ++i1) {         for (int i2 = 0; i2 != N; ++i2) {           s2[i1] = invert(s2[i1]);           s2[i2] = invert(s2[i2]);           const int r2 = howfar(s2);           if (r2 > rm) {             rm = r2;             sm = s2;           }           s2[i2] = invert(s2[i2]);           s2[i1] = invert(s2[i1]);         }       }       return solve(sm, n - 2);     } else if (n > 0) {       int rm(-10000);       std::string sm = s;       for (int i = 0; i != N; ++i) {         std::string s2 = s;         s2[i] = invert(s2[i]);         const int r = howfar(s2);         if (r > rm) {           rm = r;           sm = s2;         }       }       return solve(sm, n - 1);     }     return howfar(s);   }   int main(int argc, char* argv[]) {     std::string s;     cin >> s;     int n;     cin >> n;     cout << solve(s, n) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, q;   long long dp[15][(1 << 13) + 10][15];   struct E {     int a, b;   } e[20];   struct Lca {     int a, b, c;   } lca[100 + 10];   int num[(1 << 13) + 10];   bool il(int u, int state, int last) {     for (int i = 1; i <= q; i++) {       int xx = ((state >> lca[i].a - 1) & 1) + ((state >> lca[i].b - 1) & 1) +                ((state >> lca[i].c - 1) & 1);       if (xx == 2 && (u != lca[i].c || last == 0))         return true;       else if (xx == 1 && ((state >> lca[i].c - 1) & 1) && last == 0)         return true;       else if (xx == 3 && (u == lca[i].a || u == lca[i].b) && u != lca[i].c)         return true;     }     for (int i = 1; i <= m; i++) {       int xx = ((state >> e[i].a - 1) & 1) + ((state >> e[i].b - 1) & 1);       if (xx == 1 && u != e[i].a && u != e[i].b) return true;     }     return false;   }   long long dfs(int u, int state, int last) {     if (dp[u][state][last] != -1) return dp[u][state][last];     dp[u][state][last] = 0;     if (il(u, state, last)) return dp[u][state][last];     if (num[state] == 1) {       return dp[u][state][last] = 1;     }     int full = state ^ (1 << u - 1);     for (int x = full; x; x = (x - 1) & full) {       int ok = true;       int y = full ^ x;       for (int i = 1; i <= m; i++) {         if ((((x >> (e[i].a - 1)) & 1) && ((y >> (e[i].b - 1)) & 1)) ||             (((y >> (e[i].a - 1)) & 1) && ((x >> (e[i].b - 1)) & 1))) {           ok = false;           break;         }       }       if (!ok) continue;       for (int i = last + 1; i <= n; i++)         if ((x >> (i - 1)) & 1)           dp[u][state][last] += dfs(u, y | (1 << u - 1), i) * dfs(i, x, 0);     }     return dp[u][state][last];   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &e[i].a, &e[i].b);     }     for (int i = 1; i <= q; i++) {       scanf( %d%d%d , &lca[i].a, &lca[i].b, &lca[i].c);     }     for (int i = 0; i < (1 << n); i++) {       int x = i;       while (x) {         num[i] += x & 1;         x >>= 1;       }     }     memset(dp, -1, sizeof(dp));     printf( %I64d n , dfs(1, (1 << n) - 1, 0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 1e3 + 7;   int n, m, tot, root[N];   long long p, ans;   struct node {     int ls, rs;     long long sum;   } t[N * 30];   void insert(int x, int &y, int l, int r, int v) {     y = ++tot;     t[y] = t[x];     t[y].sum++;     if (l == r) return;     int mid = (l + r) >> 1;     if (v <= mid)       insert(t[x].ls, t[y].ls, l, mid, v);     else       insert(t[x].rs, t[y].rs, mid + 1, r, v);   }   long long query(int l, int r, int x, int y, int L, int R) {     if (L > R || l > r || L > r || R < l) return 0;     if (l >= L && r <= R) return t[y].sum - t[x].sum;     int mid = (l + r) >> 1;     return query(l, mid, t[x].ls, t[y].ls, L, R) +            query(mid + 1, r, t[x].rs, t[y].rs, L, R);   }   long long cal(long long x) { return x * (x - 1) / 2; }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       insert(root[i - 1], root[i], 1, n, x);     }     while (m--) {       int l, r, u, v;       scanf( %d%d%d%d , &l, &r, &u, &v);       ans = (long long)n * (long long)(n - 1) / 2;       p = query(1, n, root[0], root[n], 1, r - 1);       ans -= cal(p);       p = query(1, n, root[0], root[n], v + 1, n);       ans -= cal(p);       p = query(1, n, root[0], root[l - 1], 1, n);       ans -= cal(p);       p = query(1, n, root[u], root[n], 1, n);       ans -= cal(p);       p = query(1, n, root[0], root[l - 1], 1, r - 1);       ans += cal(p);       p = query(1, n, root[0], root[l - 1], v + 1, n);       ans += cal(p);       p = query(1, n, root[u], root[n], 1, r - 1);       ans += cal(p);       p = query(1, n, root[u], root[n], v + 1, n);       ans += cal(p);       printf( %I64d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   char _buf[100000], *_op(_buf), *_ed(_buf);   inline int getint() {     int _s = 0, _f = 1;     char _ch = (_op == _ed && (_ed = (_op = _buf) + fread(_buf, 1, 100000, stdin),                                _op == _ed)                     ? EOF                     : *_op++);     while (!( 0  <= _ch && _ch <=  9 ))       (_ch ==  - ) && (_f = -1),           _ch =               (_op == _ed && (_ed = (_op = _buf) + fread(_buf, 1, 100000, stdin),                               _op == _ed)                    ? EOF                    : *_op++);     while (( 0  <= _ch && _ch <=  9 ))       _s = _s * 10 + _ch - 48,       _ch = (_op == _ed && (_ed = (_op = _buf) + fread(_buf, 1, 100000, stdin),                             _op == _ed)                  ? EOF                  : *_op++);     return _s * _f;   }   const int N = 2e5 + 1, mod = 1e9 + 7;   inline void check(int& x) { x -= mod, x += x >> 31 & mod; }   inline void cmax(int& x, int y) {     if (x - y >> 31) x = y;   }   inline void cmin(int& x, int y) {     if (y - x >> 31) x = y;   }   int n, m, ans;   int Sx, Sy, Fx, Fy;   int X[N], Y[N], tag[N];   int idx[N], idy[N], posx[N], posy[N];   inline int dis(int x, int y, int p) {     return min(abs(X[p] - x), abs(Y[p] - y));   }   priority_queue<pair<int, int> > q;   inline void input() {     n = getint(), m = getint();     Sx = getint(), Sy = getint(), Fx = getint(), Fy = getint();     for (int i = 1; i <= m; i++) X[i] = getint(), Y[i] = getint();     ans = abs(Fx - Sx) + abs(Fy - Sy);     for (int i = 1; i <= m; i++) q.push(pair<int, int>(-dis(Sx, Sy, i), i));   }   inline int cmpx(int x, int y) { return X[x] < X[y]; }   inline int cmpy(int x, int y) { return Y[x] < Y[y]; }   inline void init() {     for (int i = 1; i <= m; i++) idx[i] = i;     sort(idx + 1, idx + 1 + m, cmpx);     for (int i = 1; i <= m; i++) posx[idx[i]] = i;     for (int i = 1; i <= m; i++) idy[i] = i;     sort(idy + 1, idy + 1 + m, cmpy);     for (int i = 1; i <= m; i++) posy[idy[i]] = i;   }   inline void work() {     for (int u, w, v; !q.empty();) {       w = -q.top().first, u = q.top().second, q.pop();       if (tag[u]) continue;       tag[u] = 1, ans = min(0ll + ans, 0ll + w + abs(X[u] - Fx) + abs(Y[u] - Fy));       if ((v = idx[posx[u] - 1]) && !tag[v])         q.push(pair<int, int>(-w - X[u] + X[v], v));       if ((v = idx[posx[u] + 1]) && !tag[v])         q.push(pair<int, int>(-w - X[v] + X[u], v));       if ((v = idy[posy[u] - 1]) && !tag[v])         q.push(pair<int, int>(-w - Y[u] + Y[v], v));       if ((v = idy[posy[u] + 1]) && !tag[v])         q.push(pair<int, int>(-w - Y[v] + Y[u], v));     }     cout << ans <<   n ;   }   int main() {     input();     init();     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, K;   char maze[2010][2010];   int up[2010][2010], down[2010][2010];   struct Segtree {     int key[2010 * 4], ans[2010 * 4];     void add(deque<pair<int, int> > &que, int pos, int val) {       while (!que.empty() && val < que.back().second) que.pop_back();       que.push_back(make_pair(pos, val));     }     void remove(deque<pair<int, int> > &que, int pos) {       while (!que.empty() && que.front().first <= pos) que.pop_front();     }     void cal(int l, int r, int step) {       int mid = l + r >> 1;       deque<pair<int, int> > qU, qD;       int i = 0, j = 0;       key[step] = 0;       for (; j < m; j++) {         int a, b;         add(qU, j, mid - max(l - 1, up[mid][j]));         if (mid < r)           add(qD, j, b = (min(r + 1, down[mid + 1][j]) - mid - 1));         else           add(qD, j, b = 0);         key[step] =             max(key[step], min(j - i + 1, qU.front().second + qD.front().second));         while (i < j && j - i + 1 > qU.front().second + qD.front().second) {           remove(qU, i);           remove(qD, i);           i++;           key[step] = max(key[step],                           min(j - i + 1, qU.front().second + qD.front().second));         }       }     }     void build(int l, int r, int step) {       cal(l, r, step);       if (l == r) return;       int mid = l + r >> 1;       build(l, mid, step * 2);       build(mid + 1, r, step * 2 + 1);       ans[step] = max(key[step], max(ans[step * 2], ans[step * 2 + 1]));     }     void update(int l, int r, int pos, int step) {       cal(l, r, step);       if (l == r) return;       int mid = l + r >> 1;       if (pos <= mid)         update(l, mid, pos, step * 2);       else         update(mid + 1, r, pos, step * 2 + 1);       ans[step] = max(key[step], max(ans[step * 2], ans[step * 2 + 1]));     }   } tree;   int main() {     scanf( %d%d%d , &n, &m, &K);     for (int i = 0; i < (n); i++) scanf( %s , maze[i]);     for (int j = 0; j < (m); j++) up[0][j] = maze[0][j] ==  .  ? -1 : 0;     for (int i = 1; i < n; i++)       for (int j = 0; j < (m); j++)         up[i][j] = maze[i][j] ==  .  ? up[i - 1][j] : i;     for (int j = 0; j < (m); j++)       down[n - 1][j] = maze[n - 1][j] ==  .  ? n : n - 1;     for (int i = n - 2; i >= 0; i--)       for (int j = 0; j < (m); j++)         down[i][j] = maze[i][j] ==  .  ? down[i + 1][j] : i;     tree.build(0, n - 1, 1);     while (K--) {       int x, y;       scanf( %d%d , &x, &y);       x--, y--;       maze[x][y] =  # ;       up[0][y] = maze[0][y] ==  .  ? -1 : 0;       for (int i = 1; i < n; i++) up[i][y] = maze[i][y] ==  .  ? up[i - 1][y] : i;       down[n - 1][y] = maze[n - 1][y] ==  .  ? n : n - 1;       for (int i = n - 2; i >= 0; i--)         down[i][y] = maze[i][y] ==  .  ? down[i + 1][y] : i;       tree.update(0, n - 1, x, 1);       printf( %d n , tree.ans[1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<pair<int, int> > v[1000007];   vector<int> rv[1000007];   int comp[1000007];   vector<pair<int, int> > g[1000007];   long long sm[1000007];   int used[1000007];   int stver;   stack<int> s;   vector<int> srt;   bool val[100000002];   long long hval[1000007];   long long dp[1000007];   map<int, int> ZX;   void dfs(int vertex) {     used[vertex] = 1;     int i;     int sz = v[vertex].size();     for (i = 0; i < sz; i++) {       if (used[v[vertex][i].first] == 0) {         dfs(v[vertex][i].first);       }     }     s.push(vertex);   }   void revdfs(int vertex, int id) {     comp[vertex] = id;     int i;     int sz = rv[vertex].size();     for (i = 0; i < sz; i++) {       if (comp[rv[vertex][i]] == 0) {         revdfs(rv[vertex][i], id);       }     }   }   void precalc() {     int i;     long long cur = 0;     int br = 1;     if (val[0] == true) {       hval[0] = 1;     }     for (i = 1; i < 100000002; i++) {       cur = cur + br;       if (i >= (br * (br + 1) / 2)) {         br++;       }       if (val[i] == true) {         hval[ZX[i]] = cur;       }     }   }   void calc_dp(int vertex) {     used[vertex] = 1;     int i;     int sz = g[vertex].size();     for (i = 0; i < sz; i++) {       if (used[g[vertex][i].first] == 0) {         calc_dp(g[vertex][i].first);       }       if (dp[vertex] < dp[g[vertex][i].first] + g[vertex][i].second) {         dp[vertex] = dp[g[vertex][i].first] + g[vertex][i].second;       }     }     dp[vertex] += sm[vertex];   }   void input() {     scanf( %d%d , &n, &m);     int i;     for (i = 1; i <= m; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       v[x].push_back(make_pair(y, z));       rv[y].push_back(x);       srt.push_back(z);       val[z] = true;     }     if (srt.size() != 0) {       sort(srt.begin(), srt.end());       ZX[srt[0]] = 1;       for (i = 1; i < m; i++) {         if (srt[i] == srt[i - 1]) {           continue;         }         ZX[srt[i]] = ZX[srt[i - 1]] + 1;       }     }     scanf( %d , &stver);     precalc();   }   void solve() {     int i, j;     for (i = 1; i <= n; i++) {       if (used[i] == 0) {         dfs(i);       }     }     int tp = 1;     while (s.empty() == false) {       int u = s.top();       s.pop();       if (comp[u] != 0) {         continue;       }       revdfs(u, tp);       tp++;     }     for (i = 1; i <= n; i++) {       int sz = v[i].size();       for (j = 0; j < sz; j++) {         if (comp[v[i][j].first] == comp[i]) {           sm[comp[i]] += hval[ZX[v[i][j].second]];         } else {           g[comp[i]].push_back(make_pair(comp[v[i][j].first], v[i][j].second));         }       }     }     for (i = 1; i <= n; i++) {       used[i] = 0;     }     stver = comp[stver];     calc_dp(stver);     printf( %I64d n , dp[stver]);   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     input();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int INF = 2e18;   bool isPrime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long int i = 5; i * i <= n; i = i + 6) {       if (n % i == 0 || n % (i + 2) == 0) return false;     }     return true;   }   long long int exp(long long int x, long long int n) {     long long int res = 1;     while (n > 0) {       if (n % 2 == 1) res = (res * x) % 1000000007;       x = (x * x) % 1000000007;       n = n / 2;     }     return res;   }   void null() {     long long int n, l, r;     cin >> n >> l >> r;     vector<long long int> a, b;     for (long long int i = 0; i < n; i++) {       long long int x;       cin >> x;       a.push_back(x);     }     for (long long int i = 0; i < n; i++) {       long long int x;       cin >> x;       b.push_back(x);     }     for (long long int i = 0; i < l - 1; i++) {       if (a[i] != b[i]) {         cout <<  LIE ;         return;       }     }     for (long long int i = r; i < n; i++) {       if (a[i] != b[i]) {         cout <<  LIE ;         return;       }     }     cout <<  TRUTH ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t = 1;     clock_t start, end;     start = clock();     cout << fixed << setprecision(20);     while (t--) {       null();     }     end = clock();     double time_taken = double(end - start) / double(CLOCKS_PER_SEC);   }


#include <bits/stdc++.h>   using namespace std;   long long int inv[32][2];   void rec(vector<int>& a, int b) {     if (b < 0 || a.size() == 0) return;     int c[2] = {0};     vector<int> v[2];     for (int x : a) {       int val;       if ((x & (1 << b)) > 0)         val = 1;       else         val = 0;       if (val == 0)         inv[b][0] += c[1];       else         inv[b][1] += c[0];       c[val]++;       v[val].push_back(x);     }     rec(v[0], b - 1);     rec(v[1], b - 1);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     rec(a, 30);     long long int x = 0, ans = 0;     for (int i = 0; i <= 30; i++) {       ans += min(inv[i][0], inv[i][1]);       if (inv[i][0] > inv[i][1]) x += (1 << i);     }     cout << ans <<     << x <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   vector<int> g[N];   void dfs(int u, vector<int>& dep, int par = -1, int h = 0) {     dep[u] = h;     for (int v : g[u]) {       if (v == par) continue;       dfs(v, dep, u, h + 1);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, x;     cin >> n >> x;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     vector<int> dep_r(n + 1);     vector<int> dep_x(n + 1);     dfs(1, dep_r);     dfs(x, dep_x);     int mx = -1;     for (int i = 1; i <= n; i++) {       if (dep_x[i] < dep_r[i]) {         mx = max(mx, dep_r[i] << 1);       }     }     cout << mx <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const long long inf = 1e18;   const int maxn = 1e5 + 10;   const double eps = 1e-7;   const double pi = 3.14159265359;   int n, m, t[maxn];   int par[maxn];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> t[i];     }     par[0] = t[0];     for (int i = 1; i < n; i++) {       par[i] = par[i - 1] + t[i];     }     for (int i = 0; i < n; i++) {       if (i == 0) {         cout << 0 <<    ;         continue;       }       sort(t, t + i);       int res = 0;       int s = par[i];       int id = i - 1;       while (s > m) {         s -= t[id];         id--;         res++;       }       cout << res <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   int b[10] = {0, 2, 3, 1}, a[maxn];   int main() {     int t;     scanf( %d , &t);     while (t--) {       long long n, ans = 1;       cin >> n;       int m = n % 3;       n = (n + 2) / 3;       while (n > ans) {         n -= ans;         ans *= 4;       }       int cnt = 0;       long long ans1 = ans + n - 1, ans2 = ans * 2;       n--;       while (n) {         a[++cnt] = n % 4;         n /= 4;       }       long long now = 1;       for (int i = 1; i <= cnt; i++) ans2 += b[a[i]] * now, now *= 4;       if (m == 1)         cout << ans1 << endl;       else if (m == 2)         cout << ans2 << endl;       else if (m == 0)         cout << (ans1 ^ ans2) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int q;   void solve(long long int x) {     for (long long int i = 2; i * i <= x; i++) {       if (x % i == 0) {         long long int temp = x / i;         for (long long int j = 2; j * j <= temp; j++) {           if (temp % j == 0) {             cout << 1 <<   n ;             cout << i * j;             return;           }         }         cout << 2;         return;       }     }     cout << 1 <<   n ;     cout << 0;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> q;     if (q == 1) {       cout << 1 <<   n ;       cout << 0;       return 0;     }     solve(q);     return 0;   }


#include <bits/stdc++.h>   int n;   int x[200050];   int f[200050];   int ans = 0;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &x[i]);     for (int i = 0; i < n; i++) scanf( %d , &f[i]);     int k = 0, l = 0;     while (l < n) {       if (x[k] == f[l])         k++, l++;       else         ans++, l++;     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   struct point {     double x, y, z;   } P[5200];   inline double sqr(double x) { return x * x; }   inline double dist(point a, point b) {     return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y) + sqr(a.z - b.z));   }   inline double len(point a, point b, point c) {     return dist(a, b) + dist(a, c) + dist(b, c);   }   int main() {     cin >> n;     double ans = 1e100;     for (int i = 0; i < n; i++) cin >> P[i].x >> P[i].y >> P[i].z;     for (int i = 1; i < n; i++)       for (int j = i + 1; j < n; j++) ans = min(ans, len(P[0], P[i], P[j]));     cout.precision(11);     cout << ans / 2 << endl;   }


#include <bits/stdc++.h>   int main() {     int m, n, i, j, p, q;     scanf( %d %d , &m, &n);     scanf( %d %d , &p, &q);     int ar[m], br[n];     for (i = 0; i < m; i++) {       scanf( %d , &ar[i]);     }     for (i = 0; i < n; i++) {       scanf( %d , &br[i]);     }     if (ar[p - 1] < br[n - q])       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int A[100005];   int F[100005];   int main() {     int n, x;     cin >> n >> x;     for (int i = 1; i <= n; i++) {       scanf( %d , &A[i]);       F[A[i]]++;     }     int idx = (n + 1) / 2;     bool wasPresent = true;     if (!F[x]) {       wasPresent = false;       A[n + 1] = x;       n++;     }     sort(A + 1, A + n + 1);     int ans = 100005;     for (int i = 1; i <= n; i++) {       if (A[i] == x) {         int add = 0;         if ((i - 1) > (n - i)) {           add = (i - 1) - (n - i);         } else if ((i - 1) < (n - i)) {           add = (n - i) - (i - 1) - 1;         }         ans = min(ans, add);       }     }     if (!wasPresent) ans++;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1000000000000000000;   map<pair<long long, int>, long long> memo;   long long solve(long long n, int x) {     pair<long long, int> p = make_pair(n, x);     if (memo.find(p) != memo.end()) return memo[p];     if (n == 0) return memo[p] = 0;     if (n == 1) return memo[p] = (x == 0) ? 1 : 0;     return memo[p] = solve((n + 1) / 2, x) + (x ? solve(n / 2, x - 1) : 0);   }   int main() {     ios_base::sync_with_stdio(false);     long long n, t;     cin >> n >> t;     for (int i = 0; (1ll << i) <= t; ++i)       if (t == (1ll << i)) {         cout << solve(n + 2, i + 1) - solve(2, i + 1);         return 0;       }     cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.size();     int a = 0, b = 0, c = 0, d = 0;     for (int i = 0; i < n; i++) {       if (s[i] >=  A  && s[i] <=  Z )         a = 1;       else if (s[i] >=  a  && s[i] <=  z )         b = 1;       else if (s[i] >=  0  && s[i] <=  9 )         c = 1;     }     if (n >= 5) {       if (a && b && c)         cout <<  Correct  << endl;       else         cout <<  Too weak  << endl;     } else       cout <<  Too weak  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[200010];   int main() {     int n;     while (~scanf( %lld , &n)) {       long long ans = 0;       for (int i = 0; i < n; ++i) scanf( %lld , &a[i]);       for (int i = 0; i < n;) {         ans++;         long long j = i;         while (j < n && a[j] == -1) j++;         if (j == n) break;         long long k = j + 1;         while (k < n && a[k] == -1) k++;         if (k == n) break;         long long d = k - j;         if ((a[k] - a[j]) % d) {           i = k;           continue;         }         long long s = (a[k] - a[j]) / d;         if (s > 0 && a[j] - s * (j - i) <= 0) {           i = k;           continue;         }         long long r = k + 1;         while (r < n) {           long long e = a[k] + s * (r - k);           if (a[r] != -1 && a[r] != e) break;           if (e <= 0) break;           r++;         }         i = r;       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( -O2 )   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a << endl;     err(++it, args...);   }   const int LIM = 1e5 + 5, MOD = 1e9 + 7;   int t, n, m, k, x, y;   int is_com[LIM];   vector<int> pr;   void sieve() {     for (int i = 2; i < LIM; i++) {       if (!is_com[i]) pr.push_back(i);       for (auto &it : pr) {         if (it * i >= n) break;         is_com[i * it] = 1;         if (i % it == 0) {           break;         }       }     }   }   long long int powm(long long int x, long long int pw, long long int MOD) {     long long int res = 1;     while (pw) {       if (pw & 1LL) res = ((res * x)) % MOD;       pw >>= 1;       x = ((x * x)) % MOD;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     sieve();     long long int x, y;     cin >> x >> y;     long long int ans = 0;     if (y % x == 0) {       map<int, int> fac;       y /= x;       long long int cp = y;       for (auto &it : pr) {         if (cp == 1) break;         while (cp % it == 0) fac[it]++, cp /= it;       }       if (cp > 1) fac[cp]++;       for (long long int i = 1; i < (long long int)1e5; ++i) {         if (i * i > y) break;         if (y % i == 0) {           map<int, int> f;           cp = i;           for (auto &it : fac) {             if (cp == 1) break;             while (cp % it.first == 0) f[it.first]++, cp /= it.first;           }           int mu = 1;           for (auto &it : f) {             if (it.second > 1)               mu = 0;             else               mu *= -1;           }           ans += mu * powm(2, y / i - 1, MOD);           if (y / i != i) {             map<int, int> f;             cp = y / i;             for (auto &it : fac) {               if (cp == 1) break;               while (cp % it.first == 0) f[it.first]++, cp /= it.first;             }             int mu = 1;             for (auto &it : f) {               if (it.second > 1)                 mu = 0;               else                 mu *= -1;             }             ans += mu * powm(2, i - 1, MOD);           }           ans %= MOD;         }       }       cout << (ans + MOD) % MOD <<   n ;     } else       cout << 0 <<   n ;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, m;     char ch[51];     scanf( %s , &ch);     n = strlen(ch);     if (n == 1)       printf( %c , ch[0]);     else {       if (n % 2 == 0)         m = (n / 2) - 1;       else         m = (n / 2);       printf( %c , ch[m]);       int j = 1;       for (int i = 1; i <= n / 2; i++) {         if (j < n) printf( %c , ch[m + i]);         j++;         if (j < n) printf( %c , ch[m - i]);         j++;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k, m, n, a = 0, b = 0;     cin >> n >> m;     k = n;     k = k / 9;     n = n % 9;     if (n != 0) k++;     for (i = 0; i < k; i++) cout << 54;     cout << endl;     for (i = 0; i < k - 1; i++) cout << 45;     cout << 46;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int query(int l, int r) {     if (l < 1 || r > n) return false;     string re;     cout << 1 <<     << l <<     << r << endl;     cin >> re;     return re ==  TAK ;   }   int get(int l, int r) {     if (l > r) return false;     while (l < r) {       int mid = (l + r) >> 1;       if (query(mid, mid + 1))         r = mid;       else         l = mid + 1;     }     return l;   }   int main() {     cin >> n >> k;     int x, y;     x = get(1, n);     y = get(1, x - 1);     if (!query(y, x)) y = get(x + 1, n);     cout << 2 <<     << x <<     << y << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long m, tot, cnt;   long long geta(long long limit) {     long long res = 1;     while (res * res * res <= limit) res++;     return res - 1;   }   void dfs(long long limit, long long num, long long vol) {     if (limit == 0) {       if (cnt < num) {         cnt = num;         tot = vol;       }       return;     }     long long a = geta(limit);     dfs(limit - a * a * a, num + 1, vol + a * a * a);     if (a > 1) {       dfs(a * a * a - 1 - (a - 1) * (a - 1) * (a - 1), num + 1,           vol + (a - 1) * (a - 1) * (a - 1));     }   }   int main() {     while (scanf( %I64d , &m) != EOF) {       cnt = 0, tot = 0;       dfs(m, 0, 0);       printf( %I64d %I64d n , cnt, tot);     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename C>   class mcmf {    public:     static constexpr T eps = (T)1e-9;     struct edge {       int from;       int to;       T c;       T f;       C cost;     };     vector<vector<int> > g;     vector<edge> edges;     vector<C> d;     vector<int> q;     vector<bool> in_queue;     vector<int> pe;     int n;     int st, fin;     T flow;     C cost;     mcmf(int _n, int _st, int _fin) : n(_n), st(_st), fin(_fin) {       assert(0 <= st && st < n && 0 <= fin && fin < n && st != fin);       g.resize(n);       d.resize(n);       in_queue.resize(n);       pe.resize(n);       flow = 0;       cost = 0;     }     void clear_flow() {       for (const edge &e : edges) {         e.f = 0;       }       flow = 0;     }     void add(int from, int to, T forward_cap, T backward_cap, C cost) {       assert(0 <= from && from < n && 0 <= to && to < n);       g[from].push_back((int)edges.size());       edges.push_back({from, to, forward_cap, 0, cost});       g[to].push_back((int)edges.size());       edges.push_back({to, from, backward_cap, 0, -cost});     }     bool expath() {       fill(d.begin(), d.end(), numeric_limits<C>::max());       q.clear();       q.push_back(st);       d[st] = 0;       in_queue[st] = true;       int beg = 0;       bool found = false;       while (beg < (int)q.size()) {         int i = q[beg++];         if (i == fin) {           found = true;         }         in_queue[i] = false;         for (int id : g[i]) {           const edge &e = edges[id];           if (e.c - e.f > eps && d[i] + e.cost < d[e.to]) {             d[e.to] = d[i] + e.cost;             pe[e.to] = id;             if (!in_queue[e.to]) {               q.push_back(e.to);               in_queue[e.to] = true;             }           }         }       }       if (d[fin] >= 0) found = 0;       if (found) {         T push = numeric_limits<T>::max();         int v = fin;         while (v != st) {           const edge &e = edges[pe[v]];           push = min(push, e.c - e.f);           v = e.from;         }         v = fin;         while (v != st) {           edge &e = edges[pe[v]];           e.f += push;           edge &back = edges[pe[v] ^ 1];           back.f -= push;           v = e.from;         }         flow += push;         cost += push * d[fin];       }       return found;     }     pair<T, C> max_flow_min_cost() {       while (expath()) {       }       return make_pair(flow, cost);     }   };   const int MG1 = 1e5;   int n1, n2, m, r, b;   string s1, s2;   int eu[200], ev[200], er[200];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n1 >> n2 >> m >> r >> b >> s1 >> s2;     mcmf<int, int> a(n1 + n2 + 2, n1 + n2, n1 + n2 + 1);     memset(er, -1, sizeof(er));     for (int i = 0, j = 0; i < m; ++i) {       cin >> eu[i] >> ev[i], --eu[i], --ev[i];       if (s1[eu[i]] ==  U  && s2[ev[i]] ==  U ) continue;       if (s1[eu[i]] ==  U  && s2[ev[i]] ==  R ) {         a.add(n1 + n2, n1 + ev[i], 1, 0, r);         er[i] = j++;         continue;       }       if (s1[eu[i]] ==  U  && s2[ev[i]] ==  B ) {         a.add(n1 + ev[i], n1 + n2 + 1, 1, 0, b);         er[i] = j++;         continue;       }       if (s1[eu[i]] ==  R  && s2[ev[i]] ==  U ) {         a.add(eu[i], n1 + n2 + 1, 1, 0, r);         er[i] = j++;         continue;       }       if (s1[eu[i]] ==  B  && s2[ev[i]] ==  U ) {         a.add(n1 + n2, eu[i], 1, 0, b);         er[i] = j++;         continue;       }       a.add(eu[i], n1 + ev[i], 1, 0, r);       a.add(n1 + ev[i], eu[i], 1, 0, b);       er[i] = j;       j += 2;     }     int tmg = 0;     for (int i = 0; i < n1; ++i) {       if (s1[i] ==  R ) {         a.add(n1 + n2, i, 1, 0, -MG1);         a.add(n1 + n2, i, 200, 0, 0);         tmg -= MG1;       } else if (s1[i] ==  B ) {         a.add(i, n1 + n2 + 1, 1, 0, -MG1);         a.add(i, n1 + n2 + 1, 200, 0, 0);         tmg -= MG1;       }     }     for (int i = 0; i < n2; ++i) {       if (s2[i] ==  R ) {         a.add(n1 + i, n1 + n2 + 1, 1, 0, -MG1);         a.add(n1 + i, n1 + n2 + 1, 200, 0, 0);         tmg -= MG1;       } else if (s2[i] ==  B ) {         a.add(n1 + n2, n1 + i, 1, 0, -MG1);         a.add(n1 + n2, n1 + i, 200, 0, 0);         tmg -= MG1;       }     }     pair<int, int> p = a.max_flow_min_cost();     int cost = p.second - tmg;     if (cost >= MG1) {       cout << -1;       return 0;     }     cout << cost <<   n ;     for (int i = 0; i < m; ++i) {       if (s1[eu[i]] ==  U  && s2[ev[i]] ==  U ) {         cout <<  U ;         continue;       }       if (s1[eu[i]] ==  U  && s2[ev[i]] ==  R ) {         if (a.edges[2 * er[i]].f)           cout <<  R ;         else           cout <<  U ;         continue;       }       if (s1[eu[i]] ==  U  && s2[ev[i]] ==  B ) {         if (a.edges[2 * er[i]].f)           cout <<  B ;         else           cout <<  U ;         continue;       }       if (s1[eu[i]] ==  R  && s2[ev[i]] ==  U ) {         if (a.edges[2 * er[i]].f)           cout <<  R ;         else           cout <<  U ;         continue;       }       if (s1[eu[i]] ==  B  && s2[ev[i]] ==  U ) {         if (a.edges[2 * er[i]].f)           cout <<  B ;         else           cout <<  U ;         continue;       }       if (a.edges[2 * er[i]].f)         cout <<  R ;       else if (a.edges[2 * (er[i] + 1)].f)         cout <<  B ;       else         cout <<  U ;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2,unroll-loops )   using namespace std;   const int inf = 1000000010;   const long long INF = 10000000000000010LL;   const int mod = 1000000007;   const int MAXN = 300010, LOG = 20;   int n, m, k, u, v, x, y, t, a, b, ans;   int par[MAXN], h[MAXN], leaf[MAXN];   vector<int> G[MAXN];   void dfs(int node) {     h[node] = h[par[node]] + 1;     leaf[node] = 1;     for (int v : G[node])       if (!h[v]) {         par[v] = node;         dfs(v);         leaf[node] = 0;       }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     while (m--) {       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     dfs(1);     for (int v = 1; v <= n; v++)       if (h[v] * k >= n) {         cout <<  PATH   << h[v] <<   n ;         while (v) {           cout << v <<    ;           v = par[v];         }         return 0;       }     cout <<  CYCLES n ;     for (int v = 2; v <= n && k; v++)       if (leaf[v]) {         k--;         int done = 0, x = 0, y = 0;         for (int u : G[v])           if (u != par[v]) {             if ((h[v] - h[u] + 1) % 3) {               cout << h[v] - h[u] + 1 <<   n ;               x = v;               while (1) {                 cout << x <<    ;                 if (x == u) break;                 x = par[x];               }               cout <<   n ;               done = 1;               break;             }             if (x)               y = u;             else               x = u;           }         if (done) continue;         assert(x && y);         cerr <<  {               <<  x               <<  ,                <<  y               <<  } = {  << (x) <<  ,   << (y) <<  }  << endl;         if (h[x] < h[y]) swap(x, y);         cout << h[x] - h[y] + 2 <<   n ;         while (1) {           cout << x <<    ;           if (x == y) break;           x = par[x];         }         cout << v <<   n ;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 1 << 30;   int ds[500500], par[500500], parEdge[500500], depth[500500], anc[500500],       ans[500500];   vector<pair<int, int>> a[500500];   int get(int ds[], int x) { return x == ds[x] ? x : ds[x] = get(ds, ds[x]); }   void dfs(int x) {     for (auto [y, id] : a[x])       if (y != par[x]) {         par[y] = x;         parEdge[y] = id;         depth[y] = depth[x] + 1;         dfs(y);       }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, k, m;     cin >> n >> k >> m;     for (int i = 1; i <= n; i++) ds[i] = i;     for (int i = 0; i < k; i++) {       int x, y;       cin >> x >> y;       a[x].push_back({y, i});       a[y].push_back({x, i});       ds[get(ds, x)] = get(ds, y);       ans[i] = oo;     }     vector<tuple<int, int, int>> unusedEdges;     for (int i = 0; i < m; i++) {       int x, y, z;       cin >> x >> y >> z;       int dx = get(ds, x), dy = get(ds, y);       if (dx == dy)         unusedEdges.push_back({x, y, z});       else {         ds[dx] = dy;         a[x].push_back({y, -1});         a[y].push_back({x, -1});       }     }     dfs(1);     for (int i = 1; i <= n; i++) anc[i] = i;     for (auto [x, y, z] : unusedEdges)       while (1) {         x = get(anc, x);         y = get(anc, y);         if (x == y) break;         int dx = depth[x], dy = depth[y];         if (dx >= dy) {           if (parEdge[x] >= 0 && ans[parEdge[x]] == oo) ans[parEdge[x]] = z;           x = anc[x] = par[x];         }         if (dy >= dx) {           if (parEdge[y] >= 0 && ans[parEdge[y]] == oo) ans[parEdge[y]] = z;           y = anc[y] = par[y];         }       }     long long sum = 0;     for (int i = 0; i < k; i++)       if (ans[i] < oo)         sum += ans[i];       else {         cout << -1 << endl;         return 0;       }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 112345;   vector<int> v[N];   int read() {     int x;     scanf( %d , &x);     return x;   }   int cnt[N];   bool used[N];   bool t[N];   bool never[N];   int main() {     int n, m, i, j, x, y;     n = read();     for (i = 2; i <= n; i++) {       x = read();       y = read();       v[x].push_back(y);       cnt[x]++;       cnt[y]++;       v[y].push_back(x);     }     queue<int> q;     for (int i = 1; i <= n; i++) {       if (cnt[i] == 1) {         q.push(i);         used[i] = 1;       }     }     while (!q.empty()) {       int x = q.front();       q.pop();       for (int i = 0; i < v[x].size(); i++) {         int to = v[x][i];         if (!used[to]) {           if (cnt[to] <= 2 && !t[x] && !never[to]) {             used[to] = 1;             q.push(to);           } else if (cnt[to] == 3 && !t[x] && !never[to]) {             t[to] = 1;           } else {             never[to] = 1;           }           cnt[to]--;         }       }     }     for (i = 1; i <= n; i++) {       if (cnt[i] >= 3) {         puts( no );         return 0;       }     }     puts( yes );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) a.push_back(a[i]);     int Max = 0, cur = 0;     for (int i = 0; i < 2 * n; ++i) {       if (a[i] == 1)         cur++;       else {         Max = max(Max, cur);         cur = 0;       }     }     cout << Max;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, co;     int a[100019];     cin >> n >> co;     int count = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       count += a[i] / 10;       a[i] %= 10;     }     sort(a, a + n);     reverse(a, a + n);     for (int i = 0; i < n; i++) {       if (co >= 10 - a[i]) {         count++;         co -= (10 - a[i]);       }     }     cout << min(10 * n, count + co / 10) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   const double pi = acos(-1);   void print() { cout <<   n ; }   template <typename T, typename... Params>   void print(const T& var1, const Params&... var2) {     cout << var1 <<    ;     print(var2...);   }   template <typename T>   void pr(const T& v) {     for (auto c : v) cout << c <<    ;     cout <<   n ;   }   long long int power(long long int a, long long int b, long long int p) {     if (b == 0) return 1;     long long int c = power(a, b / 2, p);     if (b % 2 == 0)       return (c * c) % p;     else       return (((c * c) % p) * a) % p;   }   long long int invmod(long long int n, long long int p) {     return power(n, p - 2, p);   }   bool isPrime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   const int maxN = 100001;   int tree[4 * maxN][2];   int A[100000], n;   void build(int node, int start, int end) {     if (start == end)       tree[node][0] = A[start], tree[node][1] = start;     else {       int mid = (start + end) / 2;       build(2 * node, start, mid);       build(2 * node + 1, mid + 1, end);       tree[node][0] = min(tree[2 * node][0], tree[2 * node + 1][0]);       if (tree[2 * node][0] < tree[2 * node + 1][0])         tree[node][1] = tree[2 * node][1];       else         tree[node][1] = tree[2 * node + 1][1];     }   }   pair<int, int> query(int node, int start, int end, int l, int r) {     if (r < start or end < l) {       return {1e9, 1e9};     }     if (l <= start and end <= r) {       return make_pair(tree[node][0], tree[node][1]);     }     int mid = (start + end) / 2;     pair<int, int> p1 = query(2 * node, start, mid, l, r);     pair<int, int> p2 = query(2 * node + 1, mid + 1, end, l, r);     if (p1.first < p2.first)       return p1;     else       return p2;   }   vector<pair<int, int> > v;   int count(int l, int r, int val) {     if (l > r) return 0;     pair<int, int> q = query(1, 0, n - 1, l, r);     int mini = q.first;     int idx = q.second;     mini -= val;     for (long long int i = 0; i < mini; i++) v.push_back({l + 1, r + 1});     return (mini + count(l, idx - 1, val + mini) + count(idx + 1, r, val + mini));   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (long long int i = 0; i < n; i++) cin >> A[i];     build(1, 0, n - 1);     print(count(0, n - 1, 0));     for (long long int i = 0; i < ((long long int)(v).size()); i++)       print(v[i].first, v[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const long long inf = 9e18;   struct NODE {     long long v, id;     bool operator<(const NODE& other) const {       return v > other.v || (v == other.v && id > other.id);     }   } node[N];   long long a[N], b[N];   long long n;   long long f(long long x, long long y) { return x - 3LL * y * y + 3LL * y - 1; }   long long find(long long v, long long x) {     long long l, r, mid;     l = 0;     r = x + 1;     while (r - l > 1) {       mid = (l + r) >> 1;       if (f(x, mid) >= v)         l = mid;       else         r = mid;     }     return l;   }   long long solve(long long x) {     long long tot = 0, i;     for (i = 1; i <= n; i++) {       tot += (b[i] = find(x, a[i]));     }     return tot;   }   int main() {     long long k, i, cnt = 0;     long long l = inf, r = -inf, mid, tot;     cin >> n >> k;     for (i = 1; i <= n; i++) {       cin >> a[i];       l = min(l, f(a[i], a[i]));       r = max(r, f(a[i], 1));     }     while (r - l > 1) {       mid = (l + r) >> 1;       if (solve(mid) <= k)         r = mid;       else         l = mid;     }     tot = solve(r);     for (i = 1; i <= n; i++)       if (b[i] < a[i]) node[++cnt].v = f(a[i], b[i] + 1), node[cnt].id = i;     sort(node + 1, node + cnt + 1);     for (i = 1; i <= cnt; i++) {       if (tot == k) break;       b[node[i].id]++;       tot++;     }     for (i = 1; i <= n; i++) cout << b[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 10 + 1e5;   const int MOD = 1e9 + 7;   int n, m;   int a[MAXN], c[MAXN];   void Inout() {     freopen(          ABC           .inp ,          r , stdin);     freopen(          ABC           .out ,          w , stdout);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     long long ans = 0;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       c[i] = max(c[i - 1], a[i] + 1);     }     for (int i = n - 1; i; --i) c[i] = max(c[i], c[i + 1] - 1);     for (int i = 1; i <= n; ++i) {       ans += c[i] - a[i] - 1;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const long long mod = 1e9 + 7;   const long long N = 2e5 + 10;   inline long long add(long long x, long long y) {     x += y;     if (x >= mod) x -= mod;     return x;   }   inline long long mul(long long x, long long y) {     x = (1LL * x * y) % mod;     return x;   }   long long first[N];   long long lvl[N];   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long n, k;     cin >> n >> k;     long long maxv = 0;     vector<long long> v(n);     for (long long i = 0; i <= n - 1; ++i) {       cin >> v[i];       first[v[i]]++;       maxv = max(maxv, v[i]);     }     long long ans = INF;     for (long long i = 0; i <= maxv; ++i) {       queue<long long> q;       q.push(i);       lvl[i] = 0;       long long val = 0;       long long cc = 0;       while (!q.empty()) {         long long x = q.front();         q.pop();         if (cc + first[x] > k) {           val += (k - cc) * lvl[x];           cc = k;           break;         } else {           cc += first[x];           val += first[x] * lvl[x];           if (i == 0) {           }         }         if (cc >= k) break;         if (2 * x <= 2e5 and x > 0) {           q.push(2 * x);           lvl[2 * x] = 1 + lvl[x];         }         if (2 * x + 1 <= 2e5) {           q.push(2 * x + 1);           lvl[2 * x + 1] = 1 + lvl[x];         }       }       if (cc < k) val = INF;       ans = min(ans, val);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int A[1000000];   map<char, int> M;   int main() {     for (int i = 0; i <= 63; i++)       for (int j = 0; j <= 63; j++) A[i & j]++;     for (int i = 0; i <= 9; i++) M[i +  0 ] = i;     for (int i = 0; i < 26; i++) M[i +  A ] = i + 10;     for (int i = 0; i < 26; i++) M[i +  a ] = i + 36;     M[ _ ] = 63, M[ - ] = 62;     string s;     cin >> s;     long long ans = 1;     long long mod = 1e9 + 7;     for (int i = 0; i < s.size(); i++) ans = ans * A[M[s[i]]] % mod;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int maxn = 1000 + 10;   int n, maxLevel;   vector<int> edge[maxn];   vector<int> gu;   int dis[maxn];   vector<int> level[maxn];   int fa[maxn];   bool used[maxn];   void print(int a[], int n, int st = 0) {     for (int i = 0; i < n; i++) {       if (i != 0) printf(   );       printf( %d , a[i + st]);     }     printf(  n );   }   void init() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) edge[i].clear();     for (int i = 0; i < n - 1; i++) {       int x, y;       scanf( %d%d , &x, &y);       edge[x].push_back(y);       edge[y].push_back(x);     }   }   void guess(vector<int> a, int &u, int &value) {     printf( ? %d , int(a.size()));     for (int i = 0; i < a.size(); i++) printf(  %d , a[i]);     printf(  n );     fflush(stdout);     scanf( %d%d , &u, &value);   }   void answer(int u1, int u2) {     char s[20];     printf( ! %d %d n , u1, u2);     fflush(stdout);     scanf( %s , s);   }   void dfs(int u) {     for (int i = 0; i < edge[u].size(); i++) {       int v = edge[u][i];       if (dis[v] == -1) {         dis[v] = dis[u] + 1;         fa[v] = u;         maxLevel = max(maxLevel, dis[v]);         level[dis[v]].push_back(v);         dfs(v);       }     }   }   void doit() {     int r, len, k1, k2;     gu.clear();     for (int i = 1; i <= n; i++) gu.push_back(i);     guess(gu, r, len);     for (int i = 0; i <= n; i++) level[i].clear();     for (int i = 0; i <= n; i++) dis[i] = -1;     dis[r] = 0;     level[0].push_back(r);     maxLevel = 0;     dfs(r);     int left = (len + 1) / 2, right = min(len, maxLevel), mid, ans, u, d;     while (left <= right) {       mid = (left + right) >> 1;       guess(level[mid], u, d);       if (d <= len) {         ans = mid;         k1 = u;         left = mid + 1;       } else {         right = mid - 1;       }     }     if (ans == len) {       answer(r, k1);       return;     }     u = k1;     for (int i = 1; i <= n; i++) used[i] = false;     while (u != r) {       used[u] = true;       u = fa[u];     }     gu.clear();     for (int i = 0; i < level[len - ans].size(); i++) {       if (!used[level[len - ans][i]]) {         gu.push_back(level[len - ans][i]);       }     }     guess(gu, k2, d);     answer(k1, k2);   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       init();       doit();     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   struct event {     long long x, type;     event() {}     event(long long _x, long long _type) {       x = _x;       type = _type;     }   };   string a, b;   long long n;   long double ans = 0;   vector<long long> v[500];   vector<event> d[500];   bool operator<(const event& a, const event& b) {     return a.x < b.x || (a.x == b.x && a.type < b.type);   }   int main() {     cin >> n;     cin >> a >> b;     for (long long i = 0; i < n; i++) {       v[a[i]].push_back(i);       d[a[i]].push_back(event(i, 0));       d[b[i]].push_back(event(i, 1));     }     long long all = 0;     for (long long i = 1; i <= n; i++) {       all += i * i;     }     for (long long i = 0; i < 500; i++) {       sort(d[i].begin(), d[i].end());       long long x = 0, y = 0;       for (long long j = 0; j < d[i].size(); j++) {         event q = d[i][j];         y += (n - q.x) * (1 - q.type);       }       for (long long j = 0; j < d[i].size(); j++) {         event q = d[i][j];         if (!q.type) {           y -= n - q.x;           x += q.x + 1;         } else {           ans += (long double)((q.x + 1) * y) / (long double)all;           ans += (long double)((n - q.x) * x) / (long double)all;         }       }     }     cout.precision(18);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:300000000 )   const long double eps = 1e-20;   const long double pi = acos(-1.0);   const long long inf = 1000 * 1000 * 1000 * 1000 * 1000 * 1000;   const long long base = 1000 * 1000 * 1000 + 7;   using namespace std;   int n, m, z, a[111111], x, y;   bool fl;   set<int> g[111111];   int main() {     ios_base ::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < (m); i++) {       cin >> x >> y;       x;       y;       g[x].insert(y);       g[y].insert(x);     }     for (int i = 0; i < (n); i++) a[i] = i + 1;     if (n < 9) {       do {         z = 0;         fl = true;         for (int i = 0; i < (n); i++) {           if (z == m) break;           if (g[a[i]].find(a[(i + 1) % n]) != g[a[i]].end()) {             fl = false;             break;           }           if (!fl) break;           z++;         }         if (fl && z == m) {           z = 0;           for (int i = 0; i < (n); i++) {             if (z == m) return 0;             cout << a[i] <<     << a[(i + 1) % n] << endl;             z++;           }           return 0;         }       } while (next_permutation(a, a + n));       cout <<  -1 ;       return 0;     }     for (int test = 0; test < (666); test++) {       random_shuffle(a, a + n);       z = 0;       fl = true;       for (int i = 0; i < (n); i++) {         if (z == m) break;         if (g[a[i]].find(a[(i + 1) % n]) != g[a[i]].end()) {           fl = false;           break;         }         if (!fl) break;         z++;       }       if (fl && z == m) {         z = 0;         for (int i = 0; i < (n); i++) {           if (z == m) return 0;           cout << a[i] <<     << a[(i + 1) % n] << endl;           z++;         }         return 0;       }     }     cout <<  -1 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (cin >> n) {       vector<long long> nums(n);       for (int i = 0; i < n; i++) {         cin >> nums[i];       }       bool hasAns = false;       for (int i = 31; i >= 0; i--) {         long long num = 1;         num = num << i;         bool hasRes = false;         long long res = 0;         int count = 0;         for (int j = 0; j < nums.size(); j++) {           if (nums[j] & num) {             if (hasRes) {               res &= nums[j];             } else {               res = nums[j];             }             count++;             hasRes = true;           }         }         if (count == 0 || (res % num)) {           continue;         }         hasAns = true;         cout << count << endl;         for (int j = 0; j < nums.size(); j++) {           if (nums[j] & num) {             cout << nums[j] <<    ;           }         }         cout << endl;         break;       }       if (!hasAns) {         cout << nums.size() << endl;         for (int j = 0; j < nums.size(); j++) {           cout << nums[j] <<    ;         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int add = 1e9;   const int INF = 2e9;   const long long mod = 1e9 + 7;   const long long mod1 = 3e9 + 19;   const long long mod2 = 3e9 - 71;   const long long longINF = 3e18;   const long long ph = 31;   const long double pi = acos(-1);   const long double eps = 1e-8;   const int M = 1 << 18;   int n, a[105], res;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     if (!(n & 1)) {       cout <<  No ;       return 0;     }     for (int i = 0; i < n; i++) cin >> a[i];     if (a[0] % 2 == 0 || a[n - 1] % 2 == 0) {       cout <<  No ;       return 0;     }     cout <<  Yes ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int tu[200], a[200];     int f[200];     int n, m, k;     int min;     int i, j;     scanf( %d %d %d , &n, &m, &k);     for (i = 0; i < m; i++) {       scanf( %d , &f[i]);       a[i] = 0;     }     for (i = 0; i < k; i++) scanf( %d , &tu[i]);     for (i = 0; i < m; i++)       for (j = 0; j < k; j++)         if (tu[j] % f[i] == 0) a[i] += 1;     min = 1000;     for (i = 0; i < m; i++) {       if (min > a[i]) min = a[i];     }     j = 0;     for (i = 0; i < m; i++) {       if (a[i] == min) tu[j++] = i;     }     for (i = 0; i < j; i++) {       for (k = i + 1; k < j; k++) {         if (tu[i] > tu[k]) {           min = tu[k];           tu[k] = tu[i];           tu[i] = min;         }       }     }     printf( %d n , j);     for (i = 0; i < j; i++) printf( %d  , tu[i] + 1);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       string s;       cin >> s;       string word =   ;       for (auto x : s) {         if (x ==  _ ) {           word =   ;         } else {           word = word + x;         }       }       if (word.substr(word.length() - 2) ==  po )         cout <<  FILIPINO n ;       else if (word.substr(word.length() - 4) ==  desu  ||                word.substr(word.length() - 4) ==  masu )         cout <<  JAPANESE n ;       else if (word.substr(word.length() - 5) ==  mnida )         cout <<  KOREAN n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     t = 1;     while (t--) {       long long int n;       cin >> n;       long long int x, y, i;       long long int suma = 0, sumb = 0;       bool found = false;       vector<char> v;       for (i = 0; i < n; i++) {         cin >> x >> y;         suma += x;         if (abs(suma - sumb) <= 500 && !found)           v.push_back( A );         else {           suma -= x;           sumb += y;           if (abs(suma - sumb) <= 500 && !found)             v.push_back( G );           else             found = true;         }       }       if (found)         cout <<  -1 n ;       else {         for (i = 0; i < v.size(); i++) cout << v[i];         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int MOD = 1e9 + 7;   const int MAXN = 1e6 + 3;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long power(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = res * x;       y = y >> 1;       x = x * x;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<long long> a(n + 1);       set<long long> st;       for (long long i = 1; i <= (n); ++i) {         cin >> a[i];         st.insert(a[i]);       }       if (st.size() == 1)         cout << n <<   n ;       else         cout << 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 20;   const int MOD = 1e9 + 7;   const int INF = 0x3f3f3f3f;   const long long LLINF = 0x3f3f3f3f3f3f3f3f;   const double PI = acos(-1.0);   const double RATE = 0.995;   const double eps = 1e-4;   int arr[MAXN];   signed main() {     int n;     long long k;     scanf( %d%lld , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %d , &arr[i]);     }     sort(arr + 1, arr + 1 + n);     long long ans = arr[n] - arr[1];     for (int i = 1; i < (n + 1) / 2; ++i) {       long long t =           min(1ll * (arr[n - i + 1] - arr[n - i] + arr[i + 1] - arr[i]), k / i);       ans -= t;       k -= i * t;     }     if (n % 2 == 0) {       long long t = min(1ll * (arr[n / 2 + 1] - arr[n / 2]), k / (n / 2));       ans -= t;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxN = (int)1e5 + 5;   int n, ar[mxN];   void solve() {     ar[0] = 0;     cin >> n;     for (int i = 1; i <= n; i++) cin >> ar[i];     int mx = 0;     for (int i = 1; i <= n; i++) {       mx = max(mx, ar[i]);     }     cout << mx;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t = 1, i = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, h[300005], tot;   map<pair<int, int>, int> c;   struct edge {     int to, nxt, val;   } e[300005 << 1];   void add(int x, int y, int z) {     e[++tot].nxt = h[x];     h[x] = tot;     e[tot].to = y;     e[tot].val = z;   }   priority_queue<pair<long long, int> > q;   vector<int> a[300005];   long long d[300005];   int v[300005], fa[300005];   void dij() {     memset(d, 0x3f, sizeof(d));     d[1] = 0;     q.push(make_pair(0, 1));     while (!q.empty()) {       int x = q.top().second;       q.pop();       v[x] = 1;       for (int i = h[x]; i; i = e[i].nxt)         if (d[x] + e[i].val < d[e[i].to]) {           d[e[i].to] = d[x] + e[i].val;           fa[e[i].to] = x;           q.push(make_pair(-d[e[i].to], e[i].to));         }       while (!q.empty() && v[q.top().second]) q.pop();     }     for (int i = 2; i <= n; i++) a[fa[i]].push_back(i);   }   void dfs(int x) {     if (k && x != 1) k--, printf( %d  , c[make_pair(fa[x], x)]);     if (!k) return;     for (int i = 0; i < (int)a[x].size(); i++) dfs(a[x][i]);   }   int main() {     scanf( %d%d%d , &n, &m, &k);     k = min(k, n - 1);     for (int i = 1; i <= m; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       add(x, y, z);       add(y, x, z);       c[make_pair(x, y)] = c[make_pair(y, x)] = i;     }     dij();     printf( %d n , k);     dfs(1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int count = 0;     int n, d;     cin >> n >> d;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j) continue;         if (abs(arr[i] - arr[j]) <= d) count++;       }     }     cout << count << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long x = 0;   bool vis[100010] = {false};   vector<int> adj[100010];   long long pow(long long a, long long b, long long m) {     stack<int> k;     int j = 128;     int l = 1;     int an = 1;     while (b) {       if (b >= j) {         k.push(j);         b -= j;       }       j /= 2;     }     while (!k.empty()) {       if (k.top() == l) {         an = (an * a) % mod;         k.pop();       }       a = (a * a) % mod;       l *= 2;     }     return an;   }   long long gcd(long a, long b) {     return b == 0 ? (a < 0 ? -a : a) : gcd(b, a % b);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     int n, m, k;     cin >> n >> m >> k;     int ma = 0, mi = 10000;     for (int i = 0; i < n; ++i) {       int t;       cin >> t;       if (t < mi) {         mi = t;       }     }     for (int i = 0; i < m; ++i) {       int t;       cin >> t;       if (t > ma) {         ma = t;       }     }     if (ma > mi) {       int j = k / mi;       k -= (j)*mi;       k += j * ma;     }     cout << k << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using Int = long long;   constexpr static int mod = 1e9 + 7;   constexpr static int inf = (1 << 30) - 1;   constexpr static Int infll = (1LL << 61) - 1;   int Competitive_Programming =       (ios_base::sync_with_stdio(false), cin.tie(nullptr),        cout << fixed << setprecision(15), 0);   #pragma GCC target( avx2 )   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   template <typename A, typename B>   string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);   string to_string(const string &s) { return     + s +    ; }   string to_string(const char *s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (int i = 0; i < static_cast<int>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto &x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   int func(string &s) {     int ret = 0, ctr = 0, mi = inf;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  ( )         ctr++;       else         ctr--;       mi = min(ctr, mi);     }     ctr = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  ( )         ctr++;       else         ctr--;       if (ctr == mi) ret++;     }     return ret;   }   int main() {     int N;     cin >> N;     string s;     cin >> s;     int op = 0, ed = 0;     for (int i = 0; i < N; i++) {       if (s[i] ==  ( )         op++;       else         ed++;     }     if (op != ed) {       cout << 0 <<   n ;       cout << 1 <<     << 1 <<   n ;       return 0;     }     int ans = 0, l = 1, r = 1;     for (int i = 0; i < N; i++) {       for (int j = i + 1; j < N; j++) {         swap(s[i], s[j]);         int cnt = func(s);         if (cnt > ans) {           ans = cnt, l = i + 1, r = j + 1;         }         swap(s[i], s[j]);       }     }     cout << ans <<   n ;     cout << l <<     << r <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD;   inline void modulas(long long a) { MOD = a; }   inline void normal(long long &a) {     a %= MOD;     (a < 0) && (a += MOD);   }   inline long long modMul(long long a, long long b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     return (a * b) % MOD;   }   inline long long modAdd(long long a, long long b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     return (a + b) % MOD;   }   inline long long modSub(long long a, long long b) {     a %= MOD, b %= MOD;     normal(a), normal(b);     a -= b;     normal(a);     return a;   }   inline long long modPow(long long b, long long p) {     long long r = 1;     while (p) {       if (p & 1) r = modMul(r, b);       b = modMul(b, b);       p >>= 1;     }     return r;   }   inline long long modInverse(long long a) { return modPow(a, MOD - 2); }   inline long long modDiv(long long a, long long b) {     return modMul(a, modInverse(b));   }   vector<bool> isPrime(10000010, true);   inline void seivePrime(long long L, long long R) {     long long lim = sqrt(R);     for (long long i = 2; i <= lim; ++i) {       for (long long j = max(i * i, (L + i - 1) / i * i); j <= R; j += i)         isPrime[j - L] = false;     }     if (L == 1) isPrime[0] = false;   }   inline long long chckPrime(long long L, long long prme) {     return isPrime[prme - L];   }   inline long long cntPrime(long long L, long long R) {     return count(isPrime.begin(), isPrime.begin() + R - L + 1, true);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t = 1;     cin >> t;     while (t--) {       int n;       cin >> n;       int ar[n];       for (int i = 0; i < n; i++) cin >> ar[i];       int s = 0, sum = 0;       for (int i = 0; i < n; i++) {         if (ar[i] == 0) {           ar[i] = 1;           s++;         }         sum += ar[i];       }       if (sum == 0) {         sort(ar, ar + n);         if (ar[n - 1] > 0)           cout << s + 1 <<   n ;         else if (ar[0] == -1)           cout << s + 2 <<   n ;         else           cout << s + 1 <<   n ;       } else         cout << s <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool solve() {     int n;     bool ret = false;     int m = 0;     scanf( %d , &n);     int a;     scanf( %d , &a);     while ((a & 1) == 0) a >>= 1;     while (a % 3 == 0) a /= 3;     m = a;     for (int i = 1; i < n; i++) {       int a;       scanf( %d , &a);       while ((a & 1) == 0) a >>= 1;       while (a % 3 == 0) a /= 3;       if (m != a) return false;     }     return true;   }   int main() {     if (solve())       puts( Yes );     else       puts( No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int INF = (int)1e9;   const long long LINF = (long long)1e18;   const long double PI = acos((long double)-1);   const long double EPS = 1e-9;   inline long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline long long fpow(long long n, long long k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   template <class T>   inline int chkmin(T& a, const T& val) {     return val < a ? a = val, 1 : 0;   }   template <class T>   inline int chkmax(T& a, const T& val) {     return a < val ? a = val, 1 : 0;   }   template <class T>   inline T isqrt(T k) {     T r = sqrt(k) + 1;     while (r * r > k) r--;     return r;   }   template <class T>   inline T icbrt(T k) {     T r = cbrt(k) + 1;     while (r * r * r > k) r--;     return r;   }   inline void addmod(int& a, int val, int p = MOD) {     if ((a = (a + val)) >= p) a -= p;   }   inline void submod(int& a, int val, int p = MOD) {     if ((a = (a - val)) < 0) a += p;   }   inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }   inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }   inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }   inline int sign(long double x, long double y) { return sign(x - y); }   int p = (int)1e9 + 7;   template <class T, class mul, class dvd>   struct FiniteField {     T x;     template <class G>     T normalize(G x) {       if (x >= 0 && x < p) return x;       x %= p;       if (x < 0)         x += p;       else if (x >= p)         x -= p;       return x;     }     FiniteField() : x(0) {}     template <class G>     FiniteField(const G& y) {       x = normalize(y);     }     FiniteField(const FiniteField& rhs) : x(rhs.x) {}     template <class G>     FiniteField operator()(const G& y) {       x = normalize(y);       return *this;     }     template <class G>     FiniteField operator=(const G& y) {       x = normalize(y);       return *this;     }     int operator==(const FiniteField& rhs) const { return x == rhs.x; }     int operator!=(const FiniteField& rhs) const { return x != rhs.x; }     int operator<(const FiniteField& rhs) const { return x < rhs.x; }     FiniteField operator++(int) {       FiniteField res = *this;       if ((++x) >= p) x -= p;       return res;     }     FiniteField operator++() {       if ((++x) >= p) x -= p;       return *this;     }     FiniteField operator--(int) {       FiniteField res = *this;       if ((--x) < 0) x += p;       return res;     }     FiniteField operator--() {       if ((--x) < 0) x += p;       return *this;     }     template <class G>     FiniteField operator+=(const G& y) {       if ((x += normalize(y)) >= p) x -= p;       return *this;     }     template <class G>     FiniteField operator-=(const G& y) {       if ((x -= normalize(y)) < 0) x += p;       return *this;     }     FiniteField operator+=(const FiniteField& rhs) {       if ((x += rhs.x) >= p) x -= p;       return *this;     }     FiniteField operator-=(const FiniteField& rhs) {       if ((x -= rhs.x) < 0) x += p;       return *this;     }     FiniteField operator+(const FiniteField& rhs) const {       FiniteField res;       res.x = x + rhs.x;       if (res.x >= p) res.x -= p;       return res;     }     FiniteField operator-(const FiniteField& rhs) const {       FiniteField res;       res.x = x - rhs.x;       if (res.x < 0) res.x += p;       return res;     }     template <class G>     FiniteField operator*=(const G& y) {       x = mul()(x, normalize(y), p);       return *this;     }     template <class G>     FiniteField operator/=(const G& y) {       x = dvd()(x, normalize(y), p);       return *this;     }     template <class G>     FiniteField operator*(const G& y) const {       FiniteField res;       res.x = mul()(x, res.normalize(y), p);       return res;     }     template <class G>     FiniteField operator/(const G& y) const {       FiniteField res;       res.x = dvd()(x, res.normalize(y), p);       return res;     }     FiniteField operator*(const FiniteField& rhs) const {       FiniteField res;       res.x = mul()(x, rhs.x, p);       return res;     }     FiniteField operator/(const FiniteField& rhs) const {       FiniteField res;       res.x = dvd()(x, rhs.x, p);       return res;     }     template <class G>     friend FiniteField operator*(const G& y, const FiniteField& rhs) {       FiniteField res;       res.x = res.normalize(y);       return res * rhs;     }     template <class G>     friend FiniteField operator/(const G& y, const FiniteField& rhs) {       FiniteField res;       res.x = res.normalize(y);       return res / rhs;     }     template <class G>     FiniteField operator^=(G k) {       if (k == 0) {         x = 1;         return *this;       }       T t = x;       k--;       while (k > 0) {         if (k & 1) x = mul()(x, t, p);         t = mul()(t, t, p);         k >>= 1;       }       return *this;     }     template <class G>     FiniteField operator^(G k) const {       if (k == 0) return 1;       T r = x, t = x;       k--;       while (k > 0) {         if (k & 1) r = mul()(r, t, p);         t = mul()(t, t, p);         k >>= 1;       }       return r;     }     friend istream& operator>>(istream& is, FiniteField& rhs) {       is >> rhs.x;       return is;     }     friend ostream& operator<<(ostream& os, const FiniteField& rhs) {       os << rhs.x;       return os;     }   };   template <class T>   class mul {    public:     T operator()(const T& x, const T& y, const T& p) {       return (long long)x * y % p;     }   };   template <class T>   class dvd {    public:     T operator()(const T& x, const T& y, const T& p) {       pair<T, T> r = euclid(y, p);       return mul<T>()(x, (r.first % p + p) % p, p);     }       private:     pair<T, T> euclid(T a, T b) {       if (b == 0) return make_pair(1, 0);       pair<T, T> r = euclid(b, a % b);       return make_pair(r.second, r.first - a / b * r.second);     }   };   const int maxn = 100000 + 5;   int m, n;   FiniteField<int, mul<int>, dvd<int> > a[maxn];   map<FiniteField<int, mul<int>, dvd<int> >, int> hs;   void solve() {     cin >> m >> n;     p = m;     for (int i = (0); i < (n); i++) cin >> a[i];     if (n == 1) {       cout << a[0] <<     << 0 <<   n ;       return;     }     if (n == p) {       cout << 0 <<     << 1 <<   n ;       return;     }     FiniteField<int, mul<int>, dvd<int> > sum = 0, sqsum = 0;     for (int i = (0); i < (n); i++) sum += a[i], sqsum += a[i] * a[i], hs[a[i]];     for (int i = (0); i < (n); i++) {       FiniteField<int, mul<int>, dvd<int> > x = a[i];       FiniteField<int, mul<int>, dvd<int> > d = (sum / n - x) * 2 / (n - 1);       if (d == 0) continue;       if (sqsum !=           x * x * n + x * d * n * (n - 1) + d * d * (n - 1) * n * (2 * n - 1) / 6)         continue;       int ok = 1;       for (int j = (0); j < (n); j++) {         if (!hs.count(x + j * d)) {           ok = 0;           break;         }       }       if (ok) {         cout << x <<     << d <<   n ;         return;       }     }     cout << -1 <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     cin >> a >> b >> c;     int n, x;     cin >> n;     int i = 0;     while (n--) {       cin >> x;       if (x > b && x < c) i++;     }     cout << i;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T By(T x, T y, T P) {     T F1 = 0;     while (y) {       if (y & 1) {         F1 += x;         if (F1 < 0 || F1 >= P) F1 -= P;       }       x <<= 1;       if (x < 0 || x >= P) x -= P;       y >>= 1;     }     return F1;   }   template <class T>   T Mul(T x, T y, T P) {     T F1 = 1;     x %= P;     while (y) {       if (y & 1) {         F1 = By(F1, x, P);       }       x = By(x, x, P);       y >>= 1;     }     return F1;   }   template <class T>   T Gcd(T x, T y) {     if (y == 0) return x;     T z;     while (z = x % y) {       x = y, y = z;     }     return y;   }   struct EDGE {     int T;     EDGE *Nxt;   };   template <class T>   void UpdataMin(T &x, T y) {     if (y < x) {       x = y;     }   }   template <class T>   void UpdataMax(T &x, T y) {     if (x < y) {       x = y;     }   }   int F[100001];   int L, R, N, M, QN;   int main() {     cin >> N >> M;     QN = N;     for (int i = 1; i <= (N); ++i) {       cin >> F[i];     }     sort(F + 1, F + N + 1);     L = lower_bound(F + 1, F + N + 1, M) - F;     R = upper_bound(F + 1, F + N + 1, M) - F - 1;     while (L > (N + 1) / 2 || R < (N + 1) / 2) {       ++N;       ++R;     }     cout << N - QN << endl;     cin >> N;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18, minf = 1e18 * (-1);   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int k, b;     cin >> k >> b;     int xyr[k][2], xyb[b][2];     for (long long i = 0; i < k; i++) cin >> xyr[i][0] >> xyr[i][1];     for (long long i = 0; i < b; i++) cin >> xyb[i][0] >> xyb[i][1];     if (k != b)       cout <<  No ;     else       cout <<  Yes ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   const int N = 100100;   int n, a[N], q;   int main() {     int t;     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       set<int> se;       for (int i = 1; i <= n; i++) {         scanf( %d , a + i);         se.insert(a[i]);       }       printf( %d n , (int)se.size());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 2e9 + 10, MAXN = 1e5 + 10;   int seg[4][MAXN * 4];   int n, S, l;   void update(int ind) {     seg[1][ind] = min(seg[1][((ind)*2)], seg[1][(((ind)*2) + 1)]);     seg[2][ind] = max(seg[2][((ind)*2)], seg[2][(((ind)*2) + 1)]);     seg[3][ind] = min(seg[3][((ind)*2)], seg[3][(((ind)*2) + 1)]);   }   void add(int s, int e, int ind, int x, int val, int t) {     if (s > x or e <= x) return;     if (s + 1 == e) {       seg[t][ind] = val;       return;     }     int mid = (s + e) / 2;     add(s, mid, ((ind)*2), x, val, t);     add(mid, e, (((ind)*2) + 1), x, val, t);     update(ind);   }   int fin(int s, int e, int ind, int x, int y, int t) {     if (s >= y or e <= x) return (t == 1 or t == 3) ? inf : -inf;     if (s >= x and e <= y) return seg[t][ind];     int mid = (s + e) / 2;     if (t == 1 or t == 3)       return min(fin(s, mid, ((ind)*2), x, y, t),                  fin(mid, e, (((ind)*2) + 1), x, y, t));     return max(fin(s, mid, ((ind)*2), x, y, t),                fin(mid, e, (((ind)*2) + 1), x, y, t));   }   void show() {     for (int i = 0; i < n; i++)       cerr << fin(0, n, 1, i, i + 1, 1) <<     << fin(0, n, 1, i, i + 1, 2)            << endl;   }   int main() {     scanf( %d%d%d , &n, &S, &l);     fill(seg[1], seg[1] + MAXN * 4, inf);     fill(seg[3], seg[3] + MAXN * 4, inf);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       add(0, n, 1, i, x, 1);       add(0, n, 1, i, x, 2);     }     for (int i = 0; i < n; i++) {       int s = -1, e = i;       while (e - s > 1) {         int mid = (s + e) / 2;         if (fin(0, n, 1, mid, i + 1, 2) - fin(0, n, 1, mid, i + 1, 1) <= S)           e = mid;         else           s = mid;       }       if (e == 0 and i + 1 >= l) {         int res = 1;         add(0, n, 1, i, res, 3);         if (i == n - 1) {           printf( 1 n );           return 0;         }       } else if (i - e + 1 >= l) {         int res = fin(0, n, 1, e - 1, i - l + 1, 3);         res = min(res + 1, inf);         add(0, n, 1, i, res, 3);         if (i == n - 1) {           if (res == inf)             printf( -1 n );           else             printf( %d n , res);           return 0;         }       }     }     printf( -1 n );     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long int modExp(long long int base, long long int power) {     if (power == 0) {       return 1;     } else {       long long int cur = modExp(base, power / 2);       cur = cur * cur;       cur = cur % 1000000007;       if (power % 2 == 1) cur = cur * base;       cur = cur % 1000000007;       return cur;     }   }   void solve() {     long long int n, k, l, r, sall, sk;     cin >> n >> k >> l >> r >> sall >> sk;     vector<long long int> ans;     long long int temp = sk / k;     long long int num = sk - temp * k;     for (long long int i = 0; i < num; i++) {       ans.push_back(temp + 1);     }     for (long long int i = 0; i < k - num; i++) {       ans.push_back(temp);     }     if (n - k != 0) {       temp = (sall - sk) / (n - k);       num = (sall - sk) - (temp * (n - k));       for (long long int i = 0; i < num; i++) {         ans.push_back(temp + 1);       }       for (long long int i = 0; i < n - k - num; i++) {         ans.push_back(temp);       }     }     sort(ans.begin(), ans.end());     for (long long int i = 0; i < n; i++) {       cout << ans[i] <<    ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct subject {     long long a, b;     int c, r, s;     bool operator<(subject const &T) const { return c < T.c; }   };   int n, m, rex, rey, fx[55][55][105], fy[55][55][105];   long long rat, val, tmp, old, dp[55][55][105], ret;   subject a[55];   void trace(int x, int y, int z) {     if (y) trace(fx[x][y][z], y - 1, fy[x][y][z]);     printf( %d %I64d n , a[x].r, a[x].a + z);   }   int main() {     scanf( %d%d%I64d , &n, &m, &rat);     for (int i = 0; i < m; i++) {       scanf( %I64d%I64d%d , &a[i].a, &a[i].b, &a[i].c);       a[i].r = i + 1;       a[i].s = a[i].b - a[i].a;     }     sort(a, a + m);     memset(dp, -1, sizeof(dp));     for (int i = 0; i < m; i++) {       for (int j = 0; j <= a[i].s; j++) {         dp[i][0][j] = val = a[i].a + j;         for (int k = 1; k <= i; k++) {           for (int l = 0; l < i; l++) {             if (a[l].c == a[i].c) continue;             if (val % rat == 0) {               tmp = val / rat - a[l].a;               if (0 <= tmp && tmp <= a[l].s) {                 old = dp[l][k - 1][tmp];                 if (old != -1 && dp[i][k][j] < old + val) {                   dp[i][k][j] = old + val;                   fx[i][k][j] = l;                   fy[i][k][j] = tmp;                 }               }             }             if (val > rat) {               tmp = val - rat - a[l].a;               if (0 <= tmp && tmp <= a[l].s) {                 old = dp[l][k - 1][tmp];                 if (old != -1 && dp[i][k][j] < old + val) {                   dp[i][k][j] = old + val;                   fx[i][k][j] = l;                   fy[i][k][j] = tmp;                 }               }             }           }         }         if (dp[i][n - 1][j] > ret) ret = dp[i][n - 1][j], rex = i, rey = j;       }     }     if (ret) {       printf( YES n , ret);       trace(rex, n - 1, rey);     } else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int b[100000], c = 0, d, e, f;     int a;     cin >> a;     f = a;     for (int i = 0; i < a; ++i) {       cin >> b[i];       if (i == b[i]) c = c + 1;     }     for (int i = 0; i < a; ++i) {       if (i != b[i]) {         if (b[b[i]] == i) {           c = c + 2;           cout << c;           return 0;         }       }     }     if (c == f)       cout << c;     else       cout << c + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace jenga {   inline char get_unempty_char() {     char ch;     while (isspace(ch = getchar()))       ;     return ch;   }   const double eps(1e-10), Inf = 1e+64;   const int RED = 1, BLUE = 2, GREEN = 3, EMPTY = 0, N = 6, Base = 67,             mod = 3000007;   int n, last[mod] = {}, next[mod] = {}, total_edge = 0, s[N * 3 - 1] = {},          tot = 0;   unsigned long long hv[mod] = {};   double f[mod] = {};   inline void add(unsigned long long hash, double v) {     int u = hash % mod;     next[++total_edge] = last[u];     last[u] = total_edge;     f[total_edge] = v;     hv[total_edge] = hash;   }   inline int get_num(char ch) {     if (ch ==  R ) return RED;     if (ch ==  B ) return BLUE;     if (ch ==  G ) return GREEN;     if (ch ==  E ) return EMPTY;     assert(false);   }   void init() {     n = get_unempty_char() -  0 ;     for (int i = 1; i <= n; ++i) {       s[i] |= get_num(get_unempty_char()) << 0;       s[i] |= get_num(get_unempty_char()) << 2;       s[i] |= get_num(get_unempty_char()) << 4;     }     tot = n;   }   inline unsigned long long hash(int *s, int k, int up) {     static int v[N * 3 + 10] = {};     unsigned long long h = 0;     int tot = 0;     for (int i = 1; i <= k; ++i) {       int c1 = (s[i] >> 4) & 3, c2 = (s[i]) & 3, c3 = (s[i] >> 2) & 3;       v[++tot] =           c1 > c2 ? (c3 << 2) | c1 | (c2 << 4) : (c3 << 2) | c2 | (c1 << 4);     }     sort(v + 1, v + tot + 1);     int c1 = (up >> 4) & 3, c2 = up & 3, c3 = (up >> 2) & 3;     if (c1 > c2) up = c1 | (c2 << 4) | (c3 << 2);     for (int i = 1; i <= tot; ++i) h = h * Base + v[i];     h = h * Base + up;     return h;   }   double work(int *s, int tot, int up) {     unsigned long long h = hash(s, tot, up);     for (int i = last[h % mod]; i; i = next[i])       if (hv[i] == h) return f[i];     double v[4] = {Inf, Inf, Inf, Inf};     int to = tot, D = 6;     if ((up & 3) && ((up >> 2) & 3) && ((up >> 4) & 3)) s[++to] = up, up = 0;     for (int i = 1; i <= tot; ++i) {       int c1 = s[i] & 3, c2 = (s[i] >> 2) & 3, c3 = (s[i] >> 4) & 3, ns = s[i];       if (c1 && c2 && c3 && v[c2] > eps) {         s[i] = 0;         if (!(up & 3))           v[c2] = min(v[c2], work(s, to, up | c2));         else if (!(up >> 4 & 3))           v[c2] = min(v[c2], work(s, to, up | c2 << 4));         if (!(up >> 2 & 3)) v[c2] = min(v[c2], work(s, to, up | c2 << 2));         s[i] = ns;       }       if (c1 && c2 && v[c1] > eps) {         s[i] = c3 == 0 ? 0 : s[i] & ~3;         if (!(up & 3))           v[c1] = min(v[c1], work(s, to, up | c1));         else if (!(up >> 4 & 3))           v[c1] = min(v[c1], work(s, to, up | c1 << 4));         if (!(up >> 2 & 3)) v[c1] = min(v[c1], work(s, to, up | c1 << 2));         s[i] = ns;       }       if (c2 && c3 && v[c3] > eps) {         s[i] = c1 == 0 ? 0 : s[i] & ~48;         if (!(up & 3))           v[c3] = min(v[c3], work(s, to, up | c3));         else if (!(up >> 4 & 3))           v[c3] = min(v[c3], work(s, to, up | c3 << 4));         if (!(up >> 2 & 3)) v[c3] = min(v[c3], work(s, to, up | c3 << 2));         s[i] = ns;       }     }     double sum = 0;     if (v[1] != Inf) sum += v[1], D -= 1;     if (v[2] != Inf) sum += v[2] * 2, D -= 2;     if (v[3] != Inf) sum += v[3] * 2, D -= 2;     sum = D == 6 ? 0 : (sum + 6) / (6 - D);     add(h, sum);     return sum;   }   int Main() {     init();     printf( %.15f n , work(s, tot - 1, s[tot]));     return 0;   }   }  // namespace jenga   int main() {     jenga::Main();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, pair<int, int> > > v;   int main() {     ios_base::sync_with_stdio(false);     ;     int n;     cin >> n;     cout << (long long)(n - 2) * (n - 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   long long fast_exp(long long base, long long exp, long long mod) {     long long res = 1;     while (exp > 0) {       if (exp % 2 == 1) res = (res * base) % mod;       base = (base * base) % mod;       exp /= 2;     }     return res;   }   int n, k, a, b, q;   int ta[211111];   int tb[211111];   long long bita[211111];   long long flaga[211111];   long long bitb[211111];   long long flagb[211111];   void upd(long long* arr, int p, int v) {     for (; p <= n; p += (p & (-p))) arr[p] += v;   }   long long sum(long long* arr, int b) {     long long sm = 0;     for (; b > 0; b -= (b & (-b))) sm += arr[b];     return sm;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> k >> a >> b >> q;     while (q--) {       int type, d, ai;       cin >> type;       if (type == 1) {         cin >> d >> ai;         long long value = sum(bita, d) - sum(bita, d - 1);         if (value + ai <= a && !ta[d])           upd(bita, d, ai);         else {           ta[d] = 1;           upd(bita, d, -value);           long long fl = sum(flaga, d) - sum(flaga, d - 1);           if (fl == 0) upd(flaga, d, 1);         }         value = sum(bitb, d) - sum(bitb, d - 1);         if (value + ai <= b && !tb[d])           upd(bitb, d, ai);         else {           tb[d] = 1;           upd(bitb, d, -value);           long long fl = sum(flagb, d) - sum(flagb, d - 1);           if (fl == 0) upd(flagb, d, 1);         }       } else {         int p;         cin >> p;         long long before = sum(bitb, p - 1) + b * sum(flagb, p - 1);         long long after = sum(bita, n) - sum(bita, p + k - 1) +                           (sum(flaga, n) - sum(flaga, p + k - 1)) * a;         cout << (before + after) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long A;   vector<pair<long long, int> > ls;   vector<long long> M2[100000];   vector<long long> ls2;   long long my_stp(long long first, int stp) {     if (stp == 0) {       return 1ll;     }     long long res = my_stp(first, stp / 2);     res = res * res;     if (stp & 1) {       res = res * first;     }     return res;   }   inline pair<bool, long long> sqrtn(long long first, int stp) {     long long t = (long long)pow((long double)first, (long double)1 / stp);     for (long long k = max(2ll, t - 1); k <= t + 1; k++) {       if (my_stp(k, stp) == first) {         return make_pair(true, k);       }     }     return make_pair(false, 0ll);   }   inline bool is_prime(long long first) {     for (long long i = 2; i * i <= first; i++) {       if (first % i == 0) return false;     }     return true;   }   void obr(long long term, int id) {     for (int i = 1; (1ll << i) <= term - 1; i++) {       pair<bool, long long> sq = sqrtn(term - 1, i);       if (sq.first && is_prime(sq.second)) {         ls2.push_back(sq.second);         M2[id].push_back(sq.second);         break;       }     }   }   vector<long long> ls3;   void bct(int k, long long mul, int id) {     if (k == (int)(ls).size()) {       obr(mul, id);       ls3[id] = mul;       return;     }     for (int j = 0; j <= ls[k].second; j++) {       bct(k + 1, mul, id * (ls[k].second + 1) + j);       mul *= ls[k].first;     }   }   vector<pair<int, int> > G[100000];   void bct2(int k, int mul1, int mul2) {     if (k == (int)(ls).size()) {       if (mul2 != mul1) G[mul1].push_back(make_pair(mul2 - mul1, mul2));       return;     }     for (int j = 0; j <= ls[k].second; j++) {       for (int j1 = j; j1 <= ls[k].second; j1++) {         bct2(k + 1, mul1 * (ls[k].second + 1) + j,              mul2 * (ls[k].second + 1) + j1);       }     }   }   int main() {     cin >> A;     long long cur = A;     for (long long i = 2; i * i <= cur; i++) {       int cnt = 0;       while (cur % i == 0) {         cnt++;         cur /= i;       }       if (cnt) {         ls.push_back(make_pair(i, cnt));       }     }     if (cur > 1) {       ls.push_back(make_pair(cur, 1));     }     int szls3 = 1;     for (auto first : ls) {       szls3 *= (first.second + 1);     }     ls3.resize(szls3);     bct(0, (long long)1, 0);     {       sort((ls2).begin(), (ls2).end()),           ls2.resize(unique((ls2).begin(), (ls2).end()) - ls2.begin());     };     bct2(0, 0, 0);     vector<vector<int> > DP((int)(ls3).size(),                             vector<int>((int)(ls2).size() + 1, 0));     DP[0][0] = 1;     for (int first = 0; first < (int)(ls3).size(); first++) {       for (auto& second : M2[first]) {         second = lower_bound((ls2).begin(), (ls2).end(), second) - ls2.begin();       }     }     for (int i = 0; i < (int)(ls3).size(); i++) {       for (int j = 0; j < (int)(ls2).size(); j++) {         DP[i][j + 1] += DP[i][j];       }       for (auto first : G[i]) {         for (int second : M2[first.first]) {           DP[first.second][second + 1] += DP[i][second];         }       }     }     cout << DP[(int)(ls3).size() - 1][(int)(ls2).size()] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr int N = 3e3 + 1;   int a[N], dp[N][N], nxt[N], prv[N], lst[N];   int main() {     cin.tie(0), ios::sync_with_stdio(0);     int t, n;     cin >> t;     while (t--) {       cin >> n;       for (int i = 0; i < n; ++i) {         cin >> a[i], --a[i];       }       memset(lst, -1, n * sizeof *lst);       n = unique(a, a + n) - a;       memset(prv, -1, n * sizeof *prv);       memset(nxt, 127, n * sizeof *nxt);       for (int i = 0; i < n; ++i) {         if (lst[a[i]] != -1) {           prv[i] = lst[a[i]];           nxt[lst[a[i]]] = i;         }         lst[a[i]] = i;       }       for (int le = 2; le <= n; ++le)         for (int i = 0; i + le <= n; ++i) {           int j = i + le - 1;           dp[i][j] = max(dp[i + 1][j], dp[i][j - 1]);           bool use_j = 0;           if (a[i] != a[j]) {             int cnti = 0, cntj = 0;             for (int z = nxt[i]; z <= j; z = nxt[z]) ++cnti;             for (int z = prv[j]; z >= i; z = prv[z]) ++cntj;             use_j = cntj < cnti;           }           if (!use_j) {             for (int z = nxt[i]; z <= j; z = nxt[z]) {               dp[i][j] = max(dp[i][j], dp[i + 1][z - 1] + dp[z][j] + 1);             }           } else {             for (int z = prv[j]; z >= i; z = prv[z]) {               dp[i][j] = max(dp[i][j], dp[i][z] + dp[z + 1][j - 1] + 1);             }           }         }       cout << n - dp[0][n - 1] - 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )   #pragma GCC optimize( -ffloat-store )   const long long INF = 9e18;   const long long N = 998244353;   const double eps = 1e-9;   const auto start_time = std::chrono::high_resolution_clock::now();   void zark() {}   void solve() {     long long n, k;     cin >> n >> k;     vector<long long> a(n), b(n);     for (long long i = (0); i < (n); i++) cin >> a[i];     for (long long i = (0); i < (n); i++) cin >> b[i];     sort((a).begin(), (a).end());     sort((b).begin(), (b).end());     long long s = 0;     long long i = 0, j = n - 1, cnt = 0;     while (cnt < k && i < n && j >= 0) {       if (a[i] < b[j])         s += b[j], cnt++, j--, i++;       else         break;     }     for (long long ii = i; ii < n; ii++) s += a[ii];     cout << s <<   n ;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) solve();     zark();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t1, t2, t0, a, b, c, d, x1, x2, lo, mid, hi, ans;   int fun(long long x1, long long x2) {     return (x1 * t1 + x2 * t2 >= t0 * (x1 + x2));   }   void fun2(long long x1, long long x2) {     long long pt = (t1 * x1 + t2 * x2) * (a + b);     long long et = (t1 * a + t2 * b) * (x1 + x2);     if (pt < et) {       a = x1;       b = x2;     }     if (pt == et && (a + b) < (x2 + x1)) {       a = x1;       b = x2;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin >> t1 >> t2 >> x1 >> x2 >> t0;     a = 0;     b = x2;     if (t1 == t2) {       cout << x1 <<     << x2;       return 0;     }     for (int i(0), _n(x1 + 1); i < _n; ++i) {       lo = 0;       hi = x2 + 1, ans = 1061109567LL;       while (lo < hi) {         mid = lo + hi;         mid /= 2;         if (fun(i, mid)) {           hi = mid;           ans = min(ans, mid);         } else           lo = mid + 1;       }       if (ans != 1061109567LL) fun2(i, ans);     }     cout << a <<     << b;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     vector<string> v;     vector<string> res;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       v.push_back(s);     }     bool flag = 0;     string t =   , pal =   ;     for (int i = 0; i < v.size(); i++) {       string s = v[i];       t = s;       reverse(s.begin(), s.end());       auto it = find(v.begin(), v.end(), s);       if (it != v.end()) {         if (*it == t) {           flag = 1;           pal = t;           continue;         }         res.push_back(v[i]);         v.erase(it);       }     }     string out =   ;     for (auto x : res) {       out += x;     }     string p = out;     if (flag) out += pal;     reverse(p.begin(), p.end());     out += p;     cout << out.length() <<   n ;     cout << out;   }