#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; }
//---------------------------------------------------------------------------------------------------
template<typename T> struct Kruskal {
    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; }
    };

    int N; vector<pair<T, pair<int, int>>> E;
    void init(int n) { N = n; E.resize(0); E.clear(); }
    Kruskal() {} Kruskal(int n) { init(n); }
    void add(int a, int b, T c) { E.push_back({ c, {a, b} }); }
    T solve() {
        sort(all(E));
        UnionFind uf(N);
        T res = 0;
        fore(p, E) {
            int a = p.second.first;
            int b = p.second.second;
            T c = p.first;
            if (uf[a] != uf[b]) {
                uf(a, b);
                res += c;
            }
        }
        return res;
    }
};
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;
Kruskal<ll> kr;
//---------------------------------------------------------------------------------------------------
void dfs(int L, int R) {
    int len = R - L;
    if (len <= 1) return;

    int cn = (L + R) / 2;
    dfs(L, cn);
    dfs(cn, R);

    auto lopt = lft.get(L, cn);
    auto ropt = rht.get(cn, R);
    rep(i, L, cn) {
        ll c = ropt.first - 1LL * i * D + A[i];
        int a = i;
        int b = ropt.second;
        kr.add(a, b, c);
    }
    rep(i, cn, R) {
        ll c = lopt.first + 1LL * i * D + A[i];
        int a = i;
        int b = lopt.second;
        kr.add(a, b, c);
    }
}
//---------------------------------------------------------------------------------------------------
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 });
    kr.init(N);

    dfs(0, N);

    cout << kr.solve() << endl;
}

Measured memory_bytes: 85088