# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class SegmentTree():
    # to par: (n-1) // 2
    # to chr: 2n+1, 2n+2
    def __init__(self, N):
        self.__N = 2**int(math.ceil(math.log(N, 2)))
        self.__table = [(sys.maxsize, -1)] * (self.__N * 2 - 1)

    def update(self, idx, x):
        i = self.__N - 1 + idx  # target leaf
        self.__table[i] = x
        while i != 0:
            pi = (i - 1) // 2  # parent
            if self.__table[i][0] < self.__table[pi][0]:
                self.__table[pi] = self.__table[i]
            else:
                break
            i = pi

    def __query(self, a, b, k, l, r):
        ans = sys.maxsize
        if r <= a or b <= l:
            return (sys.maxsize, -1)
        if a <= l and r <= b:
            return self.__table[k]

        vl = self.__query(a, b, 2 * k + 1, l, (l + r) // 2)
        vr = self.__query(a, b, 2 * k + 2, (l + r) // 2, r)

        return min(vl, vr, key=lambda x: x[0])

    def query(self, a, b):
        return self.__query(a, b, 0, 0, self.__N)

    def print(self):
        print(self.__table)

def Prim(g):
    V = list(g.keys())
    for v in g.values():
        V.extend(list(v.keys()))
    V = list(set(V))

    used = set([])
    q = []
    heapq.heappush(q, (0, V[0]))

    ret = 0
    while q:
        c, v = heapq.heappop(q)

        if v in used:
            continue
        used.add(v)
        ret += c
        for u in g[v]:
            heapq.heappush(q, (g[v][u], u))
    return ret

@mt
def slv(N, D, A):
    ans = 0
    AA = [(a, i) for i, a in enumerate(A)]
    AA.sort()

    st_l = SegmentTree(N)
    st_r = SegmentTree(N)
    g = defaultdict(dict)
    for a, i in AA:
        
        l = st_l.query(0, i)
        r = st_r.query(i, N)
        if l[1] != -1:
            j = l[1]
            g[i][j] = D*(abs(i-j))+A[i]+A[j]
            g[j][i] = g[i][j]
        if r[1] != -1:
            j = r[1]
            g[i][j] = D*(abs(i-j))+A[i]+A[j]
            g[j][i] = g[i][j]
        st_r.update(i, (D*i+a,i))
        st_l.update(i, (D*(N-i)+a,i))


    return Prim(g)


def main():
    N, D = read_int_n()
    A = read_int_n()

    print(slv(N, D, A))


if __name__ == '__main__':
    main()
