#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const int maxn = 2e5 + 555;
const int MOD = 1e9 + 7;
template <int N> struct DSU {
    int fa[N], dep[N];
    list<int> el[N];
    void init() {
        for (int i = 0; i < N; i++)
            el[i].push_back(i);
        iota(fa, fa + N, 0);
        fill(dep, dep + N, 1);
    }
    int seek(int x) { return fa[x] == x ? x : fa[x] = seek(fa[x]); }
    bool merge(int a, int b) {
        // cout << "merge" << ' ' << a << ' ' << b << endl;
        int f1 = seek(a), f2 = seek(b);
        if (f1 != f2) {
            if (dep[f1] < dep[f2]) {
                fa[f1] = f2;
                el[f2].splice(el[f2].end(), el[f1]);
            } else if (dep[f1] > dep[f2]) {
                fa[f2] = f1;
                el[f1].splice(el[f1].end(), el[f2]);
            } else {
                fa[f1] = f2;
                el[f2].splice(el[f2].end(), el[f1]);
                dep[f2]++;
            }
            return true;
        } else {
            return false;
        }
    }
    DSU() { init(); }
};
DSU<200000 + 5> dsu;
using T = pair<ll, int>;
constexpr int N = 1 << (__lg(200000) + 1);
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
template <int SZ> struct Seg {
    T seg[2 * SZ];
    static constexpr T ID = make_pair(INF, -1);
    void init() { F0R(i, 2 * SZ) seg[i] = ID; }
    Seg() {}
    void build(const vector<ll> &x) {
        init();
        for (int i = 0; i < (int)x.size(); i++) {
            seg[i + SZ] = make_pair(x[i], i);
        }
        F0Rd(i, SZ) seg[i] = comb(seg[2 * i], seg[2 * i + 1]);
    }
    T comb(const T &a, const T &b) const { return min(a, b); }
    void upd(int p, T value) {
        for (seg[p += SZ] = value; p > 1; p >>= 1)
            seg[p >> 1] = comb(seg[(p | 1) ^ 1], seg[p | 1]);
    }
    T query(int l, int r) {
        if (l > r)
            return ID;
        T res1 = ID, res2 = ID;
        r++;
        for (l += SZ, r += SZ; l < r; l >>= 1, r >>= 1) {
            if (l & 1)
                res1 = comb(res1, seg[l++]);
            if (r & 1)
                res2 = comb(seg[--r], res2);
        }
        return comb(res1, res2);
    }
};
Seg<N> seg1, seg2;
int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(10);
    cout << fixed;
    int n;
    ll d;
    cin >> n >> d;
    vector<ll> V(n);
    vector<ll> cost1(n);
    vector<ll> cost2(n);
    for (int i = 0; i < n; i++) {
        cin >> V[i];
        cost1[i] = i * d + V[i];
        cost2[i] = -i * d + V[i];
    }
    seg1.build(cost1);
    seg2.build(cost2);
    ll ans = 0;
    while (true) {
        set<int> st;
        for (int i = 0; i < n; i++)
            st.insert(dsu.seek(i));
        if (st.size() == 1)
            break;
        vector<pair<ll, int>> dis(n, make_pair(INF, -1));
        for (int i : st) {
            for (auto j : dsu.el[i]) {
                seg1.upd(j, seg1.ID);
                seg2.upd(j, seg2.ID);
            }
            for (int j : dsu.el[i]) {
                auto cost1 = seg1.query(j + 1, n);
                cost1.first += -j * d + V[j];
                dis[i] = min(dis[i], cost1);

                auto cost2 = seg2.query(0, j - 1);
                cost2.first += j * d + V[j];
                dis[i] = min(dis[i], cost2);
            }
            for (auto j : dsu.el[i]) {
                seg1.upd(j, make_pair(cost1[j], j));
                seg2.upd(j, make_pair(cost2[j], j));
            }
        }
        for (int i : st) {
            if (dis[i].second != -1) {
                int fa1 = dsu.seek(i);
                int fa2 = dsu.seek(dis[i].second);
                if (fa1 != fa2) {
                    dsu.merge(fa1, fa2);
                    ans += dis[i].first;
                }
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 49368