#include <bits/stdc++.h>
using namespace std;
using INT = long long;
using pii = pair<INT, INT>;
vector<INT> R, P, B;
INT tmp[200100];
INT calc(INT l, INT r) {
  INT ans = (INT)(r - l) * 2;
  INT val = (r - l);
  INT dis = 0;
  INT st, ed, nn = 0, mn;
  st = lower_bound(R.begin(), R.end(), l) - R.begin();
  ed = upper_bound(R.begin(), R.end(), r) - R.begin() - 1;
  if (st <= ed) {
    tmp[0] = l;
    for (INT i = st; i <= ed; i++) tmp[++nn] = R[i];
    tmp[++nn] = r;
    mn = 2e9 + 1;
    for (INT j = 0; j < nn; j++) {
      mn = min(mn, r - l - tmp[j + 1] + tmp[j]);
    }
    dis += mn;
  }
  st = lower_bound(B.begin(), B.end(), l) - B.begin();
  ed = upper_bound(B.begin(), B.end(), r) - B.begin() - 1;
  if (st <= ed) {
    nn = 0;
    tmp[0] = l;
    for (INT i = st; i <= ed; i++) tmp[++nn] = B[i];
    tmp[++nn] = r;
    mn = 2e9 + 1;
    for (INT j = 0; j < nn; j++) {
      mn = min(mn, r - l - tmp[j + 1] + tmp[j]);
    }
    dis += mn;
  }
  return min(val + dis, ans);
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  INT n;
  cin >> n;
  for (INT i = 1; i <= n; i++) {
    INT pos;
    char CO;
    cin >> pos >> CO;
    if (CO == 'R') R.push_back(pos);
    if (CO == 'B') B.push_back(pos);
    if (CO == 'P') P.push_back(pos);
  }
  if (P.size() == 0) {
    INT ans = 0;
    if (R.size()) ans += R[R.size() - 1] - R[0];
    if (B.size()) ans += B[B.size() - 1] - B[0];
    cout << ans << endl;
    return 0;
  }
  INT ans = 0;
  for (INT i = 0; i < P.size() - 1; i++) {
    INT l = P[i], r = P[i + 1];
    ans += calc(l, r);
  }
  if (R.size()) {
    ans += max(0ll, P[0] - R[0]);
    ans += max(0ll, R[R.size() - 1] - P[P.size() - 1]);
  }
  if (B.size()) {
    ans += max(0ll, P[0] - B[0]);
    ans += max(0ll, B[B.size() - 1] - P[P.size() - 1]);
  }
  cout << ans << endl;
  return 0;
}
