#include <bits/stdc++.h>
using namespace std;
struct Tree {
  int pos, app;
} Left[102], Right[102];
bool cmp(Tree A, Tree B);
bool cmmp(Tree A, Tree B);
int N, pos, apples, TL, TR;
int main() {
  cin >> N;
  TL = TR = 0;
  for (int i = 1; i <= N; ++i) {
    cin >> pos >> apples;
    if (pos < 0) {
      Left[++TL].pos = pos;
      Left[TL].app = apples;
    } else {
      Right[++TR].pos = pos;
      Right[TR].app = apples;
    }
  }
  sort(Left + 1, Left + 1 + TL, cmp);
  sort(Right + 1, Right + 1 + TR, cmmp);
  int Sum = 0;
  int dest = (TR > TL ? TL : TR);
  for (int i = 1; i <= dest; ++i) {
    Sum += Right[i].app + Left[i].app;
  }
  cout << max(Sum + Right[dest + 1].app, Sum + Left[dest + 1].app) << '\n';
  return 0;
}
bool cmp(Tree A, Tree B) { return A.pos > B.pos; }
bool cmmp(Tree A, Tree B) { return A.pos < B.pos; }
