def getR(x):
  if T[x] == x:
    return x
  return getR(T[x])
 
def judT(x, y):
  xR = getR(x)
  yR = getR(y)
  if xR != yR:
    T[xR] = yR
  return xR != yR
 
N, D = list(map(int,input().split()))
A = list(map(int, input().split()))

Ll = [(A[i] + i * D, i) for i in range(1, N)]
Lr= [(A[i] + (N-i-1) * D, i) for i in range(0, N-1)]
Ll.sort()
Lr.sort()

L = []
cnt = 0
for i in range(0, N-1):
  while True:
    if Ll[cnt][1] <= i:
      cnt+=1
    else:
      break
  L.append((A[i] + Ll[cnt][0] - i * D, i, Ll[cnt][1]))

cnt = 0
for i in range(N-1, 0, -1):
  while True:
    if Lr[cnt][1] >= i:
      cnt+=1
    else:
      break
  L.append((A[i] + Lr[cnt][0] - (N -1 - i) * D, i, Lr[cnt][1]))

L.sort()

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)