readline = open(0).readline
write = open(1, 'w').write

N, D = map(int, readline().split())
*A, = map(int, readline().split())

N0 = 2**(N-1).bit_length()
INF = (10**18, -1)
ldata = [INF]*(2*N0+1)
rdata = [INF]*(2*N0+1)

P = []; Q = []
for x in range(N0+1):
    y = N0 + x
    z = (y // (y & -y)) >> 1
    P.append(2*z-1 if z else 0)
    z = (y // (y & -y))
    Q.append(z-1)
Q.reverse()

def update(data, k, x):
    k += N0-1
    data[k] = x
    while k:
        k = (k - 1) >> 1
        data[k] = min(data[2*k+1], data[2*k+2])

# lquery: query [0, r)
def lquery(r):
    yield -1
    while r:
        yield P[r]
        r -= r & -r

# rquery: query [l, N0)
def rquery(l):
    yield -1
    r = N0 - l
    while r:
        yield Q[r]
        r -= r & -r


*I, = range(N)
I.sort(key=A.__getitem__)

lget = ldata.__getitem__
rget = rdata.__getitem__
E = []
for i in I:
    c, k = min(map(lget, lquery(i)))
    if k != -1:
        c -= (N-1-i)*D
        E.append((c + A[i], k, i))
    c, k = min(map(rget, rquery(i+1)))
    if k != -1:
        c -= i*D
        E.append((c + A[i], i, k))
    update(ldata, i, ((N-1-i)*D + A[i], i))
    update(rdata, i, (i*D + A[i], i))

*p, = range(N)
def root(x):
    if x == p[x]:
        return x
    p[x] = y = root(p[x])
    return y
def unite(x, y):
    px = root(x); py = root(y)
    if px == py:
        return 0
    if px < py:
        p[py] = px
    else:
        p[px] = py
    return 1


E.sort()
ans = 0
for c, i, j in E:
    if unite(i, j):
        ans += c
write("%d\n" % ans)