#include <bits/stdc++.h>
using namespace std;
class DSU {
 public:
  int fa[200005];
  inline void init() {
    for (int i = 0; i < 200005; ++i) fa[i] = i;
  }
  inline int f(int x) { return fa[x] == x ? x : fa[x] = f(fa[x]); }
  inline void u(int x, int y) {
    x = f(x);
    y = f(y);
    if (x == y) return;
    fa[x] = y;
  }
  inline bool same(int x, int y) { return (f(x) == f(y)); }
} dsu;
vector<pair<long long, pair<int, int> > > edges;
long long a[200005];
long long d;
int n;
inline void solve(int l, int r) {
  if (l == r) return;
  if (l == r - 1) {
    edges.push_back(make_pair(a[l] + a[r] + d, make_pair(l, r)));
    return;
  }
  int m = (l + r) >> 1;
  solve(l, m);
  solve(m + 1, r);
  int bestl, bestr;
  long long mincostl = 1e18;
  for (int i = l; i <= m; ++i) {
    if (a[i] - d * i < mincostl) {
      mincostl = a[i] - d * i;
      bestl = i;
    }
  }
  long long mincostr = 1e18;
  for (int i = m + 1; i <= r; ++i) {
    if (a[i] + d * i < mincostr) {
      mincostr = a[i] + d * i;
      bestr = i;
    }
  }
  for (int i = l; i <= m; ++i) {
    edges.push_back(make_pair(mincostr + a[i] - d * i, make_pair(i, bestr)));
  }
  for (int i = m + 1; i <= r; ++i) {
    edges.push_back(make_pair(mincostl + a[i] + d * i, make_pair(bestl, i)));
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> d;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  solve(1, n);
  sort(edges.begin(), edges.end());
  reverse(edges.begin(), edges.end());
  dsu.init();
  long long ans = 0;
  while (!edges.empty()) {
    pair<long long, pair<int, int> > E = edges.back();
    edges.pop_back();
    int u = E.second.first, v = E.second.second, cost = E.first;
    if (dsu.same(u, v)) continue;
    dsu.u(u, v);
    ans += cost;
  }
  cout << ans;
  return 0;
}
