#include <bits/stdc++.h>   using namespace std;   long long int binExp(long long int x, long long int n, long long int m) {     long long int res = 1;     while (n) {       if (n & 1) res = (res * x) % m;       x = (x * x) % m;       n >>= 1;     }     return res;   }   long long int modInv(long long int i, long long int m) {     return binExp(i, m - 2, m);   }   long long int add(long long int a, long long int b) {     long long int res = a + b;     if (res >= 1000000007) res -= 1000000007;     if (res < 0) res += 1000000007;     return res;   }   long long int mul(long long int a, long long int b) {     long long int res = (a) * (b);     res %= 1000000007;     if (res < 0) res += 1000000007;     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t, t1 = 1;     cin >> t;     while (t--) {       string str;       cin >> str;       int odd = 0, even = 0, oddq = 0, evenq = 0, oddt = 0, event = 0, ans = 0;       for (int i = 0; i < 10; i++) {         if (i % 2 != 0) {           event++;           if (str[i] ==  1 ) {             even++;           }           if (str[i] ==  ? ) {             evenq++;           }           int oddrem = 5 - oddt;           int evenrem = 5 - event;           if ((odd + oddq - even) > evenrem) {             ans = i + 1;             break;           }           if ((even + evenq - odd) > oddrem) {             ans = i + 1;             break;           }         } else {           oddt++;           if (str[i] ==  1 ) {             odd++;           }           if (str[i] ==  ? ) {             oddq++;           }           int oddrem = 5 - oddt;           int evenrem = 5 - event;           if ((odd + oddq - even) > evenrem) {             ans = i + 1;             break;           }           if ((even + evenq - odd) > oddrem) {             ans = i + 1;             break;           }         }       }       if (ans == 0) {         cout << 10 << endl;         continue;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int n;   long long p[200002], i[200002], v[200002], lvl[200002], ans;   vector<int> G[200002];   void dfs(int x, int par) {     if (par) lvl[x] = lvl[par] + 1;     for (auto it : G[x]) {       if (it == par) continue;       dfs(it, x);       ans = (ans +              2 * v[x] * (i[x] * p[it] % mod - p[x] * i[it] % mod + mod) % mod);       i[x] += p[it];       p[x] += i[it];     }     i[x]++;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> v[i];     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       G[x].push_back(y);       G[y].push_back(x);     }     dfs(1, 0);     for (int it = 1; it <= n; it++) {       if (lvl[it] % 2)         ans = (ans + 2 * v[it] *                          (i[it] * (p[1] - i[it] + 1) % mod -                           p[it] * (i[1] - p[it]) % mod + mod) %                          mod) %               mod;       else {         ans = (ans + 2 * v[it] *                          (i[it] * (i[1] - i[it] + 1) % mod -                           p[it] * (p[1] - p[it]) % mod + mod) %                          mod) %               mod;       }       ans = (ans - v[it] + mod) % mod;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   typedef struct node {     double x;     double y;     node operator-(node b) {       node ret;       ret.x = x - b.x;       ret.y = y - b.y;       return ret;     }     node operator+(node b) {       node ret;       ret.x = x + b.x;       ret.y = y + b.y;       return ret;     }     node operator/(double c) {       node ret;       ret.x = x / c;       ret.y = y / c;       return ret;     }     node operator*(double c) {       node ret;       ret.x = x * c;       ret.y = y * c;       return ret;     }   } node;   double xmul(node a, node b) { return a.x * b.y - b.x * a.y; }   void getit(double &A, double &B, double &C, node a, node b) {     double At = b.y - a.y;     double Bt = a.x - b.x;     A = -Bt;     B = At;     double x = (a.x + b.x) / 2;     double y = (a.y + b.y) / 2;     C = A * x + B * y;   }   node getcenter(node A, node B, node C) {     double A1, B1, C1;     getit(A1, B1, C1, A, B);     double A2, B2, C2;     getit(A2, B2, C2, B, C);     double det = A1 * B2 - A2 * B1;     node ret;     ret.x = (B2 * C1 - B1 * C2) / det;     ret.y = (A1 * C2 - A2 * C1) / det;     return ret;   }   bool solve(node a, node b, node c) {     node A = b * 2 - a;     node F = getcenter(A, b, c);     node G = c * 2 - F;     node E = b * 2 - F;     node D = a * 2 - E;     if (xmul(E - D, F - E) < 1e-7 || xmul(F - E, G - F) < 1e-7 ||         xmul(G - F, D - G) < 1e-7 || xmul(D - G, E - D) < 1e-7)       return false;     printf( YES n%.9lf %.9lf %.9lf %.9lf %.9lf %.9lf %.9lf %.9lf n , D.x, D.y,            E.x, E.y, F.x, F.y, G.x, G.y);     return true;   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       node a, b, c;       scanf( %lf%lf%lf%lf%lf%lf , &a.x, &a.y, &b.x, &b.y, &c.x, &c.y);       if (fabs(xmul(a - c, b - c)) < 1e-7 ||           !solve(a, b, c) && !solve(a, c, b) && !solve(c, a, b) &&               !solve(c, b, a) && !solve(b, a, c) && !solve(b, c, a))         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   template <typename T>   inline T max(T a, T b) {     return a > b ? a : b;   }   template <typename T>   inline T min(T a, T b) {     return a < b ? a : b;   }   template <typename T>   inline T abs(T a) {     return a > 0 ? a : -a;   }   template <typename T>   inline void repr(T &a, T b) {     if (a < b) a = b;   }   template <typename T>   inline void repl(T &a, T b) {     if (a > b) a = b;   }   int n, x, y, a[3001], f[3001][3001], fa[3001][3001][2], a1[3000], a2[3000], m1,       m2;   struct B {     int v, id;     bool operator<(const B &x) const { return v > x.v; }   } b[3001];   int main() {     scanf( %d%d%d , &n, &x, &y);     for (int i = 1; i <= n; i++) scanf( %d , a + i), f[0][0] += a[i];     for (int i = 1; i <= n; i++)       scanf( %d , &b[i].v), b[i].v -= a[i], b[i].id = i;     std::sort(b + 1, b + n + 1);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (f[i - 1][j] - a[b[i].id] > f[i][j])           f[i][j] = f[i - 1][j] - a[b[i].id], fa[i][j][0] = i - 1,           fa[i][j][1] = j;         if (j <= y) {           if (f[i - 1][j - 1] + b[i].v > f[i][j])             f[i][j] = f[i - 1][j - 1] + b[i].v, fa[i][j][0] = i - 1,             fa[i][j][1] = j - 1;         } else {           if (f[i - 1][j - 1] > f[i][j])             f[i][j] = f[i - 1][j - 1], fa[i][j][0] = i - 1, fa[i][j][1] = j - 1;         }       }       f[i][0] = f[i - 1][0] - a[b[i].id];     }     printf( %d n , f[n][x + y]);     for (int i = n, j = x + y; j;) {       while (fa[i][j][1] == j) {         i = fa[i][j][0];       }       if (j <= y)         a2[m2++] = b[i].id;       else         a1[m1++] = b[i].id;       i = fa[i][j][0];       j--;     }     std::sort(a1, a1 + m1);     std::sort(a2, a2 + m2);     for (int i = 0; i < m1; i++) printf( %d  , a1[i]);     printf(  n );     for (int i = 0; i < m2; i++) printf( %d  , a2[i]);     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   set<int> ss;   map<int, int> mm;   int arr[2 * 100003], pr[2 * 100003], nxt[2 * 100003];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, k;     cin >> n >> k;     for (int i = 0; i < int(n); i++) {       cin >> arr[i + 1];       ss.insert(arr[i + 1]);       mm[arr[i + 1]] = i + 1;       pr[i + 1] = i;       nxt[i + 1] = i + 2;     }     int ans[n + 1];     for (int i = 0; i < int(n); i++) {       if (ss.empty()) break;       int pos = mm[(*ss.rbegin())];       int tch = 1 + (i % 2);       ans[pos] = tch;       ss.erase(arr[pos]);       int p_f = pos, p_b = pos;       int j = k;       while (nxt[p_f] != n + 1 and j--) {         p_f = nxt[p_f];         ss.erase(arr[p_f]);         ans[p_f] = tch;       }       j = k;       while (pr[p_b] != 0 and j--) {         p_b = pr[p_b];         ans[p_b] = tch;         ss.erase(arr[p_b]);       }       pr[nxt[p_f]] = pr[p_b];       nxt[pr[p_b]] = nxt[p_f];     }     for (int i = 0; i < int(n); i++) cout << ans[i + 1];     cout <<   n ;     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int v1, v2, t, d, i = 2;     scanf( %d%d%d%d , &v1, &v2, &t, &d);     int sum = v1 + v2;     while (i != t) {       i++;       if (v1 < v2) {         v1 += d;         sum += v1;       } else {         v2 += d;         sum += v2;       }     }     printf( %d , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using pii = pair<int, int>;   using vi = vector<int>;   using vvi = vector<vi>;   const int INF = 2e9 + 5;   int main() {     cin.tie(0), cin.sync_with_stdio(0), cout.tie(0), cout.sync_with_stdio(0);     int n;     cin >> n;     vi l(n), r(n);     for (int i = 0; i < n; i++) {       cin >> l[i] >> r[i];     }     sort(l.begin(), l.end());     sort(r.begin(), r.end());     ll ans = n;     for (int i = 0; i < n; i++) ans += max(l[i], r[i]);     cout << ans;     return cout <<   n , 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const long long oo = INT_MAX;   const long long MOD = 1e9 + 7;   const long long sz = 1e5 + 5;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long tc = 1;     while (tc--) {       long long n;       cin >> n;       vector<long long> tree[n + 1];       for (long long i = 2; i < n + 1; ++i) {         long long p;         cin >> p;         tree[i].push_back(p);         tree[p].push_back(i);       }       vector<long long> nodeCnt(n + 1, 0);       vector<double> startTime(n + 1, 0.0);       startTime[1] = 1.0;       function<long long(long long, long long)> dfs1 = [&](long long node,                                                            long long parent) {         long long cnt = 1;         for (auto child : tree[node]) {           if (child != parent) {             cnt += dfs1(child, node);           }         }         nodeCnt[node] = cnt;         return cnt;       };       function<void(long long, long long)> dfs2 = [&](long long node,                                                       long long parent) {         long long ncnt = nodeCnt[node] - 1, cnt = 0;         for (auto child : tree[node]) {           if (child != parent) {             startTime[child] =                 ((ncnt - nodeCnt[child]) * 1.0) / 2 + (1.0 + startTime[node]);             dfs2(child, node);           }         }       };       dfs1(1, 0);       dfs2(1, 0);       for (long long i = 1; i < n + 1; ++i)         cout << fixed << setprecision(1) << startTime[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int k;     cin >> k;     map<char, int> dict;     for (int i = 0; i < 27; i++) dict[i +  a ] = 0;     for (int i = 0; i < s.length(); i++) dict[s[i]]++;     map<char, int>::iterator it;     vector<pair<int, char> > letras;     pair<int, char> aux;     int distinto;     for (it = dict.begin(); it != dict.end(); ++it) {       aux = make_pair((*it).second, (*it).first);       if (aux.first != 0) letras.push_back(aux);     }     sort((letras).begin(), (letras).end());     distinto = letras.size();     int l = 0;     int j = 0;     while (true) {       j += letras[l].first;       if (j > k) break;       l++;       if (j == k) break;       if (l == distinto) break;     }     if (l == distinto) {       cout << 0 << endl;       cout << endl;       return 0;     }     bool ltras[28];     memset(ltras, 0, sizeof(ltras));     for (int i = l; i < letras.size(); i++) {       ltras[letras[i].second -  a ] = 1;     }     string res =   ;     for (int i = 0; i < s.length(); i++)       if (ltras[s[i] -  a ]) res += s[i];     cout << distinto - l << endl;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, p;   int dp[105][55];   int modd(int x) {     if (x < 0)       return x + p;     else if (x >= p)       return x - p;     return x;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     cin >> n >> k >> p;     memset(dp, 128, sizeof dp);     dp[0][0] = 0;     int z = 0;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       z = (z + x) % p;       vector<int> vz(55, -2e9);       for (int l = 0; l < k; l++) {         for (int j = 0; j < p; j++) {           vz[l + 1] = max(vz[l + 1], dp[j][l] + modd(z - j + p));         }       }       for (int i = 0; i < 55; i++) dp[z][i] = max(dp[z][i], vz[i]);     }     cout << dp[z][k] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = (int)1e5 + 10;   int a[maxN];   int n;   vector<pair<int, int> > ans;   int cop[maxN];   bool solve_stupid(int n) {     for (int i = 1; i <= n; i++) cop[i] = a[i];     vector<pair<int, int> > all;     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         int k = 2 * j - i;         if (k <= n) all.emplace_back(i, j);       }     }     int m = all.size();     random_shuffle(all.begin(), all.end());     vector<pair<int, int> > nall;     for (int i = 0; i < min(m, 22); i++) nall.push_back(all[i]);     all = nall;     m = all.size();     for (int mask = 0; mask < (1 << m); mask++) {       bool ok = true;       for (int i = 1; i <= n; i++) {         a[i] = cop[i];       }       for (int bit = 0; bit < m; bit++) {         if (mask & (1 << bit)) {           int x = all[bit].first;           int y = all[bit].second;           int z = 2 * y - x;           a[x] ^= 1;           a[y] ^= 1;           a[z] ^= 1;         }       }       for (int i = 1; i <= n; i++) {         if (a[i] != 0) {           ok = false;           break;         }       }       if (ok) {         for (int bit = 0; bit < m; bit++) {           if (mask & (1 << bit)) ans.push_back(all[bit]);         }         return true;       }     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     srand(time(0));     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     while (n > 13) {       vector<pair<int, int> > possible;       possible.emplace_back(0, 0);       for (int i = n; i >= n - 5; i--) {         for (int j = i - 1; j >= n - 5; j--) {           int k = 2 * j - i;           if (k <= 0) continue;           possible.emplace_back(k, j);         }       }       for (int i = n; i >= n - 5; i--) {         int j = n - 6;         int k = 2 * j - i;         if (k >= 1) {           possible.emplace_back(k, j);         }       }       bool ok = false;       int willi = -1;       int willj = -1;       for (int i = n - 5; i <= n; i++) {         cop[i] = a[i];       }       for (int i = 0; i < possible.size(); i++) {         if (ok) break;         for (int j = i; j < possible.size(); j++) {           for (int q = n - 5; q <= n; q++) a[q] = cop[q];           int x = possible[i].first;           int y = possible[i].second;           int z = 2 * y - x;           if (x >= n - 5) a[x] ^= 1;           if (y >= n - 5) a[y] ^= 1;           if (z >= n - 5) a[z] ^= 1;           int xx = possible[j].first;           int yy = possible[j].second;           int zz = 2 * yy - xx;           if (xx >= n - 5) a[xx] ^= 1;           if (yy >= n - 5) a[yy] ^= 1;           if (zz >= n - 5) a[zz] ^= 1;           if (a[n - 5] == 0 && a[n - 4] == 0 && a[n - 3] == 0 && a[n - 2] == 0 &&               a[n - 1] == 0 && a[n] == 0) {             ok = true;             willi = i;             willj = j;             break;           }         }       }       assert(ok == true);       int x = possible[willi].first;       int y = possible[willi].second;       int z = 2 * y - x;       if (x >= 1) a[x] ^= 1;       if (y >= 1) a[y] ^= 1;       if (z >= 1) a[z] ^= 1;       if (x != 0) ans.push_back(possible[willi]);       int xx = possible[willj].first;       int yy = possible[willj].second;       int zz = 2 * yy - xx;       if (xx >= 1) a[xx] ^= 1;       if (yy >= 1) a[yy] ^= 1;       if (zz >= 1) a[zz] ^= 1;       if (xx != 0) ans.push_back(possible[willj]);       n -= 6;     }     if (solve_stupid(n)) {       cout <<  YES  <<   n ;       cout << ans.size() <<   n ;       for (auto t : ans) {         cout << t.first <<     << t.second <<     << 2 * t.second - t.first              <<   n ;       }     } else {       cout <<  NO  <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fileio() {}   vector<vector<long long int>> g;   vector<long long int> bit;   long long int n;   void add(long long int i, long long int x) {     while (i <= n) {       bit[i] += x;       i += (i & (-i));     }   }   long long int query(long long int i) {     long long int sum = 0;     while (i > 0) {       sum += bit[i];       i -= (i & (-i));     }     return sum;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     fileio();     cin >> n;     bit = vector<long long int>(n + 1, 0);     vector<long long int> p(n, 0), candi(n + 1, 0), contri(n + 1, 0);     set<long long int> s;     for (long long int i = 0; i < n; i++) {       cin >> p[i];       long long int more = query(n) - query(p[i]);       add(p[i], 1);       if (more == 1) {         long long int x = (*s.rbegin());         candi[x]++;       }       if (more == 0) {         contri[p[i]]++;       }       s.insert(p[i]);     }     long long int res = 1;     for (long long int i = 1; i <= n; i++)       if (candi[i] - contri[i] > candi[res] - contri[res]) res = i;     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   using min_pq = priority_queue<T, vector<T>, greater<T>>;   const int MAXN = 1e5 + 10, MAXQ = 3e5 + 10, MAXL = 18, ALP = 26, MOD = 1e9 + 7,             MAXK = 17, MAXA = 10, MAXB = 24, MAXBB = (1 << MAXB);   const string no =  NO n , yes =  YES n ;   const int hA[4] = {1, 0, -1, 0}, kA[4] = {0, 1, 0, -1};   const int INF = 1e9 + 10;   int n, par[MAXN], md[MAXN], st[MAXN], tt = 0;   vector<int> adj[MAXN];   int dfs1(int c = 0) {     md[c] = 1;     for (auto nxt : adj[c]) md[c] = max(md[c], dfs1(nxt) + 1);     return md[c];   }   void dfs2(int c = 0) {     sort(adj[c].begin(), adj[c].end(),          [&](int i, int j) { return md[i] < md[j]; });     st[tt++] = c;     for (auto nxt : adj[c]) dfs2(nxt);   }   void solve() {     cin >> n;     for (int i = 1; i < n; i++) {       cin >> par[i], adj[par[i]].push_back(i);     }     dfs1(), dfs2();     vector<int> ans;     ans.reserve(n);     for (int i = 1; i < n; i++) {       for (int a = st[i], b = st[i - 1]; b != par[a]; b = par[b])         ans.push_back(a);     }     for (int i = 0; i < n; i++) cout << st[i] <<    ;     cout <<   n ;     cout << (int)ans.size() <<   n ;     for (int c : ans) cout << c <<    ;     cout <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t_c = 1;     while (t_c--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     map<long long, long long> rt, lf;     long long a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];       rt[a[i]]++;     }     long long ans = 0;     for (long long i = 0; i < n; i++) {       if (a[i] % k == 0) {         long long l = a[i] / k;         rt[a[i]]--;         long long r = a[i] * k;         ans += rt[r] * lf[l];       }       lf[a[i]]++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NO_OF_ALPHABETS = 26;   vector<int> degree(NO_OF_ALPHABETS, 0);   vector<int> graph[NO_OF_ALPHABETS];   vector<int> component_no(NO_OF_ALPHABETS, 0);   void dfs(int v, int parent_v, int c) {     component_no[v] = c;     for (int i = 0; i < graph[v].size(); i++) {       int child_v = graph[v][i];       if (child_v == parent_v || component_no[child_v] == c) {         continue;       }       dfs(child_v, v, c);     }   }   void solve() {     string password;     cin >> password;     const int NO_OF_ALPHABETS = 26;     vector<vector<int> > adjacency(NO_OF_ALPHABETS,                                    vector<int>(NO_OF_ALPHABETS, false));     for (int alpha = 0; alpha < NO_OF_ALPHABETS; alpha++) {       degree[alpha] = 0;       graph[alpha].clear();       component_no[alpha] = 0;     }     for (int i = 1; i < password.size(); i++) {       if (adjacency[password[i] -  a ][password[i - 1] -  a ] == false) {         adjacency[password[i] -  a ][password[i - 1] -  a ] = true;         adjacency[password[i - 1] -  a ][password[i] -  a ] = true;         graph[password[i] -  a ].push_back(password[i - 1] -  a );         graph[password[i - 1] -  a ].push_back(password[i] -  a );         degree[password[i] -  a ]++;         degree[password[i - 1] -  a ]++;       }     }     vector<int> degree_2;     for (int alpha = 0; alpha < NO_OF_ALPHABETS; alpha++) {       if (degree[alpha] > 2) {         cout <<  NO n ;         return;       }       if (degree[alpha] == 2) {         degree_2.push_back(alpha);       }     }     int component = 1;     for (int alpha = 0; alpha < NO_OF_ALPHABETS; alpha++) {       if (component_no[alpha] == 0) {         dfs(alpha, -1, component++);       }     }     string keyboard;     vector<int> components;     vector<int> used(NO_OF_ALPHABETS, false);     for (int c = 1; c < component; c++) {       vector<int> this_component;       for (int alpha = 0; alpha < NO_OF_ALPHABETS; alpha++) {         if (component_no[alpha] == c) {           this_component.push_back(alpha);         }       }       if (this_component.size() == 1) {         keyboard += (char)( a  + this_component[0]);         used[this_component[0]] = true;         continue;       }       int border_1 = -1, border_2 = -1;       for (int i = 0; i < this_component.size(); i++) {         if (degree[this_component[i]] == 1) {           if (border_1 == -1)             border_1 = this_component[i];           else             border_2 = this_component[i];         }       }       if (border_1 == -1 || border_2 == -1) {         cout <<  NO n ;         return;       }       keyboard += (char)( a  + border_1);       used[border_1] = true;       while (keyboard.back() -  a  != border_2) {         for (int i = 0; i < graph[keyboard.back() -  a ].size(); i++) {           if (!used[graph[keyboard.back() -  a ][i]]) {             int next = graph[keyboard.back() -  a ][i];             keyboard += (char)( a  + next);             used[next] = true;             break;           }         }       }     }     cout <<  YES n ;     cout << keyboard <<   n ;     return;   }   int main() {     int no_of_test_cases;     cin >> no_of_test_cases;     while (no_of_test_cases--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long MOD2 = 998244353;   const float pi = 3.141592653;   long long power(long long a, long long b) {     if (b == 0) return 1;     long long p = power(a, b / 2);     if (b & 1)       return p * p * a;     else       return p * p;   }   void solve() {     long long n, k;     cin >> n >> k;     vector<long long> a, b, c;     for (long long i = 0; i < n; i++) {       long long o, t, f;       cin >> o >> t >> f;       if (t == 1 && f == 1)         c.push_back(o);       else if (t == 1)         a.push_back(o);       else if (f == 1)         b.push_back(o);     }     if (a.size() + c.size() < k || b.size() + c.size() < k) {       cout << -1;       return;     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     sort(c.begin(), c.end());     long long ans = 0, count = 0, index1 = 0, index2 = 0;     while (1) {       if (index2 == min(a.size(), b.size()) || index1 == c.size()) break;       if (a[index2] + b[index2] <= c[index1]) {         ans += a[index2] + b[index2];         index2++;       } else {         ans += c[index1];         index1++;       }       count++;       if (count == k) break;     }     if (index1 < c.size()) {       while (count < k) {         ans += c[index1];         index1++;         count++;       }     }     if (index2 < min(a.size(), b.size())) {       while (count < k) {         count++;         ans += (a[index2] + b[index2]);         index2++;       }     }     cout << ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int M[17], R[17], n, sum;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> M[i];     for (int i = 1; i <= n; i++) cin >> R[i];     for (int i = 1; i <= 720719; i++)       for (int j = 1; j <= n; j++) {         if (i % M[j] == R[j]) {           sum++;           break;         }       }     double ans = 1.0 * sum / 720720;     printf( %.6lf , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int res = 0;     int n, x;     cin >> n >> x;     for (int i = 1; i <= n; ++i) {       if (x % i == 0 && x / i <= n) ++res;     }     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   int op[1000005];   bool value[1000005];   bool change[1000005];   long req[1000005][2];   bool calc(long i) {     if (i <= 0) return false;     value[i] = false;     if (op[i] == 4) {       value[i] = (req[i][0] == 1);     }     if (op[i] == 3) {       value[i] = !(calc(req[i][0]));     }     if (op[i] == 2) {       value[i] = (calc(req[i][0]) ^ calc(req[i][1]));     }     if (op[i] == 1) {       value[i] = (calc(req[i][0]) | calc(req[i][1]));     }     if (op[i] == 0) {       value[i] = (calc(req[i][0]) & calc(req[i][1]));     }     return value[i];   }   void backTrace(long i, bool vt, bool vf) {     if (op[i] == 4) {       if (value[i])         change[i] = vf;       else         change[i] = vt;     }     if (op[i] == 3) {       backTrace(req[i][0], vf, vt);     }     if (op[i] == 2) {       if (value[req[i][1]]) {         backTrace(req[i][0], vf, vt);       } else {         backTrace(req[i][0], vt, vf);       }       if (value[req[i][0]]) {         backTrace(req[i][1], vf, vt);       } else {         backTrace(req[i][1], vt, vf);       }     }     if (op[i] == 1) {       if (value[req[i][1]]) {         backTrace(req[i][0], vt, vt);       } else {         backTrace(req[i][0], vt, vf);       }       if (value[req[i][0]]) {         backTrace(req[i][1], vt, vt);       } else {         backTrace(req[i][1], vt, vf);       }     }     if (op[i] == 0) {       if (value[req[i][1]]) {         backTrace(req[i][0], vt, vf);       } else {         backTrace(req[i][0], vf, vf);       }       if (value[req[i][0]]) {         backTrace(req[i][1], vt, vf);       } else {         backTrace(req[i][1], vf, vf);       }     }   }   int main() {     long n;     cin >> n;     string s;     for (long i = 1; i <= n; ++i) {       cin >> s;       if (s ==  AND ) {         op[i] = 0;         cin >> req[i][0] >> req[i][1];       } else if (s ==  OR ) {         op[i] = 1;         cin >> req[i][0] >> req[i][1];       } else if (s ==  XOR ) {         op[i] = 2;         cin >> req[i][0] >> req[i][1];       } else if (s ==  NOT ) {         op[i] = 3;         cin >> req[i][0];       } else {         op[i] = 4;         cin >> req[i][0];       }     }     calc(1);     backTrace(1, true, false);     for (long i = 1; i <= n; ++i) {       if (op[i] == 4) {         if (change[i])           cout << 1;         else           cout << 0;       }     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, a[N], lm[N], rm[N], q[N];   vector<int> tree[35];   long long ans;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       for (int j = 0; (1 << j) <= a[i]; j++)         if (a[i] & (1 << j)) tree[j].push_back(i);     }     int tail = 0;     for (int i = 1; i <= n; i++) {       while (tail && a[q[tail - 1]] < a[i]) tail--;       lm[i] = tail ? q[tail - 1] + 1 : 1;       q[tail++] = i;     }     tail = 0;     for (int i = n; i; i--) {       while (tail && a[q[tail - 1]] <= a[i]) tail--;       rm[i] = tail ? q[tail - 1] - 1 : n;       q[tail++] = i;     }     for (int i = 1; i <= n; i++) {       if (lm[i] == rm[i]) continue;       int tl = lm[i] - 1, tr = rm[i] + 1;       for (int j = 0; (1 << j) <= a[i]; j++)         if (!((1 << j) & a[i])) {           if (tree[j].size() == 0) continue;           auto it = lower_bound(tree[j].begin(), tree[j].end(), i);           if (it != tree[j].begin()) {             it--;             tl = max(tl, *it);           }           it = upper_bound(tree[j].begin(), tree[j].end(), i);           if (it != tree[j].end()) tr = min(tr, *it);         }       ans +=           1ll * (i - lm[i] + 1) * (rm[i] - i + 1ll) - 1ll * (i - tl) * (tr - i);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     char c;     while (~scanf( %d , &n)) {       c =  a ;       for (i = 1; i <= n; i++) {         printf( %c , c);         c++;         if (c ==  e ) c =  a ;       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   bool isPrime(long long int n) {     for (long long int i = 2; i * i <= n; i++) {       if (n % i == 0) {         return false;       }     }     return true;   }   bool isPowerOfTwo(long long int x) { return (x && (!(x & (x - 1)))); }   long long int countDigit(long long int num) { return (floor(log10(num)) + 1); }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int test_case = 1;     while (test_case--) {       long long int n;       cin >> n;       long long int arr[n];       for (long long int i = 0; i < n; i++) {         cin >> arr[i];       }       long long int maxx = 0;       vector<long long int> ans;       for (long long int i = n - 1; i >= 0; i--) {         if (arr[i] <= maxx) {           ans.push_back(maxx - arr[i] + 1);         } else {           ans.push_back(0);         }         maxx = max(arr[i], maxx);       }       reverse(ans.begin(), ans.end());       for (auto it : ans) {         cout << it <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void shift(vector<int> &ans) {     for (int i = 0; i < ans.size() - 1; i++) {       ans[i] = ans[i + 1];     }   }   bool check(vector<int> ans, int c) {     for (int i = 0; i < ans.size(); i++) {       if (c == ans[i]) return true;     }     return false;   }   int main() {     int n, k;     cin >> n >> k;     vector<int> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     vector<int> ans;     for (int i = 0; i < n; i++) {       if (ans.size() < k && (!check(ans, v[i])))         ans.push_back(v[i]);       else if (!check(ans, v[i])) {         shift(ans);         ans[ans.size() - 1] = v[i];       }     }     cout << ans.size() << endl;     for (int i = ans.size() - 1; i >= 0; i--) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[3];   long long kq;   void nhap() { cin >> a[0] >> a[1] >> a[2]; }   void cbi() { sort(a, a + 3); }   void xuli() {     if (a[0] == a[1] && a[1] == a[2]) {       cout << a[0];       exit(0);     }     if (a[0] + a[1] < a[2] / 2)       kq = 1ll * a[0] + a[1];     else       kq = 1ll * (a[0] + a[1] + a[2]) / 3;   }   void ghikq() { cout << kq; }   int main() {     nhap();     cbi();     xuli();     ghikq();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int INF = 0x7ffffff;   const int magic = 348;   string s1, s2;   string s;   int n;   int nxt1[200], nxt2[200];   int main() {     cin >> s1 >> s2;     cin >> n;     n %= 4;     nxt1[94] = 62;     nxt1[62] = 118;     nxt1[118] = 60;     nxt1[60] = 94;     nxt2[94] = 60;     nxt2[60] = 118;     nxt2[118] = 62;     nxt2[62] = 94;     bool f1 = false, f2 = false;     s = s1;     for (int i = 1; i <= n; i++) s[0] = nxt1[s[0]];     if (s == s2) f1 = true;     s = s1;     for (int i = 1; i <= n; i++) s[0] = nxt2[s[0]];     if (s == s2) f2 = true;     if (f1 && f2) {       cout <<  undefined  << endl;     } else {       if (f1)         cout <<  cw  << endl;       else         cout <<  ccw  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 300000;   const int MAX_E2 = 1 << 20;   struct Elm {     int l, r, v;     Elm() {}     Elm(int _l, int _r, int _v) : l(_l), r(_r), v(_v) {}     Elm(int _l) : l(_l), r(_l), v(1) {}     Elm operator+(const Elm &e) const {       if (v == 0) return e;       if (e.v == 0) return *this;       Elm a;       a.l = l, a.r = e.r;       a.v = v + e.v - ((r < e.l) ? 1 : 0);       return a;     }   };   template <typename T, const int MAX_E2>   struct SegTreeSum {     int n, e2;     T nodes[MAX_E2], z;     SegTreeSum() {}     void init(int n, T _z) {       z = _z;       for (e2 = 1; e2 < n; e2 <<= 1)         ;       fill(nodes, nodes + MAX_E2, z);     }     T &get(int i) { return nodes[e2 - 1 + i]; }     void setall() {       for (int j = e2 - 2; j >= 0; j--)         nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2];     }     void set(int i, T v) {       int j = e2 - 1 + i;       nodes[j] = v;       while (j > 0) {         j = (j - 1) / 2;         nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2];       }     }     T sum_range(int r0, int r1, int k, int i0, int i1) {       if (r1 <= i0 || i1 <= r0) return z;       if (r0 <= i0 && i1 <= r1) return nodes[k];       int im = (i0 + i1) / 2;       T v0 = sum_range(r0, r1, k * 2 + 1, i0, im);       T v1 = sum_range(r0, r1, k * 2 + 2, im, i1);       return v0 + v1;     }     T sum_range(int r0, int r1) { return sum_range(r0, r1, 0, 0, e2); }   };   int as[MAX_N];   SegTreeSum<Elm, MAX_E2> st;   int main() {     int n;     scanf( %d , &n);     st.init(n, Elm(0, 0, 0));     for (int i = 0; i < n; i++) {       scanf( %d , as + i);       as[i]--;       st.get(as[i]) = Elm(i, i, 1);     }     st.setall();     int q;     scanf( %d , &q);     while (q--) {       int p, x, y;       scanf( %d%d%d , &p, &x, &y);       if (p == 1) {         x--;         Elm e = st.sum_range(x, y);         printf( %d n , e.v);       } else {         x--, y--;         int ax = as[x], ay = as[y];         swap(as[x], as[y]);         st.set(ax, Elm(y));         st.set(ay, Elm(x));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[100005], b[100005];   vector<int> g[100005];   int next_id, from[100005], to[100005];   bitset<1000> tree[4 * 100005], primes;   int lazy[4 * 100005];   void dfs(int u) {     from[u] = next_id++;     b[from[u]] = a[u] % m;     for (int i = 0; i < g[u].size(); i++)       if (from[g[u][i]] == -1) dfs(g[u][i]);     to[u] = next_id;   }   void rot(bitset<1000> &b, int k) {     b = (b << k) | (b >> (m - k));     b ^= (b >> m) << m;   }   void init(int no, int l, int r) {     if (r - l == 1) {       tree[no].set(b[l]);       return;     }     int m = (l + r) / 2;     init(2 * no, l, m);     init(2 * no + 1, m, r);     tree[no] = tree[2 * no] | tree[2 * no + 1];   }   void prop(int no, int l, int r) {     lazy[no] %= m;     if (lazy[no] > 0) {       rot(tree[no], lazy[no]);       if (r - l > 1) {         lazy[2 * no] += lazy[no];         lazy[2 * no + 1] += lazy[no];       }       lazy[no] = 0;     }   }   void update(int no, int l, int r, int a, int b, int x) {     if (a <= l && r <= b) {       lazy[no] += x;       return;     }     prop(no, l, r);     int m = (l + r) / 2;     if (a < m) update(2 * no, l, m, a, b, x);     if (m < b) update(2 * no + 1, m, r, a, b, x);     prop(2 * no, l, m);     prop(2 * no + 1, m, r);     tree[no] = tree[2 * no] | tree[2 * no + 1];   }   bitset<1000> query(int no, int l, int r, int a, int b) {     prop(no, l, r);     if (a <= l && r <= b) return tree[no];     int m = (l + r) / 2;     bitset<1000> ret;     if (a < m) ret = query(2 * no, l, m, a, b);     if (m < b) ret |= query(2 * no + 1, m, r, a, b);     return ret;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d %d , &u, &v);       u--, v--;       g[u].push_back(v);       g[v].push_back(u);     }     memset(from, -1, sizeof(from));     next_id = 0;     dfs(0);     memset(lazy, 0, sizeof(lazy));     init(1, 0, n);     primes[2].flip();     for (int i = 3; i < m; i += 2) primes.set(i);     for (int i = 3; i * i < m; i += 2)       if (primes[i])         for (int j = i * i; j < m; j += i) primes.reset(j);     int q, op, v, x;     scanf( %d , &q);     while (q--) {       scanf( %d %d , &op, &v);       v--;       if (op == 1) {         scanf( %d , &x);         update(1, 0, n, from[v], to[v], x % m);       } else {         bitset<1000> bs = query(1, 0, n, from[v], to[v]) & primes;         printf( %d n , (int)bs.count());       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t > 0) {       int x, m, n;       cin >> x;       m = x / 7;       n = x % 7;       if (n == 0)         cout << m << endl;       else         cout << m + 1 << endl;       t--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, u, v;   vector<int> g[100005], gr[100005];   vector<int> order;   bool used[100005];   int G[100005], C[100005], k = 0;   void dfs1(int x) {     used[x] = 1;     for (int(i) = (0); (i) < (g[x].size()); (i)++) {       int nn = g[x][i];       if (!used[nn]) dfs1(nn);     }     order.push_back(x);   }   int dfs2(int x) {     used[x] = 1;     G[x] = k;     int ans = 1, nn;     for (int(i) = (0); (i) < (gr[x].size()); (i)++) {       nn = gr[x][i];       if (!used[nn]) ans += dfs2(nn);     }     return ans;   }   int dfs3(int x) {     used[x] = 1;     int ans = (C[G[x]] == 1), nn;     for (int(i) = (0); (i) < (g[x].size()); (i)++) {       nn = g[x][i];       if (!used[nn]) ans &= dfs3(nn);     }     for (int(i) = (0); (i) < (gr[x].size()); (i)++) {       nn = gr[x][i];       if (!used[nn]) ans &= dfs3(nn);     }     return ans;   }   int main() {     scanf( %d%d , &(n), &(m));     for (int(i) = (0); (i) < (m); (i)++) {       scanf( %d%d , &(u), &(v));       g[u].push_back(v);       gr[v].push_back(u);     }     for (int i = 1; i <= n; i++)       if (!used[i]) dfs1(i);     reverse(order.begin(), order.end());     memset((used), (0), sizeof(used));     for (int(i) = (0); (i) < (n); (i)++)       if (!used[order[i]]) {         C[k] = dfs2(order[i]);         k++;       }     memset((used), (0), sizeof(used));     int ans = n;     for (int i = 0; i < n; i++)       if (!used[order[i]]) ans -= dfs3(order[i]);     printf( %d n , ans);   }


