def main():
    import sys
    input = sys.stdin.readline

    class UnionFind():
        def __init__(self, n):
            self.n = n
            self.root = [-1] * (n + 1)
            self.rnk = [0] * (n + 1)

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

        def unite(self, x, y):
            x = self.find_root(x)
            y = self.find_root(y)
            if x == y:
                return
            elif self.rnk[x] > self.rnk[y]:
                self.root[x] += self.root[y]
                self.root[y] = x
            else:
                self.root[y] += self.root[x]
                self.root[x] = y
                if self.rnk[x] == self.rnk[y]:
                    self.rnk[y] += 1

        def isSameGroup(self, x, y):
            return self.find_root(x) == self.find_root(y)

        def size(self, x):
            return -self.root[self.find_root(x)]

    N, D = map(int, input().split())
    A = list(map(int, input().split()))

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

    edge = []
    m = float('inf')
    m_idx = 0
    for i in range(N-1):
        if A_minus[i] < m:
            m = A_minus[i]
            m_idx = i
        edge.append((m_idx+1, i+2, A_plus[i+1] + A_minus[m_idx]))
    m = float('inf')
    m_idx = 0
    for i in range(N-1, 0, -1):
        if A_plus[i] < m:
            m = A_plus[i]
            m_idx = i
        edge.append((m_idx+1, i, A_plus[m_idx] + A_minus[i-1]))

    edge.sort(key=lambda x: x[2])
    UF = UnionFind(N+1)
    ans = 0
    for u, v, cost in edge:
        if UF.isSameGroup(u, v):
            continue
        ans += cost
        UF.unite(u, v)
    print(ans)


if __name__ == '__main__':
    main()
