#include<bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define pb push_back
template <typename _Tp>void read(_Tp &x){
	char ch(getchar());bool f(false);while(!isdigit(ch))f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();while(isdigit(ch))x=x*10+(ch&15),ch=getchar();
	if(f)x=-x;
}
template <typename _Tp,typename... Args>void read(_Tp &t,Args &...args){read(t);read(args...);}
template <typename _Tp>inline void chmax(_Tp &a,const _Tp &b){a=a<b?b:a;}
template <typename _Tp>inline void chmin(_Tp &a,const _Tp &b){a=a<b?a:b;}
const int N=100005;
typedef long long ll;
std::vector<ll> a[3];
ll last[3];
ll calc(const std::vector<ll> &a,const std::vector<ll> &b){
	std::vector<std::pair<ll,int>> v;
	for(auto it:a)v.pb({it,0});
	for(auto it:b)v.pb({it,1});
	std::sort(v.begin(),v.end());
	last[0]=last[1]=-1e18;
	ll ans=1e18;
	for(auto [x,y]:v)chmin(ans,x-last[!y]),last[y]=x;
	return ans;
}
int main(){
	int n;read(n);
	for(int i=1;i<=n+n;++i){
		ll x;read(x);
		char ch;do{ch=getchar();}while(!isalpha(ch));
		a[ch=='R'?0:ch=='G'?1:2].pb(x);
	}
	if(SZ(a[0])%2==0&&SZ(a[1])%2==0&&SZ(a[2])%2==0)return puts("0"),0;
	int p=-1;for(int i=0;i<3;++i)if(SZ(a[i])%2==0)p=i;
	std::vector<ll> x,y,z=a[p];
	if(p==0)x=a[1],y=a[2];
	else if(p==1)x=a[0],y=a[2];
	else if(p==2)x=a[0],y=a[1];
	printf("%lld\n",std::min(calc(x,y),calc(x,z)+calc(y,z)));
	return 0;
}
// doot diddly donger cuckerino Hahahahahah


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

#define all(x)  (x).begin(), (x).end()
const ld PI = acos(-1);

template <typename T> inline T mini(T& x, T y) { return x = min(x, y); }
template <typename T> inline T maxi(T& x, T y) { return x = max(x, y); }
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
template <typename T, typename U>
std::ostream& operator<<(std::ostream& stream, const pair<T, U>& p) {
  return stream << p.first << " " << p.second;
}
template <typename T>
std::ostream& operator<<(std::ostream& out, const vector<T>& vec) {
  for (const T& x: vec) out << x << ' ';
  return out;
}
template <typename T>
std::istream& operator>>(std::istream& in, vector<T>& vec) {
  for (auto& x: vec) in >> x;
  return in;
}



#define sim       template<typename T
#define ris       return *this
#define dor       > debug & operator <<
#define eni(x)    sim > typename enable_if<sizeof dud<T>(0) x 1, debug&>::type operator<<(T i)
sim> struct rge { T b, e; };
sim> rge<T> rang(T i, T j) { return rge<T>{i, j}; }
sim> auto dud(T *x) -> decltype(cerr << *x, 0);
sim> char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) { cerr << boolalpha << i; ris; }
  eni(==) { ris << rang((i).begin(), (i).end()); }
  sim, typename U dor(pair<U, T> d) { ris << "(" << d.first << ", " << d.second << ")"; }
  sim dor(rge<T> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
  sim dor(const T&) { ris; }
#endif
};
#define pr(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


class CTricolorPyramid {
public:
  
  void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> a(n);
    map<char, int> mp = {
        {'B', 0},
        {'W', 1},
        {'R', 2},
    };
    vector<vector<int>> C(3, vector<int>(3, 0));
    for (int i = 0; i < 3; ++i) {
      C[i][i] = C[i][0] = 1;
    }
    for (int i = 1; i < 3; ++i) {
      for (int j = 1; j < i; ++j) {
        C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 3;
      }
    }
    auto getC = [](int n, int k, const vector<vector<int>>& C) {
      if (k < 0 || k > n) return 0;
      int ans = 1;
      while(n > 0) {
        int x = n % 3;
        int y = k % 3;
        n /= 3;
        k /= 3;
        ans = (ans * C[x][y]) % 3;
      }
      return ans;
    };
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      int w = getC(n - 1, i, C);
      w *= mp[s[i]];
      ans = (ans + w) % 3;
    }
    for (int i = 1; i < n; i++) {
      if (ans & 1) ans += 3;
      ans /= 2;
    }
    for (auto[k, v]: mp) {
      if (v == ans) {
        cout << k << '\n';
      }
    }
  }
};

int32_t main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
	CTricolorPyramid solver;
	
	
	solver.solve();
	return 0;
}
