#include <bits/stdc++.h>
using namespace std;
int n, d, a[200005], top, sta[200005], st, f[200005];
int find(int x) {
  if (f[x] != x) f[x] = find(f[x]);
  return f[x];
}
struct lin {
  int u, v;
  long long w;
} line[200005 * 8];
long long check(int i, int j) {
  if (i > j) swap(i, j);
  return 1ll * (j - i) * d + a[i] + a[j];
}
bool cmp(lin A, lin B) { return A.w < B.w; }
void addline(int i, int j) {
  line[++top];
  line[top].u = i;
  line[top].v = j;
  line[top].w = check(j, i);
}
long long ans;
int main() {
  scanf("%d%d", &n, &d);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), f[i] = i;
  sta[st = 1] = 1;
  for (int i = 2; i <= n; i++) {
    int l = 1, r = st, m1, m2;
    while (r - l > 2) {
      m1 = l + (r - l) / 3;
      m2 = m1 + (r - l) / 3;
      if (check(sta[m1], i) < check(sta[m2], i))
        r = m2;
      else
        l = m1;
    }
    addline(sta[l], i);
    addline(sta[(l + r) / 2], i);
    addline(sta[r], i);
    while (st && a[sta[st]] >= a[i]) st--;
    sta[++st] = i;
  }
  sta[st = 1] = n;
  for (int i = n - 1; i >= 1; i--) {
    int l = 1, r = st, m1, m2;
    while (r - l > 2) {
      m1 = l + (r - l) / 3;
      m2 = m1 + (r - l) / 3;
      if (check(sta[m1], i) < check(sta[m2], i))
        r = m2;
      else
        l = m1;
    }
    addline(sta[l], i);
    addline(sta[(l + r) / 2], i);
    addline(sta[r], i);
    while (st && a[sta[st]] >= a[i]) st--;
    sta[++st] = i;
  }
  sort(line + 1, line + 1 + top, cmp);
  for (int i = 1; i <= top; i++) {
    if (find(line[i].u) != find(line[i].v)) {
      ans += line[i].w;
      f[f[line[i].u]] = f[line[i].v];
    }
  }
  printf("%lld", ans);
  return 0;
}
