#include <bits/stdc++.h>
using namespace std;
int main() {
  map<long, long> a, b;
  map<long, long>::iterator i, j;
  long m, c, d, n = 0, p = 0;
  cin >> m;
  while (m--) {
    cin >> c >> d;
    if (c < 0) {
      a[abs(c)] += d;
      n++;
    } else {
      b[c] += d;
      p++;
    }
  }
  long mi = 0, mx = 0, k, sum = 0, f, e;
  mi = min(n, p);
  mx = max(n, p);
  if (mi != mx) mi += 1;
  for (i = a.begin(), k = 0; i != a.end(); i++, k++)
    if (k < n && k < mi) sum += i->second;
  for (j = b.begin(), k = 0; j != b.end(); j++, k++)
    if (k < p && k < mi) sum += j->second;
  cout << sum << endl;
  return 0;
}
