#include<bits/stdc++.h>
#include<vector>
#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<deque>
#define ll long long
using namespace std;
#define BUF_SIZE 1048576
char _buf[BUF_SIZE],*_is=_buf,*_it=_buf;
inline char rdc(){
	if (_is==_it) _it=(_is=_buf)+fread(_buf,1,BUF_SIZE,stdin);
	return *_is++;
}
inline void rdi(int &x){
	int f=0;
	register char ch=rdc();
	while ((ch<'0' or ch>'9') and (ch^'-')) ch=rdc();
	if (ch=='-') f=1,ch=rdc();
	while (ch>='0' and ch<='9') x=(x<<3)+(x<<1)+(ch^'0'),ch=rdc();
	if(f) x=-x;
}
inline void rdi(ll &x){
	ll f=0;
	register char ch=rdc();
	while ((ch<'0' or ch>'9') and (ch^'-')) ch=rdc();
	if (ch=='-') f=1,ch=rdc();
	while (ch>='0' and ch<='9') x=(x<<3)+(x<<1)+(ch^'0'),ch=rdc();
	if(f) x=-x;
}
inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
inline void _write(int x){
	write(x);
	putchar(' ');
}
inline void print(int x){
	write(x);
	putchar('\n');
}
inline void write(ll x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
inline void _write(ll x){
	write(x);
	putchar(' ');
}
inline void print(ll x){
	write(x);
	putchar('\n');
}
const long long INF =LLONG_MAX / 2;
class SegmentTree
{
public:
    typedef pair<long long,int> T1;
    typedef long long T2;
    static const T1 INIT_DATA;
    static T1 uniteData(T1 v1,T1 v2){
        return min(v1,v2);
    }
 
private:
    inline T1 updateData(T1 prev,T2 x){
        prev.first =x;
        return prev;
    }
    int n;
    vector<T1> data;
    inline void updateTree(int a,int k,int l,int r,T2 x){
        if(a==l and a==r){
            data[k] =updateData(data[k],x);
        }
        else if(l<=a and a<=r){
            updateTree(a,k*2+1,l,(l+r)>>1,x);
            updateTree(a,k*2+2,(l+r+1)>>1,r,x);
            data[k] =uniteData(data[k*2+1],data[k*2+2]);
        }
    }
    inline T1 getValue(int a,int b,int k,int l,int r){
        if(a<=l and r<=b){
            return data[k];
        }
        else if(a<=r and l<=b){
            T1 v1=getValue(a,b,k*2+1,l,(l+r)>>1);
            T1 v2=getValue(a,b,k*2+2,(l+r+1)>>1,r);
            return uniteData(v1,v2);
        }
        else{
            return INIT_DATA;
        }
    }
public:
    inline SegmentTree(int n0){
        n=1;
        while(n<n0)
            n*=2;
        data.assign(2*n-1,INIT_DATA);
    }
    inline SegmentTree(const vector<T1>& v) : SegmentTree((int)v.size()){
        for(unsigned i=0; i<v.size();++i)
            data[n-1+i]=v[i];
        for(int k=n-2; k>=0; --k)
            data[k]=uniteData(data[k*2+1],data[k*2+2]);
    }
    inline void update(int a,T2 x){
        updateTree(a,0,0,n-1,x);
    }
    inline T1 get(int a,int b){
        return getValue(a,b,0,0,n-1);
    }
};
const SegmentTree::T1 SegmentTree::INIT_DATA(INF,-1);
class UnionFindTree
{
private:
    int n;
    vector<int> parent;
    vector<int> rank;  
public:
    inline int find(int i){
        if(i==-1)
            return -1;
        else if(parent[i]==i)
            return i;
        else
            return parent[i]=find(parent[i]);
    }
    inline UnionFindTree(int n){ 
        this->n=n;
        parent.resize(n);
        for(int i=0; i<n;++i)
            parent[i]=i;
        rank.assign(n,0);
    }
    inline void unite(int a,int b){
        if((a=find(a)) !=(b=find(b))){
            if(rank[a]<rank[b]){
                parent[a]=b;
            }
            else{
                parent[b]=a;
                if(rank[a]==rank[b])
                  ++rank[a];
            }
        }
    }
    inline bool same(int a,int b){
        return find(a)==find(b);
    }
};
inline long long solve(const vector<long long>& a,long long d){
    int n=a.size();
    vector<pair<long long,int> > v(n),tmp(n);
    for(int i=0; i<n;++i){
        v[i].first=a[i];
        v[i].second=i;
        tmp[i].first=INF;
        tmp[i].second=i;
    }
    sort(v.begin(),v.end());
    SegmentTree st1(tmp),st2(tmp);
    multiset<tuple<long long,int,int> > ms;
    for(const auto& p : v){
        int i=p.second;
        auto x=st1.get(i+1,n-1);
        if(x.first<INF){
            int j=x.second;
            long long cost=x.first+a[i]-d*i;
            ms.insert(make_tuple(cost,i,j));
        }
        st1.update(i,a[i]+d*i);
 
        auto y=st2.get(0,i-1);
        if(y.first<INF){
            int j=y.second;
            long long cost=y.first+a[i]-d*(n-1-i);
            ms.insert(make_tuple(cost,i,j));
        }
        st2.update(i,a[i]+d*(n-1-i));
    }
 
    long long ans=0;
    UnionFindTree uft(n);
    for(const auto& t : ms){
        long long cost;
        int i,j;
        tie(cost,i,j)=t;
        if(!uft.same(i,j)){
            ans+=cost;
            uft.unite(i,j);
        }
    }
    return ans;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    int n;
    long long d;
    cin>>n>>d;
    vector<long long> a(n);
    for(int i=0;i<n;++i) cin>>a[i];
    cout<<solve(a,d)<<endl;
    return 0;
}

Measured memory_bytes: 51072