#include <bits/stdc++.h>
using namespace std;
int n;
struct node {
  int x, a;
};
node p[105];
struct Edge {
  int x_, a_;
};
Edge h[105];
inline int read() {
  int x = 0;
  char c = getchar();
  bool flag = 0;
  while (c < '0' || c > '9') {
    if (c == '-') flag = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return flag ? -x : x;
}
bool cmp1(node k, node l) { return k.x < l.x; }
bool cmp2(Edge k, Edge l) { return (-k.x_) < (-l.x_); }
int main() {
  n = read();
  int x, a;
  int tmp1 = 0, tmp2 = 0;
  for (int i = 1; i <= n; i++) {
    x = read();
    a = read();
    if (x > 0) {
      tmp1++;
      p[tmp1].x = x;
      p[tmp1].a = a;
    } else {
      tmp2++;
      h[tmp2].x_ = x;
      h[tmp2].a_ = a;
    }
  }
  sort(p + 1, p + 1 + tmp1, cmp1);
  sort(h + 1, h + 1 + tmp2, cmp2);
  int sl = min(tmp1, tmp2), ans = 0;
  for (int i = 1; i <= sl; i++) {
    ans += p[i].a;
    ans += h[i].a_;
  }
  if (tmp1 < tmp2)
    ans += h[sl + 1].a_;
  else if (tmp1 > tmp2)
    ans += p[sl + 1].a;
  printf("%d", ans);
  return 0;
}