#include <bits/stdc++.h>   using int64 = long long;   constexpr int Maxn = 200000;   constexpr int p = 1000000007;   template <class _Tp1, class _Tp2>   inline void inc(_Tp1& x, const _Tp2& y) {     x += y;     (p <= x) && (x -= p);   }   template <class _Tp1, class _Tp2>   inline void dec(_Tp1& x, const _Tp2& y) {     x -= y;     (x < 0) && (x += p);   }   template <class _Tp>   inline int md(const _Tp& v) {     return v < 0 ? ((0 <= p + v) ? (p + v) : (v % p + p)) : (v < p) ? v : (v % p);   }   namespace IOManager {   constexpr int FILESZ(131072);   unsigned char buf[FILESZ];   const unsigned char *ibuf = buf, *tbuf = buf;   struct IOManager {     inline unsigned char gc() {       return (ibuf == tbuf) &&                      (tbuf = (ibuf = buf) + fread(buf, 1, FILESZ, stdin),                       ibuf == tbuf)                  ? EOF                  : *ibuf++;     }     template <class _Tp>     inline operator _Tp() {       _Tp s = 0u;       unsigned char c = gc(), w = 0;       for (; c < 48; c = gc()) (c == 45) && (w = 1);       for (; c > 47; c = gc()) s = (_Tp)(s * 10u + c - 48u);       return w ? -s : s;     }   };   }  // namespace IOManager   IOManager::IOManager io;   const int n = io;   int64 bit[Maxn + 1];   inline void update(const int& x, const int& d) {     for (int i = x; i <= n; i += i & -i) bit[i] += d;   }   inline int64 sum(const int& x) {     int64 s = 0;     for (int i = x; i; i -= i & -i) s += bit[i];     return s;   }   int bitp[Maxn + 1];   inline void updatep(const int& x, const int& d) {     for (int i = x; i <= n; i += i & -i) inc(bitp[i], d);   }   inline int sump(const int& x) {     int64 s = 0;     for (int i = x; i; i -= i & -i) s += bitp[i];     return s % p;   }   int a[Maxn + 1], w[Maxn + 1];   int main() {     int q = io;     for (int i = 1; i <= n; ++i) a[i] = (int)io - i;     for (int i = 1; i <= n; ++i)       w[i] = io, update(i, w[i]), updatep(i, (int64)w[i] * a[i] % p);     int64 sl, sm, sr;     for (int x, y, l, m, r; q; --q)       if (x = io, y = io, x < 0) {         int d = y - w[x = -x];         w[x] = y;         update(x, d);         updatep(x, md((int64)d * a[x]));       } else {         l = x;         r = y;         sl = sum(l - 1);         sr = sum(r) - sl;         for (; l < r;)           ((sum(m = (l + r) >> 1) - sl) * 2 < sr) ? (l = m + 1) : (r = m);         sm = sum(m = l);         sr += sl;         printf( %d n , md((int64)(sump(y) - sump(m) * 2ll +                                   (int64)(sm - sr + sm - sl) % p * a[m] % p +                                   sump(x - 1))));       }     return 0;   }


