#include <bits/stdc++.h>
#define inf (long long)(1e16)
using namespace std;

struct Unionfind {
  // tree number
  vector<int> par;
  // constructor
  Unionfind(int n = 1) : par(n, -1) {}
  // search root
  int root(int x) {
    if (par[x] < 0) return x;
    return par[x] = root(par[x]);
  }
  // is same?
  bool issame(int x, int y) { return root(x) == root(y); }

  // add
  // already added, return 0
  bool uni(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return 0;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return 1;
  }
  int size(int x) { return -par[root(x)]; }
};

struct dat {
  long long cost, x, y;
  bool operator<(const dat &r) const { return cost > r.cost; }
};

// 0-indexed
template <class T>
struct SegmentTree {
  // a,b,c: T, e:T(unit)
  // abc = (ab)c = a(bc)
  // ae = ea = a
  typedef function<T(T, T)> F;
  int n;
  F f;
  T unit;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(int newn, F f, T t) : f(f), unit(t) { init(newn); }
  SegmentTree(const vector<T> &v, F f, T t) : f(f), unit(t) {
    int _n = v.size();
    init(v.size());
    for (int i = 0; i < _n; ++i) dat[n + i] = v[i];
    for (int i = n - 1; i; --i) dat[i] = f(dat[i << 1], dat[(i << 1) | 1]);
  }
  void init(int newn) {
    n = 1;
    while (n < newn) n <<= 1;
    dat.assign(n << 1, unit);
  }

  // "go up" process
  void update(int k, T newdata) {
    dat[k += n] = newdata;
    while (k >>= 1) {
      dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
    }
  }
  // [a,b)
  T query(int a, int b) {
    T vl = unit, vr = unit;
    for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) vl = f(vl, dat[l++]);
      if (r & 1) vr = f(dat[--r], vr);
    }
    return f(vl, vr);
  }
};

long long n, d;
vector<long long> a, id;
priority_queue<dat> pq;
SegmentTree<int> seg[4];

long long solve();

int main() {
  cin >> n >> d;
  a.resize(n);
  for (auto &p : a) cin >> p;
  for (int i = 0; i < n; ++i) id.push_back(i);
  sort(id.begin(), id.end(),
       [](long long l, long long r) { return a[l] < a[r]; });
  cout << solve() << endl;
  return 0;
}

long long solve() {
  {
    auto f = [](int l, int r) {
      if (l < 0) return r;
      if (r < 0 || -l * d + a[l] < -r * d + a[r]) return l;
      return r;
    };
    auto f2 = [](int l, int r) {
      if (l < 0) return r;
      if (r < 0 || l * d + a[l] < r * d + a[r]) return l;
      return r;
    };
    seg[0] = seg[1] = SegmentTree<int>(n, f, -1);
    seg[2] = seg[3] = SegmentTree<int>(n, f2, -1);
  }
  for (int i = 0; i < n; ++i) seg[1].update(i, i);
  for (int i = 0; i < n; ++i) seg[3].update(i, i);
  for (int i = 0; i < n; ++i) {
    int x = id[i];
    for (int j = 0; j < 2; ++j) {
      int y = seg[j].query(0, x);
      if (y >= 0) pq.push({(x - y) * d + a[x] + a[y], x, y});
      y = seg[j + 2].query(x + 1, n);
      if (y >= 0) pq.push({(y - x) * d + a[x] + a[y], y, x});
    }
    seg[1].update(x, -1);
    seg[0].update(x, x);
    seg[3].update(x, -1);
    seg[2].update(x, x);
  }
  long long res = 0;
  Unionfind uf(n);
  while (pq.size()) {
    dat now = pq.top();
    pq.pop();
    if (!uf.issame(now.x, now.y)) {
      res += now.cost;
      uf.uni(now.x, now.y);
    }
  }
  return res;
}

Measured memory_bytes: 40648