#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ai, xi, neg = 0, pos = 0, count = 0;
  vector<pair<int, int> > a;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> xi >> ai;
    a.push_back(pair<int, int>(xi, ai));
    if (xi < 0)
      neg++;
    else
      pos++;
    count += ai;
  }
  sort(a.begin(), a.end());
  int no = abs(neg - pos) - 1;
  if (no > 0) {
    if (neg > pos) {
      for (int i = 0; i < no; i++) count -= a[i].second;
    } else {
      for (int i = n - 1; i >= n - no; i--) count -= a[i].second;
    }
  }
  cout << count;
  return 0;
}