#include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   const int MAXN = 1e3 + 10;   using namespace std;   char str[MAXN][MAXN];   int data[MAXN];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> str[i];     for (int i = 0; i < m; i++) cin >> data[i];     long long ans = 0;     for (int i = 0; i < m; i++) {       int temp[10] = {0}, tmp = -1;       for (int j = 0; j < n; j++) temp[str[j][i] -  A ]++;       for (int j = 0; j < 5; j++) tmp = max(tmp, temp[j]);       ans += (long long)tmp * data[i];     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ans = 0;   void solve1(vector<int> &ar, bool yeah) {     int sz = ar.size();     int mid = sz / 2 + yeah * (sz % 2) - 1;     int L = mid;     int minL = ar[mid];     int maxL = ar[mid];     int minR = (1 << 30);     int maxR = 0;     for (int R = mid + 1; R < sz; ++R) {       minR = min(minR, ar[R]);       maxR = max(maxR, ar[R]);       while (L > 0 && ar[L - 1] < maxR && ar[L - 1] > minR) {         minL = min(minL, ar[L - 1]);         maxL = max(maxL, ar[--L]);       }       if (maxR > maxL && minR < minL) ans += (L <= (R - maxR + minR));     }   }   void solve2(vector<int> ar, bool yeah) {     int sz = ar.size();     int mid = sz / 2 + yeah * (sz % 2) - 1;     int L = mid;     int minL = ar[mid];     int maxL = ar[mid];     int minR = (1 << 30);     int maxR = 0;     map<int, int> m;     m[minL - L]++;     int dL = L;     for (int R = mid + 1; R < sz; ++R) {       minR = min(minR, ar[R]);       maxR = max(maxR, ar[R]);       while (L > 0 && ar[L - 1] < maxR) {         minL = min(minL, ar[L - 1]);         maxL = max(maxL, ar[--L]);         ar[L] = minL;         m[ar[L] - L]++;       }       while (dL >= L && ar[dL] > minR) {         m[ar[dL] - dL]--;         --dL;       }       if (maxR > maxL) {         ans += m[maxR - R];         int pmr = 0;       }     }   }   int ar[300005];   void go(int a, int b) {     if (a == b) {       ans++;       return;     }     vector<int> V;     for (int i = a; i <= b; ++i) V.push_back(ar[i]);     solve1(V, 1);     reverse(V.begin(), V.end());     solve1(V, 0);     reverse(V.begin(), V.end());     solve2(V, 1);     reverse(V.begin(), V.end());     solve2(V, 0);     go(a, (a + b) / 2);     go((a + b) / 2 + 1, b);   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       int a, b;       scanf( %d%d , &a, &b);       ar[a] = b;     }     go(1, n);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long ax, ay, bx, by, cx, cy, flag = 0;   long long f(long long x1, long long y1, long long x2, long long y2) {     long long res = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);     return res;   }   bool isColinear() {     long long res1 = (by - ay) * (cx - bx);     long long res2 = (cy - by) * (bx - ax);     if (res1 == res2)       return true;     else       return false;   }   int main() {     cin >> ax >> ay >> bx >> by >> cx >> cy;     if (isColinear() == true)       flag = 0;     else {       long long dis1 = f(ax, ay, bx, by);       long long dis2 = f(bx, by, cx, cy);       if (dis1 == dis2)         flag = 1;       else         flag = 0;     }     if (flag == 1)       printf( Yes n );     else       printf( No n );   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = LLONG_MAX / 2;   int extractMin(set<int> &mySet) {     set<int>::iterator it = mySet.begin();     int ans = *(it);     mySet.erase(it);     return ans;   }   int search(set<int> &mySet, int index) {     set<int>::iterator it = mySet.lower_bound(index);     if (it == mySet.end()) {       return -1;     }     int ans = *(it);     return ans;   }   void eliminate(set<int> &mySet, int index) {     set<int>::iterator it = mySet.lower_bound(index);     if (it == mySet.end()) {       assert(false);     }     mySet.erase(it);   }   void notFound() { cout << -1 <<   n ; }   void impr(vector<vector<int> > ans) {     printf( %d n , ((int)(ans).size()));     for (int i = 0; i < ((int)(ans).size()); i++) {       printf( %d , ((int)(ans[i]).size()));       for (int j = 0; j < ((int)(ans[i]).size()); j++) {         printf(  %d , ans[i][j] + 1);       }       puts(  );     }   }   void solve(string str) {     int n = ((int)(str).size());     set<int> zeroes, ones;     for (int i = 0; i < n; i++) {       if (str[i] ==  0 ) {         zeroes.insert(i);       } else {         ones.insert(i);       }     }     vector<vector<int> > ans;     while (true) {       if (zeroes.empty() && ones.empty()) {         break;       }       if (zeroes.empty()) {         notFound();         return;       }       int curZero = extractMin(zeroes);       vector<int> seq(1, curZero);       while (true) {         int curOne = search(ones, curZero + 1);         curZero = search(zeroes, curOne + 1);         if (curOne == -1 || curZero == -1) {           break;         }         seq.push_back(curOne);         seq.push_back(curZero);         eliminate(ones, curOne);         eliminate(zeroes, curZero);       }       ans.push_back(seq);     }     impr(ans);   }   int main() {     string str;     while (cin >> str) {       solve(str);     }   }


