program peti;
function stepen(a:integer; c:integer): integer;
var i,k: integer;
begin
    k:=1;
    for i:=1 to a do
    begin
    k:=k*c;
    end;
    stepen:=k
    end;
var x,m,n,c,k,z,i,j: longInt;
    a,b: array[0..20000000]of longInt;
begin
read (n);
read (m);
z:=0;
for i:=1 to m do
begin
read (b[i]);
end;
read(c);
for i:=1 to n do
begin
a[i]:=i;
end;
for i:=0 to n-m do
begin
for j:=1 to m do
begin
x:=b[j];
a[x+i]:=a[i+j];
end;
end;
for i:=1 to n do
begin
for j:=1 to i do
begin
k:=stepen(i,c);
end;
z:=z+(k*a[i]);
end;
write(z);
end.