#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
vector<long long> v[N];
int m;
long long check(int x) {
  int need = x - v[0].size();
  long long res = 0;
  vector<long long> f;
  for (int i = 1; i <= m; i++)
    for (int j = 0; j < v[i].size(); j++) {
      if (v[i].size() - j >= x) {
        res += v[i][j];
        --need;
      } else
        f.push_back(v[i][j]);
    }
  sort(f.begin(), f.end());
  for (int k = 0; k < need; k++) res += f[k];
  return res;
}
int main() {
  int n, a;
  long long b;
  while (cin >> n) {
    for (int i = 0; i <= m; i++) {
      v[i].clear();
    }
    m = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a >> b;
      m = max(m, a);
      v[a].push_back(b);
    }
    for (int i = 1; i <= m; i++) sort(v[i].begin(), v[i].end());
    int l = 0, r = n;
    while (l + 1 < r) {
      int ml = (l + r) >> 1;
      int mr = (ml + r) >> 1;
      if (check(ml) > check(mr))
        l = ml;
      else
        r = mr;
    }
    printf("%d\n", check(r));
  }
  return 0;
}
