import Data.List main = do _ <- getLine d <- map read . words <$> getLine [x, y] <- map read . words <$> getLine print $ solve d x y solve :: [Int] -> Int -> Int -> Int solve d x y | x == 0 && y == 0 = 0 | dist `elem` d = 1 | f = 2 | otherwise = -1 where dist = abs x + abs y f = if even dist then dist <= 2 * maximum d else let (_, _, ans) = foldl' g (0, 0, False) (sort d) in ans g :: (Int, Int, Bool) -> Int -> (Int, Int, Bool) g (evenMax, oddMax, ans) v | even v = (v, oddMax, ans || abs (dist - v) <= oddMax) | otherwise = (evenMax, v, ans || abs (dist - v) <= evenMax)