N, M, B = map(int, input().split()) A = list(map(int, input().split())) ans = 1 for i in range(N): ans = (1+pow(M, A[i], B))*ans%B print(ans%B)