import sys import os a, b, c, d = map(int, raw_input().strip().split(" ") ) print (a*b*c)%d