#include <bits/stdc++.h>
using namespace std;
struct status {
  pair<long long, int> asmall, abig, bsmall, bbig;
  pair<long long, int> ans;
  void init() { asmall = abig = bsmall = bbig = ans = make_pair(1e18, 0); }
};
pair<long long, int> operator+(pair<long long, int> a, pair<long long, int> b) {
  a.first += b.first;
  a.second = b.second;
  return a;
}
status merge(status a, status b) {
  status c;
  c.init();
  c.ans = min(b.ans, a.ans);
  c.asmall = min(a.asmall, b.asmall);
  c.abig = min(a.abig, b.abig);
  c.bsmall = min(a.bsmall, b.bsmall);
  c.bbig = min(a.bbig, b.bbig);
  c.ans = min(c.ans, a.asmall + b.bbig);
  c.ans = min(c.ans, b.abig + a.bsmall);
  return c;
}
long long D;
long long a[65536];
struct segmenttree {
  status tree[65536 * 2 + 10];
  void up(long long id) { tree[id] = merge(tree[id << 1], tree[id << 1 | 1]); }
  void init(long long l, long long r, long long id) {
    if (l == r) {
      tree[id].init();
      tree[id].bsmall = make_pair(a[l] - D * l, l);
      tree[id].bbig = make_pair(a[l] + D * l, l);
      return;
    }
    init(l, (l + r) / 2, id << 1);
    init((l + r) / 2 + 1, r, id << 1 | 1);
    up(id);
  }
  void update(long long x, long long l, long long r, long long id) {
    if (l == r) {
      tree[id].init();
      tree[id].asmall = make_pair(a[l] - D * l, l);
      tree[id].abig = make_pair(a[l] + D * l, l);
      return;
    }
    if (x <= (l + r) / 2)
      update(x, l, (l + r) / 2, id << 1);
    else
      update(x, (l + r) / 2 + 1, r, id << 1 | 1);
    up(id);
  }
  pair<long long, long long> query() { return tree[1].ans; }
} trcyx;
int main() {
  long long n;
  scanf("%lld", &n);
  scanf("%lld", &D);
  memset(a, 0x3f, sizeof(a));
  for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
  trcyx.init(1, 65536, 1);
  long long ans = 0;
  trcyx.update(1, 1, 65536, 1);
  for (long long i = 1; i < n; i++) {
    pair<long long, long long> op = trcyx.query();
    ans += op.first;
    trcyx.update(op.second, 1, 65536, 1);
  }
  cout << ans;
  return 0;
}
