#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
struct UnionFind {
    vector<int> par; // uf(x,y)->y
    UnionFind() {}
    UnionFind(int NV) { init(NV); }
    void init(int NV) { par.clear(); rep(i, 0, NV) par.push_back(i); }
    void reset() { rep(i, 0, par.size()) par[i] = i; }
    int operator[](int x) { return par[x] == x ? x : par[x] = operator[](par[x]); }
    void operator()(int x, int y) { x = operator[](x); y = operator[](y); if (x != y) par[x] = y; }
};
template<class V, int NV> struct SegTree { //[l,r)
    const V def = make_pair(infl,inf);
    V comp(V& l, V& r) { return min(l, r); };
 
    vector<V> val; SegTree() { val = vector<V>(NV * 2, def); }
    V get(int x, int y, int l = 0, int r = NV, int k = 1) {
        if (r <= x || y <= l)return def; if (x <= l && r <= y)return val[k];
        auto a = get(x, y, l, (l + r) / 2, k * 2);
        auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
        return comp(a, b);
    }
    void update(int i, V v) {
        i += NV; val[i] = v;
        while (i > 1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
    }
    void add(int i, V v) { update(i, val[i + NV] + v); }
    V operator[](int x) { return get(x, x + 1); }
};
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/









int N, D, A[201010];
SegTree<pair<ll, int>, 1 << 18> lft, rht;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> D;
    rep(i, 0, N) cin >> A[i];

    rep(i, 0, N) lft.update(i, { -1LL * i*D + A[i], i });
    rep(i, 0, N) rht.update(i, { 1LL * i *D + A[i], i });
    
    UnionFind uf(N);
    int cnt = N;
    ll ans = 0;
    while (2 <= cnt) {
        vector<vector<ll>> e;
        vector<vector<int>> gr(N);
        rep(i, 0, N) gr[uf[i]].push_back(i);
        rep(g, 0, N) {
            fore(i, gr[g]) {
                lft.update(i, { infl, i });
                rht.update(i, { infl, i });
            }

            ll opt = infl;
            int a, b;

            fore(i, gr[g]) {
                auto lf = lft.get(0, i);
                ll lc = lf.first + 1LL * i * D + A[i];
                if (lc < opt) {
                    opt = lc;
                    a = i;
                    b = lf.second;
                }

                auto rh = rht.get(i + 1, N);
                ll rc = rh.first - 1LL * i * D + A[i];
                if (rc < opt) {
                    opt = rc;
                    a = i;
                    b = rh.second;
                }
            }

            if(opt != infl) e.push_back({ a,b,opt });

            fore(i, gr[g]) {
                lft.update(i, { -1LL * i*D + A[i], i });
                rht.update(i, { 1LL * i *D + A[i], i });
            }
        }

        fore(v, e) {
            int a = v[0];
            int b = v[1];
            ll c = v[2];

            if (uf[a] != uf[b]) {
                uf(a, b);
                ans += c;
                cnt--;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 41452