#include <bits/stdc++.h>
void read(int &x) {
  x = 0;
  int flag = 1;
  char ch = ' ';
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= flag;
}
void read(long long &x) {
  x = 0;
  int flag = 1;
  char ch = ' ';
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= flag;
}
using namespace std;
const long long inf = 1e18;
const int maxn = 200010;
int n;
long long d, a[maxn];
struct node {
  int pos;
  long long val;
  node() {}
  node(int a, long long b) { pos = a, val = b; }
  bool operator<(const node &a) const { return val < a.val; }
};
struct Segment_Tree_1 {
  node tree[maxn << 2][2];
  void build(int p, int l, int r) {
    tree[p][0] = tree[p][1] = node(l, inf);
    if (l == r) return;
    int mid = (l + r) >> 1;
    build(p << 1, l, mid), build(p << 1 | 1, mid + 1, r);
  }
  void update(int p, int l, int r, int pos, node x, int opt) {
    if (l == r) {
      tree[p][opt] = x;
      return;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid)
      update(p << 1, l, mid, pos, x, opt);
    else
      update(p << 1 | 1, mid + 1, r, pos, x, opt);
    tree[p][opt] = min(tree[p << 1][opt], tree[p << 1 | 1][opt]);
  }
  node query(int p, int l, int r, int ql, int qr, int opt) {
    if (ql <= l && r <= qr) return tree[p][opt];
    int mid = (l + r) >> 1;
    if (ql > mid)
      return query(p << 1 | 1, mid + 1, r, ql, qr, opt);
    else if (qr <= mid)
      return query(p << 1, l, mid, ql, qr, opt);
    else
      return min(query(p << 1, l, mid, ql, qr, opt),
                 query(p << 1 | 1, mid + 1, r, ql, qr, opt));
  }
} seg1, seg2;
struct Segment_Tree_2 {
  node tree[maxn << 2];
  void build(int p, int l, int r) {
    tree[p] = node(l, inf);
    if (l == r) return;
    int mid = (l + r) >> 1;
    build(p << 1, l, mid), build(p << 1 | 1, mid + 1, r);
  }
  void push_up(int p, int l, int r) {
    int mid = (l + r) >> 1;
    tree[p] = min(tree[p << 1], tree[p << 1 | 1]);
    node x = seg1.tree[p << 1][0], y = seg2.tree[p << 1 | 1][1];
    tree[p] = min(tree[p], node(x.pos, x.val + y.val));
    x = seg1.tree[p << 1 | 1][1], y = seg2.tree[p << 1][0];
    tree[p] = min(tree[p], node(x.pos, x.val + y.val));
  }
  void update(int p, int l, int r, int x) {
    if (l == r) {
      tree[p].val = inf;
      return;
    }
    int mid = (l + r) >> 1;
    if (x <= mid)
      update(p << 1, l, mid, x);
    else
      update(p << 1 | 1, mid + 1, r, x);
    push_up(p, l, r);
  }
} seg3;
int main() {
  read(n), read(d);
  for (int i = 1; i <= n; i++) read(a[i]);
  seg1.build(1, 1, n);
  seg2.build(1, 1, n);
  seg3.build(1, 1, n);
  for (int i = 2; i <= n; i++) {
    seg1.update(1, 1, n, i, node(i, a[i] - i * d), 0);
    seg1.update(1, 1, n, i, node(i, a[i] + i * d), 1);
  }
  seg2.update(1, 1, n, 1, node(1, a[1] - d), 0);
  seg2.update(1, 1, n, 1, node(1, a[1] + d), 1);
  seg3.update(1, 1, n, 1);
  long long ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    ans += seg3.tree[1].val;
    int tmp = seg3.tree[1].pos;
    seg1.update(1, 1, n, tmp, node(tmp, inf), 0);
    seg1.update(1, 1, n, tmp, node(tmp, inf), 1);
    seg2.update(1, 1, n, tmp, node(tmp, a[tmp] - tmp * d), 0);
    seg2.update(1, 1, n, tmp, node(tmp, a[tmp] + tmp * d), 0);
    seg3.update(1, 1, n, tmp);
  }
  printf("%lld\n", ans);
  return 0;
}
