import Data.Ratio (%%) :: Integral a => Ratio a -> Ratio a -> Ratio a n %% d = (numerator n * denominator d) % (denominator n * numerator d) main :: IO () main = do bs <- map read . words <$> getLine print $ solve bs solve :: [Integer] -> Integer solve [b1, b2, b3] = numerator $ r * toRational b3 + d where d = (b1 * b3 - b2 ^ 2) % (b1 - b2) r = -(d - toRational b2) %% toRational b1