/**
 * Author : RDP
 * There are no two words in the English language more harmful than "good job".
 * 1729 ;)
**/
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << to_string(H);
    debug_out(T...);
}

#define endl '\n'
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#define FAST_IO              \
    ios::sync_with_stdio(0); \
    std::cin.tie(0);         \
    std::cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define PI 3.1415926535897932384626433832795
const ll MOD = 1000000007;
ll ncr(ll n, ll r)
{

    long long p = 1, k = 1;

    if (n - r < r)
        r = n - r;

    if (r != 0)
    {
        while (r)
        {
            p *= n;
            k *= r;

            long long m = __gcd(p, k);

            p /= m;
            k /= m;

            n--;
            r--;
        }
    }

    else
        p = 1;

    return p;
}
long long binpow(long long a, long long b)
{
    long long res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll score(string s)
{
    ll score = 0;
    vector<ll> m(10);
    for (char c : s)
    {
        if (c != '#')
        {
            m[c - '0']++;
        }
    }
    for (int i = 1; i <= 9; i++)
    {
        score += i * binpow(10, m[i]);
    }
    return score;
}
bool wins(string s, string t)
{
    return score(s) > score(t);
}
void test_case()
{
    ll k;
    double event = 0, total_event = 0;
    cin >> k;
    vector<ll> rem(10, k);
    rem[0] = 0;
    string s, t;
    cin >> s >> t;
    for (int i = 0; i <= 3; i++)
        rem[s[i] - '0']--, rem[t[i] - '0']--;
    ll score_s = score(s), score_t = score(t);
    for (int i = 1; i <= 9; i++)
    {
        for (int j = 1; j <= 9; j++)
        {
            if (i != j)
            {
                double x;
                x = max(0LL, rem[i] * rem[j]);
                if (wins(s + char('0' + i), t + char('0' + j)))
                    event += x;
                total_event += x;
            }
        }
    }
    for (int i = 1; i <= 9; i++)
    {
        double x;
        x = max(0LL, (rem[i] - 1) * rem[i]);
        if (wins(s + char('0' + i), t + char('0' + i)))
            event += x;
        total_event += x;
    }
    cout << event / total_event;
    return;
}
int main()
{
    FAST_IO
    int t = 1;
    //cin >> t;
    while (t--)
        test_case();
    return 0;
}

#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define ROF(i, a, b) for (int i = a; i >= b; --i)
#define NEXT(i, u) for (int i = h[u]; i; i = e[i].u)
const int INF = 2e9;
const int K = 1e5 + 7;

int Max(const int &a, const int &b) {return a > b ? a : b;}
int Min(const int &a, const int &b) {return a > b ? b : a;}

int sum[20], tot[20];
int k, n;
double sy;
double ans, sm;
char s[20], t[20];

int po(int x){
    int ans = 1;
    FOR (i, 1, x) ans *= 10;
    return ans;
}

int main(){
    scanf("%d", &k);
    sy = 9 * k - 8;
    scanf(" %s %s", s, t);
    n = strlen(s);
    FOR (i, 0, 3){
        int c = s[i] - '0', cc = t[i] - '0';
        ++sum[c];
        ++tot[cc];
    }
    FOR (i, 1, 9){
        FOR (j, 1, 9){
            if (i == j){
                if (sum[i] + tot[j] + 2 <= k) ++sum[i], ++tot[j];
                else continue;
            }
            else {
                if (sum[i] + tot[i] + 1 <= k && sum[j] + tot[j] + 1 <= k) ++sum[i], ++tot[j];
                else continue;
            }
            int sc1 = 0, sc2 = 0;
            FOR (l, 1, 9){
                sc1 += l * po(sum[l]);
                sc2 += l * po(tot[l]);
            }
            --sum[i];
            --tot[j];
            if (sc1 > sc2){
                if (i == j) ans += (1.0 * (1.0 * k - sum[i] - tot[i]) / sy) * (1.0 * (1.0 * k - sum[j] - tot[j] - 1) / (sy - 1));
                else ans += (1.0 * (1.0 * k - sum[i] - tot[i]) / sy) * (1.0 * (1.0 * k - sum[j] - tot[j]) / (sy - 1));
            }
        }
    }
    printf("%.16lf\n", ans);
    return 0;
}