#include<bits/stdc++.h>
#define RG register
#define il inline
#define N 510*510
#define S 0
#define T (N-1)
#define pos(i,j) ((i-1)*n+j)
using namespace std;
struct ed{int nxt,to,c;}e[N*10];
struct Dat{
int u,val;
bool operator <(const Dat & a)const{
return val>a.val;
}
};
priority_queue<Dat>que;
int head[N],tot,d[N],n;
void link(int u,int v,int c){e[tot].nxt=head[u];e[tot].to=v;e[tot].c=c;head[u]=tot++;}
void Dijkstra(int s,int t){
que.push((Dat){s,0});
memset(d,127/3,sizeof(d));
d[s]=0;
while(!que.empty()){
Dat tmp=que.top();que.pop();
int u=tmp.u;
for(int i=head[u];i!=-1;i=e[i].nxt)if(d[e[i].to]>d[u]+e[i].c){
int v=e[i].to;
d[v]=d[u]+e[i].c;
que.push((Dat){v,d[v]});
}
}
}
int main(){
memset(head,-1,sizeof(head));
scanf("%d",&n);
for(int i=1;i<=n+1;++i)
for(int j=1;j<=n;++j){
int v;scanf("%d",&v);
if(i==1){
link(pos(i,j),T,v);
}
else if(i<=n){
link(pos(i,j),pos(i-1,j),v);
}else {
link(S,pos(i-1,j),v);
}
}
for(int i=1;i<=n;++i)
for(int j=1;j<=n+1;++j){
int v;scanf("%d",&v);
if(j==1){
link(S,pos(i,j),v);
}
else if(j<=n){
link(pos(i,j-1),pos(i,j),v);
}else {
link(pos(i,j-1),T,v);
}
}
for(int i=1;i<=n+1;++i)
for(int j=1;j<=n;++j){
int v;scanf("%d",&v);
if(i==1){
link(T,pos(i,j),v);
}
else if(i<=n){
link(pos(i-1,j),pos(i,j),v);
}else {
link(pos(i-1,j),S,v);
}
}
for(int i=1;i<=n;++i)
for(int j=1;j<=n+1;++j){
int v;scanf("%d",&v);
if(j==1){
link(pos(i,j),S,v);
}
else if(j<=n){
link(pos(i,j),pos(i,j-1),v);
}else {
link(T,pos(i,j-1),v);
}
}
Dijkstra(S,T);
cout<<d[T];
return 0;
}