# coding: utf-8 if __name__ == '__main__': a, b, c, d = [int(i) for i in input().split()] print((a * b) * c % d)