main :: IO ()
main = do
    [a, b, c, d] <- fmap (read :: String -> Integer) . words <$> getLine
    print $ a * b * c `mod` d