#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100001;   vector<pair<int, int> > g1[1000], g2[1000];   int edge_colors[MAXN];   pair<int, int> colors1[1000][1000];   pair<int, int> colors2[1000][1000];   int ans;   bool used[MAXN];   bool dfs(int v, int c1, int c2) {     if (used[v]) return false;     used[v] = true;     int to = colors1[v][c1].first;     int num = colors1[v][c1].second;     if (colors2[to][c2].first == -1) {       colors1[v][c1].first = -1;       colors1[v][c1].second = -1;       colors2[to][c1].first = -1;       colors2[to][c1].second = -1;       edge_colors[colors1[v][c1].second] = -1;       edge_colors[colors2[to][c1].second] = -1;       colors1[v][c2].first = to;       colors1[v][c2].second = num;       colors2[to][c2].first = v;       colors2[to][c2].second = num;       edge_colors[num] = c2;       return true;     }     int mto = colors2[to][c2].first;     int mto_num = colors2[to][c2].second;     if (colors1[mto][c1].first == -1) {       colors1[mto][c2].first = -1;       colors1[mto][c2].second = -1;       edge_colors[colors1[mto][c2].second] = -1;       colors1[mto][c1].first = to;       colors1[mto][c1].second = mto_num;       colors2[to][c1].first = mto;       colors2[to][c1].second = mto_num;       edge_colors[mto_num] = c1;       colors1[v][c1].first = -1;       colors1[v][c1].second = -1;       edge_colors[colors1[v][c1].second] = -1;       colors1[v][c2].first = to;       colors1[v][c2].second = num;       colors2[to][c2].first = v;       colors2[to][c2].second = num;       edge_colors[num] = c2;       return true;     } else if (dfs(mto, c1, c2)) {       colors1[mto][c1].first = to;       colors1[mto][c1].second = mto_num;       colors2[to][c1].first = mto;       colors2[to][c1].second = mto_num;       edge_colors[mto_num] = c1;       colors1[v][c1].first = -1;       colors1[v][c1].second = -1;       edge_colors[colors1[v][c1].second] = -1;       colors1[v][c2].first = to;       colors1[v][c2].second = num;       colors2[to][c2].first = v;       colors2[to][c2].second = num;       edge_colors[num] = c2;       return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     int a, b, m;     cin >> a >> b >> m;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       g1[x].emplace_back(make_pair(y, i));       g2[y].emplace_back(make_pair(x, i));     }     for (int i = 0; i < a; i++)       if (g1[i].size() > ans) ans = g1[i].size();     for (int i = 0; i < b; i++)       if (g2[i].size() > ans) ans = g2[i].size();     for (int i = 0; i < 1000; i++)       for (int j = 0; j < 1000; j++) {         colors1[i][j] = make_pair(-1, -1);         colors2[i][j] = make_pair(-1, -1);       }     fill(edge_colors, edge_colors + m, -1);     for (int i = 0; i < a; i++) {       for (int j = 0; j < g1[i].size(); j++) {         int to = g1[i][j].first;         int num = g1[i][j].second;         if (edge_colors[num] == -1) {           bool ok = false;           for (int q = 0; q < ans; q++) {             if ((colors1[i][q].first == -1) && (colors2[to][q].first == -1)) {               edge_colors[num] = q;               colors1[i][q].first = to;               colors1[i][q].second = num;               colors2[to][q].first = i;               colors2[to][q].second = num;               ok = true;               break;             }           }         }       }     }     for (int i = 0; i < a; i++) {       for (int j = 0; j < g1[i].size(); j++) {         int to = g1[i][j].first;         int num = g1[i][j].second;         if (edge_colors[num] == -1) {           bool ok = false;           for (int q = 0; q < ans; q++) {             if ((colors1[i][q].first == -1) && (colors2[to][q].first == -1)) {               edge_colors[num] = q;               colors1[i][q].first = to;               colors1[i][q].second = num;               colors2[to][q].first = i;               colors2[to][q].second = num;               ok = true;               break;             }           }           if (!ok) {             int c1 = -1, c2 = -1;             for (int q = 0; q < ans; q++) {               if ((colors1[i][q].first != -1) && (colors2[to][q].first == -1))                 c1 = q;               if ((colors1[i][q].first == -1) && (colors2[to][q].first != -1))                 c2 = q;             }             fill(used, used + a, false);             used[i] = true;             if ((c1 == -1) || (c2 == -1))               while (true)                 ;             int mto = colors2[to][c2].first;             int mto_num = colors2[to][c2].second;             if (colors1[mto][c1].first == -1) {               colors1[mto][c2].first = -1;               colors1[mto][c2].second = -1;               edge_colors[colors1[mto][c2].second] = -1;               colors1[mto][c1].first = to;               colors1[mto][c1].second = mto_num;               colors2[to][c1].first = mto;               colors2[to][c1].second = mto_num;               edge_colors[mto_num] = c1;               colors1[i][c2].first = to;               colors1[i][c2].second = num;               colors2[to][c2].first = i;               colors2[to][c2].second = num;               edge_colors[num] = c2;             } else if (dfs(mto, c1, c2)) {               colors1[mto][c1].first = to;               colors1[mto][c1].second = mto_num;               colors2[to][c1].first = mto;               colors2[to][c1].second = mto_num;               edge_colors[mto_num] = c1;               colors1[i][c2].first = to;               colors1[i][c2].second = num;               colors2[to][c2].first = i;               colors2[to][c2].second = num;               edge_colors[num] = c2;             }           }         }       }     }     for (int i = 0; i < a; i++)       for (int q = 0; q < ans; q++)         if (colors1[i][q].first != -1) edge_colors[colors1[i][q].second] = q;     cout << ans << endl;     for (int i = 0; i < m; i++) {       cout << edge_colors[i] + 1 <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     long long arr[n + 1];     long long sum = 0;     for (long long i = 1; i <= n; i++) {       cin >> arr[i];       sum += arr[i];     }     if (sum % n != 0) {       cout << -1 <<   n ;       return;     }     vector<pair<long long, pair<long long, long long>>> ans;     for (long long i = 2; i <= n; i++) {       long long brak = (i - arr[i] % i) % i;       ans.push_back(make_pair(1, make_pair(i, brak)));       arr[1] -= brak;       arr[i] += brak;       ans.push_back(make_pair(i, make_pair(1, arr[i] / i)));       arr[1] += arr[i];       arr[i] = 0;     }     for (long long i = 2; i <= n; i++) {       ans.push_back(make_pair(1, make_pair(i, sum / n)));     }     cout << ans.size() <<   n ;     for (auto x : ans) {       cout << x.first <<     << x.second.first <<     << x.second.second <<   n ;     }   }   int32_t main() {     {       ios_base::sync_with_stdio(false);       cin.tie(NULL);     }     long long t = 1;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void trace_() { cerr <<   n ; }   template <typename T1, typename... T2>   void trace_(T1 t1, T2... t2) {     cerr <<     << t1;     trace_(t2...);   }   const long long mxN = 1e3 + 5;   long long n, a, b;   vector<long long> g[mxN];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     cin >> n;     vector<pair<long long, long long> > v1, v2;     for (long long i = 0; i < n - 3; i++) {       cin >> a >> b;       if (a > b) swap(a, b);       if (a != 1) v1.emplace_back(a, b);     }     sort(v1.begin(), v1.end(),          [](pair<long long, long long> a, pair<long long, long long> b) {            if (a.first == b.first) return a.second > b.second;            return a.first < b.first;          });     for (long long i = 0; i < n - 3; i++) {       cin >> a >> b;       if (a > b) swap(a, b);       g[a].push_back(b);     }     for (long long i = 2; i <= n; i++) {       sort(g[i].begin(), g[i].end());       reverse(g[i].begin(), g[i].end());       for (long long j = 1; j < (long long)(g[i].size()); j++)         v2.emplace_back(1, g[i][j]);       if ((long long)(g[i].size()) >= 1) v2.emplace_back(1, i + 1);     }     cout << (long long)(v1.size()) + (long long)(v2.size()) <<   n ;     for (pair<long long, long long> i : v1)       cout << i.first <<     << i.second <<   n ;     reverse(v2.begin(), v2.end());     for (pair<long long, long long> i : v2)       cout << i.first <<     << i.second <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   inline bool check(int x) {     for (; x; x /= 10)       if (x % 10 != 4 && x % 10 != 7) return 0;     return 1;   }   const int maxn = 100100;   int head[maxn], nxt[maxn << 1], ver[maxn << 1], val[maxn << 1], tot;   inline void addedge(int a, int b, int c) {     nxt[++tot] = head[a];     ver[tot] = b;     val[tot] = c;     head[a] = tot;     nxt[++tot] = head[b];     ver[tot] = a;     val[tot] = c;     head[b] = tot;   }   int size[maxn], sum[maxn];   int n, m;   inline void getsize(int x, int fat) {     size[x] = 1;     sum[x] = 0;     for (int i = head[x]; i; i = nxt[i]) {       int y = ver[i];       if (y == fat) continue;       getsize(y, x);       size[x] += size[y];       sum[x] += val[i] ? size[y] : sum[y];     }   }   long long ans = 0;   inline void getans(int x, int fat, int upv) {     ans += 1ll * (upv + sum[x]) * (upv + sum[x] - 1);     for (int i = head[x]; i; i = nxt[i]) {       int y = ver[i];       if (y == fat) continue;       getans(y, x, val[i] ? (size[1] - size[y]) : (upv + sum[x] - sum[y]));     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       addedge(a, b, check(c));     }     getsize(1, 0);     getans(1, 0, 0);     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   vector<int> AdjList[maxn];   bool vis[maxn];   int child[maxn];   char ans[maxn];   int n;   void dfs(int s, int p = -1) {     child[s] = 1;     for (int u : AdjList[s]) {       if (vis[u]) continue;       if (u == p) continue;       dfs(u, s);       child[s] += child[u];     }   }   int find_cen(int s, int p, int sz) {     for (int u : AdjList[s]) {       if (vis[u]) continue;       if (u == p) continue;       if (child[u] * 2 > sz) return find_cen(u, s, sz);     }     return s;   }   void centroid(int u, char c) {     dfs(u, u);     int cen = find_cen(u, u, child[u]);     ans[cen] = c;     vis[cen] = 1;     for (int v : AdjList[cen]) {       if (vis[v]) continue;       centroid(v, c + 1);     }   }   signed main() {     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       AdjList[u].push_back(v);       AdjList[v].push_back(u);     }     centroid(1,  A );     for (int i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-9;   const long long INF = 1000000000;   const int MAXN = 128;   int points[] = {0, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1};   int t, n;   map<string, vector<int> > places;   map<string, int> score;   struct T {     string name;     vector<int> place;     int score;   };   bool cmp1(const T& a, const T& b) {     if (a.score != b.score) return a.score > b.score;     for (int i = 1; i <= 55; ++i)       if (a.place[i] != b.place[i]) return a.place[i] > b.place[i];     return a.name < b.name;   }   bool cmp2(const T& a, const T& b) {     if (a.place[1] != b.place[1]) return a.place[1] > b.place[1];     if (a.score != b.score) return a.score > b.score;     for (int i = 2; i <= 55; ++i)       if (a.place[i] != b.place[i]) return a.place[i] > b.place[i];     return a.name < b.name;   }   int main() {     cin >> t;     for (int tt = 0; tt < t; ++tt) {       cin >> n;       for (int i = 1; i <= n; ++i) {         string s;         cin >> s;         int kk = 0;         if (i <= 10) kk = points[i];         score[s] += kk;         if (places.find(s) == places.end()) places[s] = vector<int>(60);         places[s][i]++;       }     }     map<string, int>::iterator it;     vector<T> a;     for (it = score.begin(); it != score.end(); ++it) {       a.push_back(T());       a.back().name = it->first;       a.back().place = places[it->first];       a.back().score = it->second;     }     sort((a).begin(), (a).end(), cmp1);     cout << a[0].name << endl;     sort((a).begin(), (a).end(), cmp2);     cout << a[0].name << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class _T>   inline _T sqr(const _T &first) {     return first * first;   }   template <class _T>   inline string tostr(const _T &a) {     ostringstream os(  );     os << a;     return os.str();   }   const long double PI = 3.1415926535897932384626433832795L;   const long double EPS = 5e-12;   char TEMPORARY_CHAR;   const int INF = 1e9;   inline void fft(vector<complex<long double> > &a, bool invert) {     int n = (int)a.size();     for (int i = 1, j = 0; i < n; ++i) {       int bit = n >> 1;       for (; j >= bit; bit >>= 1) j -= bit;       j += bit;       if (i < j) swap(a[i], a[j]);     }     for (int len = 2; len <= n; len <<= 1) {       long double ang = 2 * PI / len * (invert ? -1 : 1);       complex<long double> wlen(cos(ang), sin(ang));       for (int i = 0; i < n; i += len) {         complex<long double> w(1);         for (int j = 0; j < len / 2; ++j) {           complex<long double> u = a[i + j], v = a[i + j + len / 2] * w;           a[i + j] = u + v;           a[i + j + len / 2] = u - v;           w *= wlen;         }       }     }     if (invert)       for (int i = 0; i < n; ++i) a[i] /= n;   }   inline void input(int &a) {     a = 0;     while (((TEMPORARY_CHAR = getchar()) >  9  || TEMPORARY_CHAR <  0 ) &&            (TEMPORARY_CHAR !=  - )) {     }     char neg = 0;     if (TEMPORARY_CHAR ==  - ) {       neg = 1;       TEMPORARY_CHAR = getchar();     }     while (TEMPORARY_CHAR <=  9  && TEMPORARY_CHAR >=  0 ) {       a = (a << 3) + (a << 1) + TEMPORARY_CHAR -  0 ;       TEMPORARY_CHAR = getchar();     }     if (neg) a = -a;   }   inline void out(long long a) {     if (!a) putchar( 0 );     if (a < 0) {       putchar( - );       a = -a;     }     char s[20];     int i;     for (i = 0; a; ++i) {       s[i] =  0  + a % 10;       a /= 10;     }     for (int j = (i)-1; j >= 0; j--) putchar(s[j]);   }   inline int nxt() {     int(ret);     input((ret));     ;     return ret;   }   struct lnum {     vector<int> a;     int base;     lnum(int num = 0, int base = 1000000000) : base(base) {       if (!num) a.resize(1);       while (num) {         a.push_back(num % base);         num /= base;       }     }     inline int len() const { return a.size(); }     lnum &operator=(const lnum &l) {       if (this != &l) {         a = l.a;         base = l.base;       }       return *this;     }     inline friend lnum operator+(const lnum &l, const lnum &r) {       lnum ret(0, l.base);       int base = l.base;       int ln = l.len(), rn = r.len();       int n = max(ln, rn);       ret.a.resize(n);       int o = 0;       for (int i = 0; i < n; ++i) {         int s = o;         if (i < ln) s += l.a[i];         if (i < rn) s += r.a[i];         o = s >= base;         if (o) s -= base;         ret.a[i] = s;       }       if (o) ret.a.push_back(1);       return ret;     }     inline friend lnum operator-(const lnum &l, const lnum &r) {       lnum ret(0, l.base);       int base = l.base;       int n = l.len();       int rn = r.len();       ret.a.resize(n);       int o = 0;       for (int i = 0; i < n; ++i) {         int s = l.a[i] - o;         if (i < rn) s -= r.a[i];         o = s < 0;         if (o) s += base;         ret.a[i] = s;       }       if (ret.len() > 1 && !ret.a.back()) ret.a.pop_back();       return ret;     }     inline friend lnum operator*(const lnum &l, const lnum &r) {       lnum ret(0, l.base);       int base = l.base;       if (l.len() * r.len() > 1000000) {         vector<complex<long double> > fa(l.a.begin(), l.a.end()),             fb(r.a.begin(), r.a.end());         int n = 1;         while (n < max(l.len(), r.len())) n <<= 1;         n <<= 1;         fa.resize(n), fb.resize(n);         fft(fa, false), fft(fb, false);         for (int i = 0; i < n; ++i) fa[i] *= fb[i];         fft(fa, true);         ret.a.resize(n);         for (int i = 0; i < n; ++i) ret.a[i] = int(fa[i].real() + 0.5);         int carry = 0;         for (int i = 0; i < n; ++i) {           ret.a[i] += carry;           carry = ret.a[i] / base;           ret.a[i] %= base;         }       } else {         ret.a.resize(l.len() + r.len());         for (int i = 0; i < l.len(); ++i)           for (int j = 0, carry = 0; j < r.len() || carry; ++j) {             long long cur = ret.a[i + j] +                             (long long)l.a[i] * (j < r.len() ? r.a[j] : 0) +                             carry;             ret.a[i + j] = cur % base;             carry = cur / base;           }       }       while (ret.len() > 1 && !ret.a.back()) ret.a.pop_back();       return ret;     }     inline friend lnum operator/(const lnum &l, const int &r) {       lnum ret(0, l.base);       ret.a.resize(l.len());       int carry = 0;       for (int i = l.len() - 1; i >= 0; --i) {         long long cur = l.a[i] + (long long)carry * l.base;         ret.a[i] = cur / r;         carry = cur % r;       }       while (ret.len() > 1 && ret.a.back() == 0) ret.a.pop_back();       return ret;     }     inline friend bool operator<(const lnum &l, const lnum &r) {       if (l.len() < r.len()) return true;       if (l.len() > r.len()) return false;       int n = l.len();       for (int i = n - 1; i >= 0; --i) {         if (l.a[i] < r.a[i]) return true;         if (l.a[i] > r.a[i]) return false;       }       return false;     }     inline friend bool operator>(const lnum &l, const lnum &r) { return r < l; }     inline friend bool operator==(const lnum &l, const lnum &r) {       if (l.len() != r.len()) return false;       int n = l.len();       for (int i = n - 1; i; --i) {         if (l.a[i] != r.a[i]) return false;       }       return true;     }     inline friend bool operator!=(const lnum &l, const lnum &r) {       return !(l == r);     }     inline void print() {       if (base == 1000000000) {         printf( %d , a.back());         for (int i = a.size() - 2; i >= 0; --i) printf( %09d , a[i]);       } else {         for (int i = a.size() - 1; i >= 0; --i) printf( %d , a[i]);       }     }   };   struct item {     int key, prior;     item *l, *r;     item() {}     item(int key, int prior) : key(key), prior(prior), l(NULL), r(NULL) {}   };   typedef item *pitem;   void split(pitem t, int key, pitem &l, pitem &r) {     if (!t)       l = r = NULL;     else if (key < t->key)       split(t->l, key, l, t->l), r = t;     else       split(t->r, key, t->r, r), l = t;   }   void merge(pitem &t, pitem l, pitem r) {     if (!l || !r)       t = l ? l : r;     else if (l->prior > r->prior)       merge(l->r, l->r, r), t = l;     else       merge(r->l, l, r->l), t = r;   }   int ans[300000];   void dfs(pitem v, int ind) {     if (!v) return;     if (v->key != ind) {       ans[v->key] = ind + 1;     }     dfs(v->l, ind);     dfs(v->r, ind);   }   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     memset((ans), 0, sizeof(ans));     pitem root = NULL;     for (int i = 0; i < (int)(n); i++) {       merge(root, root, new item(i, rand()));     }     int l, r, ind;     for (int i = 0; i < (int)(m); i++) {       cin >> l >> r >> ind;       l--;       r--;       ind--;       pitem q1, otr, q2;       split(root, l - 1, q1, otr);       split(otr, r, otr, q2);       dfs(otr, ind);       merge(root, q1, new item(ind, rand()));       merge(root, root, q2);     }     for (int i = 0; i < (int)(n); i++) {       if (i) cout <<    ;       cout << ans[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[300005];   int sign(long long x) { return x > 0 ? 1 : -1; }   struct Node {     int l, r, lx, mx, rx;     void up(Node L, Node R) {       lx = L.lx;       rx = R.rx;       mx = max(L.mx, R.mx);       if (a[L.r] && a[R.l] && sign(a[L.r]) >= sign(a[R.l])) {         mx = max(mx, L.rx + R.lx);         if (L.mx == L.r - L.l + 1) lx = L.mx + R.lx;         if (R.mx == R.r - R.l + 1) rx = R.mx + L.rx;       }       mx = max({mx, lx, rx});     }   } seg[300005 * 4];   void update(int qx, int c, int l, int r, int i) {     seg[i] = {l, r};     if (l == r) {       a[qx] += c;       if (a[qx] != 0)         seg[i] = {l, r, 1, 1, 1};       else         seg[i] = {l, r, 0, 0, 0};       return;     }     int mid = (l + r) / 2;     if (qx <= mid)       update(qx, c, l, mid, i * 2);     else       update(qx, c, mid + 1, r, i * 2 + 1);     seg[i].up(seg[i * 2], seg[i * 2 + 1]);   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %I64d , &a[i]);     for (int i = 1; i < n; ++i) a[i] = a[i + 1] - a[i];     for (int i = 1; i < n; ++i) update(i, 0, 1, n - 1, 1);     int Q;     scanf( %d , &Q);     while (Q--) {       int l, r, x;       scanf( %d%d%d , &l, &r, &x);       if (l > 1) update(l - 1, x, 1, n - 1, 1);       if (r < n) update(r, -x, 1, n - 1, 1);       printf( %d n , seg[1].mx + 1);     }   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( O3 )   #pragma GCC optimize( O2 )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   const double pi =       3.141592653589793238462643383279502884197169399375105820974944;   const double e = 2.71828182845904523536028747135266249775724709369995;   const long long mod = 1e9 + 7;   const long long inf = 2e18;   const long long ninf = -2e18;   const long long nax = 1e6;   long long power(long long x, long long y, long long mod) {     long long ans = 1;     x %= mod;     while (y) {       if (y & 1) ans = (x * ans) % mod;       x = (x * x) % mod;       y >>= 1;     }     return ans;   }   template <class T>   struct search_buckets {     int N, BUCKET_SIZE;     vector<T> arr, buckets;     search_buckets(const vector<T>& initial = {}) {       arr = buckets = initial;       N = arr.size();       BUCKET_SIZE = 3 * sqrtl(N * log(N + 1)) + 1;       cerr <<  Bucket size:   << BUCKET_SIZE <<   n ;       for (int start = 0; start < N; start += BUCKET_SIZE) {         sort(buckets.begin() + start, buckets.begin() + get_bucket_end(start));       }     }     int get_bucket_end(int bucket_start) const {       return min(bucket_start + BUCKET_SIZE, N);     }     int bucket_less_than(int bucket_start, T value) const {       auto begin = buckets.begin() + bucket_start;       auto end = buckets.begin() + get_bucket_end(bucket_start);       return lower_bound(begin, end, value) - begin;     }     int less_than(int start, int end, T value) const {       int count = 0;       int bucket_start = start - start % BUCKET_SIZE;       int bucket_end = min(get_bucket_end(bucket_start), end);       if (start - bucket_start < bucket_end - start) {         while (start > bucket_start) {           count -= arr[--start] < value;         }       } else {         while (start < bucket_end) {           count += arr[start++] < value;         }       }       if (start == end) return count;       bucket_start = end - end % BUCKET_SIZE;       bucket_end = get_bucket_end(bucket_start);       if (end - bucket_start < bucket_end - end) {         while (end > bucket_start) {           count += arr[--end] < value;         }       } else {         while (end < bucket_end) {           count -= arr[end++] < value;         }       }       while (start < end && get_bucket_end(start) <= end) {         count += bucket_less_than(start, value);         start = get_bucket_end(start);       }       assert(start == end);       return count;     }     int prefix_less_than(int n, T value) const { return less_than(0, n, value); }     void modify(int index, T value) {       int bucket_start = index - index % BUCKET_SIZE;       int old_pos = bucket_start + bucket_less_than(bucket_start, arr[index]);       int new_pos = bucket_start + bucket_less_than(bucket_start, value);       if (old_pos < new_pos) {         copy(buckets.begin() + old_pos + 1, buckets.begin() + new_pos,              buckets.begin() + old_pos);         new_pos--;       } else {         copy_backward(buckets.begin() + new_pos, buckets.begin() + old_pos,                       buckets.begin() + old_pos + 1);       }       buckets[new_pos] = value;       arr[index] = value;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     time_t t1, t2;     t1 = clock();     int n;     cin >> n;     vector<int> a(n + 1);     for (int i = 1; i <= n; i++) {       cin >> a[i];       a[i] = min(a[i], n);     }     search_buckets<int> st(a);     long long ans = 0;     for (int i = 1; i <= n; i++) {       int lol = a[i] - st.less_than(1, a[i] + 1, i) - (a[i] >= i);       ;       ans += lol;     }     cout << ans / 2;     t2 = clock();     cerr <<   n           <<  time taken:   << t2 - t1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100010;   const int INF = 1000000;   int n;   stack<int> killers;   int main() {     cin >> n;     int values[n + 1], life[n + 1];     for (int i = 1; i <= n; ++i) {       cin >> values[i];     }     life[0] = INF;     values[0] = 0;     killers.push(0);     for (int i = 1; i <= n; ++i) {       life[i] = 1;       while (killers.size() && values[i] > values[killers.top()]) {         life[i] = max(life[i], life[killers.top()] + 1);         killers.pop();       }       killers.push(i);     }     int sol = 0;     for (int i = 1; i <= n; ++i) {       if (life[i] < INF) {         sol = max(sol, life[i]);       }     }     cout << sol << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; ++i) {       cin >> arr[i];     }     for (int j = 0; j < n; ++j) {       if (arr[j] == 0)         if (j == (n - 1))           cout <<  EASY  << endl;         else           continue;       else {         cout <<  HARD  << endl;         break;       }     }     return 0;   };


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k, l, m, n;     int a[1001];     char s[1000], c;     while (scanf( %d%d , &n, &m) != EOF) {       memset(a, 0, sizeof(a));       while (m--) {         scanf( %s , s);         scanf( %s , s);         scanf( %s , s);         c = s[0];         scanf( %s , s);         scanf( %d , &k);         if (c ==  r ) {           for (i = 1; i <= k; i++) a[i] = 1;         } else {           for (i = k; i <= n; i++) a[i] = 1;         }       }       k = 0;       for (i = 1; i <= n; i++)         if (a[i] == 0) k++;       if (k == 0)         printf( -1 n );       else         printf( %d n , k);     }   }


