n,m,M=map(int,input().split()) A=list(map(int,input().split())) ans=1 for i in A: ans*=pow(m,i,M)+1 ans=ans%M print(ans)