#include <bits/stdc++.h>
using namespace std;
using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;
const double eps = 1e-10;
template <typename A, typename B>
inline void chmin(A &a, B b) {
  if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b) {
  if (a < b) a = b;
}
class UnionFind {
 private:
  ::std::vector<int_fast32_t> par;
  size_t n;

 public:
  UnionFind() {}
  UnionFind(size_t n) : n(n) { par.resize(n, -1); }
  uint_fast32_t find(uint_fast32_t x) {
    return par[x] < 0 ? x : par[x] = find(par[x]);
  }
  size_t size(uint_fast32_t x) { return -par[find(x)]; }
  bool unite(uint_fast32_t x, uint_fast32_t y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (size(x) < size(y)) std::swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  bool same(uint_fast32_t x, uint_fast32_t y) { return find(x) == find(y); }
};
int64 N, D;
vector<int64> A, ed;
vector<PII> e;
UnionFind uf;
void dfs(int64 l, int64 r) {
  if (r - l == 1) return;
  int64 lmin = (int64)1e18, lidx = -1;
  int64 rmin = (int64)1e18, ridx = -1;
  int32 m = (l + r) / 2;
  for (int64 i = 0; i < (m); i++) {
    if (lmin > A[i] - i * D) {
      lmin = A[i] - i * D;
      lidx = i;
    }
  }
  for (int64 i = (m); i < (r); i++) {
    if (rmin > A[i] + i * D) {
      rmin = A[i] + i * D;
      ridx = i;
    }
  }
  for (int64 i = 0; i < (m); i++) {
    e.emplace_back(i, ridx);
    ed.emplace_back(rmin + (A[i] - i * D));
  }
  for (int64 i = (m); i < (r); i++) {
    e.emplace_back(lidx, i);
    ed.emplace_back(lmin + (A[i] + i * D));
  }
  dfs(l, m);
  dfs(m, r);
}
int main(void) {
  cin >> N >> D;
  A.resize(N);
  uf = UnionFind(N);
  for (int64 i = 0; i < (N); i++) cin >> A[i];
  dfs(0, N);
  vector<int64> ord(ed.size());
  iota(ord.begin(), ord.end(), 0);
  sort(ord.begin(), ord.end(), [&](int64 l, int64 r) { return ed[l] < ed[r]; });
  int64 res = 0;
  for (int64 i = 0; i < (e.size()); i++) {
    int64 idx = ord[i];
    if (uf.unite(e[idx].first, e[idx].second)) res += ed[idx];
  }
  cout << res << endl;
}
