A,B,C,D=map(int,raw_input().strip().split(" ")) print A*B*C%D