let () = let a, b, c, d = Scanf.scanf "%d %d %d %d " (fun a b c d -> a, b, c, d) in let a, b, c = a mod d, b mod d, c mod d in Printf.printf "%d\n" ((a * b mod d) * c mod d)