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<int,int,bool> InRange = (r,c) =>{ return 0<=r && r<H && 0 <= c && c <W; }; int[][] min = new int[H][]; for(int i=0;i<H;i++){ min[i] = new int[W]; for(int j=0;j<W;j++){ min[i][j] = -1; } } int[] dy = new int[]{0,-1,0,1}; int[] dx = new int[]{1,0,-1,0}; int md = 1<<10; Func<int,int,int> enc = (r,c)=> r*md + c; Func<int,int,bool> canGo1 = (from,to) => { return Math.Abs(S[from/md][from%md] - S[to/md][to%md])<=1; }; Func<int,int,bool> 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<int> Q = new Queue<int>(); 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;i<H;i++){ S[i] = rs(); } } static String rs(){return Console.ReadLine();} static int ri(){return int.Parse(Console.ReadLine());} static long rl(){return long.Parse(Console.ReadLine());} static double rd(){return double.Parse(Console.ReadLine());} static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);} static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.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));} }