class SegmentTree:

    def __init__(self, n, sentinel=0):
        n2 = 1 << (n - 1).bit_length()
        self.n = n2
        self.data = [sentinel] * ((n2 << 1) - 1)
        self.offset = n2 - 1

    def update(self, k, x):
        i = k + self.offset
        self.data[i] = x
        while i:
            p = (i - 1) // 2
            if self.data[p] > self.data[i]:
                self.data[p] = self.data[i]
            else:
                break
            i = p

    def get_left_min(self, k):
        i = k + self.offset - 1
        ret = self.data[i]
        while i:
            if i % 2 == 0:
                ret = min(ret, self.data[i - 1])
            i = (i - 1) // 2
        return ret

    def get_right_min(self, k):
        i = k + self.offset + 1
        ret = self.data[i]
        while i:
            if i % 2 == 1:
                ret = min(ret, self.data[i + 1])
            i = (i - 1) // 2
        return ret


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()))
seg_l = SegmentTree(n, (10 ** 10, -1))
seg_r = SegmentTree(n, (10 ** 10, -1))
bbb = sorted((a, i) for i, a in enumerate(aaa))
edges = set()

for a, i in bbb:
    cost_l = -i * d + a
    cost_r = i * d + a
    seg_l.update(i, (cost_l, i))
    seg_r.update(i, (cost_r, i))

    di = i * d
    if i > 0:
        base_cost, j = seg_l.get_left_min(i)
        if j > -1:
            edges.add((base_cost + di + a, j, i))
    if i < n - 1:
        base_cost, j = seg_r.get_right_min(i)
        if j > -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)
