#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long a[n], x[n];
  long long po[100001], ot[100001], po2[100001], ot2[100001];
  for (int i = 0; i < 100001; i++) {
    ot[i] = po[i] = 0;
    ot2[i] = po2[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    cin >> a[i];
    if (x[i] > 0) po[x[i]] = po2[x[i]] = a[i];
    if (x[i] < 0) ot[(-1) * x[i]] = ot2[(-1) * x[i]] = a[i];
  }
  long long ans1 = 0, ans2 = 0;
  int co = 0;
  int nd = 1;
  while (-100001 < co && 100001 > co) {
    if (co == 0) {
    }
    if (co > 0) {
      if (po[co] != 0) {
        ans1 += po[co];
        po[co] = 0;
        nd *= (-1);
      }
    }
    if (co < 0) {
      if (ot[(-1) * co] != 0) {
        ans1 += ot[(-1) * co];
        ot[(-1) * co] = 0;
        nd *= (-1);
      }
    }
    co += nd;
  }
  nd = -1;
  co = 0;
  while (-100001 < co && 100001 > co) {
    if (co == 0) {
    }
    if (co > 0) {
      if (po2[co] != 0) {
        ans2 += po2[co];
        po2[co] = 0;
        nd *= (-1);
      }
    }
    if (co < 0) {
      if (ot2[(-1) * co] != 0) {
        ans2 += ot2[(-1) * co];
        ot2[(-1) * co] = 0;
        nd *= (-1);
      }
    }
    co += nd;
  }
  if (ans1 > ans2) {
    cout << ans1 << endl;
  } else {
    cout << ans2 << endl;
  }
  return 0;
}
