#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, y, c = 0, d = 0, p, ps = 0, ns = 0, s = 0, res, t1, t2;
  cin >> n;
  vector<pair<int, int> > a;
  pair<int, int> b;
  for (int i = 0; i < n; i++) {
    cin >> b.first >> b.second;
    if (b.first > 0) {
      c++;
      ps += b.second;
    } else {
      d++;
      ns += b.second;
    }
    a.push_back(b);
  }
  sort(a.begin(), a.end());
  if (d == 0)
    cout << a[0].second;
  else if (c == 0)
    cout << a[a.size() - 1].second;
  else if (c == d + 1 || d == c + 1 || c == d)
    cout << ps + ns;
  else {
    int i, j;
    if (c > d) {
      for (i = 0; i < 2 * d; i++) {
        s += a[i].second;
      }
      s += a[i].second;
    } else {
      j = a.size() - 1;
      for (i = 0; i < 2 * c; i++) {
        s += a[j].second;
        j--;
      }
      s += a[j].second;
    }
    cout << s;
  }
  cout << endl;
  return 0;
}
