#include <bits/stdc++.h>
#define rep(i, begin, end) for (i=begin;i<end;i++)
#define printint(i0, i1) printf("%d %d\n", i0, i1)
#define MAX_N 1000

using namespace std;
typedef long long int ll;
const int inf = 1000000000;
const int mod = 1000000007;
const int nil = -1;
ll i, j, n, m, k, ans, l;
ll rest[10], takahashi[10], aoki[10];
string s, t;

int main() {
    scanf(" %lld", &k);
    rep(i,1,10) {
        rest[i] = k;
        takahashi[i] = 0;
        aoki[i] = 0;
    }
    cin >> s;
    cin >> t;

    rep(i,0,4) {
        takahashi[s[i] - '0']++;
        aoki[t[i] - '0']++;
        rest[s[i] - '0']--;
        rest[t[i] - '0']--;
    }
    ll cnt = 0;
    rep(i,1,10) {
        rep(j,1,10) {
            if (rest[i] == 0 || rest[j] == 0) continue;
            takahashi[i]++; aoki[j]++;
            ll score_t = 0, score_a = 0;
            rep(l, 1, 10) {
                score_t += l * pow(10, takahashi[l]);
                score_a += l * pow(10, aoki[l]);
            }
            if (score_t > score_a) cnt += i != j ? rest[i] * rest[j] : rest[i] * (rest[i] - 1);
            takahashi[i]--; aoki[j]--;
        }
    }
    double all = (9 * k - 8) * (9 * k - 9);
    printf("%12.10lf\n", (double)cnt / all);
}
// 問題の URL を書いておく
// 

#include <bits/stdc++.h>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)

using ll = long long;

int calcScore(vector<ll>& hand)
{
    ll score = 0;
    rep(i, 9)
    {
        auto ti = 1 + i;
        score += ti * (ll)pow(10, hand[ti]);
    }
    return score;
}

int main(int, const char**)
{
    ll K;
    cin >> K;
    string S, T;
    cin >> S >> T;
    vector<ll> nums(10, K);

    vector<vector<ll>> hands(2, vector<ll>(10, 0));

    rep(i, 4)
    {
        auto sn = S[i] - '0';
        hands[0][sn]++;
        nums[sn]--;

        auto tn = T[i] - '0';
        hands[1][tn]++;
        nums[tn]--;
    }

    set<pair<int, int>> wp;
    for(int i = 1; i <= 9; ++i)
    {
        for(int j = 1; j <= 9; ++j)
        {
            if(i == j)
            {
                if(!(nums[i] >= 2)) continue;
            }
            if(!(nums[i] >= 1)) continue;
            if(!(nums[j] >= 1)) continue;
            hands[0][i]++;
            hands[1][j]++;
            auto ts = calcScore(hands[0]);
            auto as = calcScore(hands[1]);
            hands[0][i]--;
            hands[1][j]--;
            if(ts > as)
            {
                wp.insert({i, j});
            }
        }
    }

    ll u = 0;

    for(auto& p : wp)
    {
        if(p.first == p.second)
        {
            u += nums[p.first] * (nums[p.first] - 1);
        }
        else
        {
            u += nums[p.first] * nums[p.second];
        }
//        printf("%d, %d\n", p.first, p.second);
    }
    ll d = (K * 9 - 8) * (K * 9 - 9);
    auto ans = u / (double)d;
    printf("%.10f\n", ans);

    return 0;
}
