#include <bits/stdc++.h>
using namespace std;
int n, d, a[200010];
struct SEG {
  struct node {
    int pos;
    long long Min;
    node() {}
    node(int pos, long long Min) : pos(pos), Min(Min) {}
    void init() { pos = -1, Min = 0x3f3f3f3f3f3f3f3f; }
    node operator+(const node &other) const {
      node res = node(-1, 0x3f3f3f3f3f3f3f3f);
      if (Min < other.Min) {
        res.Min = Min;
        res.pos = pos;
      } else {
        res.Min = other.Min;
        res.pos = other.pos;
      }
      return res;
    }
  } a[200010 << 2], res;
  void build(int id, int l, int r) {
    a[id].init();
    if (l == r) {
      a[id].pos = l;
      return;
    }
    int mid = (l + r) >> 1;
    build(id << 1, l, mid);
    build(id << 1 | 1, mid + 1, r);
  }
  void update(int id, int l, int r, int pos, long long val) {
    if (l == r) {
      a[id].Min = val;
      return;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid)
      update(id << 1, l, mid, pos, val);
    else
      update(id << 1 | 1, mid + 1, r, pos, val);
    a[id] = a[id << 1] + a[id << 1 | 1];
  }
  void query(int id, int l, int r, int ql, int qr) {
    if (l >= ql && r <= qr) {
      res = res + a[id];
      return;
    }
    int mid = (l + r) >> 1;
    if (l <= mid) query(id << 1, l, mid, ql, qr);
    if (r > mid) query(id << 1 | 1, mid + 1, r, ql, qr);
  }
} seg[2];
int pre[200010];
int find(int x) { return pre[x] == 0 ? x : pre[x] = find(pre[x]); }
struct node {
  long long v;
  int x, y;
  node() {}
  node(int x, int y, long long v) : x(x), y(y), v(v) {}
  bool operator<(const node &other) const { return v > other.v; }
};
int main() {
  while (scanf("%d%d", &n, &d) != EOF) {
    for (int i = 1; i <= n; ++i) scanf("%d", a + i);
    for (int i = 0; i < 2; ++i) seg[i].res.init();
    for (int i = 1; i <= n; ++i) {
      seg[0].update(1, 1, n, i, 1ll + a[i] - 1ll * i * d);
      seg[1].update(1, 1, n, i, 1ll + a[i] + 1ll * i * d);
    }
    memset(pre, 0, sizeof pre);
    long long res = 0;
    priority_queue<node> pq;
    seg[1].res.init();
    seg[1].query(1, 1, n, 2, n);
    pq.push(node(1, seg[1].res.pos, 1ll + a[1] + d + seg[1].res.Min));
    int cnt = 1;
    while (cnt < n) {
      node top = pq.top();
      pq.pop();
      int fx = find(top.x), fy = find(top.y);
      if (fx != fy) {
        res += top.v;
        pre[fx] = fy;
        ++cnt;
        seg[0].update(1, 1, n, top.y, 0x3f3f3f3f3f3f3f3f);
        seg[1].update(1, 1, n, top.y, 0x3f3f3f3f3f3f3f3f);
      }
      for (int i = 0; i < 2; ++i) seg[i].res.init();
      seg[0].query(1, 1, n, 1, top.y - 1);
      seg[1].query(1, 1, n, top.y + 1, n);
      long long tmpl = 1ll + a[top.y] + 1ll * top.y * d + seg[0].res.Min;
      long long tmpr = 1ll + a[top.y] - 1ll * top.y * d + seg[1].res.Min;
      if (tmpl < tmpr) {
        pq.push(node(top.y, seg[0].res.pos, tmpl));
      } else {
        pq.push(node(top.y, seg[1].res.pos, tmpr));
      }
    }
    printf("%lld\n", res);
  }
  return 0;
}
