#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> Pair;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}

void Main(){
    int K; cin >> K;
    string S,T; cin >> S >> T;
    VI num(10,K), na(10,0), nb(10,0);
    REP(i,4){
        int x = S[i]-'0';
        num[x]--; na[x]++;
        x = T[i]-'0';
        num[x]--; nb[x]++;
    }

    double ans = 0;
    FOR(i,1,10)FOR(j,1,10){
        na[i]++; nb[j]++;
        bool flag = false;
        FOR(k,1,10){
            if(na[k]+nb[k]>K){
                flag = true;
                break;
            }
        }
        if(flag){
            na[i]--; nb[j]--;
            continue;
        }

        int sa = 0, sb = 0;
        FOR(k,1,10){
            int t = 1;
            REP(_,na[k]) t *= 10;
            sa += k*t;

            t = 1;
            REP(_,nb[k]) t *= 10;
            sb += k*t;
        }

        na[i]--; nb[j]--;
        if(sa<=sb) continue;

        if(i==j){
            ans += 1.0 * num[i] / (9*K-8) / (9*K-9) * (num[i]-1);
        }
        else{
            ans += 1.0 * num[i] / (9*K-8) / (9*K-9) * num[j];
        }
    }
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}
#include <bits/stdc++.h>
using namespace std;

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}


struct Precision{
  Precision(){
    cout<<fixed<<setprecision(12);
  }
}precision_beet;


// [0, n]
template<typename T>
vector<T> powers(Int n,T x){
  vector<T> po(n+1,T(1));
  for(Int i=0;i<n;i++) po[i+1]=po[i]*x;
  return po;
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int k;
  cin>>k;

  auto way=[&](string s,string t)->Int{
    string a=s+t;
    for(char c='1';c<='9';c++){
      Int cnt=count(a.begin(),a.end(),c);
      if(cnt>k) return 0;
    }
    Int x=k-count(a.begin(),a.end(),s.back())+1;
    Int y=k-count(a.begin(),a.end(),t.back())+1;
    if(s.back()==t.back()) return x*(x+1);
    return x*y;
  };

  auto po=powers(10,10LL);
  auto score=[&](string s){
    Int res=0;
    for(char c='1';c<='9';c++){
      Int cnt=count(s.begin(),s.end(),c);
      res+=(c-'0')*po[cnt];
    }
    return res;
  };

  string s,t;
  cin>>s>>t;


  Int num=0,den=0;
  for(char x='1';x<='9';x++){
    for(char y='1';y<='9';y++){
      s.back()=x;
      t.back()=y;

      // if(x=='2' and y=='1') cout<<score(s)<<' '<<score(t)<<':'<<way(s,t)<<endl;
      if(score(s)>score(t)) num+=way(s,t);
      den+=way(s,t);
    }
  }
  // cout<<num<<' '<<den<<endl;
  using D = double;
  cout<<D(num)/D(den)<<endl;
  return 0;
}
