class SegmentTree:
    def __init__(self, n):
        k = 1
        while k < n:
            k *= 2
        self.N = k
        self.node = [(float("inf"), 0)] * (int(2 * self.N - 1))

    def update(self, i, x):
        i += self.N - 1
        self.node[i] = x
        while i > 0:
            i = (i - 1) // 2
            self.node[i] = min(self.node[2 * i + 1], self.node[2 * i + 2])

    def _find(self, a, b, i, l, r):
        if r <= a or b <= l:
            return float("inf"), 0
        elif a <= l and r <= b:
            return self.node[i]

        else:
            mid = (l + r) // 2
            return min(self._find(a, b, 2 * i + 1, l, mid), self._find(a, b, 2 * i + 2, mid, r))

    def find(self, a, b):
        return self._find(a, b + 1, 0, 0, self.N)


N, D = map(int, input().split())
A = list(map(int, input().split()))
parent = [i for i in range(N)]
rank = [0] * N


def find(i):
    if parent[i] == i:
        return i
    else:
        parent[i] = find(parent[i])
        return parent[i]


def same(x, y):
    return find(x) == find(y)


def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return

    if rank[x] > rank[y]:
        parent[y] = x
    else:
        parent[x] = y
        if rank[x] == rank[y]:
            rank[y] += 1


INF = float('inf')
R = [i for i in range(N)]
R = sorted(R, key=lambda x: A[x])
B = [0] * N
C = [0] * N
for i in range(N):
    B[i] = A[i] + D * i

for i in range(N):
    C[i] = A[i] + D * (N - i)

stL = SegmentTree(N)
stR = SegmentTree(N)
E = []
for i in R:
    p = stL.find(0, i)
    if p[0] != INF:
        cost = p[0] + A[i] - (N - i) * D
        E.append((cost, i, p[1]))
    p = stR.find(i, N - 1)
    if p[0] != INF:
        cost = p[0] + A[i] - i * D
        E.append((cost, i, p[1]))

    stL.update(i, (A[i] + (N - i) * D, i))
    stR.update(i, (A[i] + i * D, i))

E = sorted(E)
ans = 0
for e in E:
    if not same(e[1], e[2]):
        unite(e[1], e[2])
        ans += e[0]

print(ans)