#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 5;
int n;
vector<int> a[M];
int check(int to) {
  int tot = a[0].size(), ans = 0;
  vector<int> cho;
  for (int i = 1; i <= M - 5; i++) {
    int j = 0, k = a[i].size();
    while (k >= to) ans += a[i][j], j++, k--, ++tot;
    while (j < a[i].size()) cho.push_back(a[i][j]), j++;
  }
  sort(cho.begin(), cho.end());
  for (int i = 0; i < cho.size(); i++) {
    if (tot >= to) break;
    ans += cho[i], tot++;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int p, c;
    scanf("%d%d", &p, &c);
    a[p].push_back(c);
  }
  for (int i = 1; i <= M - 5; i++) sort(a[i].begin(), a[i].end());
  int l = 1, r = n;
  while (l <= r) {
    int mid = (l + r) >> 1;
    int xx = check(mid), yy = check(mid + 1);
    if (xx < yy)
      r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d", check(l));
  return 0;
}
