from collections import defaultdict import sys input = sys.stdin.readline n, m, b = map(int, input().split()) A = list(map(int, input().split())) DP = defaultdict(int) DP[0] = 1 for i in range(n): a = A[i] N = sorted(DP.keys()) NDP = defaultdict(int) for j in N: NDP[j] += DP[j] NDP[j + a] += DP[j] DP = NDP ans = 0 N = sorted(DP.keys()) for i in N: ans += DP[i] * pow(m, i, b) % b ans %= b print(ans)