#include <algorithm>
#include <iostream>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cmath>
#include <climits>
#include <queue>
#include <bitset>
using namespace std;
typedef vector<vector<long> > dim2veclo;
typedef vector<vector<int> > dim2vecin;
typedef vector<int> vecin;
typedef vector<long> veclo;

vecin takahashi = vecin(10, 0); 
vecin aoki = vecin(10, 0);
vector<double> maisuu;
long tensuuT = 0, tensuuA = 0;

int main() {
    cout << fixed << setprecision(15);
    int k;
    double kakuritu = 0;
    cin >> k;
    string s, t;
    cin >> s >> t;
    maisuu = vector<double>(10, k);
    for (int i = 0; i < 4; i++) {
        int ss = s[i] - '0';
        int tt = t[i] - '0';
        takahashi[ss]++;
        aoki[tt]++;
        maisuu[ss]--;
        maisuu[tt]--;
    }
    for (int i = 1; i <= 9; i++) {
        tensuuT += (i * pow(10, takahashi[i]));
        tensuuA += (i * pow(10, aoki[i]));
    }
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if (i == j) {
                if (maisuu[i] <= 1) continue;
            }
            else {
                if (maisuu[i] == 0) continue;
                if (maisuu[j] == 0) continue;
            }
            long T = tensuuT + i * 9 * pow(10, takahashi[i]);
            long A = tensuuA + j * 9 * pow(10, aoki[j]);
            if (T > A) {
                double bunbo = 9 * k - 8;
                double bunsi1 = maisuu[i];
                double bunsi2;
                if (i == j) bunsi2 = maisuu[i] - 1;
                else bunsi2 = maisuu[j];
                kakuritu += (bunsi1 / bunbo) * (bunsi2 / (bunbo - 1));
            }
        }
    }
    cout << kakuritu;


    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using vtll = vector<tll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); }
void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); }
template<typename T,typename U>
ostream& operator<<(ostream& os, const pair<T,U>& p) { 
    cerr << ' ' <<  p.x << ',' << p.y; return os; }
template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) { 
    for(auto x: v) os << ' ' <<  x; return os; }
template <typename T> 
ostream& operator<<(ostream& os, const set<T>& v) { 
    for(auto x: v) os << ' ' <<  x; return os; }
template<typename T,typename U>
ostream& operator<<(ostream& os, const map<T,U>& v) { 
    for(auto x: v) os << ' ' <<  x; return os; }
struct d_ {
    template<typename T> d_& operator,(const T& x) {
        cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define deb(X ...) dbg(#X, "=", X);
#define EPS (1e-10)
#define INF (1LL<<61)
#define YES(x) cout << (x ? "YES" : "NO") << endl;
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

ll score(map<ll,ll> m) {
    ll ret = 0;
    for(auto i: m) ret += i.x*pow(10,i.y);
    return ret;
}

int main(void) {
    ios_base::sync_with_stdio(false);
    ll k; string s,t; cin >> k >> s >> t;
    vll v(10,k); v[0]=0;
    map<ll,ll> A,B; FOR(i,1,10) { A[i]=0; B[i]=0; }
    F(4) { v[s[i]-'0']--; A[s[i]-'0']++; }
    F(4) { v[t[i]-'0']--; B[t[i]-'0']++; }
    ll cnt = 0; FOR(i,1,10) cnt+=v[i];
    double ret = 0;
    FOR(a,1,10) FOR(b,1,10) {
        v[a]--; v[b]--;
        bool nok = v[a]<0 || v[b]<0;
        v[a]++; v[b]++;
        if(!nok) {
            A[a]++; B[b]++;
            if(score(A) > score(B)) {
//                 dbg(v[a],v[b],cnt);
                double cur = double(v[a])/(cnt) * (v[b]-(a==b))/(cnt-1);
                ret+=cur;
//                 dbg(a,b,cur, score(A), score(B));
            }
            A[a]--; B[b]--;
        }
    }
    cout << fixed << setprecision(8) << ret << endl;
    return 0;
}
