N,D=map(int,input().split())
alist=list(map(int,input().split()))

tree_flg=[False]*N

all_dist = 0
for i in range(N):
  if tree_flg[i]:
    continue
    
  min_dist=10**15
  min_index=-1
  for j in range(N):
    if i==j:
      continue
    if min_dist > abs(j-i)*D+alist[i]+alist[j]:
      min_dist = abs(j-i)*D+alist[i]+alist[j]
      min_index = j
    #if min_dist<(j-i)*D+alist[i]+1:
    #  break
   
  all_dist += min_dist
  tree_flg[i]=True
  tree_flg[min_index]=True
  #print("{} {} {}".format(i,min_index,min_dist))
  
print(all_dist)