main = do [x,y,l] <- map read . words <$> getContents print (robot x y l) robot x y l = (div' x l) + (div' y l) + (rotate x y) where div' a b = let (d,m) = divMod (abs a) (abs b) in d + signum m rotate x y | x==0 && y>=0 = 0 | y>=0 = 1 | otherwise = 2