import numpy as np
import sys

a = list(map(int, input().split()))
n, d = a[0], a[1]
A = np.array(list(map(int, input().split())))
map = np.array([abs(i//n - i%n) * d + A[i//n] + A[i%n] for i in range(n * n)])
order = map.argsort()
score = sorted(map)
city = []
ans = 0
idx = 0
while True:
    if len(city) == n:
        break
    i, j = order[idx] // n, order[idx] % n
    if i == j:
        idx += 1
        continue
    if i in city and j in city:
        idx += 1
        continue
    else:
        if i not in city:
            city.append(i)
        if j not in city:
            city.append(j)
        ans += score[idx]
        idx += 1
print(ans)
