#include <bits/stdc++.h>
using namespace std;
int ans[100005 * 4];
long long l[100005 + 5];
long long c[100005 + 5];
int main(void) {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int loc = 0, v = 0;
    scanf("%d%d", &loc, &v);
    ans[loc + 100005] = v;
  }
  int a = 0, b = 0;
  int s = 0, t = 0;
  long long sum = 0;
  for (int i = 0; i <= 100005 * 2; i++) {
    if (ans[i]) {
      if (i < 100005)
        a++, s += ans[i], l[a] = s;
      else if (i > 100005)
        b++, t += ans[i], c[b] = t;
      if (i == 100005) sum += ans[i];
    }
  }
  int m;
  m = min(a, b);
  if (a > m)
    sum += l[a] - l[a - m - 1];
  else
    sum += l[a] - l[a - m];
  if (b > m)
    sum += c[m + 1];
  else
    sum += c[m];
  cout << sum;
}
