#include <bits/stdc++.h>
using namespace std;
struct stdr {
  int poz, app;
};
stdr st[100999];
stdr dr[100999];
inline bool cmp(stdr a, stdr b) { return a.poz > b.poz; }
inline bool cmp2(stdr a, stdr b) { return a.poz < b.poz; }
int main() {
  ios ::sync_with_stdio(false);
  int leftt = 0;
  int rightt = 0;
  int n;
  cin >> n;
  while (n--) {
    int a, b;
    cin >> a >> b;
    if (a >= 0) {
      ++rightt;
      dr[rightt].poz = a;
      dr[rightt].app = b;
    } else {
      ++leftt;
      st[leftt].poz = a;
      st[leftt].app = b;
    }
  }
  int sol = min(leftt, rightt);
  sort(st + 1, st + leftt + 1, cmp);
  sort(dr + 1, dr + rightt + 1, cmp2);
  long long add = 0;
  if (sol == leftt and sol + 1 <= rightt)
    add = dr[sol + 1].app;
  else if (sol + 1 <= leftt)
    add = st[sol + 1].app;
  for (int i = 1; i <= sol; ++i) {
    add = add + st[i].app;
    add = add + dr[i].app;
  }
  cout << add;
  return 0;
}
