#include <bits/stdc++.h>
using namespace std;
long long n, x, a, s;
vector<pair<int, long long> > v, u;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x >> a;
    if (x < 0)
      v.push_back(make_pair(-x, a));
    else
      u.push_back(make_pair(x, a));
    s += a;
  }
  sort(v.begin(), v.end());
  sort(u.begin(), u.end());
  if ((int)v.size() - (int)u.size() <= 1 &&
      (int)u.size() - (int)v.size() <= 1) {
    cout << s << endl;
    return 0;
  }
  if (v.size() > u.size()) {
    for (int i = u.size() + 1; i < v.size(); i++) s -= v[i].second;
    cout << s << endl;
    return 0;
  }
  for (int i = v.size() + 1; i < u.size(); i++) s -= u[i].second;
  cout << s << endl;
  return 0;
}
