import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines A,B,C,D = map(int,read().split()) A *= B A *= C A %= D print(A)