n,d = map(int,input().split())
a = list(map(int,input().split()))
class UnionFind():
    def __init__(self,size):
        self.table = [-1 for _  in range(size)]
    def find(self,x):
        while self.table[x] >= 0:
            x = self.table[x]
        return x
 
    def union(self,x,y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] != self.table[s2]:
                if self.table[s1] < self.table[s2]:
                    self.table[s2] = s1
                else:
                    self.table[s1] = s2
            else:
                self.table[s1] += -1
                self.table[s2] = s1
        else:
          return False
        return True
      
UF = UnionFind(n)
ki = n
ans = 0
inf = float("inf")
while ki >= 2:
  L =[]
  R = []
  hen = [[-1,-1,inf] for i in range(n)]
  for i in range(n):
    r = UF.find(i)
    for j,k in L:
      if k != r:
        if hen[r][2] > j+i*d+a[i]:
          hen[r] = [r,k,j+i*d+a[i]]
    L.append([-i*d+a[i],r])
  for i in range(n-1,-1,-1):
    r = UF.find(i)
    for j,k in R:
      if k != r:
        if hen[r][2] > j-i*d+a[i]:
          hen[r] = [r,k,j-i*d+a[i]]
    R.append([i*d+a[i],r])
  for i,j,k in hen:
    if k == float("inf"):
      continue
    if UF.union(i,j):
        ans += k
        ki -=1
print(ans)