using System; using System.Collections.Generic; using System.Linq; class Magatro { static int h, w; static int sx, sy, gx, gy; static int[,] b; static int[] x = { 0, 1, -1, 0 }; static int[] y = { 1, 0, 0, -1 }; static void Main() { Read(); bool[,] qq = new bool[h, w]; Queue qx=new Queue(), qy=new Queue(); qx.Enqueue(sx); qy.Enqueue(sy); while (qx.Count > 0) { int cx = qx.Dequeue(); int cy = qy.Dequeue(); for(int i = 0; i < 4; i++) { if (cx + x[i] >= 0 && cx + x[i] < w && cy + y[i] >= 0 && cy + y[i] < h) { if(!qq[y[i] + cy, x[i] + cx]) { if(Math.Abs(b[y[i] + cy, x[i] + cx] - b[cy, cx]) <= 1) { qq[y[i] + cy, x[i] + cx] = true; qx.Enqueue(x[i] + cx); qy.Enqueue(y[i] + cy); } } } if (cx + 2*x[i] >= 0 && cx + 2*x[i] < w && cy + 2*y[i] >= 0 && cy + 2*y[i] < h) { if (!qq[2*y[i] + cy, 2*x[i] + cx]) { if (b[2*y[i] + cy, 2*x[i] + cx] == b[cy, cx]) { if (b[y[i] + cy, x[i] + cx] < b[cy, cx]) { qq[2 * y[i] + cy, 2 * x[i] + cx] = true; qx.Enqueue(2 * x[i] + cx); qy.Enqueue(2 * y[i] + cy); } } } } } } if (qq[gy, gx]) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } static void Read() { int[] q = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); h = q[0]; w = q[1]; q = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); sx = q[1]-1; sy = q[0]-1; gx = q[3]-1; gy = q[2]-1; b = new int[h, w]; for(int i = 0; i < h; i++) { string s = Console.ReadLine(); for(int j = 0; j < w; j++) { b[i, j] = int.Parse(s[j].ToString()); } } } }