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

int main(){
    cout << fixed << setprecision(15);
    int K;
    string S, T;
    cin >> K;
    cin >> S;
    cin >> T;

    map<int,int> card,tkh,aok;
    for(int i=1; i<=9; i++){
        card[i] = K;
        tkh[i] = 0;
        aok[i] = 0;
    }
    for(int i=0; i<4; i++){
        int a = S.at(i)-'0';
        tkh[a] += 1; 
        card[a] -= 1;
        a = T.at(i)-'0';
        aok[a] += 1; 
        card[a] -= 1;
    }

    double ans=0;
    for(int i=1; i<=9; i++){
        int anst=0;
        if( card[i] > 0 ){
            if( tkh[i] < K ){
                card[i] -= 1;
                tkh[i] += 1;
                for(int j=1; j<=9; j++){
                    anst += j*pow(10,tkh[j]);
                }
                for(int l=1; l<=9; l++){   
                    int ansa=0; 
                    if( card[l] > 0 ){
                        if( aok[l] < K ){
                            aok[l] += 1;
                            for(int m=1; m<=9; m++){
                                ansa += m*pow(10,aok[m]);
                            }
                            if( anst > ansa ){
                               ans += (double(card[i]+1)/double(9*K-8))*(double(card[l])/double(9*K-9));
                            }      
                            aok[l] -= 1;
                        }
                    }
                }
                card[i] += 1;
                tkh[i] -= 1;
            }
        }
    }
    cout << ans << endl;
}

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp> 
#define deb(x) cout<<#x<<" "<<x<<endl;
#define print(arr,n) for(int i=0;i<n;++i) { cout<<arr[i]<<" "; } cout<<endl;
#define ub(x,el) upper_bound(x.begin(),x.end(),el) - x.begin()
#define lb(x,el) lower_bound(x.begin(),x.end(),el) - x.begin();
#define bs(x,el) binary_search(x.begin(),x.end(),el)
#define MOD 1000000007
#define finish return 0
#define all(x) x.begin(),x.end()
using namespace std;
//using namespace __gnu_pbds; 
typedef long long int ll;
//typedef tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<int D, typename T> struct Vec : public vector<Vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!"); template<typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) { }}; template<typename T> struct Vec<1, T> : public vector<T> { Vec(int n = 0, T val = T()) : vector<T>(n, val) { } };
inline ll mod(const ll& x) { return (x%MOD + MOD)%MOD; }
ll gcd(ll a, ll b, ll &x, ll &y){if(a == 0){x = 0, y = 1; return b;} ll x1, y1;  ll d = gcd(b%a, a, x1, y1); x = y1 - (b/a) * x1; y = x1; return d;}
ll power(ll x,ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p;   } return res; } 
ll power(ll x,ll y) { ll res = 1; while (y > 0) { if (y & 1) res = (res*x); y = y>>1; x = (x*x);   } return res; } 
ll mod(ll num, ll den){ return mod(mod(num) * power(den,MOD-2,MOD)); }
vector<ll> primes(ll n) { vector<ll> p; vector<bool> v(n+1,true); for(ll i=2;i*i<=n;++i) { if(v[i]) { for(ll j=i*i;j<=n;j+=i) v[j] = false; } } for(ll i=2;i<=n;++i) if(v[i]) p.push_back(i); return p; }
vector<ll> lpf(ll n){ vector<ll> v(n+1); for(ll i=1;i<=n;++i) v[i] = i; for(ll i=2;i*i<=n;++i) { if(v[i] == i) { for(ll j=i*i;j<=n;j+=i) { v[j] = i; } } } return v; }
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ll case_no = 1;
    ll k;
    cin>>k;
    string s,t;
    cin>>s>>t;
    unordered_map<ll,ll> mp;
    for(ll i=0;i<4;++i)
    {
        mp[s[i]-'0']++;
        mp[t[i]-'0']++;
    }
    ll total = 0;
    ll count = 0;
    for(ll i=1;i<=9;++i)
    {
        for(ll j=1;j<=9;++j)
        {
            ll s1,s2;
            s1 = s2 = 0;
            vector<ll> mp1(10),mp2(10);
            for(ll z=0;z<4;++z)
            {
                mp1[s[z]-'0']++;
                mp2[t[z]-'0']++;
            }
            ll val1 = mp1[i] + mp2[i];
            ll val2 = mp2[j] + mp1[j];
            
            mp1[i]++;
            mp2[j]++;
            bool flag = true;
            for(ll z=1;z<10;++z)
            {
                s1 += (power(10,mp1[z])*z);
                s2 += (power(10,mp2[z])*z);
            }
            for(ll z=0;z<10;++z)
            {
                if((mp1[z] + mp2[z]) > k)
                {
                    flag = false;
                    break;
                }
            }
            if(!flag) continue;

            if(i!=j)
            {
                ll v1 = k-val1;
                ll v2 = k-val2;
                if(s1 > s2) count += (v1*v2);
                
                total += (v1*v2);
            }
            else
            {
                ll v = k-val1;
                total += (v*(v-1));
                if(s1 > s2) count += (v*(v-1));
            }

        }
    }
    double ans = count;
    ans /= total;
   // deb(count);
    //deb(total);
    cout.precision(10);
    cout<<ans<<endl;
}