#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 2e9 + 5;
const ll LINF = 2e18 + 5;
int main() {
  cin.tie(0), cin.sync_with_stdio(0), cout.tie(0), cout.sync_with_stdio(0);
  int n;
  cin >> n;
  vector<pair<ll, char>> v(n);
  for (auto &p : v) cin >> p.first >> p.second;
  ll purple = -INF;
  vector<ll> reds, blues;
  ull ans = 0;
  for (auto &p : v) {
    if (p.second == 'P') {
      if (purple == -INF) {
        if (reds.size()) ans += p.first - reds.front();
        if (blues.size()) ans += p.first - blues.front();
      } else {
        ll twice = (p.first - purple) * 2;
        auto fix = [&](vector<ll> &points) {
          if (points.size() == 0) return p.first - purple;
          ll ans = points.front() - purple;
          for (int i = 1; i < points.size(); i++)
            ans = max(ans, points[i] - points[i - 1]);
          ans = max(ans, p.first - points.back());
          return ans;
        };
        ll off = fix(reds) + fix(blues);
        ans += min(twice, (p.first - purple) * 3 - off);
      }
      purple = p.first;
      reds.clear();
      blues.clear();
    } else
      (p.second == 'R' ? reds : blues).push_back(p.first);
  }
  if (reds.size() && purple == -INF) purple = reds.front();
  if (reds.size()) ans += reds.back() - purple;
  if (blues.size() &&
      (purple == -INF || (reds.size() && purple == reds.front())))
    purple = blues.front();
  if (blues.size()) ans += blues.back() - purple;
  cout << ans << '\n';
}
