#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, x, y;
  cin >> n;
  vector<pair<int, int>> pos, neg;
  while (n--) {
    cin >> x >> y;
    if (x > 0) {
      pos.push_back({x, y});
    } else {
      neg.push_back({x, y});
    }
  }
  sort(pos.begin(), pos.end());
  sort(neg.begin(), neg.end());
  reverse(neg.begin(), neg.end());
  long long ans = 0;
  int i = 0;
  for (; i < min(pos.size(), neg.size()); i++) {
    ans += pos[i].second + neg[i].second;
  }
  if (pos.size() > neg.size()) {
    ans += pos[i].second;
  }
  if (pos.size() < neg.size()) {
    ans += neg[i].second;
  }
  cout << ans;
}
