#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
const int N = 1e6 + 50;

int k;
int res[10], mul[6];
char s[10], t[10];

int cal(char *s){
    int num[10], val = 0;
    for(int i = 1; i <= 9; ++i)  num[i] = 0;
    for(int i = 1; i <= 5; ++i)  ++num[s[i] - '0'];
    for(int i = 1; i <= 9; ++i)  val += mul[num[i]] * i;
    return val;
}

int main(){
    scanf("%d%s%s", &k, s + 1, t + 1);
    mul[0] = 1;
    for(int i = 1; i <= 5; ++i)  mul[i] = mul[i - 1] * 10;
    for(int i = 1; i <= 9; ++i)  res[i] = k;
    for(int i = 1; i <= 5; ++i){
        --res[s[i] - '0'];
        --res[t[i] - '0'];
    }
    int ret = 9 * k - 8;
    double ans = 0;
    for(int i = 1; i <= 9; ++i)
        for(int j = 1; j <= 9; ++j){
            if((i == j && res[i] < 2) || res[i] < 1 || res[j] < 1)  continue;
            int zz = 0;
            if(i == j)  zz = 1;
            s[5] = '0' + i, t[5] = '0' + j;
            if(cal(s) > cal(t)){
                ans += 1.0 * res[i] / ret * (res[j] - zz) / (ret - 1);
            }
        }
    printf("%lf", ans);
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(void){
    int k;
    cin >> k;
    int a[10];
    for(int i=1;i<=9;i++) a[i] = k;
    string s,t;
    cin >> s >> t;
    int b[10]={},c[10]={};
    for(auto i:s){
        if(i!='#'){
            a[i-'0']--;
            b[i-'0']++;
        } 
    }
    for(auto i:t){
        if(i!='#'){
            a[i-'0']--;
            c[i-'0']++;
        } 
    }
    double ans = 0;
    for(int s=1;s<=9;s++){
        if(a[s]==0) continue;
        b[s]++;
        double d1 = double(a[s])/double(9*k-8);
        a[s]--;
        for(int j=1;j<=9;j++){
            long pt=0,pa=0;
            if(a[j]==0) continue;
            c[j]++;
            double d2 = double(a[j])/double(9*k-9);
            a[j]--;
            rep(i,10) pt += i*pow(10,b[i]);
            rep(i,10) pa += i*pow(10,c[i]);
            if(pt>pa) ans += d1*d2;
            c[j]--;
            a[j]++;
        }
        a[s]++;
        b[s]--;
    }
    cout <<fixed << setprecision(10) << ans << endl;
}
