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 = []
LC = 0
cnt = 0
while True:
  while Ll[cnt][1] > LC:
    L.append((A[LC] + Ll[cnt][0] - LC * D, LC, Ll[cnt][1]))
    LC += 1
  if LC == N-1:
    break
  while Ll[cnt][1] <= LC:
    cnt += 1

cnt = 0
RC = N-1
while True:
  while Lr[cnt][1] < RC:
    L.append((A[RC] + Lr[cnt][0] - (N - 1 - RC) * D, Lr[cnt][1], RC))
    RC -= 1
  if RC == 0:
    break
  while Lr[cnt][1] >= RC:
    cnt += 1

L = list(set(L))
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)
