n,m,b = map(int,input().split()) ans = 1 for v in map(int,input().split()): ans = ans*(pow(m,v,b)+1)%b print(ans)