#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
const int maxn = 2e5 + 5;
long long x[maxn];
char c[maxn];
int n;
long long getDis(int l, int r, char a) {
  long long mx = -inf, mn = inf;
  for (int i = l; i <= r; i++) {
    if (c[i] == a) mx = max(mx, x[i]), mn = min(mn, x[i]);
  }
  return max(0LL, mx - mn);
}
long long cac1(int l, int r, char a) {
  for (int i = l; i <= r; i++) {
    if (c[i] == a) {
      return x[r + 1] - x[i];
    }
  }
  return 0;
}
long long cac2(int l, int r, char a) {
  for (int i = r; i >= l; i--) {
    if (c[i] == a) {
      return x[i] - x[l - 1];
    }
  }
  return 0;
}
long long solve(int l, int r) {
  long long mx1 = 0, mx2 = 0;
  int t1 = l, t2 = l;
  for (int i = l; i <= r; i++) {
    if (c[i] == 'R') mx1 = max(mx1, x[i] - x[t1]), t1 = i;
    if (c[i] == 'B') mx2 = max(mx2, x[i] - x[t2]), t2 = i;
  }
  mx1 = max(mx1, x[r] - x[t1]);
  mx2 = max(mx2, x[r] - x[t2]);
  return min((x[r] - x[l]) * 2, (x[r] - x[l]) * 3 - mx1 - mx2);
}
int main() {
  scanf("%d", &n);
  bool ok = false;
  int cnt1 = 0, cnt2 = 0;
  for (int i = 1; i <= n; i++)
    cin >> x[i] >> c[i], ok |= (c[i] == 'P'), cnt1 += (c[i] == 'R'),
        cnt2 += (c[i] == 'B');
  if (!ok) {
    long long ans = getDis(1, n, 'R') + getDis(1, n, 'B');
    printf("%lld\n", ans);
    return 0;
  }
  int t = -1, tt = -1;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (c[i] == 'P') {
      if (t != -1)
        ans += solve(t, i);
      else
        tt = i;
      t = i;
    }
  }
  ans += cac1(1, tt - 1, 'R') + cac1(1, tt - 1, 'B') + cac2(t + 1, n, 'R') +
         cac2(t + 1, n, 'B');
  printf("%lld\n", ans);
  return 0;
}
