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