#include <bits/stdc++.h>
using namespace std;
int n, a[200020];
char c[200020];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d %c", &a[i], &c[i]);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (c[i] != 'B') {
      ans -= a[i];
      break;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (c[i] != 'R') {
      ans -= a[i];
      break;
    }
  }
  for (int i = n; i >= 1; i--) {
    if (c[i] != 'B') {
      ans += a[i];
      break;
    }
  }
  for (int i = n; i >= 1; i--) {
    if (c[i] != 'R') {
      ans += a[i];
      break;
    }
  }
  for (int i = 1, lp = 0, lr = 0, lb = 0, mr = 0, mb = 0; i <= n; i++) {
    if (!lp) {
      if (c[i] == 'P')
        lp = lr = lb = i, mr = mb = 0;
      else
        continue;
    } else {
      if (c[i] == 'B') {
        mb = max(mb, a[i] - a[lb]);
        lb = i;
      } else if (c[i] == 'R') {
        mr = max(mr, a[i] - a[lr]);
        lr = i;
      } else {
        mb = max(mb, a[i] - a[lb]);
        mr = max(mr, a[i] - a[lr]);
        ans += min(0, a[i] - a[lp] - mb - mr);
        lp = lr = lb = i;
        mr = mb = 0;
      }
    }
  }
  cout << ans << endl;
}
