/*
 * RD
*/
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#ifndef rd
#define endl '\n'
#endif
#define deb cout<<"Line: "<<__LINE__<<" plz "
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
#define pii pair<int,int>
#define sz(x) ((int)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define all(con) con.begin(),con.end()
const ll inf=1e18;
const int mod=1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//12367769,266916112,123798211
ll powm(ll a, ll b, ll m);

int n,d;
pii segtree1[400005];
pii segtree2[400005];
pii query1(int l, int r)
{
	r++;
	pii res={inf+1,inf};
	for(l+=n+1,r+=n+1; l<r; l>>=1,r>>=1)
	{
		if(l&1) res=min(res,segtree1[l++]);
		if(r&1) res=min(res,segtree1[--r]);
	}
	return res;
}
pii query2(int l, int r)
{
	r++;
	pii res={inf+1,inf};
	for(l+=n+1,r+=n+1; l<r; l>>=1,r>>=1)
	{
		if(l&1) res=min(res,segtree2[l++]);
		if(r&1) res=min(res,segtree2[--r]);
	}
	return res;
}
int a[200005];
int solve(int l, int r, int l1, int r1)
{
	if(l+1==r)
		return 0;
	pii lef=query1(l+1,r-1);
	pii rig=query2(l+1,r-1);
//	deb<<l<<" "<<r<<endl;
//	deb<<lef.fi<<" "<<lef.se<<" "<<rig.fi<<" "<<rig.se<<endl;
	ll ans=0;
	if(lef.fi+a[l1]-l1*d>rig.fi+a[r1]+r1*d)
	{
		ans+=rig.fi+a[r1]+r1*d;
		lef=rig;
	}
	else
		ans+=lef.fi+a[l1]-l1*d;
	if(a[lef.se]+lef.se*d<a[r1]+r1*d)
		ans+=solve(l,lef.se,l1,lef.se);
	else
		ans+=solve(l,lef.se,l1,r1);
	if(a[lef.se]-lef.se*d<a[l1]-l1*d)
		ans+=solve(lef.se,r,lef.se,r1);
	else
		ans+=solve(lef.se,r,l1,r1);
	return ans;
}
void solve()
{
	cin>>n>>d;
	for(int i=0; i<n; i++)
		cin>>a[i];
	a[n]=inf;
	for(int i=n+1; i<2*n+2; i++)
	{
		segtree1[i]={a[i-n-1]+(i-n-1)*d,i-n-1};
		segtree2[i]={a[i-n-1]-((i-n-1)*d),i-n-1};
	}
	for(int i=n; i>0; i--) {
		segtree1[i]=min(segtree1[i<<1],segtree1[i<<1|1]);
		segtree2[i]=min(segtree2[i<<1],segtree2[i<<1|1]);
	}
	cout<<solve(0,n,0,n)<<endl;
}
signed main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	auto clk=clock();
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}
ll powm(ll a,ll b, ll m) {
	ll te=1;
	while(b) {
		if(b&1) te=(te*a)%m;
		a=(a*a)%m;
		b>>=1;
	}
	return te;
}

#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;
}
