malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   string s[2005];   char str[2005][2005];   int a[2005][2005];   int v[2005][2005];   long long dp[8005][2005];   int pool[8005], top = 0;   int child[8005];   int ID = 0, n;   int getID() { return pool[--top]; }   void pre() {     for (int i = 8000; i >= 0; i--) pool[top++] = i;   }   void delID(int x) { pool[top++] = x; }   int K;   int combine(int me, int you, int D) {     int ret = getID();     child[ret] = min(K, child[me] + child[you]);     for (int i = 0; i <= child[ret]; i++) dp[ret][i] = 0;     for (int i = 0; i <= child[me]; i++)       for (int j = 0; j <= child[you] && i + j <= K; j++)         dp[ret][i + j] = max(dp[ret][i + j], dp[me][i] + dp[you][j] + i * j * D);     return ret;   }   int go(int L, int R, int D) {     int me = getID();     int c = 0;     while (L <= R && str[L][D] ==   0 ) ++c, ++L;     child[me] = c;     for (int i = 0; i <= c; i++) dp[me][i] = i * (i - 1) / 2 * D;     for (int i = L, j = L; i <= R; i = j) {       for (j = i; j <= R && str[i][D] == str[j][D]; j++)         ;       int you = go(i, j - 1, D + 1);       int nxt = combine(me, you, D);       delID(me);       delID(you);       me = nxt;     }     return me;   }   int main(void) {     pre();     scanf( %d%d , &n, &K);     for (int i = 1; i <= n; i++) cin >> s[i];     sort(s + 1, s + 1 + n);     for (int i = 1; i <= n; i++) strcpy(str[i], s[i].c_str());     int me = go(1, n, 0);     printf( %I64d n , dp[me][K]);     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   const int maxN = 110;   int n, k, a[maxN];   void solve() {     vector<vector<double> > d[2];     int u = 0, v = 1;     d[u].assign(maxN, vector<double>(maxN, 0.0));     for (int i = 1; i <= n; ++i) {       for (int j = i + 1; j <= n; ++j) {         if (a[i] < a[j]) {           d[u][i][j] = 1.0;         } else {           d[u][j][i] = 1.0;         }       }     }     double p = 2.0 / (double)(n * (n + 1));     for (int steps = 0; steps < k; ++steps, swap(u, v)) {       d[v].assign(maxN, vector<double>(maxN, 0.0));       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= n; ++j) {           if (i == j) {             continue;           }           for (int a = 1; a <= n; ++a) {             for (int b = a; b <= n; ++b) {               int ni = i;               if (a <= i && i <= b) {                 ni = a + b - i;               }               int nj = j;               if (a <= j && j <= b) {                 nj = a + b - j;               }               d[v][ni][nj] += p * d[u][i][j];             }           }         }       }     }     double res = 0.0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j < i; ++j) {         res += d[u][i][j];       }     }     printf( %.10lf n , res);   }   int main() {     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int q[100010], t, n;   bool cmp(int a, int b) { return a < b; }   int main() {     scanf( %d , &t);     for (int i = 1; i <= t; i++) {       scanf( %d , &n);       for (int j = 1; j <= n; j++) {         scanf( %d , &q[j]);       }       int flag = 1;       sort(q + 1, q + n + 1, cmp);       for (int k = n - 2; k >= 1; k--) {         if (q[n - 1] >= k + 1) {           printf( %d n , k);           flag = 0;           break;         }       }       if (flag) printf( 0 n );     }   }
#include <bits/stdc++.h>   int main() {     long int n, m;     int t;     scanf( %d , &t);     while (t--) {       scanf( %ld%ld , &n, &m);       if (n == 1)         printf( 0 n );       else if (n == 2) {         printf( %ld n , m);       } else {         printf( %ld n , 2 * m);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   struct particle {     int x, v;   } particles[500002];   bool possible(long double time) {     long double maxRightyX = -1e19;     for (int i = 1; i <= n; i++) {       if (particles[i].v > 0) {         maxRightyX = max(particles[i].x + particles[i].v * time, maxRightyX);       } else if (maxRightyX >= particles[i].x + particles[i].v * time) {         return true;       }     }     return false;   }   void bin() {     long double l = 0, r = 1000000000;     while (l + 0.0000000001 < r) {       long double mid = (l + r) / 2;       if (possible(mid))         r = mid;       else         l = mid + 0.0000000001;     }     cout << fixed << setprecision(10);     if (possible(l)) {       cout << l;     } else if (possible(r)) {       cout << r;     } else {       cout <<  -1 ;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> particles[i].x >> particles[i].v;     bin();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> adj;   vector<int> a;   vector<int> dep;   vector<int> ret;   unordered_map<int, vector<int>> pmp;   unordered_map<int, vector<int>> mp;   vector<int> primeFactors(int num) {     vector<int> ret;     for (int i = 2; i * i <= num; i++) {       while (num % i == 0) {         ret.push_back(i);         num /= i;       }     }     if (num != 1) ret.push_back(num);     return ret;   }   void dfs(int idx, int prev, int level) {     dep[idx] = level;     for (int i : pmp[a[idx]]) {       if (mp.count(i) && !mp[i].empty()) {         if (ret[idx] == -1 || dep[ret[idx]] < dep[mp[i].back()])           ret[idx] = mp[i].back();       }     }     for (int i : pmp[a[idx]]) {       mp[i].push_back(idx);     }     for (auto nidx : adj[idx]) {       if (nidx == prev) continue;       dfs(nidx, idx, level + 1);     }     for (int i : pmp[a[idx]]) {       mp[i].pop_back();     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, q;     cin >> n >> q;     a = vector<int>(n + 1, 0);     dep = vector<int>(n + 1, 0);     ret = vector<int>(n + 1, -1);     for (int i = 1; i <= n; i++) cin >> a[i];     adj = vector<vector<int>>(n + 1);     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     for (int i = 1; i <= n; i++) {       if (pmp.count(a[i])) continue;       pmp[a[i]] = primeFactors(a[i]);     }     dfs(1, 0, 1);     while (q--) {       int type, v, w;       cin >> type;       if (type == 1) {         cin >> v;         cout << ret[v] << endl;       } else {         cin >> v >> w;         a[v] = w;         if (pmp.count(a[v])) continue;         pmp[a[v]] = primeFactors(a[v]);         ret = vector<int>(n + 1, -1);         dfs(1, 0, 1);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool prime(int x) {     if (x % 2 == 0) return 0;     for (size_t i = 3; i * i <= x; i += 2) {       if (x % i == 0) return 0;     }     return 1;   }   void solve() {     int n, x = 3;     cin >> n;     while (n) {       if (prime(x)) {         cout << x <<    ;         n--;       }       x += 2;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();   }
#include <bits/stdc++.h>   using namespace std;   const int N = 210000;   int n, root, opt, Max[N << 6], lson[N << 6], rson[N << 6], lazy[N << 6];   void pushdown(int k, int l, int r) {     if (!lazy[k]) return;     if (l != r) {       if (!lson[k]) lson[k] = ++opt;       if (!rson[k]) rson[k] = ++opt;       lazy[lson[k]] += lazy[k];       lazy[rson[k]] += lazy[k];       Max[lson[k]] += lazy[k];       Max[rson[k]] += lazy[k];     }     lazy[k] = 0;   }   void insert(int &k, int l, int r, int L, int R) {     if (l > R || r < L) return;     if (!k) k = ++opt;     if (l >= L && r <= R) return (void)(Max[k]++, lazy[k]++);     pushdown(k, l, r);     int mid = l + r >> 1;     if (L <= mid) insert(lson[k], l, mid, L, R);     if (R > mid) insert(rson[k], mid + 1, r, L, R);     Max[k] = max(Max[lson[k]], Max[rson[k]]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x, y;       scanf( %d%d , &x, &y);       insert(root, 0, 1000000000, x, y);       if (Max[1] > 2) {         puts( NO );         return 0;       }     }     puts( YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 6e5;   const int oo = 1e9 + 5;   int du[] = {-1, 0, 0, 1};   int dv[] = {0, -1, 1, 0};   const long long mod = 1e9 + 7;   long long sqr(long long x) { return x * x; }   int n, x, a[N + 5], ans;   bool vis[N + 5];   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> x;     vis[x] = true;     for (int i = 1; i < (1 << n); i++) {       if (!vis[i]) a[ans++] = i;       vis[i ^ x] = vis[i] = true;     }     cout << ans << endl;     for (int i = 1; i <= ans; i++) cout << (a[i] ^ a[i - 1]) <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5 * 100 * 1000 + 10;   int arr[MAXN], nx[MAXN], bf[MAXN];   stack<int> st;   pair<int, int> pr[MAXN];   int main() {     int n, m, p;     cin >> n >> m >> p;     string second, w;     cin >> second >> w;     second =     + second;     int cntr = 1;     for (int i = 1; i < second.size(); i++) {       if (second[i] ==  ( ) {         arr[i] = cntr;         pr[cntr].first = i;         st.push(cntr);         cntr++;       } else {         arr[i] = st.top();         pr[arr[i]].second = i;         st.pop();       }       nx[i] = i + 1;       bf[i] = i - 1;     }     nx[0] = 1;     for (int i = 0; i < w.size(); i++) {       if (w[i] ==  R )         p = nx[p];       else if (w[i] ==  L )         p = bf[p];       else {         int sr = pr[arr[p]].first;         int er = pr[arr[p]].second;         nx[bf[sr]] = nx[er];         bf[nx[er]] = bf[sr];         if (nx[er] < second.size())           p = nx[er];         else           p = bf[sr];       }     }     int i = nx[0];     while (i < second.size()) {       cout << second[i];       i = nx[i];     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   int l, r, a, b, dif, t, x, lit, poz;   bool uz[27];   char s[1001];   int main() {     cin >> a >> b >> l >> r;     dif = min(500, r - l);     l = l % (a + b);     if (l == 0) l = a + b;     r = l + dif;     if (l <= a) {       for (int i = l; i <= min(a, r); i++) s[++poz] = i;       l = a + 1;       t = 1;     } else {       for (int i = l; i <= min(a + b, r); i++) s[++poz] = 1;       l = a + b + 1;       memset(uz, 0, sizeof(uz));       for (int i = poz; i >= max(1, poz - a + 1); i--) uz[s[i]] = 1;       lit = 1;       t = 2;     }     x = 0;     while (l <= r) {       if (t == 1) {         x++;         s[++poz] = s[poz - 1];         l++;         if (x == b) {           memset(uz, 0, sizeof(uz));           for (int i = poz; i >= max(1, poz - a + 1); i--) uz[s[i]] = 1;           lit = 1;           t = 2;           x = 0;         }       } else {         x++;         while (uz[lit] == 1) lit++;         s[++poz] = lit;         l++;         uz[lit] = 1;         if (x == a) {           t = 1;           x = 0;         }       }     }     memset(uz, 0, sizeof(uz));     for (int i = 1; i <= poz; i++) {       uz[s[i]] = 1;     }     int nr = 0;     for (int i = 1; i <= 26; i++) nr += uz[i];     cout << nr;     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);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     string a, b;     cin >> a >> b;     int cnt1 = 0;     for (int i = 0; i < (int)a.length(); i++) cnt1 += a[i] -  0 ;     int cnt2 = 0;     for (int i = 0; i < (int)b.length(); i++) cnt2 += b[i] -  0 ;     if (cnt1 + (cnt1 & 1) >= cnt2)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void amin(T &first, const T &second) {     if (second < first) first = second;   }   template <class T>   inline void amax(T &first, const T &second) {     if (first < second) first = second;   }   void solve() {     int n;     cin >> n;     vector<pair<int, int> > a(n);     map<int, int> home;     for (int i = 0; i < n; ++i) {       cin >> a[i].first >> a[i].second;       home[a[i].first]++;     }     vector<int> ret(n);     for (int i = 0; i < n; ++i) {       ret[i] = n - 1;       ret[i] += home[a[i].second];     }     for (int i = 0; i < n; ++i) {       cout << ret[i] <<     << 2 * (n - 1) - ret[i] <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int years[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31,                  30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29, 31, 30, 31, 30,                  31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30,                  31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,                  31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> v(n);     for (auto &i : v) cin >> i;     ;     for (int i = 0; i < 72; i++) {       if (years[i] != v[0]) continue;       for (int j = 0; j < n; j++) {         if (j == n - 1 && v[j] == years[i + j]) return cout <<  Yes  << endl, 0;         if (v[j] != years[i + j]) break;       }     }     cout <<  No  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     long long q;     cin >> q;     for (long long t = 0; t < q; t++) {       long long n, k;       cin >> n >> k;       vector<vector<long long>> adj((size_t)n);       map<pair<long long, long long>, long long> weight;       for (long long i = 0; i < n - 1; i++) {         long long u, v, w;         cin >> u >> v >> w;         u--, v--;         adj[u].push_back(v);         adj[v].push_back(u);         weight[{u, v}] = w;         weight[{v, u}] = w;       }       vector<vector<long long>> dp((size_t)n, vector<long long>((size_t)2));       function<void(long long, long long)> visit = [&](long long u, long long v) {         dp[v][0] = 0;         dp[v][1] = 0;         vector<long long> g;         for (long long w : adj[v]) {           if (w != u) {             visit(v, w);             dp[v][0] += dp[w][1];             dp[v][1] += dp[w][1];             g.push_back(max(dp[w][0] + weight[{v, w}], dp[w][1]) - dp[w][1]);           }         }         sort(g.rbegin(), g.rend());         dp[v][0] += accumulate(             g.begin(), g.begin() + min((long long)g.size(), k - 1), (long long)0);         dp[v][1] += accumulate(g.begin(), g.begin() + min((long long)g.size(), k),                                (long long)0);       };       visit(-1, 0);       cout << dp[0][1] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct pt {     unsigned long long x, y, v;   };   int n;   vector<unsigned long long> a, b;   pt c[200005];   vector<vector<unsigned long long>> d;   void sq(vector<unsigned long long>& v) {     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());   }   template <class T>   T gcd(T a, T b) {     T t;     while (a) {       t = a;       a = b % a;       b = t;     }     return b;   }   const unsigned long long MOD1 = 1000000007;   const unsigned long long MOD2 = 1000000009;   struct frac {     unsigned long long p, q;     bool operator==(const frac& b) const {       unsigned long long v11 = (p % MOD1 * (b.q % MOD1)) % MOD1;       unsigned long long v12 = (q % MOD1 * (b.p % MOD1)) % MOD1;       if (v11 != v12) return false;       unsigned long long v21 = (p % MOD2 * (b.q % MOD2)) % MOD2;       unsigned long long v22 = (q % MOD2 * (b.p % MOD2)) % MOD2;       if (v21 != v22) return false;       return p * b.q == q * b.p;     }   };   bool deli(unsigned long long a, unsigned long long b, unsigned long long c) {     unsigned long long g = gcd(a, b);     a /= g;     g = gcd(a, c);     return a == g;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     cin >> n;     for (int i = 0; i < n; i++) {       unsigned long long x, y, v;       cin >> x >> y >> v;       c[i] = {x, y, v};       a.push_back(x);       b.push_back(y);     }     sq(a);     sq(b);     int rows = a.size();     int cols = b.size();     if (rows * 1ll * cols != n) {       cout <<  0 n ;       return 0;     }     d.assign(rows, vector<unsigned long long>(cols, 0));     for (int i = 0; i < n; i++) {       int rr = lower_bound(a.begin(), a.end(), c[i].x) - a.begin();       int cc = lower_bound(b.begin(), b.end(), c[i].y) - b.begin();       d[rr][cc] = c[i].v;     }     bool ok = true;     for (int i = 0; i < rows - 1; i++) {       for (int j = 0; j < cols - 1; j++) {         frac a = {d[i][j], d[i + 1][j]};         frac b = {d[i][j + 1], d[i + 1][j + 1]};         if (!(a == b)) {           ok = false;         }       }     }     if (!ok) {       cout <<  0 n ;       return 0;     }     unsigned long long sol = 0;     unsigned long long v0 = d[0][0];     unsigned long long grow = 0;     for (int j = 0; j < cols; j++) grow = gcd(grow, d[0][j]);     unsigned long long gcol = 0;     for (int i = 0; i < rows; i++) gcol = gcd(gcol, d[i][0]);     set<unsigned long long> divs;     for (unsigned long long i = 1; i * i <= grow; i++) {       if (grow % i == 0) {         divs.insert(i);         divs.insert(grow / i);       }     }     for (unsigned long long g : divs) {       if (deli(v0, gcol, g)) {         sol++;       }     }     cout << sol <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     map<char, int> mp;     for (char c : s) mp[c]++;     cout << 2 * min(mp[ L ], mp[ R ]) + 2 * min(mp[ U ], mp[ D ]) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b, c;     int n;     cin >> n >> a;     sort(a.begin(), a.end());     for (int i = 0; i < a.size(); i += n) b += a[i];     for (int i = 0; i < n; i++) c += b;     b = c;     sort(b.begin(), b.end());     if (b != a)       cout << -1;     else       cout << c;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v[100005];   vector<pair<int, int> > asdf;   int n;   int m;   int cnt[100005];   vector<int> nxt[100005];   void build(int at, int num) {     if (cnt[at] > 2) return;     if (num == m) {       while ((int)asdf.size()) {         printf( %d %d n , 1 + asdf.back().first, 1 + asdf.back().second);         asdf.pop_back();       }       exit(0);     }     if (cnt[at] == 2) return;     int a, b;     if ((int)v[at].size() != 0) {       a = v[at].front();       b = v[at].back();     } else {       a = -1, b = -1;     }     int c, d;     if ((int)nxt[at].size()) {       c = nxt[at].back();       d = nxt[at].front();     } else {       c = d = -1;     }     for (auto(i) = (at + 1); (i) != (n); (i)++) {       if (i != d && i != c && i != a && i != b && cnt[i] < 2) {         asdf.push_back(make_pair(i, at));         cnt[at]++;         cnt[i]++;         nxt[at].push_back(i);         nxt[i].push_back(at);         build(i, num + 1);         nxt[at].pop_back();         nxt[i].pop_back();         cnt[at]--;         cnt[i]--;         asdf.pop_back();       }     }     if (cnt[at] > 0 && cnt[at] < 2) {       c = nxt[at].front();       d = nxt[at].back();       for (auto(i) = (0); (i) != (at); (i)++) {         if (cnt[i] < 2 && i != a && i != b && i != c && i != d) {           asdf.push_back(make_pair(i, at));           cnt[at]++;           cnt[i]++;           nxt[at].push_back(i);           nxt[i].push_back(at);           build(i, num + 1);           nxt[at].pop_back();           nxt[i].pop_back();           cnt[at]--;           cnt[i]--;           asdf.pop_back();         }       }     } else {       c = d = -1;       for (auto(i) = (0); (i) != (at); (i)++) {         if (i != c && i != d && i != a && i != b && cnt[i] < 2) {           asdf.push_back(make_pair(i, at));           cnt[at]++;           cnt[i]++;           nxt[at].push_back(i);           nxt[i].push_back(at);           build(i, num + 1);           nxt[at].pop_back();           nxt[i].pop_back();           cnt[at]--;           cnt[i]--;           asdf.pop_back();         }       }     }   }   int main() {     cin >> n >> m;     for (auto(i) = (0); (i) != (m); (i)++) {       int a, b;       cin >> a >> b;       a--;       b--;       v[a].push_back(b), v[b].push_back(a);     }     int kek = 0;     for (auto(i) = (0); (i) != (n); (i)++)       kek += (min(2, (n - 1 - (int)v[i].size())));     kek /= 2;     if (kek < m) {       puts( -1 );       return 0;     }     for (auto(i) = (0); (i) != (n); (i)++) build(i, 0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 4;   vector<int> adj[N];   int deg[N];   int lv[N];   int decr[N];   int vis[N];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 0; i < n - 1; i++) {       int x, y;       scanf( %d%d , &x, &y);       adj[x].push_back(y);       adj[y].push_back(x);       deg[x]++;       deg[y]++;     }     queue<pair<int, int>> q;     bool yes = n > 3;     for (int i = 1; i <= n; i++)       if (deg[i] == 1) q.push({i, 0}), lv[i] = 1, decr[i] = 3;     while (!q.empty()) {       auto tmp = q.front();       q.pop();       int u = tmp.first;       int p = tmp.second;       vis[u] = 1;       if (decr[u] < 3) yes = false;       for (auto v : adj[u]) {         if (vis[v]) continue;         if (lv[v] != 0 && lv[v] != lv[u] + 1) {           yes = false;         }         lv[v] = lv[u] + 1;         deg[v]--;         decr[v]++;         if (lv[v] == k + 1 && deg[v] == 0)           q.push({v, u});         else if (deg[v] == 1)           q.push({v, u});       }     }     int mx = 0;     for (int i = 1; i <= n; i++) mx = max(mx, lv[i]);     yes &= (mx == k + 1);     puts(yes ?  Yes  :  No );   }
#include <bits/stdc++.h>   using namespace std;   const int sz = 1e5 + 100;   const int INF = 1e9;   const double eps = 1e-7;   void solve() {     int n;     cin >> n;     vector<long long> a(n + 1, 0);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a.begin(), a.begin() + n);     for (int i = n - 1; i > -1; i--) {       cout << a[i % 2 ? n - 1 - i / 2 : i / 2] <<    ;     }     cout << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<long long> hs, vs;   multiset<long long> hms, vms;   int main() {     long long h, w, t, n, i, j, k, l;     char c;     cin >> w >> h >> n;     hs.insert(0);     hs.insert(h);     vs.insert(0);     vs.insert(w);     hms.insert(h);     vms.insert(w);     for (i = 0; i < n; i++) {       cin >> c >> j;       if (c ==  H ) {         hs.insert(j);         auto q = hs.find(j);         auto p = q;         auto r = q;         p--;         r++;         hms.erase(hms.find(*r - *p));         hms.insert(*q - *p);         hms.insert(*r - *q);       } else {         vs.insert(j);         auto q = vs.find(j);         auto p = q;         auto r = q;         p--;         r++;         vms.erase(vms.find(*r - *p));         vms.insert(*q - *p);         vms.insert(*r - *q);       }       cout << (*hms.rbegin()) * (*vms.rbegin()) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n, a[101], d = 0, x = 0, y = 0, m = 0, p = 0;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];       m = max(m, a[i]);       p = min(p, a[i]);       if (a[i] > 0)         x++;       else if (a[i] < 0)         y++;     }     float z = ceil(n / 2.0);     if (x >= z)       d = m;     else if (y >= z)       d = p;     cout << d << endl;     return 0;   }