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