#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


struct MinMonoid {
  using T = pair<lint, int>;
  static T op(const T& lhs, const T& rhs) { return min(lhs, rhs); }
  static constexpr T e() { return {9e18, -1}; }
};

template<class Monoid> struct SegmentTree {
  using M = Monoid;
  using T = typename M::T;

  const int n;

  SegmentTree(int n, const T& a = M::e()) : n(n), val(2 * n, a) {
    build();
  }

  template<class Itr> SegmentTree(Itr first, Itr last) :
    n(distance(first, last)), val(2 * n, M::e()) {
    copy(first, last, next(begin(val), n));
    build();
  }

  T& operator[](int i) {
    assert(0 <= i and i < n);
    return val[i + n];
  }

  void build() {
    for (int i = n - 1; i > 0; --i) {
      val[i] = M::op(val[2 * i], val[2 * i + 1]);
    }
  }

  T get(int l, int r) const {
    l = max(l, 0), r = min(r, n);
    T resl = M::e(), resr = M::e();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) resl = M::op(resl, val[l++]);
      if (r & 1) resr = M::op(val[--r], resr);
    }
    return M::op(resl, resr);
  }

  void set(int i, const T& a) {
    assert(0 <= i and i < n);
    for (val[i += n] = a, i >>= 1; i > 0; i >>= 1) {
      val[i] = M::op(val[2 * i], val[2 * i + 1]);
    }
  }

private:
  V<T> val;
};

using ST = SegmentTree<MinMonoid>;

struct UnionFind {
  const int n;

  UnionFind(int n) : n(n), dat(n, -1) {}

  bool same(int u, int v) {
    assert(0 <= u and u < n);
    assert(0 <= v and v < n);
    return find(u) == find(v);
  }

  int size(int v) {
    assert(0 <= v and v < n);
    return -dat[find(v)];
  }

  void unite(int u, int v) {
    assert(0 <= u and u < n);
    assert(0 <= v and v < n);
    if ((u = find(u)) == (v = find(v))) return;
    if (-dat[u] < -dat[v]) {
      dat[v] += dat[u];
      dat[u] = v;
    } else {
      dat[u] += dat[v];
      dat[v] = u;
    }
  }

private:
  V<> dat; // dat[v] := vは根 ? -size : parent

  int find(int v) {
    return dat[v] < 0 ? v : dat[v] = find(dat[v]);
  }
};

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, d; cin >> n >> d;
  V<> a(n); for (int i = 0; i < n; ++i) cin >> a[i];
  ST l(n), r(n);
  for (int i = 0; i < n; ++i) {
    l[i] = {a[i] - (lint) d * i, i};
    r[i] = {a[i] + (lint) d * i, i};
  }
  l.build(), r.build();
  V<> id(n);
  iota(begin(id), end(id), 0);
  sort(begin(id), end(id), [&](int i, int j) { return a[i] > a[j]; });
  V< pair<int, int> > es;
  for (int i : id) {
    if (i != 0) {
      es.emplace_back(l.get(0, i).second, i);
    }
    if (i != n - 1) {
      es.emplace_back(i, r.get(i + 1, n).second);
    }
    l.set(i, {1e18, i});
    r.set(i, {1e18, i});
  }
  auto w = [&](const auto& e) { return a[e.first] + a[e.second] + (lint) d * (e.second - e.first); };
  sort(begin(es), end(es), [&](const auto& el, const auto& er) { return w(el) < w(er); });
  UnionFind uf(n);
  lint res = 0;
  for (const auto& e : es) {
    if (uf.same(e.first, e.second)) continue;
    uf.unite(e.first, e.second);
    res += w(e);
  }
  cout << res << '\n';
}

Measured memory_bytes: 20592