info=list(map(int, input().split())) print(info[0]*info[1]*info[2]%info[3])