def kruskal(v_count: int, edges: list) -> int:
    """
    :param v_count: 頂点数
    :param edges: [(weight, from, to), ... ]
    """
    from itertools import islice
    tree = [-1]*v_count

    def get_root(x) -> int:
        if tree[x] < 0:
            return x
        tree[x] = get_root(tree[x])
        return tree[x]

    def unite(a) -> bool:
        x, y = get_root(a[1]), get_root(a[2])
        if x != y:
            big, small = (x, y) if tree[x] < tree[y] else (y, x)
            tree[big] += tree[small]
            tree[small] = big
        return x != y

    cost = 0
    for w, _s, _t in islice(filter(unite, sorted(edges)), v_count-1):
        cost += w
    return cost

import sys
from operator import itemgetter

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