from itertools import accumulate


class UnionFind:
    def __init__(self, n):
        self.table = [-1] * n

    def _root(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self._root(self.table[x])
            return self.table[x]

    def find(self, x, y):
        return self._root(x) == self._root(y)

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2


n, d = map(int, input().split())
aaa = list(map(int, input().split()))
costs_l = [(-i * d + a, i) for i, a in enumerate(aaa)]
costs_r = [(i * d + a, i) for i, a in enumerate(aaa)]

prev = (float('inf'),)
for i in range(n):
    prev = costs_l[i] = min(prev, costs_l[i])
prev = (float('inf'),)
for i in range(n - 1, -1, -1):
    prev = costs_r[i] = min(prev, costs_r[i])

edges = set()
for i, a in enumerate(aaa):
    di = i * d

    if i > 0:
        base_cost, j = costs_l[i - 1]
        edges.add((base_cost + di + a, j, i))
    if i < n - 1:
        base_cost, j = costs_r[i + 1]
        edges.add((base_cost - di + a, i, j))

uft = UnionFind(n)
ans = 0
for c, i, j in sorted(edges):
    if uft.find(i, j):
        continue
    ans += c
    uft.union(i, j)

print(ans)
