N, D = list(map(int,input().split()))
A = list(map(int, input().split()))
L = [[(abs(j-i) * D + A[i] if i != j else pow(10,10), i) for i in range(N)] for j in range(N)]

for i in range(len(L)):
  L[i].sort()

cnt = 0
T = []
for i in range(len(L)):
  if i not in T:
    cnt += A[i]
    T.append(i)
    T.append(L[i][0][1])
    cnt += L[i][0][0]

print(cnt)