using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Pair = System.Collections.Generic.KeyValuePair; //key = x, value = y namespace yuki_424 { class Program { static int h, w; static int sx, sy, gx, gy; static int[] dx = { -1, 1, 0, 0, -2, 2, 0, 0 }; static int[] dy = { 0, 0, -1, 1, 0, 0, -2, 2 }; static void Main(string[] args) { var t = scan; h = t[0]; w = t[1]; t = scan; sx = t[0]-1;sy = t[1]-1;gx = t[2]-1;gy = t[3]-1; var M = new Dictionary(); var N = new HashSet(); for (int i = 0; i < h; i++) { string s = Console.ReadLine(); for (int j = 0; j < w; j++) { M[new Pair(i, j)] = int.Parse(s[j].ToString()); } } var Q = new Queue(); Q.Enqueue(new Pair(sx, sy)); N.Add(new Pair(sx, sy)); bool flag = false; while (Q.Any()) { var u = Q.Dequeue(); //Console.WriteLine(u.Key+" "+u.Value); if(u.Key == gx && u.Value == gy) { flag = true; break; } for (int i = 0; i < 4; i++) { var tx = u.Key + dx[i]; var ty = u.Value + dy[i]; if (tx < 0 || ty < 0 || tx >= h || ty >= w) continue; var p = new Pair(tx, ty); if (Math.Abs(M[p] - M[u]) <= 1 && !N.Contains(p)) { Q.Enqueue(p); N.Add(p); } } for (int i = 4; i < 8; i++) { var tx = u.Key + dx[i]; var ty = u.Value + dy[i]; if (tx < 0 || ty < 0 || tx >= h || ty >= w) continue; var p = new Pair(tx, ty); var s = new Pair((tx + u.Key) / 2, (ty + u.Value) / 2); if (M[p] == M[u] && !N.Contains(p) && M[s] < M[u]) { Q.Enqueue(p); N.Add(p); } } } if (flag) Console.WriteLine("YES"); else Console.WriteLine("NO"); } static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } } }