#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, num[N], ans, q[N];
vector<int> v[N];
int check(int x) {
  int tnum = num[0] + x;
  int tot = 0, res = 0;
  for (int i = 1; i <= N - 10; i++) {
    for (int j = 0; j <= max(-1, num[i] - tnum); j++) {
      tot++;
      res += v[i][j];
    }
  }
  if (tot > x) return 0x3f3f3f3f;
  int cnt = 0;
  for (int i = 1; i <= N - 10; i++) {
    for (int j = max(0, num[i] - tnum + 1); j < num[i]; j++) {
      q[++cnt] = v[i][j];
    }
  }
  sort(q + 1, q + cnt + 1);
  for (int i = 1; i <= x - tot; i++) res += q[i];
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (!a || !b)
      num[0]++;
    else
      v[a].push_back(b), num[a]++;
  }
  int f = 1;
  for (int i = 1; i <= N - 10; i++)
    if (num[i] >= num[0]) {
      f = 0;
      break;
    }
  if (f) {
    puts("0");
    return 0;
  }
  for (int i = 1; i <= N - 10; i++) sort(v[i].begin(), v[i].end());
  int l = 1, r = n;
  ans = 0x3f3f3f3f;
  while (l <= r) {
    int ml = l + (r - l) / 3;
    int mr = r - (r - l) / 3;
    int t1 = check(ml), t2 = check(mr);
    if (t1 <= t2) {
      r = mr - 1;
      ans = min(ans, t1);
    } else
      l = ml + 1;
  }
  printf("%d\n", ans);
  return 0;
}
