//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
   #include <atcoder/all>
   using namespace atcoder;
#endif
#define all(v) v.begin(), v.end()
using in = long long;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
#define REP(i,a,b) for(in i=(in)(a);i<(in)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
const in MOD = 1000000007;
const in INF=(in)1e18+7;
const in inf=max(in(1e18)+7,in(1e9)+7);
using P=pair<in,in>;
using T=tuple<in,in,in>;
vector<in> dx={0,1,-1,0};
vector<in> dy={1,0,0,-1};
template <typename Typ>
bool chmin(Typ &a, const Typ& b) {if (a > b) {a = b; return true;} return false;}
template <typename Typ>
bool chmax(Typ &a, const Typ& b) {if (a < b) {a = b; return true;} return false;}
template <typename Typ>
Typ ceil(Typ x, Typ y){return (x+y-1)/y;}
#ifdef  _DEBUG
    #define debug(x) cout<<"debug:"<<x<<endl
    #define vdebug(x) cout<<"debug:";\
                      for(auto asdf:x) cout<<asdf<<" ";\
                      cout<<endl
#else
    #define debug(x) 
    #define vdebug(x) 
#endif

int main(){
ios::sync_with_stdio(false);cin.tie(nullptr);
cout << fixed << setprecision(12);
    in k;  cin>>k;
    string s,t; cin>>s>>t;
    vector<in> zan(9,k);
    vector<in> cs(9,0),ct(9,0);
    rep(i,4){
        zan[s[i]-'1'] --;
        zan[t[i]-'1'] --;
        cs[s[i]-'1'] ++;
        ct[t[i]-'1'] ++;
    }
    in sum=0;
    
    rep(i,9)rep(j,9){
        if(zan[i]==0 or zan[j]==0) continue;
        in ns=0,nt=0;
        cs[i]++;
        ct[j]++;
        rep(l,9){
            in s10=1,t10=1;
            rep(m,cs[l]) s10 *=10;
            rep(m,ct[l]) t10 *=10;
            ns += s10*(l+1);
            nt += t10*(l+1);
        }
        cs[i]--;
        ct[j]--;
        if(ns>nt){
            if(i==j and zan[i]>=2) sum += zan[i]*(zan[i]-1); 
            if(i!=j) sum += zan[i]*zan[j];
            vector<in> dv(2);
            dv[0]=i+1;dv[1]=j+1;
            vdebug(dv);
        }
    }
    in s_z=0;
    rep(i,9) s_z += zan[i];
    s_z *= (s_z-1);
    double ans=sum;
    ans /=double(s_z);
    debug(sum);
    debug(s_z);
    cout<<ans<<"\n";
    
}/*
./problem.exe
*/
#include<bits/stdc++.h>

using namespace std;

#define ll long long

const int N = 2e5 + 10;

int n,a[N],b[N],lisan[N],num,c[N],tmp[N];

ll ans = 0;

queue <int> q[N]; 

void mysort(int l,int r)
{
	if(l == r) return ;
	int mid = (l + r) >> 1;
	mysort(l,mid); mysort(mid+1,r);
	int lnow = l , rnow = mid + 1 , top = l-1;
	while(lnow <= mid || rnow <= r){
		if((c[lnow] <= c[rnow] && lnow <= mid)|| rnow > r){
			tmp[++top] = c[lnow]; lnow ++;
		} 
		else{
			tmp[++top] = c[rnow]; rnow ++;
			ans += mid - lnow + 1;
		}
 	}
 	for(int i=l;i<=r;i++) c[i] = tmp[i];
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) scanf("%d",&b[i]);
	for(int i=1;i<=n;i++) a[i] += i , lisan[i] = a[i];
	sort(lisan + 1 , lisan + 1 + n);
	num = unique(lisan + 1 , lisan + 1 + n) - lisan - 1;
	for(int i=1;i<=n;i++){
		a[i] = lower_bound(lisan + 1 , lisan + 1 + num , a[i]) - lisan;
		q[a[i]].push(i); 
	}
	for(int i=1;i<=n;i++){
		b[i] += i;
		int x = lower_bound(lisan + 1 , lisan + 1 + num , b[i]) - lisan;
		if(b[i] != lisan[x]){
			cout<<"-1"; return 0;
		}
		if(q[x].empty()){
			cout<<"-1"; return 0;
		}
		int o = q[x].front();
		q[x].pop();
		c[i] = o;
	}
	mysort(1,n);
	cout<<ans;
	return 0;
}