import sys
#sys.setrecursionlimit(200000)
def main():
    input = sys.stdin.readline
    #n = int(input())
    n,d = map(int,input().split())
    a = list(map(int,input().split()))
    ans = 0
    kore = []
    class UnionFind():
        def __init__(self,size):
            self.table = [-1 for _  in range(size)]
        def find(self,x):
            while self.table[x] >= 0:
                x = self.table[x]
            return x
    
        def union(self,x,y):
            s1 = self.find(x)
            s2 = self.find(y)
            if s1 != s2:
                if self.table[s1] != self.table[s2]:
                    if self.table[s1] < self.table[s2]:
                        self.table[s2] = s1
                    else:
                        self.table[s1] = s2
                else:
                    self.table[s1] += -1
                    self.table[s2] = s1
            return

    N0 = 2**(n).bit_length()
    INF = (2**31-1)
    data = [[INF]*4 for i in range(2*N0)]
    def update(k, x,y,z):
        k += N0-1
        data[k] = [x,z,y,z]
        while k >= 0:
            k = (k - 1) // 2
            if data[2*k+1][0] > data[2*k+2][0]:
                data[k][:2] =  data[2*k+2][:2]
            else:
                data[k][:2] =  data[2*k+1][:2]
            if data[2*k+1][2] > data[2*k+2][2]:
                data[k][2:] =  data[2*k+2][2:]
            else:
                data[k][2:] =  data[2*k+1][2:]
    def query(l, r,z):
        L = l + N0; R = r + N0
        s = [INF,INF]
        while L < R:
            if R & 1:
                R -= 1
                if s[0] > data[R-1][z*2]:
                    s = data[R-1][z*2:z*2+2]
    
            if L & 1:
                if s[0] > data[L-1][z*2]:
                    s = data[L-1][z*2:z*2+2]
                L += 1
            L >>= 1; R >>= 1
        return s
    b = []
    for i in range(n):
        b.append([a[i],i])
    b.sort()
    kimeta = UnionFind(n)
    for i in range(n):
        c = b[i]
        hidari = query(0,c[1],0)
        migi = query(c[1],n,1)
        if hidari[1] != INF:
            kore.append([a[hidari[1]]+c[0]+d*abs(c[1]-hidari[1]),c[1],hidari[1]])
        if migi[1] != INF:
            kore.append([a[migi[1]]+c[0]+d*abs(migi[1]-c[1]),c[1],migi[1]])
        update(c[1],c[0]+d*(n-c[1]),d*c[1]+c[0],c[1])  
    kore.sort()
    bpoint = 0
    for i,j,k in kore:
        if kimeta.find(j) != kimeta.find(k):
            kimeta.union(j,k)
            ans += i
            bpoint += 1
        if bpoint >= n-1:
            break
    print(ans)
if __name__ == '__main__':
    main()