var inpt = readLine()!.split(separator: " ").map({Int($0)!}) var tmp = (inpt[0] % inpt[3]) tmp = tmp * inpt[1] tmp = tmp % inpt[3] tmp = tmp * inpt[2] tmp = tmp % inpt[3] print(tmp)