#include <bits/stdc++.h>
using namespace std;
map<int, int> n2, o2;
int main() {
  vector<int> o, n;
  int h, a[100001], b[100001];
  cin >> h;
  for (int i = 0; i < h; i++) {
    cin >> a[i] >> b[i];
    if (a[i] > 0) {
      o.push_back(a[i]);
      o2[a[i]] = b[i];
    } else {
      n.push_back(a[i]);
      n2[a[i]] = b[i];
    }
  }
  sort(o.begin(), o.end());
  sort(n.begin(), n.end());
  reverse(n.begin(), n.end());
  int ans = 0, ch = 0;
  int op = 0, pp = 0;
  for (int i = 0; i < o.size() + n.size(); i++) {
    if (i % 2 == 0 && ch == 0 && op < o.size()) {
      ans += o2[o[op]];
      op++;
      ch = 1;
    } else {
      if (ch == 1 && pp < n.size()) {
        ans += n2[n[pp]];
        pp++;
        ch = 0;
      }
    }
  }
  int ans2 = 0;
  op = 0;
  ch = 0;
  pp = 0;
  for (int i = 0; i < o.size() + n.size(); i++) {
    if (i % 2 == 0 && ch == 0 && pp < n.size()) {
      ans2 += n2[n[pp]];
      pp++;
      ch = 1;
    } else {
      if (ch == 1 && op < o.size()) {
        ans2 += o2[o[op]];
        op++;
        ch = 0;
      }
    }
  }
  cout << max(ans, ans2);
  return 0;
}
