#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i:x){cout << i << " ";} cout << endl;}
#define isin(x,l,r) ((l)<=(x) && (x)<(r))
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<typename T>bool chmin(T&x,const T&y) {if(x>y){x=y;return true;} else return false;}
template<typename T>bool chmax(T&x,const T&y) {if(x<y){x=y;return true;} else return false;}

struct UnionFind {
    vector<int> d;
    UnionFind(int n): d(n,-1) {}
    int root(int x) {
        if (d[x] < 0) return x;
        return d[x] = root(d[x]);
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y);}
    int size(int x) { return -d[root(x)];}
};  // UnionFind uf(N+1);  // 1-indexed

int main() {
    // 連結成分ごとに計算、頂点数と出てきている色の種類のmin
    int N;
    cin >> N;
    vector<int> colTop(400005, -1);
    UnionFind uf(N);   // 0-indexed
    vector<pii> AB;
    rep(i, N) {
        int a, b;
        cin >> a >> b;
        AB.emplace_back(a, b);
        if (colTop[a] == -1) colTop[a] = i;
        else {
            int c = colTop[a];
            uf.unite(i, c);
        }
        if (colTop[b] == -1) colTop[b] = i;
        else {
            int c = colTop[b];
            uf.unite(i, c);
        }
    }
    vector<set<int>> st(N);
    rep(i, N) {
        int r = uf.root(i);
        auto [a, b] = AB[i];
        st[r].insert(a);
        st[r].insert(b);
    }
    ll ans  = 0;
    rep(i, N) {
        if (uf.root(i) == i) {
            int s = uf.size(i);
            int c = sz(st[i]);
            ans += min(s, c);
        }
    }
    cout << ans << '\n';
    return 0;
}
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = j, i##E = k; i <= i##E; i++)
#define R(i, j, k) for(int i = j, i##E = k; i >= i##E; i--)
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int, int>
#define mkp make_pair
using namespace std;
const int N = 1e4;
int n, k, p[N], pw[N], ss[N];
char s[N], t[N];
ll all = 0,  ans;
bool calc() {
	int sum1 = 0, sum2 = 0;
	
	L(i, 1, 9) ss[i] = 0;
	L(i, 1, 5) ss[s[i] - '0'] ++;
	L(i, 1, 9) sum1 += pw[ss[i]] * i;

	L(i, 1, 9) ss[i] = 0;
	L(i, 1, 5) ss[t[i] - '0'] ++;
	L(i, 1, 9) sum2 += pw[ss[i]] * i;

	return sum1 > sum2;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	pw[0] = 1, 
	pw[1] = 10, 
	pw[2] = 100, 
	pw[3] = 1000, 
	pw[4] = 10000, 
	pw[5] = 100000;
	cin >> k >> (s + 1) >> (t + 1);
	L(i, 1, 4) p[s[i] - '0'] ++;
	L(i, 1, 4) p[t[i] - '0'] ++;

	all = (ll) (k * 9 - 8) * (k * 9 - 9) ;
	L(i, 1, 9) L(j, 1, 9) {
		s[5] = i + '0';
		t[5] = j + '0'; 
		ll pnt = 0;
		if(i == j) pnt = (ll) (k - p[i]) * (k - p[i] - 1);
		else pnt = (ll) (k - p[i]) * (k - p[j]);
		ans += pnt * calc();
	}
	cout.precision(12), cout << fixed;
	cout << (db) ans / all << "\n";
	return 0;
} 