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