#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, count1 = 0, count2 = 0, sum = 0;
  scanf("%d", &n);
  vector<pair<int, int> > v1;
  vector<pair<int, int> > v2;
  for (int i = 0; i < n; i++) {
    int x, a;
    scanf("%d %d", &x, &a);
    if (x < 0) {
      v1.push_back(make_pair(x, a));
      count1++;
    } else {
      v2.push_back(make_pair(x, a));
      count2++;
    }
  }
  sort(v1.begin(), v1.end());
  reverse(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  vector<pair<int, int> >::iterator it1 = v1.begin();
  vector<pair<int, int> >::iterator it2 = v2.begin();
  vector<pair<int, int> >::iterator it3 = v1.end();
  vector<pair<int, int> >::iterator it4 = v2.end();
  if (count1 > count2) {
    while (it1 != v1.end()) {
      sum += it1->second;
      it1++;
      if (it2 != v2.end()) {
        sum += it2->second;
        it2++;
      } else
        break;
    }
  } else if (count1 < count2) {
    while (it2 != v2.end()) {
      sum += it2->second;
      it2++;
      if (it1 != v1.end()) {
        sum += it1->second;
        it1++;
      } else
        break;
    }
  } else if (count1 == count2) {
    if ((it3->second) > (it4->second)) {
      while (it1 != v1.end()) {
        sum += it1->second;
        it1++;
        sum += it2->second;
        it2++;
      }
    } else {
      while (it2 != v2.end()) {
        sum += it2->second;
        it2++;
        sum += it1->second;
        it1++;
      }
    }
  }
  printf("%d\n", sum);
}
