#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int tc, t1, t2, p = 0, n = 0, indx, sum = 0, sum1 = 0;
  cin >> tc;
  long long int arr1[tc], arr2[tc];
  for (long long int i = 0; i < tc; i++) {
    cin >> arr1[i] >> arr2[i];
    sum1 += arr2[i];
    if (arr1[i] > 0)
      p++;
    else
      n++;
  }
  for (long long int i = 0; i < tc; i++) {
    for (long long int j = 0; j < tc; j++) {
      if (arr1[i] < arr1[j]) {
        t1 = arr1[i];
        arr1[i] = arr1[j];
        arr1[j] = t1;
        t2 = arr2[i];
        arr2[i] = arr2[j];
        arr2[j] = t2;
      }
    }
  }
  if (n != 0 || p != 0 || p != n)
    for (long long int i = 0; i < tc; i++) {
      if (arr1[i] > 0) {
        indx = i;
        break;
      }
    }
  if (p == n && p != 0)
    cout << sum1;
  else {
    if (n == tc)
      sum += arr2[n - 1];
    else if (p == tc)
      sum += arr2[0];
    else if (p > n) {
      for (long long int i = indx - n; i <= indx + n; i++) sum += arr2[i];
    } else if (n > p) {
      for (long long int i = indx - p - 1; i <= indx + p - 1; i++)
        sum += arr2[i];
    }
    cout << sum;
  }
  return 0;
}
