#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  long long ans = 0;
  vector<pair<int, int>> items(n);
  for (int i = 0; i < n; i++) {
    int x;
    char c[3];
    scanf("%d%s", &x, &c);
    items[i] = make_pair(x, (c[0] == 'P' ? 0 : (c[0] == 'R' ? 1 : -1)));
  }
  int prev = -1;
  bool isP = false;
  bool isM = false;
  for (int i = 0; i < n; i++) {
    if (items[i].second != 0) {
      isP = isP || (items[i].second == 1);
      isM = isM || (items[i].second == -1);
    } else {
      int firstP = -1;
      int firstM = -1;
      int lastP = -1;
      int lastM = -1;
      if (isP) {
        for (int j = prev + 1; j < i; j++) {
          if (items[j].second == 1) {
            firstP = j;
            break;
          }
        }
        for (int j = i - 1; j > prev; j--) {
          if (items[j].second == 1) {
            lastP = j;
            break;
          }
        }
      }
      if (isM) {
        for (int j = prev + 1; j < i; j++) {
          if (items[j].second == -1) {
            firstM = j;
            break;
          }
        }
        for (int j = i - 1; j > prev; j--) {
          if (items[j].second == -1) {
            lastM = j;
            break;
          }
        }
      }
      if (isP && isM) {
        if (prev == -1) {
          ans += items[i].first - items[firstP].first;
          ans += items[i].first - items[firstM].first;
        } else {
          long long d1 = 3LL * (items[i].first - items[prev].first);
          int p1 = prev;
          int p2 = prev;
          long long d2 = 0;
          long long d3 = 0;
          for (int j = prev + 1; j <= i; j++) {
            if (items[j].second >= 0) {
              d2 = max(d2, (long long)(items[j].first - items[p1].first));
              p1 = j;
            }
            if (items[j].second <= 0) {
              d3 = max(d3, (long long)(items[j].first - items[p2].first));
              p2 = j;
            }
          }
          ans +=
              min(2LL * (items[i].first - items[prev].first), (d1 - d2 - d3));
        }
      } else if (isP && !isM) {
        if (prev == -1) {
          ans += items[i].first - items[firstP].first;
        } else {
          ans += 2LL * (items[i].first - items[prev].first);
          long long d = 0;
          for (int j = prev + 1; j <= i; j++)
            d = max(d, (long long)(items[j].first - items[j - 1].first));
          ans -= d;
        }
      } else if (!isP && isM) {
        if (prev == -1) {
          ans += items[i].first - items[firstM].first;
        } else {
          ans += 2LL * (items[i].first - items[prev].first);
          long long d = 0;
          for (int j = prev + 1; j <= i; j++)
            d = max(d, (long long)(items[j].first - items[j - 1].first));
          ans -= d;
        }
      } else {
        if (prev != -1) {
          ans += items[i].first - items[prev].first;
        }
      }
      prev = i;
      isP = isM = false;
    }
  }
  if (prev == -1) {
    int firstP = -1;
    int firstM = -1;
    int lastP = -1;
    int lastM = -1;
    for (int i = 0; i < n; i++) {
      if (items[i].second == 1) {
        firstP = i;
        break;
      }
    }
    for (int i = 0; i < n; i++) {
      if (items[i].second == -1) {
        firstM = i;
        break;
      }
    }
    for (int i = n - 1; i >= 0; i--) {
      if (items[i].second == 1) {
        lastP = i;
        break;
      }
    }
    for (int i = n - 1; i >= 0; i--) {
      if (items[i].second == -1) {
        lastM = i;
        break;
      }
    }
    if (firstP != -1) ans += (items[lastP].first - items[firstP].first);
    if (firstM != -1) ans += (items[lastM].first - items[firstM].first);
  } else if (prev != n - 1) {
    int lastP = -1;
    int lastM = -1;
    for (int i = n - 1; i > prev; i--) {
      if (items[i].second == 1) {
        lastP = i;
        break;
      }
    }
    for (int i = n - 1; i > prev; i--) {
      if (items[i].second == -1) {
        lastM = i;
        break;
      }
    }
    if (lastP != -1) ans += (items[lastP].first - items[prev].first);
    if (lastM != -1) ans += (items[lastM].first - items[prev].first);
  }
  printf("%I64d\n", ans);
  return 0;
}
