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