#include <bits/stdc++.h>
#ifdef DEBUG_BUILD
# include "debugger.hpp"
#else
# define debug(...)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using pll = std::pair<ll, ll>;
template <class T> using vec = std::vector<T>;
template <class T> using vec2 = std::vector<vec<T>>;
template <class T> using vec3 = std::vector<vec2<T>>;
#define rep(i, N) for (ll i = 0; i < (N); i++)
#define rrep(i, N) for (ll i = (N) - 1; i >= 0; i--)
#define range(i, A, B) for (ll i = (A); i < (B); i++)
constexpr int MOD = 1000000007;
constexpr ll INFL = std::numeric_limits<ll>::max();
template <class T> bool chmax(T &a, const T b) { if (a < b) { a = b; return true; } return false; }
template <class T> bool chmin(T &a, const T b) { if (a > b) { a = b; return true; } return false; }

ll pow10(ll n) {
    ll r = 1;
    rep(i, n) {
        r *= 10;
    }
    return r;
}

ll score(const string& s, ll n) {
    vec<ll> count(10);
    rep(i, 4) {
        count[s[i] - '0']++;
    }
    count[n]++;
    ll point = 0;
    rep(i, 10) {
        point += i * pow10(count[i]);
    }
    return point;
}

void Main()
{
    ll K;
    string S, T;
    cin >> K >> S >> T;

    vec<ll> remc(10, K);
    remc[0] = 0;
    rep(i, 5) {
        remc[S[i] - '0']--;
        remc[T[i] - '0']--;
    }

    ll ret = 0;
    for (ll send = 1; send <= 9; send++) {
        if (remc[send] == 0)
            continue;
        debug(send);

        const ll ss = remc[send];
        debug(ss);

        remc[send]--;
        for (ll tend = 1; tend <= 9; tend++) {
            if (remc[tend] == 0)
                continue;
            debug(tend);

            const ll ts = remc[tend];
            const ll sc = score(S, send);
            const ll tc = score(T, tend);
            debug(sc, tc);

            if (sc > tc) {
                ret += ss * ts;
            }
        }
        remc[send]++;

        debug(ret);
    }

    cout << (ld)ret / ((9*K-8)*(9*K-9)) << endl;
}

int main()
{
    std::cout << std::fixed << std::setprecision(10);
    Main();
    std::cout << std::flush;
    return 0;
}
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include<string>
using namespace std;

int main(){

long long k;
cin>>k;
long long count1[10]={0};
long long count2[10]={0};
long long count3[10]={0};
for(long long i=1;i<=9;i++){
  count3[i]=k;
}
string s;
string t;
cin>>s;
cin>>t;
for(long long i=0;i<4;i++){
  count1[s[i]-'0']++;
  count3[s[i]-'0']--;
}
for(long long i=0;i<4;i++){
  count2[t[i]-'0']++;
  count3[t[i]-'0']--;
}
long long sum1=0;
long long sum2=0;
long long temp=(9*k-8)*(9*k-9);
long long sum3=0;
for(long long i=1;i<=9;i++){
  sum1+=i*pow(10,count1[i]);
  sum2+=i*pow(10,count2[i]);
}

for(long long i=1;i<=9;i++){
  for(long long j=1;j<=9;j++){
    if(i==j){
      if((sum1-i*pow(10,count1[i])+i*pow(10,count1[i]+1))>(sum2-j*pow(10,count2[j])+j*pow(10,count2[j]+1))){
        sum3+=(count3[i])*(count3[i]-1);

      }
    }
    else{
      if((sum1-i*pow(10,count1[i])+i*pow(10,count1[i]+1))>(sum2-j*pow(10,count2[j])+j*pow(10,count2[j]+1))){
        sum3+=(count3[i])*(count3[j]);

      }
    }
  }
}

double ans=(double)((double)sum3/temp);
printf("%.16f", ans);
return 0;
}
