import sys
input = sys.stdin.readline

N,D=map(int,input().split())
A=list(map(int,input().split()))

#cost=abs(i-j)*D+A[i]+A[j]

SUMDA=[D*i-A[-i] for i in range(1,N+1)]
SUMDA.reverse()


MIN=SUMDA[-1]
MININD=[None]*N
MININD[N-1]=N-1
for i in range(N-2,-1,-1):
    if SUMDA[i]<MIN:
        MIN=SUMDA[i]
        MININD[i]=i
    else:
        MININD[i]=MININD[i+1]

SUMA=sum(A)
ANS=float("inf")
for i in range(N-2):
    cost=0
    k=MININD[i+1]

    cost=D*(N-1)+D*(N-1-abs(k-i))+SUMA*2-A[i]-A[k]
    #print(cost)

    if ANS>cost:
        ANS=cost

print(ANS)
    
    
    
