#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  long long x[n], a[n];
  vector<pair<int, long long>> v1, v2;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> a[i];
    if (x[i] > 0)
      v1.push_back(make_pair(x[i], a[i]));
    else
      v2.push_back(make_pair(x[i], a[i]));
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  reverse(v2.begin(), v2.end());
  long long sum1 = 0, sum2 = 0;
  if (v1.size() > v2.size()) {
    for (int i = 0; i < v2.size(); i++) sum1 += v2[i].second;
    for (int i = 0; i < v2.size() + 1; i++) sum2 += v1[i].second;
  } else if (v1.size() < v2.size()) {
    for (int i = 0; i < v1.size(); i++) sum1 += v1[i].second;
    for (int i = 0; i < v1.size() + 1; i++) sum2 += v2[i].second;
  } else {
    for (int i = 0; i < v1.size(); i++) sum1 += v1[i].second + v2[i].second;
  }
  cout << sum1 + sum2 << endl;
}
