#include <bits/stdc++.h>   using namespace std;   struct num {     static const int MA = 1e9 + 7, MB = 1e9 + 9;     int a, b;     num() {}     num(int x) : a(x), b(x) {}     num(int a, int b) : a(a), b(b) {}     num operator+(const num& x) const {       return num((a + x.a) % MA, (b + x.b) % MB);     }     num operator-(const num& x) const {       return num((a + MA - x.a) % MA, (b + MB - x.b) % MB);     }     num operator*(int x) const {       return num(((long long)a * x) % MA, ((long long)b * x) % MB);     }     num operator*(const num& x) const {       return num(((long long)a * x.a) % MA, ((long long)b * x.b) % MB);     }     bool operator==(const num& x) const { return a == x.a && b == x.b; }   };   struct num2 {     static const int MB = 1e9 + 9;     int b;     num2() {}     num2(int x) : b(x) {}     num2 operator+(const num2& x) const { return num2((b + x.b) % MB); }     num2 operator-(const num2& x) const { return num2((b + MB - x.b) % MB); }     num2 operator*(int x) const { return num2(((long long)b * x) % MB); }     num2 operator*(const num2& x) const {       return num2(((long long)b * x.b) % MB);     }     bool operator==(const num2& x) const { return b == x.b; }   };   const int MODP = 701;   template <class T>   struct StringOps {     StringOps() {}     StringOps(const string& s) : s(s) {       n = s.length();       deg.resize(n + 1);       hashes.resize(n);       deg[0] = T(1);       for (int i = 1; i <= n; ++i) {         deg[i] = deg[i - 1] * T(MODP);       }       T curhash = T(0);       for (int i = 0; i < n; ++i) {         curhash = curhash * T(MODP) + T(s[i]);         hashes[i] = curhash;       }     }     char get(int idx) { return s[idx]; }     T get_hash(int l, int r) {       T cur(0);       if (l > 0) {         cur = hashes[l - 1];       }       return hashes[r] - cur * deg[r - l + 1];     }     int string_lcp(int l, int r, int lim = 1e9) {       int cleft = 1, cright = min(n - r, n - l);       cright = min(lim, cright);       int res = 0;       while (cleft <= cright) {         int key = (cleft + cright) / 2;         if (s[l + key - 1] != s[r + key - 1]) {           cright = key - 1;         } else if (get_hash(l, l + key - 1) == get_hash(r, r + key - 1)) {           res = key;           cleft = key + 1;         } else {           cright = key - 1;         }       }       return res;     }     bool substring_cmp(int l1, int r1, int l2, int r2) {       int lcp = string_lcp(l1, l2);       int len1 = r1 - l1 + 1, len2 = r2 - l2 + 1;       if (lcp >= len1 && lcp >= len2) {         return len1 < len2;       }       if (lcp >= len1) {         return true;       }       if (lcp >= len2) {         return false;       }       return s[l1 + lcp] < s[l2 + lcp];     }     vector<T> hashes;     vector<T> deg;     string s;     int n;   };   const int maxN = 1000100;   const int MOD = 1e9 + 7;   int len1, len2;   int u, v;   StringOps<num2> sops;   int get_nlength(const pair<int, int>& a) {     if (a.first == u) {       if (a.second != len1) {         return len1 - 1;       } else {         return len1;       }     }     if (a.second != len2) {       return len2 - 1;     } else {       return len2;     }   }   void fill_segs(int& l1, int& r1, int& l2, int& r2, const pair<int, int>& a) {     if (a.first == u) {       l2 = r2 = -1;       if (a.second == 0) {         l1 = 1, r1 = len1 - 1;       } else if (a.second >= len1 - 1) {         l1 = 0, r1 = a.second - 1;       } else {         l1 = 0, r1 = a.second - 1;         l2 = a.second + 1, r2 = len1 - 1;       }       return;     }     l2 = r2 = -1;     if (a.second == 0) {       l1 = 1, r1 = len2 - 1;     } else if (a.second >= len2 - 1) {       l1 = 0, r1 = a.second - 1;     } else {       l1 = 0, r1 = a.second - 1;       l2 = a.second + 1, r2 = len2 - 1;     }     l1 += len1, r1 += len1;     if (l2 != -1) {       l2 += len1, r2 += len1;     }   }   int cmp2(vector<pair<int, int>>& a, vector<pair<int, int>>& b, int p1 = 0,            int p2 = 0) {     if (p1 == a.size() && p2 < b.size()) {       return -1;     }     if (p1 == a.size() && p2 == b.size()) {       return 0;     }     if (p2 == b.size() && p1 < a.size()) {       return 1;     }     if (p1 + 1 == a.size() && p2 + 1 == b.size() && a[0] == b[0]) {       return 0;     }     if (p1 + 2 == a.size() && p2 + 2 == b.size() && a[0] == b[0] &&         a[1] == b[1]) {       return 0;     }     if (sops.get(a[p1].first) != sops.get(b[p2].first)) {       char c1 = sops.get(a[p1].first);       char c2 = sops.get(b[p2].first);       if (c1 < c2) {         return -1;       }       return 1;     }     int lcp = sops.string_lcp(         a[p1].first, b[p2].first,         min(a[p1].second - a[p1].first + 1, b[p2].second - b[p2].first + 1));     lcp = min(         lcp, min(a[p1].second - a[p1].first + 1, b[p2].second - b[p2].first + 1));     int nx = a[p1].first + lcp - 1, ny = b[p2].first + lcp - 1;     if (nx >= a[p1].second) {       ++p1;     } else {       a[p1].first = nx + 1;     }     if (ny >= b[p2].second) {       ++p2;     } else {       b[p2].first = ny + 1;     }     return cmp2(a, b, p1, p2);   }   bool cmp(const pair<int, int>& a, const pair<int, int>& b) {     int nlen1 = get_nlength(a);     int nlen2 = get_nlength(b);     if (nlen1 == 0 && nlen2 == 0) {       if (a.first == u & b.first == v) {         return true;       }       return false;     }     if (nlen1 == 0) {       return true;     }     if (nlen2 == 0) {       return false;     }     int l1, r1, l2, r2;     fill_segs(l1, r1, l2, r2, a);     int p1, q1, p2, q2;     fill_segs(p1, q1, p2, q2, b);     vector<pair<int, int>> na;     vector<pair<int, int>> nb;     na.push_back(make_pair(l1, r1));     if (l2 != -1) {       na.push_back(make_pair(l2, r2));     }     nb.push_back(make_pair(p1, q1));     if (p2 != -1) {       nb.push_back(make_pair(p2, q2));     }     int val = cmp2(na, nb);     if (val == 0) {       if (a.first == u && b.first == v) {         return true;       }       return false;     }     return val == -1;   }   struct Node {     Node() { left = right = nullptr; }     int idxleft, idxright;     Node* left;     Node* right;   };   int curorder[maxN];   int lenorder;   void dfs(Node* root) {     if (!root) {       return;     }     if (root->left) {       dfs(root->left);     }     for (int i = root->idxleft; i <= root->idxright; ++i) {       curorder[lenorder] = i;       ++lenorder;     }     if (root->right) {       dfs(root->right);     }   }   pair<int, int> order[2][maxN];   int clen[2];   void get_order(const string& s, int p) {     int n = s.length();     Node* root = new Node();     Node* curnode = root;     for (int i = 0; i < n;) {       int cur = i;       while (cur < n && s[cur] == s[i]) {         ++cur;       }       curnode->idxleft = i, curnode->idxright = cur - 1;       if (cur == n) {         break;       }       if (s[i] < s[cur]) {         Node* left = new Node();         curnode->left = left;         curnode = curnode->left;       } else {         Node* right = new Node();         curnode->right = right;         curnode = curnode->right;       }       i = cur;     }     lenorder = 0;     dfs(root);     int ps = n;     for (int i = 0; i < n; ++i) {       if (curorder[i] == n - 1) {         ps = i + 1;         break;       }     }     vector<pair<int, int>> result;     clen[p] = 0;     for (int i = 0; i < ps; ++i) {       order[p][clen[p]] = make_pair(v, curorder[i]);       ++clen[p];     }     order[p][clen[p]] = make_pair(v, n);     ++clen[p];     for (int i = ps; i < n; ++i) {       order[p][clen[p]] = make_pair(v, curorder[i]);       ++clen[p];     }   }   int dp[2][maxN];   int dp2[2][maxN];   void gen() {     cout << 10 << endl;     for (int i = 0; i < 10; ++i) {       for (int j = 0; j < 100000; ++j) {         cout << char(rand() % 26 +  a );       }       cout << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vector<string> s(n);     for (int i = 0; i < n; ++i) {       cin >> s[i];     }     for (int i = 0; i <= s[0].length(); ++i) {       dp[u][i] = 1;       dp2[u][i] = 1;     }     sops = StringOps<num2>(s[0]);     len1 = 0, len2 = s[0].length();     u = 1, v = 0;     get_order(s[0], 0);     swap(u, v);     for (int i = 0; i + 1 < n; ++i) {       string& s1 = s[i];       string& s2 = s[i + 1];       string nw = s1 + s2;       len1 = s1.length(), len2 = s2.length();       sops = StringOps<num2>(nw);       get_order(s[i + 1], v);       int cadd = 0;       int head1 = 0, head2 = 0;       while (head1 < clen[u] || head2 < clen[v]) {         if (head1 == clen[u]) {           dp[v][order[v][head2].second] = cadd;           ++head2;         } else if (head2 == clen[v]) {           break;         } else {           if (cmp(order[u][head1], order[v][head2])) {             int nhead1 = head1;             while (nhead1 < clen[u] &&                    s1[order[u][nhead1].second] == s1[order[u][head1].second] &&                    order[u][nhead1].second - order[u][head1].second ==                        nhead1 - head1) {               ++nhead1;             }             for (int j = head1; j < nhead1; ++j) {               cadd += dp[u][order[u][j].second];               if (cadd >= MOD) {                 cadd -= MOD;               }             }             head1 = nhead1;           } else {             int nhead2 = head2;             while (nhead2 < clen[v] &&                    s2[order[v][nhead2].second] == s2[order[v][head2].second] &&                    order[v][nhead2].second - order[v][head2].second ==                        nhead2 - head2) {               ++nhead2;             }             for (int j = head2; j < nhead2; ++j) {               dp[v][order[v][j].second] = cadd;             }             head2 = nhead2;           }         }       }       swap(u, v);     }     int res = 0;     int res2 = 0;     for (int i = 0; i <= s.back().length(); ++i) {       res += dp[u][i];       if (res >= MOD) {         res -= MOD;       }       res2 += dp2[u][i];       if (res2 >= MOD) {         res2 -= MOD;       }     }     cout << res << endl;     cerr << (double)clock() / CLOCKS_PER_SEC << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     cin >> a;     vector<int> s(6);     for (int i = 0; i < 6; i++) {       if ((1 << i) & a) s[i]++;     }     int res = 0;     res += (16 * s[0]);     res += (2 * s[1]);     res += (8 * s[2]);     res += (4 * s[3]);     res += s[4];     res += (32 * s[5]);     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int l[6];   int main() {     int n, m, a;     cin >> m >> n;     for (int i = 0; i < m; i++) {       for (int i = 1; i <= n; i++) {         cin >> a;         l[i] = max(l[i - 1], l[i]) + a;       }       cout << l[n] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3fll;   const int qwq = 1 << 19;   int N, Q;   int a[qwq];   struct Query {     int r1, c1, r2, c2, id;     Query(int r1, int c1, int r2, int c2, int id)         : r1(r1), c1(c1), r2(r2), c2(c2), id(id) {}     bool inline operator<(const Query& a) const { return r2 < a.r2; }   };   struct Segtree {     int dt[qwq << 1];     void inline init() { memset(dt, Inf, sizeof(dt)); }     void inline add(int a, int x) {       a += qwq;       dt[a] = x;       while (a >>= 1) dt[a] = min(dt[a << 1], dt[a << 1 | 1]);     }     int inline get(int l, int r) {       int res = Inf;       for (l += qwq, r += qwq + 1; l < r; l >>= 1, r >>= 1) {         if (l & 1) res = min(res, dt[l++]);         if (r & 1) res = min(res, dt[--r]);       }       return res;     }   } sl, sr, qj;   vector<Query> q1, q2;   int ans[qwq];   vector<int> dd;   int inline mianx(int a, int l, int r) { return max(min(a, r), l); }   int inline Ubval(int val) {     int l = -1, r = ((int)(dd).size());     while (r - l > 1) {       int m = (l + r) >> 1;       if (a[dd[m]] > val)         r = m;       else         l = m;     }     return r;   }   int inline Lbpos(int val) {     return lower_bound((dd).begin(), (dd).end(), val) - dd.begin();   }   int inline FLbpos(int val) {     return upper_bound((dd).begin(), (dd).end(), val, greater<int>()) -            dd.begin();   }   void inline solve() {     int qid = 0;     sl.init();     sr.init();     qj.init();     for (int i = 1; i <= (N); ++i) qj.add(i, a[i]);     for (int i = 1; i <= (N); ++i) {       while (((int)(dd).size()) && a[dd.back()] >= a[i]) dd.pop_back();       sl.add(((int)(dd).size()), a[i] - 2 * i);       sr.add(((int)(dd).size()), -a[i] - 2 * i);       int rp = ((int)(dd).size());       dd.push_back(i);       while (qid < ((int)(q1).size()) && q1[qid].r2 == i) {         int id = q1[qid].id;         int r1 = q1[qid].r1, c1 = q1[qid].c1;         int r2 = q1[qid].r2, c2 = q1[qid].c2;         int lp = Lbpos(r1);         ans[id] = min(ans[id], r2 - r1 + c2 + 1);         ans[id] = min(ans[id], r2 - r1 + abs(min(c1, a[dd[lp]]) - c2));         int rpos = Ubval(c2), lpos = rpos - 1, pos;         rpos = mianx(rpos, lp, rp);         lpos = mianx(lpos, lp, rp);         if (abs(a[dd[lpos]] - c2) < abs(a[dd[rpos]] - c2))           pos = lpos;         else           pos = rpos;         ans[id] = min(ans[id], r2 - r1 + abs(a[dd[pos]] - c2) + 1);         rpos = Ubval(c2), lpos = rpos - 1;         rpos = mianx(rpos, 0, lp);         lpos = mianx(lpos, -1, lp - 1);         ans[id] = min(ans[id], r2 + r1 + sr.get(0, lpos) + c2 + 1);         ans[id] = min(ans[id], r2 + r1 + sl.get(rpos, lp - 1) - c2 + 1);         int sp = min(Ubval(min(c1, a[dd[lp]])), lp);         rpos = Ubval(c2), lpos = rpos - 1;         rpos = mianx(rpos, 0, sp);         lpos = mianx(lpos, -1, sp - 1);         ans[id] = min(ans[id], r2 + r1 + sr.get(0, lpos) + c2);         ans[id] = min(ans[id], r2 + r1 + sl.get(rpos, sp - 1) - c2);         ++qid;       }     }     dd.clear();     sl.init();     sr.init();     --qid;     for (int i = (N); ((-1) > 0 ? i <= (1) : i >= (1)); i += (-1)) {       while (((int)(dd).size()) && a[dd.back()] >= a[i]) dd.pop_back();       sl.add(((int)(dd).size()), a[i] + 2 * i);       sr.add(((int)(dd).size()), -a[i] + 2 * i);       int rp = ((int)(dd).size());       dd.push_back(i);       while (~qid && q1[qid].r2 == i) {         int id = q1[qid].id;         int r1 = q1[qid].r1, c1 = q1[qid].c1;         int r2 = q1[qid].r2, c2 = q1[qid].c2;         int rpos = Ubval(c2), lpos = rpos - 1;         rpos = mianx(rpos, 0, rp + 1);         lpos = mianx(lpos, -1, rp);         ans[id] = min(ans[id], sr.get(0, lpos) + c2 - r2 - r1 + 1);         ans[id] = min(ans[id], sl.get(rpos, rp) - c2 - r2 - r1 + 1);         int sp = min(Ubval(min(qj.get(r1, r2), c1)), rp);         rpos = Ubval(c2), lpos = rpos - 1;         rpos = mianx(rpos, 0, sp);         lpos = mianx(lpos, -1, sp - 1);         ans[id] = min(ans[id], sr.get(0, lpos) + c2 - r2 - r1);         ans[id] = min(ans[id], sl.get(rpos, sp - 1) - c2 - r2 - r1);         --qid;       }     }   }   int main() {     scanf( %d , &N);     for (int i = 1; i <= (N); ++i) scanf( %d , a + i);     scanf( %d , &Q);     memset(ans, Inf, sizeof(ans));     for (int i = 1; i <= (Q); ++i) {       int r1, c1, r2, c2;       scanf( %d%d%d%d , &r1, &c1, &r2, &c2);       if (r1 <= r2)         q1.push_back(Query(r1, c1, r2, c2, i));       else         q2.push_back(Query(N - r1 + 1, c1, N - r2 + 1, c2, i));     }     sort((q1).begin(), (q1).end());     solve();     reverse(a + 1, a + N + 1);     sort((q2).begin(), (q2).end());     q2.swap(q1);     solve();     for (int i = 1; i <= (Q); ++i) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   int main() {     float h, l;     scanf( %f %f , &h, &l);     float x = (l * l + h * h) / (2 * h) - h;     printf( %f n , x);     return 0;   }


