malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const double PI = 2.0 * acos(0.0);   inline int getInt() {     int x;     scanf( %d , &x);     return x;   }   inline long long getLL() {     long long x;     scanf( %lld , &x);     return x;   };   inline int NUM(char c) { return (int)c - 48; }   inline char CHR(int n) { return (char)(n + 48); }   template <class T>   inline T MAX(T a, T b) {     if (a > b) return a;     return b;   }   template <class T>   inline T MIN(T a, T b) {     if (a < b) return a;     return b;   }   inline void OPEN(string s) {     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);   }   int N;   int A[100000 + 5];   int sorted[100000 + 5];   map<int, stack<int> > MAP;   int pos[100000 + 5];   int idx = -1;   inline bool islucky(int x) {     if (x == 0) return false;     while (x) {       if (x % 10 != 4 && x % 10 != 7) return false;       x /= 10;     }     return true;   }   vector<pair<int, int> > sol;   stack<int> tumpuk;   bool found[100000 + 5];   inline int jelajah(int i) {     found[i] = true;     int root = i;     while (pos[i] != root) {       sol.push_back(make_pair(i, pos[i]));       i = pos[i];       found[i] = true;     }     return i;   }   int main() {     scanf( %d , &N);     for (int i = 0, _n = (N); i < _n; i++) {       scanf( %d , &A[i]);       if (islucky(A[i])) idx = i;       sorted[i] = A[i];     }     sort(sorted, sorted + N);     bool so = true;     for (int i = 0, _n = (N); i < _n; i++) {       if (A[i] != sorted[i]) {         so = false;       }     }     if (idx == -1 && !so) {       puts( -1 );       return 0;     } else if (idx == -1) {       puts( 0 );       return 0;     }     for (int i = (N)-1; i >= 0; i--) {       MAP[sorted[i]].push(i);     }     for (int i = 0, _n = (N); i < _n; i++) {       int x = A[i];       A[i] = MAP[x].top();       MAP[x].pop();       pos[A[i]] = i;     }     idx = jelajah(idx);     for (int i = 0, _n = (N); i < _n; i++) {       if (!found[i]) {         tumpuk.push(idx);         sol.push_back(make_pair(idx, i));         idx = jelajah(i);       }     }     while ((tumpuk).size() > 0) {       sol.push_back(make_pair(idx, tumpuk.top()));       idx = tumpuk.top();       tumpuk.pop();     }     printf( %d n , (sol).size());     for (int i = 0, _n = ((sol).size()); i < _n; i++) {       printf( %d %d n , sol[i].first + 1, sol[i].second + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int TAILLE_MAX = 1000;   int main() {     int n, l, r;     cin >> n >> l;     int p[TAILLE_MAX];     for (int i = 0; i < n; i++) cin >> p[i];     sort(p, p + n);     r = max(p[0], l - p[n - 1]) * 2;     for (int i = 0; i < n - 1; i++) r = max(r, p[i + 1] - p[i]);     cout.precision(20);     cout << fixed << r / 2.0 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   long long k;   long long a[200005];   long long s1;   long long s2;   long long inv[200005];   long long p;   long long ans;   long long quick_pow(long long x, long long n) {     long long res = 1;     while (n) {       if (n & 1) res = res * x % 1000000007;       x = x * x % 1000000007;       n >>= 1;     }     return res;   }   int main() {     scanf( %lld %lld , &n, &k);     inv[1] = inv[0] = 1LL;     for (long long i = 2; i <= n; i++)       inv[i] = (1000000007 - 1000000007 / i) * inv[1000000007 % i] % 1000000007;     for (long long i = 1; i <= n; ++i) inv[i] = inv[i - 1] * inv[i] % 1000000007;     for (long long i = 1; i <= n; ++i) scanf( %lld , a + i);     for (long long i = 0; i <= k; ++i) {       long long fg = 1;       if (i & 1) fg = -1;       (s1 += fg * inv[i] * inv[k - i] % 1000000007 * quick_pow(k - i, n) %              1000000007) %= 1000000007;       (s2 += fg * inv[i] * inv[k - i] % 1000000007 * quick_pow(k - i, n - 1) %              1000000007) %= 1000000007;     }     p = (s1 + s2 * (n - 1) % 1000000007) % 1000000007;     p = (p + 1000000007) % 1000000007;     for (long long i = 1; i <= n; ++i)       ans = (ans + a[i] * p % 1000000007) % 1000000007;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = (int)2E5 + 5;   const long long mdls = (long long)1E9 + 7;   vector<int> Adj[maxN];   vector<long long> suff[maxN], pref[maxN];   long long f[maxN], g[maxN], h[maxN];   int n;   void DFS(int u) {     f[u] = 1;     for (int i = 0, sz = Adj[u].size(); i < sz; ++i) {       int v = Adj[u][i];       DFS(v);       f[u] = (f[u] * (f[v] + 1)) % mdls;     }     int sz = Adj[u].size();     suff[u].resize(sz);     pref[u].resize(sz);     long long temp = 1;     for (int i = 0; i < sz; ++i) {       temp = (temp * (f[Adj[u][i]] + 1)) % mdls;       pref[u][i] = temp;     }     temp = 1;     for (int i = sz - 1; i >= 0; --i) {       temp = (temp * (f[Adj[u][i]] + 1)) % mdls;       suff[u][i] = temp;     }   }   void DFS2(int u) {     for (int i = 0, sz = Adj[u].size(); i < sz; ++i) {       int v = Adj[u][i];       h[v] = h[u];       if (i > 0) h[v] = (h[v] * pref[u][i - 1]) % mdls;       if (i < sz - 1) h[v] = (h[v] * suff[u][i + 1]) % mdls;       h[v] = (h[v] + 1) % mdls;       g[v] = (f[v] * h[v]) % mdls;       DFS2(v);     }   }   int main() {     scanf( %d , &n);     for (int u = 1; u <= n; ++u) Adj[u].clear();     for (int v = 2; v <= n; ++v) {       int u;       scanf( %d , &u);       Adj[u].push_back(v);     }     DFS(1);     h[1] = 1;     g[1] = f[1];     DFS2(1);     for (int u = 1; u <= n; ++u) printf( %I64d  , g[u]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using LL = long long;   template <class T>   int size(T &&x) {     return int(x.size());   }   template <class A, class B>   ostream &operator<<(ostream &out, const pair<A, B> &p) {     return out <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {     out <<  { ;     for (auto it = x.begin(); it != x.end(); ++it)       out << *it << (it == prev(x.end()) ?    :  ,  );     return out <<  } ;   }   void dump() {}   template <class T, class... Args>   void dump(T &&x, Args... args) {     cerr << x <<  ;   ;     dump(args...);   }   mt19937_64 rng(0);   int rd(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int _degsize;     cin >> _degsize;     vector<int> d(_degsize);     for (int &di : d) cin >> di;     vector<pair<int, int>> edges;     auto add_edge = [&](int v, int u) {       assert(v != u);       edges.emplace_back(v, u);     };     while (size(d)) {       0 && cerr;       int n = d.back() + 1;       if (size(d) == 1) {         for (int v = (0); v <= ((n)-1); ++v)           for (int u = (0); u <= ((v)-1); ++u) add_edge(v, u);         d.clear();         break;       }       int max_cnt = d.front();       for (int &di : d) di -= max_cnt;       for (int v = (n - max_cnt); v <= (n - 1); ++v)         for (int u = (0); u <= ((v)-1); ++u) add_edge(v, u);       d.erase(d.begin());       d.erase(prev(d.end()));     }     cout << size(edges) <<   n ;     for (auto [v, u] : edges) cout << v + 1 <<     << u + 1 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int mx = 5e5 + 10;   const double eps = 1e-9;   const int inf = 1e9;   char a[mx];   multiset<char> ms;   int main() {     scanf( %s , a);     int n = strlen(a);     int mn = a[0] -  a ;     printf( Mike n );     for (int i = 1; i < n; i++) {       if (a[i] -  a  > mn) {         printf( Ann n );       } else         printf( Mike n );       mn = min(mn, a[i] -  a );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int dem = 0;     int n;     int tong = 0;     int s;     cin >> n;     for (int i = 9; i >= 1; i--) {       if (n % i == 0) {         s = i;         break;       }     }     int z;     z = n / s;     cout << z << endl;     while (z) {       cout << s <<    ;       z--;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string removeZero(string s) {     int i = 0, m = 0, j = s.size() - 1;     if (s[i] ==  0 ) {       while (s[i] ==  0 ) {         i++;       }     }     s.erase(0, i);     if (s[j] ==  0 ) {       while (s[j] ==  0 ) {         m++;         j--;       }     }     s.erase(j + 1, s.size() - j);     return s;   }   int main() {     string s;     cin >> s;     s = removeZero(s);     int x = 0, o = s.size() - 1, flag = 0;     while (x <= s.size() - 1) {       if (s[x] != s[o]) {         flag = 1;         cout <<  NO ;         break;       }       x++;       o--;     }     if (flag == 0) cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long oo = 1e14;   long long ab(long long x) { return x > 0 ? x : -x; }   long long a[100005];   long long kn[66];   long long sum[100005];   map<long long, int> mp;   int nxt[100005];   int main() {     int n, k;     scanf( %d%d , &n, &k);     kn[0] = 1;     int cnt = 0;     for (int i = 1;; i++) {       kn[i] = kn[i - 1] * k;       if (kn[i] == 1) break;       cnt++;       if (ab(kn[i]) >= oo) break;     }     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       sum[i] = sum[i - 1] + a[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j <= cnt; j++) {         mp[sum[n] - sum[i] - kn[j]]++;       }     }     long long ans = 0, step = 0;     for (int i = n; i >= 1; i--) {       ans += mp[step];       for (int j = 0; j <= cnt; j++) {         mp[sum[n] - sum[i - 1] - kn[j]]--;       }       step += a[i];     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e16;   const long long int maxn = 1 << 20;   double pie = 3.1415926535;   string str[101];   bool done[101];   int main() {     long long int n, i, j, cnt, offset;     string s, s1, ans;     cin >> n >> s;     ans =   ;     for (i = 0; i < n; i++) ans +=  9 ;     for (i = 0; i < n; i++) {       offset = 10 - (s[i] -  0 );       s1.clear();       for (j = i, cnt = 0; cnt < n; cnt++, j++) {         long long int x = (s[j] -  0  + offset) % 10;         s1 += (x +  0 );         if (j == n - 1) j = -1;       }       ans = min(ans, s1);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long inff = 0x3f3f3f3f3f3f3f3f;   int main() {     cin.tie(0);     long long k, d, t, qw, e;     scanf( %I64d , &k), scanf( %I64d , &d), scanf( %I64d , &t);     qw = (k / d + 1) * d;     if (k % d == 0) {       cout << t << endl;       return 0;     }     double s = 0.0, zz, po;     po = (qw - k) * 0.5 + k;     e = 2ll * t / (qw + k);     e *= qw;     s += e;     e /= qw;     zz = t - e * po;     if (zz <= k) {       s += zz;     } else {       s += k;       zz -= k;       s += zz * 2.0;     }     printf( %.10f n , s);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fff() {     freopen( dravde.in ,  r , stdin);     freopen( dravde.out ,  w , stdout);   }   const int MAXN = 100001;   int n;   map<int, int> m[MAXN];   int f[MAXN], s[MAXN], p[MAXN], cnt = 0, z;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int v, c, l, r;       scanf( %d%d%d%d , &v, &c, &l, &r);       if (r + c < MAXN && (!l || m[l].find(r + c) != m[l].end())) {         int u = m[l][r + c];         f[i] = f[u] + v, p[i] = u;         if (!r && f[i] > f[z]) {           z = i;         }         if (f[i] > f[m[l + c][r]]) {           m[l + c][r] = i;         }       }     }     while (z) {       s[cnt++] = z;       z = p[z];     }     printf( %d n , cnt);     while (cnt--) {       printf( %d  , s[cnt]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, v;   pair<int, int> p[10];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf(  n );       for (int j = 1; j <= m; ++j) {         char ch = getchar();         if (ch ==  * ) p[++v] = make_pair(i, j);       }     }     if (p[1].first == p[2].first && p[1].second == p[3].second)       printf( %d %d , p[3].first, p[2].second);     else if (p[1].first == p[3].first && p[1].second == p[2].second)       printf( %d %d , p[2].first, p[3].second);     else if (p[2].first == p[1].first && p[2].second == p[3].second)       printf( %d %d , p[3].first, p[1].second);     else if (p[2].first == p[3].first && p[2].second == p[1].second)       printf( %d %d , p[1].first, p[3].second);     else if (p[3].first == p[1].first && p[3].second == p[2].second)       printf( %d %d , p[2].first, p[1].second);     else if (p[3].first == p[2].first && p[3].second == p[1].second)       printf( %d %d , p[1].first, p[2].second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long tests, t, qq, q, i, j, bb[200000], s1, ans[2100][2100];   long long a, b;   long solve(long long a, long long b) {     if (a < b) swap(a, b);     if (a == 0 || b == 0) return 0;     if (solve(a % b, b) == 0) return 1;     t = a / b;     if (b % 2 == 1) return 1 - t % 2;     t %= (b + 1);     if (t % 2 == 1) return 0;     return 1;   }   int main() {     long s = 0;     cin >> tests;     for (; tests; --tests) {       cin >> a >> b;       if (solve(a, b))         cout <<  First  << endl;       else         cout <<  Second  << endl;     }     cin.get();     cin.get();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100500;   using ll = long long;   using point = pair<ll, ll>;   ll& x(point& p) { return p.first; }   ll& y(point& p) { return p.second; }   int n;   point p[N], p2[N];   set<point> s;   point centerN, center2, invP;   int no() {     cout <<  NO  << endl;     return 0;   }   int main() {     cin >> n;     x(centerN) = 0;     y(centerN) = 0;     for (int i = 0; i < n; ++i) {       cin >> x(p[i]) >> y(p[i]);       x(p2[i]) = 2 * x(p[i]);       y(p2[i]) = 2 * y(p[i]);       x(centerN) += x(p[i]);       y(centerN) += y(p[i]);     }     if ((2 * x(centerN)) % n != 0 || (2 * y(centerN)) % n != 0) {       return no();     }     x(center2) = 2 * x(centerN) / n;     y(center2) = 2 * y(centerN) / n;     for (int i = 0; i < n; ++i) {       x(p2[i]) -= x(center2);       y(p2[i]) -= y(center2);       s.insert(p2[i]);     }     for (int i = 0; i < n; ++i) {       x(invP) = -x(p2[i]);       y(invP) = -y(p2[i]);       auto it = s.find(invP);       if (it == s.end()) {         return no();       }     }     cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, q;   int kek[20];   long long a[696969];   void upd(int x, int v, int s = 0, int e = (1 << n) - 1, int d = n - 1,            int p = 1) {     if (s == e) {       a[p] = v;       return;     }     int m = (s + e) / 2;     if (x <= m) {       upd(x, v, s, m, d - 1, 2 * p + kek[d]);     } else {       upd(x, v, m + 1, e, d - 1, 2 * p + 1 - kek[d]);     }     a[p] = a[2 * p] + a[2 * p + 1];   }   long long query(int s, int e, int ps = 0, int pe = (1 << n) - 1, int d = n - 1,                   int p = 1) {     if (e < ps || pe < s) return 0;     if (s <= ps && pe <= e) return a[p];     int pm = (ps + pe) / 2;     return query(s, e, ps, pm, d - 1, 2 * p + kek[d]) +            query(s, e, pm + 1, pe, d - 1, 2 * p + 1 - kek[d]);   }   int main() {     scanf( %d %d , &n, &q);     for (int i = 0; i < (1 << n); i++) {       int x;       scanf( %d , &x);       upd(i, x);     }     while (q--) {       int t;       scanf( %d , &t);       if (t == 1) {         int x, v;         scanf( %d %d , &x, &v);         x--;         upd(x, v);       }       if (t == 4) {         int s, e;         scanf( %d %d , &s, &e);         printf( %lld n , query(s - 1, e - 1));       }       if (t == 2) {         int x;         scanf( %d , &x);         for (int i = 0; i < x; i++) kek[i] ^= 1;       }       if (t == 3) {         int x;         scanf( %d , &x);         kek[x] ^= 1;       }     }   }
#include <bits/stdc++.h>   using namespace std;   struct event {     long long int peakval;     long long int pos;     long long int time1;   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n, m, d;     cin >> n >> m >> d;     struct event e1[m + 1];     e1[0].time1 = 0;     for (long long int i = 1; i <= m; i++) {       cin >> e1[i].pos >> e1[i].peakval >> e1[i].time1;     }     long long int dp[2][n + 1];     for (long long int i = 1; i <= n; i++) {       dp[0][i] = 0;     }     deque<pair<long long int, long long int> > dq1;     long long int delta, store;     for (long long int i = 1; i <= m; i++) {       delta = e1[i].time1 - (e1[i - 1].time1);       delta *= d;       for (long long int j = 1; j <= min(delta + 1, n); j++) {         while (!dq1.empty() && dp[0][j] >= dq1.back().first) {           dq1.pop_back();           if (dq1.empty()) {             break;           }         }         dq1.push_back({dp[0][j], j});       }       for (long long int j = 1; j <= n; j++) {         while (dq1.front().second < (j - delta)) {           dq1.pop_front();         }         store = e1[i].peakval - fabs(e1[i].pos - j);         dp[1][j] = dq1.front().first + store;         if ((j + delta + 1) <= n) {           while (dp[0][j + delta + 1] >= dq1.back().first) {             dq1.pop_back();             if (dq1.empty()) {               break;             }           }           dq1.push_back({dp[0][j + delta + 1], j + delta + 1});         }       }       for (long long int i = 1; i <= n; i++) {         dp[0][i] = dp[1][i];       }       dq1.clear();     }     long long int ans = -1000000000000000007;     for (long long int i = 1; i <= n; i++) {       ans = max(ans, dp[1][i]);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   class {    public:     int n, m;     vector<pair<int, int> > V[5555];     bool vis[5555], in[5555];     int ans[5555];     void solve() {       cin >> n >> m;       for (int i = 0; i < m; ++i) {         int u, v;         cin >> u >> v;         V[u].push_back({v, i});       }       for (int i = 1; i <= n; ++i) {         if (!vis[i]) dfs(i);       }       if (two)         cout << 2 <<   n ;       else         cout << 1 <<   n ;       for (int i = 0; i < m; ++i) {         cout << ans[i] + 1 <<    ;       }     }     bool two = 0;     void dfs(int u) {       in[u] = 1;       vis[u] = 1;       for (auto v : V[u]) {         if (!vis[v.first]) {           dfs(v.first);         } else if (in[v.first]) {           ans[v.second] = 1;           two = 1;         }       }       in[u] = 0;     }   } NSPACE;   int main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     NSPACE.solve();   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e9 + 7;   void solve() {     long long n, curr, val, ans = 0;     cin >> n >> curr;     vector<long long> a(n), cost(n);     for (long long i = 0; i < n; i++) cin >> a[i];     cin >> val;     for (long long i = 0; i < n; i++) cin >> cost[i];     multiset<long long> s;     for (long long i = 0; i < n; i++) {       s.insert(cost[i]);       if (curr < a[i]) {         long long x = (a[i] - curr + val - 1) / val;         if (x > s.size()) {           ans = -1;           break;         }         while (x--) {           ans += *s.begin();           curr += val;           s.erase(s.begin());         }       }     }     cout << ans;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n;   string s;   vector<long long int> ss;   inline bool check(long long int lim) {     long long int sum = 0, cnt = 0;     for (long long int i = 0; i < ss.size(); i++) {       if (sum + ss[i] <= lim) {         sum += ss[i];       } else {         cnt++;         sum = ss[i];       }     }     cnt++;     if (cnt <= n) return true;     return false;   }   int main() {     cin >> n;     cin.ignore();     getline(cin, s);     long long int pos = 0;     for (long long int i = 0; i < s.length(); i++) {       if (s[i] ==  -  || s[i] ==    ) {         ss.push_back(i - pos + 1);         pos = i + 1;       }     }     ss.push_back(s.length() - pos);     long long int low, high, mid;     high = s.length();     low = -1;     for (long long int i = 0; i < ss.size(); i++) low = max(low, ss[i]);     long long int ans = high;     while (low <= high) {       mid = (low + high) / 2;       if (check(mid)) {         high = mid - 1;         ans = min(ans, mid);       } else         low = mid + 1;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int podch[1100];   int newp[1100];   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k, x;     cin >> n >> k >> x;     for (int i = 0; i < n; i++) {       int tmp;       cin >> tmp;       podch[tmp]++;     }     for (int i = 0; i < k; i++) {       int countwas = 0;       for (int j = 0; j < 1100; j++) {         newp[j] = 0;       }       for (int j = 0; j < 1100; j++) {         int tmp = podch[j];         if (podch[j] % 2 != 0) {           if (countwas % 2 == 0) {             newp[(j ^ x)] += (podch[j] / 2 + 1);             newp[j] -= (podch[j] / 2 + 1);           } else {             newp[(j ^ x)] += (podch[j] / 2);             newp[j] -= (podch[j] / 2);           }         } else {           newp[(j ^ x)] += (podch[j] / 2);           newp[j] -= (podch[j] / 2);         }         countwas += tmp;       }       for (int j = 0; j < 1100; j++) {         podch[j] += newp[j];       }     }     int kek = 0;     for (int i = 0; i < 1100; i++) {       if (podch[i]) {         kek = i;         break;       }     }     int kek2 = 0;     for (int i = 0; i < 1100; i++) {       if (podch[i]) {         kek2 = i;       }     }     cout << kek2 <<     << kek << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long add(long long x, long long y, long long CMOD = MOD) {     return (x + y + CMOD + CMOD) % CMOD;   }   long long mult(long long x, long long y, long long CMOD = MOD) {     return add(x, 0) * add(y, 0) % CMOD;   }   long long fast_expo(long long x, long long y, long long CMOD = MOD) {     if (x == 0) return 0;     if (y == 0) return 1;     long long ans = fast_expo(x, y / 2, CMOD);     ans = mult(ans, ans, CMOD);     if (y & 1) ans = mult(ans, x, CMOD);     return ans;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long gen(long long x, long long y) {     if (x == y) return x;     return x + rng() % (y - x + 1);   }   const int TAM = 1e5 + 100;   const long long INF = LLONG_MAX / 4;   int n;   int main() {     priority_queue<long long, vector<long long>, greater<long long> > pq;     scanf( %d , &n);     if (n % 2 == 0) pq.push(0);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       pq.push(x);     }     long long ans = 0;     while (pq.size() > 1) {       long long x = 0;       for (int i = 0; i < 3; i++) {         x += pq.top();         pq.pop();       }       ans += x;       pq.push(x);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n];       int b[n];       vector<int> c;       for (int i = 0; i < n; i++) {         cin >> a[i];       }       for (int i = 0; i < n; i++) {         cin >> b[i];       }       for (int i = 0; i < n; i++) {         if (!b[i]) c.push_back(a[i]);       }       sort(c.rbegin(), c.rend());       int j = 0;       for (int i = 0; i < n; i++) {         if (b[i])           cout << a[i] <<    ;         else           cout << c[j++] <<    ;       }       cout <<   n ;     }     return 0;   }