#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

struct LazySegmentTree{
    int n, width;
    vector<PL> dat;
    VL lazy;
    const PL INF = PL(1e18, 1e9);
    const ll INFLL = 1e17;

    LazySegmentTree(VL v){
        int n = v.size();
        width = 1;
        while (width < n) width *= 2;
        dat.assign(2 * width - 1, INF);
        lazy.assign(2 * width - 1, 0);
        REP(i,n) dat[i + width - 1] = PL(v[i], i);
        FORR(i,width-2,0) dat[i] = min(dat[2 * i + 1], dat[2 * i + 2]);
    }

    void eval(int k, int l, int r){
        dat[k].first = min(INFLL, dat[k].first + lazy[k]);
        if (r - l > 1){
            lazy[2 * k + 1] = min(INFLL, lazy[2 * k + 1] + lazy[k]);
            lazy[2 * k + 2] = min(INFLL, lazy[2 * k + 2] + lazy[k]);
        }
        lazy[k] = 0;
    }

    void add(int a, int b, ll x, int k, int l, int r){
        eval(k, l, r);
        if (r <= a || b <= l) return;
        if (a <= l && r <= b){
            lazy[k] += x;
            eval(k, l, r);
        }else{
            add(a, b, x, 2 * k + 1, l, (l + r) / 2);
            add(a, b, x, 2 * k + 2, (l + r) / 2, r);
            dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }

    // [l, r) += x
    void add(int l, int r, ll x){
        add(l, r, x, 0, 0, width);
    }

    PL query(int a, int b, int k, int l, int r){
        eval(k, l, r);
        if (r <= a || b <= l) return INF;
        if (a <= l && r <= b) return dat[k];
        PL vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        PL vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return min(vl, vr);
    }

    PL query(int l, int r){
        return query(l, r, 0, 0, width);
    }
};

const ll INF = 1e16;

int main() {
    ll n, d;
    cin >> n >> d;
    VL a(n);
    REP(i,n) a[i] = in();

    VL b(n), c(n);
    REP(i,n){
        b[i] = a[i] + i * d;
        c[i] = a[i] - i * d;
    }

    set<PL> st, st2;
    st.insert(PL(0, c[0]));
    st.insert(PL(n, INF));
    st2.insert(PL(-1, INF));
    st2.insert(PL(n, INF));
    VL tmp(b);
    REP(i,n) tmp[i] += c[0];
    tmp[0] = INF;

    LazySegmentTree segtree(tmp);

    REP(i,n) tmp[i] = INF + c[i];
    tmp[0] = 1e18;
    LazySegmentTree segtree2(tmp);
    st2.insert(PL(n, INF));


    // REP(i,n){
    //     REP(j,n) cout << abs(i - j) * d + a[i] + a[j] << " ";
    //     cout << endl;
    // }

    // cout << endl;
    // REP(i,n) cout << b[i] << " ";
    // cout << endl;
    // REP(i,n) cout << c[i] << " ";
    // cout<< endl;

    ll ans = 0;
    REP(i,n-1){
        // cout << i << endl;
        PL p = min(segtree.query(0, n), segtree2.query(0, n));
        // REP(j,n) cout << segtree.query(j, j + 1).first << " ";
        // cout << endl;
        // REP(j,n) cout << segtree2.query(j, j + 1).first << " ";
        // cout << endl;
        ans += p.first;
        int x = p.second;
        segtree.add(x, x + 1, INF);
        segtree2.add(x, x + 1, INF);
        auto itr = st.lower_bound(PL(x, 0));
        itr--;
        if (itr->second > c[x]){
            auto itr2 = st.lower_bound(PL(x, 0));
            segtree.add(x + 1, itr2->first, c[x] - itr->second);
            st.insert(PL(x, c[x]));
        }
        auto itr2 = st2.lower_bound(PL(x, 0));
        if (itr2->second > b[x]){
            ll hoge = itr2->second;
            itr2--;
            segtree2.add(itr2->first + 1, x, b[x] - hoge);
            st2.insert(PL(x, b[x]));
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 55916