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