#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char ch = ' ';
  while (!isdigit(ch)) {
    ch = getchar();
    if (ch == '-') f = -1;
  }
  while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return x * f;
}
int n, a, b, tot;
vector<int> g[100005];
multiset<int> st;
int f(int x) {
  long long ans = 0, tmp = g[0].size();
  multiset<int> now = st;
  for (int i = 1; i <= 100000; i++) {
    if (g[i].size() < x) continue;
    for (int j = 0; j < g[i].size() - x + 1; j++) {
      ans += g[i][j];
      st.erase(st.find(g[i][j]));
      tmp++;
    }
  }
  while (tmp < x) {
    tmp++;
    ans += (*st.begin());
    st.erase(st.begin());
  }
  st = now;
  return ans;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int a = read(), b = read();
    g[a].push_back(b);
    if (a != 0) st.insert(b);
  }
  for (int i = 0; i <= 100000; i++) {
    sort(g[i].begin(), g[i].end());
  }
  int l = 1, r = n - 1, mid;
  while (l < r) {
    mid = (l + r) >> 1;
    if (f(mid) - f(mid + 1) > 0)
      l = mid + 1;
    else
      r = mid;
  }
  cout << f(l);
}
