#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

template<typename M,typename N=M>struct SegmentTree{
   using F=function<M(M,M)>; using G=function<M(M,N)>;
   int sz; vector<M> data; const F f; const G g; const M m1;
   SegmentTree(int n,const F f,const G g,const M &m1):f(f),g(g),m1(m1){
      sz=1; while(sz<n)sz<<=1; data.assign(2*sz,m1);
   }
   void build(vector<M> v){
      rep(i,0,v.size())data[i+sz]=v[i];
      rrep(k,sz-1,0)data[k]=f(data[2*k],data[2*k+1]);
   }
   void update(int k,const N &x){
      k+=sz; data[k]=g(data[k],x);
      while(k>>=1)data[k]=f(data[2*k],data[2*k+1]);
   }
   M query(int a,int b){
      M L=m1,R=m1;
      for(a+=sz,b+=sz;a<b;a>>=1,b>>=1){
         if(a&1)L=f(L,data[a++]);
         if(b&1)R=f(data[--b],R);
      } return f(L,R);
   }
   M operator[](const int &k)const{return data[k+sz];}
};

template<class Abel> struct UnionFind {
   vector<int> par,rank;
   vector<Abel> diff_weight;
   UnionFind(int n=1,Abel SUM_UNITY=0){init(n, SUM_UNITY);}
   void init(int n=1,Abel SUM_UNITY=0) {
      par.resize(n); rank.resize(n); diff_weight.resize(n);
      rep(i,0,n)par[i]=-1,rank[i]=0,diff_weight[i]=SUM_UNITY;
   }
   int root(int x){
      if(par[x]<0)return x;
      int r=root(par[x]); diff_weight[x]+=diff_weight[par[x]];
      return par[x]=r;
   }
   int size(int x){ return -par[root(x)]; }
   Abel weight(int x){root(x); return diff_weight[x];}
   bool issame(int x, int y){return root(x)==root(y);}
   bool merge(int x,int y,Abel w){
      w+=weight(x)-weight(y); x=root(x); y=root(y);
      if(x==y)return false;
      if(rank[x]<rank[y])swap(x,y),w=-w;
      if(rank[x]==rank[y])++rank[x];
      par[x]+=par[y]; par[y]=x; diff_weight[y]=w; return true;
   }
   Abel diff(int x,int y){return weight(y)-weight(x);}
};

typedef pair<ll,int> P; //val,idx

int main(){
   int n; ll d; scanf("%d%lld",&n,&d);
   vector<ll> a(n); rep(i,0,n)scanf("%lld",&a[i]);
   auto f=[](P a,P b){return min(a,b);};
   auto g=[](P a,P b){return b;};
   SegmentTree<P> segL(n,f,g,{INF,0}),segR(n,f,g,{INF,0});
   vector<int> ord(n); iota(ALL(ord),0);
   sort(ALL(ord),[&](int i,int j){return a[i]<a[j];});
   vector<vector<ll>> es;
   for(int i:ord){
      P p=segL.query(0,i+1);
      if(p!=P{INF,0}){
         ll co=p.first+a[i]-(n-i)*d;
         es.push_back({co,i,p.second});
      }
      p=segR.query(i,n);
      if(p!=P{INF,0}){
         ll co=p.first+a[i]-i*d;
         es.push_back({co,i,p.second});
      }
      segL.update(i,{a[i]+(n-i)*d,i});
      segR.update(i,{a[i]+i*d,i});
   }
   sort(ALL(es)); UnionFind<int> uni(n);
   ll res=0;
   for(auto e:es){
      if(!uni.issame(e[1],e[2])){
         uni.merge(e[1],e[2],1);
         res+=e[0];
      }
   } printf("%lld\n",res);
   return 0;
}

Measured memory_bytes: 44712