#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
 
int f(string s){
	vector<int> a(10);
	for(char c : s) a[c - '0']++;
	int res = 0;
	for(int i = 1; i <= 9; i++){
		int x = 1;
		for(int j = 0; j < a[i]; j++){
			x *= 10;
		}
		res += x * i;
	}
	return res;
}
 
signed main(void){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int k;
	cin >> k;
	string s, t;
	cin >> s >> t;
	vector<int> c(10, k);
	c[0] = 0;
	for(int i = 0; i < 4; i++){
		c[s[i] - '0']--;
		c[t[i] - '0']--;
	}
	int cnt = 0;
	for(int a = 1; a <= 9; a++){
		for(int b = 1; b <= 9; b++){
			s[4] = '0' + a;
			t[4] = '0' + b;
			if(f(s) > f(t)){
				if(a == b) cnt += c[a] * (c[a] - 1);
				else cnt += c[a] * c[b];
			}
		}
	}
	int C = 0;
	for(int i = 0; i < 10; i++){
		C += c[i];
	}
	int tot = C * (C - 1);
	double ans = (double) cnt / tot;
	printf("%.10f\n", ans);
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128_t LL;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define F first
#define S second
#define pb push_back
mt19937 rnd;

const int N = 1e5 + 10;
vector<ll> a[3];

bool is_even(int x) {
    return !(x & 1);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    int n;
    cin >> n;
    n *= 2;
    for (int i = 1; i <= n; i++) {
        ll val;
        char ch;
        cin >> val >> ch;
        if (ch == 'R') a[0].pb(val);
        else if (ch == 'G') a[1].pb(val);
        else a[2].pb(val);
    }
    for (int i = 0; i < 3; i++) {
        sort(a[i].begin(), a[i].end());
    }
    ll ans = 1e18;
    if (is_even(a[0].size()) && is_even(a[1].size()) && is_even(a[2].size())) {
        ans = 0;
    }
    for (int x = 0; x < 3; x++) {
        for (int y = x + 1; y < 3; y++) {
            int z = 3 - x - y;
            if (!is_even(a[x].size()) && !is_even(a[y].size())) {
                assert(is_even(a[z].size()));
                for (int i = 0, j = 0; i < a[x].size(); i++) {
                    while (j + 1 < a[y].size() && a[y][j] < a[x][i]) {
                        j++;
                    }
                    ll cur = 1e18;
                    for (int k = max(0, j - 5); k <= min(int(a[y].size() - 1), j + 5); k++) {
                        cur = min(cur, abs(a[x][i] - a[y][k]));
                    }
                    ans = min(ans, cur);
                }
                if (!a[z].empty()) {
                    vector<pair<ll, int>> lef, rig;
                    for (int i = 0, j = 0; i < a[z].size(); i++) {
                        while (j + 1 < a[x].size() && a[x][j] < a[z][i]) {
                            j++;
                        }
                        ll cur = 1e18;
                        for (int k = max(0, j - 5); k <= min(int(a[x].size() - 1), j + 5); k++) {
                            cur = min(cur, abs(a[z][i] - a[x][k]));
                        }
                        lef.pb({cur, i});
                    }
                    for (int i = 0, j = 0; i < a[z].size(); i++) {
                        while (j + 1 < a[y].size() && a[y][j] < a[z][i]) {
                            j++;
                        }
                        ll cur = 1e18;
                        for (int k = max(0, j - 5); k <= min(int(a[y].size() - 1), j + 5); k++) {
                            cur = min(cur, abs(a[z][i] - a[y][k]));
                        }
                        rig.pb({cur, i});
                    }
                    sort(lef.begin(), lef.end());
                    sort(rig.begin(), rig.end());
                    for (int i = 0; i < lef.size() && i < 10; i++) {
                        for (int j = 0; j < rig.size() && j < 10; j++) {
                            if (lef[i].S != rig[j].S) {
                                ans = min(ans, lef[i].F + rig[j].F);
                            }
                        }
                    }
                }
            }
        }
    }
    cout << ans << "\n";

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}
