use std::io::Read; fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let v: i32 = itr.next().unwrap().parse().unwrap(); let mut ox: usize = itr.next().unwrap().parse().unwrap(); let mut oy: usize = itr.next().unwrap().parse().unwrap(); let field: Vec> = (0..n) .map(|_| { (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect() }) .collect(); const INF: i32 = 40000; let mut q = std::collections::BinaryHeap::new(); let mut first: Vec> = vec![vec![-INF; n]; n]; let mut second: Vec> = vec![vec![-INF; n]; n]; q.push((v, 0)); first[0][0] = v; while let Some((life, pos)) = q.pop() { let y = pos / 1000; let x = pos % 1000; for (dy, dx) in vec![(-1, 0), (0, -1), (1, 0), (0, 1)] { let ny = (y as isize + dy) as usize; let nx = (x as isize + dx) as usize; if ny < n && nx < n && first[ny][nx] == -INF { first[ny][nx] = life - field[ny][nx]; q.push((first[ny][nx], ny * 1000 + nx)); } } } if ox != 0 || oy != 0 { oy -= 1; ox -= 1; second[oy][ox] = first[oy][ox] * 2; q.push((second[oy][ox], oy * 1000 + ox)); while let Some((life, pos)) = q.pop() { let y = pos / 1000; let x = pos % 1000; for (dy, dx) in vec![(-1, 0), (0, -1), (1, 0), (0, 1)] { let ny = (y as isize + dy) as usize; let nx = (x as isize + dx) as usize; if ny < n && nx < n && second[ny][nx] == -INF { second[ny][nx] = life - field[ny][nx]; q.push((second[ny][nx], ny * 1000 + nx)); } } } } println!( "{}", if first[n - 1][n - 1] > 0 || second[n - 1][n - 1] > 0 { "YES" } else { "NO" } ); }