#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define mp make_pair
#define lson x<<1
#define rson x<<1|1
#define mid ((l+r)>>1) 
const int INF=0x3f3f3f3f3f3f3f3f;
vector<int>v[200100];
int fa[200100],n,m,val[200100],res;
inline pii operator+(const pii &x,const pii &y){
	return min(x,y);
}
struct SegTree{
	pii p[800100];
	inline void modify(int x,int l,int r,int P,int val){
		if(l>P||r<P)return;
		if(l==r){p[x]=mp(val,l);return;}
		modify(lson,l,mid,P,val),modify(rson,mid+1,r,P,val),p[x]=p[lson]+p[rson];
	}
	inline pii query(int x,int l,int r,int L,int R){
		if(l>R||r<L)return mp(INF,INF);
		if(L<=l&&r<=R)return p[x];
		return query(lson,l,mid,L,R)+query(rson,mid+1,r,L,R);
	}	
}seg[2];
inline int find(int x){
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
inline bool merge(int x,int y){
	x=find(x),y=find(y);
	if(x==y)return false;
	if(v[x].size()<v[y].size())swap(x,y);
	fa[y]=x;
	for(auto i:v[y])v[x].push_back(i);
	v[y].clear();
	return true;
}
struct node{
	int x,y,z;
	inline node(int u=0,int v=0,int w=INF){x=u,y=v,z=w;}
	inline friend bool operator<(const node&u,const node&v){return u.z<v.z;}
};
inline void read(int &x){
	x=0;
	register char c=getchar();
	while(c>'9'||c<'0')c=getchar();
	while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
}
inline void print(int x){
	if(x<=9)putchar('0'+x);
	else print(x/10),putchar('0'+x%10);
}
signed main(){
	read(n),read(m),memset(seg,0x3f,sizeof(seg));
	for(register int i=1;i<=n;i++)read(val[i]),fa[i]=i,v[i].push_back(i),seg[0].modify(1,1,n,i,val[i]-i*m),seg[1].modify(1,1,n,i,val[i]+i*m);
	while(v[find(1)].size()!=n){
		register vector<node>edges;
		for(register int i=1;i<=n;i++){
			if(find(i)!=i)continue;
			register node ed;
//			print(ed.z);putchar('\n');
			for(register auto x:v[i])seg[0].modify(1,1,n,x,INF),seg[1].modify(1,1,n,x,INF);
			for(register auto x:v[i]){
				if(x>1){
					pii p=seg[0].query(1,1,n,1,x-1);
					int y=p.second;
					ed=min(ed,node(y,x,val[y]+val[x]+(x-y)*m));	
				}
				if(x<n){
					pii p=seg[1].query(1,1,n,x+1,n);
					int y=p.second;
					ed=min(ed,node(x,y,val[x]+val[y]+(y-x)*m));	
				}
			} 
			for(register auto x:v[i])seg[0].modify(1,1,n,x,val[x]-x*m),seg[1].modify(1,1,n,x,val[x]+x*m);
			edges.push_back(ed);
		}
		sort(edges.begin(),edges.end());
		for(register auto i:edges)if(merge(i.x,i.y))res+=i.z; 
	}
	print(res);
	return 0;
} 