#include <bits/stdc++.h>

// pbds
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
// gp_hash_table<int, int> table;

using namespace std;

#define vec vector
#define ALL(x) begin(x), end(x)

typedef unsigned long long ull;
typedef unsigned int ui;
typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;

const int inf = 1000 * 1000 * 1000;
const ll inf64 = 1e18;

const int N = 2e5 + 5;

struct RangeTree {
    int n; // 1 .. n
    vector< pair< ll, int > > t;
    void build(int v, int tl, int tr, ll *A) {
        if(tl == tr) {
            t[v] = {A[tl], tl};
        }else {
            int tm = (tl + tr) >> 1;
            build(v << 1, tl, tm, A);
            build(v << 1 | 1, tm + 1, tr, A);
            t[v] = min(t[v << 1], t[v << 1 | 1]);
        }
    }

    RangeTree(int _n, ll *A):
        n(_n)
    {
        t.resize(4 * n, make_pair(inf64, -1));
        build(1, 1, n, A);
    }

    pair< ll, int > get_min(int v, int tl, int tr, int l, int r) {
        if(l <= tl && tr <= r) {
            return t[v];
        }else {
            int tm = (tl + tr) >> 1;
            pair< ll, int > res = {inf64, -1};
            if(l <= tm) {
                res = min(res, get_min(v << 1, tl, tm, l, r));
            }
            if(r > tm) {
                res = min(res, get_min(v << 1 | 1, tm + 1, tr, l, r));
            }
            return res;
        }
    }

    pair< ll, int > get_min(int l, int r) {
        if(l > r) return make_pair(inf64, -1);
        return get_min(1, 1, n, l, r);
    }

    void update(int v, int tl, int tr, int pos, ll val) {
        if(tl == tr) {
            t[v] = {val, tl};
        }else {
            int tm = (tl + tr) >> 1;
            if(pos <= tm) {
                update(v << 1, tl, tm, pos, val);
            }else {
                update(v << 1 | 1, tm + 1, tr, pos, val);
            }
            t[v] = min(t[v << 1], t[v << 1 | 1]);
        }
    }

    void update(int pos, ll val) {
        update(1, 1, n, pos, val);
    }
};

int n, d;
int a[N];
ll A[N], B[N], ii[N];

ll fast() {
    vector< int > nxt(n + 2, -1), prv(n + 2, -1);
    nxt[1] = n + 1;
    prv[1] = 0;
    for(int i = 1;i <= n;i++) {
        A[i] = -1ll * i * d + a[i];
        B[i] = +1ll * i * d + a[i];
        ii[i] = inf64;
    }
    RangeTree ra(n, A), rb(n, B), rl(n, ii), rr(n, ii);

    rl.update(1, A[1]);
    rr.update(1, B[1]);

    vector< pair< ll, int >> ff(n + 1, make_pair(inf64, -1)), gg = ff;

    ff[1] = ra.get_min(2, n);
    gg[1] = rb.get_min(2, n);

    auto get_best_w = [&](int i) -> ll {
        if(nxt[i] == i + 1) return inf64;
        return min(ff[i].first + rr.get_min(nxt[i], n).first,
                   gg[i].first + rl.get_min(1, i).first);
    };

    auto get_best_id = [&](int i) -> pii {
        if(nxt[i] == i + 1) return {-1, -1};
        pair< ll, int > hlp1 = rr.get_min(nxt[i], n), hlp2 = rl.get_min(1, i);
        pair< ll, pii > tmp1 = {
            ff[i].first + hlp1.first,
            {ff[i].second, hlp1.second}
        }, tmp2 = {
            gg[i].first + hlp2.first,
            {gg[i].second, hlp2.second}
        };
        return min(tmp1, tmp2).second;
    };

    set< pair< ll, int > > q;

    q.insert({get_best_w(1), 1});

    ll res = 0;

    for(int iter = 1;iter < n;iter++) {
        int i = q.begin()->second;
        ll w = q.begin()->first;
        res += w;
        int u, v;
        tie(u, v) = get_best_id(i);
        nxt[u] = nxt[i];
        prv[u] = i;
        prv[nxt[u]] = u;
        nxt[i] = u;
        q.erase(q.begin());

        ff[i] = ra.get_min(i + 1, u - 1);
        gg[i] = rb.get_min(i + 1, u - 1);
        ff[u] = ra.get_min(u + 1, nxt[u] - 1);
        gg[u] = rb.get_min(u + 1, nxt[u] - 1);

        rl.update(u, A[u]);
        rr.update(u, B[u]);

        q.insert({get_best_w(i), i});
        q.insert({get_best_w(u), u});
    }

    return res;
}

ll slow() {
    vector< int > p(n + 1);
    for(int i = 1;i <= n;i++) p[i] = i;
    auto find = [&](int x) -> int {
        while(p[x] != x) x = p[x];
        return x;
    };
    vector< pair< ll, pii > > ed;
    for(int i = 1;i <= n;i++) {
        for(int j = i + 1;j <= n;j++) {
            ed.push_back({abs(i - j) * d + a[i] + a[j], {i, j}});
        }
    }
    sort(ed.begin(), ed.end());
    ll res = 0;
    for(pair< ll, pii > e : ed) {
        int u, v;
        tie(u, v) = e.second;
        u = find(u);
        v = find(v);
        if(u != v) {
            res += e.first;
            p[u] = v;
        }
    }
    return res;
}

int main() {

#ifdef debug
    freopen("input.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

//#define TEST

#ifndef TEST
    cin >> n >> d;
#else
    mt19937 rnd(time(NULL));
    n = rnd() % 50 + 1;
    d = rnd() % 100 + 1;
#endif

    for(int i = 1;i <= n;i++) {
#ifndef TEST
        cin >> a[i];
#else
        a[i] = rnd() % 100 + 1;
#endif
    }

#ifdef TEST
    ll fs = fast();
    ll sl = slow();

    if(fs == sl) {
        cout << "OK (" << fs << " == " << sl << ")\n";
    }else {
        cout << "WA\n";
        cout << "exp = " << sl << "\n";
        cout << "fnd = " << fs << "\n";
    }
#else
    cout << fast() << "\n";
//    cerr << slow() << "\n";
#endif

    return 0;
}


Measured memory_bytes: 77440