
#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define TRAV(i, a) for(auto &i : (a))
#define SZ(x) ((int)(x).size())
#define X first
#define Y second
#define MP std::make_pair
#define PR std::pair
typedef long long ll;
typedef std::pair<int, int> PII;
typedef std::vector<int> VI;

int przed[200];
bool vis[200];
std::vector<VI> g;
void dfs(int v){
        vis[v] = true;
        przed[v]++;
        TRAV(j, g[v]) if(!vis[j]){
                dfs(j);
        }
}

int main(){
        std::ios_base::sync_with_stdio(false);
        std::cin.tie(0);

        int n;
        std::cin >> n;
        g.resize(n);
        FOR(i, n){
                FOR(j, n){
                        char a;
                        std::cin >> a;
                        if(a == '1') g[i].push_back(j);
                }
        }

        FOR(i, n){
                FOR(j, 200) vis[j] = false;
                dfs(i);
        }

        long double ans = 0;
        FOR(i, n) ans += (long double)1 / przed[i];
        std::cout << std::fixed << std::setprecision(12) << ans << "\n";

        return 0;
}

/*Allah Vorosha*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define in insert
#define rev reverse
#define all(x) (x).begin(),(x).end()
#define all2(x) (x).rbegin(),(x).rend()
#define sz(v) (int)v.size()
#define yes cout << "YES\n"
#define no cout << "NO\n";
#define take for(auto &it : a) cin >> it;
#define vi vector<int>
#define vii vector<pair<int, int > >
#define vl vector<ll>
#define fi first
#define se second
#define l_b lower_bound
#define u_b upper_bound
#define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define tail cout << '\n'
#define mems(a, b) memset(a, b, sizeof(a))

using namespace std;

template<class T> void read(T &x) { cin >> x; }
template<class T, class ...U> void read(T &x, U& ... u) { read(x); read(u...); }
template<class T> void print1(const T &x) { cout << x << '\n'; }
template<class T, class ...U> void print1(const T &x, const U& ... u) { print1(x); print1(u...); }
template<class T> void print2(const T &x) { cout << x << ' '; }
template<class T, class ...U> void print2(const T &x, const U& ... u) { print2(x); print2(u...); }

const int N = 2e5 + 5, M = 5e5 + 5, mod = 1e9 + 7;
const ll inf = 9e18;
int cs = 1;

vector<int> g[N];
int cnt;
bool vis[N];

void dfs(int src) {
    vis[src] = 1;
    cnt++;
    for(auto adj : g[src]) {
        if(vis[adj]) continue;
        dfs(adj);
    }
}

void solve() {
    int n;
    read(n);
    vi a(n), b(N);
    take;
    int i = 0, j = n - 1;
    while(i <= j) {
        if(a[i] != a[j]) {
            g[a[i]].pb(a[j]);
            g[a[j]].pb(a[i]);
        }
        i++;
        j--;
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        if(!vis[a[i]]) {
            cnt = 0;
            dfs(a[i]);
            ans += cnt - 1;
        }
    }
    print1(ans);
}

int main() {
    ios;
    //int tc; cin >> tc; while(tc--)
    solve();
    return 0;
}
