#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

const ll INF = 1ll << 60;

template <class I>
class SegmentTree {
 public:
  using Op = function<I(const I&, const I&)>;

 private:
  int n;
  vector<I> dat;
  Op op;
  I e;

 public:
  SegmentTree(int n_, const Op& op, const I& e)
      : op(op), e(e) {
    n = 1;
    while (n < n_) n *= 2;
    dat.resize(2 * n - 1, e);
  }
  SegmentTree(const vector<I>& init, const Op& op, const I& e)
      : SegmentTree(init.size(), op, e) {
    for (int i = 0; i < init.size(); i++) {
      dat[i + n - 1] = init[i];
    }
    for (int i = n - 2; i >= 0; i--) {
      dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);
    }
  }
  const I& operator[](int k) const {
    return dat[k + n - 1];
  }
  void update(int k, const I& a) {
    k += n - 1;
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = op(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  // [a, b)
  I query(int a, int b) const {
    a += n - 1;
    b += n - 1;
    I vl = e;
    I vr = e;
    while (a < b) {
      if ((a & 1) == 0) vl = op(vl, dat[a]);
      if ((b & 1) == 0) vr = op(dat[b - 1], vr);
      a = a / 2;
      b = (b - 1) / 2;
    }
    return op(vl, vr);
  }
  // query(0, i) >= x となる最小のi
  int kth(const I& x) const {
    int k = 0;
    I v = e;
    while (k < n - 1) {
      I t = op(v, dat[k * 2 + 1]);
      if (x <= t) {
        k = k * 2 + 1;
      } else {
        v = t;
        k = k * 2 + 2;
      }
    }
    return k - (n - 1) + 1;
  }
};

struct UnionFind {
  vector<int> parent;  // parent[root] is the negative of the size.
  UnionFind(int n)
      : parent(n, -1){};
  bool unite(int u, int v) {
    u = root(u);
    v = root(v);
    if (u == v) return false;
    if (parent[u] > parent[v]) swap(u, v);
    parent[u] += parent[v];
    parent[v] = u;
    return true;
  }
  bool find(int u, int v) {
    return root(u) == root(v);
  }
  int root(int u) {
    return parent[u] < 0 ? u : parent[u] = root(parent[u]);
  }
  int size(int u) {
    return -parent[root(u)];
  }
};

struct Edge {
  int x, y;
  ll w;
};

using P = pair<ll, int>;

auto op = [](const P& a, const P& b) {
  return min(a, b);
};

int main() {
  int N;
  ll D;
  while (cin >> N >> D) {
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    SegmentTree<P> segL(N, op, P(INF, -1));
    SegmentTree<P> segR(N, op, P(INF, -1));
    for (int i = 0; i < N; i++) {
      segL.update(i, P(-i * D + A[i], i));
      segR.update(i, P(+i * D + A[i], i));
    }
    UnionFind uf(N);
    int components = N;
    ll res = 0;
    while (components >= 2) {
      vec<int, 2> groups(N);
      for (int i = 0; i < N; i++)
        groups[uf.root(i)].push_back(i);
      vector<Edge> edges;
      for (int r = 0; r < N; r++) {
        if (groups[r].empty())
          continue;
        for (int i : groups[r]) {
          segL.update(i, P(INF, -1));
          segR.update(i, P(INF, -1));
        }
        Edge e = {-1, -1, INF};
        for (int i : groups[r]) {
          P p(INF, -1);
          if (i > 0) {
            auto q = segL.query(0, i);
            if (q.snd >= 0)
              p = min(p, P(q.fst + i * D + A[i], q.snd));
          }
          if (i < N - 1) {
            auto q = segR.query(i + 1, N);
            if (q.snd >= 0)
              p = min(p, P(q.fst - i * D + A[i], q.snd));
          }
          if (p.fst < e.w) {
            e.w = p.fst;
            e.x = i;
            e.y = p.snd;
          }
        }
        edges.push_back(e);
        for (int i : groups[r]) {
          segL.update(i, P(-i * D + A[i], i));
          segR.update(i, P(+i * D + A[i], i));
        }
      }
      for (auto& e : edges) {
        if (uf.unite(e.x, e.y)) {
          res += e.w;
          --components;
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 36212