use std::io::*; 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 mut table = vec![vec![0i32; 4]; 4]; let mut cx = 0i32; let mut cy = 0i32; for i in 0..4 { for j in 0..4 { table[i][j] = itr.next().unwrap().parse().unwrap(); if table[i][j] == 0 { cx = j as i32; cy = i as i32; } } } let dx: Vec = [0, -1, 0, 1].to_vec(); let dy: Vec = [1, 0, -1, 0].to_vec(); loop { let target = cy * 4 + cx + 1; let mut moved = false; let mut tigau = 0; for i in 0..4 { let nx = cx + dx[i]; let ny = cy + dy[i]; if 0 <= nx && nx < 4 && 0 <= ny && ny < 4 { if table[ny as usize][nx as usize] != ny * 4 + nx + 1 { tigau += 1; } if table[ny as usize][nx as usize] == target { moved = true; table[cy as usize][cx as usize] = table[ny as usize][nx as usize]; table[ny as usize][nx as usize] = 0; cx = nx; cy = ny; break; } } } if !moved { if tigau > 0 { println!("No",); } else { for i in 0..4 { for j in 0..4 { if table[i][j] != (i * 4 + j + 1) as i32 % 16 { println!("No",); return; } } } println!("Yes",); } return; } } }