#include <bits/stdc++.h>
using namespace std;
const int kMx = 100005;
const int kInf = 2000000001;
vector<int> cst[kMx];
int get_cost(int sz) {
  int ret = 0, done = 0;
  vector<int> v;
  for (int i = 0; i < kMx; ++i) {
    for (int j = 0; j < cst[i].size(); ++j) {
      if (j >= sz - 1) {
        ret += cst[i][j];
        ++done;
      } else {
        v.push_back(cst[i][j]);
      }
    }
  }
  sort(v.begin(), v.end());
  if (done > sz) {
    return kInf;
  }
  int id = 0;
  while (done != sz) {
    ret += v[id];
    ++done;
    ++id;
  }
  return ret;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    cst[a].push_back(b);
  }
  for (int i = 0; i < kMx; ++i) {
    sort(cst[i].begin(), cst[i].end());
    reverse(cst[i].begin(), cst[i].end());
  }
  int lb = 0, ub = n;
  while (ub - lb > 10) {
    int c1 = get_cost((2 * lb + ub) / 3);
    int c2 = get_cost((2 * ub + lb) / 3);
    if (c1 == kInf) {
      lb = (2 * lb + ub) / 3;
    } else if (c1 < c2) {
      ub = (2 * ub + lb) / 3;
    } else {
      lb = (2 * lb + ub) / 3;
    }
  }
  int ret = kInf;
  for (int i = lb; i <= ub; ++i) {
    ret = min(ret, get_cost(i));
  }
  cout << ret << endl;
  return 0;
}
