#include <bits/stdc++.h>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << #x << " = " << x << endl
#define fi(i, l, r) for (int i = l; i < r; i++)
#define cd(a) scanf("%d", &a)
typedef long long ll;

ll getScore(ll s[])
{
    ll ans=0;
    for(ll i=1;i<10;i++)
    {
        ans+=i*pow(10,s[i]);
    }
    return ans;
}

// ll getScore1(ll s[])
// {
    
//     ll ans=0;
//     for(ll i=1;i<10;i++)
//     {
//         printf("s[%lld]=%lld ",i,s[i]);
//         ans+=i*pow(10,s[i]);
//         printf("i=%lld,1LL<<%lld=%lld\n",i,s[i],(1LL<<s[i]));
//     }
//     printf("\nreturn:%lld\n",ans);
//     return ans;
// }
// int main()
// {
//     ll sa[10]={2,3,0,0,0,0,0,0,0};
//     ll sb[10]={1,3,0,0,0,0,0,1,0};
//     printf("GSa=%lld\nGSb=%lld\n",getScore1(sa),getScore1(sb));
//     return 0;
// }

int main()
{
    ll k;
    cin >> k;
    char s[10], t[10];
    cin >> s >> t;
    ll shengyu[10] = {0};
    for (ll i = 1; i < 10; i++)
        shengyu[i] = k;
    ll suma[10] = {0};
    ll sumb[10] = {0};
    for (ll i = 0; i < 4; i++)
    {
        shengyu[s[i] - '0']--;
        shengyu[t[i] - '0']--;
        suma[s[i]-'0']++;
        sumb[t[i]-'0']++;
    }
    ll canWin=0;
    for (ll i = 1; i <= 9; i++)
    {
        for (ll j = 1; j <= 9; j++)
        {
            bool sfbx=false;
            if(shengyu[i]<=0)sfbx=true;
            if(shengyu[j]<=0)sfbx=true;
            suma[i]++;
            sumb[j]++;
            //shengyu[i]--;
            //shengyu[j]--;
            
            if(!sfbx)
            {
                ll sa=getScore(suma);
                ll sb=getScore(sumb);
                // if(i==2&&j==1)
                // {
                //     cout<<"i="<<i<<",j="<<j<<"!!!"<<endl;
                //     printf("suma:");
                //     for(int i=1;i<=9;i++)printf(" %d",suma[i]);
                //     printf("\nsumb:");
                //     for(int i=1;i<=9;i++)printf(" %d",sumb[i]);
                //     printf("\nsa=%lld,sb=%lld\n",sa,sb);
                //     puts("---------");
                // }
                if(sa>sb)
                {
                    if(i==j)
                    {
                        canWin += shengyu[i] * (shengyu[i]-  1);
                    }
                    else
                    {
                        canWin += shengyu[i] * shengyu[j];
                    }
                }
                // else
                // {
                //     printf("i=%lld,j=%lld,sa=%lld,sb=%lld,Cannot!!!\n",i,j,sa,sb);
                // }
            }

            suma[i]--;
            sumb[j]--;
            //shengyu[i]++;
            //shengyu[j]++;
        }
    }
    ll shengyuAll = k*9-8;
    ll canAll = shengyuAll*(shengyuAll-1);
    double ans = 1. * canWin / canAll;
    printf("%.15lf\n", ans);
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
typedef int64_t ll;
#define PA pair<ll,ll>
#define TU tuple<ll,ll,ll>
#define vi vector<ll>
#define vii vector<vector<ll> >
#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define rep2(i,m,n) for(ll (i)=(m); (i)<(ll)(n); (i)++)
const ll INF = 1ll<<30;
const ll INF2 = 1ll<<32;

int main() {
  ll k;
  cin >>k;
  string s,t;
  cin >>s >>t;
  //v_t.at(i)=数字i-1の存在個数
  vi v_t(9,0),v_a(9,0);
  rep(i,4) {
    v_t.at(s.at(i)-'1')++;
    v_a.at(t.at(i)-'1')++;
  }
  
  vi v_remain(9);
  rep(i,9) {
    v_remain.at(i) = k - (v_t.at(i)+v_a.at(i));
  }
  
  //ここでのanspはパターンの数。最終的には(9*k-8)P(2)で割る。
  ll ansp =0;
  ll pts_t, pts_a;
  vi v_tt(9), v_aa(9);
  
  rep(tak,9) {
    v_tt = v_t;
    v_tt.at(tak)++;
    rep(aok,9) {
      if(tak==aok && v_remain.at(tak)<2) continue;
      else if(v_remain.at(tak)==0 || v_remain.at(aok)==0) continue;
      v_aa = v_a;
      v_aa.at(aok)++;
      
      pts_t = 0;
      pts_a = 0;
      rep(i,9) {
        pts_t += (i+1) * pow(10,v_tt.at(i));
        pts_a += (i+1) * pow(10,v_aa.at(i));
      }
      if(pts_t>pts_a) {
        if(tak==aok) ansp += v_remain.at(tak)*(v_remain.at(tak)-1);
        else ansp += v_remain.at(tak)*v_remain.at(aok);
      }
    }
  }
  
  double ans = (double)ansp/((9*k-8)*(9*k-9));
  cout << fixed << setprecision(7);
  cout << ans << endl;
}