#include <bits/stdc++.h>
using namespace std;
void PE(string Z) {
  cout << Z;
  exit(0);
}
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 22;
int n, x, cntp, cntn, ans, y;
vector<pair<int, int> > a;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    a.push_back(make_pair(x, y));
    if (x > 0)
      cntp++;
    else
      cntn++;
  }
  sort(a.begin(), a.end());
  if (cntp == cntn) {
    for (int i = 0; i < a.size(); i++) ans += a[i].second;
  } else if (cntp > cntn) {
    for (int i = 0; i < cntn + cntn + 1; i++) {
      ans += a[i].second;
    }
  } else {
    for (int i = a.size() - 1; i >= a.size() - cntp - cntp - 1; i--) {
      ans += a[i].second;
    }
  }
  cout << ans;
  return 0;
}
