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