#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  vector<pair<int, int> > pos, neg;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a >= 0) {
      pos.push_back(make_pair(a, b));
    } else {
      neg.push_back(make_pair(-a, b));
    }
  }
  sort(pos.begin(), pos.end());
  sort(neg.begin(), neg.end());
  vector<pair<int, int> > temp;
  if (pos.size() > neg.size()) {
    temp = pos;
    pos = neg;
    neg = temp;
  }
  int ans = 0;
  for (int i = 0; i < pos.size(); i++) {
    ans += pos[i].second + neg[i].second;
  }
  if (pos.size() != neg.size()) {
    ans += neg[pos.size()].second;
  }
  cout << ans;
  return 0;
}
