#include <bits/stdc++.h>
using namespace std;
struct seg {
  int l, r;
  long long mna, mnb;
} Node[200005 * 4];
int n, d;
long long a[200005], b[200005], qa[200005], qb[200005];
int p[200005];
inline void upd(int u) {
  if (a[Node[u << 1].mna] < a[Node[u << 1 | 1].mna])
    Node[u].mna = Node[u << 1].mna;
  else
    Node[u].mna = Node[u << 1 | 1].mna;
  if (b[Node[u << 1].mnb] < b[Node[u << 1 | 1].mnb])
    Node[u].mnb = Node[u << 1].mnb;
  else
    Node[u].mnb = Node[u << 1 | 1].mnb;
  return;
}
vector<int> ch[200005];
long long Ans[200005];
struct node {
  int u;
  long long v;
};
bool operator<(node a, node b) { return a.v < b.v; }
set<node> s;
int to[200005];
void build(int u, int l, int r) {
  Node[u].l = l, Node[u].r = r;
  if (l == r) {
    Node[u].mna = l;
    Node[u].mnb = l;
    p[l] = u;
    return;
  }
  build(u << 1, l, l + r >> 1);
  build(u << 1 | 1, (l + r >> 1) + 1, r);
  upd(u);
}
void st(int u) {
  a[u] = b[u] = 1e18;
  u = (p[u] >> 1);
  while (u) {
    upd(u);
    u >>= 1;
  }
  return;
}
inline int Mina(int x, int y) { return a[x] < a[y] ? x : y; }
inline int Minb(int x, int y) { return b[x] < b[y] ? x : y; }
int querya(int u, int l, int r) {
  if (Node[u].l == l && Node[u].r == r) return Node[u].mna;
  if (r <= Node[u << 1].r)
    return querya(u << 1, l, r);
  else if (l >= Node[u << 1 | 1].l)
    return querya(u << 1 | 1, l, r);
  return Mina(querya(u << 1, l, Node[u << 1].r),
              querya(u << 1 | 1, Node[u << 1 | 1].l, r));
}
int queryb(int u, int l, int r) {
  if (Node[u].l == l && Node[u].r == r) return Node[u].mnb;
  if (r <= Node[u << 1].r)
    return queryb(u << 1, l, r);
  else if (l >= Node[u << 1 | 1].l)
    return queryb(u << 1 | 1, l, r);
  return Minb(queryb(u << 1, l, Node[u << 1].r),
              queryb(u << 1 | 1, Node[u << 1 | 1].l, r));
}
void get(int u) {
  int l = -1, r = -1;
  if (u > 1) l = querya(1, 1, u - 1);
  if (u < n) r = queryb(1, u + 1, n);
  long long al = 1e18, ar = 1e18;
  if (l != -1) al = qb[u] + a[l];
  if (r != -1) ar = qa[u] + b[r];
  if (al < ar) {
    to[u] = l;
    ch[l].push_back(u);
    s.insert((node){u, al});
    Ans[u] = al;
  } else {
    ch[r].push_back(u);
    to[u] = r;
    s.insert((node){u, ar});
    Ans[u] = ar;
  }
}
int main() {
  scanf("%d", &n);
  scanf("%d", &d);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    qa[i] = a[i] = x - 1LL * i * d;
    qb[i] = b[i] = x + 1LL * i * d;
  }
  build(1, 1, n);
  long long ans = 0;
  get(1);
  st(1);
  for (int i = 1; i < n; i++) {
    set<node>::iterator it = s.begin();
    int u = it->u;
    long long v = it->v;
    s.erase(it);
    ans += v;
    if (i == n - 1) break;
    int tu = to[u];
    st(tu);
    get(tu);
    for (int i = 0; i < ch[tu].size(); i++) {
      s.erase((node){ch[tu][i], Ans[ch[tu][i]]});
      get(ch[tu][i]);
    }
  }
  cout << ans << endl;
  return 0;
}
