#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r, ls, rs, cnt, val;
};
static struct node a[200015];
void ChangeNode(int point, int what, int how) {
  if (a[point].ls != -1) {
    if (a[a[point].ls].r >= what)
      ChangeNode(a[point].ls, what, how);
    else
      ChangeNode(a[point].rs, what, how);
  }
  a[point].cnt += how;
  a[point].val += (how * what);
}
int FindSum(int point, int K) {
  if (a[point].ls == -1) {
    return K * a[point].l;
  }
  if (a[a[point].ls].cnt < K)
    return a[a[point].ls].val + FindSum(a[point].rs, K - a[a[point].ls].cnt);
  else
    return FindSum(a[point].ls, K);
}
int main() {
  int N;
  scanf("%d", &N);
  static pair<int, int> data[200015];
  int i;
  for (i = 0; i < N; i++) {
    scanf("%d %d", &(data[i].first), &(data[i].second));
  }
  sort(data, data + N);
  int votes = 0;
  int cost = 0;
  int j;
  i = 0;
  while ((i < N) && (data[i].first == 0)) {
    votes++;
    i++;
  }
  int r = 0;
  int w = 1;
  a[r].l = 0;
  a[r].r = 10000;
  a[r].ls = -1;
  a[r].rs = -1;
  a[r].cnt = 0;
  a[r].val = 0;
  while (w > r) {
    if (a[r].r > a[r].l) {
      a[w].l = a[r].l;
      a[w].r = (a[r].l + a[r].r) / 2;
      a[w].ls = -1;
      a[w].rs = -1;
      a[w].cnt = 0;
      a[w].val = 0;
      a[r].ls = w;
      w++;
      a[w].l = a[w - 1].r + 1;
      a[w].r = a[r].r;
      a[w].ls = -1;
      a[w].rs = -1;
      a[w].cnt = 0;
      a[w].val = 0;
      a[r].rs = w;
      w++;
    }
    r++;
  }
  static pair<int, int> q[200015];
  int qc = 0;
  while (i < N) {
    j = i;
    while ((j < N) && (data[i].first == data[j].first)) j++;
    int k = j - i;
    while (i < j) {
      q[qc] = make_pair(k, data[i].second);
      qc++;
      ChangeNode(0, data[i].second, 1);
      i++;
      k--;
    }
  }
  sort(q, q + qc);
  reverse(q, q + qc);
  int pos = 0;
  int res = 2000000000;
  for (i = N; i > 0; i--) {
    while ((pos < qc) && (q[pos].first == i)) {
      ChangeNode(0, q[pos].second, -1);
      votes++;
      cost += q[pos].second;
      pos++;
    }
    int rem = i - votes;
    int temp = cost;
    if (rem > 0) {
      if (rem > a[0].cnt) continue;
      temp += FindSum(0, rem);
    }
    if (temp < res) res = temp;
  }
  printf("%d\n", res);
  return 0;
}
