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

#define stp(var, init, end) for (auto var = init; var < end; ++var)
#define stpe(var, init, end) for (auto var = init; var <= end; ++var)
#define ll long long

int main(void)
{
    int n, rnum = 0, gnum = 0, bnum = 0;
    cin >> n;

    vector<ll> rdogs;
    vector<ll> gdogs;
    vector<ll> bdogs;
    ll ina;
    char inc;
    stp(i, 0, 2 * n)
    {
        cin >> ina >> inc;
        if (inc == 'R')
        {
            rdogs.emplace_back(ina);
            ++rnum;
        }
        else if (inc == 'G')
        {
            gdogs.emplace_back(ina);
            ++gnum;
        }
        else if (inc == 'B')
        {
            bdogs.emplace_back(ina);
            ++bnum;
        }
    }
    sort(rdogs.begin(), rdogs.end());
    sort(gdogs.begin(), gdogs.end());
    sort(bdogs.begin(), bdogs.end());
    /*
    cout << "R: ";
    stp(i, 0, rnum)
    {
        cout << rdogs[i] << " ";
    }
    cout << "\n";
    cout << "G: ";
    stp(i, 0, gnum)
    {
        cout << gdogs[i] << " ";
    }
    cout << "\n";
    cout << "B: ";
    stp(i, 0, bnum)
    {
        cout << bdogs[i] << " ";
    }
    cout << "\n\n";
    */

    if (rnum % 2 == 0 && gnum % 2 == 0 && bnum % 2 == 0)
    {
        //cout << "even\n";
        cout << 0;
    }
    else
    {
        ll rgmin = 10000000000000000ll, gbmin = 10000000000000000ll, brmin = 10000000000000000ll;
        if (gnum > 0)
        {
            stp(i, 0, rnum)
            {
                auto iter = lower_bound(gdogs.begin(), gdogs.end(), rdogs[i]);
                if (iter == gdogs.begin())
                    rgmin = min(rgmin, abs(rdogs[i] - *iter));
                else if (iter == gdogs.end())
                    rgmin = min(rgmin, abs(rdogs[i] - *(iter - 1)));
                else
                    rgmin = min(rgmin, min(abs(rdogs[i] - *iter), abs(rdogs[i] - *(iter - 1))));
            }
        }
        if (bnum > 0)
        {
            stp(i, 0, gnum)
            {
                auto iter = lower_bound(bdogs.begin(), bdogs.end(), gdogs[i]);
                if (iter == bdogs.begin())
                    gbmin = min(gbmin, abs(gdogs[i] - *iter));
                else if (iter == bdogs.end())
                    gbmin = min(gbmin, abs(gdogs[i] - *(iter - 1)));
                else
                    gbmin = min(gbmin, min(abs(gdogs[i] - *iter), abs(gdogs[i] - *(iter - 1))));
            }
        }
        if (rnum > 0)
        {
            stp(i, 0, bnum)
            {
                auto iter = lower_bound(rdogs.begin(), rdogs.end(), bdogs[i]);
                if (iter == rdogs.begin())
                    brmin = min(brmin, abs(bdogs[i] - *iter));
                else if (iter == rdogs.end())
                    brmin = min(brmin, abs(bdogs[i] - *(iter - 1)));
                else
                    brmin = min(brmin, min(abs(bdogs[i] - *iter), abs(bdogs[i] - *(iter - 1))));
            }
        }

        if (rnum % 2 == 1 && gnum % 2 == 1)
        {
            if (bnum > 0)
                cout << min(rgmin, gbmin + brmin);
            else
                cout << rgmin;
        }
        else if (gnum % 2 == 1 && bnum % 2 == 1)
        {
            if (rnum > 0)
                cout << min(gbmin, brmin + rgmin);
            else
                cout << gbmin;
        }
        else if (bnum % 2 == 1 && rnum % 2 == 1)
        {
            if (gnum > 0)
                cout << min(brmin, rgmin + gbmin);
            else
                cout << brmin;
        }
    }
    return 0;
}
#include <bits/stdc++.h>
#define rei register int
using namespace std;
int K;
int cnt[11],qpow[11];
string S,T;
double ans;
int score(string A){
	memset(cnt,0,sizeof(cnt)); int res = 0;
	for(rei i = 0;i < A.size();++i) ++cnt[A[i] - '0'];
	for(rei i = 1;i <= 9;++i) res += i * qpow[cnt[i]];
	return res;
} void solve(string A,string B){
	int scoreA = score(A),scoreB = score(B);
	if(scoreA > scoreB){
//		cerr << A[4] << " " << B[4] << endl;
		double P = 1;
		memset(cnt,0,sizeof(cnt));
		for(rei i = 1;i <= 9;++i) cnt[i] = K;
		for(rei i = 0;i < A.size() - 1;++i) --cnt[A[i] - '0'];
		for(rei i = 0;i < B.size() - 1;++i) --cnt[B[i] - '0'];
		int now = 9 * K - 8;
		P *= (double)cnt[A[4] - '0'] / (double)now;--now,--cnt[A[4] - '0'];
		P *= (double)cnt[B[4] - '0'] / (double)now;--now,--cnt[B[4] - '0'];
//		printf("%.10lf\n",P);
		ans += P;
	}
}
int main(){
	cin >> K; cin >> S >> T;
	qpow[0] = 1;
	for(rei i = 1;i <= 9;++i) qpow[i] = qpow[i - 1] * 10;
	for(rei i = 1;i <= 9;++i)
	 for(rei j = 1;j <= 9;++j){
		S[4] = '0' + i,T[4] = '0' + j;
		solve(S,T);
	 } printf("%.10lf",ans); return 0;
}