#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int maxn = 5e5 + 5;
int x[maxn], t[maxn], pos[maxn], c[maxn];
vector<int> v[5];
char s[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (0); i < (n); i++) {
    scanf("%d%s", &x[i], s);
    if (s[0] == 'R')
      t[i] = 1;
    else if (s[0] == 'B')
      t[i] = 2;
  }
  long long ans = 0;
  for (int i = (0); i < (n); i++) {
    if (t[i] == 1 || t[i] == 0) {
      if ((int)v[1].size()) ans += x[i] - v[1].back();
      v[1].push_back(x[i]);
    }
    if (t[i] == 2 || t[i] == 0) {
      if ((int)v[2].size()) ans += x[i] - v[2].back();
      v[2].push_back(x[i]);
    }
  }
  int p = -1;
  for (int i = (0); i < (n); i++) {
    if (!t[i]) {
      if (p != -1) {
        int mn1 = -1, mn2 = -1;
        for (int i = (1); i < (3); i++) pos[i] = x[p];
        for (int j = (p + 1); j < (i); j++)
          if (t[j] == 1) {
            mn1 = max(mn1, x[j] - pos[1]);
            pos[1] = x[j];
          } else if (t[j] == 2) {
            mn2 = max(mn2, x[j] - pos[2]);
            pos[2] = x[j];
          }
        mn1 = max(x[i] - pos[1], mn1);
        mn2 = max(x[i] - pos[2], mn2);
        ans += min(0, x[i] - x[p] - mn1 - mn2);
      }
      p = i;
    }
  }
  printf("%lld", ans);
  return 0;
}
