#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  vector<pair<int, int>> plus;
  vector<pair<int, int>> minus;
  long long mx = 0;
  for (int i = 0; i < t; i++) {
    int a, b;
    cin >> a >> b;
    mx += b;
    if (a > 0) {
      plus.push_back({a, b});
    } else {
      minus.push_back({a, b});
    }
  }
  long long total = 0;
  sort(minus.rbegin(), minus.rend());
  sort(plus.begin(), plus.end());
  if (plus.size() == minus.size()) {
    cout << mx << endl;
  } else if (plus.size() == 0) {
    cout << minus[0].second << endl;
  } else if (minus.size() == 0) {
    cout << plus[0].second << endl;
  } else if (plus.size() > minus.size()) {
    for (int i = 0; i < minus.size(); i++) {
      total += plus[i].second + minus[i].second;
    }
    total += plus[minus.size()].second;
    cout << total << endl;
  } else if (plus.size() < minus.size()) {
    for (int i = 0; i < plus.size(); i++) {
      total += minus[i].second + plus[i].second;
    }
    total += minus[plus.size()].second;
    cout << total << endl;
  }
}
