#include <bits/stdc++.h>
using namespace std;
inline void writeln2() { cout << "\n"; }
inline void writeln() { cout << "\n"; }
inline void readln() {}
template <typename T>
inline void read(T&);
template <typename T>
inline void priws(T);
template <typename T>
inline void print(T);
void err(vector<string>::iterator it) { ++it; }
template <typename Head, typename... Tail>
inline void readln(Head& head, Tail&... tail) {
  read(head);
  readln(tail...);
}
template <typename Head, typename... Tail>
inline void writeln2(Head head, Tail... tail) {
  print(head);
  writeln2(tail...);
}
template <typename Head, typename... Tail>
inline void writeln(Head head, Tail... tail) {
  priws(head);
  writeln2(tail...);
}
template <typename T>
inline void writeln_range(T f, T s) {
  if (f != s)
    for (auto i = f; i != s; ++i) writeln(*i);
}
template <typename Head, typename... Tail>
inline void err(vector<string>::iterator it, Head head, Tail... tail) {
  writeln((*it).substr((*it)[0] == ' '), "=", head);
  err(++it, tail...);
}
vector<string> split(const string& s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c)) v.push_back(x);
  return v;
}
void run() {
  long long ans = 0;
  map<char, int> prev__, mx;
  prev__['G'] = prev__['R'] = prev__['B'] = -1;
  int n;
  readln(n);
  vector<int> x(n);
  vector<char> color(n);
  for (int i = 0; i < (int)(n); ++i) readln(x[i], color[i]);
  auto dist = [&](int i, int j) {
    if (j == -1 || i == -1) return 0;
    return abs(x[i] - x[j]);
  };
  int i = 0, j = n - 1;
  char R = 'R', B = 'B', G = 'G';
  for (; i < n && color[i] != G; ++i)
    ans += dist(prev__[color[i]], i), prev__[color[i]] = i;
  if (i < n) ans += dist(prev__[R], i) + dist(prev__[B], i);
  prev__[G] = prev__[R] = prev__[B] = -1;
  for (; j >= i && color[j] != G; --j)
    ans += dist(j, prev__[color[j]]), prev__[color[j]] = j;
  if (j >= 0) ans += dist(prev__[R], j) + dist(prev__[B], j);
  prev__[G] = prev__[R] = prev__[B] = i;
  for (int q = i; q <= j; ++q) {
    if (color[q] == G) {
      long long d = dist(q, prev__[G]);
      mx[R] = max(mx[R], dist(q, prev__[R]));
      mx[B] = max(mx[B], dist(q, prev__[B]));
      ans += min(2ll * d, 3ll * d - mx[B] - mx[R]);
      mx[R] = mx[B] = 0;
      prev__[R] = prev__[B] = q;
    } else
      mx[color[q]] = max(mx[color[q]], dist(q, prev__[color[q]]));
    prev__[color[q]] = q;
  }
  writeln(ans);
}
int main() {
  ios_base::sync_with_stdio(false);
  run();
  return 0;
}
template <typename T>
inline ostream& operator<<(ostream& os, vector<T>& _a);
template <typename T1, typename T2>
inline istream& operator>>(istream& is, pair<T1, T2>& _a) {
  return is >> _a.first >> _a.second;
}
template <typename T1, typename T2>
inline ostream& operator<<(ostream& os, pair<T1, T2>& _a) {
  return os << _a.first << " " << _a.second;
}
template <typename T>
inline ostream& operator<<(ostream& os, vector<T>& _a) {
  if (_a.size())
    os << _a[0];
  else
    os << "\n";
  for (int i = 1; i < _a.size(); ++i)
    os << "\n "[is_fundamental<T>::value] << _a[i];
  return os;
}
template <typename T>
inline istream& operator>>(istream& is, vector<T>& _a) {
  for (int i = 0; i < _a.size(); ++i) is >> _a[i];
  return is;
}
template <typename T>
inline ostream& operator<<(ostream& os, valarray<T>& _a) {
  if (_a.size())
    os << _a[0];
  else
    os << "\n";
  for (int i = 1; i < _a.size(); ++i)
    os << "\n "[is_fundamental<T>::value] << _a[i];
  return os;
}
template <typename T>
inline istream& operator>>(istream& is, valarray<T>& _a) {
  for (int i = 0; i < _a.size(); ++i) is >> _a[i];
  return is;
}
template <typename T>
inline void print(T _a) {
  cout << " " << _a;
}
template <typename T>
inline void priws(T _a) {
  cout << _a;
}
template <typename T>
inline void read(T& _a) {
  cin >> _a;
}
