import numpy as np
N,D=list(map(int,input().split()))
A=np.array(list(map(int,input().split())))
sum=np.sum(A)
AnsList=np.array([])
for i in range(N-1):
    for j in range(i+1,N):
        tmp=2*sum-A[i]-A[j]
        tmp+=D*(2*N+i-j-2)
        AnsList=np.append(AnsList,[tmp])
AnsList=np.sort(AnsList)
print(int(AnsList[0]))
