# No.373 かけ算と割った余り a, b, c, d = [int(i) for i in input().split()] print((a * b * c) % d)