#include<bits/stdc++.h>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

/////////////////////////////////////////////////////
#define pll pair<ll,ll>
#define mp make_pair
#define INF ((ll)1e17)


struct UnionFind{
    vector<int> nxt;
    UnionFind(int x){
        nxt.resize(x);
        for (int i = 0; i < x;i++){
            nxt[i] = i;
        }
    }
    inline int find(int x){
        int xx = x;
        while(nxt[xx]!=xx){
            xx=nxt[xx];
        }
        return nxt[x] = xx;
    }
    inline void unite(int x,int y){
        nxt[find(y)] = find(x);
    }
};

template<typename T>
struct SegTree{
    int num,bt;
    vector<T> node;

    void init(int num,T n){
        int i = 0,j=1;
        
        for (i = 0; j < num;i++)
            j*=2;
        j *= 2;
        node.resize((j - 1));
        for (int i = 0; i < j - 1; i++){
            node[i] = n;
        }
        bt = j / 2-1;
        //printf("bb%d\n", bt);
    }
    void sett(int x,T n){
        int i = bt+x;
        node[i] = n;
        while(i!=0){
            //printf("%d ", i);
            i = (i - 1) / 2;
            node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
        }
        //printf("\n");
    }
    T gett(int x,int y){
        int i = bt+x;
        T sss = node[i];
        if(x==0&&y==num-1){
            return node[0];
        }
        if(x!=0){
            int i = bt + x-1;
            int j = 1,l=x-1,r=x-1;
            while(i!=0){
                if(i%2&&x<=l+j&&r+j<=y){
                    //printf("%lld-%lld,%lld,%lld ",l+j,r+j, node[i + 1], sss);
                    sss = min(node[i + 1],sss);
                }
                i = (i - 1) / 2;
                j *= 2;
                l = l / j*j;
                r = r / j*j+j-1;
            }
        }
        if(y!=num-1){
            int i = bt + y+1;
            int j = 1,l=y+1,r=y+1;
            while(i!=0){
                if(i%2==0&&x<=l-j&&r-j<=y){
                    //printf("%lld-%lld,%lld,%lld ", l-j,r-j,node[i + 1], sss);
                    sss = min(node[i - 1],sss);
                }
                i = (i - 1) / 2;
                j *= 2;
                l = l / j*j;
                r = r / j*j+j-1;
            }
        }
        return sss;
    }
};
SegTree<pll> rp,lp;
UnionFind mk(0);

ll N,D,A[202020],Am;
ll i,j,ans;
vector<pll> s;
vector<pair<ll, pll>> p;
//bool mk[202020];

int main(){
    scanf("%lld%lld",&N,&D);
    fornum(i,0,N){
        scanf("%lld",&A[i]);
        s.push_back(mp(A[i],i));
    }
    if(N==0){
        printf("0");
        return 0;
    }

    sort(s.begin(),s.end());
    for (Am = 1; Am < N;Am*=2)
        ;
    rp.init(N, mp(INF,0));
    lp.init(N, mp(INF,0));
    rp.sett(s[0].second, mp(s[0].first+s[0].second*D,s[0].second));
    lp.sett(s[0].second, mp(s[0].first+(N-s[0].second)*D,s[0].second));
    fornum(i,1,N){
        auto ss = s[i];
        if(ss.second!=N-1){
            auto ps = rp.gett(ss.second + 1, N - 1);
            //pp = ps.first < pp.first ? ps : pp;
            p.push_back(mp(ps.first-ss.second*D + ss.first, mp(ss.second, ps.second)));
            //printf("%lld,%lld,%llda\n", ss.second,ps.second,p[p.size()-1].first);
        }
        if (ss.second != 0){
            auto ps=lp.gett(0,ss.second-1);
            //pp = ps.first < pp.first ? ps : pp;
            p.push_back(mp(ps.first-(N-ss.second) * D + ss.first, mp(ss.second, ps.second)));
            //printf("%lld,%lld,%llda\n", ss.second,ps.second,p[p.size()-1].first);
        }
        //p.push_back(mp(ss.first + pp.first, mp(ss.second, ps.second)));
        rp.sett(ss.second, mp(ss.first + ss.second * D, ss.second));
        lp.sett(ss.second, mp(ss.first + (N - ss.second) * D, ss.second));
        
    }

    mk = UnionFind(N);
    
    j = 0;
    sort(p.begin(), p.end());
    fornum(i,0,p.size()){
        auto ppp = p[i];
        auto pppp = ppp.second;
        //printf("%lld,%lld,%lld,%lld:\n",i, pppp.first, pppp.second,ppp.first);
        if(mk.find(pppp.first)!=mk.find(pppp.second)){
            ans += ppp.first;
            mk.unite(pppp.first, pppp.second);
            j++;

            if(j==N-1)
                break;
        }
    }

    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 38632