#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N, D;
vector<ll> A;
vector<ll> Right, Left;
vector<ll> Rmin, Lmin;
struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    vector<ll> l, r, Lmin, Rmin;
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
        l.resize(n);
        r.resize(n);
        Lmin.resize(n);
        Rmin.resize(n);
        for(int i = 0; i < N; i++) {
            l[i] = i;
            r[i] = i;
            Lmin[i] = Left[i];
            Rmin[i] = Right[i];
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        par[y] = x;
        Size[x] += Size[y];
        chmin(l[x], l[y]);
        chmax(r[x], r[y]);
        chmin(Lmin[x], Lmin[y]);
        chmin(Rmin[x], Rmin[y]);
        return true;
    }

    ll size(int x){
        return Size[root(x)];
    }
};

ll ans = 0;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> D;
    A.resize(N);
    Right.resize(N);
    Left.resize(N);
    Lmin.resize(N);
    Rmin.resize(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        Right[i] = A[i] + i * D;
        Left[i] = A[i] - i * D;
    }
    Lmin[0] = 0;
    for(int i = 1; i < N; i++) {
        Lmin[i] = Lmin[i-1];
        if(Left[i] < Left[Lmin[i]]) Lmin[i] = i;
    }
    Rmin[N-1] = N-1;
    for(int i = N - 2; i >= 0; i--) {
        Rmin[i] = Rmin[i+1];
        if(Right[i] < Right[Rmin[i]]) Rmin[i] = i;
    }
    cerr << "Left: " << endl;
    for(int i = 0; i < N; i++) {
        cerr << Left[i] << " ";
    }
    cerr << endl;
    cerr << "Right: " << endl;
    for(int i = 0; i < N; i++) {
        cerr << Right[i] << " ";
    }
    cerr << endl;
    cerr << "Lmin: " << endl;
    for(int i = 0; i < N; i++) {
        cerr << Lmin[i] << " ";
    }
    cerr << endl;
    cerr << "Rmin: " << endl;
    for(int i = 0; i < N; i++) {
        cerr << Rmin[i] << " ";
    }
    cerr << endl;
    UnionFind uni(N);
    for(int i = 0; i < N - 1; i++) {
        ll to = -1;
        ll val = 1e18;
        ll L = uni.l[uni.root(i)];
        if(L > 0) {
            ll idx = Lmin[L - 1];
            //cerr << "L:" << L << " " << idx << endl;
            ll nowval = Left[idx] + uni.Rmin[uni.root(i)];
            if(chmin(val, nowval)) to = idx;
        }
        ll R = uni.r[uni.root(i)];
        if(R < N - 1) {
            ll idx = Rmin[R + 1];
            ll nowval = Right[idx] + uni.Lmin[uni.root(i)];
            //cerr << "R:" << R << " " << idx << " " << nowval << endl;
            if(chmin(val, nowval)) to = idx;
        }
        //cerr << i << " " << to << " " << val << endl;
        ans += val;
        uni.merge(i, to);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 18176