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