#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > xn;
  vector<pair<int, int> > xp;
  int pos = 0;
  int neg = 0;
  int temp1, temp2;
  for (int i = 0; i < n; i++) {
    cin >> temp1;
    cin >> temp2;
    if (temp1 > 0) {
      xp.push_back(make_pair(temp1, temp2));
      pos++;
    } else {
      xn.push_back(make_pair(temp1, temp2));
      neg++;
    }
  }
  int answer = 0;
  sort(xp.begin(), xp.end());
  sort(xn.begin(), xn.end(), std::greater<pair<int, int> >());
  int i = 0;
  int negk = 0, posk = 0;
  if (neg == pos) {
    negk = pos;
    posk = neg;
  }
  if (neg < pos) {
    negk = neg;
    posk = neg + 1;
  } else if (neg > pos) {
    posk = pos;
    negk = pos + 1;
  }
  for (int m = 0; m < posk; m++) {
    answer += xp[m].second;
  }
  for (int m = 0; m < negk; m++) {
    answer += xn[m].second;
  }
  cout << answer;
}
