#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <utility>
#define LL long long
using namespace std;
const LL Maxn = 200010;
const LL inf = 1ll<<60; ///
LL n, DD, a[Maxn];
LL fa[Maxn], lef[Maxn], rig[Maxn];
bool v[Maxn];
pair <LL, LL> seg[Maxn<<2], none;
LL ff(LL x) { return fa[x] == x ? x : fa[x] = ff(fa[x]); }
vector <LL> vec[Maxn];
pair <LL, LL> D[Maxn];
struct lnode {
	LL x, y, d;
	bool operator<(const lnode &A) const { return d < A.d; }
}lis[Maxn]; LL ll;
pair <LL, LL> _min(pair <LL, LL> x, pair <LL, LL> y) { return x < y ? x : y; }
pair <LL, LL> qry(LL now, LL L, LL R, LL l, LL r) {
	if(l > r) return none;
	if(L == l && R == r) return seg[now];
	LL mid = L+R>>1, lc = now<<1, rc = now<<1|1;
	if(r <= mid) return qry(lc, L, mid, l, r);
	else if(l > mid) return qry(rc, mid+1, R, l, r);
	else return _min(qry(lc, L, mid, l, mid), qry(rc, mid+1, R, mid+1, r));
}
void chg(LL now, LL L, LL R, LL x, LL k) {
	if(L == R){ seg[now].first = k; return; }
	LL mid = L+R>>1, lc = now<<1, rc = now<<1|1;
	if(x <= mid) chg(lc, L, mid, x, k);
	else chg(rc, mid+1, R, x, k);
	seg[now] = _min(seg[lc], seg[rc]);
}
void build_tree1(LL now, LL L, LL R) {
	if(L < R){
		LL mid = L+R>>1, lc = now<<1, rc = now<<1|1;
		build_tree1(lc, L, mid);
		build_tree1(rc, mid+1, R);
		seg[now] = _min(seg[lc], seg[rc]);
	} else {
		seg[now].first = lef[L];
		seg[now].second = L;
	}
}
void build_tree2(LL now, LL L, LL R) {
	if(L < R){
		LL mid = L+R>>1, lc = now<<1, rc = now<<1|1;
		build_tree2(lc, L, mid);
		build_tree2(rc, mid+1, R);
		seg[now] = _min(seg[lc], seg[rc]);
	} else {
		seg[now].first = rig[L];
		seg[now].second = L;
	}
}
int main() {
	LL i, j, k;
	scanf("%lld%lld", &n, &DD);
	for(i = 1; i <= n; i++) scanf("%lld", &a[i]), lef[i] = a[i]-i*DD, rig[i] = a[i]+i*DD;
	for(i = 1; i <= n; i++) fa[i] = i;
	none.first = inf; none.second = 0;
	LL sum = n, ans = 0;
	while(sum > 1){
		for(i = 1; i <= n; i++) vec[i].clear();
		for(i = 1; i <= n; i++) vec[ff(i)].push_back(i);
		for(i = 1; i <= n; i++) D[i].first = inf;
		ll = 0;
		build_tree1(1, 1, n);
		for(i = 1; i <= n; i++){
			if(vec[i].size() == 0) continue;
			for(j = 0; j < vec[i].size(); j++){
				LL x = vec[i][j];
				chg(1, 1, n, x, inf);
			}
			for(j = 0; j < vec[i].size(); j++){
				LL x = vec[i][j];
				pair <LL, LL> p = qry(1, 1, n, 1, x-1);
				p.first += rig[x];
				D[i] = _min(D[i], p);
			}
			for(j = 0; j < vec[i].size(); j++){
				LL x = vec[i][j];
				chg(1, 1, n, x, lef[x]);
			}
		}
		build_tree2(1, 1, n);
		for(i = 1; i <= n; i++){
			if(vec[i].size() == 0) continue;
			for(j = 0; j < vec[i].size(); j++){
				LL x = vec[i][j];
				chg(1, 1, n, x, inf);
			}
			for(j = 0; j < vec[i].size(); j++){
				LL x = vec[i][j];
				pair <LL, LL> p = qry(1, 1, n, x+1, n);
				p.first += lef[x];
				D[i] = _min(D[i], p);
			}
			for(j = 0; j < vec[i].size(); j++){
				LL x = vec[i][j];
				chg(1, 1, n, x, rig[x]);
			}
			if(D[i].first < inf){
				ll++;
				lis[ll].x = D[i].second; lis[ll].y = i; lis[ll].d = D[i].first;
			}
		}
		sort(lis+1, lis+ll+1);
		for(i = 1; i <= ll; i++){
			LL fx = ff(lis[i].x), fy = ff(lis[i].y);
			if(fx != fy){
				fa[fx] = fy;
				ans += lis[i].d;
			}
		}
		sum = 0;
		for(i = 1; i <= n; i++) if(fa[i] == i) sum++;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 53348