A,B,C,D=(int (i) for i in input (). split ()) A=A*B*C%D print(A)