import sys
input = sys.stdin.readline

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)

class BIT():
    def __init__(self, number):
        self.n = number
        self.list = [10**22] * (number + 1)

    def add(self, i, x):  # ith added x  1indexed
        while i <= self.n:
            self.list[i] = min(x,self.list[i])
            i += i & -i

    def search(self, i):  # 1-i min
        s = 10**22
        while i > 0:
            s = min(s,self.list[i])
            i -= i & -i
        return s


N,D=map(int,input().split())
A=[int(i) for i in input().split()]
lefttree = BIT(N)
dd={}
table=[]
for i in range(N):
    lefttree.add(i+1,A[i]+(N-1-i)*D)
    dd[A[i]+(N-1-i)*D]=i
    if i>0:
        s=lefttree.search(i)
        y=dd[s]
        table.append((A[i]+A[y]+D*abs(i-y),i,y))
#print(table)
righttree = BIT(N)
dr={}
for i in range(N-1,-1,-1):
    righttree.add(N-i,A[i]+i*D)
    dr[A[i]+i*D]=i
    if i<N-1:
        s=righttree.search(N-1-i)
        #print(i, dr,s)
        y=dr[s]
        table.append((A[i]+A[y]+D*abs(i-y),i,y))
#print(table)

#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)


