#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int MAX = 0x7fffffff;
vector<int> v;
vector<int> q[maxn];
int check(int h) {
  v.clear();
  int need = h - q[0].size();
  int res = 0;
  for (int i = 1; i < maxn - 1; i++) {
    for (int j = 0; j < q[i].size(); j++) {
      if (q[i].size() - j >= h) {
        need--;
        res += q[i][j];
      } else
        v.push_back(q[i][j]);
    }
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < need; i++) {
    res += v[i];
  }
  return res;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n, x, y, l, r, q1, q2;
  int ans = MAX;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    q[x].push_back(y);
  }
  for (int i = 0; i <= maxn - 2; i++) {
    sort(q[i].begin(), q[i].end());
  }
  l = q[0].size();
  r = n;
  while (l + 2 < r) {
    q1 = l + (r - l) / 3;
    q2 = r - (r - l) / 3;
    if (check(q1) < check(q2)) {
      r = q2;
    } else {
      l = q1;
    }
  }
  for (int i = l; i <= r; i++) {
    ans = min(ans, check(i));
  }
  cout << ans << endl;
  return 0;
}
