use std::collections::VecDeque; fn main() { let mut xx = String::new(); std::io::Read::read_to_string(&mut std::io::stdin(), &mut xx).ok(); let xx: Vec> = xx .split_whitespace() .skip(2) .map(|s| s.chars().collect()) .collect(); let mut blk = VecDeque::new(); for y in 0..xx.len() { for x in 0..xx[0].len() { if xx[y][x] == '#' { blk.push_back((y, x)); } } } let blk = blk; if blk.len() & 1 == 1 { println!("NO"); return; } 'outer: for i in 1..blk.len() { let (dy, dx) = (blk[i].0 - blk[0].0, blk[i].1 - blk[0].1); let mut tmp = blk.clone(); while !tmp.is_empty() { let (y, x) = tmp.pop_front().unwrap(); let moves_to = (y + dy, x + dx); if tmp.contains(&moves_to) { tmp.retain(|c| c != &moves_to); } else { continue 'outer; } } println!("YES"); return; } println!("NO"); }