def judT(x, y):
  xR = x
  xC = 0
  while T[xR] != xR:
    xC += 1
    xR = T[xR]
  yR = y
  yC = 0
  while T[yR] != yR:
    yC += 1
    yR = T[yR]
  if xR != yR:
    if xC < yC:
      T[xR] = yR
    else:
      T[yR] = xR
  return xR != yR

N, D = tuple(map(int,input().split()))
A = tuple(map(int, input().split()))

rt = (N - 1) * D + A[N - 1]
Ll = [N - 1]
k = N - 2
for i in range(N - 2, 0, -1):
  t = A[i]  
  if rt > t - (k - i) * D :
    Ll.append(i)
    k = i
    rt = t

rt = (N - 1) * D + A[0]
Lr = [0]
k = 0
for i in range(1, N - 1):
  t = A[i]
  if rt > t + (k - i) * D:
    Lr.append(i)
    k = i
    rt = t
Lr.append(N)

Ll = tuple(Ll)
Lr = tuple(Lr)

L = []
lC = -1
rC = 1
for i in range(N-1):
  if i >= Ll[lC]:
    lC -= 1
  t = Ll[lC]
  L.append((A[i] + A[t] + (t - i) * D, i, t))
  k = i + 1
  if k > Lr[rC]:
    rC += 1
  t = Lr[rC-1]
  L.append((A[k] + A[t] + (k - t) * D, t, k))
 
L = list(set(L))  
L.sort()
L = tuple(L)

T = [i for i in range(N)]
C = 0
A = 0

for i in L:
  if judT(i[1], i[2]):
    C += 1
    A += i[0]
    #print(i)
    if C == N-1:
      break
 
print(A)