#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
template <class T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vec<ll> X(N);
  vec<char> C(N);
  vec<int> sumB(N + 1), sumR(N + 1);
  bool exist_p = false;
  for (int i = 0; i < N; i++) {
    cin >> X[i] >> C[i];
    sumB[i + 1] = sumB[i] + (C[i] == 'B');
    sumR[i + 1] = sumR[i] + (C[i] == 'R');
    exist_p |= C[i] == 'P';
  }
  ll ans = 0;
  if (!exist_p) {
    for (auto c : {'B', 'R'}) {
      ll mi = 2e9 + 1, ma = -2e9 - 1;
      for (int i = 0; i < N; i++)
        if (C[i] == c) {
          chmin(mi, X[i]);
          chmax(ma, X[i]);
        }
      ans += max(0LL, ma - mi);
    }
    cout << ans << "\n";
    return 0;
  }
  auto check = [&](vec<int>& A, vec<int>& B, int l, int r) {
    int a = A[r] - A[l], b = B[r] - B[l];
    int c = A[l], d = A[N] - A[r];
    if (a == 0 && (c > 0 || d > 0)) return true;
    c = B[l], d = B[N] - B[r];
    if (b == 0 && (c > 0 || d > 0)) return true;
    return false;
  };
  auto calc_fix = [&](int l, int r) {
    int prev = l;
    ll res = X[r - 1] - X[l];
    for (auto& c : {'R', 'B'}) {
      ll ma = 0;
      bool ok = false;
      for (int i = l; i < r; i++)
        if (C[i] == c || C[i] == 'P') {
          chmax(ma, X[i] - X[prev]);
          prev = i;
          ok |= C[i] == c;
        }
      if (ok) res += X[r - 1] - X[l] - ma;
    }
    return res;
  };
  int prev = -1;
  for (int i = 0; i < N; i++)
    if (C[i] == 'P') {
      if (prev == -1) {
        for (auto c : {'B', 'R'}) {
          for (int j = 0; j < i; j++)
            if (C[j] == c) {
              ans += X[i] - X[j];
              break;
            }
        }
        prev = i;
        continue;
      }
      if (check(sumB, sumR, prev, i)) {
        ans += calc_fix(prev, i + 1);
      } else {
        ans += min(calc_fix(prev, i + 1), 2 * (X[i] - X[prev]));
      }
      prev = i;
    }
  if (prev != N - 1) {
    for (auto c : {'B', 'R'}) {
      for (int j = N - 1; j > prev; j--)
        if (C[j] == c) {
          ans += X[j] - X[prev];
          break;
        }
    }
  }
  cout << ans << "\n";
}
