#include <bits/stdc++.h>
using namespace std;
vector<long long> p, d;
vector<char> s;
long long ans;
int main() {
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long x;
    char c;
    cin >> x >> c;
    p.push_back(x);
    s.push_back(c);
    if (c == 'P') d.push_back(i);
  }
  long long r = -1e12, b = -1e12;
  long long ans = 0;
  if (d.empty()) {
    for (int i = 0; i < n; i++) {
      if (s[i] == 'R') {
        if (r != -1e12) ans += p[i] - r;
        r = p[i];
      }
      if (s[i] == 'B') {
        if (b != -1e12) ans += p[i] - b;
        b = p[i];
      }
    }
    cout << ans;
    return 0;
  }
  r = -1e12, b = -1e12;
  for (int i = 0; i < d[0]; i++) {
    if (s[i] == 'R') {
      if (r != -1e12) ans += p[i] - r;
      r = p[i];
    } else {
      if (b != -1e12) ans += p[i] - b;
      b = p[i];
    }
  }
  if (b != -1e12) ans += p[d[0]] - b;
  if (r != -1e12) ans += p[d[0]] - r;
  r = -1e12;
  b = -1e12;
  for (int i = n - 1; i > d.back(); i--) {
    if (s[i] == 'R') {
      if (r != -1e12) ans += r - p[i];
      r = p[i];
    } else {
      if (b != -1e12) ans += b - p[i];
      b = p[i];
    }
  }
  if (b != -1e12) ans += b - p[d.back()];
  if (r != -1e12) ans += r - p[d.back()];
  for (int i = 0; i < d.size() - 1; i++) {
    int x = d[i];
    int y = d[i + 1];
    long long rmax = 0, bmax = 0;
    r = p[x];
    b = p[x];
    for (int j = x + 1; j < y; j++) {
      if (s[j] == 'R') {
        if (rmax < p[j] - r) {
          rmax = p[j] - r;
        }
        r = p[j];
      } else {
        if (bmax < p[j] - b) {
          bmax = p[j] - b;
        }
        b = p[j];
      }
    }
    if (rmax < p[y] - r) {
      rmax = p[y] - r;
    }
    if (bmax < p[y] - b) {
      bmax = p[y] - b;
    }
    ans += min(2 * (p[y] - p[x]), 3 * (p[y] - p[x]) - rmax - bmax);
  }
  cout << ans;
}
