#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 20;
vector<pair<int, int> > vec[N];
pair<int, int> all[N];
int n, m, cnt;
int ans = 1e9;
bool bo[N];
int check(int x) {
  memset(bo, 0, sizeof(bo));
  int now = vec[0].size();
  int cost = 0;
  for (int i = 1; i <= m; i++)
    if (vec[i].size() >= x) {
      for (int j = 0; j <= vec[i].size() - x; j++)
        cost += vec[i][j].first, now++, bo[vec[i][j].second] = 1;
    }
  for (int i = 1; i <= cnt && now < x; i++) {
    if (!bo[all[i].second]) cost += all[i].first, now++;
  }
  ans = min(ans, cost);
  return cost;
}
int main() {
  scanf("%d", &n);
  for (int i = 1, x, y; i <= n; i++) {
    scanf("%d%d", &x, &y), vec[x].push_back(make_pair(y, i)), m = max(m, x);
    if (x) all[++cnt] = make_pair(y, i);
  }
  sort(all + 1, all + cnt + 1);
  for (int i = 0; i <= m; i++) sort(vec[i].begin(), vec[i].end());
  int l = 1, r = n + 1;
  while (l < r) {
    int mid1 = l + r >> 1, mid2 = mid1 + 1;
    if (check(mid1) < check(mid2))
      r = mid2 - 1;
    else
      l = mid1 + 1;
  }
  printf("%d\n", ans);
  return 0;
}
