#include #include #include #include #include #include #include #define rep(i, a, b) for (int i = int(a); i < int(b); i++) using namespace std; using ll = long long int; using P = pair; // clang-format off #ifdef _DEBUG_ #define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; debug_print(__VA_ARGS__); } while(false) template void debug_print(const T &t, const Ts &...ts) { cerr << t; ((cerr << ", " << ts), ...); cerr << endl; } #else #define dump(...) do{ } while(false) #endif template vector make_v(size_t a, T b) { return vector(a, b); } template auto make_v(size_t a, Ts... ts) { return vector(a, make_v(ts...)); } template bool chmin(T &a, const T& b) { if (a > b) {a = b; return true; } return false; } template bool chmax(T &a, const T& b) { if (a < b) {a = b; return true; } return false; } template void print(const T& t, const Ts&... ts) { cout << t; ((cout << ' ' << ts), ...); cout << '\n'; } template void input(Ts&... ts) { (cin >> ... >> ts); } template istream &operator,(istream &in, T &t) { return in >> t; } // clang-format on #include using T = tuple; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int h, w; cin, h, w; ll cost[4]; rep(i, 0, 4) { cin, cost[i]; } ll k, p; cin, k, p; int xs, ys, xg, yg; cin, ys, xs, yg, xg; auto mp = make_v(h + 2, w + 2, '#'); rep(i, 1, h + 1) { rep(j, 1, w + 1) { cin, mp[i][j]; } } const ll inf = 1LL << 60; vector Cost((h + 2) * (w + 2), inf); priority_queue, greater> pq; pq.emplace(0, xs, ys); auto index = [&](int x, int y) { return y * (w + 2) + x; }; Cost[index(xs, ys)] = 0; int dy[4] = {-1, 1, 0, 0}, dx[4] = {0, 0, 1, -1}; while (pq.size()) { auto [c, x, y] = pq.top(); pq.pop(); int idx = index(x, y); if (Cost[idx] < c) continue; Cost[idx] = c; rep(t, 0, 4) { int nx = x + dx[t], ny = y + dy[t]; int nidx = index(nx, ny); if (mp[ny][nx] == '#') continue; ll nc = c + cost[t]; if (mp[ny][nx] == '@') { nc += p; } if (chmin(Cost[nidx], nc)) { pq.emplace(nc, nx, ny); } } } print(Cost[index(xg, yg)] <= k ? "Yes" : "No"); return 0; }