a = long(input()) b = long(input()) c = long(input()) d = long(input()) print((a * b * c) % d)