a, b, c, d = [int(x) for x in input().split()] print(a * b * c % d)