#include<bits/stdc++.h> 
using namespace std; 
typedef long  long ll;
ll MOD=1e9+7;
const ll MAX=1e5+2;
 
void solve(){
    ll n;cin>>n;
    ll a[n],b[n],c[n];
    for(auto &x:a)cin>>x;
    for(auto &x:b)cin>>x;
    for(auto &x:c)cin>>x;
    unordered_map<ll,ll>mc;
    for(auto &x:c)mc[x]++;
    unordered_map<ll,ll>mb;
    for(int i=0;i<n;i++){
        mb[b[i]]+=mc[i+1];
    }
    ll ans=0;
    for(auto &x:a){
        ans+=mb[x];
    }
    cout<<ans;
}
 
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;t=1;
    // cin>>t;
    // cin.ignore();
    while(t--){
        solve();
    }
    return 0;
}
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;


vector<vector<int>> R;
vector<int> used;
    
int rec(int cur){
    int res = 1;
    used[cur] = true;
    
    for(int nex : R[cur]){
        if(used[nex]) continue;
        res += rec(nex);
    }
    
    return res;
}

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N;
	long double ans = 0;
    
    cin>>N;
    
    R.resize(N);
	
    for(int i = 0; i < N; i++){
        string s;
        
        cin>>s;
        
        for(int j = 0; j < s.size(); j++){
            if(s[j] == '1') {
                R[j].push_back(i);
            }
        }
    }
    
    for(int i = 0; i < N; i++){
        used.clear();
        used.resize(N);
        ans += 1.0 / rec(i);
    }
    
    cout<<ans<<endl;
    
	return 0;
}