#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) #define all(c) (c).begin(), (c).end() #define zero(a) memset(a, 0, sizeof a) #define minus(a) memset(a, -1, sizeof a) #define minimize(a, x) a = std::min(a, x) #define maximize(a, x) a = std::max(a, x) typedef long long ll; int const inf = 1<<29; int dx[4] = {-1,0,1,0}; int dy[4] = {0,-1,0,1}; template constexpr bool in_range(T y, T x, T H, T W) { return 0<=y&&y vis[50][50]; int main() { int H, W; cin >> H >> W; int A, si, sj; cin >> A >> si >> sj; int B, gi, gj; cin >> B >> gi >> gj; char yuki[H][W+1]; rep(i, H) { cin >> yuki[i]; } queue> q; q.emplace(si, sj, A); vis[si][sj].insert(A); while(!q.empty()) { auto p = q.front(); q.pop(); int i, j, c; tie(i, j, c) = p; rep(d, 4) { auto const ni = i + dy[d], nj = j + dx[d]; if(!in_range(ni, nj, H, W)) { continue; } int const nc = c + (yuki[ni][nj] == '*' ? 1 : -1); if(nc <= 0 || nc > 2000) { continue; } if(vis[ni][nj].count(nc)) { continue; } if(ni == gi && nj == gj && nc == B) { cout << "Yes" << endl; exit(0); } vis[ni][nj].insert(nc); q.emplace(ni, nj, nc); } } cout << "No" << endl; return 0; }