N, M, B = map(int, input().split())
A = list(map(int, input().split()))

SUM = 1
for a in A:
    SUM += SUM*pow(M, a, B)%B
    SUM %= B

print(SUM)