#include <bits/stdc++.h>   int main() {     std::ios_base::sync_with_stdio(false);     int n;     std::cin >> n;     std::vector<std::vector<bool> > g(n, std::vector<bool>(n, 0));     for (int row = 0; row < n; row++) {       std::string s;       std::cin >> s;       for (int col = 0; col < s.size(); col++) {         g[row][col] = s[col] -  0 ;       }     }     std::vector<int> a(n);     for (int p = 0; p < n; p++) {       std::cin >> a[p];     }     bool done(false);     std::vector<int> guests;     while (!done) {       done = true;       for (int p = 0; p < n; p++) {         if (a[p] != 0) {           continue;         }         done = false;         guests.push_back(p);         for (int q = 0; q < n; q++) {           a[q] -= g[p][q];         }         break;       }     }     std::cout << guests.size() << std::endl;     for (int p = 0; p < guests.size(); p++) {       std::cout << (1 + guests[p]) << std::endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int a[111][111][111];   int color[111][111][111], cc;   char second[111];   void visit(queue<pair<pair<int, int>, int> >* q, int x, int y, int z) {     if (a[x][y][z] == 1 && color[x][y][z] != cc) {       color[x][y][z] = cc;       q->push(make_pair(make_pair(x, y), z));     }   }   void go(int x, int y, int z, int mx, int my, int mz) {     assert(a[x][y][z] == 1);     if (mx > n) mx = n;     if (my > m) my = m;     if (mz > k) mz = k;     ++cc;     queue<pair<pair<int, int>, int> > q;     color[x][y][z] = cc;     q.push(make_pair(make_pair(x, y), z));     while (!q.empty()) {       pair<pair<int, int>, int> fr = q.front();       q.pop();       int x = fr.first.first;       int y = fr.first.second;       int z = fr.second;       if (x + 1 <= mx) visit(&q, x + 1, y, z);       if (y + 1 <= my) visit(&q, x, y + 1, z);       if (z + 1 <= mz) visit(&q, x, y, z + 1);     }   }   bool reachable(int x, int y, int z) {     if (x + 1 < n && a[x + 1][y][z] == 1 && color[x + 1][y][z] != cc) {       return false;     }     if (y + 1 < m && a[x][y + 1][z] == 1 && color[x][y + 1][z] != cc) {       return false;     }     if (z + 1 < k && a[x][y][z + 1] == 1 && color[x][y][z + 1] != cc) {       return false;     }     return true;   }   bool critical(int x, int y, int z) {     if (x > 0 && a[x - 1][y][z] == 1) {       go(x - 1, y, z, x + 1, y + 1, z + 1);       if (!reachable(x, y, z)) {         return true;       }     }     if (y > 0 && a[x][y - 1][z] == 1) {       go(x, y - 1, z, x + 1, y + 1, z + 1);       if (!reachable(x, y, z)) {         return true;       }     }     if (z > 0 && a[x][y][z - 1] == 1) {       go(x, y, z - 1, x + 1, y + 1, z + 1);       if (!reachable(x, y, z)) {         return true;       }     }     return false;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         scanf( %s , second);         for (int t = 0; t < k; t++) {           a[i][j][t] = (second[t] ==  1 );         }       }     }     int res = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         for (int t = 0; t < k; t++) {           if (a[i][j][t] == 1) {             a[i][j][t] = 0;             res += critical(i, j, t);             a[i][j][t] = 1;           }         }       }     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1005;   long long n, m, q, ans;   bool vizitat[N][N];   long long dp[N][N][2];   bool verifica(long long i, long long j) {     if (i < 1 || j < 1 || i > n || j > m) return false;     return true;   }   long long cnt(long long i, long long j) {     long long answer = 0;     for (long long it = 0; it <= 1; it++) {       long long up = 0;       long long lin = i;       long long col = j;       while (verifica(lin, col) && vizitat[lin][col] == false) {         if (up % 2 == it) {           lin--;         } else {           col--;         }         up++;       }       long long down = 0;       lin = i;       col = j;       while (verifica(lin, col) && vizitat[lin][col] == false) {         if (down % 2 == it) {           col++;         } else {           lin++;         }         down++;       }       answer += up * down;     }     answer--;     return answer;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> q;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= m; j++) {         dp[i][j][1] = dp[i][j - 1][0] + 1;         dp[i][j][0] = dp[i - 1][j][1] + 1;         ans += dp[i][j][1];         ans += dp[i][j][0];       }     }     ans -= n * m;     while (q--) {       long long lin, col;       cin >> lin >> col;       if (vizitat[lin][col] == true) {         vizitat[lin][col] = false;         ans += cnt(lin, col);       } else {         ans -= cnt(lin, col);         vizitat[lin][col] = true;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define pb push_back   #define ll long long   #define ff first   #define ss second      void solve()   {       int n;      cin>>n;         int sum=0;      int cnt=1;         while(sum<n)      {        sum+=cnt;        cnt+=1;      }      if(sum-1==n)       cout<<cnt;     else       cout<<cnt-1;     cout<<  n ;           }            int main()   {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       #ifndef ONLINE_JUDGE          freopen( input.txt , r ,stdin);          freopen( output.txt , w ,stdout);        #endif       int q=1;       cin>>q;          while(q--)     {          solve();         }         return 0;               }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int ar[n + 5];     int br[n + 5];     int mark[200005];     memset(mark, 0, sizeof mark);     for (int i = 0; i < n; i++) {       cin >> ar[i];       br[i] = ar[i];     }     sort(br, br + n, greater<int>());     int sum = 0;     int cr[n + 5];     int c = 0;     for (int i = 0; i < k; i++) {       sum += br[i];       for (int j = 0; j < n; j++) {         if (br[i] == ar[j]) {           ar[j] = 0;           cr[c++] = j;         }       }     }     sort(cr, cr + k);     cout << sum << endl;     if (k == 1)       cout << n << endl;     else {       for (int i = 0; i < k; i++) {         if (i == 0) {           cout << cr[i] + 1 <<    ;         } else if (i == k - 1) {           int p = cr[i] - cr[i - 1];           p += n - cr[i] - 1;           cout << p << endl;         } else {           cout << cr[i] - cr[i - 1] <<    ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long rdtsc() {     long long tmp;     asm( rdtsc  :  =A (tmp));     return tmp;   }   inline int myrand() { return abs((rand() << 15) ^ rand()); }   inline int rnd(int x) { return myrand() % x; }   void precalc() {}   const int inf = (int)1.01e9;   const int n = 4;   int xs[n][2];   bool read() {     for (int i = 0; i < 4; ++i) {       if (scanf( %d%d , &xs[i][0], &xs[i][1]) < 2) {         return false;       }     }     return true;   }   int res;   int axs[n][2];   int perm[4];   int calcans(int x[2], int y[2]) {     for (int i = 0; i < n; ++i) {       perm[i] = i;     }     int cres = inf;     do {       int cur = 0;       for (int i = 0; i < n; ++i) {         int cx = xs[perm[i]][0], cy = xs[perm[i]][1];         int nx = x[i / 2], ny = y[i % 2];         if (cx != nx && cy != ny) {           cur = inf;           break;         }         cur = max(cur, max(abs(cx - nx), abs(cy - ny)));       }       if (res > cur) {         res = cur;         for (int i = 0; i < n; ++i) {           axs[perm[i]][0] = x[i / 2];           axs[perm[i]][1] = y[i % 2];         }       }       cres = min(cres, cur);     } while (next_permutation(perm, perm + 4));     return cres;   }   int dir[n];   map<int, vector<int> *> o[2];   void updans() {     o[0].clear();     o[1].clear();     for (int i = 0; i < n; ++i) {       int x = xs[i][dir[i]];       auto it = o[dir[i]].find(x);       vector<int> *v;       if (it != o[dir[i]].end()) {         v = it->second;       } else {         v = new vector<int>();         o[dir[i]][x] = v;       }       v->push_back(i);     }     int mx = max(((int)(o[0]).size()), ((int)(o[1]).size()));     int mn = min(((int)(o[0]).size()), ((int)(o[1]).size()));     if (mx != 2) {       return;     }     int x[2], y[2];     int cntx = 0, cnty = 0;     for (auto it : o[0]) {       x[cntx++] = it.first;     }     for (auto it : o[1]) {       y[cnty++] = it.first;     }     if (mn == 2) {       if (abs(x[1] - x[0]) != abs(y[1] - y[0])) {         return;       }       calcans(x, y);       return;     }     if (mn == 1) {       if (cntx == 1) {         int dist = abs(y[1] - y[0]);         for (int it = 0; it < 2; ++it) {           x[1] = x[0] + (it ? (-dist) : dist);           calcans(x, y);         }       } else {         int dist = abs(x[1] - x[0]);         for (int it = 0; it < 2; ++it) {           y[1] = y[0] + (it ? (-dist) : dist);           calcans(x, y);         }       }       return;     }     if (mn == 0) {       if (cntx == 0) {         int dist = abs(y[1] - y[0]);         int L = -inf, R = inf;         while (R - L > 1) {           int M = (L + R) / 2;           x[0] = M, x[1] = M + dist;           int curl = calcans(x, y);           x[0] = M + 1, x[1] = M + 1 + dist;           int curr = calcans(x, y);           if (curl >= curr) {             L = M;           } else {             R = M;           }         }         x[0] = L, x[1] = L + dist;         calcans(x, y);         x[0] = R, x[1] = R + dist;         calcans(x, y);       } else {         int dist = abs(x[1] - x[0]);         int L = -inf, R = inf;         while (R - L > 1) {           int M = (L + R) / 2;           y[0] = M, y[1] = M + dist;           int curl = calcans(x, y);           y[0] = M + 1, y[1] = M + 1 + dist;           int curr = calcans(x, y);           if (curl >= curr) {             L = M;           } else {             R = M;           }         }         y[0] = L, y[1] = L + dist;         calcans(x, y);         y[0] = R, y[1] = R + dist;         calcans(x, y);       }     }   }   void gen(int i) {     if (i == 4) {       updans();       return;     }     dir[i] = 0;     gen(i + 1);     dir[i] = 1;     gen(i + 1);   }   void solve() {     res = inf;     gen(0);     if (res == inf) {       printf( -1 n );       return;     }     printf( %d n , res);     for (int i = 0; i < 4; ++i) {       printf( %d %d n , axs[i][0], axs[i][1]);     }   }   int main() {     srand(rdtsc());     precalc();     int T = 0;     scanf( %d , &T);     for (int tn = 0; tn < T; ++tn) {       assert(read());       solve();     }     return 0;   }


