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