from collections import deque
import sys
#sys.setrecursionlimit(200000)
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]*2 for i in range(2*N0)]
data2 = [[INF]*2 for i in range(2*N0)]
def update(k, x,y):
    k += N0-1
    data[k] = [x,y]
    while k >= 0:
        k = (k - 1) // 2
        if data[2*k+1][0] > data[2*k+2][0]:
            data[k] =  data[2*k+2]
        else:
            data[k] =  data[2*k+1]
def query(l, r):
    L = l + N0; R = r + N0
    s = [INF,INF]
    while L < R:
        if R & 1:
            R -= 1
            if s[0] > data[R-1][0]:
                s = data[R-1]
 
        if L & 1:
            if s[0] > data[L-1][0]:
                s = data[L-1]
            L += 1
        L >>= 1; R >>= 1
    return s
def update2(k, x,y):
    k += N0-1
    data2[k] = [x,y]
    while k >= 0:
        k = (k - 1) // 2
        if data2[2*k+1][0] > data2[2*k+2][0]:
            data2[k] =  data2[2*k+2]
        else:
            data2[k] =  data2[2*k+1]
def query2(l, r):
    L = l + N0; R = r + N0
    s = [INF,INF]
    while L < R:
        if R & 1:
            R -= 1
            if s[0] > data2[R-1][0]:
                s = data2[R-1]
 
        if L & 1:
            if s[0] > data2[L-1][0]:
                s = data2[L-1]
            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])
    migi = query2(c[1],n)
    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]),c[1])
    update2(c[1],c[0]+d*c[1],c[1])    
kore.sort()
for i,j,k in kore:
    if kimeta.find(j) != kimeta.find(k):
        kimeta.union(j,k)
        ans += i
print(ans)