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

N, D = list(map(int,input().split()))
A = list(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 = (i - k) * D + A[i]
  if rt > t:
    Ll.append(i)
    k = i
    rt = A[i]
    
rt = (N-1) * D + A[0]
Lr = [0]
k = 0
for i in range(1, N-1):
  t = (k - i) * D + A[i]
  if rt > t:
    Lr.append(i)
    k = i
    rt = A[i]

Ch = [[0] * N for i in range(N)]
L = []
cnt = -1
for i in range(N-1):
  if i >= Ll[cnt]:
    cnt -= 1
  L.append((A[i] + A[Ll[cnt]] + (Ll[cnt] - i) * D, i, Ll[cnt]))
  Ch[i][Ll[cnt]] = 1

cnt = -1
for i in range(N-1, 0, -1):
  if i <= Lr[cnt]:
    cnt -= 1
  if Ch[Lr[cnt]][i] == 0:
  	L.append((A[i] + A[Lr[cnt]] + (i - Lr[cnt]) * D, Lr[cnt], i))

#print(L)
  
L.sort()

#print(L)

T = [[i, 0] 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)