#include <bits/stdc++.h>
using namespace std;
int n, ans, x, y, v, a[500000], b[550000];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    if (x > 0) {
      a[0]++;
      a[x] = y;
    }
    if (x < 0) {
      b[0]++;
      b[-x] = y;
    }
  }
  if (a[0] >= b[0]) {
    v = min(a[0], b[0] + 1);
    for (int i = 1; i <= 100000; i++) {
      if (a[i] > 0) {
        ans += a[i];
        v--;
      }
      if (!v) break;
    }
    v = b[0];
    for (int i = 1; i <= 100000; i++) {
      if (b[i] > 0) {
        ans += b[i];
        v--;
      }
      if (!v) break;
    }
  }
  if (a[0] < b[0]) {
    v = min(a[0] + 1, b[0]);
    for (int i = 1; i <= 100000; i++) {
      if (b[i] > 0) {
        ans += b[i];
        v--;
      }
      if (!v) break;
    }
    v = a[0];
    for (int i = 1; i <= 100000; i++) {
      if (a[i] > 0) {
        ans += a[i];
        v--;
      }
      if (!v) break;
    }
  }
  cout << ans << endl;
}
