#include <bits/stdc++.h>
using namespace std;
int N;
signed long long D;
signed long long A[202020];
signed long long mi[202020];
int id[202020];
template <int um>
class UF {
 public:
  vector<int> par, rank, cnt;
  UF() {
    par = rank = vector<int>(um, 0);
    cnt = vector<int>(um, 1);
    for (int i = 0; i < um; i++) par[i] = i;
  }
  void reinit() {
    int i;
    for (i = 0; i < (um); i++) rank[i] = 0, cnt[i] = 1, par[i] = i;
  }
  int operator[](int x) {
    return (par[x] == x) ? (x) : (par[x] = operator[](par[x]));
  }
  int count(int x) { return cnt[operator[](x)]; }
  int operator()(int x, int y) {
    if ((x = operator[](x)) == (y = operator[](y))) return x;
    cnt[y] = cnt[x] = cnt[x] + cnt[y];
    if (rank[x] > rank[y]) return par[x] = y;
    rank[x] += rank[x] == rank[y];
    return par[y] = x;
  }
};
UF<500000> uf;
set<pair<int, int>> S;
int L[202020], R[202020];
signed long long LT[202020], RT[202020], V[202020];
int le[202020], ri[202020];
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N >> D;
  for (i = 0; i < (N); i++) {
    cin >> A[i + 1];
    L[i + 1] = R[i + 1] = i + 1;
    LT[i + 1] = i * D + A[i + 1];
    RT[i + 1] = i * D - A[i + 1];
  }
  LT[0] = LT[N + 1] = 1LL << 60;
  RT[0] = RT[N + 1] = -1LL << 60;
  for (i = 0; i < (N + 2); i++) le[i] = i - 1, ri[i] = i + 1;
  set<pair<signed long long, int>> S;
  for (i = 0; i < (N + 1); i++) {
    V[i] = LT[i + 1] - RT[i];
    S.insert({V[i], i});
  }
  signed long long ret = 0;
  while (S.size() > 2) {
    x = S.begin()->second;
    y = ri[x];
    ret += S.begin()->first;
    S.erase(S.begin());
    S.erase({V[y], y});
    int xx = le[x];
    int yy = ri[y];
    S.erase({V[xx], xx});
    LT[x] = min(LT[x], LT[y]);
    RT[x] = max(RT[x], RT[y]);
    ri[x] = ri[y];
    le[ri[y]] = x;
    V[xx] = LT[x] - RT[xx];
    S.insert({V[xx], xx});
    V[x] = LT[ri[x]] - RT[x];
    S.insert({V[x], x});
  }
  cout << ret << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}
