#include <bits/stdc++.h>
using namespace std;
int n, la = -1;
long long tot, x[300005], ta, tb, tc;
char y[300005][5];
long long ans;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld%s", x + i, y[i]);
    if (y[i][0] == 'G') {
      if (la == -1) {
        for (int j = 0; j < i; j++)
          if (y[j][0] == 'B') {
            ans += x[i] - x[j];
            break;
          }
        for (int j = 0; j < i; j++)
          if (y[j][0] == 'R') {
            ans += x[i] - x[j];
            break;
          }
      } else {
        tot = x[i] - x[la];
        ta = x[la], tb = 0;
        for (int j = la + 1; j < i; j++)
          if (y[j][0] == 'B') {
            tb = max(tb, x[j] - ta);
            ta = x[j];
          }
        tc = max(tb, x[i] - ta);
        ta = x[la], tb = 0;
        for (int j = la + 1; j < i; j++)
          if (y[j][0] == 'R') {
            tb = max(tb, x[j] - ta);
            ta = x[j];
          }
        tb = max(tb, x[i] - ta);
        ans += min(tot * 2, tot * 3 - tb - tc);
      }
      la = i;
    }
  }
  if (la == -1) {
    ta = INT_MAX, tb = INT_MIN;
    for (int i = 0; i < n; i++)
      if (y[i][0] == 'B') {
        ta = min(ta, x[i]);
        tb = max(tb, x[i]);
      }
    if (ta <= tb) ans += tb - ta;
    ta = INT_MAX, tb = INT_MIN;
    for (int i = 0; i < n; i++)
      if (y[i][0] == 'R') {
        ta = min(ta, x[i]);
        tb = max(tb, x[i]);
      }
    if (ta <= tb) ans += tb - ta;
  } else {
    for (int j = n - 1; j > la; j--)
      if (y[j][0] == 'B') {
        ans += x[j] - x[la];
        break;
      }
    for (int j = n - 1; j > la; j--)
      if (y[j][0] == 'R') {
        ans += x[j] - x[la];
        break;
      }
  }
  printf("%lld\n", ans);
  return 0;
}
