#include <bits/stdc++.h>
using namespace std;
long long t, n, u, v;
vector<int> s[100005];
long long check(int mid) {
  vector<int> le;
  long long ans = 0;
  int tot = s[0].size();
  for (int i = 1; i <= 100000; i++) {
    int j = 0;
    int k = s[i].size();
    while (k >= mid) {
      ans += s[i][j];
      tot++;
      j++;
      k--;
    }
    while (j < s[i].size()) le.push_back(s[i][j++]);
  }
  sort(le.begin(), le.end());
  for (int i = 0; i < le.size(); i++) {
    if (tot >= mid) break;
    ans += le[i];
    tot++;
  }
  return ans;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> u >> v;
    s[u].push_back(v);
  }
  for (int i = 1; i <= 100000; i++) sort(s[i].begin(), s[i].end());
  int l = 1, r = n;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid) < check(mid + 1))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << check(l) << endl;
}
