There are N cities in Republic of AtCoder. The size of the i-th city is A_{i}. Takahashi would like to build N-1 bidirectional roads connecting two cities so that any city can be reached from any other city by using these roads.

Assume that the cost of building a road connecting the i-th city and the j-th city is |i-j| \times D + A_{i} + A_{j}. For Takahashi, find the minimum possible total cost to achieve the objective.

Constraints

* 1 \leq N \leq 2 \times 10^5
* 1 \leq D \leq 10^9
* 1 \leq A_{i} \leq 10^9
* A_{i} and D are integers.

Input

Input is given from Standard Input in the following format:


N D
A_1 A_2 ... A_N


Output

Print the minimum possible total cost.

Examples

Input

3 1
1 100 1


Output

106


Input

3 1000
1 100 1


Output

2202


Input

6 14
25 171 7 1 17 162


Output

497


Input

12 5
43 94 27 3 69 99 56 25 8 15 46 8


Output

658
#include<cstdio>
#include<algorithm>

using int64=long long;
using uchar=unsigned char;

constexpr int maxn(200000);
constexpr int64 inf(1e17);

template<class _Tp>
	inline bool bchkMin(_Tp&x,const _Tp&y)
		{return(x>y)&&(x=y,1);}

namespace IOManager{
	constexpr int FILESZ(131072);
	char buf[FILESZ];
	const char*ibuf=buf,*tbuf=buf;

	struct IOManager{
		inline char gc()
			{return(ibuf==tbuf)&&(tbuf=(ibuf=buf)+fread(buf,1,FILESZ,stdin),ibuf==tbuf)?EOF:*ibuf++;}

		template<class _Tp>
			inline operator _Tp(){
				_Tp s=0u;char c=gc();
				for(;c<48;c=gc());
				for(;c>47;c=gc())
					s=(_Tp)(s*10u+c-48u);
				return s;
			}
	};
}IOManager::IOManager io;

int sz[maxn+1];
int64 szl[maxn+1],szr[maxn+1];

struct Edge{
	int s,t;int64 w;

	inline void init(const int&is,const int&it,const int64&iw)
		{s=is;t=it;w=iw;}

	inline bool operator<(const Edge&rhs)
		const{return w<rhs.w;}
}e[maxn*30],*cur=e;

void calc(const int&l,const int&r){
	if(l==r)
		return;
	const int m=(l+r)>>1;

	int lmp,rmp;
	int64 lmv=inf,rmv=inf;

	for(int i=l;i<=m;++i)
		if(bchkMin(lmv,szl[i]))
			lmp=i;
	for(int i=m+1;i<=r;++i)
		if(bchkMin(rmv,szr[i]))
			rmp=i;

	for(int i=l;i<=m;++i)
		(++cur)->init(i,rmp,szl[i]+rmv);
	for(int i=m+1;i<=r;++i)
		(++cur)->init(lmp,i,lmv+szr[i]);

	calc(l,m);calc(m+1,r);
}

int ufs[maxn+1];

inline int anc(const int&v)
	{return v==ufs[v]?v:ufs[v]=anc(ufs[v]);}

int main(){
	const int n=io,D=io;
	int64 t=0;
	for(int i=1;i<=n;++i,t+=D)
		ufs[i]=i,
		sz[i]=io,
		szl[i]=sz[i]-t,
		szr[i]=sz[i]+t;

	calc(1,n);
	std::sort(e+1,cur+1);
	int64 ans=0;
	for(Edge*i=e+1;i<=cur;++i)
		if(anc(i->s)!=anc(i->t))
			ans+=i->w,ufs[ufs[i->s]]=ufs[i->t];
	printf("%lld",ans);

	return 0;
}
