#include<tuple>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

struct UnionFind {
    int n, cc, *u;
    UnionFind() : n(0), cc(0), u(NULL) {}
    UnionFind(int n_) : n(n_), cc(n_) {
	u = new int[n_];
	memset(u, -1, sizeof (int) * n);
    }
    UnionFind(const UnionFind &y) : n(y.n), cc(y.cc) {
	u = new int[y.n];
	memcpy(u, y.u, sizeof (int) * n);
    }
    ~UnionFind() {
	delete[] u; u = NULL;
	n = cc = 0;
    }
    friend void swap(UnionFind &x, UnionFind &y) {
	swap(x.n, y.n); swap(x.cc, y.cc); swap(x.u, y.u);
    }
    UnionFind& operator=(UnionFind y) { 
	swap(*this, y);
	return *this;
    }
    int root(int x) {
	int y = x, t;
	while (u[y] >= 0) y = u[y];
	while (x != y) { t = u[x]; u[x] = y; x = t; }
	return y;
    }
    bool link(int x, int y) {
	x = root(x); y = root(y);
	if (x == y) return false;
	if (u[y] < u[x]) swap(x, y);
	u[x] += u[y]; u[y] = x; cc--;
	return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int size(int x) { return -u[root(x)]; }
    int count() { return cc; }
};
template<class T> struct RMQ {
    static const int npos = -1;

    int n, m;
    vector<T> d;
    RMQ() {}
    RMQ(int n_, const T init=T()) : n(n_), m(2<<__lg(max(1, n))), d(2*m, init) {}
    template<class Iter> void build(Iter begin, Iter end, const T init=T()) {
	n = end - begin;
	m = 2<<__lg(max(1, n));
	d.resize(2*m);
	for (int i=0; begin!=end; ++begin, i++) d[i+m] = *begin;
	for (int i=n; i<m; i++) d[i+m] = init;
	for (int i=m; --i; ) d[i] = min(d[i*2+1], d[i*2]);
    };

    const T at(int i) const { return d[i+m]; }

    void modify(int i, const T v) {
	i += m; d[i] = v;
	for (i>>=1; i; i>>=1) d[i] = min(d[i*2+1], d[i*2]);
    }

    T min_v(int l, int r) const {
	l += m; r += m;
	T ret = d[l++];
	for (; l<r; l>>=1, r>>=1) {
	    if (l & 1) { amin(ret, d[l]); l++; }
	    if (r & 1) { r--; amin(ret, d[r]); }
	}
	return ret;
    }

    int min_i(int l, int r) const {
	return first_less_equal(l, min_v(l, r));
    }

    pair<T, int> min_vi(int l, int r) const {
	T t = min_v(l, r);
	return make_pair(t, first_less_equal(l, t));
    }

    // for i in [l .. n-1]:
    //   if at(i) < v: return i;
    // return npos;
    int first_less_than(int l, const T v) const {
	int r = 2*m;
	for (l+=m; l<r; l>>=1, r>>=1) {
	    if (l & 1) {
		if (d[l] < v) break;
		l++;
	    }
	}
	if (l >= r) return npos;
	for (; l<m;) {
	    if (d[l*2] < v) l = l*2;
	    else l = l*2+1;
	}
	return l - m;
    }

    // for i in [l .. n-1]:
    //   if at(i) <= v: return i;
    // return npos;
    int first_less_equal(int l, const T v) const { 
	int r = 2*m;
	for (l+=m; l<r; l>>=1, r>>=1) {
	    if (l & 1) {
		if (d[l] <= v) break;
		l++;
	    }
	}
	if (l >= r) return npos;
	for (; l<m;) {
	    if (d[l*2] <= v) l = l*2;
	    else l = l*2+1;
	}
	return l - m;
    }


    // for i in [r-1 .. 0]:
    //   if at(i) < v: return i;
    // return npos;
    int last_less_than(int r, const T v) const {
	if (r < m) {
	    for (r+=m; 1<r; r>>=1) {
		if (r & 1) {
		    r--;
		    if (d[r] < v) break;
		}
	    }
	    if (r <= 1) return npos;
	} else {
	    if (d[1] < v) r = 1;
	    else return npos;
	}
	for (; r<m; ) {
	    if (d[r*2+1] < v) r = r*2+1;
	    else r = r*2;
	}
	return r - m;
    }

    // for i in [r-1 .. 0]:
    //   if at(i) < v: return i;
    // return npos;
    int last_less_equal(int r, const T v) const { 
	if (r < m) { 
	    for (r+=m; 1<r; r>>=1) {
		if (r & 1) {
		    r--;
		    if (d[r] <= v) break;
		}
	    }
	    if (r <= 1) return npos;
	} else {
	    if (d[1] <= v) r = 1;
	    else return npos;
	}
	for (; r<m; ) {
	    if (d[r*2+1] <= v) r = r*2+1;
	    else r = r*2;
	}
	return r - m;
    }
};

const int MAXN = 200011;
const LL INF = 1LL<<60;
int N;
LL D;
LL A[MAXN];
VI G[MAXN];

void MAIN() {
    scanf("%d%lld", &N, &D);
    REP (i, N) scanf("%lld", A+i);

    UnionFind U(N);
    RMQ<LL> Fp(N), Fm(N);
    REP (i, N) {
	Fp.modify(i, A[i] + i*D);
	Fm.modify(i, A[i] - i*D);
	G[i].push_back(i);
    }

    LL ans = 0;

    while (U.count() > 1) {
	using Tuple = tuple<LL, int, int>;
	vector<Tuple> z;

	REP (i, N) if (U.root(i) == i) {
	    EACH (e, G[i]) {
		Fp.modify(*e, INF);
		Fm.modify(*e, INF);
	    }

	    EACH (e, G[i]) {
		{
		    pair<LL, int> p = (*e < N? Fp.min_vi(*e, N): make_pair(INF, -1));
		    if (p.first < INF) {
			z.emplace_back(p.first + A[*e] - *e*D, *e, p.second);
		    }
		}
		{
		    pair<LL, int> m = (0 < *e? Fm.min_vi(0, *e): make_pair(INF, -1));
		    if (m.first < INF) {
			z.emplace_back(m.first + A[*e] + *e*D, *e, m.second);
		    }
		}
	    }

	    EACH (e, G[i]) {
		Fp.modify(*e, A[*e] + *e*D);
		Fm.modify(*e, A[*e] - *e*D);
	    }
	}

	sort(z.begin(), z.end());
	EACH (e, z) {
	    LL cst;
	    int x, y;
	    tie(cst, x, y) = *e;
	    if (!U.same(x, y)) {
		ans += cst;

		x = U.root(x);
		y = U.root(y);
		U.link(x, y);
		int r = U.root(x);
		if (x == r) G[x].insert(G[x].end(), G[y].begin(), G[y].end());
		else G[y].insert(G[y].end(), G[x].begin(), G[x].end());
	    }
	}
    }

//    REP (i, N) if (U.root(i) == i) rprintf("%d", G[i].begin(), G[i].end());

    printf("%lld\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}

