#include <bits/stdc++.h>
using namespace std;
int n, dem1, dem2;
struct tr {
  int sq, td;
};
tr lh[102], nh[102];
void in() {
  cin >> n;
  dem1 = 0;
  dem2 = 0;
  int a, b;
  for (int i = 1; i <= n; i++) {
    cin >> a >> b;
    if (a > 0) {
      lh[++dem1].td = a;
      lh[dem1].sq = b;
    } else {
      nh[++dem2].td = a;
      nh[dem2].sq = b;
    }
  }
}
bool com(tr x, tr y) { return y.td < x.td; }
bool c(tr x, tr y) { return y.td > x.td; }
void Solve_() {
  sort(lh + 1, lh + dem1 + 1, c);
  sort(nh + 1, nh + dem2 + 1, com);
  int ans = 0;
  if (dem1 == dem2) {
    for (int i = 1; i <= dem1; i++) ans += lh[i].sq + nh[i].sq;
  }
  if (dem1 < dem2) {
    for (int i = 1; i <= dem1; i++) ans += lh[i].sq + nh[i].sq;
    ans += nh[dem1 + 1].sq;
  }
  if (dem1 > dem2) {
    for (int i = 1; i <= dem2; i++) ans += lh[i].sq + nh[i].sq;
    ans += lh[dem2 + 1].sq;
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  in();
  Solve_();
  return 0;
}
