def main(): A,B,C,D = map(int, input().split()) print(A * B * C % D) if __name__ == '__main__': main()