import numpy as np
N,D = map(int(input().split()))
A = np.array(list(map(int(input().split()))))
count = np.arange(A.shape[0])
totalcost = 0
cities = np.hstack([count[:,np.newaxis],A[:,np.newaxis]])
def cost(x,y):
    return np.abs(x[:,0]-y[:,0])*D+x[:,1]+y[:,1]
to = np.zeros(N-1)
fro = np.arange(1,N)
costs = cost(cities[to],cities[fro])
totalcost = costs.sum()
while True:
    target = np.argmax(costs)
    targetfro = fro[target]
    targetto = to[target]
    thinkcost = cost(cities[targetfro],cities[np.delete(count,targetto,0)])
    if thinkcost.min() < costs[target]:
        targetto[target] = np.argmin(thinkcost)
        costs = cost(cities[to],cities[fro])
    else:
        break
totalcost = costs.sum()
print(totalcost)