#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int x[n + 1], a[n + 1];
  long long int pos = 0, neg = 0, sum = 0;
  for (long long int i = 1; i <= n; i++) {
    cin >> x[i] >> a[i];
    if (x[i] > 0)
      pos++;
    else
      neg++;
  }
  for (long long int i = 1; i <= n - 1; i++) {
    for (long long int j = 1; j <= n - i; j++) {
      if (x[j] > x[j + 1]) {
        long long int p;
        p = x[j];
        x[j] = x[j + 1];
        x[j + 1] = p;
        p = a[j];
        a[j] = a[j + 1];
        a[j + 1] = p;
      }
    }
  }
  if (pos == neg) {
    for (long long int i = 1; i <= n; i++) sum += a[i];
  } else if (pos > neg) {
    for (long long int i = 1; i <= (2 * neg + 1); i++) {
      sum += a[i];
    }
  } else if (neg > pos) {
    for (long long int i = (n - (2 * pos)); i <= n; i++) {
      sum += a[i];
    }
  }
  cout << sum << endl;
  return 0;
}
