n = [int(i) for i in input().strip().split(' ')] print((n[0] * n[1] * n[2]) % n[3])