N,D=input().split()
N=int(N)
D=int(D)
A=[int(x) for x in input().split()]
final_list=[x+1 for x in range(N)]
final_cost_list=[0]*N


def Check(to,i):
  to=final_list[to]
  if to==i:
    return False
  if to>i:
    return to
  else:
    return Check(to,i)

for i in range(N-1):
  cost_list=[]
  for j in range(N):
    if j==i:
      print('con',j)
      continue
    cost_list.append(abs(i-j)*D+A[i]+A[j])

  large=max(cost_list)+1
  while True:
    min_cost=min(cost_list)
    to=cost_list.index(min_cost)
    if to>=i:
      final_list[i]=to
      final_cost_list[i]=min_cost
      break
    r=Check(to,i)
    if(r):
      final_list[i]=to
      final_cost_list[i]=min_cost
      break
    cost_list[to]=large
  print(final_list)
  
print(sum(final_cost_list))
