using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 105
int n;
char s[N];
int e[N][N];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i){
		scanf("%s",s+1);
		for (int j=1;j<=n;++j)
			e[i][j]=s[j]-'0';
	}
	for (int i=1;i<=n;++i)
		e[i][i]=1;
	for (int k=1;k<=n;++k)
		for (int i=1;i<=n;++i)
			for (int j=1;j<=n;++j)
				e[i][j]|=(e[i][k]&&e[k][j]);
	double ans=0;
	for (int i=1;i<=n;++i){
		int cnt=0;
		for (int j=1;j<=n;++j)
			if (e[j][i])
				cnt++;
		ans+=1.0/cnt;
	}
	printf("%.10lf\n",ans);
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define finf -0x3f3f3f3f
#define scNO printf("NO\n");
#define scNo printf("No\n");
#define scno printf("no\n");
#define sc0 printf("0\n");
#define sc1 printf("1\n");
#define	scf1 printf("-1\n");
#define	scz1 printf("1\n");
#define scYES printf("YES\n");
#define scyes printf("yes\n");
#define scYes printf("Yes\n");
#define scyes printf("yes\n");
#define ll long long
#define bug(a)  printf("%d \n ",a);
#define bugg(a,b)  printf("%d * %d \n",a,b);
#define buggg(a,b,c)  printf("%d * %d * %d \n",a,b,c);
#define bugggg(a,b,c,d)  printf("%d * %d * %d* %d\n",a,b,c,d);

const long N = 200000;
long prime[N] = {0},num_prime = 0;
int isNotPrime[N] = {1, 1};
int   read()  //read quickly
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*f;
}
void sushushai()
{
     	for(long i = 2 ; i < N ; i ++)
       	{
		if(! isNotPrime[i])
	 		prime[num_prime ++]=i;
		for(long j = 0 ; j < num_prime && i * prime[j] <  N ; j ++)
    		{
		      	isNotPrime[i * prime[j]] = 1;
	  		if( !(i % prime[j] ) )
				break;
		}
	}
}

void cheng(int *a,int c)		//High precision multiplication
{
	int jw=0;
	for(int i=1;i<=1000;i++)
	{
		a[i]=a[i]*c+jw;
		jw=a[i]/10;
		a[i]%=10;
	}
}
int cl(int x,int n) //High precision Division
{
	int s=0,i=0,w[101];
	while(x>=1)
	{
		w[++i]=x%n;
		x=x/n;
	}
	for(int j=i;j>=1;j--)
	   s=s*10+w[j];
	return s;
}
void pplus(int *a,int *c) //High precision addition
{
	int jw=0;
	for(int i=1;i<=1000;i++)
	{
		c[i]+=a[i]+jw;
		jw=c[i]/10;
		c[i]%=10;
	}
}
long long A(int n,int m) //(n)*(n-1)*(n-2)*....(n-m)
{
    long long ret=1;
    for(int i=0;i<m;++i)
    {
        ret*=(n-i);
       // ret%=mod;
    }
    return ret;
}

int c( int m,int n ) //c(5,1)==c(5,4)
{
	int a = 1,b = 1;
	n = min(n,m-n);
	if( n == 0 )
		return 1;
	for( int i = m ; i >=m-n+1 ; i--  )
		a = a*i;
	for( int i = 1 ; i <= n ; i++ )
		b = b*i;
	return a/b;
}

long long quickpow(long long a,long long b){



        long long ret=1;
        while(b){
            if(b&1){
                ret=ret*a;
                //%modd;
            }
            a=a*a;
            //%modd;
            b>>=1;
        }
        return ret;
}
const int MAXN=200005;
const long long mod=1e9+7;


int main()
{
    string s1;
    cin>>s1;
    int d1=s1.length();
    string s2;
    int flag=0;
    for(int i=0;i<=d1+1;i++){
        string s3=s2;
        s3+=s1;
        string s4=s3;
        reverse(s4.begin(),s4.end());
        if(s4==s3){
            scYes;
            flag=1;
            break;
        }
        s2+='0';
    }
    if(flag==0){
        scNo;
    }
}
