#include <bits/stdc++.h>
using namespace std;
bool debug;
const int inf = 1e9 + 5;
const int nax = 1e6 + 5;
int main(int argc, char *argv[]) {
  debug = argc > 1;
  vector<pair<int, int> > lewe, prawe;
  int n;
  scanf("%d", &n);
  for (int i = 0; i <= (n)-1; ++i) {
    int x, a;
    scanf("%d%d", &x, &a);
    if (x > 0)
      prawe.push_back(make_pair(x, a));
    else
      lewe.push_back(make_pair(-x, a));
  }
  sort(lewe.begin(), lewe.end());
  sort(prawe.begin(), prawe.end());
  int res = 0;
  for (int _ = 0; _ <= (2) - 1; ++_) {
    int s = 0;
    int ile = min((int)prawe.size(), (int)lewe.size());
    for (int i = 0; i <= (min(ile, (int)lewe.size())) - 1; ++i)
      s += lewe[i].second;
    for (int i = 0; i <= (min(ile + 1, (int)prawe.size())) - 1; ++i)
      s += prawe[i].second;
    res = max(res, s);
    swap(lewe, prawe);
  }
  printf("%d\n", res);
  return 0;
}
