#include <bits/stdc++.h>
using namespace std;
int root(vector<int> &parent, int n) {
  if (parent[n] == n) return n;
  return parent[n] = root(parent, parent[n]);
}
int main(void) {
  int N;
  long long D;
  cin >> N >> D;
  vector<long long> A(N), Ab(N), Af(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    Af[i] = A[i] - D * i;
    Ab[i] = A[i] + D * i;
  }
  long long ans = 0;
  vector<int> parent(N);
  for (int i = 0; i < N; i++) {
    parent[i] = i;
  }
  for (int i = 0; i < N - 1; i++) {
    long long m = 1E+12;
    int ma = 0, mb = N - 1;
    for (int a = 0; a < N - 1; a++) {
      for (int b = a + 1; b < N; b++) {
        if (parent[a] != parent[b] && Af[a] + Ab[b] < m) {
          m = Af[a] + Ab[b];
          ma = a;
          mb = b;
        }
      }
    }
    parent[ma] = mb;
    ans += m;
  }
  cout << ans << endl;
  return 0;
}
