#include "bits/stdc++.h"
#define int long long
#define pb push_back
using namespace std;
const int MOD = 1e9 + 7;
int power(int z){
    if(z==0)return 1;
    return power(z-1)*10;
}
signed main(){
    int K;
    cin >> K;
    string S,T;
    cin >> S >> T;
    int cnt[10];
    for(int i=1;i<=9;i++)cnt[i]=K;
    int to=9*K-8;
    for(int i=0;i<4;i++){
        --cnt[S[i]-'0'];
        --cnt[T[i]-'0'];
    }
    double ans=0;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            double p_cards=cnt[i]*1.0/to;
            if(i==j) p_cards*=(cnt[j]-1)*1.0/(to-1);
            else p_cards*=cnt[j]*1.0/(to-1);
            int tcnt[10], acnt[10];
            for(int k=1;k<=9;k++) tcnt[k]=acnt[k]=0;
            for(int k=0;k<4;k++){
                ++tcnt[S[k]-'0'];
                ++acnt[T[k]-'0'];
            }
            ++tcnt[i];
            ++acnt[j];
            int t_score=0, a_score=0;
            for(int k=1;k<=9;k++){
                t_score+=k*power(tcnt[k]);
                a_score+=k*power(acnt[k]);
            }
            ans+=(t_score>a_score)*p_cards;
        }
    }
    cout << fixed << setprecision(12) << ans << "\n";
}
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <set>
#include <functional>
#include <map>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
using Interval = pair<ll,ll>;
using Graph = vector<vector<ll> >;
#define fi first
#define se second

struct Edge{
    ll to;
    ll w;
    Edge(ll to, ll w):to(to),w(w){}
};

using wGraph = vector<vector<Edge> >;


template<class T> void chmax(T& a, T b){
    if (a < b){
        a=b;
    }
}

template<class T> void chmin(T& a, T b){
    if (a > b){
        a=b;
    }
}

template<class T> bool chmaxb(T& a, T b){
    if (a < b){
        a=b;
        return true;
    }
    return false;
}

template<class T> bool chminb(T& a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

const ll INF = 1LL << 60;

ll k;
string S,T;


ll MOD = 1000000007;

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    cin >> k;
    cin >> S >> T;
    vector<ll>num(10,k);
    vector<ll> tnum(10,0);
    vector<ll> anum(10,0);

    num[0] = 0;

    rep(i,4){
        ll s = S[i]-'0';
        ll t = T[i]-'0';
        tnum[s] += 1;
        anum[t] += 1;
        num[s] -= 1;
        num[t] -= 1;
    }

    double sum = 0;
    repi(i,1,10) sum+=num[i];
    double ok = 0;

    repi(i,1,10){
        repi(j,1,10){
            if (i == j){
                if (num[i] <= 1) continue;
            }
            else{
                if (num[i] <= 0 || num[j] <= 0) continue;
            }
            ll tc = 0;
            ll ac = 0;
            tnum[i] += 1;
            anum[j] += 1;
            rep(k,10){
                tc += k*modpow(10,tnum[k],MOD);
                ac += k*modpow(10,anum[k],MOD);
            }
            if (tc > ac){
               if (i == j) ok += num[i]*(num[i]-1);
               else ok += num[i]*num[j];
            }
            tnum[i] -= 1;
            anum[j] -= 1;
        }
    }

    cout << fixed << setprecision(15) << ok/(sum*(sum-1)) << endl;
    return 0;
}