#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100001;
const long long MOD = 998244353;
const int MAXL = 8000100;
const long long INF = 1e18;
int N, a, b, c;
vector<long long> V[MAXN];
int R;
long long ans;
priority_queue<pair<long long, long long> > pq;
struct node {
  int second, e, m, v, c;
  node *l, *r;
  node(int _s, int _e) : second(_s), e(_e), v(0), c(0) {
    m = (second + e) / 2;
    if (second != e) {
      l = new node(second, m);
      r = new node(m + 1, e);
    }
  }
  void ins(int x, int t) {
    assert(x <= e && x >= second);
    if (second == e) {
      c += t;
      v += t * x;
      return;
    }
    if (x <= m)
      l->ins(x, t);
    else
      r->ins(x, t);
    v = l->v + r->v;
    c = l->c + r->c;
  }
  int ask(int w) {
    if (w == c) return v;
    if (second == e) {
      return w * second;
    }
    if (l->c >= w)
      return l->ask(w);
    else
      return r->ask(w - l->c) + l->v;
  }
  void db() {
    if (second == e) {
      if (second <= 10) cout << v << ' ' << c << '\n';
    } else {
      l->db();
      r->db();
    }
  }
} * root;
int main() {
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> a >> b;
    if (a == 0 || b == 0)
      ++R;
    else
      V[a].emplace_back(b);
  }
  root = new node(0, 100000);
  for (int i = 0; i < MAXN; ++i)
    if ((int)V[i].size()) {
      pq.push(make_pair((int)V[i].size(), i));
      sort(V[i].begin(), V[i].end());
      reverse(V[i].begin(), V[i].end());
      for (auto t : V[i]) {
        root->ins(t, 1);
      }
    }
  int ans = 1e9;
  int runcst = 0;
  for (int votes = N; votes > 0; --votes) {
    while ((int)pq.size() && pq.top().first > votes - 1) {
      pair<long long, long long> t = pq.top();
      pq.pop();
      root->ins(V[t.second].back(), -1);
      runcst += V[t.second].back();
      V[t.second].pop_back();
      ++R;
      if ((int)V[t.second].size())
        pq.push(make_pair((int)V[t.second].size(), t.second));
    }
    int needs = votes - R;
    int r = runcst;
    if (needs) r += root->ask(needs);
    ans = min(ans, r);
  }
  cout << ans;
}
