#include <bits/stdc++.h>
int main() {
  using namespace std;
  unsigned long N, D;
  cin >> N >> D;
  vector<unsigned long> A(N);
  for (auto&& i : A) cin >> i;
  vector<pair<unsigned long, pair<unsigned long, unsigned long>>> edges(N);
  unsigned long tmp{A[0] + N * D}, tmpi{0};
  for (unsigned long i{1}; i < N; ++i) {
    edges.emplace_back(tmp - (N - i) * D + A[i],
                       pair<unsigned long, unsigned long>(tmpi, i));
    if (tmp >= (N - i) * D + A[i]) {
      tmpi = i;
      tmp = (N - i) * D + A[i];
    }
  }
  tmp = A.back() + (N - 1) * D;
  tmpi = N - 1;
  for (unsigned long i{N - 1}; i--;) {
    edges.emplace_back(tmp - i * D + A[i],
                       pair<unsigned long, unsigned long>(tmpi, i));
    if (tmp >= i * D + A[i]) {
      tmpi = i;
      tmp = i * D + A[i];
    }
  }
  vector<unsigned long> uf(N), sz(N, 1);
  iota(begin(uf), end(uf), 0UL);
  const auto& find = [&uf](unsigned long i) -> unsigned long {
    while (i != uf[i]) i = uf[i] = uf[uf[i]];
    return i;
  };
  const auto& unite = [&uf, &sz, &find](unsigned long i,
                                        unsigned long j) -> bool {
    i = find(i);
    j = find(j);
    if (i == j) return false;
    if (sz[i] < sz[j]) swap(i, j);
    sz[i] += sz[j];
    uf[j] = i;
    return true;
  };
  sort(begin(edges), end(edges));
  unsigned long ans{0};
  for (const auto& i : edges)
    if (unite(i.second.first, i.second.second)) ans += i.first;
  cout << ans << endl;
  return 0;
}
