#include <bits/stdc++.h>
using namespace std;
long long n, d;
vector<vector<long long>> mAdj;
vector<long long> va;
long long cost(int i, int j) {
  if (i == j) return -1;
  return abs(j - i) * d + va.at(i) + va.at(j);
}
void init() {
  cin >> n >> d;
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    va.push_back(a);
  }
  for (long long i = 0; i < n; i++) {
    vector<long long> vAdj;
    for (long long j = 0; j < n; j++) {
      vAdj.push_back(cost(i, j));
    }
    mAdj.push_back(vAdj);
  }
}
long long prim() {
  vector<long long> vMinE;
  long long minE, minV;
  minE = 1000000007;
  long long sumE = 0;
  long long s = 0;
  for (long long i = 0; i < n; i++) {
    vMinE.push_back(mAdj.at(s).at(i));
  }
  for (long long j = 1; j < n; j++) {
    minE = 1000000007;
    for (long long i = 0; i < n; i++) {
      if (vMinE.at(i) > 0 && vMinE.at(i) < minE) {
        minE = vMinE.at(i);
        minV = i;
      }
    }
    sumE += minE;
    s = minV;
    for (long long i = 0; i < n; i++) {
      vMinE.at(i) = min(vMinE.at(i), mAdj.at(s).at(i));
    }
  }
  return sumE;
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  init();
  cout << prim() << "\n";
  return 0;
}