#include <bits/stdc++.h>   const long long MAX_N = 450 + 100;   const long long MOD = 1e9 + 7;   using namespace std;   int main() {     int n, k;     cin >> n >> k;     cout << 3 * n + min(k - 1, n - k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int m, q;   int a[3];   string dday;   int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   string tostring(int x) {     string temp =   ;     for (int i = 0; i < 2; i++) {       temp = (char)( 0  + x % 10) + temp;       x /= 10;     }     return temp;   }   bool solve() {     sort(a, a + 3);     do {       if (a[1] > 12) continue;       if (a[2] % 4 == 0) {         if (a[1] == 2 && a[0] > 29) continue;       } else if (a[1] == 2 && a[0] > 28)         continue;       if (a[1] != 2 && a[0] > days[a[1] - 1]) continue;       a[2] += 18;       if (a[2] > 100) continue;       string temp = tostring(a[2]);       temp.push_back( . );       temp += tostring(a[1]);       temp.push_back( . );       temp += tostring(a[0]);       if (temp <= dday) {         return true;       }       a[2] -= 18;     } while (next_permutation(a, a + 3));     return false;   }   int main() {     scanf( %d.%d.%d , &a[0], &a[1], &a[2]);     dday = tostring(a[2]);     dday.push_back( . );     dday += tostring(a[1]);     dday.push_back( . );     dday += tostring(a[0]);     scanf( %d.%d.%d , &a[0], &a[1], &a[2]);     if (solve())       cout <<  YES n ;     else       cout <<  NO n ;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     if (n == 0) {       printf( 1 );     } else if (n % 2 == 0) {       if (n % 4 == 0) {         printf( 6 );       } else {         printf( 4 );       }     } else if (n % 2 != 0) {       if (n % 4 == 1) {         printf( 8 );       } else {         printf( 2 );       }     }     return 0;   }


#include <bits/stdc++.h>      #define fi first   #define se second   #define mp make_pair      using namespace std;   using ll = long long;   using pii = pair<int, int>;      constexpr double eps = 1e-8;   constexpr int NINF = 0xc0c0c0c0;   constexpr int INF = 0x3f3f3f3f;   constexpr ll mod = 1e9 + 7;   constexpr ll N = 1e6 + 5;      int n, a[N], f[N], l[N], r[N], cnt[N];      int main() {       ios::sync_with_stdio(false);       cin.tie(nullptr);          cin >> n;       for (int i = 1; i <= n; i++) {           cin >> a[i];           if (!l[a[i]]) l[a[i]] = i;       }       for (int i = n; i; i--) {           if (!r[a[i]]) r[a[i]] = i;       }       for (int i = n; i; i--) {           cnt[a[i]]++;           if (i == l[a[i]]) {               f[i] = max(cnt[a[i]] + f[r[a[i]] + 1], f[i + 1]);           } else {               f[i] = max(cnt[a[i]], f[i + 1]);           }       }       cout << n - f[1] <<   n ;          return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 1e9 + 5;   const int N = 1e6 + 5;   long long ans = 0;   int main() {     int n;     cin >> n;     int a[n + 1];     for (int(i) = (0); (i) < (n); i++) {       cin >> a[i];     }     sort(a, a + n);     int x;     x = (n - 1) / 2;     cout << a[x];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     while (T--) {       int n;       cin >> n;       int a[n];       bool ok = true;       bool f = true;       for (int i = 0; i < n; i++) {         cin >> a[i];         if (!ok) continue;         if (f && a[i] < i) {           f = false;         }         if (!f && a[i] < n - i - 1) ok = false;       }       if (n % 2 == 0 && a[n / 2] == (n / 2 - 1) && a[n / 2 - 1] == (n / 2 - 1))         ok = false;       if (ok)         cout <<  Yes n ;       else         cout <<  No n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<char, int> mp1;   int main() {     ios_base::sync_with_stdio(0);     string s, p, q;     long long int a, b, c, d, i, j, k, u, v, w = 0, x, y, z;     cin >> p;     for (i = 0; i < p.length(); i++) mp1[p[i]] = 1;     cin >> s;     cin >> k;     while (k--) {       w = 0;       cin >> q;       if (s.length() > q.length() + 1) {         cout <<  NO  << endl;         continue;       }       for (i = 0; i < q.length() && i < s.length(); i++) {         if (q[i] == s[i]) continue;         if (s[i] ==  ?  && mp1[q[i]] == 1) continue;         if (s[i] ==  * ) {           w = 1;           v = s.length() - 1;           for (u = q.length() - 1; v > i && u >= i; u--, v--) {             if (q[u] == s[v]) continue;             if (s[v] ==  ?  && mp1[q[u]] == 1) continue;             break;           }         } else {           cout <<  NO  << endl;           w = -1;           break;         }         if (v != i) {           w = -1;           cout <<  NO  << endl;           break;         }         for (j = u; j >= i; j--) {           if (mp1[q[j]] == 0) continue;           break;         }         if (j >= i) {           w = -1;           cout <<  NO  << endl;           break;         }         i = q.length() - 1;       }       if (w == -1) continue;       if (i != q.length()) {         cout <<  NO  << endl;         continue;       }       if (s.length() == q.length() + 1 && w == 0 && s[q.length()] !=  * ) {         cout <<  NO  << endl;         continue;       }       cout <<  YES  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 7;   const long long MOD = 1e9 + 7;   template <class T>   bool umin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool umax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool umod(T& a, T b) {     a += b;     while (a < 0) a += MOD;     a %= MOD;     return 1;   }   int las, n, cur, cost[N], m, cst;   vector<int> v[N];   vector<long long> par[N];   long long ans;   void merge(int x) {     v[x].push_back(0);     int l = x * 2, r = x * 2 + 1;     int a = 0, b = 0;     while (a < int(v[l].size()) && b < int(v[r].size())) {       if (v[l][a] + cost[l] <= v[r][b] + cost[r])         v[x].push_back(v[l][a] + cost[l]), a++;       else         v[x].push_back(v[r][b] + cost[r]), b++;     }     while (a < int(v[l].size())) v[x].push_back(v[l][a] + cost[l]), a++;     while (b < int(v[r].size())) v[x].push_back(v[r][b] + cost[r]), b++;     par[x].push_back(0LL);     for (int i = 1; i < int(v[x].size()); i++)       par[x].push_back(par[x][i - 1] + v[x][i]);   }   void dfs(int x) {     if (x > n) return;     dfs(x * 2);     dfs(x * 2 + 1);     merge(x);   }   long long get(int x, int y) {     if (x > n || y <= 0) return 0;     int ind = upper_bound(v[x].begin(), v[x].end(), y) - v[x].begin();     return 0LL + (1LL * ind * y) - par[x][ind - 1];   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 2; i <= n; i++) scanf( %d , &cost[i]);     dfs(1);     while (m--) {       int aa, bb;       scanf( %d%d , &aa, &bb);       las = -1, cur = aa, ans = 0, cst = bb;       while (las != 1 && cst > 0) {         if (las != cur * 2) ans += get(cur * 2, cst - cost[cur * 2]);         if (las != cur * 2 + 1) ans += get(cur * 2 + 1, cst - cost[cur * 2 + 1]);         ans += cst;         cst -= cost[cur];         las = cur;         cur /= 2;       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int a[maxn], x[maxn], y[maxn], sk[maxn], top, cnt;   int main() {     int n, P, ly = -1, fl = 0;     scanf( %d , &n), P = n;     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = n; i >= 1; i--) {       if (a[i] == 1) {         sk[++top] = x[++cnt] = P--;         y[cnt] = i;         if (!fl) ly = i;       } else if (a[i] == 2) {         if (top <= 0) return puts( -1 ), 0;         x[++cnt] = sk[top--];         y[cnt] = i;         if (!fl) ly = i;         P = min(P, x[cnt] - 1);       } else if (a[i] == 3) {         if (ly == -1) return puts( -1 ), 0;         x[++cnt] = P;         y[cnt] = ly;         x[++cnt] = P;         y[cnt] = ly = i;         if (!fl) top--;         fl = 1;         P--;       }     }     printf( %d n , cnt);     for (int i = 1; i <= cnt; i++) printf( %d %d n , x[i], y[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     double x, y;   };   int main() {     point p;     double a, b, c, d;     point v;     scanf( %lf%lf%lf%lf%lf%lf%lf%lf , &p.x, &p.y, &v.x, &v.y, &a, &b, &c, &d);     double lenth = sqrt(v.x * v.x + v.y * v.y);     v.x /= lenth;     v.y /= lenth;     a /= 2;     c /= 2;     point q;     q.x = p.x + v.x * b;     q.y = p.y + v.y * b;     printf( %.10f %.10f n , q.x, q.y);     q.x = p.x - v.y * a;     q.y = p.y + v.x * a;     printf( %.10f %.10f n , q.x, q.y);     q.x = p.x - v.y * c;     q.y = p.y + v.x * c;     printf( %.10f %.10f n , q.x, q.y);     point w;     w.x = q.x - v.x * d;     w.y = q.y - v.y * d;     printf( %.10f %.10f n , w.x, w.y);     q.x = w.x + v.y * c * 2;     q.y = w.y - v.x * c * 2;     printf( %.10f %.10f n , q.x, q.y);     q.x = p.x + v.y * c;     q.y = p.y - v.x * c;     printf( %.10f %.10f n , q.x, q.y);     q.x = p.x + v.y * a;     q.y = p.y - v.x * a;     printf( %.10f %.10f n , q.x, q.y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long N, M, K, R, l, r, A, B, X, Y, Z, C, D, Q, a, b, c, d, i, j, k, first,       mx, ans, cnt, T, P;   void solve() {     cin >> N >> K;     long long A[N];     long long lar = INT_MIN, sma = INT_MAX;     for (long long int i = 0; i < N; i++) {       cin >> A[i];       lar = max(lar, A[i]);       sma = min(sma, A[i]);     }     for (long long int i = 0; i < N; i++) {       A[i] = lar - A[i];     }     if (K % 2 == 0) {       for (long long int i = 0; i < N; i++) {         A[i] = lar - sma - A[i];       }     }     for (long long int i = 0; i < N; i++) {       cout << A[i] <<    ;     }     cout <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mini(long long a, long long b) {     if (a < b) return a;     return b;   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     vector<long long> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     sort(a.begin(), a.end());     reverse(a.begin(), a.end());     for (int i = 1; i < n; ++i) a[i] += a[i - 1];     vector<long long> odp(n, 0);     for (int i = 1; i <= n - 1; ++i) {       for (long long il = 1, pos = 0, w = 0; pos < n; pos += il, il *= i, ++w) {         odp[i] += w * a[mini(n - 1, pos + il - 1)];         if (pos != 0) odp[i] -= w * a[pos - 1];       }     }     int q;     cin >> q;     for (int i = 0; i < q; ++i) {       int k;       cin >> k;       k = mini(k, n - 1);       cout << odp[k] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const long long INFLL = 2e18;   const int MOD = 1e8 + 7;   const int N = 4e5 + 10;   int fx[8] = {+0, +0, +1, -1, +1, +1, -1, -1};   int fy[8] = {+1, -1, +0, +0, +1, -1, +1, -1};   int timer;   int used[N];   int tin[N], low[N];   char bridge;   vector<int> g[N];   void dfsAP(int v, int p = -1) {     if (bridge) return;     used[v] = 1;     tin[v] = low[v] = ++timer;     for (int to : g[v]) {       if (p == to) continue;       if (!used[to]) {         dfsAP(to, v);         low[v] = min(low[v], low[to]);         if (tin[v] < low[to]) bridge = 1;       } else {         low[v] = min(low[v], tin[to]);       }     }     used[v] = 2;   }   void dfsCC(int v, int p = -1) {     used[v] = 1;     for (int to : g[v]) {       if (p == to) continue;       if (!used[to]) {         dfsCC(to, v);         printf( %d %d n , v, to);       } else if (used[to] == 1) {         printf( %d %d n , v, to);       }     }     used[v] = 2;   }   void solve(int n) {     dfsAP(1);     if (bridge) {       puts( 0 );       return;     }     fill(used, used + n + 1, 0);     dfsCC(1);   }   int main() {     int n, m, u, v;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; ++i) {       scanf( %d %d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     solve(n);   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char** argv) {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int a, b, c;       cin >> a >> b >> c;       int sum1 = a + b;       int cnt = 0;       while (sum1 <= c) {         if (a > b) swap(a, b);         a += b;         cnt++;         sum1 += b;       }       cout << cnt + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int g[100000];   int res[100000];   int main() {     int N;     scanf( %d , &N);     ;     g[0] = 0;     g[1] = 0;     res[0] = res[1] = -1;     for (int(n) = 2; n < (int)N + 1; n++) {       set<int> s;       vector<int> v;       for (int i = 2; i * i <= 2 * n; i++) {         if ((2 * n) % i == 0) {           v.push_back(i);           v.push_back((2 * n) / i);         }       }       res[n] = -1;       for (__typeof(v).begin() it = v.begin(); it != v.end(); it++) {         int help = 2 * n / (*it) + *it - 1;         if (help % 2 == 0 && help / 2 >= *it && help / 2 < n) {           int num = 0;           for (int m = 0; m < *it; m++) {             num = num ^ g[help / 2 - m];           }           if (num == 0) {             res[n] = res[n] == -1 ? *it : min(res[n], *it);           }           s.insert(num);         }       }       int sol = 0;       while (s.find(sol) != s.end()) {         sol++;       }       g[n] = sol;     }     if (g[N] == 0) {       puts( -1 );     } else {       printf( %d n , res[N]);     }   }


