#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  vector<pair<int, int> > pos;
  vector<pair<int, int> > neg;
  while (t--) {
    int i, a;
    cin >> i >> a;
    if (i < 0)
      neg.push_back(make_pair(abs(i), a));
    else
      pos.push_back(make_pair(i, a));
  }
  sort(neg.begin(), neg.end());
  sort(pos.begin(), pos.end());
  long long int cnt = 0;
  int mini = min(pos.size(), neg.size());
  for (int i = 0; i < mini; i++) cnt += (pos[i].second + neg[i].second);
  if (mini != neg.size()) cnt += neg[mini].second;
  if (mini != pos.size()) cnt += pos[mini].second;
  cout << cnt << endl;
  return 0;
}