#include <bits/stdc++.h>      template <typename T, int NDIMS> struct tensor_view {    static_assert(NDIMS >= 0,  NDIMS must be nonnegative );      protected:    std::array<int, NDIMS> shape;    std::array<int, NDIMS> strides;    T* data;       tensor_view(std::array<int, NDIMS> shape_, std::array<int, NDIMS> strides_, T* data_) : shape(shape_), strides(strides_), data(data_) {}      public:    tensor_view() : shape{0}, strides{0}, data(nullptr) {}      protected:    int flatten_index(std::array<int, NDIMS> idx) const {     int res = 0;     for (int i = 0; i < NDIMS; i++) { res += idx[i] * strides[i]; }     return res;    }    int flatten_index_checked(std::array<int, NDIMS> idx) const {     int res = 0;     for (int i = 0; i < NDIMS; i++) {      assert(0 <= idx[i] && idx[i] < shape[i]);      res += idx[i] * strides[i];     }     return res;    }      public:    T& operator[] (std::array<int, NDIMS> idx) const {     return data[flatten_index(idx)];    }    T& at(std::array<int, NDIMS> idx) const {     return data[flatten_index_checked(idx)];    }       template <int D = NDIMS>    typename std::enable_if<(0 < D), tensor_view<T, NDIMS-1>>::type operator[] (int idx) const {     std::array<int, NDIMS-1> nshape; std::copy(shape.begin()+1, shape.end(), nshape.begin());     std::array<int, NDIMS-1> nstrides; std::copy(strides.begin()+1, strides.end(), nstrides.begin());     T* ndata = data + (strides[0] * idx);     return tensor_view<T, NDIMS-1>(nshape, nstrides, ndata);    }    template <int D = NDIMS>    typename std::enable_if<(0 < D), tensor_view<T, NDIMS-1>>::type at(int idx) const {     assert(0 <= idx && idx < shape[0]);     return operator[](idx);    }       template <int D = NDIMS>    typename std::enable_if<(0 == D), T&>::type operator * () const {     return *data;    }       template <typename U, int D> friend struct tensor_view;    template <typename U, int D> friend struct tensor;   };      template <typename T, int NDIMS> struct tensor {    static_assert(NDIMS >= 0,  NDIMS must be nonnegative );      protected:    std::array<int, NDIMS> shape;    std::array<int, NDIMS> strides;    int len;    T* data;      public:    tensor() : shape{0}, strides{0}, len(0), data(nullptr) {}       explicit tensor(std::array<int, NDIMS> shape_, const T& t = T()) {     shape = shape_;     strides[NDIMS-1] = 1;     for (int i = NDIMS-1; i > 0; i--) {      strides[i-1] = strides[i] * shape[i];     }     len = strides[0] * shape[0];     data = new T[len];     std::fill(data, data + len, t);    }       tensor(const tensor& o) : shape(o.shape), strides(o.strides), len(o.len), data(new T[len]) {     for (int i = 0; i < len; i++) {      data[i] = o.data[i];     }    }       tensor& operator=(tensor&& o) noexcept {     using std::swap;     swap(shape, o.shape);     swap(strides, o.strides);     swap(len, o.len);     swap(data, o.data);     return *this;    }    tensor(tensor&& o) : tensor() {     *this = std::move(o);    }    tensor& operator=(const tensor& o) {     return *this = tensor(o);    }    ~tensor() { delete[] data; }       using view_t = tensor_view<T, NDIMS>;    view_t view() {     return tensor_view<T, NDIMS>(shape, strides, data);    }    operator view_t() {     return view();    }       using const_view_t = tensor_view<const T, NDIMS>;    const_view_t view() const {     return tensor_view<const T, NDIMS>(shape, strides, data);    }    operator const_view_t() const {     return view();    }       T& operator[] (std::array<int, NDIMS> idx) { return view()[idx]; }    T& at(std::array<int, NDIMS> idx) { return view().at(idx); }    const T& operator[] (std::array<int, NDIMS> idx) const { return view()[idx]; }    const T& at(std::array<int, NDIMS> idx) const { return view().at(idx); }       template <int D = NDIMS>    typename std::enable_if<(0 < D), tensor_view<T, NDIMS-1>>::type operator[] (int idx) {     return view()[idx];    }    template <int D = NDIMS>    typename std::enable_if<(0 < D), tensor_view<T, NDIMS-1>>::type at(int idx) {     return view().at(idx);    }       template <int D = NDIMS>    typename std::enable_if<(0 < D), tensor_view<const T, NDIMS-1>>::type operator[] (int idx) const {     return view()[idx];    }    template <int D = NDIMS>    typename std::enable_if<(0 < D), tensor_view<const T, NDIMS-1>>::type at(int idx) const {     return view().at(idx);    }       template <int D = NDIMS>    typename std::enable_if<(0 == D), T&>::type operator * () {     return *view();    }    template <int D = NDIMS>    typename std::enable_if<(0 == D), const T&>::type operator * () const {     return *view();    }   };      template <typename T> void setmax(T& a, T b) { if (b > a) a = b; }      int main() {    using namespace std;    ios_base::sync_with_stdio(false), cin.tie(nullptr);       int N, Q; cin >> N >> Q;    vector<int> A(N);    for (int i = 0; i < N; i++) { cin >> A[i]; A[i] += i; }       const int MAXK = 30;    int S = 0;    while (!((1 << S) >= N)) S++;       tensor<pair<int, int>, 3> dp({S+1, N, MAXK+1});    {     vector<pair<int, int>> stk; stk.reserve(N);     for (int i = N-1; i >= 0; i--) {      while (!stk.empty() && A[i] > stk.back().first) stk.pop_back();      stk.push_back({A[i], i});      int lo = -1, hi = int(stk.size())-1;      while (hi - lo > 1) {       int md = (lo + hi) / 2;       if (stk[md].second <= A[i]) hi = md;       else lo = md;      }      pair<int, int> cur = stk[hi];      dp[{0, i, 0}] = cur;      for (int k = 1; k <= MAXK; k++) {       if (A[i] + k < N) setmax(cur, {A[A[i]+k], A[i]+k});       dp[{0, i, k}] = cur;      }     }    }       for (int s = 1; s <= S; s++) {     for (int i = 0; i < N; i++) {      for (int k1 = 0; k1 <= MAXK; k1++) {       int j = dp[{s-1, i, k1}].second;       for (int k2 = 0; k1+k2 <= MAXK; k2++) {        setmax(dp[{s, i, k1+k2}], dp[{s-1, j, k2}]);       }      }     }    }       while (Q--) {     int L, R, K; cin >> L >> R >> K; L--, R--;     cout << [&]() -> int {      if (L == R) return 0;      vector<pair<int, int>> cur(K+1, {A[L], L});      vector<pair<int, int>> nxt(K+1);      int resp = 0;      auto is_done = [&](const vector<pair<int, int>>& v) {       for (int k = 0; k <= K; k++) {        if (v[k].first + (K-k) >= R) return true;       }       return false;      };      if (is_done(cur)) return 1;      int s = 0;      while (true) {       for (int k = 0; k <= K; k++) {        nxt[k] = dp[{s, L, k}];       }       if (is_done(nxt)) {        break;       } else {        resp = (1 << s);        s++;        std::swap(nxt, cur);       }      }         if (s) s--;         while (s) {       s--;       std::copy(cur.begin(), cur.end(), nxt.begin());       for (int k = 0; k <= K; k++) {        for (int l = 0; l <= K-k; l++) {         setmax(nxt[l+k], dp[{s, cur[k].second, l}]);        }       }       if (is_done(nxt)) {        // do nothing       } else {        resp += 1 << s;        std::swap(cur, nxt);       }      }      resp++;      return resp + 1;     }() <<   n ;    }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int anc[200007];   int sz[200007];   int x[200005], y[200005];   vector<int> g[200005];   int get_set(int v) {     if (v == anc[v]) {       return v;     }     return anc[v] = get_set(anc[v]);   }   void unite_sets(int u, int v) {     u = get_set(u);     v = get_set(v);     if (u == v) {       return;     }     if (sz[u] < sz[v]) {       swap(u, v);     }     sz[u] = sz[u] + sz[v];     anc[v] = u;   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> x[i] >> y[i];       g[x[i]].push_back(y[i]);       g[y[i]].push_back(x[i]);     }     for (int i = 0; i <= n; i++) {       sz[i] = 1;       anc[i] = i;     }     int mx = 0;     int z = 1;     for (int i = 1; i <= n; i++) {       if (g[i].size() > mx) {         mx = g[i].size();         z = i;       }     }     for (int i = 0; i < g[z].size(); i++) {       if (get_set(z) != get_set(g[z][i])) {         unite_sets(z, g[z][i]);         cout << z <<     << g[z][i] << endl;       }     }     for (int i = 0; i < m; i++) {       if (get_set(x[i]) != get_set(y[i])) {         unite_sets(x[i], y[i]);         cout << x[i] <<     << y[i] << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<long long> vec(n + 1);     for (int i = 1; i <= n; i++) cin >> vec[i];     vector<long long> a;     for (int i = 1; i < n; i++) {       if (i & 1)         a.push_back(abs(vec[i] - vec[i + 1]));       else         a.push_back(-1 * abs(vec[i] - vec[i + 1]));     }     vector<long long> dp((int)a.size());     dp[0] = a[0];     long long res = dp[0];     for (int i = 1; i < dp.size(); i++) {       dp[i] = max(a[i], dp[i - 1] + a[i]);       res = max(res, dp[i]);     }     dp.clear();     a.clear();     for (int i = 1; i < n; i++) {       if (!(i & 1))         a.push_back(abs(vec[i] - vec[i + 1]));       else         a.push_back(-1 * abs(vec[i] - vec[i + 1]));     }     dp = vector<long long>((int)a.size());     dp[0] = a[0];     long long res2 = dp[0];     for (int i = 1; i < dp.size(); i++) {       dp[i] = max(a[i], dp[i - 1] + a[i]);       res2 = max(res2, dp[i]);     }     cout << max(res, res2) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long x[100010];   long long y[100010];   long long dispoint(long long x1, long long y1, long long x2, long long y2) {     return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);   }   bool issame(long long x1, long long y1, long long x2, long long y2,               long long x3, long long y3) {     long long xa = x2 - x1;     long long ya = y2 - y1;     long long xb = x3 - x1;     long long yb = y3 - y1;     if (xa * yb == xb * ya)       return 1;     else       return 0;   }   double disline(long long x1, long long y1, long long x2, long long y2,                  long long x3, long long y3) {     double xa = x1 - x3;     double ya = y1 - y3;     double xb = x2 - x3;     double yb = y2 - y3;     double l = sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb));     double s = abs(xa * yb - xb * ya);     double h = s / l;     return h;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d%I64d , &x[i], &y[i]);     int pos1 = 2;     long long mindis = dispoint(x[1], y[1], x[2], y[2]);     for (int i = 3; i <= n; i++) {       long long tmpdis = dispoint(x[1], y[1], x[i], y[i]);       if (tmpdis < mindis) {         mindis = tmpdis;         pos1 = i;       }     }     int pos2 = 0;     double mindis2 = 1e18;     for (int i = 2; i <= n; i++) {       if (i == pos1) continue;       if (issame(x[1], y[1], x[pos1], y[pos1], x[i], y[i])) continue;       double tmpdis = disline(x[1], y[1], x[pos1], y[pos1], x[i], y[i]);       if (tmpdis < mindis2) {         mindis2 = tmpdis;         pos2 = i;       }     }     printf( 1 %d %d n , pos1, pos2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<int> ans;       for (int i = 0; i <= 400; i++) {         for (int j = 0; j <= 200; j++) {           long long x = 3 * i, y = 5 * j;           long long z = n - x - y;           if (z >= 0) {             if (z % 7 == 0) {               z = z / 7;               ans.push_back(x), ans.push_back(y), ans.push_back(7 * z);               break;             }           }         }         if (ans.size() == 3) break;       }       if (ans.size() != 3)         cout << -1 <<   n ;       else         cout << ans[0] / 3 <<     << ans[1] / 5 <<     << ans[2] / 7 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(false);     int T;     cin >> T;     while (T--) {       long long int n;       string second;       cin >> n;       cin >> second;       vector<char> v, v1;       int first = 0;       int f1 = 0;       int f2 = 0;       for (int i = n - 1; i >= 0; i--) {         if (first == 0 && second[i] ==  1 ) {           v.emplace_back(second[i]);         }         if (first == 0 && second[i] ==  0 ) {           v.emplace_back(second[i]);           first = 1;           f1 = i;           break;         }       }       for (int i = 0; i < n; i++) {         if (second[i] ==  0  && i < f1) {           v.emplace_back(second[i]);         }         if (second[i] ==  1 ) {           break;         }       }       reverse(v.begin(), v.end());       for (int i = 0; i < v.size(); i++) {         cout << v[i];       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   string direc =  RDLU ;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  YES  :  NO );     exit(0);   }   void addmod(int &x, int y, int mod = 1000000007) {     x += y;     if (x >= mod) x -= mod;   }   void et() {     puts( -1 );     exit(0);   }   long long a[100005], b[100005];   bool ck(long long r) {     for (int(i) = 1; (i) <= (int)(n); (i)++) {       long long L = a[i] - r, R = a[i] + r;       int p = upper_bound(b + 1, b + 1 + m, R) - (b + 1);       p--;       int q = lower_bound(b + 1, b + 1 + m, L) - (b + 1);       q--;       if (q >= p) return 0;     }     return 1;   }   void fmain() {     scanf( %d%d , &n, &m);     for (int(i) = 1; (i) <= (int)(n); (i)++) {       scanf( %lld , a + i);     }     for (int(i) = 1; (i) <= (int)(m); (i)++) scanf( %lld , b + i);     long long l = -1, r = 2e9;     while (l + 1 < r) {       long long mid = (l + r) / 2;       if (ck(mid))         r = mid;       else         l = mid;     }     printf( %lld n , r);   }   int main() {     fmain();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void ipgraph(long long n, long long m);   vector<vector<long long>> v;   vector<bool> vis;   long long p = pow(10, 9) + 7;   long long power(long long a, long long b, long long p) {     if (b == 0) return 1;     long long c = power(a, b / 2, p);     if (b % 2 == 0)       return ((c * c) % p);     else       return ((((c * c) % p) * a) % p);   }   long long sumod(long long n) {     long long ans = 0;     while (n) {       ans += n % 10;       n /= 10;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t, i, j, n, m, k, l;     t = 1;     while (t--) {       long long a, b, c;       cin >> a >> b >> c;       vector<long long> v;       for (long long i = 1; i < 82; i++) {         if (b * power(i, a, p) + c < pow(10, 9) && b * power(i, a, p) + c > 0 &&             sumod(b * power(i, a, p) + c) == i)           v.push_back(b * power(i, a, p) + c);       }       cout << v.size() <<   n ;       for (auto x : v) {         cout << x <<    ;       }       cout <<   n ;       ;     }     cerr << endl          <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;     return 0;   }   void ipgraph(long long n, long long m) {     v.assign(n, {});     vis.assign(n, 0);     long long x, y;     for (long long i = 0; i < m; i++) {       cin >> x >> y;       x--, y--;       v[x].push_back(y);       v[y].push_back(x);     }   }


