#include <bits/stdc++.h>
using namespace std;
int res, ans, N, l, r;
class rec {
 public:
  int x, y;
} P[100010];
int t[100010], sum[100010];
bool use[100010];
bool cmp(const rec &a, const rec &b) { return a.y < b.y; }
int check(int data) {
  memcpy(t, sum, sizeof(t));
  memset(use, 0, sizeof(use));
  res = 0;
  for (int i = 1; i <= N; i++)
    if (t[P[i].x] > data) {
      t[P[i].x]--;
      t[0]++;
      res += P[i].y;
      use[i] = true;
    }
  for (int i = 1; i <= N; i++)
    if (t[0] <= data && !use[i]) {
      t[P[i].x]--;
      t[0]++;
      res += P[i].y;
      use[i] = true;
    }
  return res;
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%d%d", &P[i].x, &P[i].y), sum[P[i].x]++;
  sort(P + 1, P + N + 1, cmp);
  l = 0;
  r = 100000;
  while (l + 2 < r) {
    int delta = (r - l) / 3;
    if (check(l + delta) <= check(r - delta))
      r = r - delta;
    else
      l = l + delta;
  }
  ans = 2e9;
  for (int i = l; i <= r; i++) ans = min(ans, check(i));
  printf("%d", ans);
}
