#include <bits/stdc++.h>
#include <random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
lint gcd(lint a, lint b) { if (b == 0) return a; else return gcd(b, a % b); }
lint ceil(lint a, lint b) { return (a + b - 1) / b; }
lint digit(lint a) { return (lint)log10(a); }
const lint MOD = 1e9 + 7, INF = 1e9;
lint dx[8] = { 1, 0, -1, 0, 1, -1, 1, -1 }, dy[8] = { 0, 1, 0, -1, -1, -1, 1, 1 };
void YN(bool flag) { cout << (flag ? "Yes" : "No") << endk; }
typedef pair<lint, string> Pa;
typedef pair<lint, plint> tlint;

lint N;
lint dist[100][100];
int main() {
	cin >> N;
	REP(i, N) {
		REP(j, N) {
			dist[i][j] = INF;
			char c;
			cin >> c;
			if (c == '1') dist[i][j] = 1;
		}
	}
	REP(k, N) {
		REP(i, N) {
			REP(j, N) {
				chmin(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	long double ans = 0;
	REP(i, N) {
		long double sum = 1;
		REP(j, N) {
			if (i == j) continue;
			if (dist[j][i] != INF) sum++;
		}
		ans += (long double)1 / sum;
	}
	cout << setprecision(16) << ans << endk;
}
//wtrl,everybody hangbeat me
#include<bits/stdc++.h>
/*#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>*/
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<ll,ll> pll;
/*=====================================================================*/
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(s) (s).begin(),(s).end()
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,p,n) for(int i=p;i<=n;i++)
#define ford(i,p,n) for(int i=n;i>=p;i--)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i)
#define INF 1e9
#define PI acos(-1)
/*=====================================================================*/
string int_to_string(ll n)
{
	string s="";
	while(n)
	{
		ll now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
ll string_to_int(string s)
{
	ll n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
/*======================================================================*/
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
const int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
void solve()
{
	int n;
	cin>>n;
	int now=0;
	for(int i=1;now<=1e9;i++)
	{
		now+=i;
		if(now>=n)
		{
			cout<<i<<endl;
			return;
		}
	} 
}
/*======================================================================*/
signed main()
{
    std::ios::sync_with_stdio(false);
  /*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
  */
  /*====================================================================*/
  int t=1;
  //cin>>t;
  while(t--)
  {
  	solve();
  }
  return 0;
}
/*
注意数组越界，vector长度为0的时候循环会RE
注意输入顺序
注意循环时int*int爆ll
注意答案存爆ll
*/

