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

  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
  Lr.append(N-1)

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

  L = []
  lC = -1
  rC = 1
  lCmax = -len(Ll) - 1
  for i in range(N-1):
    if i >= Ll[lC]:
      lC -= 1
    for j in range(lC, lCmax, -1):
      t = Ll[j]
      if A[i] >= A[t]: 
        L.append((A[i] + A[t] + (t - i) * D, i, t))
        break
    k = i + 1
    if k > Lr[rC]:
      rC += 1
    for j in range(rC - 1, -1, -1):
      t = Lr[j]
      if A[k] > A[t]:
        L.append((A[k] + A[t] + (k - t) * D, t, k))
        break
  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()