#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using ll = int64_t;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>
#define vv(T) vector<vector<T>>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T> ostream& operator<<(ostream& o, const set<T>& v) {
  for (auto e : v) {
    o << e << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1

using ld = long double;

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  v(string) ss(N);
  cin >> ss;
  v(bitset<100>) es(N);
  bitset<100> vs;
  auto dfs = [&](auto dfs, int r, int v)->void {
    vs[v] = true;
    es[v][r] = true;
    F0R(i, N) {
      if (!vs[i] && ss[v][i] == '1') {
        dfs(dfs, r, i);
      }
    }
  };
  F0R(i, N) {
    vs.reset();
    dfs(dfs, i, i);
  }

  ld r = 0;

  F0R(i, N) {
    int pc = 0;
    F0R(j, N) {
      if (es[i][j]) pc++;
    }
    //show(pc);
    r += (ld)N / pc;
  }


  cout << std::fixed << std::setprecision(15);
  cout << (r/N);
}
#endif

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxN = 4e2 + 10;
ll n, a[maxN], ans;
int read();
int main(){
	n = read();
	for(int i = 0; i < n; i++){
		ll x = read() + 200;
		a[x]++;
		for(int j = 0; j <= 400; j++) ans += (x - j) * (x - j) * a[j];
	}
	cout << ans;
	return 0;
}
int read(){
	int s = 0, f = 1; char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-') f = -1;
		ch = getchar();
	}
	while(isdigit(ch)) s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
	return s * f;
}
