#include <bits/stdc++.h>
const int N = 100005;
using namespace std;
vector<int> q[N], vec;
int n, i, j, l, r, mid, mmid;
int maxn, need;
int fun(int rt) {
  vec.clear();
  need = rt - q[0].size();
  int ans = 0;
  for (i = 1; i <= maxn; i++) {
    for (j = 0; j < q[i].size(); j++) {
      if (q[i].size() - j >= rt) {
        need--;
        ans += q[i][j];
      } else {
        vec.push_back(q[i][j]);
      }
    }
  }
  sort(vec.begin(), vec.end());
  for (i = 0; i < need; i++) ans += vec[i];
  return ans;
}
int main() {
  scanf("%d", &n);
  int x, y;
  maxn = 0;
  for (i = 0; i < n; i++) {
    scanf("%d%d", &x, &y);
    q[x].push_back(y);
    maxn = max(maxn, x);
  }
  for (i = 1; i <= maxn; i++) {
    sort(q[i].begin(), q[i].end());
  }
  l = 0;
  r = n;
  while (l + 1 < r) {
    mid = (l + r) >> 1;
    mmid = (r + mid) >> 1;
    if (fun(mid) > fun(mmid)) {
      l = mid;
    } else {
      r = mmid;
    }
  }
  printf("%d\n", fun(r));
}
