#include <bits/stdc++.h>
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
using namespace std;
int p, q, y[N], tx, ty;
char s[N];
int n, mx, a, b;
vector<int> ve[N], v;
long long third(int tag) {
  int ans = 0;
  int need = tag - ve[0].size();
  v.clear();
  for (int i = 1; i <= mx; i++) {
    for (int j = 0; j < ve[i].size(); j++) {
      if (ve[i].size() - j >= tag) {
        ans += ve[i][j];
        need--;
      } else
        v.push_back(ve[i][j]);
    }
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < need; i++) ans += v[i];
  return ans;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    ve[a].push_back(b);
    mx = max(mx, a);
  }
  for (int i = 1; i <= mx; i++) sort(ve[i].begin(), ve[i].end());
  int l = 0, r = n;
  while (l + 2 < r) {
    int mid = (l + r) >> 1, mmid = (mid + r) >> 1;
    if (third(mid) > third(mmid))
      l = mid;
    else
      r = mmid;
  }
  long long ans = 0x3f3f3f3f;
  for (int i = l; i <= r; i++) ans = min(third(i), ans);
  cout << ans << endl;
  return 0;
}
