#include <bits/stdc++.h>
using namespace std;
int x[101], a[101];
int main() {
  int n;
  cin >> n;
  int p = 0, m = 0;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> a[i];
    if (x[i] > 0)
      p++;
    else
      m++;
  }
  for (int i = 0; i < n; i++)
    for (int j = 1; j < n; j++)
      if (x[j] < x[j - 1]) {
        swap(x[j], x[j - 1]);
        swap(a[j], a[j - 1]);
      }
  long long out = 0;
  if (p <= m) {
    int checker = 0;
    for (int i = n - 1; i >= 0 && checker <= p; i--) {
      if (x[i] < 0) checker++;
      out += a[i];
    }
  } else {
    int checker = 0;
    for (int i = 0; i < n && checker <= m; i++) {
      if (x[i] > 0) checker++;
      out += a[i];
    }
  }
  cout << out << endl;
}
