#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
int a[100005];
struct piao {
  int num;
  int id;
} b[100005];
int n;
int cmp(piao A, piao B) { return A.num < B.num; }
vector<int> s[100005];
long long cha(int k) {
  long long res = 0;
  int nums = 0;
  k += s[0].size();
  if (k == 0) {
    return 0x3f3f3f3f3f3f3f;
  }
  for (int i = 100000; i >= 1; i--) {
    if (b[i].num < k) {
      break;
    }
    for (int j = 0; j <= b[i].num - k; j++) {
      res += s[b[i].id][j];
      nums++;
    }
  }
  if (nums > k - s[0].size()) {
    return 0x3f3f3f3f3f3f3f;
  }
  int num2 = 0;
  for (int i = 1; i <= 100000; i++) {
    int ks = s[i].size();
    for (int j = max(0, ks - k + 1); j < s[i].size(); j++) {
      a[num2] = s[i][j];
      num2++;
    }
  }
  sort(a, a + num2);
  for (int i = 0; i < k - s[0].size() - nums; i++) {
    res += a[i];
  }
  return res;
}
int main() {
  scanf("%d", &n);
  long long ans = 0x3f3f3f3f3f3f3f3f;
  for (int i = 1; i <= n; i++) {
    int k;
    int m;
    scanf("%d%d", &k, &m);
    s[k].push_back(m);
  }
  for (int i = 1; i <= 100000; i++) {
    sort(s[i].begin(), s[i].end());
    b[i].num = s[i].size();
    b[i].id = i;
  }
  sort(b + 1, b + 100001, cmp);
  int l = 0;
  int r = 100005;
  while (l <= r) {
    int lmid = l + (r - l) / 3;
    int rmid = r - (r - l) / 3;
    if (cha(lmid) > cha(rmid)) {
      l = lmid + 1;
      ans = min(ans, cha(rmid));
    } else {
      r = rmid - 1;
      ans = min(ans, cha(lmid));
    }
  }
  printf("%lld\n", ans);
  return 0;
}
