#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5;
const long long INF = 1LL << 40;
int n, top = 0, seg[maxn + 5];
vector<long long> P, B[maxn + 5], R[maxn + 5];
long long Run(long long L, long long R, vector<long long> &bb,
              vector<long long> &rr) {
  long long res = 0;
  if (L == -INF && R == INF) {
    if (bb.size()) res += bb[(int)(bb.size()) - 1] - bb[0];
    if (rr.size()) res += rr[(int)(rr.size()) - 1] - rr[0];
    return res;
  }
  if (L == -INF) {
    if (bb.size()) res += R - bb[0];
    if (rr.size()) res += R - rr[0];
    return res;
  }
  if (R == INF) {
    if (bb.size()) res += bb[(int)(bb.size()) - 1] - L;
    if (rr.size()) res += rr[(int)(rr.size()) - 1] - L;
    return res;
  }
  long long res1 = R - L, res2 = (R - L) << 1;
  if (bb.size()) {
    long long del = max(bb[0] - L, R - bb[(int)(bb.size()) - 1]);
    for (int i = 0; i + 1 < (int)(bb.size()); ++i)
      del = max(del, bb[i + 1] - bb[i]);
    res1 += R - L - del;
  }
  if (rr.size()) {
    long long del = max(rr[0] - L, R - rr[(int)(rr.size()) - 1]);
    for (int i = 0; i + 1 < (int)(rr.size()); ++i)
      del = max(del, rr[i + 1] - rr[i]);
    res1 += R - L - del;
  }
  if (!(int)(bb.size()) && !(int)(rr.size())) res2 = R - L;
  return min(res1, res2);
}
int main() {
  char ord[5];
  int las0 = 0, las1 = 0, las2 = 0, msk = 0;
  long long ans = 0, a;
  scanf("%d", &n);
  P.push_back(-INF);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld%s", &a, ord);
    seg[i] = a;
    if (ord[0] == 'P')
      P.push_back(a), ++top;
    else if (ord[0] == 'B')
      B[top].push_back(a), msk |= 1;
    else
      R[top].push_back(a), msk |= 2;
  }
  P.push_back(INF);
  for (int i = 0; i + 1 < (int)(P.size()); ++i)
    ans += Run(P[i], P[i + 1], B[i], R[i]);
  printf("%lld\n", ans);
  return 0;
}
