import math N, M, B = map(int, input().split()) A = list(map(int, input().split())) ans = 1 for a in A : x = math.pow(M, a, B) ans = (ans * (1 + x)) % B print(ans)