#include <bits/stdc++.h>
using namespace std;
struct node {
  int x;
  int num;
} line[110];
bool cmp(node a, node b) {
  if (a.x != b.x) return a.x < b.x;
  return a.num < b.num;
}
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    int num1 = 0, num2 = 0;
    long long sum = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d%d", &line[i].x, &line[i].num);
      if (line[i].x > 0)
        num1++;
      else
        num2++;
      sum += line[i].num;
    }
    if (abs(num1 - num2) <= 1) {
      printf("%I64d\n", sum);
      continue;
    }
    sort(line + 1, line + 1 + n, cmp);
    if (num2 - num1 > 1) {
      int k = num2 - num1 - 1;
      for (int i = 1; i <= k; i++) sum -= line[i].num;
      printf("%I64d\n", sum);
    } else {
      int k = num1 - num2 - 1;
      for (int i = n; k >= 1; k--, i--) {
        sum -= line[i].num;
      }
      printf("%I64d\n", sum);
    }
  }
  return 0;
}
