#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<long long> p[100010], vec;
long long check(int vt) {
  long long ans = 0;
  int need = vt - p[0].size();
  vec.clear();
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < p[i].size(); j++) {
      if (p[i].size() - j >= vt) {
        ans += p[i][j];
        need--;
      } else {
        vec.push_back(p[i][j]);
      }
    }
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < need; i++) {
    ans += vec[i];
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  m = 0;
  for (int i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    p[a].push_back(b);
    m = max(a, m);
  }
  for (int i = 1; i <= m; i++) sort(p[i].begin(), p[i].end());
  int l = 0, r = n;
  while (r - l > 1) {
    int mid = (l + r) >> 1, nmid = (mid + r) >> 1;
    if (check(mid) > check(nmid)) {
      l = mid;
    } else {
      r = nmid;
    }
  }
  cout << check(r) << "\n";
}
