#include <bits/stdc++.h>
int upll(const void* a, const void* b) {
  return *(long long*)a < *(long long*)b   ? -1
         : *(long long*)a > *(long long*)b ? 1
                                           : 0;
}
int downll(const void* a, const void* b) {
  return *(long long*)a < *(long long*)b   ? 1
         : *(long long*)a > *(long long*)b ? -1
                                           : 0;
}
void sortup(long long* a, int n) { qsort(a, n, sizeof(long long), upll); }
void sortdown(long long* a, int n) { qsort(a, n, sizeof(long long), downll); }
long long pom(long long a, long long n, int m) {
  long long x = 1;
  for (a %= m; n; n /= 2) n& 1 ? x = x * a % m : 0, a = a * a % m;
  return x;
}
typedef struct atai {
  long long l, r, li, ri;
} atai;
atai xx(atai x, atai y) {
  atai r;
  if (x.l < y.l) {
    r.li = x.li;
    r.l = x.l;
  } else {
    r.li = y.li;
    r.l = y.l;
  }
  if (x.r < y.r) {
    r.ri = x.ri;
    r.r = x.r;
  } else {
    r.ri = y.ri;
    r.r = y.r;
  }
  return r;
}
int segNUM;
atai segN[1 << 19], *seg;
void seguse(int n) {
  segNUM = n;
  seg = segN + segNUM;
}
void seginit() {
  for (int node = segNUM - 1; node; node--)
    segN[node] = xx(segN[node * 2], segN[node * 2 + 1]);
}
void segupdate(int node, atai x) {
  node += segNUM;
  segN[node] = x;
  while (node /= 2) segN[node] = xx(segN[node * 2], segN[node * 2 + 1]);
}
atai segcalcsub(int l, int r, int k, int cl, int cr) {
  if (l <= cl && cr <= r) return segN[k];
  int cm = (cl + cr) / 2;
  if (r <= cm) return segcalcsub(l, r, 2 * k, cl, cm);
  if (cm <= l) return segcalcsub(l, r, 2 * k + 1, cm, cr);
  return xx(segcalcsub(l, r, 2 * k, cl, cm),
            segcalcsub(l, r, 2 * k + 1, cm, cr));
}
atai segcalc(int l, int r) { return segcalcsub(l, r, 1, 0, segNUM); }
typedef struct edge {
  long long s, g, c;
} E;
typedef struct graph {
  long long vcnt, ecnt;
  E e[400010];
  long long id[200010];
} G;
int csort(const void* a, const void* b) {
  long long p = (*(E*)a).c, q = (*(E*)b).c;
  return p < q ? -1 : p > q ? 1 : 0;
}
G g;
long long a[200010];
void readgraph() {
  long long n, d;
  scanf("%lld%lld", &n, &d);
  for (long long i = (0); i < (n); i++) scanf("%lld", a + i);
  seguse(1 << 18);
  for (long long i = (0); i < (n); i++) {
    seg[i].l = a[i] + d * (n - 1 - i);
    seg[i].li = i;
    seg[i].r = a[i] + d * i;
    seg[i].ri = i;
  }
  seginit();
  for (long long i = (1); i < (n - 1); i++) {
    atai temp = segcalc(0, i);
    g.e[2 * i].s = i;
    g.e[2 * i].g = temp.li;
    g.e[2 * i].c = a[i] + a[temp.li] + llabs(temp.li - i) * d;
    temp = segcalc(i + 1, n);
    g.e[2 * i + 1].s = i;
    g.e[2 * i + 1].g = temp.ri;
    g.e[2 * i + 1].c = a[i] + a[temp.ri] + llabs(temp.ri - i) * d;
  }
  atai temp = segcalc(0, n - 1);
  g.e[0].s = n - 1;
  g.e[0].g = temp.li;
  g.e[0].c = a[n - 1] + a[temp.li] + llabs(temp.li - (n - 1)) * d;
  temp = segcalc(1, n);
  g.e[1].s = 0;
  g.e[1].g = temp.ri;
  g.e[1].c = a[0] + a[temp.ri] + llabs(temp.ri - 0) * d;
  g.vcnt = n;
  g.ecnt = 2 * (n - 1);
  qsort(g.e, g.ecnt, sizeof(E), csort);
  int p = 0;
  for (long long i = (0); i < (g.vcnt); i++) {
    while (p < g.ecnt && g.e[p].s < i) p++;
    g.id[i] = p;
  }
  g.id[g.vcnt] = g.ecnt;
}
int unicnt[(1 << 18) + 10];
void ufinit(int n) {
  for (long long i = (0); i < (n); i++) unicnt[i] = 1;
}
int root(int x) {
  return unicnt[x] <= 0 ? -(unicnt[x] = -root(-unicnt[x])) : x;
}
int same(int x, int y) { return root(x) == root(y); }
void uni(int x, int y) {
  if ((x = root(x)) == (y = root(y))) return;
  if (unicnt[x] < unicnt[y]) {
    int t = x;
    x = y;
    y = t;
  }
  unicnt[x] += unicnt[y];
  unicnt[y] = -x;
}
int saishou[200010];
long long kurasukaru() {
  long long ans = 0;
  ufinit(g.vcnt);
  for (long long i = (0); i < (g.ecnt); i++) {
    if (!same(g.e[i].s, g.e[i].g)) {
      uni(g.e[i].s, g.e[i].g);
      saishou[i] = 1;
      ans += g.e[i].c;
    }
  }
  return ans;
}
int main() {
  readgraph();
  printf("%lld", kurasukaru());
}
