def judT(x, y):
  xR = x
  while T[xR][0] != xR:
    xR = T[xR][0]
  yR = y
  while T[yR][0] != yR:
    yR = T[yR][0]
  if xR != yR:
    if T[xR][1] < T[yR][1]:
      T[xR][0] = yR
      T[yR][1] = T[xR][1] + 1
    else:
      T[yR][0] = xR
      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 = [(rt, N-1)]
for i in range(N-2, -1, -1):
  t = i * D + A[i]
  if rt > t:
    Ll.append((t, i))
    rt = t
    
rt = (N-1) * D + A[0]
Lr = [(rt, 0)]
for i in range(1, N):
  t = (N - 1 - i) * D + A[i]
  if rt > t:
    Lr.append((t, i))
    rt = t

lf = Ll[-1][1]
ri = Lr[-1][1]

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

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

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