/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
Scanner scanIn
=new Scanner
(System.
in); int n, x;
n = scanIn.nextInt();
x = scanIn.nextInt();
int a[] = new int[n + 1];
for (int i = n; i >= 0; --i) {
a[i] = scanIn.nextInt(); //enter values of array
}
int s = a[n];
for (int i = 1; i <= n; ++i) {
s *= x;
s += a[n - i];
}
System.
out.
println("S = " + s
); }
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgSWRlb25lCnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbgoJewoJCVNjYW5uZXIgc2NhbkluPW5ldyBTY2FubmVyKFN5c3RlbS5pbik7IAoJCWludCBuLCB4OwogICAgIAoJCW4gPSBzY2FuSW4ubmV4dEludCgpOwoJCXggPSBzY2FuSW4ubmV4dEludCgpOwogICAgIAoJCWludCBhW10gPSBuZXcgaW50W24gKyAxXTsKICAgICAKCQlmb3IgKGludCBpID0gbjsgaSA+PSAwOyAtLWkpIHsKCQkJYVtpXSA9IHNjYW5Jbi5uZXh0SW50KCk7IC8vZW50ZXIgdmFsdWVzIG9mIGFycmF5CgkJfQogICAgIAoJCWludCBzID0gYVtuXTsKICAgICAKCQlmb3IgKGludCBpID0gMTsgaSA8PSBuOyArK2kpIHsKCQkJcyAqPSB4OyAKCQkJcyArPSBhW24gLSBpXTsKCQl9CiAgICAgCgkJU3lzdGVtLm91dC5wcmludGxuKCJTID0gIiArIHMpOwoJfQp9