#include <bits/stdc++.h>
using namespace std;
vector<long long> s[100005];
vector<long long> v;
int mmax;
long long cost(int h) {
  v.clear();
  long long ct = 0;
  int res = h - s[0].size();
  for (int i = 1; i <= mmax; i++) {
    for (int j = 0; j < s[i].size(); j++) {
      if (s[i].size() - j >= h) {
        res--;
        ct += s[i][j];
      } else {
        v.push_back(s[i][j]);
      }
    }
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < res; i++) ct += v[i];
  return ct;
}
int main() {
  int n;
  scanf("%d", &n);
  mmax = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    long long b;
    scanf("%d%lld", &a, &b);
    s[a].push_back(b);
    mmax = max(mmax, a);
  }
  for (int i = 0; i <= mmax; i++) sort(s[i].begin(), s[i].end());
  int l = 0, r = n;
  while (l + 1 < r) {
    int q1 = (l + r) / 2;
    int q2 = (r + q1) / 2;
    if (cost(q1) > cost(q2))
      l = q1;
    else
      r = q2;
  }
  cout << cost(r) << endl;
  return 0;
}
