#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
//#include <functional>
#include <queue>
//#include <stack>
//#include <set>
#include <cmath>
//#include <bitset>
#include <map>
using namespace std;
typedef long long ll;
const int MAX_V = 2*(1e5);
int cost[MAX_V][MAX_V];
int mincost[MAX_V];
bool used[MAX_V];

int main() {
  int N,D;
  cin >> N >> D;
  int A[N];
  for(int i=0; i< N; i++){
    cin >> A[i];
  }
  for(int i=0; i< N; i++){
    mincost[i] = INT_MAX;
    used[i] = false;
  }

  mincost[0] = 0;
  int res=0;

  for(int u = 0; u < N; u++){
    for(int v = 0; v < N; v++){
      if(u==v){
	cost[v][u]=INT_MAX;
      }
      else{
	cost[v][u] = abs(u-v)*D + A[u] + A[v];
      }
    }
  }


  while(true){
    int v = -1;
    for(int u = 0; u < N; u++){
      if(!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u;
    }

    if(v == -1) break;
    used[v] = true;
      res += mincost[v];
    for(int u=0; u < N; u++){
      mincost[u] = min(mincost[u], cost[v][u]);
    }
  }
  cout << res <<endl;
  return res;

}
