#include<cassert>
#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 {
    int n;
    vector<T> A; vector<int> I;
    RMQ(int n_=0): n(n_), A(n), I(2*n) {
	for (int i=0; i<n; i++) I[i+n] = i;
	for (int i=n; --i;) I[i] = I[2*i];
    }
    RMQ(const vector<T> &a): n(a.size()), A(a), I(2*n) {
	for (int i=0; i<n; i++) I[i+n] = i;
	for (int i=n; --i;) I[i] = (A[I[i*2+1]] < A[I[i*2]]? I[i*2+1]: I[i*2]);
    }
    void modify(int i, const T &v) {
	A[i] = v;
	for (i+=n; i>>=1;) I[i] = (A[I[i*2+1]] < A[I[i*2]]? I[i*2+1]: I[i*2]);
    }
    int min_i(int x, int y) {
	x += n; y += n;
	int p = -1;
	for (; x<y; x>>=1, y>>=1) {
	    if (y & 1) { --y; if (p < 0 || A[I[y]] < A[p]) p = I[y]; }
	    if (x & 1) { if (p < 0 || A[I[x]] < A[p]) p = I[x]; x++; }
	}
	return p;
    }
    T min_v(int x, int y) { return A[min_i(x, y)]; }
};

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);

//#ifdef LOCAL
//    N = 200000;
//    D = 1000000000;
//    REP (i, N) A[i] = rand() % D;
//#endif

    UnionFind U(N);
    RMQ<LL> Fp(N), Fm(N);
    REP (i, N) {
	assert(1000000000 + i*D < INF);
	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);
	    }

	    Tuple best(INF, 0, 0);
	    EACH (e, G[i]) {
		if (*e+1 < N) {
		    LL p = Fp.min_i(*e+1, N);
		    if (p != -1 && !U.same(*e, p)) 
			amin(best, Tuple((p - *e)*D + A[p] + A[*e], *e, p));
		}
		if (0 < *e) {
		    LL m = Fm.min_i(0, *e);
		    if (m != -1 && !U.same(*e, m))
			amin(best, Tuple((*e - m)*D + A[m] + A[*e], *e, m));
		}
	    }
	    z.push_back(best);

	    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);
		assert(!U.same(x, y));
		assert(U.size(x) == (int)G[x].size());
		assert(U.size(y) == (int)G[y].size());
		U.link(x, y);
		int r = U.root(x);
		if (x == r) G[r].insert(G[r].end(), G[y].begin(), G[y].end());
		else G[r].insert(G[r].end(), G[x].begin(), G[x].end());
		assert(U.size(r) == (int)G[r].size());
	    }
	}
//	REP (i, N) if (U.root(i) == i) {
//	    assert(U.size(i) == (int)G[i].size());
//	}
    }


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

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



Measured memory_bytes: 29628