#pragma region Template  // clang-format off
#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, m, n) for (int i = m; i < (int)(n); i++)
#define repe(i, m, n) for (int i = m; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define yesno {cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using pii = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#pragma endregion Template  // clang-format on

int main() {
  int k;
  cin >> k;

  string T, A;
  cin >> T >> A;

  vector<ll> c(10, k), t(10), a(10);
  rep(i, 0, 4) {
    t[T[i] - '0']++;
    a[A[i] - '0']++;
    c[T[i] - '0']--;
    c[A[i] - '0']--;
  }

  ll twin = 0, awin = 0;
  repe(i, 1, 9) repe(j, 1, 9) {
    auto tt = t, aa = a;
    tt[i]++;
    aa[j]++;
    ll tsum = 0, asum = 0, n = 0;
    if (i == j) {
      n = c[i] * (c[i] - 1);
    } else {
      n = c[i] * c[j];
    }
    repe(k, 1, 9) {
      tsum += k * (ll)pow(10, tt[k]);
      asum += k * (ll)pow(10, aa[k]);
    }
    if (tsum > asum)
      twin += n;
    else
      awin += n;
  }

  double ans = (double)twin / (twin + awin);
  printf("%.10f\n", ans);
}

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> bad(n+1);
    vector<int> aa;
    for (int i = 0; i < k; ++i) {
        int x;
        cin >> x;
        bad[x]++;
        aa.emplace_back(x);
    }
    for (int i = 0; i+m <= k; ++i) {
        if(aa[i+m-1]-aa[i] == m-1) return puts("-1"), 0;
    }
    vector<array<double, 2>> ans(n), S(n+1);
    for (int i = n-1; i >= 0; --i) {
        if(bad[i]){
            ans[i][1] = 1;
        }else {
            for (int j = 0; j < 2; ++j) {
                ans[i][j] = (S[i+1][j]-S[min(n, i+1+m)][j])/m;
            }
            ans[i][0]++;
        }
        for (int j = 0; j < 2; ++j) {
            S[i][j] = S[i+1][j]+ans[i][j];
        }
    }
    printf("%.10lf\n", ans[0][0]/(1-ans[0][1]));
    return 0;
}