#include <bits/stdc++.h>
#define ll long long 
#define endl "\n"

#define spacex ios_base::sync_with_stdio(false);cin.tie(NULL)

using namespace std; 


long long int score(string temp)
{
    vector<long long int> cnt(10,0);

    // iota(cnt.begin(),cnt.end(),0);
    // that is, it will assign or make increasing vector by +1
    // 0,1,2,3,4,5,6,7,8,9
    for(long long int i=0;i<10;i++)
    {
        cnt[i]=i;
    }
    for(char x:temp)
    {
        cnt[x-'0']*=10;
    }
    return accumulate(cnt.begin(),cnt.end(),0);
}
   
int main() 
{ 
    #ifndef ONLINE_JUDGE 
    freopen("i.txt", "r", stdin);   
    freopen("o.txt", "w", stdout); 
    #endif
    spacex;

    int k;
    cin>>k;
    string s,t;
    cin>>s>>t;
    vector<long long int> count(10,k);
    for(int i=0;i<4;i++)
    {
        count[s[i]-'0']--;
    }
    for(int i=0;i<4;i++)
    {
        count[t[i]-'0']--;
    }
    long long int win=0;
    for(int i=1;i<=9;i++)
    {
        for(int j=1;j<=9;j++)
        {
            s.back()='0'+i;
            t.back()='0'+j;

            if(score(s)<=score(t))
            {
                continue;
            }
            else
            {
                win+=(count[i]*(count[j]-(i==j)));
            }
        }
    }

    const ll rem = 9 * k - 8;
    cout << double(win) / rem / (rem - 1) << endl;

    return 0; 
}
#include<bits/stdc++.h>
using namespace std;
double eps=1e-7;
char a[10],b[10];
long long shi[7]={1,10,100,1000,10000,100000,1000000};
long long aa,bb,K,sum[15],cnta[15],cntb[15];
long long ans1,ans2;
int main()
{
	cin>>K;
	scanf("%s",a+1);
	scanf("%s",b+1);	
	for(int i=1;i<=9;i++) sum[i]=K;
	for(int i=1;i<=4;i++){
		sum[a[i]-'0']--;
		sum[b[i]-'0']--;
		cnta[a[i]-'0']++;
		cntb[b[i]-'0']++;
		//cout<<a[i]-'0'<<" "<<b[i]-'0'<<endl;
	}
//	for(int i=1;i<=9;i++){
//		cout<<cnta[i]<<" "<<cntb[i]<<endl;
//	}
//	cout<<endl;
	for(int i=1;i<=9;i++){
		if(sum[i]){
			for(int j=1;j<=9;j++){
				if(sum[j]){
					aa=0,bb=0;
					for(int k=1;k<=9;k++){
						aa=aa+k*(shi[cnta[k]+(k==i?1:0)]);
//						if(i==9)
//							cout<<aa<<endl;
						bb=bb+k*(shi[cntb[k]+(k==j?1:0)]);
//						if(j==8)
//							cout<<bb<<endl;
						//cout<<aa<<" "<<bb<<endl;
					}
					if(aa>bb){
						if(i!=j) ans1=ans1+sum[i]*sum[j];
						//cout<<i<<" "<<j<<" ";
						else ans1=ans1+sum[i]*(sum[i]-1);
							//cout<<ans1<<endl;
					}
				}
			}
		}
	}
	ans2=(K*9-8)*(K*9-9);
	//cout<<ans1<<" "<<ans2<<endl;
	printf("%.10f",(double)ans1/(double)ans2);
 	return 0;
}
