// Slower C++ solution:
#include<vector>

#include<cstdio>

#include<cstdlib>

#include<iostream>

#include<cstring>

#include<algorithm>

#define LL long long

using namespace std;

const LL inf=1LL<<60;

LL n,d,a[200010];

struct node{

	LL c1,c2,k1,k2;

	node() {}

	node(LL a,LL b,LL c,LL d) {c1=a;c2=b;k1=c;k2=d;}

};

LL fa[200010];

LL findfa(LL x) {return fa[x]==x?x:fa[x]=findfa(fa[x]);}

struct Node{

	LL x,y,c;

}e[200010];LL len=0;

struct trnode{

	LL lc,rc;

	node c;

}tr[400010];LL tot=0;

node update(node lc,node rc)

{

	node c;

	c.c1=min(lc.c1,rc.c1);

	c.k1=lc.c1<rc.c1?lc.k1:rc.k1;

	c.k2=lc.c2<rc.c2?lc.k2:rc.k2;

	c.c2=min(lc.c2,rc.c2);

	return c;

}

void change(LL x,LL l,LL r,LL k,node c)

{

	if(l==r) {tr[x].c=c;return;}

	LL mid=(l+r)/2;

	if(k<=mid) change(tr[x].lc,l,mid,k,c);

	else change(tr[x].rc,mid+1,r,k,c);

	tr[x].c=update(tr[tr[x].lc].c,tr[tr[x].rc].c);

}

node findans(LL x,LL l,LL r,LL fl,LL fr)

{

	if(fl>fr) return node(inf,inf,1,1);

	if(l==fl&&r==fr) return tr[x].c;

	LL mid=(l+r)/2;

	if(fr<=mid) return findans(tr[x].lc,l,mid,fl,fr);

	if(fl>mid) return findans(tr[x].rc,mid+1,r,fl,fr);

	return update(findans(tr[x].lc,l,mid,fl,mid),findans(tr[x].rc,mid+1,r,mid+1,fr));

}

LL bt(LL l,LL r)

{

	LL x=++tot;

	if(l!=r)

	{

		LL mid=(l+r)/2;

		tr[x].lc=bt(l,mid);

		tr[x].rc=bt(mid+1,r);

		tr[x].c=update(tr[tr[x].lc].c,tr[tr[x].rc].c);

	}

	else tr[x].c=node(l*d+a[l],-l*d+a[l],l,l);

	return x;

}

vector<int> vec[200010];

bool cmp(Node a,Node b) {return a.c<b.c;}

bool vis[200010];

int main()

{

	scanf("%lld %lld",&n,&d);

	for(LL i=1;i<=n;i++) fa[i]=i;

	for(LL i=1;i<=n;i++) scanf("%lld",&a[i]);

	bt(1,n);LL num=n;

	LL ans=0;

	while(num!=1)

	{

		memset(vis,false,sizeof(vis));

		for(LL i=1;i<=n;i++) vec[i].clear();

		for(LL i=1;i<=n;i++) vec[findfa(i)].push_back(i);

		len=0;

		for(LL i=1;i<=n;i++)

			if(findfa(i)==i)

			{

				for(LL j=0;j<vec[i].size();j++)

				{

					LL y=vec[i][j];

					change(1,1,n,y,node(inf,inf,y,y));

				}

				for(LL j=0;j<vec[i].size();j++)

				{

					LL y=vec[i][j];

					node c1=findans(1,1,n,1,y-1);

					node c2=findans(1,1,n,y+1,n);

					LL C1=c1.c2+y*d+a[y],C2=c2.c1-y*d+a[y];

					if(C1<C2) e[++len].x=i,e[len].y=c1.k2,e[len].c=C1;

					else e[++len].x=i,e[len].y=c2.k1,e[len].c=C2;

				}

				for(LL j=0;j<vec[i].size();j++)

				{

					LL y=vec[i][j];

					change(1,1,n,y,node(y*d+a[y],-y*d+a[y],y,y));

				}

			}

		sort(e+1,e+len+1,cmp);

		for(LL i=1;i<=len;i++)

		{

			LL tx=findfa(e[i].x),ty=findfa(e[i].y);

			if(vis[tx]) continue;

			vis[tx]=true;

			if(tx!=ty)

			{

				ans+=e[i].c;

				fa[tx]=ty;num--;

			}

		}

	}

	printf("%lld",ans);

}

// Faster C++ solution for the same problem (measured speedup: 33.991305208643325x):
#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<algorithm>

#include<cmath>

#include<queue>

#include<vector>

#include<ctime>

#include<map>

#include<bitset>

#include<set>

#define LL long long

#define mp(x,y) make_pair(x,y)

#define pll pair<long long,long long>

#define pii pair<int,int>

#define lc now<<1

#define rc now<<1|1

using namespace std;

inline int read()

