malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   int n, br;   int p[MAXN], niz[MAXN], num[MAXN], bio[MAXN];   inline void ne() {     printf( NO n );     exit(0);   }   void dfs1(int x) {     if (bio[x]) return;     bio[x] = br;     num[br]++;     dfs1(niz[x]);   }   void dfs2(int x) {     if (bio[x]) return;     bio[x] = 1;     if (bio[niz[x]]) return;     printf( %d %d n , x, niz[x]);     dfs2(niz[x]);   }   void dfs3(int x, int y) {     if (bio[x]) return;     bio[x] = 1;     printf( %d %d n , x, y);     dfs3(niz[x], niz[y]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &p[i]);     for (int i = 1; i <= n; i++) niz[p[i]] = p[p[i]];     br = 1;     for (int i = 1; i <= n; i++)       if (!bio[i]) {         dfs1(i);         br++;       }     int poc = 0, val = MAXN, grupa = 0;     for (int i = 1; i <= n; i++)       if (num[bio[i]] < val) {         val = num[bio[i]];         poc = i;         grupa = bio[i];       }     if (num[grupa] > 2) ne();     for (int i = 1; i < br; i++)       if (num[i] % num[grupa] != 0) ne();     printf( YES n );     memset(bio, 0, sizeof(bio));     dfs2(poc);     for (int i = 1; i <= n; i++)       if (!bio[i]) dfs3(i, poc);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> primes;   void sieve() {     vector<bool> isComposite(100000000, false);     for (int i = 2; i * i <= 100000000; i++) {       if (isComposite[i] == false)         for (int j = i * 2; j <= 100000000; j += i) isComposite[j] = true;     }     for (int i = 2; i <= 100000000; i++)       if (isComposite[i] == false) primes.push_back(i);     for (auto it : primes) cout << it <<    ;   }   long long LCM(int n) {     long long lcm = 1;     for (int i = 0; i < primes.size() && primes[i] <= n; i++) {       int pp = primes[i];       while (pp * primes[i] <= n) pp = pp * primes[i];       lcm *= pp;       lcm %= 1000000007;     }     return lcm;   }   int main() {     int t;     cin >> t;     while (t--) {       long long int n;       string keyboard;       string s;       cin >> keyboard;       cin >> s;       map<char, int> mp;       for (int i = 0; i < keyboard.size(); i++) {         mp[keyboard[i]] = i + 1;       }       long long int time = 0;       for (int i = 1; i < s.length(); i++) {         time += abs((mp[s[i]] - mp[s[i - 1]]));       }       cout << time <<   n ;     }   }
#include<bits/stdc++.h>   using namespace std;   #define sfd(x) scanf( %d ,&x)   #define sfd2(x,y) scanf( %d%d ,&x,&y)   #define sfd3(x,y,z) scanf( %d%d%d ,&x,&y,&z)   #define sfs(x) scanf( %s ,x)   #define sfll(x) scanf( %lld ,&x)   #define sfll2(x,y) scanf( %lld%lld ,&x,&y)   #define pfd(x) printf( %d ,x)   #define pfs(x) printf( %s ,x)   #define pfll(x) printf( %lld ,x)   #define nl printf(  n )   #define sp printf(   )   #define pfyes printf( YES )   #define pfno printf( NO )   #define pf0 printf( 0 )   #define FOR(i,a,b,in) for(int i=a;i<=b;i+=in)   #define RFOR(i,a,b,de) for(int i=a;i>=b;i-=de)   #define rep(i,n) for(int i=0;i<n;i++)   #define pb push_back   #define mkp make_pair   #define mod 998244353   typedef long long int ll;   typedef vector<int> vi;   typedef pair<int,int> pii;   // ------------------------//   ll power(long long x, int y, int p)   {       ll res = 1;     x = x % p;       if (x == 0) return 0;      while (y > 0)       {           if (y & 1)               res = (res*x) % p;           y = y>>1;            x = (x*x) % p;       }       return res;   }   int main()   {    int t;    sfd(t);    while(t--)    {     int n;     sfd(n);     char s[n+1];     sfs(s);     int c0 = 0;     int c1 = 0;     int cx = 0;     rep(i,n)     {      if(s[i]== 1 )      {       cx+=1;      }      else      {       c1+=(cx/2);       cx=0;       c0+=1;      }     }     c1+=(cx/2);     ll v1=1,v2=1,v3=1;     for(int i=1;i<=c0;i++)     {      v1=(v1*i)%mod;     }     for(int i=1;i<=c1;i++)     {      v2=(v2*i)%mod;     }     for(int i=1;i<=c0+c1;i++)     {      v3=(v3*i)%mod;     }     v1=(v1*v2)%mod;     ll ans = (v3*power(v1,mod-2,mod))%mod;     pfll(ans);     nl;         }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int fen1[200002];   void upd1(int pos, int val) {     for (; pos <= 200000; pos |= (pos + 1)) fen1[pos] += val;   }   int fnd1(int pos) {     int ret = 0;     for (; pos >= 0; pos = (pos & (pos + 1)) - 1) ret += fen1[pos];     return ret;   }   int fen2[200002];   void upd2(int pos, int val) {     for (; pos >= 0; pos = (pos & (pos + 1)) - 1) fen2[pos] += val;   }   int fnd2(int pos) {     int ret = 0;     for (; pos <= 200000; pos |= (pos + 1)) ret += fen2[pos];     return ret;   }   int now[200002];   int main() {     int n, k, a, b, q;     scanf( %d%d%d%d%d , &n, &k, &a, &b, &q);     while (q--) {       int t;       scanf( %d , &t);       if (t == 1) {         int d, aa;         scanf( %d%d , &d, &aa);         --d;         int add = max(0, min(aa, b - now[d]));         upd1(d, add);         add = max(0, min(aa, a - now[d]));         upd2(d, add);         now[d] += aa;       } else {         int p;         scanf( %d , &p);         --p;         int ans = fnd1(p - 1) + fnd2(p + k);         printf( %d n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, m, k;       cin >> n >> m >> k;       k = n * m / 2 - k;       if (n % 2 == 1) {         swap(n, m);         k = n * m / 2 - k;       }       if (m % 2 == 1) {         if ((k >= n / 2 && (k - n / 2) % (2) == 0)) {           cout <<  YES  <<   n ;           continue;         } else {           cout <<  NO  <<   n ;           continue;         }       } else {         if (k % 2 == 0)           cout <<  YES  <<   n ;         else           cout <<  NO  <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   struct node {     long long num;     int p;   } nd[maxn];   long long sum[maxn], f[maxn];   bool cp1(node a, node b) { return a.num < b.num; }   int main() {     int n, k;     ios::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> nd[i].num;       nd[i].p = i;     }     sort(nd + 1, nd + 1 + n, cp1);     cin >> k;     sum[0] = 0;     for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + nd[i].num;     f[1] = 0;     for (int i = 2; i <= k; i++)       f[i] = nd[i].num * (i - 1) - sum[i - 1] + f[i - 1];     long long mm = f[k];     int p = 1;     for (int i = k + 1; i <= n; i++) {       f[i] = nd[i].num * (k - 1) + f[i - 1] + nd[i - k].num * (k - 1) -              2 * (sum[i - 1] - sum[i - k]);       if (f[i] < mm) {         mm = f[i];         p = i - k + 1;       }     }     for (int i = 0; i < k; i++)       printf( %d%c , nd[i + p].p, i == k - 1 ?   n  :    );   }
#include<bits/stdc++.h>   #define ll int   #define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);   using namespace std;   ll n, m, i, j, k = 0, t, w, flag, x, y, z, sum;   string s1, s2, s;   int main()   {       FAST_IO;       cin >> n >> m >> k;       ll h[n + 1][m], l[n][m + 1];       vector<vector<ll> >re ( n + 1, vector<ll> ( m + 1, 0 ) );       vector<vector<ll> >temp ( n + 1, vector<ll> ( m + 1, 0 ) );          for ( i = 1; i <= n; i++ )           for ( j = 1; j < m; j++ )               cin >> h[i][j];          for ( i = 1; i < n; i++ )           for ( j = 1; j <= m; j ++ )               cin >> l[i][j];          for ( t = 1; t <= k / 2; t++ )       {           for ( i = 1; i <= n; i++ )           {               for ( j = 1; j <= m; j++ )               {                   temp[i][j] = ( int ) 1e9;;                   if ( i != n )                       temp[i][j] = min ( temp[i][j], re[i + 1][j] + l[i][j] * 2 );                   if ( i != 1 )                       temp[i][j] = min ( temp[i][j], re[i - 1][j] + l[i - 1][j] * 2 );                   if ( j != m )                       temp[i][j] = min ( temp[i][j], re[i][j + 1] + h[i][j] * 2 );                   if ( j != 1 )                       temp[i][j] = min ( temp[i][j], re[i][j - 1] + h[i][j - 1] * 2 );               }           }           swap ( re, temp );       }       for ( i = 1; i <= n; cout << endl, i++ )           for ( j = 1; j <= m; j++ )           {               if ( j > 1 ) cout <<    ;               cout << ( k % 2 ? -1 : re[i][j] );           }      }
#include <bits/stdc++.h>   using namespace std;   // #include <atcoder/all>   // using namespace atcoder;      #define rep(i,n) for (int i = 0; i < (n); ++i)   #define STRING(str) #str   #define ll long long   #define ld long double      template <typename T>   void print(T x, string name) {    cout << name+ :   << x << endl;   }      template <typename T >   void print_vec_1d(vector<T> x, string name) {    cout << name << endl;    cout <<  [  ;    for (int i=0;i<x.size();i++) {     cout << x[i];     if (i != x.size()-1) cout <<  ,  ;     else cout <<   ]  << endl;    }   }      template <typename T >   void print_vec_2d(vector<vector<T>> x, string name) {    cout << name << endl;    cout <<  [  ;    for (int i=0;i<x.size();i++) {     cout <<  [  ;     for (int j=0;j<x[i].size();j++) {      cout << x[i][j];      if (j != x[i].size()-1) cout <<  ,  ;      else {       cout <<   ] ;       if (!((i == x.size()-1) && (j == x[i].size()-1))) {        cout <<  ,  << endl;       }      }     }    }    cout <<   ]  << endl;   }      template <typename T >   void print_vec_3d(vector<vector<vector<T>>> x, string name) {    cout << name << endl;    cout <<  [  ;    for (int i=0;i<x.size();i++) {     cout <<  [  ;     for (int j=0;j<x[i].size();j++) {      cout <<  [  ;      for (int k=0;k<x[i][j].size();k++) {       cout << x[i][j][k];       if (k != x[i][j].size()-1) cout <<  ,  ;       else {        cout <<   ] ;        if (!((i == x.size()-1) && (j == x[i].size()-1) && (k == x[i][j].size()-1))) {         cout <<  ,  << endl;        }       }      }      if (j != x[i].size()-1) cout <<  ,  ;      else {       cout <<   ] ;       if (!((i == x.size()-1) && (j == x[i].size()-1))) {        cout <<  ,  << endl;       }      }     }    }    cout <<   ]  << endl;   }      int main() {    // ios::sync_with_stdio(0);    // cin.tie(0);       int n;    cin >> n;    int ind_2;    cout <<  ? 1   << n <<   n ;    cin >> ind_2;    ind_2--;       int a1, a2;    if (ind_2 != 0 && ind_2 != n-1) {     cout <<  ? 1   << ind_2+1 <<   n ;     cin >> a1;     a1--;        int a2;     cout <<  ?   << ind_2+1 <<     << n <<   n ;     cin >> a2;     a2--;    }       bool left_flag;    if (ind_2 == n-1) {     left_flag = true;    } else if (ind_2 == 0) {     left_flag = false;    } else if (ind_2 == a1) {     left_flag = true;    } else { // ind_2 == a2     left_flag = false;    }    if (left_flag) {     // ? ? ? 1 ? ? ? 2 ? ? ? ?     int ok = 0;     int ng = ind_2;     while (abs(ok-ng) > 1) {      int mid = (ok+ng)/2;      int b;      cout <<  ?   << mid+1 <<     << ind_2+1 <<   n ;      cin >> b;      b--;      if (b == ind_2) {       ok = mid;      } else {       ng = mid;      }     }     cout <<  !   << ok+1 <<   n ;    } else {     // ? ? ? ? ? ? ? 2 ? 1 ? ?     int ok = n-1;     int ng = ind_2;     while (abs(ok-ng) > 1) {      int mid = (ok+ng)/2;      int b;      cout <<  ?   << ind_2+1 <<     << mid+1 <<   n ;      cin >> b;      b--;      if (b == ind_2) {       ok = mid;      } else {       ng = mid;      }     }     cout <<  !   << ok+1 <<   n ;    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INFint = 2147483647;   const long long INF = 9223372036854775807ll;   const long long MOD = 1000000007ll;   long long cnt[100000];   int main() {     ios_base::sync_with_stdio(0);     long long a;     cin >> a;     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) {       long long sum = 0;       for (int j = i; j < s.size(); j++) {         sum += s[j] -  0 ;         cnt[sum]++;       }     }     long long ans = 0;     if (a == 0) {       ans = cnt[0] * cnt[0];       for (int i = 1; i < 100000; i++) {         ans += cnt[0] * cnt[i] * 2;       }     } else {       for (int i = 1; i < 100000; i++) {         if (i <= a) {           if (a % i == 0 && a / i < 100000) ans += cnt[i] * cnt[a / i];         } else           break;       }     }     cout << ans << endl;     fprintf(stderr,   nTIME = %lf n , 1.0 * clock() / CLOCKS_PER_SEC);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void debug(T a, T b) {     ;   }   template <class T>   void chmin(T& a, const T& b) {     if (a > b) a = b;   }   template <class T>   void chmax(T& a, const T& b) {     if (a < b) a = b;   }   namespace std {   template <class S, class T>   ostream& operator<<(ostream& out, const pair<S, T>& a) {     out <<  (  << a.first <<  ,  << a.second <<  ) ;     return out;   }   }  // namespace std   long long int readL() {     long long int res;     scanf( %I64d , &res);     return res;   }   void printL(long long int res) { printf( %I64d , res); }   const int INF = 5e8;   int n, m;   vector<int> g[100005];   pair<int, int> mst2[100005];   pair<int, int> es[100005];   int idx[100005], rev[100005];   vector<int> g2[100005];   int res[100005];   bool cut[100005];   int size[100005], whole;   int gsize(int v, int p) {     size[v] = 1;     for (auto to : g2[v]) {       if (cut[to] || to == p) continue;       size[v] += gsize(to, v);     }     return size[v];   }   int root, cost;   void groot(int v, int p) {     int C = whole - size[v];     for (auto to : g2[v]) {       if (cut[to] || to == p) continue;       groot(to, v);       chmax(C, size[to]);     }     if (cost > C) {       cost = C;       root = v;     }   }   void dfs(int v, int rank) {     whole = gsize(v, -1);     cost = INF;     groot(v, -1);     v = root;     res[v] = rank;     if (whole == 1) return;     cut[v] = 1;     for (auto to : g2[v]) {       if (cut[to]) continue;       dfs(to, rank + 1);     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < (m); ++i) {       int a, b;       scanf( %d%d , &a, &b);       --a;       --b;       if (a > b) swap(a, b);       es[i] = {a, b};     }     es[m++] = {0, n - 1};     sort(es, es + m, [&](pair<int, int> a, pair<int, int> b) {       return a.second - a.first < b.second - b.first;     });     set<pair<pair<int, int>, int> > range;     int cnt = 0;     for (int i = 0; i < (m); ++i) {       int a = es[i].first, b = es[i].second;       auto it = range.lower_bound({{a, -1}, -1});       pair<int, int> last = {-1, -1};       while (it != range.end() && it->first.second <= b) {         last = it->first;         g[cnt].push_back(it->second);         g[it->second].push_back(cnt);         range.erase(it++);       }       if (last.second == b)         mst2[cnt] = {last.first, b};       else         mst2[cnt] = {b - 1, b};       range.insert({{a, b}, cnt});       ++cnt;     }     for (int i = 0; i < (cnt); ++i)       if (mst2[i].second > mst2[i].first) swap(mst2[i].first, mst2[i].second);     for (int i = 0; i < (cnt); ++i) idx[i] = i;     sort(idx, idx + cnt, [&](int a, int b) { return mst2[a] < mst2[b]; });     for (int i = 0; i < (cnt); ++i) rev[idx[i]] = i;     for (int i = 0; i < (cnt); ++i)       for (auto to : g[i]) g2[rev[i]].push_back(rev[to]);     dfs(0, 0);     for (int i = 0; i < (cnt); ++i) printf( %d n , res[i] + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   double p[110], S = 0, P = 1, ans;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lf , &p[i]);     sort(p + 1, p + n + 1);     for (int i = n; i >= 1; i--)       if (1.0 - S >= 1e-12) {         ans += P * p[i] * (1 - S);         S += p[i] / (1.0 - p[i]);         P *= (1.0 - p[i]);       }     printf( %.12lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int x[N], p[N], n, d, ind[N];   long long ans = 0;   vector<pair<int, int> > tank;   int head, cur;   bool cmp(int a, int b) { return x[a] < x[b]; }   bool use(int dis) {     while (dis) {       if (head == (int)tank.size()) return 1;       int tmp = min(dis, tank[head].first);       dis -= tmp;       tank[head].first -= tmp;       cur -= tmp;       if (tank[head].first == 0) head++;     }     return 0;   }   void sale(int p) {     while ((int)tank.size() > head && tank.back().second > p) {       ans -= 1LL * tank.back().second * tank.back().first;       cur -= tank.back().first;       tank.pop_back();     }   }   void buy(int p) {     ans += 1LL * p * (n - cur);     tank.push_back(make_pair(n - cur, p));     cur = n;   }   int main() {     int m;     scanf( %d%d%d , &d, &n, &m);     for (int i = 1; i <= m; ++i) scanf( %d%d , &x[i], &p[i]), ind[i] = i;     x[m + 1] = d;     p[m + 1] = 0;     ind[m + 1] = m + 1;     sort(ind + 1, ind + 1 + m, cmp);     tank.push_back(make_pair(n, 0));     cur = n;     for (int i = 1; i <= m + 1; ++i) {       int dis = x[ind[i]] - x[ind[i - 1]];       if (use(dis)) return 0 * puts( -1 );       sale(p[ind[i]]);       buy(p[ind[i]]);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e5 + 1, INF = 1e17, MOD = 1e9 + 7;   long long n;   string s, t =  UDRL ;   map<char, long long> m;   int32_t main() {     ios_base::sync_with_stdio(0);     cin >> n >> s;     for (long long i = 0; i < n; ++i) {       m[s[i]]++;     }     cout << 2 * (min(m[t[0]], m[t[1]]) + min(m[t[2]], m[t[3]])) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char buffer[100000], *p1, *p2;   template <class T>   void read(T& x) {     char ch = ((p1 == p2 &&                 (p2 = (p1 = buffer) + fread(buffer, 1, 100000, stdin), p1 == p2))                    ? EOF                    : *p1++);     x = 0;     bool f = 1;     while (!( 0  <= ch && ch <=  9 ) && ch !=  - )       ch = ((p1 == p2 &&              (p2 = (p1 = buffer) + fread(buffer, 1, 100000, stdin), p1 == p2))                 ? EOF                 : *p1++);     if (ch ==  - )       f = 0,       ch = ((p1 == p2 &&              (p2 = (p1 = buffer) + fread(buffer, 1, 100000, stdin), p1 == p2))                 ? EOF                 : *p1++);     while ( 0  <= ch && ch <=  9 )       x = (x << 1) + (x << 3) + ch -  0 ,       ch = ((p1 == p2 &&              (p2 = (p1 = buffer) + fread(buffer, 1, 100000, stdin), p1 == p2))                 ? EOF                 : *p1++);     x = (f) ? x : -x;   }   int n, m;   int a[605];   bool vis[605][605];   int dp[605][605];   int DP(int l, int r) {     if (l >= r) return 1;     if (vis[l][r]) return dp[l][r];     vis[l][r] = 1;     int& ans = dp[l][r];     int mi = n + 1, mip = -1;     for (register int i = l; i <= r; i++)       if (mi > a[i]) mi = a[i], mip = i;     int le = 0, ri = 0;     for (register int i = l - 1; i < mip; i++)       le += (long long int)DP(l, i) * DP(i + 1, mip - 1) % 998244353,           le %= 998244353;     for (register int i = r + 1; i > mip; i--)       ri += (long long int)DP(i, r) * DP(mip + 1, i - 1) % 998244353,           ri %= 998244353;     return ans = (long long int)le * ri % 998244353;   }   int main() {     read(n), read(m);     for (register int i = 1; i <= n; i++) read(a[i]);     printf( %d , DP(1, n));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const int N = 1000000 + 10;   const int M = 1000;   const string st2 =  ABCDEFGHIJKLMNOPQRSTUVWXYZ ;   const string s1 =  abcdefghijklmnopqrstuvwxyz ;   pair<int, int> a[N];   int b[N];   string ans[N], da[N];   int main() {     cin >> b[1] >> b[2] >> b[3] >> b[4] >> b[5] >> b[6];     int n;     cin >> n;     da[1] =  S ;     da[2] =  M ;     da[3] =  L ;     da[4] =  XL ;     da[5] =  XXL ;     da[6] =  XXXL ;     for (int i = 1; i <= n; i++) {       string second;       cin >> second;       if (second ==  S )         a[i] = make_pair(1, 0);       else if (second ==  M )         a[i] = make_pair(2, 0);       else if (second ==  L )         a[i] = make_pair(3, 0);       else if (second ==  XL )         a[i] = make_pair(4, 0);       else if (second ==  XXL )         a[i] = make_pair(5, 0);       else if (second ==  XXXL )         a[i] = make_pair(6, 0);       else if (second[0] ==  S )         a[i] = make_pair(1, 1);       else if (second[0] ==  M )         a[i] = make_pair(2, 1);       else if (second[0] ==  L )         a[i] = make_pair(3, 1);       else if (second[1] ==  L )         a[i] = make_pair(4, 1);       else if (second[2] ==  L )         a[i] = make_pair(5, 1);       else         a[i] = make_pair(6, 1);     }     for (int i = 1; i <= n; i++)       if (a[i].second == 0) {         if (b[a[i].first] != 0) {           ans[i] = da[a[i].first];           b[a[i].first]--;         }       }     for (int i = 1; i <= 6; i++) {       for (int j = 1; j <= n; j++)         if (ans[j] ==    && a[j].second == 1) {           if (a[j].first + 1 == i && b[i] > 0) {             b[i]--;             ans[j] = da[i];           }         }       for (int j = 1; j <= n; j++)         if (ans[j] ==    && a[j].second == 1) {           if (a[j].first == i && b[i] > 0) {             b[i]--;             ans[j] = da[i];           }         }     }     for (int i = 1; i <= n; i++)       if (ans[i] ==   ) {         cout <<  NO  << endl;         return 0;       }     cout <<  YES  << endl;     for (int i = 1; i <= n; i++) cout << ans[i] << endl;   }
#include<bits/stdc++.h>   using namespace std;   typedef unsigned long long int ull;   typedef long long int ll;   typedef long double ld;   #define fr(i,a,b) for(ll i=a; i<b; i++)   #define rf(i,a,b) for(ll i=a; i>=b; i--)   #define pb push_back   #define mp make_pair   #define show(a) for(auto el:a)cout<<el<<      #define ff first   #define ss second   #define pairv vector<pair<ll,ll>>   #define vec vector <ll>    #define all(a) a.begin(),a.end()   #define fam(v,i) for(auto i=v.begin();i!=v.end();i++)   #define fai(v,i) for(auto i : v)   #define mo 1000000007   #define nn cout<<  n ;   #define Y cout<< YES n ;   #define N cout<< NO n ;   #define cout_dec cout << fixed << setprecision(9)    #define casepr(ti)  cout<< case # <<ti+1<< :     #define fill(a,b) memset(a, b, sizeof(a))   ll pow1(ll n,ll p)   {   if(p==0) return 1;    ll x=pow1(n, p/2);   x=(x*x)%mo;   if(p%2==0)   return x;   else   return (x*n)%mo;   }   bool sortbysec(const pair<ll,ll> &a,    const pair<ll,ll> &b)    {    return (a.second < b.second);    }    bool compare(const pair<ll, ll>&p1, const pair<ll,ll>&p2)   {   if(p1.ff < p2.ff) return true;   if(p1.ff == p2.ff) return p1.ff < p2.ss;   return false;   }   ll const maxn=200007;   ll nxt[maxn];   void seive()   {         for (ll i = 2; i < maxn; ++i) {           if (nxt[i] == 0) {               nxt[i] = i;               for (ll j = i * i; j < maxn; j += i) {                   if(j>=maxn)                   {                       break;                   }                   if (nxt[j] == 0) nxt[j] = i;               }           }       }   }   int main()   {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);          int test=1;       cin>>test;       for(int ti=0;ti<test;ti++)       {           ll i,j,k,e,f,n,c=0,x=0;           cin>>n;           ll m=n+2;           ll b[n+2];           fr(i,0,n+2)           cin>>b[i];           sort(b,b+m);           fr(i,0,n)           {               c=c+b[i];           }           if(c== b[n] || c==b[n+1])           {               fr(i,0,n)               {                   cout<<b[i]<<   ;                  }                               nn                   continue;           }           x=-1;           fr(i,0,n)           {               if(c-b[i]+b[n]==b[n+1])               {                   x=i;                   break;               }           }           if(x==-1)           {               cout<<-1;                          }           else           {               fr(i,0,n+1)               {                   if(i==x)                   {                       continue;                   }                   cout<<b[i]<<   ;               }           }                                        nn                  }               return 0;   }