#include <bits/stdc++.h>
typedef struct {
  long long N;
  long long *u;
  long long *u_rank;
} union_find;
union_find *make_union_find(long long N) {
  long long i;
  union_find *uf = (union_find *)malloc(sizeof(union_find));
  uf->N = N;
  uf->u = (long long *)malloc(sizeof(long long) * N);
  uf->u_rank = (long long *)malloc(sizeof(long long) * N);
  for (i = 0; i < N; i++) {
    uf->u[i] = i;
    uf->u_rank[i] = 1;
  }
  return uf;
}
long long root_uf(long long x, union_find *uf) {
  long long *u = uf->u;
  if (u[x] == x) {
    return x;
  } else {
    u[x] = root_uf(u[x], uf);
    return u[x];
  }
}
void combine_uf(long long x, long long y, union_find *uf) {
  long long x_root = root_uf(x, uf);
  long long y_root = root_uf(y, uf);
  long long *u = uf->u;
  long long *u_rank = uf->u_rank;
  if (x_root == y_root) {
    return;
  } else if (u_rank[x_root] < u_rank[y_root]) {
    u[x_root] = y_root;
    u_rank[y_root] += u_rank[x_root];
    u_rank[x_root] = 0;
  } else {
    u[y_root] = x_root;
    u_rank[x_root] += u_rank[y_root];
    u_rank[y_root] = 0;
  }
}
long long is_same_union_uf(long long x, long long y, union_find *uf) {
  if (root_uf(x, uf) == root_uf(y, uf)) {
    return 1;
  } else {
    return 0;
  }
}
long long rank_uf(long long x, union_find *uf) {
  return uf->u_rank[root_uf(x, uf)];
}
typedef struct {
  long long a;
  long long b;
  long long c;
} edge;
signed compare(const void *a, const void *b) {
  long long sub = ((edge *)a)->c - ((edge *)b)->c;
  if (sub < 0) {
    return -1;
  } else if (sub == 0) {
    return 0;
  } else {
    return 1;
  }
}
long long max(long long a, long long b) { return a >= b ? a : b; }
long long min(long long a, long long b) { return a <= b ? a : b; }
long long ABS(long long a) { return a >= 0 ? a : -a; }
signed main() {
  long long N, D, i, j;
  scanf("%lld%lld", &N, &D);
  long long *A = (long long *)malloc(sizeof(long long) * N);
  for (i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  if (N == 1) {
    printf("0\n");
    return 0;
  }
  long long M = 6 * N;
  edge *es = (edge *)malloc(sizeof(edge) * M);
  for (i = 0; i < M; i++) {
    es[i].a = 0;
    es[i].b = 0;
    es[i].c = (long long)(1e18);
  }
  long long k = 0;
  for (i = 0; i < N; i++) {
    for (j = max(0, i - 2); j <= min(N - 1, i + 2); j++) {
      if (i == j) {
        continue;
      }
      es[k].a = i;
      es[k].b = j;
      es[k].c = D * ABS(i - j) + A[i] + A[j];
      k++;
    }
  }
  long long theni = 0;
  for (i = 0; i < N; i++) {
    if (A[i] < A[theni]) {
      theni = i;
    }
  }
  for (i = 0; i < N; i++) {
    es[k].a = i;
    es[k].b = theni;
    es[k].c = D * ABS(i - theni) + A[i] + A[theni];
    k++;
  }
  long long thenj = (theni == 0 ? 1 : 0);
  for (i = 0; i < N; i++) {
    if (A[i] < A[thenj] && i != theni) {
      thenj = i;
    }
  }
  for (i = 0; i < N; i++) {
    es[k].a = i;
    es[k].b = thenj;
    es[k].c = D * ABS(i - thenj) + A[i] + A[thenj];
    k++;
  }
  qsort(es, M, sizeof(edge), compare);
  union_find *uf = make_union_find(N);
  long long ans = 0;
  for (i = 0; i < M; i++) {
    if (is_same_union_uf(es[i].a, es[i].b, uf) == 0) {
      combine_uf(es[i].a, es[i].b, uf);
      ans += es[i].c;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
