#include <bits/stdc++.h>
using namespace std;
const int MAXN = 101;
pair<int, int> a[MAXN + 1];
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int cntA = 0, cntB = 0, sumA = 0, sumB = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
    if (a[i].first > 0) {
      cntB++;
      sumB += a[i].second;
    } else {
      cntA++;
      sumA += a[i].second;
    }
  }
  sort(a, a + n);
  if (cntA < cntB) {
    cntA++;
    for (int i = 0; i < n; i++) {
      if (a[i].first > 0 && cntA) sumA += a[i].second, cntA--;
    }
    cout << sumA << endl;
  } else {
    cntB++;
    for (int i = n - 1; i >= 0; i--) {
      if (a[i].first < 0 && cntB) sumB += a[i].second, cntB--;
    }
    cout << sumB << endl;
  }
  return 0;
}