{

	int f=1,x=0;char ch=getchar();

	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}

	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}

	return x*f;

}

int stack[20];

inline void write(LL x)

{

	if(x<0){putchar('-');x=-x;}

    if(!x){putchar('0');return;}

    int top=0;

    while(x)stack[++top]=x%10,x/=10;

    while(top)putchar(stack[top--]+'0');

}

inline void pr1(int x){write(x);putchar(' ');}

inline void pr2(LL x){write(x);putchar('\n');}

const LL inf=1e18;

const int MAXN=200005;

int n,D,a[MAXN];

struct node

{

	int p;LL c;

	node(){}

	node(int _p,LL _c){p=_p;c=_c;}

};

node _min(node u1,node u2){return u1.c<u2.c?u1:u2;}

struct segtree1

{

	node mn[2][MAXN*4];

	void buildtree(int now,int l,int r)

	{

		if(l==r){mn[0][now]=mn[1][now]=node(l,inf);return ;}

		int mid=(l+r)/2;

		buildtree(lc,l,mid);buildtree(rc,mid+1,r);

		mn[0][now]=mn[1][now]=_min(mn[0][lc],mn[1][rc]);

	}

	void modify(int now,int l,int r,int p,node c,int opt)

	{

		if(l==r){mn[opt][now]=c;return ;}

		int mid=(l+r)/2;

		if(p<=mid)modify(lc,l,mid,p,c,opt);

		else modify(rc,mid+1,r,p,c,opt);

		mn[opt][now]=_min(mn[opt][lc],mn[opt][rc]);

	}

	node qry(int now,int l,int r,int ql,int qr,int opt)//0 左边   1 右边 

	{

		if(l==ql&&r==qr)return mn[opt][now];

		int mid=(l+r)/2;

		if(qr<=mid)return qry(lc,l,mid,ql,qr,opt);

		else if(mid+1<=ql)return qry(rc,mid+1,r,ql,qr,opt);

		else return _min(qry(lc,l,mid,ql,mid,opt),qry(rc,mid+1,r,mid+1,qr,opt));

	}

}seg1,seg2;//1  未加入   2  加入 

struct segtree2

{

	node mn[MAXN*4];

	void buildtree(int now,int l,int r)

	{

		if(l==r){mn[now]=node(l,inf);return ;}

		int mid=(l+r)/2;

		buildtree(lc,l,mid);buildtree(rc,mid+1,r);

		mn[now]=_min(mn[lc],mn[rc]);

	}

	void pushup(int now,int l,int r)

	{

		int mid=(l+r)/2;

		mn[now]=_min(mn[lc],mn[rc]);

		node u1=seg1.mn[0][lc],u2=seg2.mn[1][rc];

//		u1=seg1.qry(1,1,n,l,mid,0),u2=seg2.qry(1,1,n,mid+1,r,1);

		mn[now]=_min(mn[now],node(u1.p,u1.c+u2.c));

		u1=seg1.mn[1][rc],u2=seg2.mn[0][lc];

//		u1=seg1.qry(1,1,n,mid+1,r,1),u2=seg2.qry(1,1,n,l,mid,0);

		mn[now]=_min(mn[now],node(u1.p,u1.c+u2.c));

	}

	void modify(int now,int l,int r,int p)

	{

		if(l==r){mn[now].c=inf;return ;}

		int mid=(l+r)/2;

		if(p<=mid)modify(lc,l,mid,p);

		else modify(rc,mid+1,r,p);

		pushup(now,l,r);

	}

}seg3;

int main()

{

	n=read();D=read();

	if(n==1)return puts("0"),0;

	for(int i=1;i<=n;i++)a[i]=read();

	seg1.buildtree(1,1,n);

	seg2.buildtree(1,1,n);

	seg3.buildtree(1,1,n);

	for(int i=2;i<=n;i++)

	{

		seg1.modify(1,1,n,i,node(i,(LL)-D*i+a[i]),0);

		seg1.modify(1,1,n,i,node(i,(LL)D*i+a[i]),1);

	}

	seg2.modify(1,1,n,1,node(1,(LL)-D*1+a[1]),0);

	seg2.modify(1,1,n,1,node(1,(LL)D*1+a[1]),1);

	

	seg3.modify(1,1,n,1);

	LL ans=0;

	for(int i=1;i<n;i++)

	{

		ans+=seg3.mn[1].c;

		int u=seg3.mn[1].p;

		seg1.modify(1,1,n,u,node(u,inf),0);seg1.modify(1,1,n,u,node(u,inf),1);

		seg2.modify(1,1,n,u,node(u,(LL)-D*u+a[u]),0);seg2.modify(1,1,n,u,node(u,(LL)D*u+a[u]),1);

		seg3.modify(1,1,n,u);

	}

	pr2(ans);

	return 0;

}