#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
long long read() {
  long long s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * f;
}
inline void print(long long *f, long long len) {
  for (long long i = 0; i < len; i++) printf("%lld ", f[i]);
  puts("");
}
const long long maxn = 100000;
vector<long long> v[202020];
long long check(long long x) {
  vector<long long> w;
  long long sum1 = 0, sum2 = v[0].size();
  for (long long i = 1, iend = maxn; i <= iend; ++i) {
    long long j = 0, k = v[i].size();
    while (k >= x) sum1 += v[i][j++], --k, ++sum2;
    while (j < v[i].size()) w.push_back(v[i][j++]);
  }
  sort(w.begin(), w.end());
  if (w.size() == 0) return sum1;
  for (long long i = 0, iend = w.size() - 1; i <= iend; ++i) {
    if (sum2 >= x) break;
    sum1 += w[i];
    ++sum2;
  }
  return sum1;
}
signed main() {
  n = read();
  for (long long i = 1, iend = n; i <= iend; ++i) {
    long long a, b;
    a = read(), b = read();
    v[a].push_back(b);
  }
  for (long long i = 1, iend = maxn; i <= iend; ++i)
    sort(v[i].begin(), v[i].end());
  long long l = 1, r = n;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (check(mid) < check(mid + 1))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << check(l);
}
