#include <bits/stdc++.h>
using namespace std;
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, x, y;
  cin >> n;
  vector<pair<int, int> > a, b;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    if (x < 0)
      a.push_back(pair<int, int>(x, y));
    else
      b.push_back(pair<int, int>(x, y));
  }
  sort(a.begin(), a.end(), greater<pair<int, int> >());
  sort(b.begin(), b.end());
  int res = 0;
  if (a.size() == b.size()) {
    for (int i = 0; i < a.size(); i++) res += a[i].second + b[i].second;
  } else if (a.size() > b.size()) {
    for (int i = 0; i < b.size(); i++) res += a[i].second + b[i].second;
    res += a[b.size()].second;
  } else {
    for (int i = 0; i < a.size(); i++) res += a[i].second + b[i].second;
    res += b[a.size()].second;
  }
  cout << res;
  return 0;
  return 0;
}
