#include <bits/stdc++.h>
using namespace std;
int x[110];
int p[110];
int a[110];
bool cmp(int i, int j) { return x[i] < x[j]; }
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> a[i];
    p[i] = i;
  }
  sort(p, p + n, cmp);
  int i = 0;
  while (i < n && x[p[i]] < 0) i++;
  int l = i - 1;
  int r = i;
  int d = 1;
  int ans = 0;
  int m;
  while (1) {
    if (d) {
      if (r == n) break;
      m = r;
      r++;
    } else {
      if (l < 0) break;
      m = l;
      l--;
    }
    ans += a[p[m]];
    d ^= 1;
  }
  int gao = 0;
  d = 0;
  l = i - 1;
  r = i;
  while (1) {
    if (d) {
      if (r == n) break;
      m = r;
      r++;
    } else {
      if (l < 0) break;
      m = l;
      l--;
    }
    gao += a[p[m]];
    d ^= 1;
  }
  cout << max(ans, gao) << endl;
  return 0;
}
