func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   vector<int> v[N];   int num[N];   int q[N];   int cnt;   int check(int mid) {     int t = num[0] + mid, res = 0, tot = 0;     for (int i = 1; i <= 100000; i++) {       for (int j = 0; j <= max(-1, num[i] - t); j++) tot++, res += v[i][j];     }     if (tot > mid) return 1 << 30;     cnt = 0;     for (int i = 1; i <= 100000; i++) {       for (int j = max(0, num[i] - t + 1); j <= num[i] - 1; j++)         q[++cnt] = v[i][j];     }     sort(q + 1, q + cnt + 1);     for (int i = 1; i <= mid - tot; i++) res += q[i];     return res;   }   int main() {     int x, y;     int n;     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> y;       if (x == 0 || y == 0)         num[0]++;       else         v[x].push_back(y), num[x]++;     }     for (int i = 1; i <= 100000; i++) {       sort(v[i].begin(), v[i].end());     }     int f = 1;     for (int i = 1; i <= n; i++) {       if (num[i] >= num[0]) f = false;     }     if (f) {       puts( 0 );       return 0;     }     int l = 1, r = n;     int ans = 1 << 30;     while (l <= r) {       int mid1 = l + (r - l) / 3;       int f1 = check(mid1);       int mid2 = r - (r - l) / 3;       int f2 = check(mid2);       if (f1 <= f2)         r = mid2 - 1, ans = min(ans, f1);       else         l = mid1 + 1, ans = min(ans, f2);     }     cout << ans << endl;     return 0;   }   