#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
int n;
vector<long long> p, rp, bp;
long long val;
char c;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> val >> c;
    if (c == 'P') {
      p.emplace_back(val);
      rp.emplace_back(val);
      bp.emplace_back(val);
    } else if (c == 'R') {
      rp.emplace_back(val);
    } else {
      bp.emplace_back(val);
    }
  }
  long long ans = 0;
  if (bp.size() > 1) ans += bp.back() - bp[0];
  if (rp.size() > 1) ans += rp.back() - rp[0];
  long long st, en;
  for (int i = 1; i < (int)p.size(); ++i) {
    long long tmp = 0, tmp1 = 0;
    st = lower_bound(bp.begin(), bp.end(), p[i - 1]) - bp.begin();
    en = lower_bound(bp.begin(), bp.end(), p[i]) - bp.begin();
    for (int j = st; j < en; ++j) {
      tmp = max(tmp, (long long)(bp[j + 1] - bp[j]));
    }
    st = lower_bound(rp.begin(), rp.end(), p[i - 1]) - rp.begin();
    en = lower_bound(rp.begin(), rp.end(), p[i]) - rp.begin();
    for (int j = st; j < en; ++j) {
      tmp1 = max(tmp1, (long long)(rp[j + 1] - rp[j]));
    }
    tmp += tmp1;
    ans -= max(0ll, tmp - p[i] + p[i - 1]);
  }
  cout << ans;
  return 0;
}
