#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  vector<long long> vec, vec2;
  long long n = 0, x = 0, a = 0, max = 0, mns = 0, pls = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x >> a;
    if (x < 0)
      mns++;
    else if (x > 0)
      pls++;
    vec.push_back(x);
    vec2.push_back(a);
  }
  for (long long i = 0; i < vec.size() - 1; i++) {
    for (long long j = i + 1; j < vec.size(); j++) {
      if (vec[i] > vec[j]) {
        long long temp = vec[i];
        long long temp2 = vec2[i];
        vec[i] = vec[j];
        vec2[i] = vec2[j];
        vec[j] = temp;
        vec2[j] = temp2;
      }
    }
  }
  if (pls > 0 && mns == 0) {
    cout << vec2[0];
    return 0;
  } else if (pls == 0 && mns > 0) {
    cout << vec2[vec2.size() - 1];
    return 0;
  } else {
    while ((pls - mns) >= 2) {
      pls--;
      vec.erase(vec.begin() + vec.size() - 1);
      vec2.erase(vec2.begin() + vec2.size() - 1);
    }
    while ((mns - pls) >= 2) {
      vec.erase(vec.begin());
      vec2.erase(vec2.begin());
      mns--;
    }
  }
  cout << accumulate(vec2.begin(), vec2.end(), 0);
  return 0;
}
