/*
{By GWj
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
const LL INF=1e18;
typedef pair<int,int> mp;
/*}
*/
const int N=1<<18;
struct SEGTREE{
	pair<LL,int> tree[N*2];
	LL a[N*2];
	void modify(int index,LL val){
		index+=N-1;
		tree[index]=II(val,index-N+1);
		index>>=1;
		while(index){
			tree[index]=min(tree[index<<1],tree[index<<1|1]);
			index>>=1;
		}
	}
	void build(){
		rl(i,N+N-1,1){
			if(i>=N){
				tree[i].FIR=a[i-N+1];
				tree[i].SEC=i-N+1;
			}
			else{
				tree[i]=min(tree[i<<1],tree[i<<1|1]);
			}
		}
	}
	pair<LL,int> query(int a,int b,int now=1,int l=1,int r=N+1){
		if(r<=a||l>=b){
			return II(INF,INF);
		}
		if(r<=b&&l>=a){
			return tree[now];
		}
		int mid=(l+r)>>1;
		return min(query(a,b,now<<1,l,mid),query(a,b,now<<1|1,mid,r));
	}
}tree1,tree2;//维护Aj-j*D | Aj+j*D 
int n,d,a[N+1];
bool cleared[N+1];
void my_clear(int index){
	cleared[index]=1;
	tree1.modify(index,INF);
	tree2.modify(index,INF); 
}
int fa[200000+1];
vector<int> have[200000+1];
int root(int x){
	if(fa[x]==x) return x;
	return fa[x]=root(fa[x]);
}
void merge(int u,int v){
	u=root(u);
	v=root(v);
	if(have[u].size()>have[v].size()){
		for(auto it:have[v]){
			have[u].PB(it);
		}
		fa[v]=u;
		have[v].clear();
	}
	else{
		for(auto it:have[u]){
			have[v].PB(it);
		}
		fa[u]=v;
		have[u].clear();
	}
}
vector<mp> vv; 
vector<int> g[200000+1];
bool vis[200000+1];
LL cost(int i,int j){
	return 1ll*abs(i-j)*d+a[i]+a[j];
}
LL MST(){
	priority_queue<pair<LL,int>,vector<pair<LL,int> > ,greater<pair<LL,int> > > q;
	q.push(II(0ll,1));
	LL rest=0;
	while(!q.empty()){
		pair<LL,int> now=q.top();
		if(vis[now.SEC]){
			q.pop();
			continue;
		}
		q.pop();
		rest+=now.FIR;
		vis[now.SEC]=1;
		for(auto it:g[now.SEC]){
			q.push(II(cost(it,now.SEC),it));
		}
	}
	return rest; 
}
int main(){
	fastio;
	R2(n,d);
	rb(i,1,n)
		fa[i]=i,have[i].PB(i);
	rb(i,1,n){
		R(a[i]); 
		vv.PB(II(a[i],i));
	} 
	memset(tree1.a,127,sizeof(tree1.a));
	memset(tree2.a,127,sizeof(tree2.a));
	sort(ALL(vv));
	tree1.build();
	tree2.build();
	rb(i,1,n){
		pair<LL,int > best=II(INF,INF);
		if(vv[i-1].SEC!=1){
			pair<LL,int> tmp=tree2.query(1,vv[i-1].SEC);
			tmp.FIR+=1ll*vv[i-1].SEC*d+vv[i-1].FIR;
			best=tmp;
			if(best.FIR<1e15){
				g[vv[i-1].SEC].PB(best.SEC);
				g[best.SEC].PB(vv[i-1].SEC);
			}
		}
		if(vv[i-1].SEC!=n){
			pair<LL,int> tmp=tree1.query(vv[i-1].SEC+1,n+1);
			tmp.FIR+=-1ll*vv[i-1].SEC*d+vv[i-1].FIR;
			best=tmp;
			if(best.FIR<1e15){
				g[vv[i-1].SEC].PB(best.SEC);
				g[best.SEC].PB(vv[i-1].SEC);
			}
		}//
//		if(best.FIR<1e15){
//			g[vv[i-1].SEC].PB(best.SEC);
//			g[best.SEC].PB(vv[i-1].SEC);
//		}
		tree1.modify(vv[i-1].SEC,1ll*vv[i-1].SEC*d+vv[i-1].FIR);
		tree2.modify(vv[i-1].SEC,-1ll*vv[i-1].SEC*d+vv[i-1].FIR);
	}
	cout<<MST()<<endl;
	return 0;
}

Measured memory_bytes: 64540