#include<bits/stdc++.h>
using namespace std;
typedef struct node{
int nx;
int ny;int nz;
int val;
}node;
int main() {
int a[6][6]; int z[6][6][5];int dx[]={-1,0,1,0};
for(int i=0;i<6;i++){
for(int j=0;j<6;j++){
for(int k=0;k<5;k++){
z[i][j][k]=INT_MAX;
}
}
}
int dy[]={0,1,0,-1};
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
cin >> a[i][j];
}
}
int q1 = 0, q2 = 0, w1 = 0, w2 = 0, q = 0;
cin >> q1; cin >> q2; cin >> w1; cin >> w2;z[q1][q2][1]=0;
queue<node> dui;dui.push({q1,q2,1,0});
while(!dui.empty()){
node& n=dui.front();
dui.pop();
for(int i=0;i<4;i++){
int qx=dx[i]+n.nx;int qy=dy[i]+n.ny;int qz=n.nz;
if(qx<0||qx>5||qy<0||qy>5){
continue;
}
int cost=qz*a[qx][qy];int state=cost%4+1;
if(n.val+cost<z[qx][qy][state])
{
dui.push({qx,qy,state,n.val+cost});z[qx][qy][state]=n.val+cost;
}
}
}int mini=INT_MAX;
for(int i=0;i<5;i++)
{
mini=min(mini,z[w1][w2][i]);
}
cout<<mini;
return 0;
}