#include #include #include #include #include #include #include #include #include static constexpr size_t di[] = {size_t(-1), 0, 1, 0}; static constexpr size_t dj[] = {0, size_t(-1), 0, 1}; int main() { size_t h, w; scanf("%zu %zu", &h, &w); size_t sy, sx, gy, gx; scanf("%zu %zu %zu %zu", &sy, &sx, &gy, &gx); --sy; --sx; --gy; --gx; std::vector b(h); for (size_t i = 0; i < h; ++i) { char buf[64]; scanf("%s", buf); b[i] = buf; } std::queue> q; std::vector> vis(h, std::vector(w)); q.emplace(sy, sx); while (!q.empty()) { size_t i, j; std::tie(i, j) = q.front(); q.pop(); if (vis[i][j]) continue; vis[i][j] = true; for (int k = 0; k < 4; ++k) { size_t ni = i + di[k]; size_t nj = j + dj[k]; if (!(ni < h && nj < w)) continue; int m0 = b[i][j]; int m1 = b[ni][nj]; if (abs(m0-m1) <= 1 && !vis[ni][nj]) { q.emplace(ni, nj); } size_t nni = ni + di[k]; size_t nnj = nj + dj[k]; if (!(nni < h && nnj < w)) continue; int m2 = b[nni][nnj]; if (m2 == m0 && m2 > m1 && !vis[nni][nnj]) { q.emplace(nni, nnj); } } } puts(vis[gy][gx]? "YES":"NO"); }