a = gets.chomp.split(" ").map { |i| i.to_i } puts (a[0] * a[1] * a[2]) % a[3]