#include using namespace std; #define FOR(i,l,r) for(int i = (l);i < (r);i++) #define ALL(x) (x).begin(),(x).end() template void chmax(T& a,const T& b){if(a < b) a = b;} template void chmin(T& a,const T& b){if(b < a) a = b;} typedef long long ll; int H,W; pair S,G; bool vis [50] [50]; const int dx [] = {0,1,0,-1}; const int dy [] = {-1,0,1,0}; bool in_range(int y,int x) { return y >= 0 && y < H && x >= 0 && x < W; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> H >> W; vector board(H); cin >> S.first >> S.second >> G.first >> G.second; S.first--,S.second--,G.first--,G.second--; FOR(i,0,H){ cin >> board [i]; } queue< pair > q; q.push(S); while(q.empty() == false){ int y = q.front().first,x = q.front().second; q.pop(); if(vis [y] [x]) continue; vis [y] [x] = true; if(make_pair(y,x) == G){ cout << "YES" << endl; return 0; } FOR(i,0,4){ int yy = y + dy [i],xx = x + dx [i]; if(in_range(yy,xx) && abs(board [y] [x] - board [yy] [xx]) <= 1){ q.push(make_pair(yy,xx)); } if(in_range(yy + dy [i],xx + dx [i]) && board [yy] [xx] < board [y] [x] && board [y] [x] == board [yy + dy [i]] [xx + dx [i]]){ q.push(make_pair(yy + dy [i],xx + dx [i])); } } } cout << "NO" << endl; return 0; }