#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long LL;

const LL N = 1e10;

LL a[10];
LL b[10],c[10];

int main()
{
    LL k;
    cin >> k;
    for(int i = 1;i <= 9;i++){
        a[i] = k;
    }
    string s1,s2;
    cin >> s1 >> s2;
    for(int i = 0;i < 4;i++){
        b[s1[i] - '0']++;
        c[s2[i] - '0']++;
    }
    for(int i = 1;i <= 9;i++){
        int cnt = b[i];
        a[i] -= cnt;
        b[i] = i;
        while (cnt--)
        {
            b[i] *= 10;
        }
        int cnt1 = c[i];
        a[i] -= cnt1;
        c[i] = i;
        while (cnt1--)
        {
            c[i] *= 10;
        }
    }
    LL count = (9 * k - 8) * (9 * k - 9);//total
    LL res = 0;
    for(int i = 1;i <= 9;i++){
        for(int j = 1;j <= 9;j++){
            if(i == j && a[i] < 2){
                
            }else if(a[i] <= 0 || a[j] <= 0){
                continue;
            }else {
                b[i] *= 10;
                c[j] *= 10;
                LL sum = 0;
                for(int m1 = 1;m1 <= 9;m1++){
                    sum += b[m1];
                    sum -= c[m1];
                }
                if(sum > 0){
                    if(i == j){
                        res += a[i] * (a[j] - 1);
                    }else {
                        res += a[i] * a[j];
                    }
                }
                b[i] /= 10;
                c[j] /= 10;
            }
        }
    }
    //cout << res << "===" << count << endl;
    printf("%.7lf",double(res) / count);
    return 0;
}
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
#include <set>
#include <limits>
#include <string>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <numeric>

using namespace std;

using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

/* input & output */
#define IN(a) cin >> a
#define OUT(a) cout << a << endl
#define OUT_PREC(a, n) cout << fixed << setprecision(n) << a << endl

/* vector */
#define VEC(t, v, n, ini) vector<t> v(n, ini)
#define VEC2(t, v, m, n, ini) vector<vector<t>> v(m, vector<t>(n, ini))
#define VEC3(t, v, k, m, n, ini) vector<vector<vector<t>>> v(k, vector<vector<t>>(m, vector<t>(n, ini)))

/* bit */
#define IS_TRUE(bit, i) (bit & (1 << i))   // bitのi成分
#define FLAG_ON(bit, i) (bit｜(1 << i))    // bitのi成分をtrueに
#define FLAG_OFF(bit, i) (bit & ~(1 << i)) // bitのi成分をfalseに
#define ALL_TRUE(n) (1 << n)               // 2^n
#define CMPSET(bit, s) (bit ^ s)           // sのbitに対する補集合
#define INCLUDES(a, b) ((a & b) == b)      // aはbを含むか

double solve()
{
    int k;

    cin >> k;

    int s[9] = {0};
    int t[9] = {0};
    int rest[9] = {k, k, k, k, k, k, k, k, k};
    int crdnum = 9 * k - 8;

    string tmp;
    cin >> tmp;
    FOR(i, 0, 4)
    {
        ++s[tmp[i] - '1'];
        --rest[tmp[i] - '1'];
    }
    cin >> tmp;
    FOR(i, 0, 4)
    {
        ++t[tmp[i] - '1'];
        --rest[tmp[i] - '1'];
    }

    vector<vector<bool>> win(9, vector<bool>(9, false));

    FOR(i, 0, 9)
    {
        FOR(j, 0, 9)
        {
            ++s[i];
            ++t[j];

            ll ps = 0;
            ll pt = 0;

            FOR(k, 0, 9)
            {
                ps += (k + 1) * pow(10, s[k]);
                pt += (k + 1) * pow(10, t[k]);
            }

            if (ps > pt)
                win[i][j] = true;

            --s[i];
            --t[j];
        }
    }

    double ans = 0;
    double test = 0;

    FOR(i, 0, 9)
    {
        if (rest[i] > 0)
        {
            double pos = (double)rest[i] / (double)crdnum;
            --rest[i];
            FOR(j, 0, 9)
            {
                if (rest[j] > 0)
                {
                    double npos = pos * ((double)rest[j] / (double)(crdnum - 1));
                    test += npos;
                    if (win[i][j])
                        ans += npos;
                }
            }
            ++rest[i];
        }
    }

    return ans;
}

int main()
{
    /* solve */
    OUT_PREC(solve(), 15);
    system("pause");
}