#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}


class UnionFind{
	vector<int> par,siz;
	//0-indexed
	void init(int n){
		component = n;
		par.resize(n);
		for(int i=0;i<n;++i)par[i]=i;
		siz.resize(n,1);
		msiz = 1;
	}
public:
	int msiz,component;
	UnionFind(int n_){init(n_);}
	int root(int x){
		if(par[x]==x)return x;
		return par[x] = root(par[x]);
	}
	void unite(int x,int y){
		x = root(x);
		y = root(y);
		if(x==y)return;
		siz[y] += siz[x];
		siz[x] = 0;
		par[x] = y;
		msiz = max(msiz,siz[y]);
		component--;
	}
	int size(int x){
		return siz[root(x)];
	}
	bool same(int x,int y){
		return root(x)==root(y);
	}
};


int main(){


	ll N,D;
	cin >> N >> D;
	vector<ll> A(N);
	FOR(i,0,N) cin >> A[i];

	if(N==1){
		cout << 0 << endl;
		return 0;
	}else if(N==2){
		cout << A[0]+A[1]+D << endl;
		return 0;
	}

	vector<ll> u,v,c;

	vector<int> index(N);
	FOR(i,0,N) index[i] = i;

	stack< vector<int> > Q;
	Q.push(index);

	while(Q.size()){
		vector<int> s1,s0;
		int k1 = Q.top().size() / 2;
		int k0 = Q.top().size() - k1;
		FOR(i,  0 , k0) s0.push_back(Q.top()[i]);
		FOR(i,k0,k1+k0) s1.push_back(Q.top()[i]);

		Q.pop();
		if(s1.size() == 0)continue;

		ll min_cost_0 = INF , i0;
		ll min_cost_1 = INF , i1;
		FOR(i,0,s0.size()){
			if(min_cost_0 > A[s0[i]] - D*s0[i]){
				min_cost_0 = A[s0[i]] - D*s0[i];
				i0 = s0[i];
			}
		}
		FOR(i,0,s1.size()){
			if(min_cost_1 > A[s1[i]] + D*s1[i]){
				min_cost_1 = A[s1[i]] + D*s1[i];
				i1 = s1[i];
			}
		}
		FOR(i,0,s1.size()){
			u.push_back(i0);
			v.push_back(s1[i]);
			c.push_back( D*(s1[i]-i0) + A[i0]+A[s1[i]] );
		}
		FOR(i,0,s0.size()){
			u.push_back(i1);
			v.push_back(s0[i]);
			c.push_back( D*(i1-s0[i]) + A[i1]+A[s0[i]] );
		}


		if(s0.size()>2){
			Q.push(s0);
		}else if(s0.size()==2){
			u.push_back(s0[0]);
			v.push_back(s0[1]);
			c.push_back( abs(s0[0]-s0[1])*D+A[s0[0]]+A[s0[1]] );
		}
		if(s1.size()>2){
			Q.push(s1);
		}else if(s1.size()==2){
			u.push_back(s1[0]);
			v.push_back(s1[1]);
			c.push_back( abs(s1[0]-s1[1])*D+A[s1[0]]+A[s1[1]] );
		}
	}


	vector< pair<ll,pair<int,int>> > X;
	FOR(i,0,u.size()){
		X.push_back( { c[i] , {u[i],v[i]} } );
	}

	SORT(X);

	UnionFind uf(N);
	ll ans = 0;

	FOR(i,0,X.size()){
		int a=X[i].second.first;
		int b=X[i].second.second;
		ll add_ = X[i].first;
		if(not uf.same(a,b)){
			uf.unite(a,b);
			ans += add_;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 185464