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

using T=pair<long long int,int>;

class SegmentTree{
    vector<T> dat;
    int N;
    T E;
    function<T(T,T)> merge;
    T query_impl(int a,int b,int k,int l,int r);
    public:
    SegmentTree(size_t N,function<T(T,T)> merge,T E);
    void update(int pos,T val);        
    T query(int a,int b);
};

SegmentTree::SegmentTree(size_t N,function<T(T,T)> merge,T E):E(E),merge(merge){
    this->N=1;
    while(this->N<N){
        (this->N)*=2;
    }
    dat.assign(this->N*2-1,E);
}

void SegmentTree::update(int pos,T val){
    pos+=N-1;
    dat[pos]=val;
    while(pos!=0){
        int par=(pos-1)/2;
        int c1=par*2+1;
        int c2=par*2+2;
        dat[par]=merge(dat[c1],dat[c2]);
        pos=par;
    }
}

T SegmentTree::query(int a,int b){
    assert(a<=b);
    return query_impl(a,b,0,0,N);
}

T SegmentTree::query_impl(int a,int b,int k,int l,int r){
    if(a<=l && r<=b) return dat[k];
    if(r<=a || b<=l) return E;
    int mid=(l+r)/2;
    T c1v=query_impl(a,b,k*2+1,l,mid);
    T c2v=query_impl(a,b,k*2+2,mid,r);
    return merge(c1v,c2v);
}
using ll=long long;
const ll INF=1e16;
pair<ll,int> mymin(pair<ll,int> lhs,pair<ll,int> rhs){
    return min(lhs,rhs);
}
vector<ll> a;
struct MyComp{
    bool operator()(const int& lhs,const int& rhs){
        return make_pair(a[lhs],lhs)<make_pair(a[rhs],rhs);
    }
};
int main(){
    int n;
    ll d;
    cin>>n>>d;
    a.assign(n,0);
    for(int i=0;i<n;i++) cin>>a[i];
    
    SegmentTree segr(n,mymin,{INF,-1});
    for(int i=1;i<n;i++){
        segr.update(i,{a[i]+i*d,i});
    }
    SegmentTree segl(n,mymin,{INF,-1});
    for(int i=1;i<n;i++){
        segl.update(i,{a[i]-i*d,i});
    }
    priority_queue<pair<ll,pair<int,int>>,vector<pair<ll,pair<int,int>>>,greater<>> que;
    map<int,ll> scm;
    map<int,set<int,MyComp>> mp;
    auto insert=[&](int v){
        auto ret=segr.query(v+1,n);
        if(ret.second!=-1){
            mp[ret.second].insert(v);
            ll sc=ret.first+a[v]-v*d;
            if(!scm.count(ret.second) || sc<scm[ret.second]){
                que.push({sc,{v,ret.second}});
                scm[ret.second]=sc;
            }
        }
        ret=segl.query(0,v);
        if(ret.second!=-1){
            mp[ret.second].insert(v);
            que.push({ret.first+a[v]+v*d,{v,ret.second}});
            ll sc=ret.first+a[v]+v*d;
            if(!scm.count(ret.second) || sc<scm[ret.second]){
                que.push({sc,{v,ret.second}});
                scm[ret.second]=sc;
            }
        }
    };
    insert(0);
    ll res=0;
    vector<int> used(n);
    used[0]=true;
    
    while(!que.empty()){
        auto tmp=que.top(); que.pop();
        int from=tmp.second.first;
        int to=tmp.second.second;
        if(used[to]){
            insert(from);
            continue;
        }
        used[to]=true;
        res+=tmp.first;
        segl.update(to,{INF,-1});
        segr.update(to,{INF,-1});

        insert(to);
        for(auto v:mp[to]){
            insert(v);
        }
    }
    cout<<res<<endl;
    return 0;
}