#include <bits/stdc++.h>
using namespace std;
vector<int> v[100005];
int m, cnt;
int Judge(const int num) {
  int cost = 0, need = num - cnt;
  vector<int> vote;
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < v[i].size(); j++) {
      if (num > v[i].size() - j)
        vote.push_back(v[i][j]);
      else {
        cost += v[i][j];
        need--;
      }
    }
  }
  if (need <= 0) return cost;
  sort(vote.begin(), vote.end());
  for (int i = 0; i < need; i++) cost += vote[i];
  return cost;
}
int main(void) {
  int n, cost = 0, L, R;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (a == 0 && b == 0)
      cnt++;
    else
      v[a].push_back(b);
    if (m < a) m = a;
  }
  for (int i = 1; i <= m; i++) sort(v[i].begin(), v[i].end());
  for (L = 0, R = n; R - L > 2;) {
    int midL = ((L << 1) + R) / 3, midR = (L + (R << 1)) / 3;
    if (Judge(midL) > Judge(midR))
      L = midL;
    else
      R = midR;
  }
  printf("%d", min(Judge((L + R) >> 1), min(Judge(L), Judge(R))));
  return 0;
}
