#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

int pow10(int x){
    int ans = 1;
    while(x--) ans *= 10;
    return ans;
}

ll tri(ll x){
    return x*(x-1);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int k;
    string s, t;
    cin >> k >> s >> t;
    
    auto calc = [&](string s_, int x){
        vector<int> c(10);
        c[x]++;
        for(int i = 0; i <  4; i++) c[s_[i]-'0']++;
        int ans = 0;
        for(int i = 1; i <= 9; i++){
            ans += i*pow10(c[i]);
        }
        return ans;
    };
    double ans = 0.0;
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            vector<ll> rem(10, k);
            for(int l = 0; l < 4; l++) rem[s[l]-'0']--;
            for(int l = 0; l < 4; l++) rem[t[l]-'0']--;
            rem[i]--; rem[j]--;
            bool ok = true;
            for(int l = 1; l <= 9; l++){
                if(rem[l] < 0) ok = false;
            }
            if(ok){
                rem[i]++; rem[j]++;
                double p;
                if(i == j){
                    p = (double)(tri(rem[i]))/(double)(tri(9*k-8));
                }else{
                    p = (double)(rem[i]*rem[j])/(double)(tri(9*k-8));
                }
                if(calc(s, i) > calc(t, j)) ans += p;
                // if(true) ans += p;
            }
        }
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define rep(i, n) for(int i=0;i<n;i++)
#define all(i, v) for(auto& i : v)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

bool solve(vector<ll> v1, vector<ll> v2){
    vector<ll> v(6, 0);
    for(ll i=1;i<=9;i++){
        v[v1[i]] += i;
        v[v2[i]] -= i;
    }
    ll sum = 0;
    ll d = 1;
    rep(i, 6){
        sum += v[i] * d;
        d *= 10;
    }
    if(sum > 0) return true;
    return false;
}

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll k;
    cin >> k;
    ll cnt = k * 9 - 8;
    ll sum = (cnt - 1) * cnt;
    ll win = 0;
    string s, t;
    cin >> s >> t;
    vector<ll> num(10, k), n1(10, 0), n2(10, 0);
    rep(i, 4){
        num[s[i] - '0']--;
        n1[s[i] - '0']++;
        num[t[i] - '0']--;
        n2[t[i] - '0']++;
    }
    for(ll i=1;i<=9;i++){
        for(ll j=1;j<=9;j++){
            if(num[i] == 0) continue;
            ll cnt1 = num[i];
            num[i]--;
            if(num[j] == 0){
                num[i]++;
                continue;
            }
            ll cnt2 = num[j];
            n1[i]++;
            n2[j]++;
            if(solve(n1, n2)) win += cnt1 * cnt2;
            n1[i]--;
            n2[j]--;
            num[i]++;
        }
    }
    doublecout((double)win / (double)sum);
    return 0;
}


