malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void dbg_out() { cerr <<   b b] n ; }   template <typename Head, typename... Tail>   void dbg_out(Head H, Tail... T) {     cerr << H <<  ,  ;     dbg_out(T...);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     string s;     cin >> s;     int n = (int)s.size();     int curr = 0, last = -1;     vector<int> ans;     for (int i = 0; i < n; ++i) {       if (s[i] ==  ) )         curr--;       else if (s[i] ==  ( )         curr++;       else {         if (curr <= 0) {           cout << -1;           return 0;         }         last = i;         curr--;         ans.push_back(curr);       }       if (curr < 0) {         cout << -1;         return 0;       }     }     if (last > -1) {       int x = 0, neg = 0;       for (int i = n - 1; i > last; --i) {         if (s[i] ==  ) )           x--;         else if (s[i] ==  ( )           x++;         if (x > 0) {           cout << -1;           return 0;         }       }       x = 0;       for (int i = last + 1; i < n; ++i) {         if (s[i] ==  ) )           x--;         else if (s[i] ==  ( )           x++;         neg = min(neg, x);       }       neg = ans.back() + neg;       if (x > 0 or neg < 0) {         cout << -1;         return 0;       }       ans.pop_back();       ans.push_back(neg + 1);     }     for (int i = 0; i < (int)ans.size(); ++i) {       if (i + 1 == (int)ans.size()) {         cout << ans[i] <<   n ;       } else         cout << 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct ball {     float coord;     int mass;     float vel;     short num;   };   bool sort_num(ball a, ball b) { return a.num < b.num; }   bool sort_coord(ball a, ball b) { return a.coord < b.coord; }   void collide(ball &a, ball &b) {     float temp = a.vel;     a.vel = ((a.mass - b.mass) * a.vel + 2 * b.vel * b.mass) / (b.mass + a.mass);     b.vel = ((b.mass - a.mass) * b.vel + 2 * temp * a.mass) / (b.mass + a.mass);   }   void iter(vector<ball> &balls, int size, float &cur_time, int time) {     float col_t = 9999.9;     int col_c = -1;     float temp;     for (int i = 0; i < size - 1; i++) {       temp = (balls[i + 1].coord - balls[i].coord) /              (balls[i].vel - balls[i + 1].vel);       if (temp > 0.0000001 && temp < col_t) {         col_t = temp;         col_c = i;       }     }     if (cur_time + col_t > time || col_c == -1) {       col_t = time - cur_time;       for (int i = 0; i < size; i++) balls[i].coord += balls[i].vel * col_t;       cur_time += col_t;       return;     }     for (int i = 0; i < size; i++) {       balls[i].coord += balls[i].vel * col_t;     }     for (int i = 0; i < size - 1; i++) {       if (fabs(balls[i].coord - balls[i + 1].coord) < 0.0000001) {         collide(balls[i], balls[i + 1]);         i++;       }     }     cur_time += col_t;   }   int main() {     int n, t;     float cur_t = 0.0;     cin >> n >> t;     vector<ball> balls(n);     for (int i = 0; i < n; i++) {       cin >> balls[i].coord >> balls[i].vel >> balls[i].mass;       balls[i].num = i;     }     sort(balls.begin(), balls.end(), sort_coord);     while (cur_t < t) {       iter(balls, n, cur_t, t);     }     sort(balls.begin(), balls.end(), sort_num);     for (int i = 0; i < n; i++) cout << balls[i].coord << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> v[10005];   int color[10005];   int flag[10005];   void dfs(int src, int p, int ctr) {     if (src == p) {       return;     }     flag[src] = ctr;     int i;     for (i = 0; i < v[src].size(); i++) {       if (color[v[src][i]] == color[src]) {         if (v[src][i] != p) dfs(v[src][i], src, ctr);       }     }   }   int main(void) {     scanf( %d , &n);     int i;     int x;     for (i = 2; i <= n; i++) {       scanf( %d , &x);       v[i].push_back(x);       v[x].push_back(i);     }     for (i = 1; i <= n; i++) {       scanf( %d , &x);       color[i] = x;     }     int ctr = 0;     for (i = 1; i <= n; i++) {       if (flag[i] == 0) {         ctr++;         dfs(i, -1, -ctr);       }     }     cout << ctr << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   int maxar(int arr[], int n) {     int res = arr[0];     for (int i = 0; i < n; i++) {       res = max(res, arr[i]);     }     return res;   }   long long maxar(long long arr[], long long n) {     long long res = arr[0];     for (long long i = 0; i < n; i++) {       res = max(res, arr[i]);     }     return res;   }   long long minar(long long arr[], long long n) {     long long res = arr[0];     for (long long i = 0; i < n; i++) {       res = min(res, arr[i]);     }     return res;   }   int minar(int arr[], int n) {     int res = arr[0];     for (int i = 0; i < n; i++) {       res = min(res, arr[i]);     }     return res;   }   void inpar(int arr[], int n) {     for (int i = 0; i < n; i++) {       cin >> arr[i];     }   }   void inpar(long long arr[], long long n) {     for (long long i = 0; i < n; i++) {       cin >> arr[i];     }   }   template <typename T>   inline T readInt() {     T n = 0, s = 1;     char p = getchar();     if (p ==  - ) s = -1;     while ((p <  0  || p >  9 ) && p != EOF && p !=  - ) p = getchar();     if (p ==  - ) s = -1, p = getchar();     while (p >=  0  && p <=  9 ) {       n = (n << 3) + (n << 1) + (p -  0 );       p = getchar();     }     return n * s;   }   void solve() {     int n = readInt<int>();     int a[n];     inpar(a, n);     int res = 0;     priority_queue<int> q;     for (int i = 1; i < n; i++) {       q.push(a[i]);     }     while (q.top() >= a[0]) {       res++;       a[0]++;       int temp = q.top();       temp--;       q.pop();       q.push(temp);     }     cout << res;   }   int32_t main() {     int tc;     tc = 1;     while (tc--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200000 + 10;   int a[MAXN];   int sum[MAXN];   int cnt[100 + 10];   vector<int> vc;   unordered_map<int, int> mp;   int exist[MAXN];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       cnt[a[i]]++;     }     int D = -1;     bool flag = false;     for (int i = 1; i <= 100; ++i) {       if (cnt[i]) {         vc.push_back(i);         if (D == -1 || cnt[D] < cnt[i]) {           D = i;           flag = false;         } else if (D != -1 && cnt[i] == cnt[D] && i != D) {           flag = true;         }       }     }     if (flag) {       printf( %d n , n);       return 0;     }     sum[0] = 0;     int ans = 0;     for (int x : vc) {       if (x == D) continue;       mp.clear();       exist[0] = 0;       mp[0] = 0;       for (int i = 1; i <= n; ++i) {         if (a[i] == D)           sum[i] = sum[i - 1] + 1;         else if (a[i] == x)           sum[i] = sum[i - 1] - 1;         else           sum[i] = sum[i - 1] + 0;         if (mp.count(sum[i]) == 0) mp[sum[i]] = i;         if (a[i] == D) {           exist[i] = exist[i - 1] + 1;         } else {           exist[i] = exist[i - 1];         }       }       int L = 0;       for (int r = 1; r <= n; ++r) {         if (mp.count(sum[r])) {           int l = mp[sum[r]] + 1;           if (l <= r && exist[r] - exist[l - 1] >= 1) {             L = max(L, r - l + 1);           }         }       }       ans = max(ans, L);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int pc[1 << 10];     for (size_t i = 0; i < (1 << 10); i++) {       int buf = 0;       for (int j = 0; j < 10; j++) {         if ((1 << j) & i) buf++;       }       pc[i] = buf;     }     int n, m;     cin >> n >> m;     map<int, pair<unsigned long long, unsigned long long>> ans;     vector<int> v1(n);     vector<int> v2(m);     for (size_t i = 0; i < n; i++) {       cin >> v1[i];       v1[i] *= 2;     }     for (size_t i = 0; i < m; i++) {       cin >> v2[i];       v2[i] *= 2;     }     for (size_t i = 0; i < n; i++) {       for (size_t j = 0; j < m; j++) {         int buf = (v1[i] + v2[j]) / 2;         ans[buf].first |= (1ULL << i);         ans[buf].second |= (1ULL << j);       }     }     int ansv = 0;     for (auto i = ans.begin(); i != ans.end(); i++) {       for (auto j = i; j != ans.end(); j++) {         long long a1 = i->second.first;         long long a2 = j->second.first;         long long b1 = i->second.second;         long long b2 = j->second.second;         long long buf1 = a1 | a2;         long long buf2 = b1 | b2;         int buf = 0;         while (buf1) {           int buff = buf1 & 1023;           buf1 >>= 10;           buf += pc[buff];         }         while (buf2) {           int buff = buf2 & 1023;           buf2 >>= 10;           buf += pc[buff];         }         ansv = max(ansv, buf);       }     }     cout << ansv;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[105];   int main() {     int s = 0, t = 0;     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (int i = 0; i < n; i++) {       if (s >= m)         break;       else {         s += a[n - i - 1];         t++;       }     }     cout << t;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300 * 1000 + 13;   int n;   long long a[N], b[N];   void solve() {     scanf( %d , &n);     for (int i = 0; i < int(n); ++i) scanf( %lld%lld , &a[i], &b[i]);     long long ans = 0, mn = 1e18;     for (int i = 0; i < int(n); ++i) {       int ni = (i + 1) % n;       long long val = min(a[ni], b[i]);       ans += a[ni] - val;       mn = min(mn, val);     }     ans += mn;     printf( %lld n , ans);   }   int main() {     int T;     scanf( %d , &T);     for (int i = 0; i < int(T); ++i) solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     unsigned long long c = 0;     short p;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> p;       c += p;     }     cout << setprecision(14) << ((double)c / n);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, m, n, k, a[1100], b[1100][10], count = 0;     cin >> n >> m >> k;     for (i = 0; i <= m; i++) a[i] = 10000000;     for (i = 1; i <= n; i++) {       for (j = 0; j < 2; j++) cin >> b[i][j];       if (a[b[i][0]] > b[i][1]) a[b[i][0]] = b[i][1];     }     for (i = 1; i <= m; i++) count += a[i];     if (count > k)       cout << k << endl;     else       cout << count << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     char c[101][101];     cin >> a >> b;     for (int i = 1; i <= a; i++) {       for (int j = 1; j <= b; j++) {         if (i % 2 != 0) {           c[i][j] =  # ;         }       }     }     for (int i = 2; i <= a; i += 4) {       for (int j = 1; j <= b; j++) {         c[i][j] =  . ;         c[i][b] =  # ;       }     }     for (int i = 4; i <= a; i += 4) {       for (int j = 1; j <= b; j++) {         c[i][j] =  . ;         c[i][1] =  # ;       }     }     for (int i = 1; i <= a; i++) {       for (int j = 1; j <= b; j++) {         cout << c[i][j];       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <class T, class U>   using Pa = pair<T, U>;   template <class T>   using vec = vector<T>;   template <class T>   using vvec = vector<vec<T>>;   bool chmax(int &a, int b) {     if (a < b) {       a = b;       return true;     }     return false;   }   vec<string> A = { 1110111 ,  0010010 ,  1011101 ,  1011011 ,  0111010 ,                     1101011 ,  1101111 ,  1010010 ,  1111111 ,  1111011 };   int dp[2010][2010] = {};   int pre[2010][2010] = {};   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int N, K;     cin >> N >> K;     vec<string> S(N);     for (int i = 0; i < N; i++) cin >> S[i];     int M = 7;     auto calc = [&](string T, int num) {       string B = A[num];       bool ok = true;       int c = 0;       for (int i = 0; i < M; i++) {         if (T[i] ==  1  && B[i] ==  0 ) ok = false;         if (T[i] ==  0  && B[i] ==  1 ) c++;       }       if (!ok)         return -1;       else         return c;     };     for (int i = 0; i <= N; i++)       for (int k = 0; k <= K; k++) dp[i][k] = -1;     dp[0][0] = 0;     for (int i = 0; i < N; i++)       for (int j = 0; j <= K; j++)         if (dp[i][j] != -1) {           for (int n = 0; n < 10; n++) {             int c = calc(S[N - 1 - i], n);             if (c == -1) continue;             if (j + c <= K) {               if (chmax(dp[i + 1][j + c], n)) {                 pre[i + 1][j + c] = j;               }             }           }         }     if (dp[N][K] == -1) {       cout << -1 <<   n ;       return 0;     }     string ans =   ;     int now = K;     for (int i = N - 1; i >= 0; i--) {       char c =  0  + dp[i + 1][now];       ans += c;       now = pre[i + 1][now];     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline long long read() {     long long x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline void write(long long a) {     if (a < 0) {       a = -a;       putchar( - );     }     if (a >= 10) write(a / 10);     putchar( 0  + a % 10);   }   inline void writeln(long long a) {     write(a);     puts(  );   }   inline void wri(long long a) {     write(a);     putchar(   );   }   inline unsigned long long rnd() {     return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4;   }   const int N = 300005, mod = 998244353;   pair<long long, long long> f[N];   long long dp[N];   int a[N], n, sum;   long long ksm(long long a, int b) {     int ans = 1;     for (; b; b >>= 1) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;     }     return ans;   }   pair<long long, long long> operator*(long long k,                                        pair<long long, long long> a) {     return make_pair(a.first * k % mod, a.second * k % mod);   }   pair<long long, long long> operator+(pair<long long, long long> a,                                        pair<long long, long long> b) {     return make_pair(a.first + b.first, a.second + b.second);   }   void ycl() {     f[sum - 1] = make_pair(1, 0);     long long a = ksm(sum, mod - 2), b = ksm(n - 1, mod - 2);     for (int i = (int)(sum - 1); i >= (int)(1); i--) {       f[i - 1] =           -ksm(i, mod - 2) * sum % mod *           ((sum - i) * a % mod * b % mod * f[i + 1] +            ((sum - i) * a % mod * (1 - b) % mod - 1) * f[i] + make_pair(0, 1));     }     pair<long long, long long> c =         b * f[1] + (n - 2) * b % mod * f[0] + make_pair(0, 1);     long long X = (c.second - f[0].second) % mod *                   ksm((f[0].first - c.first) % mod, mod - 2) % mod;     for (int i = (int)(0); i <= (int)(sum); i++)       dp[i] = (f[i].first * X + f[i].second) % mod;   }   int main() {     n = read();     for (int i = (int)(1); i <= (int)(n); i++) sum += (a[i] = read());     ycl();     long long ans = 0;     for (int i = (int)(1); i <= (int)(n); i++) ans += dp[a[i]];     ans = ((ans - (n - 1) * dp[0]) % mod + mod) % mod;     cout << ans * ksm(n, mod - 2) % mod << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<long long> vis(n + 1, 0);       vector<long long> res(n);       vector<long long> v;       int b;       cin >> b;       v.push_back(b);       int cur = 1;       int ok = 1;       vis[v[0]] = 1;       res[0] = v[0];       for (int i = 1, a; i < n; i++) {         cin >> a;         v.push_back(a);         if (!ok) continue;         if (v[i] > v[i - 1]) {           vis[v[i]] = 1;           vis[v[i - 1]] = 1;           res[i] = v[i];           continue;         } else {           for (int j = cur; j < v[i]; j++) {             if (vis[j] == 0) {               vis[j] = 1;               res[i] = j;               cur = j + 1;               break;             }           }           if (res[i] == 0) {             ok = 0;           }         }       }       if (!ok)         cout << -1 << endl;       else {         for (int i = 0; i < res.size(); i++)           if (res[i] == 0)             cout << v[i] <<    ;           else             cout << res[i] <<    ;         cout << endl;       }     }   }
#include <bits/stdc++.h>   int main() {     char a[100010];     scanf( %s , a);     long long i = 0, x = 1;     while (a[i] !=   0 ) {       if (a[i] ==  0 ) {         a[i] =  2 ;         x = 0;         break;       }       i++;     }     if (x) {       a[0] =  2 ;     }     i = 0;     while (a[i] !=   0 ) {       if (a[i] !=  2 ) printf( %c , a[i]);       i++;     }     printf(  n );     return (0);   }
#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   ostream& operator<<(ostream& os, const pair<T1, T2>& p) {     os <<  {  << p.first <<  ,   << p.second <<  } ;     return os;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& p) {     os <<  [ ;     int i = 0;     for (typename vector<T>::const_iterator it = p.begin(); it != p.end(); ++it) {       os << (i == 0 ?    :  ,  ) << *it;       i++;     }     os <<  ] ;     return os;   }   template <class T>   ostream& operator<<(ostream& os, const set<T>& p) {     os <<  [ ;     int i = 0;     for (typename set<T>::const_iterator it = p.begin(); it != p.end(); ++it) {       os << (i == 0 ?    :  ,  ) << *it;       i++;     }     os <<  ] ;     return os;   }   template <class K, class V>   ostream& operator<<(ostream& os, const map<K, V>& p) {     os <<  [ ;     int i = 0;     for (typename map<K, V>::const_iterator it = p.begin(); it != p.end(); ++it) {       os << (i == 0 ?    :  ,  ) << *it;       i++;     }     os <<  ] ;     return os;   }   template <class T>   string toString(const T& o) {     stringstream ss;     ss << o;     string ret;     getline(ss, ret);     return ret;   }   template <class T>   vector<T> subv(const vector<T>& v, int from, int to) {     return vector<T>(v.begin() + min(max(0, from), (int)v.size()),                      v.begin() + min(max(0, to), (int)v.size()));   }   pair<int, int> operator+(const pair<int, int>& a, const pair<int, int>& b) {     return make_pair(a.first + b.first, a.second + b.second);   }   pair<int, int> operator*(const int& a, const pair<int, int>& b) {     return make_pair(a * b.first, a * b.second);   }   int main() {     int n;     cin >> n;     if (n == 1) {       cout <<  a na nb nb n ;     } else if (n == 2) {       cout <<  aa nbb ncc ndd n ;     } else {       if (n % 2 == 0) {         for (int i = 0; i < n / 2; ++i) cout << (i % 2 == 0 ?  aa  :  bb );         cout << endl;         for (int i = 0; i < n / 2; ++i) cout << (i % 2 != 0 ?  aa  :  bb );         cout << endl;         cout <<  e ;         for (int i = 0; i < n / 2 - 1; ++i) cout << (i % 2 == 0 ?  cc  :  dd );         cout <<  e  << endl;         cout <<  e ;         for (int i = 0; i < n / 2 - 1; ++i) cout << (i % 2 != 0 ?  cc  :  dd );         cout <<  e  << endl;       } else {         for (int i = 0; i < n / 2; ++i) cout << (i % 2 == 0 ?  aa  :  bb );         cout <<  e  << endl;         for (int i = 0; i < n / 2; ++i) cout << (i % 2 != 0 ?  aa  :  bb );         cout <<  e  << endl;         cout <<  e ;         for (int i = 0; i < n / 2; ++i) cout << (i % 2 == 0 ?  cc  :  dd );         cout << endl;         cout <<  e ;         for (int i = 0; i < n / 2; ++i) cout << (i % 2 != 0 ?  cc  :  dd );         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t = 1;     while (t--) {       int n, k;       cin >> n >> k;       vector<int> v(n);       int itr = 1;       for (int& x : v) {         cin >> x;       }       set<int> bag{0}, tmp;       map<int, vector<int>> pep;       for (int i = 0; i < n && bag.size() <= k; i++) {         tmp = bag;         for (auto x : tmp) {           if (bag.find(x + v[i]) == bag.end()) {             bag.insert(x + v[i]);             pep[x + v[i]] = pep[x];             pep[x + v[i]].push_back(v[i]);           }           if (bag.size() > k) break;         }       }       pep.erase(pep.begin());       for (auto& it : pep) {         cout << it.second.size() <<    ;         for (auto& x : it.second) {           cout << x <<    ;         }         cout <<   n ;       }     }     cerr <<  processor time:   << clock() / (double)CLOCKS_PER_SEC <<  s     ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char str[1000005];   int ar[1000005];   void solve() {     int n = (int)strlen(str + 1), i, j, ans = 0;     memset(ar, 0, sizeof(ar));     str[0] =  0 ;     for (i = n; i >= 0; i--) {       if (str[i] ==  1 ) {         j = i;         while (str[j] ==  1 ) --j;         if (i - j > 1)           ar[i] = -1, ar[j] = 1, str[j] =  1 ;         else {           int k;           for (k = -~j; k <= i; k++) ar[k] = 1;         }         i = -~j;       }     }     for (i = 0; i <= n; i++)       if (ar[i]) ans++;     printf( %d n , ans);     for (i = 0; i <= n && ans; i++) {       if (ar[i]) {         putchar(~ar[i] ?  +  :  - ), printf( 2^%d n , n - i);         --ans;       }     }   }   int main(void) {     while (~scanf( %s , str + 1)) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0, sum1 = 0;     int x;     cin >> n;     for (int i = 0; i < (int)n - 1; ++i) {       cin >> x;       sum += x;     }     for (int i = 1; i <= n; i++) sum1 += i;     cout << sum1 - sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int A[26];   int main() {     int n;     cin >> n;     string s;     cin >> s;     int cnt = 0;     for (int i = 0; i < n; i++) s[i] = tolower(s[i]);     for (int i = 0; i < n; i++) {       if (!A[s[i] -  a ]) {         A[s[i] -  a ] = 1;         ++cnt;       }     }     if (cnt == 26)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, gn1 = 0, gj1 = 0, gn2 = 0, gj2 = 0;     cin >> n >> m;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       if (x % 2 == 0)         gn1++;       else         gj1++;     }     for (int i = 0; i < m; i++) {       int x;       cin >> x;       if (x % 2 == 0)         gn2++;       else         gj2++;     }     cout << min(gj1, gn2) + min(gj2, gn1) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   ifstream fin( universal.in );   ofstream fout(  );   int n, m;   set<int> on;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       int aux;       cin >> aux;       for (int j = 1, bb; j <= aux; ++j) {         cin >> bb;         on.insert(bb);       }       if (on.size() == m) {         cout <<  YES n ;         return 0;       }     }     cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int p, i, j;     scanf( %d , &p);     int n = 1 << (p + 1);     vector<int> a(n);     for (i = 2; i < n; i++) scanf( %d , &a[i]);     vector<int> up(n), mx(n);     for (i = 1; i < n; i++) {       int sum = 0;       for (j = i; j > 1; j /= 2) sum += a[j];       up[i] = sum;     }     int maxVal = *max_element(up.begin(), up.end());     for (i = n / 2; i < n; i++) {       mx[i] += maxVal - up[i];     }     for (i = n - 1; i > 1; i--) {       int c = min(mx[i], mx[i ^ 1]);       mx[i] -= c;       mx[i ^ 1] -= c;       mx[i / 2] += c;     }     printf( %d n , accumulate(mx.begin(), mx.end(), 0));   }