#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using ll = long long;
ll solve1(const vector<pair<int, char>>& v) {
  ll ans = 0;
  int lastR = -2e9, lastB = -2e9;
  for (auto i : v) {
    if (i.second != 'B') {
      if (lastR == -2e9) {
        lastR = i.first;
      } else {
        ans += i.first - lastR;
        lastR = i.first;
      }
    }
    if (i.second != 'R') {
      if (lastB == -2e9) {
        lastB = i.first;
      } else {
        ans += i.first - lastB;
        lastB = i.first;
      }
    }
  }
  return ans;
}
ll solve2(const vector<pair<int, char>>& v) {
  ll ans = v.back().first - v[0].first;
  int rMax = 0, bMax = 0;
  int lastR = -2e9, lastB = -2e9;
  for (auto i : v) {
    if (i.second != 'B') {
      if (lastR == -2e9) {
        lastR = i.first;
      } else {
        ans += i.first - lastR;
        rMax = max(rMax, i.first - lastR);
        lastR = i.first;
      }
    }
    if (i.second != 'R') {
      if (lastB == -2e9) {
        lastB = i.first;
      } else {
        ans += i.first - lastB;
        bMax = max(bMax, i.first - lastB);
        lastB = i.first;
      }
    }
  }
  return ans - rMax - bMax;
}
int main() {
  cout.precision(20);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<vector<pair<int, char>>> v;
  v.emplace_back();
  for (int i = 0; i < n; i++) {
    int x;
    char c;
    cin >> x >> c;
    v.back().emplace_back(x, c);
    if (c == 'P') {
      v.emplace_back();
      v.back().emplace_back(x, c);
    }
  }
  ll ans = solve1(v[0]) + (v.size() > 1 ? solve1(v.back()) : 0);
  for (int i = 1; i < v.size() - 1; i++) {
    ans += min(solve1(v[i]), solve2(v[i]));
  }
  cout << ans;
}
