#include <bits/stdc++.h>
using namespace std;
bool compare(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<pair<int, int> > A;
  vector<pair<int, int> > B;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    if (x < 0)
      A.push_back(make_pair(x, y));
    else
      B.push_back(make_pair(x, y));
  }
  long long sum = 0;
  if (A.size() < B.size()) {
    sort(B.begin(), B.end());
    for (int i = 0; i < A.size(); i++) {
      sum += A[i].second + B[i].second;
    }
    sum += B[A.size()].second;
  } else if (A.size() > B.size()) {
    sort(A.begin(), A.end(), compare);
    for (int i = 0; i < B.size(); i++) {
      sum += A[i].second + B[i].second;
    }
    sum += A[B.size()].second;
  } else {
    for (int i = 0; i < B.size(); i++) {
      sum += A[i].second + B[i].second;
    }
  }
  cout << sum;
  return 0;
}
