#include using namespace std; #define rep(i, j, n) for(int i=j;i pi; template using vt = vector; template using vvt = vector>; i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));} i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);} int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; int main() { cin.tie(0); ios::sync_with_stdio(false); int h, w; int sx, sy, gx, gy; cin >> h >> w >> sx >> sy >> gx >> gy; sx--; sy--; gx--; gy--; vt b(h); rep(i, 0, h) cin >> b[i]; vvt ok(h, vt(w, false)); ok[sx][sy] = true; queue que; que.push({sx, sy}); while(!que.empty()) { int x = que.front().first, y = que.front().second; que.pop(); rep(i, 0, 4) { int nx = x + dx[i], ny = y + dy[i]; if(nx < 0 || nx >= h || ny < 0 || ny >= w) continue; if(ok[nx][ny]) continue; if(abs(b[x][y] - b[nx][ny]) <= 1) { que.push({nx, ny}); ok[nx][ny] = true; } int nnx = nx + dx[i], nny = ny + dy[i]; if(nnx < 0 || nnx >= h || nny < 0 || nny >= w) continue; if(ok[nnx][nny]) continue; if(b[x][y] == b[nnx][nny] && b[x][y] > b[nx][ny]) { que.push({nnx, nny}); ok[nnx][nny] = true; } } } if(ok[gx][gy]) cout << "YES\n"; else cout << "NO\n"; }