#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > a1;
vector<pair<int, int> > a2;
int x, k, N, sol, sol1;
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> x >> k;
    if (x < 0)
      a2.push_back({-x, k});
    else
      a1.push_back({x, k});
  }
  sort(a1.begin(), a1.end());
  sort(a2.begin(), a2.end());
  if (a1.size() == a2.size()) {
    for (int i = 0; i < a1.size(); i++) sol += a1[i].second;
    for (int i = 0; i < a2.size(); i++) sol += a2[i].second;
  } else if (a1.size() > a2.size()) {
    for (int i = 0; i < a2.size(); i++) sol += a1[i].second + a2[i].second;
    sol += a1[a2.size()].second;
  } else {
    for (int i = 0; i < a1.size(); i++) sol += a1[i].second + a2[i].second;
    sol += a2[a1.size()].second;
  }
  cout << sol;
  return 0;
}
