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