#include <bits/stdc++.h>
using namespace std;
const int maxn = 200100;
long long a[maxn], n, d;
long long f[maxn], g[maxn];
int getf(int l, int r) {
  long long minvalue = LLONG_MAX;
  int ind = 0;
  for (int i = l; i <= r; i++) {
    if (f[i] < minvalue) {
      minvalue = f[i];
      ind = i;
    }
  }
  return ind;
}
int getg(int l, int r) {
  long long minvalue = LLONG_MAX;
  int ind = 0;
  for (int i = l; i <= r; i++) {
    if (g[i] < minvalue) {
      minvalue = f[i];
      ind = i;
    }
  }
  return ind;
}
vector<pair<long long, pair<int, int> > > edges;
void solve(int l, int r) {
  if (l == r)
    return;
  else {
    int mid = (l + r) / 2;
    int fi = getf(l, mid);
    int si = getg(mid + 1, r);
    for (int i = l; i <= mid; i++) {
      edges.push_back(make_pair(f[i] + g[si], make_pair(i, si)));
    }
    for (int i = mid + 1; i <= r; i++) {
      edges.push_back(make_pair(f[fi] + g[i], make_pair(fi, i)));
    }
    solve(l, mid);
    solve(mid + 1, r);
  }
}
int uparent[maxn];
int usize[maxn];
int ufind(int x) {
  while (uparent[x] != x) {
    x = uparent[x];
  }
  return x;
}
void unite(int x, int y) {
  x = ufind(x);
  y = ufind(y);
  if (usize[x] > usize[y]) {
    uparent[y] = x;
    usize[x] += usize[y];
  } else {
    uparent[x] = y;
    usize[y] += usize[x];
  }
}
int main() {
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    f[i] = a[i] - i * d;
    g[i] = a[i] + i * d;
    uparent[i] = i;
    usize[i] = 1;
  }
  solve(1, n);
  sort(edges.begin(), edges.end());
  long long result = 0LL;
  for (auto i : edges) {
    int x = i.second.first;
    int y = i.second.second;
    if (ufind(x) != ufind(y)) {
      unite(x, y);
      result += i.first;
    }
  }
  cout << result << "\n";
  return 0;
}
