def abs(n):
    if n<0:
        return -n
    else:
        return n

n,d=list(map(int,input().split()))
a=list(map(int,input().split()))

cost=[[0 for i in range(n)] for j in range(n)]

for i in range(n):
    for j in range(n):
        if i!=j:
            cost[i][j]=abs(i-j)*d+a[i]+a[j]

edge=[]
for i in range(n):
    for j in range(n):
        edge.append((cost[i][j],i,j))
edge.sort()

class UnionFind():
    def __init__(self,n):
        self.par=[i for i in range(n)]
        self.rank=[0 for i in range(n)]
    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 unite(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return
        if self.rank[x]<self.rank[y]:
            self.par[x]=y
        else:
            self.par[y]=x
            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1
    def same(self,x,y):
        return self.find(x)==self.find(y)

t=UnionFind(n)
res=0
for e in edge:
    cost=e[0]
    v=e[1]
    u=e[2]

    if not t.same(v,u):
        #print(v,u,cost)
        #print('par['+str(v)+']=',t.find(v),'par['+str(u)+']=',t.find(u))
        t.unite(v,u)
        res+=cost

print(res)