malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n, a[200005], b[200005];     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     cin >> m;     for (int i = 0; i < m; i++) cin >> b[i];     sort(a, a + n);     sort(b, b + m);     int x = 0, y = 0;     int ans;     int aa = (x * 2 + (n - x) * 3), bb = (y * 2 + (m - y) * 3);     int max = aa - bb;     for (int i = 0; i < m + n; i++) {       if (a[x] == b[y]) {         x++;         while (a[x - 1] == a[x] && x != n) x++;         y++;         while (b[y - 1] == b[y] && y != m) y++;       } else if (a[x] < b[y]) {         x++;         while (a[x - 1] == a[x] && x != n) x++;       } else {         y++;         while (b[y - 1] == b[y] && y != m) y++;       }       ans = (x * 2 + (n - x) * 3) - (y * 2 + (m - y) * 3);       if (ans > max) {         max = ans;         aa = (x * 2 + (n - x) * 3);         bb = (y * 2 + (m - y) * 3);       }       if (x == n || y == m) break;       i = x + y;     }     ans = n * 2 - m * 2;     if (ans > max) {       max = ans;       aa = n * 2;       bb = m * 2;     }     printf( %d:%d , aa, bb);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100500];   int p[100500];   int q[100500];   vector<pair<int, int> > moves;   int n, h = -1;   bool asign(int x, int y) { return a[x] < a[y]; }   bool happy(int n) {     if (n == 0) return true;     if (n % 10 == 7 || n % 10 == 4) return happy(n / 10);     return false;   }   void move(int x, int y) {     if (x == y) return;     moves.push_back(make_pair(x + 1, y + 1));     swap(q[x], q[y]);     p[q[x]] = x;     p[q[y]] = y;     if (h == x)       h = y;     else if (h == y)       h = x;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       p[i] = i;       if (happy(a[i])) h = i;     }     sort(p, p + n, asign);     if (h == -1) {       for (int i = 0; i < n - 1; ++i)         if (a[i] > a[i + 1]) {           printf( -1 n );           return 0;         }       printf( 0 n );       return 0;     }     for (int i = 0; i < n; ++i) q[p[i]] = i;     for (int i = 0; i < n; ++i) {       if (p[i] == h) continue;       move(i, h);       move(h, p[i]);     }     printf( %d n , (int)moves.size());     for (int i = 0; i < moves.size(); ++i)       printf( %d %d n , moves[i].first, moves[i].second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void wait(double seconds) {     double endtime = clock() + (seconds * CLOCKS_PER_SEC);     while (clock() < endtime) {       ;     }   }   inline int fastIn() {     register char c = 0;     register int a = 0;     while (c < 33) c = getchar();     while (c > 33) {       a = (a * 10) + (c -  0 );       c = getchar();     }     return a;   }   int tour_count;   int win_need;   int bag_cap;   const int mx = 210;   struct NODE {     double p;     double np;     int w;     NODE(int p = 0, int np = 0, int w = 0) : p(p), np(np), w(w) {}     bool operator<(const NODE &r) const { return this->w > r.w; }   };   NODE vi[mx];   inline void read() {     scanf( %d %d %d , &tour_count, &win_need, &bag_cap);     for (int i = 0, j1 = tour_count; i < j1; ++i) {       int tmp = fastIn();       vi[i].p = (double)tmp / (double)100;       vi[i].np = (double)1 - vi[i].p;     }     for (int i = 0, j1 = tour_count; i < j1; ++i) {       scanf( %d , &vi[i].w);     }   }   struct data {     bool f;     double v;     data(bool f = false, double v = 0) : f(f), v(v) { ; }   };   double dp[200][200][201];   bool vis[200][200][201];   double go(int at, int win, int cap) {     if (cap < 0) return (double)0;     if (at >= tour_count) {       return win >= win_need ? (double)1 : (double)0;     }     if (vis[at][win][cap]) return dp[at][win][cap];     vis[at][win][cap] = true;     double v1 = vi[at].p * go(at + 1, win + 1, min(cap + vi[at].w, 200));     double v2 = vi[at].np * go(at + 1, win, cap);     return dp[at][win][cap] = (v1 + v2);   }   inline void proc() {     memset(vis, false, sizeof(vis));     sort(vi, vi + tour_count);     double res = go(0, 0, bag_cap);     printf( %.9lf n , res);   }   int main() {     int kase = 1;     for (int i = 0, j1 = kase; i < j1; ++i) {       read();       proc();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[6];     for (int i = 0; i < 6; i++) {       cin >> a[i];     }     int ans = (a[0] + a[1] + a[2]) * (a[0] + a[1] + a[2]) - a[0] * a[0] -               a[2] * a[2] - a[4] * a[4];     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int x, int y) {     if (x == 0)       return y;     else       return gcd(y % x, x);   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   bool sortbysize(string &s1, string &s2) { return s1.size() < s2.size(); }   bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {     return (a.first > b.first);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n, k, a, b, i, x, cnt = 0;     cin >> n >> k;     vector<pair<int, int>> v;     map<int, int> mp;     while (n--) {       cin >> a >> b;       v.push_back(make_pair(a, b));       mp[a]++;     }     sort(v.begin(), v.end(), sortinrev);     for (i = 0; i < v.size();) {       if (mp[v[i].first] > 1) {         sort(v.begin() + i, v.begin() + i + mp[v[i].first], sortbysec);       }       i += mp[v[i].first];     }     for (i = 0; i < v.size(); i++) {       if (v[i].second == v[k - 1].second && v[i].first == v[k - 1].first) cnt++;     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const int inf = 1000000007;   const long long linf = 1LL << 62;   const unsigned long long ulinf = 1ULL << 63;   const double eps = 0.000001;   const double pi = 3.14159265358979323846;   template <class T>   T abs(T a) {     return a >= 0 ? a : -a;   }   template <class T>   T sqr(T a) {     return a * a;   }   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <class T>   T mod(T a, T b) {     return (a % b + b) % b;   }   long long powmod(long long a, long long b, long long c) {     if (b == 0LL) return 1LL;     long long ret = powmod(a, b >> 1, c);     ret = ret * ret % c;     if (b & 1LL) ret = ret * a % c;     return ret;   }   long long inv(long long a, long long b) { return powmod(a, b - 2LL, b); }   template <class T>   void maxe(T &a, T b) {     if (a < b) a = b;   }   template <class T>   void mine(T &a, T b) {     if (a > b) a = b;   }   int iszero(double a) { return abs(a) <= eps; }   template <class T>   void geti(T &a) {     a = 0;     T b = 1;     char c = getchar();     if (c ==  - )       b = -1;     else       a = c - 48;     while ((c = getchar()) !=     && c !=   n ) a = a * 10 + c - 48;     a *= b;   }   void fileio_in_out() {     freopen( .in ,  r , stdin);     freopen( .out ,  w , stdout);   }   void fileio_txt() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   const int N = 222222;   const int M = 1111111;   const int K = 20;   int test;   int n, m, k, ans;   char s[11];   int main() {     scanf( %d , &test);     while (test--) {       vector<pair<int, int> > v;       for (int i = 0; i < 8; i++) {         scanf( %s , s);         for (int j = 0; j < 8; j++)           if (s[j] ==  K ) v.push_back(make_pair(i, j));       }       ans = ((v[0].first - v[1].first) % 4 == 0) &&             ((v[0].second - v[1].second) % 4 == 0);       puts(ans ?  YES  :  NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k;     int n;     cin >> n;     long arr[n][2];     for (i = 0; i < n; i++) cin >> arr[i][0] >> arr[i][1];     long long minx, miny, maxx, maxy;     minx = arr[0][0];     miny = arr[0][1];     maxx = arr[0][0];     maxy = arr[0][1];     for (i = 0; i < n; i++) {       if (minx > arr[i][0]) minx = arr[i][0];       if (miny > arr[i][1]) miny = arr[i][1];       if (maxx < arr[i][0]) maxx = arr[i][0];       if (maxy < arr[i][1]) maxy = arr[i][1];     }     long long l1, l2;     l1 = (maxx - minx);     l2 = (maxy - miny);     if (l1 > l2)       cout << l1 * l1;     else       cout << l2 * l2;   }
#include <bits/stdc++.h>   using namespace std;   void __print(long long x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     long long f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   const long long N = 2e5 + 4;   const long long mod = 1e9 + 7;   void solve() {     long long n;     cin >> n;     string a, b;     cin >> a >> b;     long long ans = 0;     for (long long i = 0; i < n / 2; i++) {       if (a[i] == a[n - i - 1] and b[i] == b[n - i - 1]) continue;       if (a[i] == b[i] and a[n - i - 1] == b[n - i - 1]) continue;       if (a[i] == b[n - i - 1] and b[i] == a[n - i - 1]) continue;       bool f = 0, f2 = 0;       if (b[i] == b[n - i - 1]) {         ans++;         continue;       }       if (a[i] != b[i] and a[n - i - 1] != b[n - i - 1]) {         f = 1;       }       if (a[i] != b[n - i - 1] and b[i] != a[n - i - 1]) {         f2 = 1;       }       if (f and f2) {         ans += 2;       } else {         ans++;       }     }     if (a[n / 2] != b[n / 2] and n & 1) {       ans++;     }     cout << ans;   }   int32_t main() {     long long tt;     tt = 1;     for (long long t = 1; t <= tt; t++) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const long long md = 1e9 + 7;   const long double eps = 1e-8;   struct frac {     long long x, y;     frac() {}     frac(long long x, long long y) : x(x), y(y) {}     bool operator==(const frac& ot) { return x * ot.y == y * ot.x; }     bool operator<(const frac& ot) { return x * ot.y < y * ot.x; }   };   vector<int> tr;   int sz = 1;   void add(int v, int val) {     v += sz - 1;     tr[v] += val;     while (v) {       v = (v - 1) >> 1;       tr[v] += val;     }     return;   }   int get(int v, int l, int r, int bg, int en) {     if (bg >= r || l >= en) {       return 0;     }     if (l >= bg && r <= en) {       return tr[v];     }     int m = (l + r) >> 1;     return get(2 * v + 1, l, m, bg, en) + get(2 * v + 2, m, r, bg, en);   }   int main() {     iostream::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int n;     long long w;     cin >> n >> w;     vector<long long> v(n), x(n);     for (int i = 0; i < n; i++) {       cin >> x[i] >> v[i];     }     vector<frac> f1(n), f2(n);     for (int i = 0; i < n; i++) {       f1[i] = {-x[i], v[i] + w};       if (f1[i].y < 0) {         f1[i].x = -f1[i].x;         f1[i].y = -f1[i].y;       }       f2[i] = {-x[i], v[i] - w};       if (f2[i].y < 0) {         f2[i].x = -f2[i].x;         f2[i].y = -f2[i].y;       }     }     vector<int> all(n);     for (int i = 0; i < n; i++) {       all[i] = i;     }     vector<int> F2(n);     sort(all.begin(), all.end(), [&](int a, int b) { return f2[a] < f2[b]; });     F2[all[0]] = 0;     for (int i = 1; i < n; i++) {       F2[all[i]] = F2[all[i - 1]] + !(f2[all[i]] == f2[all[i - 1]]);     }     sort(all.begin(), all.end(), [&](int a, int b) {       if (f1[a] < f1[b]) {         return true;       }       if (f1[b] < f1[a]) {         return false;       }       return F2[b] < F2[a];     });     while (sz < n) {       sz <<= 1;     }     tr.resize(2 * sz - 1, 0);     long long ans = 0;     for (int i : all) {       ans += get(0, 0, sz, F2[i], n);       add(F2[i], 1);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, c;     cin >> n >> m >> c;     vector<int> A(n), B(m);     for (auto &a : A) cin >> a;     for (auto &b : B) cin >> b;     int i = 0, x = 0;     for (int i = 0; i < n; ++i) {       if (i < m) x = (x + B[i]) % c;       if (i > n - m) x = (x - B[i - n + m - 1] + c) % c;       A[i] = (A[i] + x) % c;     }     for (auto a : A) cout << a <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500010;   int n, m;   struct edge {     int a, b, c, t;   } e[N];   inline bool operator<(const edge &a, const edge &b) { return a.c < b.c; }   struct union_find {     int f[N], h[N], sz[N], cnt;     struct oper {       int x, fx, hx, szx, tc;     } op[N * 2];     int l;     void init() {       l = 0, cnt = n;       for (int i = 1; i <= n; i++) f[i] = i, h[i] = 0, sz[i] = 1;     }     int find(int x) { return f[x] == x ? x : find(f[x]); }     void rewind(int t) {       for (int i = l; i >= t + 1; i--) {         int x = op[i].x;         f[x] = op[i].fx, h[x] = op[i].hx;         sz[x] = op[i].szx;         cnt = op[i].tc;       }       l = t;     }     void merge(int a, int b) {       int fa = find(a), fb = find(b);       if (fa != fb) {         if (h[fa] > h[fb]) swap(fa, fb);         op[++l] = (oper){fa, f[fa], h[fa], sz[fa], cnt},         op[++l] = (oper){fb, f[fb], h[fb], sz[fb], cnt};         if (sz[fa] && sz[fb]) cnt -= 2;         f[fa] = fb;         h[fb] = max(h[fb], h[fa] + 1);         sz[fb] ^= sz[fa];       }     }   } T;   int j = 1, ans[N];   vector<int> ed[N << 2];   namespace seg {   int a, b, c;   void add(int x, int l, int r) {     if (a <= l && r <= b)       ed[x].push_back(c);     else {       if (a <= ((l + r) >> 1)) add((x << 1), l, ((l + r) >> 1));       if (b > ((l + r) >> 1)) add(((x << 1) | 1), ((l + r) >> 1) + 1, r);     }   }   }  // namespace seg   void solve(int x, int l, int r) {     int len = ed[x].size(), l0 = T.l;     for (int i = 0; i < len; i++) T.merge(e[ed[x][i]].a, e[ed[x][i]].b);     if (l == r) {       ans[l] = ans[l + 1];       while (j <= m && T.cnt) {         if (e[j].t <= l) {           seg::a = e[j].t, seg::b = l - 1, seg::c = j;           if (seg::a <= seg::b) seg::add(1, 1, m);           T.merge(e[j].a, e[j].b);           ans[l] = e[j].c;         }         j++;       }       if (T.cnt) ans[l] = -1;     } else       solve(((x << 1) | 1), ((l + r) >> 1) + 1, r),           solve((x << 1), l, ((l + r) >> 1));     T.rewind(l0);   }   int main() {     scanf( %d%d , &n, &m);     T.init();     for (int i = 1; i <= m; i++)       scanf( %d%d%d , &e[i].a, &e[i].b, &e[i].c), e[i].t = i;     sort(e + 1, e + m + 1);     solve(1, 1, m);     for (int i = 1; i <= m; i++) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int a[500005], b[500005];   int main() {     int i, j, k, l, x, y, z, m, n, t;     cin >> t;     while (t--) {       cin >> x >> y >> z;       while (x > 20 && y) {         x = x / 2;         x += 10;         y--;       }       while (x >= 0 && z) {         x = x - 10;         z--;       }       x = max(0, x);       if (x)         cout <<  NO  << endl;       else         cout <<  YES  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     float a, b, c, t;     cin >> a >> b;     if (a > b) swap(a, b);     c = (b - a) / 2;     t = floor(c);     c = ceil(c);     int f = 0, y = 0;     for (int i = 1; i <= c; i++) {       f += i;     }     for (int i = 1; i <= t; i++) {       y += i;     }     cout << f + y;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     map<long long, long long> cn;     set<long long> fac;     while (t--) {       fac.clear();       cn.clear();       long long n;       cin >> n;       long long temp = n;       for (long long i = 2; i * i <= n; i++) {         while (n % i == 0) {           cn[i]++;           n /= i;           fac.insert(i);         }       }       if (n > 1) cn[n]++, fac.insert(n);       n = temp;       if (fac.size() >= 3) {         cout <<  YES n ;         long long a = *fac.begin(), b = *(++fac.begin());         cout << a <<     << b <<     << n / (a * b) <<   n ;         continue;       } else if (fac.size() == 1 && cn[*(fac.begin())] >= 6) {         cout <<  YES n ;         cout << *(fac.begin()) <<     << (*(fac.begin())) * (*(fac.begin()))              <<                  << n / ((*(fac.begin())) * (*(fac.begin())) * (*(fac.begin())))              <<   n ;         continue;       }       if (fac.size() == 2) {         long long a, ac, b, bc;         a = *(fac.begin());         ac = cn[*(fac.begin())];         b = *(++fac.begin());         bc = cn[*(++fac.begin())];         if (ac + bc >= 4) {           cout <<  YES n ;           cout << a <<     << b <<     << n / (a * b) <<   n ;           continue;         }       }       cout <<  NO n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long int a[200005];   long long int dist[200005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int n;     cin >> n;     for (long long int i = 0; i < n; i++) dist[i] = INT_MAX;     for (long long int i = 0; i < n; i++) cin >> a[i];     long long int m = INT_MAX;     for (long long int i = 0; i < n; i++) {       if (a[i] == 0) {         m = i;         dist[i] = 0;       }       if (m == INT_MAX) {         dist[i] = INT_MAX;         continue;       }       dist[i] = min(dist[i], i - m);     }     m = INT_MAX;     for (long long int i = n - 1; i > -1; i--) {       if (a[i] == 0) {         m = i;         dist[i] = 0;       }       dist[i] = min(dist[i], m - i);     }     for (long long int i = 0; i < n; i++) cout << dist[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimization( O3 )   using namespace std;   template <typename T>   inline void Cin(T& first) {     char c;     T sign = 1;     first = 0;     for (c = getchar(); c <  0  || c >  9 ; c = getchar())       if (c ==  - ) sign = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) first = first * 10 + c -  0 ;     first *= sign;   }   template <typename T>   inline void Out(T first) {     if (first > 9) Out(first / 10);     putchar(first % 10 +  0 );   }   template <typename T>   inline void Cout(T first, char c) {     if (first < 0) putchar( - );     first = abs(first);     Out(first);     putchar(c);   }   template <typename T, typename... Args>   inline void Cin(T& a, Args&... args) {     Cin(a);     Cin(args...);   }   template <typename T, typename... Args>   inline void Cout(T a, char c, Args... args) {     Cout(a, c);     Cout(args...);   }   const int N = 5002;   const int M = int(5e5) + 2;   const long long oo = (long long)1e10;   int n, k, _a[M], cur[3];   vector<long long> f[3];   struct TIrene {     int first, i;     bool operator<(const TIrene& o) const& { return i < o.i; }   } a[M];   void Enter() {     cin >> k >> n;     for (int i = 0; i < n; ++i) cin >> _a[i];     sort(_a, _a + n);     for (int i = 0; i < n; ++i) {       if (i) a[i].first = _a[i] - _a[i - 1];       a[i].i = i;     }     sort(a + 1, a + n, [](const TIrene& a, const TIrene& b) {       if (a.first != b.first) return a.first < b.first;       return a.i > b.i;     });     n = min(n, 3 * k);     sort(a + 1, a + n);   }   void Solve() {     for (int i = 0; i < 3; ++i) {       f[i].resize(k + 1);       fill(f[i].begin(), f[i].end(), oo);       cur[i] = i;     }     for (int i = 1; i < n; ++i) {       if (i - 1)         f[cur[2]][1] = min(f[cur[1]][1], (long long)a[i].first);       else         f[cur[2]][1] = a[1].first;       for (int j = 2, l = min(k, i); j <= l; ++j) {         if (a[i].i > a[i - 1].i + 1)           f[cur[2]][j] = min(f[cur[1]][j], f[cur[1]][j - 1] + a[i].first);         else           f[cur[2]][j] = min(f[cur[1]][j], f[cur[0]][j - 1] + a[i].first);       }       int t = cur[0];       cur[0] = cur[1], cur[1] = cur[2], cur[2] = t;     }     cout << f[cur[1]][k];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     if (fopen( test                 .inp ,                r )) {       freopen(            test             .inp ,            r , stdin);       freopen(            test             .out ,            w , stdout);     }     Enter(), Solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[300005], ans;   int n, num[300005], cnt[2] = {1}, sum[300005];   int change(long long x) {     int ans = 0;     while (x) {       ans += (x % 2);       x /= 2;     }     return ans;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       num[i] = change(a[i]);       sum[i] = sum[i - 1] + num[i];       ans += cnt[sum[i] % 2];       int maxn = 0;       for (int j = i, k = i + 1; j >= 1 && j >= i - 64; j--) {         while (k > j) {           k--;           maxn = max(maxn, num[k]);         }         if (maxn * 2 > sum[i] - sum[j - 1] && (sum[i] - sum[j - 1]) % 2 == 0)           ans--;       }       cnt[sum[i] % 2]++;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100000;   const int MAX_E2 = 1 << 18;   const int MAX_A = 100000;   const int INF = 1 << 30;   int uas[MAX_N];   pair<int, int> ps[MAX_N], cns[MAX_A];   vector<int> cvs[MAX_A];   bool used[MAX_A];   int check(int m, int uan, int c0, int x) {     memset(used, false, sizeof(used));     int c = c0, sum = 0;     for (int i = uan - 1; i >= 0 && cns[i].first > x; i--) {       vector<int> &cv = cvs[cns[i].second];       int maxj = cns[i].first - x;       for (int j = 0; j < maxj; j++)         sum += ps[cv[j]].first, c++, used[cv[j]] = true;     }     for (int i = 0; i < m && c <= x; i++)       if (!used[i]) sum += ps[i].first, c++;     return (c > x) ? sum : INF;   }   int main() {     int n;     scanf( %d , &n);     int m = 0, c0 = 0;     for (int i = 0; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       if (!a)         c0++;       else {         a--;         uas[m] = a;         ps[m++] = pair<int, int>(b, a);       }     }     sort(uas, uas + m);     int uan = unique(uas, uas + m) - uas;     for (int i = 0; i < m; i++) {       int ai = lower_bound(uas, uas + uan, ps[i].second) - uas;       ps[i].second = ai;     }     sort(ps, ps + m);     for (int i = 0; i < m; i++) cvs[ps[i].second].push_back(i);     for (int i = 0; i < uan; i++) cns[i] = pair<int, int>(cvs[i].size(), i);     sort(cns, cns + uan);     int x0 = 0, x1 = cns[uan - 1].first;     while (x0 + 2 < x1) {       int xx0 = (x0 * 2 + x1) / 3;       int xx1 = (x0 + x1 * 2) / 3;       int sum0 = check(m, uan, c0, xx0);       int sum1 = check(m, uan, c0, xx1);       if (sum0 >= sum1)         x0 = xx0;       else         x1 = xx1;     }     int minsum = INF;     for (int x = x0; x <= x1; x++) {       int sum = check(m, uan, c0, x);       if (minsum > sum) minsum = sum;     }     printf( %d n , minsum);     return 0;   }