#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> g[100001], vc;   int judge(int x) {     vc.clear();     int need = x - g[0].size(), ans = 0;     for (int i = 1; i < 100001; i++) {       for (int j = 0; j < g[i].size(); j++) {         if (g[i].size() - j >= x) {           need--;           ans += g[i][j];         } else           vc.push_back(g[i][j]);       }     }     sort(vc.begin(), vc.end());     for (int i = 0; i < need; i++) ans += vc[i];     return ans;   }   int main() {     scanf( %d , &n);     int a, b;     for (int i = 0; i < n; i++) {       scanf( %d%d , &a, &b);       g[a].push_back(b);     }     for (int i = 1; i < 100001; i++) {       sort(g[i].begin(), g[i].end());     }     int l = g[0].size(), r = n;     while (l < r) {       int mid = (l + l + r) / 3, mmid = (l + r + r) / 3;       if (judge(mid) > judge(mmid)) {         if (l == mid)           break;         else           l = mid;       } else {         if (r == mmid)           break;         else           r = mmid;       }     }     int ans = 0x3f3f3f3f;     for (int i = l; i <= r; i++) ans = min(ans, judge(i));     printf( %d n , ans);   }   