#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def root(x):
        if par[x] == x:
            return x
        par[x] = root(par[x])
        return par[x]

    def unite(x,y):
        x = root(x)
        y = root(y)
        if rank[x] < rank[y]:
            par[x] = y
        else:
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1

    n,d = LI()
    a = LI()
    b = [a[i]+d*i for i in range(n)]
    mb = [[None]*2 for i in range(n)]
    mb[n-1][0] = b[n-1]
    mb[n-1][1] = n-1
    for i in range(n-1)[::-1]:
        if b[i] < mb[i+1][0]:
            mb[i][0] = b[i]
            mb[i][1] = i
        else:
            mb[i][0] = mb[i+1][0]
            mb[i][1] = mb[i+1][1]
    a = [a[i]-d*i for i in range(n)]
    ma = [[None]*2 for i in range(n)]
    ma[0][0] = a[0]
    ma[0][1] = 0
    for i in range(n-1):
        if a[i+1] < ma[i][0]:
            ma[i+1][0] = a[i+1]
            ma[i+1][1] = i+1
        else:
            ma[i+1][0] = ma[i][0]
            ma[i+1][1] = ma[i][1]
    par = [i for i in range(n)]
    rank = [0]*n
    q = []
    for i in range(n):
        if i < n-1:
            q.append((a[i]+mb[i+1][0],i,mb[i+1][1]))
        if i > 0:
            q.append((b[i]+ma[i-1][0],i,ma[i-1][1]))
    q.sort()
    ans = 0
    k = 0
    for nd,x,y in q:
        if root(x) != root(y):
            k += 1
            unite(x,y)
            ans += nd
            if k == n-1:
                break
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()
