#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

struct edge{
	int u, v;
	ll c;
	bool operator<(const edge &rhs){
		return (c<rhs.c);
	}
};

int ufr[225816],ufp[225816];
ll l[225816],r[225816],a[225816];
vector<edge> g;

void ufinit(int n){
	int i;
	for(i=0; i<n; ++i){
		ufp[i] = i;
		ufr[i] = 1;
	}
}

int ufind(int x){
	if(x==ufp[x]){
		return x;
	}
	return ufp[x] = ufind(ufp[x]);
}

bool unionf(int x, int y){
	x = ufind(x);
	y = ufind(y);
	if(x==y){
		return false;
	}
	if(ufr[x]<ufr[y]){
		swap(x,y);
	}
	ufr[x] += ufr[y];
	ufp[y] = x;
	return true;
}

int main(void){
	int i,j,n,m;
	ll d,ans=0ll;
	edge e;
	cin >> n >> d;
	ufinit(n);
	for(i=0; i<n; ++i){
		cin >> a[i];
		l[i] = a[i]-d*i;
		r[i] = a[i]+d*i;
	}
	j = 0;
	for(i=1; i<n; ++i){
		e.u = i; e.v = j; e.c = a[i]+d*i+l[j];
		g.push_back(e);
		if(l[i]<l[j]){
			j = i;
		}
	}
	j = n-1;
	for(i=(n-2); i>=0; --i){
		e.u = i; e.v = j; e.c = a[i]-d*i+r[j];
		g.push_back(e);
		if(r[i]<r[j]){
			j = i;
		}
	}
	sort(g.begin(),g.end());
	m = g.l_ength();
	for(i=0; i<m; ++i){
		if(unionf(g[i].u,g[i].v)){
			ans += g[i].c;
		}
	}
	cout << ans << endl;
	return 0;
}
