def J(): return map(int,input().split()) N,M,B=J() n=1 for a in J():n=n*(1+pow(M,a,B))%B print(n)