#include using namespace std; namespace fastio { static constexpr int SZ = 1 << 17; char ibuf[SZ], obuf[SZ]; int pil = 0, pir = 0, por = 0; struct Pre { char num[40000]; constexpr Pre() : num() { for (int i = 0; i < 10000; i++) { int n = i; for (int j = 3; j >= 0; j--) { num[i * 4 + j] = n % 10 + '0'; n /= 10; } } } } constexpr pre; inline void load() { memcpy(ibuf, ibuf + pil, pir - pil); pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin); pil = 0; } inline void flush() { fwrite(obuf, 1, por, stdout); por = 0; } inline void rd(char &c) { c = ibuf[pil++]; } template inline void rd(T &x) { if (pil + 32 > pir) load(); char c; do c = ibuf[pil++]; while (c < '-'); bool minus = 0; if (c == '-') { minus = 1; c = ibuf[pil++]; } x = 0; while (c >= '0') { x = x * 10 + (c & 15); c = ibuf[pil++]; } if (minus) x = -x; } inline void rd() {} template inline void rd(Head &head, Tail &... tail) { rd(head); rd(tail...); } inline void wt(char c) { obuf[por++] = c; } template inline void wt(T x) { if (por > SZ - 32) flush(); if (!x) { obuf[por++] = '0'; return; } if (x < 0) { obuf[por++] = '-'; x = -x; } int i = 12; char buf[16]; while (x >= 10000) { memcpy(buf + i, pre.num + (x % 10000) * 4, 4); x /= 10000; i -= 4; } int d = x < 100 ? (x < 10 ? 1 : 2) : (x < 1000 ? 3 : 4); memcpy(obuf + por, pre.num + x * 4 + 4 - d, d); por += d; memcpy(obuf + por, buf + i + 4, 12 - i); por += 12 - i; } inline void wt() {} template inline void wt(Head head, Tail... tail) { wt(head); wt(tail...); } template inline void wtn(T x) { wt(x, '\n'); } struct Dummy { Dummy() { atexit(flush); } } dummy; } // namespace fastio using fastio::rd; using fastio::wt; using fastio::wtn; struct UnionFind { vector data; UnionFind(int N) : data(N, -1) {} int find(int k) { return data[k] < 0 ? k : data[k] = find(data[k]); } bool unite(int x, int y) { if ((x = find(x)) == (y = find(y))) return false; if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return true; } int size(int k) { return -data[find(k)]; } bool same(int x, int y) { return find(x) == find(y); } }; void run_yukicoder_No424() { int h, w; rd(h, w); UnionFind uf(h * w); int sx, sy, gx, gy; rd(sx, sy, gx, gy); --sx, --sy, --gx, --gy; int b[64][64]; for (int i = 0; i < h; i++) { string s; cin >> s; for (int j = 0; j < w; j++) { b[i][j] = s[j] - '0'; } } static const int dx[4] = {1, 0, -1, 0}; static const int dy[4] = {0, 1, 0, -1}; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { for (int d = 0; d < 4; d++) { int xx = j + dx[d]; int yy = i + dy[d]; if (xx < 0 || xx >= w || yy < 0 || yy >= h) continue; if (abs(b[yy][xx] - b[i][j]) <= 1) { uf.unite(i * w + j, yy * w + xx); } else if (b[yy][xx] < b[i][j]) { int xxx = xx + dx[d], yyy = yy + dy[d]; if (xxx < 0 || xxx >= w || yyy < 0 || yyy >= h) continue; if (b[yyy][xxx] == b[i][j]) uf.unite(i * w + j, yyy * w + xxx); } } } } bool ans = uf.same(sy * w + sx, gy * w + gx); cout << (ans ? "YES" : "NO") << endl; } int main() { run_yukicoder_No424(); return 0; }