#include<bits/stdc++.h>
namespace imzzy{
	#define endl '\n'
	#define rgi register int
	#define rgl register long long
	typedef long long ll;
	class fastin{private:int _ch,_f;
	public:inline fastin&operator>>(char&c){c=getchar();return*this;}
	template<typename _Tp>inline fastin&operator>>(_Tp&_x){
	_x=0;while(!isdigit(_ch))_f|=(_ch==45),_ch=getchar();
	while(isdigit(_ch))_x=(_x<<1)+(_x<<3)+(_ch^48),_ch=getchar();
	_f&&(_x=-_x,_f=0);return*this;}fastin(){_ch=_f=0;}
	}fin;class fastout{private:int _num[32],_head;
	public:inline fastout&operator<<(char c){putchar(c);return*this;}
	template<typename _Tp> inline fastout&operator<<(_Tp _x){
	_Tp _k;if(_x==0){putchar('0');return *this;}if(_x<0)putchar('-'),_x=-_x;
	while(_x>0)_k=_x/10,++_head,_num[_head]=(_x-(_k<<1)-(_k<<3))^48,_x=_k;
	while(_head>0)putchar(_num[_head]),--_head;return*this;}fastout(){_head=0;}
	}fout;inline void P_INIT(){
	#ifdef D_STDOUT_UNBUFFERED
	setbuf(stdin,NULL),setbuf(stdout,NULL);
	#endif
}}using namespace imzzy;
// ----------------------------
// #define int ll
// using namespace std;
const double pi=acos(-1.0);
const int mod=1000000000,inf=1201201201;
const int maxn=104,maxm=800004;

int cnt[maxn];
bool go[maxn][maxn];
char s[maxn];
signed main()
{P_INIT();
	int n;
	fin>>n;
	for(rgi i=1;i<=n;++i) {
		scanf("%s",s+1);
		for(rgi j=1;j<=n;++j) go[i][j]=(s[j]-'0')|(i==j);
	}
	for(rgi k=1;k<=n;++k) for(rgi i=1;i<=n;++i) for(rgi j=1;j<=n;++j) go[i][j]|=go[i][k]&go[k][j];
	for(rgi i=1;i<=n;++i) for(rgi j=1;j<=n;++j) cnt[j]+=go[i][j];
	double ans=0;
	for(rgi i=1;i<=n;++i) ans+=1.0/cnt[i];
	printf("%.12lf",ans);
	return 0;
}
// ----------------------------
// by imzzy
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const ll mod = 1e18 + 7;
const int maxn = 1e5+5;

void go() { 
    int n;string s;
    cin >> n >> s;
    //map<int,int>mp1,mp2;
    map<pair<int,int>,int>mp3;
    mp3[{0,0}] = 1;
   // mp1[0] = 1;
   // mp2[0] = 1;
    int ans = 0;
    int c0 = 0, c1 = 0;
    for (auto &i : s) {
        if (i == 'A') {
            c0++;
        }
        else if (i == 'T') {
            c0--;
        }
        else if (i == 'C') {
            c1++;
        }
        else {
            c1--;
        }
        //ans += mp1[c0];
        //ans += mp2[c1];
        ans += mp3[{c0,c1}];
        //mp1[c0]++;
        //mp2[c1]++;
        mp3[{c0,c1}]++;
    }
    cout << ans << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }
    
}