#include <iostream>
#include <string>
#include <stdlib.h>
#include <bits/stdc++.h>
#define USE_MATH_DEFINES
using namespace std;

int main()
{
long long int n, m, i, j, c, r;
int* a= new int[20000000];
int*b=new int [100000];
cin>>n>>m;
r=0;
for (i=1; i<=n; i++) {
    if (i<=m) {
    cin>>b[i];}
    a[i]=i;
}
for (i=0; i<=n-m; i++) {
    for (j=1; j<=m; j++) {
        a[i+b[j]]=a[i+j];
    }
}
cin>>c;
for (i=1; i<=n; i++) {
    r=r+pow(c, i)*a[i];}
cout<<r;
return 0;
}