#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> v[N];
int n;
int rest[N];
int f(int k) {
  if (k == n) return 0x3f3f3f3f;
  int cnt = v[0].size();
  int fee = 0;
  memset(rest, 0, sizeof(rest));
  for (int i = 1; i <= 1e5; i++) {
    int q = 0;
    if (v[i].size() > k) {
      cnt += v[i].size() - k;
      q = v[i].size() - k;
      for (int j = 0; j < v[i].size() - k; j++) {
        fee += v[i][j];
      }
    }
    for (int j = q; j < v[i].size(); j++) {
      rest[v[i][j]]++;
    }
  }
  int price = 0;
  while (cnt <= k) {
    while (!rest[price]) price++;
    cnt++;
    rest[price]--;
    fee += price;
  }
  return fee;
}
int main() {
  int name, cost;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> name >> cost;
    v[name].push_back(cost);
  }
  for (int i = 0; i <= 1e5; i++) {
    sort(v[i].begin(), v[i].end());
  }
  int r = n, l = 0;
  while (r - l > 6) {
    int m1 = l + (r - l) / 3, m2 = r - (r - l) / 3;
    if (f(m1) > f(m2))
      l = m1;
    else
      r = m2;
  }
  int minn = f(l);
  for (int i = l + 1; i <= r; i++) {
    minn = min(f(i), minn);
  }
  cout << minn << endl;
  return 0;
}