#include <bits/stdc++.h>   using namespace std;   char str[100];   int L;   bool ok(int n) {     if (n == 0) return true;     set<string> S;     for (int i = 0; i + n <= L; i++) {       string temp(str + i, str + i + n);       if (!S.insert(temp).second) return true;     }     return false;   }   int main() {     scanf( %s , str);     L = strlen(str);     int low = 0, high = L;     while (high - low > 1) {       int mid = (low + high) / 2;       if (ok(mid)) {         low = mid;       } else {         high = mid;       }     }     if (ok(high)) {       printf( %d n , high);     } else {       printf( %d n , low);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, a;     cin >> n >> k;     a = n - (k - (2 * n));     if (a >= 0)       cout << a;     else       cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long hash1 = 201326611;   const int inf = 0x3f3f3f3f;   const int _inf = 0xc0c0c0c0;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long _INF = 0xc0c0c0c0c0c0c0c0;   const long long mod = (int)1e9 + 7;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long ksm(long long a, long long b, long long mod) {     int ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return ans;   }   long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); }   void exgcd(long long a, long long b, long long &x, long long &y, long long &d) {     if (!b) {       d = a;       x = 1;       y = 0;     } else {       exgcd(b, a % b, y, x, d);       y -= x * (a / b);     }   }   inline int read() {     int date = 0, m = 1;     char ch = 0;     while (ch !=  -  && (ch< 0  | ch>  9 )) ch = getchar();     if (ch ==  - ) {       m = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       date = date * 10 + ch -  0 ;       ch = getchar();     }     return date * m;   }   const int MAX_N = 150025;   int C[MAX_N << 1], arr[MAX_N], b[MAX_N];   void add(int x, int v) {     for (; x < MAX_N; x += x & (-x)) C[x] += v;   }   int get(int x) {     int res = 0;     for (; x; x -= x & (-x)) res += C[x];     return res;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       for (int i = 1; i <= 2 * n + 2; ++i) C[i] = 0;       for (int i = 1; i <= n; ++i) scanf( %d , &arr[i]), b[i] = arr[i];       sort(b + 1, b + 1 + n);       int sz = unique(b + 1, b + 1 + n) - b - 1;       int ans = 0;       for (int i = n; i >= 1; --i) {         arr[i] = lower_bound(b + 1, b + 1 + sz, arr[i]) - b;         ans += min(get(arr[i]), 1);         add(arr[i] + 1, 1);       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   stack<int> S;   int a[1005], n;   bool judge() {     for (int i = 0; i < n; i++)       if (a[i] != i) return 0;     return 1;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 0; i <= n; i++) {       if (judge()) {         cout <<  Yes  << endl;         return 0;       }       for (int j = 0; j < n; j += 2) a[j] = (a[j] + 1) % n;       for (int j = 1; j < n; j += 2) a[j] = (a[j] - 1 + n) % n;     }     cout <<  No  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string c =  ROYGBIV ;     vector<char> s;     for (int i = 0; i < n; i++) {       if (i <= 6)         s.push_back(c[i]);       else {         s.push_back(s[i - 4]);       }     }     for (int i = 0; i < n; i++) cout << s[i];   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool uax(T &x, T y) {     return (y > x) ? x = y, true : false;   }   template <typename T>   inline bool uin(T &x, T y) {     return (y < x) ? x = y, true : false;   }   template <typename T>   void kek(T ans) {     cout << ans << endl;     exit(0);   }   const int MOD = (int)1e9 + 7;   const long long INF = (long long)1e18 + 42;   int main() {     cin.tie(nullptr)->sync_with_stdio(false);     int n;     cin >> n;     vector<vector<int>> a(n);     vector<set<pair<int, int>>> b(3);     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       a[x].push_back(i);     }     vector<int> team(3, 0);     vector<int> ans;     for (int i = 0; i < n; ++i) {       for (int j : a[i]) {         b[i % 3].emplace(i, j);       }       if (b[i % 3].empty()) kek( Impossible );       auto it = b[i % 3].upper_bound({i - team[i % 3], n});       if (it == b[i % 3].begin()) kek( Impossible );       --it;       ans.push_back(it->second);       uax(team[i % 3], i - it->first);       b[i % 3].erase(it);     }     cout <<  Possible n ;     for (int i : ans) cout << 1 + i <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a, b;   long long tinh(long long n) {     long long l = 0, r = 1000001;     while (l < r) {       long long m = (l + r + 1) / 2;       long long t = m * m * m;       if (t > n)         r = m - 1;       else         l = m;     }     return l;   }   int main() {     scanf( %d , &n);     for (int i = (1); i <= (n); i++) {       scanf( %lld %lld , &a, &b);       long long res = tinh(a * b);       if (res * res * res == a * b && a % res == 0 && b % res == 0) {         printf( YES n );       } else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using Point = complex<int>;   using ll = long long;   ll cross(Point a, Point b) {     return 1LL * a.real() * b.imag() - 1LL * b.real() * a.imag();   }   ll det(Point a, Point b, Point c) { return cross(b - a, c - a); }   namespace std {   bool operator<(const Point& a, const Point& b) {     return make_pair(a.real(), a.imag()) < make_pair(b.real(), b.imag());   }   }  // namespace std   struct DynHull {     struct Node {       int bl, br, l, r, lc, rc;     };     vector<Node> T = {{-1, -1, -1, -1, 0, 0}};     vector<Point> P;     DynHull(vector<Point> P) : P(P) {}     bool leaf(int x) { return T[x].l == T[x].r; }     int combine(int lc, int rc, int ret = -1) {       if (!lc || !rc) return lc + rc;       if (ret == -1 || ret == lc || ret == rc) ret = T.size(), T.push_back({});       T[ret] = {-1, -1, T[lc].l, T[rc].r, lc, rc};       while (!leaf(lc) || !leaf(rc)) {         int a = T[lc].bl, b = T[lc].br, c = T[rc].bl, d = T[rc].br;         if (a != b && det(P[a], P[b], P[c]) > 0) {           lc = T[lc].lc;         } else if (c != d && det(P[b], P[c], P[d]) > 0) {           rc = T[rc].rc;         } else if (a == b) {           rc = T[rc].lc;         } else if (c == d) {           lc = T[lc].rc;         } else {           auto s1 = det(P[a], P[b], P[c]), s2 = det(P[a], P[b], P[d]);           assert(s1 >= s2);           auto xc = P[c].real(), xd = P[d].real(), xm = P[T[rc].l].real();           if (s1 == s2 || s1 * xd - s2 * xc < (s1 - s2) * xm) {             lc = T[lc].rc;           } else {             rc = T[rc].lc;           }         }       }       T[ret].bl = T[lc].l;       T[ret].br = T[rc].l;       return ret;     }     int Build(int b, int e) {       if (e - b == 1) {         T.push_back({b, b, b, b, 0, 0});         return T.size() - 1;       }       int m = (b + e) / 2;       return combine(Build(b, m), Build(m, e));     }     int Erase(int x, int pos) {       if (!x || T[x].r < pos || T[x].l > pos) return x;       return leaf(x) ? 0 : combine(Erase(T[x].lc, pos), Erase(T[x].rc, pos), x);     }     template <typename Callback>     void Hull(int x, Callback&& cb, int l = 0, int r = 1e9) {       if (!x || l > r) return;       if (leaf(x)) {         cb(T[x].l);         return;       }       Hull(T[x].lc, cb, l, min(r, T[x].bl));       Hull(T[x].rc, cb, max(l, T[x].br), r);     }   };   inline ll area(Point a, Point b, Point c) {     return (ll)(b.real() - a.real()) * (c.imag() - a.imag()) -            (ll)(b.imag() - a.imag()) * (c.real() - a.real());   }   vector<Point> convexHull(vector<Point> p) {     int n = p.size(), m = 0;     if (n < 3) return p;     vector<Point> hull(n + n);     sort(p.begin(), p.end());     for (int i = 0; i < n; ++i) {       while (m > 1 and area(hull[m - 2], hull[m - 1], p[i]) <= 0) --m;       hull[m++] = p[i];     }     for (int i = n - 2, j = m + 1; i >= 0; --i) {       while (m >= j and area(hull[m - 2], hull[m - 1], p[i]) <= 0) --m;       hull[m++] = p[i];     }     hull.resize(m - 1);     return hull;   }   const int LG = 18;   const int N = 100010;   int q, par[LG][N];   inline int prv(int i, int n) { return (i ? i : n) - 1; }   inline int nxt(int i, int n) { return i + 1 < n ? i + 1 : 0; }   int kthPar(int u, int k) {     for (int i = LG - 1; i >= 0; --i) {       assert(u != -1);       if (k & 1 << i) k ^= 1 << i, u = par[i][u];     }     return u;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<pair<Point, int>> pts(n);     map<Point, int> id;     for (int i = 0; i < n; ++i) {       int x, y;       cin >> x >> y;       pts[i] = make_pair(Point{x, y}, i);       id[Point{x, y}] = i;     }     if (n == 1) {       cin >> q;       while (q--) cout << 1 <<   n ;       return 0;     }     vector<pair<Point, int>> pts_copy = pts;     sort(pts.begin(), pts.end());     vector<Point> P(n);     vector<int> remap(n);     for (int i = 0; i < n; ++i) {       remap[i] = pts[i].second;       P[i] = pts[i].first;     }     auto LH = DynHull(P);     int lh = LH.Build(0, n);     for (int i = 0; i < n; ++i) P[i] = -P[i];     reverse(P.begin(), P.end());     auto UH = DynHull(P);     int uh = UH.Build(0, n);     vector<int> layer(n, -1);     for (int i = 0;; ++i) {       vector<int> all;       LH.Hull(lh, [&](int x) { all.push_back(x); });       UH.Hull(uh, [&](int x) { all.push_back(n - x - 1); });       if (all.empty()) break;       for (auto x : all) {         lh = LH.Erase(lh, x);         uh = UH.Erase(uh, n - x - 1);         layer[remap[x]] = i;       }     }     int up = *max_element(layer.begin(), layer.end()) + 1;     vector<vector<Point>> layers(up);     for (int i = 0; i < n; ++i) {       layers[layer[i]].emplace_back(pts_copy[i].first);     }     for (int i = 0; i < up; ++i) layers[i] = convexHull(layers[i]);     vector<int> pf(up);     for (int i = 0; i < up; ++i) {       pf[i] = layers[i].size();       if (i) pf[i] += pf[i - 1];     }     vector<int> whichLayer(n), whichPos(n);     for (int i = 0; i < up; ++i) {       for (int j = 0; j < layers[i].size(); ++j) {         auto x = layers[i][j];         whichLayer[id[x]] = i, whichPos[id[x]] = j;       }     }     memset(par, -1, sizeof par);     for (int i = 0; i + 1 < up; ++i) {       if (layers[i + 1].size() == 1) {         int to = id[layers[i + 1][0]];         for (auto x : layers[i]) par[0][id[x]] = to;         continue;       }       int k = 0, sz = layers[i + 1].size();       vector<int> to(layers[i].size());       for (int j = 0; j < layers[i].size(); ++j) {         while (area(layers[i][j], layers[i + 1][k], layers[i + 1][nxt(k, sz)]) <                0)           k = nxt(k, sz);         while (area(layers[i][j], layers[i + 1][prv(k, sz)], layers[i + 1][k]) >                0)           k = prv(k, sz);         to[j] = k;       }       for (int j = 0; j < layers[i].size(); ++j) {         int u = id[layers[i][j]],             v = id[layers[i + 1][to[prv(j, layers[i].size())]]];         par[0][u] = v;       }     }     for (auto x : layers[up - 1]) par[0][id[x]] = n;     for (int j = 1; j < LG; ++j) {       for (int i = 0; i <= n; ++i)         if (par[j - 1][i] != -1) {           par[j][i] = par[j - 1][par[j - 1][i]];         }     }     int sz = layers[0].size();     vector<pair<long double, int>> vec;     for (int i = 0; i < sz; ++i) {       Point cur = layers[0][nxt(i, sz)] - layers[0][i];       vec.emplace_back(atan2l(cur.imag(), cur.real()), i);     }     sort(vec.begin(), vec.end());     cin >> q;     while (q--) {       int dx, dy, k;       cin >> dx >> dy >> k;       long double ang = atan2l(dy, dx);       int pos = -1;       auto it = upper_bound(vec.begin(), vec.end(), make_pair(ang, 696969));       if (it == vec.end())         pos = vec[0].second;       else         pos = it->second;       int where = lower_bound(pf.begin(), pf.end(), k) - pf.begin();       int ext = k - (where ? pf[where - 1] : 0);       int at = kthPar(id[layers[0][pos]], where);       assert(at != n);       int final = (whichPos[at] + ext - 1) % (int)layers[where].size();       int ans = id[layers[where][final]];       printf( %d n , ans + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using vi = vector<int>;   const int LOG = 17;   const int inf = 1e9;   template <typename T>   struct RMQ {     vector<vector<T>> spr;     RMQ(const vector<T>& v) : spr(1, v) {       for (int j = 1; (1 << j) <= (int)v.size(); ++j) {         spr.push_back(vector<T>((int)v.size() - (1 << j) + 1));         for (int i = 0; i < (int)spr[j].size(); ++i) {           spr[j][i] = min(spr[j - 1][i], spr[j - 1][i + (1 << (j - 1))]);         }       }     }     T get(int l, int r) {       int d = 31 - __builtin_clz(r - l + 1);       return min(spr[d][l], spr[d][r - (1 << d) + 1]);     }   };   int main() {     cin.tie(0)->sync_with_stdio(0);     int n, m, q;     cin >> n >> m >> q;     vi v(n), g(n);     for (int i = 0; i < n; ++i) cin >> v[i], v[i]--;     for (int i = 0; i < n; ++i) g[v[i]] = v[(i + 1) % n];     vi a(m);     for (int i = 0; i < m; ++i) cin >> a[i], a[i]--;     vector<vi> spr(LOG + 1, vi(m));     vi nxt(n, -1);     for (int i = m - 1; i >= 0; --i) {       nxt[a[i]] = i;       spr[0][i] = nxt[g[a[i]]];     }     for (int j = 0; j < LOG; ++j) {       for (int i = 0; i < m; ++i) {         if (spr[j][i] == -1)           spr[j + 1][i] = -1;         else           spr[j + 1][i] = spr[j][spr[j][i]];       }     }     vi res(m);     for (int i = 0; i < m; ++i) {       int k = i;       for (int j = LOG; j >= 0; --j) {         if ((n - 1) & (1 << j)) {           k = spr[j][k];           if (k == -1) break;         }       }       res[i] = k == -1 ? inf : k;     }     RMQ<int> rmq(res);     string ans;     for (int i = 0; i < q; ++i) {       int l, r;       cin >> l >> r;       --l, --r;       int a = rmq.get(l, r);       if (a <= r)         ans.push_back( 1 );       else         ans.push_back( 0 );     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-15;   const long double PI = 3.14159265358979323846;   inline int lg2(long long n) {     int h = 0;     while ((1ll << h) < n) ++h;     return h;   }   struct configio {     configio() {       cin.tie(nullptr);       ios_base::sync_with_stdio(false);     }   } cnfio;   int diff(int a, int b, int mod) { return ((a - b) % mod + mod) % mod; }   struct candy {     int h, m;   };   int main() {     int n, x;     cin >> n >> x;     vector<candy> v1[2];     for (int i = 0; i < n; ++i) {       int t, h, m;       cin >> t >> h >> m;       v1[t].push_back({h, m});     }     long long ans = 0;     for (int type = 0; type <= 1; ++type) {       vector<candy> v[2];       v[0] = v1[0];       v[1] = v1[1];       int cur_ans = 0;       long long cur_x = x;       int cur_type = type;       while (true) {         int id = -1;         for (int i = 0; i < v[cur_type].size(); ++i) {           if (v[cur_type][i].h <= cur_x) {             if (id == -1 || (v[cur_type][id].m < v[cur_type][i].m)) {               id = i;             }           }         }         if (id == -1) {           break;         }         cur_ans++;         cur_x += v[cur_type][id].m;         v[cur_type].erase(v[cur_type].begin() + id);         cur_type ^= 1;       }       ans = max(ans, (long long)cur_ans);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 4e3 + 5;   long long n, m, a[N], f[N][N];   long long solve(long long l, long long r) {     if (l > r) return 0;     long long p = 0;     for (long long i = l; i <= r; i++)       if (a[i] < a[p]) p = i;     long long ls = solve(l, p - 1), rs = solve(p + 1, r);     memset(f[p], -0x3f, sizeof(f[p]));     for (long long i = 0; i <= p - l; i++)       for (long long j = 0; j <= r - p; j++) {         f[p][i + j] = max(f[p][i + j], f[ls][i] + f[rs][j] - 2 * i * j * a[p]);         f[p][i + j + 1] =             max(f[p][i + j + 1], f[ls][i] + f[rs][j] - 2 * i * j * a[p] -                                      2 * (i + j) * a[p] + (m - 1) * a[p]);       }     return p;   }   signed main() {     cin >> n >> m;     a[0] = 1e18;     for (long long i = 1; i <= n; i++) cin >> a[i];     long long p = solve(1, n);     cout << f[p][m] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> a(n);     vector<long long> f(2000006, -1);     for (int i = 0; i < n; i++) {       cin >> a[i];       f[a[i]] = i;     }     long long ans = 1e18, res;     for (int i = 0; i <= 2000005; i++) {       if (f[i] < 0) continue;       if (ans > f[i]) {         res = i;       }       ans = min(f[i], ans);     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n;     cin >> n;     long long int a[n], b[n], c[n - 1];     b[n - 1] = 0, c[n - 2] = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n - 1; i++) {       cin >> b[i];     }     for (int i = 0; i < n - 2; i++) {       cin >> c[i];     }     sort(a, a + n);     sort(b, b + n - 1);     sort(c, c + n - 2);     for (int i = 0; i < n; i++) {       if (a[i] != b[i]) {         cout << a[i] << endl;         break;       }     }     for (int i = 0; i < n - 1; i++) {       if (b[i] != c[i]) {         cout << b[i] << endl;         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e5 + 5;   int n;   int ans[inf];   int last[inf];   struct node {     int x, h, q;     bool operator<(const node &s) const { return s.x > x; }   } a[inf << 1];   inline int read() {     int a = 0;     int b = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) b = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       a = a * 10 + c -  0 ;       c = getchar();     }     return a * b;   }   inline void run() {     int x, y;     n = read();     for (int i = 1; i <= n; i++) {       x = read();       y = read();       a[i].x = x;       a[i].h = y;       a[i].q = i;     }     sort(a + 1, a + 1 + n);     for (int i = 1; i <= n; i++) {       ans[i] = 1;     }     for (int i = n - 1; i > 0; i--) {       int now = i + 1;       while (now && ((a[i].x + a[i].h) > a[now].x)) {         ans[a[i].q] += ans[a[now].q];         now = last[now];       }       last[i] = now;     }     for (int i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int sum, limits;     vector<int> ans;     cin >> sum >> limits;     for (int i = limits; i >= 1; i--) {       if ((i & (-i)) <= sum) {         sum -= (i & (-i));         ans.push_back(i);       }     }     if (!sum) {       int len = ans.size();       cout << len << endl;       for (int i = 0; i < len; i++) {         cout << ans[i];         if (i == len - 1)           cout << endl;         else           cout <<    ;       }     } else       cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> arr[1000005];   int par[1000005], sz[1000005];   int find(int x) {     if (par[x] != x) par[x] = find(par[x]);     return par[x];   }   void Union(int a, int b) {     a = find(a);     b = find(b);     if (a != b) {       par[a] = b;       sz[b] += sz[a];       sz[a] = 0;     }   }   int ans[1005][1005], n, m;   bool vis[1005][1005], add[1000005];   long long k;   void dfs(int x, int y) {     vis[x][y] = 1;     if (!k) return;     ans[x][y] = 1;     k--;     for (int dx = -1; dx <= 1; dx++) {       for (int dy = -1; dy <= 1; dy++) {         if (abs(dx) + abs(dy) == 1 && x + dx >= 0 && x + dx < n && y + dy >= 0 &&             y + dy < m && !vis[x + dx][y + dy] && add[(x + dx) * m + y + dy])           dfs(x + dx, y + dy);       }     }   }   int main() {     scanf( %d%d%I64d , &n, &m, &k);     for (int i = 0; i < n * m; i++) {       scanf( %d , &arr[i].first);       arr[i].second = i;       par[i] = i;       sz[i] = 1;     }     sort(arr, arr + n * m);     for (int i = n * m - 1; i >= 0; i--) {       int idx = arr[i].second;       if (idx >= m && add[idx - m]) Union(idx, idx - m);       if (idx < (n - 1) * m && add[idx + m]) Union(idx, idx + m);       if (idx % m && add[idx - 1]) Union(idx, idx - 1);       if (idx % m != m - 1 && add[idx + 1]) Union(idx, idx + 1);       if (k % arr[i].first == 0 && sz[find(idx)] >= k / arr[i].first) {         k /= arr[i].first;         dfs(idx / m, idx % m);         printf( YES n );         for (int x = 0; x < n; x++) {           for (int j = 0; j < m; j++) printf( %d  , ans[x][j] * arr[i].first);           printf(  n );         }         return 0;       }       add[idx] = 1;     }     printf( NO );   }


