#include <bits/stdc++.h>
using namespace std;
int getMax(vector<pair<int, int> > left, vector<pair<int, int> > right) {
  int minTurns;
  vector<pair<int, int> > minVector, maxVector;
  int total = 0;
  if (right.size() == left.size()) {
    for (int i = 0; i < right.size(); i++) {
      total += right[i].second;
    }
    for (int i = 0; i < left.size(); i++) {
      total += left[i].second;
    }
    return total;
  }
  if (right.size() < left.size()) {
    minVector = right;
    maxVector = left;
    minTurns = right.size();
  } else {
    minVector = left;
    maxVector = right;
    minTurns = left.size();
  }
  for (int i = 0; i < minVector.size(); i++) {
    total += minVector[i].second;
  }
  for (int i = 0; i <= minVector.size(); i++) {
    total += maxVector[i].second;
  }
  return total;
}
int main(int argc, char const *argv[]) {
  vector<pair<int, int> > right, left;
  int n;
  cin >> n;
  while (n--) {
    int pos, numApples;
    cin >> pos >> numApples;
    if (pos > 0) {
      right.push_back(make_pair(pos, numApples));
    } else {
      pos *= -1;
      left.push_back(make_pair(pos, numApples));
    }
  }
  sort(left.begin(), left.end());
  sort(right.begin(), right.end());
  cout << getMax(left, right) << endl;
  return 0;
}
