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