#include <bits/stdc++.h>
using namespace std;
int a[101], qua[101];
int n, soam, soduong;
long long max0, max1;
int main() {
  int i, j, k, tg;
  while (scanf("%d", &n) > 0 && n > 0) {
    max0 = 0;
    max1 = 0;
    soam = 0;
    soduong = 0;
    for (i = 0; i < n; i++) {
      cin >> a[i] >> qua[i];
      if (a[i] > 0)
        soduong++;
      else
        soam++;
      max0 = max0 + qua[i];
    }
    for (i = 0; i < n; i++) {
      for (j = i + 1; j < n; j++) {
        if (a[i] > a[j]) {
          tg = a[i];
          a[i] = a[j];
          a[j] = tg;
          tg = qua[i];
          qua[i] = qua[j];
          qua[j] = tg;
        }
      }
    }
    if (soam == soduong) {
      max1 = max0;
    } else {
      if (soam > soduong) {
        if (soduong == 0) {
          max1 = qua[n - 1];
        } else {
          k = 0;
          for (i = n - 1; i >= 0; i--) {
            max1 = max1 + qua[i];
            k++;
            if (k == soduong * 2 + 1) break;
          }
        }
      } else {
        if (soam == 0) {
          max1 = qua[0];
        } else {
          k = 0;
          for (i = 0; i < n; i++) {
            max1 = max1 + qua[i];
            k++;
            if (k == soam * 2 + 1) break;
          }
        }
      }
    }
    cout << max1 << endl;
  }
  return 0;
}
