#include <bits/stdc++.h>
using namespace std;
const int maxn = 550;
struct node {
  int pp, num;
} a[maxn], b[maxn];
bool cmp(node A, node B) { return A.pp < B.pp; }
int main() {
  int ca, cb, n, pos, val;
  ca = cb = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &pos, &val);
    if (pos > 0) {
      a[ca].pp = pos;
      a[ca].num = val;
      ca++;
    } else {
      b[cb].pp = -pos;
      b[cb].num = val;
      cb++;
    }
  }
  sort(a, a + ca, cmp);
  sort(b, b + cb, cmp);
  int len = min(ca, cb);
  int sum = 0;
  for (int i = 0; i < len; i++) sum += a[i].num + b[i].num;
  if (ca > cb)
    sum += a[len].num;
  else if (ca < cb)
    sum += b[len].num;
  printf("%d\n", sum);
  return 0;
}