#include <bits/stdc++.h>   using namespace std;   inline void in(int &x) {     x = 0;     int f = 1;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = x * 10 + s - 48;       s = getchar();     }     x *= f;   }   inline void out(int x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) out(x / 10);     putchar(x % 10 + 48);   }   int a[200005];   int main() {     int n, i, maxi = 0, p = -1;     in(n);     for (i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > maxi) {         maxi = a[i];         p = i;       }     }     for (i = p - 1; i >= 0; i--) {       if (a[i] >= a[i + 1]) {         cout <<  NO ;         return 0;       }     }     for (i = p + 1; i < n; i++) {       if (a[i] >= a[i - 1]) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   const double pi = acos(-1);   using namespace std;   vector<int> v;   int c[1000000];   int main() {     int n;     double h;     cin >> n >> h;     double s = h / (2 * double(n));     for (int i = 1; i < n; i++) {       printf( %.10f n , sqrt(s * 2 * h * i));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, num[105], ans = 0, i;   int main() {     scanf( %d , &n);     for (int j = 1; j <= n; ++j) scanf( %d , &num[j]);     if (n % 2 == 0 || n < 3) {       printf( -1 n );       return 0;     }     for (int i = n; i >= 3; i -= 2) {       int max_n = max(num[i], num[i - 1]);       if (max_n <= 0) continue;       ans += max_n;       num[i] -= max_n;       num[i - 1] -= max_n;       num[(i - 1) / 2] -= max_n;     }     if (num[1] > 0) ans += num[1];     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[100007];   int dis[100007];   void bfs() {     queue<int> q;     bool vis[100007];     memset(vis, false, sizeof(vis));     dis[1] = 1;     vis[1] = true;     q.push(1);     while (!q.empty()) {       int s = q.front();       q.pop();       for (auto u : adj[s]) {         if (vis[u]) continue;         vis[u] = true;         dis[u] = dis[s] + 1;         q.push(u);       }     }   }   void solve() {     int n;     cin >> n;     for (int i = 2; i <= n; ++i) {       int node;       cin >> node;       adj[node].emplace_back(i);     }     bfs();     set<int> st;     unordered_map<int, int> mp;     for (int i = 1; i <= n; ++i) {       st.insert(dis[i]);       mp[dis[i]]++;     }     int cnt = 0;     for (auto s : st) cnt += (mp[s] % 2);     cout << cnt;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[50];   double dp[51][51][51];   bool viz[51][51][51];   long long choose[51][51];   double go(int i, int j, int k) {     if (i == m - 1) return j <= a[i] * k;     double &d = dp[i][j][k];     if (viz[i][j][k]) return d;     double res = 0;     for (int l = 0; l <= min(j, a[i] * k); l++) {       res += choose[j][l] * pow(m - i - 1, j - l) / pow(m - i, j) *              go(i + 1, j - l, k);     }     viz[i][j][k] = 1;     return d = res;   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) cin >> a[i];     for (int i = 0; i <= n; i++) choose[i][0] = 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= i; j++)         choose[i][j] = choose[i - 1][j - 1] + choose[i - 1][j];     double r = 0;     for (int i = 1; i <= n; i++) {       double p = go(0, n, i) - go(0, n, i - 1);       r += i * p;     }     printf( %.9lf n , r);   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const bool debugger1 = 0;   const bool debugger2 = 0;   const bool debugger3 = 0;   const bool debugger4 = 0;   const bool debugger5 = 0;   const long long MOD = 1e9 + 7, P = 1e9 + 7;   long long n;   long long sca, scb;   std::vector<pair<long long, long long> > liczby;   int main() {     scanf( %lld , &n);     liczby.resize(2 * n);     for (int i = 0; i < n; i++)       scanf( %lld , &liczby[i].first), liczby[i].second = 1;     for (int i = 0; i < n; i++)       scanf( %lld , &liczby[n + i].first), liczby[n + i].second = 2;     for (int i = 0; i < 2 * n; i++) liczby[i].first *= (-1);     sort(liczby.begin(), liczby.end());     for (int i = 0; i < liczby.size(); i++) {       if (liczby[i].second == 1) {         if (i % 2 == 0) sca -= liczby[i].first;       } else if (i % 2 == 1)         scb -= liczby[i].first;     }     printf( %lld , sca - scb);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const int INF = 2e9;   const long long MOD = 1e9 + 7;   const int MAXN = 1e5 + 2;   const int MN = 1e6 + 3;   int d1, d2;   int p1, p2;   bool usual = 1;   int ans[MN];   int main() {     int n, q;     scanf( %d %d , &n, &q);     p1 = 0, p2 = 1;     int tipo, x;     int pareja;     for (int(i) = (0); (i) < (q); ++(i)) {       scanf( %d , &tipo);       if (tipo == 1) {         scanf( %d , &x);         p1 += x, p2 += x;       } else {         if (p1 % 2 == 0)           p1++;         else           p1--;         if (p2 % 2 == 0)           p2++;         else           p2--;       }       p1 %= n;       if (p1 < 0) p1 += n;       p2 %= n;       if (p2 < 0) p2 += n;     }     int tt;     for (int i = 0; i < n; i += 2) {       tt = (p1 + i) % n;       if (tt < 0) tt += n;       ans[tt] = i;     }     for (int i = 1; i < n; i += 2) {       tt = (p2 + i - 1) % n;       if (tt < 0) tt += n;       ans[tt] = i;     }     for (int(i) = (0); (i) < (n); ++(i)) printf( %d  , ans[i] + 1);     return 0;   }


