#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int mod = 1000000000 + 7;
const double eps = 1e-6;
struct node {
  int id, v;
} a[maxn];
bool cmp(const node &a, const node &b) { return a.v < b.v; }
int n, cnt[maxn], t[maxn];
bool use[maxn];
int check(int x) {
  memcpy(t, cnt, sizeof(t));
  memset(use, 0, sizeof(use));
  int res = 0;
  for (int i = 1; i <= n; i++) {
    if (t[a[i].id] >= x) {
      res += a[i].v;
      t[0]++;
      t[a[i].id]--;
      use[i] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (t[0] < x && !use[i]) {
      res += a[i].v;
      t[0]++;
      t[a[i].id]--;
      use[i] = 1;
    }
  }
  return res;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].id >> a[i].v;
    cnt[a[i].id]++;
  }
  sort(a + 1, a + 1 + n, cmp);
  int l = 0, r = 100000;
  while ((r - l) >= 3) {
    int del = (r - l) / 3;
    if (check(l + del) <= check(r - del))
      r = r - del;
    else
      l = l + del;
  }
  int ans = 2e9;
  for (int i = l; i <= r; i++) ans = min(ans, check(i));
  cout << ans << endl;
  return 0;
}
