NM = raw_input().split()
NM = [int(x) for x in NM]
N = NM[0]
D = NM[1]
a_list = raw_input().split()
a_list = [int(x) for x in a_list]
place_attended = [0]
place_not_attended = range(1, N)
sum_cost = 0
while len(place_attended) < N:
    min_idx = -1
    min_cost = -1
    for i in place_attended:
        for j in place_not_attended:
            cur_cost = abs(i-j) * D + a_list[i] + a_list[j]
            if min_cost < 0 or cur_cost < min_cost:
                min_cost = cur_cost
                min_idx = j
    sum_cost += min_cost
    place_attended.append(min_idx)
    place_not_attended.remove(min_idx)
print sum_cost