#include <bits/stdc++.h>
FILE *fi, *fo;
struct Point {
  long long x;
  char type;
} v[1 + 300000];
int main() {
  fi = stdin;
  fo = stdout;
  int n;
  fscanf(fi, "%d", &n);
  int conG = 0;
  for (int i = 1; i <= n; i++) {
    fscanf(fi, "%I64d", &v[i].x);
    fgetc(fi);
    v[i].type = fgetc(fi);
    if (v[i].type == 'G') conG++;
  }
  if (conG == 0 || conG == 1) {
    long long prevB = 0, prevR = 0;
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      if (v[i].type == 'B' || v[i].type == 'G') {
        if (prevB) ans = ans + v[i].x - prevB;
        prevB = v[i].x;
      }
      if (v[i].type == 'R' || v[i].type == 'G') {
        if (prevR) ans = ans + v[i].x - prevR;
        prevR = v[i].x;
      }
    }
    fprintf(fo, "%I64d", ans);
  } else {
    int i = 1;
    long long prevB = 0, prevR = 0;
    long long ans = 0;
    while (v[i].type != 'G') {
      if (v[i].type == 'B') {
        if (prevB) ans = ans + v[i].x - prevB;
        prevB = v[i].x;
      }
      if (v[i].type == 'R') {
        if (prevR) ans = ans + v[i].x - prevR;
        prevR = v[i].x;
      }
      i++;
    }
    if (prevB) ans = ans + v[i].x - prevB;
    if (prevR) ans = ans + v[i].x - prevR;
    conG--;
    long long prevG;
    prevB = prevR = prevG = v[i].x;
    long long maxB, maxR;
    maxB = maxR = 0;
    i++;
    while (conG > 0) {
      if (v[i].type == 'G') {
        if (v[i].x - prevB > maxB) maxB = v[i].x - prevB;
        if (v[i].x - prevR > maxR) maxR = v[i].x - prevR;
        if (v[i - 1].type == 'G')
          ans += v[i].x - prevG;
        else if (prevB == prevG)
          ans += (v[i].x - prevG) * 2 - maxR;
        else if (prevR == prevG)
          ans += (v[i].x - prevG) * 2 - maxB;
        else
          ans += std::min(2 * (v[i].x - prevG),
                          3 * (v[i].x - prevG) - maxR - maxB);
        prevG = v[i].x;
        prevR = v[i].x;
        prevB = v[i].x;
        maxB = maxR = 0;
        conG--;
      }
      if (v[i].type == 'B') {
        if (v[i].x - prevB > maxB) maxB = v[i].x - prevB;
        prevB = v[i].x;
      }
      if (v[i].type == 'R') {
        if (v[i].x - prevR > maxR) maxR = v[i].x - prevR;
        prevR = v[i].x;
      }
      i++;
    }
    while (i <= n) {
      if (v[i].type == 'B') {
        if (prevB) ans = ans + v[i].x - prevB;
        prevB = v[i].x;
      }
      if (v[i].type == 'R') {
        if (prevR) ans = ans + v[i].x - prevR;
        prevR = v[i].x;
      }
      i++;
    }
    fprintf(fo, "%I64d", ans);
  }
  fclose(fi);
  fclose(fo);
  return 0;
}
