#include <bits/stdc++.h>
using namespace std;
struct node {
  int a, b;
};
node x[1001];
int n, i, j, l[1001], r[1001], k, s;
bool cmp(const node& x, const node& y) { return x.a < y.a; }
int solve(int p) {
  int i, j, ans;
  i = s;
  j = 1;
  ans = 0;
  while (true) {
    if (p == 1) {
      if (j > k) break;
      ans += r[j];
      j++;
      p = 0;
    } else {
      if (i < 1) break;
      ans += l[i];
      i--;
      p = 1;
    }
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &x[i].a, &x[i].b);
  }
  k = 0;
  s = 0;
  sort(x + 1, x + n + 1, cmp);
  for (i = 1; i <= n; i++) {
    if (x[i].a > 0) {
      k++;
      r[k] = x[i].b;
    } else {
      s++;
      l[s] = x[i].b;
    }
  }
  printf("%d", max(solve(0), solve(1)));
  return 0;
}
