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