#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<algorithm>#include<cmath>usingnamespace std;constint N =9, M =15;constint INF =1e9;int n, m =8;int s[N][N];//二维前缀和double f[N][N][N][N][M];double X;//平均值//留下部分的值doubleget(int x1,int y1,int x2,int y2){double sum = s[x2][y2]- s[x1 -1][y2]- s[x2][y1 -1]+ s[x1 -1][y1 -1]- X;return(double) sum * sum / n;}//记忆化搜索doubledp(int x1,int y1,int x2,int y2,int k){double&v = f[x1][y1][x2][y2][k];if(v >=0)return v;//说明已经计算过if(k ==1)return v =get(x1, y1, x2, y2);//不再分割的值
v = INF;for(int i = x1; i < x2; i++){//横向切割
v =min(v,dp(x1, y1, i, y2, k -1)+get(i +1, y1, x2, y2));//取上继续切计算下边
v =min(v,dp(i +1, y1, x2, y2, k -1)+get(x1, y1, i, y2));//取下继续切计算上边}for(int i = y1; i < y2; i++){//纵向切割
v =min(v,dp(x1, y1, x2, i, k -1)+get(x1, i +1, x2, y2));//取左继续切计算右边
v =min(v,dp(x1, i +1, x2, y2, k -1)+get(x1, y1, x2, i));//取右继续切计算左边}return v;}intmain(){
cin >> n;for(int i =1; i <= m; i++){for(int j =1; j <= m; j++){
cin >> s[i][j];
s[i][j]+= s[i -1][j]+ s[i][j -1]- s[i -1][j -1];}}
X =(double) s[m][m]/ n;memset(f,-1,sizeof f);printf("%.3lf\n",sqrt(dp(1,1, m, m, n)));return0;}