#include <bits/stdc++.h>   int main() {     long double val = 0.0;     unsigned transistors = 0, seconds = 0;     std::cin >> transistors >> seconds;     std::cout.precision(25);     std::cout << (long double)transistors *                      powl(1.000000011, (long double)seconds)               << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const long long maxn = 2001;   long long h[maxn], dp[maxn][2 * maxn];   signed main() {     long long n, k;     scanf( %lld%lld , &n, &k);     for (long long i = 1; i <= n; i++) scanf( %lld , &h[i]);     dp[0][2001] = 1;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j < 2 * maxn; j++)         if (h[i] == h[i % n + 1])           dp[i][j] = k * dp[i - 1][j] % mod;         else           dp[i][j] = (dp[i - 1][j + 1] + dp[i - 1][j - 1] +                       (k - 2) * dp[i - 1][j] % mod) %                      mod;     }     long long ans = 0;     for (long long i = 1; i < maxn; i++) ans = (ans + dp[n][maxn + i]) % mod;     printf( %lld n , ans);   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:66777216 )   using namespace std;   typedef double LD;   const int N = 250000 + 5;   int n;   int b[N];   long long a[N];   const int L = 200;   const int E = N / L + 10;   long long mi[2][E];   long long S[2][E];   long long ad[E];   void F(int in) {     int s = in * L, f = min(n, (in + 1) * L);     S[0][in] = 0;     S[1][in] = 0;     mi[0][in] = 1;     mi[1][in] = 0;     for (int i = s; i < f; ++i) {       int ty = (i - s) % 2;       if (i - s <= 1) {         mi[ty][in] = a[i];         if (i != s) mi[ty][in] -= a[i - 1];         S[ty][in] += mi[ty][in];       } else {         S[ty][in] += a[i] - a[i - 1];         mi[ty][in] = min(mi[ty][in], S[ty][in]);       }     }   }   void updateblock(int j, int k) {     ad[j] += k;     S[0][j] += k;     mi[0][j] += k;   }   void update(int in, int l, int r, int k) {     int s = in * L, f = min(n, (in + 1) * L);     for (int i = s; i < f; ++i) a[i] += ad[in];     ad[in] = 0;     for (int i = l; i <= r; ++i) a[i] += k;     F(in);   }   void get(int in, int l, int r, long long s[2], long long mi[2]) {     s[0] = 0;     s[1] = 0;     mi[0] = 1;     mi[1] = 0;     for (int i = l; i <= r; ++i) {       int ty = (i - l) % 2;       if (i - l <= 1) {         mi[ty] = a[i] + ad[in];         if (i != l) mi[ty] -= a[i - 1] + ad[in];         s[ty] += mi[ty];       } else {         s[ty] += a[i] - a[i - 1];         mi[ty] = min(mi[ty], s[ty]);       }     }   }   int possible(int l, int r) {     int inl = l / L;     int inr = r / L;     long long gs[2], gmi[2];     if (inl == inr) {       get(inl, l, r, gs, gmi);     } else {       long long s[2];       long long mi[2];       get(inl, l, inl * L + L - 1, s, mi);       gs[0] = s[0], gs[1] = s[1];       gmi[0] = mi[0], gmi[1] = mi[1];       for (int j = inl + 1; j <= inr; ++j) {         int ty = (j * L - l) % 2;         long long val = ad[j - 1] + a[j * L - 1];         if (j != inr) {           s[0] = S[0][j];           s[1] = S[1][j];           mi[0] = ::mi[0][j];           mi[1] = ::mi[1][j];         } else {           get(inr, inr * L, r, s, mi);         }         if (ty == 0) {           gmi[0] = min(gmi[0], gs[0] + mi[0] - val);           gmi[1] = min(gmi[1], gs[1] + mi[1]);           gs[0] += s[0] - val;           gs[1] += s[1];         } else {           gmi[0] = min(gmi[0], gs[0] + mi[1]);           gmi[1] = min(gmi[1], gs[1] + mi[0] - val);           gs[0] += s[1];           gs[1] += s[0] - val;         }       }     }     if (l == r) {       return a[l] + ad[inl] == 1;     }     if (gmi[0] >= 1 && gmi[1] >= 0 &&         gs[(r - 1 - l) % 2] + (r - 1 - l) % 2 == a[r] + ad[inr])       return true;     return false;   }   void solve() {     scanf( %d , &n);     for (int i = 0; i < (int)(n); ++i) scanf( %d , &b[i]);     for (int i = 0; i < (int)(n); ++i) a[i] = b[i];     int m = (n + L - 1) / L;     for (int in = 0; in * L < n; ++in) F(in);     int Q;     scanf( %d , &Q);     for (int it = 1; it <= (int)(Q); ++it) {       int ty, l, r;       scanf( %d%d%d , &ty, &l, &r);       int k;       if (ty == 1) {         scanf( %d , &k);         int inl = l / L;         int inr = r / L;         for (int j = inl + 1; j <= inr - 1; ++j) {           updateblock(j, k);         }         if (inl == inr) {           update(inl, l, r, k);         } else {           update(inl, l, inl * L + L - 1, k);           update(inr, inr * L, r, k);         }       } else {         int res = possible(l, r);         printf( %d n , res);       }     }   }   void testgen() {     FILE* f = fopen( input.txt ,  w );     fclose(f);   }   int main() {     std::cout << std::fixed;     std::cout.precision(8);     std::cerr << std::fixed;     std::cerr.precision(3);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p, q, r, s, t, u;   int a[25];   int b[25];   int dp[25][25];   int n;   int c[25];   int sgn(int x) {     if (x > 0)       return 1;     else if (x < 0)       return -1;     else       return 0;   }   int main() {     int i, j;     int n, k, a, b;     cin >> n >> k >> a >> b;     int p = max(a, b);     int q = min(a, b);     if ((long long int)p > (long long int)(q + 1) * k) {       cout <<  NO  << endl;       return 0;     }     int cont = 0;     char last =  B ;     for (i = 1; i <= n; i++) {       if (a > b) {         if (last ==  B ) cont = 0;         if (cont < k) {           cout <<  G ;           cont++;           last =  G ;           a--;         } else {           cout <<  B ;           cont = 1;           last =  B ;           b--;         }         continue;       } else {         if (last ==  G ) cont = 0;         if (cont < k) {           last =  B ;           cout <<  B ;           cont++;           b--;         } else {           cout <<  G ;           cont = 1;           last =  G ;           a--;         }         continue;       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int prime[1000005];   int ans[5];   int idx;   set<int> s, s1;   set<int>::iterator it;   int main() {     int i, j;     for (i = 2; i <= 1000000; i++) {       if (prime[i] == 1) continue;       for (j = i + i; j <= 1000000; j += i) prime[j] = 1;     }     int n;     scanf( %d , &n);     if (n == 1)       printf( 1 n );     else if (n == 2)       printf( 2 n );     else {       long long sum = n;       for (i = 2; i < n; i++) {         if (n % i == 0) s.insert(i);       }       int countt = 0;       for (i = n - 1; i >= 1; i--) {         bool no = 0;         for (it = s.begin(); it != s.end(); it++) {           if (i % (*it) == 0) {             no = 1;             break;           }         }         if (!no) {           sum *= (long long)i;           countt++;         }         if (countt == 2) break;       }       long long sum1 = n - 1;       for (i = 2; i < n - 1; i++) {         if ((n - 1) % i == 0) s1.insert(i);       }       countt = 0;       for (i = n - 2; i >= 1; i--) {         bool no = 0;         for (it = s1.begin(); it != s1.end(); it++) {           if (i % (*it) == 0) {             no = 1;             break;           }         }         if (!no) {           sum1 *= (long long)i;           countt++;         }         if (countt == 2) break;       }       printf( %I64d n , max(sum, sum1));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, d;     cin >> n >> m >> d;     long long x, y, z, i, j, c = 1;     map<long long, long long> mp, mp2;     set<long long> st;     vector<long long> v;     for (i = 0; i < n; i++) {       cin >> x;       v.push_back(x);       st.insert(x);     }     for (auto i : st) {       if (mp[i] == 0) {         y = i;         mp[y] = 1;         mp2[y] = c;         while (st.upper_bound(y + d) != st.end()) {           auto it = st.upper_bound(y + d);           if (mp[*it] == 0) {             mp[*it] = 1;             mp2[*it] = c;           }           y = *it;           st.erase(it);         }         c++;       }     }     cout << c - 1 << endl;     for (i = 0; i < n; i++) {       cout << mp2[v[i]] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 400;   int dp[N + 1][N + 1];   bool solve(string str, string t1, string t2) {     int n = str.size();     int m = t1.size();     for (int j = 1; j <= m; ++j) dp[0][j] = -1;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j <= m; ++j) {         dp[i][j] = -1;         if (dp[i - 1][j] != -1) {           dp[i][j] = dp[i - 1][j];           if (dp[i][j] < t2.size() && str[i - 1] == t2[dp[i][j]]) ++dp[i][j];         }         if (j > 0 && str[i - 1] == t1[j - 1]) {           dp[i][j] = max(dp[i][j], dp[i - 1][j - 1]);         }       }     }     return dp[n][m] >= (int)t2.size();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int tc;     cin >> tc;     for (int ti = 0; ti < tc; ++ti) {       string src, tar;       cin >> src >> tar;       bool works = false;       for (int a = 1; a <= tar.size(); ++a) {         string le, ri;         for (int i = 0; i < a; ++i) le.push_back(tar[i]);         for (int i = a; i < tar.size(); ++i) ri.push_back(tar[i]);         if (solve(src, le, ri)) works = true;       }       if (works)         cout <<  YES n ;       else         cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[2010];   char str[1010];   int ans[2010];   int tmp[2010];   int main() {     int n;     cin >> n;     scanf( %s , str);     for (int i = 0; i < n; i++) {       a[i] = str[i] -  0 ;     }     for (int i = n; i < 2 * n; i++) {       a[i] = a[i - n];     }     for (int i = 0; i < n; i++) ans[i] = 9;     for (int i = 0; i < n; i++) {       int d = 10 - a[i];       for (int j = 0; j < n; j++) {         tmp[j] = (a[i + j] + d) % 10;       }       for (int j = 0; j < n; j++) {         if (tmp[j] < ans[j]) {           memcpy(ans, tmp, sizeof(tmp));           break;         } else if (tmp[j] > ans[j])           break;       }     }     for (int i = 0; i < n; i++) {       cout << ans[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int INT_MAX_VAL = (int)1e20;   int INT_MIN_VAL = (int)-1e20;   long long LONG_MAX_VAL = (long long)1e20;   long long LONG_MIN_VAL = (long long)-1e20;   long long C, Hr, Hb, Wr, Wb;   long long func(long long x) {     long long y = (C - Wb * x) / Wr;     return Hb * x + Hr * y;   }   long long solve() {     long long l = 0;     long long r = min(C / Wb, 10000000LL);     long long res = 0;     for (long long i = 0; i <= r; ++i) {       res = max(res, func(i));     }     return res;   }   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     cin >> C >> Hr >> Hb >> Wr >> Wb;     long long res1 = solve();     swap(Hr, Hb);     swap(Wr, Wb);     long long res2 = solve();     cout << max(res1, res2) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   struct node {     int l, r, id;   } a[maxn];   bool cmp(node a, node b) { return a.l < b.l; }   multiset<pair<int, int> > s;   vector<int> ans;   int main() {     multiset<pair<int, int> >::iterator it;     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i].l >> a[i].r;       a[i].id = i;     }     sort(a + 1, a + 1 + n, cmp);     for (int i = 1; i <= n; i++) {       while (s.size() && (*s.begin()).first < a[i].l) s.erase(s.begin());       s.insert(make_pair(a[i].r, a[i].id));       while (s.size() > k) {         multiset<pair<int, int> >::iterator it;         it = s.end();         it--;         ans.push_back((*it).second);         s.erase(it);       }     }     int len = ans.size();     cout << len << endl;     for (int i = 0; i < len; i++) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 1;   const int MOD = 1e9 + 7;   class Problem {    public:     int N, Q, t, k, d;     char ch;     string S;     void solve(std::istream& input, std::ostream& output);   };   void Problem::solve(std::istream& input, std::ostream& output) {     input >> N;     for (int i = sqrt(N); i >= 1; i--) {       if (N % i == 0) {         output << i <<     << N / i;         exit(0);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     std::istream& input(std::cin);     std::ostream& output(std::cout);     input.tie(0);     Problem _A;     _A.solve(input, output);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int visited[505], dp[505];   int d, x, y, flag;   vector<int> vec[505];   vector<pair<int, int> > adj;   int var[505];   void dfs(int u, int dist) {     visited[u] = 1;     d = max(d, dist);     for (int i = 0; i < vec[u].size(); i++) {       if ((u == x && vec[u][i] == y) || (u == y && vec[u][i] == x)) continue;       if (!visited[vec[u][i]]) {         dfs(vec[u][i], dist + 1);       }     }   }   int main() {     int n, ans = 0, fin = 0, temp;     cin >> n;     flag = 1;     for (int i = 0; i < n - 1; i++) {       scanf( %d %d , &x, &y);       vec[x].push_back(y);       vec[y].push_back(x);       adj.push_back(make_pair(x, y));     }     for (int i = 0; i < adj.size(); i++) {       x = adj[i].first, y = adj[i].second;       ans = 0;       memset(var, 0, sizeof(var));       memset(visited, 0, sizeof(visited));       d = 0;       dfs(x, 0);       for (int j = 1; j <= n; j++) {         if (visited[j]) {           var[j] = 1;         }       }       for (int j = 1; j <= n; j++) {         if (var[j]) {           d = 0;           memset(visited, 0, sizeof(visited));           dfs(j, 0);           ans = max(ans, d);         }       }       memset(visited, 0, sizeof(visited));       dfs(y, 0);       memset(var, 0, sizeof(var));       for (int j = 1; j <= n; j++) {         if (visited[j]) {           var[j] = 1;         }       }       temp = 0;       for (int j = 1; j <= n; j++) {         if (var[j]) {           d = 0;           memset(visited, 0, sizeof(visited));           dfs(j, 0);           temp = max(temp, d);         }       }       ans *= temp;       fin = max(fin, ans);     }     cout << fin;   }


