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