#include <bits/stdc++.h>
using namespace std;
int size[200002];
int go[200002];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0, x, s; i < n; i++) {
    scanf("%d %d", &x, &s);
    size[x + 100000] = s;
  }
  memcpy(go, size, sizeof size);
  int pos = 100000, ans1 = 0, ans2 = 0;
  bool dir = false;
  while ((pos >= 0 && pos <= 200000)) {
    if (dir)
      pos++;
    else
      pos--;
    if (!(pos >= 0 && pos <= 200000)) break;
    if (go[pos]) {
      ans1 += go[pos];
      dir = !dir;
      go[pos] = 0;
    }
  }
  pos = 100000;
  memcpy(go, size, sizeof size);
  dir = true;
  while ((pos >= 0 && pos <= 200000)) {
    if (dir)
      pos++;
    else
      pos--;
    if (!(pos >= 0 && pos <= 200000)) break;
    if (go[pos]) {
      ans2 += go[pos];
      dir = !dir;
      go[pos] = 0;
    }
  }
  printf("%d", max(ans1, ans2));
  return 0;
}
