#include <bits/stdc++.h>
using namespace std;
vector<int> c[100001];
int t, n, r, l, m1, m2, ans, b[100010], x, y;
int check(int o) {
  int u = t, m = 0, ans = 0, j, k;
  for (int i = 1; i < 100001; i++) {
    for (j = 0, k = c[i].size(); k - j >= o; j++) ans += c[i][j], u++;
    for (; j < k; j++) b[m++] = c[i][j];
  }
  sort(b, b + m);
  for (int i = 0; u < o; u++, i++) ans += b[i];
  return ans;
}
int main() {
  scanf("%d", &n), r = n;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    if (x)
      c[x].push_back(y);
    else
      t++;
  }
  ans = 2147483647;
  l = max(t, 1);
  for (int i = 1; i < 100001; i++) sort(c[i].begin(), c[i].end());
  while (r - l > 0) {
    m1 = (2 * l + r) / 3, m2 = (l + 2 * r) / 3;
    if (check(m1) > check(m2))
      l = m1 + 1;
    else
      r = m2;
  }
  ans = check(l);
  printf("%d", ans);
}
