#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 100;
long long x[maxn];
char type[maxn], t;
vector<long long> B, R, G;
long long szR, szB, n, pos;
void Put(long long st, long long en) {
  R.clear();
  B.clear();
  for (int i = st; i <= en; ++i) {
    if (type[i] == 1)
      R.push_back(i);
    else if (type[i] == 2)
      B.push_back(i);
  }
  szR = R.size();
  szB = B.size();
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> pos >> t;
    x[i] = pos;
    if (t == 'P')
      type[i] = 0, G.push_back(i);
    else if (t == 'R')
      type[i] = 1;
    else
      type[i] = 2;
  }
  long long ans = 0;
  int sz = G.size();
  if (sz == 0) {
    Put(1, n);
    if (szR > 0) ans += x[R[szR - 1]] - x[R[0]];
    if (szB > 0) ans += x[B[szB - 1]] - x[B[0]];
  } else {
    Put(1, G[0] - 1);
    if (szR > 0) ans += x[G[0]] - x[R[0]];
    if (szB > 0) ans += x[G[0]] - x[B[0]];
    Put(G[sz - 1] + 1, n);
    if (szR > 0) ans += x[R[szR - 1]] - x[G[sz - 1]];
    if (szB > 0) ans += x[B[szB - 1]] - x[G[sz - 1]];
    for (int i = 0; i < sz - 1; ++i) {
      long long x1 = G[i], x2 = G[i + 1];
      long long tmp1 = 0, tmp2 = 0;
      Put(x1 + 1, x2 - 1);
      if (szR > 0) {
        tmp1 = x[R[0]] - x[x1];
        for (int p = 1; p < szR; ++p) tmp1 = max(tmp1, x[R[p]] - x[R[p - 1]]);
        tmp1 = max(tmp1, x[x2] - x[R[szR - 1]]);
      } else
        tmp1 = x[x2] - x[x1];
      if (szB > 0) {
        tmp2 = x[B[0]] - x[x1];
        for (int p = 1; p < szB; ++p) tmp2 = max(tmp2, x[B[p]] - x[B[p - 1]]);
        tmp2 = max(tmp2, x[x2] - x[B[szB - 1]]);
      } else
        tmp2 = x[x2] - x[x1];
      ans += min((x[x2] - x[x1]) * 2, (x[x2] - x[x1]) * 3 - tmp1 - tmp2);
    }
  }
  cout << ans << endl;
  return 0;
}
