#include <bits/stdc++.h>
template <typename Y>
inline bool updmin(Y &a, Y b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename Y>
inline bool updmax(Y &a, Y b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename Y>
inline Y abs(Y a) {
  if (a < 0) a = -a;
  return a;
}
template <typename Y>
inline Y sqr(Y a) {
  return a * a;
}
int read() {
  int w = 1, q = 0, ch = ' ';
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') w = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) q = q * 10 + ch - 48;
  return q * w;
}
inline void FileIO() {
  freopen(
      ""
      ".in",
      "r", stdin);
  freopen(
      ""
      ".out",
      "w", stdout);
}
int n;
std::vector<std::pair<long long, int> > v, pur;
long long ans;
const long long inf = 1e15;
long long lR = inf, rR = -inf, lB = inf, rB = -inf, lP = inf, rP = -inf;
long long solve(int L, int R) {
  long long ret1 = 0, last = v[L].first;
  for (int i = L + 1; i <= R; i++) {
    if (v[i].second == 0 || v[i].second == 2) {
      updmax(ret1, v[i].first - last);
      last = v[i].first;
    }
  }
  long long ret2 = 0;
  last = v[L].first;
  for (int i = L + 1; i <= R; i++) {
    if (v[i].second == 1 || v[i].second == 2) {
      updmax(ret2, v[i].first - last);
      last = v[i].first;
    }
  }
  return ret1 + ret2;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    long long d = read();
    char ch[10];
    scanf("%s", ch);
    if (ch[0] == 'R') {
      v.push_back(std::make_pair(d, 0));
      updmin(lR, d);
      updmax(rR, d);
    }
    if (ch[0] == 'B') {
      v.push_back(std::make_pair(d, 1));
      updmin(lB, d);
      updmax(rB, d);
    }
    if (ch[0] == 'P') {
      pur.push_back(std::make_pair(d, (int)v.size()));
      v.push_back(std::make_pair(d, 2));
      updmin(lP, d);
      updmax(rP, d);
    }
  }
  if (!pur.size()) {
    if (lR != inf) ans += rR - lR;
    if (lB != inf) ans += rB - lB;
    printf("%lld\n", ans);
    return 0;
  }
  if (lR < lP) ans += lP - lR;
  if (rR > rP) ans += rR - rP;
  if (lB < lP) ans += lP - lB;
  if (rB > rP) ans += rB - rP;
  for (int i = 1; i < pur.size(); i++) {
    long long ret = pur[i].first - pur[i - 1].first -
                    solve(pur[i - 1].second, pur[i].second);
    ans += std::min(ret, 0LL) + 2 * (pur[i].first - pur[i - 1].first);
  }
  printf("%lld\n", ans);
  return 0;
}
