#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long neg[100005];
  long long pos[100005];
  memset(neg, -1, sizeof(neg));
  memset(pos, -1, sizeof(pos));
  long long post = 0, negf = 0;
  long long mxI = 0;
  for (long long i = 0; i < n; i++) {
    long long x, a;
    cin >> x >> a;
    if (x < 0) {
      mxI = max(mxI, (x * -1));
      neg[(x * -1)] = a;
      negf++;
    } else {
      mxI = max(mxI, x);
      pos[x] = a;
      post++;
    }
  }
  long long res = 0;
  if (negf > post) {
    int cnt = 0;
    for (long long i = 0; i <= mxI; i++) {
      if (cnt == post + 1) {
        break;
      }
      if (neg[i] == -1) {
        continue;
      }
      res += neg[i];
      cnt++;
    }
    cnt = 0;
    for (long long i = 0; i <= mxI; i++) {
      if (cnt == post) {
        break;
      }
      if (pos[i] == -1) {
        continue;
      }
      res += pos[i];
      cnt++;
    }
  } else if (negf < post) {
    int cnt = 0;
    for (long long i = 0; i <= mxI; i++) {
      if (cnt == negf + 1) {
        break;
      }
      if (pos[i] == -1) {
        continue;
      }
      res += pos[i];
      cnt++;
    }
    cnt = 0;
    for (long long i = 0; i <= mxI; i++) {
      if (cnt == negf) {
        break;
      }
      if (neg[i] == -1) {
        continue;
      }
      res += neg[i];
      cnt++;
    }
  } else {
    for (long long i = 0; i <= mxI; i++) {
      if (pos[i] != -1) {
        res += pos[i];
      }
      if (neg[i] != -1) {
        res += neg[i];
      }
    }
  }
  cout << res << endl;
  return 0;
}
