#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
struct UF {
  vector<long long> par;
  vector<long long> sz;
  UF() {}
  UF(long long n) {
    par.resize(n);
    sz.resize(n, 1);
    for (long long i = 0; i < n; i++) par[i] = i;
  }
  long long find(long long x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);
  }
  void unite(long long x, long long y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sz[x] < sz[y]) swap(x, y);
    sz[x] += sz[y];
    par[y] = x;
  }
  bool same(long long x, long long y) { return find(x) == find(y); }
};
struct edge {
  long long u, v, cost;
  bool operator<(const edge &e) const { return cost < e.cost; }
};
long long n, d;
vector<edge> es;
long long kruskal() {
  long long res = 0;
  UF uf(n);
  sort(es.begin(), es.end());
  for (long long i = 0; i < es.size(); i++) {
    edge e = es[i];
    if (!uf.same(e.u, e.v)) {
      uf.unite(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}
signed main() {
  cin >> n >> d;
  vector<long long> a(n);
  vector<pair<long long, long long> > l(n), r(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) {
    long long tmp = i * d - a[i];
    if (i == 0 || l[i - 1].first <= tmp) {
      l[i] = {tmp, i};
    } else {
      l[i] = l[i - 1];
    }
  }
  for (long long i = n - 1; i >= 0; i--) {
    long long tmp = i * d + a[i];
    if (i == n - 1 || r[i + 1].first >= tmp) {
      r[i] = {tmp, i};
    } else {
      r[i] = r[i + 1];
    }
  }
  for (long long i = 0; i < n; i++) {
    if (i) {
      es.push_back({i, l[i - 1].second, i * d + a[i] - l[i - 1].first});
    }
    if (i != n - 1) {
      es.push_back({i, r[i + 1].second, r[i + 1].first - (i * d - a[i])});
    }
  }
  cout << kruskal() << endl;
}
