#include<bits/stdc++.h>
using namespace std;
const int N=18,M=10;
int n,m=8;
int s[M][M];
double f[M][M][M][M][N];
const double inf = 1e9;
double x;
double get(int a,int b,int c,int d){
double sum=s[c][d]-s[c][b-1]-s[a-1][d]+s[a-1][b-1]-x;
return sum*sum/n;
}
double dfs(int x,int y,int dx,int dy,int k){
double &v=f[x][y][dx][dy][k];
if(v>=0) return v;
if(k==1) return v=get(x,y,dx,dy);
v=inf;
for(int i=x;i<dx;i++){
v=min(v,dfs(x,y,i,dy,k-1)+get(i+1,y,dx,dy));
v=min(v,dfs(i+1,y,dx,dy,k-1)+get(x,y,i,dy));
}
for(int i=y;i<dy;i++){
v=min(v,dfs(x,y,dx,i,k-1)+get(x,i+1,dx,dy));
v=min(v,dfs(x,i+1,dx,dy,k-1)+get(x,y,dx,i));
}
return v;
}
int main(){
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];
}
memset(f,-1,sizeof f);
x=(double) s[m][m]/n;
printf("%.3lf",sqrt(dfs(1,1,8,8,n)));
}