#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18;
template <typename T>
struct SegmentTree {
  using F = function<T(T, T)>;
  long long n;
  F f;
  T ti;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(F f, T ti) : f(f), ti(ti) {}
  SegmentTree(F f, T ti, long long n_) : f(f), ti(ti) {
    n = 1;
    while (n < n_) n <<= 1;
    dat.assign(n << 1, ti);
  }
  SegmentTree(F f, T ti, const vector<T> &v) : f(f), ti(ti) {
    long long n_ = v.size();
    n = 1;
    while (n < n_) n <<= 1;
    dat.assign(n << 1, ti);
    for (long long i = 0; i < n_; i++) dat[n + i] = v[i];
    for (long long i = n - 1; i; i--)
      dat[i] = f(dat[(i << 1) | 0], dat[(i << 1), 1]);
  }
  T get(long long x) { return dat[x + n]; }
  void init(long long n_) {
    n = 1;
    while (n < n_) n <<= 1;
    dat.assign(n << 1, ti);
  }
  void build(const vector<T> &v) {
    long long n_ = v.size();
    init(n_);
    for (long long i = 0; i < n_; i++) dat[n + i] = v[i];
    for (long long i = n - 1; i; i--)
      dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
  }
  void set_val(long long k, T x) {
    dat[k += n] = x;
    while (k >>= 1) dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
  }
  T query(long long a, long long b) {
    T vl = ti, vr = ti;
    for (long long l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) vl = f(vl, dat[l++]);
      if (r & 1) vr = f(dat[--r], vr);
    }
    return f(vl, vr);
  }
  template <typename C>
  long long find(long long st, C &check, T &acc, long long k, long long l,
                 long long r) {
    if (l + 1 == r) {
      acc = f(acc, dat[k]);
      return check(acc) ? k - n : -1;
    }
    long long m = (l + r) >> 1;
    if (m <= st) return find(st, check, acc, (k << 1) | 1, m, r);
    if (st <= l && !check(f(acc, dat[k]))) {
      acc = f(acc, dat[k]);
      return -1;
    }
    long long vl = find(st, check, acc, (k << 1) | 0, l, m);
    if (~vl) return vl;
    return find(st, check, acc, (k << 1) | 1, m, r);
  }
  template <typename C>
  long long find(long long st, C &check) {
    T acc = ti;
    return find(st, check, acc, 1, 0, n);
  }
};
struct UnionFind {
  long long num;
  vector<long long> r, p;
  UnionFind() {}
  UnionFind(long long n) : num(n), r(n, 1), p(n, 0) {
    iota(p.begin(), p.end(), 0);
  }
  long long find(long long x) { return (x == p[x] ? x : p[x] = find(p[x])); }
  bool same(long long x, long long y) { return find(x) == find(y); }
  void unite(long long x, long long y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (r[x] < r[y]) swap(x, y);
    r[x] += r[y];
    p[y] = x;
    num--;
  }
  long long size(long long x) { return r[find(x)]; }
  long long count() const { return num; }
};
signed main() {
  long long n, d;
  cin >> n >> d;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  auto f = [](pair<long long, long long> a, pair<long long, long long> b) {
    return min(a, b);
  };
  SegmentTree<pair<long long, long long> > segl(
      f, pair<long long, long long>(LINF, -1), n),
      segr(f, pair<long long, long long>(LINF, -1), n);
  for (long long i = 0; i < n; i++) {
    segl.set_val(i, pair<long long, long long>(v[i] + (n - 1 - i) * d, i));
    segr.set_val(i, pair<long long, long long>(v[i] + i * d, i));
  }
  vector<pair<pair<long long, long long>, long long> > edge;
  for (long long i = 0; i < n; i++) {
    pair<long long, long long> p = segl.query(0, i);
    if (~p.second) {
      p.first += v[i] - (n - 1 - i) * d;
      edge.push_back(pair<pair<long long, long long>, long long>(p, i));
    }
    p = segr.query(i + 1, n);
    if (~p.second) {
      p.first += v[i] - i * d;
      edge.push_back(pair<pair<long long, long long>, long long>(p, i));
    }
  }
  UnionFind uf(n);
  sort(edge.begin(), edge.end());
  long long ans = 0;
  for (auto p : edge) {
    long long c = p.first.first, u = p.first.second, v = p.second;
    if (uf.same(u, v)) continue;
    uf.unite(u, v);
    ans += c;
  }
  cout << ans << endl;
}
