#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 5;
struct node {
  long long p;
  long long type;
};
bool cmp(node a, node b) { return a.p < b.p; }
node a[maxn];
int main() {
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    char c;
    scanf("%lld %c", &a[i].p, &c);
    if (c == 'R') a[i].type = 1;
    if (c == 'B') a[i].type = 2;
    if (c == 'P') a[i].type = 3;
  }
  sort(a + 1, a + 1 + n, cmp);
  long long ans = 0;
  long long p1 = 1;
  while (p1 <= n && a[p1].type != 3) p1++;
  for (long long i = p1; i <= n; i++) {
    long long j = i + 1;
    while (j <= n && a[j].type != 3) j++;
    if (j <= n) {
      long long len = a[j].p - a[i].p;
      long long temp = i, max1 = 0, max2 = 0;
      for (long long k = i + 1; k <= j; k++) {
        if (a[k].type == 2) continue;
        max1 = max(max1, a[k].p - a[temp].p);
        temp = k;
      }
      temp = i;
      for (long long k = i + 1; k <= j; k++) {
        if (a[k].type == 1) continue;
        max2 = max(max2, a[k].p - a[temp].p);
        temp = k;
      }
      ans += min(2 * len, 3 * len - max1 - max2);
    }
    i = j - 1;
  }
  long long temp = -1;
  for (int i = 1; i <= p1 && i <= n; i++) {
    if (a[i].type == 1 || a[i].type == 3) {
      if (temp == -1)
        temp = i;
      else {
        ans += a[i].p - a[temp].p;
      }
      temp = i;
    }
  }
  temp = -1;
  for (int i = 1; i <= p1 && i <= n; i++) {
    if (a[i].type == 2 || a[i].type == 3) {
      if (temp == -1)
        temp = i;
      else {
        ans += a[i].p - a[temp].p;
      }
      temp = i;
    }
  }
  if (p1 <= n) {
    long long p2 = n;
    while (p2 >= 1 && a[p2].type != 3) p2--;
    temp = p2;
    for (int i = p2 + 1; i <= n; i++) {
      if (a[i].type == 1) {
        ans += a[i].p - a[temp].p;
        temp = i;
      }
    }
    temp = p2;
    for (int i = p2 + 1; i <= n; i++) {
      if (a[i].type == 2) {
        ans += a[i].p - a[temp].p;
        temp = i;
      }
    }
  }
  cout << ans << endl;
}
