#include <bits/stdc++.h>
using namespace std;
vector<long long int> votes[100001];
vector<long long int> can;
long long int n;
long long int get(long long int limit) {
  long long int got = votes[0].size();
  long long int musthave = 0;
  long long int ans = 0;
  for (int i = 1; i <= 100000; i++) {
    long long int sz = votes[i].size();
    if (!sz) continue;
    if (sz <= limit)
      musthave = max(musthave, sz + 1);
    else {
      musthave = max(musthave, limit + 1);
      for (int j = 0; j < sz - limit; j++) ans += votes[i][j];
      got += sz - limit;
    }
  }
  if (got >= musthave) return ans;
  can.clear();
  for (int i = 1; i <= 100000; i++) {
    long long int sz = votes[i].size();
    if (!sz) continue;
    if (sz <= limit) {
      for (int j = 0; j < sz; j++) can.push_back(votes[i][j]);
    } else {
      for (int j = sz - limit; j < sz; j++) can.push_back(votes[i][j]);
    }
  }
  sort(can.begin(), can.end());
  if (can.size() < musthave - got) return 1000000000000;
  for (int i = 0; i < musthave - got; i++) ans += can[i];
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin.tie(0);
  ;
  long long int i, j, x, y, lo, mid1, mid2, res1, res2, hi, ans = 1000000000000;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> x >> y;
    votes[x].push_back(y);
  }
  for (i = 0; i <= 100000; i++) sort(votes[i].begin(), votes[i].end());
  lo = 0;
  hi = n - 1;
  for (int iter = 0; iter < 100; iter++) {
    mid1 = lo + (hi - lo) / 3;
    mid2 = hi - (hi - lo) / 3;
    res1 = get(mid1);
    res2 = get(mid2);
    ans = min(ans, res1);
    ans = min(ans, res2);
    if (res1 > res2)
      lo = mid1;
    else
      hi = mid2;
  }
  cout << ans;
  return 0;
}
