#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll scnt[10], tcnt[10];

bool win(){
    ll a = 0;
    rep(i, 1, 9){
        a += i * pow(10, scnt[i]);
    }

    ll b = 0;
    rep(i, 1, 9){
        b += i * pow(10, tcnt[i]);
    }
    //cout << a << " " << b << endl;
    return a > b;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll k; cin >> k;
    string s, t; cin >> s >> t;
    
    vector<ll> cnt(10, k);
    zep(i, 0, 4){
        scnt[s[i] - '0']++;
        cnt[s[i] - '0']--;
    }

    zep(i, 0, 4){
        tcnt[t[i] - '0']++;
        cnt[t[i] - '0']--;
    }
    //printa(scnt, 1, 9)
    ll ans = 0;
    rep(i, 1, 9){
        if(cnt[i] > 0){
            ll x = cnt[i];
            cnt[i]--;
            scnt[i]++;
            rep(j, 1, 9){
                if(cnt[j] > 0){
                    ll tmp = x * cnt[j];
                    cnt[j]--;
                    tcnt[j]++;
                    //cout << i << " " << j << endl;
                    if(win())ans += tmp;
                    tcnt[j]--;
                    cnt[j]++;
                }
            }
            scnt[i]--;
            cnt[i]++;
        }
    }
    cout << fixed << setprecision(20) << double(ans) / ((9 * k - 8) * (9 * k - 9)) << endl;

    return 0;
}
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
    ll H,W,N,M;
    cin>>H>>W>>N>>M;
    v A(N),B(N);
    v C(M),D(M);
    vv ans_grid(H,v(W,0));
    rep(i,0,N){
        cin>>A[i]>>B[i];A[i]--;B[i]--;
        ans_grid[A[i]][B[i]] = 2;
    }
    rep(i,0,M){
        cin>>C[i]>>D[i];C[i]--;D[i]--;
        ans_grid[C[i]][D[i]] = -1;
    }

    rep(i,0,H){
        bool br = false;
        rep(j,0,W){
            if(ans_grid[i][j] == 2)br = true;
            else if(ans_grid[i][j] == -1)br = false;
            else if(br) ans_grid[i][j] = 1;
        }
    }
    rep(i,0,H){
        bool br = false;
        for(ll j = W-1;j >= 0; j--){
            if(ans_grid[i][j] == 2)br = true;
            else if(ans_grid[i][j] == -1)br = false;
            else if(br)ans_grid[i][j] = 1;
        }
    }
    rep(j,0,W){
        bool br = false;
        rep(i,0,H){
            if(ans_grid[i][j] == 2)br = true;
            else if(ans_grid[i][j] == -1)br = false;
            else if(br)ans_grid[i][j] = 1;
        }
    }
    rep(j,0,W){
        bool br = false;
        for(ll i = H-1;i >= 0; i--){
            if(ans_grid[i][j] == 2)br = true;
            else if(ans_grid[i][j] == -1)br = false;
            else if(br)ans_grid[i][j] = 1;
        }
    }
    ll ans = 0;
    rep(i,0,H)rep(j,0,W){
        if(ans_grid[i][j] >= 1)ans++;
        //cout<<ans_grid[i][j];
    }
    cout<<ans;
    return 0;
}