//   //  main.cpp   //  D - Epic Transformation   //   //  Created by LiZnB on 2021/3/25.   //   #include <cstdio>   #include <cstring>   #include <algorithm>      #define ls tree[pos].l   #define rs tree[pos].r   using namespace std;      const int INF = 0x3f3f3f3f;   const int N = 200000 + 10;      int arr[N];      struct Node {       int l, r;       long long val;       int real;   };      Node max(Node a, Node b) {       if (a.val > b.val) return a;       return b;   }      struct Tree {       Node tree[N * 4];              void Built(int L, int R, int pos) {           ls = L;           rs = R;           if (L == R) {               tree[pos].val = arr[L];               tree[pos].real = L;               return;           }           int m = L + (R - L) / 2;           Built(L, m, pos << 1);           Built(m + 1, R, pos << 1 | 1);           if (tree[pos << 1].val > tree[pos << 1 | 1].val) {               tree[pos].val = tree[pos << 1].val;               tree[pos].real = tree[pos << 1].real;           } else {               tree[pos].val  = tree[pos << 1 | 1].val;               tree[pos].real = tree[pos << 1 | 1].real;           }       }              void Modify(int pos, int p, long long val) {           if (rs == p && ls == p) {               tree[pos].val += val;               return;           }           int m = ls + (rs - ls) / 2;           if (p <= m) Modify(pos << 1, p, val);           if (p > m) Modify(pos << 1 | 1, p, val);           if (tree[pos << 1].val > tree[pos << 1 | 1].val) {               tree[pos].val = tree[pos << 1].val;               tree[pos].real = tree[pos << 1].real;           } else {               tree[pos].val  = tree[pos << 1 | 1].val;               tree[pos].real = tree[pos << 1 | 1].real;           }          }              Node Query(int pos, int L, int R) {           if (ls >= L && rs <= R) {               return tree[pos];           };           int m = ls + (rs - ls) / 2;           Node ans;           ans.val = -INF;           if (m >= L) {               ans = max(Query(pos << 1, L, R), ans);           }           if (m < R) {               ans = max(Query(pos << 1 | 1, L, R), ans);           }           if (tree[pos << 1].val > tree[pos << 1 | 1].val) {               tree[pos].val = tree[pos << 1].val;               tree[pos].real = tree[pos << 1].real;           } else {               tree[pos].val  = tree[pos << 1 | 1].val;               tree[pos].real = tree[pos << 1 | 1].real;           }              return ans;       }          } T;   int d[N];   int main() {       int t;       scanf( %d , &t);       while (t--) {           int n;           scanf( %d , &n);           for (int i = 1; i <= n; i++) {               scanf( %d , &d[i]);           }           sort(d + 1, d + n + 1);           int p = 1;           arr[1] = 1;           for (int i = 2; i <= n; i++) {               if (d[i - 1] != d[i]) {                   p++;                   arr[p] = 1;               }               else {                   arr[p]++;               }           }           T.Built(1, p, 1);           int ans = n;           for (int i = 1; i <= n; i++) {               Node f1 = T.Query(1, 1, p);               T.Modify(1, f1.real, -f1.val);               Node f2 = T.Query(1, 1, p);               T.Modify(1, f1.real, f1.val);                              if (f1.val == 0 || f2.val == 0) break;               T.Modify(1, f1.real, -1);               T.Modify(1, f2.real, -1);               ans -= 2;           }           printf( %d n , ans);       }              return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, type[100001], a[100001], lead[100001], cur[100001];   bool vs[100001];   void input() {     scanf( %d , &n);     for (int i = 1, _b = n; i <= _b; i++) scanf( %d , &type[i]);     int x;     memset(lead, 0, sizeof(lead));     memset(a, 0, sizeof(a));     for (int i = 1, _b = n; i <= _b; i++) {       scanf( %d , &x);       a[x] = i;       lead[x]++;     }   }   void dfs(int i) {     vs[i] = true;     if (type[i]) {       cur[i] = 1;       return;     }     if (lead[a[i]] != 1 && !type[a[i]]) return;     if (!vs[a[i]]) dfs(a[i]);     if (cur[a[i]]) cur[i] = cur[a[i]] + 1;   }   void process() {     memset(vs, false, sizeof(vs));     memset(cur, 0, sizeof(cur));     for (int i = 0, _b = n; i <= _b; i++)       if (lead[i] != 1 && !type[i]) vs[i] = true;     for (int i = 1, _b = n; i <= _b; i++) {       if (!vs[i]) dfs(i);     }     int ans = 0;     int st = 0;     for (int i = 1, _b = n; i <= _b; i++) {       if (ans < cur[i]) {         ans = cur[i];         st = i;       }     }     cout << ans << endl;     while (!type[st]) {       printf( %d  , st);       st = a[st];     }     cout << st;   }   int main() {     input();     process();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct stra {     int x, y, z;   } arr[100000];   bool cmp(stra a, stra b) { return a.x > b.x; }   bool cmp1(stra a, stra b) { return a.y < b.y; }   int n, k = 1, g = 1;   int main() {     std::ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i <= n - 1; i++) {       cin >> arr[i].x;       arr[i].y = i;     }     sort(arr, arr + n, cmp);     arr[0].z = 1;     for (int i = 1; i <= n - 1; i++) {       if (arr[i - 1].x != arr[i].x) {         k = i + 1;         arr[i].z = k;       } else {         arr[i].z = k;       }     }     sort(arr, arr + n, cmp1);     for (int i = 0; i <= n - 1; i++) {       cout << arr[i].z <<    ;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const long long N = 1e6 + 10;   const long double eps = 1e-9;   const long long inf = 1e18;   long long a[N], b[N], c[N], d[N];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k;     long long m;     cin >> n >> m >> k;     long long a[m];     for (long long i = 0; i < m; ++i) cin >> a[i];     long long s = 0, i = 0, j = 0, k1 = k;     while (j < m) {       while (a[j] <= k1 + i) j++;       if (i == j) {         s--;         k1 = ((a[j] - i) / k) * k;         if ((a[j] - i) % k) k1 += k;       }       i = j;       s++;     }     cout << s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void s() { puts( Stannis ); }   void d() { puts( Daenerys ); }   int main() {     int n, k;     scanf( %d %d , &n, &k);     int odd = 0;     int even = 0;     long long tot = 0;     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       if (x % 2 == 0)         even++;       else         odd++;       tot += (long long)x;     }     int move = n - k;     if (n == k) {       if (tot % 2LL == 0) {         d();       } else {         s();       }     } else {       if (move % 2 == 1) {         if (move < odd && move < even) {           s();         } else {           if (move / 2 >= odd) {             d();           } else {             if (move / 2 >= even && ((move - even) + odd) % 2 == 0) {               d();             } else {               s();             }           }         }       } else {         if (move < odd && move < even) {           d();         } else {           if (move / 2 >= even && ((move - even) + odd) % 2 == 1) {             s();           } else {             d();           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 201110;   int lab[N], val[N];   vector<int> gr[N];   map<string, int> mp;   int n, m, q;   int root(int u) {     if (lab[u] < 0)       return u;     else       return lab[u] = root(lab[u]);   }   void join(int type, int u, int v) {     if (lab[u] < lab[v]) {       lab[u] += lab[v];       lab[v] = u;       for (int i = 0; i < gr[v].size(); i++) {         gr[u].push_back(gr[v][i]);         val[gr[v][i]] *= type;       }       gr[v].clear();     } else {       lab[v] += lab[u];       lab[u] = v;       for (int i = 0; i < gr[u].size(); i++) {         gr[v].push_back(gr[u][i]);         val[gr[u][i]] *= type;       }       gr[u].clear();     }   }   string read() {     char ch;     string ans =   ;     while (ch = getchar()) {       if ( a  <= ch && ch <=  z ) break;     }     ans = ans + ch;     while (ch = getchar()) {       if (ch <  a  || ch >  z ) break;       ans = ans + ch;     }     return ans;   }   int main() {     scanf( %d%d%d , &n, &m, &q);     int k = 0;     string st;     int type, u, v;     for (int i = 1; i <= n; i++) {       val[i] = 1;       gr[i].push_back(i);       st = read();       mp[st] = i;     }     memset(lab, 255, sizeof(lab));     for (int i = 1; i <= m; i++) {       scanf( %d , &type);       st = read();       u = mp[st];       st = read();       v = mp[st];       if (root(u) != root(v)) {         if ((val[u] == val[v] && type == 1) || (val[u] != val[v] && type == 2))           join(1, root(u), root(v));         else           join(-1, root(u), root(v));         puts( YES );       } else {         if ((val[u] != val[v] && type == 1) || (val[u] == val[v] && type == 2))           puts( NO );         else           puts( YES );       }     }     for (int i = 1; i <= q; i++) {       st = read();       u = mp[st];       st = read();       v = mp[st];       if (root(u) != root(v))         printf( 3 n );       else {         if (val[u] == val[v])           printf( 1 n );         else           printf( 2 n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 50;   deque<int> dq;   bool is[N], can[N];   vector<vector<int> > adj(N);   int n, m, d, cur, mx, ans[N], x;   void dfs(int u, int p) {     ans[u] = ans[p] + 1;     can[u] &= (ans[u] <= d);     if (ans[u] > mx && is[u]) mx = ans[u], x = u;     for (auto v : adj[u])       if (v != p) dfs(v, u);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> d;     ans[0] = -1;     memset(can, 1, sizeof can);     for (int i = 0; i < m; i++) cin >> x, is[x] = 1;     for (int i = 1, u, v; i < n; i++) {       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dq.push_front(x);     while (dq.size()) {       int now = dq.front();       dfs(now, 0);       dq.pop_front();       if (now != x) dq.push_front(x);     }     int s = 0;     for (int i = 1; i <= n; i++) s += can[i];     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXN = 100000;   int n;   int x[MAXN];   int ret[MAXN];   bool used[MAXN + 1];   void run() {     scanf( %d , &n);     for (int i = (0); i < (n); ++i) scanf( %d , &x[i]);     memset(ret, -1, sizeof(ret));     memset(used, false, sizeof(used));     for (int i = (0); i < (n); ++i)       if (1 <= x[i] && x[i] <= n && !used[x[i]]) ret[i] = x[i], used[x[i]] = true;     int at = 1;     for (int i = (0); i < (n); ++i)       if (ret[i] == -1) {         while (used[at]) ++at;         ret[i] = at++;       }     for (int i = (0); i < (n); ++i) {       if (i != 0) printf(   );       printf( %d , ret[i]);     }     puts(  );   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   template <class T>   inline T lcm(T a, T b) {     if (a < 0) return lcm(-a, b);     if (b < 0) return lcm(a, -b);     return a * (b / gcd(a, b));   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class T>   T power(T N, T P) {     return (P == 0) ? 1 : N * power(N, P - 1);   }   long long toInt64(string s) {     long long r = 0;     istringstream sin(s);     sin >> r;     return r;   }   double LOG(long long N, long long B) { return (log10l(N)) / (log10l(B)); }   string itoa(long long a) {     if (a == 0) return  0 ;     string ret;     for (long long i = a; i > 0; i = i / 10) ret.push_back((i % 10) + 48);     reverse(ret.begin(), ret.end());     return ret;   }   vector<string> token(string a, string b) {     const char *q = a.c_str();     while (count(b.begin(), b.end(), *q)) q++;     vector<string> oot;     while (*q) {       const char *e = q;       while (*e && !count(b.begin(), b.end(), *e)) e++;       oot.push_back(string(q, e));       q = e;       while (count(b.begin(), b.end(), *q)) q++;     }     return oot;   }   template <class T>   inline T __cin() {     T ret;     cin >> ret;     return ret;   }   int isvowel(char s) {     s = tolower(s);     if (s ==  a  || s ==  e  || s ==  i  || s ==  o  || s ==  u ) return 1;     return 0;   }   int isupper(char s) {     if (s >=  A  and s <=  Z ) return 1;     return 0;   }   int Set(int N, int pos) { return N = N | (1 << pos); }   int reset(int N, int pos) { return N = N & ~(1 << pos); }   int check(int N, int pos) { return (N & (1 << pos)); }   int toggle(int N, int pos) {     if (check(N, pos)) return N = reset(N, pos);     return N = Set(N, pos);   }   void pbit(int N) {     printf( ( );     for (int i = 10; i >= 0; i--) {       bool x = check(N, i);       cout << x;     }     puts( ) );   }   int main() {     int n = 9;     cin >> n;     long long ans = -1;     for (int i = max(n - 100, 1); i <= n; i++) {       for (int j = max(n - 100, 1); j <= n; j++) {         for (int k = max(n - 100, 1); k <= n; k++) {           long long lc = lcm((long long)i, lcm((long long)j, (long long)k));           ans = max(ans, lc);         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j, line[35], column[35], var, count;     cin >> n;     for (i = 1; i <= n; ++i) line[i] = column[i] = 0;     for (i = 1; i <= n; ++i)       for (j = 1; j <= n; ++j) {         cin >> var;         line[i] += var;         column[j] += var;       }     count = 0;     for (i = 1; i <= n; ++i)       for (j = 1; j <= n; ++j) {         if (column[i] > line[j]) count++;       }     cout << count;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int min(int a, int b) {     if (a <= b) {       return a;     } else {       return b;     }   }   int max(int a, int b) {     if (a >= b) {       return a;     } else {       return b;     }   }   int main() {     int l, r, a;     cin >> l >> r >> a;     int MAX, MIN;     int count;     MAX = max(l, r);     MIN = min(l, r);     MIN += a;     if (MIN > MAX) {       count = (2 * MAX) + ((MIN - MAX) / 2) * 2;     } else {       count = MIN * 2;     }     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 3;   int n;   vector<int> G[N];   int h[N], cnt[N];   int res = 0;   void dfs(int u, int p) {     cnt[h[u]]++;     for (int v : G[u])       if (v != p) {         h[v] = h[u] + 1;         dfs(v, u);       }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n - 1; ++i) {       int x;       cin >> x;       G[x].push_back(i + 1);     }     h[1] = 1;     dfs(1, 0);     for (int i = 1; i <= n; ++i) res += (cnt[i] % 2);     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   void frepn() {     freopen(                     .in ,          r , stdin);     freopen(                     .out ,          w , stdout);   }   const int N = 50500;   const long long INF = (1e17) + 777;   const int mod = (1e9) + 7;   int n, a[N], k, t;   int ans, ans2, ans3, ans4;   int main() {     ios_base::sync_with_stdio(0);     ;     cin >> n >> k >> t;     ans = k * t;     for (int i = 1; i <= n; i++) {       cin >> a[i];       ans4 += a[i];     }     sort(a + 1, a + 1 + n);     for (int i = n - k; i <= n; i++) {       ans2 += a[i];     }     for (int i = 1; i <= n - k; i++) {       ans3 += a[i];     }     if (ans2 < ans)       cout << ans4;     else       cout << ans3 + ans;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   const int MAXN=1e9+1;   const ll mod=1e9+7;      int main(){       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);        int n,m,k;       cin>>n>>m>>k;       int hori[n][m-1];       for(int i=0;i<n;i++){           for(int j=0;j<m-1;j++){               cin>>hori[i][j];           }       }       int verti[n-1][m];       for(int i=0;i<n-1;i++){           for(int j=0;j<m;j++){               cin>>verti[i][j];           }       }       if(k%2!=0){           for(int i=0;i<n;i++){               for(int j=0;j<m;j++)cout<< -1  ;               cout<<endl;           }           return 0;       }       k/=2;       int dp[n][m][k+1];       for(int i=0;i<n;i++){           for(int j=0;j<m;j++){               for(int step=0;step<=k;step++)dp[i][j][step]=MAXN;           }       }       for(int i=0;i<n;i++){           for(int j=0;j<m;j++)dp[i][j][0]=0;       }       for (int step = 0; step < k; step++) {               for (int i = 0; i < n; i++) {                   for (int j = 0; j < m; j++) {                       if (i > 0) dp[i - 1][j][step + 1] = min(dp[i - 1][j][step + 1], dp[i][j][step] + verti[i-1][j]);                       if (i < n - 1) dp[i + 1][j][step + 1] = min(dp[i + 1][j][step + 1], dp[i][j][step] + verti[i][j]);                       if (j > 0) dp[i][j - 1][step + 1] = min(dp[i][j - 1][step + 1], dp[i][j][step] + hori[i][j-1]);                       if (j < m - 1) dp[i][j + 1][step + 1] = min(dp[i][j + 1][step + 1], dp[i][j][step] + hori[i][j]);                   }               }           }       for(int i=0;i<n;i++){           for(int j=0;j<m;j++){               cout<<(2*dp[i][j][k])<<   ;           }           cout<<endl;       }              return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void rd(T &x) {     x = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) x = x * 10 -  0  + c, c = getchar();     x *= f;   }   const int N = 110;   int Sqr(int x) { return x * x; }   int sum[N][N][N];   int n, m;   int vis[N][N], f[N][N];   int dp(int l, int r) {     if (l + 1 >= r) return 0;     if (vis[l][r]) return f[l][r];     vis[l][r] = 1;     int res = 0;     for (int k = l + 1; k < r; ++k) {       res = max(res, Sqr(sum[k][l][r]) + dp(l, k) + dp(k, r));     }     return f[l][r] = res;   }   int main() {     rd(n), rd(m);     for (int i = 1; i <= n; ++i) {       int t, l, r;       rd(t);       while (t--) {         rd(l), rd(r);         for (int j = l; j <= r; ++j) sum[j][l - 1][r + 1]++;       }     }     for (int i = 1; i <= m; ++i) {       for (int j = i - 1; j >= 0; --j)         for (int k = i + 1; k <= m + 1; ++k)           sum[i][j][k] +=               sum[i][j + 1][k] + sum[i][j][k - 1] - sum[i][j + 1][k - 1];     }     printf( %d , dp(0, m + 1));     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   long long int power(long long int x, long long int n) {     long long int result = 1;     while (n) {       if (n % 2 == 1) result = result * x;       n = n / 2;       x = x * x;     }     return result;   }   long long int gcd(long long int a, long long int b) {     if (!b) return a;     return gcd(b, a % b);   }   long long int lcm(long long int a, long long int b) {     return (a * b) / gcd(a, b);   }   long long int BS(long long int a[], long long int s, long long int n,                    long long int val) {     long long int mid, beg = s, end = n - 1;     while (beg <= end) {       mid = (beg + end) / 2;       if (val == a[mid]) {         break;       } else if (val > a[mid]) {         beg = mid + 1;       } else {         end = mid - 1;       }     }     return mid;   }   inline long long int mul(long long int x, long long int y, long long int m) {     long long int z = 1LL * x * y;     if (z >= m) {       z %= m;     }     return z;   }   long long int powmod(long long int x, long long int y, long long int m) {     long long int r = 1;     while (y) {       if (y & 1) {         r = mul(r, x, m);       }       y >>= 1;       x = mul(x, x, m);     }     return r;   }   using namespace std;   void start() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;   }   int main() {     start();     long long int n;     cin >> n;     long long int a[n], b[n];     for (long long int i = 0; i < n; i++) cin >> a[i] >> b[i];     long long int khatam = 0;     for (long long int i = 0; i < n; i++) {       if (a[i] != b[i]) {         khatam = 1;         break;       }     }     if (khatam) {       cout <<  rated n ;       return 0;     }     long long int khatam1 = 0;     for (long long int i = 1; i < n; i++) {       if (b[i] > b[i - 1]) {         khatam1 = 1;         break;       }     }     if (khatam1)       cout <<  unrated ;     else       cout <<  maybe ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, s = 0;     bool kt;     cin >> n >> m;     char a[n][m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];       }     }     for (int i = 0; i < n; i++) {       kt = true;       for (int j = 0; j < m; j++) {         if (a[i][j] ==  S ) {           kt = false;           break;         }       }       if (kt == true)         for (int j = 0; j < m; j++) a[i][j] =  1 ;     }     for (int j = 0; j < m; j++) {       kt = true;       for (int i = 0; i < n; i++) {         if (a[i][j] ==  S ) {           kt = false;           break;         }       }       if (kt == true)         for (int i = 0; i < n; i++) a[i][j] =  1 ;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  1 ) s++;       }     }     cout << s;   }


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


