malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, t, a, x, cur = 0, sum = 0, sz = 1;     cin >> n;     vector<long long> arr(n + 20), ch(n + 20);     for (int i = 0; i < n; i++) {       cin >> t;       if (t == 1) {         cin >> a >> x;         ch[a - 1] += x;         sum += a * x;       } else if (t == 2) {         cin >> x;         sum += x;         arr[++cur] = x;       } else {         sum -= (arr[cur] + ch[cur]);         ch[cur - 1] += ch[cur];         ch[cur] = 0;         arr[cur] = 0;         cur--;       }       cout << (sum * 1.0) / (1.0 * (cur + 1)) <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(12);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e9 + 1;   const int MAXN = (int)5001;   int solve(vector<pair<int, int> > sg, int pos) {     sg.erase(sg.begin() + pos);     int mx = sg[0].first, mn = sg[0].second;     for (int i = (1); i < (int)(sg.size()); i++) {       if (sg[i].first > mn || sg[i].second < mx) return 0;       mx = max(mx, sg[i].first);       mn = min(mn, sg[i].second);     }     return abs(mx - mn);   }   bool comp1(const pair<int, int> &a, const pair<int, int> &b) {     return (a.first == b.first) ? (a.second - a.first > b.second - b.first)                                 : (a.first < b.first);   }   bool comp2(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second == b.second) ? (a.second - a.first < b.second - b.first)                                   : (a.second < b.second);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, x, y;     cin >> n;     vector<pair<int, int> > sgm;     for (int i = (0); i < (int)(n); i++) {       cin >> x >> y;       sgm.push_back(make_pair(x, y));     }     sort((sgm).begin(), (sgm).end(), comp1);     x = solve(sgm, n - 1);     sort((sgm).begin(), (sgm).end(), comp2);     cout << max(x, solve(sgm, 0));   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   string s;   set<string> st;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     while (cin >> s) {       st.clear();       for (int i = 0; i < s.size(); i++) {         string s1 =   ;         for (int j = 0; j < s.size(); j++) s1 += s[(i + j) % s.size()];         st.insert(s1);       }       cout << st.size() << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> moves = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};   bool isValid(int a, int b, int x, int y) {     return (a >= 0 && a < x) && (b >= 0 && b < y);   }   bool isPath(int n, int m, vector<string>& mat) {     bool isPossible = false;     int cnt = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (mat[i][j] ==  G ) cnt++;       }     }     if (mat[n - 1][m - 1] ==  #  && cnt > 0) return isPossible;     vector<vector<bool>> vis(n, vector<bool>(m));     queue<pair<int, int>> q;     q.push({n - 1, m - 1});     vis[n - 1][m - 1] = true;     while (!q.empty()) {       pair<int, int> curr = q.front();       q.pop();       if (mat[curr.first][curr.second] ==  G ) {         cnt--;       }       for (int i = 0; i < 4; i++) {         int nx = curr.first + moves[i][0];         int ny = curr.second + moves[i][1];         if (isValid(nx, ny, n, m) && mat[nx][ny] !=  #  && !vis[nx][ny]) {           q.push({nx, ny});           vis[nx][ny] = true;         }       }     }     isPossible = cnt <= 0 ? true : false;     return isPossible;   }   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<string> mat(n);       for (int i = 0; i < n; i++) {         cin >> mat[i];       }       bool isPossible = true;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (mat[i][j] ==  B ) {             for (int k = 0; k < 4; k++) {               int nx = i + moves[k][0];               int ny = j + moves[k][1];               if (isValid(nx, ny, n, m)) {                 if (mat[nx][ny] ==  G ) {                   isPossible = false;                   break;                 } else if (mat[nx][ny] ==  . ) {                   mat[nx][ny] =  # ;                 }               }             }           }           if (!isPossible) break;         }         if (!isPossible) break;       }       if (!isPossible) {         cout <<  No  << endl;       } else {         isPossible = isPath(n, m, mat);         if (!isPossible)           cout <<  No  << endl;         else           cout <<  Yes  << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int t = 0;   int d[300000];   int par[300000];   int t1[300000];   int t2[300000];   void dfs(int s, vector<vector<int> > &ed, int y) {     d[s] = y;     t1[s] = t++;     for (int i = 0; i < ed[s].size(); i++) {       if (ed[s][i] != par[s]) {         par[ed[s][i]] = s;         dfs(ed[s][i], ed, y + 1);       }     }     t2[s] = t++;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m;     cin >> n >> m;     vector<vector<int> > v(n);     int f, s;     for (int i = 1; i < n; i++) {       cin >> f >> s;       f--;       s--;       v[f].push_back(s);       v[s].push_back(f);     }     for (int i = 0; i < n; i++) {       sort(v[i].begin(), v[i].end());     }     par[0] = -1;     dfs(0, v, 0);     for (int i = 0; i < m; i++) {       cin >> f;       vector<int> h(f);       for (int j = 0; j < f; j++) {         cin >> h[j];         h[j]--;       }       int u = 0;       for (int j = 0; j < f; j++) {         if (d[h[j]] > d[u]) {           u = h[j];         }       }       int flag = 1;       for (int j = 0; j < f; j++) {         if (!((t1[h[j]] <= t1[u] && t2[h[j]] >= t2[u]) ||               (t1[par[h[j]]] <= t1[u] && t2[par[h[j]]] >= t2[u]))) {           flag = 0;           break;         }       }       if (flag == 0) {         cout <<  NO n ;       } else {         cout <<  YES n ;       }     }     return 0;   }
#include<bits/stdc++.h>   using namespace std;      typedef long long ll;      int q(int l, int r){       cout <<  ?   << l <<     << r << endl;       int idx; cin >> idx;       return idx;   }   void solve(){       int n;       cin >> n;       int idx = q(1, n);       int L = -1, R = -1;       if(1 < idx) L = q(1, idx);       if(n > idx) R = q(idx, n);       if(R == idx){ // 最大值在右           int ans = n, l = idx + 1, r = n, mid;           while(l <= r){               mid = l + r >> 1;               int t = q(idx, mid);               if(t == idx){                   ans = min(ans, mid);                   r = mid - 1;               }else{                   l = mid + 1;               }           }           cout <<  !   << ans << endl;       }else{           int ans = 1, l = 1, r = idx - 1, mid;           while(l <= r){               mid = l + r >> 1;               int t = q(mid, idx);               if(t == idx){                   ans = max(ans, mid);                   l = mid + 1;               }else{                   r = mid - 1;               }           }           cout <<  !   << ans << endl;       }   }   // 5 1 2 3 4   int main(){       // #define LOCAL   #ifdef LOCAL       freopen( in.in ,  r , stdin);       freopen( out.out ,  w , stdout);   #endif         int _ = 1;       // cin >> _;       for(int i = 1; i <= _; ++i) solve();   }
#include <bits/stdc++.h>   using namespace std;   long long int a[10000010];   int main() {     long long int n;     long long ans = 0;     cin >> n;     for (long long int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     ans = a[n - 1] * n;     long long int c = n;     for (long long int i = n - 2; i >= 0; i--) {       ans += (c * a[i]);       c--;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using namespace std;   int a[1100][1100], pt[1100], b[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1}, ef, n;   map<string, int> m;   string st[1100];   int f(int aa, int bb) {     if (pt[aa] != pt[bb])       return pt[aa] > pt[bb];     else {       for (int i = 0; i < 60; i++)         if (a[aa][i] != a[bb][i]) return a[aa][i] > a[bb][i];       return 0;     }   }   int f2(int aa, int bb) {     if (a[aa][0] != a[bb][0])       return a[aa][0] > a[bb][0];     else       return f(aa, bb);   }   int main() {     int t;     cin >> t;     for (int ii = 0; ii < t; ii++) {       cin >> n;       for (int i = 0; i < n; i++) {         string s;         cin >> s;         if (m.find(s) == m.end()) {           m[s] = ef++;           st[ef - 1] = s;         }         a[m[s]][i]++;         if (i <= 9) pt[m[s]] += b[i];       }     }     int r[1100];     for (int i = 0; i < m.size(); i++) r[i] = i;     sort(r, r + m.size(), f);     cout << st[r[0]] << endl;     sort(r, r + m.size(), f2);     cout << st[r[0]] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char st[500];     cin >> st;     int n = strlen(st);     int left = 0, right = 0, i = 0;     for (; i < n; ++i) {       if (st[i] ==  | )         break;       else         left++;     }     right = n - 1 - i;     char a[500];     cin >> a;     int x = strlen(a), av = x;     int he, ch = 0;     if (left > right) {       int diff = left - right;       if (diff <= x) {         right = left;         av = av - diff;         if (av % 2 == 0) {           for (int j = 0; j < av / 2; ++j) cout << a[j];           cout << st;           for (int j = av / 2; j < x; ++j) cout << a[j];         } else {           cout <<  Impossible n ;         }       } else {         cout <<  Impossible ;       }     } else if (right > left) {       int diff = right - left;       if (diff <= x) {         left = right;         av = av - diff;         if (av % 2 == 0) {           for (int j = 0; j < x - av / 2; ++j) cout << a[j];           cout << st;           for (int j = x - av / 2; j < x; ++j) cout << a[j];         } else {           cout <<  Impossible n ;         }       } else {         cout <<  Impossible ;       }     } else {       if (x % 2 == 0) {         for (int j = 0; j < x / 2; ++j) cout << a[j];         cout << st;         for (int j = x / 2; j < x; ++j) cout << a[j];       } else         cout <<  Impossible n ;     }   }
#include <bits/stdc++.h>   using namespace std;   string inc[6] = { 011112 ,  103231 ,  110121 ,  121011 ,  ,112101 ,  211110 };   string near[6] = { 1234 ,  0254 ,  0153 ,  4520 ,  3510 ,  4321 };   int opp[6] = {5, 3, 4, 1, 2, 0};   char t[7], s[7];   string t_p;   bool seen[6];   set<string> se;   void dfs(int x, int v) {     seen[x] = true;     t[v] = s[x];     if (v == 5) {       t_p = min((string)t, t_p);     } else {       for (int i = 0; i < 6; i++) {         if (inc[x][i] ==  1  && !seen[i]) {           dfs(i, v + 1);         }       }     }     seen[x] = false;   }   int X[4] = {1, 2, 3, 4}, Y[4] = {0, 1, 5, 3}, Z[4] = {0, 2, 5, 4};   void cycle(int* r) {     int x = t[r[0]];     t[r[0]] = t[r[1]];     t[r[1]] = t[r[2]];     t[r[2]] = t[r[3]];     t[r[3]] = x;   }   int main() {     t[6] =   0 ;     while (cin >> s) {       se.clear();       sort(s, s + 6);       do {         for (int i = 0; i < 6; i++) t[i] = s[i];         t_p =  ZZZZZZ ;         for (int i = 0; i < 4; i++) {           for (int j = 0; j < 4; j++) {             for (int k = 0; k < 4; k++) {               t_p = min((string)t, t_p);               cycle(X);             }             cycle(Y);           }           cycle(Z);         }         se.insert(t_p);       } while (next_permutation(s, s + 6));       cout << se.size() << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long mo(const long long input, const long long ceil) {     return input >= ceil ? input % ceil : input;   }   const long long maxn = 5e5 + 10;   long long cnt, cnta, cntb;   long long vis[maxn];   vector<long long> e[maxn];   void dfs(long long k, long long t) {     vis[k] = t;     cnt++;     for (auto i : e[k])       if (vis[i] != t) dfs(i, t);   }   void solve(long long t) {     long long n, m, a, b;     cin >> n >> m >> a >> b;     for (long long i = 1; i <= n; i++) e[i].clear();     for (long long i = 1; i <= m; i++) {       long long x, y;       cin >> x >> y;       e[x].push_back(y);       e[y].push_back(x);     }     vis[a] = t * 2 - 1;     cnt = 1;     dfs(b, t * 2 - 1);     cnta = n - cnt;     vis[b] = t * 2;     cnt = 1;     dfs(a, t * 2);     cntb = n - cnt;     cout << cnta * cntb <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long tt = 1;     cin >> tt;     for (long long i = 1; i <= tt; i++) solve(i);     cerr <<   n n nTime :            << 1000 * (long double)clock() / (long double)CLOCKS_PER_SEC <<  ms n ;     ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans[10];   int main() {     memset(ans, 0, sizeof(ans));     int n;     char c;     scanf( %d , &n);     while (n--) {       scanf(  %c , &c);       if (c ==  9 ) {         ans[7]++;         ans[3] += 2;         ans[2]++;       }       if (c ==  8 ) {         ans[7]++;         ans[2] += 3;       }       if (c ==  7 ) ans[7]++;       if (c ==  6 ) {         ans[5]++;         ans[3]++;       }       if (c ==  5 ) ans[5]++;       if (c ==  4 ) {         ans[3]++;         ans[2] += 2;       }       if (c ==  3 ) ans[3]++;       if (c ==  2 ) ans[2]++;     }     for (int i = 9; i > 1; i--)       for (int j = 0; j < ans[i]; j++) printf( %d , i);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long int __gcd(long long int a, long long int b);   void pdash(int n = 1);   int bitcount(long long int u);   long long int power(long long int x, long long int y);   long long int power(long long int x, long long int y, long long int z);   long long int modInverse(long long int n, long long int p);   long long int nCrF(long long int n, long long int r, long long int p);   void cordinate_compression(vector<int>& v);   void make_unique(vector<int>& vec);   const long long int mod = 1e9 + 7;   void solve() {     int n, q;     cin >> n >> q;     string str;     cin >> str;     vector<int> vec(n);     for (int i = 0; i < n; i++) {       vec[i] = (str[i] -  0 );     }     for (int i = 1; i < n; i++) {       vec[i] += vec[i - 1];     }     while (q--) {       int zero, one;       int a, b;       cin >> a >> b;       a--;       b--;       one = vec[b] - (((a - 1) >= 0) ? vec[a - 1] : 0);       zero = (b - a) + 1 - one;       cout << ((power(2, zero, mod) * ((power(2, one, mod) - 1 + mod) % mod)) %                mod)            <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }   }   inline long long int __gcd(long long int a, long long int b) {     if (a == 0 || b == 0) {       return max(a, b);     }     long long int tempa, tempb;     while (1) {       if (a % b == 0)         return b;       else {         tempa = a;         tempb = b;         a = tempb;         b = tempa % tempb;       }     }   }   void pdash(int n) {     for (int i = 0; i < n; i++) {       for (int j = 0; j < 30; j++) {         cout <<  - ;       }       cout <<   n ;     }   }   long long int power(long long int x, long long int y) {     long long int result = 1;     while (y > 0) {       if (y & 1) {         result = (result * x);       }       y = y >> 1;       x = (x * x);     }     return result;   }   long long int power(long long int x, long long int y, long long int z) {     long long int result = 1;     x = x % z;     while (y > 0) {       if (y & 1) {         result = (result * x) % z;       }       y = y >> 1;       x = (x * x) % z;     }     return result;   }   long long int modInverse(long long int n, long long int p) {     return power(n, p - 2, p);   }   long long int nCrF(long long int n, long long int r, long long int p) {     if (r == 0) return 1;     long long int f[n + 1];     f[0] = 1;     for (long long int i = 1; i <= n; i++) f[i] = f[i - 1] * i % p;     return (f[n] * modInverse(f[r], p) % p * modInverse(f[n - r], p) % p) % p;   }   void cordinate_compression(vector<int>& v) {     vector<int> p = v;     make_unique(p);     for (int i = 0; i < (int)((v).size()); i++)       v[i] = (int)(lower_bound(p.begin(), p.end(), v[i]) - p.begin());   }   void make_unique(vector<int>& vec) {     sort(vec.begin(), vec.end());     vec.erase(unique(vec.begin(), vec.end()), vec.end());   }   int bitcount(long long int u) {     int cnt = 0;     while (u) {       u = u & (u - 1);       cnt++;     }     return cnt;   }
#include <bits/stdc++.h>   using namespace std;   const double INF = 1000000000;   struct point {     long long x, y;     point() {}     point(long long x, long long y) : x(x), y(y) {}     point operator-(point P) { return point(x - P.x, y - P.y); }   };   double abs(point P) { return sqrt(P.x * P.x + P.y * P.y); }   double dist(point P, point Q) { return abs(Q - P); }   long long dot(point P, point Q) { return P.x * Q.x + P.y * Q.y; }   long long cross(point P, point Q) { return P.x * Q.y - P.y * Q.x; }   int main() {     cout << fixed << setprecision(20);     int N, K;     cin >> N >> K;     K--;     vector<point> P(N);     for (int i = 0; i < N; i++) {       cin >> P[i].x >> P[i].y;     }     if (N == 3) {       int a = (K + 1) % 3;       int b = (K + 2) % 3;       cout << min(dist(P[K], P[a]), dist(P[K], P[b])) + dist(P[a], P[b]) << endl;     } else {       mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());       int p;       int x;       point D;       while (true) {         int a = mt() % N;         int b = mt() % N;         int c = mt() % N;         if (a != b && b != c && c != a) {           if (cross(P[b] - P[a], P[c] - P[a]) == 0) {             x = a;             D = P[b] - P[a];             for (int i = 0; i < N; i++) {               if (cross(P[i] - P[a], D) != 0) {                 p = i;               }             }             break;           }         }       }       vector<pair<long long, int>> L;       for (int i = 0; i < N; i++) {         if (i != p) {           L.push_back(make_pair(dot(P[i] - P[x], D), i));         }       }       sort(L.begin(), L.end());       vector<point> Q(N - 1);       for (int i = 0; i < N - 1; i++) {         Q[i] = P[L[i].second];       }       if (p == K) {         cout << min(dist(P[K], Q[0]), dist(P[K], Q[N - 2])) + dist(Q[0], Q[N - 2])              << endl;       } else {         int s;         for (int i = 0; i < N - 1; i++) {           if (L[i].second == K) {             s = i;           }         }         double ans = INF;         ans = min(ans,                   dist(Q[s], Q[0]) + dist(Q[0], Q[N - 2]) + dist(Q[N - 2], P[p]));         ans = min(ans,                   dist(Q[s], Q[N - 2]) + dist(Q[N - 2], Q[0]) + dist(Q[0], P[p]));         for (int i = s; i < N - 2; i++) {           double d11 = dist(Q[s], Q[i]) + dist(Q[i], Q[0]) + dist(Q[0], P[p]);           double d12 = dist(Q[s], Q[0]) + dist(Q[0], Q[i]) + dist(Q[i], P[p]);           double d1 = min(d11, d12);           double d2 = min(dist(P[p], Q[i + 1]), dist(P[p], Q[N - 2])) +                       dist(Q[i + 1], Q[N - 2]);           ans = min(ans, d1 + d2);         }         for (int i = 1; i <= s; i++) {           double d11 =               dist(Q[s], Q[i]) + dist(Q[i], Q[N - 2]) + dist(Q[N - 2], P[p]);           double d12 =               dist(Q[s], Q[N - 2]) + dist(Q[N - 2], Q[i]) + dist(Q[i], P[p]);           double d1 = min(d11, d12);           double d2 =               min(dist(P[p], Q[i - 1]), dist(P[p], Q[0])) + dist(Q[i - 1], Q[0]);           ans = min(ans, d1 + d2);         }         cout << ans << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int _inf = 0xc0c0c0c0;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long _INF = 0xc0c0c0c0c0c0c0c0;   const long long mod = (int)1e9 + 7;   const int Z = 100;   const int N = Z * Z;   const int M = Z * Z * Z;   int px[N], py[N];   int head[N], to[M], ct[M], w[M], nt[M];   int d[N], vis[N];   int pre[N], id[N];   int s, t, tot;   void add(int u, int v, int flow, int cost) {     to[tot] = v;     ct[tot] = cost;     w[tot] = flow;     nt[tot] = head[u];     head[u] = tot++;     to[tot] = u;     ct[tot] = -cost;     w[tot] = 0;     nt[tot] = head[v];     head[v] = tot++;   }   void init() {     memset(head, -1, sizeof(head));     tot = 0;   }   int spfa(int s, int t) {     queue<int> q;     memset(d, inf, sizeof(d));     memset(vis, 0, sizeof(vis));     memset(pre, -1, sizeof(pre));     d[s] = 0;     q.push(s);     while (!q.empty()) {       int u = q.front();       q.pop();       vis[u] = 0;       for (int i = head[u]; ~i; i = nt[i]) {         if (w[i] > 0 && d[to[i]] > d[u] + ct[i]) {           d[to[i]] = d[u] + ct[i];           pre[to[i]] = u;           id[to[i]] = i;           if (!vis[to[i]]) {             vis[to[i]] = 1;             q.push(to[i]);           }         }       }     }     return d[t] < inf;   }   int MaxFlow(int s, int t) {     int Mi = inf;     int sum = 0;     int tt = 0;     while (spfa(s, t)) {       Mi = inf;       for (int i = t; i != s; i = pre[i]) Mi = min(Mi, w[id[i]]);       for (int i = t; i != s; i = pre[i]) {         w[id[i]] -= Mi;         w[id[i] ^ 1] += Mi;       }       tt += Mi;       sum += d[t] * Mi;     }     return sum;   }   int main() {     init();     int n, m, k, c, d;     scanf( %d%d%d%d%d , &n, &m, &k, &c, &d);     int s = 0, t = n * 100 + 1;     for (int i = 1; i <= 100; ++i) add(i, t, 100, 0);     for (int i = 1, v; i <= k; ++i) {       scanf( %d , &v);       add(s, (v - 1) * 100 + 1, 1, 0);     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j < 100; ++j) {         add((i - 1) * 100 + j, (i - 1) * 100 + j + 1, 100, c);       }     }     for (int i = 1, u, v; i <= m; ++i) {       scanf( %d%d , &u, &v);       for (int j = 1; j < 100; ++j) {         int idx = (u - 1) * 100 + j;         int idy = (v - 1) * 100 + j + 1;         for (int k = 1; k <= 20; ++k) {           add(idx, idy, 1, c + (k * k - (k - 1) * (k - 1)) * d);         }       }       for (int j = 1; j < 100; ++j) {         int idx = (v - 1) * 100 + j;         int idy = (u - 1) * 100 + j + 1;         for (int k = 1; k <= 20; ++k) {           add(idx, idy, 1, c + (k * k - (k - 1) * (k - 1)) * d);         }       }     }     printf( %d n , MaxFlow(s, t));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int odd_a = 0, odd_b = 0, even_a = 0, even_b = 0;     int a, b, c;     cin >> a >> b;     for (int i = 0; i < a; i++) {       cin >> c;       c % 2 ? odd_a++ : even_a++;     }     for (int i = 0; i < b; i++) {       cin >> c;       c % 2 ? odd_b++ : even_b++;     }     int ans = 0;     ans += min(odd_a, even_b);     ans += min(even_a, odd_b);     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int const N = 1e5 + 86;   int const M = 1e9 + 7;   int a[N], f[111][N];   ll ext_gcd(ll a, ll b, ll &x, ll &y) {     if (!b) {       x = 1, y = 0;       return a;     }     ll ret = ext_gcd(b, a % b, x, y);     ll t = x;     x = y, y = t - a / b * y;     return ret;   }   ll mod_inv(ll a, ll n) {     ll x, y;     ext_gcd(a, n, x, y);     x %= n;     if (x < 0) x += n;     return x;   }   void add(int &x, int y) {     x += y;     if (x >= M) x -= M;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) scanf( %d , a + i);     for (int l, r, k; m--;) {       scanf( %d%d%d , &l, &r, &k), --l, --r;       add(f[k][l], 1), add(f[k][r + 1], M - 1);       ll c = 1, m = r - l + 1;       for (int i = 1; i <= k; ++i, ++m) {         c = c * m % M;         c = c * mod_inv(i, M) % M;         add(f[k - i][r + 1], M - c);       }     }     for (int i = 100; i >= 0; --i) {       for (int j = 1; j < n; ++j) add(f[i][j], f[i][j - 1]);       for (int j = 0; i && j < n; ++j) add(f[i - 1][j], f[i][j]);     }     for (int i = 0; i < n; ++i) add(a[i], f[0][i]);     for (int i = 0; i < n; ++i) printf( %d%s , a[i], i == n - 1 ?   n  :    );     return 0;   }