#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using P=pair<int,int>;
using T=tuple<int,int,int>;
constexpr int mod=1000000007;
constexpr int inf=1e9;
int in(){
    int x;
    scanf("%d",&x);
    return x;
}
struct graph{
    vector<vector<int>>e;
    vector<int>used;
    int cnt=0;
    graph(int n){
        e.resize(n);
        used.resize(n);
    }
    void add_edge(int v,int u){
        e[v].emplace_back(u);
    }
    void dfs(int v){
        cnt++;
        for(int u:e[v])if(used[u]==0)used[u]=1,dfs(u);
    }
    int solve(int s){
        fill(used.begin(),used.end(),0);
        used[s]=1;
        cnt=0;
        dfs(s);
        return cnt;
    }
};
int main(){
    int n=in();
    graph g(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            char c;
            cin>>c;
            if(c=='1')g.add_edge(j,i);
        }
    }
    double ans=0.0;
    for(int i=0;i<n;i++)ans+=1.0/double(g.solve(i));
    printf("%.10lf",ans);
    return 0;
}
#include <bits/stdc++.h>
using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define RREP_(i, a_, b_, a, b, ...) for (Int i = Int(b) - 1, low##i = (a); i >= low##i; i--)
#define RREP(i, ...) RREP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on
struct in {
    template <class T> operator T() {
        T t;
        std::cin >> t;
        return t;
    }
};
void out() { std::cout << "\n"; }
template <class Head, class... Tail> void out(Head&& h, Tail&&... t) {
    std::cout << h << (sizeof...(Tail) == 0 ? "" : " "), out(std::forward<Tail>(t)...);
}
template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; }
template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; }
template <class T> using V = std::vector<T>;

/**
 *    author:  knshnb
 *    created: Sun Feb 28 00:29:14 JST 2021
 **/

V<V<Int>> solve(Int n) {
    V<V<Int>> ret(1);
    REP(i, 1 << n) ret[0].push_back(i < (1 << (n - 1)));
    if (n == 1) return ret;
    auto sub = solve(n - 1);
    REP(t, 2) {
        for (auto& v : sub) {
            ret.push_back({});
            for (Int x : v) ret.back().push_back(x);
            for (Int x : v) ret.back().push_back(t ? !x : x);
        }
    }
    return ret;
}
signed main() {
    Int n = in();
    auto res = solve(n);
    out(res.size());
    for (auto& v : res) {
        for (Int x : v) std::cout << char('A' + x);
        out();
    }
}
