class Segmenttree_min():
    def __init__(self, number):
        n = 1
        inf = (1 << 31) - 1
        while n < number:
            n *= 2
        self.n = n
        self.list = [inf] * (2 * n - 1)

    def add(self, i, x):  # 0indexed ith add x
        i += self.n - 1
        self.list[i] = x
        while i > 0:
            i = (i - 1) // 2
            self.list[i] = min(self.list[2 * i + 1], self.list[2 * i + 2])

    def search(self, a, b, k, l, r):  # call as search(a,b,0,0,self.n) minimun in [a,b)
        if r <= a or b <= l:
            return (1 << 31) - 1
        elif a <= l and r <= b:
            return self.list[k]
        else:
            vl = self.search(a, b, 2 * k + 1, l, (l + r) // 2)
            vr = self.search(a, b, 2 * k + 2, (l + r) // 2, r)
            return min(vl, vr)


class Unionfindtree:
    def __init__(self, number):
        self.par = [i for i in range(number)]
        self.rank = [0] * (number)

    def find(self, x):  # 親を探す
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):  # x,yを繋げる
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.rank[px] < self.rank[py]:
            self.par[px] = py
        else:
            self.par[py] = px
        if self.rank[px] == self.rank[py]:
            self.rank[px] += 1

    def connect(self, x, y):  # 親が同じかみる
        return self.find(x) == self.find(y)



N,D=map(int,input().split())
A=[int(i) for i in input().split()]
lefttree = Segmenttree_min(N)
dd={}
table=[]
for i in range(N):
    lefttree.add(i,A[i]+(N-1-i)*D)
    dd[A[i]+(N-1-i)*D]=i
    if i>0:
        s=lefttree.search(0,i,0,0,lefttree.n)
        y=dd[s]
        table.append((A[i]+A[y]+D*abs(i-y),i,y))
righttree = Segmenttree_min(N)
dr={}
for i in range(N-1,-1,-1):
    righttree.add(i,A[i]+i*D)
    dr[A[i]+i*D]=i
    if i<N-1:
        s=righttree.search(i+1,N,0,0,lefttree.n)
        y=dr[s]
        table.append((A[i]+A[y]+D*abs(i-y),i,y))
#print(table)
#print(dr)
table.sort()
uniontrees=Unionfindtree(N)
ans=0
for cost,s,t in table:
    if not uniontrees.connect(s,t):
        ans+=cost
        uniontrees.union(s,t)
print(ans)

