#include <bits/stdc++.h>
using namespace std;
int n, sum, a, b;
vector<pair<int, int> > v;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    if (x < 0) {
      b++;
    } else {
      a++;
    }
    v.push_back(pair<int, int>(x, y));
  }
  sort(v.begin(), v.end());
  if (a > b) {
    for (int i = 0; i < b + b + 1; i++) {
      sum += v[i].second;
    }
    cout << sum << endl;
    return 0;
  } else {
    if (a == b) {
      for (int i = 0; i < v.size(); i++) {
        sum += v[i].second;
      }
      cout << sum << endl;
      return 0;
    } else {
      int t = a * 2 + 1;
      for (int i = v.size() - 1; t > 0; i--) {
        sum += v[i].second;
        t--;
      }
      cout << sum << endl;
      return 0;
    }
  }
}
