#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, m;
vector<int> v[maxn];
long long check(int x) {
  long long ret = 0;
  int tot = 0;
  vector<int> tmp;
  for (int i = 0; i < maxn; ++i) {
    int j = 0, k = v[i].size();
    while (k >= x) ret += v[i][j++], --k, ++tot;
    while (j < v[i].size()) tmp.push_back(v[i][j++]);
  }
  sort(tmp.begin(), tmp.end());
  for (int i = 0; i < tmp.size(); ++i) {
    if (tot >= x) break;
    ret += tmp[i], ++tot;
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int p, c;
    scanf("%d%d", &p, &c);
    v[p].push_back(c);
  }
  for (int i = 0; i < maxn; i++) sort(v[i].begin(), v[i].end());
  for (int i = 0; i < v[0].size(); i++) v[0][i] = 0;
  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;
  }
  printf("%lld\n", check(l));
  return 0;
}
