def main(): a, b, c, d = map(int, input().split()) # print(a, b, c, d) print((a * b * c) % d) if __name__ == "__main__": main()