#include <bits/stdc++.h>
using namespace std;
int x[200010];
char tp[200010];
vector<int> vec;
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int mx = -0x3f3f3f3f, mn = 0x3f3f3f3f;
  int Mx = -0x3f3f3f3f, Mn = 0x3f3f3f3f;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> tp[i];
    if (tp[i] == 'P' || tp[i] == 'R') {
      mx = max(mx, x[i]);
      mn = min(mn, x[i]);
    }
    if (tp[i] == 'P' || tp[i] == 'B') {
      Mx = max(Mx, x[i]);
      Mn = min(Mn, x[i]);
    }
    if (tp[i] == 'P') vec.push_back(i);
  }
  long long ans = 0ll + max(0, (mx - mn)) + max(0, (Mx - Mn));
  int sz = vec.size();
  for (int i = 0; i < sz - 1; i++) {
    int L = vec[i], R = vec[i + 1];
    int ux = 0, vx = 0, prex = x[L], prey = x[L];
    for (int j = L + 1; j <= R; j++) {
      if (tp[j] == 'B' || j == R) {
        ux = max(ux, x[j] - prex);
        prex = x[j];
      }
      if (tp[j] == 'R' || j == R) {
        vx = max(vx, x[j] - prey);
        prey = x[j];
      }
    }
    long long v = x[R] - x[L];
    ans -= 2 * v;
    ans += min(2 * v, 3 * v - ux - vx);
  }
  cout << ans << endl;
}
