import Control.Applicative ((<$>)) main = do [a,b,c,d] <- fmap read. words <$> getLine print $ a * b * c `mod` d