def getR(x):
  if T[x] == x:
    return x
  return getR(T[x])
 
def judT(x, y):
  xR = getR(x)
  yR = getR(y)
  if xR != yR:
    T[xR] = yR
  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, 0, -1):
  t = i * D + A[i]
  if rt > t:
    Ll.append((t, i))
    rt = t
Ll.reverse()

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

cnt = 0
for i in range(N-1, 0, -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 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)
