#include<bits/stdc++.h>
#include<string>

using namespace std;

#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007
vector<ll> cnt(10 , 0) , cnt1(10 , 0);
ll p(ll a , ll n){
    if(n == 0){
        return 1;
    }
    ll res = p(a*a , n / 2);
    if(n % 2){
        res *= a;
    }
    return res;
}
ll calc(string b){
    ll res = 0;
    for(ll i = 1; i <= 9; i++){
        res += (i * p(10LL , cnt1[i]));
    }
    return res;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll k;
    cin>>k;
    string s , t;
    cin>>s>>t;
    for(int i = 0; i < 4; i++){
        cnt[s[i] - '0']++;
        cnt[t[i] - '0']++;
    }
    ld m = 9*k - 8;
    ld total = m*(m - 1);
    ld ans = 0;
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            for(int l = 0; l < 10; l++){
                cnt1[l] = 0;
            }
            cnt1[i]++;
            for(int l = 0; l < 4; l++){
                cnt1[s[l] - '0']++;
            }
            ll tak = calc(s);
            for(int l = 0; l < 10; l++){
                cnt1[l] = 0;
            }
            cnt1[j]++;
            for(int l = 0; l < 4; l++){
                cnt1[t[l] - '0']++;
            }
            ll aoki = calc(t);
            if(tak > aoki){
                if(i == j){
                    ans += ((k - cnt[i]) * (k - cnt[j] - 1));
                }else{
                    ans += ((k - cnt[i]) * (k - cnt[j]));
                }
            }
        }
    }
    ans /= total;
    cout<<fixed<<setprecision(16)<<ans<<"\n";
    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(auto 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;
}