#include <bits/stdc++.h>   using namespace std;   long long a[8][8], n, m, u, v, k = INT_MAX;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     cin >> n >> m;     for (long long i = 0; i < m; i++) {       cin >> u >> v;       a[u][v] = 1;       a[v][u] = 1;     }     if (n <= 6)       cout << m <<   n ;     else {       for (long long i = 1; i <= 7; i++) {         for (long long j = i + 1; j <= 7; j++) {           long long c = 0;           for (long long l = 1; l <= 7; l++)             if (a[i][l] == 1 && a[j][l] == 1) ++c;           k = min(k, c);         }       }       cout << m - k <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 9;   int n, p, q;   string s, t, a, b;   int c[2005], d[2005], h[2005], invH[2005], k[2005], invK[2005];   vector<pair<int, int>> memo;   int mul(int aa, int bb) { return ((long long)aa * bb) % MOD; }   int add(int aa, int bb) { return (aa + bb) % MOD; }   int sub(int aa, int bb) { return (aa - bb + MOD) % MOD; }   int modpow(int num, int pi) {     int res = 1;     while (pi > 0) {       if (pi & 1) res = mul(res, num);       num = mul(num, num);       pi >>= 1;     }     return res;   }   pair<int, int> getHash(int lo, int hi) {     return make_pair(mul(sub(c[hi], c[lo]), invH[lo]),                      mul(sub(d[hi], d[lo]), invK[lo]));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> s >> a >> b;     n = s.size();     p = a.size();     q = b.size();     h[0] = invH[0] = 1;     k[0] = invK[0] = 1;     for (int i = 1; i <= n; i++) {       h[i] = mul(h[i - 1], 31);       invH[i] = modpow(h[i], MOD - 2);       k[i] = mul(k[i - 1], 53);       invK[i] = modpow(k[i], MOD - 2);     }     for (int i = 0; i < n; i++) {       c[i + 1] = add(c[i], mul(h[i], s[i]));       d[i + 1] = add(d[i], mul(k[i], s[i]));     }     pair<int, int> x = make_pair(0, 0);     for (int i = 0; i < p; i++) {       x.first = add(x.first, mul(h[i], a[i]));       x.second = add(x.second, mul(k[i], a[i]));     }     pair<int, int> y = make_pair(0, 0);     for (int i = 0; i < q; i++) {       y.first = add(y.first, mul(h[i], b[i]));       y.second = add(y.second, mul(k[i], b[i]));     }     for (int i = 0; i < n - p + 1; i++) {       for (int j = i + max(0, p - q); j < n - q + 1; j++) {         if (x == getHash(i, i + p) && y == getHash(j, j + q)) {           memo.push_back(getHash(i, j + q));         }       }     }     sort(memo.begin(), memo.end());     int ans = unique(memo.begin(), memo.end()) - memo.begin();     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long a, b, x, vx, vy;   map<long long, long long> mo;   map<long long, long long>::iterator it;   map<pair<long long, long long>, long long> ex;   map<pair<long long, long long>, long long>::iterator ti;   int main() {     scanf( %d%I64d%I64d , &n, &a, &b);     for (int i = 0; i < n; i++) {       scanf( %I64d%I64d%I64d , &x, &vx, &vy);       mo[vy - a * vx]++;       ex[make_pair(vx, vy)]++;     }     long long ans = 0;     for (it = mo.begin(); it != mo.end(); it++) {       long long tmp = it->second;       ans += tmp * (tmp - 1);     }     for (ti = ex.begin(); ti != ex.end(); ti++) {       long long tmp = ti->second;       ans -= tmp * (tmp - 1);     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int N = 5005;   int n, m;   double ans, F[N][N];   bool vis[N][N];   double cal(double b, double x, double y, double ps) {     return (1 - b) * ps * x + min(1 - ps, ps * b + (1 - ps) * (1 - y));   }   double f(int a, int b, int fl) {     if (!b) return 1;     if (!a) return 1 / (double)(b + 1);     if (vis[a][b]) return F[a][b];     double res = 1 / (double)(b + 1);     vis[a][b] = 1;     double y = f(b, a - 1, 0), x = 1 - f(b - 1, a, 0);     return F[a][b] =                max(res, cal(1 / (double)(b + 1), x, y,                             y * (double)(b + 1) / (1 + y * (double)(b + 1))));   }   int main() {     int i, j;     cin >> n >> m, ans = f(n, m, 0);     printf( %.9lf %.9lf , ans, 1 - ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     vector<long long int> v(n), vv;     for (int i = 0; i < n; i++) cin >> v[i];     long long int mx = *max_element(v.begin(), v.end());     int len = 0, fg = 0;     for (long long int i = 0; i < n; i++) {       if (v[i] == mx) {         long long int j = i;         while (v[j] == mx && j <= n - 1) j++;         vv.push_back(j - i);         i = j;       }     }     sort(vv.begin(), vv.end());     cout << vv[vv.size() - 1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100000 + 2;   const int MAX_M = 100000 + 2;   int weight[MAX_N];   struct Edge {     int v, x;   } E[MAX_M * 10];   int tot;   template <int N>   struct AdjList {     int l[N];     inline void addEdge(int u, int v) {       E[tot] = (Edge){v, l[u]};       l[u] = tot++;     }     void init() { memset(l, -1, sizeof l); }   };   AdjList<MAX_N> adj;   namespace BCC {   const int N = MAX_N;   const int M = MAX_M;   set<int> p2c[N];   set<pair<int, int> > c2e[N];   map<pair<int, int>, int> e2c;   pair<int, int> S[M], tmp;   int cut[N], dep[N], low[N], ori[N + N];   int *l;   Edge *E;   int n, bcc_cnt, top;   void dfs(int u, int D, int ind);   void Pop(pair<int, int> y);   int rebuild(AdjList<N + N> &adj);   void init(int _n, int *_l, Edge *_E) {     n = _n;     l = _l;     E = _E;     for (int i = 0; i < n; i++) dep[i] = cut[i] = -1;     for (int i = 0; i < n; i++) p2c[i].clear(), c2e[i].clear();     e2c.clear();     bcc_cnt = top = 0;     for (int i = 0; i < n; i++)       if (dep[i] == -1) {         dfs(i, 0, -1);       }   }   void dfs(int u, int D, int ind) {     dep[u] = low[u] = D;     int child = 0;     for (int i = l[u]; ~i; i = E[i].x) {       if (ind == (i ^ 1)) continue;       int v = E[i].v;       S[top++] = {u, v};       if (dep[v] >= 0) {         if (dep[v] > dep[u]) top--;         low[u] = min(low[u], dep[v]);         continue;       }       child++;       dfs(v, D + 1, i);       low[u] = min(low[u], low[v]);       if (low[v] >= dep[u]) {         cut[u] = 1;         Pop(pair<int, int>(u, v));       }     }     if (child == 1 && ind < 0) cut[u] = -1;   }   void Pop(pair<int, int> y) {     do {       tmp = S[--top];       p2c[tmp.first].insert(bcc_cnt);       p2c[tmp.second].insert(bcc_cnt);       if (tmp.first > tmp.second) swap(tmp.first, tmp.second);       c2e[bcc_cnt].insert(tmp);       e2c[tmp] = bcc_cnt;     } while (top && S[top] != y);     bcc_cnt++;   }   int rebuild(AdjList<N + N> &adj) {     int c = bcc_cnt;     for (int i = 0; i < n; i++)       if (cut[i] != -1) {         cut[i] = c++;         ori[c - 1] = i;       }     adj.init();     set<int>::iterator it;     for (int u = 0; u < n; u++) {       if (cut[u] == -1) continue;       for (it = p2c[u].begin(); it != p2c[u].end(); it++) {         adj.addEdge(cut[u], *it);         adj.addEdge(*it, cut[u]);       }     }     return c;   }   };  // namespace BCC   namespace Solve {   const int N = MAX_N + MAX_N;   const int inf = 1e9;   AdjList<N> adj2;   multiset<int> value[N];   int n, m;   int dep[N], top[N], fa[N], heavy[N], siz[N];   int ID[N];   int *l;   Edge *E;   void Label(int u, int anc);   void dfs(int u);   int query(int a, int b);   struct segTree {     int Min[N << 1];     inline int getID(int l, int r) { return l + r | l != r; }     void up(int l, int r) {       int mid = l + r >> 1;       Min[getID(l, r)] = min(Min[getID(l, mid)], Min[getID(mid + 1, r)]);     }     void build(int l, int r) {       int o = getID(l, r);       if (l == r) {         if (value[l].empty()) {           puts( empty bug );           Min[o] = inf;         } else {           Min[o] = *value[l].begin();         }       } else {         int mid = l + r >> 1;         build(l, mid);         build(mid + 1, r);         up(l, r);       }     }     void update(int l, int r, int ql, int preValue, int nowValue) {       if (l == r) {         auto it = value[l].lower_bound(preValue);         if (it == value[l].end()) {           puts( delete bug );           return;         }         value[l].erase(it);         value[l].insert(nowValue);         Min[getID(l, r)] = *value[l].begin();       } else {         int mid = l + r >> 1;         if (ql <= mid)           update(l, mid, ql, preValue, nowValue);         else           update(mid + 1, r, ql, preValue, nowValue);         up(l, r);       }     }     int getMin(int l, int r, int ql, int qr) {       if (ql <= l && r <= qr) {         return Min[getID(l, r)];       }       int mid = l + r >> 1;       if (qr <= mid) return getMin(l, mid, ql, qr);       if (ql > mid) return getMin(mid + 1, r, ql, qr);       return min(getMin(l, mid, ql, qr), getMin(mid + 1, r, ql, qr));     }   } segs;   void dfs(int u) {     siz[u] = 1;     heavy[u] = -1;     for (int i = l[u], v; ~i; i = E[i].x) {       v = E[i].v;       if (fa[u] != v) {         dep[v] = dep[u] + 1;         fa[v] = u;         dfs(v);         siz[u] += siz[v];         if (heavy[u] == -1 || siz[heavy[u]] < siz[v]) {           heavy[u] = v;         }       }     }   }   void Label(int u, int anc) {     ID[u] = m++;     top[u] = anc;     if (~heavy[u]) Label(heavy[u], anc);     for (int i = l[u], v; ~i; i = E[i].x) {       v = E[i].v;       if (v != fa[u] && v != heavy[u]) {         Label(v, v);       }     }   }   int query(int a, int b) {     int ret = inf;     while (top[a] != top[b]) {       if (dep[top[a]] < dep[top[b]]) {         swap(a, b);       }       ret = min(ret, segs.getMin(0, m - 1, ID[top[a]], ID[a]));       a = fa[top[a]];     }     if (dep[a] < dep[b]) {       swap(a, b);     }     ret = min(ret, segs.getMin(0, m - 1, ID[b], ID[a]));     if (b < BCC::bcc_cnt && fa[b] != -1) {       ret = min(ret, weight[BCC::ori[fa[b]]]);     }     return ret;   }   void init(int _n, Edge *_E, int _m) {     n = _n;     for (int u = 0; u < n; u++) value[u].clear();     l = adj2.l;     E = _E;     dep[0] = -1;     fa[0] = -1;     m = 0;     dfs(0);     Label(0, 0);     for (int u = 0; u < _m; u++) {       if (BCC::cut[u] == -1) {         value[ID[*BCC::p2c[u].begin()]].insert(weight[u]);       } else {         value[ID[BCC::cut[u]]].insert(weight[u]);         value[ID[fa[BCC::cut[u]]]].insert(weight[u]);       }     }     segs.build(0, m - 1);   }   void modify(int u, int pre, int now) {     if (u >= BCC::bcc_cnt && fa[u] != -1) {       modify(fa[u], pre, now);     }     segs.update(0, m - 1, ID[u], pre, now);   }   void gao(int q) {     char op;     int a, b, w, x, y;     while (q--) {       scanf(  %c %d %d , &op, &a, &b);       if (op ==  C ) {         a--;         x = BCC::cut[a];         if (x == -1) {           if (BCC::p2c[a].size() != 1) {             puts( build bug );           }           x = *BCC::p2c[a].begin();         }         modify(x, weight[a], b);         weight[a] = b;       } else {         a--;         b--;         if (a == b) {           printf( %d n , weight[a]);           continue;         }         x = BCC::cut[a];         y = BCC::cut[b];         if (x == -1) {           if (BCC::p2c[a].size() != 1) {             puts( build bug );           }           x = *BCC::p2c[a].begin();         }         if (y == -1) {           if (BCC::p2c[b].size() != 1) {             puts( build bug );           }           y = *BCC::p2c[b].begin();         }         printf( %d n , query(x, y));       }     }   }   };  // namespace Solve   int main() {     int n, m, q, u, v, w;     scanf( %d%d%d , &n, &m, &q);     for (int i = 0; i < n; i++) {       scanf( %d , weight + i);     }     tot = 0;     adj.init();     for (int i = 0; i < m; i++) {       scanf( %d%d , &u, &v);       u--;       v--;       adj.addEdge(u, v);       adj.addEdge(v, u);     }     BCC::init(n, adj.l, E);     int bcc_cnt = BCC::rebuild(Solve::adj2);     Solve::init(bcc_cnt, E, n);     Solve::gao(q);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   const int MOD = 1e9 + 7;   int n;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed;     cin >> n;     int dp[] = {1, 0};     for (int i = 1; i < n; i++) dp[i % 2] = (dp[i % 2] + dp[1 - i % 2] + 1) % MOD;     cout << (dp[0] + dp[1]) % MOD << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, i = 0, j, k = 0, l = 0, m = 10e9, a = 0, b = 0, c, sum = 0,                  x = 0, y = 0, z = 0;     cin >> n;     long long arr[n + 1];     for (i = 1; i <= n; i++) {       cin >> arr[i];       arr[i] = arr[i] / max(i - 1, n - i);     }     for (i = 1; i <= n; i++) {       l = arr[i];       m = min(m, l);     }     cout << m;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m, i, j, q = 0;     string s, k, p =  go ;     cin >> n >> s;     vector<string> st(100);     st[0] =  ogo ;     for (i = 1; i < 100; i++) {       st[i] = st[i - 1] + p;     }     for (i = 0; i < n; i++) {       j = n - i;       q = 0;       for (j = n - i; j >= 3; j--) {         k = s.substr(i, j);         if (binary_search(st.begin(), st.end(), k)) {           i = i + j - 1;           cout <<  *** ;           q = 1;           break;         }       }       if (q == 0) cout << s[i];     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 60;   const int A = 26;   const int INF = 1000000001;   char G[MAX + 2][MAX + 3];   int D[MAX + 2][MAX + 2];   bool ok[A + 1];   pair<int, int> S, T;   vector<char> ans;   vector<int> K;   int n, m, k;   inline int con(char c) { return  a  <= c && c <=  z  ? c -  a  : A; }   vector<pair<int, int> > Q;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, 1, -1};   bool vis[A + 1][A + 1][A + 1][A + 1];   void bfs() {     sort((K).begin(), (K).end());     K.erase(unique((K).begin(), (K).end()), K.end());     if (K.back() == A) K.pop_back();     if (K.size() > k || K.empty()) return;     if (vis[K[0]][K.size() > 1 ? K[1] : A][K.size() > 2 ? K[2] : A]            [K.size() > 3 ? K[3] : A])       return;     vis[K[0]][K.size() > 1 ? K[1] : A][K.size() > 2 ? K[2] : A]        [K.size() > 3 ? K[3] : A] = true;     for (int i = 0; i < K.size(); ++i) ok[K[i]] = true;     for (int i = 0; i <= n + 1; ++i) memset(D[i], -1, sizeof(int) * (m + 2));     Q.clear();     Q.push_back(T);     D[T.first][T.second] = 0;     for (int foo = 0; foo < Q.size(); ++foo) {       pair<int, int> v = Q[foo];       if (v == S) break;       for (int foo = 0; foo < 4; ++foo) {         int i = v.first + dx[foo];         int j = v.second + dy[foo];         if (ok[con(G[i][j])] && D[i][j] == -1) {           D[i][j] = D[v.first][v.second] + 1;           Q.push_back(make_pair(i, j));         }       }     }     for (int i = 0; i < K.size(); ++i) ok[K[i]] = false;     int d = INF;     for (int foo = 0; foo < 4; ++foo) {       int i = S.first + dx[foo];       int j = S.second + dy[foo];       if (D[i][j] != -1) d = min(d, D[i][j]);     }     if (d > ans.size()) return;     int com = 0;     int index = 0;     vector<char> tmp;     tmp.reserve(d);     vector<pair<int, int> > V[2];     bool now = false;     V[0].push_back(S);     while (d) {       int best = 200;       for (int i = 0; i < K.size(); ++i)         for (__typeof((V[now]).begin()) u = (V[now]).begin(); u != (V[now]).end();              ++u)           for (int foo = 0; foo < 4; ++foo) {             int x = u->first + dx[foo];             int y = u->second + dy[foo];             if (G[x][y] == K[i] +  a  && D[x][y] == d) {               best = K[i];               goto out;             }           }     out:       tmp.push_back(best +  a );       if (!com) {         if (tmp.back() < ans[index])           com = -1;         else if (tmp.back() > ans[index])           com = 1;       }       ++index;       V[!now].clear();       for (__typeof((V[now]).begin()) u = (V[now]).begin(); u != (V[now]).end();            ++u)         for (int foo = 0; foo < 4; ++foo) {           int x = u->first + dx[foo];           int y = u->second + dy[foo];           if (G[x][y] == best +  a  && D[x][y] == d) {             V[!now].push_back(make_pair(x, y));             D[x][y] = -1;           }         }       --d;       now = !now;     }     if (tmp.size() < ans.size() || com == -1) ans = tmp;   }   void solve(int x, int i) {     if (x >= k) {       vector<int> tmpK = K;       bfs();       K = tmpK;       return;     }     if (i == A) return;     solve(x, i + 1);     for (; i < A; ++i) {       K.push_back(i);       solve(x + 1, i + 1);       K.pop_back();     }   }   int main(int argc, char *argv[]) {     scanf( %d %d %d , &n, &m, &k);     ans.resize(n * m + 10);     for (int i = 0; i <= n + 1; ++i) memset(G[i],  $ , m + 2);     for (int i = 1; i <= n; ++i) scanf( %s , G[i] + 1);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (G[i][j] ==  S )           S = make_pair(i, j);         else if (G[i][j] ==  T )           T = make_pair(i, j);     if (abs(S.first - T.first) + abs(S.second - T.second) == 1) return 0;     for (int xs = S.first - 1; xs <= S.first + 1; ++xs)       for (int ys = S.second - 1; ys <= S.second + 1; ++ys)         if (abs(xs - S.first) + abs(ys - S.second) == 1)           for (int xt = T.first - 1; xt <= T.first + 1; ++xt)             for (int yt = T.second - 1; yt <= T.second + 1; ++yt)               if (abs(xt - T.first) + abs(yt - T.second) == 1) {                 K.clear();                 K.push_back(con(G[xs][ys]));                 K.push_back(con(G[xt][yt]));                 if (K[0] == K[1]) K.pop_back();                 solve(K.size(), 0);               }     if (ans.size() == n * m + 10) {       printf( -1 n );       return 0;     }     for (__typeof((ans).begin()) i = (ans).begin(); i != (ans).end(); ++i)       printf( %c , *i);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char inp[2000];   int toNum(char x) {     if (x >=  0  && x <=  9 ) return x -  0 ;     return 10 + x -  A ;   }   char toChar(int x) {     if (x < 10) return  0  + x;     return  A  + (x - 10);   }   long long ato10(int a) {     int len = strlen(inp);     int lw = 0;     while (lw < len && inp[lw] ==  0 ) lw++;     if (lw >= len) return 0;     long long ret = 0;     for (int i = lw; i < len; i++) {       ret = ret * a + toNum(inp[i]);     }     return ret;   }   char pI[] = { I ,  X ,  C ,  M };   char pV[] = { V ,  L ,  D };   int main() {     int a, b;     gets(inp);     bool iR = false;     int len = strlen(inp);     for (int i = 0; i < len; i++) {       if (inp[i] ==  R ) iR = true;     }     if (!iR)       sscanf(inp,  %d%d , &a, &b);     else       sscanf(inp,  %d , &a);     gets(inp);     long long number = ato10(a);     if (!iR) {       string ret =   ;       if (number == 0)         ret =  0 ;       else {         while (number) {           ret = toChar(number % b) + ret;           number /= b;         }       }       printf( %s n , ret.c_str());     } else {       int idx = 0;       string ret =   ;       while (number) {         int tdec = number % 10;         number /= 10;         if (tdec <= 3)           for (int t = 0; t < tdec; t++) ret = pI[idx] + ret;         else if (tdec == 4) {           ret = pV[idx] + ret;           ret = pI[idx] + ret;         } else if (tdec == 5)           ret = pV[idx] + ret;         else if (tdec <= 8) {           tdec -= 5;           for (int t = 0; t < tdec; t++) ret = pI[idx] + ret;           ret = pV[idx] + ret;         } else {           ret = pI[idx + 1] + ret;           ret = pI[idx] + ret;         }         idx++;       }       printf( %s n , ret.c_str());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int k;   long long int ways(long long int n) {     long long int calc, ways = 0;     for (int k = 2; k <= 10000000; k++) {       calc = n / (1ll * k * k * k);       ways += calc;       if (calc == 0) {         break;       }     }     return ways;   }   long long int binarysearch(long long int low, long long int high) {     long long int temp = high;     while (low <= high) {       long long int mid = low + (high - low) / 2;       long long int x = ways(mid);       if (x > k)         high = mid - 1;       else if (x < k)         low = mid + 1;       else if (x == k) {         temp = min(temp, mid);         high = mid - 1;       }     }     return temp;   }   int main() {     scanf( %lld , &k);     long long int MAX = 10 * k;     long long int ans = binarysearch(8, MAX);     if (ans == MAX) ans = -1;     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   namespace whatever {   const long long inf = 1000000000000000001ll;   template <typename type>   type read() {     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     type value = ch -  0 ;     ch = getchar();     while (isdigit(ch)) {       value = value * 10 + ch -  0 ;       ch = getchar();     }     return value;   }   int n;   string f[201];   char result[202];   int fail[201];   int match(const string &str, int l) {     int cnt = 0;     int cur = 0;     for (char ch : str) {       while (cur && ch != result[cur + 1]) cur = fail[cur];       if (ch == result[cur + 1]) ++cur;       if (cur == l) {         ++cnt;         cur = fail[cur];       }     }     return cnt;   }   long long count(int l) {     static long long cnt[201];     int i;     for (i = 0; i <= n && (i < 2 || int(f[i - 2].size()) <= l); ++i)       cnt[i] = match(f[i], l);     if (i <= n) {       long long span_cnt[2];       span_cnt[i % 2] = match(           f[i - 2].substr(f[i - 2].size() - l + 1) + f[i - 1].substr(0, l - 1),           l);       span_cnt[1 - i % 2] = match(           f[i - 2].substr(f[i - 2].size() - l + 1) + f[i - 2].substr(0, l - 1),           l);       do {         cnt[i] = cnt[i - 2] + cnt[i - 1] + span_cnt[i % 2];         if (cnt[i] >= inf) return inf;       } while (++i <= n);     }     return cnt[n];   }   void insert(int l, char ch) {     result[l] = ch;     if (l == 1) return;     int cur = fail[l - 1];     while (cur && ch != result[cur + 1]) cur = fail[cur];     if (ch == result[cur + 1]) ++cur;     fail[l] = cur;   }   void run() {     n = read<int>();     long long k = read<long long>() + 1;     int m = read<int>();     f[0] =  0 ;     f[1] =  1 ;     int last = n;     for (int i = 2; i <= n; ++i)       if (int(f[i - 2].size()) <= m)         f[i] = f[i - 2] + f[i - 1];       else {         last = i - 1;         break;       }     cerr <<  last:   << last << endl;     fail[1] = 0;     for (int i = 1; i <= m; ++i) {       if (f[last].substr(f[last].size() - i + 1) ==           string(result + 1, result + i)) {         if (--k == 0) break;       }       insert(i,  0 );       long long cnt = count(i);       if (cnt >= k)         putchar( 0 );       else {         k -= cnt;         insert(i,  1 );         putchar( 1 );       }     }     putchar(  n );   }   }  // namespace whatever   int main() { whatever::run(); }


