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

bool flg[100][100];
int main() {
	int n; cin >> n;
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			char c; cin >> c;
			flg[i][j] = (c == '1');
		}
		flg[i][i] = true;
	}
	for(int k = 0; k < n; ++k) {
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < n; ++j) {
				flg[i][j] |= (flg[i][k] & flg[k][j]);
			}
		}
	}
	double ans = 0;
	for(int i = 0; i < n; ++i) {
		int cnt = 0;
		for(int j = 0; j < n; ++j) {
			cnt += flg[j][i];
		}
		ans += 1.0 / (double)cnt;
	}
	printf("%.15f\n", ans);
	return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define e1 first
#define e2 second
#define size(x) (int)x.size()
#define all(r) begin(r),end(r)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define time chrono::high_resolution_clock().now().time_since_epoch().count()
#define satori int testCases; cin>>testCases; while(testCases--)

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

///////////////////
#define DEBUG if(1)
///////////////////

ll pot(ll x,ll wyk,ll mod){
	ll res=1;
	while(wyk){
		if(wyk&1)
			res=(res*x)%mod;
		x=(x*x)%mod;
		wyk/=2ll;
	}
	return res;
}

int32_t main(){
	fastio;
	ll a,b;
	cin>>a>>b;
	if(b==1){
		cout<<"0\n";
		return 0;
	}
	ll residue=pot(10ll,a,b*b);
	ll res=(residue/b)%b;
	cout<<res<<'\n';
	return 0;
}
