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 | (abs x + abs y) `elem` d = 1 | f = 2 | otherwise = -1 where dist = x + 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 = (max evenMax v, oddMax, ans || abs (dist - x) <= evenMax) | otherwise = (evenMax, max oddMax v, ans || abs (dist - x) <= oddMax)