#include <bits/stdc++.h>
using namespace std;
int N;
vector<pair<int, int> > neg, pos;
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    int x, v;
    cin >> x >> v;
    if (x < 0)
      neg.emplace_back(x, v);
    else
      pos.emplace_back(x, v);
  }
  sort(neg.begin(), neg.end());
  sort(pos.begin(), pos.end());
  reverse(pos.begin(), pos.end());
  bool dir = true;
  if (neg.size() > pos.size()) dir = !dir;
  int ans = 0;
  for (; true; dir = !dir) {
    if (dir) {
      if (!pos.size()) break;
      ans += pos.back().second;
      pos.pop_back();
    } else {
      if (!neg.size()) break;
      ans += neg.back().second;
      neg.pop_back();
    }
  }
  cout << ans << endl;
  return 0;
}
