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