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()))


lf = 0
ri = N - 1

rt = (N-1) * D + A[N-1]
Ll = []
flg = False
if rt < (N-2) * D + A[N-2]:
  flg = True
  Ll.append((rt, N-1))
  
for i in range(N-2, 0, -1):
  if flg == False:
    if A[i] > A[i+1]:
      flg = True
      Ll.append((t, i + 1))
      ri = i + 1
  t = i * D + A[i]    
  if rt > t:
    if flg:
      Ll.append((t, i))
    rt = t
      
rt = (N-1) * D + A[0]
Lr = []
flg = False
if rt < (N-2) * D + A[1]:
  flg = True
  Lr.append((rt, 0))
for i in range(1, ri + 1):
  if flg == False:
    if A[i] > A[i-1]:
      flg = True
      Lr.append((t, i - 1))
      lf = i - 1
  t = (N - 1 - i) * D + A[i]
  if rt > t:
    if flg:
      Lr.append((t, i))
    rt = t
    
if flg == False:
  lf = ri
      
L = []

for i in range(0, lf):
  L.append((A[i] + A[lf] + (lf - i) * D, i, lf))
for i in range(N-1, ri, -1):
  L.append((A[i] + A[ri] + (i - ri) * D, ri, i))

if lf != ri:
  cnt = -1
  for i in range(lf, 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(ri , 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()

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)
