a,b,c,d = int(map(input().split())) print(a*b*c%d)