#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > pos, neg;
  while (n--) {
    int n1, n2;
    cin >> n1 >> n2;
    if (n1 < 0)
      neg.push_back(make_pair(n1, n2));
    else
      pos.push_back(make_pair(n1, n2));
  }
  sort(neg.begin(), neg.end());
  sort(pos.begin(), pos.end());
  int count1, flag = 0;
  if (pos.size() == neg.size())
    count1 = 2 * (pos.size());
  else if (pos.size() < neg.size()) {
    count1 = 2 * (pos.size()) + 1;
    flag = 1;
  } else
    count1 = 2 * (neg.size()) + 1;
  int k1 = neg.size() - 1, k2 = 0, ans = 0;
  while (count1--) {
    if (flag == 1) {
      ans = (ans + neg[k1].second);
      k1--;
      flag = 0;
    } else {
      ans = (ans + pos[k2].second);
      k2++;
      flag = 1;
    }
  }
  cout << ans << endl;
  return 0;
}
