#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cctype>
#include<vector>
#define int long long
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define mid (l+r>>1)
#define lch (rt<<1)
#define rch (rt<<1|1)
#define pb push_back

using namespace std;
const int N=200005;
typedef long long LL;
const LL INF=100000000000000000;
int n,cnt,top,fa[N];
LL D,a[N],ans;
vector <int> vt[N];
struct data{int x,y;} dat[N<<1];
struct seg{int id; LL mn;} t0[N<<2],t1[N<<2];

int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x;
}

seg operator + (seg x,seg y)
{
	seg rt;
	rt.mn=min(x.mn,y.mn);
	rt.id=x.mn==rt.mn?x.id:y.id;
	return rt;
}

void build(int l,int r,int rt)
{
	if(l==r)
	{
		t0[rt]=(seg){l,a[l]-l*D};
		t1[rt]=(seg){l,a[l]+l*D};
		return;
	}
	build(l,mid,lch);
	build(mid+1,r,rch);
	t0[rt]=t0[lch]+t0[rch];
	t1[rt]=t1[lch]+t1[rch];
}

void ins(int l,int r,int rt,int x,int tp)
{
	if(l==r)
	{
		if(tp)
		{
			t0[rt]=(seg){l,a[l]-l*D};
			t1[rt]=(seg){l,a[l]+l*D};
		}
		else
		{
			t0[rt]=(seg){l,INF};
			t1[rt]=(seg){l,INF};
		}
		return;
	}
	if(x<=mid) ins(l,mid,lch,x,tp);
	else ins(mid+1,r,rch,x,tp);
	t0[rt]=t0[lch]+t0[rch];
	t1[rt]=t1[lch]+t1[rch];
}

seg Ql(int l,int r,int rt,int x)
{
	if(x==1) return (seg){0,INF};
	if(r<=x) return t0[rt];
	if(x<=mid) return Ql(l,mid,lch,x);
	return Ql(l,mid,lch,x)+Ql(mid+1,r,rch,x);
}

seg Qr(int l,int r,int rt,int x)
{
	if(x==n) return (seg){0,INF};
	if(l>=x) return t1[rt];
	if(x>mid) return Qr(mid+1,r,rch,x);
	return Qr(l,mid,lch,x)+Qr(mid+1,r,rch,x);
}	

int getfa(int x)
{
	return fa[x]==x?x:fa[x]=getfa(fa[x]);
}

LL Q(int x,int y)
{
	return D*abs(x-y)+a[x]+a[y];
}

void merge(int x,int y)
{
	LL tmp=Q(x,y);
	x=getfa(x),y=getfa(y);
	if(x!=y) ++cnt,ans+=tmp,fa[x]=y;
}

bool cmp(data a,data b)
{
	return Q(a.x,a.y)<Q(b.x,b.y);
}

void trf()
{
	rep(i,1,n) vt[i].clear();
	rep(i,1,n)
		vt[getfa(i)].pb(i);
}

signed main()
{
	n=getint(),D=getint();
	rep(i,1,n) a[i]=getint();
	build(1,n,1);
	rep(i,1,n) fa[i]=i;
	while(cnt<n-1)
	{
		trf(),top=0;
		rep(i,1,n)
		{
			int sz=vt[i].size()-1;
			rep(j,0,sz) ins(1,n,1,vt[i][j],0);
			rep(j,0,sz)
			{
				seg tmp=Ql(1,n,1,vt[i][j]);
				tmp=tmp+Qr(1,n,1,vt[i][j]);
				if(tmp.mn<INF) dat[++top]=(data){vt[i][j],tmp.id};
			}
			rep(j,0,sz) ins(1,n,1,vt[i][j],1);
		}
		sort(dat+1,dat+1+top,cmp);
		rep(i,1,top) merge(dat[i].x,dat[i].y);
	}
	printf("%lld\n",ans);
	return 0;
}