#include <bits/stdc++.h>
using namespace std;
struct keep {
  int pos;
  int apples;
};
keep inp[1000];
bool cmp(keep x, keep y) {
  if (x.pos < y.pos) return 1;
  return 0;
}
int main() {
  int n;
  cin >> n;
  int l = 0, r = 0;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> inp[i].pos >> inp[i].apples;
    inp[i].pos < 0 ? l++ : r++;
    sum += inp[i].apples;
  }
  sort(inp, inp + n, cmp);
  if (l == 0) {
    cout << inp[0].apples;
    return 0;
  }
  if (r == 0) {
    cout << inp[n - 1].apples;
    return 0;
  }
  if (l - r == 1 || r - l == 1 || l == r) {
    cout << sum << endl;
    return 0;
  }
  if (l > r) {
    int ans = 0;
    int c = 0;
    int i;
    for (i = n - 1; inp[i].pos > 0; i--) {
      ans += inp[i].apples;
      c++;
    }
    int cc = 1;
    for (; cc <= c + 1; i--) {
      ans += inp[i].apples;
      cc++;
    }
    cout << ans;
    return 0;
  }
  if (r > l) {
    int ans = 0;
    int c = 0;
    int i;
    for (i = 0; inp[i].pos < 0; i++) {
      ans += inp[i].apples;
      c++;
    }
    int cc = 1;
    for (; cc <= c + 1; i++) {
      ans += inp[i].apples;
      cc++;
    }
    cout << ans;
    return 0;
  }
  return 0;
}
