#include <bits/stdc++.h>
using namespace std;
int i, j, k;
set<pair<int, int> > pos, neg;
long long int ans;
int main(void) {
  int n, x, a;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x >> a;
    if (x < 0) {
      neg.insert(make_pair(-(x), a));
    } else {
      pos.insert(make_pair(x, a));
    }
  }
  set<pair<int, int> >::iterator it1, it2;
  if (pos.size() > neg.size()) {
    if (neg.size() == 0) {
      it1 = pos.begin();
      cout << it1->second;
      return 0;
    }
    while (neg.size()) {
      it1 = pos.begin();
      it2 = neg.begin();
      ans += (it1->second) + (it2->second);
      pos.erase(make_pair(it1->first, it1->second));
      neg.erase(make_pair(it2->first, it2->second));
    }
    it2 = pos.begin();
    ans += it2->second;
  } else {
    if (pos.size() == 0) {
      it1 = neg.begin();
      cout << it1->second;
      return 0;
    }
    while (pos.size()) {
      it1 = pos.begin();
      it2 = neg.begin();
      ans += (it1->second) + (it2->second);
      pos.erase(make_pair(it1->first, it1->second));
      neg.erase(make_pair(it2->first, it2->second));
    }
    it2 = neg.begin();
    ans += it2->second;
  }
  cout << ans;
  return 0;
}
