import itertools
def inpl(): return list(map(int, input().split()))
def cost(x, y):
    if y == -1:
        return float('inf')
    return D * abs(x - y) + A[x] + A[y]
N, D = inpl()
A = inpl()
minx = A.index(min(A))
Right = [(v - i*D, i) for i, v in enumerate(A)]
Left = [(v + i*D, i) for i, v in enumerate(A)][::-1]
Right = list(itertools.accumulate(Right[minx:], min))
Left = list(itertools.accumulate(Left[N - 1 - minx:], min))
hub = [-1]
for _, i in itertools.chain(Left[::-1],Right):
    if hub[-1] != i:
        hub.append(i)
hub.append(-1)
ctr = 1
ans = sum([cost(i, j) for i, j in zip(hub[1:-1], hub[2:-1])])
for i in range(N):
    if hub[ctr] == i:
        ctr += 1
    else:
        ans += min(cost(i, hub[ctr-1]), cost(i, hub[ctr]))
print(ans)