#include<bits/stdc++.h>
using namespace std;

typedef pair<int,int> P;
typedef long long ll;

#define int ll

ll score(char c[], int a){
	ll ans = 0;
	int num[10];
	for(int i=0;i<10;i++) num[i]=0ll;
	for(int i=0;i<4;i++) num[c[i]-'0']++;
	num[a]++;

	for(int i=0;i<10;i++) ans += i*pow(10,num[i]);

	return ans;
}


main(){
	int k;
	char s[10],t[10];
	
	cin >> k >> s >> t;

	int card[10];
	card[0] = 0;
	for(int i=1;i<=9;i++) card[i] = k;

	for(int i=0;i<4;i++) card[s[i]-'0']--;
	for(int i=0;i<4;i++) card[t[i]-'0']--;
	
	ll sum = (9ll*k-8ll)*(9ll*k-9ll);

	ll win = 0ll;

	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			if(score(s, i)>score(t,j)){
				if(i==j){
					if(card[i]>=2) win += card[i]*(card[i]-1);
				}else{
					win += card[i]*card[j];
				}
			}
		}
	}
	double ans = (double) win / sum;

	printf("%.10lf\n",ans);

	return 0;
}

#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;

int calc_score(long score, int cards, int p){
    score -= p* pow(10, cards - 1);
    score += p * pow(10, cards);
    return score;
}

int main(){
    long k;
    cin >> k;
    int s_in, t_in;
    vector<int> s(4);
    vector<int> t(4);
    scanf("%d# %d#",&s_in, &t_in);
    vector<int> card_s(9);
    vector<int> card_t(9);
    long cs = 0;
    long ct = 0;
    int a = 1000;
    for(int i = 0; i < 4; i++){
        s[i] = s_in / a;
        t[i] = t_in / a;
        s_in -= s[i]*a;
        t_in -= t[i]*a;
        a = a/10;
        card_s[s[i] - 1]++;
        card_t[t[i] - 1]++;
    }
    for(int i = 0; i < 4; i++){
        int si = s[i];
        int ti = t[i];
    }
    for(int i = 1; i < 10; i++){
        cs += i * pow(10, card_s[i - 1]);
        ct += i * pow(10, card_t[i - 1]);
    }
    long kati = 0;
    for(int i = 1; i < 10; i++){
        if(card_s[i-1] + card_t[i-1]== k) continue;
        for(int j = 1; j < 10; j++){
            if(card_s[j-1] + card_t[j-1]== k) continue;
            if(i == j && card_s[i-1] + card_t[i-1] + 2 > k){
                continue;
            }
            if(calc_score(cs, card_s[i-1]+1, i) > calc_score(ct, card_t[j-1]+1, j)){
                if(i == j){
                    kati += (k - card_s[i-1] - card_t[i-1]) * (k - card_s[i-1] - card_t[i-1] - 1);
                }
                else{
                    kati += (k - card_s[i-1] - card_t[i-1]) * (k - card_s[j-1] - card_t[j-1]);
                }
            }

        }
    }
    double ans = (double)kati / ((9.0 * k  - 8.0) * (9.0 * k - 9.0));
    cout << ans << endl;


    return 0;
}