#include <bits/stdc++.h>
using namespace std;
int pos[200009], tipo[200009];
int main() {
  int n;
  scanf("%d", &n);
  vector<int> b, r;
  long long ans = 0;
  bool fst = false;
  int lastP = 0;
  for (int i = 0; i < n; i++) {
    char c;
    scanf("%d %c", &pos[i], &c);
    if (c == 'R') {
      r.push_back(pos[i]);
    }
    if (c == 'B') {
      b.push_back(pos[i]);
    }
    if (c == 'P') {
      b.push_back(pos[i]);
      r.push_back(pos[i]);
      if (!fst) {
        fst = true;
        for (int j = 1; j < b.size(); j++) {
          ans += b[j] - b[j - 1];
        }
        for (int j = 1; j < r.size(); j++) {
          ans += r[j] - r[j - 1];
        }
      } else {
        long long op1 = 2LL * (pos[i] - lastP);
        long long maxDiff = b[0] - lastP;
        for (int j = 1; j < b.size(); j++) {
          maxDiff = max(maxDiff, 1LL * b[j] - b[j - 1]);
        }
        maxDiff = max(maxDiff, 1LL * pos[i] - b.back());
        op1 -= maxDiff;
        maxDiff = r[0] - lastP;
        for (int j = 1; j < r.size(); j++) {
          maxDiff = max(maxDiff, 1LL * r[j] - r[j - 1]);
        }
        maxDiff = max(maxDiff, 1LL * pos[i] - r.back());
        op1 -= maxDiff;
        ans += min(pos[i] - lastP + op1, 2LL * (pos[i] - lastP));
      }
      b.clear();
      r.clear();
      lastP = pos[i];
    }
  }
  if (!b.empty()) {
    if (fst) {
      ans += b[0] - lastP;
    }
    for (int j = 1; j < b.size(); j++) ans += b[j] - b[j - 1];
  }
  if (!r.empty()) {
    if (fst) {
      ans += r[0] - lastP;
    }
    for (int j = 1; j < r.size(); j++) ans += r[j] - r[j - 1];
  }
  printf("%lld\n", ans);
}
