a, b, c, d = map(int, input().split()) q = a * b * c print(q % d)