#include <bits/stdc++.h>
using namespace std;
inline int Mid(int x, int y) { return (x + y) >> 1; }
struct node {
  int l, r, siz, sum;
} tree[10004 * 4];
void push_up(int id) {
  tree[id].sum = tree[(id << 1)].sum + tree[(id << 1 | 1)].sum;
  tree[id].siz = tree[(id << 1)].siz + tree[(id << 1 | 1)].siz;
}
void build(int l, int r, int id) {
  tree[id].l = l, tree[id].r = r;
  tree[id].sum = tree[id].siz = 0;
  if (l == r) return;
  int mid = Mid(l, r);
  build(l, mid, (id << 1));
  build(mid + 1, r, (id << 1 | 1));
}
void updata(int pos, int val, int id) {
  if (tree[id].l == tree[id].r) {
    tree[id].siz += val;
    tree[id].sum += pos * val;
    return;
  }
  int mid = Mid(tree[id].l, tree[id].r);
  if (pos <= mid)
    updata(pos, val, (id << 1));
  else
    updata(pos, val, (id << 1 | 1));
  push_up(id);
}
int query(int k, int id) {
  if (k <= 0) return 0;
  if (tree[id].siz <= k) {
    return tree[id].sum;
  }
  if (tree[id].l == tree[id].r) {
    return min(tree[id].siz, k) * tree[id].l;
  }
  int mid = Mid(tree[id].l, tree[id].r);
  if (tree[(id << 1)].siz <= k) {
    return tree[(id << 1)].sum + query(k - tree[(id << 1)].siz, (id << 1 | 1));
  } else
    query(k, (id << 1));
}
vector<int> a[100005], G[100005];
int n, cost, now;
int work(int x) {
  for (int i = 0; i < G[x].size(); i++) {
    cost += G[x][i];
    updata(G[x][i], -1, 1);
    now++;
  }
  int hehe = x - now;
  if (hehe <= 0) return cost;
  return cost + query(hehe, 1);
}
void input() {
  build(0, 10004, 1);
  for (int i = 0; i < 100005; i++) a[i].clear(), G[i].clear();
  for (int i = 1; i <= n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    a[u].push_back(v);
    updata(v, 1, 1);
  }
  for (int i = 1; i < 100005; i++) sort(a[i].begin(), a[i].end());
  for (int i = 0; i < 100005; i++) {
    for (int j = 0; j < a[i].size(); j++) {
      G[a[i].size() - j].push_back(a[i][j]);
    }
  }
}
int main() {
  int i, j, u, v;
  while (~scanf("%d", &n)) {
    input();
    int ans = 1e9 + 10;
    cost = 0;
    now = 0;
    for (i = n; i >= 0; i--) {
      int tmp = work(i);
      if (tmp == -1) break;
      ans = min(ans, tmp);
    }
    printf("%d\n", ans);
  }
  return 0;
}
