#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;

int score(string S){
    int res=0;
    vector<int> a(10);
    for(char c: S)a[c-'0']++;
    for(int i=1; i<=9; i++){
        int x=1;
        for(int j=0; j<a[i]; j++)x*=10;
        res+=i*x;
    }
    return res;
}

int main(){
    int K;
    long long cnt=0;
    string S,T;
    cin >> K >> S >> T;
    vector<int> c(10,K);
    
    for(int i=0; i<4;i++){
        c[S[i]-'0']--;
        c[T[i]-'0']--;
    }

    for(int i=1; i<=9;i++)for(int j=1; j<=9; j++){
        S[4] = '0' + i;
        T[4] = '0' + j;
        if(score(S) > score(T)){
            cnt += (long long)c[i]*(c[j]-(i==j)); 
        }
    }
    long long u=9LL*K-8;
    cout << fixed << setprecision(9) << (double)cnt/(u*(u-1)) << endl;
}
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i <= b ; ++i)
#define per(i, a, b) for(int i = b ; i >= a  ; --i)
#define int long long

using namespace std;

double card[10];

int S[6],T[6];

bool bigger()
{
	int sums=0,sumt=0;
	for(int i=1;i<=9;i++)
	{
		int x=i;
		for(int j=1;j<=5;j++)if(S[j]==i)x*=10;
		sums+=x;
		x=i;
		for(int j=1;j<=5;j++)if(T[j]==i)x*=10;
		sumt+=x;
	}
	return sums>sumt;
}

signed main()
{
	double tot;int K;
	cin>>K;
	tot=(double)(9*K);
	string s,t;
	cin>>s>>t;
	tot-=8.0;
	for(int i=1;i<=9;i++)card[i]=K;
	rep(i,0,3)
	{
		S[i+1]=(int)(s[i]-'0');
		T[i+1]=(int)(t[i]-'0');
		card[S[i+1]]--;
		card[T[i+1]]--;
	}
	double win=0.0;
	rep(i,1,9)
	{
		if(card[i]==0)continue;
		rep(j,1,9)
		{
			if(card[j]==0)continue;
			if(i==j)continue;
			S[5]=i;T[5]=j;
			if(bigger())
			{
				double base=tot*(tot-1.0);
				double son=(double)(card[i]*card[j]);
				son/=base;
				win+=son;
			}
		}
		if(card[i]>=2)
		{
			S[5]=i;T[5]=i;
			if(bigger())
			{
				double base=tot*(tot-1.0);
				double son=(double)(card[i]*(card[i]-1));
				son/=base;
				win+=son;
			}
		}
	}
//	if(win>1.0)win=1.0;
	printf("%.8f",win);
	return 0;
}