#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define print(x) if(x)cout<<"YES\n";else cout<<"NO\n";
#define pb push_back
#define F first
#define S second
//#define mod 1000000007
#define mod 998244353
using namespace __gnu_pbds;
using namespace std;
long long int binaryexpo(long long x, long long n)
{
	if (n == 0)
		return 1;
	else if (n & 1)
		return (x * binaryexpo(x * x, (n - 1) / 2));
	else
		return binaryexpo(x * x, (n / 2));
}
ll score(string x) {
	ll freq[10] = {};
	for (auto c : x) {
		freq[c - '0']++;
	}
	ll sc = 0;
	for (ll i = 1; i <= 9; i++) {
		ll temp = i * binaryexpo(10, freq[i]);
		sc += temp;
	}
	return sc;
}
void solve() {
	cout << fixed << setprecision(20);
	ll k;
	cin >> k;
	vector<ll> v(9, k);
	for (int i = 0; i < 9; i++) {
		v[i] = k;
	}
	string s, t;
	cin >> s >> t;
	for (auto x : s) {
		v[x - '1']--;
	}
	for (auto x : t) {
		v[x - '1']--;
	}
	ll total = (9 * k - 8) * (9 * k - 9), cnt = 0;
	long double ans = 0.00;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (i == j && v[i - 1] > 1) {
				string a = s.substr(0, 4);
				a.pb((i + '0'));
				string b = t.substr(0, 4);
				b.pb((i + '0'));
				ll x = score(a);
				ll y = score(b);
				if (x > y) {
					ll aa = v[i - 1] * (v[i - 1] - 1) ;
					ans += (long double)aa / total ;
					cnt += aa;
				}
			}
			else if (i != j && v[i - 1] > 0 && v[j - 1] > 0) {
				string a = s.substr(0, 4);
				a.pb((i + '0'));
				string b = t.substr(0, 4);
				b.pb((j + '0'));
				ll x = score(a);
				ll y = score(b);
				if (x > y) {
					ll aa = v[i - 1] * v[j - 1];
					ans += (long double)aa / total;
					cnt += aa;
				}
			}
		}
	}
	// cout << cnt << " " << total << "\n";
	// ans = (long double)cnt / total;
	cout << ans << "\n";

}
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	fastio;
	int T = 1;
	// cin >> T;
	while (T--) {
		solve();
	}
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

ll rui[20];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    rui[0]=1;
    for(int i=1;i<10;i++) rui[i]=rui[i-1]*10;
    
    ll K;cin>>K;
    string S,T;cin>>S>>T;
    vector<ll> rem(10,K);
    
    double ans=0;
    
    for(int i=0;i<4;i++){
        rem[int(S[i]-'0')]--;
        rem[int(T[i]-'0')]--;
    }
    
    for(int a=1;a<=9;a++){
        for(int b=1;b<=9;b++){
            if(a==b){
                if(rem[a]<=1) continue;
                ll cnt=rem[a]*(rem[a]-1);
                
                ll X=0,Y=0;
                for(int i=1;i<=9;i++){
                    int ca=0;
                    for(int j=0;j<4;j++){
                        if(int(S[j]-'0')==i) ca++;
                    }
                    if(i==a) ca++;
                    X+=rui[ca]*i;
                    
                    ca=0;
                    
                    for(int j=0;j<4;j++){
                        if(int(T[j]-'0')==i) ca++;
                    }
                    if(i==b) ca++;
                    Y+=rui[ca]*i;
                }
                
                if(X>Y) ans+=cnt;
            }else{
                if(rem[a]<=0||rem[b]<=0) continue;
                ll cnt=rem[a]*(rem[b]);
                
                ll X=0,Y=0;
                for(int i=1;i<=9;i++){
                    int ca=0;
                    for(int j=0;j<4;j++){
                        if(int(S[j]-'0')==i) ca++;
                    }
                    if(i==a) ca++;
                    X+=rui[ca]*i;
                    
                    ca=0;
                    
                    for(int j=0;j<4;j++){
                        if(int(T[j]-'0')==i) ca++;
                    }
                    if(i==b) ca++;
                    Y+=rui[ca]*i;
                }
                
                if(X>Y) ans+=cnt;
            }
        }
    }
    
    ll pat=(9*K-8)*(9*K-9);
    
    ans/=pat;
    
    cout<<fixed<<setprecision(25)<<ans<<endl;
}
