#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const int64_t LINF = 4611686018427387903;
const int MOD = 1e9 + 7;
const int N = 1e5 + 25;
vector<int> has[N];
int check(int m) {
  int res = 0, cur = has[0].size();
  vector<int> can;
  for (int i = 1; i < N; i++) {
    int it = 0, w = has[i].size();
    while (w >= m) {
      res += has[i][it++];
      cur++, w--;
    }
    while (it < has[i].size()) can.push_back(has[i][it++]);
  }
  sort(can.begin(), can.end());
  for (int i = 0; i < can.size(); i++) {
    if (cur >= m) break;
    res += can[i];
    cur++;
  }
  return res;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0, a, b; i < n; i++) cin >> a >> b, has[a].push_back(b);
  for (int i = 1; i < N; i++) sort(has[i].begin(), has[i].end());
  int l = 1, r = n;
  while (l < r) {
    int m = (l + r) >> 1;
    if (check(m) < check(m + 1))
      r = m;
    else
      l = m + 1;
  }
  cout << check(l) << '\n';
  return 0;
}
