#include <bits/stdc++.h>
using namespace std;
int n;
long long int ans, f1, f2, b, c, d, c1, c2, c3, a;
char ch;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> ch;
    if (ch == 'P' || ch == 'R') {
      if (c1 == 1) {
        ans += a - b;
        f1 = max(f1, a - b);
      }
      c1 = 1;
      b = a;
    }
    if (ch == 'P' || ch == 'B') {
      if (c2 == 1) {
        ans += a - c;
        f2 = max(f2, a - c);
      }
      c2 = 1;
      c = a;
    }
    if (ch == 'P') {
      if (c3 == 1) ans += min(0LL, a - d - f1 - f2);
      c3 = 1;
      d = a;
      f1 = f2 = 0;
    }
  }
  cout << ans;
  return 0;
}
