#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
char s[N];
int t[N];
int fcc[N];
int c[N];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &t[i]);
    s[i] = getchar();
    while (s[i] < 'A' || s[i] > 'Z') s[i] = getchar();
  }
  long long ans = 0;
  int numberG = 0;
  for (int i = 1; i <= n; ++i) numberG += (s[i] == 'G');
  if (numberG == 0) {
    static int laapp[500];
    for (int i = 1; i <= n; ++i) {
      if (laapp[s[i]]) {
        ans += t[i] - t[laapp[s[i]]];
      }
      laapp[s[i]] = i;
    }
    cout << ans;
    return 0;
  }
  int ll = 1;
  int rr = n;
  static int laapp[500];
  for (int i = 1;; ++i) {
    ll = i;
    if (laapp[s[i]]) ans += t[i] - t[laapp[s[i]]];
    laapp[s[i]] = i;
    if (s[i] == 'G') break;
  }
  if (laapp['B']) ans += t[ll] - t[laapp['B']];
  if (laapp['R']) ans += t[ll] - t[laapp['R']];
  memset(laapp, 0, sizeof(laapp));
  for (int i = n;; --i) {
    rr = i;
    if (laapp[s[i]]) ans += t[laapp[s[i]]] - t[i];
    laapp[s[i]] = i;
    if (s[i] == 'G') break;
  }
  if (laapp['B']) ans += t[laapp['B']] - t[rr];
  if (laapp['R']) ans += t[laapp['R']] - t[rr];
  auto paaa = [&](char a) {
    int mx = 0, la = 0, ret = 0;
    for (int i = ll; i <= rr; ++i) {
      if (s[i] != a && s[i] != 'G') continue;
      if (s[i] == a) {
        if (la) {
          mx = max(mx, t[i] - t[la]);
          ret += t[i] - t[la];
        }
      } else {
        if (la) {
          mx = max(mx, t[i] - t[la]);
          ret += t[i] - t[la];
        }
        c[i] -= mx;
        fcc[i] = ret;
        mx = 0;
        ret = 0;
      }
      la = i;
    }
  };
  paaa('B');
  paaa('R');
  for (int i = ll; i <= rr; ++i)
    if (s[i] == 'G') {
      ans += min(c[i] + fcc[i] * 3ll, fcc[i] * 2ll);
    }
  cout << ans;
}
