#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > v1, v2;
  int p, a;
  for (int i = 0; i < n; i++) {
    cin >> p >> a;
    if (p > 0) {
      v1.push_back(make_pair(p, a));
    } else {
      v2.push_back(make_pair(p, a));
    }
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  reverse(v2.begin(), v2.end());
  int try1 = 0, try2 = 0;
  int ix = 0;
  int apples = 0;
  while (ix != v1.size() && ix != v2.size()) {
    apples += (v1[ix].second + v2[ix].second);
    ix++;
  }
  if (v1.size() > v2.size()) {
    apples += v1[ix].second;
  } else if (v1.size() < v2.size()) {
    apples += v2[ix].second;
  }
  cout << apples;
}
