A,B,C,D = map(int,input().split()) ans=(A*B*C)%D print(ans)