#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
struct node {
  int x, a;
};
bool compare(const node& a, const node& b) { return a.x < b.x; }
node nodes[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &nodes[i].x, &nodes[i].a);
  }
  sort(nodes, nodes + n, compare);
  int less, more, index = -1;
  less = more = 0;
  for (int i = 0; i < n; ++i) {
    if (nodes[i].x < 0)
      ++less;
    else {
      ++more;
      if (index == -1) index = i;
    }
  }
  int v_min = (less < more ? less : more);
  if (less == 0) {
    printf("%d\n", nodes[index].a);
    return 0;
  } else if (more == 0) {
    printf("%d\n", nodes[n - 1].a);
    return 0;
  }
  int s = index - 1;
  int res = 0;
  for (int i = 0; i < v_min; ++i) res += nodes[s--].a;
  if (less > more) res += nodes[s].a;
  s = index;
  for (int i = 0; i < v_min; ++i) res += nodes[s++].a;
  if (less < more) res += nodes[s].a;
  printf("%d\n", res);
  return 0;
}
