def main():
  N, D = tuple(map(int,input().split()))
  A = tuple(map(int, input().split()))

  A2 = [[A[i], i, 0] for i in range(N)]
  A2.sort()
  for i in range(N):
    A2[i][2] = i
  A2.sort(key = lambda x: x[1])
  A2 = tuple(A2)
  rt = A[N - 1]
  Ll = [N - 1]
  k = N - 1
  for i in range(N - 2, 0, -1):
    t = A[i]  
    if rt > t - (k - i) * D :
      Ll.append(i)
      k = i
      rt = t

  rt = A[0]
  Lr = [0]
  k = 0
  for i in range(1, N - 1):
    t = A[i]
    if rt > t + (k - i) * D:
      Lr.append(i)
      k = i
      rt = t

  Ll = tuple(Ll)
  Lr = tuple(Lr)

  L = []
  lC = -1
  rC = -1
  for i in range(N-1):
    if i >= Ll[lC]:
      lC -= 1
    t = Ll[lC]
    if A2[i][2] > A2[t][2]: 
      L.append((A[i] + A[t] + (t - i) * D, i, t))
    k = N - 1 - i
    if k <= Lr[rC]:
      rC -= 1
    t = Lr[rC]
    if A2[k][2] > A2[t][2]:
      L.append((A[k] + A[t] + (k - t) * D, t, k))
  
  L.sort()
  
  T = [i for i in range(N)]
  C = 0
  A = 0
  for i in L:
    xR = i[1]
    xC = 0
    yR = i[2]
    yC = 0
    while T[xR] != xR:
      xC += 1
      xR = T[xR]
    while T[yR] != yR:
      yC += 1
      yR = T[yR]
    if xR != yR:
      if xC < yC:
        T[xR] = yR
      else:
        T[yR] = xR
    if xR != yR:
      C += 1
      A += i[0]
      #print(i)
      if C == N-1:
        break
   
  print(A)
  
main()