#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, y;
  long long s = 0;
  map<int, int> a, b, *min, *max;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    if (x > 0)
      a[x] = y;
    else {
      b[-x] = y;
    }
  }
  if (a.size() <= b.size()) {
    min = &a;
    max = &b;
  } else {
    min = &b;
    max = &a;
  }
  map<int, int>::iterator mit = (*max).begin();
  for (map<int, int>::iterator it = (*min).begin(); it != (*min).end(); ++it) {
    s += it->second;
    s += mit->second;
    mit++;
  }
  if (min->size() < max->size()) s += mit->second;
  cout << s << endl;
  return 0;
}
