#include <bits/stdc++.h>
using namespace std;
char fo[300009];
long long int n, i, lb, lr, lg, l, cr, cb, bban, bran, po[300009], apr[1000],
    ir, ib, lbp, lrp, s;
int main() {
  long long int c = 1;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> po[i] >> fo[i];
  for (i = 1; i <= n && fo[i] != 'P'; i++) {
    if (apr[fo[i]] == 0 && fo[i] == 'R') ir = po[i];
    if (apr[fo[i]] == 0 && fo[i] == 'B') ib = po[i];
    if (fo[i] == 'R') lrp = po[i];
    if (fo[i] == 'B') lbp = po[i];
    apr[fo[i]]++;
  }
  if (i == n + 1) {
    cout << lrp - ir + lbp - ib << endl;
    return 0;
  }
  l = po[i];
  if (apr['R']) s += l - ir;
  if (apr['B']) s += l - ib;
  lb = l;
  lr = l;
  lg = l;
  for (i = i + 1; i <= n; i++) {
    if (fo[i] == 'B') {
      bban = max(bban, po[i] - lb);
      lb = po[i];
      cb = 1;
    }
    if (fo[i] == 'R') {
      bran = max(bran, po[i] - lr);
      lr = po[i];
      cr = 1;
    }
    if (fo[i] == 'P') {
      bran = max(bran, po[i] - lr);
      bban = max(bban, po[i] - lb);
      lb = po[i];
      lr = po[i];
      s += min(3 * (po[i] - lg) - bban - bran, 2 * (po[i] - lg));
      lg = po[i];
      bban = 0;
      bran = 0;
      cr = cb = 0;
    }
  }
  s += lb + lr - 2 * lg;
  cout << s << endl;
  return 0;
}
