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