from heapq import heappush, heappop, heapify import sys from collections import defaultdict, deque,Counter from math import ceil, floor, sqrt, factorial,gcd from itertools import permutations, combinations,product,accumulate from bisect import bisect_left, bisect_right from copy import deepcopy from functools import lru_cache from fractions import Fraction sys.setrecursionlimit(10**7) # input = sys.stdin.readline vector1 = [[0, -1], [1, 0], [0, 1], [-1, 0]] vector2 = [[0, 1], [1, 0], [-1, 0], [0, -1], [1,-1], [-1, 1], [1, 1], [-1, -1]] def main(): N,M,mod = map(int,input().split()) A = list(map(int,input().split())) dp = [[0,0] for i in range(N)] #A[i]が[ない、ある] dp[0] = [1,pow(M,A[0],mod)] for i in range(1,N): dp[i][0] = sum(dp[i-1]) * pow(M,A[i],mod) % mod dp[i][1] = sum(dp[i-1]) print(sum(dp[-1])%mod) if __name__ == "__main__": main()