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==0 || neighbor x y) $ zip ns [1..16] move (x,ds) = case find ((==x) . fst) ds of Nothing -> (16, ds) Just (x,y) -> (y, delete (x,y) ds) neighbor x y = (qx==qy && abs (x-y) == 1) || (rx==ry && abs (x-y) == 4) where (qx,rx) = divMod (x-1) 4 (qy,ry) = divMod (y-1) 4