#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<pair<long long, long long>> vp;
  long long p, a, l = 0, r = 0, ss = 0;
  for (int i = 0; i < n; i++) {
    cin >> p >> a;
    if (p < 0) {
      ++l;
    } else {
      ++r;
    }
    ss += a;
    vp.push_back(make_pair(p, a));
  }
  if (l == r or l == r + 1 or r == l + 1) {
    cout << ss << "\n";
    return;
  }
  sort(vp.begin(), vp.end());
  if (l == 0) {
    cout << vp[0].second << "\n";
    return;
  } else if (r == 0) {
    cout << vp[n - 1].second << "\n";
    return;
  }
  long long ans = 0;
  if (l < r) {
    for (int i = 0; i <= 2 * l; i++) {
      ans += vp[i].second;
    }
  } else {
    for (int i = l - r - 1; i < n; i++) {
      ans += vp[i].second;
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t = 1;
  while (t--) solve();
  return 0;
}
