#include<iostream>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 6;
int w[N][N];
int dist[N][N][5];//因为这里已经mod4
bool st[N][N][5];
struct Node{
int a;
int b;
int f;
};
int x1,y1,x2,y2;
int spfa()
{
queue<Node> q;
q.push({x1,y1,1});
memset(dist,0x3f,sizeof dist);
dist[x1][y1][1]=0;
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
while(!q.empty())
{
auto t = q.front();
q.pop();
st[t.a][t.b][t.f] = false;
for(int i=0;i<4;i++)
{
int x = t.a+dx[i],y = t.b+dy[i];
if(x<0 || x>=6 || y<0 || y>=6) continue;
int cost = t.f *w[x][y];
int s = cost%4+1;
if(dist[x][y][s] > dist[t.a][t.b][t.f]+cost){
dist[x][y][s] = dist[t.a][t.b][t.f]+cost;
if(!st[x][y][s]){
q.push({x,y,s});
st[x][y][s];
}
}
}
}
int res = 1e9;
for(int i=0;i<5;i++)
{
res = min(res,dist[x2][y2][i]);
}
return res;
}
int main()
{
for(int i=0;i<6;i++)
{
for(int j = 0;j<6;j++)
{
cin>>w[i][j];
}
}
//用一下spfa,他全都可以用,dijkstra只能用于正
cin>>x1>>y1>>x2>>y2;
cout<<spfa()<<endl;
return 0;
}