#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long x, y, z;
} e[505050 * 4];
long long ans, pre[505050], n, a[505050], d, p, q;
int ffind(int x) {
  if (pre[x] == x) return x;
  pre[x] = ffind(pre[x]);
  return pre[x];
}
bool cmp(edge x, edge y) { return x.z < y.z; }
long long cost(int u, int v) { return 1ll * abs(u - v) * d + a[u] + a[v]; }
int main() {
  cin >> n >> d;
  p = 1;
  q = n;
  int cnt = 0;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) pre[i] = i;
  for (int i = 2; i <= n; i++) {
    e[cnt++] = {i, p, cost(i, p)};
    if (a[i] - d * i < a[p] - d * p) p = i;
  }
  for (int i = n - 1; i >= 1; i--) {
    e[cnt++] = {i, q, cost(i, q)};
    if (a[i] + d * i < a[q] + d * q) q = i;
  }
  sort(e, e + cnt, cmp);
  for (int i = 0; i < cnt; i++) {
    int u = ffind(e[i].x), v = ffind(e[i].y);
    if (u != v) ans += e[i].z, pre[v] = u;
  }
  cout << ans << endl;
}
