imagine
#include <bits/stdc++.h>
using namespace std;
long long pow(int x, int y){
if ((x == 0 || x == 1) && (y != 0)) return x;
if (y == 1) return x;
if (y == 0) return 1;
long long tmp = pow(x, y/2);
if (y%2==0) return tmp * tmp;
else return tmp * tmp * x;
}
long long solve(int a[], int idx, int n, int x){
if (idx == n) return a[n];
else return a[idx] * pow(x, n-idx+1) + solve(a, idx+1, n, x);
}
int main(){
int n,x;
cin >> n >> x;
int a[n+2];
for (int i=1;i<= n+1;i++) cin >> a[i];
cout << solve(a, 1, n+1, x);
return 0;
}