import Data.Bool import Data.List main = getContents >>= putStrLn . bool "No" "Yes" . pazzle15 . map read . words pazzle15 ns = null $ snd $ until (\(x,_) -> x==16) move (0, ds) where ds = filter (\(x,y) -> x /= y && elem (abs (x-y)) [1,4]) $ zip ns [1..16] move (x,ds) = case find ((==x) . fst) ds of Nothing -> (16, ds) Just (x,y) -> (y, delete (x,y) ds)