#include <bits/stdc++.h>
using namespace std;
const long long NMAX = 1 << 17;
long long N, dat[2 * NMAX - 1], rdat[2 * NMAX - 1];
void init(long long n_) {
  N = 1;
  while (N < n_) N *= 2;
  for (long long i = (0); i < (N * 2 - 1); i++)
    dat[i] = rdat[i] = (1LL << 31) - 1;
}
void update(long long k, long long a) {
  k += N - 1;
  dat[k] = a;
  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
  }
}
void rupdate(long long k, long long a) {
  k += N - 1;
  rdat[k] = a;
  while (k > 0) {
    k = (k - 1) / 2;
    rdat[k] = min(rdat[k * 2 + 1], rdat[k * 2 + 2]);
  }
}
long long query(long long a, long long b, long long k, long long l,
                long long r) {
  if (r <= a || b <= l) return (1LL << 31) - 1;
  if (a <= l && r <= b)
    return dat[k];
  else {
    long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
}
long long rquery(long long a, long long b, long long k, long long l,
                 long long r) {
  if (r <= a || b <= l) return (1LL << 31) - 1;
  if (a <= l && r <= b)
    return rdat[k];
  else {
    long long vl = rquery(a, b, k * 2 + 1, l, (l + r) / 2);
    long long vr = rquery(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
}
const long long MMAX = 1e6;
vector<long long> child, tree(MMAX);
long long root(long long i) {
  if (i == tree[i]) {
    for (long long j = (0); j < (child.size()); j++) tree[child[j]] = i;
    child.clear();
    return i;
  } else {
    child.push_back(i);
    return i = root(tree[i]);
  }
}
long long unit(long long x, long long y) {
  x = root(x);
  y = root(y);
  tree[max(x, y)] = min(x, y);
}
bool isUnit(long long x, long long y) { return root(x) == root(y); }
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, d;
  cin >> n >> d;
  vector<long long> a(n);
  for (long long i = (0); i < (n); i++) cin >> a[i];
  init(n);
  map<long long, long long> mp, rmp;
  for (long long i = (0); i < (n); i++)
    update(i, a[i] + d * i), mp[a[i] + d * i] = i;
  for (long long i = (0); i < (n); i++)
    rupdate(i, a[i] + d * (n - 1 - i)), rmp[a[i] + d * (n - 1 - i)] = i;
  vector<pair<long long, pair<long long, long long>>> edge;
  for (long long i = (0); i < (n); i++) {
    long long tmp;
    if (i != n - 1) {
      tmp = query(i + 1, n, 0, 0, N);
      edge.push_back(make_pair(tmp - d * i + a[i],
                               pair<long long, long long>(i, mp[tmp])));
    }
    if (i != 0) {
      tmp = rquery(0, i, 0, 0, N);
      edge.push_back(make_pair(tmp - d * (n - 1 - i) + a[i],
                               pair<long long, long long>(i, rmp[tmp])));
    }
  }
  sort(edge.begin(), edge.end());
  for (long long i = (0); i < (n); i++) tree[i] = i;
  long long ans = 0;
  for (auto &e : edge) {
    long long x = e.second.first, y = e.second.second, cost = e.first;
    if (!isUnit(x, y)) ans += cost, unit(x, y);
  }
  cout << ans << endl;
  return 0;
}
