using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST{ static void Main(){ Sol mySol =new Sol(); mySol.Solve(); } } class Sol{ public void Solve(){ Func InRange = (r,c) =>{ return 0<=r && r enc = (r,c)=> r*md + c; Func canGo1 = (from,to) => { return Math.Abs(S[from/md][from%md] - S[to/md][to%md])<=1; }; Func canGo2 = (from,to) => { return (S[from/md][from%md] == S[to/md][to%md]) && (S[from/md][from%md] > S[((from + to)/2)/md][((from + to)/2)%md]); }; Queue Q = new Queue(); Q.Enqueue(enc(sy,sx)); min[sy][sx] = 0; while(Q.Count>0){ var p = Q.Dequeue(); int r = p/md; int c = p%md; for(int t=0;t<4;t++){ int ny = r + dy[t]; int nx = c + dx[t]; if(InRange(ny,nx) && canGo1(p,enc(ny,nx)) && min[ny][nx] == -1){ min[ny][nx] = min[r][c] + 1; Q.Enqueue(enc(ny,nx)); } ny = r + 2*dy[t]; nx = c + 2*dx[t]; if(InRange(ny,nx) && canGo2(p,enc(ny,nx)) && min[ny][nx] == -1){ min[ny][nx] = min[r][c] + 1; Q.Enqueue(enc(ny,nx)); } } } Console.WriteLine(min[gy][gx] == -1?"NO":"YES"); } int H,W; int sx,sy,gx,gy; String[] S; public Sol(){ var d = ria(); H = d[0]; W = d[1]; d = ria(); sy = d[0]-1; sx = d[1]-1; gy = d[2]-1; gx = d[3]-1; S = new String[H]; for(int i=0;iint.Parse(e));} static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));} static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));} }