#include <bits/stdc++.h>   const long long N = 2e5 + 17;   using namespace std;   long long i, mn, ans = 0, als = 0, v, ii, r4 = 0, r1, r2, r3, mx, p, q, d, l, r,                    m, n, k, j;   string d1, d3, d2, s;   char kl, km, mk, lk;   double fg;   int inout() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> n >> q;     map<long long, long long> mp;     while (q--) {       cin >> r1 >> r2 >> r3;       als = 0;       ii = 0;       for (i = 1; i <= n; i++) {         if (r1 >= mp[i]) als++;         if (als == r2) break;       }       if (als == r2) {         for (i = 1; i <= n && r2; i++) {           if (r1 >= mp[i]) {             mp[i] = r1 + r3;             ii += i;             r2--;           }         }         cout << ii <<   n ;       } else         cout <<  -1               <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 51;   int n, x;   int res[MAXN];   inline int read() {     register int num = 0, neg = 1;     register char ch = getchar();     while (!isdigit(ch) && ch !=  - ) {       ch = getchar();     }     if (ch ==  - ) {       neg = -1;       ch = getchar();     }     while (isdigit(ch)) {       num = (num << 3) + (num << 1) + (ch -  0 );       ch = getchar();     }     return num * neg;   }   inline void calc1(int n) {     if (n <= 0) {       return;     }     int x = 31 - __builtin_clz(n);     reverse(res + (1 << x + 1) - n - 1, res + n + 1);     calc1((1 << x + 1) - n - 2);   }   inline void solve1() {     if (n & 1) {       return (void)puts( NO );     }     puts( YES );     for (register int i = 1; i <= n; i++) {       res[i] = i;     }     calc1(n);     for (register int i = 1; i <= n; i++) {       printf( %d  , res[i]);     }     puts(  );   }   inline void solve2() {     if (n == 3 || n == 5 || n == (n & -n)) {       return (void)puts( NO );     }     puts( YES );     for (register int i = 1; i <= n; i++) {       res[i] = i;     }     if (n & 1) {       printf( 3 6 1 5 7 2 4  );       for (register int i = 8; i <= n; i += 2) {         swap(res[i], res[i ^ 1]);       }       for (register int i = 8; i <= n; i++) {         printf( %d  , res[i]);       }     } else {       for (register int i = 2; i <= n - 3; i += 2) {         swap(res[i], res[i + 1]);       }       swap(res[1], res[n - 1]), swap(res[n], res[n - 2]);       for (register int i = 1; i <= n; i++) {         printf( %d  , res[i]);       }     }     puts(  );   }   int main() { n = read(), solve1(), solve2(); }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long sum = 0, sum2 = 0;     scanf( %d , &n);     int nav[200005];     for (int i = 0; i < n; i++) scanf( %d , &nav[i]), sum += nav[i];     for (int i = 0; i < n; i++) {       sum2 += nav[i];       if (sum2 >= (sum + 1) / 2) {         printf( %d , i + 1);         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353, N = 3e5 + 6;   long long n, k, t;   void solve() {     cin >> n >> k;     long long t = 1;     while (t * 10 <= n) t *= 10;     while (k > 1) {       t = 1;       while (t * 10 <= n) t *= 10;       while (n - t < k - 1) t /= 10;       cout << t <<    ;       n -= t;       k--;     }     cout << n;   }   int main() {     long long tt = 1;     cin >> tt;     while (tt--) {       solve();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int sa = 0, sb = 0;     int ca, cb;     char* c;     int i = 0;     scanf( %d , &n);     c = (char*)malloc(sizeof(char) * n);     while (n--) {       scanf( %d %d , &ca, &cb);       if (sb + cb > sa + 500) {         sa = sa + ca;         c[i++] =  A ;       } else {         sb += cb;         c[i++] =  G ;       }     }     c[i] =   0 ;     if (abs(sb - sa) <= 500)       printf( %s n , c);     else       printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void pause() {}   bool sortbysecdesc(const pair<int, int> &a, const pair<int, int> &b) {     return a.second > b.second;   }   int rec(int n, int i, int a[], int c) {     c++;     if (n == i) return c;     rec(a[n - 1], i, a, c);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, a[1005], c = 0;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> a[i];       }       sort(a, a + n);       for (int i = n - 1; i >= 0; i--) {         c++;         if (c == a[i]) {           cout << c;           break;         } else if (c > a[i]) {           cout << c - 1;           break;         }       }       cout <<   n ;     }     pause();   }


