#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a[100000 + 5];
inline int check(int u) {
  int ans = 0, tot = a[0].size();
  vector<int> nti;
  for (int i = 1; i <= 100000; ++i) {
    int j = 0, k = a[i].size();
    while (k >= u) ans += a[i][j++], --k, ++tot;
    while (j < a[i].size()) nti.push_back(a[i][j++]);
  }
  sort(nti.begin(), nti.end());
  for (int i = 0; i < nti.size(); ++i) {
    if (tot >= u) break;
    ans += nti[i], ++tot;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  int u, v;
  for (int i = 1; i <= n; ++i) scanf("%d%d", &u, &v), a[u].push_back(v);
  for (int i = 1; i <= 100000; ++i) sort(a[i].begin(), a[i].end());
  int l = 1, r = n;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid) < check(mid + 1))
      r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d", check(l));
  return 0;
}
