#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> pos;
  map<int, int, greater<int>> neg;
  int n, coord, appl;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> coord >> appl;
    coord > 0 ? pos[coord] = appl : neg[coord] = appl;
  }
  int sz = min(pos.size(), neg.size());
  auto pi = pos.begin();
  auto ni = neg.begin();
  long long apples = 0;
  for (int i = 0; i < sz; ++i) apples += pi++->second + ni++->second;
  if (pi != pos.end())
    apples += pi->second;
  else if (ni != neg.end())
    apples += ni->second;
  cout << apples << endl;
  return 0;
}
