#include #define rep(x, to) for (int x = 0; x < (to); x++) #define REP(x, a, to) for (int x = (a); x < (to); x++) #define EPS (1e-14) #define _PA(x,N) rep(i,N){cout< PII; typedef pair PLL; typedef complex Complex; typedef vector< vector > Mat; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int h, w; int sx, sy, gx, gy; string b[55]; int f[55][55]; char visit[55][55]; void dfs(int y, int x) { if (visit[y][x]) return; visit[y][x] = 1; for (int i = 0; i < 4; i++) { int ny = y + dy[i]; int nx = x + dx[i]; if (ny < 0 || ny >= h) continue; if (nx < 0 || nx >= w) continue; if (f[ny][nx] - 1 <= f[y][x] && f[y][x] <= f[ny][nx] + 1) { dfs(ny, nx); } else if (f[y][x] - f[ny][nx] >= 2) { ny += dy[i]; nx += dx[i]; if (ny < 0 || ny >= h) continue; if (nx < 0 || nx >= w) continue; if (f[ny][nx] != f[y][x]) continue; dfs(ny, nx); } } } void solve() { dfs(sy, sx); if (visit[gy][gx]) { cout << "YES" << endl; } else { cout << "NO" << endl; } } int main() { cin >> h >> w; cin >> sx >> sy >> gx >> gy; sx--, sy--, gx--, gy--; swap(sy, sx); swap(gy ,gx); for (int i = 0; i < h; i++) { cin >> b[i]; } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { f[i][j] = b[i][j] - '0'; } } solve(); return 0; }