#include <bits/stdc++.h>
using namespace std;
int lowbit(int x) { return x & (-x); }
int n, d;
int a[200010];
vector<pair<long long, pair<int, int> > > e;
struct UF {
  int p[200010], rank[200010];
  void init() {
    for (int i = 0; i < 200010; i++) p[i] = i;
    for (int i = 0; i < 200010; i++) rank[i] = 0;
  }
  int getf(int x) {
    if (p[x] == x) return x;
    return getf(p[x]);
  }
  bool same(int x, int y) { return getf(x) == getf(y); }
  void unite(int x, int y) {
    int xx = getf(x);
    int yy = getf(y);
    if (xx != yy) {
      if (rank[xx] < rank[yy])
        p[xx] = yy;
      else {
        p[yy] = xx;
        if (rank[xx] == rank[yy]) rank[xx]++;
      }
    }
  }
} uf;
void solve(int l, int r) {
  if (l == r) return;
  int mid = l + r >> 1;
  long long mn = 1e18;
  int pl, pr;
  for (int i = l; i <= mid; i++) {
    long long cur = a[i] - (long long)d * (long long)i;
    if (cur < mn) {
      mn = cur;
      pl = i;
    }
  }
  mn = 1e18;
  for (int j = mid + 1; j <= r; j++) {
    long long cur = a[j] - (long long)d * (long long)j;
    if (cur < mn) {
      mn = cur;
      pr = j;
    }
  }
  for (int i = mid + 1; i <= r; i++) {
    long long vl = a[pl] - 1ll * d * pl;
    long long vr = a[i] + 1ll * d * i;
    e.push_back(make_pair(vl + vr, make_pair(pl, i)));
  }
  for (int i = l; i <= mid; i++) {
    long long vl = a[i] - 1ll * d * i;
    long long vr = a[pr] + 1ll * d * pr;
    e.push_back(make_pair(vl + vr, make_pair(i, pr)));
  }
  solve(l, mid);
  solve(mid + 1, r);
}
int main() {
  scanf("%d%d", &n, &d);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  solve(0, n - 1);
  sort(e.begin(), e.end());
  uf.init();
  long long ans = 0ll;
  for (int i = 0; i < e.size(); i++) {
    int u = e[i].second.first, v = e[i].second.second;
    if (!uf.same(u, v)) {
      uf.unite(u, v);
      ans += e[i].first;
    }
  }
  cout << ans;
  return 0;
}
