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