n,d = map(int, input().split())
aList = list(map(int, input().split()))
basePoint=sum(aList)*2+(n-1)*d
print(basePoint)

ansi=0
ansj=0
ansSaPoint=100000000000
for i in range(n):
    for j in range(i+1,n):

        sa=((i+1-1)+(n-(j+1)))*d-(aList[i]+aList[j])
        print(i,j,sa)
        if(sa<ansSaPoint):
            ansSaPoint=sa
            ansi=i
            ansj=j

ans=basePoint+ansSaPoint
print(ans)