#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> pos, neg;
  map<int, int> lala;
  int negi = 0, posi = 0;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    lala[x] = y;
    if (x < 0) {
      negi++;
      neg.push_back(x);
    } else {
      posi++;
      pos.push_back(x);
    }
  }
  sort(neg.begin(), neg.end(), greater<int>());
  sort(pos.begin(), pos.end());
  int last = min(negi, posi);
  int totapp = 0;
  for (int j = 0; j < last; j++) {
    totapp += (lala[neg[j]] + lala[pos[j]]);
  }
  if (negi < posi) {
    totapp += lala[pos[last]];
  } else {
    totapp += lala[neg[last]];
  }
  cout << totapp << endl;
  return 0;
}
