#include <bits/stdc++.h>
#include <unordered_set>
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep1(i,n) for (int i=1;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int score(string str){
  vector<int> cnt(10, 0);
  rep(i,str.size()){
    cnt[(str[i] - '0')]++;
  }
  int sum = 0;
  rep1(i,cnt.size()){
    int mul = 1;
    rep(j,cnt[i]){
      mul *= 10;
    }
    sum += i * mul;
  }
  return sum;
}

int main() {
  int k;
  string s, t;
  cin >> k;
  cin >> s;
  cin >> t;
  vector<int> cards(10, k);
  int rem_cards = 9 * k - 8;

  rep(i,4){
    cards[s[i]-'0']--;
  }

  rep(i,4){
    cards[t[i]-'0']--;
  }

  double prob = 0;
  rep1(i,10){
    rep1(j,10){
      s[4] = i + '0';
      t[4] = j + '0';
      if(score(s) > score(t)){
        if(i != j){
          prob += ((double)cards[i] / rem_cards) * ((double)cards[j] / (rem_cards - 1));
        }else{
          prob += ((double)cards[i] / rem_cards) * ((double)(cards[j]-1) / (rem_cards - 1));
        }
      }
    }
  }
  
  printf("%f\n", prob);
  return 0;
}
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
using namespace std;
#define f(x,y,z) for(int x=y;x<=z;++x)
vector<int> v[200001];
array<int, 200001> jr, dkt, tdk, at, uj;
int n, k, a, b, l, r, m, hit;
void jrk(int x) {
    for(int &i:v[x]) if(i != at[x]) {
        at[i] = x, jr[i] = jr[x]+1, jrk(i);
    }
}
bool cek(int &x) {
    // cerr << x;
    fill(dkt.begin(), dkt.end(), 0x3f3f3f3f);
    fill(tdk.begin(), tdk.end(), 0);
    hit = 0;
    f(i,1,n) {
        int &z = uj[i];
        // cerr << ' ' << z;
        if(dkt[z]+tdk[z] <= x) {
            tdk[z] = -1;
        } else if(tdk[z] == x || (z == 1 && tdk[z] >= 0)) {
            ++hit, tdk[z] = -1, dkt[z] = 0;
        }
        tdk[at[z]] = max(tdk[at[z]], tdk[z]+1);
        dkt[at[z]] = min(dkt[at[z]], dkt[z]+1);
    }
    // cerr << '\n';
    return hit <= k;
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> n >> k;
    f(i,2,n) {
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    jrk(1);
    f(i,1,n) uj[i] = i;
    sort(uj.begin()+1, uj.begin()+n+1, [](int &i, int &j){
        return jr[i] > jr[j];
    });
    l = 1, r = n-1;
    while(l <= r) {
        m = (l+r)>>1;
        cek(m) ? r = m-1 : l = m+1;
    }
    cout << l << '\n';
}