#include <bits/stdc++.h>
using namespace std;
bool comp(const pair<long long, long long>& i,
          const pair<long long, long long>& j);
int main() {
  int n, i, j;
  long long x, a, sum;
  vector<pair<long long, long long> > neg, pos;
  while (cin >> n) {
    for (i = 0; i < n; i++) {
      cin >> x >> a;
      if (x > 0)
        pos.push_back(pair<long long, long long>(x, a));
      else
        neg.push_back(pair<long long, long long>(x * (-1), a));
    }
    sort(pos.begin(), pos.end(), comp);
    sort(neg.begin(), neg.end(), comp);
    i = pos.size();
    j = neg.size();
    sum = 0;
    int c = 0;
    while (c < min(i, j)) {
      sum += pos[c].second;
      sum += neg[c].second;
      c++;
    }
    if (i > j)
      sum += pos[c].second;
    else if (j > i)
      sum += neg[c].second;
    cout << sum << endl;
    pos.clear();
    neg.clear();
  }
  return 0;
}
bool comp(const pair<long long, long long>& i,
          const pair<long long, long long>& j) {
  return i.first < j.first;
}
