#include <bits/stdc++.h>
#define ll long long
#define INF (1LL << 61)
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl

using namespace std;

template<typename S,typename T>auto&operator<<(ostream&o,pair<S,T>p){return o<<"{"<<p.fi<<","<<p.se<<"}";}
template<typename T>auto&operator<<(ostream&o,set<T>s){for(auto&e:s)o<<e<<" ";return o;}
template<typename S,typename T,typename U>
auto&operator<<(ostream&o,priority_queue<S,T,U>q){while(!q.empty())o<<q.top()<<" ",q.pop();return o;}
template<typename K,typename T>auto&operator<<(ostream&o,map<K,T>&m){for(auto&e:m)o<<e<<" ";return o;}
template<typename T>auto&operator<<(ostream&o,vector<T>v){for(auto&e:v)o<<e<<" ";return o;}
void ashow(){cout<<endl;}template<typename T,typename...A>void ashow(T t,A...a){cout<<t<<" ";ashow(a...);}
template<typename S,typename T,typename U>
struct TRI{S fi;T se;U th;TRI(){}TRI(S f,T s,U t):fi(f),se(s),th(t){}
bool operator<(const TRI&_)const{return (fi==_.fi)?((se==_.se)?(th<_.th):(se<_.se)):(fi<_.fi);}};
template<typename S,typename T,typename U>
auto&operator<<(ostream&o,TRI<S,T,U>&t){return o<<"{"<<t.fi<<","<<t.se<<","<<t.th<<"}";}

typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef TRI<ll, ll, ll> tri;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<string> vs;

const int MAX_N = 200005;

ll a[MAX_N];
set<int> G[MAX_N];

template<typename T> class segtree {
private:
    int n,sz;
    vector<pair<T, int> > node;
public:
    segtree(const vector<T>& v) : n(1), sz((int)v.size()){
        while(n < sz) n *= 2;
        node.resize(2*n, make_pair(numeric_limits<T>::max(), sz));
        for(int i = 0; i < sz; i++){
            node[i+n] = make_pair(v[i], i);
        }
        for(int i=n-1; i>=1; i--){
            node[i] = min(node[2*i], node[2*i+1]);
        }
    }
    T get(int k, T a)
    {
        return node[k+n];
    }
    void update(int k, T a)
    {
    	node[k+n] = make_pair(a, k);
        k += n;
    	while(k>>=1){
            node[k] = min(node[2*k], node[2*k+1]);
    	}
    }
    pair<T, int> query(int a,int b,int k=0,int l=0,int r=-1)
    {
        pair<T, int> res1 = make_pair(numeric_limits<T>::max(), sz);
        pair<T, int> res2 = make_pair(numeric_limits<T>::max(), sz);
        a += n, b += n;
        while(a != b){
            if(a % 2) cmn(res1, node[a++]);
            if(b % 2) cmn(res2, node[--b]);
            a >>= 1, b>>= 1;
        }
        return min(res1, res2);
    }
    void print()
    {
        for(int i = 0; i < sz; i++){
            pair<T, int> p;
            p = query(i,i+1);
            cout << "st[" << i << "]: " << p.first << " " << p.second << endl;
        }
    }
};

bool visit[MAX_N];

void dfs(int u, int p, vector<int>& ver)
{
    visit[u] = true;
    ver.pb(u);
    for(int v : G[u]){
        if(v != p){
            dfs(v, u, ver);
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, D;
    cin >> n >> D;
    rep(i,n){
        cin >> a[i];
    }
    int nw = 0;
    ll sm = 0;
    while(nw < n-1){
        vl hoge1(n), hoge2(n);
        rep(i,n){
            hoge1[i] = a[i] + i*D;
            hoge2[i] = a[i] + (n-i-1)*D;
            visit[i] = false;
        }
        segtree<ll> l(hoge2), r(hoge1);
        vector<tri> add;
        rep(i,n){
            if(visit[i]) continue;
            vi ver;
            tri res = {2*INF, 2*INF, 2*INF};
            dfs(i, -1, ver);
            each(v, ver){
                l.update(v, INF), r.update(v, INF);
            }
            each(v, ver){
                auto p = l.query(0, v);
                auto q = r.query(v+1, n);
                p.fi -= (n-v-1)*D, q.fi -= v*D;
                auto hoge = min(p, q);
                cmn(res, ((tri){hoge.fi + a[v], hoge.se, v}));
            }
            add.pb((tri){res.th, res.se, res.fi});
            each(v, ver){
                l.update(v, a[v]+(n-v-1)*D), r.update(v, a[v]+v*D);
            }
        }
        each(p, add){
            if(G[p.fi].find(p.se) == G[p.fi].end()){
                G[p.fi].insert(p.se), G[p.se].insert(p.fi);
                nw++;
                sm += p.th;
            }
        }
    }
    cout << sm << "\n";
    return 0;
}


Measured memory_bytes: 58220