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