#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, ans, mx;
vector<int> f[N + 10];
inline int check(int x) {
  int s = 0, cnt = f[0].size();
  vector<int> res;
  res.clear();
  for (register int i = (1); i <= (mx); i++) {
    int now = 0, num = f[i].size();
    while (num >= x) s += f[i][now++], num--, cnt++;
    while (now < f[i].size()) res.push_back(f[i][now++]);
  }
  sort(res.begin(), res.end());
  for (int i = 0; i < res.size(); i++) {
    if (cnt >= x) break;
    s += res[i], cnt++;
  }
  return s;
}
int main() {
  scanf("%d", &n);
  for (register int i = (1); i <= (n); i++) {
    static int x, c;
    scanf("%d%d", &x, &c);
    f[x].push_back(c);
    mx = max(mx, x);
  }
  for (register int i = (1); i <= (mx); i++) sort(f[i].begin(), f[i].end());
  int l = 1, r = n;
  while (l <= r) {
    int mid = l + r >> 1;
    check(mid) < check(mid + 1) ? r = mid - 1 : l = mid + 1;
  }
  printf("%d", check(l));
  return 0;
}
