import sys input = sys.stdin.readline def getlist(): return list(map(int, input().split())) def main(): n,k = getlist() a = getlist() total = sum(a) ans = 0 K = 1 for i in range(n-1,-1,-1): ans += a[i] * K K *= k ans %= total print(ans) if __name__ == '__main__': main()