#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5 + 10;
const long long mod = 1e9 + 7;
int n;
vector<int> vec[mx];
vector<int> v;
int ok(int x) {
  v.clear();
  int cost = 0;
  int now = vec[0].size();
  for (int i = 1; i <= 100000; ++i) {
    for (int j = 0; j < vec[i].size(); ++j) {
      if (j < (int)vec[i].size() - x) {
        cost += vec[i][j];
        ++now;
      } else {
        v.push_back(vec[i][j]);
      }
    }
  }
  if (now <= x) {
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); ++i) {
      cost += v[i];
      ++now;
      if (now > x) break;
    }
    if (now <= x) return 0x3f3f3f3f + x;
  }
  return cost;
}
int main() {
  int a, b;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &a, &b);
    vec[a].push_back(b);
  }
  for (int i = 1; i <= 100000; ++i) sort(vec[i].begin(), vec[i].end());
  int l = 0;
  int r = 1e5;
  while (l + 3 <= r) {
    int lmid = l + (r - l) / 3, rmid = r - (r - l) / 3;
    if (ok(lmid) <= ok(rmid)) {
      r = rmid;
    } else {
      l = lmid;
    }
  }
  int minn = 0x3f3f3f3f;
  for (int i = l; i <= r; ++i) {
    minn = min(minn, ok(i));
  }
  printf("%d\n", minn);
}
