main = do [a,b,c,d] <- (map read . words) <$> getLine putStrLn . show $ (a * b * c) `mod` d