#include <bits/stdc++.h>
using namespace std;
void sortx(vector<int> x, vector<int> k) {}
int main() {
  int n, a = 0, b = 0;
  vector<int> xs, ks;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, k;
    cin >> x >> k;
    if (x > 0)
      a++;
    else
      b++;
    xs.push_back(x);
    ks.push_back(k);
  }
  for (int i = 0; i < xs.size(); i++) {
    for (int j = xs.size() - 1; j > i; j--) {
      if (xs[j] < xs[j - 1]) {
        swap(xs[j], xs[j - 1]);
        swap(ks[j], ks[j - 1]);
      }
    }
  }
  int apples = 0;
  if (a == b) {
    for (int i = 0; i < n; i++) {
      apples += ks[i];
    }
  } else if (a > b) {
    for (int i = 0; i < 2 * b + 1; i++) {
      apples += ks[i];
    }
  } else {
    for (int i = b - a - 1; i < n; i++) {
      apples += ks[i];
    }
  }
  cout << apples;
}
