inputer_s = input() inputer_data = inputer_s.split(" ") first_d = int(inputer_data[0]) second_d = int(inputer_data[1]) third_d = int(inputer_data[2]) forth_d=int(inputer_data[3]) first_d = int(first_d%forth_d) second_d = int(second_d%forth_d) third_d = int(third_d%forth_d) first_second = (first_d*second_d)%forth_d result=(first_second*third_d)%forth_d print(result)