#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }
int main() {
  int n;
  pair<int, int> hue[128];
  int res = 0;
  int neg = 0, pos;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> hue[i].second >> hue[i].first;
    neg += hue[i].second < 0;
  }
  pos = n - neg;
  sort(hue, hue + n, cmp);
  if (pos > neg) {
    for (int i = 0; i < n; i++) {
      if (neg < 0) break;
      res += hue[i].first;
      neg -= hue[i].second > 0;
    }
  } else if (pos < neg) {
    for (int i = n - 1; i >= 0; i--) {
      if (pos < 0) break;
      res += hue[i].first;
      pos -= hue[i].second < 0;
    }
  } else {
    for (int i = 0; i < n; i++) res += hue[i].first;
  }
  cout << res << endl;
  return 0;
}
