// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())printf("%d ",v[_]);cout<<"\n";}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")


typedef pii SegT;
const SegT defvalue={inf,inf};
class SegTree{
	private:
		vector<SegT>val;
		int n;
		SegT combine(SegT a,SegT b){return min(a,b);}
	public:
		SegTree(const vector<int> &in){
			n=1;
			while(n<in.size())n<<=1;
			val=vector<SegT>(2*n,defvalue);
			for(int i=n-1+in.size()-1;i>=0;i--){
				if(n-1<=i)val[i]={in[i-(n-1)],i-n+1};
				else val[i]=combine(val[i*2+1],val[i*2+2]);
			}
		}
		void update(int i,SegT a){
			i+=n-1;
			val[i]=a;
			while(i>0){
				i=(i-1)/2;
				val[i]=combine(val[i*2+1],val[i*2+2]);
			}
		}
		SegT query(int a,int b,int k=0,int l=0,int r=-1){//[a,b)
			if(r==-1)r=n;
			if(r<=a||b<=l)return defvalue;
			if(a<=l&&r<=b)return val[k];
			else return combine(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
		}
		void tmp(){
;//			rep(i,val.size())cout<<" "<<val[i];cout<<endl;
		}
};

struct UnionFind{
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return 0;
        if(data[y]<data[x])swap(x,y);
        data[x]+=data[y],data[y]=x;
        return 1;
    }
    bool findSet(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,d;
	cin>>n>>d;
	vi in(n);
	rep(i,n)cin>>in[i];
	vi t1=in,t2=in;
	rep(i,n)t1[i]+=d*i,t2[n-1-i]+=d*i;
	SegTree st1(t1),st2(t2);
	UnionFind uf(n);
	
	int out=0;
	vvi G;
	rep(i,n){
		pii a1=st2.query(0,i);
		pii a2=st1.query(i+1,n);
		a1.first-=(n-i-1)*d;
		a2.first-=i*d;
		if(a1.first<=a2.first){
			out+=a1.first+in[i];
			G.pb({a1.second,i,a1.first+in[i]});
			uf.unionSet(i,a1.second);
		}else{
			out+=a2.first+in[i];
			G.pb({a2.second,i,a2.first+in[i]});
			uf.unionSet(i,a2.second);
		}
	}
	int co=0;
	rep(i,n)if(uf.root(i)==i)co++;
	vvi mi(n);
	rep(i,G.size())mi[uf.root(G[i][0])].pb(G[i][2]);
	rep(i,n)if(mi[i].size()){
		sort(all(mi[i]));
		out-=mi[i][0];
	}
	vi w;
	w.pb(0);
	rep(i,n-1)if(uf.root(i)!=uf.root(i+1))w.pb(i+1);
	w.pb(n);
	// show1d(w);
	
	rep(i,w.size()-2){
		pii a1=st2.query(w[i],w[i+1]);
		pii a2=st1.query(w[i+1],w[i+2]);
		a1.first-=d*(n-1-w[i+1]);
		a2.first-=d*w[i+1];
		out+=a1.first+a2.first;
	}
	
	cout<<out<<endl;
}









Measured memory_bytes: 43436