main::IO() main = do a:b:c:d:_ <- fmap (fmap read . words) getLine print $ (a*b*c) `mod` d