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