malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct mat {     int num[4][4];   };   int p[100009];   mat mult(mat &a, mat &b) {     mat ret;     for (int i = 0; i < 4; i++)       for (int j = 0; j < 4; j++) {         long long t = 0;         for (int k = 0; k < 4; k++) t += 1ll * a.num[i][k] * b.num[k][j];         ret.num[i][j] = t % 1000000007;       }     return ret;   }   int cal(string &a, string &b) {     if (b.size() > a.size()) return 0;     int ret = 0;     p[0] = -1;     for (int j, i = 0; b[i]; i++) {       for (j = p[i]; j >= 0 && b[i] != b[j]; j = p[j])         ;       p[i + 1] = j + 1;     }     for (int j = 0, i = 0; a[i]; i++) {       for (; j >= 0 && a[i] != b[j]; j = p[j])         ;       j++;       if (j == b.size()) ret++, j = p[j];     }     return ret;   }   mat m1, m2;   int query(long long n, string &q) {     if (n == 1) {       return q ==  a  ? 1 : 0;     }     if (n == 2) {       return q ==  b  ? 1 : 0;     }     string s1 =  a , s2 =  b , s =  b ;     for (n -= 2; n && s1.size() < q.size(); n--, s1 = s2, s2 = s) s = s2 + s1;     int f1 = cal(s1, q), f2 = cal(s, q);     if (!n) return f2;     s = s2.substr(s2.size() - q.size() + 1, q.size() - 1) +         s2.substr(0, q.size() - 1);     int t1 = cal(s, q);     s = s1.substr(s1.size() - q.size() + 1, q.size() - 1) +         s1.substr(0, q.size() - 1);     int t2 = cal(s, q);     m1.num[0][0] = m1.num[0][1] = m1.num[0][2] = m1.num[1][0] = m1.num[2][2] =         m1.num[3][3] = 1;     m2.num[0][0] = m2.num[0][1] = m2.num[0][3] = m2.num[1][0] = m2.num[2][2] =         m2.num[3][3] = 1;     mat res, t = mult(m2, m1);     bool flag = 0;     if (n % 2) res = m1, flag = 1;     for (n /= 2; n; n >>= 1, t = mult(t, t))       if (n & 1) {         if (!flag)           res = t, flag = 1;         else           res = mult(res, t);       }     return (1ll * res.num[0][0] * f2 + 1ll * res.num[0][1] * f1 +             1ll * res.num[0][2] * t1 + 1ll * res.num[0][3] * t2) %            1000000007;   }   int main() {     long long n, m;     cin >> n >> m;     string s;     while (m--) cin >> s, cout << query(n, s) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n;     cin >> n;     long long int one = (n / 2) + (n / 3) + (n / 5) + (n / 7),                   two = (n / 6) + (n / 10) + (n / 14) + (n / 15) + (n / 21) +                         (n / 35),                   three = (n / (2 * 3 * 5)) + (n / (3 * 5 * 7)) +                           (n / (2 * 5 * 7)) + (n / (2 * 3 * 7)),                   four = (n / (2 * 3 * 5 * 7));     cout << n - one + two - three + four;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   long long dc(long long x, long long y) {     long long r;     while (y) {       r = x % y;       x = y;       y = r;     }     return x;   }   int main() {     cin >> n >> m >> k;     if (2 * n * m % k != 0)       cout <<  NO ;     else {       int ok = 0;       cout <<  YES  <<   n ;       if (k % 2 == 0) {         k = k / 2;         ok = 1;       }       long long d = dc(n, k);       k = k / d;       long long x = n / d;       d = dc(m, k);       k = k / d;       long long y = m / d;       if (ok) {         cout << 0 <<     << 0 <<   n ;         cout << x <<     << 0 <<   n ;         cout << 0 <<     << y <<   n ;       } else {         cout << 0 <<     << 0 <<   n ;         if (x < n)           x *= 2;         else if (y < m)           y *= 2;         cout << x <<     << 0 <<   n ;         cout << 0 <<     << y <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q, k;     cin >> q;     long long l, r, d, x;     for (k = 0; k < q; ++k) {       cin >> l >> r >> d;       if (d < l || d > r)         x = d;       else {         if (r % d == 0)           x = r + d;         else           x = r + (d - (r % d));       }       cout << x << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T solve(T n, T k) {     vector<T> arr(n);     for (T i = 0; i < n; i++) {       cin >> arr[i];     }     T sum = 0;     sort(arr.begin(), arr.end(), greater<int>());     for (int i = 2 * k; i < n; i++) {       sum += arr[i];     }     for (T i = 0; i < k; ++i) {       sum += (arr[i + k] / arr[i]);     }     return sum;   }   int main() {     int t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       cout << solve(n, k) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 10, M = 1e6 + 100, MOD = 1e9 + 7, ML = 25;   int a[M], ne[M];   map<int, bool> mp[M];   vector<int> ve[M], adj[M];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       adj[x].push_back(y);       adj[y].push_back(x);     }     for (int i = 1; i <= n; i++) {       adj[i].push_back(INF);       sort(adj[i].begin(), adj[i].end());       ne[i] = i + 1;     }     ne[n] = -1;     int l = 0, r = 0, cnt = 0, link = 1;     while (link != -1) {       int la = r;       a[r++] = link;       link = ne[link];       while (l < r) {         int v = a[l++];         ve[cnt].push_back(v);         int u = link, la = -1;         while (u != -1) {           int z = *lower_bound(adj[v].begin(), adj[v].end(), u);           if (z != u) {             if (u == link) link = ne[link];             if (la != -1) ne[la] = ne[u];             a[r++] = u;           } else             la = u;           u = ne[u];         }       }       cnt++;     }     printf( %d n , cnt);     for (int i = 0; i < cnt; i++) {       printf( %d  , ve[i].size());       for (int u : ve[i]) printf( %d  , u);       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   bool check(long long n, long long pos) { return (n & (1 << pos)); }   bool Set(long long n, long long pos) { return (n | (1 << pos)); }   long double LOG(long double b, long double e) { return log(b) / log(e); }   vector<int> v1[200005], v2[200005], comps[200005], vv;   vector<pair<int, int> > v;   int st[200005], en[200005], cnt = 1, level[200005], par[200005];   bitset<200005> b1, yes;   void solve() {     int n, a, b, cc;     cin >> n >> a >> b;     bool ok = 0;     cc = b * 10;     while (1) {       if (cc >= n) {         ok = 1;         break;       }       if (a) {         n /= 2;         n += 10;         --a;       }       if (cc >= n) {         ok = 1;         break;       }       if (a == 0) break;     }     ok ? cout <<  YES n  : cout <<  NO n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     t = 1;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<bool> visited;   vector<vector<int> > adj;   void dfs(int node, long long &s0, long long &s1, int mod) {     if (mod == 0)       s0++;     else       s1++;     visited[node] = true;     for (int i = 0; i < adj[node].size(); i++) {       if (!visited[adj[node][i]]) {         dfs(adj[node][i], s0, s1, (mod + 1) % 2);       }     }   }   int main() {     int t = 1;     while (t--) {       int n;       cin >> n;       adj = vector<vector<int> >(n + 1);       visited = vector<bool>(n + 1, false);       for (int i = 0; i < n - 1; i++) {         int a, b;         cin >> a >> b;         adj[a].push_back(b);         adj[b].push_back(a);       }       long long s0 = 0, s1 = 0;       dfs(1, s0, s1, 0);       cout << s0 * s1 - n + 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,popcnt,tune=native )   using namespace std;   const int MN = 3333, inf = 1000000005, mod = 1000000007;   const long long INF = 1000000000000000005LL;   bitset<MN> Z[MN];   int dist[MN][MN], X[MN], Y[MN];   inline int d2(int a, int b) {     return (X[a] - X[b]) * (X[a] - X[b]) + (Y[a] - Y[b]) * (Y[a] - Y[b]);   }   int n;   bool dasie(int x) {     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) Z[i][j] = (i != j && dist[i][j] >= x);     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j) {         if (Z[i][j] == 0) continue;         if ((Z[i] & Z[j]).count()) return true;       }     return false;   }   int bs() {     int zd = 0, zg = 1e9 + 5;     while (zd != zg) {       int mid = (zd + zg + 1) >> 1;       if (dasie(mid))         zd = mid;       else         zg = mid - 1;     }     return zd;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d%d , &X[i], &Y[i]);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) dist[i][j] = d2(i, j);     int ans = bs();     double odp = ans;     odp = sqrt(odp) / 2.0;     printf( %.9lf , odp);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, a = INT_MIN, b = INT_MIN;     cin >> n;     vector<long long int> v(n);     for (long long int i = 0; i < n; i++) {       cin >> v[i];     }     if (n == 1) {       for (int i = 0; i < 3; i++) {         cout << 1 <<     << 1 <<   n ;         cout << (-1) * v[0] <<   n ;         v[0] = 0;       }       return 0;     }     cout << 1 <<     << n - 1 <<   n ;     for (int i = 0; i < n - 1; i++) {       if (v[i] < 0) {         int a = v[i] % (n - 1);         cout << (abs(v[i]) + a * (n)) <<    ;         v[i] = (a * (n));         continue;       }       cout << v[i] * (n - 1) <<    ;       v[i] = v[i] * (n);     }     cout <<   n ;     cout << n <<     << n <<   n ;     cout << (-1) * v[n - 1] <<   n ;     v[n - 1] = 0;     cout << 1 <<     << n <<   n ;     for (int i = 0; i < n; i++) {       cout << (-1) * v[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   string to_string(pair<T1, T2> p);   template <typename T1, typename T2, typename T3>   string to_string(tuple<T1, T2, T3> tup);   template <typename T1, typename T2, typename T3, typename T4>   string to_string(tuple<T1, T2, T3, T4> tup);   string to_string(const string& v) { return  {  + v +  } ; }   string to_string(const char* v) { return to_string((string)v); }   string to_string(const bool& v) { return (v ?  True  :  False ); }   string to_string(vector<bool> v) {     string ret =  [ ;     int n = (int)v.size();     for (int i = 0; i < n - 1; i++) {       ret +=  [  + to_string(i) +  ](  + to_string(v[i]) +  ),  ;     }     ret +=  [  + to_string(n - 1) +  ](  + to_string(v[n - 1]) +  )] ;     return ret;   }   template <size_t N>   string to_string(bitset<N> b) {     string ret =   ;     for (int i = 0; i < N; i++) {       ret += (char)(b[i] +  0 );     }     return ret;   }   template <typename T>   string to_string(T v) {     bool ok = true;     string ret =  [ ;     int cnt = 0;     for (auto x : v) {       if (!ok) {         ret +=  ,  ;       }       ok = false;       ret +=  [  + to_string(cnt++) +  ](  + to_string(x) +  ) ;     }     return ret +  ] ;   }   template <typename T1, typename T2>   string to_string(pair<T1, T2> p) {     return  {  + to_string(p.first) +  ,   + to_string(p.second) +  } ;   }   template <typename T1, typename T2, typename T3>   string to_string(tuple<T1, T2, T3> tup) {     return  {  + to_string(get<0>(tup)) +  ,   + to_string(get<1>(tup)) +  ,   +            to_string(get<2>(tup)) +  } ;   }   template <typename T1, typename T2, typename T3, typename T4>   string to_string(tuple<T1, T2, T3, T4> tup) {     return  {  + to_string(get<0>(tup)) +  ,   + to_string(get<1>(tup)) +  ,   +            to_string(get<2>(tup)) +  ,   + to_string(get<3>(tup)) +  } ;   }   void DEBUG() { cerr <<   n ; }   template <typename start, typename... end>   void DEBUG(start first, end... other) {     cerr <<   |   << to_string(first);     DEBUG(other...);   }   void solve() {     int n, k;     cin >> n >> k;     if (n / 2 > k || (n == 1 && k != 0)) {       cout << -1;       return;     }     if (n == 1 && k == 0) {       cout << 1;       return;     }     int x = k - n / 2 + 1;     cout << x <<     << 2 * x <<    ;     for (long long i = 0; i < n - 2; i++) cout << 2 * x + 1 + i <<    ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a;     vector<vector<int> > gr(n + 1, a);     int any;     int th;     for (int i = 1; i <= n; i++) {       cin >> th;       if (th != 0) {         gr[i].push_back(th);         gr[th].push_back(i);       }     }     vector<int> chet(n + 1, 0);     for (int i = 1; i <= n; i++) {       if (gr[i].size() % 2 == 0) {         chet[i] = 1;         any = i;       }     }     if (n % 2 == 0) {       cout <<  NO ;     } else {       cout <<  YES n ;       queue<int> q;       q.push(any);       vector<int> dist(n + 1, 0);       vector<int> bfu(n + 1, 0);       vector<int> pred(n + 1, 0);       vector<vector<int> > next(n + 1, a);       bfu[any] = 1;       pred[any] = -1;       while (q.size() != 0) {         int v = q.front();         q.pop();         for (int i = 0; i < gr[v].size(); i++) {           if (bfu[gr[v][i]] == 0) {             pred[gr[v][i]] = v;             q.push(gr[v][i]);             bfu[gr[v][i]] = 1;             next[v].push_back(gr[v][i]);             dist[gr[v][i]] = dist[v] + 1;           }         }       }       vector<int> ans;       int maxd = dist[max_element(dist.begin(), dist.end()) - dist.begin()];       vector<int> ansu(n + 1, 0);       set<int> sss;       vector<set<int> > ch(maxd + 1, sss);       for (int i = 1; i <= n; i++) {         if (chet[i] == 1) {           ch[dist[i]].insert(i);         }       }       for (int i = ch.size() - 1; i >= 0; i--) {         for (auto j : ch[i]) {           queue<int> qq;           qq.push(j);           if (i != 0) {             if (ch[i - 1].find(pred[j]) != ch[i - 1].end()) {               ch[i - 1].erase(pred[j]);             } else {               ch[i - 1].insert(pred[j]);             }           }           while (qq.size() != 0) {             int v = qq.front();             qq.pop();             if (ansu[v] == 0) {               cout << v <<   n ;               ansu[v] = 1;               for (int jj = 0; jj < next[v].size(); jj++) {                 qq.push(next[v][jj]);               }             }           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<string> ans;   map<string, int> lo;   string s[100], V[55];   long long int n, m, k, done[100], fyes = -1;   void give() {     string T =  abcdef ;     do {       ans.push_back(T);     } while (next_permutation(T.begin(), T.end()));     for (int i = 0; i < ans.size(); i++) lo[ans[i]] = i;   }   int main() {     give();     cin >> n >> k;     for (int i = 0; i < (n - k + 1); i++) {       cin >> s[i];       if (s[i] ==  YES  && fyes == -1) fyes = i;     }     if (fyes != -1) {       for (int i = fyes, j = 0; j < k; i++, j++) V[i] = ans[j];       for (int i = fyes + 1; i < n - k + 1; i++) {         if (s[i] ==  YES ) {           V[i + k - 1] = ans[lo[V[i]] + k - 1];         } else {           V[i + k - 1] = V[i];         }       }       for (int i = 0; i < fyes; i++) V[i] = V[fyes];     } else {       for (int i = 0; i < n; i++) V[i] =  fuchka ;     }     for (int i = 0; i < n; i++) {       V[i][0] = V[i][0] +  A  -  a ;       cout << V[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int dp[1 << 23];   vector<pair<int, int> > p[23];   int a[100];   int main() {     int n, res = 1000;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       for (int j = 0; j < i; j++)         for (int k = j; k < i; k++)           if (a[j] + a[k] == a[i]) p[i].push_back(make_pair(j, k));     }     memset(dp, 125, sizeof(dp));     dp[1] = 1;     for (int i = 1; i < n; i++) {       for (int j = 0; j < (1 << (i - 1)); j++) {         int jj = j | (1 << (i - 1));         for (int k = 0; k < p[i].size(); k++) {           int a = p[i][k].first, b = p[i][k].second;           if (!(jj & (1 << a)) || !(jj & (1 << b))) continue;           int msk = jj | (1 << i);           dp[msk] = min(dp[msk], dp[jj] + 1);           for (int del = 0; del < i; del++)             if (msk & (1 << del))               dp[msk ^ (1 << del)] = min(dp[msk ^ (1 << del)], dp[jj]);         }       }     }     for (int i = 0; i < 1 << n; i++)       if ((i & (1 << (n - 1)))) res = min(res, dp[i]);     cout << (res == 1000 ? -1 : res) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = (int)1e9;   const double PI = 2 * acos(0.0);   const double eps = 1e-9;   int n, m;   vector<int> len;   vector<pair<int, int> > pos;   deque<int> ans;   vector<bool> vis;   int find(int x) {     for (int i = 0; i < (int)len.size(); ++i) {       if (len[i] == x and !vis[i]) return i;     }     return -1;   }   int main() {     cin >> n >> m;     pos = vector<pair<int, int> >(n);     len = vector<int>(m);     for (int i = 0; i < n; ++i) cin >> pos[i].first >> pos[i].second;     for (int i = 0; i < m; ++i) cin >> len[i];     if (n % 2) {       cout <<  NO n ;       return 0;     }     bool good = 0;     vis = vector<bool>(m, 0);     ans = deque<int>();     for (int i = 0; i < n; i += 2) {       int prev = (i + n - 1) % n;       int dist1 = (int)hypot(pos[prev].first - pos[i].first,                              pos[prev].second - pos[i].second);       int dist2 = (int)hypot(pos[i + 1].first - pos[i].first,                              pos[i + 1].second - pos[i].second);       int idx = find(dist1 + dist2);       if (idx != -1) {         vis[idx] = 1;         ans.push_back(idx);       } else         goto no;     }     cout <<  YES  << endl;     for (int i = 0; i < n; ++i) {       if (i % 2 == 1)         cout << -1 <<    ;       else {         cout << ans.front() + 1 <<    ;         ans.pop_front();       }     }     cout << endl;     return 0;   no:;     vis = vector<bool>(m, 0);     ans = deque<int>();     for (int i = 1; i < n; i += 2) {       int nxt = (i + n + 1) % n;       int dist1 = (int)hypot(pos[i - 1].first - pos[i].first,                              pos[i - 1].second - pos[i].second);       int dist2 = (int)hypot(pos[nxt].first - pos[i].first,                              pos[nxt].second - pos[i].second);       int idx = find(dist1 + dist2);       if (idx != -1) {         vis[idx] = 1;         ans.push_back(idx);       } else {         good = 0;         goto noo;       }     }     cout <<  YES  << endl;     for (int i = 0; i < n; ++i) {       if (i % 2 == 0)         cout << -1 <<    ;       else {         cout << ans.front() + 1 <<    ;         ans.pop_front();       }     }     cout << endl;     return 0;   noo:;     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a, i, j, sum, k;   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> a;       sum += a;       j += 1 - 2 * a;       if (j < 0) j = 0;       if (k < j) k = j;     }     if (!k) {       cout << sum - 1;     } else {       cout << sum + k;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       int a, b, c;       cin >> a >> b >> c;       int ans = (int)1e9;       int A = -1, B = -1, C = -1;       for (int cA = 1; cA <= 2 * a; cA++) {         for (int cB = cA; cB <= 2 * b; cB += cA) {           for (int i = 0; i < 2; i++) {             int cC = cB * (c / cB) + i * cB;             int res = abs(cA - a) + abs(cB - b) + abs(cC - c);             if (ans > res) {               ans = res;               A = cA;               B = cB;               C = cC;             }           }         }       }       cout << ans <<   n  << A <<     << B <<     << C <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 5;   long long ans[N];   struct person {     int t, s, f, num;     void read() { scanf( %d%d%d , &t, &s, &f); }     bool operator<(const person &b) const { return t < b.t; }   } a[N];   int n, m, X, D, sl, sr;   long long T;   multiset<pair<long long, int> > s;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) a[i].num = i, a[i].read();     sort(a + 1, a + n + 1);     T = 0;     X = 1;     D = 0;     int i = 1;     while (i <= n || !s.empty()) {       multiset<pair<long long, int> >::iterator tmp;       if (D == 1)         tmp = s.lower_bound(pair<long long, int>(X, -N));       else if (D == -1) {         tmp = s.upper_bound(pair<long long, int>(X, +N));         if (tmp == s.begin())           tmp = s.end();         else           --tmp;       } else         tmp = s.end();       if (i > n || tmp != s.end() && (tmp->first - X) * D <= a[i].t - T) {         T += (tmp->first - X) * D;         int tx = X;         X = tmp->first;         if (X < tx) {           multiset<pair<long long, int> >::iterator               beg = s.lower_bound(pair<long long, int>(X, -N)),               end = s.lower_bound(pair<long long, int>(X, +N));           for (; beg != end; beg++) sl--, sr++;         }         if (tmp->second > 0) {           s.insert(pair<long long, int>(a[tmp->second].f, -tmp->second));           if (a[tmp->second].f >= X)             sr++;           else             sl++;         } else {           ans[a[-tmp->second].num] = T;         }         if (tmp->first >= X)           sr--;         else           sl--;         s.erase(tmp);       } else {         X += (a[i].t - T) * D;         T = a[i].t;         s.insert(pair<long long, int>(a[i].s, i));         if (a[i].s >= X)           sr++;         else           sl++;         i++;       }       if (sr == 0 && sl == 0)         D = 0;       else if (sr >= sl)         D = 1;       else         D = -1;     }     for (int i = 1; i <= n; i++) printf( %I64d n , ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   int a, b, c;   int main() {     cin >> a >> b >> c;     int ans = 0;     for (int i = 0; i <= c; i += a) {       if ((c - i) % b == 0) ans++;     }     if (ans == 0)       cout <<  No ;     else       cout <<  Yes ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxint = -1u >> 2;   const double eps = 1e-6;   const int MAX = 100001;   int CA[MAX];   int CB[MAX];   int main() {     int N;     cin >> N;     int ans = N + 1;     if (N == 1 || N == 2) {       cout << 0 << endl;       return 0;     }     vector<int> A(N);     vector<int> B(N);     map<int, int> MA;     map<int, int> MB;     int half = N / 2;     if (N % 2) half += 1;     for (int i = 0; i < N; ++i) {       int a, b;       cin >> a >> b;       if (a != b) {         MB[b] = MB[b] + 1;       }       MA[a] = MA[a] + 1;       if (MA[a] >= half) {         cout << 0 << endl;         return 0;       }       if (MB[b] >= half) {         ans = min(ans, MB[b]);       }     }     for (map<int, int>::iterator itr = MA.begin(); itr != MA.end(); ++itr) {       if (itr->second + MB[itr->first] >= half) {         ans = min(ans, half - itr->second);       }     }     if (ans == N + 1) {       cout << -1 << endl;     } else       cout << ans << endl;     return 0;   }