#include <bits/stdc++.h>
using namespace std;
long long parent[200005];
long long mx[200005], mn[200005];
long long sz[200005];
long long find_parent(long long ver) {
  if (parent[ver] == ver) return ver;
  return parent[ver] = find_parent(parent[ver]);
}
bool merge(long long a, long long b) {
  a = find_parent(a);
  b = find_parent(b);
  if (a != b) {
    if (sz[a] < sz[b]) swap(a, b);
    sz[a] += sz[b];
    parent[b] = a;
    return true;
  }
  return false;
}
pair<long long, long long> seg_max[800005], seg_min[800004];
void build(long long ver, long long tl, long long tr) {
  if (tl > tr)
    return;
  else if (tl == tr) {
    seg_max[ver] = {mx[tl], tl};
    seg_min[ver] = {mn[tl], tl};
  } else {
    long long tm = (tl + tr) / 2;
    build(2 * ver, tl, tm);
    build(2 * ver + 1, tm + 1, tr);
    seg_max[ver] = min(seg_max[2 * ver], seg_max[2 * ver + 1]);
    seg_min[ver] = min(seg_min[2 * ver], seg_min[2 * ver + 1]);
  }
}
pair<long long, long long> get_max(long long ver, long long tl, long long tr,
                                   long long l, long long r) {
  if (tl > tr || l > r || tr < l || r < tl)
    return {1e17, 0};
  else if (tl == l && tr == r)
    return seg_max[ver];
  else {
    long long tm = (tl + tr) / 2;
    return min(get_max(2 * ver, tl, tm, l, min(tm, r)),
               get_max(2 * ver + 1, tm + 1, tr, max(tm + 1, l), r));
  }
}
pair<long long, long long> get_min(long long ver, long long tl, long long tr,
                                   long long l, long long r) {
  if (tl > tr || l > r || tr < l || r < tl)
    return {1e17, 0};
  else if (tl == l && tr == r)
    return seg_min[ver];
  else {
    long long tm = (tl + tr) / 2;
    return min(get_min(2 * ver, tl, tm, l, min(tm, r)),
               get_min(2 * ver + 1, tm + 1, tr, max(tm + 1, l), r));
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  long long n, d;
  cin >> n >> d;
  long long a[n + 1];
  for (long long i = 1; i <= n; i++) {
    sz[i] = 1;
    parent[i] = i;
    cin >> a[i];
  }
  for (long long i = 1; i <= n; i++) {
    mn[i] = -i * d + a[i];
    mx[i] = i * d + a[i];
  }
  build(1, 1, n);
  vector<pair<long long, pair<long long, long long> > > pp;
  for (long long i = 1; i <= n; i++) {
    if (i > 1) {
      pair<long long, long long> z = get_min(1, 1, n, 1, i - 1);
      pp.push_back({z.first + mx[i], {i, z.second}});
    }
    if (i < n) {
      pair<long long, long long> z = get_max(1, 1, n, i + 1, n);
      pp.push_back({z.first + mn[i], {i, z.second}});
    }
  }
  long long ans = 0;
  sort(pp.begin(), pp.end());
  for (auto i : pp) {
    if (merge(i.second.first, i.second.second)) ans += i.first;
  }
  cout << ans;
}