#include <bits/stdc++.h>   using namespace std;   int m, n, arr[200][200];   int color(int x, int y) {     int col = 1;     while (arr[x - 1][y] == col or arr[x][y - 1] == col or arr[x + 1][y] == col or            arr[x][y + 1] == col)       col++;     return col;   }   int color2(int x, int y) {     int col = 1;     while (arr[x - 1][y] == col or arr[x + 1][y] == col or arr[x][y + 1] == col)       col++;     return col;   }   int fit(int x, int y, int col) {     if (arr[x][y - 1] == col or arr[x + 1][y] == col or arr[x][y + 1] == col)       return 0;     return 1;   }   int main() {     cin >> m >> n;     int x = 1, y = 1;     while (x <= m) {       if (y == n + 1) {         x++;         y = 1;         continue;       }       if (arr[x][y]) {         y++;         continue;       }       int xx = x, yy = y, col = color(x, y);       arr[x][y] = col;       while (xx + 1 <= m and yy + 1 <= n and !arr[xx + 1][y] and              !arr[x][yy + 1] and fit(xx + 1, y, col) and color2(x, yy + 1) == col)         xx++, yy++;       for (int i = x; i <= xx; i++)         for (int j = y; j <= yy; j++) arr[i][j] = col;     }     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) printf( %c , (char)(arr[i][j] +  A  - 1));       puts(  );     }   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   double dp[205][35][35];   vector<int> p;   pair<int, int> rev(int x, int y, int rx, int ry) {     if (x >= rx && x <= ry) {       x = rx + (ry - rx) - (x - rx);     }     if (y >= rx && y <= ry) {       y = rx + (ry - rx) - (y - rx);     }     return make_pair(x, y);   }   int main() {     cin >> n >> k;     p.resize(n);     for (int i = 0; i < n; i++) {       cin >> p[i];     }     for (int i = 0; i < n; i++) {       for (int j = i; j < n; j++) {         dp[0][i][j] = 1.0;       }     }     double pp = 2.0 / (n * (n + 1));     for (int q = 1; q <= k; q++) {       for (int i = 0; i < n; i++) {         for (int j = i; j < n; j++) {           for (int k = 0; k < n; k++) {             for (int l = k; l < n; l++) {               pair<int, int> xy = rev(i, j, k, l);               if (xy.first < xy.second) {                 dp[q][i][j] += dp[q - 1][xy.first][xy.second] * pp;               } else {                 dp[q][i][j] += (1.0 - dp[q - 1][xy.second][xy.first]) * pp;               }             }           }         }       }     }     double ans = 0;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (p[i] < p[j]) {           ans += 1.0 - dp[k][i][j];         } else {           ans += dp[k][i][j];         }       }     }     printf( %.9lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long modular(long long a, long long b, long long c) {     if (b == 0) {       return 1;     }     if (b % 2 == 0) {       return modular(((a * a) % c), b / 2, c);     } else {       return ((a % c) * (modular(((a * a) % c), b / 2, c) % c)) % c;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long a[n];       string arr[n];       for (long long i = 0; i < n; i++) {         cin >> a[i];         arr[i] = bitset<32>(a[i]).to_string();       }       long long turn = 0;       long long flag = 0;       for (long long i = 0; i < 32; i++) {         long long c1 = 0;         long long c2 = 0;         for (long long j = 0; j < n; j++) {           if (arr[j][i] ==  1 ) {             c1++;           } else {             c2++;           }         }         if ((c1 % 4 == 1) || ((c1 % 4 == 3) && (n % 2 == 0))) {           if (turn == 0) {             flag = 1;             break;           } else {             flag = 2;             break;           }         }         if ((c1 % 4 == 3) && (n % 2 != 0)) {           if (turn == 0) {             flag = 2;             break;           } else {             flag = 1;             break;           }         }       }       if (flag == 0) {         cout <<  DRAW               <<   n ;       } else {         if (flag == 1) {           cout <<  WIN                 <<   n ;         } else {           cout <<  LOSE                 <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     cin >> n >> m >> k;     char grid[n][m];     bool flag1 = 0, flag2 = 0;     int cnt[100] = {};     for (int i = 0; i < n; i++) {       string s;       cin >> s;       if (s.find( - ) < 0 || s.find( - ) >= s.size()) continue;       int x = s.find( G );       int y = s.find( R );       if (y == -1 && x == -1) continue;       if (y >= s.size() || y < 0) flag1 = 1;       if (x >= s.size() || x < 0) flag2 = 1;       if (x < s.size() && x >= 0 && y < s.size() && y >= 0) {         int tmp = abs(x - y) - 1;         int cur = 0;         while (tmp) {           cnt[cur] += tmp % 2;           tmp /= 2;           cur++;         }       }     }     if (flag1 & flag2)       puts( Draw );     else if (flag1)       puts( First );     else if (flag2)       puts( Second );     else {       int ans = 0;       for (int i = 0; i < 100; i++)         if (cnt[i] % (k + 1)) {           puts( First );           return 0;         }       puts( Second );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     while (1 == scanf( %d , &N)) {       vector<int> A(N);       for (int i = 0; i < (int)(N); i++) scanf( %d , &A[i]);       sort((A).begin(), (A).end());       int need_to_fill = 0, need_to_move = 0;       for (int i = 0; i < (int)(N); i++) need_to_fill += max(0, 3 - A[i]);       int total = accumulate((A).begin(), (A).end(), 0);       sort((A).begin(), (A).end());       int ans = INT_MAX;       for (int i = 0; i < (int)(N); i++) {         int num_rooms = N - i;         if (4 * num_rooms >= total && 3 * num_rooms <= total) {           int tmp = max(need_to_move, need_to_fill);           ans = min(ans, tmp);         }         need_to_fill -= max(0, 3 - A[i]);         need_to_move += A[i];       }       if (ans == INT_MAX)         puts( -1 );       else         printf( %d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     if (t % 2 == 0) {       cout <<  Mahmoud  << endl;     } else {       cout <<  Ehab  << endl;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   inline int read() {     register int x = 0, f = 1;     register char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = x * 10 + c - 48, c = getchar();     return x * f;   }   namespace Graph {   int head[1000005], cnt;   struct edge {     int v, next, w;   } e[1000005 << 1];   inline void add(int u, int v, int w) {     e[++cnt] = (edge){v, head[u], w}, head[u] = cnt;   }   }  // namespace Graph   int n, m, k, Ans, fac, sum, g[1000005];   char c[1000005];   inline int qpow(int a, int b) {     int r = 1;     while (b) {       if (b & 1) r = 1ll * a * r % 1000000007;       a = 1ll * a * a % 1000000007, b >>= 1;     }     return r;   }   signed main() {     Ans = n = read(), k = read(), g[0] = fac = 1;     for (register int i = (1); i <= (n); ++i) {       sum = (sum + g[i - 1]) % 1000000007;       if (i > k) sum = (sum - g[i - k - 1] + 1000000007) % 1000000007;       g[i] = 1ll * sum * qpow(i, 1000000007 - 2) % 1000000007;       Ans = (Ans - g[i - 1] + 1000000007) % 1000000007;       if (i != 1) fac = 1ll * fac * (i - 1) % 1000000007;     }     cout << 1ll * fac * Ans % 1000000007;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[200000 + 9];   long long com[200000 + 9];   double f1(int i, int k) {     long long sum1 = a[i] + com[n] - com[n - k] + com[i - 1] - com[i - 1 - k];     double av1 = (double)sum1 / (2 * k + 1);     return av1;   }   double f2(int i, int k) {     long long sum2 =         a[i] + com[n] - com[n - (k - 1)] + com[i - 1] - com[i - 1 - (k - 1)];     double av2 = (double)sum2 / (2 * (k - 1) + 1);     return av2;   }   long long ValAt(int i, int k) {     long long sum = a[i] + com[n] - com[n - k] + com[i - 1] - com[i - 1 - k];     return sum;   }   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     cin >> n;     for (int i = (1); i <= (n); i++) cin >> a[i];     sort(a + 1, a + n + 1);     if (n <= 2) {       cout << n <<   n ;       for (int i = (1); i <= (n); i++) cout << a[i] <<    ;       cout <<   n ;       return 0;     }     com[0] = 0;     for (int i = (1); i <= (n); i++) com[i] = com[i - 1] + a[i];     double bestVal = 0;     int besti = 1, bestSize = 1;     for (int i = 2; i < n; i++) {       int s = 1, e = min(i - 1, n - i);       double bestAv = 0;       int size;       while (s <= e) {         int k = (s + e) / 2;         long long sum1 = ValAt(i, k);         double av1 = (double)sum1 / (2 * k + 1);         long long sum2 = ValAt(i, k - 1);         double av2 = (double)sum2 / (2 * (k - 1) + 1);         if (av1 > av2) {           s = k + 1;           bestAv = av1;           size = 2 * k + 1;         } else           e = k - 1;       }       double val = bestAv - a[i];       if (val > bestVal) {         bestVal = val;         besti = i;         bestSize = size;       }     }     vector<int> v;     v.push_back(a[besti]);     int k = (bestSize - 1) / 2;     for (int i = besti - 1; i >= besti - k; i--) v.push_back(a[i]);     for (int i = n; i > n - k; i--) v.push_back(a[i]);     sort(v.begin(), v.end());     cout << bestSize <<   n ;     for (auto x : v) cout << x <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double n, m, k;   int main() {     while (scanf( %lf %lf %lf , &n, &m, &k) != EOF) {       if (m > n + k) {         printf( %.6lf n , 0.0);         continue;       }       double resp = 1.0;       for (int i = 0; i <= k; i++) {         resp *= ((m - i) / (n + k + 1 - i));       }       printf( %.6lf n , 1.0 - resp);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 9, M = 3e5 + 9, OO = 0x3f3f3f3f;   const double EPS = 0.00000000001;   const int mod = 1000003;   int n, m, d[3005];   bool flage = 1;   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; ++i) {       scanf( %d , d + i);       if (d[i] == 1 || d[i] == n) flage = 0;     }     sort(d, d + m);     int mx = min(1, m);     for (int i = 0, j = 1; j < m; ++j)       if (d[j] == d[j - 1] + 1)         mx = max(mx, j - i + 1);       else         i = j;     if (mx >= 3) flage = 0;     if (flage)       puts( YES );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   bool a[100100];   void go() {     long long int n;     cin >> n;     memset(a, true, sizeof(a));     for (int i = 2; i <= n; i++) {       for (int j = i + 1; i * j <= n; j++) {         if (j % i == 0) continue;         a[j * i] = false;       }     }     vector<int> ans;     for (int i = 2; i <= n; i++) {       if (a[i]) ans.push_back(i);     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long int t = 1;     while (t--) go();   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 10;   const int inf = 0x3f3f3f3f;   int a[maxn];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 1; i <= k; ++i) scanf( %d , &a[i]);     int x = 2 * n, y = n;     for (int i = 1; i <= k; ++i) {       if (a[i] >= 4 && y > 0) {         int m = a[i] / 4;         a[i] -= min(m, y) * 4;         y -= min(m, y);       }     }     for (int i = 1; i <= k; ++i) {       if (x > 0) {         int m = a[i] / 2;         a[i] -= min(m, x) * 2;         x -= min(x, m);       }     }     int tmp = y;     for (int i = 1; i <= k; ++i) {       if (y > 0) {         int m = a[i] / 2;         a[i] -= min(m, y) * 2;         y -= min(m, y);       }     }     tmp = tmp - y + x;     for (int i = 1, j = k; i < j;) {       if (y > 0) {         int m = min(min(a[i], a[j]), y);         a[i] -= m, a[j] -= m, y -= m;       }       if (a[i] == 0) ++i;       if (a[j] == 0) --j;       if (y == 0) break;     }     tmp += y;     for (int i = 1; i <= k; ++i) {       if (tmp > 0) {         int m = min(tmp, a[i]);         a[i] -= m;         tmp -= m;       }     }     int f = 1;     for (int i = 1; i <= k; ++i) {       if (a[i] > 0) f = 0;     }     if (f)       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a;     cin >> n >> a;     vector<int> checkpt;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       checkpt.push_back(t);     }     sort(checkpt.begin(), checkpt.end());     long long distance = 0;     if (n == 1) {       cout << 0 << endl;       return 0;     }     if (checkpt[n - 1] <= a) {       distance += a - checkpt[1];       cout << distance << endl;       return 0;     } else if (a <= checkpt[0]) {       distance += checkpt[n - 2] - a;       cout << distance << endl;       return 0;     }     int pointer;     for (int i = 0; i < n - 1; i++) {       if (checkpt[i] <= a && checkpt[i + 1] >= a) {         checkpt.insert(checkpt.begin() + (i + 1), a);         pointer = i + 1;         break;       }     }     long long dis1 = 0;     long long dis2 = 0;     long long dis3 = 0;     long long dis4 = 0;     dis1 += checkpt[pointer] - checkpt[0];     if (pointer + 1 != n) {       dis1 += checkpt[n - 1] - checkpt[0];       dis3 += (checkpt[n - 1] - checkpt[pointer]) * 2;     }     dis3 += checkpt[pointer] - checkpt[0];     dis4 += checkpt[n] - checkpt[pointer];     if (pointer - 1 != 0) {       dis2 += (checkpt[pointer] - checkpt[1]) * 2;       dis4 += checkpt[n] - checkpt[1];     }     dis2 += checkpt[n] - checkpt[pointer];     long long min1 = min(dis1, dis2);     long long min2 = min(min1, dis3);     distance = min(min2, dis4);     cout << distance << endl;   }


