#include using namespace std; #define ll long long #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define Pr pair #define Tp tuple using Graph = vector>; #define double long double const ll mod = 1000000007; //dfs //s:始点 i:dfs回数 t:始点からの距離 vector vis; int t; vector depth; //探索範囲を距離L以下に制限する場合 int L; vector cnt(100001,0); void dfs(Graph &G, int s,int i){ int ti = t; t++; for(int nx:G[s]){ if(t>=L) break; if(vis[nx]==i) continue; depth[nx] = depth[s] + 1; vis[nx] = i; dfs(G,nx,i); } t++; cnt[s] = (t-ti)/2; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); ll H,W; cin >> H >> W; ll U,D,R,L,K,P; cin >> U >> D >> R >> L >> K >> P; ll cost[H][W]; rep(i,H){ rep(j,W) cost[i][j] = 2e18; } ll xs,xt,ys,yt; cin >> xs >> ys >> xt >> yt; cost[xs-1][ys-1] = 0; char g[H][W]; rep(i,H){ rep(j,W) cin >> g[i][j]; } //Dijkstra (普通のダイクストラ) priority_queue, greater> go; ll inf = 2e18; go.push(make_tuple(0,xs-1,ys-1)); Tp p; vector> step; step.push_back(make_pair(-1,0)); step.push_back(make_pair(0,-1)); step.push_back(make_pair(1,0)); step.push_back(make_pair(0,1)); vector cs = {U,L,D,R}; while(!go.empty()){ p = go.top(); go.pop(); auto[c,x,y] = p; if(c>cost[x][y]) continue; rep(i,4){ ll z = x+step[i].first; ll w = y+step[i].second; if(0>z||z>=H||0>w||W<=w) continue; if(g[z][w]=='#') continue; ll cc = cost[x][y]; if(g[z][w]=='@') cc += P; if(cc+cs[i]K) ans = "No"; cout << ans << endl; }