#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long b,
                 long long mod = (long long)(1e9 + 7)) {
  if (!b) return 1;
  a %= mod;
  return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mxn = 3e5;
int n;
int pos[mxn], color[mxn];
int pre[mxn][3], nxt[mxn][3];
void solve() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &pos[i]);
    char c;
    scanf(" %c", &c);
    color[i] = c == 'G' ? 0 : (c == 'R' ? 1 : 2);
  }
  int i = 0, j = n - 1;
  while (i < n && color[i]) i++;
  while (j >= 0 && color[j]) j--;
  if (i == n) {
    i = 0, j = 0;
    while (i < n && color[i] != 1) i++;
    while (j < n && color[j] != 2) j++;
    int r = i, b = j;
    i = n - 1, j = n - 1;
    while (i >= 0 && color[i] != 1) i--;
    while (j >= 0 && color[j] != 2) j--;
    long long cost = 0;
    if (r < n) cost += pos[i] - pos[r];
    if (b < n) cost += pos[j] - pos[b];
    cout << cost << endl;
  } else {
    long long cost = 0;
    int r = i, b = i, g;
    for (int k = i; k >= 0; k--)
      if (color[k] == 1)
        r = k;
      else if (color[k] == 2)
        b = k;
    cost += (pos[i] - pos[r]) + (pos[i] - pos[b]);
    r = j, b = j, g = j;
    for (int k = j; k < n; k++)
      if (color[k] == 1)
        r = k;
      else if (color[k] == 2)
        b = k;
    cost += (pos[r] - pos[j]) + (pos[b] - pos[j]);
    r = i, b = i, g = i;
    int mxr = 0, mxb = 0;
    for (; i <= j; i++) {
      if (!color[i]) {
        (mxr) = max((mxr), (pos[i] - pos[r]));
        (mxb) = max((mxb), (pos[i] - pos[b]));
        cost +=
            min(2LL * (pos[i] - pos[g]), 3LL * (pos[i] - pos[g]) - mxr - mxb);
        mxr = mxb = 0;
        r = b = g = i;
      } else if (color[i] == 1)
        (mxr) = max((mxr), (pos[i] - pos[r])), r = i;
      else if (color[i] == 2)
        (mxb) = max((mxb), (pos[i] - pos[b])), b = i;
    }
    cout << cost << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
