#include <bits/stdc++.h>
using namespace std;
int n, x, type, p, cnt;
int curr, nxt;
int firstUpR = -1, firstUpB = -1, firstDownR = -1, firstDownB = -1;
long long ans, len1, len2, dmax;
vector<pair<int, int>> v;
vector<int> rs, bs;
vector<int> ppoz;
char ch;
long long minn(long long a, long long b) {
  if (a < b) return a;
  return b;
}
long long maxx(long long a, long long b) {
  if (a > b) return a;
  return b;
}
void addToAnsUp(int type, int startPoz, int endPoz) {
  for (int i = startPoz; i <= endPoz; ++i) {
    if (v[i].second != type) continue;
    int j = i + 1;
    while (j <= endPoz && v[j].second != v[i].second) ++j;
    if (j == endPoz + 1) break;
    ans += (v[j].first - v[i].first);
    i = j - 1;
  }
}
void addToAnsDown(int type, int startPoz, int endPoz) {
  for (int i = startPoz; i >= endPoz; --i) {
    if (v[i].second != type) continue;
    int j = i - 1;
    while (j >= endPoz && v[j].second != v[i].second) --j;
    if (j == endPoz - 1) break;
    ans += (v[i].first - v[j].first);
    i = j + 1;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %c", &x, &ch);
    if (ch == 'B')
      type = 0;
    else if (ch == 'R')
      type = 1;
    else
      type = 2;
    v.push_back(make_pair(x, type));
    if (type == 2) {
      ++p;
      if (cnt && ppoz[cnt - 1] + 1 == i - 1) ans += (x - v[i - 2].first);
      ppoz.push_back(i - 1);
      ++cnt;
    }
  }
  if (!p) {
    addToAnsUp(0, 0, (int)v.size() - 1);
    addToAnsUp(1, 0, (int)v.size() - 1);
    printf("%lld\n", ans);
    return 0;
  }
  for (int i = ppoz[cnt - 1] + 1; i < n; ++i)
    if (v[i].second == 0) {
      firstUpB = i;
      break;
    }
  for (int i = ppoz[cnt - 1] + 1; i < n; ++i)
    if (v[i].second == 1) {
      firstUpR = i;
      break;
    }
  for (int i = ppoz[0] - 1; i >= 0; --i)
    if (v[i].second == 0) {
      firstDownB = i;
      break;
    }
  for (int i = ppoz[0] - 1; i >= 0; --i)
    if (v[i].second == 1) {
      firstDownR = i;
      break;
    }
  if (firstUpB != -1) ans += (v[firstUpB].first - v[ppoz[cnt - 1]].first);
  if (firstUpR != -1) ans += (v[firstUpR].first - v[ppoz[cnt - 1]].first);
  if (firstDownB != -1) ans += (v[ppoz[0]].first - v[firstDownB].first);
  if (firstDownR != -1) ans += (v[ppoz[0]].first - v[firstDownR].first);
  addToAnsUp(0, ppoz[cnt - 1], n - 1);
  addToAnsUp(1, ppoz[cnt - 1], n - 1);
  addToAnsDown(0, ppoz[0], 0);
  addToAnsDown(1, ppoz[0], 0);
  if (p > 1) {
    for (int i = 0; i < ppoz.size() - 1; ++i) {
      if (ppoz[i] + 1 == ppoz[i + 1]) continue;
      curr = ppoz[i];
      nxt = ppoz[i + 1];
      rs.clear();
      bs.clear();
      rs.push_back(curr);
      bs.push_back(curr);
      for (int j = curr + 1; j <= nxt - 1; ++j) {
        if (v[j].second == 0)
          bs.push_back(j);
        else
          rs.push_back(j);
      }
      rs.push_back(nxt);
      bs.push_back(nxt);
      len1 = 0LL;
      len2 = 0LL;
      len1 += 2LL * (v[nxt].first - v[curr].first);
      len2 += 3LL * (v[nxt].first - v[curr].first);
      dmax = 0;
      for (int j = 1; j < bs.size(); ++j)
        dmax = maxx(dmax, v[bs[j]].first - v[bs[j - 1]].first);
      len2 -= dmax;
      dmax = 0;
      for (int j = 1; j < rs.size(); ++j)
        dmax = maxx(dmax, v[rs[j]].first - v[rs[j - 1]].first);
      len2 -= dmax;
      ans += minn(len1, len2);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
