malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long a[n], b[n];       for (long long i = 0; i < n; i++) cin >> a[i];       for (long long i = 0; i < n; i++) cin >> b[i];       sort(a, a + n);       sort(b, b + n);       for (long long i = 0; i < n; i++) {         cout << a[i] <<    ;       }       cout << endl;       for (long long i = 0; i < n; i++) cout << b[i] <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, x, y;   long long c;   string s;   long long ans = 1e16;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> x >> y;     cin >> s;     s =  1  + s;     for (long long i = 1; i <= n; i++)       if (s[i] ==  0  and s[i - 1] ==  1 ) c++;     for (long long i = 0; i < c; i++) ans = min(ans, i * x + (c - i) * y);     if (c == 0) ans = 0;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma )   #pragma GCC optimize( unroll-loops )   using namespace std;   const long long N = 2005, inf = 1e15;   long long dp[N][N], suffix1[N][26], suffix2[N][26];   long long n;   string s, t;   long long dpsolve(long long i, long long j) {     if (j == 0) {       return 0;     }     if (dp[i][j] != -1) return dp[i][j];     long long ans = inf;     if (i > 0) {       ans = min(ans, 1 + dpsolve(i - 1, j));       if (s[i] == t[j]) ans = min(ans, dpsolve(i - 1, j - 1));     }     if (suffix1[i + 1][t[j] -  a ] >= suffix2[j][t[j] -  a ])       ans = min(ans, dpsolve(i, j - 1));     dp[i][j] = ans;     return ans;   }   void solve() {     cin >> n;     cin >> s;     cin >> t;     s =     + s;     t =     + t;     for (long long i = n; i >= 1; i--) {       for (long long j = 0; j < 26; j++) {         suffix1[n + 1][j] = suffix2[n + 1][j] = 0;         suffix1[i][j] = (s[i] -  a  == j) + suffix1[i + 1][j];         suffix2[i][j] = (t[i] -  a  == j) + suffix2[i + 1][j];       }     }     for (long long i = 0; i <= n; i++)       for (long long j = 0; j <= n; j++) dp[i][j] = -1;     bool flag = true;     for (long long j = 0; j < 26; j++)       if (suffix1[1][j] != suffix2[1][j]) flag = false;     if (!flag)       cout <<  -1 n ;     else {       long long ans = dpsolve(n, n);       cout << ans <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 105;   bool dmy[MAXN][MAXN][MAXN];   void dfs(int d, int m, int y, int bd, int bm, int by) {     if (dmy[bd][bm][by]) return;     dmy[bd][bm][by] = true;     if (bm > 12) return;     if (bd > 31) return;     if (!(by % 4) && bm == 2 && bd > 29) return;     if ((by % 4) && bm == 2 && bd >= 29) return;     if (y - by == 18) {       if (bm < m) {         puts( YES );         exit(0);       } else {         if (bm == m && bd <= d) {           puts( YES );           exit(0);         }       }     }     if (y - by > 18) {       puts( YES );       exit(0);     }     dfs(d, m, y, by, bd, bm);     dfs(d, m, y, bm, by, bd);     dfs(d, m, y, bd, by, bm);     dfs(d, m, y, by, bm, bd);     dfs(d, m, y, bm, bd, by);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int d, m, y, bd, bm, by;     string s;     cin >> s;     d = (s[0] -  0 ) * 10 + (s[1] -  0 );     m = (s[3] -  0 ) * 10 + (s[4] -  0 );     y = (s[6] -  0 ) * 10 + (s[7] -  0 );     cin >> s;     bd = (s[0] -  0 ) * 10 + (s[1] -  0 );     bm = (s[3] -  0 ) * 10 + (s[4] -  0 );     by = (s[6] -  0 ) * 10 + (s[7] -  0 );     dfs(d, m, y, by, bd, bm);     dfs(d, m, y, bm, by, bd);     dfs(d, m, y, bd, by, bm);     dfs(d, m, y, by, bm, bd);     dfs(d, m, y, bm, bd, by);     dfs(d, m, y, bd, bm, by);     puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   long long n, sum, arr[N], cnt;   int main() {     scanf( %lld , &n);     for (int i = 0; i < n; ++i) {       scanf( %lld , &arr[i]);       sum += arr[i];     }     sort(arr, arr + n);     for (int i = 0; i < n - 1; ++i) {       if (arr[i] == arr[i + 1]) {         cnt++;         if (i && arr[i - 1] == arr[i] - 1) return puts( cslnb ), 0;         if (cnt > 1) return puts( cslnb ), 0;         if (arr[i] == 0) return puts( cslnb ), 0;       }     }     sum -= n * (n - 1) / 2;     if (sum & 1)       puts( sjfnb );     else       puts( cslnb );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     scanf( %d%d%d , &a, &b, &c);     if (a > b) swap(a, b);     if (b - a >= c) {       printf( %d n , (a + c) * 2);       return 0;     }     if (b - a < c) {       c -= b - a;       printf( %d n , b * 2 + (c / 2) * 2);       return 0;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[200050];   int b[200050];   int c[200050];   int now[200050];   int tot[200050];   int ans[200050];   int n, m, cnt, p;   int main() {     int i, j;     while (scanf( %d %d %d , &n, &m, &p) != EOF) {       for (i = 0; i < n; i++) scanf( %d , a + i);       for (i = 0; i < m; i++) scanf( %d , b + i);       if (1 + (long long)p * (m - 1) > n) {         printf( 0 n );         continue;       }       sort(b, b + m);       for (i = 0; i < m; i++) c[i] = b[i];       int sz = unique(c, c + m) - c;       for (i = 0; i < sz; i++) {         tot[i] = upper_bound(b, b + m, c[i]) - lower_bound(b, b + m, c[i]);       }       cnt = 0;       for (i = 0; i < p; i++) {         memset(now, 0, sizeof(now));         int l, r;         l = i;         r = i - p;         while (r < n) {           r += p;           if (r >= n) continue;           int k = lower_bound(c, c + sz, a[r]) - c;           if (a[r] != c[k]) {             while (l != r) {               int kk = lower_bound(c, c + sz, a[l]) - c;               now[kk] = 0;               l += p;             }             l += p;             continue;           }           now[k]++;           if (now[k] > tot[k]) {             while (now[k] > tot[k]) {               int kk = lower_bound(c, c + sz, a[l]) - c;               now[kk]--;               l += p;             }           }           if ((r - l) / p + 1 == m) {             ans[cnt++] = l;             int kk = lower_bound(c, c + sz, a[l]) - c;             now[kk]--;             l += p;           }         }       }       printf( %d n , cnt);       if (cnt) {         sort(ans, ans + cnt);         printf( %d , ans[0] + 1);         for (i = 1; i < cnt; i++) printf(  %d , ans[i] + 1);         printf(  n );       }     }     return 0;   }
#include <bits/stdc++.h>   const int Maxn = 500010;   using namespace std;   multiset<long long> S;   int n, m;   long long t[Maxn];   void add(int pos, int x) {     for (; pos <= m; pos += pos & -pos) {       t[pos] += x;     }   }   long long query(int pos) {     long long ans = 0;     for (; pos; pos ^= pos & -pos) ans += t[pos];     return ans;   }   char c[Maxn];   int num[Maxn], b[Maxn];   int Get_ans() {     if (S.size() == 0) return 0;     multiset<long long>::iterator x = S.begin(), y;     int cnt = 0;     while (x != S.end()) {       int pos = lower_bound(b + 1, b + m + 1, *x) - b;       if (x != S.begin()) {         long long sum = query(pos - 1);         if (sum * 2 < *x) cnt++;       }       long long sum = query(pos);       x = S.upper_bound(sum * 2);       if (x == S.end()) break;     }     return S.size() - cnt - 1;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       cin >> c[i] >> num[i];       b[i] = num[i];     }     sort(b + 1, b + n + 1);     m = unique(b + 1, b + n + 1) - b - 1;     for (int i = 1; i <= n; i++) {       int w = lower_bound(b + 1, b + m + 1, num[i]) - b;       if (c[i] ==  + ) {         S.insert(num[i]);         add(w, num[i]);         printf( %d n , Get_ans());       } else {         multiset<long long>::iterator ite = S.find(num[i]);         S.erase(ite);         add(w, -num[i]);         printf( %d n , Get_ans());       }     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> vec, ves;   int main() {     int n, m, f = 0, w = 0;     bool p = false, t = false;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> m;       if (m == 0) t = true;       for (int j = 0; j < vec.size(); j++) {         p = false;         if (m == vec[j]) {           ves[j]++;           p = true;           break;         }       }       if (p == false) {         vec.push_back(m);         ves.push_back(1);       }     }     for (int i = 0; i < vec.size(); i++) {       if (vec[i] != 0 && ves[i] > 2) {         cout << -1;         return 0;       } else if (ves[i] == 2 && vec[i] != 0)         w++;     }     cout << w;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> q[200010], g[200010];   int n, m, a[200010], b[200010];   unsigned long long A, B, C, ans;   unsigned long long calc(unsigned long long a, unsigned long long b,                           unsigned long long c) {     unsigned long long s[3] = {a, b, c};     sort(s, s + 3);     return s[0] * A + s[1] * B + s[2] * C;   }   int main() {     scanf( %d%d , &n, &m);     scanf( %lld%lld%lld , &A, &B, &C);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &a[i], &b[i]);       if (a[i] > b[i]) swap(a[i], b[i]);       q[a[i]].push_back(b[i]), q[b[i]].push_back(a[i]);     }     for (int i = 0; i < n; i++) {       ans += (unsigned long long)i * A *              ((unsigned long long)(n - i - 1) * (n - i - 2) / 2LL);       ans += (unsigned long long)i * B * ((unsigned long long)(i) * (n - i - 1));       ans +=           (unsigned long long)i * C * ((unsigned long long)(i) * (i - 1) / 2LL);     }     for (int i = 1; i <= m; i++) {       ans -= (unsigned long long)a[i] * a[i] * B +              (unsigned long long)a[i] * b[i] * C +              (unsigned long long)a[i] * (a[i] - 1) / 2LL * A;       ans -= (unsigned long long)(b[i] - a[i] - 1) * a[i] * A +              (unsigned long long)(b[i] - a[i] - 1) * b[i] * C +              (unsigned long long)(b[i] - a[i] - 1) * (a[i] + b[i]) / 2LL * B;       ans -= (unsigned long long)(n - b[i] - 1) * a[i] * A +              (unsigned long long)(n - b[i] - 1) * b[i] * B +              (unsigned long long)(n - b[i] - 1) * (n + b[i]) / 2LL * C;     }     for (int i = 0; i < n; i++) sort(q[i].begin(), q[i].end());     for (int i = 0; i < n; i++) {       unsigned long long pre = 0, pre_tot = 0;       for (int j = 0; j < q[i].size(); j++) {         int to = q[i][j];         if (to > i) continue;         ans += pre_tot * i * C + pre * A + to * pre_tot * B;         pre += to;         pre_tot++;       }       unsigned long long nex = 0, nex_tot = 0;       for (int j = 0; j < q[i].size(); j++) {         int to = q[i][j];         if (to < i) continue;         ans += nex_tot * i * A + nex * B + to * nex_tot * C;         nex += to;         nex_tot++;       }       ans += pre_tot * nex_tot * i * B + pre_tot * nex * C + nex_tot * pre * A;     }     for (int i = 1; i <= m; i++) {       if (q[a[i]].size() < q[b[i]].size())         g[a[i]].push_back(b[i]);       else         g[b[i]].push_back(a[i]);     }     for (int i = 0; i < n; i++) sort(g[i].begin(), g[i].end());     for (int i = 1; i <= m; i++) {       int t1 = 0, t2 = 0;       while (t1 < g[a[i]].size() && t2 < g[b[i]].size()) {         if (g[a[i]][t1] < g[b[i]][t2])           t1++;         else if (g[a[i]][t1] > g[b[i]][t2])           t2++;         else {           ans -= calc(a[i], b[i], g[a[i]][t1]);           t1++, t2++;         }       }     }     printf( %llu n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, a[100005];   int main() {     ;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     if (a[n - 1] == 1)       a[n - 1] = 2;     else       a[n - 1] = 1;     sort(a, a + n);     for (int i = 0; i < n; i++) cout << a[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2010;   int n;   string s;   int a[N], tot, vis[N];   bitset<N> d, ba[N], sel[N];   void Trans(string s) {     reverse(s.begin(), s.end());     while (s.size() % 8) s +=  0 ;     int L = s.size() / 8;     for (int i = 0; i < L; i++) {       a[i] = 0;       for (int j = 7; ~j; j--) a[i] = a[i] * 10 + s[i * 8 + j] -  0 ;     }     long long S = 0;     tot = 0;     while (L) {       S = 0;       for (int i = L - 1; ~i; i--) {         S = S * 100000000LL + a[i];         a[i] = S >> 32;         S %= (1LL << 32);       }       for (int i = 0; i < 32; i++) d[tot++] = ((S >> i) & 1);       while (L && a[L - 1] == 0) --L;     }   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s;       Trans(s);       bitset<N> ns;       int flg = 1;       for (int j = tot - 1; ~j; j--)         if (d[j])           if (vis[j]) {             d ^= ba[j];             ns ^= sel[j];           } else {             flg = 0;             ns.flip(i);             ba[j] = d;             sel[j] = ns;             vis[j] = 1;             break;           }       if (!flg) {         cout << 0 << endl;         continue;       } else {         cout << ns.count() <<    ;         for (int i = 0; i < N; i++)           if (ns[i]) cout << i <<    ;         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const long long mod = 1000000007;   const int N = 201000;   int n, y[N];   double k;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &y[i]);     int b = -1;     for (int i = 2; i < n; ++i)       if ((long long)(y[i] - y[0]) * (i - 1) != (long long)(y[i] - y[1]) * i) {         b = i;         break;       }     if (~b) {       bool ans = 0, tans = 1;       for (int i = 2; i < n; ++i)         if (i != b) {           bool t =               (long long)(y[i] - y[0]) * (i - 1) != (long long)(y[i] - y[1]) * i;           bool s = (long long)(y[i] - y[b]) != (long long)(y[1] - y[0]) * (i - b);           if (s && t) {             tans = 0;             break;           }         }       ans |= tans;       tans = 1;       for (int i = 2; i < n; ++i)         if (i != b) {           bool t =               (long long)(y[i] - y[0]) * (i - b) != (long long)(y[i] - y[b]) * i;           bool s =               (long long)(y[i] - y[1]) * b != (long long)(y[b] - y[0]) * (i - 1);           if (s && t) {             tans = 0;             break;           }         }       ans |= tans;       tans = 1;       for (int i = 2; i < n; ++i)         if (i != b) {           bool t = (long long)(y[i] - y[1]) * (i - b) !=                    (long long)(y[i] - y[b]) * (i - 1);           bool s =               (long long)(y[i] - y[0]) * (b - 1) != (long long)(y[b] - y[1]) * i;           if (s && t) {             tans = 0;             break;           }         }       ans |= tans;       puts(ans ?  Yes  :  No );     } else {       puts( No );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <typename T>   inline T lowbit(T x) {     return x & -x;   }   template <typename S, typename T>   void debug(S s, T t) {     cerr << s <<   ==   << t <<   n ;   }   template <typename T>   void debug(T t) {     cerr << t <<   n ;   }   template <typename T>   void debug(T t[], long long st, long long ed) {     for (long long i = st; i <= ed; ++i) {       cerr << t[i] <<    ;     }     cerr <<   n ;   }   template <typename T>   void debug(const vector<T>& t) {     for (long long i = 0; i < t.size(); ++i) cerr << t[i] <<    ;     cerr <<   n ;   }   const long long N = 2e5 + 10;   void solve() {     long long x, y;     cin >> x >> y;     if (y < x)       cout << x + y <<   n ;     else if (x == y)       cout << x <<   n ;     else       cout << y - (y % x) / 2 <<   n ;   }   signed main() {     long long _;     cin >> _;     while (_--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[100005], tmp[100005], b[100005];   bool die[100005];   int n, m;   vector<long long> candidate;   bool solve(int pos) {     candidate.clear();     for (int i = 1; i <= n; i++)       if ((!die[i]) && (a[i] & (1ll << pos))) {         candidate.push_back(a[i]);         die[i] = true;       }     for (int i = 1; i <= m; i++) tmp[i] = b[i];     int len_tmp = m;     int cur = 1;     m = 0;     for (int i = 0; i < candidate.size(); i++) {       b[++m] = candidate[i];       while (cur <= len_tmp && !(tmp[cur] & (1ll << pos))) {         b[++m] = tmp[cur];         cur++;       }       if (cur > len_tmp && i != candidate.size() - 1) return false;       b[++m] = tmp[cur];       cur++;     }     while (cur <= len_tmp) {       b[++m] = tmp[cur];       cur++;     }     return true;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 59; i >= 0; i--)       if (!solve(i)) {         printf( No );         return 0;       }     cout <<  Yes n ;     for (int i = 1; i <= n; i++) cout << b[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int st, en;   } TV[200010];   bool cmp(node a, node b) {     if (a.st == b.st) {       return a.en < b.en;     }     return a.st < b.st;   }   int main() {     int n;     int tv1, tv2;     int flag;     cin >> n;     tv1 = -1;     tv2 = -1;     flag = 1;     for (int i = 0; i < n; i++) {       cin >> TV[i].st >> TV[i].en;     }     sort(TV, TV + n, cmp);     for (int i = 0; i < n && flag; i++) {       if (tv1 < TV[i].st) {         tv1 = TV[i].en;       } else {         if (tv2 < TV[i].st) {           tv2 = TV[i].en;         } else {           flag = 0;         }       }     }     if (flag) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }
#include<bits/stdc++.h>   using namespace std;   const int Maxn=2021;   const int Mod=998244353;   int C[Maxn<<1|5][Maxn<<1|5];   int w[Maxn+5][Maxn+5];   int sum[Maxn+5][Maxn+5];   int ans;   void init(){    C[0][0]=1;    for(int i=1;i<=(Maxn<<1);i++){     C[i][0]=C[i][i]=1;     for(int j=1;j<i;j++){      C[i][j]=(C[i-1][j]+C[i-1][j-1])%Mod;     }    }   }   void solve(int n,int m,int k){    for(int i=1;i<=n;i++){     for(int j=1;j<=m;j++){      int t_1=C[i-1+m-j][m-j],t_2=C[i+j-1][j-1];      w[i][j]=1ll*t_1*t_2%Mod;      sum[i][j]=(sum[i][j-1]+w[i][j])%Mod;     }    }    for(int i=1;i<n;i++){     for(int j=1;j<m;j++){      ans=(ans+1ll*w[i][j]*sum[n-i][m-j])%Mod;      if(k==1){       ans=(ans-1ll*w[i][j]*w[n-i][m-j]%Mod+Mod)%Mod;      }     }    }   }   int main(){    init();    int n,m;    scanf( %d%d ,&n,&m);    solve(n,m,1);    solve(m,n,0);    ans=(ans<<1)%Mod;    printf( %d n ,ans);    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N_ = 1050;   int N;   int P[N_];   char S[N_];   int group[N_];   int find_group(int x) {     if (x == group[x]) return x;     return group[x] = find_group(group[x]);   }   void merge_group(int a, int b) {     a = find_group(a);     b = find_group(b);     if (a != b) group[a] = b;   }   vector<int> pos[N_];   int cnt[N_];   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) group[i] = i;     for (int i = 1; i <= N; i++) scanf( %d , &P[i]);     for (int i = 1; i <= N; i++) {       scanf( %s , S + 1);       for (int j = 1; j <= N; j++)         if (S[j] ==  1 ) merge_group(i, j);     }     for (int i = 1; i <= N; i++) pos[find_group(i)].push_back(P[i]);     for (int i = 1; i <= N; i++) sort(pos[i].begin(), pos[i].end());     for (int i = 1; i <= N; i++) {       int g = find_group(i);       printf( %d%c , pos[g][cnt[g]++], (i == N) ?   n  :    );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int a, b, c, d, n, i, cnt = 0, snt = 0;   float f, flo, fload = 0;   string s, h, o, name;   int main() {     ios_base::sync_with_stdio(0);     setlocale(LC_ALL,  Russian );     ;     string t;     size_t i;     getline(cin, t,   n );     while ((i = t.find(   )) != string::npos) t.erase(i, 1);     s = t;     reverse(s.begin(), s.end());     for (int i = 0; i < s.size(); i++) s[i] = tolower(s[i]);     for (int i = 0; i < s.size(); i++) {       if (s[i] >= 65 and s[i] <= 122) {         if (s[i] ==  a  or s[i] ==  e  or s[i] ==  u  or s[i] ==  i  or             s[i] ==  y  or s[i] ==  o ) {           cout <<  YES ;           ;           return 0;           ;         } else {           cout <<  NO ;           ;           return 0;           ;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = int(3e5) + 5, inf = int(1e9) + 5;   int H[maxn], sz[maxn], start[maxn], en[maxn], res[maxn];   pair<int, int> st[4 * maxn];   vector<pair<pair<int, int>, int>> Q;   vector<int> dis, graph[maxn];   inline int left(int node) { return (node << 1); }   inline int right(int node) { return (node << 1) + 1; }   void upd(int node, int L, int R, int idx, pair<int, int> v) {     if (L == R) {       st[node] = v;     } else {       if (idx <= (L + R) / 2)         upd(left(node), L, (L + R) / 2, idx, v);       else         upd(right(node), (L + R) / 2 + 1, R, idx, v);       st[node] = max(st[left(node)], st[right(node)]);     }   }   pair<int, int> qry(int node, int L, int R, int a, int b) {     if (a > R || b < L)       return {-inf, -inf};     else if (a <= L && R <= b)       return st[node];     else       return max(qry(left(node), L, (L + R) / 2, a, b),                  qry(right(node), (L + R) / 2 + 1, R, a, b));   }   void dfs(int node, int ht) {     sz[node] = 1, H[node] = ht;     start[node] = int(dis.size());     dis.push_back(node);     for (auto it : graph[node]) {       dfs(it, ht + 1);       sz[node] += sz[it];     }     en[node] = int(dis.size()) - 1;   }   int main(void) {     int n, q, p, node;     scanf( %d%d , &n, &q);     for (int i = 0; i < 4 * maxn; i++) st[i] = {-inf, -inf};     for (int i = 1; i < n; i++) {       scanf( %d , &p);       p--;       graph[p].push_back(i);     }     dfs(0, 0);     for (int i = 0; i < q; i++) {       scanf( %d , &node);       node--;       Q.push_back({{sz[node] / 2, node}, i});     }     vector<pair<int, int>> szs;     for (int i = 0; i < n; i++) szs.push_back({sz[i], i});     sort(szs.rbegin(), szs.rend()), sort(Q.rbegin(), Q.rend());     int ptr = 0;     for (auto it : Q) {       if (ptr != n) {         while (szs[ptr].first > it.first.first) {           int node = szs[ptr].second;           upd(1, 0, int(dis.size()) - 1, start[node], {H[node], node});           ptr++;           if (ptr == n) break;         }       }       res[it.second] = qry(1, 0, int(dis.size()) - 1, start[it.first.second],                            en[it.first.second])                            .second;     }     for (int i = 0; i < q; i++) printf( %d n , res[i] + 1);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, a, c1 = 0, c2 = 0;     vector<int> v;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x;       if (x & 1) {         x /= 2;         for (int j = 1; j <= x; j++) {           cin >> a;           c1 += a;         }         cin >> a;         v.push_back(a);         for (int j = 1; j <= x; j++) {           cin >> a;           c2 += a;         }       } else {         x /= 2;         for (int j = 1; j <= x; j++) {           cin >> a;           c1 += a;         }         for (int j = 1; j <= x; j++) {           cin >> a;           c2 += a;         }       }     }     sort(v.begin(), v.end());     int i = v.size() - 1;     while (i >= 0) {       c1 += v[i];       i--;       if (i == -1) break;       c2 += v[i];       i--;     }     cout << c1 <<     << c2 << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     long q;     scanf( %ld , &q);     while (q--) {       long n;       scanf( %ld , &n);       long div = n / 4;       if (n <= 3 || n == 5 || n == 7 || n == 11) {         puts( -1 );         continue;       }       if (n & 1) {         --div;       }       printf( %ld n , div);     }     return 0;   }