#include <bits/stdc++.h>
using namespace std;
const string INPUT_FILE = "in.txt";
const string OUTPUT_FILE = "out.txt";
inline bool IS_UPPERCH(char C) { return C >= 'A' && C <= 'Z'; }
inline bool IS_LOWERCH(char C) { return C >= 'a' && C <= 'z'; }
inline bool IS_LETTERCH(char C) { return IS_UPPERCH(C) || IS_LOWERCH(C); }
inline bool IS_DIGITCH(char C) { return C >= '0' && C <= '9'; }
inline char TO_LOWERCH(char C) { return (IS_UPPERCH(C)) ? (C + 32) : C; }
inline char TO_UPPERCH(char C) { return (IS_LOWERCH(C)) ? (C - 32) : C; }
int N;
vector<pair<int, pair<int, bool> > > a;
int calc(int s, bool isToLeft) {
  int c = 0, cur = s;
  while (true) {
    int step = 1;
    if (isToLeft) {
      step = -1;
    }
    isToLeft = !isToLeft;
    while (cur >= 0 && cur < N && a[cur].second.second) {
      cur += step;
    }
    if (cur >= 0 && cur < N) {
      c += a[cur].second.first;
      a[cur].second.second = true;
    } else {
      break;
    }
  }
  return c;
}
int main() {
  scanf("%d\n", &N);
  int xi, ai;
  for (int i = 0; i < N; ++i) {
    scanf("%d %d\n", &xi, &ai);
    a.push_back(make_pair(xi, make_pair(ai, false)));
  }
  sort(a.begin(), a.end());
  int start = 0;
  for (int i = 0; i < N; ++i) {
    if (a[i].first < 0) {
      start = i;
    }
  }
  if ((0 == start && a[0].first > 0) ||
      (N - 1 == start && a[N - 1].first < 0)) {
    printf("%d", a[start].second.first);
    return 0;
  }
  a[start].second.second = true;
  int c1 = calc(start, false) + a[start].second.first;
  for (int i = 0; i < N; ++i) {
    a[i].second.second = false;
  }
  a[start + 1].second.second = true;
  int c2 = calc(start + 1, true) + a[start + 1].second.first;
  printf("%d", max(c1, c2));
  return 0;
}