#include <bits/stdc++.h>   using namespace std;   struct SegmentTree {     struct Node {       Node *lch, *rch;       long long sum;       Node() {         lch = rch = nullptr;         sum = 0;       }       void up() {         sum = 0;         if (lch != nullptr) sum += lch->sum;         if (rch != nullptr) sum += rch->sum;       }     } * root;     SegmentTree() { root = nullptr; }     void modify(int l, int r, int pos, int v, Node*& node) {       if (node == nullptr) node = new Node();       if (l == r) {         node->sum += v;       } else {         int mid = (l + r) >> 1;         if (pos <= mid)           modify(l, mid, pos, v, node->lch);         else           modify(mid + 1, r, pos, v, node->rch);         node->up();       }     }     long long query(int l, int r, int ql, int qr, Node* node) {       if (node == nullptr) return 0;       if (l == ql && r == qr) return node->sum;       int mid = (l + r) >> 1;       if (qr <= mid)         return query(l, mid, ql, qr, node->lch);       else if (ql > mid)         return query(mid + 1, r, ql, qr, node->rch);       else         return query(l, mid, ql, mid, node->lch) +                query(mid + 1, r, mid + 1, qr, node->rch);     }   } bit[100010];   int n;   inline int lowbit(int x) { return x & -x; }   inline void modify(int x, int y, int v) {     for (int i = x; i <= n; i += lowbit(i))       bit[i].modify(0, n, y, v, bit[i].root);   }   inline long long query(int pos, int ql, int qr) {     long long res = 0;     for (int i = pos; i > 0; i -= lowbit(i))       res += bit[i].query(0, n, ql, qr, bit[i].root);     return res;   }   inline long long Query(int xl, int xr, int yl, int yr) {     return query(xr, yl, yr) - query(xl - 1, yl, yr);   }   set<int> pos[100010];   int a[100010];   int main() {     int m, op, p, x, l, r;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) pos[i].insert(0);     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       auto it = pos[a[i]].end();       it--;       modify(i, *it, i - *it);       pos[a[i]].insert(i);     }     while (m--) {       scanf( %d , &op);       if (op == 1) {         scanf( %d%d , &p, &x);         auto it = pos[a[p]].find(p), it2 = it;         it2--;         it++;         modify(p, *it2, -(p - *it2));         if (it != pos[a[p]].end()) {           modify(*it, p, -(*it - p));           modify(*it, *it2, *it - *it2);         }         pos[a[p]].erase(p);         a[p] = x;         pos[x].insert(p);         it = pos[x].find(p), it2 = it;         it2--;         it++;         modify(p, *it2, p - *it2);         if (it != pos[x].end()) {           modify(*it, *it2, -(*it - *it2));           modify(*it, p, *it - p);         }       } else {         scanf( %d%d , &l, &r);         printf( %lld n , Query(l, r, l, r));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps(1e-8);   int n, m;   vector<long long> seq[100010];   long long a[100010];   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %I64d , &a[i]);     }     long long initial = 0;     a[0] = a[1];     a[m + 1] = a[m];     for (int i = 1; i <= m; i++) {       initial += abs(a[i] - a[i - 1]);     }     for (int i = 1; i <= m; i++) {       if (i - 1 != 0) {         if (a[i] != a[i - 1]) seq[a[i]].push_back(a[i - 1]);       }       if (i != m) {         if (a[i] != a[i + 1]) seq[a[i]].push_back(a[i + 1]);       }     }     long long tmp;     long long less;     long long ini;     long long answer = initial;     for (int i = 1; i <= n; i++) {       if (!seq[i].empty()) {         sort(seq[i].begin(), seq[i].end());         less = 0;         ini = 0;         tmp = seq[i][(seq[i].size() + 1) / 2 - 1];         for (int j = 0; j <= seq[i].size() - 1; j++) {           ini += abs(i - seq[i][j]);           less += abs(tmp - seq[i][j]);         }         less = initial - ini + less;         answer = min(answer, less);       }     }     printf( %I64d n , answer);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Scan();   int n, m, w, num;   double aver, cur[105];   vector<pair<int, double> > res[105];   double place(double V, int i) {     double D = aver - cur[num];     double L = min(D, V);     res[num].push_back(make_pair(i, L));     cur[num] += L;     if (fabs(cur[num] - aver) <= 1e-6) num++;     return fabs(V - L);   }   int main() {     scanf( %d%d%d , &n, &w, &m);     aver = (double)w * n / m;     num = 1;     memset(cur, 0, sizeof cur);     for (int i = 1; i <= n; ++i) {       double now = place(w, i);       if (now > 1e-6) now = place(now, i);     }     if (num != m + 1)       puts( NO );     else {       puts( YES );       for (int i = 1; i <= m; ++i) {         for (int j = 0; j < res[i].size(); ++j) {           printf( %d %.6lf , res[i][j].first, res[i][j].second);           j == res[i].size() - 1 ? puts(  ) : putchar(   );         }       }     }   }   int Scan() {     int res = 0, ch, flag = 0;     if ((ch = getchar()) ==  - )       flag = 1;     else if (ch >=  0  && ch <=  9 )       res = ch -  0 ;     while ((ch = getchar()) >=  0  && ch <=  9 ) res = res * 10 + ch -  0 ;     return flag ? -res : res;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, m;     cin >> n;     long long int ans = ((n % 10) - 1) * 10;     m = 1;     while (n > 0) {       ans += (m);       m++;       n /= 10;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     double ans = 0;     cin >> n;     for (int i = 0; i < n; i++) {       double x, y;       cin >> x >> y;       ans += y;     }     cout << 5 + ans / n;   }


