input_list = list(map(int,input().split())) a, b, c, d = input_list r1 = a % d r2 = b % d r3 = c % d res = (r1 * r2 * r3) % d print(res)