#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
using ll = long long;
const ll mod = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 2e9;
const int N = 1e5;
int n;
vector<int> b[maxn];
int f(int x) {
  int cnt = b[0].size();
  int tot = 0;
  set<pair<int, pair<int, int>>> st;
  for (int i = 1; i <= N; i++) {
    int len = b[i].size();
    if (len >= x) {
      int idx = len - x;
      cnt += idx + 1;
      tot += b[i][idx];
      if (idx + 1 < len) {
        st.insert({b[i][idx + 1] - b[i][idx], {idx + 1, i}});
      }
    } else if (len > 0) {
      st.insert({b[i][0], {0, i}});
    }
  }
  while (cnt < x) {
    if (st.empty()) {
      return inf;
    }
    auto cur = *st.begin();
    st.erase(st.begin());
    cnt++;
    tot += cur.first;
    int i = cur.second.second;
    int j = cur.second.first;
    j++;
    if (j < (int)b[i].size()) {
      st.insert({b[i][j] - b[i][j - 1], {j, i}});
    }
  }
  return tot;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    b[x].push_back(y);
  }
  for (int i = 0; i <= N; i++) {
    sort(b[i].begin(), b[i].end());
    for (int j = 1; j < (int)b[i].size(); j++) {
      b[i][j] += b[i][j - 1];
    }
  }
  int lo = 1;
  int hi = n + 1;
  while (hi - lo > 1) {
    int mid = (hi + lo) / 2;
    if (f(mid - 1) > f(mid)) {
      lo = mid;
    } else {
      hi = mid;
    }
  }
  int best = f(lo);
  cout << best << endl;
  return 0;
}
