#include <bits/stdc++.h>
using namespace std;
const int nsz = 2e5;
const long long inf = 0x3f3f3f3f3f3f3f3f;
int n, d, a[nsz + 5];
long long w1[nsz + 5], w2[nsz + 5];
pair<int, int> dat[nsz + 5];
vector<pair<int, pair<int, int> > > e;
struct segment_tree {
  int fm[nsz + 5];
  long long mn[nsz + 5];
  void inline up(int u) {
    mn[u] = min(mn[(u << 1)], mn[(u << 1 | 1)]);
    fm[u] = mn[(u << 1)] < mn[(u << 1 | 1)] ? fm[(u << 1)] : fm[(u << 1 | 1)];
  }
  void init(long long a[], int u = 1, int l = 1, int r = n) {
    if (l == r) {
      mn[u] = a[l], fm[u] = l;
      return;
    }
    int md = (l + r) >> 1;
    init(a, (u << 1), l, md);
    init(a, (u << 1 | 1), md + 1, r);
    up(u);
  }
  void upd(int id, long long w, int u = 1, int l = 1, int r = n) {
    if (l == r) {
      mn[u] = w;
      return;
    }
    int md = (l + r) >> 1;
    id <= md ? upd(id, w, (u << 1), l, md)
             : upd(id, w, (u << 1 | 1), md + 1, r);
    up(u);
  }
  pair<long long, int> qry(int el, int er, int u = 1, int l = 1, int r = n) {
    if (l >= el && r <= er) return {mn[u], fm[u]};
    int md = (l + r) >> 1;
    pair<long long, int> res = {inf, 0};
    if (el <= md) res = qry(el, er, (u << 1), l, md);
    if (er > md) {
      pair<long long, int> tmp = qry(el, er, (u << 1 | 1), md + 1, r);
      if (res.first > tmp.first) res = tmp;
    }
    return res;
  }
};
segment_tree tr1, tr2;
struct union_find {
  int sz, pr[nsz + 5];
  int inline operator[](int id) { return qry(id); }
  void inline init(int sz = n) {
    this->sz = sz;
    for (int u = 1; u <= n; ++u) pr[u] = u;
  }
  int qry(int u) { return pr[u] == u ? u : pr[u] = qry(pr[u]); }
  bool inline link(int u, int v) {
    int pu = qry(u), pv = qry(v);
    if (pu == pv) return 0;
    pr[pv] = pu;
    return 1;
  }
};
union_find uf;
long long inline w(int u, int v) {
  if (u < v) swap(u, v);
  return w1[u] + w2[v];
}
long long inline kruskal(vector<pair<int, pair<int, int> > > &e = ::e) {
  int cnt = 0;
  long long res = 0;
  uf.init();
  sort(e.begin(), e.end());
  for (int i = 0; i < e.size(); ++i) {
    int u = e[i].second.first, v = e[i].second.second;
    long long w = e[i].first;
    if (uf.link(u, v)) {
      res += w;
      if (++cnt == n - 1) break;
    }
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &d);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    dat[i] = make_pair(a[i], i);
    w1[i] = (long long)a[i] + (long long)d * i;
    w2[i] = (long long)a[i] - (long long)d * i;
  }
  sort(dat + 1, dat + n + 1);
  tr1.init(w1);
  tr2.init(w2);
  for (int i = n; i >= 1; --i) {
    int u = dat[i].second, v1 = u != 1 ? tr2.qry(1, u - 1).second : 0,
        v2 = u != n ? tr1.qry(u + 1, n).second : 0;
    if (v1) e.push_back({w(u, v1), {u, v1}});
    if (v2) e.push_back({w(u, v2), {u, v2}});
    tr1.upd(u, inf);
    tr2.upd(u, inf);
  }
  printf("%lld\n", kruskal());
}
