#pragma GCC optimize("Ofast")
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include <stack>
#include <deque>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>  

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Po = pair<double, double>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=ll(a);i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define PB push_back
#define MP make_pair
#define SZ(x) ll(x.size())
#define ALL(x) x.begin(),x.end()
#define NIL -1
#define INF pow(2,31)-1
#define MOD 998244353
#define PI 3.14159265358979323846
#define endl "\n"
#define EPS 1e-9

template <class T, class U>

void chmin(T& t, const U& u) {
	if (t > u) t = u;
}
template <class T, class U>

void chmax(T& t, const U& u) {
	if (t < u) t = u;
}

ll powmod(ll x, ll n, ll mod) {
	ll s = 1;
	REP(i, n) {
		s = s * x % mod;
	}
	if (s < 0)s += mod;
	return s;
}

ll gcd(int p, int q) {
	while (q != 0) {
		ll r = p % q;
		p = q;
		q = r;
	}
	return p;
}

V<ll> v(200001);
signed main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << a * d - b * c << endl;
}

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

#define ll long long
#define ar array
#define sz(v) (int)(v).size()
#define fi first
#define se second
#define pb push_back
#define rep(i,a,b) for(int i = (a) ; i<(b) ; ++i) 

const int mxN = 2e5;
const ll MOD = 998244353;

map<char,int> mp;
int n;
vector<ll> c[3];


ll findmin(int a, int b) {
	ll ans = 1e18;
	rep(i,0,sz(c[a])) {
		int pos = lower_bound(c[b].begin(),c[b].end(),c[a][i]) - c[b].begin();
		if(pos<sz(c[b])) {
			ans = min(ans,llabs(c[a][i]-c[b][pos]));
		}
		if(pos-1>=0) {
			ans = min(ans,llabs(c[a][i]-c[b][pos-1]));
		}
	}
	return ans;
}

int main() {
	mp['R'] = 0;
	mp['G'] = 1;
	mp['B'] = 2;
	cin>>n;
	rep(i,0,2*n) {
		char cl;
		ll x;cin>>x>>cl;
		c[mp[cl]].pb(x);
	}
	sort(c[0].begin(),c[0].end());
	sort(c[1].begin(),c[1].end());
	sort(c[2].begin(),c[2].end());
	if(!(sz(c[0])&1) && !(sz(c[1])&1) && !(sz(c[2])&1)) return cout << 0 << "\n",0;
	if(!(sz(c[0])&1)) swap(c[0],c[2]);
	if(!(sz(c[1])&1)) swap(c[1],c[2]);
	cout << min(findmin(0,1),findmin(0,2) + findmin(1,2)) << "\n";

	return 0;
}