#include <bits/stdc++.h>   using namespace std;   struct sans {     long long int t1;     long long int b1;   };   bool func(sans s1, sans s2) { return s1.t1 < s2.t1; }   long long int qw[2 * 100000 + 1];   pair<long long int, long long int> s1[2 * 100000 + 1];   int main() {     long long int t, n, i, j;     string s1, s2;     cin >> t;     while (t--) {       cin >> s1;       long long int flag = 0, flag1 = 0;       n = s1.length();       s2 =   ;       s2 = s2 + s1[0];       for (i = 1; i <= n - 1; i++) {         long long int j;         long long int flag = 0;         for (j = 0; j <= s2.length() - 1; j++) {           if (s1[i] == s2[j]) {             flag = 1;             break;           }         }         if (flag == 1) {           if (s1[i - 1] == s2[j + 1] || s1[i - 1] == s2[j - 1]) {             continue;           } else {             flag1 = 1;             cout <<  NO  << endl;             break;           }         } else {           long long int j;           for (j = 0; j <= s2.length() - 1; j++) {             if (s1[i - 1] == s2[j]) {               break;             }           }           if (j == 0) {             s2 = s1[i] + s2;           } else if (j == s2.length() - 1) {             s2 = s2 + s1[i];           } else {             flag1 = 1;             cout <<  NO  << endl;             break;           }         }       }       if (flag1 == 0) {         cout <<  YES  << endl;         long long int a1[27];         for (long long int i = 0; i <= 27; i++) a1[i] = 0;         ;         for (long long int j = 0; j < s2.length(); j++) {           a1[s2[j] -  a ] = 1;         }         for (long long int i = 0; i < 26; i++) {           if (a1[i] == 0) {             long long int qw = i +  a ;             char x = qw;             s2 = s2 + x;           }         }         cout << s2 << endl;       }     }   }


#include <bits/stdc++.h>      using namespace std;      #define int long long   #define double long double   #define FOR(i, n) for (signed i = 0; i < n; ++i)   #define ALL(x) x.begin(), x.end()   #define RALL(x) x.rbegin(), x.rend()   #define VI vector<int>   #define VII vector<VI>   #define PII pair<int, int>   #define PPII pair<int, PII>   #define make(type, x) type x; cin >> x   #define makev(x, n) VI x(n); FOR(I, n) cin >> x[I]   #define repeat(n) for(int J = n; J; --J)      #define M7 1000000007LL   #define M9 1000000009LL   #define MFFT 998244353LL   #define INF 2000000000000000000LL      void solveForSet() {       make(int, n);       map<int, VI> indices;       VI a;       for (int i = 0; i < n; ++i) {           make(int, t);           indices[t].push_back(i + 1);           a.push_back(t);       }       VI answers;       for (const auto &x: indices.rbegin()->second) {           answers.push_back(x);       }       sort(ALL(a));       VI pref(n + 1);       for (int i = 0; i < n; ++i) {           pref[i + 1] = pref[i] + a[i];       }       for (int i = n - 1; i > 0; --i) {           while (a[i - 1] == a[i])               --i;           if (i > 0 && pref[i] < a[i]) {               break;           }           for (const auto &x: indices[a[i - 1]]) {               answers.push_back(x);           }       }       sort(ALL(answers));       cout << answers.size() <<   n ;       for (const auto &x: answers) {           cout << x <<    ;       }       cout <<   n ;   }      void solve() {       make(int, t);       while (t--) {           solveForSet();       }   }      signed main(signed argc, char **argv) {       ios_base::sync_with_stdio(false);       cin.tie(nullptr);       if (argc > 1 && (string) argv[1] ==  local ) {           freopen( input.txt ,  r , stdin);           freopen( output.txt ,  w , stdout);           solve();           while (cin.peek() != EOF) {               if (isspace(cin.peek()))                   cin.get();               else {                   cout <<   n ;                   solve();               }           }       } else {           solve();       }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<long long> a, b;     for (int i = 0; i < n; i++) {       long long temp;       cin >> temp;       long long p = sqrt(temp);       if (p * p == temp)         a.push_back(temp);       else         b.push_back(temp);     }     if (a.size() > b.size()) {       int rem = a.size() - n / 2;       for (int i = 0; i < a.size(); i++) {         if (a[i] == 0)           a[i] = 2;         else           a[i] = 1;       }       sort(a.begin(), a.end());       long long c = 0;       for (int i = 0; i < a.size(); i++) {         if (rem == 0) break;         c += a[i];         rem--;       }       cout << c <<   n ;     } else if (b.size() > a.size()) {       int rem = b.size() - n / 2;       for (int i = 0; i < b.size(); i++) {         long long p = sqrt(b[i]);         b[i] = min(abs(p * p - b[i]), abs((p + 1) * (p + 1) - b[i]));       }       sort(b.begin(), b.end());       long long c = 0;       for (int i = 0; i < b.size(); i++) {         if (rem == 0) break;         c += b[i];         rem--;       }       cout << c <<   n ;     } else       cout <<  0 n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2000 + 10;   const double PI = acos(0.0) * 2;   const double eps = 1e-10;   const double STD = 0.999459;   const int dx[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};   const double One = 0.8;   int n;   char s[N];   double a[N][N], b[N][N], coef[10][10];   bool vi[N][N];   pair<int, int> q[N * N];   template <class T>   T sqr(T x) {     return x * x;   }   void GausscianBlur() {     for (int i = (1); i <= (n); i++)       for (int j = (1); j <= (n); j++) {         b[i][j] = 0.0;         for (int i1 = (i - 3); i1 <= (i + 3); i1++)           if (i1 > 0 && i1 <= n)             for (int j1 = (j - 3); j1 <= (j + 3); j1++)               if (j1 > 0 && j1 <= n) {                 b[i][j] += a[i1][j1] * coef[abs(i - i1)][abs(j - j1)];               }       }     memcpy(a, b, sizeof b);   }   void OutputGraph() {     freopen( output.txt ,  w , stdout);     for (int i = (1); i <= (n); i++) {       for (int j = (1); j <= (n); j++)         if (a[i][j] > One)           printf( 1 );         else           printf( 0 );       cout << endl;     }   }   int CntCircle, CntSquare;   void solve(int x0, int y0) {     int head = 1, tail = 1, xmin = x0, xmax = x0, ymin = y0, ymax = y0;     q[1] = make_pair(x0, y0);     vi[x0][y0] = 1;     while (head <= tail) {       int x = q[head].first, y = q[head].second;       head++;       xmin = min(xmin, x);       xmax = max(xmax, x);       ymin = min(ymin, y);       ymax = max(ymax, y);       for (int d = (0); d <= (3); d++) {         int x1 = x + dx[d][0], y1 = y + dx[d][1];         if (x1 < 1 || y1 < 1 || x1 > n || y1 > n || vi[x1][y1] || a[x1][y1] < One)           continue;         q[++tail] = make_pair(x1, y1);         vi[x1][y1] = 1;       }     }     if (tail < 150) return;     double cx = (xmin + xmax) / 2.0, cy = (ymin + ymax) / 2.0, r = 0.0;     for (int i = (1); i <= (tail); i++)       r = max(r, sqrt(sqr(cx - q[i].first) + sqr(cy - q[i].second)));     double P = tail / r / r;     if (P < 2.5)       CntSquare++;     else       CntCircle++;   }   int main() {     for (int i = (0); i <= (9); i++)       for (int j = (0); j <= (9); j++)         coef[i][j] = exp(-0.5 * (sqr(i) + sqr(j))) / 2 / PI / STD;     cin >> n;     for (int i = (1); i <= (n); i++)       for (int j = (1); j <= (n); j++) {         char ch;         do {           ch = getchar();         } while (ch !=  0  && ch !=  1 );         a[i][j] = (ch ==  1 ) ? 1.0 : 0.0;       }     for (int _ = (1); _ <= (1); _++) GausscianBlur();     for (int i = (1); i <= (n); i++)       for (int j = (1); j <= (n); j++)         if (!vi[i][j] && a[i][j] > One - eps) solve(i, j);     cout << CntCircle <<     << CntSquare << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int r1, c1, r2, c2;   int rook(int r1, int c1, int r2, int c2) {     if (r1 == r2 || c1 == c2) {       return 1;     } else {       return 2;     }   }   int bishop(int r1, int c1, int r2, int c2) {     if ((r1 + c1) % 2 == 0 && (r2 + c2) % 2 != 0) return 0;     if ((r1 + c1) % 2 != 0 && (r2 + c2) % 2 == 0) return 0;     if (abs(r1 - r2) == abs(c1 - c2))       return 1;     else       return 2;   }   int king(int r1, int c1, int r2, int c2) {     return (max(abs(r1 - r2), abs(c1 - c2)));   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> r1 >> c1 >> r2 >> c2;     cout << rook(r1, c1, r2, c2) <<    ;     cout << bishop(r1, c1, r2, c2) <<    ;     cout << king(r1, c1, r2, c2) <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const double eps = 1e-9;   const int inf = 1e9;   long long a[N];   long long dis[N];   int n, m;   vector<pair<int, long long> > adj[N];   void dij() {     set<pair<long long, int> > q;     for (int i = 1; i <= n; i++) {       dis[i] = a[i];       q.insert({dis[i], i});     }     while (q.size()) {       int u = q.begin()->second;       q.erase(q.begin());       for (auto i : adj[u]) {         long long ww = i.second;         int v = i.first;         if (dis[v] > dis[u] + ww) {           q.erase({dis[v], v});           dis[v] = dis[u] + ww;           q.insert({dis[v], v});         }       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int u, v;       long long w;       scanf( %d%d%lld , &u, &v, &w);       w *= 2;       adj[u].push_back({v, w});       adj[v].push_back({u, w});     }     for (int i = 1; i <= n; i++) scanf( %lld , a + i);     dij();     for (int i = 1; i <= n; i++) printf( %lld  , dis[i]);   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }   int main() {     string s;     cin >> s;     int a[26] = {0};     for (int i = 0; i < s.length(); i++) a[s[i] -  a ]++;     string ans = s;     for (int i = 0; i < s.length(); i++) ans[i] =  # ;     for (int i = 1; i < s.length(); i++) {       if (ans[i] !=  # ) continue;       int m = 0;       for (int j = 1; j < 26; j++)         if (a[j] > a[m]) m = j;       for (int j = 0; j < s.length(); j++)         if (ans[j] !=  #  && gcd(i + 1, j + 1) != 1) m = ans[j] -  a ;       for (int j = 0; j < s.length(); j++)         if (ans[j] ==  #  && gcd(i + 1, j + 1) != 1)           if (a[m] > 0) {             ans[j] = char(m +  a );             a[m]--;           } else {             cout <<  NO ;             return 0;           }     }     for (int j = 0; j < 26; j++)       if (a[j]) ans[0] = char(j +  a );     cout <<  YES n  + ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     cin >> a >> b;     int k = 0;     string star =  * ;     for (int i = 0; i < 12; i++) star = star + star;     a = star + a + star;     int res = 3000;     for (int i = 0; i < a.size(); i++) {       int u = 0;       for (int j = 0; j < b.size(); j++)         if (a[i + j] != b[j]) u++;       res = min(res, u);     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t;     cin >> s >> t;     reverse(t.begin(), t.end());     if (s == t)       cout <<  YES ;     else       cout <<  NO ;   }