import scala.collection.mutable.ListBuffer

object Main {
  def main(args: Array[String]): Unit = {
    println(func())
  }

  def func() : Long = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val d = sc.nextLong
    val cities = List.fill(n)(sc.nextLong).zipWithIndex

    var costs:ListBuffer[Long] = ListBuffer.empty

    cities.foreach{case(x,i) => {
      costs += cities.map{case (y,j) =>
        (i-j).abs*d+x+y
      }.min
    }}

    val max = costs.max

    costs.sum - max
  }
}