#include <bits/stdc++.h>
using namespace std;
int n;
multiset<int> gub[100003];
int good;
int a[100003];
int tem[100003];
int siz;
void mergesort(int *a, int *b, int n) {
  int i, i0, i1, iRight, iEnd, width, j;
  for (width = 1; width < n; width *= 2)
    for (i = 0; i + width < n; i += width * 2) {
      i0 = i;
      i1 = iRight = i + width;
      iEnd = min(i + width * 2, n);
      for (j = i; i0 < iRight; j++)
        if (i1 == iEnd || a[i0] < a[i1])
          b[j] = a[i0++];
        else
          b[j] = a[i1++];
      for (j = i; j < i1; j++) a[j] = b[j];
    }
}
int f(int x) {
  int res = 0;
  int chel = good;
  set<int>::iterator it;
  siz = 0;
  for (int i = 1; i <= 100000; i++) {
    int coun = gub[i].size();
    for (it = gub[i].begin(); coun >= x; it++) {
      res += *it;
      chel++;
      coun--;
    }
    while (it != gub[i].end()) {
      a[siz++] = *it;
      it++;
    }
  }
  mergesort(a, tem, siz);
  for (int i = 0; i < x - chel; i++) res += a[i];
  return res;
}
int main() {
  scanf("%d", &n);
  int i;
  int x, y;
  for (i = 0; i < n; i++) {
    scanf("%d %d", &x, &y);
    if (x == 0)
      good++;
    else
      gub[x].insert(y);
  }
  int l, r, re, m1, m2;
  l = 1;
  r = n;
  while (r - l > 3) {
    m1 = l + (r - l) / 3;
    m2 = r - (r - l) / 3;
    if (f(m1) < f(m2))
      r = m2;
    else
      l = m1;
  }
  int mini = 2000000000;
  for (i = l; i <= r; i++) mini = min(mini, f(i));
  printf("%d\n", mini);
  return 0;
}
