#include<bits/stdc++.h>
#define N 200020
#define LOGN 20
using namespace std;
int n,d,first[N],nxt[N*LOGN*10],tot=0;
long long Ans,a[N],inf=1e18;
int fa[N],cnt=0;
long long Read()
{
	long long x=0,f=1;
	char c=getchar();
	while (c<'0'||c>'9') 
	{
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0'&&c<='9') 
	{
		x=x*10+c-'0';
		c=getchar();
	}
	return f*x;
}
struct Edge
{
	int u,v,w;
}edge[N*LOGN*10];
bool cmp(const Edge a,const Edge b)
{
	if (a.w<b.w) return true;
	else return false;
}
void Add(int u,int v)
{
	int w=abs(u-v)*d+a[u]+a[v];
	tot++;
	nxt[tot]=first[u];
	first[u]=tot;
	edge[tot]=(Edge){u,v,w};
	return;
}
int Build(int l,int r,int flag)
{
	if (l==r) return l;
	int mid=(l+r)>>1;
	int minl=Build(l,mid,-1),minr=Build(mid+1,r,1);
	for (int i=l;i<=mid;i++) Add(i,minr);
	for (int i=mid+1;i<=r;i++) Add(i,minl);
	long long minlr=inf;
	int point=0;
	for (int i=l;i<=r;i++) 
	    if (i*d*flag+a[i]<minlr) point=i,minlr=i*d*flag+a[i];
	return point;
}
int Get(int x)
{
	if (x==fa[x]) return x;
	else return fa[x]=Get(fa[x]);
}
void Join(int x,int y)
{
	fa[x]=y;
	return;
}
long long Krus()
{
	long long ret=0;
	for (int i=1;i<=n;i++) fa[i]=i;
	sort(edge+1,edge+tot+1,cmp);
	for (int i=1;i<=tot;i++)
	{
		int u=edge[i].u,v=edge[i].v;
		int f1=Get(u),f2=Get(v);
		if (f1!=f2)
		{
			cnt++;
			ret+=1LL*edge[i].w;
			Join(f1,f2);
		}
	}
	return ret;
}
int main()
{
	//freopen("testdata.in","r",stdin);
	memset(first,-1,sizeof(first));
	n=Read(),d=Read();
	for (int i=1;i<=n;i++) a[i]=Read();
	Build(1,n,1);
	Ans=Krus();
	printf("%lld\n",Ans);
	return 0;
}