a,b,c,d = gets.chomp.split(" ") puts a.to_i * b.to_i * c.to_i % d.to_i