from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N,V,sy,sx,gy,gx = map(int,input().split()) sx -= 1 sy -= 1 gx -= 1 gy -= 1 A = [list(map(int,input().split())) for _ in range(N)] e = [[] for _ in range(N**4)] INF = (1<<60) def dijkstra(s,e): N = len(e) dist = [INF]*N dist[s]=0 h = [] heappush(h,(0,s)) while h: nw,v = heappop(h) if dist[v]!=nw: continue for iv,ic in e[v]: nc = ic + nw if nc < dist[iv]: dist[iv] = nc heappush(h,(nc,iv)) return dist H = N W = N def nb(x,y): tmp = [] if x+1=0: tmp.append((x-1,y)) if y+1=0: tmp.append((x,y-1)) return tmp M = N**2 for i in range(H): for j in range(W): s = N*i + j for ix,iy in nb(i,j): t = N*ix + iy a = A[ix][iy] for n in range(M-1): ss = n*M + s tt = (n+1)*M + t e[ss].append((tt,a)) d = dijkstra(sx*N+sy,e) g = N*gx + gy ans = INF for i in range(M): gg = i*M + g if d[gg]