#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const long long linf = 4000000000000000000LL;
const long long inf = 998244353;
const long double pi = 3.1415926535;
void pv(vector<int> a) {
  for (auto& x : a) cout << x << " ";
  cout << '\n';
}
void pv(vector<long long> a) {
  for (auto& x : a) cout << x << " ";
  cout << '\n';
}
void pv(vector<vector<int> > a) {
  for (int i = (0); i < (int(a.size())); ++i) {
    cout << i << '\n';
    pv(a[i]);
    cout << '\n';
  }
}
void pv(vector<vector<long long> > a) {
  for (int i = (0); i < (int(a.size())); ++i) {
    cout << i << '\n';
    pv(a[i]);
  }
  cout << '\n';
}
void pv(vector<string> a) {
  for (auto& x : a) cout << x << '\n';
  cout << '\n';
}
void setIO(string second) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (int(second.size())) {
    freopen((second + ".in").c_str(), "r", stdin);
    if (second != "test1") freopen((second + ".out").c_str(), "w", stdout);
  }
}
vector<long long> r, p, b;
long long solve(int l, int r, vector<int> t1, vector<int> t2) {
  if (int(t1.size()) == 0 && int(t2.size()) == 0) {
    return r - l;
  }
  if (int(t1.size()) == 0 || int(t2.size()) == 0) {
    long long ans = r - l;
    if (int(t1.size()) == 0) swap(t1, t2);
    int d1 = 0, d2 = 0;
    if (int(t1.size())) {
      d1 = t1[0] - l;
      for (int i = (0); i < (int(t1.size()) - 1); ++i) {
        d1 = max(d1, t1[i + 1] - t1[i]);
      }
      d1 = max(d1, r - t1[int(t1.size()) - 1]);
    }
    ans += r - l - d1;
    return ans;
  }
  long long ans = 0;
  int d1 = 0, d2 = 0;
  if (int(t1.size())) {
    d1 = t1[0] - l;
    for (int i = (0); i < (int(t1.size()) - 1); ++i) {
      d1 = max(d1, t1[i + 1] - t1[i]);
    }
    d1 = max(d1, r - t1[int(t1.size()) - 1]);
  }
  if (int(t2.size())) {
    d2 = t2[0] - l;
    for (int i = (0); i < (int(t2.size()) - 1); ++i) {
      d2 = max(d2, t2[i + 1] - t2[i]);
    }
    d2 = max(d2, r - t2[int(t2.size()) - 1]);
  }
  ans = 3 * r - 3 * l - d1 - d2;
  ans = min(ans, (long long)2 * r - 2 * l);
  return ans;
}
int main() {
  setIO("");
  int n;
  cin >> n;
  for (int i = (0); i < (n); ++i) {
    int x;
    char y;
    cin >> x >> y;
    if (y == 'R') {
      r.push_back(x);
    } else if (y == 'P') {
      p.push_back(x);
    } else {
      b.push_back(x);
    }
  }
  if (int(p.size()) == 0) {
    long long d1 = 0, d2 = 0;
    if (int(r.size())) d1 = r.back() - r[0];
    if (int(b.size())) d2 = b.back() - b[0];
    cout << d1 + d2 << '\n';
    return 0;
  }
  int i = 0, j = 0;
  vector<int> t1, t2;
  while (i < int(r.size()) && r[i] < p[0]) {
    t1.push_back(r[i++]);
  }
  while (j < int(b.size()) && b[j] < p[0]) {
    t2.push_back(b[j++]);
  }
  long long ans = 0;
  if (int(t1.size())) ans += p[0] - t1[0];
  if (int(t2.size())) ans += p[0] - t2[0];
  for (int k = (1); k < (int(p.size())); ++k) {
    t1.clear();
    t2.clear();
    while (i < int(r.size()) && r[i] < p[k]) {
      t1.push_back(r[i++]);
    }
    while (j < int(b.size()) && b[j] < p[k]) {
      t2.push_back(b[j++]);
    }
    ans += solve(p[k - 1], p[k], t1, t2);
  }
  if (int(r.size())) ans += max(0LL, r.back() - p.back());
  if (int(b.size())) ans += max(0LL, b.back() - p.back());
  cout << ans << '\n';
}
