#include <bits/stdc++.h>
using namespace std;
long long int n, x[100005], a[100005], cnt;
deque<pair<long long int, long long int> > v, v1;
int main() {
  ios_base ::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> a[i];
    if (x[i] > 0)
      v.push_back({x[i], a[i]});
    else
      v1.push_back({x[i], a[i]});
  }
  sort(v.begin(), v.end());
  sort(v1.begin(), v1.end());
  while (v.size() > 0 && v1.size() > 0) {
    cnt += v.front().second;
    v.pop_front();
    cnt += v1.back().second;
    v1.pop_back();
  }
  if (v1.size() > 0)
    cnt += v1.back().second;
  else if (v.size() > 0)
    cnt += v.front().second;
  cout << cnt << endl;
}
