a, b, c, d = gets.split("\s").map(&:to_i) puts (a * b * c) % d