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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using LD = long double;

template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; }
void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; }
void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; }

void Main(){
    const ll INF = 1e18;
    ll n; cin >> n;
    vll pow3(40, 3), pow5(30, 5);
    
    rep(i, 40) {
        if(pow3[i] > INF/3) break;
        pow3[i+1] = 3 * pow3[i];
    }
    rep(i, 30) {
        if(pow5[i] > INF/5) break;
        pow5[i+1] = 5 * pow5[i];
    }
    
    rep(i, 40) rep(j, 30){
        if(n == pow3[i] + pow5[j]){
            cout << i+1 << " " << j+1 << endl;
            return;
        }
    }
    cout << -1 << endl;
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}
/*************************************************************************
	> File Name: main.cpp
	> Author: Song
	> Mail: 2675791037@qq.com
	> Created Time: 四 11/19 08:58:42 2020
 ************************************************************************/

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>

using namespace std;

void solve() {
    string str;
    int n;
    cin >> n;
    vector<vector<bool> > a(n, vector<bool>(n, false));
    for (int i = 0; i < n; i++) {
        a[i][i] = true;
        cin >> str;
        for (int j = 0; j < str.length(); j++) {
            if (str[j] == '1') {
                a[i][j] = true; 
            }
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                if (a[j][i] && a[i][k]) a[j][k] = true;
            }
        }
    }
    double ans = 0.0;
    int cnt;
    for (int i = 0; i < n; i++) {
        cnt = 0;
        for (int j = 0; j < n; j++) {
            if (a[j][i]) cnt++;
        }
        ans += 1.0 / cnt;
    }
    cout << ans << endl;
    return ;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout << unitbuf;
    cout << fixed << setprecision(10);

    solve();
    return 0;
}
