<?php
fscanf(STDIN,"%d %d",$N,$D);
$line = trim(fgets(STDIN));$A = explode(" ", $line);

$MEMO=array();
for ($i=0;$i<$N;$i++) $MEMO[$i]=-1;
$MEMO[1]=0;

for ($n=2;$n<=$N;$n++)
{
 $C=array();
 $total=0;
 for ($i=1;$i<$n;$i++){
  $C[$i]=abs($i-($n))*$D+$A[$i-1]+$A[$n-1];
  $total+=$C[$i];
 }
 
//  var_dump($C);
//$MEMO[$n]=$min_cost=min(min($C)+min_cost($n-1),$total);
$MEMO[$n]=$min_cost=min(min($C)+$MEMO[$n-1],$total);
}



echo $min_cost;
//var_dump($MEMO);
