#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, n, ne = 0, po = 0, s = 0, sp = 0, sn = 0, x, y;
  vector<pair<long long int, long long int> > vp;
  vector<pair<long long int, long long int> > vn;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    if (x < 0)
      ne++;
    else
      po++;
    if (x < 0)
      vn.push_back(make_pair(-x, y));
    else
      vp.push_back(make_pair(x, y));
    if (x < 0)
      sn += y;
    else
      sp += y;
  }
  sort(vn.begin(), vn.end());
  sort(vp.begin(), vp.end());
  if (vn.size() == vp.size())
    cout << sn + sp << endl;
  else {
    if (vn.size() > vp.size()) {
      s = sp;
      for (i = 0; i <= vp.size(); i++) {
        s += vn[i].second;
      }
    } else {
      s = sn;
      for (i = 0; i <= vn.size(); i++) s += vp[i].second;
    }
    cout << s << endl;
  }
  return 0;
}