#include <bits/stdc++.h>   using namespace std;   int xx[8] = {0, 0, 1, -1, 1, -1, 1, -1};   int yy[8] = {-1, 1, 0, 0, 1, -1, -1, 1};   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long int n;     cin >> n;     bool flag = true;     vector<long long int> v(n);     for (long long int i = 0; i < n; i++) cin >> v[i];     long long int pos1 = -1, pos2 = -1;     for (long long int i = 0; i < n; i++) {       if (v[i] == 1) {         pos1 = i;         break;       }     }     if (pos1 == -1) {       cout <<  0 ;       return 0;     }     for (int j = n - 1; j >= 0; j--) {       if (v[j] == 1) {         pos2 = j;         break;       }     }     long long int c = 1, ans = 1;     if (pos1 == pos2) {       cout << 1 <<   n ;       return 0;     } else {       for (long long int i = pos1; i < pos2 + 1; i++) {         if (v[i] == 0) {           c++;         } else {           ans *= c;           c = 1;         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int c, v0, v1, a, l;     cin >> c >> v0 >> v1 >> a >> l;     int d = 1;     int r = v0;     int tmp = v0;     while (1) {       if (r >= c) break;       tmp = tmp + a;       if (tmp > v1) tmp = v1;       r += (tmp - l);       d++;     }     cout << d << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2010;   int n, a[N], m;   double f[N][N], p, ans;   inline int read() {     int x = 0;     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) x = (x << 3) + (x << 1) + ch - 48, ch = getchar();     return x;   }   int main() {     scanf( %d%lf%d , &n, &p, &m);     f[0][0] = 1;     for (int i = 1; i <= m; i++) {       f[i][0] = (1 - p) * f[i - 1][0];       for (int j = 1; j <= n - 1; j++)         f[i][j] = f[i - 1][j] * (1 - p) + f[i - 1][j - 1] * p;       f[i][n] = f[i - 1][n] + f[i - 1][n - 1] * p;     }     for (int i = 1; i <= n; i++) ans += f[m][i] * i;     printf( %lf , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2200;   char s[MAXN], t[MAXN];   int l[MAXN], r[MAXN];   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n, k, m = 0;       scanf( %d%d%s , &n, &k, s + 1);       for (int i = 1; i < k; i++) t[2 * i - 1] =  ( , t[2 * i] =  ) ;       for (int i = 2 * k - 1; i < k + n / 2; i++) t[i] =  ( ;       for (int i = k + n / 2; i <= n; i++) t[i] =  ) ;       for (int i = 1; i <= n; i++)         if (s[i] != t[i]) {           int k;           for (int j = i + 1; j <= n; j++)             if (s[j] == t[i]) {               k = j;               break;             }           l[++m] = i;           r[m] = k;           reverse(s + i, s + k + 1);         }       printf( %d n , m);       for (int i = 1; i <= m; i++) printf( %d %d n , l[i], r[i]);     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   long long mulmod(long long a, long long b, long long MOD) {     if (b == 0) return 0;     long long res = mulmod(a, b >> 1, MOD);     res += res;     res %= MOD;     return (b & 1) ? (a + res) % MOD : res;   }   int main() {     ios::sync_with_stdio(0);     long long t1, t2, x1, x2, t0;     cin >> t1 >> t2 >> x1 >> x2 >> t0;     long long ans1 = 3000000000000ll, ans2 = 1, ii = 0, jj = 0;     if (t1 == t0) {       if (t2 == t0) {         cout << x1 <<     << x2 << endl;         return 0;       } else {         cout << x1 <<     << 0 << endl;         return 0;       }     }     if (t2 == t0) {       cout << 0 <<     << x2 << endl;       return 0;     }     if (t0 <= t1) {       ii = x1;       jj = 0;       ans1 = x1 * t1;       ans2 = x1;     }     if (t0 <= t2 &&         (ans1 == 3000000000000ll || (t2 < t1 || (t2 == t1 && x2 > x1)))) {       ii = 0;       jj = x2;       ans1 = x2 * t2;       ans2 = x2;     }     for (long long i = 0; i <= x1; i++) {       long long j = (i * (t0 - t1)) / (t2 - t0);       if ((i * (t0 - t1)) % (t2 - t0) != 0) {         j++;       }       if (i == 0 && j == 0) continue;       if (j < 0 || j > x2) {         continue;       }       if (ans1 * (i + j) > (i * t1 + j * t2) * ans2) {         ans1 = (i * t1 + j * t2);         ans2 = (i + j);         ii = i;         jj = j;       } else {         if (ans1 * (i + j) == (i * t1 + j * t2) * ans2 && ans2 < (i + j)) {           ans1 = (i * t1 + j * t2);           ans2 = (i + j);           ii = i;           jj = j;         }       }     }     cout << ii <<     << jj << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     map<long long, long long> row, col;     row.clear();     col.clear();     long long aRow = 0, aCol = 0, res = n * n;     while (k--) {       long long x, y;       cin >> x >> y;       if (!row[x] && !col[y]) {         row[x] = 1;         col[y] = 1;         res -= (2 * n - 1 - aRow - aCol);         aRow++;         aCol++;         cout << res;       } else if (row[x] && col[y]) {         cout << res;       } else if (row[x]) {         res -= (n - aRow);         col[y] = 1;         aCol++;         cout << res;       } else if (col[y]) {         res -= (n - aCol);         row[x] = 1;         aRow++;         cout << res;       }       if (k)         cout <<    ;       else         cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int l, r;     cin >> l >> r;     int a{r}, b{max(r / 2 + 1, l)};     cout << a % b <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int t{1};     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d, start = 0;     cin >> n >> d;     vector<string> s(d);     for (string &e : s) cin >> e;     vector<int> win(d);     for (int i = 0; i < s.size(); i++) {       string q = s[i];       if (q.find( 0 ) <= q.length()) {         win[start]++;       } else {         start++;       }     }     sort(win.begin(), win.end(), greater<int>());     cout << win[0] << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct arra {     long long int d = 0, idx;   } arr[200008];   bool comp(struct arra a, struct arra b) { return a.d > b.d; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, k, a, temp, ans;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a;       arr[a].d++;       arr[a].idx = a;     }     sort(arr, arr + 200005, comp);     long long int l = 1, r = 200008, mid;     while (l <= r) {       mid = (l + r) / 2;       temp = 0;       for (int i = 0; i < n; i++) {         temp += arr[i].d / mid;       }       if (temp >= k) {         ans = mid;         l = mid + 1;       } else         r = mid - 1;     }     vector<long long> v;     for (int i = 0; i < n; i++) {       for (int j = 0; j < arr[i].d / ans; j++) {         v.push_back(arr[i].idx);       }     }     for (int i = 0; i < k; i++) cout << v[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool solve(int cn) {     int n, k;     cin >> n >> k;     vector<int> soldiers(n);     for (int i = (0); i < (n); i++) cin >> soldiers[i];     soldiers.push_back(1 << 30);     int coins = 0;     while (soldiers[0] < k) {       coins++;       for (int i = (0); i < (n); i++) {         while (soldiers[i] == soldiers[i + 1]) i++;         soldiers[i]++;       }     }     cout << coins << endl;     return 0;   }   int main() {     int cases = 1 << 30;     if (!cases) cin >> cases;     for (int cn = 1; cn <= cases && solve(cn); ++cn)       ;     return 0;   }


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