#include <bits/stdc++.h>
typedef struct UnionFind {
  int32_t *parent;
  int32_t size;
} UnionFind;
void initUnionFind(UnionFind *u) {
  for (int32_t i = 0; i < u->size; ++i) {
    u->parent[i] = -1;
  }
}
UnionFind *newUnionFind(const int32_t size) {
  UnionFind *u = (UnionFind *)calloc(1, sizeof(UnionFind));
  u->parent = (int32_t *)calloc(size, sizeof(int32_t));
  u->size = size;
  initUnionFind(u);
  return u;
}
void freeUnionFind(UnionFind *u) {
  free(u->parent);
  free(u);
}
int32_t root(UnionFind *u, int32_t x) {
  if (u->parent[x] < 0) return x;
  return u->parent[x] = root(u, u->parent[x]);
}
int same(UnionFind *u, int32_t x, int32_t y) {
  return root(u, x) == root(u, y);
}
int32_t getSize(UnionFind *u, int32_t x) { return -(u->parent[root(u, x)]); }
void unite(UnionFind *u, int32_t x, int32_t y) {
  x = root(u, x);
  y = root(u, y);
  if (x == y) return;
  if (u->parent[x] > u->parent[y]) {
    int32_t swap = x;
    x = y;
    y = swap;
  }
  u->parent[x] += u->parent[y];
  u->parent[y] = x;
}
typedef struct edge {
  int32_t a, b;
  int64_t c;
} edge;
const int32_t null_index = -1;
static inline int pairingheap_func_compare(edge a, edge b) {
  int64_t d = a.c - b.c;
  return d == 0 ? 0 : d < 0 ? -1 : 1;
}
typedef struct pairingHeapNode {
  int32_t next;
  int32_t child;
  edge val;
} heap_node;
typedef struct pairingHeapHead {
  heap_node *array;
  int32_t root;
  int32_t free_front;
  int32_t heap_size;
  int32_t array_len;
} heap;
void init_pairingheap(heap *const h) {
  if (h->array != NULL) {
    free(h->array);
  }
  const int32_t initial_len = 1;
  h->array = (heap_node *)calloc(initial_len, sizeof(heap_node));
  h->array[0].next = null_index;
  h->root = null_index;
  h->free_front = 0;
  h->array_len = initial_len;
  h->heap_size = 0;
}
heap *new_pairingheap(void) {
  heap *h = (heap *)calloc(1, sizeof(heap));
  h->array = NULL;
  init_pairingheap(h);
  return h;
}
int32_t get_heap_size(const heap *h) { return h->heap_size; }
int is_empty(const heap *h) { return h->heap_size == 0; }
static inline int32_t meld(heap_node *const array, int32_t a, int32_t b) {
  if (a == null_index) return b;
  if (b == null_index) return a;
  heap_node *p = array + a;
  heap_node *q = array + b;
  if (pairingheap_func_compare(p->val, q->val) > 0) {
    const int32_t swap_index = a;
    a = b;
    b = swap_index;
    heap_node *const swap_ptr = p;
    p = q;
    q = swap_ptr;
  }
  q->next = p->child;
  p->child = b;
  return a;
}
void push(heap *const h, const edge val) {
  if (h->free_front == null_index) {
    const int32_t front = h->array_len;
    h->array_len *= 2;
    h->array = (heap_node *)realloc(h->array, sizeof(heap_node) * h->array_len);
    h->free_front = front;
    for (int32_t i = front; i + 1 < h->array_len; ++i) {
      h->array[i].next = i + 1;
    }
    h->array[h->array_len - 1].next = null_index;
  }
  h->heap_size++;
  const int32_t k = h->free_front;
  h->free_front = h->array[h->free_front].next;
  h->array[k] = (heap_node){null_index, null_index, val};
  h->root = meld(h->array, h->root, k);
}
edge pop(heap *h) {
  h->heap_size--;
  heap_node *const array = h->array;
  const edge res = array[h->root].val;
  array[h->root].next = h->free_front;
  h->free_front = h->root;
  int32_t lst = array[h->root].child;
  int32_t r = null_index;
  while (lst != null_index && array[lst].next != null_index) {
    const int32_t a = lst;
    const int32_t b = array[a].next;
    lst = array[b].next;
    array[a].next = array[b].next = null_index;
    r = meld(array, r, meld(array, a, b));
  }
  if (lst != null_index) {
    r = meld(array, r, lst);
  }
  h->root = r;
  return res;
}
void build(const int32_t *a, const int32_t n, const int32_t d, heap *const h) {
  if (n <= 1) return;
  static int32_t buf = 0;
  int32_t m = n / 2;
  int32_t min = 0;
  for (int32_t i = 1; i < m; ++i) {
    int64_t x = (int64_t)d * (i - min) + a[min];
    int64_t y = a[i];
    if (x > y) {
      min = i;
    }
  }
  for (int32_t i = m; i < n; ++i) {
    push(h, (edge){buf + min, buf + i, (int64_t)d * (i - min) + a[min] + a[i]});
  }
  min = n - 1;
  for (int32_t i = n - 2; i >= m; --i) {
    int64_t x = (int64_t)d * (min - i) + a[min];
    int64_t y = a[i];
    if (x > y) {
      min = i;
    }
  }
  for (int32_t i = m - 1; i >= 0; --i) {
    push(h, (edge){buf + i, buf + min, (int64_t)d * (min - i) + a[min] + a[i]});
  }
  build(a, m, d, h);
  buf += m;
  build(a + m, n - m, d, h);
  buf -= m;
}
void run(void) {
  int32_t n, d;
  scanf("%" SCNi32 "%" SCNi32, &n, &d);
  int32_t *a = (int32_t *)calloc(n, sizeof(int32_t));
  for (int32_t i = 0; i < n; ++i) {
    scanf("%" SCNi32, a + i);
  }
  heap *h = new_pairingheap();
  build(a, n, d, h);
  UnionFind *u = newUnionFind(n);
  int64_t sum = 0;
  while (getSize(u, 0) < n) {
    edge e = pop(h);
    if (same(u, e.a, e.b)) continue;
    sum += e.c;
    unite(u, e.a, e.b);
  }
  printf("%" PRIi64 "\n", sum);
}
int main(void) {
  run();
  return 0;
}
