#include <bits/stdc++.h>
using namespace std;
const int maxn = 100;
int n;
int a[maxn + 10][maxn + 10];
char s[maxn + 10];
double ans;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%s", s + 1);
		for (int j = 1; j <= n; ++j)
			a[i][j] = s[j] == '1';
		a[i][i] = 1;
	}
	for (int k = 1; k <= n; ++k)
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j)
				a[i][j] |= a[i][k] && a[k][j];
	for (int i = 1; i <= n; ++i) {
		int v = 0;
		for (int j = 1; j <= n; ++j)
			v += a[j][i];
		ans += 1. / v;
	}
	printf("%.10lf", ans);
}

#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=2e5;
priority_queue<int> pq;
int tab[N+10][2];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>tab[n-i+1][0];
	for(int i=1;i<=n;i++)
		cin>>tab[i][1];
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		if(tab[i][0]>tab[i][1])
			swap(tab[i][0],tab[i][1]);
		if(!pq.empty() && (-pq.top())<tab[i][0])
		{
			ans+=pq.top();
			pq.pop();
			ans+=tab[i][0];
			pq.push(-tab[i][0]);
		}
		ans+=tab[i][1];
		pq.push(-tab[i][1]);
	}
	cout<<ans<<"\n";
	return 0;
}

