#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#pragma GCC optimize ("Ofast")
#pragma GCC optimization ("unroll-loops, no-stack-protector")
#pragma GCC target ("avx")
#pragma GCC target ("avx2")
#pragma GCC target ("fma")
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll cnt[10];
string s, t;
ll occ[10][2];
ll p10[10];
bool check(){
	ll sum1 = 0, sum2 = 0;
	for (ll i = 1; i <= 9; i++) sum1 += p10[occ[i][0]] * i;
	for (ll i = 1; i <= 9; i++) sum2 += p10[occ[i][1]] * i;
	return (sum1 > sum2);
}
int main(){
	cout << fixed << setprecision(12);
	fastio;
	p10[0] = 1;
	for (ll i = 1; i < 10; i++) p10[i] = p10[i - 1] * 10;
	ll k; cin >> k;
	for (ll i = 1; i <= 9; i++) cnt[i] = k;
	cin >> s >> t;
	for (ll i = 0; i < 4; i++){
		cnt[s[i] - '0']--;
		cnt[t[i] - '0']--;
		occ[s[i] - '0'][0]++;
		occ[t[i] - '0'][1]++;
	}
	ll sum_choice = 0, sum_good = 0;
	for (ll u = 1; u <= 9; u++){
		for (ll d = 1; d <= 9; d++){
			ll choice;
			if (u == d) choice = cnt[u] * (cnt[u] - 1);
			else choice = cnt[u] * cnt[d];
			sum_choice += choice;
			occ[u][0]++; occ[d][1]++;
			if (check()) sum_good += choice;
			occ[u][0]--; occ[d][1]--;
		}
	}
	ld tmp = sum_good; tmp /= sum_choice;
	cout << tmp << "\n";
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rrep(i, a, b) for (ll i = b - 1; a <= i; i--)
ll MOD = 1000000007;

ll K, cnt_a[10], cnt_t[10], ao, taka, win, total;
string T, A;

int main () {
  cin >> K >> T >> A;

  rep (i, 0, 4) {
    cnt_t[T[i] - '0']++;
    cnt_a[A[i] - '0']++;
  }

  rep (ura_a, 1, 10) rep (ura_t, 1, 10) {
    cnt_a[ura_a]++;
    cnt_t[ura_t]++;

    if (cnt_a[ura_a] + cnt_t[ura_a] <= K && cnt_a[ura_t] + cnt_t[ura_t] <= K) {
      ll d;
      if (ura_a == ura_t) {
        d = (K - cnt_a[ura_a] - cnt_t[ura_t] + 2) * (K - cnt_a[ura_a] - cnt_t[ura_t] + 1);
      } else {
        d = (K - cnt_a[ura_a] - cnt_t[ura_a] + 1) * (K - cnt_a[ura_t] - cnt_t[ura_t] + 1);
      }
      ao = 0, taka = 0;

      rep (i, 1, 10) {
        ll x = i;
        rep (j, 0, cnt_a[i]) x *= 10;
        ao += x;

        x = i;
        rep (j, 0, cnt_t[i]) x *= 10;
        taka += x;
      }

      total += d;
      if (taka > ao) win += d;
    }

    cnt_a[ura_a]--;
    cnt_t[ura_t]--;
  }

  double ans = (double)win / total;
  cout << fixed << setprecision(7) << ans;
}
