#include <bits/stdc++.h>
using namespace std;
int main() {
  int treenum;
  int treelocation;
  int apple = 0;
  int positivecount = 0;
  int negativecount = 0;
  int counter = 0;
  cin >> treenum;
  int positive[1000000];
  int negative[1000000];
  for (int i = 0; i < 1000000; i++) {
    positive[i] = 0;
    negative[i] = 0;
  }
  for (int i = 0; i < treenum; i++) {
    cin >> treelocation;
    if (treelocation > 0) {
      cin >> positive[treelocation];
      positivecount++;
    } else {
      cin >> negative[-treelocation];
      negativecount++;
    }
  }
  if (positivecount == negativecount) {
    for (int i = 0; i < 1000000; i++) {
      apple = apple + positive[i] + negative[i];
    }
  }
  if (positivecount > negativecount) {
    for (int i = 0; i < 1000000; i++) {
      if (positive[i] != 0) {
        apple = positive[i] + apple;
        counter++;
      }
      if (counter == negativecount + 1) {
        counter = 0;
        break;
      }
    }
    for (int i = 0; i < 1000000; i++) {
      if (negative[i] != 0) {
        apple = negative[i] + apple;
        counter++;
      }
      if (counter == negativecount) {
        counter = 0;
        break;
      }
    }
  }
  if (negativecount > positivecount) {
    for (int i = 0; i < 1000000; i++) {
      if (positive[i] != 0) {
        apple = positive[i] + apple;
        counter++;
      }
      if (counter == positivecount) {
        counter = 0;
        break;
      }
    }
    for (int i = 0; i < 1000000; i++) {
      if (negative[i] != 0) {
        apple = negative[i] + apple;
        counter++;
      }
      if (counter == positivecount + 1) {
        counter = 0;
        break;
      }
    }
  }
  cout << apple;
}
