//wtrl,everybody hangbeat me
#include<bits/stdc++.h>
/*#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>*/
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<ll,ll> pll;
/*=====================================================================*/
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define sz(a) (int)(a.size())
#define all(s) (s).begin(),(s).end()
#define m_p make_pair
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,p,n) for(int i=p;i<=n;i++)
#define ford(i,p,n) for(int i=n;i>=p;i--)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i)
#define INF 1e9
#define PI acos(-1)
/*=====================================================================*/
string int_to_string(ll n)
{
	string s="";
	while(n)
	{
		ll now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
ll string_to_int(string s)
{
	ll n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
/*======================================================================*/
ll lcm(int a,int b)
{
	return a/__gcd(a,b)*b;
}
bool prime(int n)
{
	if(n==0||n==1)
	  return false;
	for(int i=2;i*i<=n;i++)
	  if(n%i==0)
	    return false;
	return true;
}
/*======================================================================*/
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
const int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
ll cnt[20],cnt1[20],cnt2[20];
ll quickpower(ll n,ll k)
{
	ll cnt=1;
	while(k)
	{
	  //cout<<k<<endl;
	  if(k&1)
	  {
	  	cnt*=n;
	  }	
	  n*=n;
	  k>>=1;
	} 
	//cout<<n<<" "<<k<<" "<<cnt<<endl;
	return cnt;
}
/*======================================================================*/
int main()
{
    std::ios::sync_with_stdio(false);
  /*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
  */
  /*====================================================================*/
  ll k;
  cin>>k;
  rep(i,9)
  {
  	cnt[i+1]=k;
  }
  string S,T;
  cin>>S>>T;
  rep(i,4)
  {
  	cnt[S[i]-'0']--;
  	cnt1[S[i]-'0']++;
  	cnt[T[i]-'0']--;
  	cnt2[T[i]-'0']++;
  }
  ll ans=0;
  forn(i,1,9)
  {
  	forn(j,1,9)
  	{
  	  if(cnt[i]==0||cnt[j]==0||(i==j&&cnt[i]<=1))
	  {
	    continue;		
	  }	
	  cnt1[i]++;
	  cnt2[j]++;
	  ll ans1=0,ans2=0;
	  forn(k,1,9)
	  {
	  	ans1+=k*quickpower(10,cnt1[k]);
	  	ans2+=k*quickpower(10,cnt2[k]);
	  }
	  if(ans1>ans2)
	  {
	  	if(i==j)
	  	{
	  	  ans+=cnt[i]*(cnt[i]-1);	
		}
		else
		{
	  	  ans+=cnt[i]*cnt[j];
	    }
	    //cout<<i<<" "<<j<<endl;
	  }
	  cnt1[i]--;
	  cnt2[j]--;
	}
  }
  //cout<<ans<<" "<<(k*9-8)*(k*9-9)<<endl;
  cout<<fixed<<setprecision(6)<<(double)ans/((k*9-8)*(k*9-9))<<endl;
  return 0;
}
/*
注意数组越界，vector长度为0的时候循环会RE
注意输入顺序
*/




#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int k;
    string s, t;
    cin >> k >> s >> t;

    int p[10];
    for (int i = 1; i <= 9; i++) {
        p[i] = k;
    }
    for (int i = 0; i < 4; i++) {
        s[i] -= '0';
        t[i] -= '0';
        p[s[i]]--;
        p[t[i]]--;
    }

    auto f = [](const string &s) {
        int p[10] = {};
        for (int i = 0; i < 5; i++) {
            p[s[i]]++;
        }
        int r = 0;
        for (int i = 1; i <= 9; i++) {
            r += i * (int)pow(10, p[i]);
        }
        return r;
    };

    double r = 0;
    int l = k * 9 - 8;
    for (int a = 1; a <= 9; a++) {
        for (int b = 1; b <= 9; b++) {
            if (a == b && p[a] < 2) continue;
            if (p[a] < 1) continue;
            if (p[b] < 1) continue;
            s[4] = a;
            t[4] = b;
            int x = f(s) > f(t);
            r += (double)p[a] / l * (double)(p[b] - (a == b)) / (l - 1) * x;
        }
    }

    printf("%.12f\n", r);

    return 0;
}