import java.util.* data class Data(val dist: Long, val pos: Int) : Comparable { override fun compareTo(other: Data): Int { return if (dist - other.dist > 0) 1 else -1 } } fun main() { val (h, w) = readLine()!!.split(" ").map { it.toInt() } val line = readLine()!!.split(" ").map { it.toLong() } val (si, sj, ti, tj) = readLine()!!.split(" ").map { it.toInt() - 1 } val di = listOf(-1, 1, 0, 0) val dj = listOf(0, 0, 1, -1) val mat = (0 until h).map { readLine()!! } val d = List(h) { MutableList(w) { 1L shl 60 } } d[si][sj] = 0 val pq = PriorityQueue() pq.add(Data(d[si][sj], si * w + sj)) while (pq.isNotEmpty()) { val (dist, pos) = pq.poll() val i = pos / w val j = pos % w if (d[i][j] != dist) continue for (k in 0 until 4) { val ni = i + di[k] val nj = j + dj[k] if (ni !in 0 until h || nj !in 0 until w || mat[ni][nj] == '#') continue val ndist = dist + (if (mat[ni][nj] == '@') line[5] else 0) + line[k] if (d[ni][nj] >= ndist) continue d[ni][nj] = ndist pq.add(Data(ndist, ni * w + nj)) } } println(if (d[ti][tj] <= line[4]) "Yes" else "No") }