#include <bits/stdc++.h>
using namespace std;
bool compare(pair<int, int> a, pair<int, int> b) {
  if (a.first > b.first) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  int N;
  int coorx[105];
  int apples[105];
  vector<pair<int, int>> kanan;
  vector<pair<int, int>> kiri;
  cin >> N;
  for (int n = 1; n <= N; n++) {
    cin >> coorx[n] >> apples[n];
    if (coorx[n] > 0) {
      kanan.push_back({coorx[n], apples[n]});
    } else {
      kiri.push_back({coorx[n], apples[n]});
    }
  }
  sort(kanan.begin(), kanan.end());
  sort(kiri.begin(), kiri.end(), compare);
  int nkiri = kiri.size();
  int nkanan = kanan.size();
  int mins = min(nkiri, nkanan);
  int has = 0;
  for (int x = 0; x < mins; x++) {
    has = has + kanan[x].second + kiri[x].second;
  }
  if (nkanan > nkiri) {
    has += kanan[nkiri].second;
  } else if (nkiri > nkanan) {
    has += kiri[nkanan].second;
  }
  cout << has << endl;
  return 0;
}
