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

vector<int> a(10,0),b(10.0),c(10,0);


int f(int i){
    int S=0;
    for(int j=1;j<=9;j++){
        if(j!=i) S+=j*(int)pow(10,b.at(j));
        else S+=j*(int)pow(10,b.at(j)+1);
    }
    return S;
}

int g(int i){
    int S=0;
    for(int j=1;j<=9;j++){
        if(j!=i) S+=j*(int)pow(10,c.at(j));
        else S+=j*(int)pow(10,c.at(j)+1);
    }
    return S;
}

int main(){
    int64_t k,cnt1,cnt2=0;
    string s,t;
    cin >> k >> s >> t;
    cnt1=(9*k-8)*(9*k-9);
    int S,T;
    for(int i=0;i<4;i++){
        int x=s.at(i)-'0',y=t.at(i)-'0';
        a.at(x)++; b.at(x)++;
        a.at(y)++; c.at(y)++;
    }
    for(int i=1;i<=9;i++){
        if(a.at(i)+1>k) continue;
        for(int j=1;j<=9;j++){
            if(a.at(j)+1>k || (i==j && a.at(j)+2>k)) continue;
            S=f(i),T=g(j);
            if(S>T){
                if(i!=j) cnt2+=(k-a.at(i))*(k-a.at(j));
                else cnt2+=(k-a.at(i))*(k-a.at(j)-1);
            }
        }
    }
    long double d=(long double)cnt2/(long double)cnt1;
    cout << fixed << setprecision(12);
    cout << d << endl;
    return 0;
}
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
using ll = int64_t;

ll score(string S){
    vector<ll> cnt(10);
    iota(cnt.begin(), cnt.end(), 0);
    for(char c : S) cnt[c - '0'] *= 10;
    return accumulate(cnt.begin(), cnt.end(), 0);
}
int main(){
    ll K;
    string S, T;
    cin >> K >> S >> T;
    vector<ll> cnt(10, K);
    for(char c : S + T) cnt[c - '0']--;
    ll win = 0;
    for(ll x = 1; x <= 9; x++) for(ll y = 1; y <= 9; y++){
        S.back() = '0' + x;
        T.back() = '0' + y;
        if(score(S) <= score(T)) continue;
        win += cnt[x] * (cnt[y] - (x == y));
    }
    const ll rem = 9 * K - 8;
    cout << double(win) / rem / (rem - 1) << endl;
}