#include <bits/stdc++.h>   using namespace std;   map<pair<int, int>, bool> fuck;   int n, m;   char s[5];   int x, y;   long long ans;   int dx, dy;   int main() {     scanf( %d%d , &n, &m);     scanf( %d%d , &x, &y);     scanf( %s , s + 1);     if (s[1] ==  U )       dx = -1;     else       dx = 1;     if (s[2] ==  L )       dy = -1;     else       dy = 1;     int fis = 0;     int test = 1000000;     while (test--) {       pair<int, int> now = pair<int, int>(x, y);       if (!fuck[now]) {         fuck[now] = 1;         fis++;       }       if (fis == n + m - 2) {         cout << ans + 1;         return 0;       }       int xl, yl, l;       int ex, ey;       if (dx == -1)         xl = x - 1;       else         xl = n - x;       if (dy == -1)         yl = y - 1;       else         yl = m - y;       if (xl < yl) {         ex = -dx;         ey = dy;         l = xl;       } else {         if (xl > yl) {           ey = -dy;           ex = dx;           l = yl;         } else {           ex = -dx;           ey = -dy;           l = yl;         }       }       x += dx * l;       y += dy * l;       ans += 1ll * l;       dx = ex;       dy = ey;     }     printf( -1 n );     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long int cost(long long int h[], long long int n, long long int a,                      long long int r, long long int m, long long int x) {     long long int plus = 0, minus = 0;     for (int i = 0; i < n; i++) {       if (h[i] > x) {         minus += h[i] - x;       } else if (h[i] < x) {         plus += x - h[i];       }     }     if (m > a + r) {       return (a * plus + r * minus);     } else {       return (min(plus, minus) * m + (plus - min(plus, minus)) * a +               (minus - min(plus, minus)) * r);     }   }   int main() {     long long int n, a, r, m;     cin >> n >> a >> r >> m;     long long int h[n], start = 0, end = 0;     for (int i = 0; i < n; i++) {       cin >> h[i];       end = max(end, h[i]);     }     long long int ans = 1e18;     while (start <= end) {       long long int mid = (start + end) >> 1, mid_1;       long long int c_mid = cost(h, n, a, r, m, mid);       if (c_mid < ans) {         ans = c_mid;       }       mid_1 = mid + 1;       long long int c_mid_1 = cost(h, n, a, r, m, mid_1);       if (c_mid_1 > c_mid) {         end = mid - 1;       } else {         start = mid + 1;       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-9, PI = acos(-1.);   const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;   const int N = 2e5 + 5, SQ = 500;   int n, q, a[N], l[N], r[N], p[N];   long long ans[N], c[1000005], s;   void add(int x) {     int v = a[x];     s -= c[v] * c[v] * v;     c[v]++;     s += c[v] * c[v] * v;   }   void rem(int x) {     int v = a[x];     s -= c[v] * c[v] * v;     c[v]--;     s += c[v] * c[v] * v;   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 0; i < q; ++i) scanf( %d%d , &l[i], &r[i]), p[i] = i;     sort(p, p + q, [](int a, int b) {       return l[a] / SQ == l[b] / SQ ? r[a] < r[b] : l[a] < l[b];     });     int cl = 0, cr = 0;     for (int i = 0; i < q; ++i) {       int cur = p[i];       while (cl < l[cur]) rem(cl++);       while (cl > l[cur]) add(--cl);       while (cr < r[cur]) add(++cr);       while (cr > r[cur]) rem(cr--);       ans[cur] = s;     }     for (int i = 0; i < q; ++i) printf( %lld n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void check_max(T& a, T b) {     if (a < b) a = b;   }   template <class T>   void check_min(T& a, T b) {     if (a > b) a = b;   }   const int MAXN = 10100;   int n, k;   double per;   double a[MAXN];   int main() {     cin >> n >> k;     per = (double)k / 100;     for (int _t = n, i = 0; i < _t; i++) cin >> a[i];     sort(a, a + n);     double l = 0, r = 1000;     while (r - l > 1e-8) {       double m = (r + l) / 2;       double more = 0, less = 0;       for (int _t = n, i = 0; i < _t; i++)         if (a[i] > m)           more += a[i] - m;         else           less += m - a[i];       if (more * (1 - per) >= less)         l = m;       else         r = m;     }     double ans = (l + r) / 2;     printf( %.7lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long i, j, k, x, y, z, n, mi = 1e16, sum = 0;     cin >> n;     long long a[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     if (n == 1 || n == 2) {       cout << a[0] - 1;       return;     }     z = (long long)pow(1e18, 1.0 / n);     for (i = 1; i <= z; i++) {       sum = 0;       for (j = 0; j < n; j++) {         y = (long long)pow(i, j);         sum += abs(a[j] - y);       }       mi = min(mi, sum);     }     cout << mi;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t-- > 0) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int a[2005], b[2005];   int main() {     std::ios::sync_with_stdio(false);     int n, k, p;     long long minn = (1000 * 1000 * 1000 + 5);     minn *= (1000 * 1000 * 1000 + 7);     long long ans;     int j, val, i;     cin >> n >> k >> p;     for (i = 0; i < n; i++) {       cin >> a[i];     }     for (i = 0; i < k; i++) {       cin >> b[i];     }     sort(a, a + n);     sort(b, b + k);     for (i = 0; i < k - n + 1; i++) {       val = 0;       ans = 0;       for (j = i; j < i + n; j++) {         if ((b[j] >= a[val] && b[j] <= p) || (a[val] >= b[j] && b[j] >= p)) {           ans = max(ans, (long long)abs(a[val] - p));         } else {           ans = max(ans, (long long)abs(b[j] - a[val]) + abs(p - b[j]));         }         val++;       }       minn = min(minn, ans);     }     cout << minn << endl;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005];   int main() {     map<string, bool> vis;     int n;     scanf( %d , &n);     while (n--) {       string s;       cin >> s;       if (vis[s])         puts( YES );       else         puts( NO );       vis[s] = 1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double n, r;   signed main() {     scanf( %lf%lf , &n, &r);     printf( %.10f n , 2.0 * n * 0.5 * r * r * sin(acos(-1.0) / (2.0 * n)) /                           sin(acos(-1.0) - (acos(-1.0) / (2.0 * n)) * 3) *                           sin(2 * acos(-1.0) / (2.0 * n)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   double p[1000];   const int cc = 2;   double a[201][cc * 101][cc * 101];   double get(int IT) {     for (int it = 0; it <= IT; it++)       for (int i = 0; i <= cc * n; i++)         for (int j = 0; j <= cc * n; j++) a[it][i][j] = -100;     for (int i = 0; i <= cc * n; i++)       for (int j = 0; j <= min(n, i); j++)         a[0][i][min(cc * n, i - j + n - j)] =             max(a[0][i][min(cc * n, i - j + n - j)], p[j]);     for (int it = 1; it <= IT; it++) {       for (int i = 0; i <= cc * n; i++)         for (int j = 0; j <= cc * n; j++)           for (int k = 0; k <= cc * n; k++)             a[it][i][k] =                 max(a[it][i][k], (a[it - 1][i][j] + a[it - 1][j][k]) / 2);     }     double ans = 0;     for (int i = 0; i <= cc * n; i++) ans = max(ans, a[IT][0][i]);     return ans;   }   int main() {     cin >> n;     for (int i = 0; i <= n; i++) {       cin >> p[i];     }     printf( %.18lf n , (double)get(30));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long pwr(long long base, long long p, long long mod = (1000000007LL)) {     long long ans = 1;     while (p) {       if (p & 1) ans = (ans * base) % mod;       base = (base * base) % mod;       p /= 2;     }     return ans;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long nCr(long long n, long long r) {     long long C[r + 1];     memset(C, 0, sizeof(C));     C[0] = 1;     for (long long i = 1; i <= n; i++)       for (long long j = min(i, r); j > 0; j--) C[j] = C[j] + C[j - 1];     return C[r];   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n == 2) return true;     if (n % 2 == 0) return false;     long long m = sqrt(n);     for (long long i = 3; i <= m; i += 2)       if (n % i == 0) return false;     return true;   }   long long M(long long a) { return (a % (1000000007LL)); }   bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     int n;     cin >> n;     vector<int> v(n);     for (long long i = 0; i < (long long)(n); ++i) cin >> v[i];     vector<int> ans(n + 1);     for (long long i = 0; i < (long long)(n); ++i) {       vector<int> color_total(n + 1);       int best = 0;       for (int j = i; j < n; j++) {         color_total[v[j]]++;         if (color_total[v[j]] > color_total[best]) {           best = v[j];         } else if (color_total[v[j]] == color_total[best]) {           if (v[j] < best) {             best = v[j];           }         }         ans[best]++;       }     }     for (long long i = 1; i <= (long long)(n); ++i) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, q, a;     cin >> n >> k >> q;     int t[150005] = {0};     for (int i = 1; i <= n; i++) {       cin >> a;       t[i] = a;     }     set<pair<int, int> > s;     set<pair<int, int> >::iterator it;     for (int i = 1; i <= q; i++) {       int flag, id;       cin >> flag >> id;       if (flag == 1) {         if (s.size() == k) {           it = s.begin();           if (t[id] > (it->first)) {             s.erase(it);             s.insert(make_pair(t[id], id));           }         } else {           s.insert(make_pair(t[id], id));         }       } else {         if (s.find(make_pair(t[id], id)) != s.end())           cout <<  YES n ;         else           cout <<  NO n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pll = pair<ll, ll>;   using vll = vector<ll>;   using vpll = vector<pll>;   struct d_ {     template <typename T>     d_& operator,(const T& x) {       cerr <<     << x;       return *this;     }   } d_t;   int mix[1024];   int main(void) {     ios_base::sync_with_stdio(false);     ll n;     cin >> n;     ;     fill(begin(mix), end(mix), (int)1e9 + 7);     int st = 2;     for (ll i(0); i < 10; i++) {       for (ll k(0); k < 2; k++) {         set<int> vals;         for (ll j(0); j < n; j++) {           if (j % st < st / 2 and k == 0) {             vals.insert(j);           } else if (j % st >= st / 2 and k == 1) {             vals.insert(j);           }         }         if (vals.empty()) continue;         char* sp =   ;         cout << vals.size() <<   n ;         for (auto e : vals) {           cout << sp << e + 1;           sp =    ;         }         cout << endl;         for (ll j(0); j < n; j++) {           ll vl;           cin >> vl;           ;           if (!vals.count(j)) {             mix[j] = min(mix[j], (int)vl);           }         }         cout << endl;       }       st *= 2;     }     cout <<  -1  << endl;     char* sp =   ;     for (ll i(0); i < n; i++) {       cout << sp << mix[i];       sp =    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};   const int dy[] = {0, -1, 0, 1, -1, 1, 1, -1};   template <class T>   inline bool get(T& n) {     char c, mul = 1;     n = 0;     while (!isdigit(c = getchar_unlocked()) && (c != EOF) && (c !=  - ))       ;     if (c == EOF) return false;     if (c ==  - ) {       c = getchar_unlocked();       mul = -1;     }     for (; isdigit(c); c = getchar_unlocked()) n = n * 10 + c -  0 ;     n *= mul;     return true;   }   inline void get(char& c) {     while (isspace(c = getchar_unlocked()))       ;   }   struct Point {     long long x, y;   } p[101010];   long long cross(Point o, Point a, Point b) {     return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);   }   int n;   int l[101010][20], par[101010], level[101010];   vector<int> child[101010];   void dfs(int u, int l) {     level[u] = l;     for (int(i) = 0, _ = (child[u].size()); (i) < _; ++i) dfs(child[u][i], l + 1);   }   void preprocess() {     vector<int> v;     int k = 0;     for (int(i) = (n - 1), _ = (0); (i) >= _; --(i)) {       par[i] = -1;       while (k > 1 && cross(p[v[k - 2]], p[v[k - 1]], p[i]) < 0) {         --k;         v.pop_back();       }       if (k > 0) {         par[i] = v.back();         child[v.back()].push_back(i);       }       v.push_back(i);       ++k;     }     int root = 0;     while (par[root] != -1) root = par[root];     dfs(root, 0);     for (int(i) = 0, _ = (n); (i) < _; ++i)       for (int j = 0; (1 << j) < n; ++j) l[i][j] = -1;     for (int(i) = 0, _ = (n); (i) < _; ++i) l[i][0] = par[i];     for (int j = 1; 1 << j < n; ++j)       for (int(i) = 0, _ = (n); (i) < _; ++i)         if (l[i][j - 1] != -1) l[i][j] = l[l[i][j - 1]][j - 1];   }   int lca(int p, int q) {     int log, i;     if (level[p] < level[q]) swap(p, q);     for (log = 1; 1 << log <= level[p]; ++log)       ;     --log;     for (i = log; i >= 0; --i)       if (level[p] - (1 << i) >= level[q]) p = l[p][i];     if (p == q) return p;     for (i = log; i >= 0; --i)       if (l[p][i] != -1 && l[p][i] != l[q][i]) p = l[p][i], q = l[q][i];     return par[p];   }   int main() {     get(n);     for (int(i) = 0, _ = (n); (i) < _; ++i) get(p[i].x), get(p[i].y);     preprocess();     int m, a, b;     get(m);     while (m--) {       get(a);       get(b);       --a;       --b;       printf( %d  , lca(a, b) + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 50 + 5;   const int maxm = 2500 + 5;   const int inf = 1 << 29;   const long long mod = 1e9 + 7;   const double eps = 1e-8;   long long read() {     long long s = 0, w = 1;     char c = getchar();     for (; !isdigit(c); c = getchar()) {       if (c ==  - ) w = -1;     }     for (; isdigit(c); c = getchar()) {       s = (s << 3) + (s << 1) + (c ^ 48);     }     return w == 1 ? s : -s;   }   int main() {     int t = read();     while (t--) {       int a = read(), b = read();       if (a > b) swap(a, b);       if ((a + b) & 1) {         int mn = b - (a + b + 1) / 2;         int mx = min((a + b + 1) / 2, b) + min((a + b) / 2, a);         printf( %d n , mx - mn + 1);         for (int i = mn; i <= mx; i++) {           printf( %d  , i);         }         puts(  );       } else {         int mn = b - (a + b) / 2;         int mx = min((a + b) / 2, b) + min((a + b) / 2, a);         printf( %d n , (mx / 2 - mn / 2 + 1));         for (int i = mn; i <= mx; i += 2) {           printf( %d  , i);         }         puts(  );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int temp;     map<int, vector<int>> mpp;     for (int i = 2; i <= n; i++) {       cin >> temp;       mpp[temp].push_back(i);     }     for (auto itr = mpp.begin(); itr != mpp.end(); ++itr) {       vector<int> v = (*itr).second;       int cnt = 0;       if (v.size() >= 1) {         for (int j = 0; j < v.size(); j++) {           if (mpp[v[j]].size() == 0) {             cnt++;           }         }         if (cnt < 3) {           cout <<  No  << endl;           return 0;         }       }     }     cout <<  Yes  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     cin >> n >> m >> k;     pair<int, int> c = make_pair(1, 0);     int dx = 1, cover = 0, inc = 0;     while (k != 1) {       if (inc == 0) cout << 2 <<    ;       if (dx == 1 && c.second + dx <= m) {         c.second += dx;       } else if (dx == 1) {         c.first++;         dx = -1;       } else if (dx == -1 && c.second + dx >= 1) {         c.second += dx;       } else if (dx == -1) {         c.first++;         dx = 1;       }       cout << c.first <<     << c.second <<    ;       inc++;       if (inc == 2) {         cout << endl;         k--;         inc = 0;       }       cover++;     }     cout << n * m - cover <<    ;     while (cover < n * m) {       if (dx == 1 && c.second + dx <= m) {         c.second += dx;       } else if (dx == 1) {         c.first++;         dx = -1;       } else if (dx == -1 && c.second + dx >= 1) {         c.second += dx;       } else if (dx == -1) {         c.first++;         dx = 1;       }       cout << c.first <<     << c.second <<    ;       cover++;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long long li, ri;   } sum[400000];   long long pmx[400000], nmx[400000];   long long pmi[400000], nmi[400000];   int main() {     long long n;     memset(pmi, 0x7f7f7f7f, sizeof(pmi));     memset(nmi, 0x7f7f7f7f, sizeof(nmi));     memset(pmx, -0x7f7f7f7f, sizeof(pmx));     memset(nmx, -0x7f7f7f7f, sizeof(nmx));     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       scanf( %lld %lld , &sum[i].li, &sum[i].ri);     }     for (long long i = 1; i <= n; i++) {       pmx[i] = max(sum[i].li, pmx[i - 1]);       pmi[i] = min(sum[i].ri, pmi[i - 1]);     }     for (long long i = n; i >= 1; i--) {       nmx[i] = max(sum[i].li, nmx[i + 1]);       nmi[i] = min(sum[i].ri, nmi[i + 1]);     }     long long ans = -0x7f7f7f7f, sum1 = 0, sum2 = 0;     for (long long i = 1; i <= n; i++) {       sum1 = max(pmx[i - 1], nmx[i + 1]);       sum2 = min(pmi[i - 1], nmi[i + 1]);       ans = max(ans, sum2 - sum1);     }     if (ans < 0) {       printf( 0 n );     } else       printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int V = 0;   struct Node {     int id;     long long num, sum;     Node *l, *r;     Node() {       num = -1;       sum = 0;       l = r = nullptr;       id = V++;     }   };   int N;   string s;   Node* build(int& n) {     Node* node = new Node();     if (s[n] ==  ( ) {       n++;       node->l = build(n);       n++;       node->r = build(n);       n++;       node->sum += node->l->sum + node->r->sum + 1;     } else {       node->num = s[n] -  0 ;       n++;     }     return node;   }   const long long INF = 1 << 25;   int P, M;   bool remplus;   long long mi[10000][210];   long long ma[10000][210];   pair<long long, long long> f(Node* node, int rem) {     if (node->num != -1) {       if (rem) return {INF, INF};       return {node->num, node->num};     }     int id = node->id;     if (mi[id][rem] != INF) return {mi[id][rem], ma[id][rem]};     if (rem > node->sum) return {INF, INF};     pair<long long, long long> ret = {INF, -INF};     for (int i = 0; i < 2; i++) {       int nrem = rem - (remplus && !i || !remplus && i);       if (nrem < 0) continue;       for (int j = 0; j <= nrem; j++) {         auto res1 = f(node->l, j);         auto res2 = f(node->r, nrem - j);         if (res1.first == INF || res2.first == INF) continue;         if (i == 0) {           ret.first = min(ret.first, res1.first + res2.first);           ret.second = max(ret.second, res1.second + res2.second);         } else {           ret.first = min(ret.first, res1.first - res2.second);           ret.second = max(ret.second, res1.second - res2.first);         }       }     }     mi[id][rem] = ret.first;     ma[id][rem] = ret.second;     return ret;   }   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     cin >> s >> P >> M;     N = s.size();     int n = 0;     Node* root = build(n);     fill((long long*)begin(mi), (long long*)end(mi), INF);     fill((long long*)begin(ma), (long long*)end(ma), INF);     remplus = P <= M;     int rem = remplus ? P : M;     cout << f(root, rem).second << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   int c[5555], ans[5555];   int main() {     int n;     cin >> n;     int a[n + 1];     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) {       memset(c, 0, sizeof(c));       int bc = 0, bt = -1;       for (int j = i; j <= n; j++) {         int s = ++c[a[j]];         if (s > bc || (s == bc && a[j] < bt)) bc = s, bt = a[j];         ++ans[bt];       }     }     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int power(int a, int b) {     if (b == 0)       return 1;     else if (b % 2 == 0)       return power((a * a) % 1000000007, b / 2);     else       return (a * power((a * a) % 1000000007, b / 2) % 1000000007);   }   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       int n, x, i, m, res, a;       cin >> n >> x;       set<int> s;       m = INT_MIN;       bool flag = false;       for (i = 0; i < n; i++) {         cin >> a;         s.insert(a);         m = max(m, a);         if (x == a) flag = true;       }       if (flag) {         cout <<  1 n ;         continue;       }       res = x / m;       if (x % m)         cout << max(2, res + 1) <<   n ;       else         cout << res <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b, rem;     cin >> a >> b;     long long int count = 0;     a = max(a, b);     b = min(a, b);     while (a != b && b != 0) {       count += a / b;       a = a % b;       a = a + b;       b = a - b;       a = a - b;     }     cout << count;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int l, r, x, y, k;     scanf( %d%d%d%d%d , &x, &y, &l, &r, &k);     int L = (int)ceil(1.0 * x / k), R = (int)floor(1.0 * y / k);     if (R < L || R < l || r < L)       puts( NO );     else       puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct pt {     long long x;     long long y;   };   pt u;   bool cmp(pt a, pt b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }   bool cw(pt a, pt b, pt c) {     return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) < 0;   }   bool ccw(pt a, pt b, pt c) {     return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) > 0;   }   long long operator%(const pt &a, const pt &b) { return a.x * b.y - a.y * b.x; }   long long operator*(const pt &a, const pt &b) { return a.x * b.x + a.y * b.y; }   bool A(const pt &p) { return u % p > 0 || (u % p == 0 && u * p > 0); }   bool operator<(const pt &a, const pt &b) {     return (A(a) == A(b) && a % b > 0) || (A(a) && !A(b));   }   void convex_hull(vector<pt> &a) {     if (a.size() == 1) return;     sort(a.begin(), a.end(), &cmp);     pt p1 = a[0], p2 = a.back();     vector<pt> up, down;     up.push_back(p1);     down.push_back(p1);     for (int i = 1; i < (int)a.size(); i++) {       if (i == a.size() - 1 || cw(p1, a[i], p2)) {         while (up.size() >= 2 && !cw(up[up.size() - 2], up[up.size() - 1], a[i]))           up.pop_back();         up.push_back(a[i]);       }       if (i == a.size() - 1 || ccw(p1, a[i], p2)) {         while (down.size() >= 2 &&                !ccw(down[down.size() - 2], down[down.size() - 1], a[i]))           down.pop_back();         down.push_back(a[i]);       }     }     a.clear();     for (int i = 0; i < (int)up.size(); i++) a.push_back(up[i]);     for (int i = down.size() - 2; i > 0; i--) a.push_back(down[i]);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     u.x = 0;     u.y = 0;     long long n;     cin >> n;     map<pair<long long, long long>, long long> cont;     vector<pt> points, points2;     points.push_back({0, 0});     for (int i = 0; i < n; i++) {       long long x, y;       cin >> x >> y;       pt a;       a.x = x;       a.y = y;       points.push_back(a);       points2.push_back(a);     }     vector<pt> white;     vector<pt> black;     convex_hull(points);     long long vez = 1;     sort(points.begin(), points.end());     for (auto e : points) {       cont[{e.x, e.y}] = 1;       if (e.x == 0 && e.y == 0) {         white.push_back(e);         black.push_back(e);         continue;       }       vez = 1 - vez;       vez == 1 ? white.push_back(e) : black.push_back(e);     }     for (auto e : points2) {       if (cont[{e.x, e.y}] == 0) {         white.push_back(e);         black.push_back(e);       }     }     convex_hull(white);     convex_hull(black);     bool can = false;     for (auto e : points) {       if (e.x & 1 || e.y & 1) can = true;     }     for (auto e : black) {       if (e.x & 1 || e.y & 1) can = true;     }     for (auto e : white) {       if (e.x & 1 || e.y & 1) can = true;     }     if (can)       cout <<  Ani  << endl;     else       cout <<  Borna  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   char s[50001];   int last[26][50001];   int best[51][50001];   bool prv[51][50001];   void print(int i, int j, int k) {     int len = 2 * i + (k != -1 ? 1 : 0);     char ans[101];     ans[len] =   0 ;     if (k != -1) ans[i] = s[k];     while (j != 0) {       if (!prv[i][j]) {         --j;         continue;       }       --i, --j;       ans[i] = ans[len - i - 1] = s[j];     }     printf( %s n , ans);   }   void run(int casenr) {     scanf( %s , s);     n = strlen(s);     memset(last, -1, sizeof(last));     for (int j = (0); j < (n); ++j) {       int x = s[j] -  a ;       for (int xx = (0); xx < (26); ++xx) last[xx][j + 1] = last[xx][j];       last[x][j + 1] = j;     }     memset(best, -1, sizeof(best));     best[0][0] = n;     prv[0][0] = true;     for (int i = (0); i < (50); ++i)       for (int j = (0); j < (n); ++j)         if (best[i][j] != -1) {           if (j + 1 <= best[i][j] && best[i][j] > best[i][j + 1]) {             best[i][j + 1] = best[i][j];             prv[i][j + 1] = false;           }           int x = s[j] -  a ;           if (last[x][best[i][j]] != -1 && last[x][best[i][j]] >= j + 1 &&               last[x][best[i][j]] > best[i + 1][j + 1]) {             best[i + 1][j + 1] = last[x][best[i][j]];             prv[i + 1][j + 1] = true;           }         }     for (int i = 50; i >= 0; --i) {       if (i != 50)         for (int j = (0); j < (n); ++j)           if (best[i][j] != -1 && j < best[i][j]) {             print(i, j, j);             return;           }       for (int j = (0); j < (n); ++j)         if (best[i][j] != -1) {           print(i, j, -1);           return;         }     }     assert(false);   }   int main() {     run(1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 13 * 16, Mod = 1e9 + 7;   struct Matrix {     int n, m, A[N][N];     inline Matrix(int _n, int _m) : n(_n), m(_m) { memset(A, 0, sizeof(A)); }     inline Matrix operator*(Matrix &X) {       Matrix R(n, X.m);       for (int i = 0; i < n; i++)         for (int j = 0; j < X.m; j++)           for (int k = 0; k < m; k++)             R.A[i][j] = (R.A[i][j] + 1LL * A[i][k] * X.A[k][j]) % Mod;       return R;     }     inline Matrix operator^(long long pw) {       Matrix R(n, n), T = *this;       for (int i = 0; i < n; i++) R.A[i][i] = 1;       for (; pw; pw >>= 1, T = T * T)         if (pw & 1) R = R * T;       return R;     }     inline int *operator[](int id) { return A[id]; }   };   int n, k, m;   inline int Getid(int i, int j) { return (i + j * (k + 1)); }   int main() {     scanf( %d%d%d , &n, &k, &m);     Matrix A((k + 1) << m, (k + 1) << m);     for (int i = 0; i <= k; i++)       for (int j = 0; j < (1 << m); j++) {         A[Getid(i, j)][Getid(i, j >> 1)] = 1;         if (i < k)           A[Getid(i, j)][Getid(i + 1, (j >> 1) | (1 << m - 1))] =               __builtin_popcount(j) + 1;       }     A = A ^ n;     int tot = 0;     for (int j = 0; j < (1 << m); j++)       tot = (tot + A[Getid(0, 0)][Getid(k, j)]) % Mod;     return !printf( %d , tot);   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const long long inf = 1e18 + 9;   long long ans = inf;   long long ans1 = 0, ans2 = 0;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, a, b;     cin >> n >> a >> b;     long long need = n * 6;     if (a * b >= need) {       cout << a * b <<   n ;       cout << a <<     << b;       return 0;     }     for (long long i = 0; i <= 1e7; i++) {       long long new_x = a + i;       long long new_y = need / new_x;       if (need % new_x != 0) new_y++;       new_y = max(new_y, b);       new_x = max(new_x, a);       if (new_x * new_y < ans) ans = new_x * new_y, ans1 = new_x, ans2 = new_y;     }     for (long long i = 0; i <= 1e7; i++) {       long long new_y = b + i;       long long new_x = need / new_y;       if (need % new_y != 0) new_x++;       new_y = max(new_y, b);       new_x = max(new_x, a);       if (new_x * new_y < ans) ans = new_x * new_y, ans1 = new_x, ans2 = new_y;     }     cout << ans <<   n ;     cout << ans1 <<     << ans2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int t, f, w;     bool operator<(const edge& e) const { return w > e.w; }     edge(int from, int to, int weight) {       t = to;       f = from;       w = weight;     }   };   const double EPS = (1e-9);   class UnionFind {    public:     vector<int> p, rank, setSize;     int numSets;     UnionFind(int N) {       setSize.assign(N, 1);       numSets = N;       rank.assign(N, 0);       p.assign(N, 0);       for (int i = 0; i < N; i++) p[i] = i;     }     int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }     bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }     void unionSet(int i, int j) {       if (!isSameSet(i, j)) {         numSets--;         int x = findSet(i), y = findSet(j);         if (rank[x] > rank[y]) {           p[y] = x;           setSize[x] += setSize[y];         } else {           p[x] = y;           setSize[y] += setSize[x];           if (rank[x] == rank[y]) rank[y]++;         }       }     }     int numDisjointSets() { return numSets; }     int sizeOfSet(int i) { return setSize[findSet(i)]; }   };   long long root(long long x) {     long long l = 0, r = 1e9 + 1;     while (l < r - 1) {       long long m = (l + r) / 2;       if (m * m > x)         r = m;       else         l = m;     }     return l;   }   struct line {     double a, b, c;   };   bool areParallel(line l1, line l2) {     return (fabs(l1.a - l2.a) < EPS) && (fabs(l1.b - l2.b) < EPS);   }   bool areSame(line l1, line l2) {     return areParallel(l1, l2) && (fabs(l1.c - l2.c) < EPS);   }   struct point {     double x, y;     point() { x = y = 0.0; }     point(double _x, double _y) : x(_x), y(_y) {}     bool operator<(point other) const {       if (fabs(x - other.x) > EPS) return x < other.x;       return y < other.y;     }   };   void pointsToLine(point p1, point p2, line& l) {     if (fabs(p1.x - p2.x) < EPS) {       l.a = 1.0;       l.b = 0.0;       l.c = -p1.x;     } else {       l.a = -(double)(p1.y - p2.y) / (p1.x - p2.x);       l.b = 1.0;       l.c = -(double)(l.a * p1.x) - p1.y;     }   }   bool areIntersect(line l1, line l2, point& p) {     if (areParallel(l1, l2)) return false;     p.x = (l2.b * l1.c - l1.b * l2.c) / (l2.a * l1.b - l1.a * l2.b);     if (fabs(l1.b) > EPS)       p.y = -(l1.a * p.x + l1.c);     else       p.y = -(l2.a * p.x + l2.c);     return true;   }   long long binpowmod(long long a, long long b, long long m) {     a %= m;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   long long binpow(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   int findXOR(int n) {     switch (n % 4) {       case 0:         return n;       case 1:         return 1;       case 2:         return n + 1;       case 3:         return 0;     }   }   int rangeXOR(int l, int r) { return (findXOR(l - 1) ^ findXOR(r)); }   int getbit(int mask, int bit) { return (mask & (1 << bit)); }   void setbit(int& mask, int bit, int val) {     if (val)       mask |= (1 << bit);     else       mask &= ~(1 << bit);   }   const int N = 1e5 + 1;   const long long INF = 1e7 + 100;   const int MOD = 1e9 + 7;   class SegmentTree {    private:     vector<pair<int, int>> st;     vector<int> lp;     vector<int> A;     int n;     int left(int p) { return p << 1; }     int right(int p) { return (p << 1) + 1; }     pair<int, int> merge(pair<int, int> p1, pair<int, int> p2) {       if (p1.first == p2.first) return {p1.first, p1.second + p2.second};       if (p1.first < p2.first) return p1;       return p2;     }     void build(int p, int L, int R) {       if (L == R) {         st[p] = {A[L], 1};       } else {         build(left(p), L, (L + R) / 2);         build(right(p), (L + R) / 2 + 1, R);         pair<int, int> p1 = st[left(p)], p2 = st[right(p)];         st[p] = merge(p1, p2);       }     }     pair<int, int> rmq(int p, int L, int R, int i, int j) {       if (i > R || j < L) return {-1, -1};       if (L >= i && R <= j) return st[p];       pair<int, int> p1 = rmq(left(p), L, (L + R) / 2, i, j);       pair<int, int> p2 = rmq(right(p), (L + R) / 2 + 1, R, i, j);       if (p1.first == -1) return p2;       if (p2.first == -1) return p1;       return merge(p1, p2);     }     void update_point(int p, int L, int R, int idx, int v) {       int i = idx, j = idx;       if (i > R || j < L) return;       if (L == i && R == j) {         A[L] = v;         st[p] = {v, 1};         return;       }       pair<int, int> p1, p2;       update_point(left(p), L, (L + R) / 2, idx, v);       update_point(right(p), (L + R) / 2 + 1, R, idx, v);       p1 = st[left(p)];       p2 = st[right(p)];       st[p] = merge(p1, p2);     }       public:     SegmentTree(const vector<int>& _A) {       A = _A;       n = (int)A.size();       st.assign(4 * n, {0, 0});       lp.assign(4 * n, 0);       build(1, 0, n - 1);     }     pair<int, int> rmq(int i, int j) { return rmq(1, 0, n - 1, i, j); }     void update_point(int idx, int new_value) {       update_point(1, 0, n - 1, idx, new_value);     }   };   vector<int> freq;   int n;   bool can(int x) {     set<pair<int, int>, greater<pair<int, int>>> s;     vector<int> cnt(n + 1);     for (int i = 1; i <= n; ++i) {       if (freq[i]) {         cnt[i] = freq[i];         s.insert({cnt[i], i});       }     }     vector<int> b;     for (int i = 0; i < n; ++i) {       if (i >= x && cnt[b[i - x]] > 0) {         s.insert({cnt[b[i - x]], b[i - x]});       }       if (s.empty()) return false;       b.push_back(s.begin()->second);       s.erase(s.begin());       cnt[b.back()]--;     }     return true;   }   void solve() {     cin >> n;     freq.assign(n + 1, 0);     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       freq[x]++;     }     int lo = 0, hi = n;     while (hi - lo > 1) {       int mid = (hi + lo) / 2;       if (can(mid)) {         lo = mid;       } else         hi = mid;     }     cout << lo - 1 <<   n ;   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tc = 1;     cin >> tc;     while (tc--) {       solve();     }   }