#include <bits/stdc++.h>
using namespace std;
int main() {
  int sum1 = 0, sum2 = 0, u, j, i, l, k, n, m, a[2][200005] = {0}, b[100005],
      c[100005], p1 = -1, p2 = -1;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> j >> k;
    j += 100000;
    a[0][j] = 1;
    a[1][j] = k;
  }
  for (i = 100000; i >= 0; i--)
    if (a[0][i] == 1) {
      p1++;
      b[p1] = a[1][i];
    }
  for (i = 100001; i <= 200000; i++)
    if (a[0][i] == 1) {
      p2++;
      c[p2] = a[1][i];
    }
  i = 0;
  j = 0;
  int flag = 0;
  while (i <= p1 && j <= p2) {
    if (flag % 2 == 0) {
      sum1 += b[i];
      i++;
    } else {
      sum1 += c[j];
      j++;
    }
    flag++;
  }
  if (flag % 2 == 0 && i <= p1)
    sum1 += b[i];
  else if (flag % 2 == 1 && j <= p2)
    sum1 += c[j];
  i = 0;
  j = 0;
  flag = 1;
  while (i <= p1 && j <= p2) {
    if (flag % 2 == 0) {
      sum2 += b[i];
      i++;
    } else {
      sum2 += c[j];
      j++;
    }
    flag++;
  }
  if (flag % 2 == 0 && i <= p1)
    sum2 += b[i];
  else if (flag % 2 == 1 && j <= p2)
    sum2 += c[j];
  if (sum1 > sum2)
    cout << sum1 << endl;
  else
    cout << sum2 << endl;
  return 0;
}
