#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const LL INF = LL(1e18);

struct Best {
    LL len;
    int ind, cmp;
    LL len2;
    int ind2, cmp2;
};

void upd(Best &best, LL len, int ind, int cmp) {
    if (cmp == best.cmp) {
        if (len < best.len) {
            best.len = len;
            best.ind = ind;
        }
    } else if (cmp == best.cmp2) {
        if (len < best.len2) {
            best.len2 = len;
            best.ind2 = ind;
            if (best.len2 < best.len) {
                swap(best.len, best.len2);
                swap(best.ind, best.ind2);
                swap(best.cmp, best.cmp2);
            }
        }
    } else if (len < best.len) {
        best.len2 = best.len;
        best.cmp2 = best.cmp;
        best.ind2 = best.ind;

        best.len = len;
        best.ind = ind;
        best.cmp = cmp;
    } else if (len < best.len2) {
        best.len2 = len;
        best.ind2 = ind;
        best.cmp2 = cmp;
    }
}

int n, d;
int a[200005];
Best be[200005];

int par[200005], ra[200005];

pair<LL, PII> bc[200005];

void dsuInit() {
    forn(i, n) par[i] = i, ra[i] = 1;
}

int dsuParent(int v) {
    if (v == par[v]) return v;
    return par[v] = dsuParent(par[v]);
}

void dsuMerge(int u, int v) {
    u = dsuParent(u);
    v = dsuParent(v);
    if (u == v) return;
    if (ra[u] < ra[v]) swap(u, v);
    par[v] = u;
    ra[u] += ra[v];
}

int main() {
//    freopen("input.txt", "r", stdin);
    scanf("%d%d", &n, &d);
    forn(i, n) scanf("%d", a + i);
    dsuInit();
    int rem = n - 1;
    Best dum;
    dum.len = dum.len2 = INF;
    dum.ind = dum.ind2 = -1;
    dum.cmp = -1;
    dum.cmp2 = -2;
    LL ans = 0;
    while (rem > 0) {
        forn(i, n) be[i] = dum;
        Best cur = dum;
        forn(i, n) {
            if (cur.cmp >= 0) upd(be[i], cur.len + (LL)i * d + a[i], cur.ind, cur.cmp);
            if (cur.cmp2 >= 0) upd(be[i], cur.len2 + (LL)i * d + a[i], cur.ind2, cur.cmp2);
            upd(cur, -(LL)d * i + a[i], i, dsuParent(i));
        }
        cur = dum;
        for (int i = n - 1; i >= 0; --i) {
            if (cur.cmp >= 0) upd(be[i], cur.len - (LL)i * d + a[i], cur.ind, cur.cmp);
            if (cur.cmp2 >= 0) upd(be[i], cur.len2 - (LL)i * d + a[i], cur.ind2, cur.cmp2);
            upd(cur, (LL)d * i + a[i], i, dsuParent(i));
        }
        forn(i, n) bc[i] = mp(INF, mp(-1, -1));
        forn(i, n) {
            int cm = dsuParent(i);
            if (be[i].cmp >= 0 && be[i].cmp != cm) {
                bc[cm] = min(bc[cm], mp(be[i].len, mp(i, be[i].ind)));
            } else if (be[i].cmp2 >= 0 && be[i].cmp2 != cm) {
                bc[cm] = min(bc[cm], mp(be[i].len2, mp(i, be[i].ind2)));
            }
        }
        forn(i, n) if (bc[i].first < INF) {
            if (dsuParent(bc[i].second.first) != dsuParent(bc[i].second.second)) {
                dsuMerge(bc[i].second.first, bc[i].second.second);
                --rem;
                ans += bc[i].first;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11904