#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  long long x;
  char c;
  long long pr = -1, pb = -1;
  long long lr = -1, lb = -1, lp = -1;
  long long ans = 0;
  long long mr = -1, mb = -1;
  for (int i = 0; i < n; i++) {
    scanf("%lld %c", &x, &c);
    x += (long long)1e10;
    if (c == 'P') {
      if (lp == -1) {
        if (pr != -1) ans += x - pr;
        if (pb != -1) ans += x - pb;
      } else {
        if (lb != -1) mb = max(mb, x - lb);
        if (lr != -1) mr = max(mr, x - lr);
        long long dif = x - lp;
        if (lr == -1 && lb != -1) {
          ans += 2 * dif - mb;
        } else if (lr != -1 && lb == -1) {
          ans += 2 * dif - mr;
        } else if (lr != -1 && lb != -1) {
          ans += min(3 * dif - mr - mb, 2 * dif);
        } else {
          ans += dif;
        }
      }
      mb = mr = lb = lr = -1;
      lp = x;
    } else if (c == 'B') {
      if (pb == -1) pb = x;
      if (mb == -1)
        mb = x - lp;
      else
        mb = max(mb, x - lb);
      lb = x;
    } else {
      if (pr == -1) pr = x;
      if (mr == -1)
        mr = x - lp;
      else
        mr = max(mr, x - lr);
      lr = x;
    }
  }
  if (lp == -1) {
    ans = lr - pr + lb - pb;
  } else {
    if (lb != -1) ans += lb - lp;
    if (lr != -1) ans += lr - lp;
  }
  printf("%lld\n", ans);
  return 0;
}
