n, k = map(int, input().split()) a = list(map(int, input().split())) m = sum(a) ans = 0 for x in a: ans *= k ans += x ans %= m print(ans)